2017-01-17 19:53:13 +05:30
|
|
|
// 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 13:46:59 -07:00
|
|
|
#include "shell/browser/electron_web_ui_controller_factory.h"
|
2017-01-17 19:53:13 +05:30
|
|
|
|
2024-07-22 04:31:32 -05:00
|
|
|
#include "base/memory/singleton.h"
|
2020-07-07 14:04:23 -07:00
|
|
|
#include "chrome/common/webui_url_constants.h"
|
2018-10-19 15:50:30 +02:00
|
|
|
#include "content/public/browser/web_contents.h"
|
2021-07-01 17:51:37 -07:00
|
|
|
#include "content/public/browser/web_ui_controller.h"
|
2019-06-19 13:46:59 -07:00
|
|
|
#include "shell/browser/ui/devtools_ui.h"
|
2020-07-16 10:14:54 -07:00
|
|
|
#include "shell/browser/ui/webui/accessibility_ui.h"
|
2018-10-19 15:50:30 +02:00
|
|
|
|
2017-01-17 19:53:13 +05:30
|
|
|
namespace electron {
|
|
|
|
|
|
|
|
// static
|
|
|
|
ElectronWebUIControllerFactory* ElectronWebUIControllerFactory::GetInstance() {
|
|
|
|
return base::Singleton<ElectronWebUIControllerFactory>::get();
|
|
|
|
}
|
|
|
|
|
2019-09-16 18:12:00 -04:00
|
|
|
ElectronWebUIControllerFactory::ElectronWebUIControllerFactory() = default;
|
2017-01-17 19:53:13 +05:30
|
|
|
|
2019-09-16 18:12:00 -04:00
|
|
|
ElectronWebUIControllerFactory::~ElectronWebUIControllerFactory() = default;
|
2017-01-17 19:53:13 +05:30
|
|
|
|
|
|
|
content::WebUI::TypeID ElectronWebUIControllerFactory::GetWebUIType(
|
|
|
|
content::BrowserContext* browser_context,
|
2019-07-02 18:22:09 -07:00
|
|
|
const GURL& url) {
|
2024-08-23 17:15:45 -05:00
|
|
|
if (const std::string_view host = url.host_piece();
|
|
|
|
host == chrome::kChromeUIDevToolsHost ||
|
|
|
|
host == chrome::kChromeUIAccessibilityHost) {
|
2018-10-19 15:50:30 +02:00
|
|
|
return const_cast<ElectronWebUIControllerFactory*>(this);
|
|
|
|
}
|
2017-01-17 19:53:13 +05:30
|
|
|
|
|
|
|
return content::WebUI::kNoWebUI;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ElectronWebUIControllerFactory::UseWebUIForURL(
|
|
|
|
content::BrowserContext* browser_context,
|
2019-07-02 18:22:09 -07:00
|
|
|
const GURL& url) {
|
2017-01-17 19:53:13 +05:30
|
|
|
return GetWebUIType(browser_context, url) != content::WebUI::kNoWebUI;
|
|
|
|
}
|
|
|
|
|
2018-10-02 12:11:56 -07:00
|
|
|
std::unique_ptr<content::WebUIController>
|
2017-01-17 19:53:13 +05:30
|
|
|
ElectronWebUIControllerFactory::CreateWebUIControllerForURL(
|
|
|
|
content::WebUI* web_ui,
|
2019-07-02 18:22:09 -07:00
|
|
|
const GURL& url) {
|
2024-08-23 17:15:45 -05:00
|
|
|
const std::string_view host = url.host_piece();
|
|
|
|
|
|
|
|
if (host == chrome::kChromeUIDevToolsHost) {
|
2018-10-19 15:50:30 +02:00
|
|
|
auto* browser_context = web_ui->GetWebContents()->GetBrowserContext();
|
|
|
|
return std::make_unique<DevToolsUI>(browser_context, web_ui);
|
|
|
|
}
|
2020-07-16 10:14:54 -07:00
|
|
|
|
2024-08-23 17:15:45 -05:00
|
|
|
if (host == chrome::kChromeUIAccessibilityHost)
|
|
|
|
return std::make_unique<ElectronAccessibilityUI>(web_ui);
|
|
|
|
|
2024-11-29 11:44:33 -06:00
|
|
|
return {};
|
2017-01-17 19:53:13 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace electron
|