| Index: chrome/browser/ui/webui/devtools_ui.cc
|
| diff --git a/chrome/browser/ui/webui/devtools_ui.cc b/chrome/browser/ui/webui/devtools_ui.cc
|
| index 1c5f89a5fc2be8a0facf5e4426a2bc00776e6185..34bfa5d9f16aaa615541a7f77a63e11db797dc01 100644
|
| --- a/chrome/browser/ui/webui/devtools_ui.cc
|
| +++ b/chrome/browser/ui/webui/devtools_ui.cc
|
| @@ -4,11 +4,13 @@
|
|
|
| #include "chrome/browser/ui/webui/devtools_ui.h"
|
|
|
| +#include "base/command_line.h"
|
| #include "base/macros.h"
|
| #include "base/memory/ref_counted_memory.h"
|
| #include "base/strings/string_util.h"
|
| #include "base/strings/stringprintf.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| +#include "chrome/common/chrome_switches.h"
|
| #include "chrome/common/url_constants.h"
|
| #include "content/public/browser/browser_thread.h"
|
| #include "content/public/browser/devtools_frontend_host.h"
|
| @@ -16,6 +18,8 @@
|
| #include "content/public/browser/web_contents.h"
|
| #include "content/public/browser/web_ui.h"
|
| #include "content/public/common/user_agent.h"
|
| +#include "net/base/filename_util.h"
|
| +#include "net/base/load_flags.h"
|
| #include "net/url_request/url_fetcher.h"
|
| #include "net/url_request/url_fetcher_delegate.h"
|
| #include "net/url_request/url_request_context_getter.h"
|
| @@ -115,6 +119,13 @@ class DevToolsDataSource : public content::URLDataSource,
|
| int render_frame_id,
|
| const GotDataCallback& callback);
|
|
|
| + // Serves remote DevTools frontend from any endpoint, passed through
|
| + // command-line flag.
|
| + void StartCustomDataRequest(const GURL& url,
|
| + int render_process_id,
|
| + int render_frame_id,
|
| + const GotDataCallback& callback);
|
| +
|
| ~DevToolsDataSource() override;
|
|
|
| scoped_refptr<net::URLRequestContextGetter> request_context_;
|
| @@ -167,6 +178,40 @@ void DevToolsDataSource::StartDataRequest(
|
| return;
|
| }
|
|
|
| + base::FilePath remote_frontend_path =
|
| + base::CommandLine::ForCurrentProcess()->GetSwitchValuePath(
|
| + switches::kRemoteDebuggingFrontend);
|
| +
|
| + if (remote_frontend_path.empty()) {
|
| + callback.Run(NULL);
|
| + return;
|
| + }
|
| +
|
| + // Serve request from custom location.
|
| + std::string custom_path_prefix(chrome::kChromeUIDevToolsCustomPath);
|
| + custom_path_prefix += "/";
|
| +
|
| + // Generated files should be fetched from bundle.
|
| + if (base::StartsWith(path, custom_path_prefix + "gen/",
|
| + base::CompareCase::INSENSITIVE_ASCII)) {
|
| + StartBundledDataRequest(path.substr(custom_path_prefix.length()),
|
| + render_process_id, render_frame_id, callback);
|
| + return;
|
| + }
|
| + if (base::StartsWith(path, custom_path_prefix,
|
| + base::CompareCase::INSENSITIVE_ASCII)) {
|
| + // Create a dummy url to extract path.
|
| + GURL dummy_url =
|
| + GURL("http://example.com/" + path.substr(custom_path_prefix.length()));
|
| + std::string dummy_url_path = dummy_url.path();
|
| + base::FilePath file_path(base::FilePath::StringType(dummy_url_path.begin(),
|
| + dummy_url_path.end()));
|
| + file_path = remote_frontend_path.Append(file_path);
|
| + GURL url = net::FilePathToFileURL(file_path);
|
| + StartCustomDataRequest(url, render_process_id, render_frame_id, callback);
|
| + return;
|
| + }
|
| +
|
| callback.Run(NULL);
|
| }
|
|
|
| @@ -223,6 +268,24 @@ void DevToolsDataSource::StartRemoteDataRequest(
|
| fetcher->Start();
|
| }
|
|
|
| +void DevToolsDataSource::StartCustomDataRequest(
|
| + const GURL& url,
|
| + int render_process_id,
|
| + int render_frame_id,
|
| + const content::URLDataSource::GotDataCallback& callback) {
|
| + if (!url.is_valid()) {
|
| + callback.Run(
|
| + new base::RefCountedStaticMemory(kHttpNotFound, strlen(kHttpNotFound)));
|
| + return;
|
| + }
|
| + net::URLFetcher* fetcher =
|
| + net::URLFetcher::Create(url, net::URLFetcher::GET, this).release();
|
| + pending_[fetcher] = callback;
|
| + fetcher->SetRequestContext(request_context_.get());
|
| + fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE);
|
| + fetcher->Start();
|
| +}
|
| +
|
| void DevToolsDataSource::OnURLFetchComplete(const net::URLFetcher* source) {
|
| DCHECK(source);
|
| PendingRequestsMap::iterator it = pending_.find(source);
|
|
|