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/browser | |
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/browser')
-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 |
4 files changed, 84 insertions, 7 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); |