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/electron_web_ui_controller_factory.h"
|
2017-01-17 14:23:13 +00:00
|
|
|
|
2024-07-22 09:31:32 +00:00
|
|
|
#include "base/memory/singleton.h"
|
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-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
|
|
|
|
2017-01-17 14:23:13 +00:00
|
|
|
namespace electron {
|
|
|
|
|
|
|
|
// static
|
|
|
|
ElectronWebUIControllerFactory* ElectronWebUIControllerFactory::GetInstance() {
|
|
|
|
return base::Singleton<ElectronWebUIControllerFactory>::get();
|
|
|
|
}
|
|
|
|
|
2019-09-16 22:12:00 +00:00
|
|
|
ElectronWebUIControllerFactory::ElectronWebUIControllerFactory() = default;
|
2017-01-17 14:23:13 +00:00
|
|
|
|
2019-09-16 22:12:00 +00:00
|
|
|
ElectronWebUIControllerFactory::~ElectronWebUIControllerFactory() = default;
|
2017-01-17 14:23:13 +00:00
|
|
|
|
|
|
|
content::WebUI::TypeID ElectronWebUIControllerFactory::GetWebUIType(
|
|
|
|
content::BrowserContext* browser_context,
|
2019-07-03 01:22:09 +00:00
|
|
|
const GURL& url) {
|
2024-08-23 22:15:45 +00:00
|
|
|
if (const std::string_view host = url.host_piece();
|
|
|
|
host == chrome::kChromeUIDevToolsHost ||
|
|
|
|
host == chrome::kChromeUIAccessibilityHost) {
|
2018-10-19 13:50:30 +00:00
|
|
|
return const_cast<ElectronWebUIControllerFactory*>(this);
|
|
|
|
}
|
2017-01-17 14:23:13 +00:00
|
|
|
|
|
|
|
return content::WebUI::kNoWebUI;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ElectronWebUIControllerFactory::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;
|
|
|
|
}
|
|
|
|
|
2018-10-02 19:11:56 +00:00
|
|
|
std::unique_ptr<content::WebUIController>
|
2017-01-17 14:23:13 +00:00
|
|
|
ElectronWebUIControllerFactory::CreateWebUIControllerForURL(
|
|
|
|
content::WebUI* web_ui,
|
2019-07-03 01:22:09 +00:00
|
|
|
const GURL& url) {
|
2024-08-23 22:15:45 +00:00
|
|
|
const std::string_view host = url.host_piece();
|
|
|
|
|
|
|
|
if (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
|
|
|
|
2024-08-23 22:15:45 +00:00
|
|
|
if (host == chrome::kChromeUIAccessibilityHost)
|
|
|
|
return std::make_unique<ElectronAccessibilityUI>(web_ui);
|
|
|
|
|
2018-10-02 19:11:56 +00:00
|
|
|
return std::unique_ptr<content::WebUIController>();
|
2017-01-17 14:23:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace electron
|