From a23e8452443d170b57c7827ed0a4a4b35d39b65c Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Fri, 22 Mar 2019 18:11:51 -0400 Subject: [PATCH] Remove methods that modify cookie storage at runtime (see issue #2622). This change removes cookie and request handler functionality that will not supported by the NetworkService. Specifically, it is no longer possible to change cookie storage locations at runime by returning a different CefCookieManager for an already initialized CefRequestContext. After this change you will need to use a separate CefRequestContext when creating a CefBrowser if you require separate cookie storage. The following methods have been removed: - CefCookieManager::CreateManager - CefCookieManager::GetBlockingManager - CefCookieManager::SetStoragePath - CefRequestContextHandler::GetCookieManager The following methods have been renamed: - CefRequestContext::GetDefaultCookieManager to GetCookieManager. This change substantially simplifies the network implementation in CEF because it is no longer necessary to proxy objects that are normally owned by Chromium. Chromium patches that are no longer necessary will be removed as a follow-up commit. To test: Verify that `ceftests --gtest_filter=-PluginTest.*` pass with NetworkService disabled. Plugin tests will be fixed in a follow-up commit. --- BUILD.gn | 18 +- include/capi/cef_cookie_capi.h | 46 +- include/capi/cef_request_context_capi.h | 13 +- .../capi/cef_request_context_handler_capi.h | 11 +- include/cef_api_hash.h | 10 +- include/cef_cookie.h | 41 -- include/cef_request_context.h | 11 +- include/cef_request_context_handler.h | 9 - libcef/browser/browser_context.cc | 553 +++++++++++++++-- libcef/browser/browser_context.h | 218 ++++--- libcef/browser/browser_context_impl.cc | 562 ------------------ libcef/browser/browser_context_impl.h | 136 ----- libcef/browser/browser_context_proxy.cc | 267 --------- libcef/browser/browser_context_proxy.h | 102 ---- libcef/browser/browser_host_impl.cc | 13 +- libcef/browser/browser_main.cc | 4 +- libcef/browser/browser_main.h | 2 +- libcef/browser/chrome_browser_process_stub.cc | 4 +- libcef/browser/chrome_profile_manager_stub.cc | 12 +- libcef/browser/content_browser_client.cc | 6 +- libcef/browser/content_browser_client.h | 2 +- libcef/browser/cookie_manager_impl.cc | 178 +----- libcef/browser/cookie_manager_impl.h | 31 +- .../extensions/browser_extensions_util.cc | 8 +- .../extensions/extension_function_details.cc | 12 +- .../extensions/extensions_api_client.cc | 11 +- .../extensions/extensions_browser_client.cc | 15 +- libcef/browser/net/cookie_store_proxy.cc | 182 ------ libcef/browser/net/cookie_store_proxy.h | 54 -- libcef/browser/net/cookie_store_source.cc | 111 ---- libcef/browser/net/cookie_store_source.h | 75 --- libcef/browser/net/network_delegate.h | 2 +- ..._impl.cc => url_request_context_getter.cc} | 117 ++-- .../browser/net/url_request_context_getter.h | 136 ++++- .../net/url_request_context_getter_impl.h | 138 ----- .../net/url_request_context_getter_proxy.cc | 59 -- .../net/url_request_context_getter_proxy.h | 57 -- libcef/browser/net/url_request_context_impl.h | 22 - .../browser/net/url_request_context_proxy.cc | 47 -- .../browser/net/url_request_context_proxy.h | 35 -- libcef/browser/net/url_request_manager.h | 4 +- libcef/browser/prefs/browser_prefs.cc | 4 +- libcef/browser/request_context_impl.cc | 110 ++-- libcef/browser/request_context_impl.h | 26 +- libcef/browser/resource_context.cc | 44 +- libcef/browser/resource_context.h | 11 - libcef/browser/storage_partition_proxy.cc | 264 -------- libcef/browser/storage_partition_proxy.h | 112 ---- libcef_dll/cpptoc/cookie_manager_cpptoc.cc | 51 +- libcef_dll/cpptoc/request_context_cpptoc.cc | 13 +- .../cpptoc/request_context_handler_cpptoc.cc | 20 +- libcef_dll/ctocpp/cookie_manager_ctocpp.cc | 53 +- libcef_dll/ctocpp/cookie_manager_ctocpp.h | 5 +- libcef_dll/ctocpp/request_context_ctocpp.cc | 8 +- libcef_dll/ctocpp/request_context_ctocpp.h | 4 +- .../ctocpp/request_context_handler_ctocpp.cc | 18 +- .../ctocpp/request_context_handler_ctocpp.h | 3 +- libcef_dll/wrapper/libcef_dll_dylib.cc | 27 +- .../cefclient/browser/root_window_manager.cc | 15 +- tests/ceftests/cookie_unittest.cc | 546 +++-------------- .../extensions/extension_test_handler.cc | 6 +- tests/ceftests/request_context_unittest.cc | 173 +----- tests/ceftests/request_handler_unittest.cc | 259 ++------ tests/ceftests/urlrequest_unittest.cc | 6 +- tests/shared/common/client_switches.cc | 1 - tests/shared/common/client_switches.h | 1 - 66 files changed, 1175 insertions(+), 3939 deletions(-) delete mode 100644 libcef/browser/browser_context_impl.cc delete mode 100644 libcef/browser/browser_context_impl.h delete mode 100644 libcef/browser/browser_context_proxy.cc delete mode 100644 libcef/browser/browser_context_proxy.h delete mode 100644 libcef/browser/net/cookie_store_proxy.cc delete mode 100644 libcef/browser/net/cookie_store_proxy.h delete mode 100644 libcef/browser/net/cookie_store_source.cc delete mode 100644 libcef/browser/net/cookie_store_source.h rename libcef/browser/net/{url_request_context_getter_impl.cc => url_request_context_getter.cc} (84%) delete mode 100644 libcef/browser/net/url_request_context_getter_impl.h delete mode 100644 libcef/browser/net/url_request_context_getter_proxy.cc delete mode 100644 libcef/browser/net/url_request_context_getter_proxy.h delete mode 100644 libcef/browser/net/url_request_context_impl.h delete mode 100644 libcef/browser/net/url_request_context_proxy.cc delete mode 100644 libcef/browser/net/url_request_context_proxy.h delete mode 100644 libcef/browser/storage_partition_proxy.cc delete mode 100644 libcef/browser/storage_partition_proxy.h diff --git a/BUILD.gn b/BUILD.gn index 9d5cbc54e..444908a1b 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -258,12 +258,8 @@ static_library("libcef_static") { "libcef/browser/audio_push_sink.h", "libcef/browser/browser_context.cc", "libcef/browser/browser_context.h", - "libcef/browser/browser_context_impl.cc", - "libcef/browser/browser_context_impl.h", "libcef/browser/browser_context_keyed_service_factories.cc", "libcef/browser/browser_context_keyed_service_factories.h", - "libcef/browser/browser_context_proxy.cc", - "libcef/browser/browser_context_proxy.h", "libcef/browser/browser_host_impl.cc", "libcef/browser/browser_host_impl.h", "libcef/browser/browser_info.cc", @@ -377,10 +373,6 @@ static_library("libcef_static") { "libcef/browser/navigation_entry_impl.h", "libcef/browser/net/chrome_scheme_handler.cc", "libcef/browser/net/chrome_scheme_handler.h", - "libcef/browser/net/cookie_store_proxy.cc", - "libcef/browser/net/cookie_store_proxy.h", - "libcef/browser/net/cookie_store_source.cc", - "libcef/browser/net/cookie_store_source.h", "libcef/browser/net/crlset_file_util_impl.cc", "libcef/browser/net/devtools_scheme_handler.cc", "libcef/browser/net/devtools_scheme_handler.h", @@ -398,14 +390,8 @@ static_library("libcef_static") { "libcef/browser/net/source_stream.h", "libcef/browser/net/url_request_context.cc", "libcef/browser/net/url_request_context.h", + "libcef/browser/net/url_request_context_getter.cc", "libcef/browser/net/url_request_context_getter.h", - "libcef/browser/net/url_request_context_getter_impl.cc", - "libcef/browser/net/url_request_context_getter_impl.h", - "libcef/browser/net/url_request_context_getter_proxy.cc", - "libcef/browser/net/url_request_context_getter_proxy.h", - "libcef/browser/net/url_request_context_impl.h", - "libcef/browser/net/url_request_context_proxy.cc", - "libcef/browser/net/url_request_context_proxy.h", "libcef/browser/net/url_request_interceptor.cc", "libcef/browser/net/url_request_interceptor.h", "libcef/browser/net/url_request_manager.cc", @@ -465,8 +451,6 @@ static_library("libcef_static") { "libcef/browser/ssl_info_impl.h", "libcef/browser/ssl_status_impl.cc", "libcef/browser/ssl_status_impl.h", - "libcef/browser/storage_partition_proxy.cc", - "libcef/browser/storage_partition_proxy.h", "libcef/browser/stream_impl.cc", "libcef/browser/stream_impl.h", "libcef/browser/trace_impl.cc", diff --git a/include/capi/cef_cookie_capi.h b/include/capi/cef_cookie_capi.h index 802dba051..c0eab7fc2 100644 --- a/include/capi/cef_cookie_capi.h +++ b/include/capi/cef_cookie_capi.h @@ -33,7 +33,7 @@ // by hand. See the translator.README.txt file in the tools directory for // more information. // -// $hash=48b5fa68109eed1ea30fa0c805218ebd258c0573$ +// $hash=fd4529fcb0b4cebf7e94a5160854f13ee05bbab0$ // #ifndef CEF_INCLUDE_CAPI_CEF_COOKIE_CAPI_H_ @@ -123,22 +123,6 @@ typedef struct _cef_cookie_manager_t { const cef_string_t* cookie_name, struct _cef_delete_cookies_callback_t* callback); - /// - // Sets the directory path that will be used for storing cookie data. If - // |path| is NULL data will be stored in memory only. Otherwise, data will be - // stored at the specified |path|. To persist session cookies (cookies without - // an expiry date or validity interval) set |persist_session_cookies| to true - // (1). Session cookies are generally intended to be transient and most Web - // browsers do not persist them. If |callback| is non-NULL it will be executed - // asnychronously on the IO thread after the manager's storage has been - // initialized. Returns false (0) if cookies cannot be accessed. - /// - int(CEF_CALLBACK* set_storage_path)( - struct _cef_cookie_manager_t* self, - const cef_string_t* path, - int persist_session_cookies, - struct _cef_completion_callback_t* callback); - /// // Flush the backing store (if any) to disk. If |callback| is non-NULL it will // be executed asnychronously on the IO thread after the flush is complete. @@ -153,36 +137,12 @@ typedef struct _cef_cookie_manager_t { // CefSettings.cache_path if specified or in memory otherwise. If |callback| is // non-NULL it will be executed asnychronously on the IO thread after the // manager's storage has been initialized. Using this function is equivalent to -// calling cef_request_tContext::cef_request_context_get_global_context()->get_d -// efault_cookie_manager(). +// calling cef_request_tContext::cef_request_context_get_global_context()->GetDe +// faultCookieManager(). /// CEF_EXPORT cef_cookie_manager_t* cef_cookie_manager_get_global_manager( struct _cef_completion_callback_t* callback); -/// -// Returns a cookie manager that neither stores nor retrieves cookies. All usage -// of cookies will be blocked including cookies accessed via the network -// (request/response headers), via JavaScript (document.cookie), and via -// cef_cookie_manager_t functions. No cookies will be displayed in DevTools. If -// you wish to only block cookies sent via the network use the -// cef_request_tHandler CanGetCookies and CanSetCookie functions instead. -/// -CEF_EXPORT cef_cookie_manager_t* cef_cookie_manager_get_blocking_manager(); - -/// -// Creates a new cookie manager. If |path| is NULL data will be stored in memory -// only. Otherwise, data will be stored at the specified |path|. To persist -// session cookies (cookies without an expiry date or validity interval) set -// |persist_session_cookies| to true (1). Session cookies are generally intended -// to be transient and most Web browsers do not persist them. If |callback| is -// non-NULL it will be executed asnychronously on the IO thread after the -// manager's storage has been initialized. -/// -CEF_EXPORT cef_cookie_manager_t* cef_cookie_manager_create_manager( - const cef_string_t* path, - int persist_session_cookies, - struct _cef_completion_callback_t* callback); - /// // Structure to implement for visiting cookie values. The functions of this // structure will always be called on the IO thread. diff --git a/include/capi/cef_request_context_capi.h b/include/capi/cef_request_context_capi.h index 31f9bd59a..500348451 100644 --- a/include/capi/cef_request_context_capi.h +++ b/include/capi/cef_request_context_capi.h @@ -33,7 +33,7 @@ // by hand. See the translator.README.txt file in the tools directory for // more information. // -// $hash=f7f1ec971c726a6a74bcc7f5cee7a8eb1911078d$ +// $hash=1038c0c3db89ce0b829d66e166b063c96b15992d$ // #ifndef CEF_INCLUDE_CAPI_CEF_REQUEST_CONTEXT_CAPI_H_ @@ -130,14 +130,11 @@ typedef struct _cef_request_context_t { struct _cef_request_context_t* self); /// - // Returns the default cookie manager for this object. This will be the global - // cookie manager if this object is the global request context. Otherwise, - // this will be the default cookie manager used when this request context does - // not receive a value via cef_request_tContextHandler::get_cookie_manager(). - // If |callback| is non-NULL it will be executed asnychronously on the IO - // thread after the manager's storage has been initialized. + // 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 + // storage has been initialized. /// - struct _cef_cookie_manager_t*(CEF_CALLBACK* get_default_cookie_manager)( + struct _cef_cookie_manager_t*(CEF_CALLBACK* get_cookie_manager)( struct _cef_request_context_t* self, struct _cef_completion_callback_t* callback); diff --git a/include/capi/cef_request_context_handler_capi.h b/include/capi/cef_request_context_handler_capi.h index 6a4528012..0971862a1 100644 --- a/include/capi/cef_request_context_handler_capi.h +++ b/include/capi/cef_request_context_handler_capi.h @@ -33,7 +33,7 @@ // by hand. See the translator.README.txt file in the tools directory for // more information. // -// $hash=03c829d89f0b5b7ab12634fa2f11c4903cd8edb2$ +// $hash=2bf745d270f474b3d5b36fc3fc2fca2b508ec16f$ // #ifndef CEF_INCLUDE_CAPI_CEF_REQUEST_CONTEXT_HANDLER_CAPI_H_ @@ -41,7 +41,6 @@ #pragma once #include "include/capi/cef_base_capi.h" -#include "include/capi/cef_cookie_capi.h" #include "include/capi/cef_web_plugin_capi.h" #ifdef __cplusplus @@ -69,14 +68,6 @@ typedef struct _cef_request_context_handler_t { struct _cef_request_context_handler_t* self, struct _cef_request_context_t* request_context); - /// - // Called on the browser process IO thread to retrieve the cookie manager. If - // this function returns NULL the default cookie manager retrievable via - // cef_request_tContext::get_default_cookie_manager() will be used. - /// - struct _cef_cookie_manager_t*(CEF_CALLBACK* get_cookie_manager)( - struct _cef_request_context_handler_t* self); - /// // Called on multiple browser process threads before a plugin instance is // loaded. |mime_type| is the mime type of the plugin that will be loaded. diff --git a/include/cef_api_hash.h b/include/cef_api_hash.h index 24ee42432..7a1b6ea29 100644 --- a/include/cef_api_hash.h +++ b/include/cef_api_hash.h @@ -34,7 +34,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=b5fa5783096eaa1af5e76645e2557e123af56848$ +// $hash=fcc19532b6143e9c445fcde9947260b1c93a5e68$ // #ifndef CEF_INCLUDE_API_HASH_H_ @@ -47,13 +47,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 "8ae24aac4bd16d2e2d87e7d6561985064990670e" +#define CEF_API_HASH_UNIVERSAL "114e74f2c52d90fbb3fe6b3855dba9e544e40e85" #if defined(OS_WIN) -#define CEF_API_HASH_PLATFORM "fe476e7a38a8270fe783981b4bc6fac4284ab9fe" +#define CEF_API_HASH_PLATFORM "25d0b5c8337691e2bcc21148686e4eacbe1255a6" #elif defined(OS_MACOSX) -#define CEF_API_HASH_PLATFORM "ab1b4d8c4578b0bcdc97f28f13a10384057bdf95" +#define CEF_API_HASH_PLATFORM "905d65b97689874873222e99869c8c5a361bbdb7" #elif defined(OS_LINUX) -#define CEF_API_HASH_PLATFORM "73f24626e0179a3f5664d64ffe0fa2aab9edf7cf" +#define CEF_API_HASH_PLATFORM "ef345d85855d8d5c34de2fb26d25397c5e0e3534" #endif #ifdef __cplusplus diff --git a/include/cef_cookie.h b/include/cef_cookie.h index 2f3998883..60397e37d 100644 --- a/include/cef_cookie.h +++ b/include/cef_cookie.h @@ -64,32 +64,6 @@ class CefCookieManager : public virtual CefBaseRefCounted { static CefRefPtr GetGlobalManager( CefRefPtr callback); - /// - // Returns a cookie manager that neither stores nor retrieves cookies. All - // usage of cookies will be blocked including cookies accessed via the network - // (request/response headers), via JavaScript (document.cookie), and via - // CefCookieManager methods. No cookies will be displayed in DevTools. If you - // wish to only block cookies sent via the network use the CefRequestHandler - // CanGetCookies and CanSetCookie methods instead. - /// - /*--cef()--*/ - static CefRefPtr GetBlockingManager(); - - /// - // Creates a new cookie manager. If |path| is empty data will be stored in - // memory only. Otherwise, data will be stored at the specified |path|. To - // persist session cookies (cookies without an expiry date or validity - // interval) set |persist_session_cookies| to true. Session cookies are - // generally intended to be transient and most Web browsers do not persist - // them. If |callback| is non-NULL it will be executed asnychronously on the - // IO thread after the manager's storage has been initialized. - /// - /*--cef(optional_param=path,optional_param=callback)--*/ - static CefRefPtr CreateManager( - const CefString& path, - bool persist_session_cookies, - CefRefPtr callback); - /// // Set the schemes supported by this manager. The default schemes ("http", // "https", "ws" and "wss") will always be supported. If |callback| is non- @@ -152,21 +126,6 @@ class CefCookieManager : public virtual CefBaseRefCounted { const CefString& cookie_name, CefRefPtr callback) = 0; - /// - // Sets the directory path that will be used for storing cookie data. If - // |path| is empty data will be stored in memory only. Otherwise, data will be - // stored at the specified |path|. To persist session cookies (cookies without - // an expiry date or validity interval) set |persist_session_cookies| to true. - // Session cookies are generally intended to be transient and most Web - // browsers do not persist them. If |callback| is non-NULL it will be executed - // asnychronously on the IO thread after the manager's storage has been - // initialized. Returns false if cookies cannot be accessed. - /// - /*--cef(optional_param=path,optional_param=callback)--*/ - virtual bool SetStoragePath(const CefString& path, - bool persist_session_cookies, - CefRefPtr callback) = 0; - /// // Flush the backing store (if any) to disk. If |callback| is non-NULL it will // be executed asnychronously on the IO thread after the flush is complete. diff --git a/include/cef_request_context.h b/include/cef_request_context.h index 5d4bbb79f..fcbded2bf 100644 --- a/include/cef_request_context.h +++ b/include/cef_request_context.h @@ -144,15 +144,12 @@ class CefRequestContext : public virtual CefBaseRefCounted { virtual CefString GetCachePath() = 0; /// - // Returns the default cookie manager for this object. This will be the global - // cookie manager if this object is the global request context. Otherwise, - // this will be the default cookie manager used when this request context does - // not receive a value via CefRequestContextHandler::GetCookieManager(). If - // |callback| is non-NULL it will be executed asnychronously on the IO thread - // after the manager's storage has been initialized. + // 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 + // storage has been initialized. /// /*--cef(optional_param=callback)--*/ - virtual CefRefPtr GetDefaultCookieManager( + virtual CefRefPtr GetCookieManager( CefRefPtr callback) = 0; /// diff --git a/include/cef_request_context_handler.h b/include/cef_request_context_handler.h index 20d91334d..022419cbb 100644 --- a/include/cef_request_context_handler.h +++ b/include/cef_request_context_handler.h @@ -39,7 +39,6 @@ #pragma once #include "include/cef_base.h" -#include "include/cef_cookie.h" #include "include/cef_web_plugin.h" class CefRequestContext; @@ -62,14 +61,6 @@ class CefRequestContextHandler : public virtual CefBaseRefCounted { virtual void OnRequestContextInitialized( CefRefPtr request_context) {} - /// - // Called on the browser process IO thread to retrieve the cookie manager. If - // this method returns NULL the default cookie manager retrievable via - // CefRequestContext::GetDefaultCookieManager() will be used. - /// - /*--cef()--*/ - virtual CefRefPtr GetCookieManager() { return NULL; } - /// // Called on multiple browser process threads before a plugin instance is // loaded. |mime_type| is the mime type of the plugin that will be loaded. diff --git a/libcef/browser/browser_context.cc b/libcef/browser/browser_context.cc index ce58cf638..e440d6656 100644 --- a/libcef/browser/browser_context.cc +++ b/libcef/browser/browser_context.cc @@ -1,32 +1,290 @@ -// Copyright (c) 2015 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "libcef/browser/browser_context.h" + +#include +#include + #include "libcef/browser/content_browser_client.h" +#include "libcef/browser/context.h" +#include "libcef/browser/download_manager_delegate.h" #include "libcef/browser/extensions/extension_system.h" +#include "libcef/browser/prefs/browser_prefs.h" +#include "libcef/browser/request_context_impl.h" +#include "libcef/browser/ssl_host_state_delegate.h" #include "libcef/browser/thread_util.h" +#include "libcef/common/cef_switches.h" #include "libcef/common/extensions/extensions_util.h" #include "libcef/common/net_service/util.h" +#include "base/command_line.h" +#include "base/files/file_util.h" +#include "base/lazy_instance.h" #include "base/logging.h" +#include "base/strings/string_util.h" +#include "base/threading/thread_restrictions.h" +#include "chrome/browser/font_family_cache.h" #include "chrome/browser/plugins/chrome_plugin_service_filter.h" #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h" +#include "components/content_settings/core/browser/host_content_settings_map.h" +#include "components/guest_view/browser/guest_view_manager.h" #include "components/keyed_service/content/browser_context_dependency_manager.h" +#include "components/prefs/pref_service.h" +#include "components/proxy_config/pref_proxy_config_tracker_impl.h" #include "components/user_prefs/user_prefs.h" +#include "components/visitedlink/browser/visitedlink_event_listener.h" +#include "components/visitedlink/browser/visitedlink_master.h" +#include "components/zoom/zoom_event_manager.h" +#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/download_manager.h" #include "content/public/browser/storage_partition.h" +#include "extensions/browser/extension_protocols.h" #include "extensions/browser/process_manager.h" +#include "extensions/common/constants.h" +#include "net/proxy_resolution/proxy_config_service.h" +#include "net/proxy_resolution/proxy_resolution_service.h" -CefBrowserContext::CefBrowserContext(bool is_proxy) - : is_proxy_(is_proxy), extension_system_(NULL) {} +using content::BrowserThread; + +namespace { + +// Manages the global list of Impl instances. +class ImplManager { + public: + typedef std::vector Vector; + + ImplManager() {} + ~ImplManager() { + DCHECK(all_.empty()); + DCHECK(map_.empty()); + } + + void AddImpl(CefBrowserContext* impl) { + CEF_REQUIRE_UIT(); + DCHECK(!IsValidImpl(impl)); + all_.push_back(impl); + } + + void RemoveImpl(CefBrowserContext* impl, const base::FilePath& path) { + CEF_REQUIRE_UIT(); + + Vector::iterator it = GetImplPos(impl); + DCHECK(it != all_.end()); + all_.erase(it); + + if (!path.empty()) { + PathMap::iterator it = map_.find(path); + DCHECK(it != map_.end()); + if (it != map_.end()) + map_.erase(it); + } + } + + bool IsValidImpl(const CefBrowserContext* impl) { + CEF_REQUIRE_UIT(); + return GetImplPos(impl) != all_.end(); + } + + CefBrowserContext* GetImplForContext(const content::BrowserContext* context) { + CEF_REQUIRE_UIT(); + if (!context) + return NULL; + + Vector::iterator it = all_.begin(); + for (; it != all_.end(); ++it) { + if (*it == context) + return *it; + } + return NULL; + } + + void SetImplPath(CefBrowserContext* impl, const base::FilePath& path) { + CEF_REQUIRE_UIT(); + DCHECK(!path.empty()); + DCHECK(IsValidImpl(impl)); + DCHECK(GetImplForPath(path) == NULL); + map_.insert(std::make_pair(path, impl)); + } + + CefBrowserContext* GetImplForPath(const base::FilePath& path) { + CEF_REQUIRE_UIT(); + DCHECK(!path.empty()); + PathMap::const_iterator it = map_.find(path); + if (it != map_.end()) + return it->second; + return NULL; + } + + const Vector GetAllImpl() const { return all_; } + + private: + Vector::iterator GetImplPos(const CefBrowserContext* impl) { + Vector::iterator it = all_.begin(); + for (; it != all_.end(); ++it) { + if (*it == impl) + return it; + } + return all_.end(); + } + + typedef std::map PathMap; + PathMap map_; + + Vector all_; + + DISALLOW_COPY_AND_ASSIGN(ImplManager); +}; + +#if DCHECK_IS_ON() +// Because of DCHECK()s in the object destructor. +base::LazyInstance::DestructorAtExit g_manager = + LAZY_INSTANCE_INITIALIZER; +#else +base::LazyInstance::Leaky g_manager = LAZY_INSTANCE_INITIALIZER; +#endif + +} // namespace + +// Creates and manages VisitedLinkEventListener objects for each +// CefBrowserContext sharing the same VisitedLinkMaster. +class CefVisitedLinkListener : public visitedlink::VisitedLinkMaster::Listener { + public: + CefVisitedLinkListener() { DCHECK(listener_map_.empty()); } + + void CreateListenerForContext(const CefBrowserContext* context) { + CEF_REQUIRE_UIT(); + auto listener = std::make_unique( + const_cast(context)); + listener_map_.insert(std::make_pair(context, std::move(listener))); + } + + void RemoveListenerForContext(const CefBrowserContext* context) { + CEF_REQUIRE_UIT(); + ListenerMap::iterator it = listener_map_.find(context); + DCHECK(it != listener_map_.end()); + listener_map_.erase(it); + } + + // visitedlink::VisitedLinkMaster::Listener methods. + + void NewTable(base::ReadOnlySharedMemoryRegion* table_region) override { + CEF_REQUIRE_UIT(); + ListenerMap::iterator it = listener_map_.begin(); + for (; it != listener_map_.end(); ++it) + it->second->NewTable(table_region); + } + + void Add(visitedlink::VisitedLinkCommon::Fingerprint fingerprint) override { + CEF_REQUIRE_UIT(); + ListenerMap::iterator it = listener_map_.begin(); + for (; it != listener_map_.end(); ++it) + it->second->Add(fingerprint); + } + + void Reset(bool invalidate_hashes) override { + CEF_REQUIRE_UIT(); + ListenerMap::iterator it = listener_map_.begin(); + for (; it != listener_map_.end(); ++it) + it->second->Reset(invalidate_hashes); + } + + private: + // Map of CefBrowserContext to the associated VisitedLinkEventListener. + typedef std::map> + ListenerMap; + ListenerMap listener_map_; + + DISALLOW_COPY_AND_ASSIGN(CefVisitedLinkListener); +}; + +CefBrowserContext::CefBrowserContext(const CefRequestContextSettings& settings) + : settings_(settings) { + g_manager.Get().AddImpl(this); +} CefBrowserContext::~CefBrowserContext() { - // Should be cleared in Shutdown(). - DCHECK(!resource_context_.get()); + CEF_REQUIRE_UIT(); + + // No CefRequestContext should be referencing this object any longer. + DCHECK(request_context_set_.empty()); + + // Unregister the context first to avoid re-entrancy during shutdown. + g_manager.Get().RemoveImpl(this, cache_path_); + + // Send notifications to clean up objects associated with this Profile. + MaybeSendDestroyedNotification(); + + ChromePluginServiceFilter::GetInstance()->UnregisterResourceContext( + resource_context_.get()); + + // Remove any BrowserContextKeyedServiceFactory associations. This must be + // called before the ProxyService owned by CefBrowserContext is destroyed. + BrowserContextDependencyManager::GetInstance()->DestroyBrowserContextServices( + this); + + // Shuts down the storage partitions associated with this browser context. + // This must be called before the browser context is actually destroyed + // and before a clean-up task for its corresponding IO thread residents + // (e.g. ResourceContext) is posted, so that the classes that hung on + // StoragePartition can have time to do necessary cleanups on IO thread. + ShutdownStoragePartitions(); + + if (resource_context_.get()) { + // Destruction of the ResourceContext will trigger destruction of all + // associated URLRequests. + content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, + resource_context_.release()); + } + + visitedlink_listener_->RemoveListenerForContext(this); + + // The FontFamilyCache references the ProxyService so delete it before the + // ProxyService is deleted. + SetUserData(&kFontFamilyCacheKey, NULL); + + pref_proxy_config_tracker_->DetachFromPrefService(); + + if (url_request_getter_) + url_request_getter_->ShutdownOnUIThread(); + if (host_content_settings_map_) + host_content_settings_map_->ShutdownOnUIThread(); + + // Delete the download manager delegate here because otherwise we'll crash + // when it's accessed from the content::BrowserContext destructor. + if (download_manager_delegate_) + download_manager_delegate_.reset(NULL); } void CefBrowserContext::Initialize() { + cache_path_ = base::FilePath(CefString(&settings_.cache_path)); + if (!cache_path_.empty()) { + base::ThreadRestrictions::ScopedAllowIO allow_io; + if (!base::DirectoryExists(cache_path_) && + !base::CreateDirectory(cache_path_)) { + LOG(ERROR) << "The cache_path directory could not be created: " + << cache_path_.value(); + cache_path_ = base::FilePath(); + CefString(&settings_.cache_path).clear(); + } + } + + if (!cache_path_.empty()) + g_manager.Get().SetImplPath(this, cache_path_); + + if (settings_.accept_language_list.length == 0) { + // Use the global language list setting. + CefString(&settings_.accept_language_list) = + CefString(&CefContext::Get()->settings().accept_language_list); + } + + // Initialize the PrefService object. + pref_service_ = browser_prefs::CreatePrefService( + this, cache_path_, !!settings_.persist_user_preferences); + content::BrowserContext::Initialize(this, GetPath()); resource_context_.reset( @@ -42,15 +300,9 @@ void CefBrowserContext::Initialize() { if (extensions_enabled) { // Create the custom ExtensionSystem first because other KeyedServices // depend on it. - // The same CefExtensionSystem instance is shared by CefBrowserContextImpl - // and CefBrowserContextProxy objects. extension_system_ = static_cast( extensions::ExtensionSystem::Get(this)); - if (is_proxy_) { - DCHECK(extension_system_->initialized()); - } else { - extension_system_->InitForRegularProfile(true); - } + extension_system_->InitForRegularProfile(true); resource_context_->set_extensions_info_map(extension_system_->info_map()); // Make sure the ProcessManager is created so that it receives extension @@ -58,52 +310,93 @@ void CefBrowserContext::Initialize() { // background/event pages. extensions::ProcessManager::Get(this); } -} -void CefBrowserContext::PostInitialize() { + // Initialize visited links management. + base::FilePath visited_link_path; + if (!cache_path_.empty()) + visited_link_path = cache_path_.Append(FILE_PATH_LITERAL("Visited Links")); + visitedlink_listener_ = new CefVisitedLinkListener; + visitedlink_master_.reset(new visitedlink::VisitedLinkMaster( + visitedlink_listener_, this, !visited_link_path.empty(), false, + visited_link_path, 0)); + visitedlink_listener_->CreateListenerForContext(this); + visitedlink_master_->Init(); + + // Initialize proxy configuration tracker. + pref_proxy_config_tracker_.reset(new PrefProxyConfigTrackerImpl( + GetPrefs(), + base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}))); + // Spell checking support and possibly other subsystems retrieve the // PrefService associated with a BrowserContext via UserPrefs::Get(). PrefService* pref_service = GetPrefs(); DCHECK(pref_service); user_prefs::UserPrefs::Set(this, pref_service); - const bool extensions_enabled = extensions::ExtensionsEnabled(); - if (extensions_enabled && !is_proxy_) + if (extensions_enabled) extension_system_->Init(); ChromePluginServiceFilter::GetInstance()->RegisterResourceContext( this, resource_context_.get()); + + if (!net_service::IsEnabled()) { + // Create the CefURLRequestContextGetter via an indirect call to + // CreateRequestContext. Triggers a call to CefURLRequestContextGetter:: + // GetURLRequestContext() on the IO thread which creates the + // CefURLRequestContext. + GetRequestContext(); + DCHECK(url_request_getter_.get()); + } } -void CefBrowserContext::Shutdown() { +void CefBrowserContext::AddCefRequestContext(CefRequestContextImpl* context) { + CEF_REQUIRE_UIT(); + request_context_set_.insert(context); +} + +void CefBrowserContext::RemoveCefRequestContext( + CefRequestContextImpl* context) { CEF_REQUIRE_UIT(); - // Send notifications to clean up objects associated with this Profile. - MaybeSendDestroyedNotification(); - - ChromePluginServiceFilter::GetInstance()->UnregisterResourceContext( - resource_context_.get()); - - // Remove any BrowserContextKeyedServiceFactory associations. This must be - // called before the ProxyService owned by CefBrowserContextImpl is destroyed. - BrowserContextDependencyManager::GetInstance()->DestroyBrowserContextServices( - this); - - if (!is_proxy_) { - // Shuts down the storage partitions associated with this browser context. - // This must be called before the browser context is actually destroyed - // and before a clean-up task for its corresponding IO thread residents - // (e.g. ResourceContext) is posted, so that the classes that hung on - // StoragePartition can have time to do necessary cleanups on IO thread. - ShutdownStoragePartitions(); + if (extensions::ExtensionsEnabled()) { + extension_system()->OnRequestContextDeleted(context); } - if (resource_context_.get()) { - // Destruction of the ResourceContext will trigger destruction of all - // associated URLRequests. - content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, - resource_context_.release()); + request_context_set_.erase(context); + + // Delete ourselves when the reference count reaches zero. + if (request_context_set_.empty()) + delete this; +} + +CefRequestContextImpl* CefBrowserContext::GetCefRequestContext( + bool impl_only) const { + CEF_REQUIRE_UIT(); + // First try to find a non-proxy RequestContext. + for (CefRequestContextImpl* impl : request_context_set_) { + if (!impl->GetHandler()) + return impl; } + if (impl_only) + return nullptr; + return *request_context_set_.begin(); +} + +// static +CefBrowserContext* CefBrowserContext::GetForCachePath( + const base::FilePath& cache_path) { + return g_manager.Get().GetImplForPath(cache_path); +} + +// static +CefBrowserContext* CefBrowserContext::GetForContext( + content::BrowserContext* context) { + return g_manager.Get().GetImplForContext(context); +} + +// static +std::vector CefBrowserContext::GetAll() { + return g_manager.Get().GetAllImpl(); } content::ResourceContext* CefBrowserContext::GetResourceContext() { @@ -152,6 +445,186 @@ CefBrowserContext::GetURLLoaderFactory() { ->GetURLLoaderFactoryForBrowserProcess(); } +base::FilePath CefBrowserContext::GetPath() const { + return cache_path_; +} + +std::unique_ptr +CefBrowserContext::CreateZoomLevelDelegate( + const base::FilePath& partition_path) { + if (cache_path_.empty()) + return std::unique_ptr(); + + return base::WrapUnique(new ChromeZoomLevelPrefs( + GetPrefs(), cache_path_, partition_path, + zoom::ZoomEventManager::GetForBrowserContext(this)->GetWeakPtr())); +} + +bool CefBrowserContext::IsOffTheRecord() const { + // CEF contexts are never flagged as off-the-record. It causes problems + // for the extension system. + return false; +} + +content::DownloadManagerDelegate* +CefBrowserContext::GetDownloadManagerDelegate() { + if (!download_manager_delegate_) { + content::DownloadManager* manager = + BrowserContext::GetDownloadManager(this); + download_manager_delegate_.reset(new CefDownloadManagerDelegate(manager)); + } + return download_manager_delegate_.get(); +} + +content::BrowserPluginGuestManager* CefBrowserContext::GetGuestManager() { + DCHECK(extensions::ExtensionsEnabled()); + return guest_view::GuestViewManager::FromBrowserContext(this); +} + +storage::SpecialStoragePolicy* CefBrowserContext::GetSpecialStoragePolicy() { + return NULL; +} + +content::PushMessagingService* CefBrowserContext::GetPushMessagingService() { + return NULL; +} + +content::SSLHostStateDelegate* CefBrowserContext::GetSSLHostStateDelegate() { + if (!ssl_host_state_delegate_.get()) + ssl_host_state_delegate_.reset(new CefSSLHostStateDelegate()); + return ssl_host_state_delegate_.get(); +} + +content::PermissionControllerDelegate* +CefBrowserContext::GetPermissionControllerDelegate() { + return nullptr; +} + +content::BackgroundFetchDelegate* +CefBrowserContext::GetBackgroundFetchDelegate() { + return nullptr; +} + +content::BackgroundSyncController* +CefBrowserContext::GetBackgroundSyncController() { + return nullptr; +} + +content::BrowsingDataRemoverDelegate* +CefBrowserContext::GetBrowsingDataRemoverDelegate() { + return nullptr; +} + +net::URLRequestContextGetter* CefBrowserContext::CreateRequestContext( + content::ProtocolHandlerMap* protocol_handlers, + content::URLRequestInterceptorScopedVector request_interceptors) { + CEF_REQUIRE_UIT(); + DCHECK(!net_service::IsEnabled()); + DCHECK(!url_request_getter_.get()); + + auto io_thread_runner = + base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}); + + // Initialize the proxy configuration service. + // TODO(cef): Determine if we can use the Chrome/Mojo implementation from + // https://crrev.com/d0d0d050 + std::unique_ptr base_service( + net::ProxyResolutionService::CreateSystemProxyConfigService( + io_thread_runner)); + std::unique_ptr proxy_config_service( + pref_proxy_config_tracker_->CreateTrackingProxyConfigService( + std::move(base_service))); + + if (extensions::ExtensionsEnabled()) { + // Handle only chrome-extension:// requests. CEF does not support + // chrome-extension-resource:// requests (it does not store shared extension + // data in its installation directory). + extensions::InfoMap* extension_info_map = extension_system()->info_map(); + (*protocol_handlers)[extensions::kExtensionScheme] = + extensions::CreateExtensionProtocolHandler(IsOffTheRecord(), + extension_info_map); + } + + url_request_getter_ = new CefURLRequestContextGetter( + settings_, GetPrefs(), io_thread_runner, protocol_handlers, + std::move(proxy_config_service), std::move(request_interceptors)); + return url_request_getter_.get(); +} + +net::URLRequestContextGetter* +CefBrowserContext::CreateRequestContextForStoragePartition( + const base::FilePath& partition_path, + bool in_memory, + content::ProtocolHandlerMap* protocol_handlers, + content::URLRequestInterceptorScopedVector request_interceptors) { + return nullptr; +} + +PrefService* CefBrowserContext::GetPrefs() { + return pref_service_.get(); +} + +const PrefService* CefBrowserContext::GetPrefs() const { + return pref_service_.get(); +} + +SimpleFactoryKey* CefBrowserContext::GetSimpleFactoryKey() const { + return nullptr; +} + +CefRequestContextImpl* CefBrowserContext::GetCefRequestContext() const { + return GetCefRequestContext(false); +} + +const CefRequestContextSettings& CefBrowserContext::GetSettings() const { + return settings_; +} + +CefRefPtr CefBrowserContext::GetHandler() const { + return NULL; +} + +HostContentSettingsMap* CefBrowserContext::GetHostContentSettingsMap() { + DCHECK_CURRENTLY_ON(BrowserThread::UI); + if (!host_content_settings_map_.get()) { + // The |is_incognito_profile| and |is_guest_profile| arguments are + // intentionally set to false as they otherwise limit the types of values + // that can be stored in the settings map (for example, default values set + // via DefaultProvider::SetWebsiteSetting). + host_content_settings_map_ = + new HostContentSettingsMap(GetPrefs(), false, false, false, false); + + // Change the default plugin policy. + const base::CommandLine* command_line = + base::CommandLine::ForCurrentProcess(); + const std::string& plugin_policy_str = + command_line->GetSwitchValueASCII(switches::kPluginPolicy); + if (!plugin_policy_str.empty()) { + ContentSetting plugin_policy = CONTENT_SETTING_ALLOW; + if (base::LowerCaseEqualsASCII(plugin_policy_str, + switches::kPluginPolicy_Detect)) { + plugin_policy = CONTENT_SETTING_DETECT_IMPORTANT_CONTENT; + } else if (base::LowerCaseEqualsASCII(plugin_policy_str, + switches::kPluginPolicy_Block)) { + plugin_policy = CONTENT_SETTING_BLOCK; + } + host_content_settings_map_->SetDefaultContentSetting( + CONTENT_SETTINGS_TYPE_PLUGINS, plugin_policy); + } + } + return host_content_settings_map_.get(); +} + +void CefBrowserContext::AddVisitedURLs(const std::vector& urls) { + visitedlink_master_->AddURLs(urls); +} + +void CefBrowserContext::RebuildTable( + const scoped_refptr& enumerator) { + // Called when visited links will not or cannot be loaded from disk. + enumerator->OnComplete(true); +} + void CefBrowserContext::OnRenderFrameDeleted(int render_process_id, int render_frame_id, bool is_main_frame, diff --git a/libcef/browser/browser_context.h b/libcef/browser/browser_context.h index b33bb8ba1..6fab5f839 100644 --- a/libcef/browser/browser_context.h +++ b/libcef/browser/browser_context.h @@ -1,16 +1,20 @@ -// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights -// reserved. Use of this source code is governed by a BSD-style license that -// can be found in the LICENSE file. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. -#ifndef CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_H_ -#define CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_H_ +#ifndef CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_IMPL_H_ +#define CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_IMPL_H_ #pragma once #include "include/cef_request_context_handler.h" #include "libcef/browser/chrome_profile_stub.h" -#include "libcef/browser/net/url_request_context_getter_impl.h" +#include "libcef/browser/net/url_request_context_getter.h" #include "libcef/browser/resource_context.h" +#include "base/files/file_path.h" +#include "base/memory/ref_counted.h" +#include "components/proxy_config/pref_proxy_config_tracker.h" +#include "components/visitedlink/browser/visitedlink_delegate.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/content_browser_client.h" @@ -20,7 +24,7 @@ // // WC = WebContents // Content API representation of a browser. Created by BHI or the system (for -// popups) and owned by BHI. Keeps a pointer to BCI/BCP. +// popups) and owned by BHI. Keeps a pointer to BC. // // BHI = CefBrowserHostImpl // Implements the CefBrowser and CefBrowserHost interfaces which are exposed @@ -29,56 +33,32 @@ // // RCI = CefRequestContextImpl // Implements the CefRequestContext interface which is exposed to clients. -// References the isolated BCI or creates a new BCP. +// References the isolated BC. // -// BCI = CefBrowserContextImpl +// BC = CefBrowserContext // Entry point from WC when using an isolated RCI. Owns the RC and creates the // SPI indirectly. Owned by CefBrowserMainParts for the global context or RCI // for non-global contexts. // -// BCP = CefBrowserContextProxy -// Entry point from WC when using a custom RCI. Owns the RC and creates the -// URCGP and SPP. Owned by RCI. -// // SPI = content::StoragePartitionImpl // Owns storage-related objects like Quota, IndexedDB, Cache, etc. Created by -// StoragePartitionImplMap::Get(). Provides access to the URCGI. Life span is -// controlled indirectly by BCI. -// -// SPP = CefStoragePartitionProxy -// Forwards requests for storage-related objects to SPI. Created by -// GetStoragePartitionFromConfig() calling BCI::GetStoragePartitionProxy(). -// Provides access to the URCGP. Life span is controlled by BCP. +// StoragePartitionImplMap::Get(). Provides access to the URCG. Life span is +// controlled indirectly by BC. // // RC = CefResourceContext // Acts as a bridge for resource loading. URLRequest life span is tied to this -// object. Must be destroyed before the associated URCGI/URCGP. Life span is -// controlled by BCI/BCP. +// object. Must be destroyed before the associated URCG. Life span is +// controlled by BC. // -// URCGI = CefURLRequestContextGetterImpl -// Creates and owns the URCI. Created by StoragePartitionImplMap::Get() -// calling BCI::CreateRequestContext(). Life span is controlled by RC and (for +// URCG = CefURLRequestContextGetter +// Creates and owns the URC. Created by StoragePartitionImplMap::Get() +// calling BC::CreateRequestContext(). Life span is controlled by RC and (for // the global context) CefBrowserMainParts, and SPI. // -// URCGP = CefURLRequestContextGetterProxy -// Creates and owns the URCP. Created by GetStoragePartitionFromConfig() -// calling BCI::GetStoragePartitionProxy(). Life span is controlled by RC and -// SPP. -// -// URCI = CefURLRequestContextImpl +// URC = CefURLRequestContext // Owns various network-related objects including the isolated cookie manager. // Owns URLRequest objects which must be destroyed first. Life span is -// controlled by URCGI. -// -// URCP = CefURLRequestContextProxy -// Creates the CSP and forwards requests to the objects owned by URCI. Owns -// URLRequest objects which must be destroyed first. Life span is controlled -// by URCGP. -// -// CSP = CefCookieStoreProxy -// Gives the CefCookieManager instance retrieved via CefRequestContextHandler -// an opportunity to handle cookie requests. Otherwise forwards requests via -// URCI to the isolated cookie manager. Life span is controlled by URCP. +// controlled by URCG. // // // Relationship diagram: @@ -86,17 +66,13 @@ // own = ownership (std::unique_ptr) // ptr = raw pointer // -// CefBrowserMainParts----\ isolated cookie manager, etc. -// | \ ^ -// own ref ref/own -// v v | -// /---> BCI -own-> SPI -ref-> URCGI --own-> URCI <-ptr-- CSP -// / ^ ^ ^ ^ -// ptr ptr ptr ref / -// / | | | / -// BHI -own-> WC -ptr-> BCP -own-> SPP -ref-> URCGP -own-> URCP --ref-/ +// CefBrowserMainParts--\ isolated cookie manager, etc. +// | \ ^ +// own ref ref/own +// v v | +// BHI -own-> WC -ptr-> BC -own-> SPI -ref-> URCG --own-> URC // -// BHI -ref-> RCI -own-> BCI/BCP -own-> RC -ref-> URCGI/URCGP +// BHI -ref-> RCI -own-> BC -own-> RC -ref-> URCG // // // How shutdown works: @@ -104,21 +80,24 @@ // ref release, etc. // 2. CefRequestContextImpl is destroyed (possibly asynchronously) on the UI // thread due to CefBrowserHostImpl destruction, ref release, etc. -// 3. CefBrowserContext* is destroyed on the UI thread due to -// CefRequestContextImpl destruction (*Impl, *Proxy) or deletion in -// CefBrowserMainParts::PostMainMessageLoopRun() (*Impl). +// 3. CefBrowserContext is destroyed on the UI thread due to +// CefRequestContextImpl destruction or deletion in +// CefBrowserMainParts::PostMainMessageLoopRun(). // 4. CefResourceContext is destroyed asynchronously on the IO thread due to -// CefBrowserContext* destruction. This cancels/destroys any pending +// CefBrowserContext destruction. This cancels/destroys any pending // URLRequests. -// 5. CefURLRequestContextGetter* is destroyed asynchronously on the IO thread -// due to CefResourceContext destruction (*Impl, *Proxy) or ref release in -// CefBrowserMainParts::PostMainMessageLoopRun() (*Impl). This may be delayed -// if other network-related objects still have a reference to it. -// 6. CefURLRequestContext* is destroyed on the IO thread due to -// CefURLRequestContextGetter* destruction. +// 5. CefURLRequestContextGetter is destroyed asynchronously on the IO thread +// due to CefResourceContext destruction (or ref release in +// CefBrowserMainParts::PostMainMessageLoopRun. This may be delayed if other +// network-related objects still have a reference to it. +// 6. CefURLRequestContext is destroyed on the IO thread due to +// CefURLRequestContextGetter destruction. */ +class CefDownloadManagerDelegate; class CefRequestContextImpl; +class CefSSLHostStateDelegate; +class CefVisitedLinkListener; class HostContentSettingsMap; class PrefService; @@ -126,15 +105,36 @@ namespace extensions { class CefExtensionSystem; } +namespace visitedlink { +class VisitedLinkMaster; +} + // Main entry point for configuring behavior on a per-browser basis. An instance // of this class is passed to WebContents::Create in CefBrowserHostImpl:: // CreateInternal. Only accessed on the UI thread unless otherwise indicated. -class CefBrowserContext : public ChromeProfileStub { +class CefBrowserContext : public ChromeProfileStub, + public visitedlink::VisitedLinkDelegate { public: - explicit CefBrowserContext(bool is_proxy); + explicit CefBrowserContext(const CefRequestContextSettings& settings); + + // Returns the existing instance, if any, associated with the specified + // |cache_path|. + static CefBrowserContext* GetForCachePath(const base::FilePath& cache_path); + + // Returns the underlying CefBrowserContext if any. + static CefBrowserContext* GetForContext(content::BrowserContext* context); + + // Returns all existing CefBrowserContext. + static std::vector GetAll(); // Must be called immediately after this object is created. - virtual void Initialize(); + void Initialize(); + + // Track associated CefRequestContextImpl objects. This object will delete + // itself when the count reaches zero. + void AddCefRequestContext(CefRequestContextImpl* context); + void RemoveCefRequestContext(CefRequestContextImpl* context); + CefRequestContextImpl* GetCefRequestContext(bool impl_only) const; // BrowserContext methods. content::ResourceContext* GetResourceContext() override; @@ -150,31 +150,59 @@ class CefBrowserContext : public ChromeProfileStub { std::vector allow_patterns, std::vector block_patterns, base::OnceClosure closure) override; + base::FilePath GetPath() const override; + std::unique_ptr CreateZoomLevelDelegate( + const base::FilePath& partition_path) override; + bool IsOffTheRecord() const override; + content::DownloadManagerDelegate* GetDownloadManagerDelegate() override; + content::BrowserPluginGuestManager* GetGuestManager() override; + storage::SpecialStoragePolicy* GetSpecialStoragePolicy() override; + content::PushMessagingService* GetPushMessagingService() override; + content::SSLHostStateDelegate* GetSSLHostStateDelegate() override; + content::PermissionControllerDelegate* GetPermissionControllerDelegate() + override; + content::BackgroundFetchDelegate* GetBackgroundFetchDelegate() override; + content::BackgroundSyncController* GetBackgroundSyncController() override; + content::BrowsingDataRemoverDelegate* GetBrowsingDataRemoverDelegate() + override; + net::URLRequestContextGetter* CreateRequestContext( + content::ProtocolHandlerMap* protocol_handlers, + content::URLRequestInterceptorScopedVector request_interceptors) override; + net::URLRequestContextGetter* CreateRequestContextForStoragePartition( + const base::FilePath& partition_path, + bool in_memory, + content::ProtocolHandlerMap* protocol_handlers, + content::URLRequestInterceptorScopedVector request_interceptors) override; // Profile methods. ChromeZoomLevelPrefs* GetZoomLevelPrefs() override; scoped_refptr GetURLLoaderFactory() override; + PrefService* GetPrefs() override; + bool AllowsBrowserWindows() const override { return false; } + const PrefService* GetPrefs() const override; + SimpleFactoryKey* GetSimpleFactoryKey() const override; - // Returns a RequestContext associated with this object. If this object is a - // *Proxy then it will return the single associated proxy RequestContext. If - // this object is an *Impl then it will return the first non-proxy - // RequestContext, if one exists, otherwise the first proxy RequestContext. - virtual CefRequestContextImpl* GetCefRequestContext() const = 0; + // visitedlink::VisitedLinkDelegate methods. + void RebuildTable(const scoped_refptr& enumerator) override; + + // Returns the first RequestContext without a handler, if one exists, + // otherwise the first RequestContext. + CefRequestContextImpl* GetCefRequestContext() const; // Returns the settings associated with this object. Safe to call from any // thread. - virtual const CefRequestContextSettings& GetSettings() const = 0; + const CefRequestContextSettings& GetSettings() const; // Returns the handler associated with this object. Safe to call from any // thread. - virtual CefRefPtr GetHandler() const = 0; + CefRefPtr GetHandler() const; // Settings for plugins and extensions. - virtual HostContentSettingsMap* GetHostContentSettingsMap() = 0; + HostContentSettingsMap* GetHostContentSettingsMap(); // Called from CefBrowserHostImpl::DidNavigateAnyFrame to update the table of // visited links. - virtual void AddVisitedURLs(const std::vector& urls) = 0; + void AddVisitedURLs(const std::vector& urls); // Called from CefBrowserHostImpl::RenderFrameDeleted or // CefMimeHandlerViewGuestDelegate::OnGuestDetached when a render frame is @@ -195,27 +223,41 @@ class CefBrowserContext : public ChromeProfileStub { return extension_system_; } - bool is_proxy() const { return is_proxy_; } - - protected: - ~CefBrowserContext() override; - - // Must be called after all services have been initialized. - void PostInitialize(); - - // Must be called before the child object destructor has completed. - void Shutdown(); + // Guaranteed to exist once this object has been initialized. + scoped_refptr request_context_getter() const { + return url_request_getter_; + } private: - // True if this CefBrowserContext is a CefBrowserContextProxy. - const bool is_proxy_; + // Allow deletion via std::unique_ptr(). + friend std::default_delete; + + ~CefBrowserContext() override; + + // Members initialized during construction are safe to access from any thread. + CefRequestContextSettings settings_; + base::FilePath cache_path_; + + // CefRequestContextImpl objects referencing this object. + std::set request_context_set_; + + std::unique_ptr pref_service_; + std::unique_ptr pref_proxy_config_tracker_; + + std::unique_ptr download_manager_delegate_; + scoped_refptr url_request_getter_; + std::unique_ptr ssl_host_state_delegate_; + scoped_refptr host_content_settings_map_; + std::unique_ptr visitedlink_master_; + // |visitedlink_listener_| is owned by visitedlink_master_. + CefVisitedLinkListener* visitedlink_listener_; std::unique_ptr resource_context_; // Owned by the KeyedService system. - extensions::CefExtensionSystem* extension_system_; + extensions::CefExtensionSystem* extension_system_ = nullptr; DISALLOW_COPY_AND_ASSIGN(CefBrowserContext); }; -#endif // CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_H_ +#endif // CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_IMPL_H_ diff --git a/libcef/browser/browser_context_impl.cc b/libcef/browser/browser_context_impl.cc deleted file mode 100644 index 794050ac7..000000000 --- a/libcef/browser/browser_context_impl.cc +++ /dev/null @@ -1,562 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "libcef/browser/browser_context_impl.h" - -#include -#include - -#include "libcef/browser/browser_context_proxy.h" -#include "libcef/browser/content_browser_client.h" -#include "libcef/browser/context.h" -#include "libcef/browser/download_manager_delegate.h" -#include "libcef/browser/extensions/extension_system.h" -#include "libcef/browser/prefs/browser_prefs.h" -#include "libcef/browser/request_context_impl.h" -#include "libcef/browser/ssl_host_state_delegate.h" -#include "libcef/browser/thread_util.h" -#include "libcef/common/cef_switches.h" -#include "libcef/common/extensions/extensions_util.h" -#include "libcef/common/net_service/util.h" - -#include "base/command_line.h" -#include "base/files/file_util.h" -#include "base/lazy_instance.h" -#include "base/logging.h" -#include "base/strings/string_util.h" -#include "base/threading/thread_restrictions.h" -#include "chrome/browser/font_family_cache.h" -#include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h" -#include "components/content_settings/core/browser/host_content_settings_map.h" -#include "components/guest_view/browser/guest_view_manager.h" -#include "components/prefs/pref_service.h" -#include "components/proxy_config/pref_proxy_config_tracker_impl.h" -#include "components/visitedlink/browser/visitedlink_event_listener.h" -#include "components/visitedlink/browser/visitedlink_master.h" -#include "components/zoom/zoom_event_manager.h" -#include "content/public/browser/browser_task_traits.h" -#include "content/public/browser/browser_thread.h" -#include "content/public/browser/download_manager.h" -#include "content/public/browser/storage_partition.h" -#include "extensions/browser/extension_protocols.h" -#include "extensions/common/constants.h" -#include "net/proxy_resolution/proxy_config_service.h" -#include "net/proxy_resolution/proxy_resolution_service.h" - -using content::BrowserThread; - -namespace { - -// Manages the global list of Impl instances. -class ImplManager { - public: - typedef std::vector Vector; - - ImplManager() {} - ~ImplManager() { - DCHECK(all_.empty()); - DCHECK(map_.empty()); - } - - void AddImpl(CefBrowserContextImpl* impl) { - CEF_REQUIRE_UIT(); - DCHECK(!IsValidImpl(impl)); - all_.push_back(impl); - } - - void RemoveImpl(CefBrowserContextImpl* impl, const base::FilePath& path) { - CEF_REQUIRE_UIT(); - - Vector::iterator it = GetImplPos(impl); - DCHECK(it != all_.end()); - all_.erase(it); - - if (!path.empty()) { - PathMap::iterator it = map_.find(path); - DCHECK(it != map_.end()); - if (it != map_.end()) - map_.erase(it); - } - } - - bool IsValidImpl(const CefBrowserContextImpl* impl) { - CEF_REQUIRE_UIT(); - return GetImplPos(impl) != all_.end(); - } - - CefBrowserContextImpl* GetImplForContext( - const content::BrowserContext* context) { - CEF_REQUIRE_UIT(); - if (!context) - return NULL; - - const CefBrowserContext* cef_context = - static_cast(context); - const CefBrowserContextImpl* cef_context_impl = nullptr; - if (cef_context->is_proxy()) { - cef_context_impl = - static_cast(cef_context)->parent(); - } else { - cef_context_impl = static_cast(cef_context); - } - - Vector::iterator it = all_.begin(); - for (; it != all_.end(); ++it) { - if (*it == cef_context_impl) - return *it; - } - return NULL; - } - - void SetImplPath(CefBrowserContextImpl* impl, const base::FilePath& path) { - CEF_REQUIRE_UIT(); - DCHECK(!path.empty()); - DCHECK(IsValidImpl(impl)); - DCHECK(GetImplForPath(path) == NULL); - map_.insert(std::make_pair(path, impl)); - } - - CefBrowserContextImpl* GetImplForPath(const base::FilePath& path) { - CEF_REQUIRE_UIT(); - DCHECK(!path.empty()); - PathMap::const_iterator it = map_.find(path); - if (it != map_.end()) - return it->second; - return NULL; - } - - const Vector GetAllImpl() const { return all_; } - - private: - Vector::iterator GetImplPos(const CefBrowserContextImpl* impl) { - Vector::iterator it = all_.begin(); - for (; it != all_.end(); ++it) { - if (*it == impl) - return it; - } - return all_.end(); - } - - typedef std::map PathMap; - PathMap map_; - - Vector all_; - - DISALLOW_COPY_AND_ASSIGN(ImplManager); -}; - -#if DCHECK_IS_ON() -// Because of DCHECK()s in the object destructor. -base::LazyInstance::DestructorAtExit g_manager = - LAZY_INSTANCE_INITIALIZER; -#else -base::LazyInstance::Leaky g_manager = LAZY_INSTANCE_INITIALIZER; -#endif - -} // namespace - -// Creates and manages VisitedLinkEventListener objects for each -// CefBrowserContext sharing the same VisitedLinkMaster. -class CefVisitedLinkListener : public visitedlink::VisitedLinkMaster::Listener { - public: - CefVisitedLinkListener() { DCHECK(listener_map_.empty()); } - - void CreateListenerForContext(const CefBrowserContext* context) { - CEF_REQUIRE_UIT(); - auto listener = std::make_unique( - const_cast(context)); - listener_map_.insert(std::make_pair(context, std::move(listener))); - } - - void RemoveListenerForContext(const CefBrowserContext* context) { - CEF_REQUIRE_UIT(); - ListenerMap::iterator it = listener_map_.find(context); - DCHECK(it != listener_map_.end()); - listener_map_.erase(it); - } - - // visitedlink::VisitedLinkMaster::Listener methods. - - void NewTable(base::ReadOnlySharedMemoryRegion* table_region) override { - CEF_REQUIRE_UIT(); - ListenerMap::iterator it = listener_map_.begin(); - for (; it != listener_map_.end(); ++it) - it->second->NewTable(table_region); - } - - void Add(visitedlink::VisitedLinkCommon::Fingerprint fingerprint) override { - CEF_REQUIRE_UIT(); - ListenerMap::iterator it = listener_map_.begin(); - for (; it != listener_map_.end(); ++it) - it->second->Add(fingerprint); - } - - void Reset(bool invalidate_hashes) override { - CEF_REQUIRE_UIT(); - ListenerMap::iterator it = listener_map_.begin(); - for (; it != listener_map_.end(); ++it) - it->second->Reset(invalidate_hashes); - } - - private: - // Map of CefBrowserContext to the associated VisitedLinkEventListener. - typedef std::map> - ListenerMap; - ListenerMap listener_map_; - - DISALLOW_COPY_AND_ASSIGN(CefVisitedLinkListener); -}; - -CefBrowserContextImpl::CefBrowserContextImpl( - const CefRequestContextSettings& settings) - : CefBrowserContext(false), settings_(settings) { - g_manager.Get().AddImpl(this); -} - -CefBrowserContextImpl::~CefBrowserContextImpl() { - CEF_REQUIRE_UIT(); - - // No CefRequestContextImpl should be referencing this object any longer. - DCHECK(request_context_set_.empty()); - - // Unregister the context first to avoid re-entrancy during shutdown. - g_manager.Get().RemoveImpl(this, cache_path_); - - Shutdown(); - - visitedlink_listener_->RemoveListenerForContext(this); - - // The FontFamilyCache references the ProxyService so delete it before the - // ProxyService is deleted. - SetUserData(&kFontFamilyCacheKey, NULL); - - pref_proxy_config_tracker_->DetachFromPrefService(); - - if (url_request_getter_) - url_request_getter_->ShutdownOnUIThread(); - if (host_content_settings_map_) - host_content_settings_map_->ShutdownOnUIThread(); - - // Delete the download manager delegate here because otherwise we'll crash - // when it's accessed from the content::BrowserContext destructor. - if (download_manager_delegate_) - download_manager_delegate_.reset(NULL); -} - -void CefBrowserContextImpl::Initialize() { - cache_path_ = base::FilePath(CefString(&settings_.cache_path)); - if (!cache_path_.empty()) { - base::ThreadRestrictions::ScopedAllowIO allow_io; - if (!base::DirectoryExists(cache_path_) && - !base::CreateDirectory(cache_path_)) { - LOG(ERROR) << "The cache_path directory could not be created: " - << cache_path_.value(); - cache_path_ = base::FilePath(); - CefString(&settings_.cache_path).clear(); - } - } - - if (!cache_path_.empty()) - g_manager.Get().SetImplPath(this, cache_path_); - - if (settings_.accept_language_list.length == 0) { - // Use the global language list setting. - CefString(&settings_.accept_language_list) = - CefString(&CefContext::Get()->settings().accept_language_list); - } - - // Initialize the PrefService object. - pref_service_ = browser_prefs::CreatePrefService( - this, cache_path_, !!settings_.persist_user_preferences); - - CefBrowserContext::Initialize(); - - // Initialize visited links management. - base::FilePath visited_link_path; - if (!cache_path_.empty()) - visited_link_path = cache_path_.Append(FILE_PATH_LITERAL("Visited Links")); - visitedlink_listener_ = new CefVisitedLinkListener; - visitedlink_master_.reset(new visitedlink::VisitedLinkMaster( - visitedlink_listener_, this, !visited_link_path.empty(), false, - visited_link_path, 0)); - visitedlink_listener_->CreateListenerForContext(this); - visitedlink_master_->Init(); - - // Initialize proxy configuration tracker. - pref_proxy_config_tracker_.reset(new PrefProxyConfigTrackerImpl( - GetPrefs(), - base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}))); - - CefBrowserContext::PostInitialize(); - - if (!net_service::IsEnabled()) { - // Create the CefURLRequestContextGetterImpl via an indirect call to - // CreateRequestContext. Triggers a call to CefURLRequestContextGetterImpl:: - // GetURLRequestContext() on the IO thread which creates the - // CefURLRequestContextImpl. - GetRequestContext(); - DCHECK(url_request_getter_.get()); - } - - // Create the StoragePartitionImplMap and StoragePartitionImpl for this - // object. This must be done before the first WebContents is created using a - // CefBrowserContextProxy of this object, otherwise the StoragePartitionProxy - // will not be created (in that case - // CefBrowserContextProxy::CreateRequestContext will be called, which is - // incorrect). - GetDefaultStoragePartition(this); -} - -void CefBrowserContextImpl::AddProxy(const CefBrowserContextProxy* proxy) { - CEF_REQUIRE_UIT(); - visitedlink_listener_->CreateListenerForContext(proxy); -} - -void CefBrowserContextImpl::RemoveProxy(const CefBrowserContextProxy* proxy) { - CEF_REQUIRE_UIT(); - visitedlink_listener_->RemoveListenerForContext(proxy); -} - -void CefBrowserContextImpl::AddCefRequestContext( - CefRequestContextImpl* context) { - CEF_REQUIRE_UIT(); - request_context_set_.insert(context); -} - -void CefBrowserContextImpl::RemoveCefRequestContext( - CefRequestContextImpl* context) { - CEF_REQUIRE_UIT(); - - if (extensions::ExtensionsEnabled()) { - extension_system()->OnRequestContextDeleted(context); - } - - request_context_set_.erase(context); - - // Delete ourselves when the reference count reaches zero. - if (request_context_set_.empty()) - delete this; -} - -CefRequestContextImpl* CefBrowserContextImpl::GetCefRequestContext( - bool impl_only) const { - CEF_REQUIRE_UIT(); - // First try to find a non-proxy RequestContext. - for (CefRequestContextImpl* impl : request_context_set_) { - if (!impl->GetHandler()) - return impl; - } - if (impl_only) - return nullptr; - return *request_context_set_.begin(); -} - -// static -CefBrowserContextImpl* CefBrowserContextImpl::GetForCachePath( - const base::FilePath& cache_path) { - return g_manager.Get().GetImplForPath(cache_path); -} - -// static -CefBrowserContextImpl* CefBrowserContextImpl::GetForContext( - content::BrowserContext* context) { - return g_manager.Get().GetImplForContext(context); -} - -// static -std::vector CefBrowserContextImpl::GetAll() { - return g_manager.Get().GetAllImpl(); -} - -base::FilePath CefBrowserContextImpl::GetPath() const { - return cache_path_; -} - -std::unique_ptr -CefBrowserContextImpl::CreateZoomLevelDelegate( - const base::FilePath& partition_path) { - if (cache_path_.empty()) - return std::unique_ptr(); - - return base::WrapUnique(new ChromeZoomLevelPrefs( - GetPrefs(), cache_path_, partition_path, - zoom::ZoomEventManager::GetForBrowserContext(this)->GetWeakPtr())); -} - -bool CefBrowserContextImpl::IsOffTheRecord() const { - // CEF contexts are never flagged as off-the-record. It causes problems - // for the extension system. - return false; -} - -content::DownloadManagerDelegate* -CefBrowserContextImpl::GetDownloadManagerDelegate() { - if (!download_manager_delegate_) { - content::DownloadManager* manager = - BrowserContext::GetDownloadManager(this); - download_manager_delegate_.reset(new CefDownloadManagerDelegate(manager)); - } - return download_manager_delegate_.get(); -} - -content::BrowserPluginGuestManager* CefBrowserContextImpl::GetGuestManager() { - DCHECK(extensions::ExtensionsEnabled()); - return guest_view::GuestViewManager::FromBrowserContext(this); -} - -storage::SpecialStoragePolicy* -CefBrowserContextImpl::GetSpecialStoragePolicy() { - return NULL; -} - -content::PushMessagingService* -CefBrowserContextImpl::GetPushMessagingService() { - return NULL; -} - -content::SSLHostStateDelegate* -CefBrowserContextImpl::GetSSLHostStateDelegate() { - if (!ssl_host_state_delegate_.get()) - ssl_host_state_delegate_.reset(new CefSSLHostStateDelegate()); - return ssl_host_state_delegate_.get(); -} - -content::PermissionControllerDelegate* -CefBrowserContextImpl::GetPermissionControllerDelegate() { - return nullptr; -} - -content::BackgroundFetchDelegate* -CefBrowserContextImpl::GetBackgroundFetchDelegate() { - return nullptr; -} - -content::BackgroundSyncController* -CefBrowserContextImpl::GetBackgroundSyncController() { - return nullptr; -} - -content::BrowsingDataRemoverDelegate* -CefBrowserContextImpl::GetBrowsingDataRemoverDelegate() { - return nullptr; -} - -net::URLRequestContextGetter* CefBrowserContextImpl::CreateRequestContext( - content::ProtocolHandlerMap* protocol_handlers, - content::URLRequestInterceptorScopedVector request_interceptors) { - CEF_REQUIRE_UIT(); - DCHECK(!net_service::IsEnabled()); - DCHECK(!url_request_getter_.get()); - - auto io_thread_runner = - base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}); - - // Initialize the proxy configuration service. - // TODO(cef): Determine if we can use the Chrome/Mojo implementation from - // https://crrev.com/d0d0d050 - std::unique_ptr base_service( - net::ProxyResolutionService::CreateSystemProxyConfigService( - io_thread_runner)); - std::unique_ptr proxy_config_service( - pref_proxy_config_tracker_->CreateTrackingProxyConfigService( - std::move(base_service))); - - if (extensions::ExtensionsEnabled()) { - // Handle only chrome-extension:// requests. CEF does not support - // chrome-extension-resource:// requests (it does not store shared extension - // data in its installation directory). - extensions::InfoMap* extension_info_map = extension_system()->info_map(); - (*protocol_handlers)[extensions::kExtensionScheme] = - extensions::CreateExtensionProtocolHandler(IsOffTheRecord(), - extension_info_map); - } - - url_request_getter_ = new CefURLRequestContextGetterImpl( - settings_, GetPrefs(), io_thread_runner, protocol_handlers, - std::move(proxy_config_service), std::move(request_interceptors)); - return url_request_getter_.get(); -} - -net::URLRequestContextGetter* -CefBrowserContextImpl::CreateRequestContextForStoragePartition( - const base::FilePath& partition_path, - bool in_memory, - content::ProtocolHandlerMap* protocol_handlers, - content::URLRequestInterceptorScopedVector request_interceptors) { - return nullptr; -} - -content::StoragePartition* CefBrowserContextImpl::GetStoragePartitionProxy( - content::BrowserContext* browser_context, - content::StoragePartition* partition_impl) { - CefBrowserContextProxy* proxy = - static_cast(browser_context); - return proxy->GetOrCreateStoragePartitionProxy(partition_impl); -} - -PrefService* CefBrowserContextImpl::GetPrefs() { - return pref_service_.get(); -} - -const PrefService* CefBrowserContextImpl::GetPrefs() const { - return pref_service_.get(); -} - -SimpleFactoryKey* CefBrowserContextImpl::GetSimpleFactoryKey() const { - return nullptr; -} - -CefRequestContextImpl* CefBrowserContextImpl::GetCefRequestContext() const { - return GetCefRequestContext(false); -} - -const CefRequestContextSettings& CefBrowserContextImpl::GetSettings() const { - return settings_; -} - -CefRefPtr CefBrowserContextImpl::GetHandler() const { - return NULL; -} - -HostContentSettingsMap* CefBrowserContextImpl::GetHostContentSettingsMap() { - DCHECK_CURRENTLY_ON(BrowserThread::UI); - if (!host_content_settings_map_.get()) { - // The |is_incognito_profile| and |is_guest_profile| arguments are - // intentionally set to false as they otherwise limit the types of values - // that can be stored in the settings map (for example, default values set - // via DefaultProvider::SetWebsiteSetting). - host_content_settings_map_ = - new HostContentSettingsMap(GetPrefs(), false, false, false, false); - - // Change the default plugin policy. - const base::CommandLine* command_line = - base::CommandLine::ForCurrentProcess(); - const std::string& plugin_policy_str = - command_line->GetSwitchValueASCII(switches::kPluginPolicy); - if (!plugin_policy_str.empty()) { - ContentSetting plugin_policy = CONTENT_SETTING_ALLOW; - if (base::LowerCaseEqualsASCII(plugin_policy_str, - switches::kPluginPolicy_Detect)) { - plugin_policy = CONTENT_SETTING_DETECT_IMPORTANT_CONTENT; - } else if (base::LowerCaseEqualsASCII(plugin_policy_str, - switches::kPluginPolicy_Block)) { - plugin_policy = CONTENT_SETTING_BLOCK; - } - host_content_settings_map_->SetDefaultContentSetting( - CONTENT_SETTINGS_TYPE_PLUGINS, plugin_policy); - } - } - return host_content_settings_map_.get(); -} - -void CefBrowserContextImpl::AddVisitedURLs(const std::vector& urls) { - visitedlink_master_->AddURLs(urls); -} - -void CefBrowserContextImpl::RebuildTable( - const scoped_refptr& enumerator) { - // Called when visited links will not or cannot be loaded from disk. - enumerator->OnComplete(true); -} diff --git a/libcef/browser/browser_context_impl.h b/libcef/browser/browser_context_impl.h deleted file mode 100644 index 3d4ec3d0f..000000000 --- a/libcef/browser/browser_context_impl.h +++ /dev/null @@ -1,136 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_IMPL_H_ -#define CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_IMPL_H_ -#pragma once - -#include "libcef/browser/browser_context.h" - -#include "libcef/browser/net/url_request_context_getter_impl.h" - -#include "base/files/file_path.h" -#include "base/memory/ref_counted.h" -#include "components/proxy_config/pref_proxy_config_tracker.h" -#include "components/visitedlink/browser/visitedlink_delegate.h" - -class CefBrowserContextProxy; -class CefDownloadManagerDelegate; -class CefSSLHostStateDelegate; -class CefVisitedLinkListener; - -namespace visitedlink { -class VisitedLinkMaster; -} - -// Isolated BrowserContext implementation. Life span is controlled by -// CefBrowserMainParts for the global context and CefRequestContextImpl -// for non-global contexts. Only accessed on the UI thread unless otherwise -// indicated. See browser_context.h for an object relationship diagram. -class CefBrowserContextImpl : public CefBrowserContext, - public visitedlink::VisitedLinkDelegate { - public: - explicit CefBrowserContextImpl(const CefRequestContextSettings& settings); - - // Returns the existing instance, if any, associated with the specified - // |cache_path|. - static CefBrowserContextImpl* GetForCachePath( - const base::FilePath& cache_path); - - // Returns the underlying CefBrowserContextImpl if any. - static CefBrowserContextImpl* GetForContext(content::BrowserContext* context); - - // Returns all existing CefBrowserContextImpl. - static std::vector GetAll(); - - // Must be called immediately after this object is created. - void Initialize() override; - - // Track associated CefBrowserContextProxy objects. - void AddProxy(const CefBrowserContextProxy* proxy); - void RemoveProxy(const CefBrowserContextProxy* proxy); - - // Track associated CefRequestContextImpl objects. This object will delete - // itself when the count reaches zero. - void AddCefRequestContext(CefRequestContextImpl* context); - void RemoveCefRequestContext(CefRequestContextImpl* context); - CefRequestContextImpl* GetCefRequestContext(bool impl_only) const; - - // BrowserContext methods. - base::FilePath GetPath() const override; - std::unique_ptr CreateZoomLevelDelegate( - const base::FilePath& partition_path) override; - bool IsOffTheRecord() const override; - content::DownloadManagerDelegate* GetDownloadManagerDelegate() override; - content::BrowserPluginGuestManager* GetGuestManager() override; - storage::SpecialStoragePolicy* GetSpecialStoragePolicy() override; - content::PushMessagingService* GetPushMessagingService() override; - content::SSLHostStateDelegate* GetSSLHostStateDelegate() override; - content::PermissionControllerDelegate* GetPermissionControllerDelegate() - override; - content::BackgroundFetchDelegate* GetBackgroundFetchDelegate() override; - content::BackgroundSyncController* GetBackgroundSyncController() override; - content::BrowsingDataRemoverDelegate* GetBrowsingDataRemoverDelegate() - override; - net::URLRequestContextGetter* CreateRequestContext( - content::ProtocolHandlerMap* protocol_handlers, - content::URLRequestInterceptorScopedVector request_interceptors) override; - net::URLRequestContextGetter* CreateRequestContextForStoragePartition( - const base::FilePath& partition_path, - bool in_memory, - content::ProtocolHandlerMap* protocol_handlers, - content::URLRequestInterceptorScopedVector request_interceptors) override; - content::StoragePartition* GetStoragePartitionProxy( - content::BrowserContext* browser_context, - content::StoragePartition* partition_impl) override; - - // Profile methods. - PrefService* GetPrefs() override; - bool AllowsBrowserWindows() const override { return false; } - const PrefService* GetPrefs() const override; - SimpleFactoryKey* GetSimpleFactoryKey() const override; - - // CefBrowserContext methods. - CefRequestContextImpl* GetCefRequestContext() const override; - const CefRequestContextSettings& GetSettings() const override; - CefRefPtr GetHandler() const override; - HostContentSettingsMap* GetHostContentSettingsMap() override; - void AddVisitedURLs(const std::vector& urls) override; - - // visitedlink::VisitedLinkDelegate methods. - void RebuildTable(const scoped_refptr& enumerator) override; - - // Guaranteed to exist once this object has been initialized. - scoped_refptr request_context_getter() const { - return url_request_getter_; - } - - private: - // Allow deletion via std::unique_ptr(). - friend std::default_delete; - - ~CefBrowserContextImpl() override; - - // Members initialized during construction are safe to access from any thread. - CefRequestContextSettings settings_; - base::FilePath cache_path_; - - // CefRequestContextImpl objects referencing this object. - std::set request_context_set_; - - std::unique_ptr pref_service_; - std::unique_ptr pref_proxy_config_tracker_; - - std::unique_ptr download_manager_delegate_; - scoped_refptr url_request_getter_; - std::unique_ptr ssl_host_state_delegate_; - scoped_refptr host_content_settings_map_; - std::unique_ptr visitedlink_master_; - // |visitedlink_listener_| is owned by visitedlink_master_. - CefVisitedLinkListener* visitedlink_listener_; - - DISALLOW_COPY_AND_ASSIGN(CefBrowserContextImpl); -}; - -#endif // CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_IMPL_H_ diff --git a/libcef/browser/browser_context_proxy.cc b/libcef/browser/browser_context_proxy.cc deleted file mode 100644 index ed15d0d11..000000000 --- a/libcef/browser/browser_context_proxy.cc +++ /dev/null @@ -1,267 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "libcef/browser/browser_context_proxy.h" - -#include "libcef/browser/content_browser_client.h" -#include "libcef/browser/download_manager_delegate.h" -#include "libcef/browser/net/url_request_context_getter_proxy.h" -#include "libcef/browser/storage_partition_proxy.h" -#include "libcef/browser/thread_util.h" -#include "libcef/common/net_service/util.h" - -#include "base/logging.h" -#include "chrome/browser/font_family_cache.h" -#include "components/guest_view/common/guest_view_constants.h" -#include "components/visitedlink/browser/visitedlink_master.h" -#include "content/browser/blob_storage/chrome_blob_storage_context.h" -#include "content/browser/resource_context_impl.h" -#include "content/browser/streams/stream_context.h" -#include "content/browser/webui/url_data_manager.h" -#include "content/public/browser/storage_partition.h" -#include "services/service_manager/public/cpp/service.h" - -namespace { - -bool ShouldProxyUserData(const void* key) { - // If this value is not proxied then multiple StoragePartitionImpl objects - // will be created and filesystem API access will fail, among other things. - if (key == content::BrowserContext::GetStoragePartitionMapUserDataKey()) - return true; - - // If these values are not proxied then blob data fails to load for the PDF - // extension. - // See also the call to InitializeResourceContext(). - if (key == content::ChromeBlobStorageContext::GetUserDataKey() || - key == content::StreamContext::GetUserDataKey()) { - return true; - } - - // If this value is not proxied then CefBrowserContextImpl::GetGuestManager() - // returns NULL. - // See also CefExtensionsAPIClient::CreateGuestViewManagerDelegate. - if (key == guest_view::kGuestViewManagerKeyName) - return true; - - // If this value is not proxied then there will be a use-after-free while - // destroying the FontFamilyCache because it will try to access the - // ProxyService owned by CefBrowserContextImpl (which has already been freed). - if (key == kFontFamilyCacheKey) - return true; - - // If this value is not proxied WebUI will fail to load. - if (key == content::URLDataManager::GetUserDataKey()) - return true; - - return false; -} - -} // namespace - -CefBrowserContextProxy::CefBrowserContextProxy( - CefRequestContextImpl* const request_context, - CefRefPtr handler, - CefBrowserContextImpl* parent) - : CefBrowserContext(true), - request_context_(request_context), - handler_(handler), - parent_(parent) { - DCHECK(handler_.get()); - DCHECK(parent_); - parent_->AddProxy(this); -} - -CefBrowserContextProxy::~CefBrowserContextProxy() { - CEF_REQUIRE_UIT(); - - Shutdown(); - - parent_->RemoveProxy(this); -} - -void CefBrowserContextProxy::Initialize() { - CefBrowserContext::Initialize(); - - // This object's CefResourceContext needs to proxy some UserData requests to - // the parent object's CefResourceContext. - resource_context()->set_parent(parent_->resource_context()); - - CefBrowserContext::PostInitialize(); -} - -base::SupportsUserData::Data* CefBrowserContextProxy::GetUserData( - const void* key) const { - if (ShouldProxyUserData(key)) - return parent_->GetUserData(key); - return BrowserContext::GetUserData(key); -} - -void CefBrowserContextProxy::SetUserData(const void* key, - std::unique_ptr data) { - if (ShouldProxyUserData(key)) - parent_->SetUserData(key, std::move(data)); - else - BrowserContext::SetUserData(key, std::move(data)); -} - -void CefBrowserContextProxy::RemoveUserData(const void* key) { - if (ShouldProxyUserData(key)) - parent_->RemoveUserData(key); - else - BrowserContext::RemoveUserData(key); -} - -base::FilePath CefBrowserContextProxy::GetPath() const { - return parent_->GetPath(); -} - -std::unique_ptr -CefBrowserContextProxy::CreateZoomLevelDelegate( - const base::FilePath& partition_path) { - return parent_->CreateZoomLevelDelegate(partition_path); -} - -bool CefBrowserContextProxy::IsOffTheRecord() const { - return parent_->IsOffTheRecord(); -} - -content::DownloadManagerDelegate* -CefBrowserContextProxy::GetDownloadManagerDelegate() { - if (!download_manager_delegate_) { - content::DownloadManager* manager = - BrowserContext::GetDownloadManager(this); - download_manager_delegate_.reset(new CefDownloadManagerDelegate(manager)); - } - return download_manager_delegate_.get(); -} - -content::BrowserPluginGuestManager* CefBrowserContextProxy::GetGuestManager() { - return parent_->GetGuestManager(); -} - -storage::SpecialStoragePolicy* -CefBrowserContextProxy::GetSpecialStoragePolicy() { - return parent_->GetSpecialStoragePolicy(); -} - -content::PushMessagingService* -CefBrowserContextProxy::GetPushMessagingService() { - return parent_->GetPushMessagingService(); -} - -content::SSLHostStateDelegate* -CefBrowserContextProxy::GetSSLHostStateDelegate() { - return parent_->GetSSLHostStateDelegate(); -} - -content::ClientHintsControllerDelegate* -CefBrowserContextProxy::GetClientHintsControllerDelegate() { - return parent_->GetClientHintsControllerDelegate(); -} - -content::PermissionControllerDelegate* -CefBrowserContextProxy::GetPermissionControllerDelegate() { - return parent_->GetPermissionControllerDelegate(); -} - -content::BackgroundFetchDelegate* -CefBrowserContextProxy::GetBackgroundFetchDelegate() { - return parent_->GetBackgroundFetchDelegate(); -} - -content::BackgroundSyncController* -CefBrowserContextProxy::GetBackgroundSyncController() { - return parent_->GetBackgroundSyncController(); -} - -content::BrowsingDataRemoverDelegate* -CefBrowserContextProxy::GetBrowsingDataRemoverDelegate() { - return parent_->GetBrowsingDataRemoverDelegate(); -} - -net::URLRequestContextGetter* CefBrowserContextProxy::CreateRequestContext( - content::ProtocolHandlerMap* protocol_handlers, - content::URLRequestInterceptorScopedVector request_interceptors) { - // CefBrowserContextImpl::GetOrCreateStoragePartitionProxy is called instead - // of this method. - NOTREACHED(); - return nullptr; -} - -net::URLRequestContextGetter* -CefBrowserContextProxy::CreateRequestContextForStoragePartition( - const base::FilePath& partition_path, - bool in_memory, - content::ProtocolHandlerMap* protocol_handlers, - content::URLRequestInterceptorScopedVector request_interceptors) { - return nullptr; -} - -std::unique_ptr -CefBrowserContextProxy::HandleServiceRequest( - const std::string& service_name, - service_manager::mojom::ServiceRequest request) { - return parent_->HandleServiceRequest(service_name, std::move(request)); -} - -PrefService* CefBrowserContextProxy::GetPrefs() { - return parent_->GetPrefs(); -} - -bool CefBrowserContextProxy::AllowsBrowserWindows() const { - return parent_->AllowsBrowserWindows(); -} - -const PrefService* CefBrowserContextProxy::GetPrefs() const { - return parent_->GetPrefs(); -} - -SimpleFactoryKey* CefBrowserContextProxy::GetSimpleFactoryKey() const { - return parent_->GetSimpleFactoryKey(); -} - -CefRequestContextImpl* CefBrowserContextProxy::GetCefRequestContext() const { - return request_context_; -} - -const CefRequestContextSettings& CefBrowserContextProxy::GetSettings() const { - return parent_->GetSettings(); -} - -CefRefPtr CefBrowserContextProxy::GetHandler() const { - return handler_; -} - -HostContentSettingsMap* CefBrowserContextProxy::GetHostContentSettingsMap() { - return parent_->GetHostContentSettingsMap(); -} - -void CefBrowserContextProxy::AddVisitedURLs(const std::vector& urls) { - parent_->AddVisitedURLs(urls); -} - -content::StoragePartition* -CefBrowserContextProxy::GetOrCreateStoragePartitionProxy( - content::StoragePartition* partition_impl) { - CEF_REQUIRE_UIT(); - - if (!storage_partition_proxy_) { - scoped_refptr url_request_getter; - if (!net_service::IsEnabled()) { - url_request_getter = new CefURLRequestContextGetterProxy( - handler_, parent_->request_context_getter()); - } - storage_partition_proxy_.reset( - new CefStoragePartitionProxy(partition_impl, url_request_getter.get())); - - // Associates UserData keys with the ResourceContext. - // Called from StoragePartitionImplMap::Get() for CefBrowserContextImpl. - content::InitializeResourceContext(this); - } - - // There should only be one CefStoragePartitionProxy for this - // CefBrowserContextProxy. - DCHECK_EQ(storage_partition_proxy_->parent(), partition_impl); - return storage_partition_proxy_.get(); -} diff --git a/libcef/browser/browser_context_proxy.h b/libcef/browser/browser_context_proxy.h deleted file mode 100644 index 69dd17f73..000000000 --- a/libcef/browser/browser_context_proxy.h +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_PROXY_H_ -#define CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_PROXY_H_ -#pragma once - -#include "libcef/browser/browser_context.h" -#include "libcef/browser/browser_context_impl.h" - -#include "base/files/file_path.h" -#include "base/memory/ref_counted.h" - -class CefDownloadManagerDelegate; -class CefStoragePartitionProxy; - -// BrowserContext implementation for a particular CefRequestContext. Life span -// is controlled by CefRequestContextImpl. Only accessed on the UI thread. See -// browser_context.h for an object relationship diagram. -class CefBrowserContextProxy : public CefBrowserContext { - public: - CefBrowserContextProxy(CefRequestContextImpl* const request_context, - CefRefPtr handler, - CefBrowserContextImpl* parent); - - // Must be called immediately after this object is created. - void Initialize() override; - - // SupportsUserData methods. - Data* GetUserData(const void* key) const override; - void SetUserData(const void* key, std::unique_ptr data) override; - void RemoveUserData(const void* key) override; - - // BrowserContext methods. - base::FilePath GetPath() const override; - std::unique_ptr CreateZoomLevelDelegate( - const base::FilePath& partition_path) override; - bool IsOffTheRecord() const override; - content::DownloadManagerDelegate* GetDownloadManagerDelegate() override; - content::BrowserPluginGuestManager* GetGuestManager() override; - storage::SpecialStoragePolicy* GetSpecialStoragePolicy() override; - content::PushMessagingService* GetPushMessagingService() override; - content::SSLHostStateDelegate* GetSSLHostStateDelegate() override; - content::ClientHintsControllerDelegate* GetClientHintsControllerDelegate() - override; - content::PermissionControllerDelegate* GetPermissionControllerDelegate() - override; - content::BackgroundFetchDelegate* GetBackgroundFetchDelegate() override; - content::BackgroundSyncController* GetBackgroundSyncController() override; - content::BrowsingDataRemoverDelegate* GetBrowsingDataRemoverDelegate() - override; - net::URLRequestContextGetter* CreateRequestContext( - content::ProtocolHandlerMap* protocol_handlers, - content::URLRequestInterceptorScopedVector request_interceptors) override; - net::URLRequestContextGetter* CreateRequestContextForStoragePartition( - const base::FilePath& partition_path, - bool in_memory, - content::ProtocolHandlerMap* protocol_handlers, - content::URLRequestInterceptorScopedVector request_interceptors) override; - std::unique_ptr HandleServiceRequest( - const std::string& service_name, - service_manager::mojom::ServiceRequest request) override; - - // Profile methods. - PrefService* GetPrefs() override; - bool AllowsBrowserWindows() const override; - const PrefService* GetPrefs() const override; - SimpleFactoryKey* GetSimpleFactoryKey() const override; - - // CefBrowserContext methods. - CefRequestContextImpl* GetCefRequestContext() const override; - const CefRequestContextSettings& GetSettings() const override; - CefRefPtr GetHandler() const override; - HostContentSettingsMap* GetHostContentSettingsMap() override; - void AddVisitedURLs(const std::vector& urls) override; - - content::StoragePartition* GetOrCreateStoragePartitionProxy( - content::StoragePartition* partition_impl); - - CefBrowserContextImpl* parent() const { return parent_; } - - private: - // Allow deletion via std::unique_ptr() only. - friend std::default_delete; - - ~CefBrowserContextProxy() override; - - // Guaranteed to outlive this object. - CefRequestContextImpl* const request_context_; - - // Members initialized during construction are safe to access from any thread. - CefRefPtr handler_; - CefBrowserContextImpl* parent_; // Guaranteed to outlive this object. - - std::unique_ptr download_manager_delegate_; - std::unique_ptr storage_partition_proxy_; - - DISALLOW_COPY_AND_ASSIGN(CefBrowserContextProxy); -}; - -#endif // CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_PROXY_H_ diff --git a/libcef/browser/browser_host_impl.cc b/libcef/browser/browser_host_impl.cc index e21aacf32..2a7e408c7 100644 --- a/libcef/browser/browser_host_impl.cc +++ b/libcef/browser/browser_host_impl.cc @@ -9,7 +9,7 @@ #include #include "libcef/browser/audio_mirror_destination.h" -#include "libcef/browser/browser_context_impl.h" +#include "libcef/browser/browser_context.h" #include "libcef/browser/browser_info.h" #include "libcef/browser/browser_info_manager.h" #include "libcef/browser/browser_platform_delegate.h" @@ -317,7 +317,7 @@ CefRefPtr CefBrowserHostImpl::Create( DCHECK(browser_context); // A StoragePartitionImplMap must already exist for the BrowserContext. See - // additional comments in CefBrowserContextImpl::Initialize(). + // additional comments in CefBrowserContext::Initialize(). DCHECK(browser_context->GetUserData( content::BrowserContext::GetStoragePartitionMapUserDataKey())); @@ -3353,16 +3353,11 @@ void CefBrowserHostImpl::CreateExtensionHost( extensions::ViewType host_type) { DCHECK(!extension_host_); - // Use the *Impl context because ProcessManager expects it for notification - // registration. - CefBrowserContextImpl* impl_context = - CefBrowserContextImpl::GetForContext(browser_context); - if (host_type == extensions::VIEW_TYPE_EXTENSION_DIALOG || host_type == extensions::VIEW_TYPE_EXTENSION_POPUP) { // Create an extension host that we own. extension_host_ = new extensions::CefExtensionViewHost( - this, extension, impl_context, host_contents, url, host_type); + this, extension, browser_context, host_contents, url, host_type); // Trigger load of the extension URL. extension_host_->CreateRenderViewSoon(); } else if (host_type == extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { @@ -3370,7 +3365,7 @@ void CefBrowserHostImpl::CreateExtensionHost( // Create an extension host that will be owned by ProcessManager. extension_host_ = new extensions::CefExtensionBackgroundHost( this, base::BindOnce(&CefBrowserHostImpl::OnExtensionHostDeleted, this), - extension, impl_context, host_contents, url, host_type); + extension, browser_context, host_contents, url, host_type); // Load will be triggered by ProcessManager::CreateBackgroundHost. } else { NOTREACHED() << " Unsupported extension host type: " << host_type; diff --git a/libcef/browser/browser_main.cc b/libcef/browser/browser_main.cc index 7e7d4df46..49041e7af 100644 --- a/libcef/browser/browser_main.cc +++ b/libcef/browser/browser_main.cc @@ -8,7 +8,7 @@ #include -#include "libcef/browser/browser_context_impl.h" +#include "libcef/browser/browser_context.h" #include "libcef/browser/browser_context_keyed_service_factories.h" #include "libcef/browser/content_browser_client.h" #include "libcef/browser/context.h" @@ -198,7 +198,7 @@ void CefBrowserMainParts::PreMainMessageLoopRun() { // Create the global RequestContext. global_request_context_ = CefRequestContextImpl::CreateGlobalRequestContext(settings); - CefBrowserContextImpl* browser_context = static_cast( + CefBrowserContext* browser_context = static_cast( global_request_context_->GetBrowserContext()); PostProfileInit(); diff --git a/libcef/browser/browser_main.h b/libcef/browser/browser_main.h index b845812b9..56c9d95cf 100644 --- a/libcef/browser/browser_main.h +++ b/libcef/browser/browser_main.h @@ -6,7 +6,7 @@ #define CEF_LIBCEF_BROWSER_BROWSER_MAIN_H_ #pragma once -#include "libcef/browser/net/url_request_context_getter_impl.h" +#include "libcef/browser/net/url_request_context_getter.h" #include "libcef/browser/request_context_impl.h" #include "base/macros.h" diff --git a/libcef/browser/chrome_browser_process_stub.cc b/libcef/browser/chrome_browser_process_stub.cc index 6218638bf..d186455ad 100644 --- a/libcef/browser/chrome_browser_process_stub.cc +++ b/libcef/browser/chrome_browser_process_stub.cc @@ -5,7 +5,7 @@ #include "libcef/browser/chrome_browser_process_stub.h" -#include "libcef/browser/browser_context_impl.h" +#include "libcef/browser/browser_context.h" #include "libcef/browser/chrome_profile_manager_stub.h" #include "libcef/browser/prefs/browser_prefs.h" #include "libcef/browser/thread_util.h" @@ -389,7 +389,7 @@ ChromeBrowserProcessStub::pref_service_factory() const { content::BrowserContext* ChromeBrowserProcessStub::GetBrowserContextRedirectedInIncognito( content::BrowserContext* context) { - return CefBrowserContextImpl::GetForContext(context); + return CefBrowserContext::GetForContext(context); } content::BrowserContext* diff --git a/libcef/browser/chrome_profile_manager_stub.cc b/libcef/browser/chrome_profile_manager_stub.cc index 8e476584c..ba3e8cab7 100644 --- a/libcef/browser/chrome_profile_manager_stub.cc +++ b/libcef/browser/chrome_profile_manager_stub.cc @@ -5,7 +5,7 @@ #include "libcef/browser/chrome_profile_manager_stub.h" -#include "libcef/browser/browser_context_impl.h" +#include "libcef/browser/browser_context.h" #include "libcef/browser/content_browser_client.h" namespace { @@ -20,8 +20,8 @@ namespace { // context for the currently active browser (e.g. the browser with input focus). // Return the main context for now since we don't currently have a good way to // determine that. -CefBrowserContextImpl* GetActiveBrowserContext() { - return static_cast( +CefBrowserContext* GetActiveBrowserContext() { + return static_cast( CefContentBrowserClient::Get()->request_context()->GetBrowserContext()); } @@ -34,8 +34,8 @@ ChromeProfileManagerStub::~ChromeProfileManagerStub() {} Profile* ChromeProfileManagerStub::GetProfile( const base::FilePath& profile_dir) { - CefBrowserContextImpl* browser_context = - CefBrowserContextImpl::GetForCachePath(profile_dir); + CefBrowserContext* browser_context = + CefBrowserContext::GetForCachePath(profile_dir); if (!browser_context) { // ProfileManager makes assumptions about profile directory paths that do // not match CEF usage. For example, the default Chrome profile name is @@ -51,7 +51,7 @@ Profile* ChromeProfileManagerStub::GetProfile( bool ChromeProfileManagerStub::IsValidProfile(const void* profile) { if (!profile) return false; - return !!CefBrowserContextImpl::GetForContext( + return !!CefBrowserContext::GetForContext( reinterpret_cast(const_cast(profile))); } diff --git a/libcef/browser/content_browser_client.cc b/libcef/browser/content_browser_client.cc index c97462420..0d7b9a4fd 100644 --- a/libcef/browser/content_browser_client.cc +++ b/libcef/browser/content_browser_client.cc @@ -8,7 +8,7 @@ #include #include "include/cef_version.h" -#include "libcef/browser/browser_context_impl.h" +#include "libcef/browser/browser_context.h" #include "libcef/browser/browser_host_impl.h" #include "libcef/browser/browser_info.h" #include "libcef/browser/browser_info_manager.h" @@ -699,8 +699,8 @@ CefContentBrowserClient::GetExtraServiceManifests() { bool CefContentBrowserClient::IsSameBrowserContext( content::BrowserContext* context1, content::BrowserContext* context2) { - return CefBrowserContextImpl::GetForContext(context1) == - CefBrowserContextImpl::GetForContext(context2); + return CefBrowserContext::GetForContext(context1) == + CefBrowserContext::GetForContext(context2); } void CefContentBrowserClient::AppendExtraCommandLineSwitches( diff --git a/libcef/browser/content_browser_client.h b/libcef/browser/content_browser_client.h index adee97713..c39f02f4c 100644 --- a/libcef/browser/content_browser_client.h +++ b/libcef/browser/content_browser_client.h @@ -10,7 +10,7 @@ #include #include "include/cef_request_context_handler.h" -#include "libcef/browser/net/url_request_context_getter_impl.h" +#include "libcef/browser/net/url_request_context_getter.h" #include "libcef/browser/request_context_impl.h" #include "base/macros.h" diff --git a/libcef/browser/cookie_manager_impl.cc b/libcef/browser/cookie_manager_impl.cc index 8121f8476..78f8eb7cf 100644 --- a/libcef/browser/cookie_manager_impl.cc +++ b/libcef/browser/cookie_manager_impl.cc @@ -10,7 +10,6 @@ #include "libcef/browser/content_browser_client.h" #include "libcef/browser/context.h" -#include "libcef/browser/net/cookie_store_source.h" #include "libcef/browser/net/network_delegate.h" #include "libcef/common/net_service/util.h" #include "libcef/common/task_runner_impl.h" @@ -118,17 +117,9 @@ void SetCookieCallbackImpl(CefRefPtr callback, status == net::CanonicalCookie::CookieInclusionStatus::INCLUDE)); } -net::CookieStore* GetExistingCookieStoreHelper( - base::WeakPtr cookie_manager) { - if (cookie_manager.get()) - return cookie_manager->GetExistingCookieStore(); - return nullptr; -} - } // namespace -CefCookieManagerImpl::CefCookieManagerImpl(bool is_blocking) - : is_blocking_(is_blocking), weak_ptr_factory_(this) {} +CefCookieManagerImpl::CefCookieManagerImpl() : weak_ptr_factory_(this) {} CefCookieManagerImpl::~CefCookieManagerImpl() { CEF_REQUIRE_IOT(); @@ -139,18 +130,14 @@ void CefCookieManagerImpl::Initialize( const CefString& path, bool persist_session_cookies, CefRefPtr callback) { - CHECK(!is_blocking_); - if (request_context.get()) { - request_context_ = request_context; - if (!net_service::IsEnabled()) { - request_context_->GetRequestContextImpl( - base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}), - base::Bind(&CefCookieManagerImpl::InitWithContext, this, callback)); - } else { - RunAsyncCompletionOnIOThread(callback); - } + DCHECK(request_context.get()); + request_context_ = request_context; + if (!net_service::IsEnabled()) { + request_context_->GetRequestContextImpl( + base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}), + base::Bind(&CefCookieManagerImpl::InitWithContext, this, callback)); } else { - SetStoragePath(path, persist_session_cookies, callback); + RunAsyncCompletionOnIOThread(callback); } } @@ -166,48 +153,21 @@ void CefCookieManagerImpl::GetCookieStore( return; } - if (HasContext()) { - RunMethodWithContext( - base::Bind(&CefCookieManagerImpl::GetCookieStoreWithContext, this, - task_runner, callback)); - return; - } - - DCHECK(is_blocking_ || cookie_source_); - - // Binding ref-counted |this| to CookieStoreGetter may result in - // heap-use-after-free if (a) the CookieStoreGetter contains the last - // CefCookieManagerImpl reference and (b) that reference is released during - // execution of a CookieMonster callback (which then results in the - // CookieManager being deleted). Use WeakPtr instead of |this| so that, in - // that case, the CookieStoreGetter will return nullptr instead of keeping - // the CefCookieManagerImpl alive (see issue #1882). - const CookieStoreGetter& cookie_store_getter = - base::Bind(GetExistingCookieStoreHelper, weak_ptr_factory_.GetWeakPtr()); - - if (task_runner->BelongsToCurrentThread()) { - // Execute the callback immediately. - callback.Run(cookie_store_getter); - } else { - // Execute the callback on the target thread. - task_runner->PostTask(FROM_HERE, base::Bind(callback, cookie_store_getter)); - } + RunMethodWithContext( + base::Bind(&CefCookieManagerImpl::GetCookieStoreWithContext, this, + task_runner, callback)); } net::CookieStore* CefCookieManagerImpl::GetExistingCookieStore() { CEF_REQUIRE_IOT(); - if (cookie_source_) { - return cookie_source_->GetCookieStore(); - } else if (request_context_impl_.get()) { + if (request_context_impl_.get()) { net::CookieStore* cookie_store = request_context_impl_->GetExistingCookieStore(); DCHECK(cookie_store); return cookie_store; } - DCHECK(is_blocking_); - if (!is_blocking_) - LOG(ERROR) << "Cookie store does not exist"; + LOG(ERROR) << "Cookie store does not exist"; return nullptr; } @@ -279,40 +239,6 @@ bool CefCookieManagerImpl::DeleteCookies( return true; } -bool CefCookieManagerImpl::SetStoragePath( - const CefString& path, - bool persist_session_cookies, - CefRefPtr callback) { - if (!CEF_CURRENTLY_ON_IOT()) { - CEF_POST_TASK( - CEF_IOT, - base::Bind(base::IgnoreResult(&CefCookieManagerImpl::SetStoragePath), - this, path, persist_session_cookies, callback)); - return true; - } - - if (HasContext()) { - RunMethodWithContext( - base::Bind(&CefCookieManagerImpl::SetStoragePathWithContext, this, path, - persist_session_cookies, callback)); - return true; - } - - base::FilePath new_path; - if (!path.empty()) - new_path = base::FilePath(path); - - if (!cookie_source_) { - cookie_source_.reset(new CefCookieStoreOwnerSource()); - } - - cookie_source_->SetCookieStoragePath(new_path, persist_session_cookies, - g_browser_process->net_log()); - - RunAsyncCompletionOnIOThread(callback); - return true; -} - bool CefCookieManagerImpl::FlushStore( CefRefPtr callback) { GetCookieStore( @@ -393,11 +319,6 @@ void CefCookieManagerImpl::SetCookieMonsterSchemes( cookie_monster->SetCookieableSchemes(all_schemes); } -bool CefCookieManagerImpl::HasContext() { - CEF_REQUIRE_IOT(); - return (request_context_impl_.get() || request_context_.get()); -} - void CefCookieManagerImpl::RunMethodWithContext( const CefRequestContextImpl::RequestContextCallback& method) { CEF_REQUIRE_IOT(); @@ -415,7 +336,7 @@ void CefCookieManagerImpl::RunMethodWithContext( void CefCookieManagerImpl::InitWithContext( CefRefPtr callback, - scoped_refptr request_context) { + scoped_refptr request_context) { CEF_REQUIRE_IOT(); DCHECK(!request_context_impl_.get()); @@ -430,26 +351,10 @@ void CefCookieManagerImpl::InitWithContext( RunAsyncCompletionOnIOThread(callback); } -void CefCookieManagerImpl::SetStoragePathWithContext( - const CefString& path, - bool persist_session_cookies, - CefRefPtr callback, - scoped_refptr request_context) { - CEF_REQUIRE_IOT(); - - base::FilePath new_path; - if (!path.empty()) - new_path = base::FilePath(path); - - request_context->SetCookieStoragePath(new_path, persist_session_cookies); - - RunAsyncCompletionOnIOThread(callback); -} - void CefCookieManagerImpl::SetSupportedSchemesWithContext( const std::vector& schemes, CefRefPtr callback, - scoped_refptr request_context) { + scoped_refptr request_context) { CEF_REQUIRE_IOT(); request_context->SetCookieSupportedSchemes(schemes); @@ -460,12 +365,12 @@ void CefCookieManagerImpl::SetSupportedSchemesWithContext( void CefCookieManagerImpl::GetCookieStoreWithContext( scoped_refptr task_runner, const CookieStoreCallback& callback, - scoped_refptr request_context) { + scoped_refptr request_context) { CEF_REQUIRE_IOT(); DCHECK(request_context->GetExistingCookieStore()); const CookieStoreGetter& cookie_store_getter = base::Bind( - &CefURLRequestContextGetterImpl::GetExistingCookieStore, request_context); + &CefURLRequestContextGetter::GetExistingCookieStore, request_context); if (task_runner->BelongsToCurrentThread()) { // Execute the callback immediately. @@ -481,24 +386,14 @@ void CefCookieManagerImpl::SetSupportedSchemesInternal( CefRefPtr callback) { CEF_REQUIRE_IOT(); - if (HasContext()) { - if (!net_service::IsEnabled()) { - RunMethodWithContext( - base::Bind(&CefCookieManagerImpl::SetSupportedSchemesWithContext, - this, schemes, callback)); - } else { - NOTIMPLEMENTED(); - RunAsyncCompletionOnIOThread(callback); - } - return; + if (!net_service::IsEnabled()) { + RunMethodWithContext( + base::Bind(&CefCookieManagerImpl::SetSupportedSchemesWithContext, this, + schemes, callback)); + } else { + NOTIMPLEMENTED(); + RunAsyncCompletionOnIOThread(callback); } - - DCHECK(is_blocking_ || cookie_source_); - if (cookie_source_) { - cookie_source_->SetCookieSupportedSchemes(schemes); - } - - RunAsyncCompletionOnIOThread(callback); } void CefCookieManagerImpl::VisitAllCookiesInternal( @@ -638,28 +533,5 @@ CefRefPtr CefCookieManager::GetGlobalManager( return NULL; } - return CefRequestContext::GetGlobalContext()->GetDefaultCookieManager( - callback); -} - -// static -CefRefPtr CefCookieManager::GetBlockingManager() { - return new CefCookieManagerImpl(true); -} - -// static -CefRefPtr CefCookieManager::CreateManager( - const CefString& path, - bool persist_session_cookies, - CefRefPtr callback) { - // Verify that the context is in a valid state. - if (!CONTEXT_STATE_VALID()) { - NOTREACHED() << "context not valid"; - return NULL; - } - - CefRefPtr cookie_manager = - new CefCookieManagerImpl(false); - cookie_manager->Initialize(NULL, path, persist_session_cookies, callback); - return cookie_manager.get(); + return CefRequestContext::GetGlobalContext()->GetCookieManager(callback); } diff --git a/libcef/browser/cookie_manager_impl.h b/libcef/browser/cookie_manager_impl.h index 31ffb4c9a..035fc2932 100644 --- a/libcef/browser/cookie_manager_impl.h +++ b/libcef/browser/cookie_manager_impl.h @@ -15,12 +15,10 @@ #include "base/memory/weak_ptr.h" #include "net/cookies/cookie_monster.h" -class CefCookieStoreOwnerSource; - // Implementation of the CefCookieManager interface. class CefCookieManagerImpl : public CefCookieManager { public: - explicit CefCookieManagerImpl(bool is_blocking); + CefCookieManagerImpl(); ~CefCookieManagerImpl() override; // Must be called immediately after this object is created when |is_blocking| @@ -57,9 +55,6 @@ class CefCookieManagerImpl : public CefCookieManager { bool DeleteCookies(const CefString& url, const CefString& cookie_name, CefRefPtr callback) override; - bool SetStoragePath(const CefString& path, - bool persist_session_cookies, - CefRefPtr callback) override; bool FlushStore(CefRefPtr callback) override; static bool GetCefCookie(const net::CanonicalCookie& cc, CefCookie& cookie); @@ -73,29 +68,21 @@ class CefCookieManagerImpl : public CefCookieManager { const std::vector& schemes); private: - // Returns true if a context is or will be available. - bool HasContext(); - // Execute |method| on the IO thread once the request context is available. void RunMethodWithContext( const CefRequestContextImpl::RequestContextCallback& method); void InitWithContext( CefRefPtr callback, - scoped_refptr request_context); - void SetStoragePathWithContext( - const CefString& path, - bool persist_session_cookies, - CefRefPtr callback, - scoped_refptr request_context); + scoped_refptr request_context); void SetSupportedSchemesWithContext( const std::vector& schemes, CefRefPtr callback, - scoped_refptr request_context); + scoped_refptr request_context); void GetCookieStoreWithContext( scoped_refptr task_runner, const CookieStoreCallback& callback, - scoped_refptr request_context); + scoped_refptr request_context); void SetSupportedSchemesInternal(const std::vector& schemes, CefRefPtr callback); @@ -116,15 +103,9 @@ class CefCookieManagerImpl : public CefCookieManager { void FlushStoreInternal(CefRefPtr callback, const CookieStoreGetter& cookie_store_getter); - // If true all cookies will be blocked. - const bool is_blocking_; - - // Used for cookie monsters owned by the context. + // Context that owns the cookie monster. CefRefPtr request_context_; - scoped_refptr request_context_impl_; - - // Used for cookie monsters owned by this object. - std::unique_ptr cookie_source_; + scoped_refptr request_context_impl_; // Must be the last member. base::WeakPtrFactory weak_ptr_factory_; diff --git a/libcef/browser/extensions/browser_extensions_util.cc b/libcef/browser/extensions/browser_extensions_util.cc index f4741b4e2..5a6b93db8 100644 --- a/libcef/browser/extensions/browser_extensions_util.cc +++ b/libcef/browser/extensions/browser_extensions_util.cc @@ -4,7 +4,7 @@ #include "libcef/browser/extensions/browser_extensions_util.h" -#include "libcef/browser/browser_context_impl.h" +#include "libcef/browser/browser_context.h" #include "libcef/browser/browser_info_manager.h" #include "libcef/browser/thread_util.h" #include "libcef/common/extensions/extensions_util.h" @@ -140,8 +140,8 @@ CefRefPtr GetBrowserForTabId( if (tab_id < 0 || !browser_context) return nullptr; - CefBrowserContextImpl* browser_context_impl = - CefBrowserContextImpl::GetForContext(browser_context); + CefBrowserContext* browser_context_impl = + CefBrowserContext::GetForContext(browser_context); CefBrowserInfoManager::BrowserInfoList list; CefBrowserInfoManager::GetInstance()->GetBrowserInfoList(list); @@ -149,7 +149,7 @@ CefRefPtr GetBrowserForTabId( CefRefPtr current_browser = browser_info->browser(); if (current_browser && current_browser->GetIdentifier() == tab_id) { // Make sure we're operating in the same BrowserContextImpl. - if (CefBrowserContextImpl::GetForContext( + if (CefBrowserContext::GetForContext( current_browser->GetBrowserContext()) == browser_context_impl) { return current_browser; } else { diff --git a/libcef/browser/extensions/extension_function_details.cc b/libcef/browser/extensions/extension_function_details.cc index d04576485..2f96587a8 100644 --- a/libcef/browser/extensions/extension_function_details.cc +++ b/libcef/browser/extensions/extension_function_details.cc @@ -4,7 +4,7 @@ #include "libcef/browser/extensions/extension_function_details.h" -#include "libcef/browser/browser_context_impl.h" +#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" @@ -168,9 +168,8 @@ CefRefPtr CefExtensionFunctionDetails::GetCurrentBrowser() static_cast(active_browser.get()); // Make sure we're operating in the same BrowserContextImpl. - if (CefBrowserContextImpl::GetForContext( - browser->GetBrowserContext()) == - CefBrowserContextImpl::GetForContext( + if (CefBrowserContext::GetForContext(browser->GetBrowserContext()) == + CefBrowserContext::GetForContext( active_browser_impl->GetBrowserContext())) { browser = active_browser_impl; } else { @@ -349,8 +348,8 @@ base::DictionaryValue* CefExtensionFunctionDetails::OpenTab( if (params.index.get()) index = *params.index; - CefBrowserContextImpl* browser_context_impl = - CefBrowserContextImpl::GetForContext(active_browser->GetBrowserContext()); + CefBrowserContext* browser_context_impl = + CefBrowserContext::GetForContext(active_browser->GetBrowserContext()); // A CEF representation should always exist. CefRefPtr cef_extension = @@ -361,7 +360,6 @@ base::DictionaryValue* CefExtensionFunctionDetails::OpenTab( return nullptr; // Always use the same request context that the extension was registered with. - // May represent an *Impl or *Proxy BrowserContext. // GetLoaderContext() will return NULL for internal extensions. CefRefPtr request_context = cef_extension->GetLoaderContext(); diff --git a/libcef/browser/extensions/extensions_api_client.cc b/libcef/browser/extensions/extensions_api_client.cc index 0f17020a6..e4831ef49 100644 --- a/libcef/browser/extensions/extensions_api_client.cc +++ b/libcef/browser/extensions/extensions_api_client.cc @@ -6,7 +6,7 @@ #include "libcef/browser/extensions/extensions_api_client.h" #include "include/internal/cef_types_wrappers.h" -#include "libcef/browser/browser_context_impl.h" +#include "libcef/browser/browser_context.h" #include "libcef/browser/extensions/api/storage/sync_value_store_cache.h" #include "libcef/browser/extensions/extension_web_contents_observer.h" #include "libcef/browser/extensions/mime_handler_view_guest_delegate.h" @@ -35,14 +35,9 @@ CefExtensionsAPIClient::CreateGuestViewManagerDelegate( content::BrowserContext* context) const { // The GuestViewManager instance associated with the returned Delegate, which // will be retrieved in the future via GuestViewManager::FromBrowserContext, - // will be associated with the CefBrowserContextImpl instead of |context| due - // to ShouldProxyUserData in browser_context_proxy.cc. Because the - // GuestViewManagerDelegate keeps a reference to the passed-in context we need - // to provide the *Impl object instead of |context| which may be a *Proxy - // object. If we don't do this then the Delegate may attempt to access a - // *Proxy object that has already been deleted. + // will be associated with the CefBrowserContext. return base::WrapUnique(new extensions::ExtensionsGuestViewManagerDelegate( - CefBrowserContextImpl::GetForContext(context))); + CefBrowserContext::GetForContext(context))); } std::unique_ptr diff --git a/libcef/browser/extensions/extensions_browser_client.cc b/libcef/browser/extensions/extensions_browser_client.cc index cba394864..756eb146c 100644 --- a/libcef/browser/extensions/extensions_browser_client.cc +++ b/libcef/browser/extensions/extensions_browser_client.cc @@ -7,7 +7,7 @@ #include -#include "libcef/browser/browser_context_impl.h" +#include "libcef/browser/browser_context.h" #include "libcef/browser/browser_host_impl.h" #include "libcef/browser/extensions/component_extension_resource_manager.h" #include "libcef/browser/extensions/extension_system.h" @@ -65,13 +65,13 @@ bool CefExtensionsBrowserClient::AreExtensionsDisabled( } bool CefExtensionsBrowserClient::IsValidContext(BrowserContext* context) { - return CefBrowserContextImpl::GetForContext(context) != NULL; + return CefBrowserContext::GetForContext(context) != NULL; } bool CefExtensionsBrowserClient::IsSameContext(BrowserContext* first, BrowserContext* second) { // Returns true if |first| and |second| share the same underlying - // CefBrowserContextImpl. + // CefBrowserContext. return GetCefImplContext(first) == GetCefImplContext(second); } @@ -93,7 +93,7 @@ BrowserContext* CefExtensionsBrowserClient::GetOriginalContext( BrowserContext* CefExtensionsBrowserClient::GetCefImplContext( BrowserContext* context) { - return CefBrowserContextImpl::GetForContext(context); + return CefBrowserContext::GetForContext(context); } bool CefExtensionsBrowserClient::IsGuestSession(BrowserContext* context) const { @@ -196,10 +196,8 @@ bool CefExtensionsBrowserClient::CreateBackgroundExtensionHost( content::BrowserContext* browser_context, const GURL& url, ExtensionHost** host) { - // The BrowserContext referenced by ProcessManager should always be an *Impl. - DCHECK(!static_cast(browser_context)->is_proxy()); - CefBrowserContextImpl* browser_context_impl = - CefBrowserContextImpl::GetForContext(browser_context); + CefBrowserContext* browser_context_impl = + CefBrowserContext::GetForContext(browser_context); // A CEF representation should always exist. CefRefPtr cef_extension = @@ -211,7 +209,6 @@ bool CefExtensionsBrowserClient::CreateBackgroundExtensionHost( } // Always use the same request context that the extension was registered with. - // May represent an *Impl or *Proxy BrowserContext. // GetLoaderContext() will return NULL for internal extensions. CefRefPtr request_context = cef_extension->GetLoaderContext(); diff --git a/libcef/browser/net/cookie_store_proxy.cc b/libcef/browser/net/cookie_store_proxy.cc deleted file mode 100644 index 6891a2ad7..000000000 --- a/libcef/browser/net/cookie_store_proxy.cc +++ /dev/null @@ -1,182 +0,0 @@ -// Copyright (c) 2015 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/net/cookie_store_proxy.h" - -#include "include/cef_request_context.h" -#include "libcef/browser/net/cookie_store_source.h" -#include "libcef/browser/thread_util.h" - -#include "base/logging.h" -#include "net/cookies/cookie_change_dispatcher.h" - -namespace { - -class NullCookieChangeDispatcher : public net::CookieChangeDispatcher { - public: - NullCookieChangeDispatcher() {} - ~NullCookieChangeDispatcher() override {} - - // net::CookieChangeDispatcher - std::unique_ptr AddCallbackForCookie( - const GURL& url, - const std::string& name, - net::CookieChangeCallback callback) override { - return nullptr; - } - - std::unique_ptr AddCallbackForUrl( - const GURL& url, - net::CookieChangeCallback callback) override { - return nullptr; - } - - std::unique_ptr AddCallbackForAllChanges( - net::CookieChangeCallback callback) override { - return nullptr; - } - - private: - DISALLOW_COPY_AND_ASSIGN(NullCookieChangeDispatcher); -}; - -} // namespace - -CefCookieStoreProxy::CefCookieStoreProxy( - std::unique_ptr source) - : source_(std::move(source)) { - CEF_REQUIRE_IOT(); - DCHECK(source_); -} - -CefCookieStoreProxy::~CefCookieStoreProxy() { - CEF_REQUIRE_IOT(); -} - -void CefCookieStoreProxy::SetCookieWithOptionsAsync( - const GURL& url, - const std::string& cookie_line, - const net::CookieOptions& options, - SetCookiesCallback callback) { - net::CookieStore* cookie_store = GetCookieStore(); - if (cookie_store) { - cookie_store->SetCookieWithOptionsAsync(url, cookie_line, options, - std::move(callback)); - } else if (!callback.is_null()) { - std::move(callback).Run( - net::CanonicalCookie::CookieInclusionStatus::EXCLUDE_FAILURE_TO_STORE); - } -} - -void CefCookieStoreProxy::SetCanonicalCookieAsync( - std::unique_ptr cookie, - std::string source_scheme, - bool modify_http_only, - SetCookiesCallback callback) { - net::CookieStore* cookie_store = GetCookieStore(); - if (cookie_store) { - cookie_store->SetCanonicalCookieAsync(std::move(cookie), source_scheme, - modify_http_only, - std::move(callback)); - } else if (!callback.is_null()) { - std::move(callback).Run( - net::CanonicalCookie::CookieInclusionStatus::EXCLUDE_FAILURE_TO_STORE); - } -} - -void CefCookieStoreProxy::GetCookieListWithOptionsAsync( - const GURL& url, - const net::CookieOptions& options, - GetCookieListCallback callback) { - net::CookieStore* cookie_store = GetCookieStore(); - if (cookie_store) { - cookie_store->GetCookieListWithOptionsAsync(url, options, - std::move(callback)); - } else if (!callback.is_null()) { - std::move(callback).Run(net::CookieList(), net::CookieStatusList()); - } -} - -void CefCookieStoreProxy::GetAllCookiesAsync(GetCookieListCallback callback) { - net::CookieStore* cookie_store = GetCookieStore(); - if (cookie_store) { - cookie_store->GetAllCookiesAsync(std::move(callback)); - } else if (!callback.is_null()) { - std::move(callback).Run(net::CookieList(), net::CookieStatusList()); - } -} - -void CefCookieStoreProxy::DeleteCanonicalCookieAsync( - const net::CanonicalCookie& cookie, - DeleteCallback callback) { - net::CookieStore* cookie_store = GetCookieStore(); - if (cookie_store) { - cookie_store->DeleteCanonicalCookieAsync(cookie, std::move(callback)); - } else if (!callback.is_null()) { - std::move(callback).Run(0); - } -} - -void CefCookieStoreProxy::DeleteAllCreatedInTimeRangeAsync( - const net::CookieDeletionInfo::TimeRange& creation_range, - DeleteCallback callback) { - net::CookieStore* cookie_store = GetCookieStore(); - if (cookie_store) { - cookie_store->DeleteAllCreatedInTimeRangeAsync(creation_range, - std::move(callback)); - } else if (!callback.is_null()) { - std::move(callback).Run(0); - } -} - -void CefCookieStoreProxy::DeleteAllMatchingInfoAsync( - net::CookieDeletionInfo delete_info, - DeleteCallback callback) { - net::CookieStore* cookie_store = GetCookieStore(); - if (cookie_store) { - cookie_store->DeleteAllMatchingInfoAsync(delete_info, std::move(callback)); - } else if (!callback.is_null()) { - std::move(callback).Run(0); - } -} - -void CefCookieStoreProxy::DeleteSessionCookiesAsync(DeleteCallback callback) { - net::CookieStore* cookie_store = GetCookieStore(); - if (cookie_store) { - cookie_store->DeleteSessionCookiesAsync(std::move(callback)); - } else if (!callback.is_null()) { - std::move(callback).Run(0); - } -} - -void CefCookieStoreProxy::FlushStore(base::OnceClosure callback) { - net::CookieStore* cookie_store = GetCookieStore(); - if (cookie_store) { - cookie_store->FlushStore(std::move(callback)); - } else if (!callback.is_null()) { - std::move(callback).Run(); - } -} - -net::CookieChangeDispatcher& CefCookieStoreProxy::GetChangeDispatcher() { - net::CookieStore* cookie_store = GetCookieStore(); - if (cookie_store) - return cookie_store->GetChangeDispatcher(); - - if (!null_dispatcher_) - null_dispatcher_.reset(new NullCookieChangeDispatcher()); - return *null_dispatcher_; -} - -bool CefCookieStoreProxy::IsEphemeral() { - net::CookieStore* cookie_store = GetCookieStore(); - if (cookie_store) - return cookie_store->IsEphemeral(); - return true; -} - -net::CookieStore* CefCookieStoreProxy::GetCookieStore() { - CEF_REQUIRE_IOT(); - return source_->GetCookieStore(); -} diff --git a/libcef/browser/net/cookie_store_proxy.h b/libcef/browser/net/cookie_store_proxy.h deleted file mode 100644 index 5fbb6bba0..000000000 --- a/libcef/browser/net/cookie_store_proxy.h +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) 2015 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_COOKIE_STORE_PROXY_H_ -#define CEF_LIBCEF_BROWSER_COOKIE_STORE_PROXY_H_ -#pragma once - -#include "net/cookies/cookie_store.h" - -class CefCookieStoreSource; - -// Proxies cookie requests to a CefCookieStoreSource (see comments on the -// implementation classes for details). Only accessed on the IO thread. -class CefCookieStoreProxy : public net::CookieStore { - public: - explicit CefCookieStoreProxy(std::unique_ptr source); - ~CefCookieStoreProxy() override; - - // net::CookieStore methods. - void SetCookieWithOptionsAsync(const GURL& url, - const std::string& cookie_line, - const net::CookieOptions& options, - SetCookiesCallback callback) override; - void SetCanonicalCookieAsync(std::unique_ptr cookie, - std::string source_scheme, - bool modify_http_only, - SetCookiesCallback callback) override; - void GetCookieListWithOptionsAsync(const GURL& url, - const net::CookieOptions& options, - GetCookieListCallback callback) override; - void GetAllCookiesAsync(GetCookieListCallback callback) override; - void DeleteCanonicalCookieAsync(const net::CanonicalCookie& cookie, - DeleteCallback callback) override; - void DeleteAllCreatedInTimeRangeAsync( - const net::CookieDeletionInfo::TimeRange& creation_range, - DeleteCallback callback) override; - void DeleteAllMatchingInfoAsync(net::CookieDeletionInfo delete_info, - DeleteCallback callback) override; - void DeleteSessionCookiesAsync(DeleteCallback callback) override; - void FlushStore(base::OnceClosure callback) override; - net::CookieChangeDispatcher& GetChangeDispatcher() override; - bool IsEphemeral() override; - - private: - net::CookieStore* GetCookieStore(); - - std::unique_ptr const source_; - std::unique_ptr null_dispatcher_; - - DISALLOW_COPY_AND_ASSIGN(CefCookieStoreProxy); -}; - -#endif // CEF_LIBCEF_BROWSER_COOKIE_STORE_PROXY_H_ diff --git a/libcef/browser/net/cookie_store_source.cc b/libcef/browser/net/cookie_store_source.cc deleted file mode 100644 index 887758859..000000000 --- a/libcef/browser/net/cookie_store_source.cc +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright (c) 2018 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/net/cookie_store_source.h" - -#include "libcef/browser/content_browser_client.h" -#include "libcef/browser/cookie_manager_impl.h" -#include "libcef/browser/net/url_request_context_impl.h" -#include "libcef/browser/thread_util.h" - -#include "base/files/file_util.h" -#include "base/logging.h" -#include "net/extras/sqlite/sqlite_persistent_cookie_store.h" - -CefCookieStoreHandlerSource::CefCookieStoreHandlerSource( - CefURLRequestContextImpl* parent, - CefRefPtr handler) - : parent_(parent), handler_(handler) { - DCHECK(parent_); - DCHECK(handler_); -} - -net::CookieStore* CefCookieStoreHandlerSource::GetCookieStore() { - CEF_REQUIRE_IOT(); - - CefRefPtr manager = handler_->GetCookieManager(); - if (manager) { - // Use the cookie store provided by the manager. May be nullptr if the - // cookie manager is blocking. - return reinterpret_cast(manager.get()) - ->GetExistingCookieStore(); - } - - DCHECK(parent_); - if (parent_) { - // Use the cookie store from the parent. - net::CookieStore* cookie_store = parent_->cookie_store(); - DCHECK(cookie_store); - if (!cookie_store) - LOG(ERROR) << "Cookie store does not exist"; - return cookie_store; - } - - return nullptr; -} - -CefCookieStoreOwnerSource::CefCookieStoreOwnerSource() {} - -void CefCookieStoreOwnerSource::SetCookieStoragePath( - const base::FilePath& path, - bool persist_session_cookies, - net::NetLog* net_log) { - CEF_REQUIRE_IOT(); - - if (cookie_store_ && ((path_.empty() && path.empty()) || path_ == path)) { - // The path has not changed so don't do anything. - return; - } - - scoped_refptr persistent_store; - if (!path.empty()) { - // TODO(cef): Move directory creation to the blocking pool instead of - // allowing file IO on this thread. - base::ThreadRestrictions::ScopedAllowIO allow_io; - if (base::DirectoryExists(path) || base::CreateDirectory(path)) { - const base::FilePath& cookie_path = path.AppendASCII("Cookies"); - persistent_store = new net::SQLitePersistentCookieStore( - cookie_path, - base::CreateSingleThreadTaskRunnerWithTraits( - {content::BrowserThread::IO}), - // Intentionally using the background task runner exposed by CEF to - // facilitate unit test expectations. This task runner MUST be - // configured with BLOCK_SHUTDOWN. - CefContentBrowserClient::Get()->background_task_runner(), - persist_session_cookies, NULL); - } else { - NOTREACHED() << "The cookie storage directory could not be created"; - } - } - - // Set the new cookie store that will be used for all new requests. The old - // cookie store, if any, will be automatically flushed and closed when no - // longer referenced. - std::unique_ptr cookie_monster( - new net::CookieMonster(persistent_store.get(), nullptr, net_log)); - if (persistent_store.get() && persist_session_cookies) - cookie_monster->SetPersistSessionCookies(true); - path_ = path; - - // Restore the previously supported schemes. - CefCookieManagerImpl::SetCookieMonsterSchemes(cookie_monster.get(), - supported_schemes_); - - cookie_store_ = std::move(cookie_monster); -} - -void CefCookieStoreOwnerSource::SetCookieSupportedSchemes( - const std::vector& schemes) { - CEF_REQUIRE_IOT(); - - supported_schemes_ = schemes; - CefCookieManagerImpl::SetCookieMonsterSchemes( - static_cast(cookie_store_.get()), - supported_schemes_); -} - -net::CookieStore* CefCookieStoreOwnerSource::GetCookieStore() { - CEF_REQUIRE_IOT(); - return cookie_store_.get(); -} diff --git a/libcef/browser/net/cookie_store_source.h b/libcef/browser/net/cookie_store_source.h deleted file mode 100644 index a094b5c2c..000000000 --- a/libcef/browser/net/cookie_store_source.h +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) 2018 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_COOKIE_STORE_SOURCE_H_ -#define CEF_LIBCEF_BROWSER_COOKIE_STORE_SOURCE_H_ -#pragma once - -#include -#include -#include - -#include "include/cef_request_context_handler.h" - -#include "base/macros.h" - -namespace base { -class FilePath; -} - -namespace net { -class CookieStore; -class NetLog; -} // namespace net - -class CefURLRequestContextImpl; - -// Abstract base class for CookieStore sources. Only accessed on the IO thread. -class CefCookieStoreSource { - public: - virtual net::CookieStore* GetCookieStore() = 0; - virtual ~CefCookieStoreSource() {} -}; - -// Sources a cookie store that is created/owned by a CefCookieManager or the -// parent context. Life span is controlled by CefURLRequestContextProxy. See -// browser_context.h for an object relationship diagram. -class CefCookieStoreHandlerSource : public CefCookieStoreSource { - public: - CefCookieStoreHandlerSource(CefURLRequestContextImpl* parent, - CefRefPtr handler); - - net::CookieStore* GetCookieStore() override; - - private: - // The |parent_| pointer is kept alive by CefURLRequestContextGetterProxy - // which has a ref to the owning CefURLRequestContextGetterImpl. - CefURLRequestContextImpl* parent_; - CefRefPtr handler_; - - DISALLOW_COPY_AND_ASSIGN(CefCookieStoreHandlerSource); -}; - -// Sources a cookie store that is created/owned by this object. Life span is -// controlled by the owning URLRequestContext. -class CefCookieStoreOwnerSource : public CefCookieStoreSource { - public: - CefCookieStoreOwnerSource(); - - void SetCookieStoragePath(const base::FilePath& path, - bool persist_session_cookies, - net::NetLog* net_log); - void SetCookieSupportedSchemes(const std::vector& schemes); - - net::CookieStore* GetCookieStore() override; - - private: - std::unique_ptr cookie_store_; - base::FilePath path_; - std::vector supported_schemes_; - - DISALLOW_COPY_AND_ASSIGN(CefCookieStoreOwnerSource); -}; - -#endif // CEF_LIBCEF_BROWSER_COOKIE_STORE_SOURCE_H_ diff --git a/libcef/browser/net/network_delegate.h b/libcef/browser/net/network_delegate.h index 4f2741c0d..a3ec25d94 100644 --- a/libcef/browser/net/network_delegate.h +++ b/libcef/browser/net/network_delegate.h @@ -51,7 +51,7 @@ class CefNetworkDelegate : public net::NetworkDelegateImpl { const base::FilePath& original_path, const base::FilePath& absolute_path) const override; - // Weak, owned by our owner (CefURLRequestContextGetterImpl). + // Weak, owned by our owner (CefURLRequestContextGetter). BooleanPrefMember* force_google_safesearch_; DISALLOW_COPY_AND_ASSIGN(CefNetworkDelegate); diff --git a/libcef/browser/net/url_request_context_getter_impl.cc b/libcef/browser/net/url_request_context_getter.cc similarity index 84% rename from libcef/browser/net/url_request_context_getter_impl.cc rename to libcef/browser/net/url_request_context_getter.cc index 07b9e1776..eec3f0b93 100644 --- a/libcef/browser/net/url_request_context_getter_impl.cc +++ b/libcef/browser/net/url_request_context_getter.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "libcef/browser/net/url_request_context_getter_impl.h" +#include "libcef/browser/net/url_request_context_getter.h" #include #include @@ -10,8 +10,6 @@ #include "libcef/browser/content_browser_client.h" #include "libcef/browser/cookie_manager_impl.h" -#include "libcef/browser/net/cookie_store_proxy.h" -#include "libcef/browser/net/cookie_store_source.h" #include "libcef/browser/net/network_delegate.h" #include "libcef/browser/net/scheme_handler.h" #include "libcef/browser/net/url_request_interceptor.h" @@ -20,6 +18,7 @@ #include "libcef/common/content_client.h" #include "base/command_line.h" +#include "base/files/file_util.h" #include "base/logging.h" #include "base/memory/ptr_util.h" #include "base/stl_util.h" @@ -45,6 +44,7 @@ #include "net/cert/multi_log_ct_verifier.h" #include "net/cookies/cookie_monster.h" #include "net/dns/host_resolver.h" +#include "net/extras/sqlite/sqlite_persistent_cookie_store.h" #include "net/ftp/ftp_network_layer.h" #include "net/http/http_auth_handler_factory.h" #include "net/http/http_auth_preferences.h" @@ -179,7 +179,7 @@ CreateLogVerifiersForKnownLogs() { } // namespace -CefURLRequestContextGetterImpl::CefURLRequestContextGetterImpl( +CefURLRequestContextGetter::CefURLRequestContextGetter( const CefRequestContextSettings& settings, PrefService* pref_service, scoped_refptr io_task_runner, @@ -220,26 +220,25 @@ CefURLRequestContextGetterImpl::CefURLRequestContextGetterImpl( auth_server_whitelist_.Init( prefs::kAuthServerWhitelist, pref_service, - base::Bind(&CefURLRequestContextGetterImpl::UpdateServerWhitelist, + base::Bind(&CefURLRequestContextGetter::UpdateServerWhitelist, base::Unretained(this))); auth_server_whitelist_.MoveToThread(io_thread_proxy); auth_negotiate_delegate_whitelist_.Init( prefs::kAuthNegotiateDelegateWhitelist, pref_service, - base::Bind(&CefURLRequestContextGetterImpl::UpdateDelegateWhitelist, + base::Bind(&CefURLRequestContextGetter::UpdateDelegateWhitelist, base::Unretained(this))); auth_negotiate_delegate_whitelist_.MoveToThread(io_thread_proxy); } -CefURLRequestContextGetterImpl::~CefURLRequestContextGetterImpl() { +CefURLRequestContextGetter::~CefURLRequestContextGetter() { CEF_REQUIRE_IOT(); // This destructor may not be called during shutdown. Perform any required // shutdown in ShutdownOnIOThread() instead. } // static -void CefURLRequestContextGetterImpl::RegisterPrefs( - PrefRegistrySimple* registry) { +void CefURLRequestContextGetter::RegisterPrefs(PrefRegistrySimple* registry) { // Based on IOThread::RegisterPrefs. #if defined(OS_POSIX) && !defined(OS_ANDROID) registry->RegisterStringPref(prefs::kGSSAPILibraryName, std::string()); @@ -255,7 +254,7 @@ void CefURLRequestContextGetterImpl::RegisterPrefs( registry->RegisterStringPref(prefs::kAuthNegotiateDelegateWhitelist, ""); } -void CefURLRequestContextGetterImpl::ShutdownOnUIThread() { +void CefURLRequestContextGetter::ShutdownOnUIThread() { CEF_REQUIRE_UIT(); quick_check_enabled_.Destroy(); pac_https_url_stripping_enabled_.Destroy(); @@ -265,10 +264,10 @@ void CefURLRequestContextGetterImpl::ShutdownOnUIThread() { CEF_POST_TASK( CEF_IOT, - base::Bind(&CefURLRequestContextGetterImpl::ShutdownOnIOThread, this)); + base::Bind(&CefURLRequestContextGetter::ShutdownOnIOThread, this)); } -void CefURLRequestContextGetterImpl::ShutdownOnIOThread() { +void CefURLRequestContextGetter::ShutdownOnIOThread() { CEF_REQUIRE_IOT(); shutting_down_ = true; @@ -282,7 +281,7 @@ void CefURLRequestContextGetterImpl::ShutdownOnIOThread() { NotifyContextShuttingDown(); } -net::URLRequestContext* CefURLRequestContextGetterImpl::GetURLRequestContext() { +net::URLRequestContext* CefURLRequestContextGetter::GetURLRequestContext() { CEF_REQUIRE_IOT(); if (shutting_down_) @@ -296,7 +295,7 @@ net::URLRequestContext* CefURLRequestContextGetterImpl::GetURLRequestContext() { if (settings_.cache_path.length > 0) cache_path = base::FilePath(CefString(&settings_.cache_path)); - io_state_->url_request_context_.reset(new CefURLRequestContextImpl()); + io_state_->url_request_context_.reset(new CefURLRequestContext()); io_state_->url_request_context_->set_net_log(io_state_->net_log_); io_state_->url_request_context_->set_enable_brotli(true); @@ -472,63 +471,95 @@ net::URLRequestContext* CefURLRequestContextGetterImpl::GetURLRequestContext() { } scoped_refptr -CefURLRequestContextGetterImpl::GetNetworkTaskRunner() const { +CefURLRequestContextGetter::GetNetworkTaskRunner() const { return base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}); } -net::HostResolver* CefURLRequestContextGetterImpl::GetHostResolver() const { +net::HostResolver* CefURLRequestContextGetter::GetHostResolver() const { return io_state_->url_request_context_->host_resolver(); } -void CefURLRequestContextGetterImpl::SetCookieStoragePath( - const base::FilePath& path, - bool persist_session_cookies) { - CEF_REQUIRE_IOT(); - if (!io_state_->cookie_source_) { - // Use a proxy because we can't change the URLRequestContext's CookieStore - // during runtime. - io_state_->cookie_source_ = new CefCookieStoreOwnerSource(); - io_state_->storage_->set_cookie_store(std::make_unique( - base::WrapUnique(io_state_->cookie_source_))); - } - io_state_->cookie_source_->SetCookieStoragePath(path, persist_session_cookies, - io_state_->net_log_); -} - -void CefURLRequestContextGetterImpl::SetCookieSupportedSchemes( +void CefURLRequestContextGetter::SetCookieSupportedSchemes( const std::vector& schemes) { CEF_REQUIRE_IOT(); - io_state_->cookie_source_->SetCookieSupportedSchemes(schemes); + + io_state_->cookie_supported_schemes_ = schemes; + CefCookieManagerImpl::SetCookieMonsterSchemes( + static_cast(GetExistingCookieStore()), + io_state_->cookie_supported_schemes_); } -void CefURLRequestContextGetterImpl::AddHandler( +void CefURLRequestContextGetter::AddHandler( CefRefPtr handler) { if (!CEF_CURRENTLY_ON_IOT()) { - CEF_POST_TASK( - CEF_IOT, - base::Bind(&CefURLRequestContextGetterImpl::AddHandler, this, handler)); + CEF_POST_TASK(CEF_IOT, base::Bind(&CefURLRequestContextGetter::AddHandler, + this, handler)); return; } io_state_->handler_list_.push_back(handler); } -net::CookieStore* CefURLRequestContextGetterImpl::GetExistingCookieStore() - const { +net::CookieStore* CefURLRequestContextGetter::GetExistingCookieStore() const { CEF_REQUIRE_IOT(); - if (io_state_->cookie_source_) { - return io_state_->cookie_source_->GetCookieStore(); + if (io_state_->url_request_context_ && + io_state_->url_request_context_->cookie_store()) { + return io_state_->url_request_context_->cookie_store(); } LOG(ERROR) << "Cookie store does not exist"; return nullptr; } -void CefURLRequestContextGetterImpl::UpdateServerWhitelist() { +void CefURLRequestContextGetter::SetCookieStoragePath( + const base::FilePath& path, + bool persist_session_cookies) { + CEF_REQUIRE_IOT(); + + // The cookie store can't be changed during runtime. + DCHECK(!io_state_->url_request_context_->cookie_store()); + + scoped_refptr persistent_store; + if (!path.empty()) { + // TODO(cef): Move directory creation to the blocking pool instead of + // allowing file IO on this thread. + base::ThreadRestrictions::ScopedAllowIO allow_io; + if (base::DirectoryExists(path) || base::CreateDirectory(path)) { + const base::FilePath& cookie_path = path.AppendASCII("Cookies"); + persistent_store = new net::SQLitePersistentCookieStore( + cookie_path, + base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}), + // Intentionally using the background task runner exposed by CEF to + // facilitate unit test expectations. This task runner MUST be + // configured with BLOCK_SHUTDOWN. + CefContentBrowserClient::Get()->background_task_runner(), + persist_session_cookies, NULL); + } else { + NOTREACHED() << "The cookie storage directory could not be created"; + } + } + + // Set the new cookie store that will be used for all new requests. The old + // cookie store, if any, will be automatically flushed and closed when no + // longer referenced. + std::unique_ptr cookie_monster(new net::CookieMonster( + persistent_store.get(), nullptr, io_state_->net_log_)); + if (persistent_store.get() && persist_session_cookies) + cookie_monster->SetPersistSessionCookies(true); + io_state_->cookie_store_path_ = path; + + // Restore the previously supported schemes. + CefCookieManagerImpl::SetCookieMonsterSchemes( + cookie_monster.get(), io_state_->cookie_supported_schemes_); + + io_state_->storage_->set_cookie_store(std::move(cookie_monster)); +} + +void CefURLRequestContextGetter::UpdateServerWhitelist() { io_state_->http_auth_preferences_->SetServerWhitelist( auth_server_whitelist_.GetValue()); } -void CefURLRequestContextGetterImpl::UpdateDelegateWhitelist() { +void CefURLRequestContextGetter::UpdateDelegateWhitelist() { io_state_->http_auth_preferences_->SetDelegateWhitelist( auth_negotiate_delegate_whitelist_.GetValue()); } diff --git a/libcef/browser/net/url_request_context_getter.h b/libcef/browser/net/url_request_context_getter.h index 0ad28ca4c..7f6673aea 100644 --- a/libcef/browser/net/url_request_context_getter.h +++ b/libcef/browser/net/url_request_context_getter.h @@ -1,30 +1,138 @@ -// Copyright (c) 2015 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_GETTER_H_ -#define CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_GETTER_H_ +#ifndef CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_GETTER_IMPL_H_ +#define CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_GETTER_IMPL_H_ #pragma once -#include "net/url_request/url_request_context_getter.h" +#include +#include -namespace net { -class HostResolver; +#include "include/internal/cef_types_wrappers.h" +#include "libcef/browser/net/url_request_context.h" +#include "libcef/browser/net/url_request_manager.h" + +#include "base/compiler_specific.h" +#include "base/files/file_path.h" +#include "base/memory/ref_counted.h" +#include "chrome/browser/net/chrome_mojo_proxy_resolver_factory.h" +#include "components/prefs/pref_member.h" +#include "content/public/browser/browser_context.h" +#include "net/url_request/url_request_context_getter.h" +#include "net/url_request/url_request_job_factory.h" + +class PrefRegistrySimple; +class PrefService; + +namespace base { +class MessageLoop; } -// Responsible for creating and owning the URLRequestContext and all network- -// related functionality. Life span is primarily controlled by -// CefResourceContext*. See browser_context.h for an object relationship -// diagram. +namespace net { +class CookieMonster; +class FtpTransactionFactory; +class HttpAuthPreferences; +class ProxyConfigService; +class URLRequestContextStorage; +class URLRequestJobFactory; +class URLRequestJobFactoryImpl; +} // namespace net + +// Isolated URLRequestContextGetter implementation. Life span is primarily +// controlled by CefResourceContext and (for the global context) +// CefBrowserMainParts. Created on the UI thread but accessed and destroyed on +// the IO thread. See browser_context.h for an object relationship diagram. class CefURLRequestContextGetter : public net::URLRequestContextGetter { public: - CefURLRequestContextGetter() {} + CefURLRequestContextGetter( + const CefRequestContextSettings& settings, + PrefService* pref_service, + scoped_refptr io_task_runner, + content::ProtocolHandlerMap* protocol_handlers, + std::unique_ptr proxy_config_service, + content::URLRequestInterceptorScopedVector request_interceptors); + ~CefURLRequestContextGetter() override; - // Called from CefResourceContext::GetHostResolver(). - virtual net::HostResolver* GetHostResolver() const = 0; + // Register preferences. Called from browser_prefs::CreatePrefService(). + static void RegisterPrefs(PrefRegistrySimple* registry); + + // Called when the BrowserContextImpl is destroyed. + void ShutdownOnUIThread(); + + // net::URLRequestContextGetter implementation. + net::URLRequestContext* GetURLRequestContext() override; + scoped_refptr GetNetworkTaskRunner() + const override; + + // CefURLRequestContextGetter implementation. + net::HostResolver* GetHostResolver() const; + + void SetCookieSupportedSchemes(const std::vector& schemes); + + // Keep a reference to all handlers sharing this context so that they'll be + // kept alive until the context is destroyed. + void AddHandler(CefRefPtr handler); + + // Returns the existing cookie store object. Logs an error if the cookie + // store does not yet exist. Must be called on the IO thread. + net::CookieStore* GetExistingCookieStore() const; + + CefURLRequestManager* request_manager() const { + return io_state_->url_request_manager_.get(); + } private: + void SetCookieStoragePath(const base::FilePath& path, + bool persist_session_cookies); + + void UpdateServerWhitelist(); + void UpdateDelegateWhitelist(); + + void ShutdownOnIOThread(); + + const CefRequestContextSettings settings_; + + bool shutting_down_ = false; + + // State that is only accessed on the IO thread and will be reset in + // ShutdownOnIOThread(). + struct IOState { + net::NetLog* net_log_ = nullptr; // Guaranteed to outlive this object. + + scoped_refptr io_task_runner_; + +#if defined(OS_POSIX) && !defined(OS_ANDROID) + std::string gsapi_library_name_; +#endif + + std::unique_ptr proxy_config_service_; + std::unique_ptr storage_; + std::unique_ptr http_auth_preferences_; + std::unique_ptr url_request_context_; + std::unique_ptr url_request_manager_; + content::ProtocolHandlerMap protocol_handlers_; + content::URLRequestInterceptorScopedVector request_interceptors_; + + base::FilePath cookie_store_path_; + std::vector cookie_supported_schemes_; + + std::vector> handler_list_; + + proxy_resolver::mojom::ProxyResolverFactoryPtr proxy_resolver_factory_; + }; + std::unique_ptr io_state_; + + BooleanPrefMember quick_check_enabled_; + BooleanPrefMember pac_https_url_stripping_enabled_; + + // Member variables which are pointed to by the various context objects. + mutable BooleanPrefMember force_google_safesearch_; + + StringPrefMember auth_server_whitelist_; + StringPrefMember auth_negotiate_delegate_whitelist_; + DISALLOW_COPY_AND_ASSIGN(CefURLRequestContextGetter); }; -#endif // CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_GETTER_H_ +#endif // CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_GETTER_IMPL_H_ diff --git a/libcef/browser/net/url_request_context_getter_impl.h b/libcef/browser/net/url_request_context_getter_impl.h deleted file mode 100644 index 038d494e5..000000000 --- a/libcef/browser/net/url_request_context_getter_impl.h +++ /dev/null @@ -1,138 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_GETTER_IMPL_H_ -#define CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_GETTER_IMPL_H_ -#pragma once - -#include -#include - -#include "include/internal/cef_types_wrappers.h" -#include "libcef/browser/net/url_request_context_getter.h" -#include "libcef/browser/net/url_request_context_impl.h" -#include "libcef/browser/net/url_request_manager.h" - -#include "base/compiler_specific.h" -#include "base/files/file_path.h" -#include "base/memory/ref_counted.h" -#include "chrome/browser/net/chrome_mojo_proxy_resolver_factory.h" -#include "components/prefs/pref_member.h" -#include "content/public/browser/browser_context.h" -#include "net/url_request/url_request_job_factory.h" - -class CefCookieStoreOwnerSource; -class PrefRegistrySimple; -class PrefService; - -namespace base { -class MessageLoop; -} - -namespace net { -class CookieMonster; -class FtpTransactionFactory; -class HttpAuthPreferences; -class ProxyConfigService; -class URLRequestContextStorage; -class URLRequestJobFactory; -class URLRequestJobFactoryImpl; -} // namespace net - -// Isolated URLRequestContextGetter implementation. Life span is primarily -// controlled by CefResourceContext and (for the global context) -// CefBrowserMainParts. Created on the UI thread but accessed and destroyed on -// the IO thread. See browser_context.h for an object relationship diagram. -class CefURLRequestContextGetterImpl : public CefURLRequestContextGetter { - public: - CefURLRequestContextGetterImpl( - const CefRequestContextSettings& settings, - PrefService* pref_service, - scoped_refptr io_task_runner, - content::ProtocolHandlerMap* protocol_handlers, - std::unique_ptr proxy_config_service, - content::URLRequestInterceptorScopedVector request_interceptors); - ~CefURLRequestContextGetterImpl() override; - - // Register preferences. Called from browser_prefs::CreatePrefService(). - static void RegisterPrefs(PrefRegistrySimple* registry); - - // Called when the BrowserContextImpl is destroyed. - void ShutdownOnUIThread(); - - // net::URLRequestContextGetter implementation. - net::URLRequestContext* GetURLRequestContext() override; - scoped_refptr GetNetworkTaskRunner() - const override; - - // CefURLRequestContextGetter implementation. - net::HostResolver* GetHostResolver() const override; - - void SetCookieStoragePath(const base::FilePath& path, - bool persist_session_cookies); - void SetCookieSupportedSchemes(const std::vector& schemes); - - // Keep a reference to all handlers sharing this context so that they'll be - // kept alive until the context is destroyed. - void AddHandler(CefRefPtr handler); - - // Returns the existing cookie store object. Logs an error if the cookie - // store does not yet exist. Must be called on the IO thread. - net::CookieStore* GetExistingCookieStore() const; - - CefURLRequestManager* request_manager() const { - return io_state_->url_request_manager_.get(); - } - - private: - void UpdateServerWhitelist(); - void UpdateDelegateWhitelist(); - - void ShutdownOnIOThread(); - - const CefRequestContextSettings settings_; - - bool shutting_down_ = false; - - // State that is only accessed on the IO thread and will be reset in - // ShutdownOnIOThread(). - struct IOState { - net::NetLog* net_log_ = nullptr; // Guaranteed to outlive this object. - - scoped_refptr io_task_runner_; - -#if defined(OS_POSIX) && !defined(OS_ANDROID) - std::string gsapi_library_name_; -#endif - - std::unique_ptr proxy_config_service_; - std::unique_ptr storage_; - std::unique_ptr http_auth_preferences_; - std::unique_ptr url_request_context_; - std::unique_ptr url_request_manager_; - content::ProtocolHandlerMap protocol_handlers_; - content::URLRequestInterceptorScopedVector request_interceptors_; - - // Owned by the URLRequestContextStorage. - CefCookieStoreOwnerSource* cookie_source_ = nullptr; - - std::vector> handler_list_; - - proxy_resolver::mojom::ProxyResolverFactoryPtr proxy_resolver_factory_; - }; - std::unique_ptr io_state_; - - BooleanPrefMember quick_check_enabled_; - BooleanPrefMember pac_https_url_stripping_enabled_; - - // Member variables which are pointed to by the various context objects. - mutable BooleanPrefMember force_google_safesearch_; - - StringPrefMember auth_server_whitelist_; - StringPrefMember auth_negotiate_delegate_whitelist_; - - DISALLOW_COPY_AND_ASSIGN(CefURLRequestContextGetterImpl); -}; - -#endif // CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_GETTER_IMPL_H_ diff --git a/libcef/browser/net/url_request_context_getter_proxy.cc b/libcef/browser/net/url_request_context_getter_proxy.cc deleted file mode 100644 index de4c2607c..000000000 --- a/libcef/browser/net/url_request_context_getter_proxy.cc +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights -// reserved. Use of this source code is governed by a BSD-style license that can -// be found in the LICENSE file. - -#include "libcef/browser/net/url_request_context_getter_proxy.h" - -#include "libcef/browser/net/url_request_context_getter.h" -#include "libcef/browser/net/url_request_context_proxy.h" -#include "libcef/browser/thread_util.h" - -CefURLRequestContextGetterProxy::CefURLRequestContextGetterProxy( - CefRefPtr handler, - scoped_refptr parent) - : handler_(handler), parent_(parent) { - DCHECK(handler_.get()); - DCHECK(parent_.get()); -} - -CefURLRequestContextGetterProxy::~CefURLRequestContextGetterProxy() { - CEF_REQUIRE_IOT(); -} - -void CefURLRequestContextGetterProxy::ShutdownOnUIThread() { - CEF_REQUIRE_UIT(); - CEF_POST_TASK( - CEF_IOT, - base::Bind(&CefURLRequestContextGetterProxy::ShutdownOnIOThread, this)); -} - -void CefURLRequestContextGetterProxy::ShutdownOnIOThread() { - CEF_REQUIRE_IOT(); - shutting_down_ = true; - context_proxy_.reset(); - NotifyContextShuttingDown(); -} - -net::URLRequestContext* -CefURLRequestContextGetterProxy::GetURLRequestContext() { - CEF_REQUIRE_IOT(); - - if (shutting_down_) - return nullptr; - - if (!context_proxy_) { - context_proxy_.reset(new CefURLRequestContextProxy( - static_cast(parent_->GetURLRequestContext()), - handler_)); - } - return context_proxy_.get(); -} - -scoped_refptr -CefURLRequestContextGetterProxy::GetNetworkTaskRunner() const { - return parent_->GetNetworkTaskRunner(); -} - -net::HostResolver* CefURLRequestContextGetterProxy::GetHostResolver() const { - return parent_->GetHostResolver(); -} diff --git a/libcef/browser/net/url_request_context_getter_proxy.h b/libcef/browser/net/url_request_context_getter_proxy.h deleted file mode 100644 index 1d5600268..000000000 --- a/libcef/browser/net/url_request_context_getter_proxy.h +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights -// reserved. Use of this source code is governed by a BSD-style license that can -// be found in the LICENSE file. - -#ifndef CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_GETTER_PROXY_H_ -#define CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_GETTER_PROXY_H_ -#pragma once - -#include "include/cef_request_context.h" -#include "include/cef_request_context_handler.h" -#include "libcef/browser/net/url_request_context_getter.h" -#include "libcef/browser/net/url_request_context_getter_impl.h" - -class CefURLRequestContextProxy; - -// URLRequestContextGetter implementation for a particular CefRequestContext. -// Life span is primarily controlled by CefResourceContext. Created on the UI -// thread but accessed and destroyed on the IO thread. See browser_context.h for -// an object relationship diagram. -class CefURLRequestContextGetterProxy : public CefURLRequestContextGetter { - public: - CefURLRequestContextGetterProxy( - CefRefPtr handler, - scoped_refptr parent); - ~CefURLRequestContextGetterProxy() override; - - // Called when the StoragePartitionProxy is destroyed. - void ShutdownOnUIThread(); - - // net::URLRequestContextGetter implementation. - net::URLRequestContext* GetURLRequestContext() override; - scoped_refptr GetNetworkTaskRunner() - const override; - - // CefURLRequestContextGetter implementation. - net::HostResolver* GetHostResolver() const override; - - CefRefPtr handler() const { return handler_; } - - private: - void ShutdownOnIOThread(); - - CefRefPtr handler_; - - // The CefURLRequestContextImpl owned by |parent_| is passed as a raw pointer - // to CefURLRequestContextProxy and CefCookieStoreProxy. This reference is - // necessary to keep it alive. - scoped_refptr parent_; - - std::unique_ptr context_proxy_; - - bool shutting_down_ = false; - - DISALLOW_COPY_AND_ASSIGN(CefURLRequestContextGetterProxy); -}; - -#endif // CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_GETTER_PROXY_H_ diff --git a/libcef/browser/net/url_request_context_impl.h b/libcef/browser/net/url_request_context_impl.h deleted file mode 100644 index 3bb97cecd..000000000 --- a/libcef/browser/net/url_request_context_impl.h +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights -// reserved. Use of this source code is governed by a BSD-style license that can -// be found in the LICENSE file. - -#ifndef CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_IMPL_H_ -#define CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_IMPL_H_ -#pragma once - -#include "libcef/browser/net/url_request_context.h" - -// Isolated URLRequestContext implementation. Life span is controlled by -// CefURLRequestContextGetterImpl. Only accessed on the IO thread. See -// browser_context.h for an object relationship diagram. -class CefURLRequestContextImpl : public CefURLRequestContext { - public: - CefURLRequestContextImpl() {} - - private: - DISALLOW_COPY_AND_ASSIGN(CefURLRequestContextImpl); -}; - -#endif // CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_IMPL_H_ diff --git a/libcef/browser/net/url_request_context_proxy.cc b/libcef/browser/net/url_request_context_proxy.cc deleted file mode 100644 index 93731f013..000000000 --- a/libcef/browser/net/url_request_context_proxy.cc +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights -// reserved. Use of this source code is governed by a BSD-style license that can -// be found in the LICENSE file. - -#include "libcef/browser/net/url_request_context_proxy.h" - -#include "libcef/browser/net/cookie_store_proxy.h" -#include "libcef/browser/net/cookie_store_source.h" -#include "libcef/browser/net/url_request_context_impl.h" -#include "libcef/browser/thread_util.h" - -CefURLRequestContextProxy::CefURLRequestContextProxy( - CefURLRequestContextImpl* parent, - CefRefPtr handler) { - CEF_REQUIRE_IOT(); - DCHECK(parent); - DCHECK(handler.get()); - - // Cookie store that proxies to the browser implementation. - cookie_store_proxy_.reset(new CefCookieStoreProxy( - std::make_unique(parent, handler))); - set_cookie_store(cookie_store_proxy_.get()); - - // All other values refer to the parent request context. - set_net_log(parent->net_log()); - set_enable_brotli(parent->enable_brotli()); - set_host_resolver(parent->host_resolver()); - set_cert_verifier(parent->cert_verifier()); - set_transport_security_state(parent->transport_security_state()); - set_cert_transparency_verifier(parent->cert_transparency_verifier()); - set_ct_policy_enforcer(parent->ct_policy_enforcer()); - set_channel_id_service(parent->channel_id_service()); - set_proxy_resolution_service(parent->proxy_resolution_service()); - set_ssl_config_service(parent->ssl_config_service()); - set_http_auth_handler_factory(parent->http_auth_handler_factory()); - set_http_transaction_factory(parent->http_transaction_factory()); - set_network_delegate(parent->network_delegate()); - set_http_server_properties(parent->http_server_properties()); - set_transport_security_state(parent->transport_security_state()); - set_http_user_agent_settings(const_cast( - parent->http_user_agent_settings())); - set_job_factory(parent->job_factory()); -} - -CefURLRequestContextProxy::~CefURLRequestContextProxy() { - CEF_REQUIRE_IOT(); -} diff --git a/libcef/browser/net/url_request_context_proxy.h b/libcef/browser/net/url_request_context_proxy.h deleted file mode 100644 index 7bd480865..000000000 --- a/libcef/browser/net/url_request_context_proxy.h +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights -// reserved. Use of this source code is governed by a BSD-style license that can -// be found in the LICENSE file. - -#ifndef CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_PROXY_H_ -#define CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_PROXY_H_ -#pragma once - -#include "include/cef_request_context.h" -#include "include/cef_request_context_handler.h" -#include "libcef/browser/net/url_request_context.h" - -class CefBrowserHostImpl; -class CefCookieStoreProxy; -class CefURLRequestContextImpl; - -// URLRequestContext implementation for a particular CefRequestContext. Life -// span is controlled by CefURLRequestContextGetterProxy. Only accessed on the -// IO thread. See browser_context.h for an object relationship diagram. -class CefURLRequestContextProxy : public CefURLRequestContext { - public: - // The |parent| pointer is kept alive by CefURLRequestContextGetterProxy - // which has a ref to the owning CefURLRequestContextGetterImpl. It is - // guaranteed to outlive this object. - CefURLRequestContextProxy(CefURLRequestContextImpl* parent, - CefRefPtr handler); - ~CefURLRequestContextProxy() override; - - private: - std::unique_ptr cookie_store_proxy_; - - DISALLOW_COPY_AND_ASSIGN(CefURLRequestContextProxy); -}; - -#endif // CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_PROXY_H_ diff --git a/libcef/browser/net/url_request_manager.h b/libcef/browser/net/url_request_manager.h index f4717ec01..f6278f94e 100644 --- a/libcef/browser/net/url_request_manager.h +++ b/libcef/browser/net/url_request_manager.h @@ -15,7 +15,7 @@ class NetworkDelegate; class URLRequest; class URLRequestJob; class URLRequestJobFactoryImpl; -} +} // namespace net class CefProtocolHandler; @@ -66,7 +66,7 @@ class CefURLRequestManager { const std::string& scheme); // Life span of |job_factory_| is guaranteed by - // CefURLRequestContextGetterImpl which also owns this object. + // CefURLRequestContextGetter which also owns this object. net::URLRequestJobFactoryImpl* job_factory_; // Map (scheme, domain) to factories. diff --git a/libcef/browser/prefs/browser_prefs.cc b/libcef/browser/prefs/browser_prefs.cc index 08335c421..0217137f5 100644 --- a/libcef/browser/prefs/browser_prefs.cc +++ b/libcef/browser/prefs/browser_prefs.cc @@ -5,7 +5,7 @@ #include "libcef/browser/prefs/browser_prefs.h" #include "libcef/browser/media_capture_devices_dispatcher.h" -#include "libcef/browser/net/url_request_context_getter_impl.h" +#include "libcef/browser/net/url_request_context_getter.h" #include "libcef/browser/prefs/pref_store.h" #include "libcef/browser/prefs/renderer_prefs.h" #include "libcef/common/cef_switches.h" @@ -153,7 +153,7 @@ std::unique_ptr CreatePrefService(Profile* profile, update_client::RegisterPrefs(registry.get()); if (!command_line->HasSwitch(switches::kEnableNetworkService)) { - CefURLRequestContextGetterImpl::RegisterPrefs(registry.get()); + CefURLRequestContextGetter::RegisterPrefs(registry.get()); } else if (!profile) { SystemNetworkContextManager::RegisterPrefs(registry.get()); } diff --git a/libcef/browser/request_context_impl.cc b/libcef/browser/request_context_impl.cc index bf6a0440a..4c442c5ab 100644 --- a/libcef/browser/request_context_impl.cc +++ b/libcef/browser/request_context_impl.cc @@ -3,8 +3,7 @@ // can be found in the LICENSE file. #include "libcef/browser/request_context_impl.h" -#include "libcef/browser/browser_context_impl.h" -#include "libcef/browser/browser_context_proxy.h" +#include "libcef/browser/browser_context.h" #include "libcef/browser/content_browser_client.h" #include "libcef/browser/context.h" #include "libcef/browser/cookie_manager_impl.h" @@ -140,14 +139,10 @@ CefRefPtr CefRequestContext::CreateContext( CefRequestContextImpl::~CefRequestContextImpl() { CEF_REQUIRE_UIT(); - // Delete the proxy first because it also references |browser_context_impl_|. - if (browser_context_proxy_) - browser_context_proxy_.reset(nullptr); - - if (browser_context_impl_) { - // May result in |browser_context_impl_| being deleted if no other + if (browser_context_) { + // May result in |browser_context_| being deleted if no other // CefRequestContextImpl are referencing it. - browser_context_impl_->RemoveCefRequestContext(this); + browser_context_->RemoveCefRequestContext(this); } } @@ -198,7 +193,7 @@ void CefRequestContextImpl::GetRequestContextImpl( DCHECK(!net_service::IsEnabled()); if (!task_runner.get()) task_runner = CefTaskRunnerImpl::GetCurrentTaskRunner(); - if (request_context_getter_impl_) { + if (request_context_getter_) { // The browser context already exists. DCHECK(browser_context()); GetRequestContextImplOnIOThread(task_runner, callback, browser_context()); @@ -223,15 +218,6 @@ bool CefRequestContextImpl::IsSame(CefRefPtr other) { // Compare CefBrowserContext pointers if one has been associated. if (browser_context() && other_impl->browser_context()) { - if (browser_context()->is_proxy() && - other_impl->browser_context()->is_proxy()) { - CefBrowserContextProxy* proxy = - static_cast(browser_context()); - CefBrowserContextProxy* other_proxy = - static_cast(other_impl->browser_context()); - return (proxy->parent() == other_proxy->parent() && - proxy->GetHandler() == other_proxy->GetHandler()); - } return (browser_context() == other_impl->browser_context()); } else if (browser_context() || other_impl->browser_context()) { return false; @@ -264,11 +250,9 @@ bool CefRequestContextImpl::IsSharingWith(CefRefPtr other) { return pending_other->IsSharingWith(this); } - if (request_context_getter_impl_ && - other_impl->request_context_getter_impl_) { + if (request_context_getter_ && other_impl->request_context_getter_) { // Both objects are initialized. Compare the request context objects. - return (request_context_getter_impl_ == - other_impl->request_context_getter_impl_); + return (request_context_getter_ == other_impl->request_context_getter_); } // This or the other object is not initialized. Compare the cache path values. @@ -295,10 +279,9 @@ CefString CefRequestContextImpl::GetCachePath() { return CefString(&config_.settings.cache_path); } -CefRefPtr CefRequestContextImpl::GetDefaultCookieManager( +CefRefPtr CefRequestContextImpl::GetCookieManager( CefRefPtr callback) { - CefRefPtr cookie_manager = - new CefCookieManagerImpl(false); + CefRefPtr cookie_manager = new CefCookieManagerImpl(); cookie_manager->Initialize(this, CefString(), false, callback); return cookie_manager.get(); } @@ -580,65 +563,54 @@ CefRequestContextImpl::CefRequestContextImpl( void CefRequestContextImpl::Initialize() { CEF_REQUIRE_UIT(); - DCHECK(!browser_context_impl_); - DCHECK(!request_context_getter_impl_); + DCHECK(!browser_context_); + DCHECK(!request_context_getter_); if (config_.other) { // Share storage with |config_.other|. - browser_context_impl_ = CefBrowserContextImpl::GetForContext( - config_.other->GetBrowserContext()); + browser_context_ = + CefBrowserContext::GetForContext(config_.other->GetBrowserContext()); } - if (!browser_context_impl_) { + if (!browser_context_) { const base::FilePath& cache_path = base::FilePath(CefString(&config_.settings.cache_path)); if (!cache_path.empty()) { - // Check if a CefBrowserContextImpl is already globally registered for + // Check if a CefBrowserContext is already globally registered for // the specified cache path. If so then use it. - browser_context_impl_ = - CefBrowserContextImpl::GetForCachePath(cache_path); + browser_context_ = CefBrowserContext::GetForCachePath(cache_path); } } - if (!browser_context_impl_) { - // Create a new CefBrowserContextImpl instance. If the cache path is non- + if (!browser_context_) { + // Create a new CefBrowserContext instance. If the cache path is non- // empty then this new instance will become the globally registered - // CefBrowserContextImpl for that path. Otherwise, this new instance will + // CefBrowserContext for that path. Otherwise, this new instance will // be a completely isolated "incongento mode" context. - browser_context_impl_ = new CefBrowserContextImpl(config_.settings); - browser_context_impl_->Initialize(); + browser_context_ = new CefBrowserContext(config_.settings); + browser_context_->Initialize(); } - // We'll disassociate from |browser_context_impl_| on destruction. - browser_context_impl_->AddCefRequestContext(this); + // We'll disassociate from |browser_context_| on destruction. + browser_context_->AddCefRequestContext(this); - // Force our settings to match |browser_context_impl_|. - config_.settings = browser_context_impl_->GetSettings(); - - if (config_.handler.get()) { - // Use a proxy that will execute handler callbacks where appropriate and - // otherwise forward all requests to |browser_context_impl_|. - browser_context_proxy_.reset(new CefBrowserContextProxy( - this, config_.handler, browser_context_impl_)); - browser_context_proxy_->Initialize(); - DCHECK(!config_.is_global); - } + // Force our settings to match |browser_context_|. + config_.settings = browser_context_->GetSettings(); if (!net_service::IsEnabled()) { - request_context_getter_impl_ = - browser_context_impl_->request_context_getter().get(); - DCHECK(request_context_getter_impl_); + request_context_getter_ = browser_context_->request_context_getter().get(); + DCHECK(request_context_getter_); if (config_.handler.get()) { // Keep the handler alive until the associated request context is // destroyed. - request_context_getter_impl_->AddHandler(config_.handler); + request_context_getter_->AddHandler(config_.handler); } } if (config_.other) { // Clear the reference to |config_.other| after setting - // |request_context_getter_impl_|. This is the reverse order of checks in + // |request_context_getter_|. This is the reverse order of checks in // IsSharedWith(). config_.other = NULL; } @@ -652,7 +624,7 @@ void CefRequestContextImpl::EnsureBrowserContext() { if (!browser_context()) Initialize(); DCHECK(browser_context()); - DCHECK(net_service::IsEnabled() || request_context_getter_impl_); + DCHECK(net_service::IsEnabled() || request_context_getter_); } void CefRequestContextImpl::GetBrowserContextOnUIThread( @@ -690,19 +662,19 @@ void CefRequestContextImpl::GetRequestContextImplOnIOThread( } DCHECK(!net_service::IsEnabled()); - DCHECK(request_context_getter_impl_); + DCHECK(request_context_getter_); // Make sure the request context exists. - request_context_getter_impl_->GetURLRequestContext(); + request_context_getter_->GetURLRequestContext(); if (task_runner->BelongsToCurrentThread()) { // Execute the callback immediately. - callback.Run(request_context_getter_impl_); + callback.Run(request_context_getter_); } else { // Execute the callback on the target thread. task_runner->PostTask( - FROM_HERE, base::Bind(callback, base::WrapRefCounted( - request_context_getter_impl_))); + FROM_HERE, + base::Bind(callback, base::WrapRefCounted(request_context_getter_))); } } @@ -710,14 +682,14 @@ void CefRequestContextImpl::RegisterSchemeHandlerFactoryInternal( const CefString& scheme_name, const CefString& domain_name, CefRefPtr factory, - scoped_refptr request_context) { + scoped_refptr request_context) { CEF_REQUIRE_IOT(); request_context->request_manager()->AddFactory(scheme_name, domain_name, factory); } void CefRequestContextImpl::ClearSchemeHandlerFactoriesInternal( - scoped_refptr request_context) { + scoped_refptr request_context) { CEF_REQUIRE_IOT(); request_context->request_manager()->ClearFactories(); } @@ -749,7 +721,7 @@ void CefRequestContextImpl::ClearCertificateExceptionsInternal( void CefRequestContextImpl::CloseAllConnectionsInternal( CefRefPtr callback, - scoped_refptr request_context) { + scoped_refptr request_context) { CEF_REQUIRE_IOT(); net::URLRequestContext* url_context = request_context->GetURLRequestContext(); @@ -772,7 +744,7 @@ void CefRequestContextImpl::CloseAllConnectionsInternal( void CefRequestContextImpl::ResolveHostInternal( const CefString& origin, CefRefPtr callback, - scoped_refptr request_context) { + scoped_refptr request_context) { CEF_REQUIRE_IOT(); int retval = ERR_FAILED; @@ -797,7 +769,5 @@ void CefRequestContextImpl::ResolveHostInternal( } CefBrowserContext* CefRequestContextImpl::browser_context() const { - if (browser_context_proxy_) - return browser_context_proxy_.get(); - return browser_context_impl_; + return browser_context_; } diff --git a/libcef/browser/request_context_impl.h b/libcef/browser/request_context_impl.h index 0d07103d3..08163bfdc 100644 --- a/libcef/browser/request_context_impl.h +++ b/libcef/browser/request_context_impl.h @@ -10,8 +10,7 @@ #include "libcef/browser/browser_context.h" #include "libcef/browser/thread_util.h" -class CefBrowserContextImpl; -class CefBrowserContextProxy; +class CefBrowserContext; // Implementation of the CefRequestContext interface. All methods are thread- // safe unless otherwise indicated. Will be deleted on the UI thread. @@ -45,7 +44,7 @@ class CefRequestContextImpl : public CefRequestContext { // context object when it's available. If |task_runner| is NULL the callback // will be executed on the originating thread. The resulting context object // can only be accessed on the IO thread. - typedef base::Callback)> + typedef base::Callback)> RequestContextCallback; void GetRequestContextImpl( scoped_refptr task_runner, @@ -56,7 +55,7 @@ class CefRequestContextImpl : public CefRequestContext { bool IsGlobal() override; CefRefPtr GetHandler() override; CefString GetCachePath() override; - CefRefPtr GetDefaultCookieManager( + CefRefPtr GetCookieManager( CefRefPtr callback) override; bool RegisterSchemeHandlerFactory( const CefString& scheme_name, @@ -101,8 +100,7 @@ class CefRequestContextImpl : public CefRequestContext { CefRequestContextSettings settings; CefRefPtr other; - // Optionally use this handler, in which case a CefBrowserContextProxy will - // be created. + // Optionally use this handler. CefRefPtr handler; // Used to uniquely identify CefRequestContext objects before an associated @@ -133,9 +131,9 @@ class CefRequestContextImpl : public CefRequestContext { const CefString& scheme_name, const CefString& domain_name, CefRefPtr factory, - scoped_refptr request_context); + scoped_refptr request_context); void ClearSchemeHandlerFactoriesInternal( - scoped_refptr request_context); + scoped_refptr request_context); void PurgePluginListCacheInternal(bool reload_pages, CefBrowserContext* browser_context); void ClearCertificateExceptionsInternal( @@ -143,23 +141,21 @@ class CefRequestContextImpl : public CefRequestContext { CefBrowserContext* browser_context); void CloseAllConnectionsInternal( CefRefPtr callback, - scoped_refptr request_context); + scoped_refptr request_context); void ResolveHostInternal( const CefString& origin, CefRefPtr callback, - scoped_refptr request_context); + scoped_refptr request_context); CefBrowserContext* browser_context() const; - // If *Impl then we must disassociate from it on destruction. - CefBrowserContextImpl* browser_context_impl_ = nullptr; - // If *Proxy then we own it. - std::unique_ptr browser_context_proxy_; + // We must disassociate from this on destruction. + CefBrowserContext* browser_context_ = nullptr; Config config_; // Owned by the CefBrowserContext. - CefURLRequestContextGetterImpl* request_context_getter_impl_ = nullptr; + CefURLRequestContextGetter* request_context_getter_ = nullptr; IMPLEMENT_REFCOUNTING_DELETE_ON_UIT(CefRequestContextImpl); DISALLOW_COPY_AND_ASSIGN(CefRequestContextImpl); diff --git a/libcef/browser/resource_context.cc b/libcef/browser/resource_context.cc index f97d06601..0e5f57a3f 100644 --- a/libcef/browser/resource_context.cc +++ b/libcef/browser/resource_context.cc @@ -23,49 +23,13 @@ #include "net/ssl/client_cert_store_mac.h" #endif -namespace { - -bool ShouldProxyUserData(const void* key) { - // If this value is not proxied WebUI will fail to load. - if (key == content::GetURLDataManagerBackendUserDataKey()) - return true; - - return false; -} - -} // namespace - CefResourceContext::CefResourceContext( bool is_off_the_record, CefRefPtr handler) - : parent_(nullptr), - is_off_the_record_(is_off_the_record), - handler_(handler) {} + : is_off_the_record_(is_off_the_record), handler_(handler) {} CefResourceContext::~CefResourceContext() {} -base::SupportsUserData::Data* CefResourceContext::GetUserData( - const void* key) const { - if (parent_ && ShouldProxyUserData(key)) - return parent_->GetUserData(key); - return content::ResourceContext::GetUserData(key); -} - -void CefResourceContext::SetUserData(const void* key, - std::unique_ptr data) { - if (parent_ && ShouldProxyUserData(key)) - parent_->SetUserData(key, std::move(data)); - else - content::ResourceContext::SetUserData(key, std::move(data)); -} - -void CefResourceContext::RemoveUserData(const void* key) { - if (parent_ && ShouldProxyUserData(key)) - parent_->RemoveUserData(key); - else - content::ResourceContext::RemoveUserData(key); -} - std::unique_ptr CefResourceContext::CreateClientCertStore() { #if defined(USE_NSS_CERTS) @@ -91,12 +55,6 @@ void CefResourceContext::set_extensions_info_map( extension_info_map_ = extensions_info_map; } -void CefResourceContext::set_parent(CefResourceContext* parent) { - DCHECK(!parent_); - DCHECK(parent); - parent_ = parent; -} - void CefResourceContext::AddPluginLoadDecision( int render_process_id, const base::FilePath& plugin_path, diff --git a/libcef/browser/resource_context.h b/libcef/browser/resource_context.h index 2f57de34f..2f045d947 100644 --- a/libcef/browser/resource_context.h +++ b/libcef/browser/resource_context.h @@ -32,15 +32,9 @@ class CefResourceContext : public content::ResourceContext { CefRefPtr handler); ~CefResourceContext() override; - // SupportsUserData implementation. - Data* GetUserData(const void* key) const override; - void SetUserData(const void* key, std::unique_ptr data) override; - void RemoveUserData(const void* key) override; - std::unique_ptr CreateClientCertStore(); void set_extensions_info_map(extensions::InfoMap* extensions_info_map); - void set_parent(CefResourceContext* parent); // Remember the plugin load decision for plugin status requests that arrive // via CefPluginServiceFilter::IsPluginAvailable. @@ -67,11 +61,6 @@ class CefResourceContext : public content::ResourceContext { CefRefPtr GetHandler() const { return handler_; } private: - // Non-NULL when this object is owned by a CefBrowserContextProxy. |parent_| - // is guaranteed to outlive this object because CefBrowserContextProxy has a - // refptr to the CefBrowserContextImpl that owns |parent_|. - CefResourceContext* parent_; - // Only accessed on the IO thread. bool is_off_the_record_; scoped_refptr extension_info_map_; diff --git a/libcef/browser/storage_partition_proxy.cc b/libcef/browser/storage_partition_proxy.cc deleted file mode 100644 index 7e32abc45..000000000 --- a/libcef/browser/storage_partition_proxy.cc +++ /dev/null @@ -1,264 +0,0 @@ -// Copyright (c) 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "libcef/browser/storage_partition_proxy.h" - -#include "libcef/common/net_service/util.h" - -#include "base/logging.h" -#include "services/network/public/mojom/cookie_manager.mojom.h" - -CefStoragePartitionProxy::CefStoragePartitionProxy( - content::StoragePartition* parent, - CefURLRequestContextGetterProxy* url_request_context) - : parent_(parent), url_request_context_(url_request_context) { - DCHECK(net_service::IsEnabled() || url_request_context_); -} - -CefStoragePartitionProxy::~CefStoragePartitionProxy() { - if (url_request_context_) - url_request_context_->ShutdownOnUIThread(); -} - -base::FilePath CefStoragePartitionProxy::GetPath() { - return parent_->GetPath(); -} - -net::URLRequestContextGetter* CefStoragePartitionProxy::GetURLRequestContext() { - return url_request_context_.get(); -} - -net::URLRequestContextGetter* -CefStoragePartitionProxy::GetMediaURLRequestContext() { - return GetURLRequestContext(); -} - -network::mojom::NetworkContext* CefStoragePartitionProxy::GetNetworkContext() { - return parent_->GetNetworkContext(); -} - -scoped_refptr -CefStoragePartitionProxy::GetURLLoaderFactoryForBrowserProcess() { - return parent_->GetURLLoaderFactoryForBrowserProcess(); -} - -std::unique_ptr -CefStoragePartitionProxy::GetURLLoaderFactoryForBrowserProcessIOThread() { - return parent_->GetURLLoaderFactoryForBrowserProcessIOThread(); -} - -network::mojom::CookieManager* -CefStoragePartitionProxy::GetCookieManagerForBrowserProcess() { - return parent_->GetCookieManagerForBrowserProcess(); -} - -storage::QuotaManager* CefStoragePartitionProxy::GetQuotaManager() { - return parent_->GetQuotaManager(); -} - -content::AppCacheService* CefStoragePartitionProxy::GetAppCacheService() { - return parent_->GetAppCacheService(); -} - -storage::FileSystemContext* CefStoragePartitionProxy::GetFileSystemContext() { - return parent_->GetFileSystemContext(); -} - -storage::DatabaseTracker* CefStoragePartitionProxy::GetDatabaseTracker() { - return parent_->GetDatabaseTracker(); -} - -content::DOMStorageContext* CefStoragePartitionProxy::GetDOMStorageContext() { - return parent_->GetDOMStorageContext(); -} - -content::IdleManager* CefStoragePartitionProxy::GetIdleManager() { - return parent_->GetIdleManager(); -} - -content::LockManager* CefStoragePartitionProxy::GetLockManager() { - return parent_->GetLockManager(); -} - -content::IndexedDBContext* CefStoragePartitionProxy::GetIndexedDBContext() { - return parent_->GetIndexedDBContext(); -} - -content::ServiceWorkerContext* -CefStoragePartitionProxy::GetServiceWorkerContext() { - return parent_->GetServiceWorkerContext(); -} - -content::SharedWorkerService* -CefStoragePartitionProxy::GetSharedWorkerService() { - return parent_->GetSharedWorkerService(); -} - -content::CacheStorageContext* -CefStoragePartitionProxy::GetCacheStorageContext() { - return parent_->GetCacheStorageContext(); -} - -content::GeneratedCodeCacheContext* -CefStoragePartitionProxy::GetGeneratedCodeCacheContext() { - return parent_->GetGeneratedCodeCacheContext(); -} - -content::HostZoomMap* CefStoragePartitionProxy::GetHostZoomMap() { - return parent_->GetHostZoomMap(); -} - -content::HostZoomLevelContext* -CefStoragePartitionProxy::GetHostZoomLevelContext() { - return parent_->GetHostZoomLevelContext(); -} - -content::ZoomLevelDelegate* CefStoragePartitionProxy::GetZoomLevelDelegate() { - return parent_->GetZoomLevelDelegate(); -} - -content::PlatformNotificationContext* -CefStoragePartitionProxy::GetPlatformNotificationContext() { - return parent_->GetPlatformNotificationContext(); -} - -void CefStoragePartitionProxy::ClearDataForOrigin( - uint32_t remove_mask, - uint32_t quota_storage_remove_mask, - const GURL& storage_origin) { - parent_->ClearDataForOrigin(remove_mask, quota_storage_remove_mask, - storage_origin); -} - -void CefStoragePartitionProxy::ClearData(uint32_t remove_mask, - uint32_t quota_storage_remove_mask, - const GURL& storage_origin, - const base::Time begin, - const base::Time end, - base::OnceClosure callback) { - parent_->ClearData(remove_mask, quota_storage_remove_mask, storage_origin, - begin, end, std::move(callback)); -} - -void CefStoragePartitionProxy::ClearData( - uint32_t remove_mask, - uint32_t quota_storage_remove_mask, - const OriginMatcherFunction& origin_matcher, - network::mojom::CookieDeletionFilterPtr cookie_deletion_filter, - bool perform_cleanup, - const base::Time begin, - const base::Time end, - base::OnceClosure callback) { - parent_->ClearData(remove_mask, quota_storage_remove_mask, origin_matcher, - std::move(cookie_deletion_filter), perform_cleanup, begin, - end, std::move(callback)); -} - -void CefStoragePartitionProxy::ClearHttpAndMediaCaches( - const base::Time begin, - const base::Time end, - const base::Callback& url_matcher, - base::OnceClosure callback) { - parent_->ClearHttpAndMediaCaches(begin, end, url_matcher, - std::move(callback)); -} - -void CefStoragePartitionProxy::ClearCodeCaches( - base::Time begin, - base::Time end, - const base::RepeatingCallback& url_matcher, - base::OnceClosure callback) { - parent_->ClearCodeCaches(begin, end, url_matcher, std::move(callback)); -} - -void CefStoragePartitionProxy::Flush() { - parent_->Flush(); -} - -void CefStoragePartitionProxy::ResetURLLoaderFactories() { - parent_->ResetURLLoaderFactories(); -} - -void CefStoragePartitionProxy::ClearBluetoothAllowedDevicesMapForTesting() { - parent_->ClearBluetoothAllowedDevicesMapForTesting(); -} - -void CefStoragePartitionProxy::FlushNetworkInterfaceForTesting() { - parent_->FlushNetworkInterfaceForTesting(); -} - -void CefStoragePartitionProxy::WaitForDeletionTasksForTesting() { - parent_->WaitForDeletionTasksForTesting(); -} - -content::BackgroundFetchContext* -CefStoragePartitionProxy::GetBackgroundFetchContext() { - return parent_->GetBackgroundFetchContext(); -} - -content::BackgroundSyncContext* -CefStoragePartitionProxy::GetBackgroundSyncContext() { - return parent_->GetBackgroundSyncContext(); -} - -content::PaymentAppContextImpl* -CefStoragePartitionProxy::GetPaymentAppContext() { - return parent_->GetPaymentAppContext(); -} - -content::BroadcastChannelProvider* -CefStoragePartitionProxy::GetBroadcastChannelProvider() { - return parent_->GetBroadcastChannelProvider(); -} - -content::BluetoothAllowedDevicesMap* -CefStoragePartitionProxy::GetBluetoothAllowedDevicesMap() { - return parent_->GetBluetoothAllowedDevicesMap(); -} - -content::BlobRegistryWrapper* CefStoragePartitionProxy::GetBlobRegistry() { - return parent_->GetBlobRegistry(); -} - -content::PrefetchURLLoaderService* -CefStoragePartitionProxy::GetPrefetchURLLoaderService() { - return parent_->GetPrefetchURLLoaderService(); -} - -content::CookieStoreContext* CefStoragePartitionProxy::GetCookieStoreContext() { - return parent_->GetCookieStoreContext(); -} - -content::DevToolsBackgroundServicesContext* -CefStoragePartitionProxy::GetDevToolsBackgroundServicesContext() { - return parent_->GetDevToolsBackgroundServicesContext(); -} - -content::URLLoaderFactoryGetter* -CefStoragePartitionProxy::url_loader_factory_getter() { - return parent_->url_loader_factory_getter(); -} - -content::BrowserContext* CefStoragePartitionProxy::browser_context() const { - return parent_->browser_context(); -} - -mojo::BindingId CefStoragePartitionProxy::Bind( - int process_id, - mojo::InterfaceRequest request) { - return parent_->Bind(process_id, std::move(request)); -} - -void CefStoragePartitionProxy::Unbind(mojo::BindingId binding_id) { - parent_->Unbind(binding_id); -} - -void CefStoragePartitionProxy::set_site_for_service_worker( - const GURL& site_for_service_worker) { - parent_->set_site_for_service_worker(site_for_service_worker); -} - -const GURL& CefStoragePartitionProxy::site_for_service_worker() const { - return parent_->site_for_service_worker(); -} diff --git a/libcef/browser/storage_partition_proxy.h b/libcef/browser/storage_partition_proxy.h deleted file mode 100644 index 12c492d10..000000000 --- a/libcef/browser/storage_partition_proxy.h +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright (c) 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CEF_LIBCEF_BROWSER_STORAGE_PARTITION_PROXY_H_ -#define CEF_LIBCEF_BROWSER_STORAGE_PARTITION_PROXY_H_ -#pragma once - -#include "libcef/browser/net/url_request_context_getter_proxy.h" - -#include "content/public/browser/storage_partition.h" - -// StoragePartition implementation for a particular CefBrowserContextProxy. Life -// span is controlled by CefBrowserContextProxy. Only accessed on the UI thread. -// See browser_context.h for an object relationship diagram. -class CefStoragePartitionProxy : public content::StoragePartition { - public: - CefStoragePartitionProxy( - content::StoragePartition* parent, - CefURLRequestContextGetterProxy* url_request_context); - ~CefStoragePartitionProxy() override; - - // StoragePartition methods: - base::FilePath GetPath() override; - net::URLRequestContextGetter* GetURLRequestContext() override; - net::URLRequestContextGetter* GetMediaURLRequestContext() override; - network::mojom::NetworkContext* GetNetworkContext() override; - scoped_refptr - GetURLLoaderFactoryForBrowserProcess() override; - std::unique_ptr - GetURLLoaderFactoryForBrowserProcessIOThread() override; - network::mojom::CookieManager* GetCookieManagerForBrowserProcess() override; - storage::QuotaManager* GetQuotaManager() override; - content::AppCacheService* GetAppCacheService() override; - storage::FileSystemContext* GetFileSystemContext() override; - storage::DatabaseTracker* GetDatabaseTracker() override; - content::DOMStorageContext* GetDOMStorageContext() override; - content::IdleManager* GetIdleManager() override; - content::LockManager* GetLockManager() override; - content::IndexedDBContext* GetIndexedDBContext() override; - content::ServiceWorkerContext* GetServiceWorkerContext() override; - content::SharedWorkerService* GetSharedWorkerService() override; - content::CacheStorageContext* GetCacheStorageContext() override; - content::GeneratedCodeCacheContext* GetGeneratedCodeCacheContext() override; - content::HostZoomMap* GetHostZoomMap() override; - content::HostZoomLevelContext* GetHostZoomLevelContext() override; - content::ZoomLevelDelegate* GetZoomLevelDelegate() override; - content::PlatformNotificationContext* GetPlatformNotificationContext() - override; - void ClearDataForOrigin(uint32_t remove_mask, - uint32_t quota_storage_remove_mask, - const GURL& storage_origin) override; - void ClearData(uint32_t remove_mask, - uint32_t quota_storage_remove_mask, - const GURL& storage_origin, - const base::Time begin, - const base::Time end, - base::OnceClosure callback) override; - void ClearData(uint32_t remove_mask, - uint32_t quota_storage_remove_mask, - const OriginMatcherFunction& origin_matcher, - network::mojom::CookieDeletionFilterPtr cookie_deletion_filter, - bool perform_cleanup, - const base::Time begin, - const base::Time end, - base::OnceClosure callback) override; - void ClearHttpAndMediaCaches( - const base::Time begin, - const base::Time end, - const base::Callback& url_matcher, - base::OnceClosure callback) override; - void ClearCodeCaches( - base::Time begin, - base::Time end, - const base::RepeatingCallback& url_matcher, - base::OnceClosure callback) override; - void Flush() override; - void ResetURLLoaderFactories() override; - void ClearBluetoothAllowedDevicesMapForTesting() override; - void FlushNetworkInterfaceForTesting() override; - void WaitForDeletionTasksForTesting() override; - content::BackgroundFetchContext* GetBackgroundFetchContext() override; - content::BackgroundSyncContext* GetBackgroundSyncContext() override; - content::PaymentAppContextImpl* GetPaymentAppContext() override; - content::BroadcastChannelProvider* GetBroadcastChannelProvider() override; - content::BluetoothAllowedDevicesMap* GetBluetoothAllowedDevicesMap() override; - content::BlobRegistryWrapper* GetBlobRegistry() override; - content::PrefetchURLLoaderService* GetPrefetchURLLoaderService() override; - content::CookieStoreContext* GetCookieStoreContext() override; - content::DevToolsBackgroundServicesContext* - GetDevToolsBackgroundServicesContext() override; - content::URLLoaderFactoryGetter* url_loader_factory_getter() override; - content::BrowserContext* browser_context() const override; - mojo::BindingId Bind( - int process_id, - mojo::InterfaceRequest request) - override; - void Unbind(mojo::BindingId binding_id) override; - void set_site_for_service_worker( - const GURL& site_for_service_worker) override; - const GURL& site_for_service_worker() const override; - - content::StoragePartition* parent() const { return parent_; } - - private: - content::StoragePartition* parent_; // Not owned. - scoped_refptr url_request_context_; - - DISALLOW_COPY_AND_ASSIGN(CefStoragePartitionProxy); -}; - -#endif // CEF_LIBCEF_BROWSER_STORAGE_PARTITION_PROXY_H_ diff --git a/libcef_dll/cpptoc/cookie_manager_cpptoc.cc b/libcef_dll/cpptoc/cookie_manager_cpptoc.cc index 11e15e186..a66999003 100644 --- a/libcef_dll/cpptoc/cookie_manager_cpptoc.cc +++ b/libcef_dll/cpptoc/cookie_manager_cpptoc.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=229d455bfe9f7c8536f7bc03734eaf29e9e637b1$ +// $hash=a672fab541f9c28f77a06c31d89f5a9d66c78751$ // #include "libcef_dll/cpptoc/cookie_manager_cpptoc.h" @@ -35,33 +35,6 @@ CEF_EXPORT cef_cookie_manager_t* cef_cookie_manager_get_global_manager( return CefCookieManagerCppToC::Wrap(_retval); } -CEF_EXPORT cef_cookie_manager_t* cef_cookie_manager_get_blocking_manager() { - // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - - // Execute - CefRefPtr _retval = CefCookieManager::GetBlockingManager(); - - // Return type: refptr_same - return CefCookieManagerCppToC::Wrap(_retval); -} - -CEF_EXPORT cef_cookie_manager_t* cef_cookie_manager_create_manager( - const cef_string_t* path, - int persist_session_cookies, - cef_completion_callback_t* callback) { - // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - - // Unverified params: path, callback - - // Execute - CefRefPtr _retval = CefCookieManager::CreateManager( - CefString(path), persist_session_cookies ? true : false, - CefCompletionCallbackCToCpp::Wrap(callback)); - - // Return type: refptr_same - return CefCookieManagerCppToC::Wrap(_retval); -} - namespace { // MEMBER FUNCTIONS - Body may be edited by hand. @@ -193,27 +166,6 @@ cookie_manager_delete_cookies(struct _cef_cookie_manager_t* self, return _retval; } -int CEF_CALLBACK -cookie_manager_set_storage_path(struct _cef_cookie_manager_t* self, - const cef_string_t* path, - int persist_session_cookies, - cef_completion_callback_t* callback) { - // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - - DCHECK(self); - if (!self) - return 0; - // Unverified params: path, callback - - // Execute - bool _retval = CefCookieManagerCppToC::Get(self)->SetStoragePath( - CefString(path), persist_session_cookies ? true : false, - CefCompletionCallbackCToCpp::Wrap(callback)); - - // Return type: bool - return _retval; -} - int CEF_CALLBACK cookie_manager_flush_store(struct _cef_cookie_manager_t* self, cef_completion_callback_t* callback) { @@ -242,7 +194,6 @@ CefCookieManagerCppToC::CefCookieManagerCppToC() { GetStruct()->visit_url_cookies = cookie_manager_visit_url_cookies; GetStruct()->set_cookie = cookie_manager_set_cookie; GetStruct()->delete_cookies = cookie_manager_delete_cookies; - GetStruct()->set_storage_path = cookie_manager_set_storage_path; GetStruct()->flush_store = cookie_manager_flush_store; } diff --git a/libcef_dll/cpptoc/request_context_cpptoc.cc b/libcef_dll/cpptoc/request_context_cpptoc.cc index 833c6bdfa..bd0fab1c6 100644 --- a/libcef_dll/cpptoc/request_context_cpptoc.cc +++ b/libcef_dll/cpptoc/request_context_cpptoc.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=f4724d1d945c06c5113ba9e1b7f7ad8d4b735b9c$ +// $hash=29ac900a92c4ec966cc115aae96c49b545bc9db9$ // #include "libcef_dll/cpptoc/request_context_cpptoc.h" @@ -171,9 +171,9 @@ request_context_get_cache_path(struct _cef_request_context_t* self) { return _retval.DetachToUserFree(); } -cef_cookie_manager_t* CEF_CALLBACK request_context_get_default_cookie_manager( - struct _cef_request_context_t* self, - cef_completion_callback_t* callback) { +cef_cookie_manager_t* CEF_CALLBACK +request_context_get_cookie_manager(struct _cef_request_context_t* self, + cef_completion_callback_t* callback) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING DCHECK(self); @@ -183,7 +183,7 @@ cef_cookie_manager_t* CEF_CALLBACK request_context_get_default_cookie_manager( // Execute CefRefPtr _retval = - CefRequestContextCppToC::Get(self)->GetDefaultCookieManager( + CefRequestContextCppToC::Get(self)->GetCookieManager( CefCompletionCallbackCToCpp::Wrap(callback)); // Return type: refptr_same @@ -535,8 +535,7 @@ CefRequestContextCppToC::CefRequestContextCppToC() { GetStruct()->is_global = request_context_is_global; GetStruct()->get_handler = request_context_get_handler; GetStruct()->get_cache_path = request_context_get_cache_path; - GetStruct()->get_default_cookie_manager = - request_context_get_default_cookie_manager; + GetStruct()->get_cookie_manager = request_context_get_cookie_manager; GetStruct()->register_scheme_handler_factory = request_context_register_scheme_handler_factory; GetStruct()->clear_scheme_handler_factories = diff --git a/libcef_dll/cpptoc/request_context_handler_cpptoc.cc b/libcef_dll/cpptoc/request_context_handler_cpptoc.cc index 6161953de..531ef7e4f 100644 --- a/libcef_dll/cpptoc/request_context_handler_cpptoc.cc +++ b/libcef_dll/cpptoc/request_context_handler_cpptoc.cc @@ -9,11 +9,10 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=2decd7941020bd2b96ebfa736624d1729a82fa55$ +// $hash=b98ed34333ccd44a004c88c0ca496f7821f49e18$ // #include "libcef_dll/cpptoc/request_context_handler_cpptoc.h" -#include "libcef_dll/ctocpp/cookie_manager_ctocpp.h" #include "libcef_dll/ctocpp/request_context_ctocpp.h" #include "libcef_dll/ctocpp/web_plugin_info_ctocpp.h" @@ -39,22 +38,6 @@ void CEF_CALLBACK request_context_handler_on_request_context_initialized( CefRequestContextCToCpp::Wrap(request_context)); } -cef_cookie_manager_t* CEF_CALLBACK request_context_handler_get_cookie_manager( - struct _cef_request_context_handler_t* self) { - // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - - DCHECK(self); - if (!self) - return NULL; - - // Execute - CefRefPtr _retval = - CefRequestContextHandlerCppToC::Get(self)->GetCookieManager(); - - // Return type: refptr_diff - return CefCookieManagerCToCpp::Unwrap(_retval); -} - int CEF_CALLBACK request_context_handler_on_before_plugin_load( struct _cef_request_context_handler_t* self, const cef_string_t* mime_type, @@ -99,7 +82,6 @@ int CEF_CALLBACK request_context_handler_on_before_plugin_load( CefRequestContextHandlerCppToC::CefRequestContextHandlerCppToC() { GetStruct()->on_request_context_initialized = request_context_handler_on_request_context_initialized; - GetStruct()->get_cookie_manager = request_context_handler_get_cookie_manager; GetStruct()->on_before_plugin_load = request_context_handler_on_before_plugin_load; } diff --git a/libcef_dll/ctocpp/cookie_manager_ctocpp.cc b/libcef_dll/ctocpp/cookie_manager_ctocpp.cc index 7b2956a9e..b303f2fc9 100644 --- a/libcef_dll/ctocpp/cookie_manager_ctocpp.cc +++ b/libcef_dll/ctocpp/cookie_manager_ctocpp.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=bd8fe0f41380bc1e5ecedbcab726bc2ed875f827$ +// $hash=fdbb50cba70b9638aaaadc2e4040b18390ae3a6d$ // #include "libcef_dll/ctocpp/cookie_manager_ctocpp.h" @@ -36,35 +36,6 @@ CefRefPtr CefCookieManager::GetGlobalManager( return CefCookieManagerCToCpp::Wrap(_retval); } -NO_SANITIZE("cfi-icall") -CefRefPtr CefCookieManager::GetBlockingManager() { - // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - - // Execute - cef_cookie_manager_t* _retval = cef_cookie_manager_get_blocking_manager(); - - // Return type: refptr_same - return CefCookieManagerCToCpp::Wrap(_retval); -} - -NO_SANITIZE("cfi-icall") -CefRefPtr CefCookieManager::CreateManager( - const CefString& path, - bool persist_session_cookies, - CefRefPtr callback) { - // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - - // Unverified params: path, callback - - // Execute - cef_cookie_manager_t* _retval = cef_cookie_manager_create_manager( - path.GetStruct(), persist_session_cookies, - CefCompletionCallbackCppToC::Wrap(callback)); - - // Return type: refptr_same - return CefCookieManagerCToCpp::Wrap(_retval); -} - // VIRTUAL METHODS - Body may be edited by hand. NO_SANITIZE("cfi-icall") @@ -192,28 +163,6 @@ bool CefCookieManagerCToCpp::DeleteCookies( return _retval ? true : false; } -NO_SANITIZE("cfi-icall") -bool CefCookieManagerCToCpp::SetStoragePath( - const CefString& path, - bool persist_session_cookies, - CefRefPtr callback) { - cef_cookie_manager_t* _struct = GetStruct(); - if (CEF_MEMBER_MISSING(_struct, set_storage_path)) - return false; - - // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - - // Unverified params: path, callback - - // Execute - int _retval = _struct->set_storage_path( - _struct, path.GetStruct(), persist_session_cookies, - CefCompletionCallbackCppToC::Wrap(callback)); - - // Return type: bool - return _retval ? true : false; -} - NO_SANITIZE("cfi-icall") bool CefCookieManagerCToCpp::FlushStore( CefRefPtr callback) { diff --git a/libcef_dll/ctocpp/cookie_manager_ctocpp.h b/libcef_dll/ctocpp/cookie_manager_ctocpp.h index f5d54d9ec..f36a7868f 100644 --- a/libcef_dll/ctocpp/cookie_manager_ctocpp.h +++ b/libcef_dll/ctocpp/cookie_manager_ctocpp.h @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=2363533e3c6b78e16b93dd428121cd45b797ce6a$ +// $hash=99bb8be3c19be11e4abf2cf904d75667723ae643$ // #ifndef CEF_LIBCEF_DLL_CTOCPP_COOKIE_MANAGER_CTOCPP_H_ @@ -48,9 +48,6 @@ class CefCookieManagerCToCpp bool DeleteCookies(const CefString& url, const CefString& cookie_name, CefRefPtr callback) OVERRIDE; - bool SetStoragePath(const CefString& path, - bool persist_session_cookies, - CefRefPtr callback) OVERRIDE; bool FlushStore(CefRefPtr callback) OVERRIDE; }; diff --git a/libcef_dll/ctocpp/request_context_ctocpp.cc b/libcef_dll/ctocpp/request_context_ctocpp.cc index 8ab8f4f4f..781c3766a 100644 --- a/libcef_dll/ctocpp/request_context_ctocpp.cc +++ b/libcef_dll/ctocpp/request_context_ctocpp.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=ed414e127773ef135584c3c61a386615177feb59$ +// $hash=8155639f093ff697fd30a9e330ae3470108251e5$ // #include "libcef_dll/ctocpp/request_context_ctocpp.h" @@ -165,10 +165,10 @@ NO_SANITIZE("cfi-icall") CefString CefRequestContextCToCpp::GetCachePath() { } NO_SANITIZE("cfi-icall") -CefRefPtr CefRequestContextCToCpp::GetDefaultCookieManager( +CefRefPtr CefRequestContextCToCpp::GetCookieManager( CefRefPtr callback) { cef_request_context_t* _struct = GetStruct(); - if (CEF_MEMBER_MISSING(_struct, get_default_cookie_manager)) + if (CEF_MEMBER_MISSING(_struct, get_cookie_manager)) return NULL; // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING @@ -176,7 +176,7 @@ CefRefPtr CefRequestContextCToCpp::GetDefaultCookieManager( // Unverified params: callback // Execute - cef_cookie_manager_t* _retval = _struct->get_default_cookie_manager( + cef_cookie_manager_t* _retval = _struct->get_cookie_manager( _struct, CefCompletionCallbackCppToC::Wrap(callback)); // Return type: refptr_same diff --git a/libcef_dll/ctocpp/request_context_ctocpp.h b/libcef_dll/ctocpp/request_context_ctocpp.h index a81632881..0ff34b77f 100644 --- a/libcef_dll/ctocpp/request_context_ctocpp.h +++ b/libcef_dll/ctocpp/request_context_ctocpp.h @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=52475096e498cd28cbd25676eaab24e14c1438b0$ +// $hash=73f229f21f0d9ce78f3897fd8a2ec94261a52f48$ // #ifndef CEF_LIBCEF_DLL_CTOCPP_REQUEST_CONTEXT_CTOCPP_H_ @@ -43,7 +43,7 @@ class CefRequestContextCToCpp bool IsGlobal() OVERRIDE; CefRefPtr GetHandler() OVERRIDE; CefString GetCachePath() OVERRIDE; - CefRefPtr GetDefaultCookieManager( + CefRefPtr GetCookieManager( CefRefPtr callback) OVERRIDE; bool RegisterSchemeHandlerFactory( const CefString& scheme_name, diff --git a/libcef_dll/ctocpp/request_context_handler_ctocpp.cc b/libcef_dll/ctocpp/request_context_handler_ctocpp.cc index cbae91322..ba51f2704 100644 --- a/libcef_dll/ctocpp/request_context_handler_ctocpp.cc +++ b/libcef_dll/ctocpp/request_context_handler_ctocpp.cc @@ -9,11 +9,10 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=80c600e8a2f2035219c00bad1bf28a58b6dabf53$ +// $hash=4b25ca3feb69361cc3b6525fdc0c3a56710b65ec$ // #include "libcef_dll/ctocpp/request_context_handler_ctocpp.h" -#include "libcef_dll/cpptoc/cookie_manager_cpptoc.h" #include "libcef_dll/cpptoc/request_context_cpptoc.h" #include "libcef_dll/cpptoc/web_plugin_info_cpptoc.h" @@ -38,21 +37,6 @@ void CefRequestContextHandlerCToCpp::OnRequestContextInitialized( _struct, CefRequestContextCppToC::Wrap(request_context)); } -NO_SANITIZE("cfi-icall") -CefRefPtr CefRequestContextHandlerCToCpp::GetCookieManager() { - cef_request_context_handler_t* _struct = GetStruct(); - if (CEF_MEMBER_MISSING(_struct, get_cookie_manager)) - return NULL; - - // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - - // Execute - cef_cookie_manager_t* _retval = _struct->get_cookie_manager(_struct); - - // Return type: refptr_diff - return CefCookieManagerCppToC::Unwrap(_retval); -} - NO_SANITIZE("cfi-icall") bool CefRequestContextHandlerCToCpp::OnBeforePluginLoad( const CefString& mime_type, diff --git a/libcef_dll/ctocpp/request_context_handler_ctocpp.h b/libcef_dll/ctocpp/request_context_handler_ctocpp.h index dbb52a840..519c20206 100644 --- a/libcef_dll/ctocpp/request_context_handler_ctocpp.h +++ b/libcef_dll/ctocpp/request_context_handler_ctocpp.h @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=f60c9110cba752df545af2fe5905a01d30ff588e$ +// $hash=3cf1dba9c137bc586d91149920ff4558bce74a58$ // #ifndef CEF_LIBCEF_DLL_CTOCPP_REQUEST_CONTEXT_HANDLER_CTOCPP_H_ @@ -39,7 +39,6 @@ class CefRequestContextHandlerCToCpp // CefRequestContextHandler methods. void OnRequestContextInitialized( CefRefPtr request_context) override; - CefRefPtr GetCookieManager() override; bool OnBeforePluginLoad(const CefString& mime_type, const CefString& plugin_url, bool is_main_frame, diff --git a/libcef_dll/wrapper/libcef_dll_dylib.cc b/libcef_dll/wrapper/libcef_dll_dylib.cc index 7244cf92c..17634839b 100644 --- a/libcef_dll/wrapper/libcef_dll_dylib.cc +++ b/libcef_dll/wrapper/libcef_dll_dylib.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=4a4744491587c5f5b1ce8726d8dd08ad04646b92$ +// $hash=7c87ef36c39355a02bb9544b8228acac7a7abee9$ // #include @@ -198,12 +198,6 @@ typedef struct _cef_command_line_t* (*cef_command_line_get_global_ptr)(); typedef struct _cef_cookie_manager_t* ( *cef_cookie_manager_get_global_manager_ptr)( struct _cef_completion_callback_t*); -typedef struct _cef_cookie_manager_t* ( - *cef_cookie_manager_get_blocking_manager_ptr)(); -typedef struct _cef_cookie_manager_t* (*cef_cookie_manager_create_manager_ptr)( - const cef_string_t*, - int, - struct _cef_completion_callback_t*); typedef struct _cef_drag_data_t* (*cef_drag_data_create_ptr)(); typedef struct _cef_image_t* (*cef_image_create_ptr)(); typedef struct _cef_menu_model_t* (*cef_menu_model_create_ptr)( @@ -580,9 +574,6 @@ struct libcef_pointers { cef_command_line_get_global_ptr cef_command_line_get_global; cef_cookie_manager_get_global_manager_ptr cef_cookie_manager_get_global_manager; - cef_cookie_manager_get_blocking_manager_ptr - cef_cookie_manager_get_blocking_manager; - cef_cookie_manager_create_manager_ptr cef_cookie_manager_create_manager; cef_drag_data_create_ptr cef_drag_data_create; cef_image_create_ptr cef_image_create; cef_menu_model_create_ptr cef_menu_model_create; @@ -797,8 +788,6 @@ int libcef_init_pointers(const char* path) { INIT_ENTRY(cef_command_line_create); INIT_ENTRY(cef_command_line_get_global); INIT_ENTRY(cef_cookie_manager_get_global_manager); - INIT_ENTRY(cef_cookie_manager_get_blocking_manager); - INIT_ENTRY(cef_cookie_manager_create_manager); INIT_ENTRY(cef_drag_data_create); INIT_ENTRY(cef_image_create); INIT_ENTRY(cef_menu_model_create); @@ -1309,20 +1298,6 @@ struct _cef_cookie_manager_t* cef_cookie_manager_get_global_manager( return g_libcef_pointers.cef_cookie_manager_get_global_manager(callback); } -NO_SANITIZE("cfi-icall") -struct _cef_cookie_manager_t* cef_cookie_manager_get_blocking_manager() { - return g_libcef_pointers.cef_cookie_manager_get_blocking_manager(); -} - -NO_SANITIZE("cfi-icall") -struct _cef_cookie_manager_t* cef_cookie_manager_create_manager( - const cef_string_t* path, - int persist_session_cookies, - struct _cef_completion_callback_t* callback) { - return g_libcef_pointers.cef_cookie_manager_create_manager( - path, persist_session_cookies, callback); -} - NO_SANITIZE("cfi-icall") struct _cef_drag_data_t* cef_drag_data_create() { return g_libcef_pointers.cef_drag_data_create(); } diff --git a/tests/cefclient/browser/root_window_manager.cc b/tests/cefclient/browser/root_window_manager.cc index 7b1b8522e..9b1033453 100644 --- a/tests/cefclient/browser/root_window_manager.cc +++ b/tests/cefclient/browser/root_window_manager.cc @@ -22,14 +22,7 @@ namespace { class ClientRequestContextHandler : public CefRequestContextHandler, public CefExtensionHandler { public: - ClientRequestContextHandler() { - CefRefPtr command_line = - CefCommandLine::GetGlobalCommandLine(); - if (command_line->HasSwitch(switches::kRequestContextBlockCookies)) { - // Use a cookie manager that neither stores nor retrieves cookies. - cookie_manager_ = CefCookieManager::GetBlockingManager(); - } - } + ClientRequestContextHandler() {} // CefRequestContextHandler methods: bool OnBeforePluginLoad(const CefString& mime_type, @@ -80,10 +73,6 @@ class ClientRequestContextHandler : public CefRequestContextHandler, } } - CefRefPtr GetCookieManager() OVERRIDE { - return cookie_manager_; - } - // CefExtensionHandler methods: void OnExtensionLoaded(CefRefPtr extension) OVERRIDE { CEF_REQUIRE_UI_THREAD(); @@ -110,8 +99,6 @@ class ClientRequestContextHandler : public CefRequestContextHandler, } private: - CefRefPtr cookie_manager_; - IMPLEMENT_REFCOUNTING(ClientRequestContextHandler); DISALLOW_COPY_AND_ASSIGN(ClientRequestContextHandler); }; diff --git a/tests/ceftests/cookie_unittest.cc b/tests/ceftests/cookie_unittest.cc index 6cc6175d3..c4f4d5231 100644 --- a/tests/ceftests/cookie_unittest.cc +++ b/tests/ceftests/cookie_unittest.cc @@ -11,15 +11,12 @@ #include "include/cef_scheme.h" #include "include/cef_waitable_event.h" #include "include/wrapper/cef_closure_task.h" -#include "include/wrapper/cef_scoped_temp_dir.h" #include "tests/ceftests/test_handler.h" #include "tests/ceftests/test_suite.h" #include "tests/gtest/include/gtest/gtest.h" namespace { -const int kCacheDeleteDelay = 50; - const char* kTestUrl = "http://www.test.com/path/to/cookietest/foo.html"; const char* kTestDomain = "www.test.com"; const char* kTestPath = "/path/to/cookietest"; @@ -465,63 +462,10 @@ void TestAllCookies(CefRefPtr manager, VerifyNoCookies(manager, event, false); } -void TestChangeDirectory(CefRefPtr manager, - CefRefPtr event, - const CefString& original_dir) { - CefCookie cookie; - - CefScopedTempDir temp_dir; - - // Create a new temporary directory. - EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); - - // Delete all of the system cookies. - DeleteAllCookies(manager, event); - - // Set the new temporary directory as the storage location. - EXPECT_TRUE(manager->SetStoragePath(temp_dir.GetPath(), false, NULL)); - - // Wait for the storage location change to complete on the IO thread. - WaitForIOThread(); - - // Verify that no cookies exist. - VerifyNoCookies(manager, event, true); - - // Create a domain cookie. - CreateCookie(manager, cookie, true, false, event); - - // Retrieve and verify the domain cookie. - GetCookie(manager, cookie, true, event, false); - - // Restore the original storage location. - EXPECT_TRUE(manager->SetStoragePath(original_dir, false, NULL)); - - // Wait for the storage location change to complete on the IO thread. - WaitForIOThread(); - - // Verify that no cookies exist. - VerifyNoCookies(manager, event, true); - - // Set the new temporary directory as the storage location. - EXPECT_TRUE(manager->SetStoragePath(temp_dir.GetPath(), false, NULL)); - - // Wait for the storage location change to complete on the IO thread. - WaitForIOThread(); - - // Retrieve and verify the domain cookie that was set previously. - GetCookie(manager, cookie, true, event, false); - - // Restore the original storage location. - EXPECT_TRUE(manager->SetStoragePath(original_dir, false, NULL)); - - // Wait for the storage location change to complete on the IO thread. - WaitForIOThread(); -} - } // namespace // Test creation of a domain cookie. -TEST(CookieTest, DomainCookieGlobal) { +TEST(CookieTest, DomainCookie) { CefRefPtr event = CefWaitableEvent::CreateWaitableEvent(true, false); @@ -533,44 +477,8 @@ TEST(CookieTest, DomainCookieGlobal) { TestDomainCookie(manager, event); } -// Test creation of a domain cookie. -TEST(CookieTest, DomainCookieInMemory) { - CefRefPtr event = - CefWaitableEvent::CreateWaitableEvent(true, false); - - CefRefPtr manager = CefCookieManager::CreateManager( - CefString(), false, new TestCompletionCallback(event)); - event->Wait(); - EXPECT_TRUE(manager.get()); - - TestDomainCookie(manager, event); -} - -// Test creation of a domain cookie. -TEST(CookieTest, DomainCookieOnDisk) { - CefScopedTempDir temp_dir; - - // Create a new temporary directory. - EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); - - CefRefPtr event = - CefWaitableEvent::CreateWaitableEvent(true, false); - - CefRefPtr manager = CefCookieManager::CreateManager( - temp_dir.GetPath(), false, new TestCompletionCallback(event)); - event->Wait(); - EXPECT_TRUE(manager.get()); - - TestDomainCookie(manager, event); - - // The backing store will be closed on the FILE thread after the CookieManager - // is destroyed. - manager = NULL; - WaitForFILEThreadWithDelay(kCacheDeleteDelay); -} - // Test creation of a host cookie. -TEST(CookieTest, HostCookieGlobal) { +TEST(CookieTest, HostCookie) { CefRefPtr event = CefWaitableEvent::CreateWaitableEvent(true, false); @@ -582,44 +490,8 @@ TEST(CookieTest, HostCookieGlobal) { TestHostCookie(manager, event); } -// Test creation of a host cookie. -TEST(CookieTest, HostCookieInMemory) { - CefRefPtr event = - CefWaitableEvent::CreateWaitableEvent(true, false); - - CefRefPtr manager = CefCookieManager::CreateManager( - CefString(), false, new TestCompletionCallback(event)); - event->Wait(); - EXPECT_TRUE(manager.get()); - - TestHostCookie(manager, event); -} - -// Test creation of a host cookie. -TEST(CookieTest, HostCookieOnDisk) { - CefScopedTempDir temp_dir; - - // Create a new temporary directory. - EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); - - CefRefPtr event = - CefWaitableEvent::CreateWaitableEvent(true, false); - - CefRefPtr manager = CefCookieManager::CreateManager( - temp_dir.GetPath(), false, new TestCompletionCallback(event)); - event->Wait(); - EXPECT_TRUE(manager.get()); - - TestHostCookie(manager, event); - - // The backing store will be closed on the FILE thread after the CookieManager - // is destroyed. - manager = NULL; - WaitForFILEThreadWithDelay(kCacheDeleteDelay); -} - // Test creation of multiple cookies. -TEST(CookieTest, MultipleCookiesGlobal) { +TEST(CookieTest, MultipleCookies) { CefRefPtr event = CefWaitableEvent::CreateWaitableEvent(true, false); @@ -631,43 +503,7 @@ TEST(CookieTest, MultipleCookiesGlobal) { TestMultipleCookies(manager, event); } -// Test creation of multiple cookies. -TEST(CookieTest, MultipleCookiesInMemory) { - CefRefPtr event = - CefWaitableEvent::CreateWaitableEvent(true, false); - - CefRefPtr manager = CefCookieManager::CreateManager( - CefString(), false, new TestCompletionCallback(event)); - event->Wait(); - EXPECT_TRUE(manager.get()); - - TestMultipleCookies(manager, event); -} - -// Test creation of multiple cookies. -TEST(CookieTest, MultipleCookiesOnDisk) { - CefScopedTempDir temp_dir; - - // Create a new temporary directory. - EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); - - CefRefPtr event = - CefWaitableEvent::CreateWaitableEvent(true, false); - - CefRefPtr manager = CefCookieManager::CreateManager( - temp_dir.GetPath(), false, new TestCompletionCallback(event)); - event->Wait(); - EXPECT_TRUE(manager.get()); - - TestMultipleCookies(manager, event); - - // The backing store will be closed on the FILE thread after the CookieManager - // is destroyed. - manager = NULL; - WaitForFILEThreadWithDelay(kCacheDeleteDelay); -} - -TEST(CookieTest, AllCookiesGlobal) { +TEST(CookieTest, AllCookies) { CefRefPtr event = CefWaitableEvent::CreateWaitableEvent(true, false); @@ -679,135 +515,6 @@ TEST(CookieTest, AllCookiesGlobal) { TestAllCookies(manager, event); } -TEST(CookieTest, AllCookiesInMemory) { - CefRefPtr event = - CefWaitableEvent::CreateWaitableEvent(true, false); - - CefRefPtr manager = CefCookieManager::CreateManager( - CefString(), false, new TestCompletionCallback(event)); - event->Wait(); - EXPECT_TRUE(manager.get()); - - TestAllCookies(manager, event); -} - -TEST(CookieTest, AllCookiesOnDisk) { - CefScopedTempDir temp_dir; - - // Create a new temporary directory. - EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); - - CefRefPtr event = - CefWaitableEvent::CreateWaitableEvent(true, false); - - CefRefPtr manager = CefCookieManager::CreateManager( - temp_dir.GetPath(), false, new TestCompletionCallback(event)); - event->Wait(); - EXPECT_TRUE(manager.get()); - - TestAllCookies(manager, event); - - // The backing store will be closed on the FILE thread after the CookieManager - // is destroyed. - manager = NULL; - WaitForFILEThreadWithDelay(kCacheDeleteDelay); -} - -TEST(CookieTest, ChangeDirectoryGlobal) { - CefRefPtr event = - CefWaitableEvent::CreateWaitableEvent(true, false); - - CefRefPtr manager = - CefCookieManager::GetGlobalManager(new TestCompletionCallback(event)); - event->Wait(); - EXPECT_TRUE(manager.get()); - - std::string cache_path; - CefTestSuite::GetInstance()->GetCachePath(cache_path); - - TestChangeDirectory(manager, event, cache_path); -} - -TEST(CookieTest, ChangeDirectoryCreated) { - CefRefPtr event = - CefWaitableEvent::CreateWaitableEvent(true, false); - - CefRefPtr manager = CefCookieManager::CreateManager( - CefString(), false, new TestCompletionCallback(event)); - event->Wait(); - EXPECT_TRUE(manager.get()); - - TestChangeDirectory(manager, event, CefString()); -} - -TEST(CookieTest, SessionCookieNoPersist) { - CefScopedTempDir temp_dir; - CefRefPtr event = - CefWaitableEvent::CreateWaitableEvent(true, false); - CefCookie cookie; - - // Create a new temporary directory. - EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); - - CefRefPtr manager = CefCookieManager::CreateManager( - temp_dir.GetPath(), false, new TestCompletionCallback(event)); - event->Wait(); - EXPECT_TRUE(manager.get()); - - // Create a session cookie. - CreateCookie(manager, cookie, true, true, event); - - // Retrieve and verify the cookie. - GetCookie(manager, cookie, true, event, false); - - // Flush the cookie store to disk. - manager->FlushStore(new TestCompletionCallback(event)); - event->Wait(); - - // Create a new manager to read the same cookie store. - manager = CefCookieManager::CreateManager(temp_dir.GetPath(), false, - new TestCompletionCallback(event)); - event->Wait(); - EXPECT_TRUE(manager.get()); - - // Verify that the cookie doesn't exist. - VerifyNoCookies(manager, event, true); -} - -TEST(CookieTest, SessionCookieWillPersist) { - CefScopedTempDir temp_dir; - CefRefPtr event = - CefWaitableEvent::CreateWaitableEvent(true, false); - CefCookie cookie; - - // Create a new temporary directory. - EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); - - CefRefPtr manager = CefCookieManager::CreateManager( - temp_dir.GetPath(), true, new TestCompletionCallback(event)); - event->Wait(); - EXPECT_TRUE(manager.get()); - - // Create a session cookie. - CreateCookie(manager, cookie, true, true, event); - - // Retrieve and verify the cookie. - GetCookie(manager, cookie, true, event, false); - - // Flush the cookie store to disk. - manager->FlushStore(new TestCompletionCallback(event)); - event->Wait(); - - // Create a new manager to read the same cookie store. - manager = CefCookieManager::CreateManager(temp_dir.GetPath(), true, - new TestCompletionCallback(event)); - event->Wait(); - EXPECT_TRUE(manager.get()); - - // Verify that the cookie exists. - GetCookie(manager, cookie, true, event, false); -} - namespace { const char* kCookieJSUrl1 = "http://tests/cookie1.html"; @@ -815,44 +522,9 @@ const char* kCookieJSUrl2 = "http://tests/cookie2.html"; class CookieTestJSHandler : public TestHandler { public: - class RequestContextHandler : public CefRequestContextHandler { - public: - explicit RequestContextHandler(CookieTestJSHandler* handler) - : handler_(handler) {} - - CefRefPtr GetCookieManager() override { - EXPECT_TRUE(handler_); - EXPECT_TRUE(CefCurrentlyOn(TID_IO)); - - if (url_ == kCookieJSUrl1) { - // Return the first cookie manager. - handler_->got_cookie_manager1_.yes(); - return handler_->manager1_; - } else { - // Return the second cookie manager. - handler_->got_cookie_manager2_.yes(); - return handler_->manager2_; - } - } - - void SetURL(const std::string& url) { url_ = url; } - - void Detach() { handler_ = NULL; } - - private: - std::string url_; - CookieTestJSHandler* handler_; - - IMPLEMENT_REFCOUNTING(RequestContextHandler); - }; - CookieTestJSHandler() {} void RunTest() override { - // Create new in-memory managers. - manager1_ = CefCookieManager::CreateManager(CefString(), false, NULL); - manager2_ = CefCookieManager::CreateManager(CefString(), false, NULL); - std::string page = "" "" - "Nav1" - "", - "text/html"); - - CefRequestContextSettings settings; - - context_handler_ = new RequestContextHandler(this); - context_ = - CefRequestContext::CreateContext(settings, context_handler_.get()); - cookie_manager_ = CefCookieManager::CreateManager(CefString(), true, NULL); - - // Create browser that loads the 1st URL. - CreateBrowser(url_, context_); - - // Time out the test after a reasonable period of time. - SetTestTimeout(); - } - - void OnLoadEnd(CefRefPtr browser, - CefRefPtr frame, - int httpStatusCode) override { - CefRefPtr context = - browser->GetHost()->GetRequestContext(); - EXPECT_TRUE(context.get()); - EXPECT_TRUE(context->IsSame(context_)); - EXPECT_FALSE(context->IsGlobal()); - EXPECT_EQ(context->GetHandler().get(), context_handler_.get()); - - FinishTest(); - } - - protected: - void FinishTest() { - // Verify that the cookie was set correctly. - class TestVisitor : public CefCookieVisitor { - public: - explicit TestVisitor(CookieTestHandler* handler) : handler_(handler) {} - ~TestVisitor() override { - // Destroy the test. - CefPostTask(TID_UI, - base::Bind(&CookieTestHandler::DestroyTest, handler_)); - } - - bool Visit(const CefCookie& cookie, - int count, - int total, - bool& deleteCookie) override { - const std::string& name = CefString(&cookie.name); - const std::string& value = CefString(&cookie.value); - if (name == "name1" && value == "value1") - handler_->got_cookie_.yes(); - return true; - } - - private: - CookieTestHandler* handler_; - IMPLEMENT_REFCOUNTING(TestVisitor); - }; - - cookie_manager_->VisitAllCookies(new TestVisitor(this)); - } - - void DestroyTest() override { - // Verify test expectations. - EXPECT_TRUE(got_get_cookie_manager_); - EXPECT_TRUE(got_cookie_); - - context_handler_->Detach(); - context_handler_ = NULL; - context_ = NULL; - - TestHandler::DestroyTest(); - } - - std::string url_; - CefRefPtr context_; - CefRefPtr context_handler_; - CefRefPtr cookie_manager_; - - TrackCallback got_get_cookie_manager_; - TrackCallback got_cookie_; - - IMPLEMENT_REFCOUNTING(CookieTestHandler); -}; - -} // namespace - -// Test that the cookie manager is retrieved via the associated request context. -TEST(RequestContextTest, GetCookieManager) { - CefRefPtr handler = - new CookieTestHandler("http://tests-simple-rch.com/nav1.html"); - handler->ExecuteTest(); - ReleaseAndWaitForDestructor(handler); -} - -namespace { - class PopupTestHandler : public TestHandler { public: - class RequestContextHandler : public CefRequestContextHandler { - public: - explicit RequestContextHandler(PopupTestHandler* handler) - : handler_(handler) {} - - CefRefPtr GetCookieManager() override { - EXPECT_TRUE(handler_); - if (url_ == handler_->url_) - handler_->got_get_cookie_manager1_.yes(); - else if (url_ == handler_->popup_url_) - handler_->got_get_cookie_manager2_.yes(); - return handler_->cookie_manager_; - } - - void SetURL(const std::string& url) { url_ = url; } - - void Detach() { handler_ = NULL; } - - private: - PopupTestHandler* handler_; - std::string url_; - - IMPLEMENT_REFCOUNTING(RequestContextHandler); - }; - enum Mode { MODE_WINDOW_OPEN, MODE_TARGETED_LINK, @@ -394,11 +244,8 @@ class PopupTestHandler : public TestHandler { CefRequestContextSettings settings; - context_handler_ = new RequestContextHandler(this); - context_handler_->SetURL(url_); - context_ = - CefRequestContext::CreateContext(settings, context_handler_.get()); - cookie_manager_ = CefCookieManager::CreateManager(CefString(), true, NULL); + context_ = CefRequestContext::CreateContext(settings, NULL); + cookie_manager_ = context_->GetCookieManager(NULL); // Create browser that loads the 1st URL. CreateBrowser(url_, context_); @@ -421,7 +268,6 @@ class PopupTestHandler : public TestHandler { const std::string& url = frame->GetURL(); if (url == url_) { got_load_end1_.yes(); - context_handler_->SetURL(popup_url_); LaunchPopup(browser); } else if (url == popup_url_) { got_load_end2_.yes(); @@ -497,10 +343,13 @@ class PopupTestHandler : public TestHandler { bool& deleteCookie) override { const std::string& name = CefString(&cookie.name); const std::string& value = CefString(&cookie.value); - if (name == "name1" && value == "value1") + if (name == "name1" && value == "value1") { handler_->got_cookie1_.yes(); - else if (name == "name2" && value == "value2") + deleteCookie = true; + } else if (name == "name2" && value == "value2") { handler_->got_cookie2_.yes(); + deleteCookie = true; + } return true; } @@ -514,16 +363,11 @@ class PopupTestHandler : public TestHandler { void DestroyTest() override { // Verify test expectations. - EXPECT_TRUE(got_get_cookie_manager1_); EXPECT_TRUE(got_load_end1_); EXPECT_TRUE(got_on_before_popup_); - EXPECT_TRUE(got_get_cookie_manager2_); EXPECT_TRUE(got_load_end2_); EXPECT_TRUE(got_cookie1_); EXPECT_TRUE(got_cookie2_); - - context_handler_->Detach(); - context_handler_ = NULL; context_ = NULL; TestHandler::DestroyTest(); @@ -534,13 +378,10 @@ class PopupTestHandler : public TestHandler { Mode mode_; CefRefPtr context_; - CefRefPtr context_handler_; CefRefPtr cookie_manager_; - TrackCallback got_get_cookie_manager1_; TrackCallback got_load_end1_; TrackCallback got_on_before_popup_; - TrackCallback got_get_cookie_manager2_; TrackCallback got_load_end2_; TrackCallback got_cookie1_; TrackCallback got_cookie2_; diff --git a/tests/ceftests/request_handler_unittest.cc b/tests/ceftests/request_handler_unittest.cc index 5f788034b..daa15ca91 100644 --- a/tests/ceftests/request_handler_unittest.cc +++ b/tests/ceftests/request_handler_unittest.cc @@ -60,36 +60,6 @@ class NetNotifyBrowserTest : public ClientAppBrowser::Delegate { // Browser side. class NetNotifyTestHandler : public TestHandler { public: - class RequestContextHandler : public CefRequestContextHandler { - public: - explicit RequestContextHandler(NetNotifyTestHandler* handler) - : handler_(handler) {} - - CefRefPtr GetCookieManager() override { - EXPECT_TRUE(handler_); - EXPECT_TRUE(CefCurrentlyOn(TID_IO)); - - if (url_.find(handler_->url1_) == 0) - handler_->got_get_cookie_manager1_.yes(); - else if (url_.find(handler_->url2_) == 0) - handler_->got_get_cookie_manager2_.yes(); - else - EXPECT_TRUE(false); // Not reached - - return handler_->cookie_manager_; - } - - void SetURL(const std::string& url) { url_ = url; } - - void Detach() { handler_ = NULL; } - - private: - std::string url_; - NetNotifyTestHandler* handler_; - - IMPLEMENT_REFCOUNTING(RequestContextHandler); - }; - NetNotifyTestHandler(CompletionState* completion_state, NetNotifyTestType test_type, bool same_origin) @@ -106,8 +76,6 @@ class NetNotifyTestHandler : public TestHandler { << "nav2.html?t=" << test_type_; url2_ = ss.str(); - cookie_manager_ = CefCookieManager::CreateManager(CefString(), true, NULL); - const std::string& resource1 = "" "" @@ -124,13 +92,11 @@ class NetNotifyTestHandler : public TestHandler { response_length2_ = static_cast(resource2.size()); AddResource(url2_, resource2, "text/html"); - context_handler_ = new RequestContextHandler(this); - context_handler_->SetURL(url1_); - // Create the request context that will use an in-memory cache. CefRequestContextSettings settings; CefRefPtr request_context = - CefRequestContext::CreateContext(settings, context_handler_.get()); + CefRequestContext::CreateContext(settings, NULL); + cookie_manager_ = request_context->GetCookieManager(NULL); // Create browser that loads the 1st URL. CreateBrowser(url1_, request_context); @@ -138,7 +104,6 @@ class NetNotifyTestHandler : public TestHandler { void RunTest() override { // Navigate to the 2nd URL. - context_handler_->SetURL(url2_); GetBrowser()->GetMainFrame()->LoadURL(url2_); // Time out the test after a reasonable period of time. @@ -320,10 +285,13 @@ class NetNotifyTestHandler : public TestHandler { bool& deleteCookie) override { const std::string& name = CefString(&cookie.name); const std::string& value = CefString(&cookie.value); - if (name == "name1" && value == "value1") + if (name == "name1" && value == "value1") { handler_->got_cookie1_.yes(); - else if (name == "name2" && value == "value2") + deleteCookie = true; + } else if (name == "name2" && value == "value2") { handler_->got_cookie2_.yes(); + deleteCookie = true; + } return true; } @@ -344,7 +312,6 @@ class NetNotifyTestHandler : public TestHandler { EXPECT_TRUE(got_before_resource_load1_) << " browser " << browser_id; EXPECT_TRUE(got_get_resource_handler1_) << " browser " << browser_id; EXPECT_TRUE(got_resource_load_complete1_) << " browser " << browser_id; - EXPECT_TRUE(got_get_cookie_manager1_) << " browser " << browser_id; EXPECT_TRUE(got_cookie1_) << " browser " << browser_id; EXPECT_TRUE(got_process_message1_) << " browser " << browser_id; EXPECT_TRUE(got_before_browse2_) << " browser " << browser_id; @@ -352,7 +319,6 @@ class NetNotifyTestHandler : public TestHandler { EXPECT_TRUE(got_before_resource_load2_) << " browser " << browser_id; EXPECT_TRUE(got_get_resource_handler2_) << " browser " << browser_id; EXPECT_TRUE(got_resource_load_complete2_) << " browser " << browser_id; - EXPECT_TRUE(got_get_cookie_manager2_) << " browser " << browser_id; EXPECT_TRUE(got_cookie2_) << " browser " << browser_id; EXPECT_TRUE(got_process_message2_) << " browser " << browser_id; @@ -365,8 +331,6 @@ class NetNotifyTestHandler : public TestHandler { EXPECT_FALSE(got_before_browse2_delayed_) << " browser " << browser_id; } - context_handler_->Detach(); - context_handler_ = NULL; cookie_manager_ = NULL; TestHandler::DestroyTest(); @@ -377,8 +341,6 @@ class NetNotifyTestHandler : public TestHandler { std::string url1_; std::string url2_; - CefRefPtr context_handler_; - CefRefPtr cookie_manager_; TrackCallback got_before_browse1_; @@ -386,7 +348,6 @@ class NetNotifyTestHandler : public TestHandler { TrackCallback got_before_resource_load1_; TrackCallback got_get_resource_handler1_; TrackCallback got_resource_load_complete1_; - TrackCallback got_get_cookie_manager1_; TrackCallback got_cookie1_; TrackCallback got_process_message1_; TrackCallback got_before_browse2_; @@ -394,7 +355,6 @@ class NetNotifyTestHandler : public TestHandler { TrackCallback got_before_resource_load2_; TrackCallback got_get_resource_handler2_; TrackCallback got_resource_load_complete2_; - TrackCallback got_get_cookie_manager2_; TrackCallback got_cookie2_; TrackCallback got_process_message2_; TrackCallback got_before_browse2_will_delay_; @@ -2183,45 +2143,13 @@ class CookieAccessTestHandler : public RoutingTestHandler { BLOCK_READ = 1 << 0, BLOCK_WRITE = 1 << 1, BLOCK_READ_WRITE = BLOCK_READ | BLOCK_WRITE, - BLOCK_ALL = 1 << 2, - }; - - class RequestContextHandler : public CefRequestContextHandler { - public: - explicit RequestContextHandler(CookieAccessTestHandler* handler) - : handler_(handler) {} - - CefRefPtr GetCookieManager() override { - EXPECT_TRUE(handler_); - EXPECT_TRUE(CefCurrentlyOn(TID_IO)); - - handler_->got_cookie_manager_.yes(); - return handler_->cookie_manager_; - } - - void Detach() { handler_ = NULL; } - - private: - CookieAccessTestHandler* handler_; - - IMPLEMENT_REFCOUNTING(RequestContextHandler); }; CookieAccessTestHandler(TestMode test_mode, bool server_backend) : test_mode_(test_mode), server_backend_(server_backend) {} void RunTest() override { - if (test_mode_ == BLOCK_ALL) { - cookie_manager_ = CefCookieManager::GetBlockingManager(); - context_handler_ = new RequestContextHandler(this); - - // Create a request context that uses |context_handler_|. - CefRequestContextSettings settings; - context_ = - CefRequestContext::CreateContext(settings, context_handler_.get()); - } else { - cookie_manager_ = CefCookieManager::GetGlobalManager(nullptr); - } + cookie_manager_ = CefCookieManager::GetGlobalManager(nullptr); SetTestTimeout(); CefPostTask(TID_UI, @@ -2240,128 +2168,90 @@ class CookieAccessTestHandler : public RoutingTestHandler { cookie_manager_ = NULL; if (context_) context_ = NULL; - if (context_handler_) { - context_handler_->Detach(); - context_handler_ = NULL; - } // Got both network requests. EXPECT_TRUE(data1_.got_request_); EXPECT_TRUE(data2_.got_request_); - if (test_mode_ == BLOCK_ALL) { - EXPECT_TRUE(got_cookie_manager_); + EXPECT_FALSE(got_cookie_manager_); - // The callback to set the cookie comes before the actual storage fails. - EXPECT_TRUE(got_can_set_cookie1_); + // Always get a call to CanSetCookie for the 1st network request due to + // the network cookie. + EXPECT_TRUE(got_can_set_cookie1_); + // Always get a call to CanGetCookies for the 2nd network request due to + // the JS cookie. + EXPECT_TRUE(got_can_get_cookies2_); - if (!server_backend_) { - // The callback to set the cookie comes before the actual storage fails. - EXPECT_TRUE(data1_.got_can_set_cookie_net_); - } else { - EXPECT_FALSE(data1_.got_can_set_cookie_net_); - } + // Always get the JS cookie via JS. + EXPECT_TRUE(got_cookie_js1_); + EXPECT_TRUE(got_cookie_js2_); + EXPECT_TRUE(got_cookie_js3_); - // No cookies stored anywhere. - EXPECT_FALSE(got_can_get_cookies2_); - EXPECT_FALSE(got_cookie_js1_); - EXPECT_FALSE(got_cookie_js2_); - EXPECT_FALSE(got_cookie_js3_); + // Only get the net cookie via JS if cookie write was allowed. + if (test_mode_ & BLOCK_WRITE) { EXPECT_FALSE(got_cookie_net1_); EXPECT_FALSE(got_cookie_net2_); EXPECT_FALSE(got_cookie_net3_); - EXPECT_FALSE(data1_.got_cookie_js_); - EXPECT_FALSE(data1_.got_cookie_net_); - EXPECT_FALSE(data1_.got_can_get_cookie_js_); - EXPECT_FALSE(data1_.got_can_get_cookie_net_); - EXPECT_FALSE(data1_.got_can_set_cookie_js_); + } else { + EXPECT_TRUE(got_cookie_net1_); + EXPECT_TRUE(got_cookie_net2_); + EXPECT_TRUE(got_cookie_net3_); + } + + // No cookies sent for the 1st network request. + EXPECT_FALSE(data1_.got_cookie_js_); + EXPECT_FALSE(data1_.got_cookie_net_); + + // 2nd network request... + if (test_mode_ & BLOCK_READ) { + // No cookies sent if reading was blocked. EXPECT_FALSE(data2_.got_cookie_js_); EXPECT_FALSE(data2_.got_cookie_net_); - EXPECT_FALSE(data2_.got_can_get_cookie_js_); - EXPECT_FALSE(data2_.got_can_get_cookie_net_); - EXPECT_FALSE(data2_.got_can_set_cookie_js_); - EXPECT_FALSE(data2_.got_can_set_cookie_net_); + } else if (test_mode_ & BLOCK_WRITE) { + // Only JS cookie sent if writing was blocked. + EXPECT_TRUE(data2_.got_cookie_js_); + EXPECT_FALSE(data2_.got_cookie_net_); } else { - EXPECT_FALSE(got_cookie_manager_); + // All cookies sent. + EXPECT_TRUE(data2_.got_cookie_js_); + EXPECT_TRUE(data2_.got_cookie_net_); + } - // Always get a call to CanSetCookie for the 1st network request due to - // the network cookie. - EXPECT_TRUE(got_can_set_cookie1_); - // Always get a call to CanGetCookies for the 2nd network request due to - // the JS cookie. - EXPECT_TRUE(got_can_get_cookies2_); + if (!server_backend_) { + // No query to get cookies with the 1st network request because none + // have been set yet. + EXPECT_FALSE(data1_.got_can_get_cookie_js_); + EXPECT_FALSE(data1_.got_can_get_cookie_net_); - // Always get the JS cookie via JS. - EXPECT_TRUE(got_cookie_js1_); - EXPECT_TRUE(got_cookie_js2_); - EXPECT_TRUE(got_cookie_js3_); + // JS cookie is not set via a network request. + EXPECT_FALSE(data1_.got_can_set_cookie_js_); + EXPECT_FALSE(data2_.got_can_set_cookie_js_); - // Only get the net cookie via JS if cookie write was allowed. + // No query to set the net cookie for the 1st network request if write + // was blocked. if (test_mode_ & BLOCK_WRITE) { - EXPECT_FALSE(got_cookie_net1_); - EXPECT_FALSE(got_cookie_net2_); - EXPECT_FALSE(got_cookie_net3_); + EXPECT_FALSE(data1_.got_can_set_cookie_net_); } else { - EXPECT_TRUE(got_cookie_net1_); - EXPECT_TRUE(got_cookie_net2_); - EXPECT_TRUE(got_cookie_net3_); + EXPECT_TRUE(data1_.got_can_set_cookie_net_); } - // No cookies sent for the 1st network request. - EXPECT_FALSE(data1_.got_cookie_js_); - EXPECT_FALSE(data1_.got_cookie_net_); + // Net cookie is not set via the 2nd network request. + EXPECT_FALSE(data2_.got_can_set_cookie_net_); - // 2nd network request... + // No query to get the JS cookie for the 2nd network request if read was + // blocked. if (test_mode_ & BLOCK_READ) { - // No cookies sent if reading was blocked. - EXPECT_FALSE(data2_.got_cookie_js_); - EXPECT_FALSE(data2_.got_cookie_net_); - } else if (test_mode_ & BLOCK_WRITE) { - // Only JS cookie sent if writing was blocked. - EXPECT_TRUE(data2_.got_cookie_js_); - EXPECT_FALSE(data2_.got_cookie_net_); + EXPECT_FALSE(data2_.got_can_get_cookie_js_); } else { - // All cookies sent. - EXPECT_TRUE(data2_.got_cookie_js_); - EXPECT_TRUE(data2_.got_cookie_net_); + EXPECT_TRUE(data2_.got_can_get_cookie_js_); } - if (!server_backend_) { - // No query to get cookies with the 1st network request because none - // have been set yet. - EXPECT_FALSE(data1_.got_can_get_cookie_js_); - EXPECT_FALSE(data1_.got_can_get_cookie_net_); - - // JS cookie is not set via a network request. - EXPECT_FALSE(data1_.got_can_set_cookie_js_); - EXPECT_FALSE(data2_.got_can_set_cookie_js_); - - // No query to set the net cookie for the 1st network request if write - // was blocked. - if (test_mode_ & BLOCK_WRITE) { - EXPECT_FALSE(data1_.got_can_set_cookie_net_); - } else { - EXPECT_TRUE(data1_.got_can_set_cookie_net_); - } - - // Net cookie is not set via the 2nd network request. - EXPECT_FALSE(data2_.got_can_set_cookie_net_); - - // No query to get the JS cookie for the 2nd network request if read was - // blocked. - if (test_mode_ & BLOCK_READ) { - EXPECT_FALSE(data2_.got_can_get_cookie_js_); - } else { - EXPECT_TRUE(data2_.got_can_get_cookie_js_); - } - - // No query to get the net cookie for the 2nd network request if read or - // write (of the net cookie) was blocked. - if (test_mode_ & (BLOCK_READ | BLOCK_WRITE)) { - EXPECT_FALSE(data2_.got_can_get_cookie_net_); - } else { - EXPECT_TRUE(data2_.got_can_get_cookie_net_); - } + // No query to get the net cookie for the 2nd network request if read or + // write (of the net cookie) was blocked. + if (test_mode_ & (BLOCK_READ | BLOCK_WRITE)) { + EXPECT_FALSE(data2_.got_can_get_cookie_net_); + } else { + EXPECT_TRUE(data2_.got_can_get_cookie_net_); } } @@ -2581,7 +2471,6 @@ class CookieAccessTestHandler : public RoutingTestHandler { TestMode test_mode_; bool server_backend_; - CefRefPtr context_handler_; CefRefPtr context_; CefRefPtr cookie_manager_; @@ -2645,14 +2534,6 @@ TEST(RequestHandlerTest, CookieAccessServerBlockReadWrite) { ReleaseAndWaitForDestructor(handler); } -// Block all cookies with server backend. -TEST(RequestHandlerTest, CookieAccessServerBlockAll) { - CefRefPtr handler = - new CookieAccessTestHandler(CookieAccessTestHandler::BLOCK_ALL, true); - handler->ExecuteTest(); - ReleaseAndWaitForDestructor(handler); -} - // Allow reading and writing of cookies with scheme handler backend. TEST(RequestHandlerTest, CookieAccessSchemeAllow) { CefRefPtr handler = @@ -2685,14 +2566,6 @@ TEST(RequestHandlerTest, CookieAccessSchemeBlockReadWrite) { ReleaseAndWaitForDestructor(handler); } -// Block all cookies with scheme handler backend. -TEST(RequestHandlerTest, CookieAccessSchemeBlockAll) { - CefRefPtr handler = - new CookieAccessTestHandler(CookieAccessTestHandler::BLOCK_ALL, false); - handler->ExecuteTest(); - ReleaseAndWaitForDestructor(handler); -} - // Entry point for creating request handler browser test objects. // Called from client_app_delegates.cc. void CreateRequestHandlerBrowserTests( diff --git a/tests/ceftests/urlrequest_unittest.cc b/tests/ceftests/urlrequest_unittest.cc index 98a878450..037db19dc 100644 --- a/tests/ceftests/urlrequest_unittest.cc +++ b/tests/ceftests/urlrequest_unittest.cc @@ -343,7 +343,7 @@ void SetTestCookie(CefRefPtr request_context, CefString(&cookie.domain) = GetRequestHost(server_backend, false); CefString(&cookie.path) = "/"; cookie.has_expires = false; - EXPECT_TRUE(request_context->GetDefaultCookieManager(NULL)->SetCookie( + EXPECT_TRUE(request_context->GetCookieManager(NULL)->SetCookie( GetRequestOrigin(server_backend), cookie, new Callback(callback))); } @@ -383,7 +383,7 @@ void GetTestCookie(CefRefPtr request_context, }; CefRefPtr cookie_manager = - request_context->GetDefaultCookieManager(NULL); + request_context->GetCookieManager(NULL); cookie_manager->VisitUrlCookies(GetRequestOrigin(server_backend), true, new Visitor(callback)); } @@ -2183,7 +2183,7 @@ class RequestTestHandler : public TestHandler { supported_schemes.push_back(GetRequestScheme(false)); // Continue the test once supported schemes has been set. - request_context->GetDefaultCookieManager(NULL)->SetSupportedSchemes( + request_context->GetCookieManager(NULL)->SetSupportedSchemes( supported_schemes, new SupportedSchemesCompletionCallback( base::Bind(&RequestTestHandler::PreSetupComplete, this))); diff --git a/tests/shared/common/client_switches.cc b/tests/shared/common/client_switches.cc index bf6e1ae0b..dab1d4c4b 100644 --- a/tests/shared/common/client_switches.cc +++ b/tests/shared/common/client_switches.cc @@ -30,7 +30,6 @@ const char kExternalBeginFrameEnabled[] = "external-begin-frame-enabled"; const char kMouseCursorChangeDisabled[] = "mouse-cursor-change-disabled"; const char kRequestContextPerBrowser[] = "request-context-per-browser"; const char kRequestContextSharedCache[] = "request-context-shared-cache"; -const char kRequestContextBlockCookies[] = "request-context-block-cookies"; const char kBackgroundColor[] = "background-color"; const char kEnableGPU[] = "enable-gpu"; const char kFilterURL[] = "filter-url"; diff --git a/tests/shared/common/client_switches.h b/tests/shared/common/client_switches.h index ef6bb4aa8..2c2cebac2 100644 --- a/tests/shared/common/client_switches.h +++ b/tests/shared/common/client_switches.h @@ -24,7 +24,6 @@ extern const char kExternalBeginFrameEnabled[]; extern const char kMouseCursorChangeDisabled[]; extern const char kRequestContextPerBrowser[]; extern const char kRequestContextSharedCache[]; -extern const char kRequestContextBlockCookies[]; extern const char kBackgroundColor[]; extern const char kEnableGPU[]; extern const char kFilterURL[];