summaryrefslogtreecommitdiffstats
path: root/chromium/chrome/browser/ui/webui/devtools_ui_data_source.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/chrome/browser/ui/webui/devtools_ui_data_source.cc')
-rw-r--r--chromium/chrome/browser/ui/webui/devtools_ui_data_source.cc101
1 files changed, 51 insertions, 50 deletions
diff --git a/chromium/chrome/browser/ui/webui/devtools_ui_data_source.cc b/chromium/chrome/browser/ui/webui/devtools_ui_data_source.cc
index 95e73c57300..53b632a539a 100644
--- a/chromium/chrome/browser/ui/webui/devtools_ui_data_source.cc
+++ b/chromium/chrome/browser/ui/webui/devtools_ui_data_source.cc
@@ -84,11 +84,21 @@ std::string DevToolsDataSource::GetSource() {
return chrome::kChromeUIDevToolsHost;
}
+// static
+GURL GetCustomDevToolsFrontendURL() {
+ base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
+ if (command_line->HasSwitch(switches::kCustomDevtoolsFrontend)) {
+ return GURL(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+ switches::kCustomDevtoolsFrontend));
+ }
+ return GURL();
+}
+
void DevToolsDataSource::StartDataRequest(
const std::string& path,
const content::WebContents::Getter& wc_getter,
const GotDataCallback& callback) {
- // Serve request from local bundle.
+ // Serve request to devtools://bundled/ from local bundle.
std::string bundled_path_prefix(chrome::kChromeUIDevToolsBundledPath);
bundled_path_prefix += "/";
if (base::StartsWith(path, bundled_path_prefix,
@@ -99,15 +109,19 @@ void DevToolsDataSource::StartDataRequest(
base::CompareCase::INSENSITIVE_ASCII));
std::string path_under_bundled =
path_without_params.substr(bundled_path_prefix.length());
-#if BUILDFLAG(DEBUG_DEVTOOLS)
- StartFileRequestForDebugDevtools(path_under_bundled, callback);
-#else
- StartBundledDataRequest(path_under_bundled, callback);
+#if !BUILDFLAG(DEBUG_DEVTOOLS)
+ if (!GetCustomDevToolsFrontendURL().SchemeIsFile()) {
+ // Fetch from packaged resources.
+ StartBundledDataRequest(path_under_bundled, callback);
+ return;
+ }
#endif
+ // Fetch from file system.
+ StartFileRequest(path_under_bundled, callback);
return;
}
- // Serve empty page.
+ // Serve request to devtools://blank as empty page.
std::string empty_path_prefix(chrome::kChromeUIDevToolsBlankPath);
if (base::StartsWith(path, empty_path_prefix,
base::CompareCase::INSENSITIVE_ASCII)) {
@@ -115,7 +129,7 @@ void DevToolsDataSource::StartDataRequest(
return;
}
- // Serve request from remote location.
+ // Serve request to devtools://remote from remote location.
std::string remote_path_prefix(chrome::kChromeUIDevToolsRemotePath);
remote_path_prefix += "/";
if (base::StartsWith(path, remote_path_prefix,
@@ -132,29 +146,22 @@ void DevToolsDataSource::StartDataRequest(
return;
}
- std::string custom_frontend_url =
- base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
- switches::kCustomDevtoolsFrontend);
-
- if (custom_frontend_url.empty()) {
- callback.Run(nullptr);
- return;
- }
-
- // Serve request from custom location.
+ // Serve request to devtools://custom from custom URL.
std::string custom_path_prefix(chrome::kChromeUIDevToolsCustomPath);
custom_path_prefix += "/";
-
if (base::StartsWith(path, custom_path_prefix,
base::CompareCase::INSENSITIVE_ASCII)) {
- GURL url =
- GURL(custom_frontend_url + path.substr(custom_path_prefix.length()));
- DCHECK(url.is_valid());
- StartCustomDataRequest(url, callback);
- return;
+ GURL custom_devtools_frontend = GetCustomDevToolsFrontendURL();
+ if (!custom_devtools_frontend.is_empty()) {
+ GURL url = GURL(custom_devtools_frontend.spec() +
+ path.substr(custom_path_prefix.length()));
+ DCHECK(url.is_valid());
+ StartCustomDataRequest(url, callback);
+ return;
+ }
}
- callback.Run(nullptr);
+ callback.Run(CreateNotFoundResponse());
}
std::string DevToolsDataSource::GetMimeType(const std::string& path) {
@@ -279,8 +286,7 @@ void DevToolsDataSource::StartNetworkRequest(
base::Unretained(this), request_iter));
}
-#if BUILDFLAG(DEBUG_DEVTOOLS)
-scoped_refptr<base::RefCountedMemory> ReadFileForDebugDevTools(
+scoped_refptr<base::RefCountedMemory> ReadFileForDevTools(
const base::FilePath& path) {
std::string buffer;
if (!base::ReadFileToString(path, &buffer)) {
@@ -290,29 +296,26 @@ scoped_refptr<base::RefCountedMemory> ReadFileForDebugDevTools(
return base::RefCountedString::TakeString(&buffer);
}
-void DevToolsDataSource::StartFileRequestForDebugDevtools(
- const std::string& path,
- const GotDataCallback& callback) {
- base::FilePath inspector_debug_dir;
- base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
- if (command_line->HasSwitch(switches::kCustomDevtoolsFrontend)) {
- inspector_debug_dir =
- command_line->GetSwitchValuePath(switches::kCustomDevtoolsFrontend);
- // --custom-devtools-frontend may already be used to specify an URL.
- // In that case, fall back to the default debug-devtools bundle.
- if (!base::PathExists(inspector_debug_dir))
- inspector_debug_dir.clear();
- }
- if (inspector_debug_dir.empty() &&
- !base::PathService::Get(chrome::DIR_INSPECTOR_DEBUG,
- &inspector_debug_dir)) {
- callback.Run(CreateNotFoundResponse());
- return;
+void DevToolsDataSource::StartFileRequest(const std::string& path,
+ const GotDataCallback& callback) {
+ base::FilePath base_path;
+ GURL custom_devtools_frontend = GetCustomDevToolsFrontendURL();
+ if (custom_devtools_frontend.SchemeIsFile()) {
+ base_path = base_path.AppendASCII(custom_devtools_frontend.GetContent());
+ } else {
+#if BUILDFLAG(DEBUG_DEVTOOLS)
+ // Use default path for unbundled files when debug_devtools=true
+ if (!base::PathService::Get(chrome::DIR_INSPECTOR_DEBUG, &base_path)) {
+ callback.Run(CreateNotFoundResponse());
+ return;
+ }
+#else
+ NOTREACHED();
+#endif
}
- DCHECK(!inspector_debug_dir.empty());
-
- base::FilePath full_path = inspector_debug_dir.AppendASCII(path);
+ base::FilePath full_path = base_path.AppendASCII(path);
+ CHECK(base_path.IsParent(full_path));
base::PostTaskAndReplyWithResult(
FROM_HERE,
@@ -322,10 +325,8 @@ void DevToolsDataSource::StartFileRequestForDebugDevtools(
// The usage of BindRepeating below is only because the type of
// task callback needs to match that of response callback, which
// is currently a repeating callback.
- base::BindRepeating(ReadFileForDebugDevTools, std::move(full_path)),
- callback);
+ base::BindRepeating(ReadFileForDevTools, std::move(full_path)), callback);
}
-#endif // BUILDFLAG(DEBUG_DEVTOOLS)
void DevToolsDataSource::OnLoadComplete(
std::list<PendingRequest>::iterator request_iter,