summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/webui
diff options
context:
space:
mode:
authorpfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-03 12:06:06 +0000
committerpfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-03 12:06:06 +0000
commit30c58691961266c918daaf10f2b867b27691dd89 (patch)
treefdd7651e9dffc79221c365a284a4d8bc40b7a1d9 /chrome/browser/ui/webui
parent2a59ebeb4f6684eda0cbdf9183cb9fce7b32247c (diff)
downloadchromium_src-30c58691961266c918daaf10f2b867b27691dd89.zip
chromium_src-30c58691961266c918daaf10f2b867b27691dd89.tar.gz
chromium_src-30c58691961266c918daaf10f2b867b27691dd89.tar.bz2
DevTools: open remote front-ends using chrome-devtools://remote/* urls.
BUG=13392008 TBR=brettw (for oneliners outside webui) This change splits chrome-devtools:// handler into the one serving chrome-devtools://devtools (for embedded) and chrome-devtools://remote (for remote) front-ends. It also remove command line check for remote/ path. Drive-by: move url constants from content/ to chrome/, remove legacy data source registration. Review URL: https://codereview.chromium.org/13465007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@192052 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui/webui')
-rw-r--r--chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc2
-rw-r--r--chrome/browser/ui/webui/devtools_ui.cc168
-rw-r--r--chrome/browser/ui/webui/devtools_ui.h1
-rw-r--r--chrome/browser/ui/webui/inspect_ui.cc9
4 files changed, 89 insertions, 91 deletions
diff --git a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc
index 2dfcdcb..40a1b99 100644
--- a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc
+++ b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc
@@ -259,7 +259,7 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
// Bookmarks are part of NTP on Android.
if (url.host() == chrome::kChromeUIBookmarksHost)
return &NewWebUI<BookmarksUI>;
- if (url.host() == chrome::kChromeUIDevToolsHost)
+ if (url.SchemeIs(chrome::kChromeDevToolsScheme))
return &NewWebUI<DevToolsUI>;
// Downloads list on Android uses the built-in download manager.
if (url.host() == chrome::kChromeUIDownloadsHost)
diff --git a/chrome/browser/ui/webui/devtools_ui.cc b/chrome/browser/ui/webui/devtools_ui.cc
index 7229094..92dd673 100644
--- a/chrome/browser/ui/webui/devtools_ui.cc
+++ b/chrome/browser/ui/webui/devtools_ui.cc
@@ -6,14 +6,12 @@
#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"
@@ -35,8 +33,8 @@ std::string PathWithoutParams(const std::string& path) {
.path().substr(1);
}
-const char kHostedFrontendDomain[] = "chrome-devtools-frontend.appspot.com";
-const char kHostedFrontendBase[] =
+const char kRemoteFrontendDomain[] = "chrome-devtools-frontend.appspot.com";
+const char kRemoteFrontendBase[] =
"https://chrome-devtools-frontend.appspot.com/";
const char kHttpNotFound[] = "HTTP/1.1 404 Not Found\n\n";
@@ -46,10 +44,7 @@ class FetchRequest : public net::URLFetcherDelegate {
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()) {
+ if (!url.is_valid()) {
OnURLFetchComplete(NULL);
return;
}
@@ -77,105 +72,111 @@ class FetchRequest : public net::URLFetcherDelegate {
content::URLDataSource::GotDataCallback callback_;
};
-} // namespace
+std::string GetMimeTypeForPath(const std::string& path) {
+ std::string filename = PathWithoutParams(path);
+ if (EndsWith(filename, ".html", false)) {
+ return "text/html";
+ } else if (EndsWith(filename, ".css", false)) {
+ return "text/css";
+ } else if (EndsWith(filename, ".js", false)) {
+ return "application/javascript";
+ } else if (EndsWith(filename, ".png", false)) {
+ 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";
+}
-class DevToolsDataSource : public content::URLDataSource {
+class BundledDataSource : public content::URLDataSource {
public:
- explicit DevToolsDataSource(net::URLRequestContextGetter* request_context);
+ explicit BundledDataSource() {
+ }
// content::URLDataSource implementation.
- virtual std::string GetSource() OVERRIDE;
+ virtual std::string GetSource() OVERRIDE {
+ return chrome::kChromeUIDevToolsBundledHost;
+ }
+
virtual void StartDataRequest(
const std::string& path,
bool is_incognito,
- const content::URLDataSource::GotDataCallback& callback) OVERRIDE;
- virtual std::string GetMimeType(const std::string& path) const OVERRIDE;
- virtual bool ShouldAddContentSecurityPolicy() const OVERRIDE;
+ const content::URLDataSource::GotDataCallback& callback) OVERRIDE {
+ std::string filename = PathWithoutParams(path);
+
+ int resource_id =
+ content::DevToolsHttpHandler::GetFrontendResourceId(filename);
+
+ DLOG_IF(WARNING, -1 == resource_id) << "Unable to find dev tool resource: "
+ << filename << ". If you compiled with debug_devtools=1, try running"
+ " with --debug-devtools.";
+ const ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ scoped_refptr<base::RefCountedStaticMemory> bytes(rb.LoadDataResourceBytes(
+ resource_id));
+ callback.Run(bytes);
+ }
+
+ virtual std::string GetMimeType(const std::string& path) const OVERRIDE {
+ return GetMimeTypeForPath(path);
+ }
+
+ virtual bool ShouldAddContentSecurityPolicy() const OVERRIDE {
+ return false;
+ }
private:
- virtual ~DevToolsDataSource() {}
- scoped_refptr<net::URLRequestContextGetter> request_context_;
- DISALLOW_COPY_AND_ASSIGN(DevToolsDataSource);
+ virtual ~BundledDataSource() {}
+ DISALLOW_COPY_AND_ASSIGN(BundledDataSource);
};
+class RemoteDataSource : public content::URLDataSource {
+ public:
+ explicit RemoteDataSource(net::URLRequestContextGetter*
+ request_context) : request_context_(request_context) {
+ }
-DevToolsDataSource::DevToolsDataSource(
- net::URLRequestContextGetter* request_context)
- : request_context_(request_context) {
-}
-
-std::string DevToolsDataSource::GetSource() {
- return chrome::kChromeUIDevToolsHost;
-}
+ // content::URLDataSource implementation.
+ virtual std::string GetSource() OVERRIDE {
+ return chrome::kChromeUIDevToolsRemoteHost;
+ }
-void DevToolsDataSource::StartDataRequest(
- const std::string& path,
- bool is_incognito,
- const content::URLDataSource::GotDataCallback& callback) {
- std::string filename = PathWithoutParams(path);
+ virtual void StartDataRequest(
+ const std::string& path,
+ bool is_incognito,
+ const content::URLDataSource::GotDataCallback& callback) OVERRIDE {
- if (filename.find(chrome::kChromeUIDevToolsHostedPath) == 0) {
- GURL url = GURL(kHostedFrontendBase +
- filename.substr(strlen(chrome::kChromeUIDevToolsHostedPath)));
- CHECK(url.host() == kHostedFrontendDomain);
+ GURL url = GURL(kRemoteFrontendBase + path);
+ CHECK_EQ(url.host(), kRemoteFrontendDomain);
new FetchRequest(request_context_, url, callback);
- return;
}
- int resource_id =
- content::DevToolsHttpHandler::GetFrontendResourceId(filename);
-
- DLOG_IF(WARNING, -1 == resource_id) << "Unable to find dev tool resource: "
- << filename << ". If you compiled with debug_devtools=1, try running"
- " with --debug-devtools.";
- const ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- scoped_refptr<base::RefCountedStaticMemory> bytes(rb.LoadDataResourceBytes(
- resource_id));
- callback.Run(bytes);
-}
+ virtual std::string GetMimeType(const std::string& path) const OVERRIDE {
+ return GetMimeTypeForPath(path);
+ }
-std::string DevToolsDataSource::GetMimeType(const std::string& path) const {
- std::string filename = PathWithoutParams(path);
- if (EndsWith(filename, ".html", false)) {
- return "text/html";
- } else if (EndsWith(filename, ".css", false)) {
- return "text/css";
- } else if (EndsWith(filename, ".js", false)) {
- return "application/javascript";
- } else if (EndsWith(filename, ".png", false)) {
- return "image/png";
- } else if (EndsWith(filename, ".gif", false)) {
- return "image/gif";
- } else if (EndsWith(filename, ".manifest", false)) {
- return "text/cache-manifest";
+ virtual bool ShouldAddContentSecurityPolicy() const OVERRIDE {
+ return false;
}
- NOTREACHED();
- return "text/plain";
-}
-bool DevToolsDataSource::ShouldAddContentSecurityPolicy() const {
- return false;
-}
+ private:
+ virtual ~RemoteDataSource() {}
+ scoped_refptr<net::URLRequestContextGetter> request_context_;
-// static
-void DevToolsUI::RegisterDevToolsDataSource(Profile* profile) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- static bool registered = false;
- if (!registered) {
- content::URLDataSource::Add(profile, new DevToolsDataSource(
- profile->GetRequestContext()));
- registered = true;
- }
-}
+ DISALLOW_COPY_AND_ASSIGN(RemoteDataSource);
+};
+
+} // namespace
// 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,
+ CHECK_EQ(url.host(), kRemoteFrontendDomain);
+ return GURL(base::StringPrintf("%s://%s/%s", chrome::kChromeDevToolsScheme,
+ chrome::kChromeUIDevToolsRemoteHost,
url.path().substr(1).c_str()));
}
@@ -184,5 +185,8 @@ DevToolsUI::DevToolsUI(content::WebUI* web_ui) : WebUIController(web_ui) {
Profile* profile = Profile::FromWebUI(web_ui);
content::URLDataSource::Add(
profile,
- new DevToolsDataSource(profile->GetRequestContext()));
+ new BundledDataSource());
+ content::URLDataSource::Add(
+ profile,
+ new RemoteDataSource(profile->GetRequestContext()));
}
diff --git a/chrome/browser/ui/webui/devtools_ui.h b/chrome/browser/ui/webui/devtools_ui.h
index 9f67050..9c4e2b6 100644
--- a/chrome/browser/ui/webui/devtools_ui.h
+++ b/chrome/browser/ui/webui/devtools_ui.h
@@ -12,7 +12,6 @@ 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/browser/ui/webui/inspect_ui.cc b/chrome/browser/ui/webui/inspect_ui.cc
index 4c59921..b0b67c3 100644
--- a/chrome/browser/ui/webui/inspect_ui.cc
+++ b/chrome/browser/ui/webui/inspect_ui.cc
@@ -8,7 +8,6 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
-#include "base/command_line.h"
#include "base/json/json_writer.h"
#include "base/memory/ref_counted_memory.h"
#include "base/string_util.h"
@@ -19,7 +18,6 @@
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/tab_contents/tab_contents_iterator.h"
-#include "chrome/common/chrome_switches.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_data.h"
@@ -429,11 +427,8 @@ bool InspectUI::HandleRequestCallback(
const content::WebUIDataSource::GotDataCallback& callback) {
if (path == kDataFile)
return HandleDataRequestCallback(path, callback);
- if (path.find(kAdbPages) == 0) {
- const CommandLine& command_line = *CommandLine::ForCurrentProcess();
- if (command_line.HasSwitch(switches::kEnableHostedDevToolsFrontend))
- return HandleAdbPagesCallback(path, callback);
- }
+ if (path.find(kAdbPages) == 0)
+ return HandleAdbPagesCallback(path, callback);
return false;
}