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.
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
#include "shell/browser/electron_web_ui_controller_factory.h"
|
2017-01-17 14:23:13 +00:00
|
|
|
|
2020-07-07 21:04:23 +00:00
|
|
|
#include "chrome/common/webui_url_constants.h"
|
2018-10-19 13:50:30 +00:00
|
|
|
#include "content/public/browser/web_contents.h"
|
2021-07-02 00:51:37 +00:00
|
|
|
#include "content/public/browser/web_ui_controller.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"
|
2020-07-16 17:14:54 +00:00
|
|
|
#include "shell/browser/ui/webui/accessibility_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
|
|
|
|
|
|
|
// static
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronWebUIControllerFactory* ElectronWebUIControllerFactory::GetInstance() {
|
|
|
|
return base::Singleton<ElectronWebUIControllerFactory>::get();
|
2017-01-17 14:23:13 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronWebUIControllerFactory::ElectronWebUIControllerFactory() = default;
|
2017-01-17 14:23:13 +00:00
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronWebUIControllerFactory::~ElectronWebUIControllerFactory() = default;
|
2017-01-17 14:23:13 +00:00
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
content::WebUI::TypeID ElectronWebUIControllerFactory::GetWebUIType(
|
2017-01-17 14:23:13 +00:00
|
|
|
content::BrowserContext* browser_context,
|
2019-07-03 01:22:09 +00:00
|
|
|
const GURL& url) {
|
2020-07-16 17:14:54 +00:00
|
|
|
if (url.host() == chrome::kChromeUIDevToolsHost ||
|
|
|
|
url.host() == chrome::kChromeUIAccessibilityHost) {
|
2020-02-04 20:19:40 +00:00
|
|
|
return const_cast<ElectronWebUIControllerFactory*>(this);
|
2018-10-19 13:50:30 +00:00
|
|
|
}
|
2017-01-17 14:23:13 +00:00
|
|
|
|
|
|
|
return content::WebUI::kNoWebUI;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
bool ElectronWebUIControllerFactory::UseWebUIForURL(
|
2017-01-17 14:23:13 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-10-02 19:11:56 +00:00
|
|
|
std::unique_ptr<content::WebUIController>
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronWebUIControllerFactory::CreateWebUIControllerForURL(
|
|
|
|
content::WebUI* web_ui,
|
|
|
|
const GURL& url) {
|
2020-07-07 21:04:23 +00:00
|
|
|
if (url.host() == chrome::kChromeUIDevToolsHost) {
|
2018-10-19 13:50:30 +00:00
|
|
|
auto* browser_context = web_ui->GetWebContents()->GetBrowserContext();
|
|
|
|
return std::make_unique<DevToolsUI>(browser_context, web_ui);
|
2020-07-16 17:14:54 +00:00
|
|
|
} else if (url.host() == chrome::kChromeUIAccessibilityHost) {
|
|
|
|
return std::make_unique<ElectronAccessibilityUI>(web_ui);
|
2018-10-19 13:50:30 +00:00
|
|
|
}
|
2020-07-16 17:14:54 +00:00
|
|
|
|
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
|