2017-01-17 14:23:13 +00:00
|
|
|
// Copyright (c) 2017 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/atom_web_ui_controller_factory.h"
|
2017-01-17 14:23:13 +00:00
|
|
|
|
2017-01-18 17:53:54 +00:00
|
|
|
#include <string>
|
|
|
|
|
2018-10-19 13:50:30 +00:00
|
|
|
#include "content/public/browser/web_contents.h"
|
2019-11-04 17:50:31 +00:00
|
|
|
#include "electron/buildflags/buildflags.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/ui/devtools_ui.h"
|
2018-10-19 13:50:30 +00:00
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2017-01-17 14:23:13 +00:00
|
|
|
|
2018-10-19 13:50:30 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
const char kChromeUIDevToolsBundledHost[] = "devtools";
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2017-01-17 14:23:13 +00:00
|
|
|
// static
|
|
|
|
AtomWebUIControllerFactory* AtomWebUIControllerFactory::GetInstance() {
|
|
|
|
return base::Singleton<AtomWebUIControllerFactory>::get();
|
|
|
|
}
|
|
|
|
|
2019-09-16 22:12:00 +00:00
|
|
|
AtomWebUIControllerFactory::AtomWebUIControllerFactory() = default;
|
2017-01-17 14:23:13 +00:00
|
|
|
|
2019-09-16 22:12:00 +00:00
|
|
|
AtomWebUIControllerFactory::~AtomWebUIControllerFactory() = default;
|
2017-01-17 14:23:13 +00:00
|
|
|
|
|
|
|
content::WebUI::TypeID AtomWebUIControllerFactory::GetWebUIType(
|
|
|
|
content::BrowserContext* browser_context,
|
2019-07-03 01:22:09 +00:00
|
|
|
const GURL& url) {
|
2018-10-19 13:50:30 +00:00
|
|
|
if (url.host() == kChromeUIDevToolsBundledHost) {
|
|
|
|
return const_cast<AtomWebUIControllerFactory*>(this);
|
|
|
|
}
|
2017-01-17 14:23:13 +00:00
|
|
|
|
|
|
|
return content::WebUI::kNoWebUI;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AtomWebUIControllerFactory::UseWebUIForURL(
|
|
|
|
content::BrowserContext* browser_context,
|
2019-07-03 01:22:09 +00:00
|
|
|
const GURL& url) {
|
2017-01-17 14:23:13 +00:00
|
|
|
return GetWebUIType(browser_context, url) != content::WebUI::kNoWebUI;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AtomWebUIControllerFactory::UseWebUIBindingsForURL(
|
|
|
|
content::BrowserContext* browser_context,
|
2019-07-03 01:22:09 +00:00
|
|
|
const GURL& url) {
|
2017-01-17 14:23:13 +00:00
|
|
|
return UseWebUIForURL(browser_context, url);
|
|
|
|
}
|
|
|
|
|
2018-10-02 19:11:56 +00:00
|
|
|
std::unique_ptr<content::WebUIController>
|
2017-01-17 14:23:13 +00:00
|
|
|
AtomWebUIControllerFactory::CreateWebUIControllerForURL(content::WebUI* web_ui,
|
2019-07-03 01:22:09 +00:00
|
|
|
const GURL& url) {
|
2018-10-19 13:50:30 +00:00
|
|
|
if (url.host() == kChromeUIDevToolsBundledHost) {
|
|
|
|
auto* browser_context = web_ui->GetWebContents()->GetBrowserContext();
|
|
|
|
return std::make_unique<DevToolsUI>(browser_context, web_ui);
|
|
|
|
}
|
2018-10-02 19:11:56 +00:00
|
|
|
return std::unique_ptr<content::WebUIController>();
|
2017-01-17 14:23:13 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|