Add GN arg to disable Alloy bootstrap (see #3681, see #3685)

Set enable_alloy_bootstrap=false to build with Alloy bootstrap code
removed. Extension API is documented as deprecated in comments but
not compiled out with this arg.
This commit is contained in:
Marshall Greenblatt
2024-04-29 21:09:17 -04:00
parent d666ec5770
commit b5d84c254d
96 changed files with 1243 additions and 516 deletions

View File

@@ -50,10 +50,13 @@
#include "content/public/common/input/native_web_keyboard_event.h"
#include "content/public/common/url_constants.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
#include "net/base/net_errors.h"
#include "ui/events/base_event_utils.h"
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
#include "extensions/common/extension.h"
#endif
using content::KeyboardEventProcessingResult;
namespace {
@@ -75,7 +78,11 @@ CefRefPtr<AlloyBrowserHostImpl> AlloyBrowserHostImpl::Create(
// Expect runtime style to match.
CHECK(platform_delegate->IsAlloyStyle());
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
const bool is_devtools_popup = !!create_params.devtools_opener;
#else
const bool is_devtools_popup = false;
#endif
scoped_refptr<CefBrowserInfo> info =
CefBrowserInfoManager::GetInstance()->CreateBrowserInfo(
@@ -92,6 +99,7 @@ CefRefPtr<AlloyBrowserHostImpl> AlloyBrowserHostImpl::Create(
auto request_context_impl =
static_cast<CefRequestContextImpl*>(create_params.request_context.get());
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
CefRefPtr<CefExtension> cef_extension;
if (create_params.extension) {
auto cef_browser_context = request_context_impl->GetBrowserContext();
@@ -99,24 +107,39 @@ CefRefPtr<AlloyBrowserHostImpl> AlloyBrowserHostImpl::Create(
cef_browser_context->GetExtension(create_params.extension->id());
CHECK(cef_extension);
}
#endif
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
auto platform_delegate_ptr = platform_delegate.get();
#endif
CefRefPtr<AlloyBrowserHostImpl> browser = CreateInternal(
create_params.settings, create_params.client, web_contents,
own_web_contents, info, FromBaseChecked(create_params.devtools_opener),
is_devtools_popup, request_context_impl, std::move(platform_delegate),
cef_extension);
own_web_contents, info,
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
FromBaseChecked(create_params.devtools_opener),
#else
/*opener=*/nullptr,
#endif
is_devtools_popup, request_context_impl, std::move(platform_delegate)
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
,
cef_extension
#endif
);
if (!browser) {
return nullptr;
}
GURL url = url_util::MakeGURL(create_params.url, /*fixup=*/true);
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
if (create_params.extension) {
platform_delegate_ptr->CreateExtensionHost(
create_params.extension, url, create_params.extension_host_type);
} else if (!url.is_empty()) {
} else
#endif
if (!url.is_empty()) {
content::OpenURLParams params(url, content::Referrer(),
WindowOpenDisposition::CURRENT_TAB,
CefFrameHostImpl::kPageTransitionExplicit,
@@ -137,8 +160,12 @@ CefRefPtr<AlloyBrowserHostImpl> AlloyBrowserHostImpl::CreateInternal(
CefRefPtr<AlloyBrowserHostImpl> opener,
bool is_devtools_popup,
CefRefPtr<CefRequestContextImpl> request_context,
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate,
CefRefPtr<CefExtension> extension) {
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
,
CefRefPtr<CefExtension> extension
#endif
) {
CEF_REQUIRE_UIT();
DCHECK(web_contents);
DCHECK(browser_info);
@@ -169,7 +196,12 @@ CefRefPtr<AlloyBrowserHostImpl> AlloyBrowserHostImpl::CreateInternal(
CefRefPtr<AlloyBrowserHostImpl> browser = new AlloyBrowserHostImpl(
settings, client, web_contents, browser_info, opener, request_context,
std::move(platform_delegate), extension);
std::move(platform_delegate)
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
,
extension
#endif
);
browser->InitializeBrowser();
if (!browser->CreateHostWindow()) {
@@ -352,6 +384,7 @@ void AlloyBrowserHostImpl::SetAutoResizeEnabled(bool enabled,
}
}
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
CefRefPtr<CefExtension> AlloyBrowserHostImpl::GetExtension() {
return extension_;
}
@@ -359,6 +392,7 @@ CefRefPtr<CefExtension> AlloyBrowserHostImpl::GetExtension() {
bool AlloyBrowserHostImpl::IsBackgroundHost() {
return is_background_host_;
}
#endif
bool AlloyBrowserHostImpl::CanExecuteChromeCommand(int command_id) {
return false;
@@ -626,11 +660,13 @@ bool AlloyBrowserHostImpl::MaybeAllowNavigation(
return true;
}
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
extensions::ExtensionHost* AlloyBrowserHostImpl::GetExtensionHost() const {
CEF_REQUIRE_UIT();
DCHECK(platform_delegate_);
return platform_delegate_->GetExtensionHost();
}
#endif
void AlloyBrowserHostImpl::OnSetFocus(cef_focus_source_t source) {
if (!CEF_CURRENTLY_ON_UIT()) {
@@ -942,11 +978,13 @@ content::WebContents* AlloyBrowserHostImpl::OpenURLFromTab(
return nullptr;
}
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
bool AlloyBrowserHostImpl::ShouldAllowRendererInitiatedCrossProcessNavigation(
bool is_main_frame_navigation) {
return platform_delegate_->ShouldAllowRendererInitiatedCrossProcessNavigation(
is_main_frame_navigation);
}
#endif
void AlloyBrowserHostImpl::AddNewContents(
content::WebContents* source,
@@ -1088,11 +1126,13 @@ bool AlloyBrowserHostImpl::HandleKeyboardEvent(
return false;
}
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
bool AlloyBrowserHostImpl::PreHandleGestureEvent(
content::WebContents* source,
const blink::WebGestureEvent& event) {
return platform_delegate_->PreHandleGestureEvent(source, event);
}
#endif
bool AlloyBrowserHostImpl::CanDragEnter(content::WebContents* source,
const content::DropData& data,
@@ -1164,10 +1204,14 @@ void AlloyBrowserHostImpl::WebContentsCreated(
// We don't officially own |new_contents| until AddNewContents() is called.
// However, we need to install observers/delegates here.
CefRefPtr<AlloyBrowserHostImpl> browser =
CreateInternal(settings, client, new_contents, /*own_web_contents=*/false,
info, opener, /*is_devtools_popup=*/false, request_context,
std::move(platform_delegate), /*extension=*/nullptr);
CefRefPtr<AlloyBrowserHostImpl> browser = CreateInternal(
settings, client, new_contents, /*own_web_contents=*/false, info, opener,
/*is_devtools_popup=*/false, request_context, std::move(platform_delegate)
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
,
/*extension=*/nullptr
#endif
);
}
void AlloyBrowserHostImpl::RendererUnresponsive(
@@ -1255,10 +1299,12 @@ bool AlloyBrowserHostImpl::CheckMediaAccessPermission(
security_origin, type);
}
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
bool AlloyBrowserHostImpl::IsNeverComposited(
content::WebContents* web_contents) {
return platform_delegate_->IsNeverComposited(web_contents);
}
#endif
content::PictureInPictureResult AlloyBrowserHostImpl::EnterPictureInPicture(
content::WebContents* web_contents) {
@@ -1276,8 +1322,12 @@ void AlloyBrowserHostImpl::ExitPictureInPicture() {
}
bool AlloyBrowserHostImpl::IsBackForwardCacheSupported() {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
return true;
#else
// Disabled with Alloy bootstrap due to issue #3237.
return cef::IsChromeRuntimeEnabled();
#endif
}
content::PreloadingEligibility AlloyBrowserHostImpl::IsPrerender2Supported(
@@ -1399,8 +1449,12 @@ AlloyBrowserHostImpl::AlloyBrowserHostImpl(
scoped_refptr<CefBrowserInfo> browser_info,
CefRefPtr<AlloyBrowserHostImpl> opener,
CefRefPtr<CefRequestContextImpl> request_context,
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate,
CefRefPtr<CefExtension> extension)
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
,
CefRefPtr<CefExtension> extension
#endif
)
: CefBrowserHostBase(settings,
client,
std::move(platform_delegate),
@@ -1408,8 +1462,12 @@ AlloyBrowserHostImpl::AlloyBrowserHostImpl(
request_context),
content::WebContentsObserver(web_contents),
opener_(kNullWindowHandle),
is_windowless_(platform_delegate_->IsWindowless()),
extension_(extension) {
is_windowless_(platform_delegate_->IsWindowless())
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
,
extension_(extension)
#endif
{
contents_delegate_->ObserveWebContents(web_contents);
if (opener.get() && !is_views_hosted_) {

View File

@@ -25,7 +25,10 @@
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_observer.h"
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
#include "extensions/common/mojom/view_type.mojom-forward.h"
#endif
class CefAudioCapturer;
class CefBrowserInfo;
@@ -123,8 +126,10 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
void SetAutoResizeEnabled(bool enabled,
const CefSize& min_size,
const CefSize& max_size) override;
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
CefRefPtr<CefExtension> GetExtension() override;
bool IsBackgroundHost() override;
#endif
bool CanExecuteChromeCommand(int command_id) override;
void ExecuteChromeCommand(int command_id,
cef_window_open_disposition_t disposition) override;
@@ -166,8 +171,10 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
void UpdateDragOperation(ui::mojom::DragOperation operation,
bool document_is_handling_drag);
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
// Accessors that must be called on the UI thread.
extensions::ExtensionHost* GetExtensionHost() const;
#endif
void OnSetFocus(cef_focus_source_t source) override;
@@ -187,8 +194,10 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
const content::OpenURLParams& params,
base::OnceCallback<void(content::NavigationHandle&)>
navigation_handle_callback) override;
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
bool ShouldAllowRendererInitiatedCrossProcessNavigation(
bool is_main_frame_navigation) override;
#endif
void AddNewContents(content::WebContents* source,
std::unique_ptr<content::WebContents> new_contents,
const GURL& target_url,
@@ -219,8 +228,10 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
bool HandleKeyboardEvent(
content::WebContents* source,
const content::NativeWebKeyboardEvent& event) override;
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
bool PreHandleGestureEvent(content::WebContents* source,
const blink::WebGestureEvent& event) override;
#endif
bool CanDragEnter(content::WebContents* source,
const content::DropData& data,
blink::DragOperationsMask operations_allowed) override;
@@ -274,7 +285,9 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
bool CheckMediaAccessPermission(content::RenderFrameHost* render_frame_host,
const url::Origin& security_origin,
blink::mojom::MediaStreamType type) override;
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
bool IsNeverComposited(content::WebContents* web_contents) override;
#endif
content::PictureInPictureResult EnterPictureInPicture(
content::WebContents* web_contents) override;
void ExitPictureInPicture() override;
@@ -309,8 +322,12 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
CefRefPtr<AlloyBrowserHostImpl> opener,
bool is_devtools_popup,
CefRefPtr<CefRequestContextImpl> request_context,
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate,
CefRefPtr<CefExtension> extension);
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
,
CefRefPtr<CefExtension> extension
#endif
);
AlloyBrowserHostImpl(
const CefBrowserSettings& settings,
@@ -319,8 +336,12 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
scoped_refptr<CefBrowserInfo> browser_info,
CefRefPtr<AlloyBrowserHostImpl> opener,
CefRefPtr<CefRequestContextImpl> request_context,
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate,
CefRefPtr<CefExtension> extension);
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
,
CefRefPtr<CefExtension> extension
#endif
);
// Give the platform delegate an opportunity to create the host window.
bool CreateHostWindow();
@@ -331,8 +352,10 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
CefWindowHandle opener_;
const bool is_windowless_;
CefWindowHandle host_window_handle_ = kNullWindowHandle;
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
CefRefPtr<CefExtension> extension_;
bool is_background_host_ = false;
#endif
// Represents the current browser destruction state. Only accessed on the UI
// thread.

View File

@@ -6,6 +6,8 @@
#define CEF_LIBCEF_BROWSER_ALLOY_ALLOY_DOWNLOAD_UTIL_H_
#pragma once
#include "cef/libcef/features/features.h"
class DownloadPrefs;
namespace content {

View File

@@ -7,37 +7,55 @@
#include <memory>
#include "libcef/browser/alloy/alloy_browser_host_impl.h"
#include "libcef/browser/alloy/dialogs/alloy_javascript_dialog_manager_delegate.h"
#include "libcef/browser/extensions/browser_extensions_util.h"
#include "libcef/browser/extensions/extension_background_host.h"
#include "libcef/browser/extensions/extension_system.h"
#include "libcef/browser/extensions/extension_view_host.h"
#include "libcef/browser/extensions/extension_web_contents_observer.h"
#include "libcef/common/extensions/extensions_util.h"
#include "libcef/common/net/url_util.h"
#include "libcef/features/runtime_checks.h"
#include "base/logging.h"
#include "chrome/browser/printing/printing_init.h"
#include "cef/libcef/features/features.h"
#include "chrome/browser/task_manager/web_contents_tags.h"
#include "chrome/browser/ui/prefs/prefs_tab_helper.h"
#include "chrome/browser/ui/tab_helpers.h"
#include "components/find_in_page/find_tab_helper.h"
#include "components/find_in_page/find_types.h"
#include "components/javascript_dialogs/tab_modal_dialog_manager.h"
#include "components/performance_manager/embedder/performance_manager_registry.h"
#include "components/permissions/permission_request_manager.h"
#include "components/zoom/zoom_controller.h"
#include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/public/browser/render_view_host.h"
#include "extensions/browser/process_manager.h"
#include "pdf/pdf_features.h"
#include "third_party/blink/public/mojom/frame/find_in_page.mojom.h"
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
#include "libcef/browser/alloy/dialogs/alloy_javascript_dialog_manager_delegate.h"
#include "libcef/features/runtime_checks.h"
#include "chrome/browser/printing/printing_init.h"
#include "chrome/browser/ui/prefs/prefs_tab_helper.h"
#include "components/javascript_dialogs/tab_modal_dialog_manager.h"
#include "components/permissions/permission_request_manager.h"
#include "components/zoom/zoom_controller.h"
#include "extensions/browser/extension_registry.h"
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
namespace {
const char kAttachedHelpersUserDataKey[] = "CefAttachedHelpers";
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
const extensions::Extension* GetExtensionForUrl(
content::BrowserContext* browser_context,
const GURL& url) {
auto* registry = extensions::ExtensionRegistry::Get(browser_context);
if (!registry) {
return nullptr;
}
std::string extension_id = url.host();
return registry->enabled_extensions().GetByID(extension_id);
}
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
} // namespace
CefBrowserPlatformDelegateAlloy::CefBrowserPlatformDelegateAlloy()
@@ -58,13 +76,13 @@ content::WebContents* CefBrowserPlatformDelegateAlloy::CreateWebContents(
CHECK(browser_context);
scoped_refptr<content::SiteInstance> site_instance;
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
if (extensions::ExtensionsEnabled() && !create_params.url.empty()) {
GURL gurl = url_util::MakeGURL(create_params.url, /*fixup=*/true);
if (!create_params.extension) {
// We might be loading an extension app view where the extension URL is
// provided by the client.
create_params.extension =
extensions::GetExtensionForUrl(browser_context, gurl);
create_params.extension = GetExtensionForUrl(browser_context, gurl);
}
if (create_params.extension) {
if (create_params.extension_host_type ==
@@ -85,6 +103,7 @@ content::WebContents* CefBrowserPlatformDelegateAlloy::CreateWebContents(
DCHECK(site_instance);
}
}
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
content::WebContents::CreateParams wc_create_params(browser_context,
site_instance);
@@ -138,13 +157,16 @@ void CefBrowserPlatformDelegateAlloy::AddNewContents(
return;
}
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
if (extension_host_) {
extension_host_->AddNewContents(source, std::move(new_contents), target_url,
disposition, window_features, user_gesture,
was_blocked);
}
#endif
}
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
bool CefBrowserPlatformDelegateAlloy::
ShouldAllowRendererInitiatedCrossProcessNavigation(
bool is_main_frame_navigation) {
@@ -154,6 +176,7 @@ bool CefBrowserPlatformDelegateAlloy::
}
return true;
}
#endif
void CefBrowserPlatformDelegateAlloy::RenderViewReady() {
ConfigureAutoResize();
@@ -179,6 +202,7 @@ void CefBrowserPlatformDelegateAlloy::BrowserCreated(
std::make_unique<AlloyWebContentsDialogHelper>(web_contents_, this);
}
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
void CefBrowserPlatformDelegateAlloy::CreateExtensionHost(
const extensions::Extension* extension,
const GURL& url,
@@ -219,11 +243,14 @@ extensions::ExtensionHost* CefBrowserPlatformDelegateAlloy::GetExtensionHost()
const {
return extension_host_;
}
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
void CefBrowserPlatformDelegateAlloy::BrowserDestroyed(
CefBrowserHostBase* browser) {
if (primary_) {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
DestroyExtensionHost();
#endif
owned_web_contents_.reset();
}
@@ -265,6 +292,7 @@ void CefBrowserPlatformDelegateAlloy::NotifyMoveOrResizeStarted() {
}
#endif
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
bool CefBrowserPlatformDelegateAlloy::PreHandleGestureEvent(
content::WebContents* source,
const blink::WebGestureEvent& event) {
@@ -281,6 +309,7 @@ bool CefBrowserPlatformDelegateAlloy::IsNeverComposited(
}
return false;
}
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
void CefBrowserPlatformDelegateAlloy::SetAutoResizeEnabled(
bool enabled,
@@ -377,6 +406,7 @@ void CefBrowserPlatformDelegateAlloy::SetOwnedWebContents(
owned_web_contents_.reset(owned_contents);
}
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
void CefBrowserPlatformDelegateAlloy::DestroyExtensionHost() {
if (!extension_host_) {
return;
@@ -402,6 +432,7 @@ void CefBrowserPlatformDelegateAlloy::OnExtensionHostDeleted() {
DCHECK(extension_host_);
extension_host_ = nullptr;
}
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
void CefBrowserPlatformDelegateAlloy::AttachHelpers(
content::WebContents* web_contents) {
@@ -416,6 +447,7 @@ void CefBrowserPlatformDelegateAlloy::AttachHelpers(
web_contents->SetUserData(&kAttachedHelpersUserDataKey,
std::make_unique<base::SupportsUserData::Data>());
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
// Create all the helpers.
if (cef::IsAlloyRuntimeEnabled()) {
find_in_page::FindTabHelper::CreateForWebContents(web_contents);
@@ -427,7 +459,9 @@ void CefBrowserPlatformDelegateAlloy::AttachHelpers(
javascript_dialogs::TabModalDialogManager::CreateForWebContents(
web_contents, CreateAlloyJavaScriptTabModalDialogManagerDelegateDesktop(
web_contents));
} else {
} else
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
{
if (IsWindowless()) {
// Logic from ChromeContentBrowserClientCef::GetWebContentsViewDelegate
// which is not called for windowless browsers. Needs to be done before

View File

@@ -33,14 +33,18 @@ class CefBrowserPlatformDelegateAlloy : public CefBrowserPlatformDelegate {
const blink::mojom::WindowFeatures& window_features,
bool user_gesture,
bool* was_blocked) override;
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
bool ShouldAllowRendererInitiatedCrossProcessNavigation(
bool is_main_frame_navigation) override;
#endif
void RenderViewReady() override;
void BrowserCreated(CefBrowserHostBase* browser) override;
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
void CreateExtensionHost(const extensions::Extension* extension,
const GURL& url,
extensions::mojom::ViewType host_type) override;
extensions::ExtensionHost* GetExtensionHost() const override;
#endif
void BrowserDestroyed(CefBrowserHostBase* browser) override;
web_modal::WebContentsModalDialogHost* GetWebContentsModalDialogHost()
const override;
@@ -48,9 +52,11 @@ class CefBrowserPlatformDelegateAlloy : public CefBrowserPlatformDelegate {
#if BUILDFLAG(IS_WIN) || (BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC))
void NotifyMoveOrResizeStarted() override;
#endif
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
bool PreHandleGestureEvent(content::WebContents* source,
const blink::WebGestureEvent& event) override;
bool IsNeverComposited(content::WebContents* web_contents) override;
#endif
bool IsAlloyStyle() const override { return true; }
void SetAutoResizeEnabled(bool enabled,
const CefSize& min_size,
@@ -83,8 +89,10 @@ class CefBrowserPlatformDelegateAlloy : public CefBrowserPlatformDelegate {
private:
void SetOwnedWebContents(content::WebContents* owned_contents);
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
void DestroyExtensionHost();
void OnExtensionHostDeleted();
#endif
void ConfigureAutoResize();
@@ -105,9 +113,11 @@ class CefBrowserPlatformDelegateAlloy : public CefBrowserPlatformDelegate {
// matches, the find selection rectangle, etc.
find_in_page::FindNotificationDetails last_search_result_;
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
// Used when the browser is hosting an extension.
extensions::ExtensionHost* extension_host_ = nullptr;
bool is_background_host_ = false;
#endif
// Used with auto-resize.
bool auto_resize_enabled_ = false;

View File

@@ -366,6 +366,7 @@ void CefBrowserContext::ClearSchemeHandlerFactories() {
iothread_state_));
}
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
void CefBrowserContext::LoadExtension(
const CefString& root_directory,
CefRefPtr<CefDictionaryValue> manifest,
@@ -392,6 +393,7 @@ bool CefBrowserContext::UnloadExtension(const CefString& extension_id) {
NOTIMPLEMENTED();
return false;
}
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
network::mojom::NetworkContext* CefBrowserContext::GetNetworkContext() {
CEF_REQUIRE_UIT();

View File

@@ -18,6 +18,7 @@
#include "base/functional/callback.h"
#include "base/memory/weak_ptr.h"
#include "base/task/sequenced_task_runner_helpers.h"
#include "cef/libcef/features/features.h"
#include "chrome/common/plugin.mojom.h"
#include "services/network/public/mojom/network_context.mojom.h"
#include "ui/base/page_transition_types.h"
@@ -160,7 +161,8 @@ class CefBrowserContext {
const CefString& domain_name,
CefRefPtr<CefSchemeHandlerFactory> factory);
void ClearSchemeHandlerFactories();
// TODO(chrome-runtime): Make these extension methods pure virtual.
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
virtual void LoadExtension(const CefString& root_directory,
CefRefPtr<CefDictionaryValue> manifest,
CefRefPtr<CefExtensionHandler> handler,
@@ -170,6 +172,7 @@ class CefBrowserContext {
// Called from CefExtensionImpl::Unload().
virtual bool UnloadExtension(const CefString& extension_id);
#endif
// Called from AlloyBrowserHostImpl::DidFinishNavigation to update the table
// of visited links.

View File

@@ -731,6 +731,15 @@ void CefBrowserHostBase::NotifyMoveOrResizeStarted() {
#endif
}
CefRefPtr<CefExtension> CefBrowserHostBase::GetExtension() {
NOTIMPLEMENTED();
return nullptr;
}
bool CefBrowserHostBase::IsBackgroundHost() {
return false;
}
bool CefBrowserHostBase::IsFullscreen() {
if (!CEF_CURRENTLY_ON_UIT()) {
DCHECK(false) << "called on invalid thread";

View File

@@ -22,7 +22,11 @@
#include "base/observer_list.h"
#include "base/synchronization/lock.h"
#include "cef/libcef/features/features.h"
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
#include "extensions/common/mojom/view_type.mojom.h"
#endif
namespace extensions {
class Extension;
@@ -99,9 +103,11 @@ struct CefBrowserCreateParams {
// Browser settings.
CefBrowserSettings settings;
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
// Other browser that opened this DevTools browser. Will be nullptr for non-
// DevTools browsers. Currently used with the alloy runtime only.
CefRefPtr<CefBrowserHostBase> devtools_opener;
#endif
// Request context to use when creating the browser. If nullptr the global
// request context will be used.
@@ -111,12 +117,14 @@ struct CefBrowserCreateParams {
// CefRenderProcessHandler::OnBrowserCreated.
CefRefPtr<CefDictionaryValue> extra_info;
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
// Used when explicitly creating the browser as an extension host via
// ProcessManager::CreateBackgroundHost. Currently used with the alloy
// runtime only.
const extensions::Extension* extension = nullptr;
extensions::mojom::ViewType extension_host_type =
extensions::mojom::ViewType::kInvalid;
#endif
};
// Base class for CefBrowserHost implementations. Includes functionality that is
@@ -251,6 +259,8 @@ class CefBrowserHostBase : public CefBrowserHost,
bool current_only) override;
CefRefPtr<CefNavigationEntry> GetVisibleNavigationEntry() override;
void NotifyMoveOrResizeStarted() override;
CefRefPtr<CefExtension> GetExtension() override;
bool IsBackgroundHost() override;
bool IsFullscreen() override;
void ExitFullscreen(bool will_cause_resize) override;
bool IsRenderProcessUnresponsive() override;

View File

@@ -154,9 +154,11 @@ CefRefPtr<CefBrowser> CefBrowserHost::CreateBrowserSync(
// static
bool CefBrowserCreateParams::IsChromeStyle(const CefWindowInfo* window_info) {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
if (!cef::IsChromeRuntimeEnabled()) {
return false;
}
#endif
if (!window_info) {
return true;
}
@@ -167,9 +169,11 @@ bool CefBrowserCreateParams::IsChromeStyle(const CefWindowInfo* window_info) {
}
bool CefBrowserCreateParams::IsChromeStyle() const {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
if (!cef::IsChromeRuntimeEnabled()) {
return false;
}
#endif
const bool chrome_style_via_window_info = IsChromeStyle(window_info.get());
@@ -206,7 +210,11 @@ void CefBrowserCreateParams::InitWindowInfo(CefWindowInfo* window_info,
window_info->SetAsPopup(nullptr, CefString());
#endif
if (cef::IsChromeRuntimeEnabled() && opener->IsAlloyStyle()) {
if (
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
cef::IsChromeRuntimeEnabled() &&
#endif
opener->IsAlloyStyle()) {
// Give the popup the same runtime style as the opener.
window_info->runtime_style = CEF_RUNTIME_STYLE_ALLOY;
}
@@ -216,10 +224,12 @@ void CefBrowserCreateParams::MaybeSetWindowInfo(
const CefWindowInfo& new_window_info,
bool allow_alloy_style,
bool allow_chrome_style) {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
if (!cef::IsChromeRuntimeEnabled()) {
// Chrome style is not supported wih the Alloy bootstrap.
allow_chrome_style = false;
}
#endif
if (allow_chrome_style && new_window_info.windowless_rendering_enabled) {
// Chrome style is not supported with windowles rendering.
@@ -253,7 +263,11 @@ void CefBrowserCreateParams::MaybeSetWindowInfo(
if (!is_chrome_style ||
chrome_child_window::HasParentHandle(new_window_info)) {
window_info = std::make_unique<CefWindowInfo>(new_window_info);
if (cef::IsChromeRuntimeEnabled() && !allow_chrome_style) {
if (
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
cef::IsChromeRuntimeEnabled() &&
#endif
!allow_chrome_style) {
// Only Alloy style is allowed.
window_info->runtime_style = CEF_RUNTIME_STYLE_ALLOY;
} else if (reset_style) {

View File

@@ -280,7 +280,9 @@ void CefBrowserInfoManager::WebContentsCreated(
bool CefBrowserInfoManager::AddWebContents(content::WebContents* new_contents) {
CEF_REQUIRE_UIT();
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
DCHECK(cef::IsChromeRuntimeEnabled());
#endif
// Pending popup information may be missing in cases where
// chrome::AddWebContents is called directly from the Chrome UI (profile

View File

@@ -118,11 +118,13 @@ void CefBrowserPlatformDelegate::WebContentsDestroyed(
web_contents_ = nullptr;
}
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
bool CefBrowserPlatformDelegate::
ShouldAllowRendererInitiatedCrossProcessNavigation(
bool is_main_frame_navigation) {
return true;
}
#endif
void CefBrowserPlatformDelegate::RenderViewCreated(
content::RenderViewHost* render_view_host) {
@@ -144,6 +146,7 @@ void CefBrowserPlatformDelegate::BrowserCreated(CefBrowserHostBase* browser) {
browser_ = browser;
}
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
void CefBrowserPlatformDelegate::CreateExtensionHost(
const extensions::Extension* extension,
const GURL& url,
@@ -156,6 +159,7 @@ extensions::ExtensionHost* CefBrowserPlatformDelegate::GetExtensionHost()
DCHECK(false);
return nullptr;
}
#endif
void CefBrowserPlatformDelegate::NotifyBrowserCreated() {}
@@ -347,6 +351,7 @@ bool CefBrowserPlatformDelegate::HandleKeyboardEvent(
return false;
}
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
bool CefBrowserPlatformDelegate::PreHandleGestureEvent(
content::WebContents* source,
const blink::WebGestureEvent& event) {
@@ -357,6 +362,7 @@ bool CefBrowserPlatformDelegate::IsNeverComposited(
content::WebContents* web_contents) {
return false;
}
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
// static
void CefBrowserPlatformDelegate::HandleExternalProtocol(const GURL& url) {

View File

@@ -15,13 +15,17 @@
#include "include/views/cef_browser_view.h"
#include "base/functional/callback_forward.h"
#include "extensions/common/mojom/view_type.mojom-forward.h"
#include "cef/libcef/features/features.h"
#include "third_party/blink/public/common/page/drag_operation.h"
#include "third_party/blink/public/mojom/drag/drag.mojom-forward.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/dragdrop/mojom/drag_drop_types.mojom-forward.h"
#include "ui/base/window_open_disposition.h"
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
#include "extensions/common/mojom/view_type.mojom-forward.h"
#endif
class GURL;
namespace blink {
@@ -48,10 +52,12 @@ class WebContents;
class WebContentsView;
} // namespace content
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
namespace extensions {
class Extension;
class ExtensionHost;
} // namespace extensions
#endif
namespace gfx {
class ImageSkia;
@@ -126,9 +132,11 @@ class CefBrowserPlatformDelegate {
// BrowserDestroyed(). Will only be called a single time per instance.
virtual void WebContentsDestroyed(content::WebContents* web_contents);
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
// See WebContentsDelegate documentation.
virtual bool ShouldAllowRendererInitiatedCrossProcessNavigation(
bool is_main_frame_navigation);
#endif
// Called after the RenderViewHost is created.
virtual void RenderViewCreated(content::RenderViewHost* render_view_host);
@@ -141,6 +149,7 @@ class CefBrowserPlatformDelegate {
// from this method.
virtual void BrowserCreated(CefBrowserHostBase* browser);
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
// Called from BrowserHost::Create.
virtual void CreateExtensionHost(const extensions::Extension* extension,
const GURL& url,
@@ -148,6 +157,7 @@ class CefBrowserPlatformDelegate {
// Returns the current extension host.
virtual extensions::ExtensionHost* GetExtensionHost() const;
#endif
// Send any notifications related to browser creation. Called after
// BrowserCreated().
@@ -278,12 +288,14 @@ class CefBrowserPlatformDelegate {
virtual bool HandleKeyboardEvent(
const content::NativeWebKeyboardEvent& event);
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
// See WebContentsDelegate documentation.
virtual bool PreHandleGestureEvent(content::WebContents* source,
const blink::WebGestureEvent& event);
// See WebContentsDelegate documentation.
virtual bool IsNeverComposited(content::WebContents* web_contents);
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
// Invoke platform specific handling for the external protocol.
static void HandleExternalProtocol(const GURL& url);

View File

@@ -16,7 +16,6 @@
#include "libcef/browser/chrome/views/browser_platform_delegate_chrome_child_window.h"
#include "libcef/browser/chrome/views/browser_platform_delegate_chrome_views.h"
#include "libcef/browser/chrome/views/chrome_child_window.h"
#include "libcef/browser/extensions/browser_platform_delegate_background.h"
#include "libcef/browser/views/browser_platform_delegate_views.h"
#if BUILDFLAG(IS_WIN)
@@ -32,6 +31,10 @@
#error A delegate implementation is not available for your platform.
#endif
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
#include "libcef/browser/extensions/browser_platform_delegate_background.h"
#endif
namespace {
std::unique_ptr<CefBrowserPlatformDelegateNative> CreateNativeDelegate(
@@ -109,6 +112,7 @@ std::unique_ptr<CefBrowserPlatformDelegate> CefBrowserPlatformDelegate::Create(
return std::make_unique<CefBrowserPlatformDelegateViews>(
std::move(native_delegate),
static_cast<CefBrowserViewImpl*>(create_params.browser_view.get()));
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
} else if (create_params.extension_host_type ==
extensions::mojom::ViewType::kExtensionBackgroundPage) {
// Creating a background extension host without a window.
@@ -116,6 +120,7 @@ std::unique_ptr<CefBrowserPlatformDelegate> CefBrowserPlatformDelegate::Create(
CreateNativeDelegate(CefWindowInfo(), background_color);
return std::make_unique<CefBrowserPlatformDelegateBackground>(
std::move(native_delegate));
#endif
} else if (create_params.window_info) {
std::unique_ptr<CefBrowserPlatformDelegateNative> native_delegate =
CreateNativeDelegate(*create_params.window_info, background_color);

View File

@@ -780,9 +780,11 @@ std::unique_ptr<BrowserDelegate> BrowserDelegate::Create(
Browser* browser,
scoped_refptr<CreateParams> cef_params,
const Browser* opener) {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
if (!cef::IsChromeRuntimeEnabled()) {
return nullptr;
}
#endif
CefBrowserCreateParams create_params;

View File

@@ -68,35 +68,45 @@ CefRefPtr<ChromeBrowserHostImpl> ChromeBrowserHostImpl::FromBaseChecked(
// static
CefRefPtr<ChromeBrowserHostImpl> ChromeBrowserHostImpl::GetBrowserForHost(
const content::RenderViewHost* host) {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
REQUIRE_CHROME_RUNTIME();
#endif
return FromBaseChecked(CefBrowserHostBase::GetBrowserForHost(host));
}
// static
CefRefPtr<ChromeBrowserHostImpl> ChromeBrowserHostImpl::GetBrowserForHost(
const content::RenderFrameHost* host) {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
REQUIRE_CHROME_RUNTIME();
#endif
return FromBaseChecked(CefBrowserHostBase::GetBrowserForHost(host));
}
// static
CefRefPtr<ChromeBrowserHostImpl> ChromeBrowserHostImpl::GetBrowserForContents(
const content::WebContents* contents) {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
REQUIRE_CHROME_RUNTIME();
#endif
return FromBaseChecked(CefBrowserHostBase::GetBrowserForContents(contents));
}
// static
CefRefPtr<ChromeBrowserHostImpl> ChromeBrowserHostImpl::GetBrowserForGlobalId(
const content::GlobalRenderFrameHostId& global_id) {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
REQUIRE_CHROME_RUNTIME();
#endif
return FromBaseChecked(CefBrowserHostBase::GetBrowserForGlobalId(global_id));
}
// static
CefRefPtr<ChromeBrowserHostImpl> ChromeBrowserHostImpl::GetBrowserForBrowser(
const Browser* browser) {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
REQUIRE_CHROME_RUNTIME();
#endif
// Return the ChromeBrowserHostImpl that is currently active.
// Views-hosted Browsers will contain a single ChromeBrowserHostImpl.
// Otherwise, there will be a ChromeBrowserHostImpl per Tab/WebContents.
@@ -317,14 +327,6 @@ void ChromeBrowserHostImpl::SetAutoResizeEnabled(bool enabled,
NOTIMPLEMENTED();
}
CefRefPtr<CefExtension> ChromeBrowserHostImpl::GetExtension() {
return nullptr;
}
bool ChromeBrowserHostImpl::IsBackgroundHost() {
return false;
}
bool ChromeBrowserHostImpl::CanExecuteChromeCommand(int command_id) {
// Verify that this method is being called on the UI thread.
if (!CEF_CURRENTLY_ON_UIT()) {

View File

@@ -114,8 +114,6 @@ class ChromeBrowserHostImpl : public CefBrowserHostBase {
void SetAutoResizeEnabled(bool enabled,
const CefSize& min_size,
const CefSize& max_size) override;
CefRefPtr<CefExtension> GetExtension() override;
bool IsBackgroundHost() override;
bool CanExecuteChromeCommand(int command_id) override;
void ExecuteChromeCommand(int command_id,
cef_window_open_disposition_t disposition) override;

View File

@@ -28,6 +28,7 @@
#include "base/command_line.h"
#include "base/path_service.h"
#include "cef/libcef/features/features.h"
#include "chrome/browser/chrome_browser_main.h"
#include "chrome/browser/net/system_network_context_manager.h"
#include "chrome/browser/profiles/profile.h"
@@ -102,8 +103,10 @@ void ChromeContentBrowserClientCef::AppendExtraCommandLineSwitches(
ChromeContentBrowserClient::AppendExtraCommandLineSwitches(command_line,
child_process_id);
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
// Necessary to launch sub-processes in the correct mode.
command_line->AppendSwitch(switches::kEnableChromeRuntime);
#endif
// Necessary to populate DIR_USER_DATA in sub-processes.
// See resource_util.cc GetUserDataPath.

View File

@@ -4,14 +4,19 @@
#include "libcef/browser/devtools/devtools_window_runner.h"
#include "libcef/browser/alloy/devtools/alloy_devtools_window_runner.h"
#include "libcef/browser/chrome/chrome_devtools_window_runner.h"
#include "libcef/features/runtime.h"
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
#include "libcef/browser/alloy/devtools/alloy_devtools_window_runner.h"
#endif
// static
std::unique_ptr<CefDevToolsWindowRunner> CefDevToolsWindowRunner::Create() {
if (cef::IsChromeRuntimeEnabled()) {
return std::make_unique<ChromeDevToolsWindowRunner>();
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
if (cef::IsAlloyRuntimeEnabled()) {
return std::make_unique<AlloyDevToolsWindowRunner>();
}
return std::make_unique<AlloyDevToolsWindowRunner>();
#endif
return std::make_unique<ChromeDevToolsWindowRunner>();
}

View File

@@ -12,7 +12,9 @@ namespace cef {
// static
std::unique_ptr<cef::DownloadManagerDelegate> DownloadManagerDelegate::Create(
content::DownloadManager* download_manager) {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
REQUIRE_CHROME_RUNTIME();
#endif
return std::make_unique<CefDownloadManagerDelegateImpl>(
download_manager, /*alloy_bootstrap=*/false);
}

View File

@@ -4,20 +4,10 @@
#include "libcef/browser/extensions/browser_extensions_util.h"
#include "libcef/browser/alloy/alloy_browser_host_impl.h"
#include "libcef/browser/browser_context.h"
#include "libcef/browser/browser_info_manager.h"
#include "libcef/browser/thread_util.h"
#include "libcef/common/extensions/extensions_util.h"
#include "libcef/features/runtime_checks.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/printing/print_preview_dialog_controller.h"
#include "content/browser/browser_plugin/browser_plugin_guest.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_plugin_guest_manager.h"
#include "extensions/browser/extension_registry.h"
namespace extensions {
@@ -73,48 +63,4 @@ bool IsPrintPreviewDialog(const content::WebContents* web_contents) {
return !!GetInitiatorForPrintPreviewDialog(web_contents);
}
CefRefPtr<AlloyBrowserHostImpl> GetBrowserForTabId(
int tab_id,
content::BrowserContext* browser_context) {
REQUIRE_ALLOY_RUNTIME();
CEF_REQUIRE_UIT();
DCHECK(browser_context);
if (tab_id < 0 || !browser_context) {
return nullptr;
}
auto cef_browser_context =
CefBrowserContext::FromBrowserContext(browser_context);
for (const auto& browser_info :
CefBrowserInfoManager::GetInstance()->GetBrowserInfoList()) {
auto current_browser =
AlloyBrowserHostImpl::FromBaseChecked(browser_info->browser());
if (current_browser && current_browser->GetIdentifier() == tab_id) {
// Make sure we're operating in the same CefBrowserContext.
if (CefBrowserContext::FromBrowserContext(
current_browser->GetBrowserContext()) == cef_browser_context) {
return current_browser;
} else {
LOG(WARNING) << "Browser with tabId " << tab_id
<< " cannot be accessed because is uses a different "
"CefRequestContext";
break;
}
}
}
return nullptr;
}
const Extension* GetExtensionForUrl(content::BrowserContext* browser_context,
const GURL& url) {
ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context);
if (!registry) {
return nullptr;
}
std::string extension_id = url.host();
return registry->enabled_extensions().GetByID(extension_id);
}
} // namespace extensions

View File

@@ -5,23 +5,12 @@
#ifndef CEF_LIBCEF_BROWSER_EXTENSIONS_BROWSER_EXTENSIONS_UTIL_H_
#define CEF_LIBCEF_BROWSER_EXTENSIONS_BROWSER_EXTENSIONS_UTIL_H_
#include <vector>
#include "include/internal/cef_ptr.h"
#include "url/gurl.h"
namespace content {
class BrowserContext;
class WebContents;
} // namespace content
class AlloyBrowserHostImpl;
namespace extensions {
class Extension;
// Returns the WebContents that owns the specified |guest|, if any.
content::WebContents* GetOwnerForGuestContents(
const content::WebContents* guest);
@@ -30,18 +19,6 @@ content::WebContents* GetOwnerForGuestContents(
bool IsBrowserPluginGuest(const content::WebContents* web_contents);
bool IsPrintPreviewDialog(const content::WebContents* web_contents);
// Returns the browser matching |tab_id| and |browser_context|. Returns false if
// |tab_id| is < 0 or a matching browser cannot be found within
// |browser_context|. Similar in concept to ExtensionTabUtil::GetTabById.
CefRefPtr<AlloyBrowserHostImpl> GetBrowserForTabId(
int tab_id,
content::BrowserContext* browser_context);
// Returns the extension associated with |url| in |profile|. Returns nullptr
// if the extension does not exist.
const Extension* GetExtensionForUrl(content::BrowserContext* browser_context,
const GURL& url);
} // namespace extensions
#endif // CEF_LIBCEF_BROWSER_EXTENSIONS_BROWSER_EXTENSIONS_UTIL_H_

View File

@@ -6,7 +6,9 @@
#include <memory>
#include "libcef/browser/alloy/alloy_browser_host_impl.h"
#include "libcef/browser/browser_context.h"
#include "libcef/browser/browser_info_manager.h"
#include "libcef/browser/extensions/browser_extensions_util.h"
#include "libcef/browser/extensions/extension_system.h"
#include "libcef/browser/thread_util.h"
@@ -135,6 +137,39 @@ class CefGetExtensionLoadFileCallbackImpl
IMPLEMENT_REFCOUNTING(CefGetExtensionLoadFileCallbackImpl);
};
CefRefPtr<AlloyBrowserHostImpl> GetBrowserForTabId(
int tab_id,
content::BrowserContext* browser_context) {
CEF_REQUIRE_UIT();
DCHECK(browser_context);
if (tab_id < 0 || !browser_context) {
return nullptr;
}
auto cef_browser_context =
CefBrowserContext::FromBrowserContext(browser_context);
for (const auto& browser_info :
CefBrowserInfoManager::GetInstance()->GetBrowserInfoList()) {
auto current_browser =
AlloyBrowserHostImpl::FromBaseChecked(browser_info->browser());
if (current_browser && current_browser->GetIdentifier() == tab_id) {
// Make sure we're operating in the same CefBrowserContext.
if (CefBrowserContext::FromBrowserContext(
current_browser->GetBrowserContext()) == cef_browser_context) {
return current_browser;
} else {
LOG(WARNING) << "Browser with tabId " << tab_id
<< " cannot be accessed because is uses a different "
"CefRequestContext";
break;
}
}
}
return nullptr;
}
} // namespace
CefExtensionFunctionDetails::CefExtensionFunctionDetails(

View File

@@ -4,7 +4,6 @@
#include "libcef/browser/iothread_state.h"
#include "libcef/browser/net/scheme_handler.h"
#include "libcef/browser/thread_util.h"
#include "libcef/common/net/scheme_registration.h"
@@ -15,13 +14,20 @@
#include "content/browser/resource_context_impl.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/global_routing_id.h"
#include "url/gurl.h"
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
#include "libcef/browser/net/scheme_handler.h"
#endif
CefIOThreadState::CefIOThreadState() {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
// Using base::Unretained() is safe because both this callback and possible
// deletion of |this| will execute on the IO thread, and this callback will
// be executed first.
CEF_POST_TASK(CEF_IOT, base::BindOnce(&CefIOThreadState::InitOnIOThread,
base::Unretained(this)));
#endif
}
CefIOThreadState::~CefIOThreadState() {
@@ -83,8 +89,10 @@ void CefIOThreadState::ClearSchemeHandlerFactories() {
scheme_handler_factory_map_.clear();
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
// Restore the default internal handlers.
scheme::RegisterInternalHandlers(this);
#endif
}
CefRefPtr<CefSchemeHandlerFactory> CefIOThreadState::GetSchemeHandlerFactory(
@@ -121,9 +129,11 @@ CefRefPtr<CefSchemeHandlerFactory> CefIOThreadState::GetSchemeHandlerFactory(
return nullptr;
}
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
void CefIOThreadState::InitOnIOThread() {
CEF_REQUIRE_IOT();
// Add the default internal handlers.
scheme::RegisterInternalHandlers(this);
}
#endif

View File

@@ -9,9 +9,9 @@
#include "include/cef_request_context.h"
#include "include/cef_request_context_handler.h"
#include "include/cef_scheme.h"
#include "libcef/browser/request_context_handler_map.h"
#include "cef/libcef/features/features.h"
#include "content/public/browser/browser_thread.h"
namespace content {
@@ -54,7 +54,9 @@ class CefIOThreadState : public base::RefCountedThreadSafe<
~CefIOThreadState();
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
void InitOnIOThread();
#endif
// Map IDs to CefRequestContextHandler objects.
CefRequestContextHandlerMap handler_map_;

View File

@@ -7,7 +7,6 @@
#include "libcef/browser/browser_message_loop.h"
#include "libcef/browser/thread_util.h"
#include "libcef/common/alloy/alloy_main_runner_delegate.h"
#include "libcef/common/cef_switches.h"
#include "libcef/common/chrome/chrome_main_runner_delegate.h"
#include "libcef/features/runtime.h"
@@ -47,29 +46,39 @@
#include "sandbox/win/src/sandbox_types.h"
#endif
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
#include "libcef/common/alloy/alloy_main_runner_delegate.h"
#endif
namespace {
enum class RuntimeType {
UNINITIALIZED,
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
ALLOY,
#endif
CHROME,
};
RuntimeType g_runtime_type = RuntimeType::UNINITIALIZED;
std::unique_ptr<CefMainRunnerDelegate> MakeDelegate(
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
RuntimeType type,
#endif
CefMainRunnerHandler* runner,
CefSettings* settings,
CefRefPtr<CefApp> application) {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
if (type == RuntimeType::ALLOY) {
g_runtime_type = RuntimeType::ALLOY;
return std::make_unique<AlloyMainRunnerDelegate>(runner, settings,
application);
} else {
g_runtime_type = RuntimeType::CHROME;
return std::make_unique<ChromeMainRunnerDelegate>(runner, settings,
application);
}
#endif
g_runtime_type = RuntimeType::CHROME;
return std::make_unique<ChromeMainRunnerDelegate>(runner, settings,
application);
}
// Based on components/crash/core/app/run_as_crashpad_handler_win.cc
@@ -258,10 +267,18 @@ bool CefMainRunner::Initialize(CefSettings* settings,
void* windows_sandbox_info,
bool* initialized,
base::OnceClosure context_initialized) {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
LOG_IF(WARNING, !settings->chrome_runtime)
<< "Alloy bootstrap is deprecated and will be removed in ~M127. See "
"https://github.com/chromiumembedded/cef/issues/3685";
#endif
DCHECK(!main_delegate_);
main_delegate_ = MakeDelegate(
settings->chrome_runtime ? RuntimeType::CHROME : RuntimeType::ALLOY, this,
settings, application);
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
settings->chrome_runtime ? RuntimeType::CHROME : RuntimeType::ALLOY,
#endif
this, settings, application);
exit_code_ =
ContentMainInitialize(args, windows_sandbox_info, &settings->no_sandbox);
@@ -373,11 +390,13 @@ int CefMainRunner::RunAsHelperProcess(const CefMainArgs& args,
return -1;
}
auto runtime_type = command_line.HasSwitch(switches::kEnableChromeRuntime)
? RuntimeType::CHROME
: RuntimeType::ALLOY;
auto main_delegate = MakeDelegate(runtime_type, /*runner=*/nullptr,
/*settings=*/nullptr, application);
auto main_delegate = MakeDelegate(
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
command_line.HasSwitch(switches::kEnableChromeRuntime)
? RuntimeType::CHROME
: RuntimeType::ALLOY,
#endif
/*runner=*/nullptr, /*settings=*/nullptr, application);
main_delegate->BeforeExecuteProcess(args);
int result;
@@ -584,9 +603,11 @@ void CefMainRunner::FinishShutdownOnUIThread() {
// From libcef/features/runtime.h:
namespace cef {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
bool IsAlloyRuntimeEnabled() {
return g_runtime_type == RuntimeType::ALLOY;
}
#endif
bool IsChromeRuntimeEnabled() {
return g_runtime_type == RuntimeType::CHROME;

View File

@@ -6,18 +6,89 @@
#include "include/cef_permission_handler.h"
#include "libcef/browser/browser_host_base.h"
#include "libcef/browser/media_capture_devices_dispatcher.h"
#include "libcef/browser/media_stream_registrar.h"
#include "libcef/browser/thread_util.h"
#include "libcef/common/cef_switches.h"
#include "libcef/features/runtime.h"
#include "base/command_line.h"
#include "base/functional/callback_helpers.h"
#include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
#include "third_party/blink/public/mojom/mediastream/media_stream.mojom.h"
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
#include "libcef/browser/media_capture_devices_dispatcher.h"
#endif
namespace media_access_query {
namespace {
const blink::MediaStreamDevice* FindDefaultDeviceWithId(
const blink::MediaStreamDevices& devices,
const std::string& device_id) {
if (devices.empty()) {
return nullptr;
}
blink::MediaStreamDevices::const_iterator iter = devices.begin();
for (; iter != devices.end(); ++iter) {
if (iter->id == device_id) {
return &(*iter);
}
}
return &(*devices.begin());
}
void GetRequestedDeviceChrome(const std::string& requested_device_id,
bool audio,
bool video,
blink::MediaStreamDevices* devices) {
CEF_REQUIRE_UIT();
DCHECK(audio || video);
auto* dispatcher = MediaCaptureDevicesDispatcher::GetInstance();
if (audio) {
const blink::MediaStreamDevices& audio_devices =
dispatcher->GetAudioCaptureDevices();
const blink::MediaStreamDevice* const device =
FindDefaultDeviceWithId(audio_devices, requested_device_id);
if (device) {
devices->push_back(*device);
}
}
if (video) {
const blink::MediaStreamDevices& video_devices =
dispatcher->GetVideoCaptureDevices();
const blink::MediaStreamDevice* const device =
FindDefaultDeviceWithId(video_devices, requested_device_id);
if (device) {
devices->push_back(*device);
}
}
}
// Helper for picking the device that was requested for an OpenDevice request.
// If the device requested is not available it will revert to using the first
// available one instead or will return an empty list if no devices of the
// requested kind are present. Called on the UI thread.
void GetRequestedDevice(const std::string& requested_device_id,
bool audio,
bool video,
blink::MediaStreamDevices* devices) {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
if (cef::IsAlloyRuntimeEnabled()) {
CefMediaCaptureDevicesDispatcher::GetInstance()->GetRequestedDevice(
requested_device_id, audio, video, devices);
return;
}
#endif
GetRequestedDeviceChrome(requested_device_id, audio, video, devices);
}
class CefMediaAccessQuery {
public:
using CallbackType = content::MediaResponseCallback;
@@ -136,9 +207,8 @@ class CefMediaAccessQuery {
!request_.requested_audio_device_ids.front().empty()) {
// Pick the desired device or fall back to the first available of the
// given type.
CefMediaCaptureDevicesDispatcher::GetInstance()->GetRequestedDevice(
request_.requested_audio_device_ids.front(), true, false,
&audio_devices);
GetRequestedDevice(request_.requested_audio_device_ids.front(), true,
false, &audio_devices);
}
if (device_video_requested() &&
@@ -146,9 +216,8 @@ class CefMediaAccessQuery {
!request_.requested_video_device_ids.front().empty()) {
// Pick the desired device or fall back to the first available of the
// given type.
CefMediaCaptureDevicesDispatcher::GetInstance()->GetRequestedDevice(
request_.requested_video_device_ids.front(), false, true,
&video_devices);
GetRequestedDevice(request_.requested_video_device_ids.front(), false,
true, &video_devices);
}
if (desktop_audio_requested()) {

View File

@@ -13,7 +13,6 @@
#include "include/cef_version.h"
#include "libcef/browser/extensions/chrome_api_registration.h"
#include "libcef/browser/frame_host_impl.h"
#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"
@@ -23,6 +22,7 @@
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted_memory.h"
#include "base/path_service.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
@@ -163,6 +163,7 @@ 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.
@@ -179,6 +180,7 @@ bool IsAllowedWebUIHost(const std::string& host) {
return false;
}
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
// Additional debug URLs that are not included in chrome::kChromeDebugURLs.
const char* kAllowedDebugURLs[] = {
@@ -294,63 +296,65 @@ 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;
}
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
if (cef::IsAlloyRuntimeEnabled()) {
static const char kDevURL[] = "https://developer.chrome.com/extensions/";
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";
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;
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;
}
// 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";
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)
if (has_top_level_name) {
// End the last top-level API entry.
html += "</ul></li>\n";
}
html += "</ul>\n</body>\n</html>";
*output = html;
// 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;
}
@@ -534,6 +538,7 @@ 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);
@@ -549,6 +554,18 @@ class CefWebUIControllerFactory : public content::WebUIControllerFactory {
}
return false;
#else // !BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
if (url.SchemeIs(content::kChromeDevToolsScheme)) {
return DevToolsUIBindings::IsValidFrontendURL(url);
}
if (!url.SchemeIs(content::kChromeUIScheme) &&
!url.SchemeIs(content::kChromeUIUntrustedScheme)) {
return false;
}
return true;
#endif // ! BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
}
// Returns true if WebUI is allowed to make network requests.
@@ -650,6 +667,7 @@ class CefWebUIControllerFactory : public content::WebUIControllerFactory {
}
static void BrowserURLHandlerCreated(content::BrowserURLHandler* handler) {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
// For Chrome runtime this is registered in
// ChromeContentBrowserClient::BrowserURLHandlerCreated().
if (cef::IsAlloyRuntimeEnabled()) {
@@ -657,6 +675,7 @@ class CefWebUIControllerFactory : public content::WebUIControllerFactory {
handler->AddHandlerPair(&HandleChromeAboutAndChromeSyncRewrite,
content::BrowserURLHandler::null_handler());
}
#endif
// chrome: & friends. For Chrome runtime the default registration is
// disabled is ChromeContentBrowserClient::BrowserURLHandlerCreated().

View File

@@ -254,7 +254,11 @@ std::unique_ptr<permissions::PermissionPrompt> CreatePermissionPromptImpl(
bool* default_handling) {
CEF_REQUIRE_UIT();
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
bool is_alloy_style = cef::IsAlloyRuntimeEnabled();
#else
bool is_alloy_style = false;
#endif
if (auto browser = CefBrowserHostBase::GetBrowserForContents(web_contents)) {
is_alloy_style = browser->IsAlloyStyle();

View File

@@ -6,8 +6,15 @@
#include "libcef/browser/browser_context.h"
#include "libcef/browser/context.h"
#include "libcef/browser/media_capture_devices_dispatcher.h"
#include "libcef/browser/prefs/pref_registrar.h"
#include "chrome/browser/profiles/profile.h"
#include "components/language/core/browser/pref_names.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
#include "libcef/browser/media_capture_devices_dispatcher.h"
#include "libcef/browser/prefs/pref_store.h"
#include "libcef/browser/prefs/renderer_prefs.h"
#include "libcef/common/cef_switches.h"
@@ -26,7 +33,6 @@
#include "chrome/browser/prefs/chrome_command_line_pref_store.h"
#include "chrome/browser/preloading/preloading_prefs.h"
#include "chrome/browser/printing/print_preview_sticky_settings.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_key.h"
#include "chrome/browser/ssl/ssl_config_service_manager.h"
#include "chrome/browser/supervised_user/supervised_user_settings_service_factory.h"
@@ -47,7 +53,6 @@
#include "components/flags_ui/pref_service_flags_storage.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/language/core/browser/language_prefs.h"
#include "components/language/core/browser/pref_names.h"
#include "components/media_device_salt/media_device_id_salt.h"
#include "components/permissions/permission_actions_history.h"
#include "components/permissions/permission_hats_trigger_helper.h"
@@ -55,8 +60,6 @@
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/json_pref_store.h"
#include "components/prefs/pref_filter.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/privacy_sandbox/privacy_sandbox_prefs.h"
#include "components/proxy_config/pref_proxy_config_tracker_impl.h"
#include "components/proxy_config/proxy_config_dictionary.h"
@@ -79,6 +82,7 @@
#if BUILDFLAG(IS_WIN)
#include "components/os_crypt/sync/os_crypt.h"
#endif
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
namespace browser_prefs {
@@ -108,10 +112,12 @@ std::string GetAcceptLanguageListSetting(Profile* profile) {
return std::string();
}
} // namespace
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
constexpr char kUserPrefsFileName[] = "UserPrefs.json";
constexpr char kLocalPrefsFileName[] = "LocalPrefs.json";
#endif
const char kUserPrefsFileName[] = "UserPrefs.json";
const char kLocalPrefsFileName[] = "LocalPrefs.json";
} // namespace
void RegisterLocalStatePrefs(PrefRegistrySimple* registry) {
pref_registrar::RegisterCustomPrefs(CEF_PREFERENCES_TYPE_GLOBAL, registry);
@@ -122,6 +128,7 @@ void RegisterProfilePrefs(PrefRegistrySimple* registry) {
registry);
}
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
const base::FilePath& cache_path,
bool persist_user_preferences) {
@@ -349,6 +356,7 @@ std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
// Build the PrefService that manages the PrefRegistry and PrefStores.
return factory.CreateSyncable(registry.get());
}
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
std::string GetAcceptLanguageList(Profile* profile) {
// Always prefer to the CEF settings configuration, if specified.

View File

@@ -6,30 +6,36 @@
#define CEF_LIBCEF_BROWSER_PREFS_BROWSER_PREFS_H_
#include <memory>
#include <string>
#include "cef/libcef/features/features.h"
class PrefRegistrySimple;
class Profile;
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
namespace base {
class FilePath;
}
class PrefRegistrySimple;
class PrefService;
class Profile;
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
namespace browser_prefs {
// Name for the user prefs JSON file.
extern const char kUserPrefsFileName[];
// Register preferences specific to CEF.
// Called from chrome/browser/prefs/browser_prefs.cc
void RegisterLocalStatePrefs(PrefRegistrySimple* registry);
void RegisterProfilePrefs(PrefRegistrySimple* registry);
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
// Create the PrefService used to manage pref registration and storage.
// |profile| will be nullptr for the system-level PrefService. Used with the
// Alloy runtime only.
std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
const base::FilePath& cache_path,
bool persist_user_preferences);
#endif
// Returns the value for populating the accept-language HTTP request header.
// |browser_context| and/or |browser| may be nullptr. If |expand| is true then

View File

@@ -4,15 +4,18 @@
#include "libcef/browser/prefs/renderer_prefs.h"
#include <string>
#include "libcef/common/cef_switches.h"
#include "base/command_line.h"
#include "content/public/common/content_switches.h"
#include "third_party/blink/public/common/web_preferences/web_preferences.h"
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
#include "libcef/browser/alloy/alloy_browser_host_impl.h"
#include "libcef/browser/context.h"
#include "libcef/common/cef_switches.h"
#include "libcef/common/extensions/extensions_util.h"
#include "libcef/features/runtime_checks.h"
#include "base/command_line.h"
#include "base/i18n/character_encoding.h"
#include "base/memory/ptr_util.h"
#include "base/values.h"
@@ -41,12 +44,14 @@
#include "extensions/common/constants.h"
#include "media/media_buildflags.h"
#include "third_party/blink/public/common/peerconnection/webrtc_ip_handling_policy.h"
#include "third_party/blink/public/common/web_preferences/web_preferences.h"
#include "ui/color/color_provider_key.h"
#include "ui/native_theme/native_theme.h"
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
namespace renderer_prefs {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
namespace {
// Chrome preferences.
@@ -266,6 +271,8 @@ void SetCommandLinePrefDefaults(CommandLinePrefStore* prefs) {
}
}
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
void SetDefaultPrefs(blink::web_pref::WebPreferences& web) {
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
@@ -358,6 +365,8 @@ void SetCefPrefs(const CefBrowserSettings& cef,
}
}
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry,
const std::string& locale) {
PrefsTabHelper::RegisterProfilePrefs(registry, locale);
@@ -457,4 +466,6 @@ bool PopulateWebPreferencesAfterNavigation(
web_contents, native_theme);
}
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
} // namespace renderer_prefs

View File

@@ -6,16 +6,21 @@
#define CEF_LIBCEF_BROWSER_PREFS_RENDERER_PREFS_H_
#pragma once
#include <string>
#include "include/internal/cef_types_wrappers.h"
#include "third_party/skia/include/core/SkColor.h"
#include "cef/libcef/features/features.h"
class CommandLinePrefStore;
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
#include "third_party/skia/include/core/SkColor.h"
#endif
namespace blink::web_pref {
struct WebPreferences;
}
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
namespace content {
class RenderViewHost;
class WebContents;
@@ -25,8 +30,12 @@ namespace user_prefs {
class PrefRegistrySyncable;
}
class CommandLinePrefStore;
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
namespace renderer_prefs {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
// Register additional renderer-related preferences.
void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry,
const std::string& locale);
@@ -35,6 +44,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry,
// available via the PrefService. Chromium command-line flags should not exist
// for these preferences.
void SetCommandLinePrefDefaults(CommandLinePrefStore* prefs);
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
// Set default values based on CEF command-line flags for preferences that are
// not available via the PrefService. Chromium command-line flags should not
@@ -45,6 +55,7 @@ void SetDefaultPrefs(blink::web_pref::WebPreferences& web);
void SetCefPrefs(const CefBrowserSettings& cef,
blink::web_pref::WebPreferences& web);
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
// Populate WebPreferences based on a combination of command-line values,
// PrefService and CefBrowserSettings.
void PopulateWebPreferences(content::RenderViewHost* rvh,
@@ -53,6 +64,7 @@ void PopulateWebPreferences(content::RenderViewHost* rvh,
bool PopulateWebPreferencesAfterNavigation(
content::WebContents* web_contents,
blink::web_pref::WebPreferences& web);
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
} // namespace renderer_prefs

View File

@@ -490,6 +490,7 @@ void CefRequestContextImpl::LoadExtension(
const CefString& root_directory,
CefRefPtr<CefDictionaryValue> manifest,
CefRefPtr<CefExtensionHandler> handler) {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
GetBrowserContext(content::GetUIThreadTaskRunner({}),
base::BindOnce(
[](const CefString& root_directory,
@@ -505,20 +506,34 @@ void CefRequestContextImpl::LoadExtension(
},
root_directory, manifest, handler,
CefRefPtr<CefRequestContextImpl>(this)));
#else
NOTIMPLEMENTED();
#endif
}
bool CefRequestContextImpl::DidLoadExtension(const CefString& extension_id) {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
CefRefPtr<CefExtension> extension = GetExtension(extension_id);
// GetLoaderContext() will return NULL for internal extensions.
return extension && IsSame(extension->GetLoaderContext());
#else
NOTIMPLEMENTED();
return false;
#endif
}
bool CefRequestContextImpl::HasExtension(const CefString& extension_id) {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
return !!GetExtension(extension_id);
#else
NOTIMPLEMENTED();
return false;
#endif
}
bool CefRequestContextImpl::GetExtensions(
std::vector<CefString>& extension_ids) {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
extension_ids.clear();
if (!VerifyBrowserContext()) {
@@ -526,15 +541,24 @@ bool CefRequestContextImpl::GetExtensions(
}
return browser_context()->GetExtensions(extension_ids);
#else
NOTIMPLEMENTED();
return false;
#endif
}
CefRefPtr<CefExtension> CefRequestContextImpl::GetExtension(
const CefString& extension_id) {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
if (!VerifyBrowserContext()) {
return nullptr;
}
return browser_context()->GetExtension(extension_id);
#else
NOTIMPLEMENTED();
return nullptr;
#endif
}
CefRefPtr<CefMediaRouter> CefRequestContextImpl::GetMediaRouter(

View File

@@ -40,12 +40,17 @@ std::optional<cef_gesture_command_t> GetGestureCommand(
bool ComputeAlloyStyle(CefBrowserViewDelegate* cef_delegate,
bool is_devtools_popup) {
// Alloy style is not supported with Chrome DevTools popups.
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
const bool supports_alloy_style =
cef::IsAlloyRuntimeEnabled() || !is_devtools_popup;
const bool supports_chrome_style = cef::IsChromeRuntimeEnabled();
const auto default_style = cef::IsAlloyRuntimeEnabled()
? CEF_RUNTIME_STYLE_ALLOY
: CEF_RUNTIME_STYLE_CHROME;
#else
const bool supports_alloy_style = !is_devtools_popup;
const auto default_style = CEF_RUNTIME_STYLE_CHROME;
#endif
auto result_style = default_style;
@@ -59,12 +64,17 @@ bool ComputeAlloyStyle(CefBrowserViewDelegate* cef_delegate,
"Chrome style is supported";
}
} else if (requested_style == CEF_RUNTIME_STYLE_CHROME) {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
if (supports_chrome_style) {
result_style = requested_style;
} else {
LOG(ERROR) << "GetBrowserRuntimeStyle() requested Chrome style; only "
"Alloy style is supported";
}
#else
// Chrome style is always supported.
result_style = requested_style;
#endif
}
}

View File

@@ -356,15 +356,20 @@ void UpdateModalDialogPosition(views::Widget* widget,
}
bool ComputeAlloyStyle(CefWindowDelegate* cef_delegate) {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
const bool supports_chrome_style = cef::IsChromeRuntimeEnabled();
const auto default_style = cef::IsAlloyRuntimeEnabled()
? CEF_RUNTIME_STYLE_ALLOY
: CEF_RUNTIME_STYLE_CHROME;
#else
const auto default_style = CEF_RUNTIME_STYLE_CHROME;
#endif
auto result_style = default_style;
if (cef_delegate) {
auto requested_style = cef_delegate->GetWindowRuntimeStyle();
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
if (requested_style == CEF_RUNTIME_STYLE_ALLOY) {
// Alloy style is always supported.
result_style = requested_style;
@@ -376,6 +381,11 @@ bool ComputeAlloyStyle(CefWindowDelegate* cef_delegate) {
"Alloy style is supported";
}
}
#else
if (requested_style != CEF_RUNTIME_STYLE_DEFAULT) {
result_style = requested_style;
}
#endif
}
return result_style == CEF_RUNTIME_STYLE_ALLOY;

View File

@@ -5,7 +5,6 @@
#include "libcef/common/app_manager.h"
#include "libcef/common/net/scheme_info.h"
#include "libcef/common/net/scheme_registration.h"
#include "libcef/common/scheme_registrar_impl.h"
#include "base/command_line.h"
@@ -18,6 +17,10 @@
#include "base/path_service.h"
#endif
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
#include "libcef/common/net/scheme_registration.h"
#endif
namespace {
CefAppManager* g_manager = nullptr;
@@ -88,7 +91,9 @@ void CefAppManager::AddAdditionalSchemes(
schemeRegistrar.GetSchemes(schemes);
}
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
scheme::AddInternalSchemes(schemes);
#endif
scheme_info_list_locked_ = true;
}

View File

@@ -108,8 +108,10 @@ const char kDisableNewBrowserInfoTimeout[] = "disable-new-browser-info-timeout";
// File used for logging DevTools protocol messages.
const char kDevToolsProtocolLogFile[] = "devtools-protocol-log-file";
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
// Enable use of the Chrome runtime in CEF. See issue #2969 for details.
const char kEnableChromeRuntime[] = "enable-chrome-runtime";
#endif
// Delegate all login requests to the client GetAuthCredentials callback when
// using the Chrome runtime.

View File

@@ -9,6 +9,7 @@
#pragma once
#include "build/build_config.h"
#include "cef/libcef/features/features.h"
namespace switches {
@@ -52,7 +53,9 @@ extern const char kDisablePdfExtension[];
extern const char kEnablePrintPreview[];
extern const char kDisableNewBrowserInfoTimeout[];
extern const char kDevToolsProtocolLogFile[];
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
extern const char kEnableChromeRuntime[];
#endif
extern const char kDisableChromeLoginPrompt[];
extern const char kUserAgentProductAndVersion[];
extern const char kDisableRequestHandlingForTesting[];

View File

@@ -5,6 +5,8 @@
#ifndef CEF_LIBCEF_COMMON_EXTENSIONS_EXTENSIONS_UTIL_H_
#define CEF_LIBCEF_COMMON_EXTENSIONS_EXTENSIONS_UTIL_H_
#include "cef/libcef/features/runtime.h"
namespace extensions {
// Returns true if extensions have not been disabled via the command-line.

View File

@@ -4,8 +4,6 @@
#include "libcef/common/net/scheme_registration.h"
#include "libcef/common/app_manager.h"
#include "libcef/common/net/scheme_info.h"
#include "libcef/features/runtime.h"
#include "base/containers/contains.h"
@@ -14,8 +12,14 @@
#include "url/url_constants.h"
#include "url/url_util.h"
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
#include "libcef/common/app_manager.h"
#include "libcef/common/net/scheme_info.h"
#endif
namespace scheme {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
void AddInternalSchemes(content::ContentClient::Schemes* schemes) {
if (!cef::IsAlloyRuntimeEnabled()) {
return;
@@ -60,6 +64,7 @@ void AddInternalSchemes(content::ContentClient::Schemes* schemes) {
CefAppManager::Get()->AddCustomScheme(&scheme);
}
}
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
bool IsInternalHandledScheme(const std::string& scheme) {
static const char* schemes[] = {

View File

@@ -9,12 +9,18 @@
#include <string>
#include <vector>
#include "cef/libcef/features/features.h"
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
#include "content/public/common/content_client.h"
#endif
namespace scheme {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
// Add internal schemes.
void AddInternalSchemes(content::ContentClient::Schemes* schemes);
#endif
// Returns true if the specified |scheme| is handled internally.
bool IsInternalHandledScheme(const std::string& scheme);

View File

@@ -8,18 +8,24 @@
#include <dlfcn.h>
#endif
#include "libcef/features/runtime.h"
#include "base/base_paths.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/notreached.h"
#include "base/path_service.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_paths_internal.h"
#include "chrome/common/chrome_switches.h"
#if BUILDFLAG(IS_LINUX)
#include "base/environment.h"
#include "base/nix/xdg_util.h"
#endif
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
#include "base/files/file_util.h"
#include "base/notreached.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths_internal.h"
#include "ui/base/layout.h"
#if BUILDFLAG(IS_MAC)
@@ -27,14 +33,10 @@
#include "libcef/common/util_mac.h"
#endif
#if BUILDFLAG(IS_LINUX)
#include "base/environment.h"
#include "base/nix/xdg_util.h"
#endif
#if BUILDFLAG(IS_WIN)
#include "base/win/registry.h"
#endif
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
namespace resource_util {
@@ -116,6 +118,12 @@ base::FilePath GetUserDataPath(CefSettings* settings,
return result;
}
} // namespace
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
namespace {
// Consider downloads 'dangerous' if they go to the home directory on Linux and
// to the desktop on any platform.
// From chrome/browser/download/download_prefs.cc.
@@ -206,6 +214,16 @@ void OverrideDefaultDownloadDir() {
}
}
// Same as ui::ResourceBundle::IsScaleFactorSupported.
bool IsScaleFactorSupported(ui::ResourceScaleFactor scale_factor) {
const auto& supported_scale_factors = ui::GetSupportedResourceScaleFactors();
return std::find(supported_scale_factors.begin(),
supported_scale_factors.end(),
scale_factor) != supported_scale_factors.end();
}
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
void OverrideUserDataDir(CefSettings* settings,
const base::CommandLine* command_line) {
const base::FilePath& user_data_path =
@@ -223,14 +241,6 @@ void OverrideUserDataDir(CefSettings* settings,
true); // Create if necessary.
}
// Same as ui::ResourceBundle::IsScaleFactorSupported.
bool IsScaleFactorSupported(ui::ResourceScaleFactor scale_factor) {
const auto& supported_scale_factors = ui::GetSupportedResourceScaleFactors();
return std::find(supported_scale_factors.begin(),
supported_scale_factors.end(),
scale_factor) != supported_scale_factors.end();
}
#if BUILDFLAG(IS_LINUX)
void OverrideAssetPath() {
Dl_info dl_info;

View File

@@ -8,15 +8,22 @@
#include "include/cef_base.h"
#include "cef/libcef/features/features.h"
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
#include "ui/base/resource/resource_scale_factor.h"
#endif
namespace base {
class CommandLine;
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
class FilePath;
#endif
} // namespace base
namespace resource_util {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
// Returns the directory that contains resource files (*.bin, *.dat, *.pak,
// etc).
base::FilePath GetResourcesDir();
@@ -26,11 +33,13 @@ base::FilePath GetDefaultLogFilePath();
// Called from MainDelegate::PreSandboxStartup.
void OverrideDefaultDownloadDir();
void OverrideUserDataDir(CefSettings* settings,
const base::CommandLine* command_line);
// Returns true if |scale_factor| is supported by this platform.
bool IsScaleFactorSupported(ui::ResourceScaleFactor scale_factor);
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
void OverrideUserDataDir(CefSettings* settings,
const base::CommandLine* command_line);
#if BUILDFLAG(IS_LINUX)
// Look for binary files (*.bin, *.dat, *.pak, chrome-sandbox, libGLESv2.so,

View File

@@ -80,6 +80,7 @@ buildflag_header("features") {
header = "features.h"
flags = [
"ENABLE_ALLOY_BOOTSTRAP=$enable_alloy_bootstrap",
"ENABLE_CEF=$enable_cef",
"IS_CEF_SANDBOX_BUILD=$is_cef_sandbox_build",
]

View File

@@ -12,3 +12,9 @@ declare_args() {
# PERFORMANCE AND/OR SECURITY IMPLICATIONS.
is_cef_sandbox_build = false
}
declare_args() {
# Enables the Alloy bootstrap. This will be disabled and removed in ~M127.
# See issue #3685.
enable_alloy_bootstrap = enable_cef
}

View File

@@ -16,8 +16,10 @@ inline bool IsCefBuildEnabled() {
return true;
}
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
// True if CEF was initialized with the Alloy runtime.
bool IsAlloyRuntimeEnabled();
#endif
// True if CEF was initialized with the Chrome runtime.
bool IsChromeRuntimeEnabled();
@@ -25,14 +27,16 @@ bool IsChromeRuntimeEnabled();
// True if CEF crash reporting is enabled.
bool IsCrashReportingEnabled();
#else
#else // !BUILDFLAG(ENABLE_CEF)
inline bool IsCefBuildEnabled() {
return false;
}
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
inline bool IsAlloyRuntimeEnabled() {
return false;
}
#endif
inline bool IsChromeRuntimeEnabled() {
return false;
}
@@ -40,7 +44,7 @@ inline bool IsCrashReportingEnabled() {
return false;
}
#endif
#endif // !BUILDFLAG(ENABLE_CEF)
} // namespace cef

View File

@@ -6,13 +6,18 @@
#define CEF_LIBCEF_FEATURES_RUNTIME_CHECKS_H_
#pragma once
#include "base/logging.h"
#include "cef/libcef/features/runtime.h"
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
#include "base/logging.h"
#define REQUIRE_ALLOY_RUNTIME() \
CHECK(cef::IsAlloyRuntimeEnabled()) << "Alloy runtime is required"
#define REQUIRE_CHROME_RUNTIME() \
CHECK(cef::IsChromeRuntimeEnabled()) << "Chrome runtime is required"
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
#endif // CEF_LIBCEF_FEATURES_RUNTIME_CHECKS_H_