Compare commits

...

61 Commits
4430 ... 4472

Author SHA1 Message Date
CEF Spotify
04c8d5653c Update to Chromium version 91.0.4472.164 2021-07-19 15:42:33 +00:00
CEF Spotify
c67b5dd17a Update to Chromium version 91.0.4472.124 2021-07-02 02:05:30 +00:00
Marshall Greenblatt
9dd45fe159 Update to Chromium version 91.0.4472.114 2021-06-19 21:29:51 -04:00
Matthew Isaacs
58006652e8 widevine: Add arm64 arch manifest value (see issue #2981) 2021-06-17 10:11:14 -04:00
Marshall Greenblatt
a92e5d5e3d alloy: Fix link click navigation in PDF files (fixes issue #3143)
This change adds a minimal implementation of the |tabs.update| extension API and
modifies StreamsPrivateAPI::SendExecuteMimeTypeHandlerEvent to return a valid
|streamInfo.tabId| value as required by the navigateInCurrentTab implementation
in chrome/browser/resources/pdf/browser_api.js.
2021-06-16 16:19:46 -04:00
Alex Maitland
b0e72423cf Expose certificate error codes to OnLoadError 2021-06-16 12:05:27 -04:00
Marshall Greenblatt
18455833f1 widevine: Fix VP9 version string for v4.10.2209.0 (fixes issue #3138) 2021-06-14 14:49:43 -04:00
Marshall Greenblatt
c95b2a1c4c Windows: Allow non-component Debug official sandbox builds (see issue #2679) 2021-06-11 20:57:48 -04:00
Marshall Greenblatt
0b869d2aff Use Chromium code for cookie date validity check (fixes issue #2927) 2021-06-11 13:51:57 -04:00
Marshall Greenblatt
2a9d8b8ee4 Add --disable-request-handling-for-testing option
Add a command-line option to bypass request handling in CEF to faciliate
debugging of network-related issues.
2021-06-11 13:51:50 -04:00
Marshall Greenblatt
a65fc80313 Windows: Forbid non-component Debug builds (see issue #2679) 2021-06-11 13:51:43 -04:00
Marshall Greenblatt
cf0c26af87 Update to Chromium version 91.0.4472.101 2021-06-10 22:00:18 -04:00
Marshall Greenblatt
70b6b712ac Fix CefBrowser::GetMainFrame assumptions in the renderer process (see issue #2421)
ClientAppRenderer::Delegate callbacks are executed for all tests. In this case
CorsTest.IframeAllowScriptsCustomNonStandardSchemeToServer was crashing on Linux
because CefBrowser::GetMainFrame() returns nullptr in the renderer process when
called from a cross-origin sub-frame.
2021-06-10 16:49:57 -04:00
Marshall Greenblatt
2e83e000ad Mac: Fix Xcode 12.5 build errors related to implicit copy assignment operators 2021-06-10 16:46:57 -04:00
Marshall Greenblatt
c19f7e2fb7 Mac: Don't enable dSYMs by default for non-offical builds
Building with dSYMs enabled results in substantially longer link times and
provides minimal benefit for builds that are not intended for distribution.

They can still optionally be enabled by setting enable_dsyms=true via
GN_DEFINES. They remain enabled by default for official builds generated
with is_official_build=true and are required if packaging symbols via the
make_distrib.py script.
2021-06-10 16:46:48 -04:00
Marshall Greenblatt
f605ad04f4 Mac: Fix flaky ResourceRequestHandlerTest failures
The AbortAfterCreated and AbortBeforeBrowse tests were flaking due to a race
between request handling and browser close. The tests would fail if the request
handling completed first.
2021-06-10 16:46:37 -04:00
Marshall Greenblatt
cb517af03e Linux: Fix Check failed: generated_timestamp < total_latency_stage.end_time (see issue #3102) 2021-06-10 16:46:24 -04:00
Marshall Greenblatt
8a752eb705 Update to Chromium version 91.0.4472.77 2021-05-27 00:26:45 -04:00
Marshall Greenblatt
719b66a9e5 Restore support for CreateBrowserSync with NULL |request_context| (see issue #2969)
This was unintentionally lost during the Chrome runtime refactoring effort.
2021-05-20 15:16:30 -04:00
Marshall Greenblatt
10153e24f8 Fix crash closing DevTools window (fixes issue #3111) 2021-05-05 12:49:36 -04:00
Marshall Greenblatt
f48ea7f032 Fix crash in OnGuestDetached when unloading PDF (fixes issue #3121) 2021-05-04 13:29:16 -04:00
Marshall Greenblatt
fae1e9eaa1 Restore async CreateBrowser behavior (fixes issue #3116, fixes issue #3118)
Restore the async CreateBrowser behavior that existed prior to commit 691c9c2
because executing synchronously (for example, from inside OnContextInitialized)
causes issues on MacOS and possibly other platforms.
2021-04-29 17:35:08 -04:00
Marshall Greenblatt
ddf5446588 chrome: Support configuration of accept language (see issue #2969)
This change adds support for CEF settings configuration of accept_language_list.
If specified, this value will take precedence over the "intl.accept_languages"
preference which is controlled by chrome://settings/languages.
2021-04-28 14:29:28 -04:00
Marshall Greenblatt
351901861c chrome: Support configuration of user agent and locale (see issue #2969)
This change adds support for CefSettings and command-line configuration of
user_agent, user_agent_product (formerly product_version) and locale.
2021-04-27 12:44:42 -04:00
Marshall Greenblatt
a149cf128f Windows: Disable iterator debugging for cef_sandbox builds (fixes issue #3109)
Iterator debugging has been disabled by default (_HAS_ITERATOR_DEBUGGING=0)
for CEF/Chromium builds using clang/LLVM since 2018. Inversely, it is enabled
by default (_ITERATOR_DEBUG_LEVEL=2) for the MSVC Debug build configuration.
In order to minimize configuration-related headaches for MSVC-based clients
we have been building the Debug cef_sandbox.lib with iterator debugging
enabled. Recently, we have identified a number of crashes that may be due to
bugs in current clang/LLVM or MSVC versions but in any case can be resolved by
disabling iterator debugging:

- Crash when loading chrome://sandbox.
- Crash if an application lists libraries that utilize iterators after
  cef_sandbox.lib in the linker order.

To resolve these crashes we will now disable iterator debugging by default
for the cef_sandbox.lib builds. Client applications that link cef_sandbox.lib
will now also need to build with iterator debugging disabled by setting
_HAS_ITERATOR_DEBUGGING=0 or _ITERATOR_DEBUG_LEVEL=0 in their project
configuration (this will be done for you if you use cef_variables.cmake from
the binary distribution).

In addition to the crash fixes mentioned above, this change also:

- Reduces the size of the Debug cef_sandbox.lib by ~10MB.
- May result in faster Debug executables (see https://crbug.com/539996).
2021-04-26 18:22:00 -04:00
Marshall Greenblatt
16095a90f6 ceftests: Add missing newline at end of file 2021-04-23 21:03:01 -04:00
Marshall Greenblatt
7fb78654cb Linux: cefclient: Don't use std::make_unique which requires C++14 2021-04-23 21:02:54 -04:00
Marshall Greenblatt
fef384b1fc Update to Chromium version 91.0.4472.19 2021-04-23 17:52:43 -04:00
Marshall Greenblatt
ae4f68f695 Update to Chromium version 91.0.4472.0 (#870763) 2021-04-23 11:38:51 -04:00
Marshall Greenblatt
b189c7b472 Fix extension loading test failure 2021-04-22 17:15:14 -04:00
Marshall Greenblatt
f84762d84a Fix crash closing DevTools window (fixes issue #3111) 2021-04-22 12:41:35 -04:00
Marshall Greenblatt
cf1074cf49 chrome: Support configuration of renderer prefs (see issue #2969) 2021-04-17 21:23:55 -04:00
Marshall Greenblatt
9756e15a23 chrome: Don't rely on CREATE_STATUS_CREATED for disk-based profiles (see issue #2969) 2021-04-15 13:36:10 -04:00
Marshall Greenblatt
a4d71d8fe2 cefclient: Fix slow loading of the Views image cache (see issue #2969) 2021-04-14 22:29:30 -04:00
Marshall Greenblatt
34c63a665d Wait for CefBrowserContext initialization (see issue #2969)
With the Chrome runtime, Profile initialization may be asynchronous. Code that
waited on CefBrowserContext creation now needs to wait on CefBrowserContext
initialization instead.
2021-04-14 21:03:44 -04:00
Marshall Greenblatt
fc7f9ff505 Fix crash when navigating to an unregistered scheme (fixes issue #3105)
The policy->CanAccessDataForOrigin CHECK in NavigationRequest::
GetOriginForURLLoaderFactory was failing because unregistered schemes
(which are already considered non-standard schemes) didn't trigger the
registered non-standard scheme allowance that we previously added in
ChildProcessSecurityPolicyImpl::CanAccessDataForOrigin. This change
modifies GetOriginForURLLoaderFactory to always return an opaque/unique
origin for non-standard schemes resulting in unregistered and non-standard
schemes receiving the same treatment.

New test coverage has been added for this condition, and can be run with:
ceftests --gtest_filter=CorsTest.*CustomUnregistered*
2021-04-12 16:18:37 -04:00
Marshall Greenblatt
e1b6f5ad31 chrome: mac: Fix exception_port_.is_valid() failure (see issue #2969)
Fixes the following startup error:
FATAL:crashpad_client_mac.cc(499) Check failed: exception_port_.is_valid()
2021-04-11 20:44:28 -04:00
Marshall Greenblatt
6d25033822 mac: ceftests: Fix helper app linker errors (see issue #2969) 2021-04-11 20:44:28 -04:00
Marshall Greenblatt
a4603c6f1a chrome: Support usage of the Chrome toolbar from Views (see issue #2969) 2021-04-11 20:44:28 -04:00
Marshall Greenblatt
9c82785077 chrome: Fix assertion when clicking the incognito profile button (see issue #2969)
Profile::IsIncognitoProfile() currently returns false for CEF incognito profiles
because they are not the primary OTR profile. At the same time, we don't
necessarily want IsIncognitoProfile() to return true for CEF profiles because,
among other things, that causes the BrowserView to apply the dark toolbar theme.
Instead, this change updates ProfileMenu expectations to support the CEF
incognito profiles without otherwise modifying the incognito behavior.

Note that the IsIncognitoProfile() implementation has recently changed in
https://crrev.com/7bf6eb2497 and the conclusions in this commit will likely need
to be revisited in an upcoming Chromium update.
2021-04-11 16:05:10 -04:00
Marshall Greenblatt
1c04d96468 chrome: Fix FrameTest and RequestHandlerTest failures (see issue #2969) 2021-04-09 22:24:44 -04:00
Marshall Greenblatt
5318dfe252 chrome: Fix PreferenceTest failures (see issue #2969) 2021-04-09 22:00:33 -04:00
Marshall Greenblatt
76642ccafa Move cookieable scheme configuration to settings (see issue #2969)
The Chrome runtime requires that cookieable scheme information be available
at Profile initialization time because it also triggers NetworkContext creation
at the same time. To make this possible, and to avoid various race conditions
when setting state, the cookieable scheme configuration has been added as
|cookieable_schemes_list| and |cookieable_schemes_exclude_defaults| in
CefSettings and CefBrowserContextSettings. The CefCookieManager::
SetSupportedSchemes and CefBrowserProcessHandler::GetCookieableSchemes methods
are no longer required and have been removed.

This change also modifies chrome to delay OffTheRecordProfileImpl initialization
so that |ChromeBrowserContext::profile_| can be set before
ChromeContentBrowserClientCef::ConfigureNetworkContextParams calls
CefBrowserContext::FromBrowserContext to retrieve the ChromeBrowserContext
and associated cookieable scheme information. Otherwise, the
ChromeBrowserContext will not be matched and the NetworkContext will not be
configured correctly.

The CookieTest suite now passes with the Chrome runtime enabled.
2021-04-09 15:04:24 -04:00
Marshall Greenblatt
c565d9b1e6 Fix server thread assertion on CEF shutdown (see issue #2969)
The server thread was not guaranteed to be released in the correct scope on
CEF shutdown. This resulted in occasional thread_restrictions assertions on
ceftests shutdown after running the URLRequestTest suite with the Chrome
runtime enabled.
2021-04-09 14:22:51 -04:00
Marshall Greenblatt
09a9d9b54c chrome: Support customization of context menus (see issue #2969) 2021-04-08 19:38:29 -04:00
Marshall Greenblatt
701f51b1cc Fix URL rewrite on browser creation (see issue #2969)
The WebUITest suite now passes with the Chrome runtime enabled.
2021-04-07 18:56:07 -04:00
Marshall Greenblatt
4188cc2f75 Avoid potential use-after-free of CefIOThreadState (see issue #2969)
The problem occured while executing multiple URLRequestTest with the Chrome
runtime.
2021-04-07 18:19:46 -04:00
Marshall Greenblatt
09fa22898d chrome: Support client-created request contexts (see issue #2969)
RequestContextTest and URLRequestTest suites now pass with the Chrome runtime
enabled.
2021-04-07 18:19:17 -04:00
Marshall Greenblatt
1cddbeb12f chrome: Fix CorsTest.RedirectPost307HttpSchemeToCustomNonStandardScheme failure (see issue #2969) 2021-04-05 14:49:30 -04:00
Marshall Greenblatt
09c6586480 chrome: Fix NavigationTest and ResourceRequestHandlerTest failures (see issue #2969) 2021-04-05 13:50:21 -04:00
Marshall Greenblatt
25701cfa6f chrome: Add support for reparenting of popups with Views (see issue #2969) 2021-04-02 16:53:34 -04:00
Marshall Greenblatt
4960970dbd Customize the 'platform' crash key value for ARM builds (see issue #2981, see issue #2773) 2021-03-31 11:00:37 -04:00
Marshall Greenblatt
19ac738b77 cefclient: Simplify ClientPrintHandlerGtk for single browser usage (see issue #2196) 2021-03-30 09:49:17 -07:00
Marshall Greenblatt
7876a2f321 Move GetPrintHandler to CefClient (see issue #2196)
This new location is preferred because we now know the associated CefBrowser
for all CefPrintHandler callbacks.
2021-03-30 12:26:57 -04:00
Marshall Greenblatt
f7a4c777e8 Remove CefBrowserSettings.web_security (fixes issue #3058) 2021-03-25 13:07:17 -04:00
Marshall Greenblatt
b375397efb Fix crash in MediaRouterEnabled due to missing pref registration (see issue #2900) 2021-03-24 15:15:53 -04:00
Corentin Dumont
6574e1d914 Windows: Fix out-of-sync timestamps in OSR mode (fixes issue #3102) 2021-03-23 20:13:03 +00:00
Marshall Greenblatt
91ecc85e93 Fix potential use-after-free of V8TrackArrayBuffer (fixes issue #3074) 2021-03-23 16:02:51 -04:00
Marshall Greenblatt
96404f1fd9 Revert "Fix potential use-after-free of V8TrackArrayBuffer (fixes issue #3074)"
This reverts commit 64a1612b70.
2021-03-22 19:44:42 -04:00
Marshall Greenblatt
288366c96d Mac: Fix "fatal error: 'include/cef_pack_resources.h' file not found"
This occurs on a clean build of the ceftests target.
2021-03-22 19:40:37 -04:00
Marshall Greenblatt
64a1612b70 Fix potential use-after-free of V8TrackArrayBuffer (fixes issue #3074) 2021-03-22 13:53:18 -04:00
350 changed files with 6461 additions and 3729 deletions

View File

@@ -125,7 +125,6 @@ if (is_mac) {
import("//build/config/mac/rules.gni")
import("//build/util/version.gni")
import("//media/cdm/library_cdm/cdm_paths.gni")
import("//build/config/mac/base_rules.gni")
# Template to compile .xib and .storyboard files.
#
@@ -262,12 +261,6 @@ if (is_clang) {
assert(!clang_use_chrome_plugins)
}
if (is_mac) {
# Always generate dSYM files. The make_distrib script will fail if
# enable_dsyms=true is not explicitly set when is_official_build=false.
assert(enable_dsyms)
}
#
# Local variables.
@@ -461,6 +454,8 @@ static_library("libcef_static") {
"libcef/browser/chrome/chrome_browser_main_extra_parts_cef.h",
"libcef/browser/chrome/chrome_content_browser_client_cef.cc",
"libcef/browser/chrome/chrome_content_browser_client_cef.h",
"libcef/browser/chrome/chrome_context_menu_handler.cc",
"libcef/browser/chrome/chrome_context_menu_handler.h",
"libcef/browser/chrome_crash_reporter_client_stub.cc",
"libcef/browser/context.cc",
"libcef/browser/context.h",
@@ -486,6 +481,8 @@ static_library("libcef_static") {
"libcef/browser/extensions/api/storage/sync_value_store_cache.h",
"libcef/browser/extensions/api/tabs/tabs_api.cc",
"libcef/browser/extensions/api/tabs/tabs_api.h",
"libcef/browser/extensions/alloy_extensions_util.cc",
"libcef/browser/extensions/alloy_extensions_util.h",
"libcef/browser/extensions/browser_extensions_util.cc",
"libcef/browser/extensions/browser_extensions_util.h",
"libcef/browser/extensions/browser_platform_delegate_background.cc",
@@ -637,6 +634,8 @@ static_library("libcef_static") {
"libcef/browser/scheme_impl.cc",
"libcef/browser/server_impl.cc",
"libcef/browser/server_impl.h",
"libcef/browser/simple_menu_model_impl.cc",
"libcef/browser/simple_menu_model_impl.h",
"libcef/browser/speech_recognition_manager_delegate.cc",
"libcef/browser/speech_recognition_manager_delegate.h",
"libcef/browser/ssl_host_state_delegate.cc",
@@ -716,6 +715,8 @@ static_library("libcef_static") {
"libcef/common/net/upload_data.h",
"libcef/common/net/upload_element.cc",
"libcef/common/net/upload_element.h",
"libcef/common/net/url_util.cc",
"libcef/common/net/url_util.h",
"libcef/common/net_service/net_service_util.cc",
"libcef/common/net_service/net_service_util.h",
"libcef/common/parser_impl.cc",
@@ -1064,6 +1065,10 @@ static_library("libcef_static") {
"libcef/browser/chrome/views/chrome_browser_frame.h",
"libcef/browser/chrome/views/chrome_browser_view.cc",
"libcef/browser/chrome/views/chrome_browser_view.h",
"libcef/browser/chrome/views/toolbar_view_impl.cc",
"libcef/browser/chrome/views/toolbar_view_impl.h",
"libcef/browser/chrome/views/toolbar_view_view.cc",
"libcef/browser/chrome/views/toolbar_view_view.h",
"libcef/browser/native/window_delegate_view.cc",
"libcef/browser/native/window_delegate_view.h",
"libcef/browser/views/basic_label_button_impl.cc",
@@ -1774,6 +1779,7 @@ if (is_mac) {
public_deps = [ ":libcef_dll_wrapper" ]
deps = [
":cef_make_headers",
":libcef_dll_wrapper",
":${app_name}_framework_bundle_data",
]

View File

@@ -7,5 +7,6 @@
# https://bitbucket.org/chromiumembedded/cef/wiki/BranchesAndBuilding
{
'chromium_checkout': 'refs/tags/90.0.4430.0'
'chromium_checkout': 'refs/tags/91.0.4472.164',
'depot_tools_checkout': '61bf6e8d69'
}

View File

@@ -22,7 +22,6 @@
'include/base/cef_platform_thread.h',
'include/base/cef_ref_counted.h',
'include/base/cef_scoped_ptr.h',
'include/base/cef_string16.h',
'include/base/cef_template_util.h',
'include/base/cef_thread_checker.h',
'include/base/cef_trace_event.h',
@@ -128,7 +127,6 @@
'libcef_dll/base/cef_lock_impl.cc',
'libcef_dll/base/cef_logging.cc',
'libcef_dll/base/cef_ref_counted.cc',
'libcef_dll/base/cef_string16.cc',
'libcef_dll/base/cef_thread_checker_impl.cc',
'libcef_dll/base/cef_weak_ptr.cc',
],
@@ -563,6 +561,7 @@
'tests/ceftests/audio_output_unittest.cc',
'tests/ceftests/client_app_delegates.cc',
'tests/ceftests/cookie_unittest.cc',
'tests/ceftests/cors_unittest.cc',
'tests/ceftests/dom_unittest.cc',
'tests/ceftests/frame_unittest.cc',
'tests/ceftests/message_router_unittest.cc',

View File

@@ -491,6 +491,9 @@ if(OS_WINDOWS)
PSAPI_VERSION=1 # Required by cef_sandbox.lib
CEF_USE_SANDBOX # Used by apps to test if the sandbox is enabled
)
list(APPEND CEF_COMPILER_DEFINES_DEBUG
_HAS_ITERATOR_DEBUGGING=0 # Disable iterator debugging
)
# Libraries required by cef_sandbox.lib.
set(CEF_SANDBOX_STANDARD_LIBS

View File

@@ -75,7 +75,6 @@ typedef unsigned short uint16;
#endif
// UTF-16 character type.
// This should be kept synchronized with base/strings/string16.h
#ifndef char16
#if defined(WCHAR_T_IS_UTF16)
typedef wchar_t char16;

View File

@@ -1,223 +0,0 @@
// Copyright (c) 2014 Marshall A. Greenblatt. Portions copyright (c) 2013
// Google Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the name Chromium Embedded
// Framework nor the names of its contributors may be used to endorse
// or promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef CEF_INCLUDE_BASE_CEF_STRING16_H_
#define CEF_INCLUDE_BASE_CEF_STRING16_H_
#pragma once
#if defined(BASE_STRINGS_STRING16_H_)
// Do nothing if the Chromium header has already been included.
// This can happen in cases where Chromium code is used directly by the
// client application. When using Chromium code directly always include
// the Chromium header first to avoid type conflicts.
#elif defined(USING_CHROMIUM_INCLUDES)
// When building CEF include the Chromium header directly.
#include "base/strings/string16.h"
#else // !USING_CHROMIUM_INCLUDES
// The following is substantially similar to the Chromium implementation.
// If the Chromium implementation diverges the below implementation should be
// updated to match.
// WHAT:
// A version of std::basic_string that provides 2-byte characters even when
// wchar_t is not implemented as a 2-byte type. You can access this class as
// string16. We also define char16, which string16 is based upon.
//
// WHY:
// On Windows, wchar_t is 2 bytes, and it can conveniently handle UTF-16/UCS-2
// data. Plenty of existing code operates on strings encoded as UTF-16.
//
// On many other platforms, sizeof(wchar_t) is 4 bytes by default. We can make
// it 2 bytes by using the GCC flag -fshort-wchar. But then std::wstring fails
// at run time, because it calls some functions (like wcslen) that come from
// the system's native C library -- which was built with a 4-byte wchar_t!
// It's wasteful to use 4-byte wchar_t strings to carry UTF-16 data, and it's
// entirely improper on those systems where the encoding of wchar_t is defined
// as UTF-32.
//
// Here, we define string16, which is similar to std::wstring but replaces all
// libc functions with custom, 2-byte-char compatible routines. It is capable
// of carrying UTF-16-encoded data.
#include <stdio.h>
#include <string>
#include "include/base/cef_basictypes.h"
#if defined(WCHAR_T_IS_UTF16)
namespace base {
typedef wchar_t char16;
typedef std::wstring string16;
typedef std::char_traits<wchar_t> string16_char_traits;
} // namespace base
#elif defined(WCHAR_T_IS_UTF32)
#include <stdint.h> // For uint16_t
#include "include/base/cef_macros.h"
namespace cef {
namespace base {
typedef uint16_t char16;
// char16 versions of the functions required by string16_char_traits; these
// are based on the wide character functions of similar names ("w" or "wcs"
// instead of "c16").
int c16memcmp(const char16* s1, const char16* s2, size_t n);
size_t c16len(const char16* s);
const char16* c16memchr(const char16* s, char16 c, size_t n);
char16* c16memmove(char16* s1, const char16* s2, size_t n);
char16* c16memcpy(char16* s1, const char16* s2, size_t n);
char16* c16memset(char16* s, char16 c, size_t n);
struct string16_char_traits {
typedef char16 char_type;
typedef int int_type;
// int_type needs to be able to hold each possible value of char_type, and in
// addition, the distinct value of eof().
COMPILE_ASSERT(sizeof(int_type) > sizeof(char_type), unexpected_type_width);
typedef std::streamoff off_type;
typedef mbstate_t state_type;
typedef std::fpos<state_type> pos_type;
static void assign(char_type& c1, const char_type& c2) { c1 = c2; }
static bool eq(const char_type& c1, const char_type& c2) { return c1 == c2; }
static bool lt(const char_type& c1, const char_type& c2) { return c1 < c2; }
static int compare(const char_type* s1, const char_type* s2, size_t n) {
return c16memcmp(s1, s2, n);
}
static size_t length(const char_type* s) { return c16len(s); }
static const char_type* find(const char_type* s,
size_t n,
const char_type& a) {
return c16memchr(s, a, n);
}
static char_type* move(char_type* s1, const char_type* s2, int_type n) {
return c16memmove(s1, s2, n);
}
static char_type* copy(char_type* s1, const char_type* s2, size_t n) {
return c16memcpy(s1, s2, n);
}
static char_type* assign(char_type* s, size_t n, char_type a) {
return c16memset(s, a, n);
}
static int_type not_eof(const int_type& c) {
return eq_int_type(c, eof()) ? 0 : c;
}
static char_type to_char_type(const int_type& c) { return char_type(c); }
static int_type to_int_type(const char_type& c) { return int_type(c); }
static bool eq_int_type(const int_type& c1, const int_type& c2) {
return c1 == c2;
}
static int_type eof() { return static_cast<int_type>(EOF); }
};
typedef std::basic_string<char16, string16_char_traits> string16;
} // namespace base
} // namespace cef
namespace base {
typedef cef::base::char16 char16;
typedef cef::base::string16 string16;
extern std::ostream& operator<<(std::ostream& out, const string16& str);
// This is required by googletest to print a readable output on test failures.
extern void PrintTo(const string16& str, std::ostream* out);
} // namespace base
// The string class will be explicitly instantiated only once, in string16.cc.
//
// std::basic_string<> in GNU libstdc++ contains a static data member,
// _S_empty_rep_storage, to represent empty strings. When an operation such
// as assignment or destruction is performed on a string, causing its existing
// data member to be invalidated, it must not be freed if this static data
// member is being used. Otherwise, it counts as an attempt to free static
// (and not allocated) data, which is a memory error.
//
// Generally, due to C++ template magic, _S_empty_rep_storage will be marked
// as a coalesced symbol, meaning that the linker will combine multiple
// instances into a single one when generating output.
//
// If a string class is used by multiple shared libraries, a problem occurs.
// Each library will get its own copy of _S_empty_rep_storage. When strings
// are passed across a library boundary for alteration or destruction, memory
// errors will result. GNU libstdc++ contains a configuration option,
// --enable-fully-dynamic-string (_GLIBCXX_FULLY_DYNAMIC_STRING), which
// disables the static data member optimization, but it's a good optimization
// and non-STL code is generally at the mercy of the system's STL
// configuration. Fully-dynamic strings are not the default for GNU libstdc++
// libstdc++ itself or for the libstdc++ installations on the systems we care
// about, such as Mac OS X and relevant flavors of Linux.
//
// See also http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24196 .
//
// To avoid problems, string classes need to be explicitly instantiated only
// once, in exactly one library. All other string users see it via an "extern"
// declaration. This is precisely how GNU libstdc++ handles
// std::basic_string<char> (string) and std::basic_string<wchar_t> (wstring).
//
// This also works around a Mac OS X linker bug in ld64-85.2.1 (Xcode 3.1.2),
// in which the linker does not fully coalesce symbols when dead code
// stripping is enabled. This bug causes the memory errors described above
// to occur even when a std::basic_string<> does not cross shared library
// boundaries, such as in statically-linked executables.
//
// TODO(mark): File this bug with Apple and update this note with a bug number.
extern template class std::basic_string<cef::base::char16,
cef::base::string16_char_traits>;
#endif // WCHAR_T_IS_UTF32
#endif // !USING_CHROMIUM_INCLUDES
#endif // CEF_INCLUDE_BASE_CEF_STRING16_H_

View File

@@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=09b6ebd4116e983b4af634f1efa17b326a3fc517$
// $hash=92c4d38f6895018f72fbafeecb13c47320ef0b1d$
//
#ifndef CEF_INCLUDE_CAPI_CEF_BROWSER_CAPI_H_
@@ -139,7 +139,11 @@ typedef struct _cef_browser_t {
int(CEF_CALLBACK* has_document)(struct _cef_browser_t* self);
///
// Returns the main (top-level) frame for the browser window.
// Returns the main (top-level) frame for the browser window. In the browser
// process this will return a valid object until after
// cef_life_span_handler_t::OnBeforeClose is called. In the renderer process
// this will return NULL if the main frame is hosted in a different renderer
// process (e.g. for cross-origin sub-frames).
///
struct _cef_frame_t*(CEF_CALLBACK* get_main_frame)(
struct _cef_browser_t* self);

View File

@@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=f0cd169568e9ea5bcc8bf2aa891691b76c05356d$
// $hash=ade537f836add7fe0b5fd94ceba26d678abb3e43$
//
#ifndef CEF_INCLUDE_CAPI_CEF_BROWSER_PROCESS_HANDLER_CAPI_H_
@@ -43,7 +43,6 @@
#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"
#ifdef __cplusplus
@@ -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.
@@ -98,13 +78,6 @@ typedef struct _cef_browser_process_handler_t {
struct _cef_browser_process_handler_t* self,
struct _cef_command_line_t* command_line);
///
// Return the handler for printing on Linux. If a print handler is not
// provided then printing will not be supported on the Linux platform.
///
struct _cef_print_handler_t*(CEF_CALLBACK* get_print_handler)(
struct _cef_browser_process_handler_t* self);
///
// Called from any thread when work has been scheduled for the browser process
// main (UI) thread. This callback is used in combination with CefSettings.

View File

@@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=4cfcac55d2a1dee466a2a0753f30fb34a78ef3b2$
// $hash=14eca959988209ba8f95037a47192fd50d64f2f1$
//
#ifndef CEF_INCLUDE_CAPI_CEF_CLIENT_CAPI_H_
@@ -53,6 +53,7 @@
#include "include/capi/cef_keyboard_handler_capi.h"
#include "include/capi/cef_life_span_handler_capi.h"
#include "include/capi/cef_load_handler_capi.h"
#include "include/capi/cef_print_handler_capi.h"
#include "include/capi/cef_process_message_capi.h"
#include "include/capi/cef_render_handler_capi.h"
#include "include/capi/cef_request_handler_capi.h"
@@ -146,6 +147,13 @@ typedef struct _cef_client_t {
struct _cef_load_handler_t*(CEF_CALLBACK* get_load_handler)(
struct _cef_client_t* self);
///
// Return the handler for printing on Linux. If a print handler is not
// provided then printing will not be supported on the Linux platform.
///
struct _cef_print_handler_t*(CEF_CALLBACK* get_print_handler)(
struct _cef_client_t* self);
///
// Return the handler for off-screen rendering events.
///

View File

@@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=20ba58ac3e861344ee738b58433869223c757e24$
// $hash=b19ef1c8a781f8d59276357609fe64370bb8a107$
//
#ifndef CEF_INCLUDE_CAPI_CEF_COOKIE_CAPI_H_
@@ -61,21 +61,6 @@ typedef struct _cef_cookie_manager_t {
///
cef_base_ref_counted_t base;
///
// Set the schemes supported by this manager. If |include_defaults| is true
// (1) the default schemes ("http", "https", "ws" and "wss") will also be
// supported. Calling this function with an NULL |schemes| value and
// |include_defaults| set to false (0) will disable all loading and saving of
// cookies for this manager. If |callback| is non-NULL it will be executed
// asnychronously on the UI thread after the change has been applied. Must be
// called before any cookies are accessed.
///
void(CEF_CALLBACK* set_supported_schemes)(
struct _cef_cookie_manager_t* self,
cef_string_list_t schemes,
int include_defaults,
struct _cef_completion_callback_t* callback);
///
// Visit all cookies on the UI thread. The returned cookies are ordered by
// longest path, then by earliest creation date. Returns false (0) if cookies

View File

@@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=3767c7759578cd4abc1c2ecef504e7ed60775abb$
// $hash=79e4e38c732c0cfeef495c8a9726e105054012bb$
//
#ifndef CEF_INCLUDE_CAPI_CEF_MEDIA_ROUTER_CAPI_H_
@@ -41,6 +41,7 @@
#pragma once
#include "include/capi/cef_base_capi.h"
#include "include/capi/cef_callback_capi.h"
#include "include/capi/cef_registration_capi.h"
#ifdef __cplusplus
@@ -110,11 +111,14 @@ typedef struct _cef_media_router_t {
} cef_media_router_t;
///
// Returns the MediaRouter object associated with the global request context.
// Equivalent to calling cef_request_context_t::cef_request_context_get_global_c
// ontext()->get_media_router().
// Returns the MediaRouter object associated with the global request context. If
// |callback| is non-NULL it will be executed asnychronously on the UI thread
// after the manager's storage has been initialized. Equivalent to calling cef_r
// equest_context_t::cef_request_context_get_global_context()->get_media_router(
// ).
///
CEF_EXPORT cef_media_router_t* cef_media_router_get_global();
CEF_EXPORT cef_media_router_t* cef_media_router_get_global(
struct _cef_completion_callback_t* callback);
///
// Implemented by the client to observe MediaRouter events and registered via

View File

@@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=54ed1e16c5c1d133bcd097350c5f5871228efd4f$
// $hash=84fc58b3898f25476d9cdd260553390ba5e0b30b$
//
#ifndef CEF_INCLUDE_CAPI_CEF_PRINT_HANDLER_CAPI_H_
@@ -148,6 +148,7 @@ typedef struct _cef_print_handler_t {
///
cef_size_t(CEF_CALLBACK* get_pdf_paper_size)(
struct _cef_print_handler_t* self,
struct _cef_browser_t* browser,
int device_units_per_inch);
} cef_print_handler_t;

View File

@@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=d5079b6a5146ccd2085c3bbf948925c009d329ed$
// $hash=2e42334fc22050e207e5a0af6fe290a592e4105f$
//
#ifndef CEF_INCLUDE_CAPI_CEF_REQUEST_CONTEXT_CAPI_H_
@@ -132,7 +132,7 @@ typedef struct _cef_request_context_t {
///
// Returns the cookie manager for this object. If |callback| is non-NULL it
// will be executed asnychronously on the IO thread after the manager's
// will be executed asnychronously on the UI thread after the manager's
// storage has been initialized.
///
struct _cef_cookie_manager_t*(CEF_CALLBACK* get_cookie_manager)(
@@ -356,10 +356,13 @@ typedef struct _cef_request_context_t {
const cef_string_t* extension_id);
///
// Returns the MediaRouter object associated with this context.
// Returns the MediaRouter object associated with this context. If |callback|
// is non-NULL it will be executed asnychronously on the UI thread after the
// manager's context has been initialized.
///
struct _cef_media_router_t*(CEF_CALLBACK* get_media_router)(
struct _cef_request_context_t* self);
struct _cef_request_context_t* self,
struct _cef_completion_callback_t* callback);
} cef_request_context_t;
///

View File

@@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=d8b5b641cc036a9cd9375442254d558b066ada69$
// $hash=f74bf4d33914d56d760f1bf5aadcf2651740c711$
//
#ifndef CEF_INCLUDE_CAPI_CEF_WEB_PLUGIN_CAPI_H_
@@ -214,7 +214,7 @@ CEF_EXPORT void cef_is_web_plugin_unstable(
// D. "x-cdm-interface-versions": Interface API version (e.g. "8").
// E. "x-cdm-host-versions": Host API version (e.g. "8").
// F. "version": CDM version (e.g. "1.4.8.903").
// G. "x-cdm-codecs": List of supported codecs (e.g. "vp8,vp9.0,avc1").
// G. "x-cdm-codecs": List of supported codecs (e.g. "vp8,vp09,avc1").
//
// A through E are used to verify compatibility with the current Chromium
// version. If the CDM is not compatible the registration will fail and

View File

@@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=0fbd582ed5d0231550840ebf3eed2e488ac546d4$
// $hash=3e4eb9ed3a0cb28ae0459a50f20c8405c7722437$
//
#ifndef CEF_INCLUDE_CAPI_VIEWS_CEF_BROWSER_VIEW_CAPI_H_
@@ -65,6 +65,17 @@ typedef struct _cef_browser_view_t {
struct _cef_browser_t*(CEF_CALLBACK* get_browser)(
struct _cef_browser_view_t* self);
///
// Returns the Chrome toolbar associated with this BrowserView. Only supported
// when using the Chrome runtime. The cef_browser_view_delegate_t::
// get_chrome_toolbar_type() function must return a value other than
// CEF_CTT_NONE and the toolbar will not be available until after this
// BrowserView is added to a cef_window_t and
// cef_view_delegate_t::on_window_changed() has been called.
///
struct _cef_view_t*(CEF_CALLBACK* get_chrome_toolbar)(
struct _cef_browser_view_t* self);
///
// Sets whether accelerators registered with cef_window_t::SetAccelerator are
// triggered before or after the event is sent to the cef_browser_t. If

View File

@@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=37bbfadf761b3a1996276885d593d27d3fed5f8d$
// $hash=220a126af3682f716f10b9019e8d1461702aa7c9$
//
#ifndef CEF_INCLUDE_CAPI_VIEWS_CEF_BROWSER_VIEW_DELEGATE_CAPI_H_
@@ -112,6 +112,14 @@ typedef struct _cef_browser_view_delegate_t {
struct _cef_browser_view_t* browser_view,
struct _cef_browser_view_t* popup_browser_view,
int is_devtools);
///
// Returns the Chrome toolbar type that will be available via
// cef_browser_view_t::get_chrome_toolbar(). See that function for related
// documentation.
///
cef_chrome_toolbar_type_t(CEF_CALLBACK* get_chrome_toolbar_type)(
struct _cef_browser_view_delegate_t* self);
} cef_browser_view_delegate_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=8bd92dd03af4f5cf8c359c45a2d6d013565c2ead$
// $hash=a060cb3c53317d758e7f6b4a275288cd08f086e7$
//
#ifndef CEF_INCLUDE_CAPI_VIEWS_CEF_VIEW_DELEGATE_CAPI_H_
@@ -114,6 +114,13 @@ typedef struct _cef_view_delegate_t {
int added,
struct _cef_view_t* child);
///
// Called when |view| is added or removed from the cef_window_t.
///
void(CEF_CALLBACK* on_window_changed)(struct _cef_view_delegate_t* self,
struct _cef_view_t* view,
int added);
///
// Called when |view| gains focus.
///

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 "694bc8d68956bd174529f72fea5710929ac8bbf0"
#define CEF_API_HASH_UNIVERSAL "d026196d35d8894a836ab3a3d033b84195cdb835"
#if defined(OS_WIN)
#define CEF_API_HASH_PLATFORM "597ae4ad020de2665469e7de990d784bfda8d514"
#define CEF_API_HASH_PLATFORM "4150bd26e7bf639a9b1f3e5860af8c76eeae8570"
#elif defined(OS_MAC)
#define CEF_API_HASH_PLATFORM "fa3b4a918791bf53a4a8715ac9f0c843a3c08061"
#define CEF_API_HASH_PLATFORM "5cc32f88bd134410eff86b21095138b339d572f2"
#elif defined(OS_LINUX)
#define CEF_API_HASH_PLATFORM "83ff6d6fb2e0ac8447f68fa6141091cc9f666ca0"
#define CEF_API_HASH_PLATFORM "b227b3fdd6142a9d8ff0f2252a71425f15960800"
#endif
#ifdef __cplusplus

View File

@@ -142,7 +142,11 @@ class CefBrowser : public virtual CefBaseRefCounted {
virtual bool HasDocument() = 0;
///
// Returns the main (top-level) frame for the browser window.
// Returns the main (top-level) frame for the browser window. In the browser
// process this will return a valid object until after
// CefLifeSpanHandler::OnBeforeClose is called. In the renderer process this
// will return NULL if the main frame is hosted in a different renderer
// process (e.g. for cross-origin sub-frames).
///
/*--cef()--*/
virtual CefRefPtr<CefFrame> GetMainFrame() = 0;

View File

@@ -41,7 +41,6 @@
#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.
@@ -86,13 +68,6 @@ class CefBrowserProcessHandler : public virtual CefBaseRefCounted {
virtual void OnBeforeChildProcessLaunch(
CefRefPtr<CefCommandLine> command_line) {}
///
// Return the handler for printing on Linux. If a print handler is not
// provided then printing will not be supported on the Linux platform.
///
/*--cef()--*/
virtual CefRefPtr<CefPrintHandler> GetPrintHandler() { return nullptr; }
///
// Called from any thread when work has been scheduled for the browser process
// main (UI) thread. This callback is used in combination with CefSettings.

View File

@@ -51,6 +51,7 @@
#include "include/cef_keyboard_handler.h"
#include "include/cef_life_span_handler.h"
#include "include/cef_load_handler.h"
#include "include/cef_print_handler.h"
#include "include/cef_process_message.h"
#include "include/cef_render_handler.h"
#include "include/cef_request_handler.h"
@@ -139,6 +140,13 @@ class CefClient : public virtual CefBaseRefCounted {
/*--cef()--*/
virtual CefRefPtr<CefLoadHandler> GetLoadHandler() { return nullptr; }
///
// Return the handler for printing on Linux. If a print handler is not
// provided then printing will not be supported on the Linux platform.
///
/*--cef()--*/
virtual CefRefPtr<CefPrintHandler> GetPrintHandler() { return nullptr; }
///
// Return the handler for off-screen rendering events.
///

View File

@@ -64,21 +64,6 @@ class CefCookieManager : public virtual CefBaseRefCounted {
static CefRefPtr<CefCookieManager> GetGlobalManager(
CefRefPtr<CefCompletionCallback> callback);
///
// Set the schemes supported by this manager. If |include_defaults| is true
// the default schemes ("http", "https", "ws" and "wss") will also be
// supported. Calling this method with an empty |schemes| value and
// |include_defaults| set to false will disable all loading and saving of
// cookies for this manager. If |callback| is non-NULL it will be executed
// asnychronously on the UI thread after the change has been applied. Must be
// called before any cookies are accessed.
///
/*--cef(optional_param=callback)--*/
virtual void SetSupportedSchemes(
const std::vector<CefString>& schemes,
bool include_defaults,
CefRefPtr<CefCompletionCallback> callback) = 0;
///
// Visit all cookies on the UI thread. The returned cookies are ordered by
// longest path, then by earliest creation date. Returns false if cookies

View File

@@ -40,6 +40,7 @@
#include <vector>
#include "include/cef_base.h"
#include "include/cef_callback.h"
#include "include/cef_registration.h"
class CefMediaObserver;
@@ -59,11 +60,13 @@ class CefMediaRouter : public virtual CefBaseRefCounted {
public:
///
// Returns the MediaRouter object associated with the global request context.
// Equivalent to calling
// CefRequestContext::GetGlobalContext()->GetMediaRouter().
// If |callback| is non-NULL it will be executed asnychronously on the UI
// thread after the manager's storage has been initialized. Equivalent to
// calling CefRequestContext::GetGlobalContext()->GetMediaRouter().
///
/*--cef()--*/
static CefRefPtr<CefMediaRouter> GetGlobalMediaRouter();
/*--cef(optional_param=callback)--*/
static CefRefPtr<CefMediaRouter> GetGlobalMediaRouter(
CefRefPtr<CefCompletionCallback> callback);
///
// Add an observer for MediaRouter events. The observer will remain registered

View File

@@ -133,7 +133,8 @@ class CefPrintHandler : public virtual CefBaseRefCounted {
// CefBrowserHost::PrintToPDF().
///
/*--cef()--*/
virtual CefSize GetPdfPaperSize(int device_units_per_inch) {
virtual CefSize GetPdfPaperSize(CefRefPtr<CefBrowser> browser,
int device_units_per_inch) {
return CefSize();
}
};

View File

@@ -146,7 +146,7 @@ class CefRequestContext : public virtual CefBaseRefCounted {
///
// Returns the cookie manager for this object. If |callback| is non-NULL it
// will be executed asnychronously on the IO thread after the manager's
// will be executed asnychronously on the UI thread after the manager's
// storage has been initialized.
///
/*--cef(optional_param=callback)--*/
@@ -364,10 +364,13 @@ class CefRequestContext : public virtual CefBaseRefCounted {
const CefString& extension_id) = 0;
///
// Returns the MediaRouter object associated with this context.
// Returns the MediaRouter object associated with this context. If |callback|
// is non-NULL it will be executed asnychronously on the UI thread after the
// manager's context has been initialized.
///
/*--cef()--*/
virtual CefRefPtr<CefMediaRouter> GetMediaRouter() = 0;
/*--cef(optional_param=callback)--*/
virtual CefRefPtr<CefMediaRouter> GetMediaRouter(
CefRefPtr<CefCompletionCallback> callback) = 0;
};
#endif // CEF_INCLUDE_CEF_REQUEST_CONTEXT_H_

View File

@@ -191,7 +191,7 @@ class CefRegisterCdmCallback : public virtual CefBaseRefCounted {
// D. "x-cdm-interface-versions": Interface API version (e.g. "8").
// E. "x-cdm-host-versions": Host API version (e.g. "8").
// F. "version": CDM version (e.g. "1.4.8.903").
// G. "x-cdm-codecs": List of supported codecs (e.g. "vp8,vp9.0,avc1").
// G. "x-cdm-codecs": List of supported codecs (e.g. "vp8,vp09,avc1").
//
// A through E are used to verify compatibility with the current Chromium
// version. If the CDM is not compatible the registration will fail and

View File

@@ -34,7 +34,6 @@
#include <memory.h>
#include <string>
#include "include/base/cef_string16.h"
#include "include/internal/cef_string_types.h"
#if defined(USING_CHROMIUM_INCLUDES)
@@ -91,32 +90,34 @@ struct CefStringTraitsWide {
: false;
}
#if defined(WCHAR_T_IS_UTF32)
static inline base::string16 to_string16(const struct_type* s) {
static inline std::u16string to_string16(const struct_type* s) {
cef_string_utf16_t cstr;
memset(&cstr, 0, sizeof(cstr));
cef_string_wide_to_utf16(s->str, s->length, &cstr);
base::string16 str;
std::u16string str;
if (cstr.length > 0) {
str = base::string16(
reinterpret_cast<base::string16::value_type*>(cstr.str), cstr.length);
str = std::u16string(
reinterpret_cast<std::u16string::value_type*>(cstr.str), cstr.length);
}
cef_string_utf16_clear(&cstr);
return str;
}
static inline bool from_string16(const base::string16& str, struct_type* s) {
static inline bool from_string16(const std::u16string& str, struct_type* s) {
return cef_string_utf16_to_wide(
reinterpret_cast<const char16*>(str.c_str()), str.length(), s)
? true
: false;
}
#else // WCHAR_T_IS_UTF32
static inline base::string16 to_string16(const struct_type* s) {
return base::string16(
reinterpret_cast<const base::string16::value_type*>(s->str), s->length);
static inline std::u16string to_string16(const struct_type* s) {
return std::u16string(
reinterpret_cast<const std::u16string::value_type*>(s->str), s->length);
}
static inline bool from_string16(const base::string16& str, struct_type* s) {
return cef_string_wide_set(str.c_str(), str.length(), s, true) ? true
: false;
static inline bool from_string16(const std::u16string& str, struct_type* s) {
return cef_string_wide_set(reinterpret_cast<const wchar_t*>(str.c_str()),
str.length(), s, true)
? true
: false;
}
#endif // WCHAR_T_IS_UTF32
};
@@ -169,19 +170,19 @@ struct CefStringTraitsUTF8 {
static inline bool from_wstring(const std::wstring& str, struct_type* s) {
return cef_string_wide_to_utf8(str.c_str(), str.length(), s) ? true : false;
}
static inline base::string16 to_string16(const struct_type* s) {
static inline std::u16string to_string16(const struct_type* s) {
cef_string_utf16_t cstr;
memset(&cstr, 0, sizeof(cstr));
cef_string_utf8_to_utf16(s->str, s->length, &cstr);
base::string16 str;
std::u16string str;
if (cstr.length > 0) {
str = base::string16(
reinterpret_cast<base::string16::value_type*>(cstr.str), cstr.length);
str = std::u16string(
reinterpret_cast<std::u16string::value_type*>(cstr.str), cstr.length);
}
cef_string_utf16_clear(&cstr);
return str;
}
static inline bool from_string16(const base::string16& str, struct_type* s) {
static inline bool from_string16(const std::u16string& str, struct_type* s) {
return cef_string_utf16_to_utf8(
reinterpret_cast<const char16*>(str.c_str()), str.length(), s)
? true
@@ -256,11 +257,11 @@ struct CefStringTraitsUTF16 {
: false;
}
#endif // WCHAR_T_IS_UTF32
static inline base::string16 to_string16(const struct_type* s) {
return base::string16(
reinterpret_cast<const base::string16::value_type*>(s->str), s->length);
static inline std::u16string to_string16(const struct_type* s) {
return std::u16string(
reinterpret_cast<const std::u16string::value_type*>(s->str), s->length);
}
static inline bool from_string16(const base::string16& str, struct_type* s) {
static inline bool from_string16(const std::u16string& str, struct_type* s) {
return cef_string_utf16_set(reinterpret_cast<const char16*>(str.c_str()),
str.length(), s, true)
? true
@@ -341,19 +342,25 @@ class CefStringBase {
FromWString(std::wstring(src));
}
#if defined(WCHAR_T_IS_UTF32)
///
// Create a new string from an existing string16. Data will be always
// copied. Translation will occur if necessary based on the underlying string
// type.
///
CefStringBase(const base::string16& src) : string_(NULL), owner_(false) {
CefStringBase(const std::u16string& src) : string_(NULL), owner_(false) {
FromString16(src);
}
CefStringBase(const char16* src) : string_(NULL), owner_(false) {
CefStringBase(const std::u16string::value_type* src)
: string_(NULL), owner_(false) {
if (src)
FromString16(base::string16(
reinterpret_cast<const base::string16::value_type*>(src)));
FromString16(std::u16string(src));
}
#if defined(WCHAR_T_IS_UTF32)
CefStringBase(const char16* src) : string_(NULL), owner_(false) {
if (src) {
FromString16(std::u16string(
reinterpret_cast<const std::u16string::value_type*>(src)));
}
}
#endif // WCHAR_T_IS_UTF32
@@ -620,9 +627,9 @@ class CefStringBase {
// Return this string's data as a string16. Translation will occur if
// necessary based on the underlying string type.
///
base::string16 ToString16() const {
std::u16string ToString16() const {
if (empty())
return base::string16();
return std::u16string();
return traits::to_string16(string_);
}
@@ -631,7 +638,7 @@ class CefStringBase {
// copied. Translation will occur if necessary based on the underlying string
// type.
///
bool FromString16(const base::string16& str) {
bool FromString16(const std::u16string& str) {
if (str.empty()) {
clear();
return true;
@@ -683,15 +690,19 @@ class CefStringBase {
FromWString(std::wstring(str));
return *this;
}
#if defined(WCHAR_T_IS_UTF32)
operator base::string16() const { return ToString16(); }
CefStringBase& operator=(const base::string16& str) {
operator std::u16string() const { return ToString16(); }
CefStringBase& operator=(const std::u16string& str) {
FromString16(str);
return *this;
}
CefStringBase& operator=(const std::u16string::value_type* str) {
FromString16(std::u16string(str));
return *this;
}
#if defined(WCHAR_T_IS_UTF32)
CefStringBase& operator=(const char16* str) {
FromString16(base::string16(
reinterpret_cast<const base::string16::value_type*>(str)));
FromString16(std::u16string(
reinterpret_cast<const std::u16string::value_type*>(str)));
return *this;
}
#endif // WCHAR_T_IS_UTF32

View File

@@ -242,7 +242,9 @@ typedef struct _cef_settings_t {
// in-memory caches are used for storage and no data is persisted to disk.
// HTML5 databases such as localStorage will only persist across sessions if a
// cache path is specified. Can be overridden for individual CefRequestContext
// instances via the CefRequestContextSettings.cache_path value.
// instances via the CefRequestContextSettings.cache_path value. When using
// the Chrome runtime the "default" profile will be used if |cache_path| and
// |root_cache_path| have the same value.
///
cef_string_t cache_path;
@@ -264,7 +266,8 @@ typedef struct _cef_settings_t {
// directory on Linux, "~/Library/Application Support/CEF/User Data" directory
// on Mac OS X, "Local Settings\Application Data\CEF\User Data" directory
// under the user profile directory on Windows). If this value is non-empty
// then it must be an absolute path.
// then it must be an absolute path. When using the Chrome runtime this value
// will be ignored in favor of the |root_cache_path| value.
///
cef_string_t user_data_path;
@@ -301,9 +304,9 @@ typedef struct _cef_settings_t {
// Value that will be inserted as the product portion of the default
// User-Agent string. If empty the Chromium product version will be used. If
// |userAgent| is specified this value will be ignored. Also configurable
// using the "product-version" command-line switch.
// using the "user-agent-product" command-line switch.
///
cef_string_t product_version;
cef_string_t user_agent_product;
///
// The locale string that will be passed to WebKit. If empty the default
@@ -419,6 +422,20 @@ typedef struct _cef_settings_t {
///
cef_string_t accept_language_list;
///
// Comma delimited list of schemes supported by the associated
// CefCookieManager. If |cookieable_schemes_exclude_defaults| is false (0) the
// default schemes ("http", "https", "ws" and "wss") will also be supported.
// Specifying a |cookieable_schemes_list| value and setting
// |cookieable_schemes_exclude_defaults| to true (1) will disable all loading
// and saving of cookies for this manager. Can be overridden
// for individual CefRequestContext instances via the
// CefRequestContextSettings.cookieable_schemes_list and
// CefRequestContextSettings.cookieable_schemes_exclude_defaults values.
///
cef_string_t cookieable_schemes_list;
int cookieable_schemes_exclude_defaults;
///
// GUID string used for identifying the application. This is passed to the
// system AV function for scanning downloaded files. By default, the GUID
@@ -487,6 +504,18 @@ typedef struct _cef_request_context_settings_t {
// ignored if |cache_path| matches the CefSettings.cache_path value.
///
cef_string_t accept_language_list;
///
// Comma delimited list of schemes supported by the associated
// CefCookieManager. If |cookieable_schemes_exclude_defaults| is false (0) the
// default schemes ("http", "https", "ws" and "wss") will also be supported.
// Specifying a |cookieable_schemes_list| value and setting
// |cookieable_schemes_exclude_defaults| to true (1) will disable all loading
// and saving of cookies for this manager. These values will be ignored if
// |cache_path| matches the CefSettings.cache_path value.
///
cef_string_t cookieable_schemes_list;
int cookieable_schemes_exclude_defaults;
} cef_request_context_settings_t;
///
@@ -585,14 +614,6 @@ typedef struct _cef_browser_settings_t {
///
cef_state_t file_access_from_file_urls;
///
// Controls whether web security restrictions (same-origin policy) will be
// enforced. Disabling this setting is not recommend as it will allow risky
// security behavior such as cross-site scripting (XSS). Also configurable
// using the "disable-web-security" command-line switch.
///
cef_state_t web_security;
///
// Controls whether image URLs will be loaded from the network. A cached image
// will still be rendered if requested. Also configurable using the
@@ -659,7 +680,7 @@ typedef struct _cef_browser_settings_t {
///
// Comma delimited ordered list of language codes without any whitespace that
// will be used in the "Accept-Language" HTTP header. May be set globally
// using the CefBrowserSettings.accept_language_list value. If both values are
// using the CefSettings.accept_language_list value. If both values are
// empty then "en-US,en" will be used.
///
cef_string_t accept_language_list;
@@ -3193,6 +3214,15 @@ typedef enum {
CEF_TFC_SELECT_ALL,
} cef_text_field_commands_t;
///
// Supported Chrome toolbar types.
///
typedef enum {
CEF_CTT_NONE = 1,
CEF_CTT_NORMAL,
CEF_CTT_LOCATION,
} cef_chrome_toolbar_type_t;
#ifdef __cplusplus
}
#endif

View File

@@ -151,10 +151,9 @@ class CefPoint : public CefStructBase<CefPointTraits> {
public:
typedef CefStructBase<CefPointTraits> parent;
CefPoint() : parent() {}
CefPoint() {}
CefPoint(const cef_point_t& r) : parent(r) {}
CefPoint(const CefPoint& r) : parent(r) {}
CefPoint(int x, int y) : parent() { Set(x, y); }
CefPoint(int x, int y) { Set(x, y); }
bool IsEmpty() const { return x <= 0 && y <= 0; }
void Set(int x_val, int y_val) { x = x_val, y = y_val; }
@@ -188,12 +187,9 @@ class CefRect : public CefStructBase<CefRectTraits> {
public:
typedef CefStructBase<CefRectTraits> parent;
CefRect() : parent() {}
CefRect() {}
CefRect(const cef_rect_t& r) : parent(r) {}
CefRect(const CefRect& r) : parent(r) {}
CefRect(int x, int y, int width, int height) : parent() {
Set(x, y, width, height);
}
CefRect(int x, int y, int width, int height) { Set(x, y, width, height); }
bool IsEmpty() const { return width <= 0 || height <= 0; }
void Set(int x_val, int y_val, int width_val, int height_val) {
@@ -240,10 +236,9 @@ class CefSize : public CefStructBase<CefSizeTraits> {
public:
typedef CefStructBase<CefSizeTraits> parent;
CefSize() : parent() {}
CefSize() {}
CefSize(const cef_size_t& r) : parent(r) {}
CefSize(const CefSize& r) : parent(r) {}
CefSize(int width, int height) : parent() { Set(width, height); }
CefSize(int width, int height) { Set(width, height); }
bool IsEmpty() const { return width <= 0 || height <= 0; }
void Set(int width_val, int height_val) {
@@ -279,10 +274,9 @@ class CefRange : public CefStructBase<CefRangeTraits> {
public:
typedef CefStructBase<CefRangeTraits> parent;
CefRange() : parent() {}
CefRange() {}
CefRange(const cef_range_t& r) : parent(r) {}
CefRange(const CefRange& r) : parent(r) {}
CefRange(int from, int to) : parent() { Set(from, to); }
CefRange(int from, int to) { Set(from, to); }
void Set(int from_val, int to_val) { from = from_val, to = to_val; }
};
@@ -315,10 +309,9 @@ class CefInsets : public CefStructBase<CefInsetsTraits> {
public:
typedef CefStructBase<CefInsetsTraits> parent;
CefInsets() : parent() {}
CefInsets() {}
CefInsets(const cef_insets_t& r) : parent(r) {}
CefInsets(const CefInsets& r) : parent(r) {}
CefInsets(int top, int left, int bottom, int right) : parent() {
CefInsets(int top, int left, int bottom, int right) {
Set(top, left, bottom, right);
}
@@ -356,10 +349,9 @@ class CefDraggableRegion : public CefStructBase<CefDraggableRegionTraits> {
public:
typedef CefStructBase<CefDraggableRegionTraits> parent;
CefDraggableRegion() : parent() {}
CefDraggableRegion() {}
CefDraggableRegion(const cef_draggable_region_t& r) : parent(r) {}
CefDraggableRegion(const CefDraggableRegion& r) : parent(r) {}
CefDraggableRegion(const CefRect& bounds, bool draggable) : parent() {
CefDraggableRegion(const CefRect& bounds, bool draggable) {
Set(bounds, draggable);
}
@@ -405,16 +397,14 @@ class CefScreenInfo : public CefStructBase<CefScreenInfoTraits> {
public:
typedef CefStructBase<CefScreenInfoTraits> parent;
CefScreenInfo() : parent() {}
CefScreenInfo() {}
CefScreenInfo(const cef_screen_info_t& r) : parent(r) {}
CefScreenInfo(const CefScreenInfo& r) : parent(r) {}
CefScreenInfo(float device_scale_factor,
int depth,
int depth_per_component,
bool is_monochrome,
const CefRect& rect,
const CefRect& available_rect)
: parent() {
const CefRect& available_rect) {
Set(device_scale_factor, depth, depth_per_component, is_monochrome, rect,
available_rect);
}
@@ -548,13 +538,14 @@ struct CefSettingsTraits {
cef_string_clear(&s->root_cache_path);
cef_string_clear(&s->user_data_path);
cef_string_clear(&s->user_agent);
cef_string_clear(&s->product_version);
cef_string_clear(&s->user_agent_product);
cef_string_clear(&s->locale);
cef_string_clear(&s->log_file);
cef_string_clear(&s->javascript_flags);
cef_string_clear(&s->resources_dir_path);
cef_string_clear(&s->locales_dir_path);
cef_string_clear(&s->accept_language_list);
cef_string_clear(&s->cookieable_schemes_list);
cef_string_clear(&s->application_client_id_for_file_scanning);
}
@@ -586,8 +577,8 @@ struct CefSettingsTraits {
cef_string_set(src->user_agent.str, src->user_agent.length,
&target->user_agent, copy);
cef_string_set(src->product_version.str, src->product_version.length,
&target->product_version, copy);
cef_string_set(src->user_agent_product.str, src->user_agent_product.length,
&target->user_agent_product, copy);
cef_string_set(src->locale.str, src->locale.length, &target->locale, copy);
cef_string_set(src->log_file.str, src->log_file.length, &target->log_file,
@@ -609,6 +600,13 @@ struct CefSettingsTraits {
cef_string_set(src->accept_language_list.str,
src->accept_language_list.length,
&target->accept_language_list, copy);
cef_string_set(src->cookieable_schemes_list.str,
src->cookieable_schemes_list.length,
&target->cookieable_schemes_list, copy);
target->cookieable_schemes_exclude_defaults =
src->cookieable_schemes_exclude_defaults;
cef_string_set(src->application_client_id_for_file_scanning.str,
src->application_client_id_for_file_scanning.length,
&target->application_client_id_for_file_scanning, copy);
@@ -628,6 +626,7 @@ struct CefRequestContextSettingsTraits {
static inline void clear(struct_type* s) {
cef_string_clear(&s->cache_path);
cef_string_clear(&s->accept_language_list);
cef_string_clear(&s->cookieable_schemes_list);
}
static inline void set(const struct_type* src,
@@ -641,6 +640,12 @@ struct CefRequestContextSettingsTraits {
cef_string_set(src->accept_language_list.str,
src->accept_language_list.length,
&target->accept_language_list, copy);
cef_string_set(src->cookieable_schemes_list.str,
src->cookieable_schemes_list.length,
&target->cookieable_schemes_list, copy);
target->cookieable_schemes_exclude_defaults =
src->cookieable_schemes_exclude_defaults;
}
};
@@ -705,7 +710,6 @@ struct CefBrowserSettingsTraits {
target->universal_access_from_file_urls =
src->universal_access_from_file_urls;
target->file_access_from_file_urls = src->file_access_from_file_urls;
target->web_security = src->web_security;
target->image_loading = src->image_loading;
target->image_shrink_standalone_to_fit =
src->image_shrink_standalone_to_fit;
@@ -792,11 +796,10 @@ class CefTime : public CefStructBase<CefTimeTraits> {
public:
typedef CefStructBase<CefTimeTraits> parent;
CefTime() : parent() {}
CefTime() {}
CefTime(const cef_time_t& r) : parent(r) {}
CefTime(const CefTime& r) : parent(r) {}
explicit CefTime(time_t r) : parent() { SetTimeT(r); }
explicit CefTime(double r) : parent() { SetDoubleT(r); }
explicit CefTime(time_t r) { SetTimeT(r); }
explicit CefTime(double r) { SetDoubleT(r); }
// Converts to/from time_t.
void SetTimeT(time_t r) { cef_time_from_timet(r, this); }

View File

@@ -80,6 +80,17 @@ class CefBrowserView : public CefView {
/*--cef()--*/
virtual CefRefPtr<CefBrowser> GetBrowser() = 0;
///
// Returns the Chrome toolbar associated with this BrowserView. Only supported
// when using the Chrome runtime. The CefBrowserViewDelegate::
// GetChromeToolbarType() method must return a value other than
// CEF_CTT_NONE and the toolbar will not be available until after this
// BrowserView is added to a CefWindow and CefViewDelegate::OnWindowChanged()
// has been called.
///
/*--cef()--*/
virtual CefRefPtr<CefView> GetChromeToolbar() = 0;
///
// Sets whether accelerators registered with CefWindow::SetAccelerator are
// triggered before or after the event is sent to the CefBrowser. If

View File

@@ -52,6 +52,8 @@ class CefBrowserView;
/*--cef(source=client)--*/
class CefBrowserViewDelegate : public CefViewDelegate {
public:
typedef cef_chrome_toolbar_type_t ChromeToolbarType;
///
// Called when |browser| associated with |browser_view| is created. This
// method will be called after CefLifeSpanHandler::OnAfterCreated() is called
@@ -104,6 +106,14 @@ class CefBrowserViewDelegate : public CefViewDelegate {
bool is_devtools) {
return false;
}
///
// Returns the Chrome toolbar type that will be available via
// CefBrowserView::GetChromeToolbar(). See that method for related
// documentation.
///
/*--cef(default_retval=CEF_CTT_NONE)--*/
virtual ChromeToolbarType GetChromeToolbarType() { return CEF_CTT_NONE; }
};
#endif // CEF_INCLUDE_VIEWS_CEF_BROWSER_VIEW_DELEGATE_H_

View File

@@ -105,6 +105,12 @@ class CefViewDelegate : public virtual CefBaseRefCounted {
bool added,
CefRefPtr<CefView> child) {}
///
// Called when |view| is added or removed from the CefWindow.
///
/*--cef(optional_param=window)--*/
virtual void OnWindowChanged(CefRefPtr<CefView> view, bool added) {}
///
// Called when |view| gains focus.
///

View File

@@ -113,6 +113,18 @@ AlloyBrowserContext::~AlloyBrowserContext() {
}
}
bool AlloyBrowserContext::IsInitialized() const {
CEF_REQUIRE_UIT();
return !!key_;
}
void AlloyBrowserContext::StoreOrTriggerInitCallback(
base::OnceClosure callback) {
CEF_REQUIRE_UIT();
// Initialization is always synchronous.
std::move(callback).Run();
}
void AlloyBrowserContext::Initialize() {
CefBrowserContext::Initialize();
@@ -297,16 +309,6 @@ AlloyBrowserContext::GetClientHintsControllerDelegate() {
return nullptr;
}
void AlloyBrowserContext::SetCorsOriginAccessListForOrigin(
TargetBrowserContexts target_mode,
const url::Origin& source_origin,
std::vector<network::mojom::CorsOriginPatternPtr> allow_patterns,
std::vector<network::mojom::CorsOriginPatternPtr> block_patterns,
base::OnceClosure closure) {
// This method is called for Extension support.
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, std::move(closure));
}
ChromeZoomLevelPrefs* AlloyBrowserContext::GetZoomLevelPrefs() {
return static_cast<ChromeZoomLevelPrefs*>(
GetStoragePartition(this, nullptr)->GetZoomLevelDelegate());

View File

@@ -42,6 +42,8 @@ class AlloyBrowserContext : public ChromeProfileAlloy,
// CefBrowserContext overrides.
content::BrowserContext* AsBrowserContext() override { return this; }
Profile* AsProfile() override { return this; }
bool IsInitialized() const override;
void StoreOrTriggerInitCallback(base::OnceClosure callback) override;
void Initialize() override;
void Shutdown() override;
void RemoveCefRequestContext(CefRequestContextImpl* context) override;
@@ -58,12 +60,6 @@ class AlloyBrowserContext : public ChromeProfileAlloy,
content::ResourceContext* GetResourceContext() override;
content::ClientHintsControllerDelegate* GetClientHintsControllerDelegate()
override;
void SetCorsOriginAccessListForOrigin(
TargetBrowserContexts target_mode,
const url::Origin& source_origin,
std::vector<network::mojom::CorsOriginPatternPtr> allow_patterns,
std::vector<network::mojom::CorsOriginPatternPtr> block_patterns,
base::OnceClosure closure) override;
base::FilePath GetPath() override;
base::FilePath GetPath() const override;
std::unique_ptr<content::ZoomLevelDelegate> CreateZoomLevelDelegate(

View File

@@ -24,6 +24,7 @@
#include "libcef/common/cef_messages.h"
#include "libcef/common/cef_switches.h"
#include "libcef/common/drag_data_impl.h"
#include "libcef/common/net/url_util.h"
#include "libcef/common/request_impl.h"
#include "libcef/common/values_impl.h"
#include "libcef/features/runtime_checks.h"
@@ -175,12 +176,13 @@ CefRefPtr<AlloyBrowserHostImpl> AlloyBrowserHostImpl::Create(
if (!browser)
return nullptr;
GURL url = url_util::MakeGURL(create_params.url, /*fixup=*/true);
if (create_params.extension) {
platform_delegate_ptr->CreateExtensionHost(
create_params.extension, create_params.url,
create_params.extension_host_type);
} else if (!create_params.url.is_empty()) {
content::OpenURLParams params(create_params.url, content::Referrer(),
create_params.extension, url, create_params.extension_host_type);
} else if (!url.is_empty()) {
content::OpenURLParams params(url, content::Referrer(),
WindowOpenDisposition::CURRENT_TAB,
CefFrameHostImpl::kPageTransitionExplicit,
/*is_renderer_initiated=*/false);
@@ -810,12 +812,6 @@ bool AlloyBrowserHostImpl::MaybeAllowNavigation(
return true;
}
SkColor AlloyBrowserHostImpl::GetBackgroundColor() const {
// Don't use |platform_delegate_| because it's not thread-safe.
return CefContext::Get()->GetBackgroundColor(
&settings_, is_windowless_ ? STATE_ENABLED : STATE_DISABLED);
}
extensions::ExtensionHost* AlloyBrowserHostImpl::GetExtensionHost() const {
CEF_REQUIRE_UIT();
DCHECK(platform_delegate_);
@@ -1195,9 +1191,9 @@ void AlloyBrowserHostImpl::UpdateTargetURL(content::WebContents* source,
bool AlloyBrowserHostImpl::DidAddMessageToConsole(
content::WebContents* source,
blink::mojom::ConsoleMessageLevel level,
const base::string16& message,
const std::u16string& message,
int32_t line_no,
const base::string16& source_id) {
const std::u16string& source_id) {
return contents_delegate_->DidAddMessageToConsole(source, level, message,
line_no, source_id);
}

View File

@@ -22,12 +22,11 @@
#include "libcef/browser/menu_manager.h"
#include "libcef/browser/request_context_impl.h"
#include "base/strings/string16.h"
#include "base/synchronization/lock.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"
#include "extensions/common/mojom/view_type.mojom-forward.h"
class CefAudioCapturer;
class CefBrowserInfo;
@@ -151,7 +150,7 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
bool IsBackgroundHost() override;
// Returns true if windowless rendering is enabled.
bool IsWindowless() const;
bool IsWindowless() const override;
// Returns true if this browser supports picture-in-picture.
bool IsPictureInPictureSupported() const;
@@ -182,9 +181,6 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
content::RenderWidgetHostImpl* source_rwh);
void UpdateDragCursor(ui::mojom::DragOperation operation);
// Thread safe accessors.
SkColor GetBackgroundColor() const;
// Accessors that must be called on the UI thread.
extensions::ExtensionHost* GetExtensionHost() const;
@@ -225,9 +221,9 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
void UpdateTargetURL(content::WebContents* source, const GURL& url) override;
bool DidAddMessageToConsole(content::WebContents* source,
blink::mojom::ConsoleMessageLevel log_level,
const base::string16& message,
const std::u16string& message,
int32_t line_no,
const base::string16& source_id) override;
const std::u16string& source_id) override;
void BeforeUnloadFired(content::WebContents* source,
bool proceed,
bool* proceed_to_fire_unload) override;

View File

@@ -25,6 +25,7 @@
#include "base/bind.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/post_task.h"
#include "base/task/thread_pool.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"
@@ -152,7 +153,7 @@ int AlloyBrowserMainParts::PreCreateThreads() {
return 0;
}
void AlloyBrowserMainParts::PreMainMessageLoopRun() {
int AlloyBrowserMainParts::PreMainMessageLoopRun() {
#if defined(USE_AURA)
display::Screen::SetScreenInstance(views::CreateDesktopScreen());
#endif
@@ -173,14 +174,14 @@ void AlloyBrowserMainParts::PreMainMessageLoopRun() {
// ChromeBrowserMainExtraPartsProfiles for details.
cef::EnsureBrowserContextKeyedServiceFactoriesBuilt();
background_task_runner_ = base::CreateSingleThreadTaskRunner(
{base::ThreadPool(), base::TaskPriority::BEST_EFFORT,
background_task_runner_ = base::ThreadPool::CreateSingleThreadTaskRunner(
{base::TaskPriority::BEST_EFFORT,
base::TaskShutdownBehavior::BLOCK_SHUTDOWN, base::MayBlock()});
user_visible_task_runner_ = base::CreateSingleThreadTaskRunner(
{base::ThreadPool(), base::TaskPriority::USER_VISIBLE,
user_visible_task_runner_ = base::ThreadPool::CreateSingleThreadTaskRunner(
{base::TaskPriority::USER_VISIBLE,
base::TaskShutdownBehavior::BLOCK_SHUTDOWN, base::MayBlock()});
user_blocking_task_runner_ = base::CreateSingleThreadTaskRunner(
{base::ThreadPool(), base::TaskPriority::USER_BLOCKING,
user_blocking_task_runner_ = base::ThreadPool::CreateSingleThreadTaskRunner(
{base::TaskPriority::USER_BLOCKING,
base::TaskShutdownBehavior::BLOCK_SHUTDOWN, base::MayBlock()});
CefRequestContextSettings settings;
@@ -204,6 +205,8 @@ void AlloyBrowserMainParts::PreMainMessageLoopRun() {
PluginFinder::GetInstance()->Init();
scheme::RegisterWebUIControllerFactory();
return content::RESULT_CODE_NORMAL_EXIT;
}
void AlloyBrowserMainParts::PostMainMessageLoopRun() {

View File

@@ -50,7 +50,7 @@ class AlloyBrowserMainParts : public content::BrowserMainParts {
void PreMainMessageLoopStart() override;
void PostMainMessageLoopStart() override;
int PreCreateThreads() override;
void PreMainMessageLoopRun() override;
int PreMainMessageLoopRun() override;
void PostMainMessageLoopRun() override;
void PostDestroyThreads() override;

View File

@@ -253,7 +253,7 @@ class CefAllowCertificateErrorCallbackImpl : public CefRequestCallback {
CEF_REQUIRE_UIT();
std::move(callback).Run(
allow ? content::CERTIFICATE_REQUEST_RESULT_TYPE_CONTINUE
: content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL);
: content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
}
CallbackType callback_;
@@ -695,9 +695,9 @@ void AlloyContentBrowserClient::AppendExtraCommandLineSwitches(
switches::kLocalesDirPath,
switches::kLogFile,
switches::kLogSeverity,
switches::kProductVersion,
switches::kResourcesDirPath,
embedder_support::kUserAgent,
switches::kUserAgentProductAndVersion,
};
command_line->CopySwitchesFrom(*browser_cmd, kSwitchNames,
base::size(kSwitchNames));
@@ -855,7 +855,7 @@ void AlloyContentBrowserClient::AllowCertificateError(
// A sub-resource has a certificate error. The user doesn't really
// have a context for making the right decision, so block the request
// hard.
std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL);
std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
return;
}
@@ -882,7 +882,7 @@ void AlloyContentBrowserClient::AllowCertificateError(
// |callback| may be null if the user executed it despite returning false.
callback = callbackImpl->Disconnect();
if (!callback.is_null()) {
std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL);
std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
}
}
}
@@ -988,9 +988,9 @@ void AlloyContentBrowserClient::DidCreatePpapiPlugin(
new ChromeBrowserPepperHostFactory(browser_host)));
}
content::DevToolsManagerDelegate*
AlloyContentBrowserClient::GetDevToolsManagerDelegate() {
return new CefDevToolsManagerDelegate();
std::unique_ptr<content::DevToolsManagerDelegate>
AlloyContentBrowserClient::CreateDevToolsManagerDelegate() {
return std::make_unique<CefDevToolsManagerDelegate>();
}
std::vector<std::unique_ptr<content::NavigationThrottle>>
@@ -1244,6 +1244,7 @@ bool AlloyContentBrowserClient::HandleExternalProtocol(
const GURL& url,
content::WebContents::OnceGetter web_contents_getter,
int child_id,
int frame_tree_node_id,
content::NavigationUIData* navigation_data,
bool is_main_frame,
ui::PageTransition page_transition,

View File

@@ -109,7 +109,8 @@ class AlloyContentBrowserClient : public content::ContentBrowserClient {
void BrowserURLHandlerCreated(content::BrowserURLHandler* handler) override;
std::string GetDefaultDownloadName() override;
void DidCreatePpapiPlugin(content::BrowserPpapiHost* browser_host) override;
content::DevToolsManagerDelegate* GetDevToolsManagerDelegate() override;
std::unique_ptr<content::DevToolsManagerDelegate>
CreateDevToolsManagerDelegate() override;
std::vector<std::unique_ptr<content::NavigationThrottle>>
CreateThrottlesForNavigation(
content::NavigationHandle* navigation_handle) override;
@@ -179,6 +180,7 @@ class AlloyContentBrowserClient : public content::ContentBrowserClient {
const GURL& url,
content::WebContents::OnceGetter web_contents_getter,
int child_id,
int frame_tree_node_id,
content::NavigationUIData* navigation_data,
bool is_main_frame,
ui::PageTransition page_transition,

View File

@@ -12,6 +12,7 @@
#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/common/net/url_util.h"
#include "libcef/features/runtime_checks.h"
#include "base/logging.h"
@@ -58,18 +59,20 @@ content::WebContents* CefBrowserPlatformDelegateAlloy::CreateWebContents(
}
scoped_refptr<content::SiteInstance> site_instance;
if (extensions::ExtensionsEnabled() && !create_params.url.is_empty()) {
if (extensions::ExtensionsEnabled() && !create_params.url.empty()) {
GURL gurl = url_util::MakeGURL(create_params.url, /*fixup=*/true);
if (!create_params.extension) {
// We might be loading an extension app view where the extension URL is
// provided by the client.
create_params.extension =
extensions::GetExtensionForUrl(browser_context, create_params.url);
extensions::GetExtensionForUrl(browser_context, gurl);
}
if (create_params.extension) {
if (create_params.extension_host_type == extensions::VIEW_TYPE_INVALID) {
if (create_params.extension_host_type ==
extensions::mojom::ViewType::kInvalid) {
// Default to dialog behavior.
create_params.extension_host_type =
extensions::VIEW_TYPE_EXTENSION_DIALOG;
extensions::mojom::ViewType::kExtensionDialog;
}
// Extension resources will fail to load if we don't use a SiteInstance
@@ -79,7 +82,7 @@ content::WebContents* CefBrowserPlatformDelegateAlloy::CreateWebContents(
// ExtensionProtocolHandler::MaybeCreateJob will return false resulting in
// ERR_BLOCKED_BY_CLIENT).
site_instance = extensions::ProcessManager::Get(browser_context)
->GetSiteInstanceForURL(create_params.url);
->GetSiteInstanceForURL(gurl);
DCHECK(site_instance);
}
}
@@ -189,7 +192,7 @@ void CefBrowserPlatformDelegateAlloy::BrowserCreated(
void CefBrowserPlatformDelegateAlloy::CreateExtensionHost(
const extensions::Extension* extension,
const GURL& url,
extensions::ViewType host_type) {
extensions::mojom::ViewType host_type) {
REQUIRE_ALLOY_RUNTIME();
DCHECK(primary_);
@@ -200,14 +203,15 @@ void CefBrowserPlatformDelegateAlloy::CreateExtensionHost(
auto alloy_browser = static_cast<AlloyBrowserHostImpl*>(browser_);
if (host_type == extensions::VIEW_TYPE_EXTENSION_DIALOG ||
host_type == extensions::VIEW_TYPE_EXTENSION_POPUP) {
if (host_type == extensions::mojom::ViewType::kExtensionDialog ||
host_type == extensions::mojom::ViewType::kExtensionPopup) {
// Create an extension host that we own.
extension_host_ = new extensions::CefExtensionViewHost(
alloy_browser, extension, web_contents_, url, host_type);
// Trigger load of the extension URL.
extension_host_->CreateRendererSoon();
} else if (host_type == extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) {
} else if (host_type ==
extensions::mojom::ViewType::kExtensionBackgroundPage) {
is_background_host_ = true;
alloy_browser->is_background_host_ = true;
// Create an extension host that will be owned by ProcessManager.
@@ -449,7 +453,7 @@ void CefBrowserPlatformDelegateAlloy::DestroyExtensionHost() {
if (!extension_host_)
return;
if (extension_host_->extension_host_type() ==
extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) {
extensions::mojom::ViewType::kExtensionBackgroundPage) {
DCHECK(is_background_host_);
// Close notification for background pages arrives via CloseContents.
// The extension host will be deleted by

View File

@@ -33,7 +33,7 @@ class CefBrowserPlatformDelegateAlloy : public CefBrowserPlatformDelegate {
void BrowserCreated(CefBrowserHostBase* browser) override;
void CreateExtensionHost(const extensions::Extension* extension,
const GURL& url,
extensions::ViewType host_type) override;
extensions::mojom::ViewType host_type) override;
extensions::ExtensionHost* GetExtensionHost() const override;
void BrowserDestroyed(CefBrowserHostBase* browser) override;
void SendCaptureLostEvent() override;

View File

@@ -71,7 +71,8 @@ std::string ChromeProfileAlloy::GetProfileUserName() const {
}
Profile* ChromeProfileAlloy::GetOffTheRecordProfile(
const Profile::OTRProfileID& otr_profile_id) {
const Profile::OTRProfileID& otr_profile_id,
bool create_if_needed) {
NOTREACHED();
return nullptr;
}

View File

@@ -26,8 +26,8 @@ class ChromeProfileAlloy : public Profile {
variations::VariationsClient* GetVariationsClient() override;
scoped_refptr<base::SequencedTaskRunner> GetIOTaskRunner() override;
std::string GetProfileUserName() const override;
Profile* GetOffTheRecordProfile(
const Profile::OTRProfileID& otr_profile_id) override;
Profile* GetOffTheRecordProfile(const Profile::OTRProfileID& otr_profile_id,
bool create_if_needed) override;
std::vector<Profile*> GetAllOffTheRecordProfiles() override;
void DestroyOffTheRecordProfile(Profile* otr_profile) override;
bool HasOffTheRecordProfile(

View File

@@ -16,6 +16,7 @@
#include "content/public/browser/notification_source.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_view_host.h"
#include "third_party/blink/public/mojom/favicon/favicon_url.mojom.h"
using content::KeyboardEventProcessingResult;
@@ -68,9 +69,12 @@ content::WebContents* CefBrowserContentsDelegate::OpenURLFromTab(
if (auto c = client()) {
if (auto handler = c->GetRequestHandler()) {
// May return nullptr for omnibox navigations.
auto frame = browser()->GetFrame(params.frame_tree_node_id);
if (!frame)
frame = browser()->GetMainFrame();
cancel = handler->OnOpenURLFromTab(
browser(), browser()->GetFrame(params.frame_tree_node_id),
params.url.spec(),
browser(), frame, params.url.spec(),
static_cast<cef_window_open_disposition_t>(params.disposition),
params.user_gesture);
}
@@ -105,6 +109,7 @@ void CefBrowserContentsDelegate::LoadingStateChanged(
if (auto c = client()) {
if (auto handler = c->GetLoadHandler()) {
auto navigation_lock = browser_info_->CreateNavigationLock();
handler->OnLoadingStateChange(browser(), is_loading, can_go_back,
can_go_forward);
}
@@ -123,9 +128,9 @@ void CefBrowserContentsDelegate::UpdateTargetURL(content::WebContents* source,
bool CefBrowserContentsDelegate::DidAddMessageToConsole(
content::WebContents* source,
blink::mojom::ConsoleMessageLevel log_level,
const base::string16& message,
const std::u16string& message,
int32_t line_no,
const base::string16& source_id) {
const std::u16string& source_id) {
if (auto c = client()) {
if (auto handler = c->GetDisplayHandler()) {
// Use LOGSEVERITY_DEBUG for unrecognized |level| values.
@@ -324,7 +329,8 @@ void CefBrowserContentsDelegate::OnFrameFocused(
OnStateChanged(State::kFocusedFrame);
}
void CefBrowserContentsDelegate::DocumentAvailableInMainFrame() {
void CefBrowserContentsDelegate::DocumentAvailableInMainFrame(
content::RenderFrameHost* render_frame_host) {
has_document_ = true;
OnStateChanged(State::kDocument);
@@ -507,6 +513,7 @@ void CefBrowserContentsDelegate::OnLoadEnd(CefRefPtr<CefFrame> frame,
int http_status_code) {
if (auto c = client()) {
if (auto handler = c->GetLoadHandler()) {
auto navigation_lock = browser_info_->CreateNavigationLock();
handler->OnLoadEnd(browser(), frame, http_status_code);
}
}
@@ -565,6 +572,7 @@ void CefBrowserContentsDelegate::OnLoadStart(
ui::PageTransition transition_type) {
if (auto c = client()) {
if (auto handler = c->GetLoadHandler()) {
auto navigation_lock = browser_info_->CreateNavigationLock();
// On the handler that loading has started.
handler->OnLoadStart(browser(), frame,
static_cast<cef_transition_type_t>(transition_type));
@@ -586,7 +594,7 @@ void CefBrowserContentsDelegate::OnLoadError(CefRefPtr<CefFrame> frame,
}
}
void CefBrowserContentsDelegate::OnTitleChange(const base::string16& title) {
void CefBrowserContentsDelegate::OnTitleChange(const std::u16string& title) {
if (auto c = client()) {
if (auto handler = c->GetDisplayHandler()) {
handler->OnTitleChange(browser(), title);

View File

@@ -87,9 +87,9 @@ class CefBrowserContentsDelegate : public content::WebContentsDelegate,
void UpdateTargetURL(content::WebContents* source, const GURL& url) override;
bool DidAddMessageToConsole(content::WebContents* source,
blink::mojom::ConsoleMessageLevel log_level,
const base::string16& message,
const std::u16string& message,
int32_t line_no,
const base::string16& source_id) override;
const std::u16string& source_id) override;
void DidNavigateMainFramePostCommit(
content::WebContents* web_contents) override;
void EnterFullscreenModeForTab(
@@ -112,7 +112,8 @@ class CefBrowserContentsDelegate : public content::WebContentsDelegate,
void RenderViewReady() override;
void RenderProcessGone(base::TerminationStatus status) override;
void OnFrameFocused(content::RenderFrameHost* render_frame_host) override;
void DocumentAvailableInMainFrame() override;
void DocumentAvailableInMainFrame(
content::RenderFrameHost* render_frame_host) override;
void LoadProgressChanged(double progress) override;
void DidStopLoading() override;
void DidFinishNavigation(
@@ -163,7 +164,7 @@ class CefBrowserContentsDelegate : public content::WebContentsDelegate,
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 OnTitleChange(const std::u16string& title);
void OnFullscreenModeChange(bool fullscreen);
void OnStateChanged(State state_changed);

View File

@@ -7,16 +7,20 @@
#include <map>
#include <utility>
#include "libcef/browser/iothread_state.h"
#include "libcef/browser/context.h"
#include "libcef/browser/media_router/media_router_manager.h"
#include "libcef/browser/request_context_impl.h"
#include "libcef/browser/thread_util.h"
#include "libcef/common/cef_switches.h"
#include "libcef/features/runtime.h"
#include "base/files/file_util.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/no_destructor.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "chrome/browser/profiles/profile.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
@@ -141,6 +145,28 @@ CefBrowserContext* GetSelf(base::WeakPtr<CefBrowserContext> self) {
return self.get();
}
CefBrowserContext::CookieableSchemes MakeSupportedSchemes(
const CefString& schemes_list,
bool include_defaults) {
std::vector<std::string> all_schemes;
if (!schemes_list.empty()) {
all_schemes =
base::SplitString(schemes_list.ToString(), std::string(","),
base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
}
if (include_defaults) {
// Add default schemes that should always support cookies.
// This list should match CookieMonster::kDefaultCookieableSchemes.
all_schemes.push_back("http");
all_schemes.push_back("https");
all_schemes.push_back("ws");
all_schemes.push_back("wss");
}
return base::make_optional(all_schemes);
}
} // namespace
CefBrowserContext::CefBrowserContext(const CefRequestContextSettings& settings)
@@ -154,13 +180,6 @@ CefBrowserContext::~CefBrowserContext() {
#if DCHECK_IS_ON()
DCHECK(is_shutdown_);
#endif
if (iothread_state_) {
// Destruction of the CefIOThreadState will trigger destruction of all
// associated network requests.
content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE,
iothread_state_.release());
}
}
void CefBrowserContext::Initialize() {
@@ -169,7 +188,14 @@ void CefBrowserContext::Initialize() {
if (!cache_path_.empty())
g_manager.Get().SetImplPath(this, cache_path_);
iothread_state_ = std::make_unique<CefIOThreadState>();
iothread_state_ = base::MakeRefCounted<CefIOThreadState>();
if (settings_.cookieable_schemes_list.length > 0 ||
settings_.cookieable_schemes_exclude_defaults) {
cookieable_schemes_ =
MakeSupportedSchemes(CefString(&settings_.cookieable_schemes_list),
!settings_.cookieable_schemes_exclude_defaults);
}
}
void CefBrowserContext::Shutdown() {
@@ -229,6 +255,25 @@ CefBrowserContext* CefBrowserContext::FromBrowserContext(
return g_manager.Get().GetImplFromBrowserContext(context);
}
// static
CefBrowserContext* CefBrowserContext::FromProfile(const Profile* profile) {
auto* cef_context = FromBrowserContext(profile);
if (cef_context)
return cef_context;
if (cef::IsChromeRuntimeEnabled()) {
auto* original_profile = profile->GetOriginalProfile();
if (original_profile != profile) {
// With the Chrome runtime if the user launches an incognito window via
// the UI we might be associated with the original Profile instead of the
// (current) incognito profile.
return FromBrowserContext(original_profile);
}
}
return nullptr;
}
// static
std::vector<CefBrowserContext*> CefBrowserContext::GetAll() {
return g_manager.Get().GetAllImpl();
@@ -254,15 +299,10 @@ void CefBrowserContext::OnRenderFrameCreated(
handler_map_.AddHandler(render_process_id, render_frame_id,
frame_tree_node_id, handler);
if (iothread_state_) {
// Using base::Unretained() is safe because both this callback and
// possible deletion of |iothread_state_| will execute on the IO thread,
// and this callback will be executed first.
CEF_POST_TASK(CEF_IOT, base::Bind(&CefIOThreadState::AddHandler,
base::Unretained(iothread_state_.get()),
render_process_id, render_frame_id,
frame_tree_node_id, handler));
}
CEF_POST_TASK(CEF_IOT,
base::Bind(&CefIOThreadState::AddHandler, iothread_state_,
render_process_id, render_frame_id,
frame_tree_node_id, handler));
}
}
@@ -292,15 +332,9 @@ void CefBrowserContext::OnRenderFrameDeleted(
handler_map_.RemoveHandler(render_process_id, render_frame_id,
frame_tree_node_id);
if (iothread_state_) {
// Using base::Unretained() is safe because both this callback and
// possible deletion of |iothread_state_| will execute on the IO thread,
// and this callback will be executed first.
CEF_POST_TASK(CEF_IOT, base::Bind(&CefIOThreadState::RemoveHandler,
base::Unretained(iothread_state_.get()),
render_process_id, render_frame_id,
frame_tree_node_id));
}
CEF_POST_TASK(CEF_IOT, base::Bind(&CefIOThreadState::RemoveHandler,
iothread_state_, render_process_id,
render_frame_id, frame_tree_node_id));
}
if (is_main_frame) {
@@ -404,26 +438,15 @@ void CefBrowserContext::RegisterSchemeHandlerFactory(
const CefString& scheme_name,
const CefString& domain_name,
CefRefPtr<CefSchemeHandlerFactory> factory) {
if (iothread_state_) {
// Using base::Unretained() is safe because both this callback and possible
// deletion of |iothread_state_| will execute on the IO thread, and this
// callback will be executed first.
CEF_POST_TASK(CEF_IOT,
base::Bind(&CefIOThreadState::RegisterSchemeHandlerFactory,
base::Unretained(iothread_state_.get()),
scheme_name, domain_name, factory));
}
CEF_POST_TASK(CEF_IOT,
base::Bind(&CefIOThreadState::RegisterSchemeHandlerFactory,
iothread_state_, scheme_name, domain_name, factory));
}
void CefBrowserContext::ClearSchemeHandlerFactories() {
if (iothread_state_) {
// Using base::Unretained() is safe because both this callback and possible
// deletion of |iothread_state_| will execute on the IO thread, and this
// callback will be executed first.
CEF_POST_TASK(CEF_IOT,
base::Bind(&CefIOThreadState::ClearSchemeHandlerFactories,
base::Unretained(iothread_state_.get())));
}
CEF_POST_TASK(CEF_IOT,
base::Bind(&CefIOThreadState::ClearSchemeHandlerFactories,
iothread_state_));
}
void CefBrowserContext::LoadExtension(
@@ -477,5 +500,24 @@ CefBrowserContext::CookieableSchemes CefBrowserContext::GetCookieableSchemes()
if (cookieable_schemes_)
return cookieable_schemes_;
return CefCookieManagerImpl::GetGlobalCookieableSchemes();
return GetGlobalCookieableSchemes();
}
// static
CefBrowserContext::CookieableSchemes
CefBrowserContext::GetGlobalCookieableSchemes() {
CEF_REQUIRE_UIT();
static base::NoDestructor<CookieableSchemes> schemes(
[]() -> CookieableSchemes {
const auto& settings = CefContext::Get()->settings();
if (settings.cookieable_schemes_list.length > 0 ||
settings.cookieable_schemes_exclude_defaults) {
return MakeSupportedSchemes(
CefString(&settings.cookieable_schemes_list),
!settings.cookieable_schemes_exclude_defaults);
}
return base::nullopt;
}());
return *schemes;
}

View File

@@ -10,6 +10,7 @@
#include <vector>
#include "include/cef_request_context_handler.h"
#include "libcef/browser/iothread_state.h"
#include "libcef/browser/request_context_handler_map.h"
#include "base/callback.h"
@@ -80,7 +81,6 @@ class BrowserContext;
class CefMediaRouterManager;
class CefRequestContextImpl;
class CefIOThreadState;
class Profile;
// Main entry point for configuring behavior on a per-RequestContext basis. The
@@ -103,6 +103,7 @@ class CefBrowserContext {
// Returns the underlying CefBrowserContext if any.
static CefBrowserContext* FromBrowserContext(
const content::BrowserContext* context);
static CefBrowserContext* FromProfile(const Profile* profile);
// Returns all existing CefBrowserContext.
static std::vector<CefBrowserContext*> GetAll();
@@ -111,6 +112,13 @@ class CefBrowserContext {
virtual content::BrowserContext* AsBrowserContext() = 0;
virtual Profile* AsProfile() = 0;
// Returns true if the context is fully initialized.
virtual bool IsInitialized() const = 0;
// If the context is fully initialized execute |callback|, otherwise
// store it until the context is fully initialized.
virtual void StoreOrTriggerInitCallback(base::OnceClosure callback) = 0;
// Called from CefRequestContextImpl to track associated objects. This
// object will delete itself when the count reaches zero.
void AddCefRequestContext(CefRequestContextImpl* context);
@@ -197,17 +205,15 @@ class CefBrowserContext {
// 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;
}
static CookieableSchemes GetGlobalCookieableSchemes();
// These accessors are safe to call from any thread because the values don't
// change during this object's lifespan.
const CefRequestContextSettings& settings() const { return settings_; }
base::FilePath cache_path() const { return cache_path_; }
CefIOThreadState* iothread_state() const { return iothread_state_.get(); }
scoped_refptr<CefIOThreadState> iothread_state() const {
return iothread_state_;
}
// Used to hold a WeakPtr reference to this this object. The Getter returns
// nullptr if this object has already been destroyed.
@@ -230,7 +236,7 @@ class CefBrowserContext {
base::FilePath cache_path_;
private:
std::unique_ptr<CefIOThreadState> iothread_state_;
scoped_refptr<CefIOThreadState> iothread_state_;
CookieableSchemes cookieable_schemes_;
std::unique_ptr<CefMediaRouterManager> media_router_manager_;

View File

@@ -6,16 +6,17 @@
#include "libcef/browser/browser_info_manager.h"
#include "libcef/browser/browser_platform_delegate.h"
#include "libcef/browser/context.h"
#include "libcef/browser/image_impl.h"
#include "libcef/browser/navigation_entry_impl.h"
#include "libcef/browser/thread_util.h"
#include "libcef/common/net/url_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 "components/url_formatter/url_fixer.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/download_request_utils.h"
@@ -761,16 +762,9 @@ bool CefBrowserHostBase::Navigate(const content::OpenURLParams& params) {
CEF_REQUIRE_UIT();
auto web_contents = GetWebContents();
if (web_contents) {
// Fix common problems with user-typed text. Among other things, this:
// - Converts absolute file paths to "file://" URLs.
// - Normalizes "about:" and "chrome:" to "chrome://" URLs.
// - Adds the "http://" scheme if none was specified.
GURL gurl = url_formatter::FixupURL(params.url.possibly_invalid_spec(),
std::string());
if (!gurl.is_valid()) {
LOG(ERROR) << "Invalid URL: " << params.url.possibly_invalid_spec();
GURL gurl = params.url;
if (!url_util::FixupGURL(gurl))
return false;
}
web_contents->GetController().LoadURL(
gurl, params.referrer, params.transition, params.extra_headers);
@@ -833,6 +827,16 @@ int CefBrowserHostBase::browser_id() const {
return browser_info_->browser_id();
}
SkColor CefBrowserHostBase::GetBackgroundColor() const {
// Don't use |platform_delegate_| because it's not thread-safe.
return CefContext::Get()->GetBackgroundColor(
&settings_, IsWindowless() ? STATE_ENABLED : STATE_DISABLED);
}
bool CefBrowserHostBase::IsWindowless() const {
return false;
}
content::WebContents* CefBrowserHostBase::GetWebContents() const {
CEF_REQUIRE_UIT();
return contents_delegate_->web_contents();

View File

@@ -18,7 +18,7 @@
#include "base/observer_list.h"
#include "base/synchronization/lock.h"
#include "extensions/common/view_type.h"
#include "extensions/common/mojom/view_type.mojom.h"
namespace extensions {
class Extension;
@@ -51,8 +51,13 @@ struct CefBrowserCreateParams {
#if defined(TOOLKIT_VIEWS)
// The BrowserView that will own a Views-hosted browser. Will be nullptr for
// popup browsers (the BrowserView will be created later in that case).
// popup browsers.
CefRefPtr<CefBrowserView> browser_view;
// True if this browser is a popup and has a Views-hosted opener, in which
// case the BrowserView for this browser will be created later (from
// PopupWebContentsCreated).
bool popup_with_views_hosted_opener = false;
#endif
// Client implementation. May be nullptr.
@@ -60,7 +65,7 @@ struct CefBrowserCreateParams {
// 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;
CefString url;
// Browser settings.
CefBrowserSettings settings;
@@ -81,7 +86,8 @@ struct CefBrowserCreateParams {
// ProcessManager::CreateBackgroundHost. Currently used with the alloy
// runtime only.
const extensions::Extension* extension = nullptr;
extensions::ViewType extension_host_type = extensions::VIEW_TYPE_INVALID;
extensions::mojom::ViewType extension_host_type =
extensions::mojom::ViewType::kInvalid;
};
// Base class for CefBrowserHost implementations. Includes functionality that is
@@ -241,6 +247,10 @@ class CefBrowserHostBase : public CefBrowserHost,
return request_context_;
}
bool is_views_hosted() const { return is_views_hosted_; }
SkColor GetBackgroundColor() const;
// Returns true if windowless rendering is enabled.
virtual bool IsWindowless() const;
// Accessors that must be called on the UI thread.
content::WebContents* GetWebContents() const;

View File

@@ -27,6 +27,11 @@ class CreateBrowserHelper {
extra_info_(extra_info),
request_context_(request_context) {}
void Run() {
CefBrowserHost::CreateBrowserSync(window_info_, client_, url_, settings_,
extra_info_, request_context_);
}
CefWindowInfo window_info_;
CefRefPtr<CefClient> client_;
CefString url_;
@@ -71,19 +76,25 @@ bool CefBrowserHost::CreateBrowser(
"reduced performance or runtime errors.";
}
// Create the browser on the UI thread.
CreateBrowserHelper* helper = new CreateBrowserHelper(
if (!request_context) {
request_context = CefRequestContext::GetGlobalContext();
}
auto helper = std::make_unique<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));
auto request_context_impl =
static_cast<CefRequestContextImpl*>(request_context.get());
// Wait for the browser context to be initialized before creating the browser.
request_context_impl->ExecuteWhenBrowserContextInitialized(base::BindOnce(
[](std::unique_ptr<CreateBrowserHelper> helper) {
// Always execute asynchronously to avoid potential issues if we're
// being called synchronously during app initialization.
CEF_POST_TASK(CEF_UIT, base::BindOnce(&CreateBrowserHelper::Run,
std::move(helper)));
},
std::move(helper)));
return true;
}
@@ -108,9 +119,14 @@ CefRefPtr<CefBrowser> CefBrowserHost::CreateBrowserSync(
return nullptr;
}
// Verify that this method is being called on the UI thread.
if (!CEF_CURRENTLY_ON_UIT()) {
NOTREACHED() << "called on invalid thread";
if (!request_context) {
request_context = CefRequestContext::GetGlobalContext();
}
// Verify that the browser context is valid.
auto request_context_impl =
static_cast<CefRequestContextImpl*>(request_context.get());
if (!request_context_impl->VerifyBrowserContext()) {
return nullptr;
}
@@ -124,12 +140,7 @@ CefRefPtr<CefBrowser> CefBrowserHost::CreateBrowserSync(
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.url = url;
create_params.settings = settings;
create_params.extra_info = extra_info;
create_params.request_context = request_context;

View File

@@ -181,8 +181,11 @@ bool CefBrowserInfoManager::CanCreateWindow(
if (allow) {
CefBrowserCreateParams create_params;
if (!browser->HasView())
if (browser->HasView()) {
create_params.popup_with_views_hosted_opener = true;
} else {
create_params.window_info = std::move(window_info);
}
create_params.settings = pending_popup->settings;
create_params.client = pending_popup->client;

View File

@@ -76,7 +76,7 @@ void CefBrowserPlatformDelegate::BrowserCreated(CefBrowserHostBase* browser) {
void CefBrowserPlatformDelegate::CreateExtensionHost(
const extensions::Extension* extension,
const GURL& url,
extensions::ViewType host_type) {
extensions::mojom::ViewType host_type) {
NOTREACHED();
}

View File

@@ -15,7 +15,7 @@
#include "include/views/cef_browser_view.h"
#include "base/callback_forward.h"
#include "extensions/common/view_type.h"
#include "extensions/common/mojom/view_type.mojom-forward.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"
@@ -134,7 +134,7 @@ class CefBrowserPlatformDelegate {
// Called from AlloyBrowserHostImpl::Create.
virtual void CreateExtensionHost(const extensions::Extension* extension,
const GURL& url,
extensions::ViewType host_type);
extensions::mojom::ViewType host_type);
// Returns the current extension host.
virtual extensions::ExtensionHost* GetExtensionHost() const;

View File

@@ -84,7 +84,8 @@ std::unique_ptr<CefBrowserPlatformDelegate> CefBrowserPlatformDelegate::Create(
std::unique_ptr<CefBrowserPlatformDelegateNative> native_delegate =
CreateNativeDelegate(CefWindowInfo(), background_color);
#if defined(TOOLKIT_VIEWS)
if (create_params.browser_view) {
if (create_params.browser_view ||
create_params.popup_with_views_hosted_opener) {
return std::make_unique<CefBrowserPlatformDelegateChromeViews>(
std::move(native_delegate),
static_cast<CefBrowserViewImpl*>(create_params.browser_view.get()));
@@ -114,7 +115,7 @@ std::unique_ptr<CefBrowserPlatformDelegate> CefBrowserPlatformDelegate::Create(
}
return std::move(native_delegate);
} else if (create_params.extension_host_type ==
extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) {
extensions::mojom::ViewType::kExtensionBackgroundPage) {
// Creating a background extension host without a window.
std::unique_ptr<CefBrowserPlatformDelegateNative> native_delegate =
CreateNativeDelegate(CefWindowInfo(), background_color);

View File

@@ -4,13 +4,14 @@
#include "libcef/browser/chrome/chrome_browser_context.h"
#include "libcef/browser/prefs/browser_prefs.h"
#include "libcef/browser/thread_util.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/off_the_record_profile_impl.h"
ChromeBrowserContext::ChromeBrowserContext(
const CefRequestContextSettings& settings)
: CefBrowserContext(settings) {}
: CefBrowserContext(settings), weak_ptr_factory_(this) {}
ChromeBrowserContext::~ChromeBrowserContext() = default;
@@ -22,19 +23,106 @@ Profile* ChromeBrowserContext::AsProfile() {
return profile_;
}
void ChromeBrowserContext::Initialize() {
bool ChromeBrowserContext::IsInitialized() const {
CEF_REQUIRE_UIT();
return !!profile_;
}
void ChromeBrowserContext::StoreOrTriggerInitCallback(
base::OnceClosure callback) {
CEF_REQUIRE_UIT();
if (IsInitialized()) {
std::move(callback).Run();
} else {
init_callbacks_.emplace_back(std::move(callback));
}
}
void ChromeBrowserContext::InitializeAsync(base::OnceClosure initialized_cb) {
init_callbacks_.emplace_back(std::move(initialized_cb));
CefBrowserContext::Initialize();
// TODO(chrome-runtime): ProfileManager can create new profiles relative to
// the user-data-dir, but it should be done asynchronously.
// The global ProfileManager instance can be retrieved via
// |g_browser_process->profile_manager()|.
profile_ = ProfileManager::GetLastUsedProfileAllowedByPolicy();
if (!cache_path_.empty()) {
auto* profile_manager = g_browser_process->profile_manager();
const auto& user_data_dir = profile_manager->user_data_dir();
browser_prefs::SetLanguagePrefs(profile_);
if (cache_path_ == user_data_dir) {
// Use the default disk-based profile.
auto profile = profile_manager->GetPrimaryUserProfile();
ProfileCreated(profile, Profile::CreateStatus::CREATE_STATUS_INITIALIZED);
return;
} else if (cache_path_.DirName() == user_data_dir) {
// Create or load a specific disk-based profile. May continue
// synchronously or asynchronously.
profile_manager->CreateProfileAsync(
cache_path_, base::Bind(&ChromeBrowserContext::ProfileCreated,
weak_ptr_factory_.GetWeakPtr()));
return;
} else {
// All profile directories must be relative to |user_data_dir|.
LOG(ERROR) << "Cannot create profile at path "
<< cache_path_.AsUTF8Unsafe();
}
}
// Default to creating a new/unique OffTheRecord profile.
ProfileCreated(nullptr, Profile::CreateStatus::CREATE_STATUS_CANCELED);
}
void ChromeBrowserContext::Shutdown() {
CefBrowserContext::Shutdown();
// |g_browser_process| may be nullptr during shutdown.
if (should_destroy_ && g_browser_process) {
g_browser_process->profile_manager()
->GetPrimaryUserProfile()
->DestroyOffTheRecordProfile(profile_);
}
profile_ = nullptr;
}
void ChromeBrowserContext::ProfileCreated(Profile* profile,
Profile::CreateStatus status) {
Profile* parent_profile = nullptr;
OffTheRecordProfileImpl* otr_profile = nullptr;
if (status != Profile::CreateStatus::CREATE_STATUS_CREATED &&
status != Profile::CreateStatus::CREATE_STATUS_INITIALIZED) {
CHECK(!profile);
CHECK(!profile_);
// Creation of a disk-based profile failed for some reason. Create a
// new/unique OffTheRecord profile instead.
const auto& profile_id = Profile::OTRProfileID::CreateUniqueForCEF();
parent_profile =
g_browser_process->profile_manager()->GetPrimaryUserProfile();
profile_ = parent_profile->GetOffTheRecordProfile(profile_id);
otr_profile = static_cast<OffTheRecordProfileImpl*>(profile_);
status = Profile::CreateStatus::CREATE_STATUS_INITIALIZED;
should_destroy_ = true;
} else if (profile && !profile_) {
// May be CREATE_STATUS_CREATED or CREATE_STATUS_INITIALIZED since
// *CREATED isn't always sent for a disk-based profile that already
// exists.
profile_ = profile;
}
if (status == Profile::CreateStatus::CREATE_STATUS_INITIALIZED) {
CHECK(profile_);
// Must set |profile_| before Init() calls
// ChromeContentBrowserClientCef::ConfigureNetworkContextParams so that
// CefBrowserContext::FromBrowserContext can find us.
if (otr_profile) {
otr_profile->Init();
parent_profile->NotifyOffTheRecordProfileCreated(otr_profile);
}
if (!init_callbacks_.empty()) {
for (auto& callback : init_callbacks_) {
std::move(callback).Run();
}
init_callbacks_.clear();
}
}
}

View File

@@ -8,22 +8,36 @@
#include "libcef/browser/browser_context.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/profiles/profile_manager.h"
// See CefBrowserContext documentation for usage. Only accessed on the UI thread
// unless otherwise indicated.
class ChromeBrowserContext : public CefBrowserContext {
public:
explicit ChromeBrowserContext(const CefRequestContextSettings& settings);
void InitializeAsync(base::OnceClosure initialized_cb);
// CefBrowserContext overrides.
content::BrowserContext* AsBrowserContext() override;
Profile* AsProfile() override;
void Initialize() override;
bool IsInitialized() const override;
void StoreOrTriggerInitCallback(base::OnceClosure callback) override;
void Shutdown() override;
private:
~ChromeBrowserContext() override;
void ProfileCreated(Profile* profile, Profile::CreateStatus status);
base::OnceClosure initialized_cb_;
Profile* profile_ = nullptr;
bool should_destroy_ = false;
std::vector<base::OnceClosure> init_callbacks_;
base::WeakPtrFactory<ChromeBrowserContext> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(ChromeBrowserContext);
};

View File

@@ -16,6 +16,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "content/public/browser/keyboard_event_processing_result.h"
#include "content/public/browser/native_web_keyboard_event.h"
@@ -65,7 +66,7 @@ void ChromeBrowserDelegate::SetAsDelegate(content::WebContents* web_contents,
create_params_.request_context);
CreateBrowser(web_contents, create_params_.settings, create_params_.client,
std::move(platform_delegate), browser_info,
std::move(platform_delegate), browser_info, /*opener=*/nullptr,
request_context_impl);
}
@@ -103,7 +104,28 @@ void ChromeBrowserDelegate::WebContentsCreated(
// 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);
browser_info, opener, request_context_impl);
}
void ChromeBrowserDelegate::AddNewContents(
content::WebContents* source_contents,
std::unique_ptr<content::WebContents> new_contents,
const GURL& target_url,
WindowOpenDisposition disposition,
const gfx::Rect& initial_rect,
bool user_gesture,
bool* was_blocked) {
auto new_browser =
ChromeBrowserHostImpl::GetBrowserForContents(new_contents.get());
if (new_browser) {
// Create a new Browser and give it ownership of the WebContents.
new_browser->AddNewContents(std::move(new_contents));
return;
}
// Fall back to default behavior from Browser::AddNewContents.
chrome::AddWebContents(browser_, source_contents, std::move(new_contents),
target_url, disposition, initial_rect);
}
content::WebContents* ChromeBrowserDelegate::OpenURLFromTab(
@@ -134,9 +156,9 @@ void ChromeBrowserDelegate::UpdateTargetURL(content::WebContents* source,
bool ChromeBrowserDelegate::DidAddMessageToConsole(
content::WebContents* source,
blink::mojom::ConsoleMessageLevel log_level,
const base::string16& message,
const std::u16string& message,
int32_t line_no,
const base::string16& source_id) {
const std::u16string& source_id) {
if (auto delegate = GetDelegateForWebContents(source)) {
return delegate->DidAddMessageToConsole(source, log_level, message, line_no,
source_id);
@@ -195,6 +217,7 @@ void ChromeBrowserDelegate::CreateBrowser(
CefRefPtr<CefClient> client,
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate,
scoped_refptr<CefBrowserInfo> browser_info,
CefRefPtr<ChromeBrowserHostImpl> opener,
CefRefPtr<CefRequestContextImpl> request_context_impl) {
CEF_REQUIRE_UIT();
DCHECK(web_contents);
@@ -202,6 +225,9 @@ void ChromeBrowserDelegate::CreateBrowser(
DCHECK(browser_info);
DCHECK(request_context_impl);
// If |opener| is non-nullptr it must be a popup window.
DCHECK(!opener.get() || browser_info->is_popup());
if (!client) {
if (auto app = CefAppManager::Get()->GetApplication()) {
if (auto bph = app->GetBrowserProcessHandler()) {
@@ -226,7 +252,12 @@ void ChromeBrowserDelegate::CreateBrowser(
CefRefPtr<ChromeBrowserHostImpl> browser_host =
new ChromeBrowserHostImpl(settings, client, std::move(platform_delegate),
browser_info, request_context_impl);
browser_host->Attach(browser_, web_contents);
browser_host->Attach(web_contents, opener);
// The Chrome browser for a popup won't be created until AddNewContents().
if (!opener) {
browser_host->SetBrowser(browser_);
}
}
CefBrowserContentsDelegate* ChromeBrowserDelegate::GetDelegateForWebContents(

View File

@@ -55,6 +55,13 @@ class ChromeBrowserDelegate : public cef::BrowserDelegate {
const std::string& frame_name,
const GURL& target_url,
content::WebContents* new_contents) override;
void AddNewContents(content::WebContents* source_contents,
std::unique_ptr<content::WebContents> new_contents,
const GURL& target_url,
WindowOpenDisposition disposition,
const gfx::Rect& initial_rect,
bool user_gesture,
bool* was_blocked) override;
content::WebContents* OpenURLFromTab(
content::WebContents* source,
const content::OpenURLParams& params) override;
@@ -63,9 +70,9 @@ class ChromeBrowserDelegate : public cef::BrowserDelegate {
void UpdateTargetURL(content::WebContents* source, const GURL& url) override;
bool DidAddMessageToConsole(content::WebContents* source,
blink::mojom::ConsoleMessageLevel log_level,
const base::string16& message,
const std::u16string& message,
int32_t line_no,
const base::string16& source_id) override;
const std::u16string& source_id) override;
void DidNavigateMainFramePostCommit(
content::WebContents* web_contents) override;
void EnterFullscreenModeForTab(
@@ -88,6 +95,7 @@ class ChromeBrowserDelegate : public cef::BrowserDelegate {
CefRefPtr<CefClient> client,
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate,
scoped_refptr<CefBrowserInfo> browser_info,
CefRefPtr<ChromeBrowserHostImpl> opener,
CefRefPtr<CefRequestContextImpl> request_context_impl);
CefBrowserContentsDelegate* GetDelegateForWebContents(

View File

@@ -8,6 +8,7 @@
#include "libcef/browser/chrome/browser_platform_delegate_chrome.h"
#include "libcef/browser/thread_util.h"
#include "libcef/browser/views/browser_view_impl.h"
#include "libcef/common/net/url_util.h"
#include "libcef/features/runtime_checks.h"
#include "base/logging.h"
@@ -21,8 +22,6 @@
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/pref_names.h"
#include "components/url_formatter/url_fixer.h"
#include "url/url_constants.h"
#if defined(TOOLKIT_VIEWS)
#include "libcef/browser/chrome/views/chrome_browser_frame.h"
@@ -32,62 +31,9 @@
// 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();
auto browser = CreateBrowser(params);
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);
#if defined(TOOLKIT_VIEWS)
// Configure Browser creation to use the existing Views-based
// Widget/BrowserFrame (ChromeBrowserFrame) and BrowserView/BrowserWindow
// (ChromeBrowserView). See views/chrome_browser_frame.h for related
// documentation.
ChromeBrowserView* chrome_browser_view = nullptr;
if (params.browser_view) {
// Don't show most controls.
chrome_params.type = Browser::TYPE_POPUP;
// Don't show title bar or address.
chrome_params.trusted_source = true;
auto view_impl =
static_cast<CefBrowserViewImpl*>(params.browser_view.get());
chrome_browser_view =
static_cast<ChromeBrowserView*>(view_impl->root_view());
chrome_params.window = chrome_browser_view;
auto chrome_widget =
static_cast<ChromeBrowserFrame*>(chrome_browser_view->GetWidget());
chrome_browser_view->set_frame(chrome_widget);
}
#endif // defined(TOOLKIT_VIEWS)
// 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. The returned Browser is owned by the
// associated BrowserView.
auto browser = Browser::Create(chrome_params);
#if defined(TOOLKIT_VIEWS)
if (chrome_browser_view) {
// Initialize the BrowserFrame and BrowserView and create the controls that
// require access to the Browser.
chrome_browser_view->InitBrowser(base::WrapUnique(browser),
params.browser_view);
}
#endif
GURL url = params.url;
GURL url = url_util::MakeGURL(params.url, /*fixup=*/true);
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
@@ -98,7 +44,8 @@ CefRefPtr<ChromeBrowserHostImpl> ChromeBrowserHostImpl::Create(
// 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);
chrome::AddTabAt(browser, url, /*index=*/TabStripModel::kNoTab,
/*foreground=*/true);
// The new tab WebContents.
auto web_contents = browser->tab_strip_model()->GetActiveWebContents();
@@ -159,6 +106,34 @@ CefRefPtr<ChromeBrowserHostImpl> ChromeBrowserHostImpl::GetBrowserForFrameRoute(
ChromeBrowserHostImpl::~ChromeBrowserHostImpl() = default;
void ChromeBrowserHostImpl::AddNewContents(
std::unique_ptr<content::WebContents> contents) {
DCHECK(contents);
DCHECK(!browser_);
// We should already be associated with the WebContents.
DCHECK_EQ(GetWebContents(), contents.get());
CefBrowserCreateParams params;
params.request_context = request_context();
#if defined(TOOLKIT_VIEWS)
params.browser_view = GetBrowserView();
#endif
// Create the new Browser representation.
auto browser = CreateBrowser(params);
// Add the WebContents to the Browser.
browser->tab_strip_model()->AddWebContents(
std::move(contents), /*index=*/TabStripModel::kNoTab,
ui::PageTransition::PAGE_TRANSITION_AUTO_TOPLEVEL,
TabStripModel::ADD_ACTIVE);
SetBrowser(browser);
browser->window()->Show();
}
void ChromeBrowserHostImpl::OnWebContentsDestroyed(
content::WebContents* web_contents) {
platform_delegate_->WebContentsDestroyed(web_contents);
@@ -416,16 +391,9 @@ bool ChromeBrowserHostImpl::Navigate(const content::OpenURLParams& params) {
}
if (browser_) {
// Fix common problems with user-typed text. Among other things, this:
// - Converts absolute file paths to "file://" URLs.
// - Normalizes "about:" and "chrome:" to "chrome://" URLs.
// - Adds the "http://" scheme if none was specified.
GURL gurl = url_formatter::FixupURL(params.url.possibly_invalid_spec(),
std::string());
if (!gurl.is_valid()) {
LOG(ERROR) << "Invalid URL: " << params.url.possibly_invalid_spec();
GURL gurl = params.url;
if (!url_util::FixupGURL(gurl))
return false;
}
// This is generally equivalent to calling Browser::OpenURL, except:
// 1. It doesn't trigger a call to CefRequestHandler::OnOpenURLFromTab, and
@@ -461,17 +429,113 @@ ChromeBrowserHostImpl::ChromeBrowserHostImpl(
browser_info,
request_context) {}
void ChromeBrowserHostImpl::Attach(Browser* browser,
content::WebContents* web_contents) {
DCHECK(browser);
// static
Browser* ChromeBrowserHostImpl::CreateBrowser(
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();
CHECK(profile);
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);
#if defined(TOOLKIT_VIEWS)
// Configure Browser creation to use the existing Views-based
// Widget/BrowserFrame (ChromeBrowserFrame) and BrowserView/BrowserWindow
// (ChromeBrowserView). See views/chrome_browser_frame.h for related
// documentation.
ChromeBrowserView* chrome_browser_view = nullptr;
if (params.browser_view) {
// Don't show most controls.
chrome_params.type = Browser::TYPE_POPUP;
// Don't show title bar or address.
chrome_params.trusted_source = true;
auto view_impl =
static_cast<CefBrowserViewImpl*>(params.browser_view.get());
chrome_browser_view =
static_cast<ChromeBrowserView*>(view_impl->root_view());
chrome_params.window = chrome_browser_view;
auto chrome_widget =
static_cast<ChromeBrowserFrame*>(chrome_browser_view->GetWidget());
chrome_browser_view->set_frame(chrome_widget);
}
#endif // defined(TOOLKIT_VIEWS)
// 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. The returned Browser is owned by the
// associated BrowserView.
auto browser = Browser::Create(chrome_params);
#if defined(TOOLKIT_VIEWS)
if (chrome_browser_view) {
// Initialize the BrowserFrame and BrowserView and create the controls that
// require access to the Browser.
chrome_browser_view->InitBrowser(base::WrapUnique(browser),
params.browser_view);
}
#endif
return browser;
}
void ChromeBrowserHostImpl::Attach(content::WebContents* web_contents,
CefRefPtr<ChromeBrowserHostImpl> opener) {
DCHECK(web_contents);
SetBrowser(browser);
if (opener) {
// Give the opener browser's platform delegate an opportunity to modify the
// new browser's platform delegate.
opener->platform_delegate_->PopupWebContentsCreated(
settings_, client_, web_contents, platform_delegate_.get(),
/*is_devtools_popup=*/false);
}
platform_delegate_->WebContentsCreated(web_contents,
/*own_web_contents=*/false);
contents_delegate_->ObserveWebContents(web_contents);
// Associate the platform delegate with this browser.
platform_delegate_->BrowserCreated(this);
// Associate the base class with the WebContents.
InitializeBrowser();
// Notify that the browser has been created. These must be delivered in the
// expected order.
// 1. Notify the browser's LifeSpanHandler. This must always be the first
// notification for the browser.
{
// 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();
}
// 2. Notify the platform delegate. With Views this will result in a call to
// CefBrowserViewDelegate::OnBrowserCreated().
platform_delegate_->NotifyBrowserCreated();
if (opener && opener->platform_delegate_) {
// 3. Notify the opener browser's platform delegate. With Views this will
// result in a call to CefBrowserViewDelegate::OnPopupBrowserViewCreated().
opener->platform_delegate_->PopupBrowserCreated(
this,
/*is_devtools_popup=*/false);
}
}
void ChromeBrowserHostImpl::SetBrowser(Browser* browser) {
@@ -481,21 +545,6 @@ void ChromeBrowserHostImpl::SetBrowser(Browser* browser) {
->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::WindowDestroyed() {
CEF_REQUIRE_UIT();
#if defined(TOOLKIT_VIEWS)

View File

@@ -142,17 +142,24 @@ class ChromeBrowserHostImpl : public CefBrowserHostBase {
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);
// Create a new Browser without initializing the WebContents.
static Browser* CreateBrowser(const CefBrowserCreateParams& params);
// 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.
// Called from ChromeBrowserDelegate::CreateBrowser when this object is first
// created. Must be called on the UI thread.
void Attach(content::WebContents* web_contents,
CefRefPtr<ChromeBrowserHostImpl> opener);
// Called from ChromeBrowserDelegate::AddNewContents to take ownership of a
// popup WebContents.
void AddNewContents(std::unique_ptr<content::WebContents> contents);
// Called when this object changes Browser ownership (e.g. initially created,
// dragging between windows, etc). The old Browser, if any, 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 WindowDestroyed() override;
void DestroyBrowser() override;

View File

@@ -4,10 +4,12 @@
#include "libcef/browser/chrome/chrome_browser_main_extra_parts_cef.h"
#include "libcef/browser/chrome/chrome_context_menu_handler.h"
#include "libcef/browser/context.h"
#include "libcef/browser/net/chrome_scheme_handler.h"
#include "base/task/post_task.h"
#include "base/task/thread_pool.h"
ChromeBrowserMainExtraPartsCef::ChromeBrowserMainExtraPartsCef() = default;
@@ -23,15 +25,16 @@ void ChromeBrowserMainExtraPartsCef::PostProfileInit() {
}
void ChromeBrowserMainExtraPartsCef::PreMainMessageLoopRun() {
background_task_runner_ = base::CreateSingleThreadTaskRunner(
{base::ThreadPool(), base::TaskPriority::BEST_EFFORT,
background_task_runner_ = base::ThreadPool::CreateSingleThreadTaskRunner(
{base::TaskPriority::BEST_EFFORT,
base::TaskShutdownBehavior::BLOCK_SHUTDOWN, base::MayBlock()});
user_visible_task_runner_ = base::CreateSingleThreadTaskRunner(
{base::ThreadPool(), base::TaskPriority::USER_VISIBLE,
user_visible_task_runner_ = base::ThreadPool::CreateSingleThreadTaskRunner(
{base::TaskPriority::USER_VISIBLE,
base::TaskShutdownBehavior::BLOCK_SHUTDOWN, base::MayBlock()});
user_blocking_task_runner_ = base::CreateSingleThreadTaskRunner(
{base::ThreadPool(), base::TaskPriority::USER_BLOCKING,
user_blocking_task_runner_ = base::ThreadPool::CreateSingleThreadTaskRunner(
{base::TaskPriority::USER_BLOCKING,
base::TaskShutdownBehavior::BLOCK_SHUTDOWN, base::MayBlock()});
scheme::RegisterWebUIControllerFactory();
context_menu::RegisterMenuCreatedCallback();
}

View File

@@ -7,13 +7,17 @@
#include "libcef/browser/browser_info_manager.h"
#include "libcef/browser/browser_message_filter.h"
#include "libcef/browser/chrome/chrome_browser_host_impl.h"
#include "libcef/browser/chrome/chrome_browser_main_extra_parts_cef.h"
#include "libcef/browser/context.h"
#include "libcef/browser/net/chrome_scheme_handler.h"
#include "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/browser/prefs/browser_prefs.h"
#include "libcef/browser/prefs/renderer_prefs.h"
#include "libcef/common/app_manager.h"
#include "libcef/common/cef_switches.h"
#include "libcef/common/command_line_impl.h"
@@ -25,7 +29,11 @@
#include "chrome/common/chrome_switches.h"
#include "content/public/browser/navigation_throttle.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/common/content_switches.h"
#include "third_party/blink/public/common/web_preferences/web_preferences.h"
#include "third_party/blink/public/mojom/loader/resource_load_info.mojom-shared.h"
namespace {
@@ -33,13 +41,15 @@ namespace {
void HandleExternalProtocolHelper(
ChromeContentBrowserClientCef* self,
content::WebContents::OnceGetter web_contents_getter,
int frame_tree_node_id,
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,
content::ChildProcessHost::kInvalidUniqueID, frame_tree_node_id,
navigation_data,
resource_request.resource_type ==
static_cast<int>(blink::mojom::ResourceType::kMainFrame),
static_cast<ui::PageTransition>(resource_request.transition_type),
@@ -82,6 +92,16 @@ void ChromeContentBrowserClientCef::AppendExtraCommandLineSwitches(
const base::CommandLine* browser_cmd = base::CommandLine::ForCurrentProcess();
{
// Propagate the following switches to all command lines (along with any
// associated values) if present in the browser command line.
static const char* const kSwitchNames[] = {
switches::kUserAgentProductAndVersion,
};
command_line->CopySwitchesFrom(*browser_cmd, kSwitchNames,
base::size(kSwitchNames));
}
const std::string& process_type =
command_line->GetSwitchValueASCII(switches::kProcessType);
if (process_type == switches::kRendererProcess) {
@@ -148,6 +168,33 @@ bool ChromeContentBrowserClientCef::CanCreateWindow(
user_gesture, opener_suppressed, no_javascript_access);
}
void ChromeContentBrowserClientCef::OverrideWebkitPrefs(
content::WebContents* web_contents,
blink::web_pref::WebPreferences* prefs) {
renderer_prefs::SetDefaultPrefs(*prefs);
ChromeContentBrowserClient::OverrideWebkitPrefs(web_contents, prefs);
auto browser = ChromeBrowserHostImpl::GetBrowserForContents(web_contents);
if (browser) {
renderer_prefs::SetCefPrefs(browser->settings(), *prefs);
// Set the background color for the WebView.
prefs->base_background_color = browser->GetBackgroundColor();
} else {
// We don't know for sure that the browser will be windowless but assume
// that the global windowless state is likely to be accurate.
prefs->base_background_color =
CefContext::Get()->GetBackgroundColor(nullptr, STATE_DEFAULT);
}
auto rvh = web_contents->GetRenderViewHost();
if (rvh->GetWidget()->GetView()) {
rvh->GetWidget()->GetView()->SetBackgroundColor(
prefs->base_background_color);
}
}
bool ChromeContentBrowserClientCef::WillCreateURLLoaderFactory(
content::BrowserContext* browser_context,
content::RenderFrameHost* frame,
@@ -175,7 +222,7 @@ bool ChromeContentBrowserClientCef::WillCreateURLLoaderFactory(
// For example, the User Manager profile created via
// profiles::CreateSystemProfileForUserManager.
auto profile = Profile::FromBrowserContext(browser_context);
if (!CefBrowserContext::FromBrowserContext(profile->GetOriginalProfile()))
if (!CefBrowserContext::FromProfile(profile))
return false;
auto request_handler = net_service::CreateInterceptedRequestHandler(
@@ -193,6 +240,7 @@ bool ChromeContentBrowserClientCef::HandleExternalProtocol(
const GURL& url,
content::WebContents::OnceGetter web_contents_getter,
int child_id,
int frame_tree_node_id,
content::NavigationUIData* navigation_data,
bool is_main_frame,
ui::PageTransition page_transition,
@@ -210,9 +258,9 @@ bool ChromeContentBrowserClientCef::HandleExternalProtocol(
// 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);
url, std::move(web_contents_getter), child_id, frame_tree_node_id,
navigation_data, is_main_frame, page_transition, has_user_gesture,
initiating_origin, nullptr);
}
bool ChromeContentBrowserClientCef::HandleExternalProtocol(
@@ -228,7 +276,8 @@ bool ChromeContentBrowserClientCef::HandleExternalProtocol(
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));
web_contents_getter, frame_tree_node_id, navigation_data,
resource_request));
net_service::ProxyURLLoaderFactory::CreateProxy(
web_contents_getter, std::move(receiver), std::move(request_handler));
@@ -258,7 +307,18 @@ void ChromeContentBrowserClientCef::ConfigureNetworkContextParams(
auto cef_context = CefBrowserContext::FromBrowserContext(context);
network_context_params->cookieable_schemes =
cef_context ? cef_context->GetCookieableSchemes()
: CefCookieManagerImpl::GetGlobalCookieableSchemes();
: CefBrowserContext::GetGlobalCookieableSchemes();
// Prefer the CEF settings configuration, if specified, instead of the
// kAcceptLanguages preference which is controlled by the
// chrome://settings/languages configuration.
const std::string& accept_language_list =
browser_prefs::GetAcceptLanguageList(cef_context, /*browser=*/nullptr,
/*expand=*/true);
if (!accept_language_list.empty() &&
accept_language_list != network_context_params->accept_language) {
network_context_params->accept_language = accept_language_list;
}
}
std::unique_ptr<content::LoginDelegate>

View File

@@ -40,6 +40,8 @@ class ChromeContentBrowserClientCef : public ChromeContentBrowserClient {
bool user_gesture,
bool opener_suppressed,
bool* no_javascript_access) override;
void OverrideWebkitPrefs(content::WebContents* web_contents,
blink::web_pref::WebPreferences* prefs) override;
bool WillCreateURLLoaderFactory(
content::BrowserContext* browser_context,
content::RenderFrameHost* frame,
@@ -58,6 +60,7 @@ class ChromeContentBrowserClientCef : public ChromeContentBrowserClient {
const GURL& url,
content::WebContents::OnceGetter web_contents_getter,
int child_id,
int frame_tree_node_id,
content::NavigationUIData* navigation_data,
bool is_main_frame,
ui::PageTransition page_transition,

View File

@@ -0,0 +1,207 @@
// Copyright (c) 2021 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_context_menu_handler.h"
#include "libcef/browser/browser_host_base.h"
#include "libcef/browser/context_menu_params_impl.h"
#include "libcef/browser/simple_menu_model_impl.h"
#include "chrome/browser/renderer_context_menu/render_view_context_menu.h"
namespace context_menu {
namespace {
// Lifespan is controlled by RenderViewContextMenu.
class CefContextMenuObserver : public RenderViewContextMenuObserver,
public CefSimpleMenuModelImpl::StateDelegate {
public:
CefContextMenuObserver(RenderViewContextMenu* context_menu,
CefRefPtr<CefBrowserHostBase> browser,
CefRefPtr<CefContextMenuHandler> handler)
: context_menu_(context_menu), browser_(browser), handler_(handler) {}
// RenderViewContextMenuObserver methods:
void InitMenu(const content::ContextMenuParams& params) override {
params_ = new CefContextMenuParamsImpl(
const_cast<content::ContextMenuParams*>(&context_menu_->params()));
model_ = new CefSimpleMenuModelImpl(
const_cast<ui::SimpleMenuModel*>(&context_menu_->menu_model()),
context_menu_, this, /*is_owned=*/false, /*is_popup=*/false);
handler_->OnBeforeContextMenu(browser_, GetFrame(), params_, model_);
}
bool IsCommandIdSupported(int command_id) override {
// Always claim support for the reserved user ID range.
if (command_id >= MENU_ID_USER_FIRST && command_id <= MENU_ID_USER_LAST)
return true;
// Also claim support in specific cases where an ItemInfo exists.
return GetItemInfo(command_id) != nullptr;
}
// Only called if IsCommandIdSupported() returns true.
bool IsCommandIdEnabled(int command_id) override {
// Always return true to use the SimpleMenuModel state.
return true;
}
// Only called if IsCommandIdSupported() returns true.
bool IsCommandIdChecked(int command_id) override {
auto* info = GetItemInfo(command_id);
return info ? info->checked : false;
}
// Only called if IsCommandIdSupported() returns true.
bool GetAccelerator(int command_id, ui::Accelerator* accel) override {
auto* info = GetItemInfo(command_id);
if (info && info->accel) {
*accel = *info->accel;
return true;
}
return false;
}
void CommandWillBeExecuted(int command_id) override {
if (handler_->OnContextMenuCommand(browser_, GetFrame(), params_,
command_id, EVENTFLAG_NONE)) {
// Create an ItemInfo so that we get the ExecuteCommand() callback
// instead of the default handler.
GetOrCreateItemInfo(command_id);
}
}
// Only called if IsCommandIdSupported() returns true.
void ExecuteCommand(int command_id) override {
auto* info = GetItemInfo(command_id);
if (info) {
// In case it was added in CommandWillBeExecuted().
MaybeDeleteItemInfo(command_id, info);
}
}
void OnMenuClosed() override {
handler_->OnContextMenuDismissed(browser_, GetFrame());
model_->Detach();
// Clear stored state because this object won't be deleted until a new
// context menu is created or the associated browser is destroyed.
browser_ = nullptr;
handler_ = nullptr;
params_ = nullptr;
model_ = nullptr;
iteminfomap_.clear();
}
// CefSimpleMenuModelImpl::StateDelegate methods:
void SetChecked(int command_id, bool checked) override {
// No-op if already at the default state.
if (!checked && !GetItemInfo(command_id))
return;
auto* info = GetOrCreateItemInfo(command_id);
info->checked = checked;
if (!checked)
MaybeDeleteItemInfo(command_id, info);
}
void SetAccelerator(int command_id,
base::Optional<ui::Accelerator> accel) override {
// No-op if already at the default state.
if (!accel && !GetItemInfo(command_id))
return;
auto* info = GetOrCreateItemInfo(command_id);
info->accel = accel;
if (!accel)
MaybeDeleteItemInfo(command_id, info);
}
private:
struct ItemInfo {
ItemInfo() {}
bool checked = false;
base::Optional<ui::Accelerator> accel;
};
ItemInfo* GetItemInfo(int command_id) {
auto it = iteminfomap_.find(command_id);
if (it != iteminfomap_.end()) {
return &it->second;
}
return nullptr;
}
ItemInfo* GetOrCreateItemInfo(int command_id) {
if (auto info = GetItemInfo(command_id))
return info;
auto result = iteminfomap_.insert(std::make_pair(command_id, ItemInfo()));
return &result.first->second;
}
void MaybeDeleteItemInfo(int command_id, ItemInfo* info) {
// Remove if all info has reverted to the default state.
if (!info->checked && !info->accel) {
auto it = iteminfomap_.find(command_id);
iteminfomap_.erase(it);
}
}
CefRefPtr<CefFrame> GetFrame() const {
CefRefPtr<CefFrame> frame;
// May return nullptr if the frame is destroyed while the menu is pending.
auto* rfh = context_menu_->GetRenderFrameHost();
if (rfh) {
frame = browser_->GetFrameForHost(rfh);
}
if (!frame) {
frame = browser_->GetMainFrame();
}
return frame;
}
RenderViewContextMenu* const context_menu_;
CefRefPtr<CefBrowserHostBase> browser_;
CefRefPtr<CefContextMenuHandler> handler_;
CefRefPtr<CefContextMenuParams> params_;
CefRefPtr<CefSimpleMenuModelImpl> model_;
// Map of command_id to ItemInfo.
using ItemInfoMap = std::map<int, ItemInfo>;
ItemInfoMap iteminfomap_;
DISALLOW_COPY_AND_ASSIGN(CefContextMenuObserver);
};
std::unique_ptr<RenderViewContextMenuObserver> MenuCreatedCallback(
RenderViewContextMenu* context_menu) {
auto browser = CefBrowserHostBase::GetBrowserForContents(
context_menu->source_web_contents());
if (browser) {
if (auto client = browser->GetClient()) {
if (auto handler = client->GetContextMenuHandler()) {
return std::make_unique<CefContextMenuObserver>(context_menu, browser,
handler);
}
}
}
return nullptr;
}
} // namespace
void RegisterMenuCreatedCallback() {
RenderViewContextMenu::RegisterMenuCreatedCallback(
base::BindRepeating(&MenuCreatedCallback));
}
} // namespace context_menu

View File

@@ -0,0 +1,16 @@
// Copyright (c) 2021 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_CONTEXT_MENU_HANDLER_H_
#define CEF_LIBCEF_BROWSER_CHROME_CHROME_CONTEXT_MENU_HANDLER_H_
#pragma once
namespace context_menu {
// Register the context menu created callback.
void RegisterMenuCreatedCallback();
} // namespace context_menu
#endif // CEF_LIBCEF_BROWSER_CHROME_CHROME_CONTEXT_MENU_HANDLER_H_

View File

@@ -4,14 +4,59 @@
#include "libcef/browser/chrome/views/browser_platform_delegate_chrome_views.h"
#include "include/views/cef_window.h"
#include "chrome/browser/ui/browser.h"
#include "ui/views/widget/widget.h"
namespace {
// Default popup window delegate implementation.
class PopupWindowDelegate : public CefWindowDelegate {
public:
explicit PopupWindowDelegate(CefRefPtr<CefBrowserView> browser_view)
: browser_view_(browser_view) {}
void OnWindowCreated(CefRefPtr<CefWindow> window) override {
window->AddChildView(browser_view_);
window->Show();
browser_view_->RequestFocus();
}
void OnWindowDestroyed(CefRefPtr<CefWindow> window) override {
browser_view_ = nullptr;
}
bool CanClose(CefRefPtr<CefWindow> window) override {
CefRefPtr<CefBrowser> browser = browser_view_->GetBrowser();
if (browser)
return browser->GetHost()->TryCloseBrowser();
return true;
}
private:
CefRefPtr<CefBrowserView> browser_view_;
IMPLEMENT_REFCOUNTING(PopupWindowDelegate);
DISALLOW_COPY_AND_ASSIGN(PopupWindowDelegate);
};
} // namespace
CefBrowserPlatformDelegateChromeViews::CefBrowserPlatformDelegateChromeViews(
std::unique_ptr<CefBrowserPlatformDelegateNative> native_delegate,
CefRefPtr<CefBrowserViewImpl> browser_view)
: CefBrowserPlatformDelegateChrome(std::move(native_delegate)),
browser_view_(browser_view) {}
: CefBrowserPlatformDelegateChrome(std::move(native_delegate)) {
if (browser_view)
SetBrowserView(browser_view);
}
void CefBrowserPlatformDelegateChromeViews::SetBrowserView(
CefRefPtr<CefBrowserViewImpl> browser_view) {
DCHECK(!browser_view_);
DCHECK(browser_view);
browser_view_ = browser_view;
}
void CefBrowserPlatformDelegateChromeViews::WebContentsCreated(
content::WebContents* web_contents,
@@ -59,6 +104,50 @@ CefBrowserPlatformDelegateChromeViews::GetBrowserView() const {
return browser_view_.get();
}
void CefBrowserPlatformDelegateChromeViews::PopupWebContentsCreated(
const CefBrowserSettings& settings,
CefRefPtr<CefClient> client,
content::WebContents* new_web_contents,
CefBrowserPlatformDelegate* new_platform_delegate,
bool is_devtools) {
DCHECK(new_platform_delegate->IsViewsHosted());
auto* new_platform_delegate_impl =
static_cast<CefBrowserPlatformDelegateChromeViews*>(
new_platform_delegate);
CefRefPtr<CefBrowserViewDelegate> new_delegate;
if (browser_view_->delegate()) {
new_delegate = browser_view_->delegate()->GetDelegateForPopupBrowserView(
browser_view_.get(), settings, client, is_devtools);
}
// Create a new BrowserView for the popup.
CefRefPtr<CefBrowserViewImpl> new_browser_view =
CefBrowserViewImpl::CreateForPopup(settings, new_delegate);
// Associate the PlatformDelegate with the new BrowserView.
new_platform_delegate_impl->SetBrowserView(new_browser_view);
}
void CefBrowserPlatformDelegateChromeViews::PopupBrowserCreated(
CefBrowserHostBase* new_browser,
bool is_devtools) {
CefRefPtr<CefBrowserView> new_browser_view =
CefBrowserView::GetForBrowser(new_browser);
DCHECK(new_browser_view);
bool popup_handled = false;
if (browser_view_->delegate()) {
popup_handled = browser_view_->delegate()->OnPopupBrowserViewCreated(
browser_view_.get(), new_browser_view.get(), is_devtools);
}
if (!popup_handled) {
CefWindow::CreateTopLevelWindow(
new PopupWindowDelegate(new_browser_view.get()));
}
}
bool CefBrowserPlatformDelegateChromeViews::IsViewsHosted() const {
return true;
}

View File

@@ -26,9 +26,19 @@ class CefBrowserPlatformDelegateChromeViews
void CloseHostWindow() override;
views::Widget* GetWindowWidget() const override;
CefRefPtr<CefBrowserView> GetBrowserView() const override;
void PopupWebContentsCreated(
const CefBrowserSettings& settings,
CefRefPtr<CefClient> client,
content::WebContents* new_web_contents,
CefBrowserPlatformDelegate* new_platform_delegate,
bool is_devtools) override;
void PopupBrowserCreated(CefBrowserHostBase* new_browser,
bool is_devtools) override;
bool IsViewsHosted() const override;
private:
void SetBrowserView(CefRefPtr<CefBrowserViewImpl> browser_view);
CefRefPtr<CefBrowserViewImpl> browser_view_;
};

View File

@@ -68,3 +68,31 @@ void ChromeBrowserView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
ParentClass::OnBoundsChanged(previous_bounds);
browser_view_delegate_->OnBoundsChanged();
}
ToolbarView* ChromeBrowserView::OverrideCreateToolbar(
Browser* browser,
BrowserView* browser_view) {
if (cef_delegate()) {
auto toolbar_type = cef_delegate()->GetChromeToolbarType();
base::Optional<ToolbarView::DisplayMode> display_mode;
switch (toolbar_type) {
case CEF_CTT_NORMAL:
display_mode = ToolbarView::DisplayMode::NORMAL;
break;
case CEF_CTT_LOCATION:
display_mode = ToolbarView::DisplayMode::LOCATION;
break;
default:
break;
}
if (display_mode) {
cef_toolbar_ = CefToolbarViewImpl::Create(nullptr, browser, browser_view,
display_mode);
// Ownership will be taken by BrowserView.
view_util::PassOwnership(cef_toolbar_).release();
return cef_toolbar_->root_view();
}
}
return nullptr;
}

View File

@@ -8,6 +8,7 @@
#include "include/views/cef_browser_view.h"
#include "include/views/cef_browser_view_delegate.h"
#include "libcef/browser/chrome/views/toolbar_view_impl.h"
#include "libcef/browser/views/browser_view_view.h"
#include "libcef/browser/views/view_view.h"
@@ -42,6 +43,12 @@ class ChromeBrowserView
void AddedToWidget() override;
void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
// BrowserView methods:
ToolbarView* OverrideCreateToolbar(Browser* browser,
BrowserView* browser_view) override;
CefRefPtr<CefToolbarViewImpl> cef_toolbar() const { return cef_toolbar_; }
private:
// Not owned by this object.
Delegate* browser_view_delegate_;
@@ -51,6 +58,8 @@ class ChromeBrowserView
bool destroyed_ = false;
CefRefPtr<CefToolbarViewImpl> cef_toolbar_;
DISALLOW_COPY_AND_ASSIGN(ChromeBrowserView);
};

View File

@@ -0,0 +1,40 @@
// Copyright 2021 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/views/toolbar_view_impl.h"
// static
CefRefPtr<CefToolbarViewImpl> CefToolbarViewImpl::Create(
CefRefPtr<CefViewDelegate> delegate,
Browser* browser,
BrowserView* browser_view,
base::Optional<ToolbarView::DisplayMode> display_mode) {
CEF_REQUIRE_UIT_RETURN(nullptr);
CefRefPtr<CefToolbarViewImpl> view =
new CefToolbarViewImpl(delegate, browser, browser_view, display_mode);
view->Initialize();
return view;
}
// static
const char* const CefToolbarViewImpl::kTypeString = "ToolbarView";
CefToolbarViewImpl::CefToolbarViewImpl(
CefRefPtr<CefViewDelegate> delegate,
Browser* browser,
BrowserView* browser_view,
base::Optional<ToolbarView::DisplayMode> display_mode)
: ParentClass(delegate),
browser_(browser),
browser_view_(browser_view),
display_mode_(display_mode) {}
CefToolbarViewView* CefToolbarViewImpl::CreateRootView() {
return new CefToolbarViewView(delegate(), browser_, browser_view_,
display_mode_);
}
void CefToolbarViewImpl::InitializeRootView() {
static_cast<CefToolbarViewView*>(root_view())->Initialize();
}

View File

@@ -0,0 +1,55 @@
// Copyright 2021 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_VIEWS_TOOLBAR_VIEW_IMPL_H_
#define CEF_LIBCEF_BROWSER_CHROME_VIEWS_TOOLBAR_VIEW_IMPL_H_
#pragma once
#include "include/views/cef_view_delegate.h"
#include "libcef/browser/chrome/views/toolbar_view_view.h"
#include "libcef/browser/views/view_impl.h"
class Browser;
class BrowserView;
class CefToolbarViewImpl
: public CefViewImpl<CefToolbarViewView, CefView, CefViewDelegate> {
public:
typedef CefViewImpl<CefToolbarViewView, CefView, CefViewDelegate> ParentClass;
// Create a new CefToolbarViewImpl instance. |delegate| may be nullptr.
static CefRefPtr<CefToolbarViewImpl> Create(
CefRefPtr<CefViewDelegate> delegate,
Browser* browser,
BrowserView* browser_view,
base::Optional<ToolbarView::DisplayMode> display_mode);
static const char* const kTypeString;
// CefViewAdapter methods:
std::string GetDebugType() override { return kTypeString; }
private:
// Create a new implementation object.
// Always call Initialize() after creation.
// |delegate| may be nullptr.
CefToolbarViewImpl(CefRefPtr<CefViewDelegate> delegate,
Browser* browser,
BrowserView* browser_view,
base::Optional<ToolbarView::DisplayMode> display_mode);
// CefViewImpl methods:
CefToolbarViewView* CreateRootView() override;
void InitializeRootView() override;
Browser* const browser_;
BrowserView* const browser_view_;
base::Optional<ToolbarView::DisplayMode> const display_mode_;
IMPLEMENT_REFCOUNTING_DELETE_ON_UIT(CefToolbarViewImpl);
DISALLOW_COPY_AND_ASSIGN(CefToolbarViewImpl);
};
#endif // CEF_LIBCEF_BROWSER_VIEWS_SCROLL_VIEW_IMPL_H_

View File

@@ -0,0 +1,11 @@
// Copyright 2021 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/views/toolbar_view_view.h"
CefToolbarViewView::CefToolbarViewView(CefViewDelegate* cef_delegate,
Browser* browser,
BrowserView* browser_view,
base::Optional<DisplayMode> display_mode)
: ParentClass(cef_delegate, browser, browser_view, display_mode) {}

View File

@@ -0,0 +1,27 @@
// Copyright 2021 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_VIEWS_TOOLBAR_VIEW_VIEW_H_
#define CEF_LIBCEF_BROWSER_CHROME_VIEWS_TOOLBAR_VIEW_VIEW_H_
#pragma once
#include "libcef/browser/views/view_view.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
class CefToolbarViewView : public CefViewView<ToolbarView, CefViewDelegate> {
public:
typedef CefViewView<ToolbarView, CefViewDelegate> ParentClass;
// |cef_delegate| may be nullptr.
explicit CefToolbarViewView(CefViewDelegate* cef_delegate,
Browser* browser,
BrowserView* browser_view,
base::Optional<DisplayMode> display_mode);
private:
DISALLOW_COPY_AND_ASSIGN(CefToolbarViewView);
};
#endif // CEF_LIBCEF_BROWSER_CHROME_VIEWS_TOOLBAR_VIEW_VIEW_H_

View File

@@ -5,6 +5,7 @@
#include "libcef/browser/context.h"
#include "libcef/browser/browser_info_manager.h"
#include "libcef/browser/request_context_impl.h"
#include "libcef/browser/thread_util.h"
#include "libcef/browser/trace_subscriber.h"
#include "libcef/common/cef_switches.h"
@@ -434,8 +435,11 @@ void CefContext::PopulateGlobalRequestContextSettings(
settings->ignore_certificate_errors =
settings_.ignore_certificate_errors ||
command_line->HasSwitch(switches::kIgnoreCertificateErrors);
CefString(&settings->accept_language_list) =
CefString(&settings_.accept_language_list);
CefString(&settings->cookieable_schemes_list) =
CefString(&settings_.cookieable_schemes_list);
settings->cookieable_schemes_exclude_defaults =
settings_.cookieable_schemes_exclude_defaults;
}
void CefContext::NormalizeRequestContextSettings(
@@ -443,12 +447,6 @@ void CefContext::NormalizeRequestContextSettings(
// The |root_cache_path| value was already normalized in Initialize.
const base::FilePath& root_cache_path = CefString(&settings_.root_cache_path);
NormalizeCachePathAndSet(settings->cache_path, root_cache_path);
if (settings->accept_language_list.length == 0) {
// Use the global language list setting.
CefString(&settings->accept_language_list) =
CefString(&settings_.accept_language_list);
}
}
void CefContext::AddObserver(Observer* observer) {
@@ -469,12 +467,19 @@ bool CefContext::HasObserver(Observer* observer) const {
void CefContext::OnContextInitialized() {
CEF_REQUIRE_UIT();
// Notify the handler.
if (application_) {
CefRefPtr<CefBrowserProcessHandler> handler =
application_->GetBrowserProcessHandler();
if (handler)
handler->OnContextInitialized();
// Notify the handler after the global browser context has initialized.
CefRefPtr<CefRequestContext> request_context =
CefRequestContext::GetGlobalContext();
auto impl = static_cast<CefRequestContextImpl*>(request_context.get());
impl->ExecuteWhenBrowserContextInitialized(base::BindOnce(
[](CefRefPtr<CefApp> app) {
CefRefPtr<CefBrowserProcessHandler> handler =
app->GetBrowserProcessHandler();
if (handler)
handler->OnContextInitialized();
},
application_));
}
}

View File

@@ -119,7 +119,7 @@ bool CefContextMenuParamsImpl::GetDictionarySuggestions(
if (const_value().dictionary_suggestions.empty())
return false;
std::vector<base::string16>::const_iterator it =
std::vector<std::u16string>::const_iterator it =
const_value().dictionary_suggestions.begin();
for (; it != const_value().dictionary_suggestions.end(); ++it)
suggestions.push_back(*it);

View File

@@ -91,7 +91,7 @@ void CefDevToolsController::RemoveObserver(Observer* observer) {
void CefDevToolsController::DispatchProtocolMessage(
content::DevToolsAgentHost* agent_host,
base::span<const uint8_t> message) {
if (!observers_.might_have_observers())
if (observers_.empty())
return;
base::StringPiece str_message(reinterpret_cast<const char*>(message.data()),

View File

@@ -15,6 +15,7 @@
#include "base/path_service.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/post_task.h"
#include "base/task/thread_pool.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "base/util/values/values_util.h"
#include "base/values.h"
@@ -44,8 +45,8 @@ CefDevToolsFileManager::CefDevToolsFileManager(
PrefService* prefs)
: browser_impl_(browser_impl),
prefs_(prefs),
file_task_runner_(base::CreateSequencedTaskRunner(
{base::ThreadPool(), base::MayBlock()})),
file_task_runner_(
base::ThreadPool::CreateSequencedTaskRunner({base::MayBlock()})),
weak_factory_(this) {}
void CefDevToolsFileManager::SaveToFile(const std::string& url,

View File

@@ -338,7 +338,8 @@ void CefDevToolsFrontend::ReadyToCommitNavigation(
content::DevToolsFrontendHost::SetupExtensionsAPI(frame, script);
}
void CefDevToolsFrontend::DocumentAvailableInMainFrame() {
void CefDevToolsFrontend::DocumentAvailableInMainFrame(
content::RenderFrameHost* render_frame_host) {
// Don't call AttachClient multiple times for the same DevToolsAgentHost.
// Otherwise it will call AgentHostClosed which closes the DevTools window.
// This may happen in cases where the DevTools content fails to load.
@@ -390,8 +391,7 @@ void CefDevToolsFrontend::HandleMessageFromDevToolsFrontend(
this, base::as_bytes(base::make_span(protocol_message)));
} else if (method == "loadCompleted") {
web_contents()->GetMainFrame()->ExecuteJavaScriptForTests(
base::ASCIIToUTF16("DevToolsAPI.setUseSoftMenu(true);"),
base::NullCallback());
u"DevToolsAPI.setUseSoftMenu(true);", base::NullCallback());
} else if (method == "loadNetworkResource" && params->GetSize() == 3) {
// TODO(pfeldman): handle some of the embedder messages in content.
std::string url;
@@ -461,7 +461,7 @@ void CefDevToolsFrontend::HandleMessageFromDevToolsFrontend(
SendMessageAck(request_id, &response);
return;
} else {
auto* partition = content::BrowserContext::GetStoragePartitionForSite(
auto* partition = content::BrowserContext::GetStoragePartitionForUrl(
web_contents()->GetBrowserContext(), gurl);
url_loader_factory = partition->GetURLLoaderFactoryForBrowserProcess();
}
@@ -493,8 +493,7 @@ void CefDevToolsFrontend::HandleMessageFromDevToolsFrontend(
update.Get()->RemoveWithoutPathExpansion(name, nullptr);
} else if (method == "requestFileSystems") {
web_contents()->GetMainFrame()->ExecuteJavaScriptForTests(
base::ASCIIToUTF16("DevToolsAPI.fileSystemsLoaded([]);"),
base::NullCallback());
u"DevToolsAPI.fileSystemsLoaded([]);", base::NullCallback());
} else if (method == "reattach") {
if (!agent_host_)
return;
@@ -533,6 +532,11 @@ void CefDevToolsFrontend::HandleMessageFromDevToolsFrontend(
void CefDevToolsFrontend::DispatchProtocolMessage(
content::DevToolsAgentHost* agent_host,
base::span<const uint8_t> message) {
if (!frontend_browser_->GetWebContents() ||
frontend_browser_->GetWebContents()->IsBeingDestroyed()) {
return;
}
base::StringPiece str_message(reinterpret_cast<const char*>(message.data()),
message.size());
if (ProtocolLoggingEnabled()) {
@@ -547,7 +551,7 @@ void CefDevToolsFrontend::DispatchProtocolMessage(
std::string param;
base::EscapeJSONString(str_message, true, &param);
std::string code = "DevToolsAPI.dispatchMessage(" + param + ");";
base::string16 javascript = base::UTF8ToUTF16(code);
std::u16string javascript = base::UTF8ToUTF16(code);
web_contents()->GetMainFrame()->ExecuteJavaScriptForTests(
javascript, base::NullCallback());
return;
@@ -561,7 +565,7 @@ void CefDevToolsFrontend::DispatchProtocolMessage(
&param);
std::string code = "DevToolsAPI.dispatchMessageChunk(" + param + "," +
std::to_string(pos ? 0 : total_size) + ");";
base::string16 javascript = base::UTF8ToUTF16(code);
std::u16string javascript = base::UTF8ToUTF16(code);
web_contents()->GetMainFrame()->ExecuteJavaScriptForTests(
javascript, base::NullCallback());
}

View File

@@ -76,7 +76,8 @@ class CefDevToolsFrontend : public content::WebContentsObserver,
// WebContentsObserver overrides
void ReadyToCommitNavigation(
content::NavigationHandle* navigation_handle) override;
void DocumentAvailableInMainFrame() override;
void DocumentAvailableInMainFrame(
content::RenderFrameHost* render_frame_host) override;
void WebContentsDestroyed() override;
void SendMessageAck(int request_id, const base::Value* arg1);

View File

@@ -0,0 +1,20 @@
// Copyright 2021 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/extensions/alloy_extensions_util.h"
#include "libcef/browser/alloy/alloy_browser_host_impl.h"
namespace extensions {
namespace alloy {
int GetTabIdForWebContents(content::WebContents* web_contents) {
auto browser = AlloyBrowserHostImpl::GetBrowserForContents(web_contents);
if (!browser)
return -1;
return browser->GetIdentifier();
}
} // namespace alloy
} // namespace extensions

View File

@@ -0,0 +1,21 @@
// Copyright 2021 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_EXTENSIONS_ALLOY_EXTENSIONS_UTIL_H_
#define CEF_LIBCEF_BROWSER_EXTENSIONS_ALLOY_EXTENSIONS_UTIL_H_
namespace content {
class WebContents;
}
namespace extensions {
namespace alloy {
// Returns the tabId for |web_contents|, or -1 if not found.
int GetTabIdForWebContents(content::WebContents* web_contents);
} // namespace alloy
} // namespace extensions
#endif // CEF_LIBCEF_BROWSER_EXTENSIONS_ALLOY_EXTENSIONS_UTIL_H_

View File

@@ -56,7 +56,7 @@ void SyncValueStoreCache::RunWithValueStoreForExtension(
// A neat way to implement unlimited storage; if the extension has the
// unlimited storage permission, force through all calls to Set().
if (extension->permissions_data()->HasAPIPermission(
APIPermission::kUnlimitedStorage)) {
mojom::APIPermissionID::kUnlimitedStorage)) {
WeakUnlimitedSettingsStorage unlimited_storage(storage);
std::move(callback).Run(&unlimited_storage);
} else {

View File

@@ -6,10 +6,15 @@
#include "libcef/browser/extensions/extension_web_contents_observer.h"
#include "base/notreached.h"
#include "base/strings/string_number_conversions.h"
#include "chrome/browser/extensions/api/tabs/tabs_constants.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#include "components/zoom/zoom_controller.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/site_instance.h"
#include "extensions/browser/extension_api_frame_id_map.h"
#include "extensions/browser/extension_zoom_request_client.h"
#include "extensions/common/error_utils.h"
@@ -17,6 +22,8 @@
#include "extensions/common/permissions/permissions_data.h"
#include "third_party/blink/public/common/page/page_zoom.h"
using zoom::ZoomController;
namespace extensions {
namespace cef {
@@ -97,6 +104,148 @@ ExtensionFunction::ResponseAction TabsCreateFunction::Run() {
: NoArguments());
}
BaseAPIFunction::BaseAPIFunction() : cef_details_(this) {}
content::WebContents* BaseAPIFunction::GetWebContents(int tab_id) {
// Find a browser that we can access, or set |error_| and return nullptr.
CefRefPtr<AlloyBrowserHostImpl> browser =
cef_details_.GetBrowserForTabIdFirstTime(tab_id, &error_);
if (!browser)
return nullptr;
return browser->web_contents();
}
ExtensionFunction::ResponseAction TabsUpdateFunction::Run() {
std::unique_ptr<tabs::Update::Params> params(
tabs::Update::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());
tab_id_ = params->tab_id ? *params->tab_id : -1;
content::WebContents* web_contents = GetWebContents(tab_id_);
if (!web_contents)
return RespondNow(Error(std::move(error_)));
web_contents_ = web_contents;
// TODO(rafaelw): handle setting remaining tab properties:
// -title
// -favIconUrl
// Navigate the tab to a new location if the url is different.
if (params->update_properties.url.get()) {
std::string updated_url = *params->update_properties.url;
if (!UpdateURL(updated_url, tab_id_, &error_))
return RespondNow(Error(std::move(error_)));
}
bool active = false;
// TODO(rafaelw): Setting |active| from js doesn't make much sense.
// Move tab selection management up to window.
if (params->update_properties.selected.get())
active = *params->update_properties.selected;
// The 'active' property has replaced 'selected'.
if (params->update_properties.active.get())
active = *params->update_properties.active;
if (active) {
// TODO: Activate the tab at |tab_id_|.
NOTIMPLEMENTED();
return RespondNow(Error(tabs_constants::kTabStripNotEditableError));
}
if (params->update_properties.highlighted.get() &&
*params->update_properties.highlighted) {
// TODO: Highlight the tab at |tab_id_|.
NOTIMPLEMENTED();
return RespondNow(Error(tabs_constants::kTabStripNotEditableError));
}
if (params->update_properties.pinned.get() &&
*params->update_properties.pinned) {
// TODO: Pin the tab at |tab_id_|.
NOTIMPLEMENTED();
return RespondNow(Error(tabs_constants::kTabStripNotEditableError));
}
if (params->update_properties.muted.get()) {
// TODO: Mute/unmute the tab at |tab_id_|.
NOTIMPLEMENTED();
return RespondNow(Error(ErrorUtils::FormatErrorMessage(
tabs_constants::kCannotUpdateMuteCaptured,
base::NumberToString(tab_id_))));
}
if (params->update_properties.opener_tab_id.get()) {
int opener_id = *params->update_properties.opener_tab_id;
if (opener_id == tab_id_)
return RespondNow(Error("Cannot set a tab's opener to itself."));
// TODO: Set the opener for the tab at |tab_id_|.
NOTIMPLEMENTED();
return RespondNow(Error(tabs_constants::kTabStripNotEditableError));
}
if (params->update_properties.auto_discardable.get()) {
// TODO: Set auto-discardable state for the tab at |tab_id_|.
NOTIMPLEMENTED();
}
return RespondNow(GetResult());
}
bool TabsUpdateFunction::UpdateURL(const std::string& url_string,
int tab_id,
std::string* error) {
GURL url;
if (!ExtensionTabUtil::PrepareURLForNavigation(url_string, extension(), &url,
error)) {
return false;
}
const bool is_javascript_scheme = url.SchemeIs(url::kJavaScriptScheme);
// JavaScript URLs are forbidden in chrome.tabs.update().
if (is_javascript_scheme) {
*error = tabs_constants::kJavaScriptUrlsNotAllowedInTabsUpdate;
return false;
}
content::NavigationController::LoadURLParams load_params(url);
// Treat extension-initiated navigations as renderer-initiated so that the URL
// does not show in the omnibox until it commits. This avoids URL spoofs
// since URLs can be opened on behalf of untrusted content.
load_params.is_renderer_initiated = true;
// All renderer-initiated navigations need to have an initiator origin.
load_params.initiator_origin = extension()->origin();
// |source_site_instance| needs to be set so that a renderer process
// compatible with |initiator_origin| is picked by Site Isolation.
load_params.source_site_instance = content::SiteInstance::CreateForURL(
web_contents_->GetBrowserContext(),
load_params.initiator_origin->GetURL());
// Marking the navigation as initiated via an API means that the focus
// will stay in the omnibox - see https://crbug.com/1085779.
load_params.transition_type = ui::PAGE_TRANSITION_FROM_API;
web_contents_->GetController().LoadURLWithParams(load_params);
DCHECK_EQ(url,
web_contents_->GetController().GetPendingEntry()->GetVirtualURL());
return true;
}
ExtensionFunction::ResponseValue TabsUpdateFunction::GetResult() {
if (!has_callback())
return NoArguments();
return ArgumentList(tabs::Get::Results::Create(*cef_details_.CreateTabObject(
AlloyBrowserHostImpl::GetBrowserForContents(web_contents_),
/*opener_browser_id=*/-1, /*active=*/true, tab_id_)));
}
ExecuteCodeInTabFunction::ExecuteCodeInTabFunction()
: cef_details_(this), execute_tab_id_(-1) {}
@@ -128,7 +277,8 @@ ExecuteCodeFunction::InitResult ExecuteCodeInTabFunction::Init() {
execute_tab_id_ = browser->GetIdentifier();
details_ = std::move(details);
set_host_id(HostID(HostID::EXTENSIONS, extension()->id()));
set_host_id(
mojom::HostID(mojom::HostID::HostType::kExtensions, extension()->id()));
return set_init_result(SUCCESS);
}
@@ -182,7 +332,7 @@ bool ExecuteCodeInTabFunction::CanExecuteScriptOnPage(std::string* error) {
execute_tab_id_, error)) {
if (is_about_url &&
extension()->permissions_data()->active_permissions().HasAPIPermission(
APIPermission::kTab)) {
mojom::APIPermissionID::kTab)) {
*error = ErrorUtils::FormatErrorMessage(
manifest_errors::kCannotAccessAboutUrl,
rfh->GetLastCommittedURL().spec(),
@@ -243,165 +393,124 @@ bool TabsRemoveCSSFunction::ShouldRemoveCSS() const {
return true;
}
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 =
cef_details_.GetBrowserForTabIdFirstTime(tab_id, &error_);
if (!browser)
return nullptr;
return browser->web_contents();
}
void ZoomAPIFunction::SendResponse(bool success) {
ResponseValue response;
if (success) {
response = ArgumentList(std::move(results_));
} else {
response = results_ ? ErrorWithArguments(std::move(results_), error_)
: Error(error_);
}
Respond(std::move(response));
}
ExtensionFunction::ResponseAction ZoomAPIFunction::Run() {
if (RunAsync())
return RespondLater();
// TODO(devlin): Track these down and eliminate them if possible. We
// shouldn't return results and an error.
if (results_)
return RespondNow(ErrorWithArguments(std::move(results_), error_));
return RespondNow(Error(error_));
}
bool TabsSetZoomFunction::RunAsync() {
ExtensionFunction::ResponseAction TabsSetZoomFunction::Run() {
std::unique_ptr<tabs::SetZoom::Params> params(
tabs::SetZoom::Params::Create(*args_));
EXTENSION_FUNCTION_PRERUN_VALIDATE(params);
EXTENSION_FUNCTION_VALIDATE(params);
int tab_id = params->tab_id ? *params->tab_id : -1;
content::WebContents* web_contents = GetWebContents(tab_id);
if (!web_contents)
return false;
return RespondNow(Error(std::move(error_)));
GURL url(web_contents->GetVisibleURL());
if (extension()->permissions_data()->IsRestrictedUrl(url, &error_))
return false;
return RespondNow(Error(std::move(error_)));
zoom::ZoomController* zoom_controller =
zoom::ZoomController::FromWebContents(web_contents);
ZoomController* zoom_controller =
ZoomController::FromWebContents(web_contents);
double zoom_level =
params->zoom_factor > 0
? blink::PageZoomFactorToZoomLevel(params->zoom_factor)
: zoom_controller->GetDefaultZoomLevel();
scoped_refptr<extensions::ExtensionZoomRequestClient> client(
new extensions::ExtensionZoomRequestClient(extension()));
auto client = base::MakeRefCounted<ExtensionZoomRequestClient>(extension());
if (!zoom_controller->SetZoomLevelByClient(zoom_level, client)) {
// Tried to zoom a tab in disabled mode.
error_ = keys::kCannotZoomDisabledTabError;
return false;
return RespondNow(Error(tabs_constants::kCannotZoomDisabledTabError));
}
SendResponse(true);
return true;
return RespondNow(NoArguments());
}
bool TabsGetZoomFunction::RunAsync() {
ExtensionFunction::ResponseAction TabsGetZoomFunction::Run() {
std::unique_ptr<tabs::GetZoom::Params> params(
tabs::GetZoom::Params::Create(*args_));
EXTENSION_FUNCTION_PRERUN_VALIDATE(params);
EXTENSION_FUNCTION_VALIDATE(params);
int tab_id = params->tab_id ? *params->tab_id : -1;
content::WebContents* web_contents = GetWebContents(tab_id);
if (!web_contents)
return false;
return RespondNow(Error(std::move(error_)));
double zoom_level =
zoom::ZoomController::FromWebContents(web_contents)->GetZoomLevel();
double zoom_factor = blink::PageZoomLevelToZoomFactor(zoom_level);
results_ = tabs::GetZoom::Results::Create(zoom_factor);
SendResponse(true);
return true;
return RespondNow(ArgumentList(tabs::GetZoom::Results::Create(zoom_factor)));
}
bool TabsSetZoomSettingsFunction::RunAsync() {
ExtensionFunction::ResponseAction TabsSetZoomSettingsFunction::Run() {
using api::tabs::ZoomSettings;
std::unique_ptr<tabs::SetZoomSettings::Params> params(
tabs::SetZoomSettings::Params::Create(*args_));
EXTENSION_FUNCTION_PRERUN_VALIDATE(params);
EXTENSION_FUNCTION_VALIDATE(params);
int tab_id = params->tab_id ? *params->tab_id : -1;
content::WebContents* web_contents = GetWebContents(tab_id);
if (!web_contents)
return false;
return RespondNow(Error(std::move(error_)));
GURL url(web_contents->GetVisibleURL());
std::string error;
if (extension()->permissions_data()->IsRestrictedUrl(url, &error_))
return false;
return RespondNow(Error(std::move(error_)));
// "per-origin" scope is only available in "automatic" mode.
if (params->zoom_settings.scope == tabs::ZOOM_SETTINGS_SCOPE_PER_ORIGIN &&
params->zoom_settings.mode != tabs::ZOOM_SETTINGS_MODE_AUTOMATIC &&
params->zoom_settings.mode != tabs::ZOOM_SETTINGS_MODE_NONE) {
error_ = keys::kPerOriginOnlyInAutomaticError;
return false;
return RespondNow(Error(tabs_constants::kPerOriginOnlyInAutomaticError));
}
// Determine the correct internal zoom mode to set |web_contents| to from the
// user-specified |zoom_settings|.
zoom::ZoomController::ZoomMode zoom_mode =
zoom::ZoomController::ZOOM_MODE_DEFAULT;
ZoomController::ZoomMode zoom_mode = ZoomController::ZOOM_MODE_DEFAULT;
switch (params->zoom_settings.mode) {
case tabs::ZOOM_SETTINGS_MODE_NONE:
case tabs::ZOOM_SETTINGS_MODE_AUTOMATIC:
switch (params->zoom_settings.scope) {
case tabs::ZOOM_SETTINGS_SCOPE_NONE:
case tabs::ZOOM_SETTINGS_SCOPE_PER_ORIGIN:
zoom_mode = zoom::ZoomController::ZOOM_MODE_DEFAULT;
zoom_mode = ZoomController::ZOOM_MODE_DEFAULT;
break;
case tabs::ZOOM_SETTINGS_SCOPE_PER_TAB:
zoom_mode = zoom::ZoomController::ZOOM_MODE_ISOLATED;
zoom_mode = ZoomController::ZOOM_MODE_ISOLATED;
}
break;
case tabs::ZOOM_SETTINGS_MODE_MANUAL:
zoom_mode = zoom::ZoomController::ZOOM_MODE_MANUAL;
zoom_mode = ZoomController::ZOOM_MODE_MANUAL;
break;
case tabs::ZOOM_SETTINGS_MODE_DISABLED:
zoom_mode = zoom::ZoomController::ZOOM_MODE_DISABLED;
zoom_mode = ZoomController::ZOOM_MODE_DISABLED;
}
zoom::ZoomController::FromWebContents(web_contents)->SetZoomMode(zoom_mode);
ZoomController::FromWebContents(web_contents)->SetZoomMode(zoom_mode);
SendResponse(true);
return true;
return RespondNow(NoArguments());
}
bool TabsGetZoomSettingsFunction::RunAsync() {
ExtensionFunction::ResponseAction TabsGetZoomSettingsFunction::Run() {
std::unique_ptr<tabs::GetZoomSettings::Params> params(
tabs::GetZoomSettings::Params::Create(*args_));
EXTENSION_FUNCTION_PRERUN_VALIDATE(params);
EXTENSION_FUNCTION_VALIDATE(params);
int tab_id = params->tab_id ? *params->tab_id : -1;
content::WebContents* web_contents = GetWebContents(tab_id);
if (!web_contents)
return false;
zoom::ZoomController* zoom_controller =
zoom::ZoomController::FromWebContents(web_contents);
return RespondNow(Error(std::move(error_)));
ZoomController* zoom_controller =
ZoomController::FromWebContents(web_contents);
zoom::ZoomController::ZoomMode zoom_mode = zoom_controller->zoom_mode();
ZoomController::ZoomMode zoom_mode = zoom_controller->zoom_mode();
api::tabs::ZoomSettings zoom_settings;
ZoomModeToZoomSettings(zoom_mode, &zoom_settings);
zoom_settings.default_zoom_factor.reset(
new double(blink::PageZoomLevelToZoomFactor(
zoom_controller->GetDefaultZoomLevel())));
zoom_settings.default_zoom_factor = std::make_unique<double>(
blink::PageZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel()));
results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings);
SendResponse(true);
return true;
return RespondNow(
ArgumentList(api::tabs::GetZoomSettings::Results::Create(zoom_settings)));
}
} // namespace cef

View File

@@ -42,6 +42,37 @@ class TabsCreateFunction : public ExtensionFunction {
const CefExtensionFunctionDetails cef_details_;
};
class BaseAPIFunction : public ExtensionFunction {
public:
BaseAPIFunction();
protected:
~BaseAPIFunction() override {}
// Gets the WebContents for |tab_id| if it is specified. Otherwise get the
// WebContents for the active tab in the current window. Calling this function
// may set |error_|.
content::WebContents* GetWebContents(int tab_id);
std::string error_;
const CefExtensionFunctionDetails cef_details_;
};
class TabsUpdateFunction : public BaseAPIFunction {
private:
~TabsUpdateFunction() override {}
ResponseAction Run() override;
bool UpdateURL(const std::string& url, int tab_id, std::string* error);
ResponseValue GetResult();
DECLARE_EXTENSION_FUNCTION("tabs.update", TABS_UPDATE)
int tab_id_ = -1;
content::WebContents* web_contents_ = nullptr;
};
// Implement API calls tabs.executeScript, tabs.insertCSS, and tabs.removeCSS.
class ExecuteCodeInTabFunction : public ExecuteCodeFunction {
public:
@@ -108,58 +139,44 @@ class ZoomAPIFunction : public ExtensionFunction {
// may set |error_|.
content::WebContents* GetWebContents(int tab_id);
virtual bool RunAsync() = 0;
// Responds with success/failure. |results_| or |error_| should be set
// accordingly.
void SendResponse(bool success);
// Exposed versions of ExtensionFunction::results_ and
// ExtensionFunction::error_ that are curried into the response.
// These need to keep the same name to avoid breaking existing
// implementations, but this should be temporary with crbug.com/648275
// and crbug.com/634140.
std::unique_ptr<base::ListValue> results_;
std::string error_;
private:
ResponseAction Run() final;
const CefExtensionFunctionDetails cef_details_;
};
class TabsSetZoomFunction : public ZoomAPIFunction {
class TabsSetZoomFunction : public BaseAPIFunction {
private:
~TabsSetZoomFunction() override {}
bool RunAsync() override;
ResponseAction Run() override;
DECLARE_EXTENSION_FUNCTION("tabs.setZoom", TABS_SETZOOM)
};
class TabsGetZoomFunction : public ZoomAPIFunction {
class TabsGetZoomFunction : public BaseAPIFunction {
private:
~TabsGetZoomFunction() override {}
bool RunAsync() override;
ResponseAction Run() override;
DECLARE_EXTENSION_FUNCTION("tabs.getZoom", TABS_GETZOOM)
};
class TabsSetZoomSettingsFunction : public ZoomAPIFunction {
class TabsSetZoomSettingsFunction : public BaseAPIFunction {
private:
~TabsSetZoomSettingsFunction() override {}
bool RunAsync() override;
ResponseAction Run() override;
DECLARE_EXTENSION_FUNCTION("tabs.setZoomSettings", TABS_SETZOOMSETTINGS)
};
class TabsGetZoomSettingsFunction : public ZoomAPIFunction {
class TabsGetZoomSettingsFunction : public BaseAPIFunction {
private:
~TabsGetZoomSettingsFunction() override {}
bool RunAsync() override;
ResponseAction Run() override;
DECLARE_EXTENSION_FUNCTION("tabs.getZoomSettings", TABS_GETZOOMSETTINGS)
};

View File

@@ -51,6 +51,7 @@ const char* const kSupportedAPIs[] = {
"tabs",
EXTENSION_FUNCTION_NAME(cefimpl::TabsGetFunction),
EXTENSION_FUNCTION_NAME(cefimpl::TabsCreateFunction),
EXTENSION_FUNCTION_NAME(cefimpl::TabsUpdateFunction),
EXTENSION_FUNCTION_NAME(cefimpl::TabsExecuteScriptFunction),
EXTENSION_FUNCTION_NAME(cefimpl::TabsInsertCSSFunction),
EXTENSION_FUNCTION_NAME(cefimpl::TabsRemoveCSSFunction),
@@ -95,6 +96,7 @@ void ChromeFunctionRegistry::RegisterAll(ExtensionFunctionRegistry* registry) {
registry->RegisterFunction<cefimpl::TabsRemoveCSSFunction>();
registry->RegisterFunction<cefimpl::TabsGetFunction>();
registry->RegisterFunction<cefimpl::TabsCreateFunction>();
registry->RegisterFunction<cefimpl::TabsUpdateFunction>();
registry->RegisterFunction<cefimpl::TabsSetZoomFunction>();
registry->RegisterFunction<cefimpl::TabsGetZoomFunction>();
registry->RegisterFunction<cefimpl::TabsSetZoomSettingsFunction>();

View File

@@ -23,7 +23,7 @@ CefComponentExtensionResourceManager::CefComponentExtensionResourceManager() {
base::Value dict(base::Value::Type::DICTIONARY);
pdf_extension_util::AddStrings(
pdf_extension_util::PdfViewerContext::kPdfViewer, &dict);
pdf_extension_util::AddAdditionalData(&dict);
pdf_extension_util::AddAdditionalData(/*enable_annotations=*/true, &dict);
ui::TemplateReplacements pdf_viewer_replacements;
ui::TemplateReplacementsFromDictionaryValue(

View File

@@ -17,7 +17,7 @@ CefExtensionBackgroundHost::CefExtensionBackgroundHost(
const Extension* extension,
content::WebContents* host_contents,
const GURL& url,
ViewType host_type)
mojom::ViewType host_type)
: ExtensionHost(new CefExtensionHostDelegate(browser),
extension,
host_contents->GetBrowserContext(),
@@ -28,7 +28,7 @@ CefExtensionBackgroundHost::CefExtensionBackgroundHost(
DCHECK(!deleted_callback_.is_null());
// Only used for background pages.
DCHECK(host_type == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE);
DCHECK(host_type == mojom::ViewType::kExtensionBackgroundPage);
}
CefExtensionBackgroundHost::~CefExtensionBackgroundHost() {

View File

@@ -29,7 +29,7 @@ class CefExtensionBackgroundHost : public ExtensionHost {
const Extension* extension,
content::WebContents* host_contents,
const GURL& url,
ViewType host_type);
mojom::ViewType host_type);
~CefExtensionBackgroundHost() override;
// content::WebContentsDelegate methods:

View File

@@ -7,11 +7,11 @@
#include "libcef/browser/browser_context.h"
#include "libcef/browser/extensions/browser_extensions_util.h"
#include "libcef/browser/extensions/extension_system.h"
#include "libcef/browser/navigate_params.h"
#include "libcef/browser/thread_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/post_task.h"
#include "base/task/thread_pool.h"
#include "chrome/browser/extensions/api/tabs/tabs_constants.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/profiles/profile.h"
@@ -81,10 +81,9 @@ class CefGetExtensionLoadFileCallbackImpl
return;
}
base::PostTaskAndReplyWithResult(
base::ThreadPool::PostTaskAndReplyWithResult(
FROM_HERE,
{base::ThreadPool(), base::MayBlock(),
base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN},
{base::MayBlock(), base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN},
base::BindOnce(LoadFileFromStream, file, stream), std::move(callback));
}
@@ -319,24 +318,12 @@ base::DictionaryValue* CefExtensionFunctionDetails::OpenTab(
GURL url;
if (params.url.get()) {
std::string url_string = *params.url;
url = ExtensionTabUtil::ResolvePossiblyRelativeURL(url_string,
function()->extension());
if (!url.is_valid()) {
if (error_message) {
*error_message =
ErrorUtils::FormatErrorMessage(keys::kInvalidUrlError, url_string);
}
if (!ExtensionTabUtil::PrepareURLForNavigation(
url_string, function()->extension(), &url, error_message)) {
return nullptr;
}
}
// Don't let extensions crash the browser or renderers.
if (ExtensionTabUtil::IsKillURL(url)) {
if (error_message)
*error_message = keys::kNoCrashBrowserError;
return nullptr;
}
// Default to foreground for the new tab. The presence of 'active' property
// will override this default.
bool active = true;
@@ -366,7 +353,7 @@ base::DictionaryValue* CefExtensionFunctionDetails::OpenTab(
return nullptr;
CefBrowserCreateParams create_params;
create_params.url = url;
create_params.url = url.spec();
create_params.request_context = request_context;
create_params.window_info.reset(new CefWindowInfo);
@@ -381,9 +368,9 @@ base::DictionaryValue* CefExtensionFunctionDetails::OpenTab(
CefRefPtr<CefExtensionHandler> handler = cef_extension->GetHandler();
if (handler.get() &&
handler->OnBeforeBrowser(cef_extension, sender_browser.get(),
active_browser.get(), index, url.spec(), active,
*create_params.window_info, create_params.client,
create_params.settings)) {
active_browser.get(), index, create_params.url,
active, *create_params.window_info,
create_params.client, create_params.settings)) {
// Cancel the browser creation.
return nullptr;
}

View File

@@ -547,7 +547,8 @@ scoped_refptr<const Extension> CefExtensionSystem::CreateExtension(
// Tests should continue to use the Manifest::COMMAND_LINE value here
// Some Chrome APIs will cause undesired effects if this is incorrect
// e.g.: alarms API has 1 minute minimum applied to Packed Extensions
info.internal ? Manifest::COMPONENT : Manifest::COMMAND_LINE,
info.internal ? mojom::ManifestLocation::kComponent
: mojom::ManifestLocation::kCommandLine,
*info.manifest, flags, utf8_error);
}
@@ -576,12 +577,12 @@ const Extension* CefExtensionSystem::LoadExtension(
// Insert first so that callbacks can retrieve the loaded extension.
extension_map_.insert(std::make_pair(extension->id(), cef_extension));
cef_extension->OnExtensionLoaded();
// This may trigger additional callbacks.
registry_->AddEnabled(extension.get());
NotifyExtensionLoaded(extension.get());
cef_extension->OnExtensionLoaded();
return extension.get();
}

View File

@@ -25,7 +25,7 @@ CefExtensionViewHost::CefExtensionViewHost(AlloyBrowserHostImpl* browser,
const Extension* extension,
content::WebContents* host_contents,
const GURL& url,
ViewType host_type)
mojom::ViewType host_type)
: ExtensionHost(new CefExtensionHostDelegate(browser),
extension,
host_contents->GetBrowserContext(),
@@ -33,8 +33,8 @@ CefExtensionViewHost::CefExtensionViewHost(AlloyBrowserHostImpl* browser,
url,
host_type) {
// Only used for dialogs and popups.
DCHECK(host_type == VIEW_TYPE_EXTENSION_DIALOG ||
host_type == VIEW_TYPE_EXTENSION_POPUP);
DCHECK(host_type == mojom::ViewType::kExtensionDialog ||
host_type == mojom::ViewType::kExtensionPopup);
}
CefExtensionViewHost::~CefExtensionViewHost() {}
@@ -76,7 +76,7 @@ bool CefExtensionViewHost::PreHandleGestureEvent(
}
WebContents* CefExtensionViewHost::GetVisibleWebContents() const {
if (extension_host_type() == VIEW_TYPE_EXTENSION_POPUP)
if (extension_host_type() == mojom::ViewType::kExtensionPopup)
return host_contents();
return nullptr;
}

View File

@@ -31,7 +31,7 @@ class CefExtensionViewHost : public ExtensionHost,
const Extension* extension,
content::WebContents* host_contents,
const GURL& url,
ViewType host_type);
mojom::ViewType host_type);
~CefExtensionViewHost() override;
// ExtensionHost methods:

View File

@@ -251,21 +251,20 @@ bool CefExtensionsBrowserClient::CreateBackgroundExtensionHost(
}
CefBrowserCreateParams create_params;
create_params.url = url;
create_params.url = url.spec();
create_params.request_context = request_context;
CefRefPtr<CefExtensionHandler> handler = cef_extension->GetHandler();
if (handler.get() && handler->OnBeforeBackgroundBrowser(
cef_extension, url.spec(), create_params.client,
create_params.settings)) {
cef_extension, create_params.url,
create_params.client, create_params.settings)) {
// Cancel the background host creation.
return true;
}
// This triggers creation of the background host.
create_params.extension = extension;
create_params.extension_host_type =
extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE;
create_params.extension_host_type = mojom::ViewType::kExtensionBackgroundPage;
// Browser creation may fail under certain rare circumstances. Fail the
// background host creation in that case.

View File

@@ -92,17 +92,17 @@ ValueStore::WriteResult CefValueStore::Set(
if (!status_.ok())
return WriteResult(CreateStatusCopy(status_));
std::unique_ptr<ValueStoreChangeList> changes(new ValueStoreChangeList());
ValueStoreChangeList changes;
for (base::DictionaryValue::Iterator it(settings); !it.IsAtEnd();
it.Advance()) {
base::Value* old_value = nullptr;
base::Value* old_value = NULL;
if (!storage_.GetWithoutPathExpansion(it.key(), &old_value) ||
!old_value->Equals(&it.value())) {
changes->push_back(ValueStoreChange(
it.key(),
old_value ? base::Optional<base::Value>(old_value->Clone())
: base::nullopt,
it.value().Clone()));
changes.emplace_back(it.key(),
old_value
? base::Optional<base::Value>(old_value->Clone())
: base::nullopt,
it.value().Clone());
storage_.SetWithoutPathExpansion(it.key(), it.value().CreateDeepCopy());
}
}
@@ -119,13 +119,11 @@ ValueStore::WriteResult CefValueStore::Remove(
if (!status_.ok())
return WriteResult(CreateStatusCopy(status_));
std::unique_ptr<ValueStoreChangeList> changes(new ValueStoreChangeList());
for (std::vector<std::string>::const_iterator it = keys.begin();
it != keys.end(); ++it) {
ValueStoreChangeList changes;
for (auto it = keys.cbegin(); it != keys.cend(); ++it) {
std::unique_ptr<base::Value> old_value;
if (storage_.RemoveWithoutPathExpansion(*it, &old_value)) {
changes->push_back(
ValueStoreChange(*it, std::move(*old_value), base::nullopt));
changes.emplace_back(*it, std::move(*old_value), base::nullopt);
}
}
return WriteResult(std::move(changes), CreateStatusCopy(status_));

View File

@@ -274,7 +274,7 @@ void CefFileDialogManager::RunFileChooserInternal(
if (params.hidereadonly)
mode |= FILE_DIALOG_HIDEREADONLY_FLAG;
std::vector<base::string16>::const_iterator it;
std::vector<std::u16string>::const_iterator it;
std::vector<CefString> accept_filters;
it = params.accept_types.begin();
@@ -357,7 +357,7 @@ void CefFileDialogManager::OnRunFileChooserDelegateCallback(
// Convert FilePath list to SelectedFileInfo list.
for (size_t i = 0; i < file_paths.size(); ++i) {
auto info = blink::mojom::FileChooserFileInfo::NewNativeFile(
blink::mojom::NativeFileInfo::New(file_paths[i], base::string16()));
blink::mojom::NativeFileInfo::New(file_paths[i], std::u16string()));
selected_files.push_back(std::move(info));
}
}

View File

@@ -12,12 +12,12 @@
#include "libcef/browser/navigate_params.h"
#include "libcef/browser/net_service/browser_urlrequest_impl.h"
#include "libcef/common/cef_messages.h"
#include "libcef/common/frame_util.h"
#include "libcef/common/frame_util.h"
#include "libcef/common/net/url_util.h"
#include "libcef/common/process_message_impl.h"
#include "libcef/common/request_impl.h"
#include "libcef/common/task_runner_impl.h"
#include "components/url_formatter/url_fixer.h"
#include "content/browser/renderer_host/frame_tree_node.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
@@ -310,16 +310,9 @@ void CefFrameHostImpl::NotifyMoveOrResizeStarted() {
void CefFrameHostImpl::Navigate(const CefNavigateParams& params) {
CefMsg_LoadRequest_Params request;
// Fix common problems with user-typed text. Among other things, this:
// - Converts absolute file paths to "file://" URLs.
// - Normalizes "about:" and "chrome:" to "chrome://" URLs.
// - Adds the "http://" scheme if none was specified.
request.url = url_formatter::FixupURL(params.url.possibly_invalid_spec(),
std::string());
if (!request.url.is_valid()) {
LOG(ERROR) << "Invalid URL: " << params.url.possibly_invalid_spec();
request.url = params.url;
if (!url_util::FixupGURL(request.url))
return;
}
request.method = params.method;
request.referrer = params.referrer.url;
@@ -347,16 +340,8 @@ void CefFrameHostImpl::LoadURLWithExtras(const std::string& url,
if (frame_id < CefFrameHostImpl::kMainFrameId)
return;
// Any necessary fixup of the URL will occur in
// [CefBrowserHostBase|CefFrameHostImpl]::Navigate().
GURL gurl(url);
if (!url.empty() && !gurl.is_valid() && !gurl.has_scheme()) {
std::string fixed_scheme(url::kHttpScheme);
fixed_scheme.append(url::kStandardSchemeSeparator);
std::string new_url = url;
new_url.insert(0, fixed_scheme);
gurl = GURL(new_url);
}
// Any necessary fixup will occur in Navigate.
GURL gurl = url_util::MakeGURL(url, /*fixup=*/false);
if (frame_id == CefFrameHostImpl::kMainFrameId) {
// Load via the browser using NavigationController.

View File

@@ -23,7 +23,9 @@ CefIOThreadState::CefIOThreadState() {
base::Unretained(this)));
}
CefIOThreadState::~CefIOThreadState() {}
CefIOThreadState::~CefIOThreadState() {
CEF_REQUIRE_IOT();
}
void CefIOThreadState::AddHandler(int render_process_id,
int render_frame_id,

View File

@@ -12,15 +12,18 @@
#include "libcef/browser/request_context_handler_map.h"
#include "content/public/browser/browser_thread.h"
class GURL;
// Stores state that will be accessed on the IO thread. Life span is controlled
// by CefBrowserContext. Created on the UI thread but accessed and destroyed on
// the IO thread. See browser_context.h for an object relationship diagram.
class CefIOThreadState {
class CefIOThreadState : public base::RefCountedThreadSafe<
CefIOThreadState,
content::BrowserThread::DeleteOnIOThread> {
public:
CefIOThreadState();
virtual ~CefIOThreadState();
// See comments in CefRequestContextHandlerMap.
void AddHandler(int render_process_id,
@@ -44,6 +47,12 @@ class CefIOThreadState {
CefRefPtr<CefSchemeHandlerFactory> GetSchemeHandlerFactory(const GURL& url);
private:
friend struct content::BrowserThread::DeleteOnThread<
content::BrowserThread::IO>;
friend class base::DeleteHelper<CefIOThreadState>;
~CefIOThreadState();
void InitOnIOThread();
// Map IDs to CefRequestContextHandler objects.

View File

@@ -52,7 +52,7 @@ class CefJSDialogCallbackImpl : public CefJSDialogCallback {
private:
static void CancelNow(CallbackType callback) {
CEF_REQUIRE_UIT();
std::move(callback).Run(false, base::string16());
std::move(callback).Run(false, std::u16string());
}
CallbackType callback_;
@@ -82,8 +82,8 @@ void CefJavaScriptDialogManager::RunJavaScriptDialog(
content::WebContents* web_contents,
content::RenderFrameHost* render_frame_host,
content::JavaScriptDialogType message_type,
const base::string16& message_text,
const base::string16& default_prompt_text,
const std::u16string& message_text,
const std::u16string& default_prompt_text,
DialogClosedCallback callback,
bool* did_suppress_message) {
const GURL& origin_url = render_frame_host->GetLastCommittedURL();
@@ -128,7 +128,7 @@ void CefJavaScriptDialogManager::RunJavaScriptDialog(
dialog_running_ = true;
const base::string16& display_url =
const std::u16string& display_url =
url_formatter::FormatUrlForSecurityDisplay(origin_url);
DCHECK(!callback.is_null());
@@ -147,12 +147,11 @@ void CefJavaScriptDialogManager::RunBeforeUnloadDialog(
AlloyBrowserHostImpl::DESTRUCTION_STATE_ACCEPTED) {
// Currently destroying the browser. Accept the unload without showing
// the prompt.
std::move(callback).Run(true, base::string16());
std::move(callback).Run(true, std::u16string());
return;
}
const base::string16& message_text =
base::ASCIIToUTF16("Is it OK to leave/reload this page?");
const std::u16string& message_text = u"Is it OK to leave/reload this page?";
CefRefPtr<CefClient> client = browser_->GetClient();
if (client.get()) {
@@ -179,7 +178,7 @@ void CefJavaScriptDialogManager::RunBeforeUnloadDialog(
LOG(WARNING) << "No javascript dialog runner available for this platform";
// Suppress the dialog if there is no platform runner or if the dialog is
// currently running.
std::move(callback).Run(true, base::string16());
std::move(callback).Run(true, std::u16string());
return;
}
@@ -188,9 +187,9 @@ void CefJavaScriptDialogManager::RunBeforeUnloadDialog(
DCHECK(!callback.is_null());
runner_->Run(
browser_, content::JAVASCRIPT_DIALOG_TYPE_CONFIRM,
base::string16(), // display_url
std::u16string(), // display_url
message_text,
base::string16(), // default_prompt_text
std::u16string(), // default_prompt_text
base::BindOnce(&CefJavaScriptDialogManager::DialogClosed,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
@@ -216,7 +215,7 @@ void CefJavaScriptDialogManager::CancelDialogs(
void CefJavaScriptDialogManager::DialogClosed(
DialogClosedCallback callback,
bool success,
const base::string16& user_input) {
const std::u16string& user_input) {
CefRefPtr<CefClient> client = browser_->GetClient();
if (client.get()) {
CefRefPtr<CefJSDialogHandler> handler = client->GetJSDialogHandler();

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