Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(540)

Unified Diff: chrome/browser/ui/webui/devtools_ui.cc

Issue 2458033003: DevTools: introduce --custom-devtools-frontend flag. (Closed)
Patch Set: address comments Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/devtools/frontend/devtools_discovery_page.html ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ed6c43c7640d5dbe0c9164b805ad1e05cb30c49d..a6611b5e1c0703333b696e278c368dcdb48b929a 100644
--- a/chrome/browser/ui/webui/devtools_ui.cc
+++ b/chrome/browser/ui/webui/devtools_ui.cc
@@ -4,12 +4,14 @@
#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_split.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"
@@ -18,6 +20,8 @@
#include "content/public/browser/web_ui.h"
#include "content/public/common/user_agent.h"
#include "net/base/escape.h"
+#include "net/base/filename_util.h"
+#include "net/base/load_flags.h"
#include "net/base/url_util.h"
#include "net/url_request/url_fetcher.h"
#include "net/url_request/url_fetcher_delegate.h"
@@ -237,6 +241,11 @@ class DevToolsDataSource : public content::URLDataSource,
void StartRemoteDataRequest(const std::string& path,
const GotDataCallback& callback);
+ // Serves remote DevTools frontend from any endpoint, passed through
+ // command-line flag.
+ void StartCustomDataRequest(const GURL& url,
+ const GotDataCallback& callback);
+
~DevToolsDataSource() override;
scoped_refptr<net::URLRequestContextGetter> request_context_;
@@ -288,6 +297,27 @@ void DevToolsDataSource::StartDataRequest(
return;
}
+ std::string custom_frontend_url =
+ base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+ switches::kCustomDevtoolsFrontend);
+
+ if (custom_frontend_url.empty()) {
+ callback.Run(NULL);
+ return;
+ }
+
+ // Serve request from custom location.
+ 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()));
+ StartCustomDataRequest(url, callback);
+ return;
+ }
+
callback.Run(NULL);
}
@@ -340,6 +370,22 @@ void DevToolsDataSource::StartRemoteDataRequest(
fetcher->Start();
}
+void DevToolsDataSource::StartCustomDataRequest(
+ const GURL& url,
+ 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);
« no previous file with comments | « chrome/browser/devtools/frontend/devtools_discovery_page.html ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698