chore: don't duplicate devtools constants (#24440)

This commit is contained in:
Shelley Vohr 2020-07-07 14:04:23 -07:00 committed by GitHub
parent 7fd96cd188
commit 446100cdfe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 13 deletions

View file

@ -6,18 +6,13 @@
#include <string> #include <string>
#include "chrome/common/webui_url_constants.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "electron/buildflags/buildflags.h" #include "electron/buildflags/buildflags.h"
#include "shell/browser/ui/devtools_ui.h" #include "shell/browser/ui/devtools_ui.h"
namespace electron { namespace electron {
namespace {
const char kChromeUIDevToolsBundledHost[] = "devtools";
} // namespace
// static // static
ElectronWebUIControllerFactory* ElectronWebUIControllerFactory::GetInstance() { ElectronWebUIControllerFactory* ElectronWebUIControllerFactory::GetInstance() {
return base::Singleton<ElectronWebUIControllerFactory>::get(); return base::Singleton<ElectronWebUIControllerFactory>::get();
@ -30,7 +25,7 @@ ElectronWebUIControllerFactory::~ElectronWebUIControllerFactory() = default;
content::WebUI::TypeID ElectronWebUIControllerFactory::GetWebUIType( content::WebUI::TypeID ElectronWebUIControllerFactory::GetWebUIType(
content::BrowserContext* browser_context, content::BrowserContext* browser_context,
const GURL& url) { const GURL& url) {
if (url.host() == kChromeUIDevToolsBundledHost) { if (url.host() == chrome::kChromeUIDevToolsHost) {
return const_cast<ElectronWebUIControllerFactory*>(this); return const_cast<ElectronWebUIControllerFactory*>(this);
} }
@ -53,7 +48,7 @@ std::unique_ptr<content::WebUIController>
ElectronWebUIControllerFactory::CreateWebUIControllerForURL( ElectronWebUIControllerFactory::CreateWebUIControllerForURL(
content::WebUI* web_ui, content::WebUI* web_ui,
const GURL& url) { const GURL& url) {
if (url.host() == kChromeUIDevToolsBundledHost) { if (url.host() == chrome::kChromeUIDevToolsHost) {
auto* browser_context = web_ui->GetWebContents()->GetBrowserContext(); auto* browser_context = web_ui->GetWebContents()->GetBrowserContext();
return std::make_unique<DevToolsUI>(browser_context, web_ui); return std::make_unique<DevToolsUI>(browser_context, web_ui);
} }

View file

@ -11,6 +11,7 @@
#include "base/memory/ref_counted_memory.h" #include "base/memory/ref_counted_memory.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "chrome/common/webui_url_constants.h"
#include "content/public/browser/devtools_frontend_host.h" #include "content/public/browser/devtools_frontend_host.h"
#include "content/public/browser/url_data_source.h" #include "content/public/browser/url_data_source.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
@ -20,9 +21,6 @@ namespace electron {
namespace { namespace {
const char kChromeUIDevToolsHost[] = "devtools";
const char kChromeUIDevToolsBundledPath[] = "bundled";
std::string PathWithoutParams(const std::string& path) { std::string PathWithoutParams(const std::string& path) {
return GURL(std::string("devtools://devtools/") + path).path().substr(1); return GURL(std::string("devtools://devtools/") + path).path().substr(1);
} }
@ -59,14 +57,14 @@ class BundledDataSource : public content::URLDataSource {
~BundledDataSource() override = default; ~BundledDataSource() override = default;
// content::URLDataSource implementation. // content::URLDataSource implementation.
std::string GetSource() override { return kChromeUIDevToolsHost; } std::string GetSource() override { return chrome::kChromeUIDevToolsHost; }
void StartDataRequest(const GURL& url, void StartDataRequest(const GURL& url,
const content::WebContents::Getter& wc_getter, const content::WebContents::Getter& wc_getter,
GotDataCallback callback) override { GotDataCallback callback) override {
const std::string path = content::URLDataSource::URLToRequestPath(url); const std::string path = content::URLDataSource::URLToRequestPath(url);
// Serve request from local bundle. // Serve request from local bundle.
std::string bundled_path_prefix(kChromeUIDevToolsBundledPath); std::string bundled_path_prefix(chrome::kChromeUIDevToolsBundledPath);
bundled_path_prefix += "/"; bundled_path_prefix += "/";
if (base::StartsWith(path, bundled_path_prefix, if (base::StartsWith(path, bundled_path_prefix,
base::CompareCase::INSENSITIVE_ASCII)) { base::CompareCase::INSENSITIVE_ASCII)) {