mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Delete Alloy bootstrap (fixes #3685)
This commit is contained in:
@@ -24,11 +24,9 @@
|
||||
#include "base/values.h"
|
||||
#include "cef/grit/cef_resources.h"
|
||||
#include "cef/include/cef_version.h"
|
||||
#include "cef/libcef/browser/extensions/chrome_api_registration.h"
|
||||
#include "cef/libcef/browser/frame_host_impl.h"
|
||||
#include "cef/libcef/browser/thread_util.h"
|
||||
#include "cef/libcef/common/app_manager.h"
|
||||
#include "cef/libcef/features/runtime.h"
|
||||
#include "chrome/browser/browser_about_handler.h"
|
||||
#include "chrome/browser/devtools/devtools_ui_bindings.h"
|
||||
#include "chrome/browser/profiles/profile.h"
|
||||
@@ -52,8 +50,6 @@
|
||||
#include "ui/base/resource/resource_bundle.h"
|
||||
#include "v8/include/v8.h"
|
||||
|
||||
using extensions::api::cef::kSupportedAPIs;
|
||||
|
||||
namespace scheme {
|
||||
|
||||
const char kChromeURL[] = "chrome://";
|
||||
@@ -163,25 +159,6 @@ bool IsUnlistedHost(const std::string& host) {
|
||||
return false;
|
||||
}
|
||||
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
// 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 (auto& kAllowedWebUIHost : kAllowedWebUIHosts) {
|
||||
if (base::EqualsCaseInsensitiveASCII(kAllowedWebUIHost, host.c_str())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
|
||||
// Additional debug URLs that are not included in chrome::kChromeDebugURLs.
|
||||
const char* kAllowedDebugURLs[] = {
|
||||
blink::kChromeUIBrowserCrashURL,
|
||||
@@ -296,59 +273,6 @@ class TemplateParser {
|
||||
bool OnExtensionsSupportUI(std::string* mime_type, std::string* output) {
|
||||
*mime_type = "text/html";
|
||||
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
if (cef::IsAlloyRuntimeEnabled()) {
|
||||
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 "
|
||||
"href=\"https://github.com/chromiumembedded/cef/issues/1947\" "
|
||||
"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;
|
||||
}
|
||||
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
|
||||
// Redirect to the Chrome documentation.
|
||||
*output =
|
||||
"<html><head>\n"
|
||||
@@ -538,23 +462,6 @@ class CefWebUIControllerFactory : public content::WebUIControllerFactory {
|
||||
|
||||
// Returns true if WebUI is allowed to handle the specified |url|.
|
||||
static bool AllowWebUIForURL(const GURL& url) {
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
if (cef::IsChromeRuntimeEnabled() &&
|
||||
url.SchemeIs(content::kChromeDevToolsScheme)) {
|
||||
return DevToolsUIBindings::IsValidFrontendURL(url);
|
||||
}
|
||||
|
||||
if (!url.SchemeIs(content::kChromeUIScheme) &&
|
||||
!url.SchemeIs(content::kChromeUIUntrustedScheme)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsAllowedWebUIHost(url.host())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
#else // !BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
if (url.SchemeIs(content::kChromeDevToolsScheme)) {
|
||||
return DevToolsUIBindings::IsValidFrontendURL(url);
|
||||
}
|
||||
@@ -565,7 +472,6 @@ class CefWebUIControllerFactory : public content::WebUIControllerFactory {
|
||||
}
|
||||
|
||||
return true;
|
||||
#endif // ! BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
}
|
||||
|
||||
// Returns true if WebUI is allowed to make network requests.
|
||||
@@ -667,18 +573,8 @@ class CefWebUIControllerFactory : public content::WebUIControllerFactory {
|
||||
}
|
||||
|
||||
static void BrowserURLHandlerCreated(content::BrowserURLHandler* handler) {
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
// For Chrome runtime this is registered in
|
||||
// chrome: & friends. The default registration is disabled is
|
||||
// ChromeContentBrowserClient::BrowserURLHandlerCreated().
|
||||
if (cef::IsAlloyRuntimeEnabled()) {
|
||||
// Handler to rewrite chrome://about and chrome://sync URLs.
|
||||
handler->AddHandlerPair(&HandleChromeAboutAndChromeSyncRewrite,
|
||||
content::BrowserURLHandler::null_handler());
|
||||
}
|
||||
#endif
|
||||
|
||||
// chrome: & friends. For Chrome runtime the default registration is
|
||||
// disabled is ChromeContentBrowserClient::BrowserURLHandlerCreated().
|
||||
handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
|
||||
}
|
||||
|
||||
|
@@ -1,49 +0,0 @@
|
||||
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
|
||||
// reserved. Use of this source code is governed by a BSD-style license that can
|
||||
// be found in the LICENSE file.
|
||||
|
||||
#include "cef/libcef/browser/net/devtools_scheme_handler.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "cef/libcef/browser/iothread_state.h"
|
||||
#include "cef/libcef/browser/net/internal_scheme_handler.h"
|
||||
#include "content/public/browser/devtools_frontend_host.h"
|
||||
#include "content/public/common/url_constants.h"
|
||||
|
||||
namespace scheme {
|
||||
|
||||
const char kChromeDevToolsHost[] = "devtools";
|
||||
|
||||
namespace {
|
||||
|
||||
class Delegate : public InternalHandlerDelegate {
|
||||
public:
|
||||
Delegate() = default;
|
||||
|
||||
bool OnRequest(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefRequest> request,
|
||||
Action* action) override {
|
||||
GURL url = GURL(request->GetURL().ToString());
|
||||
std::string path = url.path();
|
||||
if (path.length() > 0) {
|
||||
path = path.substr(1);
|
||||
}
|
||||
|
||||
action->bytes =
|
||||
content::DevToolsFrontendHost::GetFrontendResourceBytes(path);
|
||||
return !!action->bytes;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
void RegisterChromeDevToolsHandler(CefIOThreadState* iothread_state) {
|
||||
iothread_state->RegisterSchemeHandlerFactory(
|
||||
content::kChromeDevToolsScheme, kChromeDevToolsHost,
|
||||
CreateInternalHandlerFactory(base::WrapUnique(new Delegate())));
|
||||
}
|
||||
|
||||
} // namespace scheme
|
@@ -1,20 +0,0 @@
|
||||
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
|
||||
// reserved. Use of this source code is governed by a BSD-style license that can
|
||||
// be found in the LICENSE file.
|
||||
|
||||
#ifndef CEF_LIBCEF_BROWSER_NET_DEVTOOLS_SCHEME_HANDLER_H_
|
||||
#define CEF_LIBCEF_BROWSER_NET_DEVTOOLS_SCHEME_HANDLER_H_
|
||||
#pragma once
|
||||
|
||||
class CefIOThreadState;
|
||||
|
||||
namespace scheme {
|
||||
|
||||
extern const char kChromeDevToolsHost[];
|
||||
|
||||
// Register the chrome-devtools scheme handler.
|
||||
void RegisterChromeDevToolsHandler(CefIOThreadState* iothread_state);
|
||||
|
||||
} // namespace scheme
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_NET_DEVTOOLS_SCHEME_HANDLER_H_
|
@@ -1,219 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#include "cef/libcef/browser/net/internal_scheme_handler.h"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "base/notreached.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "base/threading/thread_restrictions.h"
|
||||
#include "cef/libcef/common/app_manager.h"
|
||||
#include "net/base/mime_util.h"
|
||||
#include "ui/base/resource/resource_bundle.h"
|
||||
|
||||
namespace scheme {
|
||||
|
||||
namespace {
|
||||
|
||||
base::FilePath FilePathFromASCII(const std::string& str) {
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
return base::FilePath(base::ASCIIToWide(str));
|
||||
#else
|
||||
return base::FilePath(str);
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string GetMimeType(const std::string& filename) {
|
||||
// Requests should not block on the disk! On POSIX this goes to disk.
|
||||
// http://code.google.com/p/chromium/issues/detail?id=59849
|
||||
base::ScopedAllowBlockingForTesting allow_blocking;
|
||||
|
||||
std::string mime_type;
|
||||
const base::FilePath& file_path = FilePathFromASCII(filename);
|
||||
if (net::GetMimeTypeFromFile(file_path, &mime_type)) {
|
||||
return mime_type;
|
||||
}
|
||||
|
||||
// Check for newer extensions used by internal resources but not yet
|
||||
// recognized by the mime type detector.
|
||||
const std::string& extension = CefString(file_path.FinalExtension());
|
||||
if (extension == ".md") {
|
||||
return "text/markdown";
|
||||
}
|
||||
if (extension == ".woff2") {
|
||||
return "application/font-woff2";
|
||||
}
|
||||
|
||||
DCHECK(false) << "No known mime type for file: " << filename.c_str();
|
||||
return "text/plain";
|
||||
}
|
||||
|
||||
class RedirectHandler : public CefResourceHandler {
|
||||
public:
|
||||
explicit RedirectHandler(const GURL& url) : url_(url) {}
|
||||
|
||||
RedirectHandler(const RedirectHandler&) = delete;
|
||||
RedirectHandler& operator=(const RedirectHandler&) = delete;
|
||||
|
||||
bool Open(CefRefPtr<CefRequest> request,
|
||||
bool& handle_request,
|
||||
CefRefPtr<CefCallback> callback) override {
|
||||
// Continue immediately.
|
||||
handle_request = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void GetResponseHeaders(CefRefPtr<CefResponse> response,
|
||||
int64_t& response_length,
|
||||
CefString& redirectUrl) override {
|
||||
response_length = 0;
|
||||
redirectUrl = url_.spec();
|
||||
}
|
||||
|
||||
bool Read(void* data_out,
|
||||
int bytes_to_read,
|
||||
int& bytes_read,
|
||||
CefRefPtr<CefResourceReadCallback> callback) override {
|
||||
DCHECK(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
void Cancel() override {}
|
||||
|
||||
private:
|
||||
GURL url_;
|
||||
|
||||
IMPLEMENT_REFCOUNTING(RedirectHandler);
|
||||
};
|
||||
|
||||
class InternalHandler : public CefResourceHandler {
|
||||
public:
|
||||
InternalHandler(const std::string& mime_type,
|
||||
CefRefPtr<CefStreamReader> reader,
|
||||
int size)
|
||||
: mime_type_(mime_type), reader_(reader), size_(size) {}
|
||||
|
||||
InternalHandler(const InternalHandler&) = delete;
|
||||
InternalHandler& operator=(const InternalHandler&) = delete;
|
||||
|
||||
bool Open(CefRefPtr<CefRequest> request,
|
||||
bool& handle_request,
|
||||
CefRefPtr<CefCallback> callback) override {
|
||||
// Continue immediately.
|
||||
handle_request = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void GetResponseHeaders(CefRefPtr<CefResponse> response,
|
||||
int64_t& response_length,
|
||||
CefString& redirectUrl) override {
|
||||
response_length = size_;
|
||||
|
||||
response->SetMimeType(mime_type_);
|
||||
response->SetStatus(200);
|
||||
}
|
||||
|
||||
bool Read(void* data_out,
|
||||
int bytes_to_read,
|
||||
int& bytes_read,
|
||||
CefRefPtr<CefResourceReadCallback> callback) override {
|
||||
// Read until the buffer is full or until Read() returns 0 to indicate no
|
||||
// more data.
|
||||
bytes_read = 0;
|
||||
int read = 0;
|
||||
do {
|
||||
read = static_cast<int>(
|
||||
reader_->Read(static_cast<char*>(data_out) + bytes_read, 1,
|
||||
bytes_to_read - bytes_read));
|
||||
bytes_read += read;
|
||||
} while (read != 0 && bytes_read < bytes_to_read);
|
||||
|
||||
return (bytes_read > 0);
|
||||
}
|
||||
|
||||
void Cancel() override {}
|
||||
|
||||
private:
|
||||
std::string mime_type_;
|
||||
CefRefPtr<CefStreamReader> reader_;
|
||||
int size_;
|
||||
|
||||
IMPLEMENT_REFCOUNTING(InternalHandler);
|
||||
};
|
||||
|
||||
class InternalHandlerFactory : public CefSchemeHandlerFactory {
|
||||
public:
|
||||
explicit InternalHandlerFactory(
|
||||
std::unique_ptr<InternalHandlerDelegate> delegate)
|
||||
: delegate_(std::move(delegate)) {}
|
||||
|
||||
InternalHandlerFactory(const InternalHandlerFactory&) = delete;
|
||||
InternalHandlerFactory& operator=(const InternalHandlerFactory&) = delete;
|
||||
|
||||
CefRefPtr<CefResourceHandler> Create(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
const CefString& scheme_name,
|
||||
CefRefPtr<CefRequest> request) override {
|
||||
GURL url = GURL(request->GetURL().ToString());
|
||||
|
||||
InternalHandlerDelegate::Action action;
|
||||
if (delegate_->OnRequest(browser, request, &action)) {
|
||||
if (!action.redirect_url.is_empty() && action.redirect_url.is_valid()) {
|
||||
return new RedirectHandler(action.redirect_url);
|
||||
}
|
||||
|
||||
if (action.mime_type.empty()) {
|
||||
action.mime_type = GetMimeType(url.path());
|
||||
}
|
||||
|
||||
if (!action.bytes && action.resource_id >= 0) {
|
||||
std::string str =
|
||||
ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
|
||||
action.resource_id);
|
||||
if (str.empty()) {
|
||||
DCHECK(false) << "Failed to load internal resource for id: "
|
||||
<< action.resource_id << " URL: " << url.spec().c_str();
|
||||
return nullptr;
|
||||
}
|
||||
action.bytes =
|
||||
base::MakeRefCounted<base::RefCountedString>(std::move(str));
|
||||
}
|
||||
|
||||
if (action.bytes) {
|
||||
action.stream = CefStreamReader::CreateForData(
|
||||
const_cast<unsigned char*>(action.bytes->data()),
|
||||
action.bytes->size());
|
||||
action.stream_size = action.bytes->size();
|
||||
}
|
||||
|
||||
if (action.stream.get()) {
|
||||
return new InternalHandler(action.mime_type, action.stream,
|
||||
action.stream_size);
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<InternalHandlerDelegate> delegate_;
|
||||
|
||||
IMPLEMENT_REFCOUNTING(InternalHandlerFactory);
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
InternalHandlerDelegate::Action::Action() = default;
|
||||
|
||||
CefRefPtr<CefSchemeHandlerFactory> CreateInternalHandlerFactory(
|
||||
std::unique_ptr<InternalHandlerDelegate> delegate) {
|
||||
DCHECK(delegate.get());
|
||||
return new InternalHandlerFactory(std::move(delegate));
|
||||
}
|
||||
|
||||
} // namespace scheme
|
@@ -1,58 +0,0 @@
|
||||
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
|
||||
// reserved. Use of this source code is governed by a BSD-style license that can
|
||||
// be found in the LICENSE file.
|
||||
|
||||
#ifndef CEF_LIBCEF_BROWSER_NET_INTERNAL_SCHEME_HANDLER_H_
|
||||
#define CEF_LIBCEF_BROWSER_NET_INTERNAL_SCHEME_HANDLER_H_
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/memory/ref_counted_memory.h"
|
||||
#include "cef/include/cef_scheme.h"
|
||||
#include "url/gurl.h"
|
||||
|
||||
namespace scheme {
|
||||
|
||||
// All methods will be called on the browser process IO thread.
|
||||
class InternalHandlerDelegate {
|
||||
public:
|
||||
class Action {
|
||||
public:
|
||||
Action();
|
||||
|
||||
// Set to the appropriate value or leave empty to have it determined based
|
||||
// on the file extension.
|
||||
std::string mime_type;
|
||||
|
||||
// Option 1: Provide a stream for the resource contents. Set |stream_size|
|
||||
// to the stream size or to -1 if unknown.
|
||||
CefRefPtr<CefStreamReader> stream;
|
||||
int stream_size = -1;
|
||||
|
||||
// Option 2: Provide a base::RefCountedMemory for the resource contents.
|
||||
scoped_refptr<base::RefCountedMemory> bytes;
|
||||
|
||||
// Option 3: Specify a resource id to load static content.
|
||||
int resource_id = -1;
|
||||
|
||||
// Option 4: Redirect to the specified URL.
|
||||
GURL redirect_url;
|
||||
};
|
||||
|
||||
virtual ~InternalHandlerDelegate() = default;
|
||||
|
||||
// Populate |action| and return true if the request was handled.
|
||||
virtual bool OnRequest(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefRequest> request,
|
||||
Action* action) = 0;
|
||||
};
|
||||
|
||||
// Create an internal scheme handler factory. The factory will take ownership of
|
||||
// |delegate|.
|
||||
CefRefPtr<CefSchemeHandlerFactory> CreateInternalHandlerFactory(
|
||||
std::unique_ptr<InternalHandlerDelegate> delegate);
|
||||
|
||||
} // namespace scheme
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_NET_INTERNAL_SCHEME_HANDLER_H_
|
@@ -1,25 +0,0 @@
|
||||
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#include "cef/libcef/browser/net/scheme_handler.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "cef/libcef/browser/net/chrome_scheme_handler.h"
|
||||
#include "cef/libcef/browser/net/devtools_scheme_handler.h"
|
||||
#include "cef/libcef/common/net/scheme_registration.h"
|
||||
#include "cef/libcef/features/runtime.h"
|
||||
#include "content/public/common/url_constants.h"
|
||||
|
||||
namespace scheme {
|
||||
|
||||
void RegisterInternalHandlers(CefIOThreadState* iothread_state) {
|
||||
if (!cef::IsAlloyRuntimeEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
scheme::RegisterChromeDevToolsHandler(iothread_state);
|
||||
}
|
||||
|
||||
} // namespace scheme
|
@@ -1,22 +0,0 @@
|
||||
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#ifndef CEF_LIBCEF_BROWSER_NET_SCHEME_HANDLER_H_
|
||||
#define CEF_LIBCEF_BROWSER_NET_SCHEME_HANDLER_H_
|
||||
#pragma once
|
||||
|
||||
#include "cef/include/cef_frame.h"
|
||||
#include "content/public/browser/browser_context.h"
|
||||
#include "url/gurl.h"
|
||||
|
||||
class CefIOThreadState;
|
||||
|
||||
namespace scheme {
|
||||
|
||||
// Register the internal scheme handlers that can be overridden.
|
||||
void RegisterInternalHandlers(CefIOThreadState* iothread_state);
|
||||
|
||||
} // namespace scheme
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_NET_SCHEME_HANDLER_H_
|
Reference in New Issue
Block a user