2012-10-18 00:45:49 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors.
|
|
|
|
// Portions copyright (c) 2012 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2012-10-08 19:47:37 +02:00
|
|
|
|
2015-11-26 03:53:12 +01:00
|
|
|
#include "libcef/browser/net/chrome_scheme_handler.h"
|
2012-10-18 00:45:49 +02:00
|
|
|
|
2016-11-07 20:14:09 +01:00
|
|
|
#include <algorithm>
|
2012-10-08 19:47:37 +02:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2016-01-06 20:20:54 +01:00
|
|
|
#include <utility>
|
2012-10-18 00:45:49 +02:00
|
|
|
|
2012-10-08 19:47:37 +02:00
|
|
|
#include "include/cef_version.h"
|
2017-08-04 00:55:19 +02:00
|
|
|
#include "libcef/browser/extensions/chrome_api_registration.h"
|
2012-10-18 00:45:49 +02:00
|
|
|
#include "libcef/browser/frame_host_impl.h"
|
2015-11-26 03:53:12 +01:00
|
|
|
#include "libcef/browser/net/internal_scheme_handler.h"
|
2012-10-18 00:45:49 +02:00
|
|
|
#include "libcef/browser/thread_util.h"
|
2020-06-28 23:05:36 +02:00
|
|
|
#include "libcef/common/app_manager.h"
|
2021-02-16 00:24:28 +01:00
|
|
|
#include "libcef/features/runtime.h"
|
2012-10-18 00:45:49 +02:00
|
|
|
|
2012-10-08 19:47:37 +02:00
|
|
|
#include "base/command_line.h"
|
2014-11-12 20:25:15 +01:00
|
|
|
#include "base/files/file_util.h"
|
2016-11-07 20:14:09 +01:00
|
|
|
#include "base/lazy_instance.h"
|
2012-10-18 00:45:49 +02:00
|
|
|
#include "base/logging.h"
|
2016-04-27 22:38:52 +02:00
|
|
|
#include "base/memory/ptr_util.h"
|
2012-10-08 19:47:37 +02:00
|
|
|
#include "base/path_service.h"
|
2013-06-22 04:06:32 +02:00
|
|
|
#include "base/strings/string_util.h"
|
|
|
|
#include "base/strings/stringprintf.h"
|
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2012-10-18 00:45:49 +02:00
|
|
|
#include "base/values.h"
|
2016-07-14 03:35:07 +02:00
|
|
|
#include "cef/grit/cef_resources.h"
|
2016-11-07 20:14:09 +01:00
|
|
|
#include "chrome/browser/browser_about_handler.h"
|
2023-01-23 19:42:05 +01:00
|
|
|
#include "chrome/browser/devtools/devtools_ui_bindings.h"
|
2020-06-28 23:05:36 +02:00
|
|
|
#include "chrome/browser/profiles/profile.h"
|
2022-04-21 20:58:48 +02:00
|
|
|
#include "chrome/browser/ui/webui/chrome_untrusted_web_ui_configs.h"
|
2016-11-07 20:14:09 +01:00
|
|
|
#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
|
2019-10-04 12:29:35 +02:00
|
|
|
#include "chrome/browser/ui/webui/theme_source.h"
|
2016-11-07 20:14:09 +01:00
|
|
|
#include "chrome/common/url_constants.h"
|
2020-10-08 21:54:42 +02:00
|
|
|
#include "content/browser/renderer_host/debug_urls.h"
|
2016-11-07 20:14:09 +01:00
|
|
|
#include "content/public/browser/browser_url_handler.h"
|
2020-06-28 23:05:36 +02:00
|
|
|
#include "content/public/browser/content_browser_client.h"
|
2019-04-30 22:45:13 +02:00
|
|
|
#include "content/public/browser/url_data_source.h"
|
2018-06-08 18:53:10 +02:00
|
|
|
#include "content/public/browser/web_ui_controller.h"
|
2022-04-21 20:58:48 +02:00
|
|
|
#include "content/public/browser/webui_config_map.h"
|
2013-03-12 21:23:24 +01:00
|
|
|
#include "content/public/common/url_constants.h"
|
2017-12-07 22:44:24 +01:00
|
|
|
#include "content/public/common/url_utils.h"
|
2014-04-04 18:50:38 +02:00
|
|
|
#include "content/public/common/user_agent.h"
|
2012-10-18 00:45:49 +02:00
|
|
|
#include "ipc/ipc_channel.h"
|
2021-06-04 03:34:56 +02:00
|
|
|
#include "third_party/blink/public/common/chrome_debug_urls.h"
|
2020-07-02 20:45:16 +02:00
|
|
|
#include "ui/base/resource/resource_bundle.h"
|
2012-10-08 19:47:37 +02:00
|
|
|
#include "v8/include/v8.h"
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
using extensions::api::cef::kSupportedAPIs;
|
|
|
|
|
2012-10-08 19:47:37 +02:00
|
|
|
namespace scheme {
|
|
|
|
|
|
|
|
const char kChromeURL[] = "chrome://";
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
const char kChromeUIExtensionsSupportHost[] = "extensions-support";
|
2016-11-07 20:14:09 +01:00
|
|
|
const char kChromeUILicenseHost[] = "license";
|
|
|
|
const char kChromeUIWebUIHostsHost[] = "webui-hosts";
|
|
|
|
|
2019-04-30 22:45:13 +02:00
|
|
|
// TODO(network): Consider handling content::kChromeDevToolsScheme via WebUI
|
|
|
|
// (DevToolsUI class) with the following changes:
|
|
|
|
// 1. Add an entry for content::kChromeDevToolsScheme in
|
2020-06-28 20:29:44 +02:00
|
|
|
// AlloyContentBrowserClient::GetAdditionalWebUISchemes.
|
2019-04-30 22:45:13 +02:00
|
|
|
// 2. Allow the scheme in CefWebUIControllerFactory::AllowWebUIForURL.
|
|
|
|
// 3. Add an entry for chrome::kChromeUIDevToolsHost in kAllowedWebUIHosts and
|
|
|
|
// kUnlistedHosts.
|
|
|
|
// 4. Remove scheme::RegisterInternalHandlers and related plumbing.
|
|
|
|
|
2016-11-07 20:14:09 +01:00
|
|
|
// Chrome hosts implemented by WebUI.
|
|
|
|
// Some WebUI handlers have Chrome dependencies that may fail in CEF without
|
|
|
|
// additional changes. Do not add new hosts to this list without also manually
|
|
|
|
// testing all related functionality in CEF.
|
|
|
|
const char* kAllowedWebUIHosts[] = {
|
2018-07-31 21:21:39 +02:00
|
|
|
chrome::kChromeUIAccessibilityHost,
|
2017-05-17 11:29:28 +02:00
|
|
|
content::kChromeUIBlobInternalsHost,
|
2020-07-02 21:40:09 +02:00
|
|
|
chrome::kChromeUIChromeURLsHost,
|
2017-05-17 11:29:28 +02:00
|
|
|
chrome::kChromeUICreditsHost,
|
2019-04-30 22:45:13 +02:00
|
|
|
kChromeUIExtensionsSupportHost,
|
2017-05-17 11:29:28 +02:00
|
|
|
content::kChromeUIGpuHost,
|
|
|
|
content::kChromeUIHistogramHost,
|
|
|
|
content::kChromeUIIndexedDBInternalsHost,
|
2019-04-30 22:45:13 +02:00
|
|
|
kChromeUILicenseHost,
|
2017-05-17 11:29:28 +02:00
|
|
|
content::kChromeUIMediaInternalsHost,
|
|
|
|
chrome::kChromeUINetExportHost,
|
|
|
|
chrome::kChromeUINetInternalsHost,
|
|
|
|
content::kChromeUINetworkErrorHost,
|
|
|
|
content::kChromeUINetworkErrorsListingHost,
|
2019-07-17 20:47:27 +02:00
|
|
|
chrome::kChromeUIPrintHost,
|
2019-10-04 12:29:35 +02:00
|
|
|
content::kChromeUIProcessInternalsHost,
|
2017-05-17 11:29:28 +02:00
|
|
|
content::kChromeUIResourcesHost,
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX)
|
2020-10-29 18:55:45 +01:00
|
|
|
chrome::kChromeUISandboxHost,
|
|
|
|
#endif
|
2017-05-17 11:29:28 +02:00
|
|
|
content::kChromeUIServiceWorkerInternalsHost,
|
|
|
|
chrome::kChromeUISystemInfoHost,
|
2019-10-04 12:29:35 +02:00
|
|
|
chrome::kChromeUIThemeHost,
|
2017-05-17 11:29:28 +02:00
|
|
|
content::kChromeUITracingHost,
|
2019-04-30 22:45:13 +02:00
|
|
|
chrome::kChromeUIVersionHost,
|
2017-05-17 11:29:28 +02:00
|
|
|
content::kChromeUIWebRTCInternalsHost,
|
2019-04-30 22:45:13 +02:00
|
|
|
kChromeUIWebUIHostsHost,
|
2016-11-07 20:14:09 +01:00
|
|
|
};
|
2012-10-08 19:47:37 +02:00
|
|
|
|
2016-12-12 11:05:29 +01:00
|
|
|
// Hosts that don't have useful output when linked directly. They'll be excluded
|
|
|
|
// from the "chrome://webui-hosts" listing.
|
|
|
|
const char* kUnlistedHosts[] = {
|
2019-01-17 10:56:52 +01:00
|
|
|
content::kChromeUINetworkErrorHost,
|
|
|
|
content::kChromeUIResourcesHost,
|
2019-10-04 12:29:35 +02:00
|
|
|
chrome::kChromeUIThemeHost,
|
2016-12-12 11:05:29 +01:00
|
|
|
};
|
|
|
|
|
2016-11-07 20:14:09 +01:00
|
|
|
enum ChromeHostId {
|
2012-10-08 19:47:37 +02:00
|
|
|
CHROME_UNKNOWN = 0,
|
2017-08-04 00:55:19 +02:00
|
|
|
CHROME_EXTENSIONS_SUPPORT,
|
2012-10-08 19:47:37 +02:00
|
|
|
CHROME_LICENSE,
|
|
|
|
CHROME_VERSION,
|
2016-11-07 20:14:09 +01:00
|
|
|
CHROME_WEBUI_HOSTS,
|
2012-10-08 19:47:37 +02:00
|
|
|
};
|
|
|
|
|
2016-11-07 20:14:09 +01:00
|
|
|
// Chrome hosts implemented by CEF.
|
|
|
|
const struct {
|
|
|
|
const char* host;
|
|
|
|
ChromeHostId host_id;
|
|
|
|
} kAllowedCefHosts[] = {
|
2020-07-02 21:40:09 +02:00
|
|
|
{chrome::kChromeUIChromeURLsHost, CHROME_WEBUI_HOSTS},
|
2017-08-04 00:55:19 +02:00
|
|
|
{kChromeUIExtensionsSupportHost, CHROME_EXTENSIONS_SUPPORT},
|
2017-05-17 11:29:28 +02:00
|
|
|
{kChromeUILicenseHost, CHROME_LICENSE},
|
|
|
|
{chrome::kChromeUIVersionHost, CHROME_VERSION},
|
|
|
|
{kChromeUIWebUIHostsHost, CHROME_WEBUI_HOSTS},
|
2016-11-07 20:14:09 +01:00
|
|
|
};
|
2012-10-08 19:47:37 +02:00
|
|
|
|
2016-11-07 20:14:09 +01:00
|
|
|
ChromeHostId GetChromeHostId(const std::string& host) {
|
2017-05-17 11:29:28 +02:00
|
|
|
for (size_t i = 0; i < sizeof(kAllowedCefHosts) / sizeof(kAllowedCefHosts[0]);
|
|
|
|
++i) {
|
2016-11-07 20:14:09 +01:00
|
|
|
if (base::EqualsCaseInsensitiveASCII(kAllowedCefHosts[i].host,
|
|
|
|
host.c_str())) {
|
|
|
|
return kAllowedCefHosts[i].host_id;
|
|
|
|
}
|
2012-10-08 19:47:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return CHROME_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2019-04-30 22:45:13 +02:00
|
|
|
// Returns WebUI hosts. Does not include chrome debug hosts (for crashing, etc).
|
2016-11-07 20:14:09 +01:00
|
|
|
void GetAllowedHosts(std::vector<std::string>* hosts) {
|
2016-12-12 11:05:29 +01:00
|
|
|
// Explicitly whitelisted WebUI hosts.
|
2016-11-07 20:14:09 +01:00
|
|
|
for (size_t i = 0;
|
|
|
|
i < sizeof(kAllowedWebUIHosts) / sizeof(kAllowedWebUIHosts[0]); ++i) {
|
|
|
|
hosts->push_back(kAllowedWebUIHosts[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-12 11:05:29 +01:00
|
|
|
// Returns true if a host should not be listed on "chrome://webui-hosts".
|
|
|
|
bool IsUnlistedHost(const std::string& host) {
|
2017-05-17 11:29:28 +02:00
|
|
|
for (size_t i = 0; i < sizeof(kUnlistedHosts) / sizeof(kUnlistedHosts[0]);
|
|
|
|
++i) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (host == kUnlistedHosts[i]) {
|
2016-12-12 11:05:29 +01:00
|
|
|
return true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true if a host is WebUI and should be allowed to load.
|
|
|
|
bool IsAllowedWebUIHost(const std::string& host) {
|
2021-02-16 00:24:28 +01:00
|
|
|
// Chrome runtime allows all WebUI hosts.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (cef::IsChromeRuntimeEnabled()) {
|
2021-02-16 00:24:28 +01:00
|
|
|
return true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-02-16 00:24:28 +01:00
|
|
|
|
2016-12-12 11:05:29 +01:00
|
|
|
// Explicitly whitelisted WebUI hosts.
|
|
|
|
for (size_t i = 0;
|
2017-05-17 11:29:28 +02:00
|
|
|
i < sizeof(kAllowedWebUIHosts) / sizeof(kAllowedWebUIHosts[0]); ++i) {
|
|
|
|
if (base::EqualsCaseInsensitiveASCII(kAllowedWebUIHosts[i], host.c_str())) {
|
2016-12-12 11:05:29 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Additional debug URLs that are not included in chrome::kChromeDebugURLs.
|
|
|
|
const char* kAllowedDebugURLs[] = {
|
2021-06-04 03:34:56 +02:00
|
|
|
blink::kChromeUIBrowserCrashURL,
|
2016-12-12 11:05:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void GetDebugURLs(std::vector<std::string>* urls) {
|
2017-12-07 22:44:24 +01:00
|
|
|
for (size_t i = 0; i < chrome::kNumberOfChromeDebugURLs; ++i) {
|
2016-12-12 11:05:29 +01:00
|
|
|
urls->push_back(chrome::kChromeDebugURLs[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0;
|
|
|
|
i < sizeof(kAllowedDebugURLs) / sizeof(kAllowedDebugURLs[0]); ++i) {
|
|
|
|
urls->push_back(kAllowedDebugURLs[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-30 22:45:13 +02:00
|
|
|
std::string GetOSType() {
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2019-04-30 22:45:13 +02:00
|
|
|
return "Windows";
|
2022-01-24 18:58:02 +01:00
|
|
|
#elif BUILDFLAG(IS_MAC)
|
2019-04-30 22:45:13 +02:00
|
|
|
return "Mac OS X";
|
2022-01-24 18:58:02 +01:00
|
|
|
#elif BUILDFLAG(IS_LINUX)
|
2019-04-30 22:45:13 +02:00
|
|
|
return "Linux";
|
|
|
|
#else
|
|
|
|
return "Unknown";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string GetCommandLine() {
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2019-04-30 22:45:13 +02:00
|
|
|
return base::WideToUTF8(
|
|
|
|
base::CommandLine::ForCurrentProcess()->GetCommandLineString());
|
2022-01-24 18:58:02 +01:00
|
|
|
#elif BUILDFLAG(IS_POSIX)
|
2019-04-30 22:45:13 +02:00
|
|
|
std::string command_line = "";
|
2021-12-06 21:40:25 +01:00
|
|
|
using ArgvList = std::vector<std::string>;
|
2019-04-30 22:45:13 +02:00
|
|
|
const ArgvList& argv = base::CommandLine::ForCurrentProcess()->argv();
|
2023-01-02 23:59:03 +01:00
|
|
|
for (ArgvList::const_iterator iter = argv.begin(); iter != argv.end();
|
|
|
|
iter++) {
|
2019-04-30 22:45:13 +02:00
|
|
|
command_line += " " + *iter;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-04-30 22:45:13 +02:00
|
|
|
// TODO(viettrungluu): |command_line| could really have any encoding, whereas
|
|
|
|
// below we assumes it's UTF-8.
|
|
|
|
return command_line;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string GetModulePath() {
|
|
|
|
base::FilePath path;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (base::PathService::Get(base::FILE_MODULE, &path)) {
|
2019-04-30 22:45:13 +02:00
|
|
|
return CefString(path.value());
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-04-30 22:45:13 +02:00
|
|
|
return std::string();
|
|
|
|
}
|
|
|
|
|
|
|
|
class TemplateParser {
|
|
|
|
public:
|
|
|
|
TemplateParser() : ident_start_("$$"), ident_end_("$$") {}
|
|
|
|
|
|
|
|
TemplateParser(const std::string& ident_start, const std::string& ident_end)
|
|
|
|
: ident_start_(ident_start), ident_end_(ident_end) {}
|
|
|
|
|
|
|
|
void Add(const std::string& key, const std::string& value) {
|
|
|
|
values_.insert(std::make_pair(key, value));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Parse(std::string* tmpl) {
|
|
|
|
int start_pos, end_pos = 0;
|
|
|
|
int ident_start_len = ident_start_.length();
|
|
|
|
int ident_end_len = ident_end_.length();
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
start_pos = tmpl->find(ident_start_, end_pos);
|
|
|
|
if (start_pos >= 0) {
|
|
|
|
end_pos = tmpl->find(ident_end_, start_pos + ident_start_len);
|
|
|
|
if (end_pos >= 0) {
|
|
|
|
// Found an identifier. Check if a substitution exists.
|
|
|
|
std::string key = tmpl->substr(start_pos + ident_start_len,
|
|
|
|
end_pos - start_pos - ident_start_len);
|
|
|
|
KeyMap::const_iterator it = values_.find(key);
|
|
|
|
if (it != values_.end()) {
|
|
|
|
// Peform the substitution.
|
|
|
|
tmpl->replace(start_pos, end_pos + ident_end_len - start_pos,
|
|
|
|
it->second);
|
|
|
|
end_pos = start_pos + it->second.length();
|
|
|
|
} else {
|
|
|
|
// Leave the unknown identifier in place.
|
|
|
|
end_pos += ident_end_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (end_pos >= static_cast<int>(tmpl->length()) - ident_start_len -
|
|
|
|
ident_end_len) {
|
|
|
|
// Not enough room remaining for more identifiers.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// No end identifier found.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// No start identifier found.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2021-12-06 21:40:25 +01:00
|
|
|
using KeyMap = std::map<std::string, std::string>;
|
2019-04-30 22:45:13 +02:00
|
|
|
KeyMap values_;
|
|
|
|
std::string ident_start_;
|
|
|
|
std::string ident_end_;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool OnExtensionsSupportUI(std::string* mime_type, std::string* output) {
|
2021-02-16 00:24:28 +01:00
|
|
|
*mime_type = "text/html";
|
|
|
|
|
|
|
|
if (cef::IsChromeRuntimeEnabled()) {
|
|
|
|
// Redirect to the Chrome documentation.
|
|
|
|
*output =
|
|
|
|
"<html><head>\n"
|
|
|
|
"<meta http-equiv=\"refresh\" "
|
|
|
|
"content=\"0;URL='https://developer.chrome.com/docs/extensions/'\"/>\n"
|
|
|
|
"</head></html>\n";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-04-30 22:45:13 +02:00
|
|
|
static const char kDevURL[] = "https://developer.chrome.com/extensions/";
|
|
|
|
|
|
|
|
std::string html =
|
|
|
|
"<html>\n<head><title>Extensions Support</title></head>\n"
|
|
|
|
"<body bgcolor=\"white\"><h3>Supported Chrome Extensions "
|
|
|
|
"APIs</h3>\nFollow <a "
|
2023-03-13 18:45:20 +01:00
|
|
|
"href=\"https://github.com/chromiumembedded/cef/issues/1947\" "
|
2019-04-30 22:45:13 +02:00
|
|
|
"target=\"new\">issue #1947</a> for development progress.\n<ul>\n";
|
|
|
|
|
|
|
|
bool has_top_level_name = false;
|
|
|
|
for (size_t i = 0; kSupportedAPIs[i] != nullptr; ++i) {
|
|
|
|
const std::string& api_name = kSupportedAPIs[i];
|
|
|
|
if (api_name.find("Private") != std::string::npos) {
|
|
|
|
// Don't list private APIs.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const size_t dot_pos = api_name.find('.');
|
|
|
|
if (dot_pos == std::string::npos) {
|
|
|
|
if (has_top_level_name) {
|
|
|
|
// End the previous top-level API entry.
|
|
|
|
html += "</ul></li>\n";
|
|
|
|
} else {
|
|
|
|
has_top_level_name = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start a new top-level API entry.
|
|
|
|
html += "<li><a href=\"" + std::string(kDevURL) + api_name +
|
|
|
|
"\" target=\"new\">" + api_name + "</a><ul>\n";
|
|
|
|
} else {
|
|
|
|
// Function name.
|
|
|
|
const std::string& group_name = api_name.substr(0, dot_pos);
|
|
|
|
const std::string& function_name = api_name.substr(dot_pos + 1);
|
|
|
|
html += "\t<li><a href=\"" + std::string(kDevURL) + group_name +
|
|
|
|
"#method-" + function_name + "\" target=\"new\">" + api_name +
|
|
|
|
"</a></li>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has_top_level_name) {
|
|
|
|
// End the last top-level API entry.
|
|
|
|
html += "</ul></li>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
html += "</ul>\n</body>\n</html>";
|
|
|
|
|
|
|
|
*output = html;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OnLicenseUI(std::string* mime_type, std::string* output) {
|
2020-07-02 20:45:16 +02:00
|
|
|
std::string piece =
|
|
|
|
ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
|
2021-02-28 21:23:42 +01:00
|
|
|
IDR_CEF_LICENSE_TXT);
|
2019-04-30 22:45:13 +02:00
|
|
|
if (piece.empty()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "Failed to load license txt resource.";
|
2019-04-30 22:45:13 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*mime_type = "text/html";
|
2020-07-02 20:45:16 +02:00
|
|
|
*output = "<html><head><title>License</title></head><body><pre>" + piece +
|
|
|
|
"</pre></body></html>";
|
2019-04-30 22:45:13 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OnVersionUI(Profile* profile,
|
|
|
|
std::string* mime_type,
|
|
|
|
std::string* output) {
|
2020-07-02 20:45:16 +02:00
|
|
|
std::string tmpl =
|
|
|
|
ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
|
|
|
|
IDR_CEF_VERSION_HTML);
|
|
|
|
if (tmpl.empty()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "Failed to load version html resource.";
|
2019-04-30 22:45:13 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
TemplateParser parser;
|
|
|
|
parser.Add("YEAR", MAKE_STRING(COPYRIGHT_YEAR));
|
|
|
|
parser.Add("CEF", CEF_VERSION);
|
|
|
|
parser.Add("CHROMIUM",
|
|
|
|
base::StringPrintf("%d.%d.%d.%d", CHROME_VERSION_MAJOR,
|
|
|
|
CHROME_VERSION_MINOR, CHROME_VERSION_BUILD,
|
|
|
|
CHROME_VERSION_PATCH));
|
|
|
|
parser.Add("OS", GetOSType());
|
|
|
|
parser.Add("WEBKIT", content::GetWebKitVersion());
|
|
|
|
parser.Add("JAVASCRIPT", v8::V8::GetVersion());
|
2020-06-28 23:05:36 +02:00
|
|
|
parser.Add(
|
|
|
|
"USERAGENT",
|
|
|
|
CefAppManager::Get()->GetContentClient()->browser()->GetUserAgent());
|
2019-04-30 22:45:13 +02:00
|
|
|
parser.Add("COMMANDLINE", GetCommandLine());
|
|
|
|
parser.Add("MODULEPATH", GetModulePath());
|
|
|
|
parser.Add("CACHEPATH", CefString(profile->GetPath().value()));
|
|
|
|
|
|
|
|
parser.Parse(&tmpl);
|
|
|
|
|
|
|
|
*mime_type = "text/html";
|
|
|
|
*output = tmpl;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OnWebUIHostsUI(std::string* mime_type, std::string* output) {
|
|
|
|
std::string html =
|
2020-07-02 21:40:09 +02:00
|
|
|
"<html>\n<head><title>Chrome URLs</title></head>\n"
|
|
|
|
"<body bgcolor=\"white\"><h3>List of Chrome URLs</h3>\n<ul>\n";
|
2019-04-30 22:45:13 +02:00
|
|
|
|
|
|
|
std::vector<std::string> list;
|
|
|
|
GetAllowedHosts(&list);
|
|
|
|
std::sort(list.begin(), list.end());
|
|
|
|
|
|
|
|
for (size_t i = 0U; i < list.size(); ++i) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (IsUnlistedHost(list[i])) {
|
2019-04-30 22:45:13 +02:00
|
|
|
continue;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-04-30 22:45:13 +02:00
|
|
|
|
|
|
|
html += "<li><a href=\"chrome://" + list[i] + "\">chrome://" + list[i] +
|
|
|
|
"</a></li>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
list.clear();
|
|
|
|
GetDebugURLs(&list);
|
|
|
|
std::sort(list.begin(), list.end());
|
|
|
|
|
|
|
|
html +=
|
|
|
|
"</ul>\n<h3>For Debug</h3>\n"
|
|
|
|
"<p>The following pages are for debugging purposes only. Because they "
|
|
|
|
"crash or hang the renderer, they're not linked directly; you can type "
|
|
|
|
"them into the address bar if you need them.</p>\n<ul>\n";
|
|
|
|
for (size_t i = 0U; i < list.size(); ++i) {
|
|
|
|
html += "<li>" + std::string(list[i]) + "</li>\n";
|
|
|
|
}
|
|
|
|
html += "</ul>\n";
|
|
|
|
|
|
|
|
html += "</body>\n</html>";
|
|
|
|
|
|
|
|
*mime_type = "text/html";
|
|
|
|
*output = html;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const content::WebUI::TypeID kCefWebUITypeID = &kCefWebUITypeID;
|
|
|
|
|
|
|
|
class CefURLDataSource : public content::URLDataSource {
|
|
|
|
public:
|
|
|
|
CefURLDataSource(const std::string& host,
|
|
|
|
ChromeHostId host_id,
|
|
|
|
Profile* profile)
|
|
|
|
: host_(host), host_id_(host_id), profile_(profile) {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
output_ = new base::RefCountedString();
|
|
|
|
bool handled = false;
|
|
|
|
switch (host_id_) {
|
|
|
|
case CHROME_EXTENSIONS_SUPPORT:
|
|
|
|
handled = OnExtensionsSupportUI(&mime_type_, &output_->data());
|
|
|
|
break;
|
|
|
|
case CHROME_LICENSE:
|
|
|
|
handled = OnLicenseUI(&mime_type_, &output_->data());
|
|
|
|
break;
|
|
|
|
case CHROME_VERSION:
|
|
|
|
handled = OnVersionUI(profile_, &mime_type_, &output_->data());
|
|
|
|
break;
|
|
|
|
case CHROME_WEBUI_HOSTS:
|
|
|
|
handled = OnWebUIHostsUI(&mime_type_, &output_->data());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DCHECK(handled) << "Unhandled WebUI host: " << host;
|
|
|
|
}
|
|
|
|
|
2021-12-06 21:40:25 +01:00
|
|
|
CefURLDataSource(const CefURLDataSource&) = delete;
|
|
|
|
CefURLDataSource& operator=(const CefURLDataSource&) = delete;
|
|
|
|
|
2019-04-30 22:45:13 +02:00
|
|
|
~CefURLDataSource() override = default;
|
|
|
|
|
|
|
|
// content::URLDataSource implementation.
|
2019-09-04 17:13:32 +02:00
|
|
|
std::string GetSource() override { return host_; }
|
2019-04-30 22:45:13 +02:00
|
|
|
|
|
|
|
void StartDataRequest(
|
2020-02-10 18:10:17 +01:00
|
|
|
const GURL& path,
|
2019-10-01 15:55:16 +02:00
|
|
|
const content::WebContents::Getter& wc_getter,
|
2020-02-10 18:10:17 +01:00
|
|
|
content::URLDataSource::GotDataCallback callback) override {
|
|
|
|
std::move(callback).Run(output_);
|
2019-04-30 22:45:13 +02:00
|
|
|
}
|
|
|
|
|
2022-08-23 03:37:40 +02:00
|
|
|
std::string GetMimeType(const GURL& url) override { return mime_type_; }
|
2019-04-30 22:45:13 +02:00
|
|
|
|
2019-09-04 17:13:32 +02:00
|
|
|
bool AllowCaching() override { return false; }
|
2019-04-30 22:45:13 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
const std::string host_;
|
|
|
|
const ChromeHostId host_id_;
|
|
|
|
Profile* const profile_;
|
|
|
|
|
|
|
|
std::string mime_type_;
|
|
|
|
scoped_refptr<base::RefCountedString> output_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CefWebUIController : public content::WebUIController {
|
|
|
|
public:
|
|
|
|
CefWebUIController(content::WebUI* web_ui,
|
|
|
|
const std::string& host,
|
|
|
|
ChromeHostId host_id)
|
|
|
|
: content::WebUIController(web_ui) {
|
|
|
|
Profile* profile = Profile::FromWebUI(web_ui);
|
|
|
|
content::URLDataSource::Add(
|
|
|
|
profile, std::make_unique<CefURLDataSource>(host, host_id, profile));
|
|
|
|
}
|
|
|
|
|
2021-12-06 21:40:25 +01:00
|
|
|
CefWebUIController(const CefWebUIController&) = delete;
|
|
|
|
CefWebUIController& operator=(const CefWebUIController&) = delete;
|
2019-04-30 22:45:13 +02:00
|
|
|
|
2021-12-06 21:40:25 +01:00
|
|
|
~CefWebUIController() override = default;
|
2019-04-30 22:45:13 +02:00
|
|
|
};
|
|
|
|
|
2016-11-07 20:14:09 +01:00
|
|
|
// Intercepts all WebUI calls and either blocks them or forwards them to the
|
|
|
|
// Content or Chrome WebUI factory as appropriate.
|
|
|
|
class CefWebUIControllerFactory : public content::WebUIControllerFactory {
|
|
|
|
public:
|
2021-12-06 21:40:25 +01:00
|
|
|
CefWebUIControllerFactory(const CefWebUIControllerFactory&) = delete;
|
|
|
|
CefWebUIControllerFactory& operator=(const CefWebUIControllerFactory&) =
|
|
|
|
delete;
|
|
|
|
|
2016-11-07 20:14:09 +01:00
|
|
|
// Returns true if WebUI is allowed to handle the specified |url|.
|
|
|
|
static bool AllowWebUIForURL(const GURL& url) {
|
2023-01-23 19:42:05 +01:00
|
|
|
if (cef::IsChromeRuntimeEnabled() &&
|
|
|
|
url.SchemeIs(content::kChromeDevToolsScheme)) {
|
|
|
|
return DevToolsUIBindings::IsValidFrontendURL(url);
|
|
|
|
}
|
|
|
|
|
2022-02-16 22:24:41 +01:00
|
|
|
if (!url.SchemeIs(content::kChromeUIScheme) &&
|
|
|
|
!url.SchemeIs(content::kChromeUIUntrustedScheme)) {
|
2016-11-07 20:14:09 +01:00
|
|
|
return false;
|
2022-02-16 22:24:41 +01:00
|
|
|
}
|
2016-11-07 20:14:09 +01:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (IsAllowedWebUIHost(url.host())) {
|
2016-12-12 11:05:29 +01:00
|
|
|
return true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-11-07 20:14:09 +01:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-04-30 22:45:13 +02:00
|
|
|
// Returns true if WebUI is allowed to make network requests.
|
|
|
|
static bool IsWebUIAllowedToMakeNetworkRequests(const url::Origin& origin) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!AllowWebUIForURL(origin.GetURL())) {
|
2019-04-30 22:45:13 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-04-30 22:45:13 +02:00
|
|
|
|
|
|
|
if (ChromeWebUIControllerFactory::IsWebUIAllowedToMakeNetworkRequests(
|
|
|
|
origin)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-06-08 18:53:10 +02:00
|
|
|
std::unique_ptr<content::WebUIController> CreateWebUIControllerForURL(
|
2016-11-07 20:14:09 +01:00
|
|
|
content::WebUI* web_ui,
|
2019-09-04 17:13:32 +02:00
|
|
|
const GURL& url) override {
|
2018-06-08 18:53:10 +02:00
|
|
|
std::unique_ptr<content::WebUIController> controller;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!AllowWebUIForURL(url)) {
|
2016-11-07 20:14:09 +01:00
|
|
|
return controller;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-11-07 20:14:09 +01:00
|
|
|
|
2019-10-04 12:29:35 +02:00
|
|
|
// Set up the chrome://theme/ source. These URLs are referenced from many
|
|
|
|
// places (WebUI and chrome://resources which live in //ui). WebUI code
|
|
|
|
// can live in both //content and //chrome. Since ThemeSource lives in
|
|
|
|
// //chrome the WebUI from //content is not performing this setup despite
|
|
|
|
// the fact that it's needed for proper handling of theme resource requests.
|
|
|
|
// See https://crbug.com/1011280.
|
|
|
|
Profile* profile = Profile::FromWebUI(web_ui);
|
|
|
|
content::URLDataSource::Add(profile,
|
|
|
|
std::make_unique<ThemeSource>(profile));
|
|
|
|
|
2019-04-30 22:45:13 +02:00
|
|
|
const auto host_id = GetChromeHostId(url.host());
|
|
|
|
if (host_id != CHROME_UNKNOWN) {
|
|
|
|
return std::make_unique<CefWebUIController>(web_ui, url.host(), host_id);
|
|
|
|
}
|
|
|
|
|
2022-04-21 20:58:48 +02:00
|
|
|
controller = content::WebUIConfigMap::GetInstance()
|
|
|
|
.controller_factory()
|
2022-02-16 23:27:59 +01:00
|
|
|
->CreateWebUIControllerForURL(web_ui, url);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (controller) {
|
2022-02-16 23:27:59 +01:00
|
|
|
return controller;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2022-02-16 23:27:59 +01:00
|
|
|
|
2018-06-08 18:53:10 +02:00
|
|
|
return ChromeWebUIControllerFactory::GetInstance()
|
|
|
|
->CreateWebUIControllerForURL(web_ui, url);
|
2016-11-07 20:14:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
content::WebUI::TypeID GetWebUIType(content::BrowserContext* browser_context,
|
2019-09-04 17:13:32 +02:00
|
|
|
const GURL& url) override {
|
2016-11-07 20:14:09 +01:00
|
|
|
content::WebUI::TypeID type = content::WebUI::kNoWebUI;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!AllowWebUIForURL(url)) {
|
2016-11-07 20:14:09 +01:00
|
|
|
return type;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-11-07 20:14:09 +01:00
|
|
|
|
2019-04-30 22:45:13 +02:00
|
|
|
const auto host_id = GetChromeHostId(url.host());
|
|
|
|
if (host_id != CHROME_UNKNOWN) {
|
|
|
|
return kCefWebUITypeID;
|
|
|
|
}
|
|
|
|
|
2022-04-21 20:58:48 +02:00
|
|
|
type = content::WebUIConfigMap::GetInstance()
|
|
|
|
.controller_factory()
|
|
|
|
->GetWebUIType(browser_context, url);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (type != content::WebUI::kNoWebUI) {
|
2022-02-16 23:27:59 +01:00
|
|
|
return type;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2022-02-16 23:27:59 +01:00
|
|
|
|
2016-11-07 20:14:09 +01:00
|
|
|
type = ChromeWebUIControllerFactory::GetInstance()->GetWebUIType(
|
|
|
|
browser_context, url);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (type != content::WebUI::kNoWebUI) {
|
2016-11-07 20:14:09 +01:00
|
|
|
return type;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-11-07 20:14:09 +01:00
|
|
|
|
|
|
|
return content::WebUI::kNoWebUI;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UseWebUIForURL(content::BrowserContext* browser_context,
|
2019-09-04 17:13:32 +02:00
|
|
|
const GURL& url) override {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!AllowWebUIForURL(url)) {
|
2016-11-07 20:14:09 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-11-07 20:14:09 +01:00
|
|
|
|
2019-04-30 22:45:13 +02:00
|
|
|
const auto host_id = GetChromeHostId(url.host());
|
|
|
|
if (host_id != CHROME_UNKNOWN) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-07-21 19:26:10 +02:00
|
|
|
if (content::WebUIConfigMap::GetInstance()
|
2022-04-21 20:58:48 +02:00
|
|
|
.controller_factory()
|
|
|
|
->UseWebUIForURL(browser_context, url) ||
|
2016-11-07 20:14:09 +01:00
|
|
|
ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
|
|
|
|
browser_context, url)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void BrowserURLHandlerCreated(content::BrowserURLHandler* handler) {
|
2021-02-27 20:25:46 +01:00
|
|
|
// For Chrome runtime this is registered in
|
|
|
|
// ChromeContentBrowserClient::BrowserURLHandlerCreated().
|
|
|
|
if (cef::IsAlloyRuntimeEnabled()) {
|
|
|
|
// Handler to rewrite chrome://about and chrome://sync URLs.
|
|
|
|
handler->AddHandlerPair(&HandleChromeAboutAndChromeSyncRewrite,
|
|
|
|
content::BrowserURLHandler::null_handler());
|
|
|
|
}
|
2016-11-07 20:14:09 +01:00
|
|
|
|
2021-02-27 20:25:46 +01:00
|
|
|
// chrome: & friends. For Chrome runtime the default registration is
|
|
|
|
// disabled is ChromeContentBrowserClient::BrowserURLHandlerCreated().
|
2016-11-07 20:14:09 +01:00
|
|
|
handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
|
|
|
|
}
|
|
|
|
|
|
|
|
static CefWebUIControllerFactory* GetInstance();
|
|
|
|
|
|
|
|
protected:
|
2021-12-06 21:40:25 +01:00
|
|
|
CefWebUIControllerFactory() = default;
|
|
|
|
~CefWebUIControllerFactory() override = default;
|
2016-11-07 20:14:09 +01:00
|
|
|
|
|
|
|
private:
|
2017-04-20 21:28:17 +02:00
|
|
|
friend struct base::LazyInstanceTraitsBase<CefWebUIControllerFactory>;
|
2016-11-07 20:14:09 +01:00
|
|
|
|
|
|
|
// From chrome/browser/chrome_content_browser_client.cc
|
|
|
|
|
|
|
|
// Handles rewriting Web UI URLs.
|
|
|
|
static bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!GetInstance()->UseWebUIForURL(browser_context, *url)) {
|
2016-11-07 20:14:09 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-11-07 20:14:09 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-10-01 15:55:16 +02:00
|
|
|
// Reverse URL handler for Web UI.
|
2016-11-07 20:14:09 +01:00
|
|
|
static bool HandleWebUIReverse(GURL* url,
|
|
|
|
content::BrowserContext* browser_context) {
|
2019-10-01 15:55:16 +02:00
|
|
|
// No need to actually reverse-rewrite the URL.
|
|
|
|
return false;
|
2016-11-07 20:14:09 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
base::LazyInstance<CefWebUIControllerFactory>::Leaky
|
|
|
|
g_web_ui_controller_factory = LAZY_INSTANCE_INITIALIZER;
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefWebUIControllerFactory* CefWebUIControllerFactory::GetInstance() {
|
|
|
|
return &g_web_ui_controller_factory.Get();
|
|
|
|
}
|
|
|
|
|
2012-10-08 19:47:37 +02:00
|
|
|
} // namespace
|
|
|
|
|
2016-11-07 20:14:09 +01:00
|
|
|
void RegisterWebUIControllerFactory() {
|
|
|
|
// Channel all WebUI handling through CefWebUIControllerFactory.
|
2022-04-21 20:58:48 +02:00
|
|
|
content::WebUIControllerFactory::UnregisterFactoryForTesting(
|
|
|
|
content::WebUIConfigMap::GetInstance().controller_factory());
|
2022-02-17 00:19:56 +01:00
|
|
|
|
2016-11-07 20:14:09 +01:00
|
|
|
content::WebUIControllerFactory::RegisterFactory(
|
|
|
|
CefWebUIControllerFactory::GetInstance());
|
2022-04-21 20:58:48 +02:00
|
|
|
|
|
|
|
RegisterChromeUntrustedWebUIConfigs();
|
2016-11-07 20:14:09 +01:00
|
|
|
}
|
2012-10-08 19:47:37 +02:00
|
|
|
|
2016-11-07 20:14:09 +01:00
|
|
|
void BrowserURLHandlerCreated(content::BrowserURLHandler* handler) {
|
|
|
|
CefWebUIControllerFactory::BrowserURLHandlerCreated(handler);
|
2012-10-08 19:47:37 +02:00
|
|
|
}
|
|
|
|
|
2019-04-30 22:45:13 +02:00
|
|
|
bool IsWebUIAllowedToMakeNetworkRequests(const url::Origin& origin) {
|
|
|
|
return CefWebUIControllerFactory::IsWebUIAllowedToMakeNetworkRequests(origin);
|
|
|
|
}
|
|
|
|
|
2012-10-08 19:47:37 +02:00
|
|
|
} // namespace scheme
|