Compare commits

..

46 Commits
4280 ... 4183

Author SHA1 Message Date
Marshall Greenblatt
cd6cbe008b Fix CVE-2020-15999 Heap overflow in the freetype library. 2020-10-23 12:13:46 -04:00
Marshall Greenblatt
3e94ebf031 Update to Chromium version 85.0.4183.121 2020-10-01 18:55:26 -04:00
Marshall Greenblatt
364460420a Windows: Fix incorrect placement with GetInitialBounds (fixes issue #2980)
The coordinates passed to ScreenWin::GetDisplayMatching need to be converted
from DIP to screen coordinates.
2020-09-25 14:27:50 -04:00
Marshall Greenblatt
18f6db50fc Add missing print preview resources (fixes issue #2989) 2020-09-22 17:50:30 -04:00
Marshall Greenblatt
b045a6e974 Linux: cmake: Disable GTK deprecated functions (fixes issue #2791) 2020-09-15 12:42:41 -04:00
Marshall Greenblatt
01947ac530 Fix crash when sending programmatic event to a Views-hosted browser window.
The |web_contents_| member was nullptr in CefBrowserPlatformDelegateNativeAura
when calling methods like SendKeyEvent from CefBrowserPlatformDelegateViews.
2020-09-15 11:10:58 -04:00
Marshall Greenblatt
7de12437b5 Persist media device IDs across navigation and restart (fixes issue #2064)
Media device IDs will now be persisted across navigation and reload by default.
The device IDs will also be persisted across restart if --cache-path=<path> and
--persist-user-preferences settings are specified.
2020-09-14 16:37:06 -04:00
Marshall Greenblatt
acfac2f56b Support CORS preflight requests with OutOfBlinkCors (fixes issue #3006)
A CORS preflight request is an "OPTIONS" request sent to a server prior to a
cross-origin XMLHttpRequest or Fetch request. The server's response determines
which HTTP request methods are allowed and supported, and whether credentials
such as Cookies and HTTP Authentication should be sent with requests.

A CORS preflight request will only be sent if certain conditions are met. For
example, it will be sent for requests that have potentially unsafe HTTP
methods [1] or request headers [2]. See the NeedsPreflight function in
services/network/cors/cors_url_loader.cc for full details.

CORS preflight functionality is implemented in the network service and will not
be triggered if the client handles the request instead of allowing it to proceed
over the network. Since the preflight request itself also runs in the network
service it cannot be intercepted by the client.

[1] https://fetch.spec.whatwg.org/#cors-safelisted-method
[2] https://fetch.spec.whatwg.org/#cors-safelisted-request-header
2020-09-11 19:09:59 -04:00
Marshall Greenblatt
d7ff3589e4 Update to Chromium version 85.0.4183.102 2020-09-09 19:41:28 -04:00
Marshall Greenblatt
e768eb7c36 Fix incorrect Origin and Cookie headers for POST redirects (fixes issue #2806)
This change also adds unit test coverage for cross-origin POST redirects.
2020-09-09 18:25:25 -04:00
Marshall Greenblatt
8e08b6c202 Fix DCHECK failure in the URLLoader constructor.
The request.trusted_params.isolation_info.site_for_cookies value must
match request.site_for_cookies.

This change also adds unit test coverage for cross-origin GET redirects.
2020-09-09 14:10:03 -04:00
Marshall Greenblatt
3b2f416731 Don't save or load cookies for non-cookieable scheme requests.
This fixes an IsCanonical() DCHECK failure triggered by calling
CanonicalCookie::Create for a non-cookieable URL.

This change also adds unit test coverage for cross-origin cookie
behavior with sub-resource requests (iframe, XHR, Fetch).
2020-09-04 16:26:11 -04:00
Marshall Greenblatt
1306235098 Disable Badging API which is not supported (fixes issue #3005) 2020-09-02 15:06:45 -04:00
Marshall Greenblatt
c5d55d4b5c views: Support specification of screen bounds for CefWindow creation (fixes issue #2980) 2020-09-02 14:42:44 -04:00
Marshall Greenblatt
fb115c6aec Include capi sub-directories in API hash calculation 2020-09-02 14:42:44 -04:00
Marshall Greenblatt
5445ef53a0 Restore the CefRenderHandler::OnScrollOffsetChanged callback (fixes issue #2810) 2020-09-02 12:51:15 -04:00
Marshall Greenblatt
6a7969fa1c ceftests: Add missing newline at end of file 2020-09-02 12:34:52 -04:00
Marshall Greenblatt
02028168ae ceftests: Fix incorrect usage of std::string::find 2020-08-28 11:50:17 -04:00
Marshall Greenblatt
17bc62666b ceftests: Fix warning C4245: 'initializing': conversion from 'int' to 'size_t' 2020-08-28 11:45:21 -04:00
Marshall Greenblatt
37773afcc4 Update to Chromium version 85.0.4183.83 2020-08-26 20:49:11 -04:00
Marshall Greenblatt
1119d2723c Add support and enable out-of-Blink CORS (fixes issue #2716)
It can still be disabled for a short time by passing
`--disable-features=OutOfBlinkCors` on the command-line.
2020-08-26 17:21:10 -04:00
Marshall Greenblatt
4c3785756f wrapper: Allow null stream parameter to CefStreamResourceHandler 2020-08-26 17:21:02 -04:00
Marshall Greenblatt
ee4e036af8 ceftests: Add shared test_request and test_server implementations
To reduce text execution time and flakyness this change also
introduces a global test server that is initialized when needed
and torn down after all tests have completed.
2020-08-26 17:20:53 -04:00
Marshall Greenblatt
e12dc09620 wrapper: Add thread-specific IMPLEMENT_REFCOUNTING variant 2020-08-26 17:20:42 -04:00
Marshall Greenblatt
d042c3a577 ceftests: Move TrackCallback to a separate header file 2020-08-26 17:20:33 -04:00
Marshall Greenblatt
3bde5d25e9 ceftests: Fix incorrect include guard #ifdef names 2020-08-26 17:20:25 -04:00
Masako Toda
3f0eaa53b7 Fix initial transparency delay for OSR + gpu-disabled (see issue #2938) 2020-08-13 14:59:43 -04:00
Cristian Amarie
5b78afcf54 Add limit on request redirects (fixes issue #3001) 2020-08-13 14:59:38 -04:00
Marshall Greenblatt
94efef25d9 Update API hash to include enums (see issue #300) 2020-08-07 13:15:55 -04:00
Dmitry Azaraev
48ac1d640e Include enum declarations into API hash calculation (fixes issue #3000) 2020-08-07 13:15:26 -04:00
Marshall Greenblatt
082e6dc106 Fix automate-git.py argument error 2020-08-03 15:02:01 -04:00
Marshall Greenblatt
9a28c1fdf6 Add --distrib-subdir-suffix option to make_distrib 2020-08-03 14:42:14 -04:00
Marshall Greenblatt
a0532bbb72 Fix DCHECK when showing print preview dialog (see issue #2952) 2020-07-23 15:57:08 -04:00
Marshall Greenblatt
19c0e69125 Fix link navigation from PDF files (fixes issue #2952)
Navigations initiated from a guest view will now be routed to the
OpenURLFromTab callback.
2020-07-23 15:57:03 -04:00
Marshall Greenblatt
f0c9073dc0 Windows: cmake: Simplify the MSVC version check 2020-07-23 12:31:35 -04:00
Czarek Tomczak
da5bb13369 MacOS: Update target SDK to 10.10 for cmake and tests 2020-07-23 12:31:29 -04:00
Marshall Greenblatt
bcf4f6bc92 cmake: Update documentation of build requirements and examples 2020-07-21 16:14:11 -04:00
Marshall Greenblatt
989b0078e4 Fix crash in ThemeService with --disable-extensions (fixes issue #2852) 2020-07-21 13:10:56 -04:00
Masako Toda
a49878faee Fix excessive CPU usage with external and multi-threaded message loops (fixes issue #2809, fixes issue #2970). 2020-07-21 12:28:15 -04:00
Mike Wiedenbauer
2c0ba41a10 Return decompressed values from CefResourceBundle (fixes issue #2976) 2020-07-21 11:58:29 -04:00
Masako Toda
a177ba96e5 Fix timing of InstallTransparency for OSR + gpu-disabled (see issue #2938) 2020-07-20 16:02:20 -04:00
Marshall Greenblatt
9fb5d763a8 cefclient: Fix rendering of example background for OSR transparency (see issue #2938) 2020-07-20 15:44:21 -04:00
Andrei Kurushin
4bd2755a6e Fix crash when closing an OSR browser (fixes issue #2919)
Release the Compositor before the WebContents is destroyed to match
the behavior in non-OSR code.
2020-07-20 14:36:16 -04:00
Cristian Amarie
b0a4097775 Properly disable the notification and push APIs (fixes issue #2951) 2020-07-20 14:36:10 -04:00
Marshall Greenblatt
ee3ed79da3 Fix shutdown crash in InitNetworkContext with multi-threaded message loop (fixes issue #2985) 2020-07-20 14:00:40 -04:00
Marshall Greenblatt
b672bd9235 Update to Chromium version 85.0.4183.26 2020-07-17 19:31:28 -04:00
409 changed files with 8176 additions and 11018 deletions

112
BUILD.gn
View File

@@ -122,8 +122,8 @@ if (is_linux) {
import("//third_party/fontconfig/fontconfig.gni")
}
if (is_mac) {
import("//build/apple/tweak_info_plist.gni")
import("//build/config/mac/rules.gni")
import("//build/mac/tweak_info_plist.gni")
import("//build/util/version.gni")
import("//media/cdm/library_cdm/cdm_paths.gni")
import("//build/config/mac/base_rules.gni")
@@ -409,8 +409,6 @@ static_library("libcef_static") {
gypi_paths.autogen_cpp_includes + [
"libcef/browser/alloy/alloy_browser_context.cc",
"libcef/browser/alloy/alloy_browser_context.h",
"libcef/browser/alloy/alloy_browser_host_impl.cc",
"libcef/browser/alloy/alloy_browser_host_impl.h",
"libcef/browser/alloy/alloy_browser_main.cc",
"libcef/browser/alloy/alloy_browser_main.h",
"libcef/browser/alloy/browser_platform_delegate_alloy.cc",
@@ -425,15 +423,12 @@ static_library("libcef_static") {
"libcef/browser/alloy/alloy_content_browser_client.h",
"libcef/browser/audio_capturer.cc",
"libcef/browser/audio_capturer.h",
"libcef/browser/browser_contents_delegate.cc",
"libcef/browser/browser_contents_delegate.h",
"libcef/browser/browser_context.cc",
"libcef/browser/browser_context.h",
"libcef/browser/browser_context_keyed_service_factories.cc",
"libcef/browser/browser_context_keyed_service_factories.h",
"libcef/browser/browser_host_base.cc",
"libcef/browser/browser_host_base.h",
"libcef/browser/browser_host_create.cc",
"libcef/browser/browser_host_impl.cc",
"libcef/browser/browser_host_impl.h",
"libcef/browser/browser_info.cc",
"libcef/browser/browser_info.h",
"libcef/browser/browser_info_manager.cc",
@@ -447,15 +442,10 @@ static_library("libcef_static") {
"libcef/browser/browser_platform_delegate_create.cc",
"libcef/browser/browser_util.cc",
"libcef/browser/browser_util.h",
"libcef/browser/chrome/browser_delegate.h",
"libcef/browser/chrome/browser_platform_delegate_chrome.cc",
"libcef/browser/chrome/browser_platform_delegate_chrome.h",
"libcef/browser/chrome/chrome_browser_context.cc",
"libcef/browser/chrome/chrome_browser_context.h",
"libcef/browser/chrome/chrome_browser_delegate.cc",
"libcef/browser/chrome/chrome_browser_delegate.h",
"libcef/browser/chrome/chrome_browser_host_impl.cc",
"libcef/browser/chrome/chrome_browser_host_impl.h",
"libcef/browser/chrome/chrome_browser_main_extra_parts_cef.cc",
"libcef/browser/chrome/chrome_browser_main_extra_parts_cef.h",
"libcef/browser/chrome/chrome_content_browser_client_cef.cc",
@@ -556,8 +546,6 @@ static_library("libcef_static") {
"libcef/browser/menu_runner.h",
"libcef/browser/native/browser_platform_delegate_native.cc",
"libcef/browser/native/browser_platform_delegate_native.h",
"libcef/browser/native/cursor_util.h",
"libcef/browser/native/cursor_util.cc",
"libcef/browser/navigate_params.cc",
"libcef/browser/navigate_params.h",
"libcef/browser/navigation_entry_impl.cc",
@@ -571,8 +559,6 @@ static_library("libcef_static") {
"libcef/browser/net/internal_scheme_handler.h",
"libcef/browser/net/scheme_handler.cc",
"libcef/browser/net/scheme_handler.h",
"libcef/browser/net/throttle_handler.cc",
"libcef/browser/net/throttle_handler.h",
"libcef/browser/net_service/browser_urlrequest_impl.cc",
"libcef/browser/net_service/browser_urlrequest_impl.h",
"libcef/browser/net_service/cookie_helper.cc",
@@ -765,18 +751,8 @@ static_library("libcef_static") {
"libcef/features/runtime_checks.h",
"libcef/renderer/alloy/alloy_content_renderer_client.cc",
"libcef/renderer/alloy/alloy_content_renderer_client.h",
"libcef/renderer/alloy/alloy_render_frame_observer.cc",
"libcef/renderer/alloy/alloy_render_frame_observer.h",
"libcef/renderer/alloy/alloy_render_thread_observer.cc",
"libcef/renderer/alloy/alloy_render_thread_observer.h",
"libcef/renderer/alloy/url_loader_throttle_provider_impl.cc",
"libcef/renderer/alloy/url_loader_throttle_provider_impl.h",
"libcef/renderer/browser_impl.cc",
"libcef/renderer/browser_impl.h",
"libcef/renderer/browser_manager.cc",
"libcef/renderer/browser_manager.h",
"libcef/renderer/chrome/chrome_content_renderer_client_cef.cc",
"libcef/renderer/chrome/chrome_content_renderer_client_cef.h",
"libcef/renderer/dom_document_impl.cc",
"libcef/renderer/dom_document_impl.h",
"libcef/renderer/dom_node_impl.cc",
@@ -798,6 +774,8 @@ static_library("libcef_static") {
"libcef/renderer/render_urlrequest_impl.cc",
"libcef/renderer/render_urlrequest_impl.h",
"libcef/renderer/thread_util.h",
"libcef/renderer/url_loader_throttle_provider_impl.cc",
"libcef/renderer/url_loader_throttle_provider_impl.h",
"libcef/renderer/v8_impl.cc",
"libcef/renderer/v8_impl.h",
@@ -830,6 +808,7 @@ static_library("libcef_static") {
deps = [
":cef_make_headers",
":cef_service_manifests",
":libcef_static_unittested",
@@ -861,9 +840,8 @@ static_library("libcef_static") {
"//components/google/core/common",
"//components/keyed_service/content:content",
"//components/keyed_service/core:core",
"//components/media_router/common/mojom:media_router",
"//components/navigation_interception",
"//components/network_session_configurator/common",
"//components/network_session_configurator/browser",
"//components/pdf/browser",
"//components/pdf/renderer",
"//components/plugins/renderer",
@@ -909,6 +887,7 @@ static_library("libcef_static") {
"//printing/buildflags",
"//services/network:network_service",
"//services/network/public/cpp",
"//services/service_manager/embedder",
"//services/service_manager/public/cpp",
"//skia",
"//storage/browser",
@@ -940,7 +919,6 @@ static_library("libcef_static") {
"libcef/browser/alloy/alloy_browser_main_win.cc",
"libcef/browser/native/browser_platform_delegate_native_win.cc",
"libcef/browser/native/browser_platform_delegate_native_win.h",
"libcef/browser/native/cursor_util_win.cc",
"libcef/browser/native/file_dialog_runner_win.cc",
"libcef/browser/native/file_dialog_runner_win.h",
"libcef/browser/native/javascript_dialog_runner_win.cc",
@@ -954,6 +932,7 @@ static_library("libcef_static") {
"libcef/browser/native/native_menu_win.h",
"libcef/browser/osr/browser_platform_delegate_osr_win.cc",
"libcef/browser/osr/browser_platform_delegate_osr_win.h",
"libcef/browser/osr/render_widget_host_view_osr_win.cc",
# Part of //chrome/utility.
"//chrome/utility/printing_handler.cc",
@@ -984,11 +963,11 @@ static_library("libcef_static") {
sources += includes_linux + [
"libcef/browser/native/browser_platform_delegate_native_linux.cc",
"libcef/browser/native/browser_platform_delegate_native_linux.h",
"libcef/browser/native/cursor_util_linux.cc",
"libcef/browser/native/menu_runner_linux.cc",
"libcef/browser/native/menu_runner_linux.h",
"libcef/browser/osr/browser_platform_delegate_osr_linux.cc",
"libcef/browser/osr/browser_platform_delegate_osr_linux.h",
"libcef/browser/osr/render_widget_host_view_osr_linux.cc",
"libcef/browser/printing/print_dialog_linux.cc",
"libcef/browser/printing/print_dialog_linux.h",
]
@@ -1188,6 +1167,8 @@ static_library("libcef_static") {
sources += [
# Support for UI input events.
# Part of //ui/aura:test_support which is testingonly.
"//ui/aura/test/ui_controls_factory_aurax11.cc",
"//ui/aura/test/x11_event_sender.cc",
"//ui/aura/test/x11_event_sender.h",
# Part of //ui/views:test_support which is testingonly.
"//ui/views/test/ui_controls_factory_desktop_aurax11.cc",
@@ -1258,7 +1239,7 @@ if (is_win) {
sources = [ "libcef_dll/sandbox/sandbox_win.cc" ]
# CEF sources use include paths relative to the CEF root directory.
include_dirs = [ "." ]
deps = [ "libcef/features", "//sandbox" ]
deps = [ "//sandbox" ]
}
}
@@ -1267,13 +1248,60 @@ if (is_mac) {
sources = [ "libcef_dll/sandbox/sandbox_mac.mm" ]
# CEF sources use include paths relative to the CEF root directory.
include_dirs = [ "." ]
deps = [
"//build/config:executable_deps",
"//sandbox/mac:seatbelt"
]
deps = [ "//sandbox/mac:seatbelt" ]
}
}
#
# Service manifests.
#
source_set("cef_content_browser_overlay_manifest") {
sources = [
"libcef/common/service_manifests/cef_content_browser_overlay_manifest.cc",
"libcef/common/service_manifests/cef_content_browser_overlay_manifest.h",
]
configs += [
"libcef/features:config"
]
deps = [
"//base",
"//extensions/buildflags",
"//extensions/common:mojom",
"//extensions/common/api:mojom",
"//services/service_manager/public/cpp",
"//third_party/blink/public/common",
]
}
source_set("cef_content_renderer_overlay_manifest") {
sources = [
"libcef/common/service_manifests/cef_content_renderer_overlay_manifest.h",
]
configs += [
"libcef/features:config"
]
deps = [
"//base",
"//components/subresource_filter/content/mojom",
"//extensions/buildflags",
"//extensions/common:mojom",
"//services/service_manager/public/cpp",
"//third_party/blink/public/common",
]
}
source_set("cef_service_manifests") {
public_deps = [
":cef_content_browser_overlay_manifest",
":cef_content_renderer_overlay_manifest",
]
}
#
# Resource grit/pack targets.
#
@@ -1635,7 +1663,7 @@ if (is_mac) {
]
public_deps += [ "//v8" ]
if (use_v8_context_snapshot) {
sources += [ "$root_out_dir/$v8_context_snapshot_filename" ]
sources += [ "$root_out_dir/v8_context_snapshot.bin" ]
public_deps += [ "//tools/v8_context_snapshot" ]
}
}
@@ -1911,8 +1939,8 @@ if (is_mac) {
deps += invoker.deps
}
if (defined(invoker.frameworks)) {
frameworks = invoker.frameworks
if (defined(invoker.libs)) {
libs = invoker.libs
}
if (defined(invoker.defines)) {
@@ -1996,7 +2024,7 @@ if (is_mac) {
":cefclient_resources_bundle_data_english",
":cefclient_xibs",
]
frameworks = [
libs = [
"AppKit.framework",
"OpenGL.framework",
]
@@ -2060,7 +2088,7 @@ if (is_mac) {
":cefsimple_resources_bundle_data_english",
":cefsimple_xibs",
]
frameworks = [
libs = [
"AppKit.framework",
]
defines = [
@@ -2131,7 +2159,7 @@ if (is_mac) {
":ceftests_xibs",
"//testing/gtest",
]
frameworks = [
libs = [
"AppKit.framework",
]
defines = [

View File

@@ -7,6 +7,6 @@
# https://bitbucket.org/chromiumembedded/cef/wiki/BranchesAndBuilding
{
'chromium_checkout': 'refs/tags/87.0.4280.141',
'depot_tools_checkout': '39d870e1f0'
'chromium_checkout': 'refs/tags/85.0.4183.121',
'depot_tools_checkout': '233589f2e7'
}

View File

@@ -27,6 +27,8 @@
# Files in the chromium/src directory that should be evaluated for changes.
# Similar changes may need to be applied to the CEF source code.
'files': [
'chrome/app/chrome_*_manifest.*',
'chrome/app/chrome_*_manifests.*',
'chrome/browser/browser_process.h',
'chrome/browser/extensions/api/tabs/tabs_api.*',
'chrome/browser/extensions/chrome_component_extension_resource_manager.*',

View File

@@ -12,7 +12,7 @@
# distribution include:
#
# Linux: Ninja, Unix Makefiles
# MacOS: Ninja, Xcode 8+ (x64) or Xcode 12.2+ (ARM64)
# MacOS: Ninja, Xcode 8+
# Windows: Ninja, Visual Studio 2015+
#
# Ninja is a cross-platform open-source tool for running fast builds using
@@ -53,8 +53,8 @@
# installed. Only 64-bit builds are supported.
#
# - Windows requirements:
# Visual Studio 2015 Update 2 or newer building on Windows 7 or newer. Visual
# Studio 2019 and Windows 10 64-bit are recommended.
# Visual Studio 2015 or newer building on Windows 7 or newer. Visual Studio
# 2019 and Windows 10 64-bit are recommended.
#
# BUILD EXAMPLES
#
@@ -84,15 +84,6 @@
# > cmake -G "Ninja" -DPROJECT_ARCH="x86_64" -DCMAKE_BUILD_TYPE=Debug ..
# > ninja cefclient cefsimple
#
# To perform a MacOS build using an ARM64 CEF binary distribution:
# Using the Xcode IDE:
# > cmake -G "Xcode" -DPROJECT_ARCH="arm64" ..
# Open build\cef.xcodeproj in Xcode and select Product > Build.
#
# Using Ninja:
# > cmake -G "Ninja" -DPROJECT_ARCH="arm64" -DCMAKE_BUILD_TYPE=Debug ..
# > ninja cefclient cefsimple
#
# To perform a Windows build using a 32-bit CEF binary distribution:
# Using the Visual Studio 2019 IDE:
# > cmake -G "Visual Studio 16" -A Win32 ..

View File

@@ -25,7 +25,7 @@ macro(PRINT_CEF_CONFIG)
message(STATUS "Binary distribution root: ${_CEF_ROOT}")
if(OS_MAC)
if(OS_MACOSX)
message(STATUS "Base SDK: ${CMAKE_OSX_SYSROOT}")
message(STATUS "Target SDK: ${CEF_TARGET_SDK}")
endif()
@@ -75,8 +75,8 @@ macro(APPEND_PLATFORM_SOURCES name_of_list)
if(OS_WINDOWS AND ${name_of_list}_WINDOWS)
list(APPEND ${name_of_list} ${${name_of_list}_WINDOWS})
endif()
if(OS_MAC AND ${name_of_list}_MAC)
list(APPEND ${name_of_list} ${${name_of_list}_MAC})
if(OS_MACOSX AND ${name_of_list}_MACOSX)
list(APPEND ${name_of_list} ${${name_of_list}_MACOSX})
endif()
endmacro()
@@ -184,10 +184,10 @@ endif(OS_LINUX)
# Mac OS X macros.
#
if(OS_MAC)
if(OS_MACOSX)
# Manually process and copy over resource files.
macro(COPY_MAC_RESOURCES resource_list prefix_list target source_dir app_path)
macro(COPY_MACOSX_RESOURCES resource_list prefix_list target source_dir app_path)
foreach(FILENAME ${resource_list})
# Remove one or more prefixes from the source paths.
set(TARGET_FILENAME "${FILENAME}")
@@ -229,7 +229,7 @@ macro(COPY_MAC_RESOURCES resource_list prefix_list target source_dir app_path)
endforeach()
endmacro()
endif(OS_MAC)
endif(OS_MACOSX)
#
@@ -298,7 +298,7 @@ macro(SET_COMMON_TARGET_PROPERTIES target)
set_property(TARGET ${target} PROPERTY LINK_FLAGS_RELEASE ${_flags_str})
endif()
if(OS_MAC)
if(OS_MACOSX)
# Set Xcode target properties.
set_target_properties(${target} PROPERTIES
XCODE_ATTRIBUTE_ALWAYS_SEARCH_USER_PATHS NO

View File

@@ -14,8 +14,7 @@ endif()
# Determine the platform.
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
set(OS_MAC 1)
set(OS_MACOSX 1) # For backwards compatibility.
set(OS_MACOSX 1)
set(OS_POSIX 1)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
set(OS_LINUX 1)
@@ -32,7 +31,7 @@ if(NOT DEFINED PROJECT_ARCH)
set(PROJECT_ARCH "x86")
endif()
if(OS_MAC)
if(OS_MACOSX)
# PROJECT_ARCH should be specified on Mac OS X.
message(WARNING "No PROJECT_ARCH value specified, using ${PROJECT_ARCH}")
endif()
@@ -247,7 +246,7 @@ endif()
# Mac OS X configuration.
#
if(OS_MAC)
if(OS_MACOSX)
# Platform-specific compiler/linker flags.
# See also Xcode target properties in cef_macros.cmake.
set(CEF_LIBTYPE SHARED)
@@ -328,8 +327,6 @@ if(OS_MAC)
# Target architecture.
if(PROJECT_ARCH STREQUAL "x86_64")
set(CMAKE_OSX_ARCHITECTURES "x86_64")
elseif(PROJECT_ARCH STREQUAL "arm64")
set(CMAKE_OSX_ARCHITECTURES "arm64")
else()
set(CMAKE_OSX_ARCHITECTURES "i386")
endif()

View File

@@ -180,7 +180,7 @@ Atomic64 Release_Load(volatile const Atomic64* ptr);
#include "include/base/internal/cef_atomicops_x86_msvc.h"
#elif defined(OS_WIN) && (defined(__ARM_ARCH_ISA_A64) || defined(_M_ARM64))
#include "include/base/internal/cef_atomicops_arm64_msvc.h"
#elif defined(OS_MAC)
#elif defined(OS_MACOSX)
#include "include/base/internal/cef_atomicops_mac.h"
#elif defined(COMPILER_GCC) && defined(ARCH_CPU_X86_FAMILY)
#include "include/base/internal/cef_atomicops_x86_gcc.h"
@@ -194,7 +194,7 @@ Atomic64 Release_Load(volatile const Atomic64* ptr);
// On some platforms we need additional declarations to make
// AtomicWord compatible with our other Atomic* types.
#if defined(OS_MAC) || defined(OS_OPENBSD)
#if defined(OS_MACOSX) || defined(OS_OPENBSD)
#include "include/base/internal/cef_atomicops_atomicword_compat.h"
#endif

View File

@@ -42,7 +42,7 @@
//
// On Mac OS X, |long long| is used for 64-bit types for compatibility with
// <inttypes.h> format macros even in the LP64 model.
#if defined(__LP64__) && !defined(OS_MAC) && !defined(OS_OPENBSD)
#if defined(__LP64__) && !defined(OS_MACOSX) && !defined(OS_OPENBSD)
typedef long int64;
typedef unsigned long uint64;
#else

View File

@@ -44,14 +44,6 @@
#define OS_WIN 1
#endif
#elif defined(__APPLE__)
// New platform defines after https://crbug.com/1105907.
#ifndef OS_MAC
#define OS_MAC 1
#endif
#ifndef OS_APPLE
#define OS_APPLE 1
#endif
// Old platform defines retained for backwards compatibility.
#ifndef OS_MACOSX
#define OS_MACOSX 1
#endif
@@ -65,7 +57,7 @@
// For access to standard POSIXish features, use OS_POSIX instead of a
// more specific macro.
#if defined(OS_MAC) || defined(OS_LINUX)
#if defined(OS_MACOSX) || defined(OS_LINUX)
#ifndef OS_POSIX
#define OS_POSIX 1
#endif

View File

@@ -250,11 +250,11 @@ class WeakPtr : public cef_internal::WeakPtrBase {
T* get() const { return ref_.is_valid() ? ptr_ : NULL; }
T& operator*() const {
CHECK(ref_.is_valid());
DCHECK(get() != NULL);
return *get();
}
T* operator->() const {
CHECK(ref_.is_valid());
DCHECK(get() != NULL);
return get();
}

View File

@@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=965eb2e55afec0a4618a7acd9478b9c1215be29d$
// $hash=6cb00a0fa3631a46903abb3a783f315895511db2$
//
#ifndef CEF_INCLUDE_CAPI_CEF_BROWSER_CAPI_H_
@@ -562,6 +562,19 @@ typedef struct _cef_browser_host_t {
struct _cef_navigation_entry_visitor_t* visitor,
int current_only);
///
// Set whether mouse cursor change is disabled.
///
void(CEF_CALLBACK* set_mouse_cursor_change_disabled)(
struct _cef_browser_host_t* self,
int disabled);
///
// Returns true (1) if mouse cursor change is disabled.
///
int(CEF_CALLBACK* is_mouse_cursor_change_disabled)(
struct _cef_browser_host_t* self);
///
// If a misspelled word is currently selected in an editable node calling this
// function will replace it with the specified |word|.

View File

@@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=d56cbf83d6faefa9f716c7308bf7007dad98697d$
// $hash=306236316b35037523ca566068d133755bce48fd$
//
#ifndef CEF_INCLUDE_CAPI_CEF_BROWSER_PROCESS_HANDLER_CAPI_H_
@@ -41,7 +41,6 @@
#pragma once
#include "include/capi/cef_base_capi.h"
#include "include/capi/cef_client_capi.h"
#include "include/capi/cef_command_line_capi.h"
#include "include/capi/cef_print_handler_capi.h"
#include "include/capi/cef_values_capi.h"
@@ -61,25 +60,6 @@ typedef struct _cef_browser_process_handler_t {
///
cef_base_ref_counted_t base;
///
// Called on the browser process UI thread to retrieve the list of schemes
// that should support cookies. If |include_defaults| is true (1) the default
// schemes ("http", "https", "ws" and "wss") will also be supported. Providing
// an NULL |schemes| value and setting |include_defaults| to false (0) will
// disable all loading and saving of cookies.
//
// This state will apply to the cef_cookie_manager_t associated with the
// global cef_request_context_t. It will also be used as the initial state for
// any new cef_request_context_ts created by the client. After creating a new
// cef_request_context_t the cef_cookie_manager_t::SetSupportedSchemes
// function may be called on the associated cef_cookie_manager_t to futher
// override these values.
///
void(CEF_CALLBACK* get_cookieable_schemes)(
struct _cef_browser_process_handler_t* self,
cef_string_list_t schemes,
int* include_defaults);
///
// Called on the browser process UI thread immediately after the CEF context
// has been initialized.
@@ -121,16 +101,6 @@ typedef struct _cef_browser_process_handler_t {
void(CEF_CALLBACK* on_schedule_message_pump_work)(
struct _cef_browser_process_handler_t* self,
int64 delay_ms);
///
// Return the default client for use with a newly created browser window. If
// null is returned the browser will be unmanaged (no callbacks will be
// executed for that browser) and application shutdown will be blocked until
// the browser window is closed manually. This function is currently only used
// with the chrome runtime.
///
struct _cef_client_t*(CEF_CALLBACK* get_default_client)(
struct _cef_browser_process_handler_t* self);
} cef_browser_process_handler_t;
#ifdef __cplusplus

View File

@@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=eada7e92085d96497f4e69f3e8a7e8aa6746b175$
// $hash=951c936c8070dbf9bd246cc766b81cdfe06a3d81$
//
#ifndef CEF_INCLUDE_CAPI_CEF_DISPLAY_HANDLER_CAPI_H_
@@ -141,19 +141,6 @@ typedef struct _cef_display_handler_t {
struct _cef_display_handler_t* self,
struct _cef_browser_t* browser,
double progress);
///
// Called when the browser's cursor has changed. If |type| is CT_CUSTOM then
// |custom_cursor_info| will be populated with the custom cursor information.
// Return true (1) if the cursor change was handled or false (0) for default
// handling.
///
int(CEF_CALLBACK* on_cursor_change)(
struct _cef_display_handler_t* self,
struct _cef_browser_t* browser,
cef_cursor_handle_t cursor,
cef_cursor_type_t type,
const struct _cef_cursor_info_t* custom_cursor_info);
} cef_display_handler_t;
#ifdef __cplusplus

View File

@@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=19337a70a13352e70452be7fcc25ef2de4b1ae4c$
// $hash=14cf03e02d8ca3416e65f756470afd8185c7bc78$
//
#ifndef CEF_INCLUDE_CAPI_CEF_PARSER_CAPI_H_
@@ -153,11 +153,13 @@ CEF_EXPORT struct _cef_value_t* cef_parse_json_buffer(
///
// Parses the specified |json_string| and returns a dictionary or list
// representation. If JSON parsing fails this function returns NULL and
// populates |error_msg_out| with a formatted error message.
// populates |error_code_out| and |error_msg_out| with an error code and a
// formatted error message respectively.
///
CEF_EXPORT struct _cef_value_t* cef_parse_jsonand_return_error(
const cef_string_t* json_string,
cef_json_parser_options_t options,
cef_json_parser_error_t* error_code_out,
cef_string_t* error_msg_out);
///

View File

@@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=f9806cd79f33b6a762fff25edd4189ae42bc8fd2$
// $hash=e642fc1fe3b97a90c0eae7f0fc0a5cfd385e3e17$
//
#ifndef CEF_INCLUDE_CAPI_CEF_RENDER_HANDLER_CAPI_H_
@@ -159,6 +159,17 @@ typedef struct _cef_render_handler_t {
cef_rect_t const* dirtyRects,
void* shared_handle);
///
// Called when the browser's cursor has changed. If |type| is CT_CUSTOM then
// |custom_cursor_info| will be populated with the custom cursor information.
///
void(CEF_CALLBACK* on_cursor_change)(
struct _cef_render_handler_t* self,
struct _cef_browser_t* browser,
cef_cursor_handle_t cursor,
cef_cursor_type_t type,
const struct _cef_cursor_info_t* custom_cursor_info);
///
// Called when the user starts dragging content in the web view. Contextual
// information about the dragged content is supplied by |drag_data|. (|x|,

View File

@@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=d443c0990241554b548bc946f46f35582445e818$
// $hash=370cdeaa3252a9ed0e1a627d858dcab23af24ee1$
//
#ifndef CEF_INCLUDE_CAPI_CEF_THREAD_CAPI_H_
@@ -98,8 +98,8 @@ typedef struct _cef_thread_t {
// identify the thread. |priority| is the thread execution priority.
// |message_loop_type| indicates the set of asynchronous events that the thread
// can process. If |stoppable| is true (1) the thread will stopped and joined on
// destruction or when stop() is called; otherwise, the thread cannot be stopped
// and will be leaked on shutdown. On Windows the |com_init_mode| value
// destruction or when stop() is called; otherwise, the the thread cannot be
// stopped and will be leaked on shutdown. On Windows the |com_init_mode| value
// specifies how COM will be initialized for the thread. If |com_init_mode| is
// set to COM_INIT_MODE_STA then |message_loop_type| must be set to ML_TYPE_UI.
///

View File

@@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=75f4f7a9ff628a6ae699a697722caa5d49546784$
// $hash=63d875f5a922dd2c2e1efaaf0ddaa20475f79ef8$
//
#ifndef CEF_INCLUDE_CAPI_CEF_URLREQUEST_CAPI_H_
@@ -115,13 +115,20 @@ typedef struct _cef_urlrequest_t {
// Create a new URL request that is not associated with a specific browser or
// frame. Use cef_frame_t::CreateURLRequest instead if you want the request to
// have this association, in which case it may be handled differently (see
// documentation on that function). A request created with this function may
// only originate from the browser process, and will behave as follows:
// documentation on that function). Requests may originate from the both browser
// process and the render process.
//
// For requests originating from the browser process:
// - It may be intercepted by the client via CefResourceRequestHandler or
// CefSchemeHandlerFactory.
// - POST data may only contain only a single element of type PDE_TYPE_FILE
// or PDE_TYPE_BYTES.
// - If |request_context| is empty the global request context will be used.
// For requests originating from the render process:
// - It cannot be intercepted by the client so only http(s) and blob schemes
// are supported.
// - POST data may only contain a single element of type PDE_TYPE_BYTES.
// - The |request_context| parameter must be NULL.
//
// The |request| object will be marked as read-only after calling this function.
///

View File

@@ -42,13 +42,13 @@
// way that may cause binary incompatibility with other builds. The universal
// hash value will change if any platform is affected whereas the platform hash
// values will change only if that particular platform is affected.
#define CEF_API_HASH_UNIVERSAL "7f349b7262bfe13bda037370004f56a6081e543b"
#define CEF_API_HASH_UNIVERSAL "09d3d4f08869644fe3baa7a751de537f3446525b"
#if defined(OS_WIN)
#define CEF_API_HASH_PLATFORM "8a5523fec15255e2fb1de64deaa15dc3554b91e5"
#elif defined(OS_MAC)
#define CEF_API_HASH_PLATFORM "f572c8f7d3aee3cd3b85bd398b0ba43eb7fe79a0"
#define CEF_API_HASH_PLATFORM "3022db6736af26cc38158d38e22f74a51312a5c9"
#elif defined(OS_MACOSX)
#define CEF_API_HASH_PLATFORM "13e2e2451c2320f0d16b35ba53b3295409888dd8"
#elif defined(OS_LINUX)
#define CEF_API_HASH_PLATFORM "abf4cc6ff102e5cd019aaf51f13eb30f9bfeae45"
#define CEF_API_HASH_PLATFORM "d781b815150795b0bce95d72ce967b508c9a04d5"
#endif
#ifdef __cplusplus

View File

@@ -35,7 +35,7 @@
#include "include/cef_base.h"
#endif // __cplusplus
#if defined(OS_MAC) && defined(__OBJC__)
#if defined(OS_MACOSX) && defined(__OBJC__)
#ifdef USING_CHROMIUM_INCLUDES
@@ -105,6 +105,6 @@ class CefScopedSendingEvent {
#endif // __cplusplus
#endif // defined(OS_MAC) && defined(__OBJC__)
#endif // defined(OS_MACOSX) && defined(__OBJC__)
#endif // CEF_INCLUDE_CEF_APPLICATION_MAC_H_

View File

@@ -40,7 +40,7 @@
#include "include/internal/cef_types_wrappers.h"
#if defined(OS_WIN)
#include "include/internal/cef_win.h"
#elif defined(OS_MAC)
#elif defined(OS_MACOSX)
#include "include/internal/cef_mac.h"
#elif defined(OS_LINUX)
#include "include/internal/cef_linux.h"

View File

@@ -592,6 +592,18 @@ class CefBrowserHost : public virtual CefBaseRefCounted {
CefRefPtr<CefNavigationEntryVisitor> visitor,
bool current_only) = 0;
///
// Set whether mouse cursor change is disabled.
///
/*--cef()--*/
virtual void SetMouseCursorChangeDisabled(bool disabled) = 0;
///
// Returns true if mouse cursor change is disabled.
///
/*--cef()--*/
virtual bool IsMouseCursorChangeDisabled() = 0;
///
// If a misspelled word is currently selected in an editable node calling
// this method will replace it with the specified |word|.

View File

@@ -39,7 +39,6 @@
#pragma once
#include "include/cef_base.h"
#include "include/cef_client.h"
#include "include/cef_command_line.h"
#include "include/cef_print_handler.h"
#include "include/cef_values.h"
@@ -51,23 +50,6 @@
/*--cef(source=client,no_debugct_check)--*/
class CefBrowserProcessHandler : public virtual CefBaseRefCounted {
public:
///
// Called on the browser process UI thread to retrieve the list of schemes
// that should support cookies. If |include_defaults| is true the default
// schemes ("http", "https", "ws" and "wss") will also be supported. Providing
// an empty |schemes| value and setting |include_defaults| to false will
// disable all loading and saving of cookies.
//
// This state will apply to the CefCookieManager associated with the global
// CefRequestContext. It will also be used as the initial state for any new
// CefRequestContexts created by the client. After creating a new
// CefRequestContext the CefCookieManager::SetSupportedSchemes method may be
// called on the associated CefCookieManager to futher override these values.
///
/*--cef()--*/
virtual void GetCookieableSchemes(std::vector<CefString>& schemes,
bool& include_defaults) {}
///
// Called on the browser process UI thread immediately after the CEF context
// has been initialized.
@@ -108,16 +90,6 @@ class CefBrowserProcessHandler : public virtual CefBaseRefCounted {
///
/*--cef()--*/
virtual void OnScheduleMessagePumpWork(int64 delay_ms) {}
///
// Return the default client for use with a newly created browser window. If
// null is returned the browser will be unmanaged (no callbacks will be
// executed for that browser) and application shutdown will be blocked until
// the browser window is closed manually. This method is currently only used
// with the chrome runtime.
///
/*--cef()--*/
virtual CefRefPtr<CefClient> GetDefaultClient() { return nullptr; }
};
#endif // CEF_INCLUDE_CEF_BROWSER_PROCESS_HANDLER_H_

View File

@@ -135,19 +135,6 @@ class CefDisplayHandler : public virtual CefBaseRefCounted {
/*--cef()--*/
virtual void OnLoadingProgressChange(CefRefPtr<CefBrowser> browser,
double progress) {}
///
// Called when the browser's cursor has changed. If |type| is CT_CUSTOM then
// |custom_cursor_info| will be populated with the custom cursor information.
// Return true if the cursor change was handled or false for default handling.
///
/*--cef()--*/
virtual bool OnCursorChange(CefRefPtr<CefBrowser> browser,
CefCursorHandle cursor,
cef_cursor_type_t type,
const CefCursorInfo& custom_cursor_info) {
return false;
}
};
#endif // CEF_INCLUDE_CEF_DISPLAY_HANDLER_H_

View File

@@ -146,12 +146,14 @@ CefRefPtr<CefValue> CefParseJSON(const void* json,
///
// Parses the specified |json_string| and returns a dictionary or list
// representation. If JSON parsing fails this method returns NULL and populates
// |error_msg_out| with a formatted error message.
// |error_code_out| and |error_msg_out| with an error code and a formatted error
// message respectively.
///
/*--cef()--*/
CefRefPtr<CefValue> CefParseJSONAndReturnError(
const CefString& json_string,
cef_json_parser_options_t options,
cef_json_parser_error_t& error_code_out,
CefString& error_msg_out);
///

View File

@@ -52,6 +52,7 @@
/*--cef(source=client)--*/
class CefRenderHandler : public virtual CefBaseRefCounted {
public:
typedef cef_cursor_type_t CursorType;
typedef cef_drag_operations_mask_t DragOperation;
typedef cef_drag_operations_mask_t DragOperationsMask;
typedef cef_paint_element_type_t PaintElementType;
@@ -161,6 +162,16 @@ class CefRenderHandler : public virtual CefBaseRefCounted {
const RectList& dirtyRects,
void* shared_handle) {}
///
// Called when the browser's cursor has changed. If |type| is CT_CUSTOM then
// |custom_cursor_info| will be populated with the custom cursor information.
///
/*--cef()--*/
virtual void OnCursorChange(CefRefPtr<CefBrowser> browser,
CefCursorHandle cursor,
CursorType type,
const CefCursorInfo& custom_cursor_info) {}
///
// Called when the user starts dragging content in the web view. Contextual
// information about the dragged content is supplied by |drag_data|.

View File

@@ -34,7 +34,7 @@
#include "include/base/cef_build.h"
#include "include/internal/cef_export.h"
#if defined(OS_MAC)
#if defined(OS_MACOSX)
#ifdef __cplusplus
extern "C" {
@@ -83,6 +83,6 @@ class CEF_EXPORT CefScopedSandboxContext {
};
#endif // __cplusplus
#endif // defined(OS_MAC)
#endif // defined(OS_MACOSX)
#endif // CEF_INCLUDE_CEF_SANDBOX_MAC_H_

View File

@@ -61,7 +61,7 @@ class CefThread : public CefBaseRefCounted {
// to identify the thread. |priority| is the thread execution priority.
// |message_loop_type| indicates the set of asynchronous events that the
// thread can process. If |stoppable| is true the thread will stopped and
// joined on destruction or when Stop() is called; otherwise, the thread
// joined on destruction or when Stop() is called; otherwise, the the thread
// cannot be stopped and will be leaked on shutdown. On Windows the
// |com_init_mode| value specifies how COM will be initialized for the thread.
// If |com_init_mode| is set to COM_INIT_MODE_STA then |message_loop_type|

View File

@@ -63,13 +63,20 @@ class CefURLRequest : public virtual CefBaseRefCounted {
// Create a new URL request that is not associated with a specific browser or
// frame. Use CefFrame::CreateURLRequest instead if you want the request to
// have this association, in which case it may be handled differently (see
// documentation on that method). A request created with this method may only
// originate from the browser process, and will behave as follows:
// documentation on that method). Requests may originate from the both browser
// process and the render process.
//
// For requests originating from the browser process:
// - It may be intercepted by the client via CefResourceRequestHandler or
// CefSchemeHandlerFactory.
// - POST data may only contain only a single element of type PDE_TYPE_FILE
// or PDE_TYPE_BYTES.
// - If |request_context| is empty the global request context will be used.
// For requests originating from the render process:
// - It cannot be intercepted by the client so only http(s) and blob schemes
// are supported.
// - POST data may only contain a single element of type PDE_TYPE_BYTES.
// - The |request_context| parameter must be NULL.
//
// The |request| object will be marked as read-only after calling this method.
///

View File

@@ -39,7 +39,7 @@
// Bring in platform-specific definitions.
#if defined(OS_WIN)
#include "include/internal/cef_types_win.h"
#elif defined(OS_MAC)
#elif defined(OS_MACOSX)
#include "include/internal/cef_types_mac.h"
#elif defined(OS_LINUX)
#include "include/internal/cef_types_linux.h"
@@ -2367,6 +2367,22 @@ typedef enum {
JSON_PARSER_ALLOW_TRAILING_COMMAS = 1 << 0,
} cef_json_parser_options_t;
///
// Error codes that can be returned from CefParseJSONAndReturnError.
///
typedef enum {
JSON_NO_ERROR = 0,
JSON_INVALID_ESCAPE,
JSON_SYNTAX_ERROR,
JSON_UNEXPECTED_TOKEN,
JSON_TRAILING_COMMA,
JSON_TOO_MUCH_NESTING,
JSON_UNEXPECTED_DATA_AFTER_ROOT,
JSON_UNSUPPORTED_ENCODING,
JSON_UNQUOTED_DICTIONARY_KEY,
JSON_PARSE_ERROR_COUNT
} cef_json_parser_error_t;
///
// Options that can be passed to CefWriteJSON.
///

View File

@@ -33,7 +33,7 @@
#include "include/base/cef_build.h"
#if defined(OS_MAC)
#if defined(OS_MACOSX)
#include "include/internal/cef_string.h"
// Handle types.
@@ -137,6 +137,6 @@ typedef struct _cef_window_info_t {
}
#endif
#endif // OS_MAC
#endif // OS_MACOSX
#endif // CEF_INCLUDE_INTERNAL_CEF_TYPES_MAC_H_

View File

@@ -56,7 +56,7 @@ int cef_unload_library();
#ifdef __cplusplus
}
#if defined(OS_MAC)
#if defined(OS_MACOSX)
///
// Scoped helper for loading and unloading the CEF framework library at
@@ -122,7 +122,7 @@ class CefScopedLibraryLoader {
DISALLOW_COPY_AND_ASSIGN(CefScopedLibraryLoader);
};
#endif // defined(OS_MAC)
#endif // defined(OS_MACOSX)
#endif // __cplusplus
#endif // CEF_INCLUDE_WRAPPER_CEF_LIBRARY_LOADER_H_

View File

@@ -285,6 +285,10 @@ bool AlloyBrowserContext::IsPrintPreviewSupported() const {
return !GetPrefs()->GetBoolean(prefs::kPrintPreviewDisabled);
}
void AlloyBrowserContext::AddVisitedURLs(const std::vector<GURL>& urls) {
visitedlink_master_->AddURLs(urls);
}
content::ResourceContext* AlloyBrowserContext::GetResourceContext() {
if (!resource_context_) {
resource_context_ = std::make_unique<content::ResourceContext>();
@@ -450,7 +454,3 @@ DownloadPrefs* AlloyBrowserContext::GetDownloadPrefs() {
}
return download_prefs_.get();
}
void AlloyBrowserContext::AddVisitedURLs(const std::vector<GURL>& urls) {
visitedlink_master_->AddURLs(urls);
}

View File

@@ -53,6 +53,7 @@ class AlloyBrowserContext : public ChromeProfileAlloy,
CefRefPtr<CefExtension> GetExtension(const CefString& extension_id) override;
bool UnloadExtension(const CefString& extension_id) override;
bool IsPrintPreviewSupported() const override;
void AddVisitedURLs(const std::vector<GURL>& urls) override;
// content::BrowserContext overrides.
content::ResourceContext* GetResourceContext() override;
@@ -97,12 +98,15 @@ class AlloyBrowserContext : public ChromeProfileAlloy,
// Values checked in ProfileNetworkContextService::CreateNetworkContextParams
// when creating the NetworkContext.
bool ShouldRestoreOldSessionCookies() const override {
bool ShouldRestoreOldSessionCookies() override {
return ShouldPersistSessionCookies();
}
bool ShouldPersistSessionCookies() const override {
bool ShouldPersistSessionCookies() override {
return !!settings_.persist_session_cookies;
}
base::Optional<std::vector<std::string>> GetCookieableSchemes() override {
return cookieable_schemes();
}
// visitedlink::VisitedLinkDelegate methods.
void RebuildTable(const scoped_refptr<URLEnumerator>& enumerator) override;
@@ -112,10 +116,6 @@ class AlloyBrowserContext : public ChromeProfileAlloy,
return extension_system_;
}
// Called from AlloyBrowserHostImpl::DidFinishNavigation to update the table
// of visited links.
void AddVisitedURLs(const std::vector<GURL>& urls);
// Called from DownloadPrefs::FromBrowserContext.
DownloadPrefs* GetDownloadPrefs();

File diff suppressed because it is too large Load Diff

View File

@@ -27,16 +27,15 @@
#include "base/strings/string_number_conversions.h"
#include "base/task/post_task.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/media/router/chrome_media_router_factory.h"
#include "chrome/browser/net/system_network_context_manager.h"
#include "chrome/browser/plugins/plugin_finder.h"
#include "components/constrained_window/constrained_window_views.h"
#include "content/public/browser/gpu_data_manager.h"
#include "content/public/browser/network_service_instance.h"
#include "content/public/common/result_codes.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/constants.h"
#include "net/base/net_module.h"
#include "services/service_manager/embedder/result_codes.h"
#include "ui/base/resource/resource_bundle.h"
#if defined(USE_AURA) && defined(USE_X11)
@@ -58,7 +57,7 @@
#endif // defined(USE_AURA)
#if defined(TOOLKIT_VIEWS)
#if defined(OS_MAC)
#if defined(OS_MACOSX)
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/browser/ui/views/chrome_views_delegate.h"
#else
@@ -89,7 +88,7 @@ int AlloyBrowserMainParts::PreEarlyInitialization() {
ui::InitializeInputMethodForTesting();
#endif
return content::RESULT_CODE_NORMAL_EXIT;
return service_manager::RESULT_CODE_NORMAL_EXIT;
}
void AlloyBrowserMainParts::ToolkitInitialized() {
@@ -106,7 +105,7 @@ void AlloyBrowserMainParts::ToolkitInitialized() {
#endif // defined(USE_AURA)
#if defined(TOOLKIT_VIEWS)
#if defined(OS_MAC)
#if defined(OS_MACOSX)
views_delegate_ = std::make_unique<ChromeViewsDelegate>();
layout_provider_ = ChromeLayoutProvider::CreateLayoutProvider();
#else
@@ -131,8 +130,6 @@ void AlloyBrowserMainParts::PreMainMessageLoopStart() {
// setup.exe. In Chrome, these strings are in the locale files.
ChromeBrowserMainPartsWin::SetupInstallerUtilStrings();
#endif // defined(OS_WIN)
media_router::ChromeMediaRouterFactory::DoPlatformInit();
}
void AlloyBrowserMainParts::PostMainMessageLoopStart() {
@@ -233,7 +230,7 @@ void AlloyBrowserMainParts::PostDestroyThreads() {
#if defined(TOOLKIT_VIEWS)
views_delegate_.reset();
#if defined(OS_MAC)
#if defined(OS_MACOSX)
layout_provider_.reset();
#endif
#endif // defined(TOOLKIT_VIEWS)

View File

@@ -32,7 +32,7 @@ class WMState;
#if defined(TOOLKIT_VIEWS)
namespace views {
class ViewsDelegate;
#if defined(OS_MAC)
#if defined(OS_MACOSX)
class LayoutProvider;
#endif
} // namespace views
@@ -96,7 +96,7 @@ class AlloyBrowserMainParts : public content::BrowserMainParts {
#if defined(TOOLKIT_VIEWS)
std::unique_ptr<views::ViewsDelegate> views_delegate_;
#if defined(OS_MAC)
#if defined(OS_MACOSX)
std::unique_ptr<views::LayoutProvider> layout_provider_;
#endif
#endif // defined(TOOLKIT_VIEWS)

View File

@@ -9,9 +9,9 @@
#include "include/cef_version.h"
#include "libcef/browser/alloy/alloy_browser_context.h"
#include "libcef/browser/alloy/alloy_browser_host_impl.h"
#include "libcef/browser/alloy/alloy_browser_main.h"
#include "libcef/browser/browser_context.h"
#include "libcef/browser/browser_host_impl.h"
#include "libcef/browser/browser_info.h"
#include "libcef/browser/browser_info_manager.h"
#include "libcef/browser/browser_message_filter.h"
@@ -22,8 +22,6 @@
#include "libcef/browser/extensions/extension_web_contents_observer.h"
#include "libcef/browser/media_capture_devices_dispatcher.h"
#include "libcef/browser/net/chrome_scheme_handler.h"
#include "libcef/browser/net/throttle_handler.h"
#include "libcef/browser/net_service/cookie_manager_impl.h"
#include "libcef/browser/net_service/login_delegate.h"
#include "libcef/browser/net_service/proxy_url_loader_factory.h"
#include "libcef/browser/net_service/resource_request_handler_wrapper.h"
@@ -42,6 +40,7 @@
#include "libcef/common/extensions/extensions_util.h"
#include "libcef/common/net/scheme_registration.h"
#include "libcef/common/request_impl.h"
#include "libcef/common/service_manifests/cef_content_browser_overlay_manifest.h"
#include "base/base_switches.h"
#include "base/command_line.h"
@@ -73,10 +72,13 @@
#include "chrome/grit/generated_resources.h"
#include "chrome/services/printing/printing_service.h"
#include "components/content_settings/core/browser/cookie_settings.h"
#include "components/navigation_interception/intercept_navigation_throttle.h"
#include "components/navigation_interception/navigation_params.h"
#include "components/spellcheck/common/spellcheck.mojom.h"
#include "components/variations/variations_http_header_provider.h"
#include "components/version_info/version_info.h"
#include "content/browser/frame_host/render_frame_host_impl.h"
#include "content/browser/plugin_service_impl.h"
#include "content/browser/renderer_host/render_frame_host_impl.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_ppapi_host.h"
#include "content/public/browser/browser_thread.h"
@@ -97,14 +99,13 @@
#include "content/public/common/storage_quota_params.h"
#include "content/public/common/url_constants.h"
#include "content/public/common/user_agent.h"
#include "content/public/common/web_preferences.h"
#include "extensions/browser/extension_message_filter.h"
#include "extensions/browser/extension_protocols.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/guest_view/extensions_guest_view_message_filter.h"
#include "extensions/browser/guest_view/web_view/web_view_guest.h"
#include "extensions/browser/info_map.h"
#include "extensions/browser/process_map.h"
#include "extensions/browser/url_loader_factory_manager.h"
#include "extensions/common/constants.h"
#include "extensions/common/switches.h"
@@ -113,12 +114,12 @@
#include "net/base/auth.h"
#include "net/ssl/ssl_cert_request_info.h"
#include "ppapi/host/ppapi_host.h"
#include "sandbox/policy/switches.h"
#include "services/network/public/cpp/network_switches.h"
#include "services/proxy_resolver/public/mojom/proxy_resolver.mojom.h"
#include "services/service_manager/embedder/switches.h"
#include "services/service_manager/public/mojom/connector.mojom.h"
#include "services/service_manager/sandbox/switches.h"
#include "storage/browser/quota/quota_settings.h"
#include "third_party/blink/public/common/web_preferences/web_preferences.h"
#include "third_party/blink/public/mojom/insecure_input/insecure_input_service.mojom.h"
#include "third_party/blink/public/mojom/prerender/prerender.mojom.h"
#include "third_party/blink/public/web/web_window_features.h"
@@ -132,7 +133,7 @@
#include "libcef/common/widevine_loader.h"
#endif
#if defined(OS_POSIX) && !defined(OS_MAC)
#if defined(OS_POSIX) && !defined(OS_MACOSX)
#include "base/debug/leak_annotations.h"
#include "chrome/common/chrome_paths.h"
#include "components/crash/content/browser/crash_handler_host_linux.h"
@@ -140,7 +141,7 @@
#include "content/public/common/content_descriptors.h"
#endif
#if defined(OS_MAC)
#if defined(OS_MACOSX)
#include "net/ssl/client_cert_store_mac.h"
#include "services/video_capture/public/mojom/constants.mojom.h"
#endif
@@ -348,9 +349,9 @@ class CefQuotaPermissionContext : public content::QuotaPermissionContext {
bool handled = false;
CefRefPtr<AlloyBrowserHostImpl> browser =
AlloyBrowserHostImpl::GetBrowserForFrameRoute(render_process_id,
params.render_frame_id);
CefRefPtr<CefBrowserHostImpl> browser =
CefBrowserHostImpl::GetBrowserForFrameRoute(render_process_id,
params.render_frame_id);
if (browser.get()) {
CefRefPtr<CefClient> client = browser->GetClient();
if (client.get()) {
@@ -382,7 +383,7 @@ class CefQuotaPermissionContext : public content::QuotaPermissionContext {
DISALLOW_COPY_AND_ASSIGN(CefQuotaPermissionContext);
};
#if defined(OS_POSIX) && !defined(OS_MAC)
#if defined(OS_POSIX) && !defined(OS_MACOSX)
breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost(
const std::string& process_type) {
base::FilePath dumps_path;
@@ -437,7 +438,74 @@ int GetCrashSignalFD(const base::CommandLine& command_line) {
return -1;
}
#endif // defined(OS_POSIX) && !defined(OS_MAC)
#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
// TODO(cef): We can't currently trust NavigationParams::is_main_frame() because
// it's always set to true in
// InterceptNavigationThrottle::CheckIfShouldIgnoreNavigation. Remove the
// |is_main_frame| argument once this problem is fixed.
bool NavigationOnUIThread(
bool is_main_frame,
int64_t frame_id,
int64_t parent_frame_id,
int frame_tree_node_id,
content::WebContents* source,
const navigation_interception::NavigationParams& params) {
CEF_REQUIRE_UIT();
content::OpenURLParams open_params(
params.url(), params.referrer(), WindowOpenDisposition::CURRENT_TAB,
params.transition_type(), params.is_renderer_initiated());
open_params.user_gesture = params.has_user_gesture();
open_params.initiator_origin = params.initiator_origin();
CefRefPtr<CefBrowserHostImpl> browser;
if (!CefBrowserInfoManager::GetInstance()->MaybeAllowNavigation(
source->GetMainFrame(), open_params, browser)) {
// Cancel the navigation.
return true;
}
bool ignore_navigation = false;
if (browser.get()) {
CefRefPtr<CefClient> client = browser->GetClient();
if (client.get()) {
CefRefPtr<CefRequestHandler> handler = client->GetRequestHandler();
if (handler.get()) {
CefRefPtr<CefFrame> frame;
if (is_main_frame) {
frame = browser->GetMainFrame();
} else if (frame_id >= 0) {
frame = browser->GetFrame(frame_id);
}
if (!frame && frame_tree_node_id >= 0) {
frame = browser->GetFrameForFrameTreeNode(frame_tree_node_id);
}
if (!frame) {
// Create a temporary frame object for navigation of sub-frames that
// don't yet exist.
frame = browser->browser_info()->CreateTempSubFrame(parent_frame_id);
}
CefRefPtr<CefRequestImpl> request = new CefRequestImpl();
request->Set(params, is_main_frame);
request->SetReadOnly(true);
// Initiating a new navigation in OnBeforeBrowse will delete the
// InterceptNavigationThrottle that currently owns this callback,
// resulting in a crash. Use the lock to prevent that.
std::unique_ptr<CefBrowserHostImpl::NavigationLock> navigation_lock =
browser->CreateNavigationLock();
ignore_navigation = handler->OnBeforeBrowse(
browser.get(), frame, request.get(), params.has_user_gesture(),
params.is_redirect());
}
}
}
return ignore_navigation;
}
// From chrome/browser/plugins/chrome_content_browser_client_plugins_part.cc.
void BindPluginInfoHost(
@@ -631,6 +699,12 @@ void AlloyContentBrowserClient::SiteInstanceGotProcess(
extensions::ProcessMap::Get(browser_context)
->Insert(extension->id(), site_instance->GetProcess()->GetID(),
site_instance->GetId());
CEF_POST_TASK(
CEF_IOT, base::Bind(&extensions::InfoMap::RegisterExtensionProcess,
browser_context->extension_system()->info_map(),
extension->id(), site_instance->GetProcess()->GetID(),
site_instance->GetId()));
}
void AlloyContentBrowserClient::SiteInstanceDeleting(
@@ -657,6 +731,12 @@ void AlloyContentBrowserClient::SiteInstanceDeleting(
extensions::ProcessMap::Get(browser_context)
->Remove(extension->id(), site_instance->GetProcess()->GetID(),
site_instance->GetId());
CEF_POST_TASK(
CEF_IOT, base::Bind(&extensions::InfoMap::UnregisterExtensionProcess,
browser_context->extension_system()->info_map(),
extension->id(), site_instance->GetProcess()->GetID(),
site_instance->GetId()));
}
void AlloyContentBrowserClient::BindHostReceiverForRenderer(
@@ -678,6 +758,15 @@ void AlloyContentBrowserClient::BindHostReceiverForRenderer(
#endif // BUILDFLAG(HAS_SPELLCHECK_PANEL)
}
base::Optional<service_manager::Manifest>
AlloyContentBrowserClient::GetServiceManifestOverlay(base::StringPiece name) {
if (name == content::mojom::kBrowserServiceName) {
return GetCefContentBrowserOverlayManifest();
}
return base::nullopt;
}
void AlloyContentBrowserClient::AppendExtraCommandLineSwitches(
base::CommandLine* command_line,
int child_process_id) {
@@ -688,7 +777,7 @@ void AlloyContentBrowserClient::AppendExtraCommandLineSwitches(
// associated values) if present in the browser command line.
static const char* const kSwitchNames[] = {
switches::kDisablePackLoading,
#if defined(OS_MAC)
#if defined(OS_MACOSX)
switches::kFrameworkDirPath,
switches::kMainBundlePath,
#endif
@@ -757,7 +846,7 @@ void AlloyContentBrowserClient::AppendExtraCommandLineSwitches(
}
#if defined(OS_LINUX)
if (process_type == switches::kZygoteProcess) {
if (process_type == service_manager::switches::kZygoteProcess) {
// Propagate the following switches to the zygote command line (along with
// any associated values) if present in the browser command line.
static const char* const kSwitchNames[] = {
@@ -768,7 +857,7 @@ void AlloyContentBrowserClient::AppendExtraCommandLineSwitches(
base::size(kSwitchNames));
#if BUILDFLAG(ENABLE_WIDEVINE) && BUILDFLAG(ENABLE_LIBRARY_CDMS)
if (!browser_cmd->HasSwitch(sandbox::policy::switches::kNoSandbox)) {
if (!browser_cmd->HasSwitch(service_manager::switches::kNoSandbox)) {
// Pass the Widevine CDM path to the Zygote process. See comments in
// CefWidevineLoader::AddContentDecryptionModules.
const base::FilePath& cdm_path = CefWidevineLoader::GetInstance()->path();
@@ -872,8 +961,8 @@ void AlloyContentBrowserClient::AllowCertificateError(
return;
}
CefRefPtr<AlloyBrowserHostImpl> browser =
AlloyBrowserHostImpl::GetBrowserForContents(web_contents);
CefRefPtr<CefBrowserHostImpl> browser =
CefBrowserHostImpl::GetBrowserForContents(web_contents);
if (!browser.get())
return;
CefRefPtr<CefClient> client = browser->GetClient();
@@ -908,8 +997,8 @@ base::OnceClosure AlloyContentBrowserClient::SelectClientCertificate(
CEF_REQUIRE_UIT();
CefRefPtr<CefRequestHandler> handler;
CefRefPtr<AlloyBrowserHostImpl> browser =
AlloyBrowserHostImpl::GetBrowserForContents(web_contents);
CefRefPtr<CefBrowserHostImpl> browser =
CefBrowserHostImpl::GetBrowserForContents(web_contents);
if (browser.get()) {
CefRefPtr<CefClient> client = browser->GetClient();
if (client.get())
@@ -965,7 +1054,7 @@ bool AlloyContentBrowserClient::CanCreateWindow(
void AlloyContentBrowserClient::OverrideWebkitPrefs(
content::RenderViewHost* rvh,
blink::web_pref::WebPreferences* prefs) {
content::WebPreferences* prefs) {
// Using RVH instead of RFH here because rvh->GetMainFrame() may be nullptr
// when this method is called.
renderer_prefs::PopulateWebPreferences(rvh, *prefs);
@@ -976,13 +1065,6 @@ void AlloyContentBrowserClient::OverrideWebkitPrefs(
}
}
bool AlloyContentBrowserClient::OverrideWebPreferencesAfterNavigation(
content::WebContents* web_contents,
blink::web_pref::WebPreferences* prefs) {
return renderer_prefs::PopulateWebPreferencesAfterNavigation(web_contents,
*prefs);
}
void AlloyContentBrowserClient::BrowserURLHandlerCreated(
content::BrowserURLHandler* handler) {
scheme::BrowserURLHandlerCreated(handler);
@@ -1007,8 +1089,33 @@ AlloyContentBrowserClient::GetDevToolsManagerDelegate() {
std::vector<std::unique_ptr<content::NavigationThrottle>>
AlloyContentBrowserClient::CreateThrottlesForNavigation(
content::NavigationHandle* navigation_handle) {
throttle::NavigationThrottleList throttles;
throttle::CreateThrottlesForNavigation(navigation_handle, throttles);
CEF_REQUIRE_UIT();
std::vector<std::unique_ptr<content::NavigationThrottle>> throttles;
const bool is_main_frame = navigation_handle->IsInMainFrame();
// Identify the RenderFrameHost that originated the navigation.
const int64_t parent_frame_id =
!is_main_frame
? CefFrameHostImpl::MakeFrameId(navigation_handle->GetParentFrame())
: CefFrameHostImpl::kInvalidFrameId;
const int64_t frame_id = !is_main_frame && navigation_handle->HasCommitted()
? CefFrameHostImpl::MakeFrameId(
navigation_handle->GetRenderFrameHost())
: CefFrameHostImpl::kInvalidFrameId;
// Must use SynchronyMode::kSync to ensure that OnBeforeBrowse is always
// called before OnBeforeResourceLoad.
std::unique_ptr<content::NavigationThrottle> throttle =
std::make_unique<navigation_interception::InterceptNavigationThrottle>(
navigation_handle,
base::Bind(&NavigationOnUIThread, is_main_frame, frame_id,
parent_frame_id, navigation_handle->GetFrameTreeNodeId()),
navigation_interception::SynchronyMode::kSync);
throttles.push_back(std::move(throttle));
return throttles;
}
@@ -1044,7 +1151,7 @@ void AlloyContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
content::PosixFileDescriptorInfo* mappings) {
int crash_signal_fd = GetCrashSignalFD(command_line);
if (crash_signal_fd >= 0) {
mappings->Share(kCrashDumpSignal, crash_signal_fd);
mappings->Share(service_manager::kCrashDumpSignal, crash_signal_fd);
}
}
#endif // defined(OS_LINUX)
@@ -1074,7 +1181,7 @@ AlloyContentBrowserClient::CreateClientCertStore(
net::ClientCertStoreNSS::PasswordDelegateFactory()));
#elif defined(OS_WIN)
return std::unique_ptr<net::ClientCertStore>(new net::ClientCertStoreWin());
#elif defined(OS_MAC)
#elif defined(OS_MACOSX)
return std::unique_ptr<net::ClientCertStore>(new net::ClientCertStoreMac());
#else
#error Unknown platform.
@@ -1098,8 +1205,6 @@ AlloyContentBrowserClient::CreateLoginDelegate(
void AlloyContentBrowserClient::RegisterNonNetworkNavigationURLLoaderFactories(
int frame_tree_node_id,
base::UkmSourceId ukm_source_id,
NonNetworkURLLoaderFactoryDeprecatedMap* uniquely_owned_factories,
NonNetworkURLLoaderFactoryMap* factories) {
if (!extensions::ExtensionsEnabled())
return;
@@ -1109,14 +1214,13 @@ void AlloyContentBrowserClient::RegisterNonNetworkNavigationURLLoaderFactories(
factories->emplace(
extensions::kExtensionScheme,
extensions::CreateExtensionNavigationURLLoaderFactory(
web_contents->GetBrowserContext(), ukm_source_id,
web_contents->GetBrowserContext(),
!!extensions::WebViewGuest::FromWebContents(web_contents)));
}
void AlloyContentBrowserClient::RegisterNonNetworkSubresourceURLLoaderFactories(
int render_process_id,
int render_frame_id,
NonNetworkURLLoaderFactoryDeprecatedMap* uniquely_owned_factories,
NonNetworkURLLoaderFactoryMap* factories) {
if (!extensions::ExtensionsEnabled())
return;
@@ -1158,10 +1262,10 @@ void AlloyContentBrowserClient::RegisterNonNetworkSubresourceURLLoaderFactories(
allowed_webui_hosts.emplace_back(chrome::kChromeUIThemeHost);
}
if (!allowed_webui_hosts.empty()) {
factories->emplace(content::kChromeUIScheme,
content::CreateWebUIURLLoaderFactory(
frame_host, content::kChromeUIScheme,
std::move(allowed_webui_hosts)));
factories->emplace(
content::kChromeUIScheme,
content::CreateWebUIURLLoader(frame_host, content::kChromeUIScheme,
std::move(allowed_webui_hosts)));
}
}
@@ -1172,7 +1276,6 @@ bool AlloyContentBrowserClient::WillCreateURLLoaderFactory(
URLLoaderFactoryType type,
const url::Origin& request_initiator,
base::Optional<int64_t> navigation_id,
base::UkmSourceId ukm_source_id,
mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver,
mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>*
header_client,
@@ -1217,16 +1320,10 @@ void AlloyContentBrowserClient::ConfigureNetworkContextParams(
return;
}
auto cef_context = CefBrowserContext::FromBrowserContext(context);
Profile* profile = cef_context->AsProfile();
Profile* profile = Profile::FromBrowserContext(context);
profile->ConfigureNetworkContextParams(in_memory, relative_partition_path,
network_context_params,
cert_verifier_creation_params);
network_context_params->cookieable_schemes =
cef_context->GetCookieableSchemes();
// TODO(cef): Remove this and add required NetworkIsolationKeys,
// this is currently not the case and this was not required pre M84.
network_context_params->require_network_isolation_key = false;
@@ -1253,7 +1350,7 @@ AlloyContentBrowserClient::GetNetworkContextsParentDirectory() {
bool AlloyContentBrowserClient::HandleExternalProtocol(
const GURL& url,
content::WebContents::OnceGetter web_contents_getter,
base::OnceCallback<content::WebContents*()> web_contents_getter,
int child_id,
content::NavigationUIData* navigation_data,
bool is_main_frame,
@@ -1273,16 +1370,32 @@ bool AlloyContentBrowserClient::HandleExternalProtocol(
mojo::PendingRemote<network::mojom::URLLoaderFactory>* out_factory) {
mojo::PendingReceiver<network::mojom::URLLoaderFactory> receiver =
out_factory->InitWithNewPipeAndPassReceiver();
// CefBrowserPlatformDelegate::HandleExternalProtocol may be called if
// nothing handles the request.
auto request_handler = net_service::CreateInterceptedRequestHandler(
web_contents_getter, frame_tree_node_id, resource_request,
base::Bind(CefBrowserPlatformDelegate::HandleExternalProtocol,
resource_request.url));
if (CEF_CURRENTLY_ON_IOT()) {
auto request_handler = net_service::CreateInterceptedRequestHandler(
web_contents_getter, frame_tree_node_id, resource_request);
net_service::ProxyURLLoaderFactory::CreateProxy(
web_contents_getter, std::move(receiver), std::move(request_handler));
} else {
auto request_handler = net_service::CreateInterceptedRequestHandler(
web_contents_getter, frame_tree_node_id, resource_request);
CEF_POST_TASK(
CEF_IOT,
base::BindOnce(
[](mojo::PendingReceiver<network::mojom::URLLoaderFactory> receiver,
std::unique_ptr<net_service::InterceptedRequestHandler>
request_handler,
content::WebContents::Getter web_contents_getter) {
// Manages its own lifetime.
net_service::ProxyURLLoaderFactory::CreateProxy(
web_contents_getter, std::move(receiver), std::move(request_handler));
net_service::ProxyURLLoaderFactory::CreateProxy(
web_contents_getter, std::move(receiver),
std::move(request_handler));
},
std::move(receiver), std::move(request_handler),
std::move(web_contents_getter)));
}
return true;
}

View File

@@ -61,6 +61,8 @@ class AlloyContentBrowserClient : public content::ContentBrowserClient {
void BindHostReceiverForRenderer(
content::RenderProcessHost* render_process_host,
mojo::GenericPendingReceiver receiver) override;
base::Optional<service_manager::Manifest> GetServiceManifestOverlay(
base::StringPiece name) override;
void AppendExtraCommandLineSwitches(base::CommandLine* command_line,
int child_process_id) override;
std::string GetApplicationLocale() override;
@@ -102,10 +104,7 @@ class AlloyContentBrowserClient : public content::ContentBrowserClient {
bool opener_suppressed,
bool* no_javascript_access) override;
void OverrideWebkitPrefs(content::RenderViewHost* rvh,
blink::web_pref::WebPreferences* prefs) override;
bool OverrideWebPreferencesAfterNavigation(
content::WebContents* web_contents,
blink::web_pref::WebPreferences* prefs) override;
content::WebPreferences* prefs) override;
void BrowserURLHandlerCreated(content::BrowserURLHandler* handler) override;
std::string GetDefaultDownloadName() override;
void DidCreatePpapiPlugin(content::BrowserPpapiHost* browser_host) override;
@@ -150,13 +149,10 @@ class AlloyContentBrowserClient : public content::ContentBrowserClient {
LoginAuthRequiredCallback auth_required_callback) override;
void RegisterNonNetworkNavigationURLLoaderFactories(
int frame_tree_node_id,
base::UkmSourceId ukm_source_id,
NonNetworkURLLoaderFactoryDeprecatedMap* uniquely_owned_factories,
NonNetworkURLLoaderFactoryMap* factories) override;
void RegisterNonNetworkSubresourceURLLoaderFactories(
int render_process_id,
int render_frame_id,
NonNetworkURLLoaderFactoryDeprecatedMap* uniquely_owned_factories,
NonNetworkURLLoaderFactoryMap* factories) override;
bool WillCreateURLLoaderFactory(
content::BrowserContext* browser_context,
@@ -165,7 +161,6 @@ class AlloyContentBrowserClient : public content::ContentBrowserClient {
URLLoaderFactoryType type,
const url::Origin& request_initiator,
base::Optional<int64_t> navigation_id,
base::UkmSourceId ukm_source_id,
mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver,
mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>*
header_client,
@@ -184,7 +179,7 @@ class AlloyContentBrowserClient : public content::ContentBrowserClient {
std::vector<base::FilePath> GetNetworkContextsParentDirectory() override;
bool HandleExternalProtocol(
const GURL& url,
content::WebContents::OnceGetter web_contents_getter,
base::OnceCallback<content::WebContents*()> web_contents_getter,
int child_id,
content::NavigationUIData* navigation_data,
bool is_main_frame,

View File

@@ -4,7 +4,7 @@
#include "libcef/browser/alloy/browser_platform_delegate_alloy.h"
#include "libcef/browser/alloy/alloy_browser_host_impl.h"
#include "libcef/browser/browser_host_impl.h"
#include "libcef/browser/extensions/browser_extensions_util.h"
#include "libcef/browser/extensions/extension_background_host.h"
#include "libcef/browser/extensions/extension_system.h"
@@ -12,7 +12,6 @@
#include "libcef/browser/extensions/extension_web_contents_observer.h"
#include "libcef/browser/printing/print_view_manager.h"
#include "libcef/common/extensions/extensions_util.h"
#include "libcef/features/runtime_checks.h"
#include "base/logging.h"
#include "chrome/browser/printing/print_view_manager.h"
@@ -25,24 +24,12 @@
#include "extensions/browser/process_manager.h"
#include "third_party/blink/public/mojom/frame/find_in_page.mojom.h"
namespace {
printing::CefPrintViewManager* GetPrintViewManager(
content::WebContents* web_contents) {
return printing::CefPrintViewManager::FromWebContents(web_contents);
}
} // namespace
CefBrowserPlatformDelegateAlloy::CefBrowserPlatformDelegateAlloy()
: weak_ptr_factory_(this) {}
content::WebContents* CefBrowserPlatformDelegateAlloy::CreateWebContents(
CefBrowserCreateParams& create_params,
CefBrowserHostImpl::CreateParams& create_params,
bool& own_web_contents) {
REQUIRE_ALLOY_RUNTIME();
DCHECK(primary_);
// Get or create the request context and browser context.
CefRefPtr<CefRequestContextImpl> request_context_impl =
CefRequestContextImpl::GetOrCreateForRequestContext(
@@ -118,11 +105,8 @@ void CefBrowserPlatformDelegateAlloy::AddNewContents(
const gfx::Rect& initial_rect,
bool user_gesture,
bool* was_blocked) {
REQUIRE_ALLOY_RUNTIME();
DCHECK(primary_);
CefRefPtr<AlloyBrowserHostImpl> owner =
AlloyBrowserHostImpl::GetBrowserForContents(new_contents.get());
CefRefPtr<CefBrowserHostImpl> owner =
CefBrowserHostImpl::GetBrowserForContents(new_contents.get());
if (owner) {
// Taking ownership of |new_contents|.
static_cast<CefBrowserPlatformDelegateAlloy*>(
@@ -159,15 +143,10 @@ void CefBrowserPlatformDelegateAlloy::RenderViewReady() {
}
void CefBrowserPlatformDelegateAlloy::BrowserCreated(
CefBrowserHostBase* browser) {
CefBrowserHostImpl* browser) {
CefBrowserPlatformDelegate::BrowserCreated(browser);
// Only register WebContents delegate/observers if we're the primary delegate.
if (!primary_)
return;
DCHECK(!web_contents_->GetDelegate());
web_contents_->SetDelegate(static_cast<AlloyBrowserHostImpl*>(browser));
web_contents_->SetDelegate(browser);
PrefsTabHelper::CreateForWebContents(web_contents_);
printing::CefPrintViewManager::CreateForWebContents(web_contents_);
@@ -190,29 +169,24 @@ void CefBrowserPlatformDelegateAlloy::CreateExtensionHost(
const extensions::Extension* extension,
const GURL& url,
extensions::ViewType host_type) {
REQUIRE_ALLOY_RUNTIME();
DCHECK(primary_);
// Should get WebContentsCreated and BrowserCreated calls first.
DCHECK(web_contents_);
DCHECK(browser_);
DCHECK(!extension_host_);
auto alloy_browser = static_cast<AlloyBrowserHostImpl*>(browser_);
if (host_type == extensions::VIEW_TYPE_EXTENSION_DIALOG ||
host_type == extensions::VIEW_TYPE_EXTENSION_POPUP) {
// Create an extension host that we own.
extension_host_ = new extensions::CefExtensionViewHost(
alloy_browser, extension, web_contents_, url, host_type);
browser_, extension, web_contents_, url, host_type);
// Trigger load of the extension URL.
extension_host_->CreateRenderViewSoon();
} else if (host_type == extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) {
is_background_host_ = true;
alloy_browser->is_background_host_ = true;
browser_->is_background_host_ = true;
// Create an extension host that will be owned by ProcessManager.
extension_host_ = new extensions::CefExtensionBackgroundHost(
alloy_browser,
browser_,
base::BindOnce(&CefBrowserPlatformDelegateAlloy::OnExtensionHostDeleted,
weak_ptr_factory_.GetWeakPtr()),
extension, web_contents_, url, host_type);
@@ -228,11 +202,9 @@ extensions::ExtensionHost* CefBrowserPlatformDelegateAlloy::GetExtensionHost()
}
void CefBrowserPlatformDelegateAlloy::BrowserDestroyed(
CefBrowserHostBase* browser) {
if (primary_) {
DestroyExtensionHost();
owned_web_contents_.reset();
}
CefBrowserHostImpl* browser) {
DestroyExtensionHost();
owned_web_contents_.reset();
CefBrowserPlatformDelegate::BrowserDestroyed(browser);
}
@@ -250,7 +222,7 @@ void CefBrowserPlatformDelegateAlloy::SendCaptureLostEvent() {
widget->LostCapture();
}
#if defined(OS_WIN) || (defined(OS_POSIX) && !defined(OS_MAC))
#if defined(OS_WIN) || (defined(OS_POSIX) && !defined(OS_MACOSX))
void CefBrowserPlatformDelegateAlloy::NotifyMoveOrResizeStarted() {
if (!web_contents_)
return;
@@ -331,8 +303,6 @@ void CefBrowserPlatformDelegateAlloy::SetAccessibilityState(
}
bool CefBrowserPlatformDelegateAlloy::IsPrintPreviewSupported() const {
REQUIRE_ALLOY_RUNTIME();
auto actionable_contents = GetActionableWebContents();
if (!actionable_contents)
return false;
@@ -348,8 +318,6 @@ bool CefBrowserPlatformDelegateAlloy::IsPrintPreviewSupported() const {
}
void CefBrowserPlatformDelegateAlloy::Print() {
REQUIRE_ALLOY_RUNTIME();
auto actionable_contents = GetActionableWebContents();
if (!actionable_contents)
return;
@@ -357,9 +325,11 @@ void CefBrowserPlatformDelegateAlloy::Print() {
auto rfh = actionable_contents->GetMainFrame();
if (IsPrintPreviewSupported()) {
GetPrintViewManager(actionable_contents)->PrintPreviewNow(rfh, false);
printing::CefPrintViewManager::FromWebContents(actionable_contents)
->PrintPreviewNow(rfh, false);
} else {
GetPrintViewManager(actionable_contents)->PrintNow(rfh);
printing::PrintViewManager::FromWebContents(actionable_contents)
->PrintNow(rfh);
}
}
@@ -367,8 +337,6 @@ void CefBrowserPlatformDelegateAlloy::PrintToPDF(
const CefString& path,
const CefPdfPrintSettings& settings,
CefRefPtr<CefPdfPrintCallback> callback) {
REQUIRE_ALLOY_RUNTIME();
content::WebContents* actionable_contents = GetActionableWebContents();
if (!actionable_contents)
return;
@@ -377,7 +345,7 @@ void CefBrowserPlatformDelegateAlloy::PrintToPDF(
pdf_callback = base::Bind(&CefPdfPrintCallback::OnPdfPrintFinished,
callback.get(), path);
}
GetPrintViewManager(actionable_contents)
printing::CefPrintViewManager::FromWebContents(actionable_contents)
->PrintToPDF(actionable_contents->GetMainFrame(), base::FilePath(path),
settings, pdf_callback);
}
@@ -401,7 +369,7 @@ void CefBrowserPlatformDelegateAlloy::Find(int identifier,
auto options = blink::mojom::FindOptions::New();
options->forward = forward;
options->match_case = matchCase;
options->find_match = findNext;
options->find_next_if_selection_matches = findNext;
web_contents_->Find(identifier, searchText, std::move(options));
}
@@ -437,8 +405,6 @@ CefBrowserPlatformDelegateAlloy::GetActionableWebContents() const {
void CefBrowserPlatformDelegateAlloy::SetOwnedWebContents(
content::WebContents* owned_contents) {
DCHECK(primary_);
// Should not currently own a WebContents.
CHECK(!owned_web_contents_);
owned_web_contents_.reset(owned_contents);

View File

@@ -10,14 +10,13 @@
#include "libcef/browser/web_contents_dialog_helper.h"
#include "base/memory/weak_ptr.h"
#include "content/public/browser/web_contents.h"
#include "ui/gfx/geometry/size.h"
// Implementation of Alloy-based browser functionality.
class CefBrowserPlatformDelegateAlloy : public CefBrowserPlatformDelegate {
public:
content::WebContents* CreateWebContents(CefBrowserCreateParams& create_params,
bool& own_web_contents) override;
content::WebContents* CreateWebContents(
CefBrowserHostImpl::CreateParams& create_params,
bool& own_web_contents) override;
void WebContentsCreated(content::WebContents* web_contents,
bool owned) override;
void AddNewContents(content::WebContents* source,
@@ -30,14 +29,14 @@ class CefBrowserPlatformDelegateAlloy : public CefBrowserPlatformDelegate {
bool ShouldTransferNavigation(bool is_main_frame_navigation) override;
void RenderViewCreated(content::RenderViewHost* render_view_host) override;
void RenderViewReady() override;
void BrowserCreated(CefBrowserHostBase* browser) override;
void BrowserCreated(CefBrowserHostImpl* browser) override;
void CreateExtensionHost(const extensions::Extension* extension,
const GURL& url,
extensions::ViewType host_type) override;
extensions::ExtensionHost* GetExtensionHost() const override;
void BrowserDestroyed(CefBrowserHostBase* browser) override;
void BrowserDestroyed(CefBrowserHostImpl* browser) override;
void SendCaptureLostEvent() override;
#if defined(OS_WIN) || (defined(OS_POSIX) && !defined(OS_MAC))
#if defined(OS_WIN) || (defined(OS_POSIX) && !defined(OS_MACOSX))
void NotifyMoveOrResizeStarted() override;
#endif
bool PreHandleGestureEvent(content::WebContents* source,
@@ -70,9 +69,6 @@ class CefBrowserPlatformDelegateAlloy : public CefBrowserPlatformDelegate {
// Otherwise, the browser's WebContents will be returned.
content::WebContents* GetActionableWebContents() const;
// Called from BrowserPlatformDelegateNative::set_windowless_handler().
void set_as_secondary() { primary_ = false; }
private:
void SetOwnedWebContents(content::WebContents* owned_contents);
@@ -102,10 +98,6 @@ class CefBrowserPlatformDelegateAlloy : public CefBrowserPlatformDelegate {
gfx::Size auto_resize_min_;
gfx::Size auto_resize_max_;
// True if this is the primary platform delegate, in which case it will
// register WebContents delegate/observers.
bool primary_ = true;
base::WeakPtrFactory<CefBrowserPlatformDelegateAlloy> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(CefBrowserPlatformDelegateAlloy);

View File

@@ -325,12 +325,6 @@ ChromeBrowserProcessAlloy::floc_blocklist_service() {
return nullptr;
}
federated_learning::FlocSortingLshClustersService*
ChromeBrowserProcessAlloy::floc_sorting_lsh_clusters_service() {
NOTREACHED();
return nullptr;
}
optimization_guide::OptimizationGuideService*
ChromeBrowserProcessAlloy::optimization_guide_service() {
NOTREACHED();

View File

@@ -83,8 +83,6 @@ class ChromeBrowserProcessAlloy : public BrowserProcess {
subresource_filter::RulesetService* subresource_filter_ruleset_service()
override;
federated_learning::FlocBlocklistService* floc_blocklist_service() override;
federated_learning::FlocSortingLshClustersService*
floc_sorting_lsh_clusters_service() override;
optimization_guide::OptimizationGuideService* optimization_guide_service()
override;
StartupData* startup_data() override;

View File

@@ -5,9 +5,8 @@
#include "libcef/browser/alloy/chrome_profile_alloy.h"
#include "base/no_destructor.h"
#include "components/variations/variations_client.h"
#include "components/variations/variations_ids_provider.h"
#include "components/variations/variations_http_header_provider.h"
#include "net/url_request/url_request_context.h"
namespace {
@@ -23,10 +22,9 @@ class CefVariationsClient : public variations::VariationsClient {
return browser_context_->IsOffTheRecord();
}
variations::mojom::VariationsHeadersPtr GetVariationsHeaders()
const override {
return variations::VariationsIdsProvider::GetInstance()
->GetClientDataHeaders(false /* is_signed_in */);
std::string GetVariationsHeader() const override {
return variations::VariationsHttpHeaderProvider::GetInstance()
->GetClientDataHeader(false /* is_signed_in */);
}
private:
@@ -159,7 +157,7 @@ void ChromeProfileAlloy::SetExitType(ExitType exit_type) {
NOTREACHED();
}
Profile::ExitType ChromeProfileAlloy::GetLastSessionExitType() const {
Profile::ExitType ChromeProfileAlloy::GetLastSessionExitType() {
NOTREACHED();
return EXIT_NORMAL;
}
@@ -172,7 +170,3 @@ base::Time ChromeProfileAlloy::GetCreationTime() const {
void ChromeProfileAlloy::SetCreationTimeForTesting(base::Time creation_time) {
NOTREACHED();
}
void ChromeProfileAlloy::RecordMainFrameNavigation() {
NOTREACHED();
}

View File

@@ -47,10 +47,9 @@ class ChromeProfileAlloy : public Profile {
GURL GetHomePage() override;
bool WasCreatedByVersionOrLater(const std::string& version) override;
void SetExitType(ExitType exit_type) override;
ExitType GetLastSessionExitType() const override;
ExitType GetLastSessionExitType() override;
base::Time GetCreationTime() const override;
void SetCreationTimeForTesting(base::Time creation_time) override;
void RecordMainFrameNavigation() override;
private:
std::unique_ptr<variations::VariationsClient> variations_client_;

View File

@@ -4,7 +4,7 @@
// found in the LICENSE file.
#include "libcef/browser/audio_capturer.h"
#include "libcef/browser/alloy/alloy_browser_host_impl.h"
#include "libcef/browser/browser_host_impl.h"
#include "components/mirroring/service/captured_audio_input.h"
#include "content/public/browser/audio_loopback_stream_creator.h"
@@ -51,7 +51,7 @@ void StreamCreatorHelper(
} // namespace
CefAudioCapturer::CefAudioCapturer(const CefAudioParameters& params,
CefRefPtr<AlloyBrowserHostImpl> browser,
CefRefPtr<CefBrowserHostImpl> browser,
CefRefPtr<CefAudioHandler> audio_handler)
: params_(params),
browser_(browser),

View File

@@ -21,12 +21,12 @@ class AudioInputDevice;
} // namespace media
class CefAudioHandler;
class AlloyBrowserHostImpl;
class CefBrowserHostImpl;
class CefAudioCapturer : public media::AudioCapturerSource::CaptureCallback {
public:
CefAudioCapturer(const CefAudioParameters& params,
CefRefPtr<AlloyBrowserHostImpl> browser,
CefRefPtr<CefBrowserHostImpl> browser,
CefRefPtr<CefAudioHandler> audio_handler);
~CefAudioCapturer() override;
@@ -42,7 +42,7 @@ class CefAudioCapturer : public media::AudioCapturerSource::CaptureCallback {
void StopStream();
CefAudioParameters params_;
CefRefPtr<AlloyBrowserHostImpl> browser_;
CefRefPtr<CefBrowserHostImpl> browser_;
CefRefPtr<CefAudioHandler> audio_handler_;
std::unique_ptr<content::AudioLoopbackStreamCreator> audio_stream_creator_;
scoped_refptr<media::AudioInputDevice> audio_input_device_;

View File

@@ -1,616 +0,0 @@
// Copyright 2020 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 "libcef/browser/browser_contents_delegate.h"
#include "libcef/browser/browser_host_base.h"
#include "libcef/browser/browser_platform_delegate.h"
#include "libcef/browser/browser_util.h"
#include "content/public/browser/keyboard_event_processing_result.h"
#include "content/public/browser/native_web_keyboard_event.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_view_host.h"
using content::KeyboardEventProcessingResult;
CefBrowserContentsDelegate::CefBrowserContentsDelegate(
scoped_refptr<CefBrowserInfo> browser_info)
: browser_info_(browser_info) {
DCHECK(browser_info_->browser());
}
void CefBrowserContentsDelegate::ObserveWebContents(
content::WebContents* new_contents) {
WebContentsObserver::Observe(new_contents);
if (new_contents) {
registrar_.reset(new content::NotificationRegistrar);
// When navigating through the history, the restored NavigationEntry's title
// will be used. If the entry ends up having the same title after we return
// to it, as will usually be the case, the
// NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED will then be suppressed, since
// the NavigationEntry's title hasn't changed.
registrar_->Add(this, content::NOTIFICATION_LOAD_STOP,
content::Source<content::NavigationController>(
&new_contents->GetController()));
// Make sure RenderViewCreated is called at least one time.
RenderViewCreated(new_contents->GetRenderViewHost());
// Create the frame representation before OnAfterCreated is called for a new
// browser. Additionally, RenderFrameCreated is otherwise not called at all
// for new popup browsers.
RenderFrameCreated(new_contents->GetMainFrame());
} else {
registrar_.reset();
}
}
void CefBrowserContentsDelegate::AddObserver(Observer* observer) {
observers_.AddObserver(observer);
}
void CefBrowserContentsDelegate::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer);
}
// |source| may be NULL for navigations in the current tab, or if the
// navigation originates from a guest view via MaybeAllowNavigation.
content::WebContents* CefBrowserContentsDelegate::OpenURLFromTab(
content::WebContents* source,
const content::OpenURLParams& params) {
bool cancel = false;
if (auto c = client()) {
if (auto handler = c->GetRequestHandler()) {
cancel = handler->OnOpenURLFromTab(
browser(), browser()->GetFrame(params.frame_tree_node_id),
params.url.spec(),
static_cast<cef_window_open_disposition_t>(params.disposition),
params.user_gesture);
}
}
// Returning nullptr will cancel the navigation.
return cancel ? nullptr : web_contents();
}
void CefBrowserContentsDelegate::LoadingStateChanged(
content::WebContents* source,
bool to_different_document) {
const int current_index =
source->GetController().GetLastCommittedEntryIndex();
const int max_index = source->GetController().GetEntryCount() - 1;
const bool is_loading = source->IsLoading();
const bool can_go_back = (current_index > 0);
const bool can_go_forward = (current_index < max_index);
// This method may be called multiple times in a row with |is_loading|
// true as a result of https://crrev.com/5e750ad0. Ignore the 2nd+ times.
if (is_loading_ == is_loading && can_go_back_ == can_go_back &&
can_go_forward_ == can_go_forward) {
return;
}
is_loading_ = is_loading;
can_go_back_ = can_go_back;
can_go_forward_ = can_go_forward;
OnStateChanged(State::kNavigation);
if (auto c = client()) {
if (auto handler = c->GetLoadHandler()) {
handler->OnLoadingStateChange(browser(), is_loading, can_go_back,
can_go_forward);
}
}
}
void CefBrowserContentsDelegate::UpdateTargetURL(content::WebContents* source,
const GURL& url) {
if (auto c = client()) {
if (auto handler = c->GetDisplayHandler()) {
handler->OnStatusMessage(browser(), url.spec());
}
}
}
bool CefBrowserContentsDelegate::DidAddMessageToConsole(
content::WebContents* source,
blink::mojom::ConsoleMessageLevel log_level,
const base::string16& message,
int32_t line_no,
const base::string16& source_id) {
if (auto c = client()) {
if (auto handler = c->GetDisplayHandler()) {
// Use LOGSEVERITY_DEBUG for unrecognized |level| values.
cef_log_severity_t cef_level = LOGSEVERITY_DEBUG;
switch (log_level) {
case blink::mojom::ConsoleMessageLevel::kVerbose:
cef_level = LOGSEVERITY_DEBUG;
break;
case blink::mojom::ConsoleMessageLevel::kInfo:
cef_level = LOGSEVERITY_INFO;
break;
case blink::mojom::ConsoleMessageLevel::kWarning:
cef_level = LOGSEVERITY_WARNING;
break;
case blink::mojom::ConsoleMessageLevel::kError:
cef_level = LOGSEVERITY_ERROR;
break;
}
return handler->OnConsoleMessage(browser(), cef_level, message, source_id,
line_no);
}
}
return false;
}
void CefBrowserContentsDelegate::DidNavigateMainFramePostCommit(
content::WebContents* web_contents) {
has_document_ = false;
OnStateChanged(State::kDocument);
}
void CefBrowserContentsDelegate::EnterFullscreenModeForTab(
content::RenderFrameHost* requesting_frame,
const blink::mojom::FullscreenOptions& options) {
OnFullscreenModeChange(/*fullscreen=*/true);
}
void CefBrowserContentsDelegate::ExitFullscreenModeForTab(
content::WebContents* web_contents) {
OnFullscreenModeChange(/*fullscreen=*/false);
}
KeyboardEventProcessingResult
CefBrowserContentsDelegate::PreHandleKeyboardEvent(
content::WebContents* source,
const content::NativeWebKeyboardEvent& event) {
if (auto delegate = platform_delegate()) {
if (auto c = client()) {
if (auto handler = c->GetKeyboardHandler()) {
CefKeyEvent cef_event;
if (browser_util::GetCefKeyEvent(event, cef_event)) {
cef_event.focus_on_editable_field = focus_on_editable_field_;
auto event_handle = delegate->GetEventHandle(event);
bool is_keyboard_shortcut = false;
bool result = handler->OnPreKeyEvent(
browser(), cef_event, event_handle, &is_keyboard_shortcut);
if (result) {
return KeyboardEventProcessingResult::HANDLED;
} else if (is_keyboard_shortcut) {
return KeyboardEventProcessingResult::NOT_HANDLED_IS_SHORTCUT;
}
}
}
}
}
return KeyboardEventProcessingResult::NOT_HANDLED;
}
bool CefBrowserContentsDelegate::HandleKeyboardEvent(
content::WebContents* source,
const content::NativeWebKeyboardEvent& event) {
// Check to see if event should be ignored.
if (event.skip_in_browser)
return false;
if (auto delegate = platform_delegate()) {
if (auto c = client()) {
if (auto handler = c->GetKeyboardHandler()) {
CefKeyEvent cef_event;
if (browser_util::GetCefKeyEvent(event, cef_event)) {
cef_event.focus_on_editable_field = focus_on_editable_field_;
auto event_handle = delegate->GetEventHandle(event);
if (handler->OnKeyEvent(browser(), cef_event, event_handle)) {
return true;
}
}
}
}
}
return false;
}
void CefBrowserContentsDelegate::RenderFrameCreated(
content::RenderFrameHost* render_frame_host) {
browser_info_->MaybeCreateFrame(render_frame_host, false /* is_guest_view */);
}
void CefBrowserContentsDelegate::RenderFrameHostChanged(
content::RenderFrameHost* old_host,
content::RenderFrameHost* new_host) {
// Just in case RenderFrameCreated wasn't called for some reason.
RenderFrameCreated(new_host);
}
void CefBrowserContentsDelegate::RenderFrameDeleted(
content::RenderFrameHost* render_frame_host) {
const auto frame_id = CefFrameHostImpl::MakeFrameId(render_frame_host);
browser_info_->RemoveFrame(render_frame_host);
if (focused_frame_ && focused_frame_->GetIdentifier() == frame_id) {
focused_frame_ = nullptr;
OnStateChanged(State::kFocusedFrame);
}
}
void CefBrowserContentsDelegate::RenderViewCreated(
content::RenderViewHost* render_view_host) {
// May be already registered if the renderer crashed previously.
if (!registrar_->IsRegistered(
this, content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
content::Source<content::RenderViewHost>(render_view_host))) {
registrar_->Add(this, content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
content::Source<content::RenderViewHost>(render_view_host));
}
}
void CefBrowserContentsDelegate::RenderViewDeleted(
content::RenderViewHost* render_view_host) {
if (registrar_->IsRegistered(
this, content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
content::Source<content::RenderViewHost>(render_view_host))) {
registrar_->Remove(
this, content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
content::Source<content::RenderViewHost>(render_view_host));
}
}
void CefBrowserContentsDelegate::RenderViewReady() {
if (auto c = client()) {
if (auto handler = c->GetRequestHandler()) {
handler->OnRenderViewReady(browser());
}
}
}
void CefBrowserContentsDelegate::RenderProcessGone(
base::TerminationStatus status) {
cef_termination_status_t ts = TS_ABNORMAL_TERMINATION;
if (status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED)
ts = TS_PROCESS_WAS_KILLED;
else if (status == base::TERMINATION_STATUS_PROCESS_CRASHED)
ts = TS_PROCESS_CRASHED;
else if (status == base::TERMINATION_STATUS_OOM)
ts = TS_PROCESS_OOM;
else if (status != base::TERMINATION_STATUS_ABNORMAL_TERMINATION)
return;
if (auto c = client()) {
if (auto handler = c->GetRequestHandler()) {
auto navigation_lock = browser_info_->CreateNavigationLock();
handler->OnRenderProcessTerminated(browser(), ts);
}
}
}
void CefBrowserContentsDelegate::OnFrameFocused(
content::RenderFrameHost* render_frame_host) {
CefRefPtr<CefFrameHostImpl> frame = static_cast<CefFrameHostImpl*>(
browser_info_->GetFrameForHost(render_frame_host).get());
if (!frame || frame->IsFocused())
return;
CefRefPtr<CefFrameHostImpl> previous_frame = focused_frame_;
if (frame->IsMain())
focused_frame_ = nullptr;
else
focused_frame_ = frame;
if (!previous_frame) {
// The main frame is focused by default.
previous_frame = browser_info_->GetMainFrame();
}
if (previous_frame->GetIdentifier() != frame->GetIdentifier()) {
previous_frame->SetFocused(false);
frame->SetFocused(true);
}
OnStateChanged(State::kFocusedFrame);
}
void CefBrowserContentsDelegate::DocumentAvailableInMainFrame() {
has_document_ = true;
OnStateChanged(State::kDocument);
if (auto c = client()) {
if (auto handler = c->GetRequestHandler()) {
handler->OnDocumentAvailableInMainFrame(browser());
}
}
}
void CefBrowserContentsDelegate::LoadProgressChanged(double progress) {
if (auto c = client()) {
if (auto handler = c->GetDisplayHandler()) {
handler->OnLoadingProgressChange(browser(), progress);
}
}
}
void CefBrowserContentsDelegate::DidStopLoading() {
// Notify all renderers that loading has stopped. We used to use
// RenderFrameObserver::DidStopLoading in the renderer process but that was
// removed in https://crrev.com/3e37dd0ead. However, that callback wasn't
// necessarily accurate because it wasn't called in all of the cases where
// RenderFrameImpl sends the FrameHostMsg_DidStopLoading message. This adds
// an additional round trip but should provide the same or improved
// functionality.
for (const auto& frame : browser_info_->GetAllFrames()) {
frame->MaybeSendDidStopLoading();
}
}
void CefBrowserContentsDelegate::DidFinishNavigation(
content::NavigationHandle* navigation_handle) {
const net::Error error_code = navigation_handle->GetNetErrorCode();
// Skip calls where the navigation has not yet committed and there is no
// error code. For example, when creating a browser without loading a URL.
if (!navigation_handle->HasCommitted() && error_code == net::OK)
return;
const bool is_main_frame = navigation_handle->IsInMainFrame();
const GURL& url =
(error_code == net::OK ? navigation_handle->GetURL() : GURL());
auto browser_info = browser_info_;
// May return NULL when starting a new navigation if the previous navigation
// caused the renderer process to crash during load.
CefRefPtr<CefFrameHostImpl> frame = browser_info->GetFrameForFrameTreeNode(
navigation_handle->GetFrameTreeNodeId());
if (!frame) {
if (is_main_frame) {
frame = browser_info->GetMainFrame();
} else {
frame =
browser_info->CreateTempSubFrame(CefFrameHostImpl::kInvalidFrameId);
}
}
frame->RefreshAttributes();
if (error_code == net::OK) {
// The navigation has been committed and there is no error.
DCHECK(navigation_handle->HasCommitted());
// Don't call OnLoadStart for same page navigations (fragments,
// history state).
if (!navigation_handle->IsSameDocument()) {
OnLoadStart(frame.get(), navigation_handle->GetPageTransition());
}
if (is_main_frame) {
OnAddressChange(url);
}
} else {
// The navigation failed with an error. This may happen before commit
// (e.g. network error) or after commit (e.g. response filter error).
// If the error happened before commit then this call will originate from
// RenderFrameHostImpl::OnDidFailProvisionalLoadWithError.
// OnLoadStart/OnLoadEnd will not be called.
OnLoadError(frame.get(), navigation_handle->GetURL(), error_code);
}
}
void CefBrowserContentsDelegate::DidFailLoad(
content::RenderFrameHost* render_frame_host,
const GURL& validated_url,
int error_code) {
// The navigation failed after commit. OnLoadStart was called so we also
// call OnLoadEnd.
auto frame = browser_info_->GetFrameForHost(render_frame_host);
frame->RefreshAttributes();
OnLoadError(frame, validated_url, error_code);
OnLoadEnd(frame, validated_url, error_code);
}
bool CefBrowserContentsDelegate::OnMessageReceived(
const IPC::Message& message,
content::RenderFrameHost* render_frame_host) {
// Messages may arrive after a frame is detached. Ignore those messages.
auto frame = browser_info_->GetFrameForHost(render_frame_host);
if (frame) {
return static_cast<CefFrameHostImpl*>(frame.get())
->OnMessageReceived(message);
}
return false;
}
void CefBrowserContentsDelegate::TitleWasSet(content::NavigationEntry* entry) {
// |entry| may be NULL if a popup is created via window.open and never
// navigated.
if (entry)
OnTitleChange(entry->GetTitle());
else if (web_contents())
OnTitleChange(web_contents()->GetTitle());
}
void CefBrowserContentsDelegate::PluginCrashed(
const base::FilePath& plugin_path,
base::ProcessId plugin_pid) {
if (auto c = client()) {
if (auto handler = c->GetRequestHandler()) {
handler->OnPluginCrashed(browser(), plugin_path.value());
}
}
}
void CefBrowserContentsDelegate::DidUpdateFaviconURL(
content::RenderFrameHost* render_frame_host,
const std::vector<blink::mojom::FaviconURLPtr>& candidates) {
if (auto c = client()) {
if (auto handler = c->GetDisplayHandler()) {
std::vector<CefString> icon_urls;
for (const auto& icon : candidates) {
if (icon->icon_type == blink::mojom::FaviconIconType::kFavicon) {
icon_urls.push_back(icon->icon_url.spec());
}
}
if (!icon_urls.empty()) {
handler->OnFaviconURLChange(browser(), icon_urls);
}
}
}
}
void CefBrowserContentsDelegate::OnWebContentsFocused(
content::RenderWidgetHost* render_widget_host) {
if (auto c = client()) {
if (auto handler = c->GetFocusHandler()) {
handler->OnGotFocus(browser());
}
}
}
void CefBrowserContentsDelegate::WebContentsDestroyed() {
auto wc = web_contents();
ObserveWebContents(nullptr);
for (auto& observer : observers_) {
observer.OnWebContentsDestroyed(wc);
}
}
void CefBrowserContentsDelegate::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
DCHECK(type == content::NOTIFICATION_LOAD_STOP ||
type == content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE);
if (type == content::NOTIFICATION_LOAD_STOP) {
content::NavigationController* controller =
content::Source<content::NavigationController>(source).ptr();
OnTitleChange(controller->GetWebContents()->GetTitle());
} else if (type == content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE) {
focus_on_editable_field_ = *content::Details<bool>(details).ptr();
}
}
void CefBrowserContentsDelegate::OnLoadEnd(CefRefPtr<CefFrame> frame,
const GURL& url,
int http_status_code) {
if (auto c = client()) {
if (auto handler = c->GetLoadHandler()) {
handler->OnLoadEnd(browser(), frame, http_status_code);
}
}
}
bool CefBrowserContentsDelegate::OnSetFocus(cef_focus_source_t source) {
// SetFocus() might be called while inside the OnSetFocus() callback. If
// so, don't re-enter the callback.
if (is_in_onsetfocus_)
return true;
if (auto c = client()) {
if (auto handler = c->GetFocusHandler()) {
is_in_onsetfocus_ = true;
bool handled = handler->OnSetFocus(browser(), source);
is_in_onsetfocus_ = false;
return handled;
}
}
return false;
}
CefRefPtr<CefClient> CefBrowserContentsDelegate::client() const {
if (auto b = browser()) {
return b->GetHost()->GetClient();
}
return nullptr;
}
CefRefPtr<CefBrowser> CefBrowserContentsDelegate::browser() const {
return browser_info_->browser();
}
CefBrowserPlatformDelegate* CefBrowserContentsDelegate::platform_delegate()
const {
auto browser = browser_info_->browser();
if (browser)
return browser->platform_delegate();
return nullptr;
}
void CefBrowserContentsDelegate::OnAddressChange(const GURL& url) {
if (auto c = client()) {
if (auto handler = c->GetDisplayHandler()) {
// On the handler of an address change.
handler->OnAddressChange(browser(), browser_info_->GetMainFrame(),
url.spec());
}
}
}
void CefBrowserContentsDelegate::OnLoadStart(
CefRefPtr<CefFrame> frame,
ui::PageTransition transition_type) {
if (auto c = client()) {
if (auto handler = c->GetLoadHandler()) {
// On the handler that loading has started.
handler->OnLoadStart(browser(), frame,
static_cast<cef_transition_type_t>(transition_type));
}
}
}
void CefBrowserContentsDelegate::OnLoadError(CefRefPtr<CefFrame> frame,
const GURL& url,
int error_code) {
if (auto c = client()) {
if (auto handler = c->GetLoadHandler()) {
auto navigation_lock = browser_info_->CreateNavigationLock();
// On the handler that loading has failed.
handler->OnLoadError(browser(), frame,
static_cast<cef_errorcode_t>(error_code),
net::ErrorToShortString(error_code), url.spec());
}
}
}
void CefBrowserContentsDelegate::OnTitleChange(const base::string16& title) {
if (auto c = client()) {
if (auto handler = c->GetDisplayHandler()) {
handler->OnTitleChange(browser(), title);
}
}
}
void CefBrowserContentsDelegate::OnFullscreenModeChange(bool fullscreen) {
if (fullscreen == is_fullscreen_)
return;
is_fullscreen_ = fullscreen;
OnStateChanged(State::kFullscreen);
if (auto c = client()) {
if (auto handler = c->GetDisplayHandler()) {
handler->OnFullscreenModeChange(browser(), fullscreen);
}
}
}
void CefBrowserContentsDelegate::OnStateChanged(State state_changed) {
for (auto& observer : observers_) {
observer.OnStateChanged(state_changed);
}
}

View File

@@ -1,198 +0,0 @@
// Copyright 2020 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_BROWSER_CONTENTS_DELEGATE_H_
#define CEF_LIBCEF_BROWSER_BROWSER_CONTENTS_DELEGATE_H_
#pragma once
#include <memory>
#include "libcef/browser/frame_host_impl.h"
#include "base/observer_list.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_observer.h"
class CefBrowser;
class CefBrowserInfo;
class CefBrowserPlatformDelegate;
class CefClient;
// Flags that represent which states have changed.
enum class CefBrowserContentsState : uint8_t {
kNone = 0,
kNavigation = (1 << 0),
kDocument = (1 << 1),
kFullscreen = (1 << 2),
kFocusedFrame = (1 << 3),
};
constexpr inline CefBrowserContentsState operator&(
CefBrowserContentsState lhs,
CefBrowserContentsState rhs) {
return static_cast<CefBrowserContentsState>(static_cast<int>(lhs) &
static_cast<int>(rhs));
}
constexpr inline CefBrowserContentsState operator|(
CefBrowserContentsState lhs,
CefBrowserContentsState rhs) {
return static_cast<CefBrowserContentsState>(static_cast<int>(lhs) |
static_cast<int>(rhs));
}
// Tracks state and executes client callbacks based on WebContents callbacks.
// Includes functionality that is shared by the alloy and chrome runtimes.
// Only accessed on the UI thread.
class CefBrowserContentsDelegate : public content::WebContentsDelegate,
public content::WebContentsObserver,
public content::NotificationObserver {
public:
using State = CefBrowserContentsState;
// Interface to implement for observers that wish to be informed of changes
// to the delegate. All methods will be called on the UI thread.
class Observer : public base::CheckedObserver {
public:
// Called after state has changed and before the associated CefClient
// callback is executed.
virtual void OnStateChanged(State state_changed) = 0;
// Called when the associated WebContents is destroyed.
virtual void OnWebContentsDestroyed(content::WebContents* web_contents) = 0;
protected:
~Observer() override {}
};
explicit CefBrowserContentsDelegate(
scoped_refptr<CefBrowserInfo> browser_info);
void ObserveWebContents(content::WebContents* new_contents);
// Manage observer objects. The observer must either outlive this object or
// be removed before destruction.
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
// WebContentsDelegate methods:
content::WebContents* OpenURLFromTab(
content::WebContents* source,
const content::OpenURLParams& params) override;
void LoadingStateChanged(content::WebContents* source,
bool to_different_document) override;
void UpdateTargetURL(content::WebContents* source, const GURL& url) override;
bool DidAddMessageToConsole(content::WebContents* source,
blink::mojom::ConsoleMessageLevel log_level,
const base::string16& message,
int32_t line_no,
const base::string16& source_id) override;
void DidNavigateMainFramePostCommit(
content::WebContents* web_contents) override;
void EnterFullscreenModeForTab(
content::RenderFrameHost* requesting_frame,
const blink::mojom::FullscreenOptions& options) override;
void ExitFullscreenModeForTab(content::WebContents* web_contents) override;
content::KeyboardEventProcessingResult PreHandleKeyboardEvent(
content::WebContents* source,
const content::NativeWebKeyboardEvent& event) override;
bool HandleKeyboardEvent(
content::WebContents* source,
const content::NativeWebKeyboardEvent& event) override;
// WebContentsObserver methods:
void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override;
void RenderFrameHostChanged(content::RenderFrameHost* old_host,
content::RenderFrameHost* new_host) override;
void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override;
void RenderViewCreated(content::RenderViewHost* render_view_host) override;
void RenderViewDeleted(content::RenderViewHost* render_view_host) override;
void RenderViewReady() override;
void RenderProcessGone(base::TerminationStatus status) override;
void OnFrameFocused(content::RenderFrameHost* render_frame_host) override;
void DocumentAvailableInMainFrame() override;
void LoadProgressChanged(double progress) override;
void DidStopLoading() override;
void DidFinishNavigation(
content::NavigationHandle* navigation_handle) override;
void DidFailLoad(content::RenderFrameHost* render_frame_host,
const GURL& validated_url,
int error_code) override;
bool OnMessageReceived(const IPC::Message& message,
content::RenderFrameHost* render_frame_host) override;
void TitleWasSet(content::NavigationEntry* entry) override;
void PluginCrashed(const base::FilePath& plugin_path,
base::ProcessId plugin_pid) override;
void DidUpdateFaviconURL(
content::RenderFrameHost* render_frame_host,
const std::vector<blink::mojom::FaviconURLPtr>& candidates) override;
void OnWebContentsFocused(
content::RenderWidgetHost* render_widget_host) override;
void WebContentsDestroyed() override;
// NotificationObserver methods.
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
// Accessors for state information. Changes will be signaled to
// Observer::OnStateChanged.
bool is_loading() const { return is_loading_; }
bool can_go_back() const { return can_go_back_; }
bool can_go_forward() const { return can_go_forward_; }
bool has_document() const { return has_document_; }
bool is_fullscreen() const { return is_fullscreen_; }
CefRefPtr<CefFrameHostImpl> focused_frame() const { return focused_frame_; }
// Helpers for executing client callbacks.
// TODO(cef): Make this private if/when possible.
void OnLoadEnd(CefRefPtr<CefFrame> frame,
const GURL& url,
int http_status_code);
bool OnSetFocus(cef_focus_source_t source);
private:
CefRefPtr<CefClient> client() const;
CefRefPtr<CefBrowser> browser() const;
CefBrowserPlatformDelegate* platform_delegate() const;
// Helpers for executing client callbacks.
void OnAddressChange(const GURL& url);
void OnLoadStart(CefRefPtr<CefFrame> frame,
ui::PageTransition transition_type);
void OnLoadError(CefRefPtr<CefFrame> frame, const GURL& url, int error_code);
void OnTitleChange(const base::string16& title);
void OnFullscreenModeChange(bool fullscreen);
void OnStateChanged(State state_changed);
scoped_refptr<CefBrowserInfo> browser_info_;
bool is_loading_ = false;
bool can_go_back_ = false;
bool can_go_forward_ = false;
bool has_document_ = false;
bool is_fullscreen_ = false;
// The currently focused frame, or nullptr if the main frame is focused.
CefRefPtr<CefFrameHostImpl> focused_frame_;
// True if currently in the OnSetFocus callback.
bool is_in_onsetfocus_ = false;
// Observers that want to be notified of changes to this object.
base::ObserverList<Observer> observers_;
// Used for managing notification subscriptions.
std::unique_ptr<content::NotificationRegistrar> registrar_;
// True if the focus is currently on an editable field on the page.
bool focus_on_editable_field_ = false;
DISALLOW_COPY_AND_ASSIGN(CefBrowserContentsDelegate);
};
#endif // CEF_LIBCEF_BROWSER_BROWSER_CONTENTS_DELEGATE_H_

View File

@@ -456,6 +456,8 @@ bool CefBrowserContext::IsPrintPreviewSupported() const {
return true;
}
void CefBrowserContext::AddVisitedURLs(const std::vector<GURL>& urls) {}
network::mojom::NetworkContext* CefBrowserContext::GetNetworkContext() {
CEF_REQUIRE_UIT();
auto browser_context = AsBrowserContext();
@@ -470,12 +472,3 @@ CefMediaRouterManager* CefBrowserContext::GetMediaRouterManager() {
}
return media_router_manager_.get();
}
CefBrowserContext::CookieableSchemes CefBrowserContext::GetCookieableSchemes()
const {
CEF_REQUIRE_UIT();
if (cookieable_schemes_)
return cookieable_schemes_;
return CefCookieManagerImpl::GetGlobalCookieableSchemes();
}

View File

@@ -27,7 +27,7 @@
// Content API representation of a browser. Created by BHI or the system (for
// popups) and owned by BHI. Keeps a pointer to the content::BrowserContext.
//
// BHI = AlloyBrowserHostImpl
// BHI = CefBrowserHostImpl
// Implements the CefBrowser and CefBrowserHost interfaces which are exposed
// to clients. References an RCI instance. Owns a WC. Lifespan is controlled
// by client references and CefBrowserInfoManager (until the browser has
@@ -62,9 +62,9 @@
//
//
// How shutdown works:
// 1. AlloyBrowserHostImpl::DestroyBrowser is called on the UI thread after the
// 1. CefBrowserHostImpl::DestroyBrowser is called on the UI thread after the
// browser is closed and deletes the WebContents.
// 1. AlloyBrowserHostImpl is destroyed on any thread when the last reference
// 1. CefBrowserHostImpl is destroyed on any thread when the last reference
// is released.
// 2. CefRequestContextImpl is destroyed (possibly asynchronously) on the UI
// thread when the last reference is released.
@@ -85,7 +85,7 @@ class Profile;
// Main entry point for configuring behavior on a per-RequestContext basis. The
// content::BrowserContext represented by this class is passed to
// WebContents::Create in AlloyBrowserHostImpl::CreateInternal. Only accessed on
// WebContents::Create in CefBrowserHostImpl::CreateInternal. Only accessed on
// the UI thread unless otherwise indicated.
class CefBrowserContext {
public:
@@ -188,20 +188,19 @@ class CefBrowserContext {
// Returns true if this context supports print preview.
virtual bool IsPrintPreviewSupported() const;
// Called from CefBrowserHostImpl::DidNavigateAnyFrame to update the table of
// visited links.
virtual void AddVisitedURLs(const std::vector<GURL>& urls);
network::mojom::NetworkContext* GetNetworkContext();
CefMediaRouterManager* GetMediaRouterManager();
using CookieableSchemes = base::Optional<std::vector<std::string>>;
// Returns the schemes associated with this context specifically, or the
// global configuration if unset.
CookieableSchemes GetCookieableSchemes() const;
// Set the schemes associated with this context specifically.
void set_cookieable_schemes(const CookieableSchemes& schemes) {
cookieable_schemes_ = schemes;
}
CookieableSchemes cookieable_schemes() const { return cookieable_schemes_; }
// These accessors are safe to call from any thread because the values don't
// change during this object's lifespan.

View File

@@ -6,7 +6,6 @@
#include "libcef/common/extensions/extensions_util.h"
#include "chrome/browser/content_settings/cookie_settings_factory.h"
#include "chrome/browser/media/router/chrome_media_router_factory.h"
#include "chrome/browser/plugins/plugin_prefs_factory.h"
#include "chrome/browser/profiles/renderer_updater_factory.h"
#include "chrome/browser/spellchecker/spellcheck_factory.h"
@@ -20,7 +19,6 @@ namespace cef {
void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
CookieSettingsFactory::GetInstance();
media_router::ChromeMediaRouterFactory::GetInstance();
PluginPrefsFactory::GetInstance();
PrefsTabHelper::GetServiceInstance();
RendererUpdaterFactory::GetInstance();

View File

@@ -1,789 +0,0 @@
// Copyright 2020 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 "libcef/browser/browser_host_base.h"
#include "libcef/browser/browser_info_manager.h"
#include "libcef/browser/browser_platform_delegate.h"
#include "libcef/browser/image_impl.h"
#include "libcef/browser/navigation_entry_impl.h"
#include "libcef/browser/net/scheme_handler.h"
#include "libcef/browser/thread_util.h"
#include "base/logging.h"
#include "chrome/browser/spellchecker/spellcheck_factory.h"
#include "chrome/browser/spellchecker/spellcheck_service.h"
#include "components/favicon/core/favicon_url.h"
#include "components/spellcheck/common/spellcheck_features.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/download_request_utils.h"
#include "content/public/browser/navigation_entry.h"
#include "ui/gfx/image/image_skia.h"
#if defined(OS_MAC)
#include "components/spellcheck/browser/spellcheck_platform.h"
#endif
namespace {
// Associates a CefBrowserHostBase instance with a WebContents. This object will
// be deleted automatically when the WebContents is destroyed.
class WebContentsUserDataAdapter : public base::SupportsUserData::Data {
public:
static void Register(CefRefPtr<CefBrowserHostBase> browser) {
new WebContentsUserDataAdapter(browser);
}
static CefRefPtr<CefBrowserHostBase> Get(
const content::WebContents* web_contents) {
WebContentsUserDataAdapter* adapter =
static_cast<WebContentsUserDataAdapter*>(
web_contents->GetUserData(UserDataKey()));
if (adapter)
return adapter->browser_;
return nullptr;
}
private:
WebContentsUserDataAdapter(CefRefPtr<CefBrowserHostBase> browser)
: browser_(browser) {
auto web_contents = browser->GetWebContents();
DCHECK(web_contents);
web_contents->SetUserData(UserDataKey(), base::WrapUnique(this));
}
static void* UserDataKey() {
// We just need a unique constant. Use the address of a static that
// COMDAT folding won't touch in an optimizing linker.
static int data_key = 0;
return reinterpret_cast<void*>(&data_key);
}
CefRefPtr<CefBrowserHostBase> browser_;
};
} // namespace
// static
CefRefPtr<CefBrowserHostBase> CefBrowserHostBase::GetBrowserForHost(
const content::RenderViewHost* host) {
DCHECK(host);
CEF_REQUIRE_UIT();
content::WebContents* web_contents = content::WebContents::FromRenderViewHost(
const_cast<content::RenderViewHost*>(host));
if (web_contents)
return GetBrowserForContents(web_contents);
return nullptr;
}
// static
CefRefPtr<CefBrowserHostBase> CefBrowserHostBase::GetBrowserForHost(
const content::RenderFrameHost* host) {
DCHECK(host);
CEF_REQUIRE_UIT();
content::WebContents* web_contents =
content::WebContents::FromRenderFrameHost(
const_cast<content::RenderFrameHost*>(host));
if (web_contents)
return GetBrowserForContents(web_contents);
return nullptr;
}
// static
CefRefPtr<CefBrowserHostBase> CefBrowserHostBase::GetBrowserForContents(
const content::WebContents* contents) {
DCHECK(contents);
CEF_REQUIRE_UIT();
return WebContentsUserDataAdapter::Get(contents);
}
// static
CefRefPtr<CefBrowserHostBase> CefBrowserHostBase::GetBrowserForFrameTreeNode(
int frame_tree_node_id) {
// Use the thread-safe approach.
auto info =
CefBrowserInfoManager::GetInstance()->GetBrowserInfoForFrameTreeNode(
frame_tree_node_id);
if (info) {
auto browser = info->browser();
if (!browser) {
LOG(WARNING) << "Found browser id " << info->browser_id()
<< " but no browser object matching frame tree node id "
<< frame_tree_node_id;
}
return browser;
}
return nullptr;
}
// static
CefRefPtr<CefBrowserHostBase> CefBrowserHostBase::GetBrowserForFrameRoute(
int render_process_id,
int render_routing_id) {
if (render_process_id == -1 || render_routing_id == MSG_ROUTING_NONE)
return nullptr;
if (CEF_CURRENTLY_ON_UIT()) {
// Use the non-thread-safe but potentially faster approach.
content::RenderFrameHost* render_frame_host =
content::RenderFrameHost::FromID(render_process_id, render_routing_id);
if (!render_frame_host)
return nullptr;
return GetBrowserForHost(render_frame_host);
} else {
// Use the thread-safe approach.
bool is_guest_view = false;
auto info =
CefBrowserInfoManager::GetInstance()->GetBrowserInfoForFrameRoute(
render_process_id, render_routing_id, &is_guest_view);
if (info && !is_guest_view) {
auto browser = info->browser();
if (!browser) {
LOG(WARNING) << "Found browser id " << info->browser_id()
<< " but no browser object matching frame process id "
<< render_process_id << " and routing id "
<< render_routing_id;
}
return browser;
}
return nullptr;
}
}
CefBrowserHostBase::CefBrowserHostBase(
const CefBrowserSettings& settings,
CefRefPtr<CefClient> client,
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate,
scoped_refptr<CefBrowserInfo> browser_info,
CefRefPtr<CefRequestContextImpl> request_context)
: settings_(settings),
client_(client),
platform_delegate_(std::move(platform_delegate)),
browser_info_(browser_info),
request_context_(request_context) {
CEF_REQUIRE_UIT();
DCHECK(!browser_info_->browser().get());
browser_info_->SetBrowser(this);
contents_delegate_ =
std::make_unique<CefBrowserContentsDelegate>(browser_info_);
contents_delegate_->AddObserver(this);
}
void CefBrowserHostBase::InitializeBrowser() {
CEF_REQUIRE_UIT();
// Associate the WebContents with this browser object.
DCHECK(GetWebContents());
WebContentsUserDataAdapter::Register(this);
}
void CefBrowserHostBase::DestroyBrowser() {
CEF_REQUIRE_UIT();
platform_delegate_.reset(nullptr);
contents_delegate_->RemoveObserver(this);
contents_delegate_->ObserveWebContents(nullptr);
CefBrowserInfoManager::GetInstance()->RemoveBrowserInfo(browser_info_);
browser_info_->SetBrowser(nullptr);
}
CefRefPtr<CefBrowser> CefBrowserHostBase::GetBrowser() {
return this;
}
CefRefPtr<CefClient> CefBrowserHostBase::GetClient() {
return client_;
}
CefRefPtr<CefRequestContext> CefBrowserHostBase::GetRequestContext() {
return request_context_;
}
void CefBrowserHostBase::StartDownload(const CefString& url) {
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(
CEF_UIT, base::BindOnce(&CefBrowserHostBase::StartDownload, this, url));
return;
}
GURL gurl = GURL(url.ToString());
if (gurl.is_empty() || !gurl.is_valid())
return;
auto web_contents = GetWebContents();
if (!web_contents)
return;
auto browser_context = web_contents->GetBrowserContext();
if (!browser_context)
return;
content::DownloadManager* manager =
content::BrowserContext::GetDownloadManager(browser_context);
if (!manager)
return;
std::unique_ptr<download::DownloadUrlParameters> params(
content::DownloadRequestUtils::CreateDownloadForWebContentsMainFrame(
web_contents, gurl, MISSING_TRAFFIC_ANNOTATION));
manager->DownloadUrl(std::move(params));
}
void CefBrowserHostBase::DownloadImage(
const CefString& image_url,
bool is_favicon,
uint32 max_image_size,
bool bypass_cache,
CefRefPtr<CefDownloadImageCallback> callback) {
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(
CEF_UIT,
base::BindOnce(&CefBrowserHostBase::DownloadImage, this, image_url,
is_favicon, max_image_size, bypass_cache, callback));
return;
}
if (!callback)
return;
GURL gurl = GURL(image_url.ToString());
if (gurl.is_empty() || !gurl.is_valid())
return;
auto web_contents = GetWebContents();
if (!web_contents)
return;
web_contents->DownloadImage(
gurl, is_favicon, max_image_size,
max_image_size * gfx::ImageSkia::GetMaxSupportedScale(), bypass_cache,
base::BindOnce(
[](uint32 max_image_size,
CefRefPtr<CefDownloadImageCallback> callback, int id,
int http_status_code, const GURL& image_url,
const std::vector<SkBitmap>& bitmaps,
const std::vector<gfx::Size>& sizes) {
CEF_REQUIRE_UIT();
CefRefPtr<CefImageImpl> image_impl;
if (!bitmaps.empty()) {
image_impl = new CefImageImpl();
image_impl->AddBitmaps(max_image_size, bitmaps);
}
callback->OnDownloadImageFinished(
image_url.spec(), http_status_code, image_impl.get());
},
max_image_size, callback));
}
void CefBrowserHostBase::GetNavigationEntries(
CefRefPtr<CefNavigationEntryVisitor> visitor,
bool current_only) {
DCHECK(visitor.get());
if (!visitor.get())
return;
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(
CEF_UIT, base::BindOnce(&CefBrowserHostBase::GetNavigationEntries, this,
visitor, current_only));
return;
}
auto web_contents = GetWebContents();
if (!web_contents)
return;
content::NavigationController& controller = web_contents->GetController();
const int total = controller.GetEntryCount();
const int current = controller.GetCurrentEntryIndex();
if (current_only) {
// Visit only the current entry.
CefRefPtr<CefNavigationEntryImpl> entry =
new CefNavigationEntryImpl(controller.GetEntryAtIndex(current));
visitor->Visit(entry.get(), true, current, total);
entry->Detach(nullptr);
} else {
// Visit all entries.
bool cont = true;
for (int i = 0; i < total && cont; ++i) {
CefRefPtr<CefNavigationEntryImpl> entry =
new CefNavigationEntryImpl(controller.GetEntryAtIndex(i));
cont = visitor->Visit(entry.get(), (i == current), i, total);
entry->Detach(nullptr);
}
}
}
CefRefPtr<CefNavigationEntry> CefBrowserHostBase::GetVisibleNavigationEntry() {
if (!CEF_CURRENTLY_ON_UIT()) {
NOTREACHED() << "called on invalid thread";
return nullptr;
}
content::NavigationEntry* entry = nullptr;
auto web_contents = GetWebContents();
if (web_contents)
entry = web_contents->GetController().GetVisibleEntry();
if (!entry)
return nullptr;
return new CefNavigationEntryImpl(entry);
}
void CefBrowserHostBase::ReplaceMisspelling(const CefString& word) {
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(
CEF_UIT,
base::BindOnce(&CefBrowserHostBase::ReplaceMisspelling, this, word));
return;
}
auto web_contents = GetWebContents();
if (web_contents)
web_contents->ReplaceMisspelling(word);
}
void CefBrowserHostBase::AddWordToDictionary(const CefString& word) {
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(
CEF_UIT,
base::BindOnce(&CefBrowserHostBase::AddWordToDictionary, this, word));
return;
}
auto web_contents = GetWebContents();
if (!web_contents)
return;
SpellcheckService* spellcheck = nullptr;
content::BrowserContext* browser_context = web_contents->GetBrowserContext();
if (browser_context) {
spellcheck = SpellcheckServiceFactory::GetForContext(browser_context);
if (spellcheck)
spellcheck->GetCustomDictionary()->AddWord(word);
}
#if defined(OS_MAC)
if (spellcheck && spellcheck::UseBrowserSpellChecker()) {
spellcheck_platform::AddWord(spellcheck->platform_spell_checker(), word);
}
#endif
}
void CefBrowserHostBase::SendKeyEvent(const CefKeyEvent& event) {
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(CEF_UIT, base::BindOnce(&CefBrowserHostBase::SendKeyEvent,
this, event));
return;
}
if (platform_delegate_)
platform_delegate_->SendKeyEvent(event);
}
void CefBrowserHostBase::SendMouseClickEvent(const CefMouseEvent& event,
MouseButtonType type,
bool mouseUp,
int clickCount) {
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(CEF_UIT,
base::BindOnce(&CefBrowserHostBase::SendMouseClickEvent, this,
event, type, mouseUp, clickCount));
return;
}
if (platform_delegate_) {
platform_delegate_->SendMouseClickEvent(event, type, mouseUp, clickCount);
}
}
void CefBrowserHostBase::SendMouseMoveEvent(const CefMouseEvent& event,
bool mouseLeave) {
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(CEF_UIT,
base::BindOnce(&CefBrowserHostBase::SendMouseMoveEvent, this,
event, mouseLeave));
return;
}
if (platform_delegate_) {
platform_delegate_->SendMouseMoveEvent(event, mouseLeave);
}
}
void CefBrowserHostBase::SendMouseWheelEvent(const CefMouseEvent& event,
int deltaX,
int deltaY) {
if (deltaX == 0 && deltaY == 0) {
// Nothing to do.
return;
}
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(CEF_UIT,
base::BindOnce(&CefBrowserHostBase::SendMouseWheelEvent, this,
event, deltaX, deltaY));
return;
}
if (platform_delegate_) {
platform_delegate_->SendMouseWheelEvent(event, deltaX, deltaY);
}
}
CefRefPtr<CefBrowserHost> CefBrowserHostBase::GetHost() {
return this;
}
bool CefBrowserHostBase::CanGoBack() {
base::AutoLock lock_scope(state_lock_);
return can_go_back_;
}
void CefBrowserHostBase::GoBack() {
auto callback = base::BindOnce(&CefBrowserHostBase::GoBack, this);
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(CEF_UIT, std::move(callback));
return;
}
if (browser_info_->IsNavigationLocked(std::move(callback))) {
return;
}
auto wc = GetWebContents();
if (wc && wc->GetController().CanGoBack()) {
wc->GetController().GoBack();
}
}
bool CefBrowserHostBase::CanGoForward() {
base::AutoLock lock_scope(state_lock_);
return can_go_forward_;
}
void CefBrowserHostBase::GoForward() {
auto callback = base::BindOnce(&CefBrowserHostBase::GoForward, this);
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(CEF_UIT, std::move(callback));
return;
}
if (browser_info_->IsNavigationLocked(std::move(callback))) {
return;
}
auto wc = GetWebContents();
if (wc && wc->GetController().CanGoForward()) {
wc->GetController().GoForward();
}
}
bool CefBrowserHostBase::IsLoading() {
base::AutoLock lock_scope(state_lock_);
return is_loading_;
}
void CefBrowserHostBase::Reload() {
auto callback = base::BindOnce(&CefBrowserHostBase::Reload, this);
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(CEF_UIT, std::move(callback));
return;
}
if (browser_info_->IsNavigationLocked(std::move(callback))) {
return;
}
auto wc = GetWebContents();
if (wc) {
wc->GetController().Reload(content::ReloadType::NORMAL, true);
}
}
void CefBrowserHostBase::ReloadIgnoreCache() {
auto callback = base::BindOnce(&CefBrowserHostBase::ReloadIgnoreCache, this);
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(CEF_UIT, std::move(callback));
return;
}
if (browser_info_->IsNavigationLocked(std::move(callback))) {
return;
}
auto wc = GetWebContents();
if (wc) {
wc->GetController().Reload(content::ReloadType::BYPASSING_CACHE, true);
}
}
void CefBrowserHostBase::StopLoad() {
auto callback = base::BindOnce(&CefBrowserHostBase::StopLoad, this);
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(CEF_UIT, std::move(callback));
return;
}
if (browser_info_->IsNavigationLocked(std::move(callback))) {
return;
}
auto wc = GetWebContents();
if (wc) {
wc->Stop();
}
}
int CefBrowserHostBase::GetIdentifier() {
return browser_id();
}
bool CefBrowserHostBase::IsSame(CefRefPtr<CefBrowser> that) {
auto impl = static_cast<CefBrowserHostBase*>(that.get());
return (impl == this);
}
bool CefBrowserHostBase::HasDocument() {
base::AutoLock lock_scope(state_lock_);
return has_document_;
}
bool CefBrowserHostBase::IsPopup() {
return browser_info_->is_popup();
}
CefRefPtr<CefFrame> CefBrowserHostBase::GetMainFrame() {
return GetFrame(CefFrameHostImpl::kMainFrameId);
}
CefRefPtr<CefFrame> CefBrowserHostBase::GetFocusedFrame() {
return GetFrame(CefFrameHostImpl::kFocusedFrameId);
}
CefRefPtr<CefFrame> CefBrowserHostBase::GetFrame(int64 identifier) {
if (identifier == CefFrameHostImpl::kInvalidFrameId) {
return nullptr;
} else if (identifier == CefFrameHostImpl::kMainFrameId) {
return browser_info_->GetMainFrame();
} else if (identifier == CefFrameHostImpl::kFocusedFrameId) {
base::AutoLock lock_scope(state_lock_);
if (!focused_frame_) {
// The main frame is focused by default.
return browser_info_->GetMainFrame();
}
return focused_frame_;
}
return browser_info_->GetFrameForId(identifier);
}
CefRefPtr<CefFrame> CefBrowserHostBase::GetFrame(const CefString& name) {
for (const auto& frame : browser_info_->GetAllFrames()) {
if (frame->GetName() == name)
return frame;
}
return nullptr;
}
size_t CefBrowserHostBase::GetFrameCount() {
return browser_info_->GetAllFrames().size();
}
void CefBrowserHostBase::GetFrameIdentifiers(std::vector<int64>& identifiers) {
if (identifiers.size() > 0)
identifiers.clear();
const auto frames = browser_info_->GetAllFrames();
if (frames.empty())
return;
identifiers.reserve(frames.size());
for (const auto& frame : frames) {
identifiers.push_back(frame->GetIdentifier());
}
}
void CefBrowserHostBase::GetFrameNames(std::vector<CefString>& names) {
if (names.size() > 0)
names.clear();
const auto frames = browser_info_->GetAllFrames();
if (frames.empty())
return;
names.reserve(frames.size());
for (const auto& frame : frames) {
names.push_back(frame->GetName());
}
}
void CefBrowserHostBase::OnStateChanged(CefBrowserContentsState state_changed) {
// Make sure that CefBrowser state is consistent before the associated
// CefClient callback is executed.
base::AutoLock lock_scope(state_lock_);
if ((state_changed & CefBrowserContentsState::kNavigation) ==
CefBrowserContentsState::kNavigation) {
is_loading_ = contents_delegate_->is_loading();
can_go_back_ = contents_delegate_->can_go_back();
can_go_forward_ = contents_delegate_->can_go_forward();
}
if ((state_changed & CefBrowserContentsState::kDocument) ==
CefBrowserContentsState::kDocument) {
has_document_ = contents_delegate_->has_document();
}
if ((state_changed & CefBrowserContentsState::kFullscreen) ==
CefBrowserContentsState::kFullscreen) {
is_fullscreen_ = contents_delegate_->is_fullscreen();
}
if ((state_changed & CefBrowserContentsState::kFocusedFrame) ==
CefBrowserContentsState::kFocusedFrame) {
focused_frame_ = contents_delegate_->focused_frame();
}
}
void CefBrowserHostBase::OnWebContentsDestroyed(
content::WebContents* web_contents) {}
CefRefPtr<CefFrame> CefBrowserHostBase::GetFrameForHost(
const content::RenderFrameHost* host) {
CEF_REQUIRE_UIT();
if (!host)
return nullptr;
return browser_info_->GetFrameForHost(host);
}
CefRefPtr<CefFrame> CefBrowserHostBase::GetFrameForFrameTreeNode(
int frame_tree_node_id) {
return browser_info_->GetFrameForFrameTreeNode(frame_tree_node_id, nullptr);
}
void CefBrowserHostBase::AddObserver(Observer* observer) {
CEF_REQUIRE_UIT();
observers_.AddObserver(observer);
}
void CefBrowserHostBase::RemoveObserver(Observer* observer) {
CEF_REQUIRE_UIT();
observers_.RemoveObserver(observer);
}
bool CefBrowserHostBase::HasObserver(Observer* observer) const {
CEF_REQUIRE_UIT();
return observers_.HasObserver(observer);
}
void CefBrowserHostBase::LoadMainFrameURL(
const content::OpenURLParams& params) {
if (!params.url.is_valid()) {
LOG(ERROR) << "Invalid URL: " << params.url.spec();
return;
}
auto callback =
base::BindOnce(&CefBrowserHostBase::LoadMainFrameURL, this, params);
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(CEF_UIT, std::move(callback));
return;
}
if (browser_info_->IsNavigationLocked(std::move(callback))) {
return;
}
if (Navigate(params)) {
OnSetFocus(FOCUS_SOURCE_NAVIGATION);
}
}
bool CefBrowserHostBase::Navigate(const content::OpenURLParams& params) {
CEF_REQUIRE_UIT();
auto web_contents = GetWebContents();
if (web_contents) {
web_contents->GetController().LoadURL(
params.url, params.referrer, params.transition, params.extra_headers);
return true;
}
return false;
}
void CefBrowserHostBase::OnDidFinishLoad(CefRefPtr<CefFrameHostImpl> frame,
const GURL& validated_url,
int http_status_code) {
frame->RefreshAttributes();
// Give internal scheme handlers an opportunity to update content.
scheme::DidFinishLoad(frame, validated_url);
contents_delegate_->OnLoadEnd(frame, validated_url, http_status_code);
}
void CefBrowserHostBase::ViewText(const std::string& text) {
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(CEF_UIT,
base::BindOnce(&CefBrowserHostBase::ViewText, this, text));
return;
}
if (platform_delegate_)
platform_delegate_->ViewText(text);
}
bool CefBrowserHostBase::MaybeAllowNavigation(
content::RenderFrameHost* opener,
bool is_guest_view,
const content::OpenURLParams& params) {
return true;
}
void CefBrowserHostBase::OnAfterCreated() {
CEF_REQUIRE_UIT();
if (client_) {
if (auto handler = client_->GetLifeSpanHandler()) {
handler->OnAfterCreated(this);
}
}
}
void CefBrowserHostBase::OnBeforeClose() {
CEF_REQUIRE_UIT();
if (client_) {
if (auto handler = client_->GetLifeSpanHandler()) {
handler->OnBeforeClose(this);
}
}
}
void CefBrowserHostBase::OnBrowserDestroyed() {
CEF_REQUIRE_UIT();
for (auto& observer : observers_)
observer.OnBrowserDestroyed(this);
}
int CefBrowserHostBase::browser_id() const {
return browser_info_->browser_id();
}
content::WebContents* CefBrowserHostBase::GetWebContents() const {
CEF_REQUIRE_UIT();
return contents_delegate_->web_contents();
}
content::BrowserContext* CefBrowserHostBase::GetBrowserContext() const {
CEF_REQUIRE_UIT();
auto web_contents = GetWebContents();
if (web_contents)
return web_contents->GetBrowserContext();
return nullptr;
}

View File

@@ -1,268 +0,0 @@
// Copyright 2020 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_BROWSER_HOST_BASE_H_
#define CEF_LIBCEF_BROWSER_BROWSER_HOST_BASE_H_
#pragma once
#include "include/cef_browser.h"
#include "include/cef_client.h"
#include "include/views/cef_browser_view.h"
#include "libcef/browser/browser_contents_delegate.h"
#include "libcef/browser/browser_info.h"
#include "libcef/browser/browser_platform_delegate.h"
#include "libcef/browser/frame_host_impl.h"
#include "libcef/browser/request_context_impl.h"
#include "base/observer_list.h"
#include "base/synchronization/lock.h"
#include "extensions/common/view_type.h"
namespace extensions {
class Extension;
}
// Parameters that are passed to the runtime-specific Create methods.
struct CefBrowserCreateParams {
CefBrowserCreateParams() {}
// Copy constructor used with the chrome runtime only.
CefBrowserCreateParams(const CefBrowserCreateParams& that) {
operator=(that);
}
CefBrowserCreateParams& operator=(const CefBrowserCreateParams& that) {
// Not all parameters can be copied.
client = that.client;
url = that.url;
settings = that.settings;
request_context = that.request_context;
extra_info = that.extra_info;
return *this;
}
// Platform-specific window creation info. Will be nullptr when creating a
// views-hosted browser. Currently used with the alloy runtime only.
std::unique_ptr<CefWindowInfo> window_info;
#if defined(USE_AURA)
// The BrowserView that will own a views-hosted browser. Will be nullptr for
// popup browsers (the BrowserView will be created later in that case).
// Currently used with the alloy runtime only.
CefRefPtr<CefBrowserView> browser_view;
#endif
// Client implementation. May be nullptr.
CefRefPtr<CefClient> client;
// Initial URL to load. May be empty. If this is a valid extension URL then
// the browser will be created as an app view extension host.
GURL url;
// Browser settings.
CefBrowserSettings settings;
// 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;
// Request context to use when creating the browser. If nullptr the global
// request context will be used.
CefRefPtr<CefRequestContext> request_context;
// Extra information that will be passed to
// CefRenderProcessHandler::OnBrowserCreated.
CefRefPtr<CefDictionaryValue> extra_info;
// 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::ViewType extension_host_type = extensions::VIEW_TYPE_INVALID;
};
// Base class for CefBrowserHost implementations. Includes functionality that is
// shared by the alloy and chrome runtimes. All methods are thread-safe unless
// otherwise indicated.
class CefBrowserHostBase : public CefBrowserHost,
public CefBrowser,
public CefBrowserContentsDelegate::Observer {
public:
// Interface to implement for observers that wish to be informed of changes
// to the CefBrowserHostBase. All methods will be called on the UI thread.
class Observer : public base::CheckedObserver {
public:
// Called before |browser| is destroyed. Any references to |browser| should
// be cleared when this method is called.
virtual void OnBrowserDestroyed(CefBrowserHostBase* browser) = 0;
protected:
virtual ~Observer() {}
};
// Returns the browser associated with the specified RenderViewHost.
static CefRefPtr<CefBrowserHostBase> GetBrowserForHost(
const content::RenderViewHost* host);
// Returns the browser associated with the specified RenderFrameHost.
static CefRefPtr<CefBrowserHostBase> GetBrowserForHost(
const content::RenderFrameHost* host);
// Returns the browser associated with the specified WebContents.
static CefRefPtr<CefBrowserHostBase> GetBrowserForContents(
const content::WebContents* contents);
// Returns the browser associated with the specified FrameTreeNode ID.
static CefRefPtr<CefBrowserHostBase> GetBrowserForFrameTreeNode(
int frame_tree_node_id);
// Returns the browser associated with the specified frame routing IDs.
static CefRefPtr<CefBrowserHostBase> GetBrowserForFrameRoute(
int render_process_id,
int render_routing_id);
CefBrowserHostBase(
const CefBrowserSettings& settings,
CefRefPtr<CefClient> client,
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate,
scoped_refptr<CefBrowserInfo> browser_info,
CefRefPtr<CefRequestContextImpl> request_context);
// Called on the UI thread after the associated WebContents is created.
virtual void InitializeBrowser();
// Called on the UI thread after the associated WebContents is destroyed.
// Also called from CefBrowserInfoManager::DestroyAllBrowsers if the browser
// was not properly shut down.
virtual void DestroyBrowser();
// CefBrowserHost methods:
CefRefPtr<CefBrowser> GetBrowser() override;
CefRefPtr<CefClient> GetClient() override;
CefRefPtr<CefRequestContext> GetRequestContext() override;
void StartDownload(const CefString& url) override;
void DownloadImage(const CefString& image_url,
bool is_favicon,
uint32 max_image_size,
bool bypass_cache,
CefRefPtr<CefDownloadImageCallback> callback) override;
void ReplaceMisspelling(const CefString& word) override;
void AddWordToDictionary(const CefString& word) override;
void SendKeyEvent(const CefKeyEvent& event) override;
void SendMouseClickEvent(const CefMouseEvent& event,
MouseButtonType type,
bool mouseUp,
int clickCount) override;
void SendMouseMoveEvent(const CefMouseEvent& event, bool mouseLeave) override;
void SendMouseWheelEvent(const CefMouseEvent& event,
int deltaX,
int deltaY) override;
void GetNavigationEntries(CefRefPtr<CefNavigationEntryVisitor> visitor,
bool current_only) override;
CefRefPtr<CefNavigationEntry> GetVisibleNavigationEntry() override;
// CefBrowser methods:
CefRefPtr<CefBrowserHost> GetHost() override;
bool CanGoBack() override;
void GoBack() override;
bool CanGoForward() override;
void GoForward() override;
bool IsLoading() override;
void Reload() override;
void ReloadIgnoreCache() override;
void StopLoad() override;
int GetIdentifier() override;
bool IsSame(CefRefPtr<CefBrowser> that) override;
bool HasDocument() override;
bool IsPopup() override;
CefRefPtr<CefFrame> GetMainFrame() override;
CefRefPtr<CefFrame> GetFocusedFrame() override;
CefRefPtr<CefFrame> GetFrame(int64 identifier) override;
CefRefPtr<CefFrame> GetFrame(const CefString& name) override;
size_t GetFrameCount() override;
void GetFrameIdentifiers(std::vector<int64>& identifiers) override;
void GetFrameNames(std::vector<CefString>& names) override;
// CefBrowserContentsDelegate::Observer methods:
void OnStateChanged(CefBrowserContentsState state_changed) override;
void OnWebContentsDestroyed(content::WebContents* web_contents) override;
// Returns the frame associated with the specified RenderFrameHost.
CefRefPtr<CefFrame> GetFrameForHost(const content::RenderFrameHost* host);
// Returns the frame associated with the specified FrameTreeNode ID.
CefRefPtr<CefFrame> GetFrameForFrameTreeNode(int frame_tree_node_id);
// Manage observer objects. The observer must either outlive this object or
// be removed before destruction. Must be called on the UI thread.
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
bool HasObserver(Observer* observer) const;
// Methods called from CefFrameHostImpl.
void LoadMainFrameURL(const content::OpenURLParams& params);
void OnDidFinishLoad(CefRefPtr<CefFrameHostImpl> frame,
const GURL& validated_url,
int http_status_code);
virtual void OnSetFocus(cef_focus_source_t source) = 0;
void ViewText(const std::string& text);
// Called from CefBrowserInfoManager::MaybeAllowNavigation.
virtual bool MaybeAllowNavigation(content::RenderFrameHost* opener,
bool is_guest_view,
const content::OpenURLParams& params);
// Helpers for executing client callbacks. Must be called on the UI thread.
void OnAfterCreated();
void OnBeforeClose();
void OnBrowserDestroyed();
// Thread-safe accessors.
const CefBrowserSettings& settings() const { return settings_; }
CefRefPtr<CefClient> client() const { return client_; }
scoped_refptr<CefBrowserInfo> browser_info() const { return browser_info_; }
int browser_id() const;
CefRefPtr<CefRequestContextImpl> request_context() const {
return request_context_;
}
// Accessors that must be called on the UI thread.
content::WebContents* GetWebContents() const;
content::BrowserContext* GetBrowserContext() const;
CefBrowserPlatformDelegate* platform_delegate() const {
return platform_delegate_.get();
}
CefBrowserContentsDelegate* contents_delegate() const {
return contents_delegate_.get();
}
protected:
// Called from LoadMainFrameURL to perform the actual navigation.
virtual bool Navigate(const content::OpenURLParams& params);
// Thread-safe members.
CefBrowserSettings settings_;
CefRefPtr<CefClient> client_;
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate_;
scoped_refptr<CefBrowserInfo> browser_info_;
CefRefPtr<CefRequestContextImpl> request_context_;
// Only accessed on the UI thread.
std::unique_ptr<CefBrowserContentsDelegate> contents_delegate_;
// Observers that want to be notified of changes to this object.
// Only accessed on the UI thread.
base::ObserverList<Observer> observers_;
// Volatile state accessed from multiple threads. All access must be protected
// by |state_lock_|.
base::Lock state_lock_;
bool is_loading_ = false;
bool can_go_back_ = false;
bool can_go_forward_ = false;
bool has_document_ = false;
bool is_fullscreen_ = false;
CefRefPtr<CefFrameHostImpl> focused_frame_;
private:
IMPLEMENT_REFCOUNTING(CefBrowserHostBase);
DISALLOW_COPY_AND_ASSIGN(CefBrowserHostBase);
};
#endif // CEF_LIBCEF_BROWSER_BROWSER_HOST_BASE_H_

View File

@@ -1,144 +0,0 @@
// Copyright (c) 2012 The Chromium Embedded Framework Authors.
// Portions copyright (c) 2011 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 "include/cef_browser.h"
#include "libcef/browser/alloy/alloy_browser_host_impl.h"
#include "libcef/browser/chrome/chrome_browser_host_impl.h"
#include "libcef/browser/context.h"
#include "libcef/browser/thread_util.h"
#include "libcef/features/runtime.h"
namespace {
class CreateBrowserHelper {
public:
CreateBrowserHelper(const CefWindowInfo& windowInfo,
CefRefPtr<CefClient> client,
const CefString& url,
const CefBrowserSettings& settings,
CefRefPtr<CefDictionaryValue> extra_info,
CefRefPtr<CefRequestContext> request_context)
: window_info_(windowInfo),
client_(client),
url_(url),
settings_(settings),
extra_info_(extra_info),
request_context_(request_context) {}
CefWindowInfo window_info_;
CefRefPtr<CefClient> client_;
CefString url_;
CefBrowserSettings settings_;
CefRefPtr<CefDictionaryValue> extra_info_;
CefRefPtr<CefRequestContext> request_context_;
};
} // namespace
// static
bool CefBrowserHost::CreateBrowser(
const CefWindowInfo& windowInfo,
CefRefPtr<CefClient> client,
const CefString& url,
const CefBrowserSettings& settings,
CefRefPtr<CefDictionaryValue> extra_info,
CefRefPtr<CefRequestContext> request_context) {
// Verify that the context is in a valid state.
if (!CONTEXT_STATE_VALID()) {
NOTREACHED() << "context not valid";
return false;
}
// Verify that the settings structure is a valid size.
if (settings.size != sizeof(cef_browser_settings_t)) {
NOTREACHED() << "invalid CefBrowserSettings structure size";
return false;
}
// Verify windowless rendering requirements.
if (windowInfo.windowless_rendering_enabled &&
!client->GetRenderHandler().get()) {
NOTREACHED() << "CefRenderHandler implementation is required";
return false;
}
if (windowInfo.windowless_rendering_enabled &&
!CefContext::Get()->settings().windowless_rendering_enabled) {
LOG(ERROR) << "Creating a windowless browser without setting "
"CefSettings.windowless_rendering_enabled may result in "
"reduced performance or runtime errors.";
}
// Create the browser on the UI thread.
CreateBrowserHelper* helper = new CreateBrowserHelper(
windowInfo, client, url, settings, extra_info, request_context);
CEF_POST_TASK(CEF_UIT, base::BindOnce(
[](CreateBrowserHelper* helper) {
CefBrowserHost::CreateBrowserSync(
helper->window_info_, helper->client_,
helper->url_, helper->settings_,
helper->extra_info_,
helper->request_context_);
delete helper;
},
helper));
return true;
}
// static
CefRefPtr<CefBrowser> CefBrowserHost::CreateBrowserSync(
const CefWindowInfo& windowInfo,
CefRefPtr<CefClient> client,
const CefString& url,
const CefBrowserSettings& settings,
CefRefPtr<CefDictionaryValue> extra_info,
CefRefPtr<CefRequestContext> request_context) {
// Verify that the context is in a valid state.
if (!CONTEXT_STATE_VALID()) {
NOTREACHED() << "context not valid";
return nullptr;
}
// Verify that the settings structure is a valid size.
if (settings.size != sizeof(cef_browser_settings_t)) {
NOTREACHED() << "invalid CefBrowserSettings structure size";
return nullptr;
}
// Verify that this method is being called on the UI thread.
if (!CEF_CURRENTLY_ON_UIT()) {
NOTREACHED() << "called on invalid thread";
return nullptr;
}
// Verify windowless rendering requirements.
if (windowInfo.windowless_rendering_enabled &&
!client->GetRenderHandler().get()) {
NOTREACHED() << "CefRenderHandler implementation is required";
return nullptr;
}
CefBrowserCreateParams create_params;
create_params.window_info.reset(new CefWindowInfo(windowInfo));
create_params.client = client;
create_params.url = GURL(url.ToString());
if (!url.empty() && !create_params.url.is_valid() &&
!create_params.url.has_scheme()) {
std::string new_url = std::string("http://") + url.ToString();
create_params.url = GURL(new_url);
}
create_params.settings = settings;
create_params.extra_info = extra_info;
create_params.request_context = request_context;
if (cef::IsChromeRuntimeEnabled()) {
auto browser = ChromeBrowserHostImpl::Create(create_params);
return browser.get();
}
auto browser = AlloyBrowserHostImpl::Create(create_params);
return browser.get();
}

File diff suppressed because it is too large Load Diff

View File

@@ -3,8 +3,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CEF_LIBCEF_BROWSER_ALLOY_ALLOY_BROWSER_HOST_IMPL_H_
#define CEF_LIBCEF_BROWSER_ALLOY_ALLOY_BROWSER_HOST_IMPL_H_
#ifndef CEF_LIBCEF_BROWSER_BROWSER_HOST_IMPL_H_
#define CEF_LIBCEF_BROWSER_BROWSER_HOST_IMPL_H_
#pragma once
#include <map>
@@ -14,7 +14,7 @@
#include "include/cef_browser.h"
#include "include/cef_client.h"
#include "include/cef_frame.h"
#include "libcef/browser/browser_host_base.h"
#include "include/views/cef_browser_view.h"
#include "libcef/browser/browser_info.h"
#include "libcef/browser/file_dialog_manager.h"
#include "libcef/browser/frame_host_impl.h"
@@ -22,36 +22,62 @@
#include "libcef/browser/menu_manager.h"
#include "libcef/browser/request_context_impl.h"
#include "base/observer_list.h"
#include "base/strings/string16.h"
#include "base/synchronization/lock.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_observer.h"
#include "extensions/common/view_type.h"
namespace content {
struct DragEventSourceInfo;
class RenderWidgetHostImpl;
} // namespace content
namespace extensions {
class Extension;
class ExtensionHost;
} // namespace extensions
namespace gfx {
class ImageSkia;
}
#if defined(USE_AURA)
namespace views {
class Widget;
}
#endif // defined(USE_AURA)
class CefAudioCapturer;
class CefBrowserInfo;
class CefBrowserPlatformDelegate;
class CefDevToolsManager;
class SiteInstance;
// CefBrowser implementation for the alloy runtime. Method calls are delegated
// to the CefPlatformDelegate or the WebContents as appropriate. All methods are
// thread-safe unless otherwise indicated.
// Implementation of CefBrowser.
//
// WebContentsDelegate: Interface for handling WebContents delegations. There is
// a one-to-one relationship between AlloyBrowserHostImpl and WebContents
// a one-to-one relationship between CefBrowserHostImpl and WebContents
// instances.
//
// WebContentsObserver: Interface for observing WebContents notifications and
// IPC messages. There is a one-to-one relationship between WebContents and
// RenderViewHost instances. IPC messages received by the RenderViewHost will be
// forwarded to this WebContentsObserver implementation via WebContents. IPC
// messages sent using AlloyBrowserHostImpl::Send() will be forwarded to the
// messages sent using CefBrowserHostImpl::Send() will be forwarded to the
// RenderViewHost (after posting to the UI thread if necessary). Use
// WebContentsObserver::routing_id() when sending IPC messages.
class AlloyBrowserHostImpl : public CefBrowserHostBase,
public content::WebContentsDelegate,
public content::WebContentsObserver {
//
// NotificationObserver: Interface for observing post-processed notifications.
class CefBrowserHostImpl : public CefBrowserHost,
public CefBrowser,
public content::WebContentsDelegate,
public content::WebContentsObserver,
public content::NotificationObserver {
public:
// Used for handling the response to command messages.
class CommandResponseHandler : public virtual CefBaseRefCounted {
@@ -59,36 +85,87 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
virtual void OnResponse(const std::string& response) = 0;
};
~AlloyBrowserHostImpl() override;
// Interface to implement for observers that wish to be informed of changes
// to the CefBrowserHostImpl. All methods will be called on the UI thread.
class Observer {
public:
// Called before |browser| is destroyed. Any references to |browser| should
// be cleared when this method is called.
virtual void OnBrowserDestroyed(CefBrowserHostImpl* browser) = 0;
// Create a new AlloyBrowserHostImpl instance with owned WebContents.
static CefRefPtr<AlloyBrowserHostImpl> Create(
CefBrowserCreateParams& create_params);
protected:
virtual ~Observer() {}
};
~CefBrowserHostImpl() override;
struct CreateParams {
// Platform-specific window creation info. Will be nullptr when creating a
// views-hosted browser.
std::unique_ptr<CefWindowInfo> window_info;
#if defined(USE_AURA)
// The BrowserView that will own a views-hosted browser. Will be nullptr for
// popup browsers (the BrowserView will be created later in that case).
CefRefPtr<CefBrowserView> browser_view;
#endif
// Client implementation. May be nullptr.
CefRefPtr<CefClient> client;
// Initial URL to load. May be empty. If this is a valid extension URL then
// the browser will be created as an app view extension host.
GURL url;
// Browser settings.
CefBrowserSettings settings;
// Other browser that opened this DevTools browser. Will be nullptr for non-
// DevTools browsers.
CefRefPtr<CefBrowserHostImpl> devtools_opener;
// Request context to use when creating the browser. If nullptr the global
// request context will be used.
CefRefPtr<CefRequestContext> request_context;
CefRefPtr<CefDictionaryValue> extra_info;
// Used when explicitly creating the browser as an extension host via
// ProcessManager::CreateBackgroundHost.
const extensions::Extension* extension = nullptr;
extensions::ViewType extension_host_type = extensions::VIEW_TYPE_INVALID;
};
// Create a new CefBrowserHostImpl instance.
static CefRefPtr<CefBrowserHostImpl> Create(CreateParams& create_params);
// Returns the browser associated with the specified RenderViewHost.
static CefRefPtr<AlloyBrowserHostImpl> GetBrowserForHost(
static CefRefPtr<CefBrowserHostImpl> GetBrowserForHost(
const content::RenderViewHost* host);
// Returns the browser associated with the specified RenderFrameHost.
static CefRefPtr<AlloyBrowserHostImpl> GetBrowserForHost(
static CefRefPtr<CefBrowserHostImpl> GetBrowserForHost(
const content::RenderFrameHost* host);
// Returns the browser associated with the specified WebContents.
static CefRefPtr<AlloyBrowserHostImpl> GetBrowserForContents(
static CefRefPtr<CefBrowserHostImpl> GetBrowserForContents(
const content::WebContents* contents);
// Returns the browser associated with the specified FrameTreeNode ID.
static CefRefPtr<AlloyBrowserHostImpl> GetBrowserForFrameTreeNode(
static CefRefPtr<CefBrowserHostImpl> GetBrowserForFrameTreeNode(
int frame_tree_node_id);
// Returns the browser associated with the specified frame routing IDs.
static CefRefPtr<AlloyBrowserHostImpl> GetBrowserForFrameRoute(
static CefRefPtr<CefBrowserHostImpl> GetBrowserForFrameRoute(
int render_process_id,
int render_routing_id);
// CefBrowserHost methods.
CefRefPtr<CefBrowser> GetBrowser() override;
void CloseBrowser(bool force_close) override;
bool TryCloseBrowser() override;
void SetFocus(bool focus) override;
CefWindowHandle GetWindowHandle() override;
CefWindowHandle GetOpenerWindowHandle() override;
bool HasView() override;
CefRefPtr<CefClient> GetClient() override;
CefRefPtr<CefRequestContext> GetRequestContext() override;
double GetZoomLevel() override;
void SetZoomLevel(double zoomLevel) override;
void RunFileDialog(FileDialogMode mode,
@@ -97,6 +174,12 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
const std::vector<CefString>& accept_filters,
int selected_accept_filter,
CefRefPtr<CefRunFileDialogCallback> callback) override;
void StartDownload(const CefString& url) override;
void DownloadImage(const CefString& image_url,
bool is_favicon,
uint32 max_image_size,
bool bypass_cache,
CefRefPtr<CefDownloadImageCallback> callback) override;
void Print() override;
void PrintToPDF(const CefString& path,
const CefPdfPrintSettings& settings,
@@ -119,12 +202,27 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
CefRefPtr<CefDictionaryValue> params) override;
CefRefPtr<CefRegistration> AddDevToolsMessageObserver(
CefRefPtr<CefDevToolsMessageObserver> observer) override;
void GetNavigationEntries(CefRefPtr<CefNavigationEntryVisitor> visitor,
bool current_only) override;
void SetMouseCursorChangeDisabled(bool disabled) override;
bool IsMouseCursorChangeDisabled() override;
bool IsWindowRenderingDisabled() override;
void ReplaceMisspelling(const CefString& word) override;
void AddWordToDictionary(const CefString& word) override;
void WasResized() override;
void WasHidden(bool hidden) override;
void NotifyScreenInfoChanged() override;
void Invalidate(PaintElementType type) override;
void SendExternalBeginFrame() override;
void SendKeyEvent(const CefKeyEvent& event) override;
void SendMouseClickEvent(const CefMouseEvent& event,
MouseButtonType type,
bool mouseUp,
int clickCount) override;
void SendMouseMoveEvent(const CefMouseEvent& event, bool mouseLeave) override;
void SendMouseWheelEvent(const CefMouseEvent& event,
int deltaX,
int deltaY) override;
void SendTouchEvent(const CefTouchEvent& event) override;
void SendFocusEvent(bool setFocus) override;
void SendCaptureLostEvent() override;
@@ -151,6 +249,7 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
void DragSourceEndedAt(int x, int y, DragOperationsMask op) override;
void SetAudioMuted(bool mute) override;
bool IsAudioMuted() override;
CefRefPtr<CefNavigationEntry> GetVisibleNavigationEntry() override;
void SetAccessibilityState(cef_state_t accessibility_state) override;
void SetAutoResizeEnabled(bool enabled,
const CefSize& min_size,
@@ -158,6 +257,28 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
CefRefPtr<CefExtension> GetExtension() override;
bool IsBackgroundHost() override;
// CefBrowser methods.
CefRefPtr<CefBrowserHost> GetHost() override;
bool CanGoBack() override;
void GoBack() override;
bool CanGoForward() override;
void GoForward() override;
bool IsLoading() override;
void Reload() override;
void ReloadIgnoreCache() override;
void StopLoad() override;
int GetIdentifier() override;
bool IsSame(CefRefPtr<CefBrowser> that) override;
bool IsPopup() override;
bool HasDocument() override;
CefRefPtr<CefFrame> GetMainFrame() override;
CefRefPtr<CefFrame> GetFocusedFrame() override;
CefRefPtr<CefFrame> GetFrame(int64 identifier) override;
CefRefPtr<CefFrame> GetFrame(const CefString& name) override;
size_t GetFrameCount() override;
void GetFrameIdentifiers(std::vector<int64>& identifiers) override;
void GetFrameNames(std::vector<CefString>& names) override;
// Returns true if windowless rendering is enabled.
bool IsWindowless() const;
@@ -172,7 +293,7 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
// Destroy the browser members. This method should only be called after the
// native browser window is not longer processing messages.
void DestroyBrowser() override;
void DestroyBrowser();
// Cancel display of the context menu, if any.
void CancelContextMenu();
@@ -187,29 +308,53 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
CefRefPtr<CefBrowserView> GetBrowserView() const;
#endif
bool MaybeAllowNavigation(content::RenderFrameHost* opener,
bool is_guest_view,
const content::OpenURLParams& params) override;
// Returns the frame associated with the specified RenderFrameHost.
CefRefPtr<CefFrame> GetFrameForHost(const content::RenderFrameHost* host);
// Returns the frame associated with the specified FrameTreeNode ID.
CefRefPtr<CefFrame> GetFrameForFrameTreeNode(int frame_tree_node_id);
// Load the specified URL in the main frame.
void LoadMainFrameURL(const std::string& url,
const content::Referrer& referrer,
ui::PageTransition transition,
const std::string& extra_headers);
// Called from CefFrameHostImpl.
void OnDidFinishLoad(CefRefPtr<CefFrameHostImpl> frame,
const GURL& validated_url,
int http_status_code);
// Open the specified text in the default text editor.
void ViewText(const std::string& text);
// Convert from view coordinates to screen coordinates. Potential display
// scaling will be applied to the result.
gfx::Point GetScreenPoint(const gfx::Point& view) const;
void StartDragging(const content::DropData& drop_data,
blink::DragOperationsMask allowed_ops,
blink::WebDragOperationsMask allowed_ops,
const gfx::ImageSkia& image,
const gfx::Vector2d& image_offset,
const blink::mojom::DragEventSourceInfo& event_info,
const content::DragEventSourceInfo& event_info,
content::RenderWidgetHostImpl* source_rwh);
void UpdateDragCursor(blink::DragOperation operation);
void UpdateDragCursor(blink::WebDragOperation operation);
// Thread safe accessors.
const CefBrowserSettings& settings() const { return settings_; }
SkColor GetBackgroundColor() const;
CefRefPtr<CefClient> client() const { return client_; }
scoped_refptr<CefBrowserInfo> browser_info() const { return browser_info_; }
int browser_id() const;
CefRefPtr<CefRequestContextImpl> request_context() const {
return request_context_;
}
// Accessors that must be called on the UI thread.
content::BrowserContext* GetBrowserContext() const;
extensions::ExtensionHost* GetExtensionHost() const;
void OnSetFocus(cef_focus_source_t source) override;
void OnSetFocus(cef_focus_source_t source);
// Run the file chooser dialog specified by |params|. Only a single dialog may
// be pending at any given time. |callback| will be executed asynchronously
@@ -242,6 +387,7 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
bool* was_blocked) override;
void LoadingStateChanged(content::WebContents* source,
bool to_different_document) override;
void LoadProgressChanged(double progress) override;
void CloseContents(content::WebContents* source) override;
void UpdateTargetURL(content::WebContents* source, const GURL& url) override;
bool DidAddMessageToConsole(content::WebContents* source,
@@ -265,7 +411,7 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
const blink::WebGestureEvent& event) override;
bool CanDragEnter(content::WebContents* source,
const content::DropData& data,
blink::DragOperationsMask operations_allowed) override;
blink::WebDragOperationsMask operations_allowed) override;
void GetCustomWebContentsView(
content::WebContents* web_contents,
const GURL& target_url,
@@ -284,7 +430,7 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
content::JavaScriptDialogManager* GetJavaScriptDialogManager(
content::WebContents* source) override;
void RunFileChooser(content::RenderFrameHost* render_frame_host,
scoped_refptr<content::FileSelectListener> listener,
std::unique_ptr<content::FileSelectListener> listener,
const blink::mojom::FileChooserParams& params) override;
bool EmbedsFullscreenWidget() override;
void EnterFullscreenModeForTab(
@@ -321,39 +467,87 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
// content::WebContentsObserver methods.
using content::WebContentsObserver::BeforeUnloadFired;
void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override;
void RenderFrameHostChanged(content::RenderFrameHost* old_host,
content::RenderFrameHost* new_host) override;
void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override;
void RenderViewCreated(content::RenderViewHost* render_view_host) override;
void RenderViewDeleted(content::RenderViewHost* render_view_host) override;
void RenderViewReady() override;
void RenderProcessGone(base::TerminationStatus status) override;
void DidFinishNavigation(
content::NavigationHandle* navigation_handle) override;
void DidStopLoading() override;
void DocumentAvailableInMainFrame() override;
void DidFailLoad(content::RenderFrameHost* render_frame_host,
const GURL& validated_url,
int error_code) override;
void TitleWasSet(content::NavigationEntry* entry) override;
void PluginCrashed(const base::FilePath& plugin_path,
base::ProcessId plugin_pid) override;
void DidUpdateFaviconURL(
content::RenderFrameHost* render_frame_host,
const std::vector<blink::mojom::FaviconURLPtr>& candidates) override;
void OnAudioStateChanged(bool audible) override;
bool OnMessageReceived(const IPC::Message& message,
content::RenderFrameHost* render_frame_host) override;
void OnFrameFocused(content::RenderFrameHost* render_frame_host) override;
void AccessibilityEventReceived(
const content::AXEventNotificationDetails& content_event_bundle) override;
void AccessibilityLocationChangesReceived(
const std::vector<content::AXLocationChangeNotificationDetails>& locData)
override;
void OnWebContentsFocused(
content::RenderWidgetHost* render_widget_host) override;
void WebContentsDestroyed() override;
// Manage observer objects. The observer must either outlive this object or
// remove itself before destruction. These methods can only be called on the
// UI thread.
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
bool HasObserver(Observer* observer) const;
class NavigationLock final {
private:
friend class CefBrowserHostImpl;
friend std::unique_ptr<NavigationLock>::deleter_type;
explicit NavigationLock(CefRefPtr<CefBrowserHostImpl> browser);
~NavigationLock();
CefRefPtr<CefBrowserHostImpl> browser_;
};
// Block navigation-related events on NavigationLock life span.
std::unique_ptr<NavigationLock> CreateNavigationLock();
private:
friend class CefBrowserPlatformDelegateAlloy;
static CefRefPtr<AlloyBrowserHostImpl> CreateInternal(
static CefRefPtr<CefBrowserHostImpl> CreateInternal(
const CefBrowserSettings& settings,
CefRefPtr<CefClient> client,
content::WebContents* web_contents,
bool own_web_contents,
scoped_refptr<CefBrowserInfo> browser_info,
CefRefPtr<AlloyBrowserHostImpl> opener,
CefRefPtr<CefBrowserHostImpl> opener,
bool is_devtools_popup,
CefRefPtr<CefRequestContextImpl> request_context,
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate,
CefRefPtr<CefExtension> extension);
AlloyBrowserHostImpl(
// content::NotificationObserver methods.
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
CefBrowserHostImpl(
const CefBrowserSettings& settings,
CefRefPtr<CefClient> client,
content::WebContents* web_contents,
scoped_refptr<CefBrowserInfo> browser_info,
CefRefPtr<AlloyBrowserHostImpl> opener,
CefRefPtr<CefBrowserHostImpl> opener,
CefRefPtr<CefRequestContextImpl> request_context,
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate,
CefRefPtr<CefExtension> extension);
@@ -361,6 +555,21 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
// Give the platform delegate an opportunity to create the host window.
bool CreateHostWindow();
// Returns true if navigation actions are currently locked.
bool navigation_locked() const;
// Action to be executed once the navigation lock is released.
void set_pending_navigation_action(base::OnceClosure action);
void OnAddressChange(const GURL& url);
void OnLoadStart(CefRefPtr<CefFrame> frame,
ui::PageTransition transition_type);
void OnLoadError(CefRefPtr<CefFrame> frame, const GURL& url, int error_code);
void OnLoadEnd(CefRefPtr<CefFrame> frame,
const GURL& url,
int http_status_code);
void OnFullscreenModeChange(bool fullscreen);
void OnTitleChange(const base::string16& title);
// Create the CefFileDialogManager if it doesn't already exist.
void EnsureFileDialogManager();
@@ -371,23 +580,57 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
void InitializeDevToolsRegistrationOnUIThread(
CefRefPtr<CefRegistration> registration);
void SetFocusInternal(bool focus);
CefBrowserSettings settings_;
CefRefPtr<CefClient> client_;
scoped_refptr<CefBrowserInfo> browser_info_;
CefWindowHandle opener_;
CefRefPtr<CefRequestContextImpl> request_context_;
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate_;
const bool is_windowless_;
const bool is_views_hosted_;
CefWindowHandle host_window_handle_ = kNullWindowHandle;
CefRefPtr<CefExtension> extension_;
bool is_background_host_ = false;
// Volatile state information. All access must be protected by the state lock.
base::Lock state_lock_;
bool is_loading_ = false;
bool can_go_back_ = false;
bool can_go_forward_ = false;
bool has_document_ = false;
bool is_fullscreen_ = false;
// The currently focused frame, or nullptr if the main frame is focused.
CefRefPtr<CefFrameHostImpl> focused_frame_;
// Represents the current browser destruction state. Only accessed on the UI
// thread.
DestructionState destruction_state_ = DESTRUCTION_STATE_NONE;
// Navigation will not occur while |navigation_lock_count_| > 0.
// |pending_navigation_action_| will be executed when the lock is released.
// Only accessed on the UI thread.
int navigation_lock_count_ = 0;
base::OnceClosure pending_navigation_action_;
// True if the OS window hosting the browser has been destroyed. Only accessed
// on the UI thread.
bool window_destroyed_ = false;
// True if currently in the OnSetFocus callback. Only accessed on the UI
// thread.
bool is_in_onsetfocus_ = false;
// True if the focus is currently on an editable field on the page. Only
// accessed on the UI thread.
bool focus_on_editable_field_ = false;
// True if mouse cursor change is disabled.
bool mouse_cursor_change_disabled_ = false;
// Used for managing notification subscriptions.
std::unique_ptr<content::NotificationRegistrar> registrar_;
// Used for creating and managing file dialogs.
std::unique_ptr<CefFileDialogManager> file_dialog_manager_;
@@ -400,6 +643,9 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
// Used for creating and managing DevTools instances.
std::unique_ptr<CefDevToolsManager> devtools_manager_;
// Observers that want to be notified of changes to this object.
base::ObserverList<Observer>::Unchecked observers_;
// Used for capturing audio for CefAudioHandler.
std::unique_ptr<CefAudioCapturer> audio_capturer_;
@@ -407,6 +653,9 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
// starts running when a tab stops being audible, and is canceled if it starts
// being audible again before it fires.
base::OneShotTimer recently_audible_timer_;
IMPLEMENT_REFCOUNTING(CefBrowserHostImpl);
DISALLOW_COPY_AND_ASSIGN(CefBrowserHostImpl);
};
#endif // CEF_LIBCEF_BROWSER_ALLOY_ALLOY_BROWSER_HOST_IMPL_H_
#endif // CEF_LIBCEF_BROWSER_BROWSER_HOST_IMPL_H_

View File

@@ -4,13 +4,13 @@
#include "libcef/browser/browser_info.h"
#include "libcef/browser/browser_host_base.h"
#include "libcef/browser/browser_host_impl.h"
#include "libcef/browser/thread_util.h"
#include "libcef/common/values_impl.h"
#include "base/logging.h"
#include "content/browser/renderer_host/frame_tree_node.h"
#include "content/browser/renderer_host/render_frame_host_impl.h"
#include "content/browser/frame_host/frame_tree_node.h"
#include "content/browser/frame_host/render_frame_host_impl.h"
#include "content/public/browser/render_process_host.h"
#include "ipc/ipc_message.h"
@@ -34,12 +34,12 @@ CefBrowserInfo::CefBrowserInfo(int browser_id,
CefBrowserInfo::~CefBrowserInfo() {}
CefRefPtr<CefBrowserHostBase> CefBrowserInfo::browser() const {
CefRefPtr<CefBrowserHostImpl> CefBrowserInfo::browser() const {
base::AutoLock lock_scope(lock_);
return browser_;
}
void CefBrowserInfo::SetBrowser(CefRefPtr<CefBrowserHostBase> browser) {
void CefBrowserInfo::SetBrowser(CefRefPtr<CefBrowserHostImpl> browser) {
base::AutoLock lock_scope(lock_);
browser_ = browser;
@@ -297,37 +297,6 @@ CefBrowserInfo::FrameHostList CefBrowserInfo::GetAllFrames() const {
return frames;
}
CefBrowserInfo::NavigationLock::NavigationLock() : weak_ptr_factory_(this) {}
CefBrowserInfo::NavigationLock::~NavigationLock() {
CEF_REQUIRE_UIT();
if (pending_action_) {
CEF_POST_TASK(CEF_UIT, std::move(pending_action_));
}
}
scoped_refptr<CefBrowserInfo::NavigationLock>
CefBrowserInfo::CreateNavigationLock() {
CEF_REQUIRE_UIT();
scoped_refptr<NavigationLock> lock;
if (!navigation_lock_) {
lock = new NavigationLock();
navigation_lock_ = lock->weak_ptr_factory_.GetWeakPtr();
} else {
lock = navigation_lock_.get();
}
return lock;
}
bool CefBrowserInfo::IsNavigationLocked(base::OnceClosure pending_action) {
CEF_REQUIRE_UIT();
if (navigation_lock_) {
navigation_lock_->pending_action_ = std::move(pending_action);
return true;
}
return false;
}
void CefBrowserInfo::MaybeUpdateFrameTreeNodeIdMap(FrameInfo* info) {
lock_.AssertAcquired();

View File

@@ -12,10 +12,8 @@
#include "include/internal/cef_ptr.h"
#include "libcef/common/values_impl.h"
#include "base/callback.h"
#include "base/containers/unique_ptr_adapters.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/synchronization/lock.h"
#include "base/values.h"
@@ -23,12 +21,12 @@ namespace content {
class RenderFrameHost;
}
class CefBrowserHostBase;
class CefBrowserHostImpl;
class CefFrameHostImpl;
// CefBrowserInfo is used to associate a browser ID and render view/process
// IDs with a particular CefBrowserHostBase. Render view/process IDs may change
// during the lifetime of a single CefBrowserHostBase.
// IDs with a particular CefBrowserHostImpl. Render view/process IDs may change
// during the lifetime of a single CefBrowserHostImpl.
//
// CefBrowserInfo objects are managed by CefBrowserInfoManager and should not be
// created directly.
@@ -46,24 +44,23 @@ class CefBrowserInfo : public base::RefCountedThreadSafe<CefBrowserInfo> {
// May return NULL if the browser has not yet been created or if the browser
// has been destroyed.
CefRefPtr<CefBrowserHostBase> browser() const;
CefRefPtr<CefBrowserHostImpl> browser() const;
// Set or clear the browser. Called from CefBrowserHostBase InitializeBrowser
// Set or clear the browser. Called from the CefBrowserHostImpl constructor
// (to set) and DestroyBrowser (to clear).
void SetBrowser(CefRefPtr<CefBrowserHostBase> browser);
void SetBrowser(CefRefPtr<CefBrowserHostImpl> browser);
// Ensure that a frame record exists for |host|. Called for the main frame
// when the RenderView is created, or for a sub-frame when the associated
// RenderFrame is created in the renderer process.
// Called from CefBrowserContentsDelegate::RenderFrameCreated (is_guest_view =
// false) or CefMimeHandlerViewGuestDelegate::OnGuestAttached (is_guest_view =
// true).
// Called from CefBrowserHostImpl::RenderFrameCreated (is_guest_view = false)
// or CefMimeHandlerViewGuestDelegate::OnGuestAttached (is_guest_view = true).
void MaybeCreateFrame(content::RenderFrameHost* host, bool is_guest_view);
// Remove the frame record for |host|. Called for the main frame when the
// RenderView is destroyed, or for a sub-frame when the associated RenderFrame
// is destroyed in the renderer process.
// Called from CefBrowserContentsDelegate::RenderFrameDeleted or
// Called from CefBrowserHostImpl::FrameDeleted or
// CefMimeHandlerViewGuestDelegate::OnGuestDetached.
void RemoveFrame(content::RenderFrameHost* host);
@@ -124,28 +121,6 @@ class CefBrowserInfo : public base::RefCountedThreadSafe<CefBrowserInfo> {
typedef std::set<CefRefPtr<CefFrameHostImpl>> FrameHostList;
FrameHostList GetAllFrames() const;
class NavigationLock final : public base::RefCounted<NavigationLock> {
private:
friend class CefBrowserInfo;
friend class base::RefCounted<NavigationLock>;
NavigationLock();
~NavigationLock();
base::OnceClosure pending_action_;
base::WeakPtrFactory<NavigationLock> weak_ptr_factory_;
};
// Block navigation actions on NavigationLock life span. Must be called on the
// UI thread.
scoped_refptr<NavigationLock> CreateNavigationLock();
// Returns true if navigation actions are currently blocked. If this method
// returns true the most recent |pending_action| will be executed on the UI
// thread once the navigation lock is released. Must be called on the UI
// thread.
bool IsNavigationLocked(base::OnceClosure pending_action);
private:
friend class base::RefCountedThreadSafe<CefBrowserInfo>;
@@ -176,15 +151,11 @@ class CefBrowserInfo : public base::RefCountedThreadSafe<CefBrowserInfo> {
bool is_windowless_;
CefRefPtr<CefDictionaryValue> extra_info_;
// Navigation will be blocked while |navigation_lock_| exists.
// Only accessed on the UI thread.
base::WeakPtr<NavigationLock> navigation_lock_;
mutable base::Lock lock_;
// The below members must be protected by |lock_|.
CefRefPtr<CefBrowserHostBase> browser_;
CefRefPtr<CefBrowserHostImpl> browser_;
// Owner of FrameInfo structs.
typedef std::set<std::unique_ptr<FrameInfo>, base::UniquePtrComparator>

View File

@@ -6,7 +6,7 @@
#include <utility>
#include "libcef/browser/browser_host_base.h"
#include "libcef/browser/browser_host_impl.h"
#include "libcef/browser/browser_platform_delegate.h"
#include "libcef/browser/extensions/browser_extensions_util.h"
#include "libcef/browser/thread_util.h"
@@ -14,7 +14,6 @@
#include "libcef/common/cef_switches.h"
#include "libcef/common/extensions/extensions_util.h"
#include "libcef/common/values_impl.h"
#include "libcef/features/runtime_checks.h"
#include "base/command_line.h"
#include "base/logging.h"
@@ -24,6 +23,7 @@
#include "content/public/browser/web_contents.h"
#include "content/public/common/child_process_host.h"
#include "content/public/common/url_constants.h"
#include "extensions/common/constants.h"
namespace {
@@ -122,7 +122,7 @@ bool CefBrowserInfoManager::CanCreateWindow(
/*is_renderer_initiated=*/true);
params.user_gesture = user_gesture;
CefRefPtr<CefBrowserHostBase> browser;
CefRefPtr<CefBrowserHostImpl> browser;
if (!MaybeAllowNavigation(opener, params, browser) || !browser) {
// Cancel the popup.
return false;
@@ -157,7 +157,7 @@ bool CefBrowserInfoManager::CanCreateWindow(
CefPopupFeatures cef_features;
TranslatePopupFeatures(features, cef_features);
#if (defined(OS_WIN) || defined(OS_MAC))
#if (defined(OS_WIN) || defined(OS_MACOSX))
// Default to the size from the popup features.
if (cef_features.xSet)
window_info->x = cef_features.x;
@@ -180,9 +180,9 @@ bool CefBrowserInfoManager::CanCreateWindow(
}
if (allow) {
CefBrowserCreateParams create_params;
CefBrowserHostImpl::CreateParams create_params;
if (!browser->HasView())
if (!browser->IsViewsHosted())
create_params.window_info = std::move(window_info);
create_params.settings = pending_popup->settings;
@@ -213,7 +213,6 @@ void CefBrowserInfoManager::GetCustomWebContentsView(
content::WebContentsView** view,
content::RenderViewHostDelegateView** delegate_view) {
CEF_REQUIRE_UIT();
REQUIRE_ALLOY_RUNTIME();
std::unique_ptr<CefBrowserInfoManager::PendingPopup> pending_popup =
PopPendingPopup(CefBrowserInfoManager::PendingPopup::CAN_CREATE_WINDOW,
@@ -242,15 +241,10 @@ void CefBrowserInfoManager::WebContentsCreated(
CefRefPtr<CefDictionaryValue>& extra_info) {
CEF_REQUIRE_UIT();
// GET_CUSTOM_WEB_CONTENTS_VIEW is only used with the alloy runtime.
const auto previous_step =
cef::IsAlloyRuntimeEnabled()
? CefBrowserInfoManager::PendingPopup::GET_CUSTOM_WEB_CONTENTS_VIEW
: CefBrowserInfoManager::PendingPopup::CAN_CREATE_WINDOW;
std::unique_ptr<CefBrowserInfoManager::PendingPopup> pending_popup =
PopPendingPopup(previous_step, opener_render_process_id,
opener_render_routing_id, target_url);
PopPendingPopup(
CefBrowserInfoManager::PendingPopup::GET_CUSTOM_WEB_CONTENTS_VIEW,
opener_render_process_id, opener_render_routing_id, target_url);
DCHECK(pending_popup.get());
DCHECK(pending_popup->platform_delegate.get());
@@ -338,7 +332,7 @@ void CefBrowserInfoManager::DestroyAllBrowsers() {
if (!list.empty()) {
BrowserInfoList::iterator it = list.begin();
for (; it != list.end(); ++it) {
CefRefPtr<CefBrowserHostBase> browser = (*it)->browser();
CefRefPtr<CefBrowserHostImpl> browser = (*it)->browser();
DCHECK(browser.get());
if (browser.get()) {
// DestroyBrowser will call RemoveBrowserInfo.
@@ -367,18 +361,28 @@ CefBrowserInfoManager::GetBrowserInfoForFrameRoute(int render_process_id,
bool CefBrowserInfoManager::MaybeAllowNavigation(
content::RenderFrameHost* opener,
const content::OpenURLParams& params,
CefRefPtr<CefBrowserHostBase>& browser_out) const {
CefRefPtr<CefBrowserHostImpl>& browser_out) const {
CEF_REQUIRE_UIT();
bool is_guest_view = false;
auto browser = extensions::GetOwnerBrowserForHost(opener, &is_guest_view);
CefRefPtr<CefBrowserHostImpl> browser =
extensions::GetOwnerBrowserForHost(opener, &is_guest_view);
if (!browser) {
// Print preview uses a modal dialog where we don't own the WebContents.
// Allow that navigation to proceed.
return true;
}
if (!browser->MaybeAllowNavigation(opener, is_guest_view, params)) {
if (is_guest_view && !params.url.SchemeIs(extensions::kExtensionScheme) &&
!params.url.SchemeIs(content::kChromeUIScheme)) {
// The PDF viewer will load the PDF extension in the guest view, and print
// preview will load chrome://print in the guest view. All other navigations
// are passed to the owner browser.
CEF_POST_TASK(
CEF_UIT,
base::Bind(base::IgnoreResult(&CefBrowserHostImpl::OpenURLFromTab),
browser.get(), nullptr, params));
return false;
}

View File

@@ -37,7 +37,6 @@ namespace IPC {
class Message;
}
class CefBrowserHostBase;
class CefBrowserPlatformDelegate;
// Singleton object for managing BrowserInfo instances.
@@ -49,14 +48,14 @@ class CefBrowserInfoManager : public content::RenderProcessHostObserver {
// Returns this singleton instance of this class.
static CefBrowserInfoManager* GetInstance();
// Called immediately before a new CefBrowserHost implementation is created
// Called from CefBrowserHostImpl::Create when a new browser is being created
// directly. In this case |is_popup| will be true only for DevTools browsers.
scoped_refptr<CefBrowserInfo> CreateBrowserInfo(
bool is_popup,
bool is_windowless,
CefRefPtr<CefDictionaryValue> extra_info);
// Called from WebContentsDelegate::WebContentsCreated when a new browser is
// Called from CefBrowserHostImpl::WebContentsCreated when a new browser is
// being created for a traditional popup (e.g. window.open() or targeted
// link). If any OnGetNewBrowserInfo requests are pending for the popup the
// response will be sent when this method is called.
@@ -65,7 +64,7 @@ class CefBrowserInfoManager : public content::RenderProcessHostObserver {
bool is_windowless,
CefRefPtr<CefDictionaryValue> extra_info);
// Called from ContentBrowserClient::CanCreateWindow. See comments on
// Called from AlloyContentBrowserClient::CanCreateWindow. See comments on
// PendingPopup for more information.
bool CanCreateWindow(content::RenderFrameHost* opener,
const GURL& target_url,
@@ -77,8 +76,8 @@ class CefBrowserInfoManager : public content::RenderProcessHostObserver {
bool opener_suppressed,
bool* no_javascript_access);
// Called from WebContentsDelegate::GetCustomWebContentsView (alloy runtime
// only). See comments on PendingPopup for more information.
// Called from CefBrowserHostImpl::GetCustomWebContentsView. See comments on
// PendingPopup for more information.
void GetCustomWebContentsView(
const GURL& target_url,
int opener_render_process_id,
@@ -86,7 +85,7 @@ class CefBrowserInfoManager : public content::RenderProcessHostObserver {
content::WebContentsView** view,
content::RenderViewHostDelegateView** delegate_view);
// Called from WebContentsDelegate::WebContentsCreated. See comments on
// Called from CefBrowserHostImpl::WebContentsCreated. See comments on
// PendingPopup for more information.
void WebContentsCreated(
const GURL& target_url,
@@ -108,7 +107,7 @@ class CefBrowserInfoManager : public content::RenderProcessHostObserver {
int render_routing_id,
IPC::Message* reply_msg);
// Called from CefBrowserHostBase::DestroyBrowser() when a browser is
// Called from CefBrowserHostImpl::DestroyBrowser() when a browser is
// destroyed.
void RemoveBrowserInfo(scoped_refptr<CefBrowserInfo> browser_info);
@@ -117,7 +116,7 @@ class CefBrowserInfoManager : public content::RenderProcessHostObserver {
// Returns the CefBrowserInfo matching the specified IDs or nullptr if no
// match is found. It is allowed to add new callers of this method but
// consider using CefBrowserHostBase::GetBrowserForFrameRoute() or
// consider using CefBrowserHostImpl::GetBrowserForFrameRoute() or
// extensions::GetOwnerBrowserForFrameRoute() instead. If |is_guest_view| is
// non-nullptr it will be set to true if the IDs match a guest view associated
// with the returned browser info instead of the browser itself.
@@ -128,7 +127,7 @@ class CefBrowserInfoManager : public content::RenderProcessHostObserver {
// Returns the CefBrowserInfo matching the specified ID or nullptr if no match
// is found. It is allowed to add new callers of this method but consider
// using CefBrowserHostBase::GetBrowserForFrameTreeNode() instead. If
// using CefBrowserHostImpl::GetBrowserForFrameTreeNode() instead. If
// |is_guest_view| is non-nullptr it will be set to true if the IDs match a
// guest view associated with the returned browser info instead of the browser
// itself.
@@ -145,24 +144,23 @@ class CefBrowserInfoManager : public content::RenderProcessHostObserver {
// |browser| will be set to the target browser if any.
bool MaybeAllowNavigation(content::RenderFrameHost* opener,
const content::OpenURLParams& params,
CefRefPtr<CefBrowserHostBase>& browser) const;
CefRefPtr<CefBrowserHostImpl>& browser) const;
private:
// RenderProcessHostObserver methods:
void RenderProcessHostDestroyed(content::RenderProcessHost* host) override;
// Store state information about pending popups. Call order is:
// - CanCreateWindow (UIT):
// - AlloyContentBrowserClient::CanCreateWindow (UIT)
// Provides an opportunity to cancel the popup (calls OnBeforePopup) and
// creates the new platform delegate for the popup. If the popup owner is
// an extension guest view then the popup is canceled and
// WebContentsDelegate::OpenURLFromTab is called via the
// CefBrowserHostBase::MaybeAllowNavigation implementation.
// CefBrowserHostImpl::OpenURLFromTab is called.
// And then the following calls may occur at the same time:
// - GetCustomWebContentsView (UIT) (alloy runtime only):
// - CefBrowserHostImpl::GetCustomWebContentsView (UIT)
// Creates the OSR views for windowless popups.
// - WebContentsCreated (UIT):
// Creates the CefBrowserHost representation for the popup.
// - CefBrowserHostImpl::WebContentsCreated (UIT)
// Creates the CefBrowserHostImpl representation for the popup.
// - CefBrowserMessageFilter::OnGetNewBrowserInfo (IOT)
// Passes information about the popup to the renderer process.
struct PendingPopup {

View File

@@ -9,7 +9,7 @@
#include "base/message_loop/message_pump.h"
#include "base/message_loop/message_pump_for_ui.h"
#if defined(OS_MAC)
#if defined(OS_MACOSX)
#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/message_loop/message_pump_mac.h"
#endif
@@ -29,7 +29,7 @@ class MessagePumpExternal : public base::MessagePumpForUI {
void Run(Delegate* delegate) override {
base::TimeTicks start = base::TimeTicks::Now();
while (true) {
#if defined(OS_MAC)
#if defined(OS_MACOSX)
base::mac::ScopedNSAutoreleasePool autorelease_pool;
#endif
@@ -108,7 +108,7 @@ std::unique_ptr<base::MessagePump> MessagePumpFactoryForUI() {
return std::make_unique<MessagePumpExternal>(0.01f, handler);
}
#if defined(OS_MAC)
#if defined(OS_MACOSX)
return base::MessagePumpMac::Create();
#else
return std::make_unique<base::MessagePumpForUI>();

View File

@@ -4,7 +4,7 @@
#include "libcef/browser/browser_platform_delegate.h"
#include "libcef/browser/alloy/alloy_browser_host_impl.h"
#include "libcef/browser/browser_host_impl.h"
#include "base/logging.h"
@@ -14,13 +14,6 @@ CefBrowserPlatformDelegate::~CefBrowserPlatformDelegate() {
DCHECK(!browser_);
}
content::WebContents* CefBrowserPlatformDelegate::CreateWebContents(
CefBrowserCreateParams& create_params,
bool& own_web_contents) {
NOTREACHED();
return nullptr;
}
void CefBrowserPlatformDelegate::CreateViewForWebContents(
content::WebContentsView** view,
content::RenderViewHostDelegateView** delegate_view) {
@@ -64,7 +57,7 @@ void CefBrowserPlatformDelegate::RenderViewCreated(
void CefBrowserPlatformDelegate::RenderViewReady() {}
void CefBrowserPlatformDelegate::BrowserCreated(CefBrowserHostBase* browser) {
void CefBrowserPlatformDelegate::BrowserCreated(CefBrowserHostImpl* browser) {
// We should have an associated WebContents at this point.
DCHECK(web_contents_);
@@ -90,7 +83,7 @@ void CefBrowserPlatformDelegate::NotifyBrowserCreated() {}
void CefBrowserPlatformDelegate::NotifyBrowserDestroyed() {}
void CefBrowserPlatformDelegate::BrowserDestroyed(CefBrowserHostBase* browser) {
void CefBrowserPlatformDelegate::BrowserDestroyed(CefBrowserHostImpl* browser) {
// WebContentsDestroyed should already be called.
DCHECK(!web_contents_);
@@ -107,11 +100,6 @@ void CefBrowserPlatformDelegate::CloseHostWindow() {
NOTREACHED();
}
CefWindowHandle CefBrowserPlatformDelegate::GetHostWindowHandle() const {
NOTREACHED();
return kNullWindowHandle;
}
#if defined(USE_AURA)
views::Widget* CefBrowserPlatformDelegate::GetWindowWidget() const {
NOTREACHED();
@@ -132,75 +120,19 @@ void CefBrowserPlatformDelegate::PopupWebContentsCreated(
bool is_devtools) {}
void CefBrowserPlatformDelegate::PopupBrowserCreated(
CefBrowserHostBase* new_browser,
CefBrowserHostImpl* new_browser,
bool is_devtools) {}
SkColor CefBrowserPlatformDelegate::GetBackgroundColor() const {
NOTREACHED();
return SkColor();
}
void CefBrowserPlatformDelegate::WasResized() {
NOTREACHED();
}
void CefBrowserPlatformDelegate::SendKeyEvent(const CefKeyEvent& event) {
NOTIMPLEMENTED();
}
void CefBrowserPlatformDelegate::SendMouseClickEvent(
const CefMouseEvent& event,
CefBrowserHost::MouseButtonType type,
bool mouseUp,
int clickCount) {
NOTIMPLEMENTED();
}
void CefBrowserPlatformDelegate::SendMouseMoveEvent(const CefMouseEvent& event,
bool mouseLeave) {
NOTIMPLEMENTED();
}
void CefBrowserPlatformDelegate::SendMouseWheelEvent(const CefMouseEvent& event,
int deltaX,
int deltaY) {
NOTIMPLEMENTED();
}
void CefBrowserPlatformDelegate::SendTouchEvent(const CefTouchEvent& event) {
NOTIMPLEMENTED();
}
void CefBrowserPlatformDelegate::SendFocusEvent(bool setFocus) {
NOTIMPLEMENTED();
}
void CefBrowserPlatformDelegate::SendCaptureLostEvent() {
NOTIMPLEMENTED();
}
#if defined(OS_WIN) || (defined(OS_POSIX) && !defined(OS_MAC))
#if defined(OS_WIN) || (defined(OS_POSIX) && !defined(OS_MACOSX))
void CefBrowserPlatformDelegate::NotifyMoveOrResizeStarted() {}
void CefBrowserPlatformDelegate::SizeTo(int width, int height) {}
#endif
gfx::Point CefBrowserPlatformDelegate::GetScreenPoint(
const gfx::Point& view) const {
NOTREACHED();
return gfx::Point();
}
void CefBrowserPlatformDelegate::ViewText(const std::string& text) {
NOTIMPLEMENTED();
}
bool CefBrowserPlatformDelegate::HandleKeyboardEvent(
const content::NativeWebKeyboardEvent& event) {
NOTREACHED();
return false;
}
bool CefBrowserPlatformDelegate::PreHandleGestureEvent(
content::WebContents* source,
const blink::WebGestureEvent& event) {
@@ -212,12 +144,6 @@ bool CefBrowserPlatformDelegate::IsNeverComposited(
return false;
}
CefEventHandle CefBrowserPlatformDelegate::GetEventHandle(
const content::NativeWebKeyboardEvent& event) const {
NOTREACHED();
return kNullEventHandle;
}
std::unique_ptr<CefFileDialogRunner>
CefBrowserPlatformDelegate::CreateFileDialogRunner() {
NOTIMPLEMENTED();
@@ -230,19 +156,6 @@ CefBrowserPlatformDelegate::CreateJavaScriptDialogRunner() {
return nullptr;
}
std::unique_ptr<CefMenuRunner> CefBrowserPlatformDelegate::CreateMenuRunner() {
NOTIMPLEMENTED();
return nullptr;
}
bool CefBrowserPlatformDelegate::IsWindowless() const {
return false;
}
bool CefBrowserPlatformDelegate::IsViewsHosted() const {
return false;
}
void CefBrowserPlatformDelegate::WasHidden(bool hidden) {
NOTREACHED();
}
@@ -309,16 +222,16 @@ void CefBrowserPlatformDelegate::DragTargetDrop(const CefMouseEvent& event) {
void CefBrowserPlatformDelegate::StartDragging(
const content::DropData& drop_data,
blink::DragOperationsMask allowed_ops,
blink::WebDragOperationsMask allowed_ops,
const gfx::ImageSkia& image,
const gfx::Vector2d& image_offset,
const blink::mojom::DragEventSourceInfo& event_info,
const content::DragEventSourceInfo& event_info,
content::RenderWidgetHostImpl* source_rwh) {
NOTREACHED();
}
void CefBrowserPlatformDelegate::UpdateDragCursor(
blink::DragOperation operation) {
blink::WebDragOperation operation) {
NOTREACHED();
}

View File

@@ -13,18 +13,12 @@
#include "include/cef_drag_data.h"
#include "include/internal/cef_types.h"
#include "include/views/cef_browser_view.h"
#include "libcef/browser/browser_host_impl.h"
#include "base/callback_forward.h"
#include "extensions/common/view_type.h"
#include "third_party/blink/public/common/page/drag_operation.h"
#include "third_party/blink/public/mojom/page/drag.mojom-forward.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/window_open_disposition.h"
class GURL;
#include "content/public/browser/web_contents.h"
namespace blink {
class WebGestureEvent;
class WebMouseEvent;
class WebMouseWheelEvent;
class WebInputEvent;
@@ -32,29 +26,15 @@ class WebTouchEvent;
} // namespace blink
namespace content {
struct AXEventNotificationDetails;
struct AXLocationChangeNotificationDetails;
struct DropData;
struct NativeWebKeyboardEvent;
class RenderViewHost;
class RenderViewHostDelegateView;
class RenderWidgetHostImpl;
class WebContents;
class WebContentsView;
} // namespace content
namespace extensions {
class Extension;
class ExtensionHost;
} // namespace extensions
namespace gfx {
class ImageSkia;
class Point;
class Rect;
class Size;
class Vector2d;
} // namespace gfx
}
#if defined(USE_AURA)
namespace views {
@@ -62,8 +42,6 @@ class Widget;
}
#endif
struct CefBrowserCreateParams;
class CefBrowserHostBase;
class CefFileDialogRunner;
class CefJavaScriptDialogRunner;
class CefMenuRunner;
@@ -76,14 +54,14 @@ class CefBrowserPlatformDelegate {
// Create a new CefBrowserPlatformDelegate instance. May be called on multiple
// threads.
static std::unique_ptr<CefBrowserPlatformDelegate> Create(
const CefBrowserCreateParams& create_params);
CefBrowserHostImpl::CreateParams& create_params);
// Called from AlloyBrowserHostImpl::Create.
// Called from CefBrowserHostImpl::Create.
// Wait for the call to WebContentsCreated(owned=true) before taking ownership
// of the resulting WebContents object.
virtual content::WebContents* CreateWebContents(
CefBrowserCreateParams& create_params,
bool& own_web_contents);
CefBrowserHostImpl::CreateParams& create_params,
bool& own_web_contents) = 0;
// Called to create the view objects for a new WebContents. Will only be
// called a single time per instance. May be called on multiple threads. Only
@@ -125,12 +103,12 @@ class CefBrowserPlatformDelegate {
// See WebContentsObserver documentation.
virtual void RenderViewReady();
// Called after the owning AlloyBrowserHostImpl is created. Will only be
// called a single time per instance. Do not send any client notifications
// from this method.
virtual void BrowserCreated(CefBrowserHostBase* browser);
// Called after the owning CefBrowserHostImpl is created. Will only be called
// a single time per instance. Do not send any client notifications from this
// method.
virtual void BrowserCreated(CefBrowserHostImpl* browser);
// Called from AlloyBrowserHostImpl::Create.
// Called from CefBrowserHostImpl::Create.
virtual void CreateExtensionHost(const extensions::Extension* extension,
const GURL& url,
extensions::ViewType host_type);
@@ -146,11 +124,11 @@ class CefBrowserPlatformDelegate {
// BrowserDestroyed().
virtual void NotifyBrowserDestroyed();
// Called before the owning AlloyBrowserHostImpl is destroyed. Will only be
// called a single time per instance. All references to the
// AlloyBrowserHostImpl and WebContents should be cleared when this method is
// called. Do not send any client notifications from this method.
virtual void BrowserDestroyed(CefBrowserHostBase* browser);
// Called before the owning CefBrowserHostImpl is destroyed. Will only be
// called a single time per instance. All references to the CefBrowserHostImpl
// and WebContents should be cleared when this method is called. Do not send
// any client notifications from this method.
virtual void BrowserDestroyed(CefBrowserHostImpl* browser);
// Create the window that hosts the browser. Will only be called a single time
// per instance. Only used with windowed rendering.
@@ -165,7 +143,7 @@ class CefBrowserPlatformDelegate {
// rendering this will return the most immediate parent window handle. For
// windowless rendering this will return the parent window handle specified by
// the client, which may be NULL. May be called on multiple threads.
virtual CefWindowHandle GetHostWindowHandle() const;
virtual CefWindowHandle GetHostWindowHandle() const = 0;
#if defined(USE_AURA)
// Returns the Widget owner for the browser window. Only used with windowed
@@ -178,7 +156,7 @@ class CefBrowserPlatformDelegate {
#endif
// Called after the WebContents have been created for a new popup browser
// parented to this browser but before the AlloyBrowserHostImpl is created for
// parented to this browser but before the CefBrowserHostImpl is created for
// the popup. |is_devtools| will be true if the popup will host DevTools. This
// method will be called before WebContentsCreated() is called on
// |new_platform_delegate|. Do not make the new browser visible in this
@@ -190,13 +168,13 @@ class CefBrowserPlatformDelegate {
CefBrowserPlatformDelegate* new_platform_delegate,
bool is_devtools);
// Called after the AlloyBrowserHostImpl is created for a new popup browser
// Called after the CefBrowserHostImpl is created for a new popup browser
// parented to this browser. |is_devtools| will be true if the popup will host
// DevTools. This method will be called immediately after
// CefLifeSpanHandler::OnAfterCreated() for the popup browser. It is safe to
// make the new browser visible in this callback (for example, add the browser
// to a window and show it).
virtual void PopupBrowserCreated(CefBrowserHostBase* new_browser,
virtual void PopupBrowserCreated(CefBrowserHostImpl* new_browser,
bool is_devtools);
// Returns the background color for the browser. The alpha component will be
@@ -204,31 +182,32 @@ class CefBrowserPlatformDelegate {
// fully opaque). SK_AlphaOPAQUE will always be returned for windowed
// browsers. SK_ColorTRANSPARENT may be returned for windowless browsers to
// enable transparency.
virtual SkColor GetBackgroundColor() const;
virtual SkColor GetBackgroundColor() const = 0;
// Notify the window that it was resized.
virtual void WasResized();
virtual void WasResized() = 0;
// Send input events.
virtual void SendKeyEvent(const CefKeyEvent& event);
virtual void SendKeyEvent(const CefKeyEvent& event) = 0;
virtual void SendMouseClickEvent(const CefMouseEvent& event,
CefBrowserHost::MouseButtonType type,
bool mouseUp,
int clickCount);
virtual void SendMouseMoveEvent(const CefMouseEvent& event, bool mouseLeave);
int clickCount) = 0;
virtual void SendMouseMoveEvent(const CefMouseEvent& event,
bool mouseLeave) = 0;
virtual void SendMouseWheelEvent(const CefMouseEvent& event,
int deltaX,
int deltaY);
virtual void SendTouchEvent(const CefTouchEvent& event);
int deltaY) = 0;
virtual void SendTouchEvent(const CefTouchEvent& event) = 0;
// Send focus event. The browser's WebContents may be NULL when this method is
// called.
virtual void SendFocusEvent(bool setFocus);
virtual void SendFocusEvent(bool setFocus) = 0;
// Send capture lost event.
virtual void SendCaptureLostEvent();
#if defined(OS_WIN) || (defined(OS_POSIX) && !defined(OS_MAC))
#if defined(OS_WIN) || (defined(OS_POSIX) && !defined(OS_MACOSX))
// The window hosting the browser is about to be moved or resized. Only used
// on Windows and Linux.
virtual void NotifyMoveOrResizeStarted();
@@ -240,15 +219,15 @@ class CefBrowserPlatformDelegate {
// Convert from view coordinates to screen coordinates. Potential display
// scaling will be applied to the result.
virtual gfx::Point GetScreenPoint(const gfx::Point& view) const;
virtual gfx::Point GetScreenPoint(const gfx::Point& view) const = 0;
// Open the specified text in the default text editor.
virtual void ViewText(const std::string& text);
virtual void ViewText(const std::string& text) = 0;
// Forward the keyboard event to the application or frame window to allow
// processing of shortcut keys.
virtual bool HandleKeyboardEvent(
const content::NativeWebKeyboardEvent& event);
const content::NativeWebKeyboardEvent& event) = 0;
// See WebContentsDelegate documentation.
virtual bool PreHandleGestureEvent(content::WebContents* source,
@@ -262,7 +241,7 @@ class CefBrowserPlatformDelegate {
// Returns the OS event handle, if any, associated with |event|.
virtual CefEventHandle GetEventHandle(
const content::NativeWebKeyboardEvent& event) const;
const content::NativeWebKeyboardEvent& event) const = 0;
// Create the platform-specific file dialog runner.
virtual std::unique_ptr<CefFileDialogRunner> CreateFileDialogRunner();
@@ -272,15 +251,15 @@ class CefBrowserPlatformDelegate {
CreateJavaScriptDialogRunner();
// Create the platform-specific menu runner.
virtual std::unique_ptr<CefMenuRunner> CreateMenuRunner();
virtual std::unique_ptr<CefMenuRunner> CreateMenuRunner() = 0;
// Returns true if this delegate implements windowless rendering. May be
// called on multiple threads.
virtual bool IsWindowless() const;
virtual bool IsWindowless() const = 0;
// Returns true if this delegate implements views-hosted browser handling. May
// be called on multiple threads.
virtual bool IsViewsHosted() const;
virtual bool IsViewsHosted() const = 0;
// Notify the browser that it was hidden. Only used with windowless rendering.
virtual void WasHidden(bool hidden);
@@ -320,14 +299,13 @@ class CefBrowserPlatformDelegate {
cef_drag_operations_mask_t allowed_ops);
virtual void DragTargetDragLeave();
virtual void DragTargetDrop(const CefMouseEvent& event);
virtual void StartDragging(
const content::DropData& drop_data,
blink::DragOperationsMask allowed_ops,
const gfx::ImageSkia& image,
const gfx::Vector2d& image_offset,
const blink::mojom::DragEventSourceInfo& event_info,
content::RenderWidgetHostImpl* source_rwh);
virtual void UpdateDragCursor(blink::DragOperation operation);
virtual void StartDragging(const content::DropData& drop_data,
blink::WebDragOperationsMask allowed_ops,
const gfx::ImageSkia& image,
const gfx::Vector2d& image_offset,
const content::DragEventSourceInfo& event_info,
content::RenderWidgetHostImpl* source_rwh);
virtual void UpdateDragCursor(blink::WebDragOperation operation);
virtual void DragSourceEndedAt(int x, int y, cef_drag_operations_mask_t op);
virtual void DragSourceSystemDragEnded();
virtual void AccessibilityEventReceived(
@@ -365,7 +343,7 @@ class CefBrowserPlatformDelegate {
// Not owned by this object.
content::WebContents* web_contents_ = nullptr;
CefBrowserHostBase* browser_ = nullptr;
CefBrowserHostImpl* browser_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(CefBrowserPlatformDelegate);
};

View File

@@ -11,7 +11,6 @@
#include "base/memory/ptr_util.h"
#include "build/build_config.h"
#include "libcef/browser/browser_host_base.h"
#include "libcef/browser/chrome/browser_platform_delegate_chrome.h"
#include "libcef/browser/extensions/browser_platform_delegate_background.h"
#include "libcef/features/runtime_checks.h"
@@ -19,7 +18,7 @@
#if defined(OS_WIN)
#include "libcef/browser/native/browser_platform_delegate_native_win.h"
#include "libcef/browser/osr/browser_platform_delegate_osr_win.h"
#elif defined(OS_MAC)
#elif defined(OS_MACOSX)
#include "libcef/browser/native/browser_platform_delegate_native_mac.h"
#include "libcef/browser/osr/browser_platform_delegate_osr_mac.h"
#elif defined(OS_LINUX)
@@ -41,7 +40,7 @@ std::unique_ptr<CefBrowserPlatformDelegateNative> CreateNativeDelegate(
#if defined(OS_WIN)
return std::make_unique<CefBrowserPlatformDelegateNativeWin>(
window_info, background_color);
#elif defined(OS_MAC)
#elif defined(OS_MACOSX)
return std::make_unique<CefBrowserPlatformDelegateNativeMac>(
window_info, background_color);
#elif defined(OS_LINUX)
@@ -57,7 +56,7 @@ std::unique_ptr<CefBrowserPlatformDelegateOsr> CreateOSRDelegate(
#if defined(OS_WIN)
return std::make_unique<CefBrowserPlatformDelegateOsrWin>(
std::move(native_delegate), use_shared_texture, use_external_begin_frame);
#elif defined(OS_MAC)
#elif defined(OS_MACOSX)
return std::make_unique<CefBrowserPlatformDelegateOsrMac>(
std::move(native_delegate));
#elif defined(OS_LINUX)
@@ -70,7 +69,7 @@ std::unique_ptr<CefBrowserPlatformDelegateOsr> CreateOSRDelegate(
// static
std::unique_ptr<CefBrowserPlatformDelegate> CefBrowserPlatformDelegate::Create(
const CefBrowserCreateParams& create_params) {
CefBrowserHostImpl::CreateParams& create_params) {
const bool is_windowless =
create_params.window_info &&
create_params.window_info->windowless_rendering_enabled &&
@@ -79,11 +78,7 @@ std::unique_ptr<CefBrowserPlatformDelegate> CefBrowserPlatformDelegate::Create(
&create_params.settings, is_windowless ? STATE_ENABLED : STATE_DISABLED);
if (cef::IsChromeRuntimeEnabled()) {
// CefWindowInfo is not used in this case.
std::unique_ptr<CefBrowserPlatformDelegateNative> native_delegate =
CreateNativeDelegate(CefWindowInfo(), background_color);
return std::make_unique<CefBrowserPlatformDelegateChrome>(
std::move(native_delegate));
return std::make_unique<CefBrowserPlatformDelegateChrome>(background_color);
}
if (create_params.window_info) {

View File

@@ -1,48 +0,0 @@
// Copyright 2020 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_CHROME_BROWSER_DELEGATE_H_
#define CEF_LIBCEF_BROWSER_CHROME_BROWSER_DELEGATE_H_
#pragma once
#include <memory>
#include "base/memory/scoped_refptr.h"
#include "content/public/browser/web_contents_delegate.h"
class Browser;
namespace cef {
// Delegate for the chrome Browser object. Lifespan is controlled by the Browser
// object. See the ChromeBrowserDelegate documentation for additional details.
// Only accessed on the UI thread.
class BrowserDelegate : public content::WebContentsDelegate {
public:
// Opaque ref-counted base class for CEF-specific parameters passed via
// Browser::CreateParams::cef_params and possibly shared by multiple Browser
// instances.
class CreateParams : public base::RefCounted<CreateParams> {
public:
virtual ~CreateParams() {}
};
// Called from the Browser constructor to create a new delegate.
static std::unique_ptr<BrowserDelegate> Create(
Browser* browser,
scoped_refptr<CreateParams> cef_params);
~BrowserDelegate() override {}
// Called immediately after |new_contents| is created.
virtual void OnWebContentsCreated(content::WebContents* new_contents) = 0;
// Add or remove ownership of the WebContents.
virtual void SetAsDelegate(content::WebContents* web_contents,
bool set_delegate) = 0;
};
} // namespace cef
#endif // CEF_LIBCEF_BROWSER_CHROME_BROWSER_DELEGATE_H_

View File

@@ -4,98 +4,135 @@
#include "libcef/browser/chrome/browser_platform_delegate_chrome.h"
#include "base/logging.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h"
#include "ui/display/screen.h"
#include "ui/gfx/geometry/point.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
CefBrowserPlatformDelegateChrome::CefBrowserPlatformDelegateChrome(
std::unique_ptr<CefBrowserPlatformDelegateNative> native_delegate)
: native_delegate_(std::move(native_delegate)) {
native_delegate_->set_windowless_handler(this);
}
SkColor background_color)
: background_color_(background_color) {}
void CefBrowserPlatformDelegateChrome::WebContentsCreated(
content::WebContents* web_contents,
bool owned) {
CefBrowserPlatformDelegate::WebContentsCreated(web_contents, owned);
native_delegate_->WebContentsCreated(web_contents, /*owned=*/false);
content::WebContents* CefBrowserPlatformDelegateChrome::CreateWebContents(
CefBrowserHostImpl::CreateParams& create_params,
bool& own_web_contents) {
// Get or create the request context and profile.
CefRefPtr<CefRequestContextImpl> request_context_impl =
CefRequestContextImpl::GetOrCreateForRequestContext(
create_params.request_context);
CHECK(request_context_impl);
auto cef_browser_context = request_context_impl->GetBrowserContext();
CHECK(cef_browser_context);
auto profile = cef_browser_context->AsProfile();
if (!create_params.request_context) {
// Using the global request context.
create_params.request_context = request_context_impl.get();
}
// Create a Browser.
Browser::CreateParams params =
Browser::CreateParams(profile, /*user_gesture=*/false);
chrome_browser_ = new Browser(params);
chrome::AddTabAt(chrome_browser_, create_params.url, /*idx=*/-1,
/*foreground=*/true);
auto web_contents =
chrome_browser_->tab_strip_model()->GetActiveWebContents();
CHECK(web_contents);
own_web_contents = false;
return web_contents;
}
void CefBrowserPlatformDelegateChrome::WebContentsDestroyed(
content::WebContents* web_contents) {
CefBrowserPlatformDelegate::WebContentsDestroyed(web_contents);
native_delegate_->WebContentsDestroyed(web_contents);
}
void CefBrowserPlatformDelegateChrome::BrowserCreated(
CefBrowserHostBase* browser) {
CefBrowserPlatformDelegate::BrowserCreated(browser);
native_delegate_->BrowserCreated(browser);
// TODO(chrome-runtime): Find a better way to be notified of Browser
// destruction.
browser_->WindowDestroyed();
}
void CefBrowserPlatformDelegateChrome::BrowserDestroyed(
CefBrowserHostBase* browser) {
CefBrowserHostImpl* browser) {
CefBrowserPlatformDelegate::BrowserDestroyed(browser);
native_delegate_->BrowserDestroyed(browser);
// Release the reference added in CreateHostWindow.
browser->Release();
}
bool CefBrowserPlatformDelegateChrome::CreateHostWindow() {
// Keep a reference to the CEF browser.
browser_->AddRef();
chrome_browser_->window()->Show();
return true;
}
void CefBrowserPlatformDelegateChrome::CloseHostWindow() {}
CefWindowHandle CefBrowserPlatformDelegateChrome::GetHostWindowHandle() const {
return kNullWindowHandle;
}
SkColor CefBrowserPlatformDelegateChrome::GetBackgroundColor() const {
return native_delegate_->GetBackgroundColor();
return background_color_;
}
void CefBrowserPlatformDelegateChrome::SendKeyEvent(const CefKeyEvent& event) {
native_delegate_->SendKeyEvent(event);
}
void CefBrowserPlatformDelegateChrome::WasResized() {}
void CefBrowserPlatformDelegateChrome::SendKeyEvent(const CefKeyEvent& event) {}
void CefBrowserPlatformDelegateChrome::SendMouseClickEvent(
const CefMouseEvent& event,
CefBrowserHost::MouseButtonType type,
bool mouseUp,
int clickCount) {
native_delegate_->SendMouseClickEvent(event, type, mouseUp, clickCount);
}
int clickCount) {}
void CefBrowserPlatformDelegateChrome::SendMouseMoveEvent(
const CefMouseEvent& event,
bool mouseLeave) {
native_delegate_->SendMouseMoveEvent(event, mouseLeave);
}
bool mouseLeave) {}
void CefBrowserPlatformDelegateChrome::SendMouseWheelEvent(
const CefMouseEvent& event,
int deltaX,
int deltaY) {
native_delegate_->SendMouseWheelEvent(event, deltaX, deltaY);
}
int deltaY) {}
void CefBrowserPlatformDelegateChrome::SendTouchEvent(
const CefTouchEvent& event) {}
void CefBrowserPlatformDelegateChrome::SendFocusEvent(bool setFocus) {}
gfx::Point CefBrowserPlatformDelegateChrome::GetScreenPoint(
const gfx::Point& view) const {
auto screen = display::Screen::GetScreen();
gfx::NativeWindow native_window =
chrome_browser_ ? chrome_browser_->window()->GetNativeWindow() : nullptr;
// Returns screen pixel coordinates.
auto screen_rect = screen->DIPToScreenRectInWindow(
native_window, gfx::Rect(view, gfx::Size(0, 0)));
return screen_rect.origin();
return view;
}
void CefBrowserPlatformDelegateChrome::ViewText(const std::string& text) {
native_delegate_->ViewText(text);
void CefBrowserPlatformDelegateChrome::ViewText(const std::string& text) {}
bool CefBrowserPlatformDelegateChrome::HandleKeyboardEvent(
const content::NativeWebKeyboardEvent& event) {
return false;
}
CefWindowHandle CefBrowserPlatformDelegateChrome::GetParentWindowHandle()
const {
return GetHostWindowHandle();
CefEventHandle CefBrowserPlatformDelegateChrome::GetEventHandle(
const content::NativeWebKeyboardEvent& event) const {
return kNullEventHandle;
}
gfx::Point CefBrowserPlatformDelegateChrome::GetParentScreenPoint(
const gfx::Point& view) const {
return GetScreenPoint(view);
std::unique_ptr<CefMenuRunner>
CefBrowserPlatformDelegateChrome::CreateMenuRunner() {
NOTIMPLEMENTED();
return nullptr;
}
void CefBrowserPlatformDelegateChrome::set_chrome_browser(Browser* browser) {
chrome_browser_ = browser;
bool CefBrowserPlatformDelegateChrome::IsWindowless() const {
return false;
}
bool CefBrowserPlatformDelegateChrome::IsViewsHosted() const {
return false;
}

View File

@@ -6,25 +6,25 @@
#define CEF_LIBCEF_BROWSER_CHROME_BROWSER_PLATFORM_DELEGATE_CHROME_H_
#include "libcef/browser/browser_platform_delegate.h"
#include "libcef/browser/native/browser_platform_delegate_native.h"
class Browser;
// Implementation of Chrome-based browser functionality.
class CefBrowserPlatformDelegateChrome
: public CefBrowserPlatformDelegate,
public CefBrowserPlatformDelegateNative::WindowlessHandler {
class CefBrowserPlatformDelegateChrome : public CefBrowserPlatformDelegate {
public:
explicit CefBrowserPlatformDelegateChrome(
std::unique_ptr<CefBrowserPlatformDelegateNative> native_delegate);
explicit CefBrowserPlatformDelegateChrome(SkColor background_color);
// CefBrowserPlatformDelegate overrides.
void WebContentsCreated(content::WebContents* web_contents,
bool owned) override;
content::WebContents* CreateWebContents(
CefBrowserHostImpl::CreateParams& create_params,
bool& own_web_contents) override;
void WebContentsDestroyed(content::WebContents* web_contents) override;
void BrowserCreated(CefBrowserHostBase* browser) override;
void BrowserDestroyed(CefBrowserHostBase* browser) override;
void BrowserDestroyed(CefBrowserHostImpl* browser) override;
bool CreateHostWindow() override;
void CloseHostWindow() override;
CefWindowHandle GetHostWindowHandle() const override;
SkColor GetBackgroundColor() const override;
void WasResized() override;
void SendKeyEvent(const CefKeyEvent& event) override;
void SendMouseClickEvent(const CefMouseEvent& event,
CefBrowserHost::MouseButtonType type,
@@ -34,19 +34,22 @@ class CefBrowserPlatformDelegateChrome
void SendMouseWheelEvent(const CefMouseEvent& event,
int deltaX,
int deltaY) override;
void SendTouchEvent(const CefTouchEvent& event) override;
void SendFocusEvent(bool setFocus) override;
gfx::Point GetScreenPoint(const gfx::Point& view) const override;
void ViewText(const std::string& text) override;
// CefBrowserPlatformDelegateNative::WindowlessHandler methods:
CefWindowHandle GetParentWindowHandle() const override;
gfx::Point GetParentScreenPoint(const gfx::Point& view) const override;
void set_chrome_browser(Browser* browser);
bool HandleKeyboardEvent(
const content::NativeWebKeyboardEvent& event) override;
CefEventHandle GetEventHandle(
const content::NativeWebKeyboardEvent& event) const override;
std::unique_ptr<CefMenuRunner> CreateMenuRunner() override;
bool IsWindowless() const override;
bool IsViewsHosted() const override;
private:
std::unique_ptr<CefBrowserPlatformDelegateNative> native_delegate_;
const SkColor background_color_;
Browser* chrome_browser_ = nullptr;
Browser* chrome_browser_;
};
#endif // CEF_LIBCEF_BROWSER_CHROME_BROWSER_PLATFORM_DELEGATE_CHROME_H_

View File

@@ -4,8 +4,6 @@
#include "libcef/browser/chrome/chrome_browser_context.h"
#include "libcef/browser/prefs/browser_prefs.h"
#include "chrome/browser/profiles/profile_manager.h"
ChromeBrowserContext::ChromeBrowserContext(
@@ -30,8 +28,6 @@ void ChromeBrowserContext::Initialize() {
// The global ProfileManager instance can be retrieved via
// |g_browser_process->profile_manager()|.
profile_ = ProfileManager::GetLastUsedProfileAllowedByPolicy();
browser_prefs::SetLanguagePrefs(profile_);
}
void ChromeBrowserContext::Shutdown() {

View File

@@ -1,260 +0,0 @@
// Copyright 2020 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 <memory>
#include "libcef/browser/chrome/chrome_browser_delegate.h"
#include "libcef/browser/browser_contents_delegate.h"
#include "libcef/browser/browser_host_base.h"
#include "libcef/browser/browser_info_manager.h"
#include "libcef/browser/browser_platform_delegate.h"
#include "libcef/browser/chrome/chrome_browser_host_impl.h"
#include "libcef/browser/request_context_impl.h"
#include "libcef/common/app_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "content/public/browser/keyboard_event_processing_result.h"
#include "content/public/browser/native_web_keyboard_event.h"
using content::KeyboardEventProcessingResult;
ChromeBrowserDelegate::ChromeBrowserDelegate(
Browser* browser,
const CefBrowserCreateParams& create_params)
: browser_(browser), create_params_(create_params) {
DCHECK(browser_);
}
ChromeBrowserDelegate::~ChromeBrowserDelegate() = default;
void ChromeBrowserDelegate::OnWebContentsCreated(
content::WebContents* new_contents) {
// Necessary to receive LoadingStateChanged calls during initial navigation.
// This will be called again in Browser::SetAsDelegate, which should be fine.
new_contents->SetDelegate(browser_);
SetAsDelegate(new_contents, /*set_delegate=*/true);
}
void ChromeBrowserDelegate::SetAsDelegate(content::WebContents* web_contents,
bool set_delegate) {
DCHECK(web_contents);
auto browser_host =
ChromeBrowserHostImpl::GetBrowserForContents(web_contents);
// |set_delegate=false| only makes sense if we already have a browser host.
DCHECK(browser_host || set_delegate);
if (browser_host) {
// We already have a browser host, so just change the associated Browser.
browser_host->SetBrowser(set_delegate ? browser_ : nullptr);
return;
}
auto platform_delegate = CefBrowserPlatformDelegate::Create(create_params_);
CHECK(platform_delegate);
auto browser_info = CefBrowserInfoManager::GetInstance()->CreateBrowserInfo(
/*is_popup=*/false, /*is_windowless=*/false, create_params_.extra_info);
auto request_context_impl =
CefRequestContextImpl::GetOrCreateForRequestContext(
create_params_.request_context);
CreateBrowser(web_contents, create_params_.settings, create_params_.client,
std::move(platform_delegate), browser_info,
request_context_impl);
}
void ChromeBrowserDelegate::WebContentsCreated(
content::WebContents* source_contents,
int opener_render_process_id,
int opener_render_frame_id,
const std::string& frame_name,
const GURL& target_url,
content::WebContents* new_contents) {
CefBrowserSettings settings;
CefRefPtr<CefClient> client;
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate;
CefRefPtr<CefDictionaryValue> extra_info;
CefBrowserInfoManager::GetInstance()->WebContentsCreated(
target_url, opener_render_process_id, opener_render_frame_id, settings,
client, platform_delegate, extra_info);
auto opener = ChromeBrowserHostImpl::GetBrowserForContents(source_contents);
if (!opener) {
LOG(ERROR) << "No opener found for chrome popup browser";
return;
}
auto browser_info =
CefBrowserInfoManager::GetInstance()->CreatePopupBrowserInfo(
new_contents, /*is_windowless=*/false, extra_info);
CHECK(browser_info->is_popup());
// Popups must share the same RequestContext as the parent.
auto request_context_impl = opener->request_context();
CHECK(request_context_impl);
// We don't officially own |new_contents| until AddNewContents() is called.
// However, we need to install observers/delegates here.
CreateBrowser(new_contents, settings, client, std::move(platform_delegate),
browser_info, request_context_impl);
}
content::WebContents* ChromeBrowserDelegate::OpenURLFromTab(
content::WebContents* source,
const content::OpenURLParams& params) {
// Return nullptr to cancel the navigation. Otherwise, proceed with default
// chrome handling.
if (auto delegate = GetDelegateForWebContents(source)) {
return delegate->OpenURLFromTab(source, params);
}
return nullptr;
}
void ChromeBrowserDelegate::LoadingStateChanged(content::WebContents* source,
bool to_different_document) {
if (auto delegate = GetDelegateForWebContents(source)) {
delegate->LoadingStateChanged(source, to_different_document);
}
}
void ChromeBrowserDelegate::UpdateTargetURL(content::WebContents* source,
const GURL& url) {
if (auto delegate = GetDelegateForWebContents(source)) {
delegate->UpdateTargetURL(source, url);
}
}
bool ChromeBrowserDelegate::DidAddMessageToConsole(
content::WebContents* source,
blink::mojom::ConsoleMessageLevel log_level,
const base::string16& message,
int32_t line_no,
const base::string16& source_id) {
if (auto delegate = GetDelegateForWebContents(source)) {
return delegate->DidAddMessageToConsole(source, log_level, message, line_no,
source_id);
}
return false;
}
void ChromeBrowserDelegate::DidNavigateMainFramePostCommit(
content::WebContents* web_contents) {
if (auto delegate = GetDelegateForWebContents(web_contents)) {
delegate->DidNavigateMainFramePostCommit(web_contents);
}
}
void ChromeBrowserDelegate::EnterFullscreenModeForTab(
content::RenderFrameHost* requesting_frame,
const blink::mojom::FullscreenOptions& options) {
auto web_contents =
content::WebContents::FromRenderFrameHost(requesting_frame);
if (!web_contents)
return;
if (auto delegate = GetDelegateForWebContents(web_contents)) {
delegate->EnterFullscreenModeForTab(requesting_frame, options);
}
}
void ChromeBrowserDelegate::ExitFullscreenModeForTab(
content::WebContents* web_contents) {
if (auto delegate = GetDelegateForWebContents(web_contents)) {
delegate->ExitFullscreenModeForTab(web_contents);
}
}
KeyboardEventProcessingResult ChromeBrowserDelegate::PreHandleKeyboardEvent(
content::WebContents* source,
const content::NativeWebKeyboardEvent& event) {
if (auto delegate = GetDelegateForWebContents(source)) {
return delegate->PreHandleKeyboardEvent(source, event);
}
return KeyboardEventProcessingResult::NOT_HANDLED;
}
bool ChromeBrowserDelegate::HandleKeyboardEvent(
content::WebContents* source,
const content::NativeWebKeyboardEvent& event) {
if (auto delegate = GetDelegateForWebContents(source)) {
return delegate->HandleKeyboardEvent(source, event);
}
return false;
}
void ChromeBrowserDelegate::CreateBrowser(
content::WebContents* web_contents,
CefBrowserSettings settings,
CefRefPtr<CefClient> client,
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate,
scoped_refptr<CefBrowserInfo> browser_info,
CefRefPtr<CefRequestContextImpl> request_context_impl) {
CEF_REQUIRE_UIT();
DCHECK(web_contents);
DCHECK(platform_delegate);
DCHECK(browser_info);
DCHECK(request_context_impl);
if (!client) {
if (auto app = CefAppManager::Get()->GetApplication()) {
if (auto bph = app->GetBrowserProcessHandler()) {
client = bph->GetDefaultClient();
}
}
}
if (!client) {
LOG(WARNING) << "Creating a chrome browser without a client";
}
// Check if chrome and CEF are using the same browser context.
// TODO(chrome-runtime): Verify if/when this might occur.
auto chrome_browser_context =
CefBrowserContext::FromBrowserContext(browser_->create_params().profile);
if (chrome_browser_context != request_context_impl->GetBrowserContext()) {
LOG(WARNING) << "Creating a chrome browser with mismatched context";
}
// Remains alive until the associated WebContents is destroyed.
CefRefPtr<ChromeBrowserHostImpl> browser_host =
new ChromeBrowserHostImpl(settings, client, std::move(platform_delegate),
browser_info, request_context_impl);
browser_host->Attach(browser_, web_contents);
}
CefBrowserContentsDelegate* ChromeBrowserDelegate::GetDelegateForWebContents(
content::WebContents* web_contents) {
auto browser_host =
ChromeBrowserHostImpl::GetBrowserForContents(web_contents);
if (browser_host)
return browser_host->contents_delegate();
return nullptr;
}
namespace cef {
// static
std::unique_ptr<BrowserDelegate> BrowserDelegate::Create(
Browser* browser,
scoped_refptr<CreateParams> cef_params) {
CefBrowserCreateParams create_params;
// Parameters from ChromeBrowserHostImpl::Create, or nullptr if the Browser
// was created from somewhere else.
auto params = static_cast<ChromeBrowserHostImpl::DelegateCreateParams*>(
cef_params.get());
if (params) {
create_params = params->create_params_;
}
return std::make_unique<ChromeBrowserDelegate>(browser, create_params);
}
} // namespace cef

View File

@@ -1,104 +0,0 @@
// Copyright 2020 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_CHROME_CHROME_BROWSER_DELEGATE_H_
#define CEF_LIBCEF_BROWSER_CHROME_CHROME_BROWSER_DELEGATE_H_
#pragma once
#include <memory>
#include "libcef/browser/browser_host_base.h"
#include "libcef/browser/browser_info.h"
#include "libcef/browser/chrome/browser_delegate.h"
#include "base/optional.h"
class CefBrowserContentsDelegate;
class CefRequestContextImpl;
class ChromeBrowserHostImpl;
// Implementation of the cef::BrowserDelegate interface. Lifespan is controlled
// by the Browser object. Only accessed on the UI thread.
//
// The Browser object represents the top-level Chrome browser window. One or
// more tabs (WebContents) are then owned by the Browser object via
// TabStripModel. A new Browser object can be created programmatically using
// "new Browser" or Browser::Create, or as a result of user action such as
// dragging a tab out of an existing window. New or existing tabs can also be
// added to an already existing Browser object.
//
// The Browser object acts as the WebContentsDelegate for all attached tabs. CEF
// integration requires WebContentsDelegate callbacks and notification of tab
// attach/detach. To support this integration a cef::BrowserDelegate
// (ChromeBrowserDelegate) member is created in the Browser constructor and
// receives delegation for the Browser callbacks. ChromeBrowserDelegate creates
// a new ChromeBrowserHostImpl when a tab is added to a Browser for the first
// time, and that ChromeBrowserHostImpl continues to exist until the tab's
// WebContents is destroyed. The associated WebContents object does not change,
// but the Browser object will change when the tab is dragged between windows.
class ChromeBrowserDelegate : public cef::BrowserDelegate {
public:
ChromeBrowserDelegate(Browser* browser,
const CefBrowserCreateParams& create_params);
~ChromeBrowserDelegate() override;
// cef::BrowserDelegate methods:
void OnWebContentsCreated(content::WebContents* new_contents) override;
void SetAsDelegate(content::WebContents* web_contents,
bool set_delegate) override;
// WebContentsDelegate methods:
void WebContentsCreated(content::WebContents* source_contents,
int opener_render_process_id,
int opener_render_frame_id,
const std::string& frame_name,
const GURL& target_url,
content::WebContents* new_contents) override;
content::WebContents* OpenURLFromTab(
content::WebContents* source,
const content::OpenURLParams& params) override;
void LoadingStateChanged(content::WebContents* source,
bool to_different_document) override;
void UpdateTargetURL(content::WebContents* source, const GURL& url) override;
bool DidAddMessageToConsole(content::WebContents* source,
blink::mojom::ConsoleMessageLevel log_level,
const base::string16& message,
int32_t line_no,
const base::string16& source_id) override;
void DidNavigateMainFramePostCommit(
content::WebContents* web_contents) override;
void EnterFullscreenModeForTab(
content::RenderFrameHost* requesting_frame,
const blink::mojom::FullscreenOptions& options) override;
void ExitFullscreenModeForTab(content::WebContents* web_contents) override;
content::KeyboardEventProcessingResult PreHandleKeyboardEvent(
content::WebContents* source,
const content::NativeWebKeyboardEvent& event) override;
bool HandleKeyboardEvent(
content::WebContents* source,
const content::NativeWebKeyboardEvent& event) override;
Browser* browser() const { return browser_; }
private:
void CreateBrowser(
content::WebContents* web_contents,
CefBrowserSettings settings,
CefRefPtr<CefClient> client,
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate,
scoped_refptr<CefBrowserInfo> browser_info,
CefRefPtr<CefRequestContextImpl> request_context_impl);
CefBrowserContentsDelegate* GetDelegateForWebContents(
content::WebContents* web_contents);
Browser* const browser_;
// Used when creating a new browser host.
const CefBrowserCreateParams create_params_;
DISALLOW_COPY_AND_ASSIGN(ChromeBrowserDelegate);
};
#endif // CEF_LIBCEF_BROWSER_CHROME_CHROME_BROWSER_DELEGATE_H_

View File

@@ -1,502 +0,0 @@
// Copyright 2020 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 "libcef/browser/chrome/chrome_browser_host_impl.h"
#include "libcef/browser/browser_platform_delegate.h"
#include "libcef/browser/chrome/browser_platform_delegate_chrome.h"
#include "libcef/browser/thread_util.h"
#include "libcef/features/runtime_checks.h"
#include "base/logging.h"
#include "base/notreached.h"
#include "chrome/browser/printing/print_view_manager_common.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/pref_names.h"
#include "url/url_constants.h"
// static
CefRefPtr<ChromeBrowserHostImpl> ChromeBrowserHostImpl::Create(
const CefBrowserCreateParams& params) {
// Get or create the request context and profile.
CefRefPtr<CefRequestContextImpl> request_context_impl =
CefRequestContextImpl::GetOrCreateForRequestContext(
params.request_context);
CHECK(request_context_impl);
auto cef_browser_context = request_context_impl->GetBrowserContext();
CHECK(cef_browser_context);
auto profile = cef_browser_context->AsProfile();
Browser::CreateParams chrome_params =
Browser::CreateParams(profile, /*user_gesture=*/false);
// Pass |params| to cef::BrowserDelegate::Create from the Browser constructor.
chrome_params.cef_params = base::MakeRefCounted<DelegateCreateParams>(params);
// Create the Browser. This will indirectly create the ChomeBrowserDelegate.
// The same params will be used to create a new Browser if the tab is dragged
// out of the existing Browser.
auto browser = new Browser(chrome_params);
GURL url = params.url;
if (url.is_empty()) {
// Chrome will navigate to kChromeUINewTabURL by default. We want to keep
// the current CEF behavior of not navigating at all. Use a special URL that
// will be recognized in HandleNonNavigationAboutURL.
url = GURL("chrome://ignore/");
}
// Add a new tab. This will indirectly create a new tab WebContents and
// call ChromeBrowserDelegate::OnWebContentsCreated to create the associated
// ChromeBrowserHostImpl.
chrome::AddTabAt(browser, url, /*idx=*/-1, /*foreground=*/true);
// The new tab WebContents.
auto web_contents = browser->tab_strip_model()->GetActiveWebContents();
CHECK(web_contents);
// The associated ChromeBrowserHostImpl.
auto browser_host =
ChromeBrowserHostImpl::GetBrowserForContents(web_contents);
CHECK(browser_host);
browser->window()->Show();
return browser_host;
}
// static
CefRefPtr<ChromeBrowserHostImpl> ChromeBrowserHostImpl::GetBrowserForHost(
const content::RenderViewHost* host) {
REQUIRE_CHROME_RUNTIME();
auto browser = CefBrowserHostBase::GetBrowserForHost(host);
return static_cast<ChromeBrowserHostImpl*>(browser.get());
}
// static
CefRefPtr<ChromeBrowserHostImpl> ChromeBrowserHostImpl::GetBrowserForHost(
const content::RenderFrameHost* host) {
REQUIRE_CHROME_RUNTIME();
auto browser = CefBrowserHostBase::GetBrowserForHost(host);
return static_cast<ChromeBrowserHostImpl*>(browser.get());
}
// static
CefRefPtr<ChromeBrowserHostImpl> ChromeBrowserHostImpl::GetBrowserForContents(
const content::WebContents* contents) {
REQUIRE_CHROME_RUNTIME();
auto browser = CefBrowserHostBase::GetBrowserForContents(contents);
return static_cast<ChromeBrowserHostImpl*>(browser.get());
}
// static
CefRefPtr<ChromeBrowserHostImpl>
ChromeBrowserHostImpl::GetBrowserForFrameTreeNode(int frame_tree_node_id) {
REQUIRE_CHROME_RUNTIME();
auto browser =
CefBrowserHostBase::GetBrowserForFrameTreeNode(frame_tree_node_id);
return static_cast<ChromeBrowserHostImpl*>(browser.get());
}
// static
CefRefPtr<ChromeBrowserHostImpl> ChromeBrowserHostImpl::GetBrowserForFrameRoute(
int render_process_id,
int render_routing_id) {
REQUIRE_CHROME_RUNTIME();
auto browser = CefBrowserHostBase::GetBrowserForFrameRoute(render_process_id,
render_routing_id);
return static_cast<ChromeBrowserHostImpl*>(browser.get());
}
ChromeBrowserHostImpl::~ChromeBrowserHostImpl() = default;
void ChromeBrowserHostImpl::OnWebContentsDestroyed(
content::WebContents* web_contents) {
platform_delegate_->WebContentsDestroyed(web_contents);
DestroyBrowser();
}
void ChromeBrowserHostImpl::OnSetFocus(cef_focus_source_t source) {
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(CEF_UIT, base::BindOnce(&ChromeBrowserHostImpl::OnSetFocus,
this, source));
return;
}
if (contents_delegate_->OnSetFocus(source))
return;
if (browser_) {
const int tab_index = GetCurrentTabIndex();
if (tab_index != TabStripModel::kNoTab) {
chrome::SelectNumberedTab(browser_, tab_index);
}
}
}
void ChromeBrowserHostImpl::CloseBrowser(bool force_close) {
// Always do this asynchronously because TabStripModel is not re-entrant.
CEF_POST_TASK(CEF_UIT, base::BindOnce(&ChromeBrowserHostImpl::DoCloseBrowser,
this, force_close));
}
bool ChromeBrowserHostImpl::TryCloseBrowser() {
NOTIMPLEMENTED();
return false;
}
void ChromeBrowserHostImpl::SetFocus(bool focus) {
if (focus) {
OnSetFocus(FOCUS_SOURCE_SYSTEM);
}
}
CefWindowHandle ChromeBrowserHostImpl::GetWindowHandle() {
NOTIMPLEMENTED();
return kNullWindowHandle;
}
CefWindowHandle ChromeBrowserHostImpl::GetOpenerWindowHandle() {
NOTIMPLEMENTED();
return kNullWindowHandle;
}
bool ChromeBrowserHostImpl::HasView() {
// TODO(chrome-runtime): Support Views-hosted browsers.
return false;
}
double ChromeBrowserHostImpl::GetZoomLevel() {
NOTIMPLEMENTED();
return 0.0;
}
void ChromeBrowserHostImpl::SetZoomLevel(double zoomLevel) {
NOTIMPLEMENTED();
}
void ChromeBrowserHostImpl::RunFileDialog(
FileDialogMode mode,
const CefString& title,
const CefString& default_file_path,
const std::vector<CefString>& accept_filters,
int selected_accept_filter,
CefRefPtr<CefRunFileDialogCallback> callback) {
NOTIMPLEMENTED();
callback->OnFileDialogDismissed(0, {});
}
void ChromeBrowserHostImpl::Print() {
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(CEF_UIT, base::BindOnce(&ChromeBrowserHostImpl::Print, this));
return;
}
if (browser_) {
// Like chrome::Print() but specifying the WebContents.
printing::StartPrint(GetWebContents(),
/*print_renderer=*/mojo::NullAssociatedRemote(),
browser_->profile()->GetPrefs()->GetBoolean(
prefs::kPrintPreviewDisabled),
/*has_selection=*/false);
}
}
void ChromeBrowserHostImpl::PrintToPDF(
const CefString& path,
const CefPdfPrintSettings& settings,
CefRefPtr<CefPdfPrintCallback> callback) {
NOTIMPLEMENTED();
callback->OnPdfPrintFinished(CefString(), false);
}
void ChromeBrowserHostImpl::Find(int identifier,
const CefString& searchText,
bool forward,
bool matchCase,
bool findNext) {
NOTIMPLEMENTED();
}
void ChromeBrowserHostImpl::StopFinding(bool clearSelection) {
NOTIMPLEMENTED();
}
void ChromeBrowserHostImpl::ShowDevTools(const CefWindowInfo& windowInfo,
CefRefPtr<CefClient> client,
const CefBrowserSettings& settings,
const CefPoint& inspect_element_at) {
NOTIMPLEMENTED();
}
void ChromeBrowserHostImpl::CloseDevTools() {
NOTIMPLEMENTED();
}
bool ChromeBrowserHostImpl::HasDevTools() {
NOTIMPLEMENTED();
return false;
}
bool ChromeBrowserHostImpl::SendDevToolsMessage(const void* message,
size_t message_size) {
NOTIMPLEMENTED();
return false;
}
int ChromeBrowserHostImpl::ExecuteDevToolsMethod(
int message_id,
const CefString& method,
CefRefPtr<CefDictionaryValue> params) {
NOTIMPLEMENTED();
return 0;
}
CefRefPtr<CefRegistration> ChromeBrowserHostImpl::AddDevToolsMessageObserver(
CefRefPtr<CefDevToolsMessageObserver> observer) {
NOTIMPLEMENTED();
return nullptr;
}
bool ChromeBrowserHostImpl::IsWindowRenderingDisabled() {
return false;
}
void ChromeBrowserHostImpl::WasResized() {
NOTIMPLEMENTED();
}
void ChromeBrowserHostImpl::WasHidden(bool hidden) {
NOTIMPLEMENTED();
}
void ChromeBrowserHostImpl::NotifyScreenInfoChanged() {
NOTIMPLEMENTED();
}
void ChromeBrowserHostImpl::Invalidate(PaintElementType type) {
NOTIMPLEMENTED();
}
void ChromeBrowserHostImpl::SendExternalBeginFrame() {
NOTIMPLEMENTED();
}
void ChromeBrowserHostImpl::SendTouchEvent(const CefTouchEvent& event) {
NOTIMPLEMENTED();
}
void ChromeBrowserHostImpl::SendFocusEvent(bool setFocus) {
NOTIMPLEMENTED();
}
void ChromeBrowserHostImpl::SendCaptureLostEvent() {
NOTIMPLEMENTED();
}
void ChromeBrowserHostImpl::NotifyMoveOrResizeStarted() {
NOTIMPLEMENTED();
}
int ChromeBrowserHostImpl::GetWindowlessFrameRate() {
return 0;
}
void ChromeBrowserHostImpl::SetWindowlessFrameRate(int frame_rate) {}
void ChromeBrowserHostImpl::ImeSetComposition(
const CefString& text,
const std::vector<CefCompositionUnderline>& underlines,
const CefRange& replacement_range,
const CefRange& selection_range) {
NOTIMPLEMENTED();
}
void ChromeBrowserHostImpl::ImeCommitText(const CefString& text,
const CefRange& replacement_range,
int relative_cursor_pos) {
NOTIMPLEMENTED();
}
void ChromeBrowserHostImpl::ImeFinishComposingText(bool keep_selection) {
NOTIMPLEMENTED();
}
void ChromeBrowserHostImpl::ImeCancelComposition() {
NOTIMPLEMENTED();
}
void ChromeBrowserHostImpl::DragTargetDragEnter(
CefRefPtr<CefDragData> drag_data,
const CefMouseEvent& event,
DragOperationsMask allowed_ops) {
NOTIMPLEMENTED();
}
void ChromeBrowserHostImpl::DragTargetDragOver(const CefMouseEvent& event,
DragOperationsMask allowed_ops) {
NOTIMPLEMENTED();
}
void ChromeBrowserHostImpl::DragTargetDragLeave() {
NOTIMPLEMENTED();
}
void ChromeBrowserHostImpl::DragTargetDrop(const CefMouseEvent& event) {
NOTIMPLEMENTED();
}
void ChromeBrowserHostImpl::DragSourceSystemDragEnded() {
NOTIMPLEMENTED();
}
void ChromeBrowserHostImpl::DragSourceEndedAt(int x,
int y,
DragOperationsMask op) {
NOTIMPLEMENTED();
}
void ChromeBrowserHostImpl::SetAudioMuted(bool mute) {
NOTIMPLEMENTED();
}
bool ChromeBrowserHostImpl::IsAudioMuted() {
NOTIMPLEMENTED();
return false;
}
void ChromeBrowserHostImpl::SetAccessibilityState(
cef_state_t accessibility_state) {
NOTIMPLEMENTED();
}
void ChromeBrowserHostImpl::SetAutoResizeEnabled(bool enabled,
const CefSize& min_size,
const CefSize& max_size) {
NOTIMPLEMENTED();
}
CefRefPtr<CefExtension> ChromeBrowserHostImpl::GetExtension() {
return nullptr;
}
bool ChromeBrowserHostImpl::IsBackgroundHost() {
return false;
}
bool ChromeBrowserHostImpl::Navigate(const content::OpenURLParams& params) {
CEF_REQUIRE_UIT();
if (GetCurrentTabIndex() == TabStripModel::kNoTab) {
// We can't navigate via the Browser because we don't have a current tab.
return CefBrowserHostBase::Navigate(params);
}
if (browser_) {
// This is generally equivalent to calling Browser::OpenURL, except:
// 1. It doesn't trigger a call to CefRequestHandler::OnOpenURLFromTab, and
// 2. It navigates in this CefBrowserHost's WebContents instead of
// (a) creating a new WebContents, or (b) using the Browser's active
// WebContents (which may not be the same), and
// 3. There is no risk of triggering chrome's popup blocker.
NavigateParams nav_params(browser_, params.url, params.transition);
nav_params.FillNavigateParamsFromOpenURLParams(params);
// Always navigate in the current tab.
nav_params.disposition = WindowOpenDisposition::CURRENT_TAB;
nav_params.source_contents = GetWebContents();
nav_params.tabstrip_add_types = TabStripModel::ADD_NONE;
if (params.user_gesture)
nav_params.window_action = NavigateParams::SHOW_WINDOW;
::Navigate(&nav_params);
return true;
}
return false;
}
ChromeBrowserHostImpl::ChromeBrowserHostImpl(
const CefBrowserSettings& settings,
CefRefPtr<CefClient> client,
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate,
scoped_refptr<CefBrowserInfo> browser_info,
CefRefPtr<CefRequestContextImpl> request_context)
: CefBrowserHostBase(settings,
client,
std::move(platform_delegate),
browser_info,
request_context) {}
void ChromeBrowserHostImpl::Attach(Browser* browser,
content::WebContents* web_contents) {
DCHECK(browser);
DCHECK(web_contents);
platform_delegate_->WebContentsCreated(web_contents,
/*own_web_contents=*/false);
SetBrowser(browser);
contents_delegate_->ObserveWebContents(web_contents);
InitializeBrowser();
}
void ChromeBrowserHostImpl::SetBrowser(Browser* browser) {
CEF_REQUIRE_UIT();
browser_ = browser;
static_cast<CefBrowserPlatformDelegateChrome*>(platform_delegate_.get())
->set_chrome_browser(browser);
}
void ChromeBrowserHostImpl::InitializeBrowser() {
CEF_REQUIRE_UIT();
DCHECK(browser_);
// Associate the platform delegate with this browser.
platform_delegate_->BrowserCreated(this);
CefBrowserHostBase::InitializeBrowser();
// The WebContents won't be added to the Browser's TabStripModel until later
// in the current call stack. Block navigation until that time.
auto navigation_lock = browser_info_->CreateNavigationLock();
OnAfterCreated();
}
void ChromeBrowserHostImpl::DestroyBrowser() {
CEF_REQUIRE_UIT();
browser_ = nullptr;
OnBeforeClose();
OnBrowserDestroyed();
// Disassociate the platform delegate from this browser.
platform_delegate_->BrowserDestroyed(this);
CefBrowserHostBase::DestroyBrowser();
}
void ChromeBrowserHostImpl::DoCloseBrowser(bool force_close) {
CEF_REQUIRE_UIT();
if (browser_) {
// Like chrome::CloseTab() but specifying the WebContents.
const int tab_index = GetCurrentTabIndex();
if (tab_index != TabStripModel::kNoTab) {
browser_->tab_strip_model()->CloseWebContentsAt(
tab_index, TabStripModel::CLOSE_CREATE_HISTORICAL_TAB |
TabStripModel::CLOSE_USER_GESTURE);
}
}
}
int ChromeBrowserHostImpl::GetCurrentTabIndex() const {
CEF_REQUIRE_UIT();
if (browser_) {
return browser_->tab_strip_model()->GetIndexOfWebContents(GetWebContents());
}
return TabStripModel::kNoTab;
}

View File

@@ -1,174 +0,0 @@
// Copyright 2020 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_CHROME_CHROME_BROWSER_HOST_IMPL_H_
#define CEF_LIBCEF_BROWSER_CHROME_CHROME_BROWSER_HOST_IMPL_H_
#pragma once
#include <memory>
#include "libcef/browser/browser_host_base.h"
#include "libcef/browser/chrome/browser_delegate.h"
class Browser;
class ChromeBrowserDelegate;
// CefBrowser implementation for the chrome runtime. Method calls are delegated
// to the chrome Browser object or the WebContents as appropriate. See the
// ChromeBrowserDelegate documentation for additional details. All methods are
// thread-safe unless otherwise indicated.
class ChromeBrowserHostImpl : public CefBrowserHostBase {
public:
// CEF-specific parameters passed via Browser::CreateParams::cef_params and
// possibly shared by multiple Browser instances.
class DelegateCreateParams : public cef::BrowserDelegate::CreateParams {
public:
DelegateCreateParams(const CefBrowserCreateParams& create_params)
: create_params_(create_params) {}
CefBrowserCreateParams create_params_;
};
// Create a new Browser with a single tab (WebContents) and associated
// ChromeBrowserHostImpl instance.
static CefRefPtr<ChromeBrowserHostImpl> Create(
const CefBrowserCreateParams& params);
// Returns the browser associated with the specified RenderViewHost.
static CefRefPtr<ChromeBrowserHostImpl> GetBrowserForHost(
const content::RenderViewHost* host);
// Returns the browser associated with the specified RenderFrameHost.
static CefRefPtr<ChromeBrowserHostImpl> GetBrowserForHost(
const content::RenderFrameHost* host);
// Returns the browser associated with the specified WebContents.
static CefRefPtr<ChromeBrowserHostImpl> GetBrowserForContents(
const content::WebContents* contents);
// Returns the browser associated with the specified FrameTreeNode ID.
static CefRefPtr<ChromeBrowserHostImpl> GetBrowserForFrameTreeNode(
int frame_tree_node_id);
// Returns the browser associated with the specified frame routing IDs.
static CefRefPtr<ChromeBrowserHostImpl> GetBrowserForFrameRoute(
int render_process_id,
int render_routing_id);
~ChromeBrowserHostImpl() override;
// CefBrowserContentsDelegate::Observer methods:
void OnWebContentsDestroyed(content::WebContents* web_contents) override;
// CefBrowserHostBase methods called from CefFrameHostImpl:
void OnSetFocus(cef_focus_source_t source) override;
// CefBrowserHost methods:
void CloseBrowser(bool force_close) override;
bool TryCloseBrowser() override;
void SetFocus(bool focus) override;
CefWindowHandle GetWindowHandle() override;
CefWindowHandle GetOpenerWindowHandle() override;
bool HasView() override;
double GetZoomLevel() override;
void SetZoomLevel(double zoomLevel) override;
void RunFileDialog(FileDialogMode mode,
const CefString& title,
const CefString& default_file_path,
const std::vector<CefString>& accept_filters,
int selected_accept_filter,
CefRefPtr<CefRunFileDialogCallback> callback) override;
void Print() override;
void PrintToPDF(const CefString& path,
const CefPdfPrintSettings& settings,
CefRefPtr<CefPdfPrintCallback> callback) override;
void Find(int identifier,
const CefString& searchText,
bool forward,
bool matchCase,
bool findNext) override;
void StopFinding(bool clearSelection) override;
void ShowDevTools(const CefWindowInfo& windowInfo,
CefRefPtr<CefClient> client,
const CefBrowserSettings& settings,
const CefPoint& inspect_element_at) override;
void CloseDevTools() override;
bool HasDevTools() override;
bool SendDevToolsMessage(const void* message, size_t message_size) override;
int ExecuteDevToolsMethod(int message_id,
const CefString& method,
CefRefPtr<CefDictionaryValue> params) override;
CefRefPtr<CefRegistration> AddDevToolsMessageObserver(
CefRefPtr<CefDevToolsMessageObserver> observer) override;
bool IsWindowRenderingDisabled() override;
void WasResized() override;
void WasHidden(bool hidden) override;
void NotifyScreenInfoChanged() override;
void Invalidate(PaintElementType type) override;
void SendExternalBeginFrame() override;
void SendTouchEvent(const CefTouchEvent& event) override;
void SendFocusEvent(bool setFocus) override;
void SendCaptureLostEvent() override;
void NotifyMoveOrResizeStarted() override;
int GetWindowlessFrameRate() override;
void SetWindowlessFrameRate(int frame_rate) override;
void ImeSetComposition(const CefString& text,
const std::vector<CefCompositionUnderline>& underlines,
const CefRange& replacement_range,
const CefRange& selection_range) override;
void ImeCommitText(const CefString& text,
const CefRange& replacement_range,
int relative_cursor_pos) override;
void ImeFinishComposingText(bool keep_selection) override;
void ImeCancelComposition() override;
void DragTargetDragEnter(CefRefPtr<CefDragData> drag_data,
const CefMouseEvent& event,
DragOperationsMask allowed_ops) override;
void DragTargetDragOver(const CefMouseEvent& event,
DragOperationsMask allowed_ops) override;
void DragTargetDragLeave() override;
void DragTargetDrop(const CefMouseEvent& event) override;
void DragSourceSystemDragEnded() override;
void DragSourceEndedAt(int x, int y, DragOperationsMask op) override;
void SetAudioMuted(bool mute) override;
bool IsAudioMuted() override;
void SetAccessibilityState(cef_state_t accessibility_state) override;
void SetAutoResizeEnabled(bool enabled,
const CefSize& min_size,
const CefSize& max_size) override;
CefRefPtr<CefExtension> GetExtension() override;
bool IsBackgroundHost() override;
protected:
bool Navigate(const content::OpenURLParams& params) override;
private:
friend class ChromeBrowserDelegate;
ChromeBrowserHostImpl(
const CefBrowserSettings& settings,
CefRefPtr<CefClient> client,
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate,
scoped_refptr<CefBrowserInfo> browser_info,
CefRefPtr<CefRequestContextImpl> request_context);
// Called from ChromeBrowserDelegate::SetAsDelegate when this object is first
// created. Must be called on the UI thread.
void Attach(Browser* browser, content::WebContents* web_contents);
// Called from ChromeBrowserDelegate::SetAsDelegate when this object changes
// Browser ownership (e.g. dragging between windows). The old Browser will be
// cleared before the new Browser is added. Must be called on the UI thread.
void SetBrowser(Browser* browser);
// CefBrowserHostBase methods:
void InitializeBrowser() override;
void DestroyBrowser() override;
void DoCloseBrowser(bool force_close);
// Returns the current tab index for the associated WebContents, or
// TabStripModel::kNoTab if not found.
int GetCurrentTabIndex() const;
Browser* browser_ = nullptr;
};
#endif // CEF_LIBCEF_BROWSER_CHROME_CHROME_BROWSER_HOST_IMPL_H_

View File

@@ -21,7 +21,7 @@ void ChromeBrowserMainExtraPartsCef::PostProfileInit() {
CefRequestContextImpl::CreateGlobalRequestContext(settings);
}
void ChromeBrowserMainExtraPartsCef::PreMainMessageLoopRun() {
void ChromeBrowserMainExtraPartsCef::PostMainMessageLoopRun() {
background_task_runner_ = base::CreateSingleThreadTaskRunner(
{base::ThreadPool(), base::TaskPriority::BEST_EFFORT,
base::TaskShutdownBehavior::BLOCK_SHUTDOWN, base::MayBlock()});

View File

@@ -37,7 +37,7 @@ class ChromeBrowserMainExtraPartsCef : public ChromeBrowserMainExtraParts {
private:
// ChromeBrowserMainExtraParts overrides.
void PostProfileInit() override;
void PreMainMessageLoopRun() override;
void PostMainMessageLoopRun() override;
CefRefPtr<CefRequestContextImpl> global_request_context_;

View File

@@ -5,48 +5,14 @@
#include "libcef/browser/chrome/chrome_content_browser_client_cef.h"
#include "libcef/browser/browser_info_manager.h"
#include "libcef/browser/browser_message_filter.h"
#include "libcef/browser/chrome/chrome_browser_main_extra_parts_cef.h"
#include "libcef/browser/net/throttle_handler.h"
#include "libcef/browser/net_service/cookie_manager_impl.h"
#include "libcef/browser/net_service/login_delegate.h"
#include "libcef/browser/net_service/proxy_url_loader_factory.h"
#include "libcef/browser/net_service/resource_request_handler_wrapper.h"
#include "libcef/common/app_manager.h"
#include "libcef/common/cef_switches.h"
#include "libcef/common/command_line_impl.h"
#include "base/command_line.h"
#include "base/path_service.h"
#include "chrome/browser/chrome_browser_main.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "content/public/browser/navigation_throttle.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/common/content_switches.h"
#include "third_party/blink/public/mojom/loader/resource_load_info.mojom-shared.h"
namespace {
void HandleExternalProtocolHelper(
ChromeContentBrowserClientCef* self,
content::WebContents::OnceGetter web_contents_getter,
content::NavigationUIData* navigation_data,
const network::ResourceRequest& resource_request) {
// Match the logic of the original call in
// NavigationURLLoaderImpl::PrepareForNonInterceptedRequest.
self->HandleExternalProtocol(
resource_request.url, std::move(web_contents_getter),
content::ChildProcessHost::kInvalidUniqueID, navigation_data,
resource_request.resource_type ==
static_cast<int>(blink::mojom::ResourceType::kMainFrame),
static_cast<ui::PageTransition>(resource_request.transition_type),
resource_request.has_user_gesture, resource_request.request_initiator,
nullptr);
}
} // namespace
ChromeContentBrowserClientCef::ChromeContentBrowserClientCef(
StartupData* startup_data)
@@ -60,8 +26,7 @@ ChromeContentBrowserClientCef::CreateBrowserMainParts(
ChromeContentBrowserClient::CreateBrowserMainParts(parameters);
browser_main_parts_ = new ChromeBrowserMainExtraPartsCef;
static_cast<ChromeBrowserMainParts*>(main_parts.get())
->AddParts(
base::WrapUnique<ChromeBrowserMainExtraParts>(browser_main_parts_));
->AddParts(browser_main_parts_);
return main_parts;
}
@@ -80,200 +45,6 @@ void ChromeContentBrowserClientCef::AppendExtraCommandLineSwitches(
if (base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) {
command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
}
const base::CommandLine* browser_cmd = base::CommandLine::ForCurrentProcess();
const std::string& process_type =
command_line->GetSwitchValueASCII(switches::kProcessType);
if (process_type == switches::kRendererProcess) {
// Propagate the following switches to the renderer command line (along with
// any associated values) if present in the browser command line.
static const char* const kSwitchNames[] = {
switches::kUncaughtExceptionStackSize,
};
command_line->CopySwitchesFrom(*browser_cmd, kSwitchNames,
base::size(kSwitchNames));
}
CefRefPtr<CefApp> app = CefAppManager::Get()->GetApplication();
if (app.get()) {
CefRefPtr<CefBrowserProcessHandler> handler =
app->GetBrowserProcessHandler();
if (handler.get()) {
CefRefPtr<CefCommandLineImpl> commandLinePtr(
new CefCommandLineImpl(command_line, false, false));
handler->OnBeforeChildProcessLaunch(commandLinePtr.get());
commandLinePtr->Detach(nullptr);
}
}
}
void ChromeContentBrowserClientCef::RenderProcessWillLaunch(
content::RenderProcessHost* host) {
const int id = host->GetID();
host->AddFilter(new CefBrowserMessageFilter(id));
// If the renderer process crashes then the host may already have
// CefBrowserInfoManager as an observer. Try to remove it first before adding
// to avoid DCHECKs.
host->RemoveObserver(CefBrowserInfoManager::GetInstance());
host->AddObserver(CefBrowserInfoManager::GetInstance());
}
bool ChromeContentBrowserClientCef::CanCreateWindow(
content::RenderFrameHost* opener,
const GURL& opener_url,
const GURL& opener_top_level_frame_url,
const url::Origin& source_origin,
content::mojom::WindowContainerType container_type,
const GURL& target_url,
const content::Referrer& referrer,
const std::string& frame_name,
WindowOpenDisposition disposition,
const blink::mojom::WindowFeatures& features,
bool user_gesture,
bool opener_suppressed,
bool* no_javascript_access) {
// The chrome layer has popup blocker, extensions, etc.
if (!ChromeContentBrowserClient::CanCreateWindow(
opener, opener_url, opener_top_level_frame_url, source_origin,
container_type, target_url, referrer, frame_name, disposition,
features, user_gesture, opener_suppressed, no_javascript_access)) {
return false;
}
return CefBrowserInfoManager::GetInstance()->CanCreateWindow(
opener, target_url, referrer, frame_name, disposition, features,
user_gesture, opener_suppressed, no_javascript_access);
}
bool ChromeContentBrowserClientCef::WillCreateURLLoaderFactory(
content::BrowserContext* browser_context,
content::RenderFrameHost* frame,
int render_process_id,
URLLoaderFactoryType type,
const url::Origin& request_initiator,
base::Optional<int64_t> navigation_id,
base::UkmSourceId ukm_source_id,
mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver,
mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>*
header_client,
bool* bypass_redirect_checks,
bool* disable_secure_dns,
network::mojom::URLLoaderFactoryOverridePtr* factory_override) {
bool use_proxy = ChromeContentBrowserClient::WillCreateURLLoaderFactory(
browser_context, frame, render_process_id, type, request_initiator,
navigation_id, ukm_source_id, factory_receiver, header_client,
bypass_redirect_checks, disable_secure_dns, factory_override);
if (use_proxy) {
// The chrome layer will handle the request.
return use_proxy;
}
auto request_handler = net_service::CreateInterceptedRequestHandler(
browser_context, frame, render_process_id,
type == URLLoaderFactoryType::kNavigation,
type == URLLoaderFactoryType::kDownload, request_initiator);
net_service::ProxyURLLoaderFactory::CreateProxy(
browser_context, factory_receiver, header_client,
std::move(request_handler));
return true;
}
bool ChromeContentBrowserClientCef::HandleExternalProtocol(
const GURL& url,
content::WebContents::OnceGetter web_contents_getter,
int child_id,
content::NavigationUIData* navigation_data,
bool is_main_frame,
ui::PageTransition page_transition,
bool has_user_gesture,
const base::Optional<url::Origin>& initiating_origin,
mojo::PendingRemote<network::mojom::URLLoaderFactory>* out_factory) {
// |out_factory| will be non-nullptr when this method is initially called
// from NavigationURLLoaderImpl::PrepareForNonInterceptedRequest.
if (out_factory) {
// Let the other HandleExternalProtocol variant handle the request.
return false;
}
// The request was unhandled and we've recieved a callback from
// HandleExternalProtocolHelper. Forward to the chrome layer for default
// handling.
return ChromeContentBrowserClient::HandleExternalProtocol(
url, std::move(web_contents_getter), child_id, navigation_data,
is_main_frame, page_transition, has_user_gesture, initiating_origin,
nullptr);
}
bool ChromeContentBrowserClientCef::HandleExternalProtocol(
content::WebContents::Getter web_contents_getter,
int frame_tree_node_id,
content::NavigationUIData* navigation_data,
const network::ResourceRequest& resource_request,
mojo::PendingRemote<network::mojom::URLLoaderFactory>* out_factory) {
mojo::PendingReceiver<network::mojom::URLLoaderFactory> receiver =
out_factory->InitWithNewPipeAndPassReceiver();
// HandleExternalProtocolHelper may be called if nothing handles the request.
auto request_handler = net_service::CreateInterceptedRequestHandler(
web_contents_getter, frame_tree_node_id, resource_request,
base::Bind(HandleExternalProtocolHelper, base::Unretained(this),
web_contents_getter, navigation_data, resource_request));
net_service::ProxyURLLoaderFactory::CreateProxy(
web_contents_getter, std::move(receiver), std::move(request_handler));
return true;
}
std::vector<std::unique_ptr<content::NavigationThrottle>>
ChromeContentBrowserClientCef::CreateThrottlesForNavigation(
content::NavigationHandle* navigation_handle) {
auto throttles = ChromeContentBrowserClient::CreateThrottlesForNavigation(
navigation_handle);
throttle::CreateThrottlesForNavigation(navigation_handle, throttles);
return throttles;
}
void ChromeContentBrowserClientCef::ConfigureNetworkContextParams(
content::BrowserContext* context,
bool in_memory,
const base::FilePath& relative_partition_path,
network::mojom::NetworkContextParams* network_context_params,
network::mojom::CertVerifierCreationParams* cert_verifier_creation_params) {
ChromeContentBrowserClient::ConfigureNetworkContextParams(
context, in_memory, relative_partition_path, network_context_params,
cert_verifier_creation_params);
auto cef_context = CefBrowserContext::FromBrowserContext(context);
network_context_params->cookieable_schemes =
cef_context ? cef_context->GetCookieableSchemes()
: CefCookieManagerImpl::GetGlobalCookieableSchemes();
}
std::unique_ptr<content::LoginDelegate>
ChromeContentBrowserClientCef::CreateLoginDelegate(
const net::AuthChallengeInfo& auth_info,
content::WebContents* web_contents,
const content::GlobalRequestID& request_id,
bool is_request_for_main_frame,
const GURL& url,
scoped_refptr<net::HttpResponseHeaders> response_headers,
bool first_auth_attempt,
LoginAuthRequiredCallback auth_required_callback) {
// |web_contents| is nullptr for CefURLRequests without an associated frame.
if (!web_contents || base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableChromeLoginPrompt)) {
// Delegate auth callbacks to GetAuthCredentials.
return std::make_unique<net_service::LoginDelegate>(
auth_info, web_contents, request_id, url,
std::move(auth_required_callback));
}
return ChromeContentBrowserClient::CreateLoginDelegate(
auth_info, web_contents, request_id, is_request_for_main_frame, url,
response_headers, first_auth_attempt, std::move(auth_required_callback));
}
CefRefPtr<CefRequestContextImpl>

View File

@@ -15,7 +15,7 @@
class ChromeBrowserMainExtraPartsCef;
// CEF override of ChromeContentBrowserClient.
// CEF override of ChromeContentBrowserClient
class ChromeContentBrowserClientCef : public ChromeContentBrowserClient {
public:
explicit ChromeContentBrowserClientCef(StartupData* startup_data = nullptr);
@@ -26,71 +26,6 @@ class ChromeContentBrowserClientCef : public ChromeContentBrowserClient {
const content::MainFunctionParams& parameters) override;
void AppendExtraCommandLineSwitches(base::CommandLine* command_line,
int child_process_id) override;
void RenderProcessWillLaunch(content::RenderProcessHost* host) override;
bool CanCreateWindow(content::RenderFrameHost* opener,
const GURL& opener_url,
const GURL& opener_top_level_frame_url,
const url::Origin& source_origin,
content::mojom::WindowContainerType container_type,
const GURL& target_url,
const content::Referrer& referrer,
const std::string& frame_name,
WindowOpenDisposition disposition,
const blink::mojom::WindowFeatures& features,
bool user_gesture,
bool opener_suppressed,
bool* no_javascript_access) override;
bool WillCreateURLLoaderFactory(
content::BrowserContext* browser_context,
content::RenderFrameHost* frame,
int render_process_id,
URLLoaderFactoryType type,
const url::Origin& request_initiator,
base::Optional<int64_t> navigation_id,
base::UkmSourceId ukm_source_id,
mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver,
mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>*
header_client,
bool* bypass_redirect_checks,
bool* disable_secure_dns,
network::mojom::URLLoaderFactoryOverridePtr* factory_override) override;
bool HandleExternalProtocol(
const GURL& url,
content::WebContents::OnceGetter web_contents_getter,
int child_id,
content::NavigationUIData* navigation_data,
bool is_main_frame,
ui::PageTransition page_transition,
bool has_user_gesture,
const base::Optional<url::Origin>& initiating_origin,
mojo::PendingRemote<network::mojom::URLLoaderFactory>* out_factory)
override;
bool HandleExternalProtocol(
content::WebContents::Getter web_contents_getter,
int frame_tree_node_id,
content::NavigationUIData* navigation_data,
const network::ResourceRequest& request,
mojo::PendingRemote<network::mojom::URLLoaderFactory>* out_factory)
override;
std::vector<std::unique_ptr<content::NavigationThrottle>>
CreateThrottlesForNavigation(
content::NavigationHandle* navigation_handle) override;
void ConfigureNetworkContextParams(
content::BrowserContext* context,
bool in_memory,
const base::FilePath& relative_partition_path,
network::mojom::NetworkContextParams* network_context_params,
network::mojom::CertVerifierCreationParams* cert_verifier_creation_params)
override;
std::unique_ptr<content::LoginDelegate> CreateLoginDelegate(
const net::AuthChallengeInfo& auth_info,
content::WebContents* web_contents,
const content::GlobalRequestID& request_id,
bool is_request_for_main_frame,
const GURL& url,
scoped_refptr<net::HttpResponseHeaders> response_headers,
bool first_auth_attempt,
LoginAuthRequiredCallback auth_required_callback) override;
CefRefPtr<CefRequestContextImpl> request_context() const;

View File

@@ -5,11 +5,11 @@
#include "build/build_config.h"
#if defined(OS_MAC)
#if defined(OS_MACOSX)
#include "chrome/app/chrome_crash_reporter_client.h"
// Required due to https://crrev.com/1c9f89a06f
void ChromeCrashReporterClient::Create() {}
#endif // defined(OS_MAC)
#endif // defined(OS_MACOSX)

View File

@@ -11,8 +11,8 @@
#include "base/bind.h"
#include "base/files/file_util.h"
#include "base/message_loop/message_loop_current.h"
#include "base/run_loop.h"
#include "base/task/current_thread.h"
#include "base/threading/thread_restrictions.h"
#include "components/network_session_configurator/common/network_switches.h"
#include "content/public/browser/notification_service.h"
@@ -294,7 +294,7 @@ void CefSetOSModalLoop(bool osModalLoop) {
}
if (CEF_CURRENTLY_ON_UIT())
base::CurrentThread::Get()->set_os_modal_loop(osModalLoop);
base::MessageLoopCurrent::Get()->set_os_modal_loop(osModalLoop);
else
CEF_POST_TASK(CEF_UIT, base::Bind(CefSetOSModalLoop, osModalLoop));
#endif // defined(OS_WIN)

View File

@@ -17,11 +17,14 @@
#include "base/threading/platform_thread.h"
#include "third_party/skia/include/core/SkColor.h"
class CefBrowserHostImpl;
class CefBrowserInfoManager;
class CefTraceSubscriber;
class CefContext {
public:
typedef std::list<CefRefPtr<CefBrowserHostImpl>> BrowserList;
// Interface to implement for observers that wish to be informed of changes
// to the context. All methods will be called on the UI thread.
class Observer {

View File

@@ -4,7 +4,7 @@
#include "libcef/browser/devtools/devtools_file_manager.h"
#include "libcef/browser/alloy/alloy_browser_host_impl.h"
#include "libcef/browser/browser_host_impl.h"
#include "base/bind.h"
#include "base/callback.h"
@@ -39,9 +39,8 @@ void AppendToFile(const base::FilePath& path, const std::string& content) {
} // namespace
CefDevToolsFileManager::CefDevToolsFileManager(
AlloyBrowserHostImpl* browser_impl,
PrefService* prefs)
CefDevToolsFileManager::CefDevToolsFileManager(CefBrowserHostImpl* browser_impl,
PrefService* prefs)
: browser_impl_(browser_impl),
prefs_(prefs),
file_task_runner_(base::CreateSequencedTaskRunner(

View File

@@ -18,7 +18,7 @@ class SequencedTaskRunner;
class Value;
} // namespace base
class AlloyBrowserHostImpl;
class CefBrowserHostImpl;
class PrefService;
// File management helper for DevTools.
@@ -26,8 +26,7 @@ class PrefService;
// chrome/browser/devtools/devtools_file_helper.cc.
class CefDevToolsFileManager {
public:
CefDevToolsFileManager(AlloyBrowserHostImpl* browser_impl,
PrefService* prefs);
CefDevToolsFileManager(CefBrowserHostImpl* browser_impl, PrefService* prefs);
void SaveToFile(const std::string& url,
const std::string& content,
@@ -69,7 +68,7 @@ class CefDevToolsFileManager {
const base::Value* arg3);
// Guaranteed to outlive this object.
AlloyBrowserHostImpl* browser_impl_;
CefBrowserHostImpl* browser_impl_;
PrefService* prefs_;
typedef std::map<std::string, base::FilePath> PathsMap;

View File

@@ -25,7 +25,6 @@
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/post_task.h"
@@ -54,7 +53,6 @@
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/cpp/simple_url_loader_stream_consumer.h"
#include "services/network/public/cpp/wrapper_shared_url_loader_factory.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "storage/browser/file_system/native_file_util.h"
@@ -236,7 +234,7 @@ const size_t kMaxMessageChunkSize = IPC::Channel::kMaximumMessageSize / 4;
// static
CefDevToolsFrontend* CefDevToolsFrontend::Show(
AlloyBrowserHostImpl* inspected_browser,
CefBrowserHostImpl* inspected_browser,
const CefWindowInfo& windowInfo,
CefRefPtr<CefClient> client,
const CefBrowserSettings& settings,
@@ -250,7 +248,7 @@ CefDevToolsFrontend* CefDevToolsFrontend::Show(
new_settings.background_color = SK_ColorWHITE;
}
CefBrowserCreateParams create_params;
CefBrowserHostImpl::CreateParams create_params;
if (!inspected_browser->IsViewsHosted())
create_params.window_info.reset(new CefWindowInfo(windowInfo));
create_params.client = client;
@@ -259,15 +257,15 @@ CefDevToolsFrontend* CefDevToolsFrontend::Show(
create_params.request_context = inspected_browser->GetRequestContext();
create_params.extra_info = inspected_browser->browser_info()->extra_info();
CefRefPtr<AlloyBrowserHostImpl> frontend_browser =
AlloyBrowserHostImpl::Create(create_params);
CefRefPtr<CefBrowserHostImpl> frontend_browser =
CefBrowserHostImpl::Create(create_params);
content::WebContents* inspected_contents = inspected_browser->web_contents();
// CefDevToolsFrontend will delete itself when the frontend WebContents is
// destroyed.
CefDevToolsFrontend* devtools_frontend = new CefDevToolsFrontend(
static_cast<AlloyBrowserHostImpl*>(frontend_browser.get()),
static_cast<CefBrowserHostImpl*>(frontend_browser.get()),
inspected_contents, inspect_element_at,
std::move(frontend_destroyed_callback));
@@ -294,12 +292,12 @@ void CefDevToolsFrontend::InspectElementAt(int x, int y) {
void CefDevToolsFrontend::Close() {
base::PostTask(FROM_HERE, {content::BrowserThread::UI},
base::Bind(&AlloyBrowserHostImpl::CloseBrowser,
base::Bind(&CefBrowserHostImpl::CloseBrowser,
frontend_browser_.get(), true));
}
CefDevToolsFrontend::CefDevToolsFrontend(
AlloyBrowserHostImpl* frontend_browser,
CefBrowserHostImpl* frontend_browser,
content::WebContents* inspected_contents,
const CefPoint& inspect_element_at,
base::OnceClosure frontend_destroyed_callback)
@@ -446,15 +444,15 @@ void CefDevToolsFrontend::HandleMessageFromDevToolsFrontend(
resource_request->site_for_cookies = net::SiteForCookies::FromUrl(gurl);
resource_request->headers.AddHeadersFromString(headers);
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory;
std::unique_ptr<network::mojom::URLLoaderFactory> file_url_loader_factory;
scoped_refptr<network::SharedURLLoaderFactory> network_url_loader_factory;
std::unique_ptr<network::mojom::URLLoaderFactory> webui_url_loader_factory;
network::mojom::URLLoaderFactory* url_loader_factory;
if (gurl.SchemeIsFile()) {
mojo::PendingRemote<network::mojom::URLLoaderFactory> pending_remote =
content::CreateFileURLLoaderFactory(
base::FilePath() /* profile_path */,
nullptr /* shared_cors_origin_access_list */);
url_loader_factory = network::SharedURLLoaderFactory::Create(
std::make_unique<network::WrapperPendingSharedURLLoaderFactory>(
std::move(pending_remote)));
file_url_loader_factory = content::CreateFileURLLoaderFactory(
base::FilePath() /* profile_path */,
nullptr /* shared_cors_origin_access_list */);
url_loader_factory = file_url_loader_factory.get();
} else if (content::HasWebUIScheme(gurl)) {
base::DictionaryValue response;
response.SetInteger("statusCode", 403);
@@ -463,13 +461,15 @@ void CefDevToolsFrontend::HandleMessageFromDevToolsFrontend(
} else {
auto* partition = content::BrowserContext::GetStoragePartitionForSite(
web_contents()->GetBrowserContext(), gurl);
url_loader_factory = partition->GetURLLoaderFactoryForBrowserProcess();
network_url_loader_factory =
partition->GetURLLoaderFactoryForBrowserProcess();
url_loader_factory = network_url_loader_factory.get();
}
auto simple_url_loader = network::SimpleURLLoader::Create(
std::move(resource_request), traffic_annotation);
auto resource_loader = std::make_unique<NetworkResourceLoader>(
stream_id, this, std::move(simple_url_loader), url_loader_factory.get(),
stream_id, this, std::move(simple_url_loader), url_loader_factory,
request_id);
loaders_.insert(std::move(resource_loader));
return;
@@ -538,7 +538,7 @@ void CefDevToolsFrontend::DispatchProtocolMessage(
if (ProtocolLoggingEnabled()) {
// Quick check to avoid parsing the JSON object. Events begin with a
// "method" value whereas method results begin with an "id" value.
LogProtocolMessage(base::StartsWith(str_message, "{\"method\":")
LogProtocolMessage(str_message.starts_with("{\"method\":")
? ProtocolMessageType::EVENT
: ProtocolMessageType::RESULT,
str_message);

View File

@@ -7,7 +7,7 @@
#include <memory>
#include "libcef/browser/alloy/alloy_browser_host_impl.h"
#include "libcef/browser/browser_host_impl.h"
#include "libcef/browser/devtools/devtools_file_manager.h"
#include "base/compiler_specific.h"
@@ -42,7 +42,7 @@ class CefDevToolsFrontend : public content::WebContentsObserver,
public content::DevToolsAgentHostClient {
public:
static CefDevToolsFrontend* Show(
AlloyBrowserHostImpl* inspected_browser,
CefBrowserHostImpl* inspected_browser,
const CefWindowInfo& windowInfo,
CefRefPtr<CefClient> client,
const CefBrowserSettings& settings,
@@ -60,7 +60,7 @@ class CefDevToolsFrontend : public content::WebContentsObserver,
const base::Value* arg3);
private:
CefDevToolsFrontend(AlloyBrowserHostImpl* frontend_browser,
CefDevToolsFrontend(CefBrowserHostImpl* frontend_browser,
content::WebContents* inspected_contents,
const CefPoint& inspect_element_at,
base::OnceClosure destroyed_callback);
@@ -87,7 +87,7 @@ class CefDevToolsFrontend : public content::WebContentsObserver,
PrefService* GetPrefs() const;
CefRefPtr<AlloyBrowserHostImpl> frontend_browser_;
CefRefPtr<CefBrowserHostImpl> frontend_browser_;
content::WebContents* inspected_contents_;
scoped_refptr<content::DevToolsAgentHost> agent_host_;
CefPoint inspect_element_at_;

View File

@@ -31,7 +31,7 @@ class CefDevToolsRegistrationImpl : public CefRegistration,
controller_->RemoveObserver(this);
}
void Initialize(AlloyBrowserHostImpl* browser,
void Initialize(CefBrowserHostImpl* browser,
base::WeakPtr<CefDevToolsController> controller) {
CEF_REQUIRE_UIT();
DCHECK(browser && controller);
@@ -83,7 +83,7 @@ class CefDevToolsRegistrationImpl : public CefRegistration,
CefRefPtr<CefDevToolsMessageObserver> observer_;
AlloyBrowserHostImpl* browser_ = nullptr;
CefBrowserHostImpl* browser_ = nullptr;
base::WeakPtr<CefDevToolsController> controller_;
IMPLEMENT_REFCOUNTING_DELETE_ON_UIT(CefDevToolsRegistrationImpl);
@@ -92,7 +92,7 @@ class CefDevToolsRegistrationImpl : public CefRegistration,
} // namespace
CefDevToolsManager::CefDevToolsManager(AlloyBrowserHostImpl* inspected_browser)
CefDevToolsManager::CefDevToolsManager(CefBrowserHostImpl* inspected_browser)
: inspected_browser_(inspected_browser), weak_ptr_factory_(this) {
CEF_REQUIRE_UIT();
}

View File

@@ -10,7 +10,7 @@
#include "base/memory/weak_ptr.h"
class AlloyBrowserHostImpl;
class CefBrowserHostImpl;
class CefDevToolsController;
class CefDevToolsFrontend;
@@ -23,7 +23,7 @@ class WebContents;
class CefDevToolsManager {
public:
// |inspected_browser| will outlive this object.
explicit CefDevToolsManager(AlloyBrowserHostImpl* inspected_browser);
explicit CefDevToolsManager(CefBrowserHostImpl* inspected_browser);
~CefDevToolsManager();
// See CefBrowserHost methods of the same name for documentation.
@@ -52,7 +52,7 @@ class CefDevToolsManager {
bool EnsureController();
AlloyBrowserHostImpl* const inspected_browser_;
CefBrowserHostImpl* const inspected_browser_;
// CefDevToolsFrontend will delete itself when the frontend WebContents is
// destroyed.

View File

@@ -8,6 +8,8 @@
#include <vector>
#include "libcef/browser/browser_host_impl.h"
#include "base/atomicops.h"
#include "base/bind.h"
#include "base/command_line.h"

View File

@@ -5,7 +5,6 @@
#include "libcef/browser/devtools/devtools_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
namespace devtools_util {
@@ -25,7 +24,7 @@ bool ParseEvent(const base::StringPiece& message,
static const char kMethodEnd[] = "\"";
static const char kParamsStart[] = ",\"params\":";
if (!base::StartsWith(message, kMethodStart))
if (!message.starts_with(kMethodStart))
return false;
const size_t method_start = sizeof(kMethodStart) - 1;
@@ -42,7 +41,7 @@ bool ParseEvent(const base::StringPiece& message,
params = base::StringPiece();
} else {
const base::StringPiece& remainder = message.substr(remainder_start);
if (base::StartsWith(remainder, kParamsStart)) {
if (remainder.starts_with(kParamsStart)) {
// Stop immediately before the message closing bracket.
remainder_start += sizeof(kParamsStart) - 1;
params =
@@ -72,7 +71,7 @@ bool ParseResult(const base::StringPiece& message,
static const char kResultStart[] = "\"result\":";
static const char kErrorStart[] = "\"error\":";
if (!base::StartsWith(message, kIdStart))
if (!message.starts_with(kIdStart))
return false;
const size_t id_start = sizeof(kIdStart) - 1;
@@ -85,13 +84,13 @@ bool ParseResult(const base::StringPiece& message,
size_t remainder_start = id_end + sizeof(kIdEnd) - 1;
const base::StringPiece& remainder = message.substr(remainder_start);
if (base::StartsWith(remainder, kResultStart)) {
if (remainder.starts_with(kResultStart)) {
// Stop immediately before the message closing bracket.
remainder_start += sizeof(kResultStart) - 1;
result =
message.substr(remainder_start, message.size() - 1 - remainder_start);
success = true;
} else if (base::StartsWith(remainder, kErrorStart)) {
} else if (remainder.starts_with(kErrorStart)) {
// Stop immediately before the message closing bracket.
remainder_start += sizeof(kErrorStart) - 1;
result =

View File

@@ -5,7 +5,6 @@
#include "libcef/browser/download_manager_delegate.h"
#include "include/cef_download_handler.h"
#include "libcef/browser/alloy/alloy_browser_host_impl.h"
#include "libcef/browser/context.h"
#include "libcef/browser/download_item_impl.h"
#include "libcef/browser/thread_util.h"
@@ -31,7 +30,7 @@ namespace {
// Helper function to retrieve the CefDownloadHandler.
CefRefPtr<CefDownloadHandler> GetDownloadHandler(
CefRefPtr<AlloyBrowserHostImpl> browser) {
CefRefPtr<CefBrowserHostImpl> browser) {
CefRefPtr<CefClient> client = browser->GetClient();
if (client.get())
return client->GetDownloadHandler();
@@ -125,8 +124,8 @@ class CefBeforeDownloadCallbackImpl : public CefBeforeDownloadCallback {
if (show_dialog) {
WebContents* web_contents =
content::DownloadItemUtils::GetWebContents(item);
CefRefPtr<AlloyBrowserHostImpl> browser =
AlloyBrowserHostImpl::GetBrowserForContents(web_contents);
CefRefPtr<CefBrowserHostImpl> browser =
CefBrowserHostImpl::GetBrowserForContents(web_contents);
if (browser.get()) {
handled = true;
@@ -276,7 +275,7 @@ CefDownloadManagerDelegate::~CefDownloadManagerDelegate() {
}
void CefDownloadManagerDelegate::OnDownloadUpdated(DownloadItem* download) {
CefRefPtr<AlloyBrowserHostImpl> browser = GetBrowser(download);
CefRefPtr<CefBrowserHostImpl> browser = GetBrowser(download);
CefRefPtr<CefDownloadHandler> handler;
if (browser.get())
handler = GetDownloadHandler(browser);
@@ -296,7 +295,7 @@ void CefDownloadManagerDelegate::OnDownloadUpdated(DownloadItem* download) {
void CefDownloadManagerDelegate::OnDownloadDestroyed(DownloadItem* item) {
item->RemoveObserver(this);
AlloyBrowserHostImpl* browser = nullptr;
CefBrowserHostImpl* browser = nullptr;
ItemBrowserMap::iterator it = item_browser_map_.find(item);
DCHECK(it != item_browser_map_.end());
@@ -326,7 +325,7 @@ void CefDownloadManagerDelegate::OnDownloadCreated(DownloadManager* manager,
DownloadItem* item) {
// This callback may arrive after DetermineDownloadTarget, so we allow
// association from either method.
CefRefPtr<AlloyBrowserHostImpl> browser = GetOrAssociateBrowser(item);
CefRefPtr<CefBrowserHostImpl> browser = GetOrAssociateBrowser(item);
if (!browser) {
// If the download is rejected (e.g. ALT+click on an invalid protocol link)
// then an "interrupted" download will be started via DownloadManagerImpl::
@@ -365,7 +364,7 @@ bool CefDownloadManagerDelegate::DetermineDownloadTarget(
// This callback may arrive before OnDownloadCreated, so we allow association
// from either method.
CefRefPtr<AlloyBrowserHostImpl> browser = GetOrAssociateBrowser(item);
CefRefPtr<CefBrowserHostImpl> browser = GetOrAssociateBrowser(item);
CefRefPtr<CefDownloadHandler> handler;
if (browser.get())
handler = GetDownloadHandler(browser);
@@ -406,7 +405,7 @@ std::string CefDownloadManagerDelegate::ApplicationClientIdForFileScanning() {
}
void CefDownloadManagerDelegate::OnBrowserDestroyed(
CefBrowserHostBase* browser) {
CefBrowserHostImpl* browser) {
ItemBrowserMap::iterator it = item_browser_map_.begin();
for (; it != item_browser_map_.end(); ++it) {
if (it->second == browser) {
@@ -418,17 +417,17 @@ void CefDownloadManagerDelegate::OnBrowserDestroyed(
}
}
AlloyBrowserHostImpl* CefDownloadManagerDelegate::GetOrAssociateBrowser(
CefBrowserHostImpl* CefDownloadManagerDelegate::GetOrAssociateBrowser(
download::DownloadItem* item) {
ItemBrowserMap::const_iterator it = item_browser_map_.find(item);
if (it != item_browser_map_.end())
return it->second;
AlloyBrowserHostImpl* browser = nullptr;
CefBrowserHostImpl* browser = nullptr;
content::WebContents* contents =
content::DownloadItemUtils::GetWebContents(item);
if (contents) {
browser = AlloyBrowserHostImpl::GetBrowserForContents(contents).get();
browser = CefBrowserHostImpl::GetBrowserForContents(contents).get();
DCHECK(browser);
}
if (!browser)
@@ -446,8 +445,7 @@ AlloyBrowserHostImpl* CefDownloadManagerDelegate::GetOrAssociateBrowser(
return browser;
}
AlloyBrowserHostImpl* CefDownloadManagerDelegate::GetBrowser(
DownloadItem* item) {
CefBrowserHostImpl* CefDownloadManagerDelegate::GetBrowser(DownloadItem* item) {
ItemBrowserMap::const_iterator it = item_browser_map_.find(item);
if (it != item_browser_map_.end())
return it->second;

View File

@@ -8,7 +8,7 @@
#include <set>
#include "libcef/browser/browser_host_base.h"
#include "libcef/browser/browser_host_impl.h"
#include "base/compiler_specific.h"
#include "base/memory/weak_ptr.h"
@@ -16,12 +16,10 @@
#include "content/public/browser/download_manager.h"
#include "content/public/browser/download_manager_delegate.h"
class AlloyBrowserHostImpl;
class CefDownloadManagerDelegate : public download::DownloadItem::Observer,
public content::DownloadManager::Observer,
public content::DownloadManagerDelegate,
public CefBrowserHostBase::Observer {
public CefBrowserHostImpl::Observer {
public:
explicit CefDownloadManagerDelegate(content::DownloadManager* manager);
~CefDownloadManagerDelegate() override;
@@ -43,20 +41,19 @@ class CefDownloadManagerDelegate : public download::DownloadItem::Observer,
void GetNextId(content::DownloadIdCallback callback) override;
std::string ApplicationClientIdForFileScanning() override;
// CefBrowserHostBase::Observer methods.
void OnBrowserDestroyed(CefBrowserHostBase* browser) override;
// CefBrowserHostImpl::Observer methods.
void OnBrowserDestroyed(CefBrowserHostImpl* browser) override;
AlloyBrowserHostImpl* GetOrAssociateBrowser(download::DownloadItem* item);
AlloyBrowserHostImpl* GetBrowser(download::DownloadItem* item);
CefBrowserHostImpl* GetOrAssociateBrowser(download::DownloadItem* item);
CefBrowserHostImpl* GetBrowser(download::DownloadItem* item);
content::DownloadManager* manager_;
base::WeakPtrFactory<content::DownloadManager> manager_ptr_factory_;
// Map of DownloadItem to originating AlloyBrowserHostImpl. Maintaining this
// Map of DownloadItem to originating CefBrowserHostImpl. Maintaining this
// map is necessary because DownloadItem::GetWebContents() may return NULL if
// the browser navigates while the download is in progress.
typedef std::map<download::DownloadItem*, AlloyBrowserHostImpl*>
ItemBrowserMap;
typedef std::map<download::DownloadItem*, CefBrowserHostImpl*> ItemBrowserMap;
ItemBrowserMap item_browser_map_;
DISALLOW_COPY_AND_ASSIGN(CefDownloadManagerDelegate);

View File

@@ -119,7 +119,7 @@ ExecuteCodeFunction::InitResult ExecuteCodeInTabFunction::Init() {
// Find a browser that we can access, or fail with error.
std::string error;
CefRefPtr<AlloyBrowserHostImpl> browser =
CefRefPtr<CefBrowserHostImpl> browser =
cef_details_.GetBrowserForTabIdFirstTime(tab_id, &error);
if (!browser)
return set_init_result_error(error);
@@ -130,18 +130,10 @@ ExecuteCodeFunction::InitResult ExecuteCodeInTabFunction::Init() {
return set_init_result(SUCCESS);
}
bool ExecuteCodeInTabFunction::ShouldInsertCSS() const {
return false;
}
bool ExecuteCodeInTabFunction::ShouldRemoveCSS() const {
return false;
}
bool ExecuteCodeInTabFunction::CanExecuteScriptOnPage(std::string* error) {
CHECK_GE(execute_tab_id_, 0);
CefRefPtr<AlloyBrowserHostImpl> browser =
CefRefPtr<CefBrowserHostImpl> browser =
cef_details_.GetBrowserForTabIdAgain(execute_tab_id_, error);
if (!browser)
return false;
@@ -196,7 +188,7 @@ ScriptExecutor* ExecuteCodeInTabFunction::GetScriptExecutor(
std::string* error) {
CHECK_GE(execute_tab_id_, 0);
CefRefPtr<AlloyBrowserHostImpl> browser =
CefRefPtr<CefBrowserHostImpl> browser =
cef_details_.GetBrowserForTabIdAgain(execute_tab_id_, error);
if (!browser)
return nullptr;
@@ -233,11 +225,11 @@ void ExecuteCodeInTabFunction::LoadFileComplete(
DidLoadAndLocalizeFile(file, success, std::move(data));
}
bool TabsInsertCSSFunction::ShouldInsertCSS() const {
return true;
bool TabsExecuteScriptFunction::ShouldInsertCSS() const {
return false;
}
bool TabsRemoveCSSFunction::ShouldRemoveCSS() const {
bool TabsInsertCSSFunction::ShouldInsertCSS() const {
return true;
}
@@ -245,7 +237,7 @@ ZoomAPIFunction::ZoomAPIFunction() : cef_details_(this) {}
content::WebContents* ZoomAPIFunction::GetWebContents(int tab_id) {
// Find a browser that we can access, or set |error_| and return nullptr.
CefRefPtr<AlloyBrowserHostImpl> browser =
CefRefPtr<CefBrowserHostImpl> browser =
cef_details_.GetBrowserForTabIdFirstTime(tab_id, &error_);
if (!browser)
return nullptr;

View File

@@ -42,7 +42,7 @@ class TabsCreateFunction : public ExtensionFunction {
const CefExtensionFunctionDetails cef_details_;
};
// Implement API calls tabs.executeScript, tabs.insertCSS, and tabs.removeCSS.
// Implement API call tabs.executeScript and tabs.insertCSS.
class ExecuteCodeInTabFunction : public ExecuteCodeFunction {
public:
ExecuteCodeInTabFunction();
@@ -52,8 +52,6 @@ class ExecuteCodeInTabFunction : public ExecuteCodeFunction {
// Initializes |execute_tab_id_| and |details_|.
InitResult Init() override;
bool ShouldInsertCSS() const override;
bool ShouldRemoveCSS() const override;
bool CanExecuteScriptOnPage(std::string* error) override;
ScriptExecutor* GetScriptExecutor(std::string* error) override;
bool IsWebView() const override;
@@ -71,6 +69,9 @@ class ExecuteCodeInTabFunction : public ExecuteCodeFunction {
};
class TabsExecuteScriptFunction : public ExecuteCodeInTabFunction {
protected:
bool ShouldInsertCSS() const override;
private:
~TabsExecuteScriptFunction() override {}
@@ -86,15 +87,6 @@ class TabsInsertCSSFunction : public ExecuteCodeInTabFunction {
DECLARE_EXTENSION_FUNCTION("tabs.insertCSS", TABS_INSERTCSS)
};
class TabsRemoveCSSFunction : public ExecuteCodeInTabFunction {
private:
~TabsRemoveCSSFunction() override {}
bool ShouldRemoveCSS() const override;
DECLARE_EXTENSION_FUNCTION("tabs.removeCSS", TABS_INSERTCSS)
};
// Based on ChromeAsyncExtensionFunction.
class ZoomAPIFunction : public ExtensionFunction {
public:

View File

@@ -4,13 +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_host_base.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"
@@ -19,8 +16,6 @@
#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 "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_view_host.h"
#include "extensions/browser/extension_registry.h"
namespace extensions {
@@ -64,7 +59,8 @@ content::WebContents* GetOwnerForGuestContents(content::WebContents* guest) {
content::BrowserPluginGuest* plugin_guest =
guest_impl->GetBrowserPluginGuest();
if (plugin_guest) {
return plugin_guest->owner_web_contents();
return content::WebContents::FromRenderFrameHost(
plugin_guest->GetEmbedderFrame());
}
// Maybe it's a print preview dialog.
@@ -73,7 +69,7 @@ content::WebContents* GetOwnerForGuestContents(content::WebContents* guest) {
return print_preview_controller->GetInitiator(guest);
}
CefRefPtr<CefBrowserHostBase> GetOwnerBrowserForFrameRoute(
CefRefPtr<CefBrowserHostImpl> GetOwnerBrowserForFrameRoute(
int render_process_id,
int render_routing_id,
bool* is_guest_view) {
@@ -90,7 +86,7 @@ CefRefPtr<CefBrowserHostBase> GetOwnerBrowserForFrameRoute(
CefBrowserInfoManager::GetInstance()->GetBrowserInfoForFrameRoute(
render_process_id, render_routing_id, is_guest_view);
if (info.get()) {
CefRefPtr<CefBrowserHostBase> browser = info->browser();
CefRefPtr<CefBrowserHostImpl> browser = info->browser();
if (!browser.get()) {
LOG(WARNING) << "Found browser id " << info->browser_id()
<< " but no browser object matching view process id "
@@ -103,20 +99,20 @@ CefRefPtr<CefBrowserHostBase> GetOwnerBrowserForFrameRoute(
}
}
CefRefPtr<CefBrowserHostBase> GetOwnerBrowserForHost(
CefRefPtr<CefBrowserHostImpl> GetOwnerBrowserForHost(
content::RenderViewHost* host,
bool* is_guest_view) {
if (is_guest_view)
*is_guest_view = false;
CefRefPtr<CefBrowserHostBase> browser =
CefBrowserHostBase::GetBrowserForHost(host);
CefRefPtr<CefBrowserHostImpl> browser =
CefBrowserHostImpl::GetBrowserForHost(host);
if (!browser.get() && ExtensionsEnabled()) {
// Retrieve the owner browser, if any.
content::WebContents* owner = GetOwnerForGuestContents(
content::WebContents::FromRenderViewHost(host));
if (owner) {
browser = CefBrowserHostBase::GetBrowserForContents(owner);
browser = CefBrowserHostImpl::GetBrowserForContents(owner);
if (browser.get() && is_guest_view)
*is_guest_view = true;
}
@@ -124,20 +120,20 @@ CefRefPtr<CefBrowserHostBase> GetOwnerBrowserForHost(
return browser;
}
CefRefPtr<CefBrowserHostBase> GetOwnerBrowserForHost(
CefRefPtr<CefBrowserHostImpl> GetOwnerBrowserForHost(
content::RenderFrameHost* host,
bool* is_guest_view) {
if (is_guest_view)
*is_guest_view = false;
CefRefPtr<CefBrowserHostBase> browser =
CefBrowserHostBase::GetBrowserForHost(host);
CefRefPtr<CefBrowserHostImpl> browser =
CefBrowserHostImpl::GetBrowserForHost(host);
if (!browser.get() && ExtensionsEnabled()) {
// Retrieve the owner browser, if any.
content::WebContents* owner = GetOwnerForGuestContents(
content::WebContents::FromRenderFrameHost(host));
if (owner) {
browser = CefBrowserHostBase::GetBrowserForContents(owner);
browser = CefBrowserHostImpl::GetBrowserForContents(owner);
if (browser.get() && is_guest_view)
*is_guest_view = true;
}
@@ -145,10 +141,9 @@ CefRefPtr<CefBrowserHostBase> GetOwnerBrowserForHost(
return browser;
}
CefRefPtr<AlloyBrowserHostImpl> GetBrowserForTabId(
CefRefPtr<CefBrowserHostImpl> GetBrowserForTabId(
int tab_id,
content::BrowserContext* browser_context) {
REQUIRE_ALLOY_RUNTIME();
CEF_REQUIRE_UIT();
DCHECK(browser_context);
if (tab_id < 0 || !browser_context)
@@ -159,8 +154,7 @@ CefRefPtr<AlloyBrowserHostImpl> GetBrowserForTabId(
for (const auto& browser_info :
CefBrowserInfoManager::GetInstance()->GetBrowserInfoList()) {
CefRefPtr<AlloyBrowserHostImpl> current_browser =
static_cast<AlloyBrowserHostImpl*>(browser_info->browser().get());
CefRefPtr<CefBrowserHostImpl> current_browser = browser_info->browser();
if (current_browser && current_browser->GetIdentifier() == tab_id) {
// Make sure we're operating in the same CefBrowserContext.
if (CefBrowserContext::FromBrowserContext(

View File

@@ -7,20 +7,16 @@
#include <vector>
#include "include/internal/cef_ptr.h"
#include "libcef/browser/browser_host_impl.h"
#include "url/gurl.h"
namespace content {
class BrowserContext;
class RenderFrameHost;
class RenderViewHost;
class WebContents;
} // namespace content
class CefBrowserHostBase;
class AlloyBrowserHostImpl;
namespace extensions {
class Extension;
@@ -36,31 +32,31 @@ void GetAllGuestsForOwnerContents(content::WebContents* owner,
// Returns the WebContents that owns the specified |guest|, if any.
content::WebContents* GetOwnerForGuestContents(content::WebContents* guest);
// Returns the CefBrowserHostBase that owns the host identified by the specified
// Returns the CefBrowserHostImpl that owns the host identified by the specified
// routing IDs, if any. |is_guest_view| will be set to true if the IDs
// match a guest view associated with the returned browser instead of the
// browser itself.
CefRefPtr<CefBrowserHostBase> GetOwnerBrowserForFrameRoute(
CefRefPtr<CefBrowserHostImpl> GetOwnerBrowserForFrameRoute(
int render_process_id,
int render_routing_id,
bool* is_guest_view);
// Returns the CefBrowserHostBase that owns the specified |host|, if any.
// Returns the CefBrowserHostImpl that owns the specified |host|, if any.
// |is_guest_view| will be set to true if the host matches a guest view
// associated with the returned browser instead of the browser itself.
// TODO(cef): Delete the RVH variant once the remaining use case
// (via AlloyContentBrowserClient::OverrideWebkitPrefs) has been removed.
CefRefPtr<CefBrowserHostBase> GetOwnerBrowserForHost(
CefRefPtr<CefBrowserHostImpl> GetOwnerBrowserForHost(
content::RenderViewHost* host,
bool* is_guest_view);
CefRefPtr<CefBrowserHostBase> GetOwnerBrowserForHost(
CefRefPtr<CefBrowserHostImpl> GetOwnerBrowserForHost(
content::RenderFrameHost* host,
bool* is_guest_view);
// 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(
CefRefPtr<CefBrowserHostImpl> GetBrowserForTabId(
int tab_id,
content::BrowserContext* browser_context);

View File

@@ -6,9 +6,8 @@
#include <utility>
#include "libcef/browser/alloy/alloy_browser_host_impl.h"
#include "libcef/browser/browser_host_impl.h"
#include "libcef/browser/thread_util.h"
#include "libcef/features/runtime_checks.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host.h"
@@ -16,7 +15,6 @@
CefBrowserPlatformDelegateBackground::CefBrowserPlatformDelegateBackground(
std::unique_ptr<CefBrowserPlatformDelegateNative> native_delegate)
: native_delegate_(std::move(native_delegate)) {
REQUIRE_ALLOY_RUNTIME();
native_delegate_->set_windowless_handler(this);
}
@@ -29,8 +27,7 @@ void CefBrowserPlatformDelegateBackground::CloseHostWindow() {
// No host window, so continue browser destruction now. Do it asynchronously
// so the call stack has a chance to unwind.
CEF_POST_TASK(CEF_UIT,
base::Bind(&AlloyBrowserHostImpl::WindowDestroyed,
static_cast<AlloyBrowserHostImpl*>(browser_)));
base::Bind(&CefBrowserHostImpl::WindowDestroyed, browser_));
}
CefWindowHandle CefBrowserPlatformDelegateBackground::GetHostWindowHandle()
@@ -118,6 +115,14 @@ CefBrowserPlatformDelegateBackground::CreateMenuRunner() {
return nullptr;
}
bool CefBrowserPlatformDelegateBackground::IsWindowless() const {
return false;
}
bool CefBrowserPlatformDelegateBackground::IsViewsHosted() const {
return false;
}
CefWindowHandle CefBrowserPlatformDelegateBackground::GetParentWindowHandle()
const {
return GetHostWindowHandle();

View File

@@ -44,6 +44,8 @@ class CefBrowserPlatformDelegateBackground
std::unique_ptr<CefJavaScriptDialogRunner> CreateJavaScriptDialogRunner()
override;
std::unique_ptr<CefMenuRunner> CreateMenuRunner() override;
bool IsWindowless() const override;
bool IsViewsHosted() const override;
// CefBrowserPlatformDelegateNative::WindowlessHandler methods:
CefWindowHandle GetParentWindowHandle() const override;

View File

@@ -53,7 +53,6 @@ const char* const kSupportedAPIs[] = {
EXTENSION_FUNCTION_NAME(cefimpl::TabsCreateFunction),
EXTENSION_FUNCTION_NAME(cefimpl::TabsExecuteScriptFunction),
EXTENSION_FUNCTION_NAME(cefimpl::TabsInsertCSSFunction),
EXTENSION_FUNCTION_NAME(cefimpl::TabsRemoveCSSFunction),
EXTENSION_FUNCTION_NAME(cefimpl::TabsSetZoomFunction),
EXTENSION_FUNCTION_NAME(cefimpl::TabsGetZoomFunction),
EXTENSION_FUNCTION_NAME(cefimpl::TabsSetZoomSettingsFunction),
@@ -92,7 +91,6 @@ void ChromeFunctionRegistry::RegisterAll(ExtensionFunctionRegistry* registry) {
registry->RegisterFunction<StorageStorageAreaGetBytesInUseFunction>();
registry->RegisterFunction<cefimpl::TabsExecuteScriptFunction>();
registry->RegisterFunction<cefimpl::TabsInsertCSSFunction>();
registry->RegisterFunction<cefimpl::TabsRemoveCSSFunction>();
registry->RegisterFunction<cefimpl::TabsGetFunction>();
registry->RegisterFunction<cefimpl::TabsCreateFunction>();
registry->RegisterFunction<cefimpl::TabsSetZoomFunction>();

View File

@@ -4,7 +4,7 @@
#include "libcef/browser/extensions/extension_background_host.h"
#include "libcef/browser/alloy/alloy_browser_host_impl.h"
#include "libcef/browser/browser_host_impl.h"
#include "libcef/browser/extensions/extension_host_delegate.h"
#include "base/callback.h"
@@ -12,7 +12,7 @@
namespace extensions {
CefExtensionBackgroundHost::CefExtensionBackgroundHost(
AlloyBrowserHostImpl* browser,
CefBrowserHostImpl* browser,
base::OnceClosure deleted_callback,
const Extension* extension,
content::WebContents* host_contents,

View File

@@ -11,7 +11,7 @@
#include "base/macros.h"
#include "extensions/browser/extension_host.h"
class AlloyBrowserHostImpl;
class CefBrowserHostImpl;
namespace content {
class WebContents;
@@ -24,7 +24,7 @@ namespace extensions {
// is managed by ProcessManager.
class CefExtensionBackgroundHost : public ExtensionHost {
public:
CefExtensionBackgroundHost(AlloyBrowserHostImpl* browser,
CefExtensionBackgroundHost(CefBrowserHostImpl* browser,
base::OnceClosure deleted_callback,
const Extension* extension,
content::WebContents* host_contents,

View File

@@ -143,18 +143,18 @@ Profile* CefExtensionFunctionDetails::GetProfile() const {
return Profile::FromBrowserContext(function_->browser_context());
}
CefRefPtr<AlloyBrowserHostImpl> CefExtensionFunctionDetails::GetSenderBrowser()
CefRefPtr<CefBrowserHostImpl> CefExtensionFunctionDetails::GetSenderBrowser()
const {
content::WebContents* web_contents = function_->GetSenderWebContents();
if (web_contents)
return AlloyBrowserHostImpl::GetBrowserForContents(web_contents);
return CefBrowserHostImpl::GetBrowserForContents(web_contents);
return nullptr;
}
CefRefPtr<AlloyBrowserHostImpl> CefExtensionFunctionDetails::GetCurrentBrowser()
CefRefPtr<CefBrowserHostImpl> CefExtensionFunctionDetails::GetCurrentBrowser()
const {
// Start with the browser hosting the extension.
CefRefPtr<AlloyBrowserHostImpl> browser = GetSenderBrowser();
CefRefPtr<CefBrowserHostImpl> browser = GetSenderBrowser();
if (browser && browser->client()) {
CefRefPtr<CefExtensionHandler> handler = GetCefExtension()->GetHandler();
if (handler) {
@@ -163,8 +163,8 @@ CefRefPtr<AlloyBrowserHostImpl> CefExtensionFunctionDetails::GetCurrentBrowser()
handler->GetActiveBrowser(GetCefExtension(), browser.get(),
function_->include_incognito_information());
if (active_browser && active_browser != browser) {
CefRefPtr<AlloyBrowserHostImpl> active_browser_impl =
static_cast<AlloyBrowserHostImpl*>(active_browser.get());
CefRefPtr<CefBrowserHostImpl> active_browser_impl =
static_cast<CefBrowserHostImpl*>(active_browser.get());
// Make sure we're operating in the same CefBrowserContext.
if (CefBrowserContext::FromBrowserContext(
@@ -187,11 +187,11 @@ CefRefPtr<AlloyBrowserHostImpl> CefExtensionFunctionDetails::GetCurrentBrowser()
}
bool CefExtensionFunctionDetails::CanAccessBrowser(
CefRefPtr<AlloyBrowserHostImpl> target) const {
CefRefPtr<CefBrowserHostImpl> target) const {
DCHECK(target);
// Start with the browser hosting the extension.
CefRefPtr<AlloyBrowserHostImpl> browser = GetSenderBrowser();
CefRefPtr<CefBrowserHostImpl> browser = GetSenderBrowser();
if (browser == target) {
// A sender can always access itself.
return true;
@@ -210,14 +210,14 @@ bool CefExtensionFunctionDetails::CanAccessBrowser(
return true;
}
CefRefPtr<AlloyBrowserHostImpl>
CefRefPtr<CefBrowserHostImpl>
CefExtensionFunctionDetails::GetBrowserForTabIdFirstTime(
int tab_id,
std::string* error_message) const {
DCHECK(!get_browser_called_first_time_);
get_browser_called_first_time_ = true;
CefRefPtr<AlloyBrowserHostImpl> browser;
CefRefPtr<CefBrowserHostImpl> browser;
if (tab_id >= 0) {
// May be an invalid tabId or in the wrong BrowserContext.
@@ -243,7 +243,7 @@ CefExtensionFunctionDetails::GetBrowserForTabIdFirstTime(
return browser;
}
CefRefPtr<AlloyBrowserHostImpl>
CefRefPtr<CefBrowserHostImpl>
CefExtensionFunctionDetails::GetBrowserForTabIdAgain(
int tab_id,
std::string* error_message) const {
@@ -251,7 +251,7 @@ CefExtensionFunctionDetails::GetBrowserForTabIdAgain(
DCHECK(get_browser_called_first_time_);
// May return NULL during shutdown.
CefRefPtr<AlloyBrowserHostImpl> browser =
CefRefPtr<CefBrowserHostImpl> browser =
GetBrowserForTabId(tab_id, function_->browser_context());
if (!browser || !browser->web_contents()) {
if (error_message) {
@@ -265,7 +265,7 @@ CefExtensionFunctionDetails::GetBrowserForTabIdAgain(
bool CefExtensionFunctionDetails::LoadFile(const std::string& file,
LoadFileCallback callback) const {
// Start with the browser hosting the extension.
CefRefPtr<AlloyBrowserHostImpl> browser = GetSenderBrowser();
CefRefPtr<CefBrowserHostImpl> browser = GetSenderBrowser();
if (browser && browser->client()) {
CefRefPtr<CefExtensionHandler> handler = GetCefExtension()->GetHandler();
if (handler) {
@@ -290,7 +290,7 @@ base::DictionaryValue* CefExtensionFunctionDetails::OpenTab(
const OpenTabParams& params,
bool user_gesture,
std::string* error_message) const {
CefRefPtr<AlloyBrowserHostImpl> sender_browser = GetSenderBrowser();
CefRefPtr<CefBrowserHostImpl> sender_browser = GetSenderBrowser();
if (!sender_browser)
return nullptr;
@@ -301,7 +301,7 @@ base::DictionaryValue* CefExtensionFunctionDetails::OpenTab(
// CEF doesn't have the concept of windows containing tab strips so we'll
// select an "active browser" for BrowserContext sharing instead.
CefRefPtr<AlloyBrowserHostImpl> active_browser =
CefRefPtr<CefBrowserHostImpl> active_browser =
GetBrowserForTabIdFirstTime(window_id, error_message);
if (!active_browser)
return nullptr;
@@ -365,7 +365,7 @@ base::DictionaryValue* CefExtensionFunctionDetails::OpenTab(
if (!request_context)
return nullptr;
CefBrowserCreateParams create_params;
CefBrowserHostImpl::CreateParams create_params;
create_params.url = url;
create_params.request_context = request_context;
create_params.window_info.reset(new CefWindowInfo);
@@ -394,8 +394,8 @@ base::DictionaryValue* CefExtensionFunctionDetails::OpenTab(
}
// Browser creation may fail under certain rare circumstances.
CefRefPtr<AlloyBrowserHostImpl> new_browser =
AlloyBrowserHostImpl::Create(create_params);
CefRefPtr<CefBrowserHostImpl> new_browser =
CefBrowserHostImpl::Create(create_params);
if (!new_browser)
return nullptr;
@@ -412,7 +412,7 @@ base::DictionaryValue* CefExtensionFunctionDetails::OpenTab(
}
std::unique_ptr<api::tabs::Tab> CefExtensionFunctionDetails::CreateTabObject(
CefRefPtr<AlloyBrowserHostImpl> new_browser,
CefRefPtr<CefBrowserHostImpl> new_browser,
int opener_browser_id,
bool active,
int index) const {

View File

@@ -5,7 +5,7 @@
#ifndef CEF_LIBCEF_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_DETAILS_H_
#define CEF_LIBCEF_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_DETAILS_H_
#include "libcef/browser/alloy/alloy_browser_host_impl.h"
#include "libcef/browser/browser_host_impl.h"
#include "include/cef_extension.h"
@@ -36,7 +36,7 @@ class CefExtensionFunctionDetails {
// Get the "sender" browser that is hosting the extension. May return NULL
// during startup/shutdown.
CefRefPtr<AlloyBrowserHostImpl> GetSenderBrowser() const;
CefRefPtr<CefBrowserHostImpl> GetSenderBrowser() const;
// Get the "current" browser that will be acted on by this extension function,
// if any. When mapping from a tabId use the GetBrowserForTabId* methods
@@ -57,12 +57,12 @@ class CefExtensionFunctionDetails {
// This method can return NULL if there is no matching browser, which can
// happen if only incognito windows are open, or early in startup or shutdown
// shutdown when there are no active windows.
CefRefPtr<AlloyBrowserHostImpl> GetCurrentBrowser() const;
CefRefPtr<CefBrowserHostImpl> GetCurrentBrowser() const;
// Returns true if the sender browser can access |target|. When mapping from a
// tabId use the GetBrowserForTabId* methods instead of calling this method
// directly.
bool CanAccessBrowser(CefRefPtr<AlloyBrowserHostImpl> target) const;
bool CanAccessBrowser(CefRefPtr<CefBrowserHostImpl> target) const;
// Returns the browser matching |tab_id| or NULL if the browser cannot be
// found or does not have a WebContents. If |tab_id| is < 0 the "current"
@@ -70,7 +70,7 @@ class CefExtensionFunctionDetails {
// will be set with an appropriate message on error. This method should only
// be called one time per extension function and will check all necessary
// client permissions.
CefRefPtr<AlloyBrowserHostImpl> GetBrowserForTabIdFirstTime(
CefRefPtr<CefBrowserHostImpl> GetBrowserForTabIdFirstTime(
int tab_id,
std::string* error_message) const;
@@ -79,7 +79,7 @@ class CefExtensionFunctionDetails {
// |error_message| can optionally be passed in and will be set with an
// appropriate message on error. This method should be called only after
// GetBrowserForTabIdFirstTime() has succeeded for the same |tab_id|.
CefRefPtr<AlloyBrowserHostImpl> GetBrowserForTabIdAgain(
CefRefPtr<CefBrowserHostImpl> GetBrowserForTabIdAgain(
int tab_id,
std::string* error_message) const;
@@ -114,7 +114,7 @@ class CefExtensionFunctionDetails {
// permissions of the extension, the object may or may not include sensitive
// data such as the tab's URL.
std::unique_ptr<api::tabs::Tab> CreateTabObject(
CefRefPtr<AlloyBrowserHostImpl> new_browser,
CefRefPtr<CefBrowserHostImpl> new_browser,
int opener_browser_id,
bool active,
int index) const;

Some files were not shown because too many files have changed in this diff Show More