diff options
author | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-02 07:46:05 +0000 |
---|---|---|
committer | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-02 07:46:05 +0000 |
commit | aac8bcdc3e4309db08d9edcc86adac9432c227eb (patch) | |
tree | 1e35f5b7eda2e972b943dcd13bf273ce3b518986 /chrome | |
parent | 0f440df043a5bfec369aaebbce4c0d4d41094efa (diff) | |
download | chromium_src-aac8bcdc3e4309db08d9edcc86adac9432c227eb.zip chromium_src-aac8bcdc3e4309db08d9edcc86adac9432c227eb.tar.gz chromium_src-aac8bcdc3e4309db08d9edcc86adac9432c227eb.tar.bz2 |
DevTools: allow devtools to load front-end off remote host.
BUG=225362
TBR=mmenke (for profile_io_data one liner)
Review URL: https://codereview.chromium.org/13392008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@191797 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/devtools/devtools_window.cc | 2 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_io_data.cc | 3 | ||||
-rw-r--r-- | chrome/browser/ui/webui/devtools_ui.cc | 85 | ||||
-rw-r--r-- | chrome/browser/ui/webui/devtools_ui.h | 1 | ||||
-rw-r--r-- | chrome/common/chrome_switches.cc | 3 | ||||
-rw-r--r-- | chrome/common/chrome_switches.h | 1 | ||||
-rw-r--r-- | chrome/common/url_constants.cc | 3 | ||||
-rw-r--r-- | chrome/common/url_constants.h | 1 |
8 files changed, 91 insertions, 8 deletions
diff --git a/chrome/browser/devtools/devtools_window.cc b/chrome/browser/devtools/devtools_window.cc index 63620b0..15cafe7 100644 --- a/chrome/browser/devtools/devtools_window.cc +++ b/chrome/browser/devtools/devtools_window.cc @@ -640,7 +640,7 @@ GURL DevToolsWindow::GetDevToolsUrl(Profile* profile, bool experiments_enabled = command_line.HasSwitch(switches::kEnableDevToolsExperiments); - std::string url_string = base::StringPrintf("%sdevtools.html?" + std::string url_string = base::StringPrintf("%s?" "dockSide=%s&toolbarColor=%s&textColor=%s%s%s", chrome::kChromeUIDevToolsURL, SideToString(dock_side).c_str(), diff --git a/chrome/browser/profiles/profile_io_data.cc b/chrome/browser/profiles/profile_io_data.cc index 35f0a2f..2cbc148 100644 --- a/chrome/browser/profiles/profile_io_data.cc +++ b/chrome/browser/profiles/profile_io_data.cc @@ -146,7 +146,8 @@ Profile* GetProfileOnUI(ProfileManager* profile_manager, Profile* profile) { #if defined(DEBUG_DEVTOOLS) bool IsSupportedDevToolsURL(const GURL& url, base::FilePath* path) { if (!url.SchemeIs(chrome::kChromeDevToolsScheme) || - url.host() != chrome::kChromeUIDevToolsHost) { + url.host() != chrome::kChromeUIDevToolsHost || + url.path().find(chrome::kChromeUIDevToolsHostedPath) == 1) { return false; } diff --git a/chrome/browser/ui/webui/devtools_ui.cc b/chrome/browser/ui/webui/devtools_ui.cc index bce9c48..7229094 100644 --- a/chrome/browser/ui/webui/devtools_ui.cc +++ b/chrome/browser/ui/webui/devtools_ui.cc @@ -6,17 +6,23 @@ #include <string> +#include "base/command_line.h" #include "base/memory/ref_counted_memory.h" #include "base/memory/scoped_ptr.h" #include "base/string_util.h" +#include "base/stringprintf.h" #include "chrome/browser/net/chrome_url_request_context.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_http_handler.h" #include "content/public/browser/url_data_source.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_ui.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" #include "ui/base/resource/resource_bundle.h" using content::BrowserThread; @@ -29,11 +35,53 @@ std::string PathWithoutParams(const std::string& path) { .path().substr(1); } +const char kHostedFrontendDomain[] = "chrome-devtools-frontend.appspot.com"; +const char kHostedFrontendBase[] = + "https://chrome-devtools-frontend.appspot.com/"; +const char kHttpNotFound[] = "HTTP/1.1 404 Not Found\n\n"; + +class FetchRequest : public net::URLFetcherDelegate { + public: + FetchRequest(net::URLRequestContextGetter* request_context, + const GURL& url, + const content::URLDataSource::GotDataCallback& callback) + : callback_(callback) { + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + bool hosted_frontend = + command_line.HasSwitch(switches::kEnableHostedDevToolsFrontend); + if (!hosted_frontend || !url.is_valid()) { + OnURLFetchComplete(NULL); + return; + } + + fetcher_.reset(net::URLFetcher::Create(url, net::URLFetcher::GET, this)); + fetcher_->SetRequestContext(request_context); + fetcher_->Start(); + } + + private: + virtual ~FetchRequest() {} + + virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE { + std::string response; + if (source) + source->GetResponseAsString(&response); + else + response = kHttpNotFound; + + callback_.Run(base::RefCountedString::TakeString(&response)); + delete this; + } + + scoped_ptr<net::URLFetcher> fetcher_; + content::URLDataSource::GotDataCallback callback_; +}; + } // namespace class DevToolsDataSource : public content::URLDataSource { public: - DevToolsDataSource(); + explicit DevToolsDataSource(net::URLRequestContextGetter* request_context); // content::URLDataSource implementation. virtual std::string GetSource() OVERRIDE; @@ -46,11 +94,14 @@ class DevToolsDataSource : public content::URLDataSource { private: virtual ~DevToolsDataSource() {} + scoped_refptr<net::URLRequestContextGetter> request_context_; DISALLOW_COPY_AND_ASSIGN(DevToolsDataSource); }; -DevToolsDataSource::DevToolsDataSource() { +DevToolsDataSource::DevToolsDataSource( + net::URLRequestContextGetter* request_context) + : request_context_(request_context) { } std::string DevToolsDataSource::GetSource() { @@ -63,6 +114,14 @@ void DevToolsDataSource::StartDataRequest( const content::URLDataSource::GotDataCallback& callback) { std::string filename = PathWithoutParams(path); + if (filename.find(chrome::kChromeUIDevToolsHostedPath) == 0) { + GURL url = GURL(kHostedFrontendBase + + filename.substr(strlen(chrome::kChromeUIDevToolsHostedPath))); + CHECK(url.host() == kHostedFrontendDomain); + new FetchRequest(request_context_, url, callback); + return; + } + int resource_id = content::DevToolsHttpHandler::GetFrontendResourceId(filename); @@ -87,6 +146,8 @@ std::string DevToolsDataSource::GetMimeType(const std::string& path) const { return "image/png"; } else if (EndsWith(filename, ".gif", false)) { return "image/gif"; + } else if (EndsWith(filename, ".manifest", false)) { + return "text/cache-manifest"; } NOTREACHED(); return "text/plain"; @@ -101,13 +162,27 @@ void DevToolsUI::RegisterDevToolsDataSource(Profile* profile) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); static bool registered = false; if (!registered) { - content::URLDataSource::Add(profile, new DevToolsDataSource); + content::URLDataSource::Add(profile, new DevToolsDataSource( + profile->GetRequestContext())); registered = true; } } +// static +GURL DevToolsUI::GetProxyURL(const std::string& frontend_url) { + GURL url(frontend_url); + CHECK(url.is_valid()); + CHECK_EQ(url.host(), kHostedFrontendDomain); + return GURL(base::StringPrintf("%s://%s/%s%s", chrome::kChromeDevToolsScheme, + chrome::kChromeUIDevToolsHost, + chrome::kChromeUIDevToolsHostedPath, + url.path().substr(1).c_str())); +} + DevToolsUI::DevToolsUI(content::WebUI* web_ui) : WebUIController(web_ui) { web_ui->SetBindings(0); - content::URLDataSource::Add(Profile::FromWebUI(web_ui), - new DevToolsDataSource); + Profile* profile = Profile::FromWebUI(web_ui); + content::URLDataSource::Add( + profile, + new DevToolsDataSource(profile->GetRequestContext())); } diff --git a/chrome/browser/ui/webui/devtools_ui.h b/chrome/browser/ui/webui/devtools_ui.h index 777d142..9f67050 100644 --- a/chrome/browser/ui/webui/devtools_ui.h +++ b/chrome/browser/ui/webui/devtools_ui.h @@ -13,6 +13,7 @@ class Profile; class DevToolsUI : public content::WebUIController { public: static void RegisterDevToolsDataSource(Profile* profile); + static GURL GetProxyURL(const std::string& frontend_url); explicit DevToolsUI(content::WebUI* web_ui); diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index d3ec727..fe58994 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -495,6 +495,9 @@ const char kEnableDesktopGuestMode[] = "enable-desktop-guest-mode"; // If true devtools experimental settings are enabled. const char kEnableDevToolsExperiments[] = "enable-devtools-experiments"; +// If true devtools is allowed to load hosted front-ends. +const char kEnableHostedDevToolsFrontend[] = "enable-hosted-devtools-frontend"; + // Enables an interactive autocomplete UI and a way to invoke this UI from // WebKit by enabling HTMLFormElement#requestAutocomplete (and associated // autocomplete* events and logic). diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index 312d380..cb15a1b 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -154,6 +154,7 @@ extern const char kEnableExtensionActivityLogTesting[]; extern const char kEnableExtensionActivityUI[]; extern const char kEnableFileCookies[]; extern const char kEnableGoogleNowIntegration[]; +extern const char kEnableHostedDevToolsFrontend[]; extern const char kEnableInstantExtendedAPI[]; extern const char kEnableInteractiveAutocomplete[]; extern const char kEnableIPCFuzzing[]; diff --git a/chrome/common/url_constants.cc b/chrome/common/url_constants.cc index eb317e8..f7b9e85 100644 --- a/chrome/common/url_constants.cc +++ b/chrome/common/url_constants.cc @@ -29,7 +29,7 @@ const char kChromeUIConflictsURL[] = "chrome://conflicts/"; const char kChromeUIConstrainedHTMLTestURL[] = "chrome://constrained-test/"; const char kChromeUICrashesURL[] = "chrome://crashes/"; const char kChromeUICreditsURL[] = "chrome://credits/"; -const char kChromeUIDevToolsURL[] = "chrome-devtools://devtools/"; +const char kChromeUIDevToolsURL[] = "chrome-devtools://devtools/devtools.html"; const char kChromeUIDownloadsURL[] = "chrome://downloads/"; const char kChromeUIEditSearchEngineDialogURL[] = "chrome://editsearchengine/"; const char kChromeUIExtensionActivityURL[] = "chrome://extension-activity/"; @@ -209,6 +209,7 @@ const char kChromeUIUserActionsHost[] = "user-actions"; const char kChromeUIVersionHost[] = "version"; const char kChromeUIWorkersHost[] = "workers"; +const char kChromeUIDevToolsHostedPath[] = "hosted/"; const char kChromeUIScreenshotPath[] = "screenshots"; const char kChromeUIThemePath[] = "theme"; diff --git a/chrome/common/url_constants.h b/chrome/common/url_constants.h index 1edb1bae..5e49877 100644 --- a/chrome/common/url_constants.h +++ b/chrome/common/url_constants.h @@ -201,6 +201,7 @@ extern const char kChromeUIUserActionsHost[]; extern const char kChromeUIVersionHost[]; extern const char kChromeUIWorkersHost[]; +extern const char kChromeUIDevToolsHostedPath[]; extern const char kChromeUIScreenshotPath[]; extern const char kChromeUIThemePath[]; |