chrome: Add CEF-specific WebUI handling (see issue #2969)
To avoid conflicting IDs between Alloy (which uses cef.pak) and Chrome (which uses chrome_100_percent.pak) the cef/LICENSE.txt file is now included in both cef/libcef/resources/cef_resources.grd and chrome/app/theme/chrome_unscaled_resources.grd with different ID values. The cef.pak file currently contains both CEF-specific resources and Chrome resources that are already included in the default *.pak files distributed with Chrome. In the future we should remove this duplication and just distribute the same *.pak files as Chrome for the majority of resources.
This commit is contained in:
parent
ec7067c55e
commit
8f5fdc1f9a
|
@ -5,6 +5,7 @@
|
|||
#include "libcef/browser/chrome/chrome_browser_main_extra_parts_cef.h"
|
||||
|
||||
#include "libcef/browser/context.h"
|
||||
#include "libcef/browser/net/chrome_scheme_handler.h"
|
||||
|
||||
#include "base/task/post_task.h"
|
||||
|
||||
|
@ -31,4 +32,6 @@ void ChromeBrowserMainExtraPartsCef::PreMainMessageLoopRun() {
|
|||
user_blocking_task_runner_ = base::CreateSingleThreadTaskRunner(
|
||||
{base::ThreadPool(), base::TaskPriority::USER_BLOCKING,
|
||||
base::TaskShutdownBehavior::BLOCK_SHUTDOWN, base::MayBlock()});
|
||||
|
||||
scheme::RegisterWebUIControllerFactory();
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "libcef/browser/browser_info_manager.h"
|
||||
#include "libcef/browser/browser_message_filter.h"
|
||||
#include "libcef/browser/chrome/chrome_browser_main_extra_parts_cef.h"
|
||||
#include "libcef/browser/net/chrome_scheme_handler.h"
|
||||
#include "libcef/browser/net/throttle_handler.h"
|
||||
#include "libcef/browser/net_service/cookie_manager_impl.h"
|
||||
#include "libcef/browser/net_service/login_delegate.h"
|
||||
|
@ -283,6 +284,17 @@ ChromeContentBrowserClientCef::CreateLoginDelegate(
|
|||
response_headers, first_auth_attempt, std::move(auth_required_callback));
|
||||
}
|
||||
|
||||
void ChromeContentBrowserClientCef::BrowserURLHandlerCreated(
|
||||
content::BrowserURLHandler* handler) {
|
||||
scheme::BrowserURLHandlerCreated(handler);
|
||||
ChromeContentBrowserClient::BrowserURLHandlerCreated(handler);
|
||||
}
|
||||
|
||||
bool ChromeContentBrowserClientCef::IsWebUIAllowedToMakeNetworkRequests(
|
||||
const url::Origin& origin) {
|
||||
return scheme::IsWebUIAllowedToMakeNetworkRequests(origin);
|
||||
}
|
||||
|
||||
CefRefPtr<CefRequestContextImpl>
|
||||
ChromeContentBrowserClientCef::request_context() const {
|
||||
return browser_main_parts_->request_context();
|
||||
|
|
|
@ -91,6 +91,8 @@ class ChromeContentBrowserClientCef : public ChromeContentBrowserClient {
|
|||
scoped_refptr<net::HttpResponseHeaders> response_headers,
|
||||
bool first_auth_attempt,
|
||||
LoginAuthRequiredCallback auth_required_callback) override;
|
||||
void BrowserURLHandlerCreated(content::BrowserURLHandler* handler) override;
|
||||
bool IsWebUIAllowedToMakeNetworkRequests(const url::Origin& origin) override;
|
||||
|
||||
CefRefPtr<CefRequestContextImpl> request_context() const;
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "libcef/browser/net/internal_scheme_handler.h"
|
||||
#include "libcef/browser/thread_util.h"
|
||||
#include "libcef/common/app_manager.h"
|
||||
#include "libcef/features/runtime.h"
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/files/file_util.h"
|
||||
|
@ -34,6 +35,7 @@
|
|||
#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
|
||||
#include "chrome/browser/ui/webui/theme_source.h"
|
||||
#include "chrome/common/url_constants.h"
|
||||
#include "chrome/grit/chrome_unscaled_resources.h"
|
||||
#include "content/browser/renderer_host/debug_urls.h"
|
||||
#include "content/browser/webui/content_web_ui_controller_factory.h"
|
||||
#include "content/public/browser/browser_url_handler.h"
|
||||
|
@ -164,6 +166,10 @@ bool IsUnlistedHost(const std::string& host) {
|
|||
|
||||
// Returns true if a host is WebUI and should be allowed to load.
|
||||
bool IsAllowedWebUIHost(const std::string& host) {
|
||||
// Chrome runtime allows all WebUI hosts.
|
||||
if (cef::IsChromeRuntimeEnabled())
|
||||
return true;
|
||||
|
||||
// Explicitly whitelisted WebUI hosts.
|
||||
for (size_t i = 0;
|
||||
i < sizeof(kAllowedWebUIHosts) / sizeof(kAllowedWebUIHosts[0]); ++i) {
|
||||
|
@ -285,6 +291,18 @@ class TemplateParser {
|
|||
};
|
||||
|
||||
bool OnExtensionsSupportUI(std::string* mime_type, std::string* output) {
|
||||
*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;
|
||||
}
|
||||
|
||||
static const char kDevURL[] = "https://developer.chrome.com/extensions/";
|
||||
|
||||
std::string html =
|
||||
|
@ -331,16 +349,22 @@ bool OnExtensionsSupportUI(std::string* mime_type, std::string* output) {
|
|||
|
||||
html += "</ul>\n</body>\n</html>";
|
||||
|
||||
*mime_type = "text/html";
|
||||
*output = html;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OnLicenseUI(std::string* mime_type, std::string* output) {
|
||||
// TODO(chrome): Currently, CEF-specific resources for the Alloy runtime come
|
||||
// from cef/libcef/resources/cef_resources.grd via cef.pak and CEF-specific
|
||||
// resources for the Chrome runtime come from
|
||||
// chrome/app/theme/chrome_unscaled_resources.grd via chrome_100_percent.pak.
|
||||
// It would be better to have a single pak file (and single ID value) for
|
||||
// CEF-specific resources and share the same *.pak files as Chrome for the
|
||||
// other resources.
|
||||
std::string piece =
|
||||
ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
|
||||
IDR_CEF_LICENSE_TXT);
|
||||
cef::IsChromeRuntimeEnabled() ? IDR_CHROME_CEF_LICENSE_TXT
|
||||
: IDR_CEF_LICENSE_TXT);
|
||||
if (piece.empty()) {
|
||||
NOTREACHED() << "Failed to load license txt resource.";
|
||||
return false;
|
||||
|
|
|
@ -77,6 +77,18 @@ index db85b6b2fcf5..bcf6867e8f4e 100644
|
|||
}
|
||||
|
||||
#endif // defined(OS_LINUX) || defined(OS_CHROMEOS)
|
||||
diff --git chrome/app/theme/chrome_unscaled_resources.grd chrome/app/theme/chrome_unscaled_resources.grd
|
||||
index b4e4545e3520..29335f1614e2 100644
|
||||
--- chrome/app/theme/chrome_unscaled_resources.grd
|
||||
+++ chrome/app/theme/chrome_unscaled_resources.grd
|
||||
@@ -62,6 +62,7 @@
|
||||
</if>
|
||||
</if>
|
||||
<if expr="not _google_chrome">
|
||||
+ <include name="IDR_CHROME_CEF_LICENSE_TXT" file="../../../cef/LICENSE.txt" type="BINDATA" />
|
||||
<include name="IDR_PRODUCT_LOGO_64" file="chromium/product_logo_64.png" type="BINDATA" />
|
||||
<include name="IDR_PRODUCT_LOGO_128" file="chromium/product_logo_128.png" type="BINDATA" />
|
||||
<include name="IDR_PRODUCT_LOGO_256" file="chromium/product_logo_256.png" type="BINDATA" />
|
||||
diff --git chrome/browser/chrome_browser_main.cc chrome/browser/chrome_browser_main.cc
|
||||
index fee4d5f1a8ca..2e4fb506d851 100644
|
||||
--- chrome/browser/chrome_browser_main.cc
|
||||
|
|
Loading…
Reference in New Issue