Remove the old network implementation (see issue #2622)

The `--disable-features=NetworkService` flag is no longer supported.
This commit is contained in:
Marshall Greenblatt 2019-07-29 17:27:12 -04:00
parent ccb06ce3cb
commit 67b61c4af9
76 changed files with 296 additions and 6113 deletions

View File

@ -371,37 +371,15 @@ static_library("libcef_static") {
"libcef/browser/navigate_params.h", "libcef/browser/navigate_params.h",
"libcef/browser/navigation_entry_impl.cc", "libcef/browser/navigation_entry_impl.cc",
"libcef/browser/navigation_entry_impl.h", "libcef/browser/navigation_entry_impl.h",
"libcef/browser/net/browser_urlrequest_old_impl.cc",
"libcef/browser/net/browser_urlrequest_old_impl.h",
"libcef/browser/net/chrome_scheme_handler.cc", "libcef/browser/net/chrome_scheme_handler.cc",
"libcef/browser/net/chrome_scheme_handler.h", "libcef/browser/net/chrome_scheme_handler.h",
"libcef/browser/net/cookie_manager_old_impl.cc",
"libcef/browser/net/cookie_manager_old_impl.h",
"libcef/browser/net/crlset_file_util_impl.cc", "libcef/browser/net/crlset_file_util_impl.cc",
"libcef/browser/net/devtools_scheme_handler.cc", "libcef/browser/net/devtools_scheme_handler.cc",
"libcef/browser/net/devtools_scheme_handler.h", "libcef/browser/net/devtools_scheme_handler.h",
"libcef/browser/net/internal_scheme_handler.cc", "libcef/browser/net/internal_scheme_handler.cc",
"libcef/browser/net/internal_scheme_handler.h", "libcef/browser/net/internal_scheme_handler.h",
"libcef/browser/net/net_util.cc",
"libcef/browser/net/net_util.h",
"libcef/browser/net/network_delegate.cc",
"libcef/browser/net/network_delegate.h",
"libcef/browser/net/resource_request_job.cc",
"libcef/browser/net/resource_request_job.h",
"libcef/browser/net/scheme_handler.cc", "libcef/browser/net/scheme_handler.cc",
"libcef/browser/net/scheme_handler.h", "libcef/browser/net/scheme_handler.h",
"libcef/browser/net/source_stream.cc",
"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_interceptor.cc",
"libcef/browser/net/url_request_interceptor.h",
"libcef/browser/net/url_request_manager.cc",
"libcef/browser/net/url_request_manager.h",
"libcef/browser/net/url_request_user_data.cc",
"libcef/browser/net/url_request_user_data.h",
"libcef/browser/net_service/browser_urlrequest_impl.cc", "libcef/browser/net_service/browser_urlrequest_impl.cc",
"libcef/browser/net_service/browser_urlrequest_impl.h", "libcef/browser/net_service/browser_urlrequest_impl.h",
"libcef/browser/net_service/cookie_helper.cc", "libcef/browser/net_service/cookie_helper.cc",
@ -462,8 +440,6 @@ static_library("libcef_static") {
"libcef/browser/process_util_impl.cc", "libcef/browser/process_util_impl.cc",
"libcef/browser/resource_context.cc", "libcef/browser/resource_context.cc",
"libcef/browser/resource_context.h", "libcef/browser/resource_context.h",
"libcef/browser/resource_dispatcher_host_delegate.cc",
"libcef/browser/resource_dispatcher_host_delegate.h",
"libcef/browser/request_context_impl.cc", "libcef/browser/request_context_impl.cc",
"libcef/browser/request_context_impl.h", "libcef/browser/request_context_impl.h",
"libcef/browser/scheme_impl.cc", "libcef/browser/scheme_impl.cc",
@ -538,8 +514,6 @@ static_library("libcef_static") {
"libcef/common/net/upload_element.h", "libcef/common/net/upload_element.h",
"libcef/common/net_service/net_service_util.cc", "libcef/common/net_service/net_service_util.cc",
"libcef/common/net_service/net_service_util.h", "libcef/common/net_service/net_service_util.h",
"libcef/common/net_service/util.cc",
"libcef/common/net_service/util.h",
"libcef/common/parser_impl.cc", "libcef/common/parser_impl.cc",
"libcef/common/process_message_impl.cc", "libcef/common/process_message_impl.cc",
"libcef/common/process_message_impl.h", "libcef/common/process_message_impl.h",

View File

@ -17,7 +17,6 @@
#include "libcef/browser/thread_util.h" #include "libcef/browser/thread_util.h"
#include "libcef/common/cef_switches.h" #include "libcef/common/cef_switches.h"
#include "libcef/common/extensions/extensions_util.h" #include "libcef/common/extensions/extensions_util.h"
#include "libcef/common/net_service/util.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
@ -245,7 +244,7 @@ CefBrowserContext::~CefBrowserContext() {
if (resource_context_.get()) { if (resource_context_.get()) {
// Destruction of the ResourceContext will trigger destruction of all // Destruction of the ResourceContext will trigger destruction of all
// associated URLRequests. // associated network requests.
content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE,
resource_context_.release()); resource_context_.release());
} }
@ -258,8 +257,6 @@ CefBrowserContext::~CefBrowserContext() {
pref_proxy_config_tracker_->DetachFromPrefService(); pref_proxy_config_tracker_->DetachFromPrefService();
if (url_request_getter_)
url_request_getter_->ShutdownOnUIThread();
if (host_content_settings_map_) if (host_content_settings_map_)
host_content_settings_map_->ShutdownOnUIThread(); host_content_settings_map_->ShutdownOnUIThread();
@ -352,15 +349,6 @@ void CefBrowserContext::Initialize() {
ChromePluginServiceFilter::GetInstance()->RegisterResourceContext( ChromePluginServiceFilter::GetInstance()->RegisterResourceContext(
this, resource_context_.get()); 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::AddCefRequestContext(CefRequestContextImpl* context) { void CefBrowserContext::AddCefRequestContext(CefRequestContextImpl* context) {
@ -410,9 +398,8 @@ CefBrowserContext::GetClientHintsControllerDelegate() {
} }
net::URLRequestContextGetter* CefBrowserContext::GetRequestContext() { net::URLRequestContextGetter* CefBrowserContext::GetRequestContext() {
CEF_REQUIRE_UIT(); NOTREACHED() << "NetworkService is required";
DCHECK(!net_service::IsEnabled()); return nullptr;
return GetDefaultStoragePartition(this)->GetURLRequestContext();
} }
net::URLRequestContextGetter* CefBrowserContext::CreateMediaRequestContext() { net::URLRequestContextGetter* CefBrowserContext::CreateMediaRequestContext() {
@ -519,37 +506,8 @@ CefBrowserContext::GetBrowsingDataRemoverDelegate() {
net::URLRequestContextGetter* CefBrowserContext::CreateRequestContext( net::URLRequestContextGetter* CefBrowserContext::CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers, content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) { content::URLRequestInterceptorScopedVector request_interceptors) {
CEF_REQUIRE_UIT(); NOTREACHED() << "NetworkService is required";
DCHECK(!net_service::IsEnabled()); return nullptr;
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<net::ProxyConfigService> base_service(
net::ProxyResolutionService::CreateSystemProxyConfigService(
io_thread_runner));
std::unique_ptr<net::ProxyConfigService> 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* net::URLRequestContextGetter*
@ -742,7 +700,6 @@ void CefBrowserContext::ClearSchemeHandlerFactories() {
network::mojom::NetworkContext* CefBrowserContext::GetNetworkContext() { network::mojom::NetworkContext* CefBrowserContext::GetNetworkContext() {
CEF_REQUIRE_UIT(); CEF_REQUIRE_UIT();
DCHECK(net_service::IsEnabled());
return GetDefaultStoragePartition(this)->GetNetworkContext(); return GetDefaultStoragePartition(this)->GetNetworkContext();
} }

View File

@ -8,7 +8,6 @@
#include "include/cef_request_context_handler.h" #include "include/cef_request_context_handler.h"
#include "libcef/browser/chrome_profile_stub.h" #include "libcef/browser/chrome_profile_stub.h"
#include "libcef/browser/net/url_request_context_getter.h"
#include "libcef/browser/resource_context.h" #include "libcef/browser/resource_context.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
@ -47,33 +46,23 @@
// controlled indirectly by BC. // controlled indirectly by BC.
// //
// RC = CefResourceContext // RC = CefResourceContext
// Acts as a bridge for resource loading. URLRequest life span is tied to this // Acts as a bridge for resource loading. Network request life span is tied to
// object. Must be destroyed before the associated URCG. Life span is // this object. Must be destroyed before the associated URCG. Life span is
// controlled by BC. // controlled by BC.
// //
// 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.
//
// 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 URCG.
//
// //
// Relationship diagram: // Relationship diagram:
// ref = reference (CefRefPtr/scoped_refptr) // ref = reference (CefRefPtr/scoped_refptr)
// own = ownership (std::unique_ptr) // own = ownership (std::unique_ptr)
// ptr = raw pointer // ptr = raw pointer
// //
// CefBrowserMainParts--\ isolated cookie manager, etc. // CefBrowserMainParts
// | \ ^ // |
// own ref ref/own // own
// v v | // v
// BHI -own-> WC -ptr-> BC -own-> SPI -ref-> URCG --own-> URC // BHI -own-> WC -ptr-> BC -own-> SPI
// //
// BHI -ref-> RCI -own-> BC -own-> RC -ref-> URCG // BHI -ref-> RCI -own-> BC -own-> RC
// //
// //
// How shutdown works: // How shutdown works:
@ -86,13 +75,7 @@
// CefBrowserMainParts::PostMainMessageLoopRun(). // CefBrowserMainParts::PostMainMessageLoopRun().
// 4. CefResourceContext is destroyed asynchronously on the IO thread due to // 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. // network requests.
// 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 CefDownloadManagerDelegate;
@ -256,11 +239,6 @@ class CefBrowserContext : public ChromeProfileStub,
return extension_system_; return extension_system_;
} }
// Guaranteed to exist once this object has been initialized.
scoped_refptr<CefURLRequestContextGetter> request_context_getter() const {
return url_request_getter_;
}
// Called from DownloadPrefs::FromBrowserContext. // Called from DownloadPrefs::FromBrowserContext.
DownloadPrefs* GetDownloadPrefs(); DownloadPrefs* GetDownloadPrefs();
@ -284,7 +262,6 @@ class CefBrowserContext : public ChromeProfileStub,
std::unique_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_; std::unique_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;
std::unique_ptr<CefDownloadManagerDelegate> download_manager_delegate_; std::unique_ptr<CefDownloadManagerDelegate> download_manager_delegate_;
scoped_refptr<CefURLRequestContextGetter> url_request_getter_;
std::unique_ptr<CefSSLHostStateDelegate> ssl_host_state_delegate_; std::unique_ptr<CefSSLHostStateDelegate> ssl_host_state_delegate_;
scoped_refptr<HostContentSettingsMap> host_content_settings_map_; scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
std::unique_ptr<visitedlink::VisitedLinkMaster> visitedlink_master_; std::unique_ptr<visitedlink::VisitedLinkMaster> visitedlink_master_;

View File

@ -22,7 +22,6 @@
#include "libcef/common/extensions/extensions_client.h" #include "libcef/common/extensions/extensions_client.h"
#include "libcef/common/extensions/extensions_util.h" #include "libcef/common/extensions/extensions_util.h"
#include "libcef/common/net/net_resource_provider.h" #include "libcef/common/net/net_resource_provider.h"
#include "libcef/common/net_service/util.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
@ -128,12 +127,10 @@ void CefBrowserMainParts::PreMainMessageLoopStart() {
#endif #endif
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
if (net_service::IsEnabled()) { // Initialize the OSCrypt.
// Initialize the OSCrypt. PrefService* local_state = g_browser_process->local_state();
PrefService* local_state = g_browser_process->local_state(); DCHECK(local_state);
DCHECK(local_state); OSCrypt::Init(local_state);
OSCrypt::Init(local_state);
}
#endif #endif
for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
@ -162,10 +159,7 @@ int CefBrowserMainParts::PreCreateThreads() {
// Initialize these objects before IO access restrictions are applied and // Initialize these objects before IO access restrictions are applied and
// before the IO thread is started. // before the IO thread is started.
content::GpuDataManager::GetInstance(); content::GpuDataManager::GetInstance();
if (net_service::IsEnabled()) { SystemNetworkContextManager::CreateInstance(g_browser_process->local_state());
SystemNetworkContextManager::CreateInstance(
g_browser_process->local_state());
}
for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
chrome_extra_parts_[i]->PreCreateThreads(); chrome_extra_parts_[i]->PreCreateThreads();

View File

@ -6,7 +6,6 @@
#define CEF_LIBCEF_BROWSER_BROWSER_MAIN_H_ #define CEF_LIBCEF_BROWSER_BROWSER_MAIN_H_
#pragma once #pragma once
#include "libcef/browser/net/url_request_context_getter.h"
#include "libcef/browser/request_context_impl.h" #include "libcef/browser/request_context_impl.h"
#include "base/macros.h" #include "base/macros.h"
@ -14,7 +13,6 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "content/public/browser/browser_main_parts.h" #include "content/public/browser/browser_main_parts.h"
#include "net/url_request/url_request_context_getter.h"
namespace content { namespace content {
struct MainFunctionParams; struct MainFunctionParams;

View File

@ -11,7 +11,6 @@
#include "libcef/browser/prefs/browser_prefs.h" #include "libcef/browser/prefs/browser_prefs.h"
#include "libcef/browser/thread_util.h" #include "libcef/browser/thread_util.h"
#include "libcef/common/cef_switches.h" #include "libcef/common/cef_switches.h"
#include "libcef/common/net_service/util.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "chrome/browser/net/system_network_context_manager.h" #include "chrome/browser/net/system_network_context_manager.h"
@ -21,7 +20,6 @@
#include "chrome/browser/printing/print_preview_dialog_controller.h" #include "chrome/browser/printing/print_preview_dialog_controller.h"
#include "chrome/browser/ui/prefs/pref_watcher.h" #include "chrome/browser/ui/prefs/pref_watcher.h"
#include "components/net_log/chrome_net_log.h" #include "components/net_log/chrome_net_log.h"
#include "components/net_log/net_export_file_writer.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "content/browser/startup_helper.h" #include "content/browser/startup_helper.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
@ -79,7 +77,7 @@ void ChromeBrowserProcessStub::Shutdown() {
profile_manager_.reset(); profile_manager_.reset();
event_router_forwarder_ = nullptr; event_router_forwarder_ = nullptr;
if (net_service::IsEnabled() && SystemNetworkContextManager::GetInstance()) { if (SystemNetworkContextManager::GetInstance()) {
SystemNetworkContextManager::DeleteInstance(); SystemNetworkContextManager::DeleteInstance();
} }
@ -145,14 +143,6 @@ ChromeBrowserProcessStub::system_network_context_manager() {
return SystemNetworkContextManager::GetInstance(); return SystemNetworkContextManager::GetInstance();
} }
net_log::NetExportFileWriter*
ChromeBrowserProcessStub::net_export_file_writer() {
if (!net_export_file_writer_) {
net_export_file_writer_ = std::make_unique<net_log::NetExportFileWriter>();
}
return net_export_file_writer_.get();
}
network::NetworkQualityTracker* network::NetworkQualityTracker*
ChromeBrowserProcessStub::network_quality_tracker() { ChromeBrowserProcessStub::network_quality_tracker() {
NOTREACHED(); NOTREACHED();

View File

@ -47,7 +47,6 @@ class ChromeBrowserProcessStub : public BrowserProcess {
rappor::RapporServiceImpl* rappor_service() override; rappor::RapporServiceImpl* rappor_service() override;
IOThread* io_thread() override; IOThread* io_thread() override;
SystemNetworkContextManager* system_network_context_manager() override; SystemNetworkContextManager* system_network_context_manager() override;
net_log::NetExportFileWriter* net_export_file_writer() override;
network::NetworkQualityTracker* network_quality_tracker() override; network::NetworkQualityTracker* network_quality_tracker() override;
WatchDogThread* watchdog_thread() override; WatchDogThread* watchdog_thread() override;
ProfileManager* profile_manager() override; ProfileManager* profile_manager() override;
@ -122,7 +121,6 @@ class ChromeBrowserProcessStub : public BrowserProcess {
print_preview_dialog_controller_; print_preview_dialog_controller_;
std::unique_ptr<printing::BackgroundPrintingManager> std::unique_ptr<printing::BackgroundPrintingManager>
background_printing_manager_; background_printing_manager_;
std::unique_ptr<net_log::NetExportFileWriter> net_export_file_writer_;
std::unique_ptr<PrefService> local_state_; std::unique_ptr<PrefService> local_state_;
// Must be destroyed after |local_state_|. // Must be destroyed after |local_state_|.
std::unique_ptr<policy::ChromeBrowserPolicyConnector> std::unique_ptr<policy::ChromeBrowserPolicyConnector>

View File

@ -72,11 +72,8 @@ PrefService* ChromeProfileStub::GetOffTheRecordPrefs() {
base::OnceCallback<net::CookieStore*()> base::OnceCallback<net::CookieStore*()>
ChromeProfileStub::GetExtensionsCookieStoreGetter() { ChromeProfileStub::GetExtensionsCookieStoreGetter() {
return base::BindOnce( NOTREACHED();
[](scoped_refptr<net::URLRequestContextGetter> context) { return base::OnceCallback<net::CookieStore*()>();
return context->GetURLRequestContext()->cookie_store();
},
base::WrapRefCounted(GetRequestContext()));
} }
bool ChromeProfileStub::IsSameProfile(Profile* profile) { bool ChromeProfileStub::IsSameProfile(Profile* profile) {

View File

@ -21,14 +21,12 @@
#include "libcef/browser/extensions/extension_web_contents_observer.h" #include "libcef/browser/extensions/extension_web_contents_observer.h"
#include "libcef/browser/media_capture_devices_dispatcher.h" #include "libcef/browser/media_capture_devices_dispatcher.h"
#include "libcef/browser/net/chrome_scheme_handler.h" #include "libcef/browser/net/chrome_scheme_handler.h"
#include "libcef/browser/net/net_util.h"
#include "libcef/browser/net_service/login_delegate.h" #include "libcef/browser/net_service/login_delegate.h"
#include "libcef/browser/net_service/proxy_url_loader_factory.h" #include "libcef/browser/net_service/proxy_url_loader_factory.h"
#include "libcef/browser/net_service/resource_request_handler_wrapper.h" #include "libcef/browser/net_service/resource_request_handler_wrapper.h"
#include "libcef/browser/plugins/plugin_service_filter.h" #include "libcef/browser/plugins/plugin_service_filter.h"
#include "libcef/browser/prefs/renderer_prefs.h" #include "libcef/browser/prefs/renderer_prefs.h"
#include "libcef/browser/printing/printing_message_filter.h" #include "libcef/browser/printing/printing_message_filter.h"
#include "libcef/browser/resource_dispatcher_host_delegate.h"
#include "libcef/browser/speech_recognition_manager_delegate.h" #include "libcef/browser/speech_recognition_manager_delegate.h"
#include "libcef/browser/ssl_info_impl.h" #include "libcef/browser/ssl_info_impl.h"
#include "libcef/browser/thread_util.h" #include "libcef/browser/thread_util.h"
@ -39,7 +37,6 @@
#include "libcef/common/content_client.h" #include "libcef/common/content_client.h"
#include "libcef/common/extensions/extensions_util.h" #include "libcef/common/extensions/extensions_util.h"
#include "libcef/common/net/scheme_registration.h" #include "libcef/common/net/scheme_registration.h"
#include "libcef/common/net_service/util.h"
#include "libcef/common/request_impl.h" #include "libcef/common/request_impl.h"
#include "libcef/common/service_manifests/builtin_service_manifests.h" #include "libcef/common/service_manifests/builtin_service_manifests.h"
#include "libcef/common/service_manifests/cef_content_browser_overlay_manifest.h" #include "libcef/common/service_manifests/cef_content_browser_overlay_manifest.h"
@ -1087,13 +1084,6 @@ bool CefContentBrowserClient::CanCreateWindow(
user_gesture, opener_suppressed, no_javascript_access); user_gesture, opener_suppressed, no_javascript_access);
} }
void CefContentBrowserClient::ResourceDispatcherHostCreated() {
resource_dispatcher_host_delegate_.reset(
new CefResourceDispatcherHostDelegate());
content::ResourceDispatcherHost::Get()->SetDelegate(
resource_dispatcher_host_delegate_.get());
}
void CefContentBrowserClient::OverrideWebkitPrefs( void CefContentBrowserClient::OverrideWebkitPrefs(
content::RenderViewHost* rvh, content::RenderViewHost* rvh,
content::WebPreferences* prefs) { content::WebPreferences* prefs) {
@ -1171,12 +1161,9 @@ CefContentBrowserClient::CreateURLLoaderThrottles(
CEF_REQUIRE_IOT(); CEF_REQUIRE_IOT();
std::vector<std::unique_ptr<content::URLLoaderThrottle>> result; std::vector<std::unique_ptr<content::URLLoaderThrottle>> result;
if (net_service::IsEnabled()) { // Used to substitute View ID for PDF contents when using the PDF plugin.
// Used to substitute View ID for PDF contents when using the PDF plugin. result.push_back(std::make_unique<PluginResponseInterceptorURLLoaderThrottle>(
result.push_back( resource_context, request.resource_type, frame_tree_node_id));
std::make_unique<PluginResponseInterceptorURLLoaderThrottle>(
resource_context, request.resource_type, frame_tree_node_id));
}
return result; return result;
} }
@ -1324,9 +1311,6 @@ bool CefContentBrowserClient::WillCreateURLLoaderFactory(
network::mojom::URLLoaderFactoryRequest* factory_request, network::mojom::URLLoaderFactoryRequest* factory_request,
network::mojom::TrustedURLLoaderHeaderClientPtrInfo* header_client, network::mojom::TrustedURLLoaderHeaderClientPtrInfo* header_client,
bool* bypass_redirect_checks) { bool* bypass_redirect_checks) {
if (!net_service::IsEnabled())
return false;
auto request_handler = net_service::CreateInterceptedRequestHandler( auto request_handler = net_service::CreateInterceptedRequestHandler(
browser_context, frame, render_process_id, is_navigation, is_download, browser_context, frame, render_process_id, is_navigation, is_download,
request_initiator); request_initiator);
@ -1339,9 +1323,6 @@ bool CefContentBrowserClient::WillCreateURLLoaderFactory(
void CefContentBrowserClient::OnNetworkServiceCreated( void CefContentBrowserClient::OnNetworkServiceCreated(
network::mojom::NetworkService* network_service) { network::mojom::NetworkService* network_service) {
if (!net_service::IsEnabled())
return;
DCHECK(g_browser_process); DCHECK(g_browser_process);
PrefService* local_state = g_browser_process->local_state(); PrefService* local_state = g_browser_process->local_state();
DCHECK(local_state); DCHECK(local_state);
@ -1392,16 +1373,7 @@ bool CefContentBrowserClient::HandleExternalProtocol(
bool has_user_gesture, bool has_user_gesture,
network::mojom::URLLoaderFactoryRequest* factory_request, network::mojom::URLLoaderFactoryRequest* factory_request,
network::mojom::URLLoaderFactory*& out_factory) { network::mojom::URLLoaderFactory*& out_factory) {
if (net_service::IsEnabled()) { // Call the other HandleExternalProtocol variant.
// Call the other HandleExternalProtocol variant.
return false;
}
CefRefPtr<CefRequestImpl> requestPtr = new CefRequestImpl();
requestPtr->SetURL(url.spec());
requestPtr->SetReadOnly(true);
net_util::HandleExternalProtocol(requestPtr, web_contents_getter);
return false; return false;
} }
@ -1412,7 +1384,6 @@ bool CefContentBrowserClient::HandleExternalProtocol(
const network::ResourceRequest& request, const network::ResourceRequest& request,
network::mojom::URLLoaderFactoryRequest* factory_request, network::mojom::URLLoaderFactoryRequest* factory_request,
network::mojom::URLLoaderFactory*& out_factory) { network::mojom::URLLoaderFactory*& out_factory) {
DCHECK(net_service::IsEnabled());
// CefBrowserPlatformDelegate::HandleExternalProtocol may be called if // CefBrowserPlatformDelegate::HandleExternalProtocol may be called if
// nothing handles the request. // nothing handles the request.
auto request_handler = net_service::CreateInterceptedRequestHandler( auto request_handler = net_service::CreateInterceptedRequestHandler(
@ -1423,8 +1394,7 @@ bool CefContentBrowserClient::HandleExternalProtocol(
} }
std::string CefContentBrowserClient::GetProduct() const { std::string CefContentBrowserClient::GetProduct() const {
// Match the logic in chrome_content_browser_client.cc GetProduct() which // Match the logic in chrome_content_browser_client.cc GetProduct().
// will be called when the NetworkService is enabled.
return ::GetProduct(); return ::GetProduct();
} }
@ -1433,8 +1403,7 @@ std::string CefContentBrowserClient::GetChromeProduct() const {
} }
std::string CefContentBrowserClient::GetUserAgent() const { std::string CefContentBrowserClient::GetUserAgent() const {
// Match the logic in chrome_content_browser_client.cc GetUserAgent() which // Match the logic in chrome_content_browser_client.cc GetUserAgent().
// will be called when the NetworkService is enabled.
return ::GetUserAgent(); return ::GetUserAgent();
} }

View File

@ -10,7 +10,6 @@
#include <utility> #include <utility>
#include "include/cef_request_context_handler.h" #include "include/cef_request_context_handler.h"
#include "libcef/browser/net/url_request_context_getter.h"
#include "libcef/browser/request_context_impl.h" #include "libcef/browser/request_context_impl.h"
#include "base/macros.h" #include "base/macros.h"
@ -21,7 +20,6 @@
class CefBrowserMainParts; class CefBrowserMainParts;
class CefDevToolsDelegate; class CefDevToolsDelegate;
class CefResourceDispatcherHostDelegate;
namespace content { namespace content {
class PluginServiceFilter; class PluginServiceFilter;
@ -121,7 +119,6 @@ class CefContentBrowserClient : public content::ContentBrowserClient {
bool user_gesture, bool user_gesture,
bool opener_suppressed, bool opener_suppressed,
bool* no_javascript_access) override; bool* no_javascript_access) override;
void ResourceDispatcherHostCreated() override;
void OverrideWebkitPrefs(content::RenderViewHost* rvh, void OverrideWebkitPrefs(content::RenderViewHost* rvh,
content::WebPreferences* prefs) override; content::WebPreferences* prefs) override;
void BrowserURLHandlerCreated(content::BrowserURLHandler* handler) override; void BrowserURLHandlerCreated(content::BrowserURLHandler* handler) override;
@ -232,8 +229,6 @@ class CefContentBrowserClient : public content::ContentBrowserClient {
CefBrowserMainParts* browser_main_parts_; CefBrowserMainParts* browser_main_parts_;
std::unique_ptr<content::PluginServiceFilter> plugin_service_filter_; std::unique_ptr<content::PluginServiceFilter> plugin_service_filter_;
std::unique_ptr<CefResourceDispatcherHostDelegate>
resource_dispatcher_host_delegate_;
}; };
#endif // CEF_LIBCEF_BROWSER_CONTENT_BROWSER_CLIENT_H_ #endif // CEF_LIBCEF_BROWSER_CONTENT_BROWSER_CLIENT_H_

View File

@ -11,7 +11,6 @@
#include "libcef/browser/browser_context.h" #include "libcef/browser/browser_context.h"
#include "libcef/browser/devtools/devtools_manager_delegate.h" #include "libcef/browser/devtools/devtools_manager_delegate.h"
#include "libcef/browser/net/devtools_scheme_handler.h" #include "libcef/browser/net/devtools_scheme_handler.h"
#include "libcef/common/net_service/util.h"
#include "base/base64.h" #include "base/base64.h"
#include "base/guid.h" #include "base/guid.h"
@ -46,69 +45,11 @@
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "net/http/http_response_headers.h" #include "net/http/http_response_headers.h"
#include "net/traffic_annotation/network_traffic_annotation.h" #include "net/traffic_annotation/network_traffic_annotation.h"
#include "net/url_request/url_fetcher.h"
#include "net/url_request/url_fetcher_response_writer.h"
#include "services/network/public/cpp/simple_url_loader.h" #include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/cpp/simple_url_loader_stream_consumer.h" #include "services/network/public/cpp/simple_url_loader_stream_consumer.h"
namespace { namespace {
// ResponseWriter -------------------------------------------------------------
class ResponseWriter : public net::URLFetcherResponseWriter {
public:
ResponseWriter(base::WeakPtr<CefDevToolsFrontend> shell_devtools_,
int stream_id);
~ResponseWriter() override;
// URLFetcherResponseWriter overrides:
int Initialize(net::CompletionOnceCallback callback) override;
int Write(net::IOBuffer* buffer,
int num_bytes,
net::CompletionOnceCallback callback) override;
int Finish(int net_error, net::CompletionOnceCallback callback) override;
private:
base::WeakPtr<CefDevToolsFrontend> shell_devtools_;
int stream_id_;
DISALLOW_COPY_AND_ASSIGN(ResponseWriter);
};
ResponseWriter::ResponseWriter(
base::WeakPtr<CefDevToolsFrontend> shell_devtools,
int stream_id)
: shell_devtools_(shell_devtools), stream_id_(stream_id) {}
ResponseWriter::~ResponseWriter() {}
int ResponseWriter::Initialize(net::CompletionOnceCallback callback) {
return net::OK;
}
int ResponseWriter::Write(net::IOBuffer* buffer,
int num_bytes,
net::CompletionOnceCallback callback) {
std::string chunk = std::string(buffer->data(), num_bytes);
if (!base::IsStringUTF8(chunk))
return num_bytes;
base::Value* id = new base::Value(stream_id_);
base::Value* chunkValue = new base::Value(chunk);
base::PostTaskWithTraits(
FROM_HERE, {content::BrowserThread::UI},
base::BindOnce(&CefDevToolsFrontend::CallClientFunction, shell_devtools_,
"DevToolsAPI.streamWrite", base::Owned(id),
base::Owned(chunkValue), nullptr));
return num_bytes;
}
int ResponseWriter::Finish(int net_error,
net::CompletionOnceCallback callback) {
return net::OK;
}
static std::string GetFrontendURL() { static std::string GetFrontendURL() {
return base::StringPrintf("%s://%s/devtools_app.html", return base::StringPrintf("%s://%s/devtools_app.html",
content::kChromeDevToolsScheme, content::kChromeDevToolsScheme,
@ -279,10 +220,7 @@ CefDevToolsFrontend::CefDevToolsFrontend(
file_manager_(frontend_browser.get(), GetPrefs()), file_manager_(frontend_browser.get(), GetPrefs()),
weak_factory_(this) {} weak_factory_(this) {}
CefDevToolsFrontend::~CefDevToolsFrontend() { CefDevToolsFrontend::~CefDevToolsFrontend() {}
for (const auto& pair : pending_requests_)
delete pair.first;
}
void CefDevToolsFrontend::ReadyToCommitNavigation( void CefDevToolsFrontend::ReadyToCommitNavigation(
content::NavigationHandle* navigation_handle) { content::NavigationHandle* navigation_handle) {
@ -397,61 +335,43 @@ void CefDevToolsFrontend::HandleMessageFromDevToolsFrontend(
} }
})"); })");
if (net_service::IsEnabled()) { // Based on DevToolsUIBindings::LoadNetworkResource.
// Based on DevToolsUIBindings::LoadNetworkResource. auto resource_request = std::make_unique<network::ResourceRequest>();
auto resource_request = std::make_unique<network::ResourceRequest>(); resource_request->url = gurl;
resource_request->url = gurl; // TODO(caseq): this preserves behavior of URLFetcher-based
// TODO(caseq): this preserves behavior of URLFetcher-based // implementation. We really need to pass proper first party origin from
// implementation. We really need to pass proper first party origin from // the front-end.
// the front-end. resource_request->site_for_cookies = gurl;
resource_request->site_for_cookies = gurl; resource_request->headers.AddHeadersFromString(headers);
resource_request->headers.AddHeadersFromString(headers);
std::unique_ptr<network::mojom::URLLoaderFactory> file_url_loader_factory; std::unique_ptr<network::mojom::URLLoaderFactory> file_url_loader_factory;
scoped_refptr<network::SharedURLLoaderFactory> network_url_loader_factory; scoped_refptr<network::SharedURLLoaderFactory> network_url_loader_factory;
std::unique_ptr<network::mojom::URLLoaderFactory> std::unique_ptr<network::mojom::URLLoaderFactory> webui_url_loader_factory;
webui_url_loader_factory; network::mojom::URLLoaderFactory* url_loader_factory;
network::mojom::URLLoaderFactory* url_loader_factory; if (gurl.SchemeIsFile()) {
if (gurl.SchemeIsFile()) { file_url_loader_factory = content::CreateFileURLLoaderFactory(
file_url_loader_factory = content::CreateFileURLLoaderFactory( base::FilePath() /* profile_path */,
base::FilePath() /* profile_path */, nullptr /* shared_cors_origin_access_list */);
nullptr /* shared_cors_origin_access_list */); url_loader_factory = file_url_loader_factory.get();
url_loader_factory = file_url_loader_factory.get(); } else if (content::HasWebUIScheme(gurl)) {
} else if (content::HasWebUIScheme(gurl)) { base::DictionaryValue response;
base::DictionaryValue response; response.SetInteger("statusCode", 403);
response.SetInteger("statusCode", 403); SendMessageAck(request_id, &response);
SendMessageAck(request_id, &response); return;
return;
} else {
auto* partition = content::BrowserContext::GetStoragePartitionForSite(
web_contents()->GetBrowserContext(), gurl);
network_url_loader_factory =
partition->GetURLLoaderFactoryForBrowserProcess();
url_loader_factory = network_url_loader_factory.get();
}
auto simple_url_loader = network::SimpleURLLoader::Create(
std::move(resource_request), traffic_annotation);
auto resource_loader = std::make_unique<NetworkResourceLoader>(
stream_id, this, std::move(simple_url_loader), url_loader_factory,
request_id);
loaders_.insert(std::move(resource_loader));
} else { } else {
net::URLFetcher* fetcher = auto* partition = content::BrowserContext::GetStoragePartitionForSite(
net::URLFetcher::Create(gurl, net::URLFetcher::GET, this, web_contents()->GetBrowserContext(), gurl);
traffic_annotation) network_url_loader_factory =
.release(); partition->GetURLLoaderFactoryForBrowserProcess();
pending_requests_[fetcher] = request_id; url_loader_factory = network_url_loader_factory.get();
fetcher->SetRequestContext(
content::BrowserContext::GetDefaultStoragePartition(
web_contents()->GetBrowserContext())
->GetURLRequestContext());
fetcher->SetExtraRequestHeaders(headers);
fetcher->SaveResponseWithWriter(
std::unique_ptr<net::URLFetcherResponseWriter>(
new ResponseWriter(weak_factory_.GetWeakPtr(), stream_id)));
fetcher->Start();
} }
auto simple_url_loader = network::SimpleURLLoader::Create(
std::move(resource_request), traffic_annotation);
auto resource_loader = std::make_unique<NetworkResourceLoader>(
stream_id, this, std::move(simple_url_loader), url_loader_factory,
request_id);
loaders_.insert(std::move(resource_loader));
return; return;
} else if (method == "getPreferences") { } else if (method == "getPreferences") {
SendMessageAck(request_id, SendMessageAck(request_id,
@ -536,32 +456,6 @@ void CefDevToolsFrontend::DispatchProtocolMessage(
} }
} }
void CefDevToolsFrontend::OnURLFetchComplete(const net::URLFetcher* source) {
DCHECK(!net_service::IsEnabled());
// TODO(pfeldman): this is a copy of chrome's devtools_ui_bindings.cc.
// We should handle some of the commands including this one in content.
DCHECK(source);
PendingRequestsMap::iterator it = pending_requests_.find(source);
DCHECK(it != pending_requests_.end());
base::DictionaryValue response;
auto headers = std::make_unique<base::DictionaryValue>();
net::HttpResponseHeaders* rh = source->GetResponseHeaders();
response.SetInteger("statusCode", rh ? rh->response_code() : 200);
size_t iterator = 0;
std::string name;
std::string value;
while (rh && rh->EnumerateHeaderLines(&iterator, &name, &value))
headers->SetString(name, value);
response.Set("headers", std::move(headers));
SendMessageAck(it->second, &response);
pending_requests_.erase(it);
delete source;
}
void CefDevToolsFrontend::CallClientFunction(const std::string& function_name, void CefDevToolsFrontend::CallClientFunction(const std::string& function_name,
const base::Value* arg1, const base::Value* arg1,
const base::Value* arg2, const base::Value* arg2,

View File

@ -18,7 +18,6 @@
#include "content/public/browser/devtools_agent_host.h" #include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/devtools_frontend_host.h" #include "content/public/browser/devtools_frontend_host.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "net/url_request/url_fetcher_delegate.h"
namespace base { namespace base {
class Value; class Value;
@ -33,8 +32,7 @@ class WebContents;
class PrefService; class PrefService;
class CefDevToolsFrontend : public content::WebContentsObserver, class CefDevToolsFrontend : public content::WebContentsObserver,
public content::DevToolsAgentHostClient, public content::DevToolsAgentHostClient {
public net::URLFetcherDelegate {
public: public:
static CefDevToolsFrontend* Show( static CefDevToolsFrontend* Show(
CefRefPtr<CefBrowserHostImpl> inspected_browser, CefRefPtr<CefBrowserHostImpl> inspected_browser,
@ -78,9 +76,6 @@ class CefDevToolsFrontend : public content::WebContentsObserver,
void DocumentAvailableInMainFrame() override; void DocumentAvailableInMainFrame() override;
void WebContentsDestroyed() override; void WebContentsDestroyed() override;
// net::URLFetcherDelegate overrides.
void OnURLFetchComplete(const net::URLFetcher* source) override;
void SendMessageAck(int request_id, const base::Value* arg1); void SendMessageAck(int request_id, const base::Value* arg1);
PrefService* GetPrefs() const; PrefService* GetPrefs() const;
@ -91,9 +86,6 @@ class CefDevToolsFrontend : public content::WebContentsObserver,
CefPoint inspect_element_at_; CefPoint inspect_element_at_;
std::unique_ptr<content::DevToolsFrontendHost> frontend_host_; std::unique_ptr<content::DevToolsFrontendHost> frontend_host_;
using PendingRequestsMap = std::map<const net::URLFetcher*, int>;
PendingRequestsMap pending_requests_;
class NetworkResourceLoader; class NetworkResourceLoader;
std::set<std::unique_ptr<NetworkResourceLoader>, base::UniquePtrComparator> std::set<std::unique_ptr<NetworkResourceLoader>, base::UniquePtrComparator>
loaders_; loaders_;

View File

@ -319,8 +319,8 @@ void CefDownloadManagerDelegate::OnDownloadDestroyed(DownloadItem* item) {
void CefDownloadManagerDelegate::OnDownloadCreated(DownloadManager* manager, void CefDownloadManagerDelegate::OnDownloadCreated(DownloadManager* manager,
DownloadItem* item) { DownloadItem* item) {
// When NetworkService is enabled this callback may arrive after // This callback may arrive after DetermineDownloadTarget, so we allow
// DetermineDownloadTarget, so we allow association from either method. // association from either method.
CefRefPtr<CefBrowserHostImpl> browser = GetOrAssociateBrowser(item); CefRefPtr<CefBrowserHostImpl> browser = GetOrAssociateBrowser(item);
if (!browser) { if (!browser) {
// If the download is rejected (e.g. ALT+click on an invalid protocol link) // If the download is rejected (e.g. ALT+click on an invalid protocol link)
@ -356,8 +356,8 @@ bool CefDownloadManagerDelegate::DetermineDownloadTarget(
return true; return true;
} }
// When NetworkService is enabled this callback may arrive before // This callback may arrive before OnDownloadCreated, so we allow association
// OnDownloadCreated, so we allow association from either method. // from either method.
CefRefPtr<CefBrowserHostImpl> browser = GetOrAssociateBrowser(item); CefRefPtr<CefBrowserHostImpl> browser = GetOrAssociateBrowser(item);
CefRefPtr<CefDownloadHandler> handler; CefRefPtr<CefDownloadHandler> handler;
if (browser.get()) if (browser.get())

View File

@ -190,9 +190,8 @@ void CefExtensionSystem::Init() {
// mime type by the below call to AddExtension. // mime type by the below call to AddExtension.
// 3. A page requests a resource with the "application/pdf" mime type. For // 3. A page requests a resource with the "application/pdf" mime type. For
// example, by loading a PDF file. // example, by loading a PDF file.
// 4. CefResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream // 4. PluginResponseInterceptorURLLoaderThrottle intercepts the PDF resource
// or PluginResponseInterceptorURLLoaderThrottle (NetworkService) // load in the browser process, generates a
// intercepts the PDF resource load in the browser process, generates a
// unique View ID that is associated with the resource request for later // unique View ID that is associated with the resource request for later
// retrieval via MimeHandlerStreamManager and the // retrieval via MimeHandlerStreamManager and the
// chrome.mimeHandlerPrivate JS API (extensions/common/api/ // chrome.mimeHandlerPrivate JS API (extensions/common/api/
@ -213,10 +212,9 @@ void CefExtensionSystem::Init() {
// 8. Access to PDF extension resources is checked by // 8. Access to PDF extension resources is checked by
// CefExtensionsBrowserClient::AllowCrossRendererResourceLoad. // CefExtensionsBrowserClient::AllowCrossRendererResourceLoad.
// 9. PDF extension resources are provided from bundle via // 9. PDF extension resources are provided from bundle via
// CefExtensionsBrowserClient::MaybeCreateResourceBundleRequestJob or
// CefExtensionsBrowserClient::LoadResourceFromResourceBundle, // CefExtensionsBrowserClient::LoadResourceFromResourceBundle,
// CefContentBrowserClient::RegisterNonNetworkSubresourceURLLoaderFactories // CefContentBrowserClient::RegisterNonNetworkSubresourceURLLoaderFactories
// (NetworkService) and CefComponentExtensionResourceManager. // and CefComponentExtensionResourceManager.
// 10.The PDF extension (chrome/browser/resources/pdf/browser_api.js) calls // 10.The PDF extension (chrome/browser/resources/pdf/browser_api.js) calls
// chrome.mimeHandlerPrivate.getStreamInfo to retrieve the PDF resource // chrome.mimeHandlerPrivate.getStreamInfo to retrieve the PDF resource
// stream. This API is implemented using Mojo as described in // stream. This API is implemented using Mojo as described in

View File

@ -114,9 +114,8 @@ CefExtensionsBrowserClient::MaybeCreateResourceBundleRequestJob(
const base::FilePath& directory_path, const base::FilePath& directory_path,
const std::string& content_security_policy, const std::string& content_security_policy,
bool send_cors_header) { bool send_cors_header) {
return chrome_url_request_util::MaybeCreateURLRequestResourceBundleJob( NOTREACHED();
request, network_delegate, directory_path, content_security_policy, return nullptr;
send_cors_header);
} }
base::FilePath CefExtensionsBrowserClient::GetBundleResourcePath( base::FilePath CefExtensionsBrowserClient::GetBundleResourcePath(

View File

@ -10,11 +10,9 @@
#include "include/test/cef_test_helpers.h" #include "include/test/cef_test_helpers.h"
#include "libcef/browser/browser_host_impl.h" #include "libcef/browser/browser_host_impl.h"
#include "libcef/browser/navigate_params.h" #include "libcef/browser/navigate_params.h"
#include "libcef/browser/net/browser_urlrequest_old_impl.h"
#include "libcef/browser/net_service/browser_urlrequest_impl.h" #include "libcef/browser/net_service/browser_urlrequest_impl.h"
#include "libcef/common/cef_messages.h" #include "libcef/common/cef_messages.h"
#include "libcef/common/frame_util.h" #include "libcef/common/frame_util.h"
#include "libcef/common/net_service/util.h"
#include "libcef/common/process_message_impl.h" #include "libcef/common/process_message_impl.h"
#include "libcef/common/request_impl.h" #include "libcef/common/request_impl.h"
#include "libcef/common/task_runner_impl.h" #include "libcef/common/task_runner_impl.h"
@ -266,17 +264,10 @@ CefRefPtr<CefURLRequest> CefFrameHostImpl::CreateURLRequest(
auto request_context = browser->request_context(); auto request_context = browser->request_context();
if (net_service::IsEnabled()) { CefRefPtr<CefBrowserURLRequest> impl =
CefRefPtr<CefBrowserURLRequest> impl = new CefBrowserURLRequest(this, request, client, request_context);
new CefBrowserURLRequest(this, request, client, request_context); if (impl->Start())
if (impl->Start()) return impl.get();
return impl.get();
} else {
CefRefPtr<CefBrowserURLRequestOld> impl =
new CefBrowserURLRequestOld(request, client, request_context);
if (impl->Start())
return impl.get();
}
return nullptr; return nullptr;
} }

View File

@ -1,497 +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/browser_urlrequest_old_impl.h"
#include <string>
#include <utility>
#include "libcef/browser/browser_context.h"
#include "libcef/browser/content_browser_client.h"
#include "libcef/browser/net/url_request_user_data.h"
#include "libcef/browser/request_context_impl.h"
#include "libcef/browser/thread_util.h"
#include "libcef/common/request_impl.h"
#include "libcef/common/response_impl.h"
#include "libcef/common/task_runner_impl.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "base/strings/string_util.h"
#include "base/task/post_task.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/http/http_response_headers.h"
#include "net/url_request/url_fetcher.h"
#include "net/url_request/url_fetcher_delegate.h"
#include "net/url_request/url_fetcher_response_writer.h"
#include "net/url_request/url_request_status.h"
using content::BrowserThread;
namespace {
class CefURLFetcherDelegate : public net::URLFetcherDelegate {
public:
CefURLFetcherDelegate(CefBrowserURLRequestOld::Context* context,
int request_flags);
~CefURLFetcherDelegate() override;
// net::URLFetcherDelegate methods.
void OnURLFetchComplete(const net::URLFetcher* source) override;
void OnURLFetchDownloadProgress(const net::URLFetcher* source,
int64 current,
int64 total,
int64_t current_network_bytes) override;
void OnURLFetchUploadProgress(const net::URLFetcher* source,
int64 current,
int64 total) override;
private:
// The context_ pointer will outlive this object.
CefBrowserURLRequestOld::Context* context_;
int request_flags_;
};
class CefURLFetcherResponseWriter : public net::URLFetcherResponseWriter {
public:
CefURLFetcherResponseWriter(
CefRefPtr<CefBrowserURLRequestOld> url_request,
scoped_refptr<base::SequencedTaskRunner> task_runner)
: url_request_(url_request), task_runner_(task_runner) {}
// net::URLFetcherResponseWriter methods.
int Initialize(net::CompletionOnceCallback callback) override {
return net::OK;
}
int Write(net::IOBuffer* buffer,
int num_bytes,
net::CompletionOnceCallback callback) override {
if (url_request_.get()) {
task_runner_->PostTask(
FROM_HERE,
base::Bind(&CefURLFetcherResponseWriter::WriteOnClientThread,
url_request_, scoped_refptr<net::IOBuffer>(buffer),
num_bytes, base::Passed(std::move(callback)),
CefTaskRunnerImpl::GetCurrentTaskRunner()));
return net::ERR_IO_PENDING;
}
return num_bytes;
}
int Finish(int net_error, net::CompletionOnceCallback callback) override {
if (url_request_.get())
url_request_ = NULL;
return net::OK;
}
private:
static void WriteOnClientThread(
CefRefPtr<CefBrowserURLRequestOld> url_request,
scoped_refptr<net::IOBuffer> buffer,
int num_bytes,
net::CompletionOnceCallback callback,
scoped_refptr<base::SequencedTaskRunner> source_message_loop_proxy) {
CefRefPtr<CefURLRequestClient> client = url_request->GetClient();
if (client.get())
client->OnDownloadData(url_request.get(), buffer->data(), num_bytes);
source_message_loop_proxy->PostTask(
FROM_HERE,
base::Bind(&CefURLFetcherResponseWriter::ContinueOnSourceThread,
num_bytes, base::Passed(std::move(callback))));
}
static void ContinueOnSourceThread(int num_bytes,
net::CompletionOnceCallback callback) {
std::move(callback).Run(num_bytes);
}
CefRefPtr<CefBrowserURLRequestOld> url_request_;
scoped_refptr<base::SequencedTaskRunner> task_runner_;
DISALLOW_COPY_AND_ASSIGN(CefURLFetcherResponseWriter);
};
std::unique_ptr<base::SupportsUserData::Data> CreateURLRequestUserData(
CefRefPtr<CefURLRequestClient> client) {
return base::WrapUnique(new CefURLRequestUserData(client));
}
} // namespace
// CefBrowserURLRequestOld::Context
// ----------------------------------------------
class CefBrowserURLRequestOld::Context
: public base::RefCountedThreadSafe<CefBrowserURLRequestOld::Context> {
public:
Context(CefRefPtr<CefBrowserURLRequestOld> url_request,
CefRefPtr<CefRequest> request,
CefRefPtr<CefURLRequestClient> client,
CefRefPtr<CefRequestContext> request_context)
: url_request_(url_request),
request_(request),
client_(client),
request_context_(request_context),
task_runner_(CefTaskRunnerImpl::GetCurrentTaskRunner()),
status_(UR_IO_PENDING),
error_code_(ERR_NONE),
response_was_cached_(false),
upload_data_size_(0),
got_upload_progress_complete_(false) {
// Mark the request as read-only.
static_cast<CefRequestImpl*>(request_.get())->SetReadOnly(true);
}
inline bool CalledOnValidThread() {
return task_runner_->RunsTasksInCurrentSequence();
}
bool Start() {
DCHECK(CalledOnValidThread());
const GURL& url = GURL(request_->GetURL().ToString());
if (!url.is_valid())
return false;
const std::string& method =
base::ToLowerASCII(request_->GetMethod().ToString());
net::URLFetcher::RequestType request_type = net::URLFetcher::GET;
if (base::LowerCaseEqualsASCII(method, "get")) {
} else if (base::LowerCaseEqualsASCII(method, "post")) {
request_type = net::URLFetcher::POST;
} else if (base::LowerCaseEqualsASCII(method, "head")) {
request_type = net::URLFetcher::HEAD;
} else if (base::LowerCaseEqualsASCII(method, "delete")) {
request_type = net::URLFetcher::DELETE_REQUEST;
} else if (base::LowerCaseEqualsASCII(method, "put")) {
request_type = net::URLFetcher::PUT;
} else {
NOTREACHED() << "invalid request type";
return false;
}
base::PostTaskWithTraitsAndReply(
FROM_HERE, {BrowserThread::UI},
base::Bind(
&CefBrowserURLRequestOld::Context::GetRequestContextOnUIThread,
this),
base::Bind(
&CefBrowserURLRequestOld::Context::ContinueOnOriginatingThread,
this, url, request_type));
return true;
}
void GetRequestContextOnUIThread() {
CEF_REQUIRE_UIT();
// Get or create the request context and browser context.
CefRefPtr<CefRequestContextImpl> request_context_impl =
CefRequestContextImpl::GetOrCreateForRequestContext(request_context_);
DCHECK(request_context_impl.get());
CefBrowserContext* browser_context =
request_context_impl->GetBrowserContext();
DCHECK(browser_context);
if (!request_context_.get())
request_context_ = request_context_impl.get();
// The request context is created on the UI thread but accessed and
// destroyed on the IO thread.
url_request_getter_ = browser_context->GetRequestContext();
}
void ContinueOnOriginatingThread(const GURL& url,
net::URLFetcher::RequestType request_type) {
DCHECK(CalledOnValidThread());
int request_flags = request_->GetFlags();
fetcher_delegate_.reset(new CefURLFetcherDelegate(this, request_flags));
fetcher_ =
net::URLFetcher::Create(url, request_type, fetcher_delegate_.get());
DCHECK(url_request_getter_.get());
fetcher_->SetRequestContext(url_request_getter_.get());
static_cast<CefRequestImpl*>(request_.get())
->Get(*fetcher_, upload_data_size_);
fetcher_->SetURLRequestUserData(
CefURLRequestUserData::kUserDataKey,
base::Bind(&CreateURLRequestUserData, client_));
std::unique_ptr<net::URLFetcherResponseWriter> response_writer;
if (request_flags & UR_FLAG_NO_DOWNLOAD_DATA) {
response_writer.reset(new CefURLFetcherResponseWriter(NULL, NULL));
} else {
response_writer.reset(
new CefURLFetcherResponseWriter(url_request_, task_runner_));
}
fetcher_->SaveResponseWithWriter(std::move(response_writer));
fetcher_->Start();
}
void Cancel() {
DCHECK(CalledOnValidThread());
// The request may already be complete.
if (!fetcher_.get())
return;
// Cancel the fetch by deleting the fetcher.
fetcher_.reset(NULL);
status_ = UR_CANCELED;
error_code_ = ERR_ABORTED;
OnComplete();
}
void OnComplete() {
DCHECK(CalledOnValidThread());
if (fetcher_.get()) {
const net::URLRequestStatus& status = fetcher_->GetStatus();
if (status.is_success())
NotifyUploadProgressIfNecessary();
switch (status.status()) {
case net::URLRequestStatus::SUCCESS:
status_ = UR_SUCCESS;
break;
case net::URLRequestStatus::IO_PENDING:
status_ = UR_IO_PENDING;
break;
case net::URLRequestStatus::CANCELED:
status_ = UR_CANCELED;
break;
case net::URLRequestStatus::FAILED:
status_ = UR_FAILED;
break;
}
error_code_ = static_cast<CefURLRequest::ErrorCode>(status.error());
if (!response_.get())
OnResponse();
}
DCHECK(url_request_.get());
client_->OnRequestComplete(url_request_.get());
if (fetcher_.get())
fetcher_.reset(NULL);
// This may result in the Context object being deleted.
url_request_ = NULL;
}
void OnDownloadProgress(int64 current, int64 total) {
DCHECK(CalledOnValidThread());
DCHECK(url_request_.get());
if (!response_.get())
OnResponse();
NotifyUploadProgressIfNecessary();
client_->OnDownloadProgress(url_request_.get(), current, total);
}
void OnDownloadData(std::unique_ptr<std::string> download_data) {
DCHECK(CalledOnValidThread());
DCHECK(url_request_.get());
if (!response_.get())
OnResponse();
client_->OnDownloadData(url_request_.get(), download_data->c_str(),
download_data->length());
}
void OnUploadProgress(int64 current, int64 total) {
DCHECK(CalledOnValidThread());
DCHECK(url_request_.get());
if (current == total)
got_upload_progress_complete_ = true;
client_->OnUploadProgress(url_request_.get(), current, total);
}
CefRefPtr<CefRequest> request() const { return request_; }
CefRefPtr<CefURLRequestClient> client() const { return client_; }
CefURLRequest::Status status() const { return status_; }
CefURLRequest::ErrorCode error_code() const { return error_code_; }
CefRefPtr<CefResponse> response() const { return response_; }
bool response_was_cached() const { return response_was_cached_; }
private:
friend class base::RefCountedThreadSafe<CefBrowserURLRequestOld::Context>;
~Context() {
if (fetcher_.get()) {
// Delete the fetcher object on the thread that created it.
task_runner_->DeleteSoon(FROM_HERE, fetcher_.release());
}
}
void NotifyUploadProgressIfNecessary() {
if (!got_upload_progress_complete_ && upload_data_size_ > 0) {
// URLFetcher sends upload notifications using a timer and will not send
// a notification if the request completes too quickly. We therefore
// send the notification here if necessary.
client_->OnUploadProgress(url_request_.get(), upload_data_size_,
upload_data_size_);
got_upload_progress_complete_ = true;
}
}
void OnResponse() {
if (fetcher_.get()) {
response_was_cached_ = fetcher_->WasCached();
response_ = new CefResponseImpl();
CefResponseImpl* responseImpl =
static_cast<CefResponseImpl*>(response_.get());
responseImpl->SetURL(fetcher_->GetURL().spec());
responseImpl->SetStatus(fetcher_->GetResponseCode());
net::HttpResponseHeaders* headers = fetcher_->GetResponseHeaders();
if (headers)
responseImpl->SetResponseHeaders(*headers);
responseImpl->SetReadOnly(true);
}
}
// Members only accessed on the initialization thread.
CefRefPtr<CefBrowserURLRequestOld> url_request_;
CefRefPtr<CefRequest> request_;
CefRefPtr<CefURLRequestClient> client_;
CefRefPtr<CefRequestContext> request_context_;
scoped_refptr<base::SequencedTaskRunner> task_runner_;
std::unique_ptr<net::URLFetcher> fetcher_;
std::unique_ptr<CefURLFetcherDelegate> fetcher_delegate_;
CefURLRequest::Status status_;
CefURLRequest::ErrorCode error_code_;
CefRefPtr<CefResponse> response_;
bool response_was_cached_;
int64 upload_data_size_;
bool got_upload_progress_complete_;
scoped_refptr<net::URLRequestContextGetter> url_request_getter_;
};
// CefURLFetcherDelegate ------------------------------------------------------
namespace {
CefURLFetcherDelegate::CefURLFetcherDelegate(
CefBrowserURLRequestOld::Context* context,
int request_flags)
: context_(context), request_flags_(request_flags) {}
CefURLFetcherDelegate::~CefURLFetcherDelegate() {}
void CefURLFetcherDelegate::OnURLFetchComplete(const net::URLFetcher* source) {
// Complete asynchronously so as not to delete the URLFetcher while it's still
// in the call stack.
CefTaskRunnerImpl::GetCurrentTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&CefBrowserURLRequestOld::Context::OnComplete, context_));
}
void CefURLFetcherDelegate::OnURLFetchDownloadProgress(
const net::URLFetcher* source,
int64 current,
int64 total,
int64_t current_network_bytes) {
context_->OnDownloadProgress(current, total);
}
void CefURLFetcherDelegate::OnURLFetchUploadProgress(
const net::URLFetcher* source,
int64 current,
int64 total) {
if (request_flags_ & UR_FLAG_REPORT_UPLOAD_PROGRESS)
context_->OnUploadProgress(current, total);
}
} // namespace
// CefBrowserURLRequestOld
// -------------------------------------------------------
CefBrowserURLRequestOld::CefBrowserURLRequestOld(
CefRefPtr<CefRequest> request,
CefRefPtr<CefURLRequestClient> client,
CefRefPtr<CefRequestContext> request_context) {
context_ = new Context(this, request, client, request_context);
}
CefBrowserURLRequestOld::~CefBrowserURLRequestOld() {}
bool CefBrowserURLRequestOld::Start() {
if (!VerifyContext())
return false;
return context_->Start();
}
CefRefPtr<CefRequest> CefBrowserURLRequestOld::GetRequest() {
if (!VerifyContext())
return NULL;
return context_->request();
}
CefRefPtr<CefURLRequestClient> CefBrowserURLRequestOld::GetClient() {
if (!VerifyContext())
return NULL;
return context_->client();
}
CefURLRequest::Status CefBrowserURLRequestOld::GetRequestStatus() {
if (!VerifyContext())
return UR_UNKNOWN;
return context_->status();
}
CefURLRequest::ErrorCode CefBrowserURLRequestOld::GetRequestError() {
if (!VerifyContext())
return ERR_NONE;
return context_->error_code();
}
CefRefPtr<CefResponse> CefBrowserURLRequestOld::GetResponse() {
if (!VerifyContext())
return NULL;
return context_->response();
}
bool CefBrowserURLRequestOld::ResponseWasCached() {
if (!VerifyContext())
return false;
return context_->response_was_cached();
}
void CefBrowserURLRequestOld::Cancel() {
if (!VerifyContext())
return;
return context_->Cancel();
}
bool CefBrowserURLRequestOld::VerifyContext() {
DCHECK(context_.get());
if (!context_->CalledOnValidThread()) {
NOTREACHED() << "called on invalid thread";
return false;
}
return true;
}

View File

@ -1,40 +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_BROWSER_URLREQUEST_OLD_IMPL_H_
#define CEF_LIBCEF_BROWSER_NET_BROWSER_URLREQUEST_OLD_IMPL_H_
#include "include/cef_urlrequest.h"
#include "base/memory/ref_counted.h"
class CefBrowserURLRequestOld : public CefURLRequest {
public:
class Context;
CefBrowserURLRequestOld(CefRefPtr<CefRequest> request,
CefRefPtr<CefURLRequestClient> client,
CefRefPtr<CefRequestContext> request_context);
~CefBrowserURLRequestOld() override;
bool Start();
// CefURLRequest methods.
CefRefPtr<CefRequest> GetRequest() override;
CefRefPtr<CefURLRequestClient> GetClient() override;
Status GetRequestStatus() override;
ErrorCode GetRequestError() override;
CefRefPtr<CefResponse> GetResponse() override;
bool ResponseWasCached() override;
void Cancel() override;
private:
bool VerifyContext();
scoped_refptr<Context> context_;
IMPLEMENT_REFCOUNTING(CefBrowserURLRequestOld);
};
#endif // CEF_LIBCEF_BROWSER_NET_BROWSER_URLREQUEST_OLD_IMPL_H_

View File

@ -16,7 +16,6 @@
#include "libcef/browser/extensions/chrome_api_registration.h" #include "libcef/browser/extensions/chrome_api_registration.h"
#include "libcef/browser/frame_host_impl.h" #include "libcef/browser/frame_host_impl.h"
#include "libcef/browser/net/internal_scheme_handler.h" #include "libcef/browser/net/internal_scheme_handler.h"
#include "libcef/browser/net/url_request_manager.h"
#include "libcef/browser/thread_util.h" #include "libcef/browser/thread_util.h"
#include "libcef/common/content_client.h" #include "libcef/common/content_client.h"
@ -43,7 +42,6 @@
#include "content/public/common/url_utils.h" #include "content/public/common/url_utils.h"
#include "content/public/common/user_agent.h" #include "content/public/common/user_agent.h"
#include "ipc/ipc_channel.h" #include "ipc/ipc_channel.h"
#include "net/url_request/url_request.h"
#include "v8/include/v8.h" #include "v8/include/v8.h"
using extensions::api::cef::kSupportedAPIs; using extensions::api::cef::kSupportedAPIs;
@ -171,31 +169,6 @@ const char* kAllowedDebugURLs[] = {
content::kChromeUIBrowserCrashURL, content::kChromeUIBrowserCrashURL,
}; };
// Returns true for debug URLs that receive special handling (for crashes, etc).
bool IsDebugURL(const GURL& url) {
// URLs handled by the renderer process in
// content/renderer/render_frame_impl.cc MaybeHandleDebugURL().
if (content::IsRendererDebugURL(url))
return true;
// Also include URLs handled by the browser process in
// content/browser/frame_host/debug_urls.cc HandleDebugURL().
for (size_t i = 0; i < chrome::kNumberOfChromeDebugURLs; ++i) {
GURL host(chrome::kChromeDebugURLs[i]);
if (url.GetOrigin() == host.GetOrigin())
return true;
}
for (size_t i = 0;
i < sizeof(kAllowedDebugURLs) / sizeof(kAllowedDebugURLs[0]); ++i) {
GURL host(kAllowedDebugURLs[i]);
if (url.GetOrigin() == host.GetOrigin())
return true;
}
return false;
}
void GetDebugURLs(std::vector<std::string>* urls) { void GetDebugURLs(std::vector<std::string>* urls) {
for (size_t i = 0; i < chrome::kNumberOfChromeDebugURLs; ++i) { for (size_t i = 0; i < chrome::kNumberOfChromeDebugURLs; ++i) {
urls->push_back(chrome::kChromeDebugURLs[i]); urls->push_back(chrome::kChromeDebugURLs[i]);
@ -791,43 +764,6 @@ void DidFinishChromeVersionLoad(CefRefPtr<CefFrame> frame) {
CefVisitWebPluginInfo(new Visitor(frame)); CefVisitWebPluginInfo(new Visitor(frame));
} }
// Wrapper for a ChromeProtocolHandler instance from
// content/browser/webui/url_data_manager_backend.cc.
class ChromeProtocolHandlerWrapper
: public net::URLRequestJobFactory::ProtocolHandler {
public:
ChromeProtocolHandlerWrapper(
CefURLRequestManager* request_manager,
std::unique_ptr<net::URLRequestJobFactory::ProtocolHandler>
chrome_protocol_handler)
: request_manager_(request_manager),
chrome_protocol_handler_(std::move(chrome_protocol_handler)) {
DCHECK(request_manager_);
}
net::URLRequestJob* MaybeCreateJob(
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const override {
// Don't handle debug URLs.
if (IsDebugURL(request->url()))
return nullptr;
// Only allow WebUI to handle chrome:// URLs whitelisted by CEF.
if (CefWebUIControllerFactory::AllowWebUIForURL(request->url())) {
return chrome_protocol_handler_->MaybeCreateJob(request,
network_delegate);
}
// Use the protocol handler registered with CEF.
return request_manager_->GetRequestJob(request, network_delegate);
}
private:
CefURLRequestManager* request_manager_;
std::unique_ptr<net::URLRequestJobFactory::ProtocolHandler>
chrome_protocol_handler_;
};
} // namespace } // namespace
void RegisterWebUIControllerFactory() { void RegisterWebUIControllerFactory() {
@ -858,15 +794,4 @@ bool IsWebUIAllowedToMakeNetworkRequests(const url::Origin& origin) {
return CefWebUIControllerFactory::IsWebUIAllowedToMakeNetworkRequests(origin); return CefWebUIControllerFactory::IsWebUIAllowedToMakeNetworkRequests(origin);
} }
std::unique_ptr<net::URLRequestJobFactory::ProtocolHandler>
WrapChromeProtocolHandler(
CefURLRequestManager* request_manager,
std::unique_ptr<net::URLRequestJobFactory::ProtocolHandler>
chrome_protocol_handler) {
std::unique_ptr<net::URLRequestJobFactory::ProtocolHandler> ret(
new ChromeProtocolHandlerWrapper(request_manager,
std::move(chrome_protocol_handler)));
return ret;
}
} // namespace scheme } // namespace scheme

View File

@ -12,7 +12,6 @@
#include "include/cef_frame.h" #include "include/cef_frame.h"
#include "include/cef_process_message.h" #include "include/cef_process_message.h"
#include "net/url_request/url_request_job_factory.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace base { namespace base {
@ -27,8 +26,6 @@ namespace url {
class Origin; class Origin;
} }
class CefURLRequestManager;
namespace scheme { namespace scheme {
extern const char kChromeURL[]; extern const char kChromeURL[];
@ -45,14 +42,6 @@ void DidFinishChromeLoad(CefRefPtr<CefFrame> frame, const GURL& validated_url);
// Returns true if WebUI is allowed to make network requests. // Returns true if WebUI is allowed to make network requests.
bool IsWebUIAllowedToMakeNetworkRequests(const url::Origin& origin); bool IsWebUIAllowedToMakeNetworkRequests(const url::Origin& origin);
// Create a new ProtocolHandler that will filter the URLs passed to the default
// "chrome" protocol handler and forward the rest to CEF's handler.
std::unique_ptr<net::URLRequestJobFactory::ProtocolHandler>
WrapChromeProtocolHandler(
CefURLRequestManager* request_manager,
std::unique_ptr<net::URLRequestJobFactory::ProtocolHandler>
chrome_protocol_handler);
} // namespace scheme } // namespace scheme
#endif // CEF_LIBCEF_BROWSER_CHROME_SCHEME_HANDLER_H_ #endif // CEF_LIBCEF_BROWSER_CHROME_SCHEME_HANDLER_H_

View File

@ -1,475 +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/cookie_manager_old_impl.h"
#include <set>
#include <string>
#include <vector>
#include "libcef/browser/content_browser_client.h"
#include "libcef/browser/context.h"
#include "libcef/browser/net/network_delegate.h"
#include "libcef/common/net_service/net_service_util.h"
#include "libcef/common/task_runner_impl.h"
#include "libcef/common/time_util.h"
#include "base/bind.h"
#include "base/format_macros.h"
#include "base/logging.h"
#include "base/threading/thread_restrictions.h"
#include "chrome/browser/browser_process.h"
#include "components/net_log/chrome_net_log.h"
#include "content/browser/storage_partition_impl.h"
#include "content/public/browser/browser_task_traits.h"
#include "net/url_request/url_request_context.h"
#include "url/gurl.h"
using content::BrowserThread;
namespace {
// Callback class for visiting cookies.
class VisitCookiesCallback
: public base::RefCountedThreadSafe<VisitCookiesCallback> {
public:
explicit VisitCookiesCallback(
const CefCookieManagerOldImpl::CookieStoreGetter& cookie_store_getter,
CefRefPtr<CefCookieVisitor> visitor)
: cookie_store_getter_(cookie_store_getter), visitor_(visitor) {}
void Run(const net::CookieList& list,
const net::CookieStatusList& excluded_list) {
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(CEF_UIT, base::Bind(&VisitCookiesCallback::Run, this, list,
excluded_list));
return;
}
int total = list.size(), count = 0;
net::CookieList::const_iterator it = list.begin();
for (; it != list.end(); ++it, ++count) {
CefCookie cookie;
const net::CanonicalCookie& cc = *(it);
net_service::MakeCefCookie(cc, cookie);
bool deleteCookie = false;
bool keepLooping = visitor_->Visit(cookie, count, total, deleteCookie);
if (deleteCookie) {
CEF_POST_TASK(
CEF_IOT,
base::Bind(&VisitCookiesCallback::DeleteOnIOThread, this, cc));
}
if (!keepLooping)
break;
}
}
private:
friend class base::RefCountedThreadSafe<VisitCookiesCallback>;
~VisitCookiesCallback() {}
void DeleteOnIOThread(const net::CanonicalCookie& cc) {
net::CookieStore* cookie_store = cookie_store_getter_.Run();
if (cookie_store) {
cookie_store->DeleteCanonicalCookieAsync(
cc, net::CookieMonster::DeleteCallback());
}
}
CefCookieManagerOldImpl::CookieStoreGetter cookie_store_getter_;
CefRefPtr<CefCookieVisitor> visitor_;
};
// Always execute the callback asynchronously.
void RunAsyncCompletionOnUIThread(CefRefPtr<CefCompletionCallback> callback) {
if (!callback.get())
return;
CEF_POST_TASK(CEF_UIT,
base::Bind(&CefCompletionCallback::OnComplete, callback.get()));
}
// Always execute the callback asynchronously.
void DeleteCookiesCallbackImpl(CefRefPtr<CefDeleteCookiesCallback> callback,
uint32_t num_deleted) {
if (!callback.get())
return;
CEF_POST_TASK(CEF_UIT, base::Bind(&CefDeleteCookiesCallback::OnComplete,
callback.get(), num_deleted));
}
// Always execute the callback asynchronously.
void SetCookieCallbackImpl(CefRefPtr<CefSetCookieCallback> callback,
net::CanonicalCookie::CookieInclusionStatus status) {
if (!callback.get())
return;
CEF_POST_TASK(
CEF_UIT,
base::Bind(
&CefSetCookieCallback::OnComplete, callback.get(),
status == net::CanonicalCookie::CookieInclusionStatus::INCLUDE));
}
} // namespace
CefCookieManagerOldImpl::CefCookieManagerOldImpl() {}
CefCookieManagerOldImpl::~CefCookieManagerOldImpl() {
CEF_REQUIRE_IOT();
}
void CefCookieManagerOldImpl::Initialize(
CefRefPtr<CefRequestContextImpl> request_context,
const CefString& path,
bool persist_session_cookies,
CefRefPtr<CefCompletionCallback> callback) {
DCHECK(request_context.get());
request_context_ = request_context;
request_context_->GetRequestContextImpl(
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}),
base::Bind(&CefCookieManagerOldImpl::InitWithContext, this, callback));
}
void CefCookieManagerOldImpl::GetCookieStore(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
const CookieStoreCallback& callback) {
if (!task_runner.get())
task_runner = CefTaskRunnerImpl::GetCurrentTaskRunner();
if (!CEF_CURRENTLY_ON_IOT()) {
CEF_POST_TASK(CEF_IOT, base::Bind(&CefCookieManagerOldImpl::GetCookieStore,
this, task_runner, callback));
return;
}
RunMethodWithContext(
base::Bind(&CefCookieManagerOldImpl::GetCookieStoreWithContext, this,
task_runner, callback));
}
net::CookieStore* CefCookieManagerOldImpl::GetExistingCookieStore() {
CEF_REQUIRE_IOT();
if (request_context_impl_.get()) {
net::CookieStore* cookie_store =
request_context_impl_->GetExistingCookieStore();
DCHECK(cookie_store);
return cookie_store;
}
LOG(ERROR) << "Cookie store does not exist";
return nullptr;
}
void CefCookieManagerOldImpl::SetSupportedSchemes(
const std::vector<CefString>& schemes,
bool include_defaults,
CefRefPtr<CefCompletionCallback> callback) {
if (!CEF_CURRENTLY_ON_IOT()) {
CEF_POST_TASK(
CEF_IOT, base::Bind(&CefCookieManagerOldImpl::SetSupportedSchemes, this,
schemes, include_defaults, callback));
return;
}
std::vector<std::string> scheme_set;
std::vector<CefString>::const_iterator it = schemes.begin();
for (; it != schemes.end(); ++it)
scheme_set.push_back(*it);
SetSupportedSchemesInternal(scheme_set, include_defaults, callback);
}
bool CefCookieManagerOldImpl::VisitAllCookies(
CefRefPtr<CefCookieVisitor> visitor) {
GetCookieStore(
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}),
base::Bind(&CefCookieManagerOldImpl::VisitAllCookiesInternal, this,
visitor));
return true;
}
bool CefCookieManagerOldImpl::VisitUrlCookies(
const CefString& url,
bool includeHttpOnly,
CefRefPtr<CefCookieVisitor> visitor) {
GetCookieStore(
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}),
base::Bind(&CefCookieManagerOldImpl::VisitUrlCookiesInternal, this, url,
includeHttpOnly, visitor));
return true;
}
bool CefCookieManagerOldImpl::SetCookie(
const CefString& url,
const CefCookie& cookie,
CefRefPtr<CefSetCookieCallback> callback) {
GURL gurl = GURL(url.ToString());
if (!gurl.is_valid())
return false;
GetCookieStore(
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}),
base::Bind(&CefCookieManagerOldImpl::SetCookieInternal, this, gurl,
cookie, callback));
return true;
}
bool CefCookieManagerOldImpl::DeleteCookies(
const CefString& url,
const CefString& cookie_name,
CefRefPtr<CefDeleteCookiesCallback> callback) {
// Empty URLs are allowed but not invalid URLs.
GURL gurl = GURL(url.ToString());
if (!gurl.is_empty() && !gurl.is_valid())
return false;
GetCookieStore(
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}),
base::Bind(&CefCookieManagerOldImpl::DeleteCookiesInternal, this, gurl,
cookie_name, callback));
return true;
}
bool CefCookieManagerOldImpl::FlushStore(
CefRefPtr<CefCompletionCallback> callback) {
GetCookieStore(
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}),
base::Bind(&CefCookieManagerOldImpl::FlushStoreInternal, this, callback));
return true;
}
// static
void CefCookieManagerOldImpl::SetCookieMonsterSchemes(
net::CookieMonster* cookie_monster,
const std::vector<std::string>& schemes,
bool include_defaults) {
CEF_REQUIRE_IOT();
std::vector<std::string> all_schemes = schemes;
if (include_defaults) {
// Add default schemes that should always support cookies.
all_schemes.push_back("http");
all_schemes.push_back("https");
all_schemes.push_back("ws");
all_schemes.push_back("wss");
}
cookie_monster->SetCookieableSchemes(
all_schemes, net::CookieStore::SetCookieableSchemesCallback());
}
void CefCookieManagerOldImpl::RunMethodWithContext(
const CefRequestContextImpl::RequestContextCallback& method) {
CEF_REQUIRE_IOT();
if (request_context_impl_.get()) {
method.Run(request_context_impl_);
} else if (request_context_.get()) {
// Try again after the request context is initialized.
request_context_->GetRequestContextImpl(
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}),
method);
} else {
NOTREACHED();
}
}
void CefCookieManagerOldImpl::InitWithContext(
CefRefPtr<CefCompletionCallback> callback,
scoped_refptr<CefURLRequestContextGetter> request_context) {
CEF_REQUIRE_IOT();
DCHECK(!request_context_impl_.get());
request_context_impl_ = request_context;
// Clear the CefRequestContextImpl reference here to avoid a potential
// reference loop between CefRequestContextImpl (which has a reference to
// CefRequestContextHandler), CefRequestContextHandler (which may keep a
// reference to this object) and this object.
request_context_ = NULL;
RunAsyncCompletionOnUIThread(callback);
}
void CefCookieManagerOldImpl::SetSupportedSchemesWithContext(
const std::vector<std::string>& schemes,
bool include_defaults,
CefRefPtr<CefCompletionCallback> callback,
scoped_refptr<CefURLRequestContextGetter> request_context) {
CEF_REQUIRE_IOT();
request_context->SetCookieSupportedSchemes(schemes, include_defaults);
RunAsyncCompletionOnUIThread(callback);
}
void CefCookieManagerOldImpl::GetCookieStoreWithContext(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
const CookieStoreCallback& callback,
scoped_refptr<CefURLRequestContextGetter> request_context) {
CEF_REQUIRE_IOT();
DCHECK(request_context->GetExistingCookieStore());
const CookieStoreGetter& cookie_store_getter = base::Bind(
&CefURLRequestContextGetter::GetExistingCookieStore, request_context);
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));
}
}
void CefCookieManagerOldImpl::SetSupportedSchemesInternal(
const std::vector<std::string>& schemes,
bool include_defaults,
CefRefPtr<CefCompletionCallback> callback) {
CEF_REQUIRE_IOT();
RunMethodWithContext(
base::Bind(&CefCookieManagerOldImpl::SetSupportedSchemesWithContext, this,
schemes, include_defaults, callback));
}
void CefCookieManagerOldImpl::VisitAllCookiesInternal(
CefRefPtr<CefCookieVisitor> visitor,
const CookieStoreGetter& cookie_store_getter) {
CEF_REQUIRE_IOT();
net::CookieStore* cookie_store = cookie_store_getter.Run();
if (!cookie_store)
return;
scoped_refptr<VisitCookiesCallback> callback(
new VisitCookiesCallback(cookie_store_getter, visitor));
cookie_store->GetAllCookiesAsync(
base::Bind(&VisitCookiesCallback::Run, callback.get()));
}
void CefCookieManagerOldImpl::VisitUrlCookiesInternal(
const CefString& url,
bool includeHttpOnly,
CefRefPtr<CefCookieVisitor> visitor,
const CookieStoreGetter& cookie_store_getter) {
CEF_REQUIRE_IOT();
net::CookieStore* cookie_store = cookie_store_getter.Run();
if (!cookie_store)
return;
net::CookieOptions options;
if (includeHttpOnly)
options.set_include_httponly();
scoped_refptr<VisitCookiesCallback> callback(
new VisitCookiesCallback(cookie_store_getter, visitor));
GURL gurl = GURL(url.ToString());
cookie_store->GetCookieListWithOptionsAsync(
gurl, options, base::Bind(&VisitCookiesCallback::Run, callback.get()));
}
void CefCookieManagerOldImpl::SetCookieInternal(
const GURL& url,
const CefCookie& cookie,
CefRefPtr<CefSetCookieCallback> callback,
const CookieStoreGetter& cookie_store_getter) {
CEF_REQUIRE_IOT();
net::CookieStore* cookie_store = cookie_store_getter.Run();
if (!cookie_store) {
if (callback.get()) {
CEF_POST_TASK(CEF_IOT, base::Bind(&CefSetCookieCallback::OnComplete,
callback.get(), false));
}
return;
}
std::string name = CefString(&cookie.name).ToString();
std::string value = CefString(&cookie.value).ToString();
std::string domain = CefString(&cookie.domain).ToString();
std::string path = CefString(&cookie.path).ToString();
base::Time expiration_time;
if (cookie.has_expires)
cef_time_to_basetime(cookie.expires, expiration_time);
auto canonical_cookie = net::CanonicalCookie::CreateSanitizedCookie(
url, name, value, domain, path,
base::Time(), // Creation time.
expiration_time,
base::Time(), // Last access time.
cookie.secure ? true : false, cookie.httponly ? true : false,
net::CookieSameSite::UNSPECIFIED, net::COOKIE_PRIORITY_DEFAULT);
net::CookieOptions options;
if (cookie.httponly)
options.set_include_httponly();
if (!canonical_cookie) {
SetCookieCallbackImpl(
callback,
net::CanonicalCookie::CookieInclusionStatus::EXCLUDE_UNKNOWN_ERROR);
return;
}
cookie_store->SetCanonicalCookieAsync(
std::move(canonical_cookie), url.scheme(), options,
base::Bind(SetCookieCallbackImpl, callback));
}
void CefCookieManagerOldImpl::DeleteCookiesInternal(
const GURL& url,
const CefString& cookie_name,
CefRefPtr<CefDeleteCookiesCallback> callback,
const CookieStoreGetter& cookie_store_getter) {
CEF_REQUIRE_IOT();
net::CookieStore* cookie_store = cookie_store_getter.Run();
if (!cookie_store) {
if (callback.get()) {
CEF_POST_TASK(CEF_IOT, base::Bind(&CefDeleteCookiesCallback::OnComplete,
callback.get(), 0));
}
return;
}
if (url.is_empty()) {
// Delete all cookies.
cookie_store->DeleteAllAsync(
base::Bind(DeleteCookiesCallbackImpl, callback));
} else if (cookie_name.empty()) {
// Delete all matching host cookies.
net::CookieDeletionInfo delete_info;
delete_info.host = url.host();
cookie_store->DeleteAllMatchingInfoAsync(
delete_info, base::Bind(DeleteCookiesCallbackImpl, callback));
} else {
// Delete all matching host and domain cookies.
net::CookieDeletionInfo delete_info;
delete_info.url = url;
delete_info.name = cookie_name;
cookie_store->DeleteAllMatchingInfoAsync(
delete_info, base::Bind(DeleteCookiesCallbackImpl, callback));
}
}
void CefCookieManagerOldImpl::FlushStoreInternal(
CefRefPtr<CefCompletionCallback> callback,
const CookieStoreGetter& cookie_store_getter) {
CEF_REQUIRE_IOT();
net::CookieStore* cookie_store = cookie_store_getter.Run();
if (!cookie_store) {
RunAsyncCompletionOnUIThread(callback);
return;
}
cookie_store->FlushStore(base::Bind(RunAsyncCompletionOnUIThread, callback));
}

View File

@ -1,110 +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_COOKIE_MANAGER_OLD_IMPL_H_
#define CEF_LIBCEF_BROWSER_NET_COOKIE_MANAGER_OLD_IMPL_H_
#include <set>
#include "include/cef_cookie.h"
#include "libcef/browser/request_context_impl.h"
#include "libcef/browser/thread_util.h"
#include "base/files/file_path.h"
#include "net/cookies/cookie_monster.h"
// Implementation of the CefCookieManager interface.
class CefCookieManagerOldImpl : public CefCookieManager {
public:
CefCookieManagerOldImpl();
~CefCookieManagerOldImpl() override;
// Must be called immediately after this object is created when |is_blocking|
// is false.
void Initialize(CefRefPtr<CefRequestContextImpl> request_context,
const CefString& path,
bool persist_session_cookies,
CefRefPtr<CefCompletionCallback> callback);
// Executes |callback| either synchronously or asynchronously with the
// CookieStoreGetter when the cookie store object is available. If
// |task_runner| is NULL the callback will be executed on the originating
// thread. CookieStoreGetter can only be executed on, and the resulting cookie
// store object can only be accessed on, the IO thread.
typedef base::Callback<net::CookieStore*()> CookieStoreGetter;
typedef base::Callback<void(const CookieStoreGetter&)> CookieStoreCallback;
void GetCookieStore(scoped_refptr<base::SingleThreadTaskRunner> task_runner,
const CookieStoreCallback& callback);
// 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();
// CefCookieManager methods.
void SetSupportedSchemes(const std::vector<CefString>& schemes,
bool include_defaults,
CefRefPtr<CefCompletionCallback> callback) override;
bool VisitAllCookies(CefRefPtr<CefCookieVisitor> visitor) override;
bool VisitUrlCookies(const CefString& url,
bool includeHttpOnly,
CefRefPtr<CefCookieVisitor> visitor) override;
bool SetCookie(const CefString& url,
const CefCookie& cookie,
CefRefPtr<CefSetCookieCallback> callback) override;
bool DeleteCookies(const CefString& url,
const CefString& cookie_name,
CefRefPtr<CefDeleteCookiesCallback> callback) override;
bool FlushStore(CefRefPtr<CefCompletionCallback> callback) override;
// Set the schemes supported by |cookie_monster|.
static void SetCookieMonsterSchemes(net::CookieMonster* cookie_monster,
const std::vector<std::string>& schemes,
bool include_defaults);
private:
// Execute |method| on the IO thread once the request context is available.
void RunMethodWithContext(
const CefRequestContextImpl::RequestContextCallback& method);
void InitWithContext(
CefRefPtr<CefCompletionCallback> callback,
scoped_refptr<CefURLRequestContextGetter> request_context);
void SetSupportedSchemesWithContext(
const std::vector<std::string>& schemes,
bool include_defaults,
CefRefPtr<CefCompletionCallback> callback,
scoped_refptr<CefURLRequestContextGetter> request_context);
void GetCookieStoreWithContext(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
const CookieStoreCallback& callback,
scoped_refptr<CefURLRequestContextGetter> request_context);
void SetSupportedSchemesInternal(const std::vector<std::string>& schemes,
bool include_defaults,
CefRefPtr<CefCompletionCallback> callback);
void VisitAllCookiesInternal(CefRefPtr<CefCookieVisitor> visitor,
const CookieStoreGetter& cookie_store_getter);
void VisitUrlCookiesInternal(const CefString& url,
bool includeHttpOnly,
CefRefPtr<CefCookieVisitor> visitor,
const CookieStoreGetter& cookie_store_getter);
void SetCookieInternal(const GURL& url,
const CefCookie& cookie,
CefRefPtr<CefSetCookieCallback> callback,
const CookieStoreGetter& cookie_store_getter);
void DeleteCookiesInternal(const GURL& url,
const CefString& cookie_name,
CefRefPtr<CefDeleteCookiesCallback> callback,
const CookieStoreGetter& cookie_store_getter);
void FlushStoreInternal(CefRefPtr<CefCompletionCallback> callback,
const CookieStoreGetter& cookie_store_getter);
// Context that owns the cookie monster.
CefRefPtr<CefRequestContextImpl> request_context_;
scoped_refptr<CefURLRequestContextGetter> request_context_impl_;
IMPLEMENT_REFCOUNTING_DELETE_ON_IOT(CefCookieManagerOldImpl);
};
#endif // CEF_LIBCEF_BROWSER_NET_COOKIE_MANAGER_OLD_IMPL_H_

View File

@ -6,7 +6,6 @@
#include "libcef/browser/context.h" #include "libcef/browser/context.h"
#include "libcef/browser/thread_util.h" #include "libcef/browser/thread_util.h"
#include "libcef/common/net_service/util.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/logging.h" #include "base/logging.h"
@ -43,10 +42,5 @@ void CefLoadCRLSetsFile(const CefString& path) {
return; return;
} }
if (!net_service::IsEnabled()) {
NOTIMPLEMENTED();
return;
}
CEF_POST_USER_VISIBLE_TASK(base::BindOnce(&LoadFromDisk, path)); CEF_POST_USER_VISIBLE_TASK(base::BindOnce(&LoadFromDisk, path));
} }

View File

@ -7,7 +7,6 @@
#include <string> #include <string>
#include "libcef/browser/net/internal_scheme_handler.h" #include "libcef/browser/net/internal_scheme_handler.h"
#include "libcef/browser/net/url_request_manager.h"
#include "libcef/browser/resource_context.h" #include "libcef/browser/resource_context.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
@ -41,12 +40,6 @@ class Delegate : public InternalHandlerDelegate {
} // namespace } // namespace
void RegisterChromeDevToolsHandler(CefURLRequestManager* request_manager) {
request_manager->AddFactory(
content::kChromeDevToolsScheme, kChromeDevToolsHost,
CreateInternalHandlerFactory(base::WrapUnique(new Delegate())));
}
void RegisterChromeDevToolsHandler(CefResourceContext* resource_context) { void RegisterChromeDevToolsHandler(CefResourceContext* resource_context) {
resource_context->RegisterSchemeHandlerFactory( resource_context->RegisterSchemeHandlerFactory(
content::kChromeDevToolsScheme, kChromeDevToolsHost, content::kChromeDevToolsScheme, kChromeDevToolsHost,

View File

@ -7,14 +7,12 @@
#pragma once #pragma once
class CefResourceContext; class CefResourceContext;
class CefURLRequestManager;
namespace scheme { namespace scheme {
extern const char kChromeDevToolsHost[]; extern const char kChromeDevToolsHost[];
// Register the chrome-devtools scheme handler. // Register the chrome-devtools scheme handler.
void RegisterChromeDevToolsHandler(CefURLRequestManager* request_manager);
void RegisterChromeDevToolsHandler(CefResourceContext* resource_context); void RegisterChromeDevToolsHandler(CefResourceContext* resource_context);
} // namespace scheme } // namespace scheme

View File

@ -1,315 +0,0 @@
// Copyright (c) 2017 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/net_util.h"
#include "libcef/browser/browser_host_impl.h"
#include "libcef/browser/browser_platform_delegate.h"
#include "libcef/browser/resource_context.h"
#include "libcef/common/net/scheme_registration.h"
#include "base/optional.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/resource_context.h"
#include "content/public/browser/resource_request_info.h"
#include "net/url_request/url_request.h"
#include "url/origin.h"
#include "url/url_constants.h"
namespace net_util {
namespace {
CefString SerializeRequestInitiator(
base::Optional<url::Origin> request_initiator) {
if (request_initiator.has_value())
return request_initiator->Serialize();
return "null";
}
CefRefPtr<CefResourceRequestHandler> GetResourceRequestHandler(
CefResourceContext* resource_context,
int render_process_id,
int render_frame_id,
int frame_tree_node_id,
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
bool is_navigation,
bool is_download,
base::Optional<url::Origin> request_initiator) {
CEF_REQUIRE_IOT();
DCHECK(resource_context);
DCHECK(request);
CefRefPtr<CefResourceRequestHandler> resource_request_handler;
const CefString& request_initiator_str =
SerializeRequestInitiator(request_initiator);
const bool is_custom_scheme =
!GURL(request->GetURL().ToString()).SchemeIsHTTPOrHTTPS();
// Not supported by the old network implementation, but keep the value
// consistent with the NetworkService implementation.
bool disable_default_handling = is_custom_scheme;
// Give the browser handler a chance first.
if (browser) {
DCHECK(frame);
CefRefPtr<CefClient> client = browser->GetHost()->GetClient();
if (client) {
CefRefPtr<CefRequestHandler> request_handler =
client->GetRequestHandler();
if (request_handler) {
resource_request_handler = request_handler->GetResourceRequestHandler(
browser, frame, request, is_navigation, is_download,
request_initiator_str, disable_default_handling);
}
}
}
// Give the request context handler a chance.
if (!resource_request_handler) {
CefRefPtr<CefRequestContextHandler> request_context_handler =
resource_context->GetHandler(render_process_id, render_frame_id,
frame_tree_node_id, false);
if (request_context_handler) {
resource_request_handler =
request_context_handler->GetResourceRequestHandler(
browser, frame, request, is_navigation, is_download,
request_initiator_str, disable_default_handling);
}
}
return resource_request_handler;
}
void HandleExternalProtocolOnIOThread(CefResourceContext* resource_context,
int render_process_id,
CefRefPtr<CefBrowserHostImpl> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequestImpl> request) {
CEF_REQUIRE_IOT();
CefRefPtr<CefResourceRequestHandler> request_handler =
GetResourceRequestHandler(
resource_context, render_process_id, -1, -1, browser.get(), frame,
request.get(), true /* is_navigation */, false /* is_download */,
base::Optional<url::Origin>());
if (!request_handler)
return;
bool allow_os_execution = false;
request_handler->OnProtocolExecution(browser, frame, request.get(),
allow_os_execution);
if (allow_os_execution) {
const GURL& url = GURL(request->GetURL().ToString());
CefBrowserPlatformDelegate::HandleExternalProtocol(url);
}
}
} // namespace
bool IsInternalRequest(const net::URLRequest* request) {
// With PlzNavigate we now receive blob URLs. Ignore these URLs.
// See https://crbug.com/776884 for details.
if (request->url().SchemeIs(url::kBlobScheme)) {
return true;
}
return false;
}
CefRefPtr<CefBrowserHostImpl> GetBrowserForRequest(
const net::URLRequest* request) {
DCHECK(request);
CEF_REQUIRE_IOT();
// When navigating the main frame a new (pre-commit) URLRequest will be
// created before the RenderFrameHost. Consequently we can't rely on
// ResourceRequestInfo::GetRenderFrameForRequest returning a valid frame
// ID. See https://crbug.com/776884 for background.
int render_process_id = -1;
int render_frame_id = MSG_ROUTING_NONE;
if (content::ResourceRequestInfo::GetRenderFrameForRequest(
request, &render_process_id, &render_frame_id) &&
render_process_id >= 0 && render_frame_id >= 0) {
return CefBrowserHostImpl::GetBrowserForFrameRoute(render_process_id,
render_frame_id);
}
content::ResourceRequestInfo* request_info =
content::ResourceRequestInfo::ForRequest(request);
if (request_info) {
return CefBrowserHostImpl::GetBrowserForFrameTreeNode(
request_info->GetFrameTreeNodeId());
}
return nullptr;
}
CefRefPtr<CefFrame> GetFrameForRequest(
scoped_refptr<CefBrowserInfo> browser_info,
const net::URLRequest* request) {
CEF_REQUIRE_IOT();
content::ResourceRequestInfo* info =
content::ResourceRequestInfo::ForRequest(request);
if (!info)
return nullptr;
// Try to locate the most reasonable match by ID.
auto frame =
browser_info->GetFrameForFrameTreeNode(info->GetFrameTreeNodeId());
if (!frame) {
frame = browser_info->GetFrameForRoute(info->GetRouteID(),
info->GetRenderFrameID());
}
if (frame)
return frame;
// The IsMainFrame() flag isn't completely reliable, so do this after
// searching by ID.
if (info->IsMainFrame())
return browser_info->GetMainFrame();
// Create a temporary frame object for requests referencing sub-frames that
// don't yet exist. Use the main frame as the parent because we don't know
// the real parent.
return browser_info->CreateTempSubFrame(CefFrameHostImpl::kInvalidFrameId);
}
CefRefPtr<CefResourceRequestHandler> GetResourceRequestHandler(
const net::URLRequest* request,
CefRefPtr<CefRequestImpl>& cef_request,
CefRefPtr<CefBrowser>& cef_browser,
CefRefPtr<CefFrame>& cef_frame) {
CEF_REQUIRE_IOT();
content::ResourceRequestInfo* info =
content::ResourceRequestInfo::ForRequest(request);
if (!info)
return nullptr;
// Initiator will be non-null for subresource loads.
const bool is_navigation =
ui::PageTransitionIsNewNavigation(info->GetPageTransition()) &&
!request->initiator().has_value();
const bool is_download = info->IsDownload();
const CefString& request_initiator =
SerializeRequestInitiator(request->initiator());
const bool is_custom_scheme =
!scheme::IsInternalHandledScheme(request->url().scheme());
// Not supported by the old network implementation, but keep the value
// consistent with the NetworkService implementation.
bool disable_default_handling = is_custom_scheme;
CefRefPtr<CefResourceRequestHandler> resource_request_handler;
CefRefPtr<CefBrowserHostImpl> browser = GetBrowserForRequest(request);
CefRefPtr<CefFrame> frame;
CefRefPtr<CefRequestImpl> requestPtr;
// Give the browser handler a chance first.
if (browser) {
// A frame should always exist, or be created.
frame = GetFrameForRequest(browser->browser_info(), request);
DCHECK(frame);
CefRefPtr<CefClient> client = browser->GetClient();
if (client) {
CefRefPtr<CefRequestHandler> request_handler =
client->GetRequestHandler();
if (request_handler) {
requestPtr = new CefRequestImpl();
requestPtr->Set(request);
requestPtr->SetReadOnly(true);
resource_request_handler = request_handler->GetResourceRequestHandler(
browser.get(), frame, requestPtr.get(), is_navigation, is_download,
request_initiator, disable_default_handling);
}
}
}
// Give the request context handler a chance.
if (!resource_request_handler) {
CefResourceContext* resource_context =
static_cast<CefResourceContext*>(info->GetContext());
if (!resource_context)
return nullptr;
const int render_process_id = info->GetChildID();
const int render_frame_id = info->GetRenderFrameID();
const int frame_tree_node_id = info->GetFrameTreeNodeId();
CefRefPtr<CefRequestContextHandler> request_context_handler =
resource_context->GetHandler(render_process_id, render_frame_id,
frame_tree_node_id, false);
if (request_context_handler) {
if (!requestPtr) {
requestPtr = new CefRequestImpl();
requestPtr->Set(request);
requestPtr->SetReadOnly(true);
}
resource_request_handler =
request_context_handler->GetResourceRequestHandler(
browser.get(), frame, requestPtr.get(), is_navigation,
is_download, request_initiator, disable_default_handling);
}
}
if (resource_request_handler) {
// Success! Return all the objects that were discovered/created.
cef_request = requestPtr;
cef_browser = browser.get();
cef_frame = frame;
}
return resource_request_handler;
}
void HandleExternalProtocol(
CefRefPtr<CefRequestImpl> request,
const content::ResourceRequestInfo::WebContentsGetter&
web_contents_getter) {
DCHECK(request);
DCHECK(request->IsReadOnly());
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(CEF_UIT, base::BindOnce(HandleExternalProtocol, request,
web_contents_getter));
return;
}
content::WebContents* web_contents = web_contents_getter.Run();
if (!web_contents)
return;
CefRefPtr<CefBrowserHostImpl> browser =
CefBrowserHostImpl::GetBrowserForContents(web_contents);
if (!browser)
return;
content::BrowserContext* browser_context = web_contents->GetBrowserContext();
DCHECK(browser_context);
CefResourceContext* resource_context =
static_cast<CefResourceContext*>(browser_context->GetResourceContext());
DCHECK(resource_context);
const int render_process_id =
web_contents->GetRenderViewHost()->GetProcess()->GetID();
CEF_POST_TASK(
CEF_IOT, base::Bind(HandleExternalProtocolOnIOThread,
base::Unretained(resource_context), render_process_id,
browser, browser->GetMainFrame(), request));
}
} // namespace net_util

View File

@ -1,56 +0,0 @@
// Copyright (c) 2017 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_NET_UTIL_H_
#define CEF_LIBCEF_BROWSER_NET_NET_UTIL_H_
#pragma once
#include "include/cef_resource_request_handler.h"
#include "libcef/common/request_impl.h"
#include "content/public/browser/resource_request_info.h"
namespace net {
class URLRequest;
}
class GURL;
class CefBrowserHostImpl;
class CefBrowserInfo;
namespace net_util {
// Returns true if |request| is handled internally and should not be exposed via
// the CEF API.
bool IsInternalRequest(const net::URLRequest* request);
// Returns the browser associated with the specified URLRequest.
CefRefPtr<CefBrowserHostImpl> GetBrowserForRequest(
const net::URLRequest* request);
// Returns the frame associated with the specified URLRequest.
CefRefPtr<CefFrame> GetFrameForRequest(
scoped_refptr<CefBrowserInfo> browser_info,
const net::URLRequest* request);
// Returns the appropriate CefResourceRequestHandler as determined by the
// associated CefBrowser/CefRequestHandler and/or CefRequestContextHandler, if
// any. The out-params will be nullptr if no handler is returned. Otherwise,
// the |cef_request| parameter will be set based on the contents of |request|
// (read-only by default), and the |cef_browser| and |cef_frame| parameters
// will be set if the request is associated with a browser.
CefRefPtr<CefResourceRequestHandler> GetResourceRequestHandler(
const net::URLRequest* request,
CefRefPtr<CefRequestImpl>& cef_request,
CefRefPtr<CefBrowser>& cef_browser,
CefRefPtr<CefFrame>& cef_frame);
void HandleExternalProtocol(
CefRefPtr<CefRequestImpl> request,
const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter);
} // namespace net_util
#endif // CEF_LIBCEF_BROWSER_NET_NET_UTIL_H_

View File

@ -1,515 +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/network_delegate.h"
#include <string>
#include <utility>
#include "include/cef_urlrequest.h"
#include "libcef/browser/browser_host_impl.h"
#include "libcef/browser/net/cookie_manager_old_impl.h"
#include "libcef/browser/net/net_util.h"
#include "libcef/browser/net/source_stream.h"
#include "libcef/browser/net/url_request_user_data.h"
#include "libcef/browser/thread_util.h"
#include "libcef/common/net_service/net_service_util.h"
#include "libcef/common/request_impl.h"
#include "libcef/common/response_impl.h"
#include "base/command_line.h"
#include "base/metrics/field_trial.h"
#include "base/strings/string_util.h"
#include "chrome/common/net/safe_search_util.h"
#include "components/prefs/pref_member.h"
#include "components/prefs/pref_service.h"
#include "content/public/common/content_switches.h"
#include "net/base/net_errors.h"
#include "net/http/http_util.h"
#include "net/url_request/url_request.h"
namespace {
const void* kAuthCallbackHolderUserDataKey =
static_cast<const void*>(&kAuthCallbackHolderUserDataKey);
class CefBeforeResourceLoadCallbackImpl : public CefRequestCallback {
public:
typedef net::CompletionOnceCallback CallbackType;
CefBeforeResourceLoadCallbackImpl(CefRefPtr<CefRequestImpl> cef_request,
GURL* new_url,
net::URLRequest* url_request,
bool force_google_safesearch,
CallbackType callback)
: cef_request_(cef_request),
new_url_(new_url),
url_request_(url_request),
force_google_safesearch_(force_google_safesearch),
callback_(std::move(callback)) {
DCHECK(new_url);
DCHECK(url_request_);
// Add an association between the URLRequest and this object.
url_request_->SetUserData(UserDataKey(),
base::WrapUnique(new Disconnector(this)));
}
~CefBeforeResourceLoadCallbackImpl() {
if (!callback_.is_null()) {
// The callback is still pending. Cancel it now.
if (CEF_CURRENTLY_ON_IOT()) {
RunNow(cef_request_, new_url_, url_request_, std::move(callback_),
force_google_safesearch_, false);
} else {
CEF_POST_TASK(CEF_IOT,
base::Bind(&CefBeforeResourceLoadCallbackImpl::RunNow,
cef_request_, new_url_, url_request_,
base::Passed(std::move(callback_)),
force_google_safesearch_, false));
}
}
}
void Continue(bool allow) override {
// Always continue asynchronously.
CEF_POST_TASK(CEF_IOT,
base::Bind(&CefBeforeResourceLoadCallbackImpl::ContinueNow,
this, allow));
}
void Cancel() override { Continue(false); }
void ContinueNow(bool allow) {
CEF_REQUIRE_IOT();
if (!callback_.is_null()) {
RunNow(cef_request_, new_url_, url_request_, std::move(callback_),
force_google_safesearch_, allow);
Disconnect();
}
}
private:
void Disconnect() {
CEF_REQUIRE_IOT();
cef_request_ = nullptr;
new_url_ = nullptr;
url_request_ = nullptr;
callback_.Reset();
}
// Used to disconnect the callback when the associated URLRequest is
// destroyed.
class Disconnector : public base::SupportsUserData::Data {
public:
explicit Disconnector(CefBeforeResourceLoadCallbackImpl* callback)
: callback_(callback) {}
~Disconnector() override {
if (callback_)
callback_->Disconnect();
}
void Disconnect() { callback_ = NULL; }
private:
CefBeforeResourceLoadCallbackImpl* callback_;
};
static void RunNow(CefRefPtr<CefRequestImpl> cef_request,
GURL* new_url,
net::URLRequest* request,
CallbackType callback,
bool force_google_safesearch,
bool allow) {
CEF_REQUIRE_IOT();
if (allow) {
// Update the URLRequest with only the values that have been changed by
// the client.
cef_request->Get(request, true);
if (!!(cef_request->GetChanges() & CefRequestImpl::kChangedUrl)) {
// If the URL was changed then redirect the request.
GURL url = GURL(cef_request->GetURL().ToString());
DCHECK_NE(url, request->url());
new_url->Swap(&url);
}
}
// Remove the association between the URLRequest and this object.
Disconnector* disconnector =
static_cast<Disconnector*>(request->GetUserData(UserDataKey()));
DCHECK(disconnector);
disconnector->Disconnect();
request->RemoveUserData(UserDataKey());
// Only execute the callback if the request has not been canceled.
if (request->status().status() != net::URLRequestStatus::CANCELED) {
if (force_google_safesearch && allow && new_url->is_empty())
safe_search_util::ForceGoogleSafeSearch(request->url(), new_url);
std::move(callback).Run(allow ? net::OK : net::ERR_ABORTED);
}
}
static inline void* UserDataKey() { return &kLocatorKey; }
CefRefPtr<CefRequestImpl> cef_request_;
const GURL old_url_;
GURL* new_url_;
net::URLRequest* url_request_;
bool force_google_safesearch_;
CallbackType callback_;
// The user data key.
static int kLocatorKey;
IMPLEMENT_REFCOUNTING(CefBeforeResourceLoadCallbackImpl);
DISALLOW_COPY_AND_ASSIGN(CefBeforeResourceLoadCallbackImpl);
};
int CefBeforeResourceLoadCallbackImpl::kLocatorKey = 0;
class CefAuthCallbackImpl : public CefAuthCallback {
public:
typedef net::NetworkDelegate::AuthCallback CallbackType;
CefAuthCallbackImpl(CallbackType callback, net::AuthCredentials* credentials)
: callback_(std::move(callback)), credentials_(credentials) {}
~CefAuthCallbackImpl() override {
if (!callback_.is_null()) {
// The auth callback is still pending. Cancel it now.
if (CEF_CURRENTLY_ON_IOT()) {
CancelNow(std::move(callback_));
} else {
CEF_POST_TASK(CEF_IOT, base::Bind(&CefAuthCallbackImpl::CancelNow,
base::Passed(std::move(callback_))));
}
}
}
void Continue(const CefString& username, const CefString& password) override {
if (CEF_CURRENTLY_ON_IOT()) {
if (!callback_.is_null()) {
credentials_->Set(username, password);
std::move(callback_).Run(
net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH);
}
} else {
CEF_POST_TASK(CEF_IOT, base::Bind(&CefAuthCallbackImpl::Continue, this,
username, password));
}
}
void Cancel() override {
if (CEF_CURRENTLY_ON_IOT()) {
if (!callback_.is_null()) {
CancelNow(std::move(callback_));
}
} else {
CEF_POST_TASK(CEF_IOT, base::Bind(&CefAuthCallbackImpl::Cancel, this));
}
}
CallbackType Disconnect() WARN_UNUSED_RESULT { return std::move(callback_); }
private:
static void CancelNow(CallbackType callback) {
CEF_REQUIRE_IOT();
std::move(callback).Run(
net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION);
}
CallbackType callback_;
net::AuthCredentials* credentials_;
IMPLEMENT_REFCOUNTING(CefAuthCallbackImpl);
};
// Invalidates CefAuthCallbackImpl::callback_ if the URLRequest is deleted
// before the callback.
class AuthCallbackHolder : public base::SupportsUserData::Data {
public:
explicit AuthCallbackHolder(CefRefPtr<CefAuthCallbackImpl> callback)
: callback_(callback) {}
~AuthCallbackHolder() override { callback_->Disconnect().Reset(); }
private:
CefRefPtr<CefAuthCallbackImpl> callback_;
};
} // namespace
CefNetworkDelegate::CefNetworkDelegate() : force_google_safesearch_(nullptr) {}
CefNetworkDelegate::~CefNetworkDelegate() {}
std::unique_ptr<net::SourceStream> CefNetworkDelegate::CreateSourceStream(
net::URLRequest* request,
std::unique_ptr<net::SourceStream> upstream) {
if (net_util::IsInternalRequest(request))
return upstream;
CefRefPtr<CefRequestImpl> requestPtr;
CefRefPtr<CefBrowser> browser;
CefRefPtr<CefFrame> frame;
CefRefPtr<CefResourceRequestHandler> handler =
net_util::GetResourceRequestHandler(request, requestPtr, browser, frame);
if (handler) {
CefRefPtr<CefResponseImpl> responsePtr = new CefResponseImpl();
responsePtr->Set(request);
responsePtr->SetReadOnly(true);
CefRefPtr<CefResponseFilter> cef_filter =
handler->GetResourceResponseFilter(browser, frame, requestPtr.get(),
responsePtr.get());
if (cef_filter && cef_filter->InitFilter()) {
return std::make_unique<CefSourceStream>(cef_filter, std::move(upstream));
}
}
return upstream;
}
int CefNetworkDelegate::OnBeforeURLRequest(net::URLRequest* request,
net::CompletionOnceCallback callback,
GURL* new_url) {
if (net_util::IsInternalRequest(request))
return net::OK;
const bool force_google_safesearch =
(force_google_safesearch_ && force_google_safesearch_->GetValue());
CefRefPtr<CefRequestImpl> requestPtr;
CefRefPtr<CefBrowser> browser;
CefRefPtr<CefFrame> frame;
CefRefPtr<CefResourceRequestHandler> handler =
net_util::GetResourceRequestHandler(request, requestPtr, browser, frame);
if (handler) {
// The following callback allows modification of the request object.
requestPtr->SetReadOnly(false);
CefBrowserHostImpl* browser_impl =
static_cast<CefBrowserHostImpl*>(browser.get());
if (browser_impl) {
const CefBrowserSettings& browser_settings = browser_impl->settings();
if (browser_settings.accept_language_list.length > 0) {
const std::string& accept_language =
net::HttpUtil::GenerateAcceptLanguageHeader(
CefString(&browser_settings.accept_language_list));
request->SetExtraRequestHeaderByName(
net::HttpRequestHeaders::kAcceptLanguage, accept_language, false);
requestPtr->SetHeaderByName(net::HttpRequestHeaders::kAcceptLanguage,
accept_language, false);
}
}
requestPtr->SetTrackChanges(true);
CefRefPtr<CefBeforeResourceLoadCallbackImpl> callbackImpl(
new CefBeforeResourceLoadCallbackImpl(requestPtr, new_url, request,
force_google_safesearch,
std::move(callback)));
// Give the client an opportunity to evaluate the request.
cef_return_value_t retval = handler->OnBeforeResourceLoad(
browser, frame, requestPtr.get(), callbackImpl.get());
if (retval == RV_CANCEL) {
// Cancel the request.
callbackImpl->Continue(false);
} else if (retval == RV_CONTINUE) {
// Continue the request.
callbackImpl->Continue(true);
}
// Continue or cancel the request asynchronously.
return net::ERR_IO_PENDING;
}
if (force_google_safesearch && new_url->is_empty())
safe_search_util::ForceGoogleSafeSearch(request->url(), new_url);
// Continue the request immediately.
return net::OK;
}
void CefNetworkDelegate::OnCompleted(net::URLRequest* request,
bool started,
int net_error) {
if (net_util::IsInternalRequest(request))
return;
if (!started)
return;
CefRefPtr<CefRequestImpl> requestPtr;
CefRefPtr<CefBrowser> browser;
CefRefPtr<CefFrame> frame;
CefRefPtr<CefResourceRequestHandler> handler =
net_util::GetResourceRequestHandler(request, requestPtr, browser, frame);
if (!handler)
return;
CefRefPtr<CefResponseImpl> responsePtr = new CefResponseImpl();
responsePtr->Set(request);
responsePtr->SetReadOnly(true);
cef_urlrequest_status_t status = UR_UNKNOWN;
switch (request->status().status()) {
case net::URLRequestStatus::SUCCESS:
status = UR_SUCCESS;
break;
case net::URLRequestStatus::CANCELED:
status = UR_CANCELED;
break;
case net::URLRequestStatus::FAILED:
status = UR_FAILED;
break;
default:
NOTREACHED();
break;
}
const int64 received_content_length =
request->received_response_content_length();
handler->OnResourceLoadComplete(browser, frame, requestPtr.get(),
responsePtr.get(), status,
received_content_length);
}
net::NetworkDelegate::AuthRequiredResponse CefNetworkDelegate::OnAuthRequired(
net::URLRequest* request,
const net::AuthChallengeInfo& auth_info,
AuthCallback callback,
net::AuthCredentials* credentials) {
if (net_util::IsInternalRequest(request))
return AUTH_REQUIRED_RESPONSE_NO_ACTION;
CefRefPtr<CefBrowserHostImpl> browser =
net_util::GetBrowserForRequest(request);
if (browser.get()) {
CefRefPtr<CefClient> client = browser->GetClient();
if (client.get()) {
CefRefPtr<CefRequestHandler> handler = client->GetRequestHandler();
if (handler.get()) {
CefRefPtr<CefAuthCallbackImpl> callbackPtr(
new CefAuthCallbackImpl(std::move(callback), credentials));
if (handler->GetAuthCredentials(
browser.get(), request->url().spec(), auth_info.is_proxy,
auth_info.challenger.host(), auth_info.challenger.port(),
auth_info.realm, auth_info.scheme, callbackPtr.get())) {
request->SetUserData(
kAuthCallbackHolderUserDataKey,
std::make_unique<AuthCallbackHolder>(callbackPtr));
return AUTH_REQUIRED_RESPONSE_IO_PENDING;
} else {
callback = callbackPtr->Disconnect();
}
}
}
}
CefURLRequestUserData* user_data =
(CefURLRequestUserData*)request->GetUserData(
CefURLRequestUserData::kUserDataKey);
if (user_data) {
CefRefPtr<CefURLRequestClient> client = user_data->GetClient();
if (client.get()) {
CefRefPtr<CefAuthCallbackImpl> callbackPtr(
new CefAuthCallbackImpl(std::move(callback), credentials));
if (client->GetAuthCredentials(
auth_info.is_proxy, auth_info.challenger.host(),
auth_info.challenger.port(), auth_info.realm, auth_info.scheme,
callbackPtr.get())) {
request->SetUserData(kAuthCallbackHolderUserDataKey,
std::make_unique<AuthCallbackHolder>(callbackPtr));
return AUTH_REQUIRED_RESPONSE_IO_PENDING;
} else {
callback = callbackPtr->Disconnect();
}
}
}
return AUTH_REQUIRED_RESPONSE_NO_ACTION;
}
bool CefNetworkDelegate::OnCanGetCookies(const net::URLRequest& request,
const net::CookieList& cookie_list,
bool allowed_from_caller) {
if (!allowed_from_caller)
return false;
if (net_util::IsInternalRequest(&request))
return true;
CefRefPtr<CefRequestImpl> requestPtr;
CefRefPtr<CefBrowser> browser;
CefRefPtr<CefFrame> frame;
CefRefPtr<CefResourceRequestHandler> handler =
net_util::GetResourceRequestHandler(&request, requestPtr, browser, frame);
if (!handler)
return true;
CefRefPtr<CefCookieAccessFilter> cookie_filter =
handler->GetCookieAccessFilter(browser, frame, requestPtr.get());
if (!cookie_filter)
return true;
bool cookie_blocked = false;
for (const auto& cookie : cookie_list) {
CefCookie cef_cookie;
if (!net_service::MakeCefCookie(cookie, cef_cookie))
continue;
if (!cookie_filter->CanSendCookie(browser, frame, requestPtr.get(),
cef_cookie)) {
if (!cookie_blocked)
cookie_blocked = true;
}
}
return !cookie_blocked;
}
bool CefNetworkDelegate::OnCanSetCookie(const net::URLRequest& request,
const net::CanonicalCookie& cookie,
net::CookieOptions* options,
bool allowed_from_caller) {
if (!allowed_from_caller)
return false;
if (net_util::IsInternalRequest(&request))
return true;
CefRefPtr<CefRequestImpl> requestPtr;
CefRefPtr<CefBrowser> browser;
CefRefPtr<CefFrame> frame;
CefRefPtr<CefResourceRequestHandler> handler =
net_util::GetResourceRequestHandler(&request, requestPtr, browser, frame);
if (!handler)
return true;
CefRefPtr<CefCookieAccessFilter> cookie_filter =
handler->GetCookieAccessFilter(browser, frame, requestPtr.get());
if (!cookie_filter)
return true;
CefCookie cef_cookie;
if (!net_service::MakeCefCookie(cookie, cef_cookie))
return true;
CefRefPtr<CefResponseImpl> responsePtr = new CefResponseImpl();
responsePtr->Set(&request);
responsePtr->SetReadOnly(true);
return cookie_filter->CanSaveCookie(browser, frame, requestPtr.get(),
responsePtr.get(), cef_cookie);
}
bool CefNetworkDelegate::OnCanAccessFile(
const net::URLRequest& request,
const base::FilePath& original_path,
const base::FilePath& absolute_path) const {
return true;
}

View File

@ -1,60 +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_NETWORK_DELEGATE_H_
#define CEF_LIBCEF_BROWSER_NET_NETWORK_DELEGATE_H_
#pragma once
#include "base/macros.h"
#include "net/base/network_delegate_impl.h"
template <class T>
class PrefMember;
typedef PrefMember<bool> BooleanPrefMember;
// Used for intercepting resource requests, redirects and responses. The single
// instance of this class is managed by CefURLRequestContextGetter.
class CefNetworkDelegate : public net::NetworkDelegateImpl {
public:
CefNetworkDelegate();
~CefNetworkDelegate() override;
void set_force_google_safesearch(BooleanPrefMember* force_google_safesearch) {
force_google_safesearch_ = force_google_safesearch;
}
private:
// net::NetworkDelegate methods.
std::unique_ptr<net::SourceStream> CreateSourceStream(
net::URLRequest* request,
std::unique_ptr<net::SourceStream> upstream) override;
int OnBeforeURLRequest(net::URLRequest* request,
net::CompletionOnceCallback callback,
GURL* new_url) override;
AuthRequiredResponse OnAuthRequired(
net::URLRequest* request,
const net::AuthChallengeInfo& auth_info,
AuthCallback callback,
net::AuthCredentials* credentials) override;
void OnCompleted(net::URLRequest* request,
bool started,
int net_error) override;
bool OnCanGetCookies(const net::URLRequest& request,
const net::CookieList& cookie_list,
bool allowed_from_caller) override;
bool OnCanSetCookie(const net::URLRequest& request,
const net::CanonicalCookie& cookie,
net::CookieOptions* options,
bool allowed_from_caller) override;
bool OnCanAccessFile(const net::URLRequest& request,
const base::FilePath& original_path,
const base::FilePath& absolute_path) const override;
// Weak, owned by our owner (CefURLRequestContextGetter).
BooleanPrefMember* force_google_safesearch_;
DISALLOW_COPY_AND_ASSIGN(CefNetworkDelegate);
};
#endif // CEF_LIBCEF_BROWSER_NET_NETWORK_DELEGATE_H_

View File

@ -1,592 +0,0 @@
// Copyright (c) 2012 The Chromium Embedded Framework Authors.
// Portions copyright (c) 2006-2009 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/net/resource_request_job.h"
#include <map>
#include <vector>
#include "include/cef_callback.h"
#include "include/cef_parser.h"
#include "libcef/browser/net/cookie_manager_old_impl.h"
#include "libcef/browser/thread_util.h"
#include "libcef/common/net_service/net_service_util.h"
#include "libcef/common/request_impl.h"
#include "libcef/common/response_impl.h"
#include "base/bind.h"
#include "base/logging.h"
#include "base/strings/string_util.h"
#include "net/base/http_user_agent_settings.h"
#include "net/base/io_buffer.h"
#include "net/base/load_flags.h"
#include "net/base/mime_util.h"
#include "net/http/http_response_headers.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_context.h"
using net::URLRequestStatus;
namespace {
using HeaderMap = std::multimap<CefString, CefString>;
struct CaseInsensitiveComparator {
base::StringPiece search;
CaseInsensitiveComparator(const std::string& s) : search(s) {}
bool operator()(const HeaderMap::value_type& p) const {
return base::EqualsCaseInsensitiveASCII(search, p.first.ToString());
}
};
HeaderMap::const_iterator FindHeader(const HeaderMap& m,
const std::string& name) {
return std::find_if(m.begin(), m.end(), CaseInsensitiveComparator(name));
}
bool SetHeaderIfMissing(CefRequest::HeaderMap& headerMap,
const std::string& name,
const std::string& value) {
if (value.empty())
return false;
CefRequest::HeaderMap::const_iterator it = headerMap.find(name);
if (it == headerMap.end()) {
headerMap.insert(std::make_pair(name, value));
return true;
}
return false;
}
} // namespace
// Client callback for asynchronous response continuation.
class CefResourceRequestJobCallback : public CefCallback {
public:
enum Type {
HEADERS_AVAILABLE,
BYTES_AVAILABLE,
};
explicit CefResourceRequestJobCallback(CefResourceRequestJob* job, Type type)
: job_(job), type_(type), dest_(NULL), dest_size_(0) {}
void Continue() override {
// Continue asynchronously.
CEF_POST_TASK(
CEF_IOT,
base::Bind(&CefResourceRequestJobCallback::ContinueOnIOThread, this));
}
void Cancel() override {
// Cancel asynchronously.
CEF_POST_TASK(
CEF_IOT,
base::Bind(&CefResourceRequestJobCallback::CancelOnIOThread, this));
}
void Detach() {
CEF_REQUIRE_IOT();
job_ = NULL;
}
void SetDestination(net::IOBuffer* dest, int dest_size) {
CEF_REQUIRE_IOT();
// Should not be called multiple times while IO is pending.
DCHECK(!dest_);
dest_ = dest;
dest_size_ = dest_size;
}
private:
void ContinueOnIOThread() {
CEF_REQUIRE_IOT();
// Return early if the callback has already been detached.
if (!job_)
return;
if (type_ == HEADERS_AVAILABLE) {
// Callback for headers available.
if (!job_->has_response_started()) {
// Send header information.
job_->SendHeaders();
}
// This type of callback only ever needs to be called once.
Detach();
} else if (type_ == BYTES_AVAILABLE) {
// Callback for bytes available.
if (job_->has_response_started() && job_->GetStatus().is_io_pending()) {
// Read the bytes. They should be available but, if not, wait again.
int bytes_read = job_->ReadRawData(dest_, dest_size_);
if (bytes_read == net::ERR_IO_PENDING) {
// Still pending, nothing to do...
} else if (bytes_read >= 0) {
// Must clear the members here because they may be reset as a result
// of calling ReadRawDataComplete.
dest_size_ = 0;
dest_ = NULL;
// Notify about the available bytes. If bytes_read > 0 then
// ReadRawData may be called from URLRequest::Read. If bytes_read == 0
// then Kill will be called from the URLRequest destructor.
job_->ReadRawDataComplete(bytes_read);
} else {
// Failed due to an error.
NOTREACHED() << "ReadRawData returned error " << bytes_read;
job_->ReadRawDataComplete(bytes_read);
Detach();
}
}
}
}
void CancelOnIOThread() {
CEF_REQUIRE_IOT();
if (job_)
job_->Kill();
}
CefResourceRequestJob* job_;
Type type_;
net::IOBuffer* dest_;
int dest_size_;
IMPLEMENT_REFCOUNTING(CefResourceRequestJobCallback);
};
CefResourceRequestJob::CefResourceRequestJob(
net::URLRequest* request,
net::NetworkDelegate* network_delegate,
CefRefPtr<CefResourceHandler> handler)
: net::URLRequestJob(request, network_delegate),
handler_(handler),
done_(false),
remaining_bytes_(0),
sent_bytes_(0),
response_cookies_save_index_(0),
weak_factory_(this) {}
CefResourceRequestJob::~CefResourceRequestJob() {}
void CefResourceRequestJob::Start() {
CEF_REQUIRE_IOT();
request_start_time_ = base::Time::Now();
cef_request_ = CefRequest::Create();
// Populate the request data.
static_cast<CefRequestImpl*>(cef_request_.get())->Set(request_);
// Add default headers if not already specified.
const net::URLRequestContext* context = request_->context();
if (context) {
CefRequest::HeaderMap headerMap;
cef_request_->GetHeaderMap(headerMap);
bool changed = false;
const net::HttpUserAgentSettings* ua_settings =
context->http_user_agent_settings();
if (ua_settings) {
if (SetHeaderIfMissing(headerMap,
net::HttpRequestHeaders::kAcceptLanguage,
ua_settings->GetAcceptLanguage())) {
changed = true;
}
if (SetHeaderIfMissing(headerMap, net::HttpRequestHeaders::kUserAgent,
ua_settings->GetUserAgent())) {
changed = true;
}
}
if (changed)
cef_request_->SetHeaderMap(headerMap);
}
AddCookieHeaderAndStart();
}
void CefResourceRequestJob::Kill() {
CEF_REQUIRE_IOT();
if (!done_) {
// Notify the handler that the request has been canceled.
handler_->Cancel();
}
if (callback_.get()) {
callback_->Detach();
callback_ = NULL;
}
net::URLRequestJob::Kill();
}
// This method will be called by URLRequestJob::Read and our callback.
// It can indicate the following states:
// 1. Return ERR_IO_PENDING, and call ReadRawDataComplete when the read
// completes in any way, or
// 2. Return a count of bytes read >= 0, indicating synchronous success, or
// 3. Return another error code < 0, indicating synchronous failure.
int CefResourceRequestJob::ReadRawData(net::IOBuffer* dest, int dest_size) {
CEF_REQUIRE_IOT();
DCHECK_NE(dest_size, 0);
if (remaining_bytes_ == 0) {
// No more data to read.
DoneWithRequest();
return 0;
} else if (remaining_bytes_ > 0 && remaining_bytes_ < dest_size) {
// The handler knows the content size beforehand.
dest_size = static_cast<int>(remaining_bytes_);
}
if (!callback_.get()) {
// Create the bytes available callback that will be used until the request
// is completed.
callback_ = new CefResourceRequestJobCallback(
this, CefResourceRequestJobCallback::BYTES_AVAILABLE);
}
// Read response data from the handler.
int bytes_read = 0;
bool rv = handler_->ReadResponse(dest->data(), dest_size, bytes_read,
callback_.get());
if (!rv) {
// The handler has indicated completion of the request.
DoneWithRequest();
return 0;
} else if (bytes_read == 0) {
// Continue reading asynchronously. May happen multiple times in a row so
// only set destination members the first time.
if (!GetStatus().is_io_pending())
callback_->SetDestination(dest, dest_size);
return net::ERR_IO_PENDING;
} else if (bytes_read > dest_size) {
// Normalize the return value.
bytes_read = dest_size;
}
sent_bytes_ += bytes_read;
if (remaining_bytes_ > 0)
remaining_bytes_ -= bytes_read;
// Continue calling this method.
return bytes_read;
}
void CefResourceRequestJob::GetResponseInfo(net::HttpResponseInfo* info) {
CEF_REQUIRE_IOT();
info->headers = GetResponseHeaders();
}
void CefResourceRequestJob::GetLoadTimingInfo(
net::LoadTimingInfo* load_timing_info) const {
// If haven't made it far enough to receive any headers, don't return
// anything. This makes for more consistent behavior in the case of errors.
if (!response_.get() || receive_headers_end_.is_null())
return;
load_timing_info->request_start_time = request_start_time_;
load_timing_info->receive_headers_end = receive_headers_end_;
}
bool CefResourceRequestJob::IsRedirectResponse(
GURL* location,
int* http_status_code,
bool* insecure_scheme_was_upgraded) {
CEF_REQUIRE_IOT();
bool redirect = false;
*insecure_scheme_was_upgraded = false;
if (redirect_url_.is_valid()) {
// Redirect to the new URL.
*http_status_code = 303;
location->Swap(&redirect_url_);
redirect = true;
} else if (response_.get()) {
// Check for HTTP 302 or HTTP 303 redirect.
int status = response_->GetStatus();
if (net::HttpResponseHeaders::IsRedirectResponseCode(status)) {
CefResponse::HeaderMap headerMap;
response_->GetHeaderMap(headerMap);
CefRequest::HeaderMap::const_iterator iter =
FindHeader(headerMap, "Location");
if (iter != headerMap.end()) {
GURL new_url = request_->url().Resolve(std::string(iter->second));
if (new_url.is_valid()) {
*http_status_code = status;
*location = new_url;
redirect = true;
}
}
}
}
if (redirect) {
// Set the correct response status. This avoids a DCHECK in
// RedirectInfo::ComputeRedirectInfo.
request_->response_headers()->ReplaceStatusLine(
net_service::MakeStatusLine(*http_status_code, std::string(), true));
}
return redirect;
}
bool CefResourceRequestJob::GetMimeType(std::string* mime_type) const {
CEF_REQUIRE_IOT();
if (response_.get())
*mime_type = response_->GetMimeType();
return true;
}
bool CefResourceRequestJob::GetCharset(std::string* charset) {
CEF_REQUIRE_IOT();
if (net::HttpResponseHeaders* headers = GetResponseHeaders())
return headers->GetCharset(charset);
return false;
}
int CefResourceRequestJob::GetResponseCode() const {
CEF_REQUIRE_IOT();
if (response_.get())
return response_->GetStatus();
return -1;
}
void CefResourceRequestJob::SendHeaders() {
CEF_REQUIRE_IOT();
// Clear the headers available callback.
callback_ = NULL;
// We may have been orphaned...
if (!request())
return;
response_ = new CefResponseImpl();
remaining_bytes_ = 0;
// Set the response mime type if it can be determined from the file extension.
if (request_->url().has_path()) {
const std::string& path = request_->url().path();
size_t found = path.find_last_of(".");
if (found != std::string::npos) {
std::string suggest_mime_type;
if (net::GetWellKnownMimeTypeFromExtension(
base::FilePath::FromUTF8Unsafe(path.substr(found + 1)).value(),
&suggest_mime_type)) {
response_->SetMimeType(suggest_mime_type);
}
}
}
CefString redirectUrl;
// Get header information from the handler.
handler_->GetResponseHeaders(response_, remaining_bytes_, redirectUrl);
receive_headers_end_ = base::TimeTicks::Now();
if (response_->GetError() != ERR_NONE) {
const URLRequestStatus& status =
URLRequestStatus::FromError(response_->GetError());
if (status.status() == URLRequestStatus::CANCELED ||
status.status() == URLRequestStatus::FAILED) {
NotifyStartError(status);
return;
}
}
if (!redirectUrl.empty()) {
std::string redirectUrlStr = redirectUrl;
redirect_url_ = request_->url().Resolve(redirectUrlStr);
}
if (remaining_bytes_ > 0)
set_expected_content_size(remaining_bytes_);
// Continue processing the request.
SaveCookiesAndNotifyHeadersComplete();
}
void CefResourceRequestJob::AddCookieHeaderAndStart() {
// If the request was destroyed, then there is no more work to do.
if (!request_)
return;
net::CookieStore* cookie_store = request_->context()->cookie_store();
if (cookie_store &&
!(request_->load_flags() & net::LOAD_DO_NOT_SEND_COOKIES)) {
cookie_store->GetAllCookiesForURLAsync(
request_->url(),
base::Bind(&CefResourceRequestJob::CheckCookiePolicyAndLoad,
weak_factory_.GetWeakPtr()));
} else {
DoStartTransaction();
}
}
void CefResourceRequestJob::DoLoadCookies() {
net::CookieOptions options;
options.set_include_httponly();
request_->context()->cookie_store()->GetCookieListWithOptionsAsync(
request_->url(), options,
base::Bind(&CefResourceRequestJob::OnCookiesLoaded,
weak_factory_.GetWeakPtr()));
}
void CefResourceRequestJob::CheckCookiePolicyAndLoad(
const net::CookieList& cookie_list,
const net::CookieStatusList& excluded_list) {
const bool can_get_cookies =
!cookie_list.empty() && CanGetCookies(cookie_list);
if (can_get_cookies)
DoLoadCookies();
else
DoStartTransaction();
}
void CefResourceRequestJob::OnCookiesLoaded(
const net::CookieList& cookie_list,
const net::CookieStatusList& excluded_list) {
if (!cookie_list.empty()) {
const std::string& cookie_line =
net::CanonicalCookie::BuildCookieLine(cookie_list);
CefRequest::HeaderMap headerMap;
cef_request_->GetHeaderMap(headerMap);
headerMap.insert(
std::make_pair(net::HttpRequestHeaders::kCookie, cookie_line));
cef_request_->SetHeaderMap(headerMap);
}
DoStartTransaction();
}
void CefResourceRequestJob::DoStartTransaction() {
// We may have been canceled while retrieving cookies.
if (GetStatus().is_success()) {
StartTransaction();
} else {
NotifyCanceled();
}
}
void CefResourceRequestJob::StartTransaction() {
// Create the callback that will be used to notify when header information is
// available.
callback_ = new CefResourceRequestJobCallback(
this, CefResourceRequestJobCallback::HEADERS_AVAILABLE);
// Protect against deletion of this object.
base::WeakPtr<CefResourceRequestJob> weak_ptr(weak_factory_.GetWeakPtr());
// Handler can decide whether to process the request.
bool rv = handler_->ProcessRequest(cef_request_, callback_.get());
if (weak_ptr.get() && !rv) {
// Cancel the request.
NotifyCanceled();
}
}
net::HttpResponseHeaders* CefResourceRequestJob::GetResponseHeaders() {
DCHECK(response_.get());
if (!response_headers_.get()) {
CefResponseImpl* responseImpl =
static_cast<CefResponseImpl*>(response_.get());
response_headers_ = responseImpl->GetResponseHeaders();
}
return response_headers_.get();
}
void CefResourceRequestJob::SaveCookiesAndNotifyHeadersComplete() {
if (request_->load_flags() & net::LOAD_DO_NOT_SAVE_COOKIES) {
NotifyHeadersComplete();
return;
}
response_cookies_.clear();
response_cookies_save_index_ = 0;
FetchResponseCookies(&response_cookies_);
// Now, loop over the response cookies, and attempt to persist each.
SaveNextCookie();
}
void CefResourceRequestJob::SaveNextCookie() {
if (response_cookies_save_index_ == response_cookies_.size()) {
response_cookies_.clear();
response_cookies_save_index_ = 0;
NotifyHeadersComplete();
return;
}
const std::string& cookie_line =
response_cookies_[response_cookies_save_index_];
net::CookieOptions options;
options.set_include_httponly();
std::unique_ptr<net::CanonicalCookie> cookie = net::CanonicalCookie::Create(
request_->url(), cookie_line, base::Time::Now(), options);
const bool can_set_cookie = cookie && CanSetCookie(*cookie, &options);
if (can_set_cookie) {
request_->context()->cookie_store()->SetCanonicalCookieAsync(
std::move(cookie), request_->url().scheme(), options,
base::Bind(&CefResourceRequestJob::OnCookieSaved,
weak_factory_.GetWeakPtr()));
return;
}
CookieHandled();
}
void CefResourceRequestJob::OnCookieSaved(
net::CanonicalCookie::CookieInclusionStatus status) {
CookieHandled();
}
void CefResourceRequestJob::CookieHandled() {
response_cookies_save_index_++;
// We may have been canceled within OnSetCookie.
if (GetStatus().is_success()) {
SaveNextCookie();
} else {
NotifyCanceled();
}
}
void CefResourceRequestJob::FetchResponseCookies(
std::vector<std::string>* cookies) {
const std::string name = "Set-Cookie";
std::string value;
size_t iter = 0;
net::HttpResponseHeaders* headers = GetResponseHeaders();
while (headers->EnumerateHeader(&iter, name, &value)) {
if (!value.empty())
cookies->push_back(value);
}
}
void CefResourceRequestJob::DoneWithRequest() {
if (done_)
return;
done_ = true;
if (request_)
request_->set_received_response_content_length(sent_bytes_);
}

View File

@ -1,92 +0,0 @@
// Copyright (c) 2012 The Chromium Embedded Framework Authors.
// Portions copyright (c) 2006-2009 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_RESOURCE_REQUEST_JOB_H_
#define CEF_LIBCEF_BROWSER_RESOURCE_REQUEST_JOB_H_
#include <stdint.h>
#include <string>
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "include/cef_request_handler.h"
#include "net/cookies/cookie_monster.h"
#include "net/url_request/url_request_job.h"
namespace net {
class HttpResponseHeaders;
class URLRequest;
} // namespace net
class CefResourceRequestJobCallback;
class CefResourceRequestJob : public net::URLRequestJob {
public:
CefResourceRequestJob(net::URLRequest* request,
net::NetworkDelegate* network_delegate,
CefRefPtr<CefResourceHandler> handler);
~CefResourceRequestJob() override;
private:
// net::URLRequestJob methods.
void Start() override;
void Kill() override;
int ReadRawData(net::IOBuffer* dest, int dest_size) override;
void GetResponseInfo(net::HttpResponseInfo* info) override;
void GetLoadTimingInfo(net::LoadTimingInfo* load_timing_info) const override;
bool IsRedirectResponse(GURL* location,
int* http_status_code,
bool* insecure_scheme_was_upgraded) override;
bool GetMimeType(std::string* mime_type) const override;
bool GetCharset(std::string* charset) override;
int GetResponseCode() const override;
void SendHeaders();
// Used for sending cookies with the request.
void AddCookieHeaderAndStart();
void DoLoadCookies();
void CheckCookiePolicyAndLoad(const net::CookieList& cookie_list,
const net::CookieStatusList& excluded_list);
void OnCookiesLoaded(const net::CookieList& cookie_list,
const net::CookieStatusList& excluded_list);
void DoStartTransaction();
void StartTransaction();
// Used for saving cookies returned as part of the response.
net::HttpResponseHeaders* GetResponseHeaders();
void SaveCookiesAndNotifyHeadersComplete();
void SaveNextCookie();
void OnCookieSaved(net::CanonicalCookie::CookieInclusionStatus status);
void CookieHandled();
void FetchResponseCookies(std::vector<std::string>* cookies);
void DoneWithRequest();
CefRefPtr<CefResourceHandler> handler_;
bool done_;
CefRefPtr<CefResponse> response_;
GURL redirect_url_;
int64_t remaining_bytes_;
int64_t sent_bytes_;
CefRefPtr<CefRequest> cef_request_;
CefRefPtr<CefResourceRequestJobCallback> callback_;
scoped_refptr<net::HttpResponseHeaders> response_headers_;
std::vector<std::string> response_cookies_;
size_t response_cookies_save_index_;
base::Time request_start_time_;
base::TimeTicks receive_headers_end_;
// Must be the last member.
base::WeakPtrFactory<CefResourceRequestJob> weak_factory_;
friend class CefResourceRequestJobCallback;
DISALLOW_COPY_AND_ASSIGN(CefResourceRequestJob);
};
#endif // CEF_LIBCEF_BROWSER_RESOURCE_REQUEST_JOB_H_

View File

@ -8,74 +8,12 @@
#include "libcef/browser/net/chrome_scheme_handler.h" #include "libcef/browser/net/chrome_scheme_handler.h"
#include "libcef/browser/net/devtools_scheme_handler.h" #include "libcef/browser/net/devtools_scheme_handler.h"
#include "libcef/browser/resource_context.h"
#include "libcef/common/net/scheme_registration.h" #include "libcef/common/net/scheme_registration.h"
#include "base/memory/ptr_util.h"
#include "base/task/post_task.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/common/url_constants.h" #include "content/public/common/url_constants.h"
#include "net/net_buildflags.h"
#include "net/url_request/data_protocol_handler.h"
#include "net/url_request/file_protocol_handler.h"
#include "net/url_request/ftp_protocol_handler.h"
#include "net/url_request/url_request_job_factory_impl.h"
#include "url/url_constants.h"
namespace scheme { namespace scheme {
void InstallInternalProtectedHandlers(
net::URLRequestJobFactoryImpl* job_factory,
CefURLRequestManager* request_manager,
content::ProtocolHandlerMap* protocol_handlers,
net::HostResolver* host_resolver) {
protocol_handlers->insert(std::make_pair(
url::kDataScheme, std::make_unique<net::DataProtocolHandler>()));
protocol_handlers->insert(std::make_pair(
url::kFileScheme,
std::make_unique<net::FileProtocolHandler>(
base::CreateTaskRunnerWithTraits(
{base::MayBlock(), base::TaskPriority::USER_VISIBLE,
base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}))));
#if !BUILDFLAG(DISABLE_FTP_SUPPORT)
protocol_handlers->insert(std::make_pair(
url::kFtpScheme, net::FtpProtocolHandler::Create(host_resolver)));
#endif
for (content::ProtocolHandlerMap::iterator it = protocol_handlers->begin();
it != protocol_handlers->end(); ++it) {
const std::string& scheme = it->first;
std::unique_ptr<net::URLRequestJobFactory::ProtocolHandler>
protocol_handler;
if (scheme == content::kChromeDevToolsScheme) {
// Don't use the default "chrome-devtools" handler.
continue;
} else if (scheme == content::kChromeUIScheme) {
// Filter the URLs that are passed to the default "chrome" handler so as
// not to interfere with CEF's "chrome" handler.
protocol_handler.reset(
scheme::WrapChromeProtocolHandler(
request_manager, base::WrapUnique(it->second.release()))
.release());
} else {
protocol_handler.reset(it->second.release());
}
// Make sure IsInternalProtectedScheme() stays synchronized with what
// Chromium is actually giving us.
DCHECK(IsInternalProtectedScheme(scheme));
bool set_protocol = job_factory->SetProtocolHandler(
scheme, base::WrapUnique(protocol_handler.release()));
DCHECK(set_protocol);
}
}
void RegisterInternalHandlers(CefURLRequestManager* request_manager) {
scheme::RegisterChromeDevToolsHandler(request_manager);
}
void RegisterInternalHandlers(CefResourceContext* resource_context) { void RegisterInternalHandlers(CefResourceContext* resource_context) {
scheme::RegisterChromeDevToolsHandler(resource_context); scheme::RegisterChromeDevToolsHandler(resource_context);
} }

View File

@ -11,26 +11,11 @@
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace net {
class HostResolver;
class URLRequestJobFactoryImpl;
} // namespace net
class CefResourceContext; class CefResourceContext;
class CefURLRequestManager;
namespace scheme { namespace scheme {
// Install the internal scheme handlers provided by Chromium that cannot be
// overridden.
void InstallInternalProtectedHandlers(
net::URLRequestJobFactoryImpl* job_factory,
CefURLRequestManager* request_manager,
content::ProtocolHandlerMap* protocol_handlers,
net::HostResolver* host_resolver);
// Register the internal scheme handlers that can be overridden. // Register the internal scheme handlers that can be overridden.
void RegisterInternalHandlers(CefURLRequestManager* request_manager);
void RegisterInternalHandlers(CefResourceContext* resource_context); void RegisterInternalHandlers(CefResourceContext* resource_context);
// Used to fire any asynchronous content updates. // Used to fire any asynchronous content updates.

View File

@ -1,74 +0,0 @@
// Copyright 2016 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/source_stream.h"
#include <utility>
#include "net/base/io_buffer.h"
// Use TYPE_INVALID so that URLRequestJob::NotifyHeadersComplete() doesn't
// assume that the "content-length" header is accurate.
CefSourceStream::CefSourceStream(CefRefPtr<CefResponseFilter> cef_filter,
std::unique_ptr<net::SourceStream> upstream)
: net::FilterSourceStream(net::SourceStream::TYPE_INVALID,
std::move(upstream)),
cef_filter_(cef_filter) {}
int CefSourceStream::FilterData(net::IOBuffer* output_buffer,
int output_buffer_size,
net::IOBuffer* input_buffer,
int input_buffer_size,
int* consumed_bytes,
bool upstream_eof_reached) {
if (!output_buffer || output_buffer_size <= 0)
return net::ERR_CONTENT_DECODING_FAILED;
if (input_buffer_size == 0 && last_status_ == RESPONSE_FILTER_DONE) {
// No more input data. Respect the client's desire to be done with
// outputting data.
*consumed_bytes = 0;
return 0;
}
size_t data_in_size = static_cast<size_t>(input_buffer_size);
size_t data_in_read = 0;
size_t data_out_size = static_cast<size_t>(output_buffer_size);
size_t data_out_written = 0;
last_status_ = cef_filter_->Filter(
data_in_size > 0 ? input_buffer->data() : nullptr, data_in_size,
data_in_read, output_buffer->data(), data_out_size, data_out_written);
// Return early if there's an error.
if (last_status_ == RESPONSE_FILTER_ERROR)
return net::ERR_CONTENT_DECODING_FAILED;
// Validate the out values.
if (data_in_read > data_in_size) {
LOG(ERROR) << "potential buffer overflow; data_in_read > data_in_size";
return net::ERR_CONTENT_DECODING_FAILED;
}
if (data_out_written > data_out_size) {
LOG(ERROR) << "potential buffer overflow; data_out_written > data_out_size";
return net::ERR_CONTENT_DECODING_FAILED;
}
// If FilterData() returns 0, *|consumed_bytes| must be equal to
// |input_buffer_size|.
if (data_out_written == 0 && data_in_read != data_in_size) {
LOG(ERROR) << "when no data is written all input must be consumed; "
"data_out_written == 0 && data_in_read != data_in_size";
return net::ERR_CONTENT_DECODING_FAILED;
}
*consumed_bytes = static_cast<int>(data_in_read);
// Output the number of bytes written.
return static_cast<int>(data_out_written);
}
std::string CefSourceStream::GetTypeAsString() const {
return "cef_filter";
}

View File

@ -1,34 +0,0 @@
// Copyright 2016 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_SOURCE_STREAM_H_
#define CEF_LIBCEF_BROWSER_NET_SOURCE_STREAM_H_
#include "include/cef_response_filter.h"
#include "base/macros.h"
#include "net/filter/filter_source_stream.h"
class CefSourceStream : public net::FilterSourceStream {
public:
CefSourceStream(CefRefPtr<CefResponseFilter> cef_filter,
std::unique_ptr<net::SourceStream> upstream);
int FilterData(net::IOBuffer* output_buffer,
int output_buffer_size,
net::IOBuffer* input_buffer,
int input_buffer_size,
int* consumed_bytes,
bool upstream_eof_reached) override;
std::string GetTypeAsString() const override;
private:
CefRefPtr<CefResponseFilter> cef_filter_;
cef_response_filter_status_t last_status_ = RESPONSE_FILTER_NEED_MORE_DATA;
DISALLOW_COPY_AND_ASSIGN(CefSourceStream);
};
#endif // CEF_LIBCEF_BROWSER_NET_SOURCE_STREAM_H_

View File

@ -1,21 +0,0 @@
// Copyright (c) 2015 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/net/url_request_context.h"
#if DCHECK_IS_ON()
base::AtomicRefCount CefURLRequestContext::DebugObjCt;
#endif
CefURLRequestContext::CefURLRequestContext() {
#if DCHECK_IS_ON()
DebugObjCt.Increment();
#endif
}
CefURLRequestContext::~CefURLRequestContext() {
#if DCHECK_IS_ON()
DebugObjCt.Decrement();
#endif
}

View File

@ -1,31 +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_H_
#define CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_H_
#pragma once
#include "base/logging.h"
#include "net/url_request/url_request_context.h"
// Owns URLRequest instances and provides access to network-related
// functionality. Life span is controlled by CefURLRequestContextGetter*. Only
// accessed on the IO thread. URLRequest objects are created via ResourceContext
// and URLFetcher. All URLRequest objects must be destroyed before this object
// is destroyed. See browser_context.h for an object relationship diagram.
class CefURLRequestContext : public net::URLRequestContext {
public:
CefURLRequestContext();
~CefURLRequestContext() override;
#if DCHECK_IS_ON()
// Simple tracking of allocated objects.
static base::AtomicRefCount DebugObjCt;
#endif
private:
DISALLOW_COPY_AND_ASSIGN(CefURLRequestContext);
};
#endif // CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_H_

View File

@ -1,556 +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/net/url_request_context_getter.h"
#include <string>
#include <utility>
#include <vector>
#include "libcef/browser/content_browser_client.h"
#include "libcef/browser/net/cookie_manager_old_impl.h"
#include "libcef/browser/net/network_delegate.h"
#include "libcef/browser/net/scheme_handler.h"
#include "libcef/browser/net/url_request_interceptor.h"
#include "libcef/browser/thread_util.h"
#include "libcef/common/cef_switches.h"
#include "libcef/common/content_client.h"
#include "base/build_time.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"
#include "base/strings/string_util.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "components/certificate_transparency/chrome_ct_policy_enforcer.h"
#include "components/certificate_transparency/ct_known_logs.h"
#include "components/net_log/chrome_net_log.h"
#include "components/network_session_configurator/browser/network_session_configurator.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/common/content_client.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/url_constants.h"
#include "net/base/http_user_agent_settings.h"
#include "net/cert/cert_verifier.h"
#include "net/cert/ct_log_verifier.h"
#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"
#include "net/http/http_cache.h"
#include "net/http/http_server_properties_impl.h"
#include "net/http/http_util.h"
#include "net/http/transport_security_state.h"
#include "net/proxy_resolution/dhcp_pac_file_fetcher_factory.h"
#include "net/proxy_resolution/pac_file_fetcher_impl.h"
#include "net/proxy_resolution/proxy_resolution_service.h"
#include "net/ssl/ssl_config_service_defaults.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_storage.h"
#include "net/url_request/url_request_intercepting_job_factory.h"
#include "net/url_request/url_request_job_factory_impl.h"
#include "net/url_request/url_request_job_manager.h"
#include "services/network/proxy_service_mojo.h"
#include "url/url_constants.h"
#if defined(OS_WIN)
#include <winhttp.h>
#endif
#if defined(USE_NSS_CERTS)
#include "net/cert_net/nss_ocsp.h"
#endif
using content::BrowserThread;
#if defined(OS_WIN)
#pragma comment(lib, "winhttp.lib")
#endif
namespace {
// An implementation of |HttpUserAgentSettings| that provides a static
// HTTP Accept-Language header value and uses |content::GetUserAgent|
// to provide the HTTP User-Agent header value.
class CefHttpUserAgentSettings : public net::HttpUserAgentSettings {
public:
explicit CefHttpUserAgentSettings(const std::string& raw_language_list)
: http_accept_language_(
net::HttpUtil::GenerateAcceptLanguageHeader(raw_language_list)) {
CEF_REQUIRE_IOT();
}
// net::HttpUserAgentSettings implementation
std::string GetAcceptLanguage() const override {
CEF_REQUIRE_IOT();
return http_accept_language_;
}
std::string GetUserAgent() const override {
CEF_REQUIRE_IOT();
return CefContentClient::Get()->browser()->GetUserAgent();
}
private:
const std::string http_accept_language_;
DISALLOW_COPY_AND_ASSIGN(CefHttpUserAgentSettings);
};
// Based on ProxyResolutionServiceFactory::CreateProxyResolutionService which
// was deleted in http://crrev.com/1c261ff4.
std::unique_ptr<net::ProxyResolutionService> CreateProxyResolutionService(
net::NetLog* net_log,
net::URLRequestContext* context,
net::NetworkDelegate* network_delegate,
proxy_resolver::mojom::ProxyResolverFactoryPtr proxy_resolver_factory,
std::unique_ptr<net::ProxyConfigService> proxy_config_service,
const base::CommandLine& command_line,
bool quick_check_enabled) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
bool use_v8 = !command_line.HasSwitch(switches::kWinHttpProxyResolver);
// TODO(eroman): Figure out why this doesn't work in single-process mode.
// Should be possible now that a private isolate is used.
// http://crbug.com/474654
if (use_v8 && command_line.HasSwitch(switches::kSingleProcess)) {
LOG(ERROR) << "Cannot use V8 Proxy resolver in single process mode.";
use_v8 = false; // Fallback to non-v8 implementation.
}
std::unique_ptr<net::ProxyResolutionService> proxy_service;
if (use_v8) {
std::unique_ptr<net::DhcpPacFileFetcher> dhcp_pac_file_fetcher;
net::DhcpPacFileFetcherFactory dhcp_factory;
dhcp_pac_file_fetcher = dhcp_factory.Create(context);
proxy_service = network::CreateProxyResolutionServiceUsingMojoFactory(
std::move(proxy_resolver_factory), std::move(proxy_config_service),
net::PacFileFetcherImpl::Create(context),
std::move(dhcp_pac_file_fetcher), context->host_resolver(), net_log,
network_delegate);
} else {
proxy_service = net::ProxyResolutionService::CreateUsingSystemProxyResolver(
std::move(proxy_config_service), net_log);
}
proxy_service->set_quick_check_enabled(quick_check_enabled);
return proxy_service;
}
// Based on net::ct::CreateLogVerifiersForKnownLogs which was deleted in
// https://crrev.com/24711fe395.
std::vector<scoped_refptr<const net::CTLogVerifier>>
CreateLogVerifiersForKnownLogs() {
std::vector<scoped_refptr<const net::CTLogVerifier>> verifiers;
for (const auto& log : certificate_transparency::GetKnownLogs()) {
scoped_refptr<const net::CTLogVerifier> log_verifier =
net::CTLogVerifier::Create(
base::StringPiece(log.log_key, log.log_key_length), log.log_name);
// Make sure no null logs enter verifiers. Parsing of all statically
// configured logs should always succeed, unless there has been binary or
// memory corruption.
CHECK(log_verifier);
verifiers.push_back(std::move(log_verifier));
}
return verifiers;
}
} // namespace
CefURLRequestContextGetter::CefURLRequestContextGetter(
const CefRequestContextSettings& settings,
PrefService* pref_service,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
content::ProtocolHandlerMap* protocol_handlers,
std::unique_ptr<net::ProxyConfigService> proxy_config_service,
content::URLRequestInterceptorScopedVector request_interceptors)
: settings_(settings), io_state_(std::make_unique<IOState>()) {
// Must first be created on the UI thread.
CEF_REQUIRE_UIT();
io_state_->net_log_ = g_browser_process->net_log(),
DCHECK(io_state_->net_log_);
io_state_->io_task_runner_ = std::move(io_task_runner);
io_state_->proxy_resolver_factory_ =
ChromeMojoProxyResolverFactory::CreateWithStrongBinding();
io_state_->proxy_config_service_ = std::move(proxy_config_service);
io_state_->request_interceptors_ = std::move(request_interceptors);
std::swap(io_state_->protocol_handlers_, *protocol_handlers);
auto io_thread_proxy =
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO});
quick_check_enabled_.Init(prefs::kQuickCheckEnabled, pref_service);
quick_check_enabled_.MoveToThread(io_thread_proxy);
force_google_safesearch_.Init(prefs::kForceGoogleSafeSearch, pref_service);
force_google_safesearch_.MoveToThread(io_thread_proxy);
#if defined(OS_POSIX) && !defined(OS_ANDROID)
io_state_->gsapi_library_name_ =
pref_service->GetString(prefs::kGSSAPILibraryName);
#endif
auth_server_whitelist_.Init(
prefs::kAuthServerWhitelist, pref_service,
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(&CefURLRequestContextGetter::UpdateDelegateWhitelist,
base::Unretained(this)));
auth_negotiate_delegate_whitelist_.MoveToThread(io_thread_proxy);
}
CefURLRequestContextGetter::~CefURLRequestContextGetter() {
CEF_REQUIRE_IOT();
// This destructor may not be called during shutdown. Perform any required
// shutdown in ShutdownOnIOThread() instead.
}
// static
void CefURLRequestContextGetter::RegisterPrefs(PrefRegistrySimple* registry) {
// Based on IOThread::RegisterPrefs.
#if defined(OS_POSIX) && !defined(OS_ANDROID)
registry->RegisterStringPref(prefs::kGSSAPILibraryName, std::string());
#endif
registry->RegisterBooleanPref(prefs::kQuickCheckEnabled, true);
// Based on ProfileImpl::RegisterProfilePrefs.
registry->RegisterBooleanPref(prefs::kForceGoogleSafeSearch, false);
// Based on IOThread::RegisterPrefs.
registry->RegisterStringPref(prefs::kAuthServerWhitelist, "");
registry->RegisterStringPref(prefs::kAuthNegotiateDelegateWhitelist, "");
}
void CefURLRequestContextGetter::ShutdownOnUIThread() {
CEF_REQUIRE_UIT();
quick_check_enabled_.Destroy();
force_google_safesearch_.Destroy();
auth_server_whitelist_.Destroy();
auth_negotiate_delegate_whitelist_.Destroy();
CEF_POST_TASK(
CEF_IOT,
base::Bind(&CefURLRequestContextGetter::ShutdownOnIOThread, this));
}
void CefURLRequestContextGetter::ShutdownOnIOThread() {
CEF_REQUIRE_IOT();
shutting_down_ = true;
// Delete the ProxyResolutionService object here so that any pending requests
// will be canceled before the URLRequestContext is destroyed.
io_state_->storage_->set_proxy_resolution_service(NULL);
io_state_.reset();
NotifyContextShuttingDown();
}
net::URLRequestContext* CefURLRequestContextGetter::GetURLRequestContext() {
CEF_REQUIRE_IOT();
if (shutting_down_)
return nullptr;
if (!io_state_->url_request_context_.get()) {
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
base::FilePath cache_path;
if (settings_.cache_path.length > 0)
cache_path = base::FilePath(CefString(&settings_.cache_path));
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);
io_state_->storage_.reset(new net::URLRequestContextStorage(
io_state_->url_request_context_.get()));
SetCookieStoragePath(cache_path,
settings_.persist_session_cookies ? true : false);
std::unique_ptr<CefNetworkDelegate> network_delegate(
new CefNetworkDelegate());
network_delegate->set_force_google_safesearch(&force_google_safesearch_);
io_state_->storage_->set_network_delegate(std::move(network_delegate));
const std::string& accept_language =
settings_.accept_language_list.length > 0
? CefString(&settings_.accept_language_list)
: "en-US,en";
io_state_->storage_->set_http_user_agent_settings(
base::WrapUnique(new CefHttpUserAgentSettings(accept_language)));
io_state_->storage_->set_host_resolver(
net::HostResolver::CreateStandaloneResolver(io_state_->net_log_));
io_state_->storage_->set_cert_verifier(
net::CertVerifier::CreateDefault(/*cert_net_fetcher=*/nullptr));
std::unique_ptr<net::TransportSecurityState> transport_security_state(
new net::TransportSecurityState);
transport_security_state->set_enforce_net_security_expiration(
settings_.enable_net_security_expiration ? true : false);
io_state_->storage_->set_transport_security_state(
std::move(transport_security_state));
std::vector<scoped_refptr<const net::CTLogVerifier>> ct_logs(
CreateLogVerifiersForKnownLogs());
std::unique_ptr<net::MultiLogCTVerifier> ct_verifier(
new net::MultiLogCTVerifier());
ct_verifier->AddLogs(ct_logs);
io_state_->storage_->set_cert_transparency_verifier(std::move(ct_verifier));
std::unique_ptr<certificate_transparency::ChromeCTPolicyEnforcer>
ct_policy_enforcer(new certificate_transparency::ChromeCTPolicyEnforcer(
base::GetBuildTime(),
certificate_transparency::GetDisqualifiedLogs(),
certificate_transparency::GetLogsOperatedByGoogle()));
io_state_->storage_->set_ct_policy_enforcer(std::move(ct_policy_enforcer));
std::unique_ptr<net::ProxyResolutionService> system_proxy_service =
CreateProxyResolutionService(
io_state_->net_log_, io_state_->url_request_context_.get(),
io_state_->url_request_context_->network_delegate(),
std::move(io_state_->proxy_resolver_factory_),
std::move(io_state_->proxy_config_service_), *command_line,
quick_check_enabled_.GetValue());
io_state_->storage_->set_proxy_resolution_service(
std::move(system_proxy_service));
io_state_->storage_->set_ssl_config_service(
std::make_unique<net::SSLConfigServiceDefaults>());
std::vector<std::string> supported_schemes;
supported_schemes.push_back("basic");
supported_schemes.push_back("digest");
supported_schemes.push_back("ntlm");
supported_schemes.push_back("negotiate");
io_state_->http_auth_preferences_.reset(new net::HttpAuthPreferences());
io_state_->storage_->set_http_auth_handler_factory(
net::HttpAuthHandlerRegistryFactory::Create(
io_state_->http_auth_preferences_.get(), supported_schemes
#if defined(OS_POSIX) && !defined(OS_ANDROID)
,
io_state_->gsapi_library_name_
#endif
));
io_state_->storage_->set_http_server_properties(
base::WrapUnique(new net::HttpServerPropertiesImpl));
base::FilePath http_cache_path;
if (!cache_path.empty())
http_cache_path = cache_path.Append(FILE_PATH_LITERAL("Cache"));
UpdateServerWhitelist();
UpdateDelegateWhitelist();
std::unique_ptr<net::HttpCache::DefaultBackend> main_backend(
new net::HttpCache::DefaultBackend(
cache_path.empty() ? net::MEMORY_CACHE : net::DISK_CACHE,
net::CACHE_BACKEND_DEFAULT, http_cache_path, 0));
net::HttpNetworkSession::Context network_session_context;
network_session_context.host_resolver =
io_state_->url_request_context_->host_resolver();
network_session_context.cert_verifier =
io_state_->url_request_context_->cert_verifier();
network_session_context.transport_security_state =
io_state_->url_request_context_->transport_security_state();
network_session_context.cert_transparency_verifier =
io_state_->url_request_context_->cert_transparency_verifier();
network_session_context.ct_policy_enforcer =
io_state_->url_request_context_->ct_policy_enforcer();
network_session_context.proxy_resolution_service =
io_state_->url_request_context_->proxy_resolution_service();
network_session_context.ssl_config_service =
io_state_->url_request_context_->ssl_config_service();
network_session_context.http_auth_handler_factory =
io_state_->url_request_context_->http_auth_handler_factory();
network_session_context.http_server_properties =
io_state_->url_request_context_->http_server_properties();
network_session_context.net_log = io_state_->net_log_;
net::HttpNetworkSession::Params network_session_params;
network_session_configurator::ParseCommandLineAndFieldTrials(
*base::CommandLine::ForCurrentProcess(),
false /* is_quic_force_disabled */,
CefContentClient::Get()
->browser()
->GetUserAgent() /* quic_user_agent_id */,
&network_session_params);
network_session_params.ignore_certificate_errors =
settings_.ignore_certificate_errors ? true : false;
io_state_->storage_->set_http_network_session(
base::WrapUnique(new net::HttpNetworkSession(network_session_params,
network_session_context)));
io_state_->storage_->set_http_transaction_factory(
base::WrapUnique(new net::HttpCache(
io_state_->storage_->http_network_session(),
std::move(main_backend), true /* set_up_quic_server_info */)));
std::unique_ptr<net::URLRequestJobFactoryImpl> job_factory(
new net::URLRequestJobFactoryImpl());
io_state_->url_request_manager_.reset(
new CefURLRequestManager(job_factory.get()));
// Install internal scheme handlers that cannot be overridden.
scheme::InstallInternalProtectedHandlers(
job_factory.get(), io_state_->url_request_manager_.get(),
&io_state_->protocol_handlers_, network_session_context.host_resolver);
io_state_->protocol_handlers_.clear();
// Register internal scheme handlers that can be overridden.
scheme::RegisterInternalHandlers(io_state_->url_request_manager_.get());
io_state_->request_interceptors_.push_back(
std::make_unique<CefRequestInterceptor>());
// Set up interceptors in the reverse order.
std::unique_ptr<net::URLRequestJobFactory> top_job_factory =
std::move(job_factory);
for (auto i = io_state_->request_interceptors_.rbegin();
i != io_state_->request_interceptors_.rend(); ++i) {
top_job_factory.reset(new net::URLRequestInterceptingJobFactory(
std::move(top_job_factory), std::move(*i)));
}
io_state_->request_interceptors_.clear();
io_state_->storage_->set_job_factory(std::move(top_job_factory));
#if defined(USE_NSS_CERTS)
// Only do this for the first (global) request context.
static bool request_context_for_nss_set = false;
if (!request_context_for_nss_set) {
net::SetURLRequestContextForNSSHttpIO(
io_state_->url_request_context_.get());
request_context_for_nss_set = true;
}
#endif
}
return io_state_->url_request_context_.get();
}
scoped_refptr<base::SingleThreadTaskRunner>
CefURLRequestContextGetter::GetNetworkTaskRunner() const {
return base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO});
}
net::HostResolver* CefURLRequestContextGetter::GetHostResolver() const {
return io_state_->url_request_context_->host_resolver();
}
void CefURLRequestContextGetter::SetCookieSupportedSchemes(
const std::vector<std::string>& schemes,
bool include_defaults) {
CEF_REQUIRE_IOT();
io_state_->cookie_supported_schemes_ = schemes;
io_state_->include_defaults_ = include_defaults;
CefCookieManagerOldImpl::SetCookieMonsterSchemes(
static_cast<net::CookieMonster*>(GetExistingCookieStore()), schemes,
include_defaults);
}
void CefURLRequestContextGetter::AddHandler(
CefRefPtr<CefRequestContextHandler> handler) {
if (!CEF_CURRENTLY_ON_IOT()) {
CEF_POST_TASK(CEF_IOT, base::Bind(&CefURLRequestContextGetter::AddHandler,
this, handler));
return;
}
io_state_->handler_list_.push_back(handler);
}
net::CookieStore* CefURLRequestContextGetter::GetExistingCookieStore() const {
CEF_REQUIRE_IOT();
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 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<net::SQLitePersistentCookieStore> 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<net::CookieMonster> cookie_monster(
new net::CookieMonster(persistent_store.get(), 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.
CefCookieManagerOldImpl::SetCookieMonsterSchemes(
cookie_monster.get(), io_state_->cookie_supported_schemes_,
io_state_->include_defaults_);
io_state_->storage_->set_cookie_store(std::move(cookie_monster));
}
void CefURLRequestContextGetter::UpdateServerWhitelist() {
io_state_->http_auth_preferences_->SetServerWhitelist(
auth_server_whitelist_.GetValue());
}
void CefURLRequestContextGetter::UpdateDelegateWhitelist() {
io_state_->http_auth_preferences_->SetDelegateWhitelist(
auth_negotiate_delegate_whitelist_.GetValue());
}

View File

@ -1,139 +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 <set>
#include <string>
#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;
}
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(
const CefRequestContextSettings& settings,
PrefService* pref_service,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
content::ProtocolHandlerMap* protocol_handlers,
std::unique_ptr<net::ProxyConfigService> proxy_config_service,
content::URLRequestInterceptorScopedVector request_interceptors);
~CefURLRequestContextGetter() 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<base::SingleThreadTaskRunner> GetNetworkTaskRunner()
const override;
// CefURLRequestContextGetter implementation.
net::HostResolver* GetHostResolver() const;
void SetCookieSupportedSchemes(const std::vector<std::string>& schemes,
bool include_defaults);
// Keep a reference to all handlers sharing this context so that they'll be
// kept alive until the context is destroyed.
void AddHandler(CefRefPtr<CefRequestContextHandler> 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<base::SingleThreadTaskRunner> io_task_runner_;
#if defined(OS_POSIX) && !defined(OS_ANDROID)
std::string gsapi_library_name_;
#endif
std::unique_ptr<net::ProxyConfigService> proxy_config_service_;
std::unique_ptr<net::URLRequestContextStorage> storage_;
std::unique_ptr<net::HttpAuthPreferences> http_auth_preferences_;
std::unique_ptr<CefURLRequestContext> url_request_context_;
std::unique_ptr<CefURLRequestManager> url_request_manager_;
content::ProtocolHandlerMap protocol_handlers_;
content::URLRequestInterceptorScopedVector request_interceptors_;
base::FilePath cookie_store_path_;
std::vector<std::string> cookie_supported_schemes_;
bool include_defaults_ = true;
std::vector<CefRefPtr<CefRequestContextHandler>> handler_list_;
proxy_resolver::mojom::ProxyResolverFactoryPtr proxy_resolver_factory_;
};
std::unique_ptr<IOState> io_state_;
BooleanPrefMember quick_check_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_IMPL_H_

View File

@ -1,142 +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_interceptor.h"
#include <string>
#include "libcef/browser/browser_host_impl.h"
#include "libcef/browser/net/net_util.h"
#include "libcef/browser/net/resource_request_job.h"
#include "libcef/browser/thread_util.h"
#include "libcef/common/net/http_header_utils.h"
#include "libcef/common/request_impl.h"
#include "libcef/common/response_impl.h"
#include "net/base/upload_data_stream.h"
#include "net/http/http_response_headers.h"
#include "net/url_request/url_request_job_manager.h"
#include "net/url_request/url_request_redirect_job.h"
CefRequestInterceptor::CefRequestInterceptor() {
CEF_REQUIRE_IOT();
}
CefRequestInterceptor::~CefRequestInterceptor() {
CEF_REQUIRE_IOT();
}
net::URLRequestJob* CefRequestInterceptor::MaybeInterceptRequest(
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const {
if (net_util::IsInternalRequest(request))
return nullptr;
CefRefPtr<CefRequestImpl> requestPtr;
CefRefPtr<CefBrowser> browser;
CefRefPtr<CefFrame> frame;
CefRefPtr<CefResourceRequestHandler> handler =
net_util::GetResourceRequestHandler(request, requestPtr, browser, frame);
if (handler) {
// Give the client an opportunity to replace the request.
CefRefPtr<CefResourceHandler> resourceHandler =
handler->GetResourceHandler(browser, frame, requestPtr.get());
if (resourceHandler) {
return new CefResourceRequestJob(request, network_delegate,
resourceHandler);
}
}
return nullptr;
}
net::URLRequestJob* CefRequestInterceptor::MaybeInterceptRedirect(
net::URLRequest* request,
net::NetworkDelegate* network_delegate,
const GURL& location) const {
if (net_util::IsInternalRequest(request))
return nullptr;
CefRefPtr<CefRequestImpl> requestPtr;
CefRefPtr<CefBrowser> browser;
CefRefPtr<CefFrame> frame;
CefRefPtr<CefResourceRequestHandler> handler =
net_util::GetResourceRequestHandler(request, requestPtr, browser, frame);
if (handler) {
CefRefPtr<CefResponseImpl> responsePtr = new CefResponseImpl();
responsePtr->Set(request);
responsePtr->SetReadOnly(true);
// Give the client an opportunity to redirect the request.
CefString newUrlStr = location.spec();
handler->OnResourceRedirect(browser, frame, requestPtr.get(),
responsePtr.get(), newUrlStr);
if (newUrlStr != location.spec()) {
const GURL new_url = GURL(newUrlStr.ToString());
if (!new_url.is_empty() && new_url.is_valid()) {
return new net::URLRequestRedirectJob(
request, network_delegate, new_url,
net::URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT,
"Resource Redirect");
}
}
}
return nullptr;
}
net::URLRequestJob* CefRequestInterceptor::MaybeInterceptResponse(
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const {
if (net_util::IsInternalRequest(request))
return nullptr;
CefRefPtr<CefRequestImpl> requestPtr;
CefRefPtr<CefBrowser> browser;
CefRefPtr<CefFrame> frame;
CefRefPtr<CefResourceRequestHandler> handler =
net_util::GetResourceRequestHandler(request, requestPtr, browser, frame);
if (!handler)
return nullptr;
// The below callback allows modification of the request object.
requestPtr->SetReadOnly(false);
requestPtr->SetTrackChanges(true);
CefRefPtr<CefResponseImpl> responsePtr = new CefResponseImpl();
responsePtr->Set(request);
responsePtr->SetReadOnly(true);
const GURL old_url = request->url();
// Give the client an opportunity to retry or redirect the request.
if (!handler->OnResourceResponse(browser, frame, requestPtr.get(),
responsePtr.get())) {
return nullptr;
}
// This flag will be reset by URLRequest::RestartWithJob() calling
// URLRequest::PrepareToRestart() after this method returns but we need it
// reset sooner so that we can modify the request headers without asserting.
request->set_is_pending(false);
// Update the URLRequest with only the values that have been changed by the
// client.
requestPtr->Get(request, true);
// If the URL was changed then redirect the request.
if (!!(requestPtr->GetChanges() & CefRequestImpl::kChangedUrl)) {
const GURL new_url = old_url.Resolve(requestPtr->GetURL().ToString());
if (new_url != old_url) {
return new net::URLRequestRedirectJob(
request, network_delegate, new_url,
net::URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT,
"Resource Redirect");
}
}
// Otherwise queue a new job.
return net::URLRequestJobManager::GetInstance()->CreateJob(request,
network_delegate);
}

View File

@ -1,33 +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_INTERCEPTOR_H_
#define CEF_LIBCEF_BROWSER_NET_URL_REQUEST_INTERCEPTOR_H_
#pragma once
#include "net/url_request/url_request_interceptor.h"
// Used for intercepting resource requests, redirects and responses. The single
// instance of this class is managed by CefURLRequestContextGetter.
class CefRequestInterceptor : public net::URLRequestInterceptor {
public:
CefRequestInterceptor();
~CefRequestInterceptor() override;
// net::URLRequestInterceptor methods.
net::URLRequestJob* MaybeInterceptRequest(
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const override;
net::URLRequestJob* MaybeInterceptRedirect(
net::URLRequest* request,
net::NetworkDelegate* network_delegate,
const GURL& location) const override;
net::URLRequestJob* MaybeInterceptResponse(
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const override;
DISALLOW_COPY_AND_ASSIGN(CefRequestInterceptor);
};
#endif // CEF_LIBCEF_BROWSER_NET_URL_REQUEST_INTERCEPTOR_H_

View File

@ -1,279 +0,0 @@
// Copyright (c) 2015 The Chromium Embedded Framework Authors.
// Portions copyright (c) 2006-2009 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/net/url_request_manager.h"
#include "include/cef_browser.h"
#include "include/cef_scheme.h"
#include "libcef/browser/browser_context.h"
#include "libcef/browser/browser_host_impl.h"
#include "libcef/browser/net/net_util.h"
#include "libcef/browser/net/resource_request_job.h"
#include "libcef/browser/net/scheme_handler.h"
#include "libcef/browser/thread_util.h"
#include "libcef/common/net/scheme_registration.h"
#include "libcef/common/request_impl.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_filter.h"
#include "net/url_request/url_request_http_job.h"
#include "net/url_request/url_request_job.h"
#include "net/url_request/url_request_job_factory_impl.h"
#include "url/third_party/mozilla/url_parse.h"
#include "url/url_util.h"
using net::URLRequestStatus;
namespace {
// Copied from net/url_request/url_request_job_manager.cc.
struct SchemeToFactory {
const char* scheme;
net::URLRequest::ProtocolFactory* factory;
};
static const SchemeToFactory kBuiltinFactories[] = {
{"http", net::URLRequestHttpJob::Factory},
{"https", net::URLRequestHttpJob::Factory},
};
bool IsBuiltinScheme(const std::string& scheme) {
for (size_t i = 0; i < base::size(kBuiltinFactories); ++i)
if (base::LowerCaseEqualsASCII(scheme, kBuiltinFactories[i].scheme))
return true;
return false;
}
net::URLRequestJob* GetBuiltinSchemeRequestJob(
net::URLRequest* request,
net::NetworkDelegate* network_delegate,
const std::string& scheme) {
// See if the request should be handled by a built-in protocol factory.
for (size_t i = 0; i < base::size(kBuiltinFactories); ++i) {
if (scheme == kBuiltinFactories[i].scheme) {
net::URLRequestJob* job =
(kBuiltinFactories[i].factory)(request, network_delegate, scheme);
DCHECK(job); // The built-in factories are not expected to fail!
return job;
}
}
return NULL;
}
std::string ToLower(const std::string& str) {
std::string str_lower = str;
std::transform(str_lower.begin(), str_lower.end(), str_lower.begin(),
towlower);
return str;
}
} // namespace
// Class used for creating URLRequestJob instances. The lifespan of this object
// is managed by URLRequestJobFactory.
class CefProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler {
public:
CefProtocolHandler(CefURLRequestManager* request_manager,
const std::string& scheme)
: request_manager_(request_manager), scheme_(scheme) {}
// From net::URLRequestJobFactory::ProtocolHandler
net::URLRequestJob* MaybeCreateJob(
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const override {
CEF_REQUIRE_IOT();
return request_manager_->GetRequestJob(request, network_delegate, scheme_);
}
private:
CefURLRequestManager* request_manager_;
std::string scheme_;
};
CefURLRequestManager::CefURLRequestManager(
net::URLRequestJobFactoryImpl* job_factory)
: job_factory_(job_factory) {
CEF_REQUIRE_IOT();
DCHECK(job_factory_);
}
CefURLRequestManager::~CefURLRequestManager() {
CEF_REQUIRE_IOT();
}
bool CefURLRequestManager::AddFactory(
const std::string& scheme,
const std::string& domain,
CefRefPtr<CefSchemeHandlerFactory> factory) {
if (!factory.get()) {
RemoveFactory(scheme, domain);
return true;
}
CEF_REQUIRE_IOT();
std::string scheme_lower = ToLower(scheme);
std::string domain_lower = ToLower(domain);
// Hostname is only supported for standard schemes.
if (!scheme::IsStandardScheme(scheme_lower))
domain_lower.clear();
SetProtocolHandlerIfNecessary(scheme_lower, true);
handler_map_[make_pair(scheme_lower, domain_lower)] = factory;
return true;
}
void CefURLRequestManager::RemoveFactory(const std::string& scheme,
const std::string& domain) {
CEF_REQUIRE_IOT();
std::string scheme_lower = ToLower(scheme);
std::string domain_lower = ToLower(domain);
// Hostname is only supported for standard schemes.
if (!scheme::IsStandardScheme(scheme_lower))
domain_lower.clear();
HandlerMap::iterator iter =
handler_map_.find(make_pair(scheme_lower, domain_lower));
if (iter != handler_map_.end()) {
handler_map_.erase(iter);
SetProtocolHandlerIfNecessary(scheme_lower, false);
}
}
// Clear all the existing URL handlers and unregister the ProtocolFactory.
void CefURLRequestManager::ClearFactories() {
CEF_REQUIRE_IOT();
// Create a unique set of scheme names.
std::set<std::string> schemes;
for (HandlerMap::const_iterator i = handler_map_.begin();
i != handler_map_.end(); ++i) {
schemes.insert(i->first.first);
}
for (std::set<std::string>::const_iterator scheme = schemes.begin();
scheme != schemes.end(); ++scheme) {
const std::string& scheme_name = *scheme;
if (!scheme::IsInternalProtectedScheme(scheme_name)) {
bool set_protocol = job_factory_->SetProtocolHandler(scheme_name, NULL);
DCHECK(set_protocol);
}
}
handler_map_.clear();
// Re-register internal scheme handlers that can be overridden.
scheme::RegisterInternalHandlers(this);
}
// Helper for chaining ProtocolHandler implementations.
net::URLRequestJob* CefURLRequestManager::GetRequestJob(
net::URLRequest* request,
net::NetworkDelegate* network_delegate) {
CEF_REQUIRE_IOT();
return GetRequestJob(request, network_delegate, request->url().scheme());
}
void CefURLRequestManager::SetProtocolHandlerIfNecessary(
const std::string& scheme,
bool add) {
// Don't modify a protocol handler for internal protected schemes or if the
// protocol handler is still needed by other registered factories.
if (scheme::IsInternalProtectedScheme(scheme) || HasFactory(scheme))
return;
bool set_protocol = job_factory_->SetProtocolHandler(
scheme,
base::WrapUnique(add ? new CefProtocolHandler(this, scheme) : NULL));
DCHECK(set_protocol);
}
bool CefURLRequestManager::HasFactory(const std::string& scheme) {
if (handler_map_.empty())
return false;
for (HandlerMap::const_iterator i = handler_map_.begin();
i != handler_map_.end(); ++i) {
if (scheme == i->first.first)
return true;
}
return false;
}
CefRefPtr<CefSchemeHandlerFactory> CefURLRequestManager::GetHandlerFactory(
net::URLRequest* request,
const std::string& scheme) {
CefRefPtr<CefSchemeHandlerFactory> factory;
if (request->url().is_valid() && scheme::IsStandardScheme(scheme)) {
// Check for a match with a domain first.
const std::string& domain = request->url().host();
HandlerMap::iterator i = handler_map_.find(make_pair(scheme, domain));
if (i != handler_map_.end())
factory = i->second;
}
if (!factory.get()) {
// Check for a match with no specified domain.
HandlerMap::iterator i =
handler_map_.find(make_pair(scheme, std::string()));
if (i != handler_map_.end())
factory = i->second;
}
return factory;
}
net::URLRequestJob* CefURLRequestManager::GetRequestJob(
net::URLRequest* request,
net::NetworkDelegate* network_delegate,
const std::string& scheme) {
net::URLRequestJob* job = NULL;
CefRefPtr<CefSchemeHandlerFactory> factory =
GetHandlerFactory(request, scheme);
if (factory.get()) {
CefRefPtr<CefBrowserHostImpl> browser =
net_util::GetBrowserForRequest(request);
CefRefPtr<CefFrame> frame;
if (browser.get()) {
frame = net_util::GetFrameForRequest(browser->browser_info(), request);
}
// Populate the request data.
CefRefPtr<CefRequestImpl> requestPtr(new CefRequestImpl());
requestPtr->Set(request);
// Call the handler factory to create the handler for the request.
CefRefPtr<CefResourceHandler> handler =
factory->Create(browser.get(), frame, scheme, requestPtr.get());
if (handler.get())
job = new CefResourceRequestJob(request, network_delegate, handler);
}
if (!job && IsBuiltinScheme(scheme)) {
// Give the built-in scheme handler a chance to handle the request.
job = GetBuiltinSchemeRequestJob(request, network_delegate, scheme);
}
#if DCHECK_IS_ON()
if (job)
DLOG(INFO) << "CefURLRequestManager hit for " << request->url().spec();
#endif
return job;
}

View File

@ -1,81 +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_MANAGER_H_
#define CEF_LIBCEF_BROWSER_NET_URL_REQUEST_MANAGER_H_
#pragma once
#include <map>
#include "include/cef_scheme.h"
namespace net {
class NetworkDelegate;
class URLRequest;
class URLRequestJob;
class URLRequestJobFactoryImpl;
} // namespace net
class CefProtocolHandler;
// Class that manages CefSchemeHandlerFactory instances. Only accessed on the IO
// thread.
class CefURLRequestManager {
public:
explicit CefURLRequestManager(net::URLRequestJobFactoryImpl* job_factory);
~CefURLRequestManager();
// Add |factory| for the specified |scheme| and |domain|. See documentation on
// CefRequestContext::RegisterSchemeHandlerFactory() for usage.
bool AddFactory(const std::string& scheme,
const std::string& domain,
CefRefPtr<CefSchemeHandlerFactory> factory);
// Remove all factories associated with the specified |scheme| and |domain|.
void RemoveFactory(const std::string& scheme, const std::string& domain);
// Clear all the existing URL handlers and unregister the ProtocolFactory.
void ClearFactories();
// Helper for chaining ProtocolHandler implementations.
net::URLRequestJob* GetRequestJob(net::URLRequest* request,
net::NetworkDelegate* network_delegate);
private:
friend class CefProtocolHandler;
// Add or remove the protocol handler if necessary. |scheme| will already be
// in lower case.
void SetProtocolHandlerIfNecessary(const std::string& scheme, bool add);
// Returns true if any factory currently exists for |scheme|. |scheme| will
// already be in lower case.
bool HasFactory(const std::string& scheme);
// Retrieve the matching handler factory, if any. |scheme| will already be in
// lower case.
CefRefPtr<CefSchemeHandlerFactory> GetHandlerFactory(
net::URLRequest* request,
const std::string& scheme);
// Create the job that will handle the request. |scheme| will already be in
// lower case.
net::URLRequestJob* GetRequestJob(net::URLRequest* request,
net::NetworkDelegate* network_delegate,
const std::string& scheme);
// Life span of |job_factory_| is guaranteed by
// CefURLRequestContextGetter which also owns this object.
net::URLRequestJobFactoryImpl* job_factory_;
// Map (scheme, domain) to factories.
typedef std::map<std::pair<std::string, std::string>,
CefRefPtr<CefSchemeHandlerFactory>>
HandlerMap;
HandlerMap handler_map_;
DISALLOW_COPY_AND_ASSIGN(CefURLRequestManager);
};
#endif // CEF_LIBCEF_BROWSER_NET_URL_REQUEST_MANAGER_H_

View File

@ -1,19 +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/net/url_request_user_data.h"
CefURLRequestUserData::CefURLRequestUserData(
CefRefPtr<CefURLRequestClient> client)
: client_(client) {}
CefURLRequestUserData::~CefURLRequestUserData() {}
CefRefPtr<CefURLRequestClient> CefURLRequestUserData::GetClient() {
return client_;
}
// static
const void* CefURLRequestUserData::kUserDataKey =
static_cast<const void*>(&CefURLRequestUserData::kUserDataKey);

View File

@ -1,27 +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.
#ifndef CEF_LIBCEF_BROWSER_NET_URL_REQUEST_USER_DATA_H_
#define CEF_LIBCEF_BROWSER_NET_URL_REQUEST_USER_DATA_H_
#include "include/cef_base.h"
#include "include/cef_urlrequest.h"
#include "base/supports_user_data.h"
// Used to annotate all URLRequests for which the request can be associated
// with the CefURLRequestClient.
class CefURLRequestUserData : public base::SupportsUserData::Data {
public:
CefURLRequestUserData(CefRefPtr<CefURLRequestClient> client);
~CefURLRequestUserData() override;
CefRefPtr<CefURLRequestClient> GetClient();
static const void* kUserDataKey;
private:
CefRefPtr<CefURLRequestClient> client_;
};
#endif // CEF_LIBCEF_BROWSER_NET_URL_REQUEST_USER_DATA_H_

View File

@ -28,7 +28,9 @@
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h" #include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "net/base/load_flags.h"
#include "net/http/http_status_code.h" #include "net/http/http_status_code.h"
#include "net/http/http_util.h"
#include "ui/base/page_transition_types.h" #include "ui/base/page_transition_types.h"
#include "url/origin.h" #include "url/origin.h"

View File

@ -6,12 +6,10 @@
#include "libcef/browser/browser_context.h" #include "libcef/browser/browser_context.h"
#include "libcef/browser/media_capture_devices_dispatcher.h" #include "libcef/browser/media_capture_devices_dispatcher.h"
#include "libcef/browser/net/url_request_context_getter.h"
#include "libcef/browser/prefs/pref_store.h" #include "libcef/browser/prefs/pref_store.h"
#include "libcef/browser/prefs/renderer_prefs.h" #include "libcef/browser/prefs/renderer_prefs.h"
#include "libcef/common/cef_switches.h" #include "libcef/common/cef_switches.h"
#include "libcef/common/extensions/extensions_util.h" #include "libcef/common/extensions/extensions_util.h"
#include "libcef/common/net_service/util.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
@ -177,9 +175,7 @@ std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
SSLConfigServiceManager::RegisterPrefs(registry.get()); SSLConfigServiceManager::RegisterPrefs(registry.get());
update_client::RegisterPrefs(registry.get()); update_client::RegisterPrefs(registry.get());
if (!net_service::IsEnabled()) { if (!profile) {
CefURLRequestContextGetter::RegisterPrefs(registry.get());
} else if (!profile) {
SystemNetworkContextManager::RegisterPrefs(registry.get()); SystemNetworkContextManager::RegisterPrefs(registry.get());
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
OSCrypt::RegisterLocalPrefs(registry.get()); OSCrypt::RegisterLocalPrefs(registry.get());

View File

@ -7,11 +7,9 @@
#include "libcef/browser/content_browser_client.h" #include "libcef/browser/content_browser_client.h"
#include "libcef/browser/context.h" #include "libcef/browser/context.h"
#include "libcef/browser/extensions/extension_system.h" #include "libcef/browser/extensions/extension_system.h"
#include "libcef/browser/net/cookie_manager_old_impl.h"
#include "libcef/browser/net_service/cookie_manager_impl.h" #include "libcef/browser/net_service/cookie_manager_impl.h"
#include "libcef/browser/thread_util.h" #include "libcef/browser/thread_util.h"
#include "libcef/common/extensions/extensions_util.h" #include "libcef/common/extensions/extensions_util.h"
#include "libcef/common/net_service/util.h"
#include "libcef/common/task_runner_impl.h" #include "libcef/common/task_runner_impl.h"
#include "libcef/common/values_impl.h" #include "libcef/common/values_impl.h"
@ -23,8 +21,6 @@
#include "content/public/browser/plugin_service.h" #include "content/public/browser/plugin_service.h"
#include "content/public/browser/ssl_host_state_delegate.h" #include "content/public/browser/ssl_host_state_delegate.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding.h"
#include "net/http/http_cache.h"
#include "net/http/http_transaction_factory.h"
#include "services/network/public/cpp/resolve_host_client_base.h" #include "services/network/public/cpp/resolve_host_client_base.h"
using content::BrowserThread; using content::BrowserThread;
@ -247,25 +243,6 @@ void CefRequestContextImpl::GetBrowserContext(
GetBrowserContextOnUIThread(task_runner, callback); GetBrowserContextOnUIThread(task_runner, callback);
} }
void CefRequestContextImpl::GetRequestContextImpl(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
const RequestContextCallback& callback) {
DCHECK(!net_service::IsEnabled());
if (!task_runner.get())
task_runner = CefTaskRunnerImpl::GetCurrentTaskRunner();
if (request_context_getter_) {
// The browser context already exists.
DCHECK(browser_context());
GetRequestContextImplOnIOThread(task_runner, callback, browser_context());
} else {
// Need to initialize the browser context first.
GetBrowserContextOnUIThread(
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}),
base::Bind(&CefRequestContextImpl::GetRequestContextImplOnIOThread,
this, task_runner, callback));
}
}
bool CefRequestContextImpl::IsSame(CefRefPtr<CefRequestContext> other) { bool CefRequestContextImpl::IsSame(CefRefPtr<CefRequestContext> other) {
CefRequestContextImpl* other_impl = CefRequestContextImpl* other_impl =
static_cast<CefRequestContextImpl*>(other.get()); static_cast<CefRequestContextImpl*>(other.get());
@ -310,11 +287,6 @@ bool CefRequestContextImpl::IsSharingWith(CefRefPtr<CefRequestContext> other) {
return pending_other->IsSharingWith(this); return pending_other->IsSharingWith(this);
} }
if (request_context_getter_ && other_impl->request_context_getter_) {
// Both objects are initialized. Compare the request context objects.
return (request_context_getter_ == other_impl->request_context_getter_);
}
// This or the other object is not initialized. Compare the cache path values. // This or the other object is not initialized. Compare the cache path values.
// If both are non-empty and the same then they'll share the same storage. // If both are non-empty and the same then they'll share the same storage.
if (config_.settings.cache_path.length > 0 && if (config_.settings.cache_path.length > 0 &&
@ -341,30 +313,15 @@ CefString CefRequestContextImpl::GetCachePath() {
CefRefPtr<CefCookieManager> CefRequestContextImpl::GetCookieManager( CefRefPtr<CefCookieManager> CefRequestContextImpl::GetCookieManager(
CefRefPtr<CefCompletionCallback> callback) { CefRefPtr<CefCompletionCallback> callback) {
if (!net_service::IsEnabled()) { CefRefPtr<CefCookieManagerImpl> cookie_manager = new CefCookieManagerImpl();
CefRefPtr<CefCookieManagerOldImpl> cookie_manager = cookie_manager->Initialize(this, callback);
new CefCookieManagerOldImpl(); return cookie_manager.get();
cookie_manager->Initialize(this, CefString(), false, callback);
return cookie_manager.get();
} else {
CefRefPtr<CefCookieManagerImpl> cookie_manager = new CefCookieManagerImpl();
cookie_manager->Initialize(this, callback);
return cookie_manager.get();
}
} }
bool CefRequestContextImpl::RegisterSchemeHandlerFactory( bool CefRequestContextImpl::RegisterSchemeHandlerFactory(
const CefString& scheme_name, const CefString& scheme_name,
const CefString& domain_name, const CefString& domain_name,
CefRefPtr<CefSchemeHandlerFactory> factory) { CefRefPtr<CefSchemeHandlerFactory> factory) {
if (!net_service::IsEnabled()) {
GetRequestContextImpl(
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}),
base::Bind(&CefRequestContextImpl::RegisterSchemeHandlerFactoryInternal,
this, scheme_name, domain_name, factory));
return true;
}
if (!CEF_CURRENTLY_ON_UIT()) { if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(CEF_UIT, CEF_POST_TASK(CEF_UIT,
base::BindOnce( base::BindOnce(
@ -383,14 +340,6 @@ bool CefRequestContextImpl::RegisterSchemeHandlerFactory(
} }
bool CefRequestContextImpl::ClearSchemeHandlerFactories() { bool CefRequestContextImpl::ClearSchemeHandlerFactories() {
if (!net_service::IsEnabled()) {
GetRequestContextImpl(
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}),
base::Bind(&CefRequestContextImpl::ClearSchemeHandlerFactoriesInternal,
this));
return true;
}
if (!CEF_CURRENTLY_ON_UIT()) { if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK( CEF_POST_TASK(
CEF_UIT, CEF_UIT,
@ -548,48 +497,27 @@ void CefRequestContextImpl::ClearCertificateExceptions(
void CefRequestContextImpl::ClearHttpAuthCredentials( void CefRequestContextImpl::ClearHttpAuthCredentials(
CefRefPtr<CefCompletionCallback> callback) { CefRefPtr<CefCompletionCallback> callback) {
if (net_service::IsEnabled()) { GetBrowserContext(
GetBrowserContext( base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::UI}),
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::UI}), base::Bind(&CefRequestContextImpl::ClearHttpAuthCredentialsInternal, this,
base::Bind(&CefRequestContextImpl::ClearHttpAuthCredentialsInternal, callback));
this, callback));
} else {
GetRequestContextImpl(
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}),
base::Bind(&CefRequestContextImpl::ClearHttpAuthCredentialsInternalOld,
this, callback));
}
} }
void CefRequestContextImpl::CloseAllConnections( void CefRequestContextImpl::CloseAllConnections(
CefRefPtr<CefCompletionCallback> callback) { CefRefPtr<CefCompletionCallback> callback) {
if (net_service::IsEnabled()) { GetBrowserContext(
GetBrowserContext( base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::UI}),
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::UI}), base::Bind(&CefRequestContextImpl::CloseAllConnectionsInternal, this,
base::Bind(&CefRequestContextImpl::CloseAllConnectionsInternal, this, callback));
callback));
} else {
GetRequestContextImpl(
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}),
base::Bind(&CefRequestContextImpl::CloseAllConnectionsInternalOld, this,
callback));
}
} }
void CefRequestContextImpl::ResolveHost( void CefRequestContextImpl::ResolveHost(
const CefString& origin, const CefString& origin,
CefRefPtr<CefResolveCallback> callback) { CefRefPtr<CefResolveCallback> callback) {
if (net_service::IsEnabled()) { GetBrowserContext(
GetBrowserContext( base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::UI}),
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::UI}), base::Bind(&CefRequestContextImpl::ResolveHostInternal, this, origin,
base::Bind(&CefRequestContextImpl::ResolveHostInternal, this, origin, callback));
callback));
} else {
GetRequestContextImpl(
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}),
base::Bind(&CefRequestContextImpl::ResolveHostInternalOld, this, origin,
callback));
}
} }
void CefRequestContextImpl::LoadExtension( void CefRequestContextImpl::LoadExtension(
@ -707,7 +635,6 @@ void CefRequestContextImpl::Initialize() {
CEF_REQUIRE_UIT(); CEF_REQUIRE_UIT();
DCHECK(!browser_context_); DCHECK(!browser_context_);
DCHECK(!request_context_getter_);
if (config_.other) { if (config_.other) {
// Share storage with |config_.other|. // Share storage with |config_.other|.
@ -740,17 +667,6 @@ void CefRequestContextImpl::Initialize() {
// Force our settings to match |browser_context_|. // Force our settings to match |browser_context_|.
config_.settings = browser_context_->GetSettings(); config_.settings = browser_context_->GetSettings();
if (!net_service::IsEnabled()) {
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_->AddHandler(config_.handler);
}
}
if (config_.other) { if (config_.other) {
// Clear the reference to |config_.other| after setting // Clear the reference to |config_.other| after setting
// |request_context_getter_|. This is the reverse order of checks in // |request_context_getter_|. This is the reverse order of checks in
@ -767,7 +683,6 @@ void CefRequestContextImpl::EnsureBrowserContext() {
if (!browser_context()) if (!browser_context())
Initialize(); Initialize();
DCHECK(browser_context()); DCHECK(browser_context());
DCHECK(net_service::IsEnabled() || request_context_getter_);
} }
void CefRequestContextImpl::GetBrowserContextOnUIThread( void CefRequestContextImpl::GetBrowserContextOnUIThread(
@ -792,51 +707,6 @@ void CefRequestContextImpl::GetBrowserContextOnUIThread(
} }
} }
void CefRequestContextImpl::GetRequestContextImplOnIOThread(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
const RequestContextCallback& callback,
CefBrowserContext* browser_context) {
if (!CEF_CURRENTLY_ON_IOT()) {
CEF_POST_TASK(
CEF_IOT,
base::Bind(&CefRequestContextImpl::GetRequestContextImplOnIOThread,
this, task_runner, callback, browser_context));
return;
}
DCHECK(!net_service::IsEnabled());
DCHECK(request_context_getter_);
// Make sure the request context exists.
request_context_getter_->GetURLRequestContext();
if (task_runner->BelongsToCurrentThread()) {
// Execute the callback immediately.
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_)));
}
}
void CefRequestContextImpl::RegisterSchemeHandlerFactoryInternal(
const CefString& scheme_name,
const CefString& domain_name,
CefRefPtr<CefSchemeHandlerFactory> factory,
scoped_refptr<CefURLRequestContextGetter> request_context) {
CEF_REQUIRE_IOT();
request_context->request_manager()->AddFactory(scheme_name, domain_name,
factory);
}
void CefRequestContextImpl::ClearSchemeHandlerFactoriesInternal(
scoped_refptr<CefURLRequestContextGetter> request_context) {
CEF_REQUIRE_IOT();
request_context->request_manager()->ClearFactories();
}
void CefRequestContextImpl::PurgePluginListCacheInternal( void CefRequestContextImpl::PurgePluginListCacheInternal(
bool reload_pages, bool reload_pages,
CefBrowserContext* browser_context) { CefBrowserContext* browser_context) {
@ -871,27 +741,6 @@ void CefRequestContextImpl::ClearHttpAuthCredentialsInternal(
base::Time(), base::Bind(&CefCompletionCallback::OnComplete, callback)); base::Time(), base::Bind(&CefCompletionCallback::OnComplete, callback));
} }
void CefRequestContextImpl::ClearHttpAuthCredentialsInternalOld(
CefRefPtr<CefCompletionCallback> callback,
scoped_refptr<CefURLRequestContextGetter> request_context) {
CEF_REQUIRE_IOT();
net::URLRequestContext* url_context = request_context->GetURLRequestContext();
if (url_context) {
net::HttpNetworkSession* http_session =
url_context->http_transaction_factory()->GetSession();
DCHECK(http_session);
http_session->http_auth_cache()->ClearEntriesAddedSince(base::Time());
http_session->CloseAllConnections();
}
if (callback) {
CEF_POST_TASK(CEF_UIT,
base::Bind(&CefCompletionCallback::OnComplete, callback));
}
}
void CefRequestContextImpl::CloseAllConnectionsInternal( void CefRequestContextImpl::CloseAllConnectionsInternal(
CefRefPtr<CefCompletionCallback> callback, CefRefPtr<CefCompletionCallback> callback,
CefBrowserContext* browser_context) { CefBrowserContext* browser_context) {
@ -901,28 +750,6 @@ void CefRequestContextImpl::CloseAllConnectionsInternal(
base::Bind(&CefCompletionCallback::OnComplete, callback)); base::Bind(&CefCompletionCallback::OnComplete, callback));
} }
void CefRequestContextImpl::CloseAllConnectionsInternalOld(
CefRefPtr<CefCompletionCallback> callback,
scoped_refptr<CefURLRequestContextGetter> request_context) {
CEF_REQUIRE_IOT();
net::URLRequestContext* url_context = request_context->GetURLRequestContext();
if (url_context) {
net::HttpTransactionFactory* http_factory =
url_context->http_transaction_factory();
if (http_factory) {
net::HttpCache* cache = http_factory->GetCache();
if (cache)
cache->CloseAllConnections();
}
}
if (callback) {
CEF_POST_TASK(CEF_UIT,
base::Bind(&CefCompletionCallback::OnComplete, callback));
}
}
void CefRequestContextImpl::ResolveHostInternal( void CefRequestContextImpl::ResolveHostInternal(
const CefString& origin, const CefString& origin,
CefRefPtr<CefResolveCallback> callback, CefRefPtr<CefResolveCallback> callback,
@ -934,33 +761,6 @@ void CefRequestContextImpl::ResolveHostInternal(
helper->Start(browser_context, origin); helper->Start(browser_context, origin);
} }
void CefRequestContextImpl::ResolveHostInternalOld(
const CefString& origin,
CefRefPtr<CefResolveCallback> callback,
scoped_refptr<CefURLRequestContextGetter> request_context) {
CEF_REQUIRE_IOT();
int retval = ERR_FAILED;
// |helper| will be deleted in ResolveHostHelperOld::OnResolveCompleted().
ResolveHostHelperOld* helper = new ResolveHostHelperOld(callback);
net::HostResolver* host_resolver = request_context->GetHostResolver();
if (host_resolver) {
helper->request_ = host_resolver->CreateRequest(
net::HostPortPair::FromURL(GURL(origin.ToString())),
net::NetLogWithSource(), {});
retval = helper->request_->Start(base::Bind(
&ResolveHostHelperOld::OnResolveCompleted, base::Unretained(helper)));
if (retval == net::ERR_IO_PENDING) {
// The result will be delivered asynchronously via the callback.
return;
}
}
helper->OnResolveCompleted(retval);
}
CefBrowserContext* CefRequestContextImpl::browser_context() const { CefBrowserContext* CefRequestContextImpl::browser_context() const {
return browser_context_; return browser_context_;
} }

View File

@ -40,16 +40,6 @@ class CefRequestContextImpl : public CefRequestContext {
scoped_refptr<base::SingleThreadTaskRunner> task_runner, scoped_refptr<base::SingleThreadTaskRunner> task_runner,
const BrowserContextCallback& callback); const BrowserContextCallback& callback);
// Executes |callback| either synchronously or asynchronously with the request
// 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<void(scoped_refptr<CefURLRequestContextGetter>)>
RequestContextCallback;
void GetRequestContextImpl(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
const RequestContextCallback& callback);
bool IsSame(CefRefPtr<CefRequestContext> other) override; bool IsSame(CefRefPtr<CefRequestContext> other) override;
bool IsSharingWith(CefRefPtr<CefRequestContext> other) override; bool IsSharingWith(CefRefPtr<CefRequestContext> other) override;
bool IsGlobal() override; bool IsGlobal() override;
@ -142,18 +132,7 @@ class CefRequestContextImpl : public CefRequestContext {
void GetBrowserContextOnUIThread( void GetBrowserContextOnUIThread(
scoped_refptr<base::SingleThreadTaskRunner> task_runner, scoped_refptr<base::SingleThreadTaskRunner> task_runner,
const BrowserContextCallback& callback); const BrowserContextCallback& callback);
void GetRequestContextImplOnIOThread(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
const RequestContextCallback& callback,
CefBrowserContext* browser_context);
void RegisterSchemeHandlerFactoryInternal(
const CefString& scheme_name,
const CefString& domain_name,
CefRefPtr<CefSchemeHandlerFactory> factory,
scoped_refptr<CefURLRequestContextGetter> request_context);
void ClearSchemeHandlerFactoriesInternal(
scoped_refptr<CefURLRequestContextGetter> request_context);
void PurgePluginListCacheInternal(bool reload_pages, void PurgePluginListCacheInternal(bool reload_pages,
CefBrowserContext* browser_context); CefBrowserContext* browser_context);
void ClearCertificateExceptionsInternal( void ClearCertificateExceptionsInternal(
@ -162,21 +141,11 @@ class CefRequestContextImpl : public CefRequestContext {
void ClearHttpAuthCredentialsInternal( void ClearHttpAuthCredentialsInternal(
CefRefPtr<CefCompletionCallback> callback, CefRefPtr<CefCompletionCallback> callback,
CefBrowserContext* browser_context); CefBrowserContext* browser_context);
void ClearHttpAuthCredentialsInternalOld(
CefRefPtr<CefCompletionCallback> callback,
scoped_refptr<CefURLRequestContextGetter> request_context);
void CloseAllConnectionsInternal(CefRefPtr<CefCompletionCallback> callback, void CloseAllConnectionsInternal(CefRefPtr<CefCompletionCallback> callback,
CefBrowserContext* browser_context); CefBrowserContext* browser_context);
void CloseAllConnectionsInternalOld(
CefRefPtr<CefCompletionCallback> callback,
scoped_refptr<CefURLRequestContextGetter> request_context);
void ResolveHostInternal(const CefString& origin, void ResolveHostInternal(const CefString& origin,
CefRefPtr<CefResolveCallback> callback, CefRefPtr<CefResolveCallback> callback,
CefBrowserContext* browser_context); CefBrowserContext* browser_context);
void ResolveHostInternalOld(
const CefString& origin,
CefRefPtr<CefResolveCallback> callback,
scoped_refptr<CefURLRequestContextGetter> request_context);
CefBrowserContext* browser_context() const; CefBrowserContext* browser_context() const;
@ -185,9 +154,6 @@ class CefRequestContextImpl : public CefRequestContext {
Config config_; Config config_;
// Owned by the CefBrowserContext.
CefURLRequestContextGetter* request_context_getter_ = nullptr;
IMPLEMENT_REFCOUNTING_DELETE_ON_UIT(CefRequestContextImpl); IMPLEMENT_REFCOUNTING_DELETE_ON_UIT(CefRequestContextImpl);
DISALLOW_COPY_AND_ASSIGN(CefRequestContextImpl); DISALLOW_COPY_AND_ASSIGN(CefRequestContextImpl);
}; };

View File

@ -5,10 +5,8 @@
#include "libcef/browser/resource_context.h" #include "libcef/browser/resource_context.h"
#include "libcef/browser/net/scheme_handler.h" #include "libcef/browser/net/scheme_handler.h"
#include "libcef/browser/net/url_request_context_getter.h"
#include "libcef/browser/thread_util.h" #include "libcef/browser/thread_util.h"
#include "libcef/common/net/scheme_registration.h" #include "libcef/common/net/scheme_registration.h"
#include "libcef/common/net_service/util.h"
#include "base/i18n/case_conversion.h" #include "base/i18n/case_conversion.h"
#include "base/logging.h" #include "base/logging.h"
@ -39,14 +37,7 @@ CefResourceContext::CefResourceContext(bool is_off_the_record)
base::Unretained(this))); base::Unretained(this)));
} }
CefResourceContext::~CefResourceContext() { CefResourceContext::~CefResourceContext() {}
// This is normally called in the parent ResourceContext destructor, but we
// want to call it here so that this CefResourceContext object is still
// valid when CefNetworkDelegate::OnCompleted is called via the URLRequest
// destructor.
if (content::ResourceDispatcherHostImpl::Get())
content::ResourceDispatcherHostImpl::Get()->CancelRequestsForContext(this);
}
std::unique_ptr<net::ClientCertStore> std::unique_ptr<net::ClientCertStore>
CefResourceContext::CreateClientCertStore() { CefResourceContext::CreateClientCertStore() {
@ -195,7 +186,6 @@ void CefResourceContext::RegisterSchemeHandlerFactory(
const std::string& domain_name, const std::string& domain_name,
CefRefPtr<CefSchemeHandlerFactory> factory) { CefRefPtr<CefSchemeHandlerFactory> factory) {
CEF_REQUIRE_IOT(); CEF_REQUIRE_IOT();
DCHECK(net_service::IsEnabled());
const std::string& scheme_lower = base::ToLowerASCII(scheme_name); const std::string& scheme_lower = base::ToLowerASCII(scheme_name);
std::string domain_lower; std::string domain_lower;
@ -222,7 +212,6 @@ void CefResourceContext::RegisterSchemeHandlerFactory(
void CefResourceContext::ClearSchemeHandlerFactories() { void CefResourceContext::ClearSchemeHandlerFactories() {
CEF_REQUIRE_IOT(); CEF_REQUIRE_IOT();
DCHECK(net_service::IsEnabled());
scheme_handler_factory_map_.clear(); scheme_handler_factory_map_.clear();
@ -233,7 +222,6 @@ void CefResourceContext::ClearSchemeHandlerFactories() {
CefRefPtr<CefSchemeHandlerFactory> CefResourceContext::GetSchemeHandlerFactory( CefRefPtr<CefSchemeHandlerFactory> CefResourceContext::GetSchemeHandlerFactory(
const GURL& url) { const GURL& url) {
CEF_REQUIRE_IOT(); CEF_REQUIRE_IOT();
DCHECK(net_service::IsEnabled());
if (scheme_handler_factory_map_.empty()) if (scheme_handler_factory_map_.empty())
return nullptr; return nullptr;
@ -265,8 +253,6 @@ CefRefPtr<CefSchemeHandlerFactory> CefResourceContext::GetSchemeHandlerFactory(
void CefResourceContext::InitOnIOThread() { void CefResourceContext::InitOnIOThread() {
CEF_REQUIRE_IOT(); CEF_REQUIRE_IOT();
if (net_service::IsEnabled()) { // Add the default internal handlers.
// Add the default internal handlers. scheme::RegisterInternalHandlers(this);
scheme::RegisterInternalHandlers(this);
}
} }

View File

@ -8,6 +8,7 @@
#include "include/cef_request_context.h" #include "include/cef_request_context.h"
#include "include/cef_request_context_handler.h" #include "include/cef_request_context_handler.h"
#include "include/cef_scheme.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "chrome/common/plugin.mojom.h" #include "chrome/common/plugin.mojom.h"
@ -16,15 +17,11 @@
#include "net/ssl/client_cert_store.h" #include "net/ssl/client_cert_store.h"
#include "url/origin.h" #include "url/origin.h"
class CefURLRequestContextGetter;
// Acts as a bridge for resource loading. Life span is controlled by // Acts as a bridge for resource loading. Life span is controlled by
// CefBrowserContext. Created on the UI thread but accessed and destroyed on the // CefBrowserContext. Created on the UI thread but accessed and destroyed on the
// IO thread. URLRequest objects are associated with the ResourceContext via // IO thread. Network request objects are associated with the ResourceContext
// ResourceDispatcherHost. When the ResourceContext is destroyed all outstanding // via ProxyURLLoaderFactory. When the ResourceContext is destroyed all
// URLRequest objects will be deleted via the ResourceLoader that owns them and // outstanding network request objects will be canceled.
// removed from the associated URLRequestContext. Other URLRequest objects may
// be created via URLFetcher that are not associated with a RequestContext.
// See browser_context.h for an object relationship diagram. // See browser_context.h for an object relationship diagram.
class CefResourceContext : public content::ResourceContext { class CefResourceContext : public content::ResourceContext {
public: public:
@ -100,7 +97,7 @@ class CefResourceContext : public content::ResourceContext {
RenderIdHandlerMap render_id_handler_map_; RenderIdHandlerMap render_id_handler_map_;
// Map of frame_tree_node_id to handler. Keeping this map is necessary // Map of frame_tree_node_id to handler. Keeping this map is necessary
// because, when navigating the main frame, a new (pre-commit) URLRequest // because, when navigating the main frame, a new (pre-commit) network request
// will be created before the RenderFrameHost. Consequently we can't rely // will be created before the RenderFrameHost. Consequently we can't rely
// on valid render IDs. See https://crbug.com/776884 for background. // on valid render IDs. See https://crbug.com/776884 for background.
typedef std::map<int, CefRefPtr<CefRequestContextHandler>> NodeIdHandlerMap; typedef std::map<int, CefRefPtr<CefRequestContextHandler>> NodeIdHandlerMap;

View File

@ -1,129 +0,0 @@
// Copyright 2015 The Chromium Embedded Framework Authors.
// Portions copyright 2014 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/resource_dispatcher_host_delegate.h"
#include <stdint.h>
#include <utility>
#include "libcef/browser/browser_host_impl.h"
#include "libcef/browser/origin_whitelist_impl.h"
#include "libcef/browser/resource_context.h"
#include "libcef/browser/thread_util.h"
#include "libcef/common/extensions/extensions_util.h"
#include "base/guid.h"
#include "base/task/post_task.h"
#include "build/build_config.h"
#include "chrome/browser/extensions/api/streams_private/streams_private_api.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/plugin_service.h"
#include "content/public/browser/plugin_service_filter.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/resource_request_info.h"
#include "content/public/browser/stream_info.h"
#include "content/public/common/webplugininfo.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
#include "extensions/common/manifest_handlers/mime_types_handler.h"
#include "net/http/http_response_headers.h"
#include "net/url_request/url_request.h"
CefResourceDispatcherHostDelegate::CefResourceDispatcherHostDelegate() {}
CefResourceDispatcherHostDelegate::~CefResourceDispatcherHostDelegate() {}
// Implementation based on
// ChromeResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream.
bool CefResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream(
net::URLRequest* request,
const std::string& mime_type,
GURL* origin,
std::string* payload) {
if (!extensions::ExtensionsEnabled())
return false;
content::ResourceRequestInfo* info =
content::ResourceRequestInfo::ForRequest(request);
CefResourceContext* context =
static_cast<CefResourceContext*>(info->GetContext());
bool profile_is_off_the_record = context->IsOffTheRecord();
const scoped_refptr<const extensions::InfoMap> extension_info_map(
context->GetExtensionInfoMap());
std::vector<std::string> whitelist = MimeTypesHandler::GetMIMETypeWhitelist();
// Go through the white-listed extensions and try to use them to intercept
// the URL request.
for (const std::string& extension_id : whitelist) {
const extensions::Extension* extension =
extension_info_map->extensions().GetByID(extension_id);
// The white-listed extension may not be installed, so we have to NULL check
// |extension|.
if (!extension || (profile_is_off_the_record &&
!extension_info_map->IsIncognitoEnabled(extension_id))) {
continue;
}
MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension);
if (!handler)
continue;
if (handler->CanHandleMIMEType(mime_type)) {
StreamTargetInfo target_info;
*origin = extensions::Extension::GetBaseURLFromExtensionId(extension_id);
target_info.extension_id = extension_id;
target_info.view_id = base::GenerateGUID();
*payload = target_info.view_id;
stream_target_info_[request] = target_info;
return true;
}
}
return false;
}
// Implementation based on
// ChromeResourceDispatcherHostDelegate::OnStreamCreated.
void CefResourceDispatcherHostDelegate::OnStreamCreated(
net::URLRequest* request,
std::unique_ptr<content::StreamInfo> stream) {
DCHECK(extensions::ExtensionsEnabled());
content::ResourceRequestInfo* info =
content::ResourceRequestInfo::ForRequest(request);
std::map<net::URLRequest*, StreamTargetInfo>::iterator ix =
stream_target_info_.find(request);
CHECK(ix != stream_target_info_.end());
bool embedded = info->GetResourceType() != content::ResourceType::kMainFrame;
base::PostTaskWithTraits(
FROM_HERE, {content::BrowserThread::UI},
base::BindOnce(
&extensions::StreamsPrivateAPI::SendExecuteMimeTypeHandlerEvent,
ix->second.extension_id, ix->second.view_id, embedded,
info->GetFrameTreeNodeId(), info->GetChildID(),
info->GetRenderFrameID(), std::move(stream),
nullptr /* transferrable_loader */, GURL()));
stream_target_info_.erase(request);
}
void CefResourceDispatcherHostDelegate::OnRequestRedirected(
const GURL& redirect_url,
net::URLRequest* request,
content::ResourceContext* resource_context,
network::ResourceResponse* response) {
const GURL& active_url = request->url();
if (active_url.is_valid() && redirect_url.is_valid() &&
active_url.GetOrigin() != redirect_url.GetOrigin() &&
HasCrossOriginWhitelistEntry(active_url, redirect_url)) {
if (!response->head.headers.get())
response->head.headers = new net::HttpResponseHeaders(std::string());
// Add CORS headers to support XMLHttpRequest redirects.
response->head.headers->AddHeader(
"Access-Control-Allow-Origin: " + active_url.scheme() + "://" +
active_url.host());
response->head.headers->AddHeader("Access-Control-Allow-Credentials: true");
}
}

View File

@ -1,45 +0,0 @@
// Copyright 2015 The Chromium Embedded Framework Authors.
// Portions copyright 2014 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_RESOURCE_DISPATCHER_HOST_DELEGATE_H_
#define CEF_LIBCEF_BROWSER_RESOURCE_DISPATCHER_HOST_DELEGATE_H_
#pragma once
#include <map>
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "content/public/browser/resource_dispatcher_host_delegate.h"
// Implements ResourceDispatcherHostDelegate.
class CefResourceDispatcherHostDelegate
: public content::ResourceDispatcherHostDelegate {
public:
CefResourceDispatcherHostDelegate();
~CefResourceDispatcherHostDelegate() override;
// ResourceDispatcherHostDelegate methods.
bool ShouldInterceptResourceAsStream(net::URLRequest* request,
const std::string& mime_type,
GURL* origin,
std::string* payload) override;
void OnStreamCreated(net::URLRequest* request,
std::unique_ptr<content::StreamInfo> stream) override;
void OnRequestRedirected(const GURL& redirect_url,
net::URLRequest* request,
content::ResourceContext* resource_context,
network::ResourceResponse* response) override;
private:
struct StreamTargetInfo {
std::string extension_id;
std::string view_id;
};
std::map<net::URLRequest*, StreamTargetInfo> stream_target_info_;
DISALLOW_COPY_AND_ASSIGN(CefResourceDispatcherHostDelegate);
};
#endif // CEF_LIBCEF_BROWSER_RESOURCE_DISPATCHER_HOST_DELEGATE_H_

View File

@ -77,31 +77,6 @@ bool IsInternalHandledScheme(const std::string& scheme) {
return false; return false;
} }
bool IsInternalProtectedScheme(const std::string& scheme) {
// Some of these values originate from StoragePartitionImplMap::Get() in
// content/browser/storage_partition_impl_map.cc and are modified by
// InstallInternalProtectedHandlers().
static const char* schemes[] = {
url::kBlobScheme,
content::kChromeUIScheme,
url::kDataScheme,
extensions::kExtensionScheme,
url::kFileScheme,
url::kFileSystemScheme,
#if !BUILDFLAG(DISABLE_FTP_SUPPORT)
url::kFtpScheme,
#endif
url::kJavaScriptScheme,
};
for (size_t i = 0; i < sizeof(schemes) / sizeof(schemes[0]); ++i) {
if (scheme == schemes[i])
return true;
}
return false;
}
bool IsStandardScheme(const std::string& scheme) { bool IsStandardScheme(const std::string& scheme) {
url::Component scheme_comp(0, scheme.length()); url::Component scheme_comp(0, scheme.length());
return url::IsStandard(scheme.c_str(), scheme_comp); return url::IsStandard(scheme.c_str(), scheme_comp);

View File

@ -19,13 +19,6 @@ void AddInternalSchemes(content::ContentClient::Schemes* schemes);
// Returns true if the specified |scheme| is handled internally. // Returns true if the specified |scheme| is handled internally.
bool IsInternalHandledScheme(const std::string& scheme); bool IsInternalHandledScheme(const std::string& scheme);
// Returns true if the specified |scheme| is handled internally and should not
// be explicitly registered or unregistered with the URLRequestJobFactory. A
// registered handler for one of these schemes (like "chrome") may still be
// triggered via chaining from an existing ProtocolHandler. |scheme| should
// always be a lower-case string.
bool IsInternalProtectedScheme(const std::string& scheme);
// Returns true if the specified |scheme| is a registered standard scheme. // Returns true if the specified |scheme| is a registered standard scheme.
bool IsStandardScheme(const std::string& scheme); bool IsStandardScheme(const std::string& scheme);

View File

@ -1,16 +0,0 @@
// Copyright (c) 2019 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/common/net_service/util.h"
#include "base/feature_list.h"
#include "services/network/public/cpp/features.h"
namespace net_service {
bool IsEnabled() {
return base::FeatureList::IsEnabled(network::features::kNetworkService);
}
} // namespace net_service

View File

@ -1,16 +0,0 @@
// Copyright (c) 2019 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_COMMON_NET_SERVICE_UTIL_H_
#define CEF_LIBCEF_COMMON_NET_SERVICE_UTIL_H_
#pragma once
namespace net_service {
// Returns true if the NetworkService is enabled.
bool IsEnabled();
} // namespace net_service
#endif // CEF_LIBCEF_COMMON_NET_SERVICE_UTIL_H_

View File

@ -22,7 +22,6 @@
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "components/navigation_interception/navigation_params.h" #include "components/navigation_interception/navigation_params.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/resource_request_info.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "content/public/common/resource_type.h" #include "content/public/common/resource_type.h"
#include "net/base/elements_upload_data_stream.h" #include "net/base/elements_upload_data_stream.h"
@ -34,8 +33,6 @@
#include "net/http/http_request_headers.h" #include "net/http/http_request_headers.h"
#include "net/http/http_util.h" #include "net/http/http_util.h"
#include "net/url_request/redirect_info.h" #include "net/url_request/redirect_info.h"
#include "net/url_request/url_fetcher.h"
#include "net/url_request/url_request.h"
#include "services/network/public/cpp/data_element.h" #include "services/network/public/cpp/data_element.h"
#include "services/network/public/cpp/network_switches.h" #include "services/network/public/cpp/network_switches.h"
#include "services/network/public/cpp/resource_request.h" #include "services/network/public/cpp/resource_request.h"
@ -50,7 +47,6 @@
namespace { namespace {
const char kReferrerLowerCase[] = "referer"; const char kReferrerLowerCase[] = "referer";
const char kContentTypeLowerCase[] = "content-type";
const char kCacheControlLowerCase[] = "cache-control"; const char kCacheControlLowerCase[] = "cache-control";
const char kCacheControlDirectiveNoCacheLowerCase[] = "no-cache"; const char kCacheControlDirectiveNoCacheLowerCase[] = "no-cache";
const char kCacheControlDirectiveNoStoreLowerCase[] = "no-store"; const char kCacheControlDirectiveNoStoreLowerCase[] = "no-store";
@ -104,16 +100,6 @@ class FileElementReader : public net::UploadFileElementReader {
DISALLOW_COPY_AND_ASSIGN(FileElementReader); DISALLOW_COPY_AND_ASSIGN(FileElementReader);
}; };
std::string GetURLRequestReferrer(const GURL& referrer_url) {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (!referrer_url.is_valid() ||
command_line->HasSwitch(network::switches::kNoReferrers)) {
return std::string();
}
return referrer_url.spec();
}
void MakeASCIILower(std::string* str) { void MakeASCIILower(std::string* str) {
std::transform(str->begin(), str->end(), str->begin(), ::tolower); std::transform(str->begin(), str->end(), str->begin(), ::tolower);
} }
@ -602,82 +588,6 @@ void CefRequestImpl::Set(const net::HttpRequestHeaders& headers) {
::GetHeaderMap(headers, headermap_); ::GetHeaderMap(headers, headermap_);
} }
void CefRequestImpl::Set(const net::URLRequest* request) {
base::AutoLock lock_scope(lock_);
CHECK_READONLY_RETURN_VOID();
Reset();
url_ = request->url();
method_ = request->method();
identifier_ = request->identifier();
// URLRequest::SetReferrer ensures that we do not send username and password
// fields in the referrer.
GURL referrer(request->referrer());
// Our consumer should have made sure that this is a safe referrer. See for
// instance WebCore::FrameLoader::HideReferrer.
if (referrer.is_valid()) {
referrer_url_ = referrer;
referrer_policy_ =
static_cast<cef_referrer_policy_t>(request->referrer_policy());
}
// Transfer request headers.
::GetHeaderMap(request->extra_request_headers(), headermap_);
// Transfer post data, if any.
const net::UploadDataStream* data = request->get_upload();
if (data) {
postdata_ = CefPostData::Create();
static_cast<CefPostDataImpl*>(postdata_.get())->Set(*data);
}
first_party_for_cookies_ = request->site_for_cookies();
content::ResourceRequestInfo* info =
content::ResourceRequestInfo::ForRequest(request);
if (info) {
resource_type_ = static_cast<cef_resource_type_t>(info->GetResourceType());
transition_type_ =
static_cast<cef_transition_type_t>(info->GetPageTransition());
}
}
void CefRequestImpl::Get(net::URLRequest* request, bool changed_only) const {
base::AutoLock lock_scope(lock_);
if (ShouldSet(kChangedMethod, changed_only))
request->set_method(method_);
if (ShouldSet(kChangedReferrer, changed_only)) {
request->SetReferrer(GetURLRequestReferrer(referrer_url_));
request->set_referrer_policy(
static_cast<net::URLRequest::ReferrerPolicy>(referrer_policy_));
}
if (ShouldSet(kChangedHeaderMap, changed_only)) {
net::HttpRequestHeaders headers;
headers.AddHeadersFromString(HttpHeaderUtils::GenerateHeaders(headermap_));
request->SetExtraRequestHeaders(headers);
}
if (ShouldSet(kChangedPostData, changed_only)) {
if (postdata_.get()) {
request->set_upload(
static_cast<CefPostDataImpl*>(postdata_.get())->Get());
} else if (request->get_upload()) {
request->set_upload(std::unique_ptr<net::UploadDataStream>());
}
}
if (!first_party_for_cookies_.is_empty() &&
ShouldSet(kChangedFirstPartyForCookies, changed_only)) {
request->set_site_for_cookies(first_party_for_cookies_);
}
}
void CefRequestImpl::Set( void CefRequestImpl::Set(
const navigation_interception::NavigationParams& params, const navigation_interception::NavigationParams& params,
bool is_main_frame) { bool is_main_frame) {
@ -867,106 +777,6 @@ void CefRequestImpl::Get(CefNavigateParams& params) const {
params.load_flags = flags_; params.load_flags = flags_;
} }
void CefRequestImpl::Get(net::URLFetcher& fetcher,
int64& upload_data_size) const {
base::AutoLock lock_scope(lock_);
if (!referrer_url_.is_empty()) {
fetcher.SetReferrer(GetURLRequestReferrer(referrer_url_));
fetcher.SetReferrerPolicy(
static_cast<net::URLRequest::ReferrerPolicy>(referrer_policy_));
}
CefRequest::HeaderMap headerMap = headermap_;
std::string content_type;
// Extract the Content-Type header value.
{
HeaderMap::iterator it = headerMap.begin();
for (; it != headerMap.end(); ++it) {
if (base::LowerCaseEqualsASCII(it->first.ToString(),
kContentTypeLowerCase)) {
content_type = it->second;
headerMap.erase(it);
break;
}
}
}
fetcher.SetExtraRequestHeaders(HttpHeaderUtils::GenerateHeaders(headerMap));
if (postdata_.get()) {
CefPostData::ElementVector elements;
postdata_->GetElements(elements);
if (elements.size() == 1) {
// Default to URL encoding if not specified.
if (content_type.empty())
content_type = net_service::kContentTypeApplicationFormURLEncoded;
CefPostDataElementImpl* impl =
static_cast<CefPostDataElementImpl*>(elements[0].get());
switch (elements[0]->GetType()) {
case PDE_TYPE_BYTES: {
const size_t size = impl->GetBytesCount();
if (flags_ & UR_FLAG_REPORT_UPLOAD_PROGRESS) {
// Return the upload data size.
upload_data_size = size;
}
fetcher.SetUploadData(
content_type,
std::string(static_cast<char*>(impl->GetBytes()), size));
break;
}
case PDE_TYPE_FILE:
fetcher.SetUploadFilePath(
content_type, base::FilePath(impl->GetFile()), 0,
std::numeric_limits<uint64_t>::max(), GetFileTaskRunner());
break;
case PDE_TYPE_EMPTY:
break;
}
} else if (elements.size() > 1) {
NOTIMPLEMENTED() << " multi-part form data is not supported";
}
}
if (!first_party_for_cookies_.is_empty())
fetcher.SetInitiator(url::Origin::Create(first_party_for_cookies_));
int flags = flags_;
if (!(flags & kURCachePolicyMask)) {
// Only consider the Cache-Control directives when a cache policy is not
// explicitly set on the request.
flags |= GetCacheControlHeaderPolicy(headerMap);
}
if (flags & UR_FLAG_NO_RETRY_ON_5XX)
fetcher.SetAutomaticallyRetryOn5xx(false);
if (flags & UR_FLAG_STOP_ON_REDIRECT)
fetcher.SetStopOnRedirect(true);
int net_flags = 0;
if (flags & UR_FLAG_SKIP_CACHE) {
net_flags |= net::LOAD_BYPASS_CACHE;
}
if (flags & UR_FLAG_ONLY_FROM_CACHE) {
net_flags |= net::LOAD_ONLY_FROM_CACHE | net::LOAD_SKIP_CACHE_VALIDATION;
}
if (flags & UR_FLAG_DISABLE_CACHE) {
net_flags |= net::LOAD_DISABLE_CACHE;
}
if (!(flags & UR_FLAG_ALLOW_STORED_CREDENTIALS)) {
net_flags |= net::LOAD_DO_NOT_SEND_AUTH_DATA |
net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES;
}
fetcher.SetLoadFlags(net_flags);
}
void CefRequestImpl::SetReadOnly(bool read_only) { void CefRequestImpl::SetReadOnly(bool read_only) {
base::AutoLock lock_scope(lock_); base::AutoLock lock_scope(lock_);
if (read_only_ == read_only) if (read_only_ == read_only)

View File

@ -32,8 +32,6 @@ class UploadData;
class UploadDataStream; class UploadDataStream;
class UploadElement; class UploadElement;
class UploadElementReader; class UploadElementReader;
class URLFetcher;
class URLRequest;
} // namespace net } // namespace net
namespace network { namespace network {
@ -103,13 +101,6 @@ class CefRequestImpl : public CefRequest {
// Populate this object from teh HttpRequestHeaders object. // Populate this object from teh HttpRequestHeaders object.
void Set(const net::HttpRequestHeaders& headers); void Set(const net::HttpRequestHeaders& headers);
// Populate this object from the URLRequest object.
void Set(const net::URLRequest* request);
// Populate the URLRequest object from this object.
// If |changed_only| is true then only the changed fields will be updated.
void Get(net::URLRequest* request, bool changed_only) const;
// Populate this object from the NavigationParams object. // Populate this object from the NavigationParams object.
// TODO(cef): Remove the |is_main_frame| argument once NavigationParams is // TODO(cef): Remove the |is_main_frame| argument once NavigationParams is
// reliable in reporting that value. // reliable in reporting that value.
@ -130,11 +121,6 @@ class CefRequestImpl : public CefRequest {
// Called from CefBrowserHostImpl::LoadRequest(). // Called from CefBrowserHostImpl::LoadRequest().
void Get(CefNavigateParams& params) const; void Get(CefNavigateParams& params) const;
// Populate the URLFetcher object from this object.
// Called from
// CefBrowserURLRequestOld::Context::ContinueOnOriginatingThread().
void Get(net::URLFetcher& fetcher, int64& upload_data_size) const;
void SetReadOnly(bool read_only); void SetReadOnly(bool read_only);
// Enable or disable tracking of changes. If |track_changes| is true the // Enable or disable tracking of changes. If |track_changes| is true the

View File

@ -12,7 +12,6 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "net/http/http_request_headers.h" #include "net/http/http_request_headers.h"
#include "net/http/http_response_headers.h" #include "net/http/http_response_headers.h"
#include "net/url_request/url_request.h"
#include "third_party/blink/public/platform/web_http_header_visitor.h" #include "third_party/blink/public/platform/web_http_header_visitor.h"
#include "third_party/blink/public/platform/web_string.h" #include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/public/platform/web_url.h" #include "third_party/blink/public/platform/web_url.h"
@ -206,14 +205,6 @@ void CefResponseImpl::Set(const blink::WebURLResponse& response) {
response.VisitHttpHeaderFields(&visitor); response.VisitHttpHeaderFields(&visitor);
} }
void CefResponseImpl::Set(const net::URLRequest* request) {
DCHECK(request);
const net::HttpResponseHeaders* headers = request->response_headers();
if (headers)
SetResponseHeaders(*headers);
}
void CefResponseImpl::SetReadOnly(bool read_only) { void CefResponseImpl::SetReadOnly(bool read_only) {
base::AutoLock lock_scope(lock_); base::AutoLock lock_scope(lock_);
read_only_ = read_only; read_only_ = read_only;

View File

@ -12,7 +12,6 @@
namespace net { namespace net {
class HttpResponseHeaders; class HttpResponseHeaders;
class URLRequest;
} // namespace net } // namespace net
namespace blink { namespace blink {
@ -46,7 +45,6 @@ class CefResponseImpl : public CefResponse {
void SetResponseHeaders(const net::HttpResponseHeaders& headers); void SetResponseHeaders(const net::HttpResponseHeaders& headers);
void Set(const blink::WebURLResponse& response); void Set(const blink::WebURLResponse& response);
void Set(const net::URLRequest* request);
void SetReadOnly(bool read_only); void SetReadOnly(bool read_only);

View File

@ -3,10 +3,8 @@
// be found in the LICENSE file. // be found in the LICENSE file.
#include "include/cef_urlrequest.h" #include "include/cef_urlrequest.h"
#include "libcef/browser/net/browser_urlrequest_old_impl.h"
#include "libcef/browser/net_service/browser_urlrequest_impl.h" #include "libcef/browser/net_service/browser_urlrequest_impl.h"
#include "libcef/common/content_client.h" #include "libcef/common/content_client.h"
#include "libcef/common/net_service/util.h"
#include "libcef/common/task_runner_impl.h" #include "libcef/common/task_runner_impl.h"
#include "libcef/renderer/render_urlrequest_impl.h" #include "libcef/renderer/render_urlrequest_impl.h"
@ -31,17 +29,10 @@ CefRefPtr<CefURLRequest> CefURLRequest::Create(
if (CefContentClient::Get()->browser()) { if (CefContentClient::Get()->browser()) {
// In the browser process. // In the browser process.
if (net_service::IsEnabled()) { CefRefPtr<CefBrowserURLRequest> impl =
CefRefPtr<CefBrowserURLRequest> impl = new CefBrowserURLRequest(nullptr, request, client, request_context);
new CefBrowserURLRequest(nullptr, request, client, request_context); if (impl->Start())
if (impl->Start()) return impl.get();
return impl.get();
} else {
CefRefPtr<CefBrowserURLRequestOld> impl =
new CefBrowserURLRequestOld(request, client, request_context);
if (impl->Start())
return impl.get();
}
return NULL; return NULL;
} else if (CefContentClient::Get()->renderer()) { } else if (CefContentClient::Get()->renderer()) {
// In the render process. // In the render process.

View File

@ -316,9 +316,9 @@ class CefRenderURLRequest::Context
void NotifyUploadProgressIfNecessary() { void NotifyUploadProgressIfNecessary() {
if (!got_upload_progress_complete_ && upload_data_size_ > 0) { if (!got_upload_progress_complete_ && upload_data_size_ > 0) {
// URLFetcher sends upload notifications using a timer and will not send // Upload notifications are sent using a timer and may not occur if the
// a notification if the request completes too quickly. We therefore // request completes too quickly. We therefore send the notification here
// send the notification here if necessary. // if necessary.
client_->OnUploadProgress(url_request_.get(), upload_data_size_, client_->OnUploadProgress(url_request_.get(), upload_data_size_,
upload_data_size_); upload_data_size_);
got_upload_progress_complete_ = true; got_upload_progress_complete_ = true;

View File

@ -46,8 +46,6 @@ CefURLLoaderThrottleProviderImpl::CreateThrottles(
std::vector<std::unique_ptr<content::URLLoaderThrottle>> throttles; std::vector<std::unique_ptr<content::URLLoaderThrottle>> throttles;
bool network_service_enabled =
base::FeatureList::IsEnabled(network::features::kNetworkService);
// Some throttles have already been added in the browser for frame resources. // Some throttles have already been added in the browser for frame resources.
// Don't add them for frame requests. // Don't add them for frame requests.
bool is_frame_resource = content::IsResourceTypeFrame(resource_type); bool is_frame_resource = content::IsResourceTypeFrame(resource_type);
@ -55,7 +53,7 @@ CefURLLoaderThrottleProviderImpl::CreateThrottles(
DCHECK(!is_frame_resource || DCHECK(!is_frame_resource ||
type_ == content::URLLoaderThrottleProviderType::kFrame); type_ == content::URLLoaderThrottleProviderType::kFrame);
if (extensions::ExtensionsEnabled() && network_service_enabled && if (extensions::ExtensionsEnabled() &&
type_ == content::URLLoaderThrottleProviderType::kFrame && type_ == content::URLLoaderThrottleProviderType::kFrame &&
resource_type == content::ResourceType::kObject) { resource_type == content::ResourceType::kObject) {
content::RenderFrame* render_frame = content::RenderFrame* render_frame =

View File

@ -128,12 +128,6 @@ patches = [
# https://codereview.chromium.org/208313009 # https://codereview.chromium.org/208313009
'name': 'ui_dragdrop_355390', 'name': 'ui_dragdrop_355390',
}, },
{
# Make URLRequest::set_is_pending() public so that it can be called from
# CefRequestInterceptor::MaybeInterceptResponse().
# https://bitbucket.org/chromiumembedded/cef/issues/1327
'name': 'net_urlrequest_1327',
},
{ {
# Remove NOTREACHED() that is hit when loading Flash in incognito mode. # Remove NOTREACHED() that is hit when loading Flash in incognito mode.
# https://bitbucket.org/chromiumembedded/cef/issue/1586 # https://bitbucket.org/chromiumembedded/cef/issue/1586
@ -170,11 +164,6 @@ patches = [
'name': 'pdfium_print_549365', 'name': 'pdfium_print_549365',
'path': 'third_party/pdfium/', 'path': 'third_party/pdfium/',
}, },
{
# Enable support for filtering resource responses.
# https://bitbucket.org/chromiumembedded/cef/issues/515
'name': 'net_filter_515',
},
{ {
# Modify views::View to extend SupportsUserData. # Modify views::View to extend SupportsUserData.
# https://bitbucket.org/chromiumembedded/cef/issues/1749 # https://bitbucket.org/chromiumembedded/cef/issues/1749
@ -222,11 +211,6 @@ patches = [
'name': 'chrome_browser_profiles', 'name': 'chrome_browser_profiles',
}, },
{ {
# Support direct access to NetExportFileWriter via BrowserProcess instead
# of adding a dependency on SystemNetworkContextManager (see
# https://crrev.com/6ed14d99e9).
# TODO(cef): Consider removing this once we support NetworkService.
#
# Show the CEF Save As dialog. # Show the CEF Save As dialog.
# https://bitbucket.org/chromiumembedded/cef/issues/2613 # https://bitbucket.org/chromiumembedded/cef/issues/2613
'name': 'chrome_browser_net_export', 'name': 'chrome_browser_net_export',
@ -257,11 +241,6 @@ patches = [
# https://bitbucket.org/chromiumembedded/cef/issues/2037 # https://bitbucket.org/chromiumembedded/cef/issues/2037
'name': 'webui_2037', 'name': 'webui_2037',
}, },
{
# Support an option to enable/disable net security expiration.
# https://bitbucket.org/chromiumembedded/cef/issues/1994
'name': 'net_security_expiration_1994',
},
{ {
# Implement breakpad/crashpad customization required by CEF. # Implement breakpad/crashpad customization required by CEF.
# https://bitbucket.org/chromiumembedded/cef/issues/1995 # https://bitbucket.org/chromiumembedded/cef/issues/1995

View File

@ -1,55 +1,3 @@
diff --git chrome/browser/browser_process.h chrome/browser/browser_process.h
index 761d300aa06b..f86558dd6efc 100644
--- chrome/browser/browser_process.h
+++ chrome/browser/browser_process.h
@@ -40,6 +40,10 @@ class WatchDogThread;
class WebRtcLogUploader;
class StartupData;
+namespace net_log {
+class NetExportFileWriter;
+}
+
namespace network {
class NetworkQualityTracker;
class SharedURLLoaderFactory;
@@ -184,6 +188,9 @@ class BrowserProcess {
// backed by the IOThread's URLRequestContext.
virtual SystemNetworkContextManager* system_network_context_manager() = 0;
+ // Provide direct accessor for CEF.
+ virtual net_log::NetExportFileWriter* net_export_file_writer() = 0;
+
// Returns a NetworkQualityTracker that can be used to subscribe for
// network quality change events.
virtual network::NetworkQualityTracker* network_quality_tracker() = 0;
diff --git chrome/browser/browser_process_impl.cc chrome/browser/browser_process_impl.cc
index c2e0b9172eb2..57c22ff16f4b 100644
--- chrome/browser/browser_process_impl.cc
+++ chrome/browser/browser_process_impl.cc
@@ -683,6 +683,10 @@ BrowserProcessImpl::system_network_context_manager() {
return SystemNetworkContextManager::GetInstance();
}
+net_log::NetExportFileWriter* BrowserProcessImpl::net_export_file_writer() {
+ return system_network_context_manager()->GetNetExportFileWriter();
+}
+
scoped_refptr<network::SharedURLLoaderFactory>
BrowserProcessImpl::shared_url_loader_factory() {
return system_network_context_manager()->GetSharedURLLoaderFactory();
diff --git chrome/browser/browser_process_impl.h chrome/browser/browser_process_impl.h
index 95a7bd8e8b58..af7685f86848 100644
--- chrome/browser/browser_process_impl.h
+++ chrome/browser/browser_process_impl.h
@@ -142,6 +142,7 @@ class BrowserProcessImpl : public BrowserProcess,
// TODO(qinmin): Remove this method as callers can retrieve the global
// instance from SystemNetworkContextManager directly.
SystemNetworkContextManager* system_network_context_manager() override;
+ net_log::NetExportFileWriter* net_export_file_writer() override;
scoped_refptr<network::SharedURLLoaderFactory> shared_url_loader_factory()
override;
network::NetworkQualityTracker* network_quality_tracker() override;
diff --git chrome/browser/ui/BUILD.gn chrome/browser/ui/BUILD.gn diff --git chrome/browser/ui/BUILD.gn chrome/browser/ui/BUILD.gn
index 6bd5bea7ddb0..076306275b5b 100644 index 6bd5bea7ddb0..076306275b5b 100644
--- chrome/browser/ui/BUILD.gn --- chrome/browser/ui/BUILD.gn
@ -82,7 +30,7 @@ index 6bd5bea7ddb0..076306275b5b 100644
"//chrome:resources", "//chrome:resources",
"//chrome:strings", "//chrome:strings",
diff --git chrome/browser/ui/webui/net_export_ui.cc chrome/browser/ui/webui/net_export_ui.cc diff --git chrome/browser/ui/webui/net_export_ui.cc chrome/browser/ui/webui/net_export_ui.cc
index 1b9b3d857f47..84b875f0e01d 100644 index 1b9b3d857f47..85e2d1e5a5d5 100644
--- chrome/browser/ui/webui/net_export_ui.cc --- chrome/browser/ui/webui/net_export_ui.cc
+++ chrome/browser/ui/webui/net_export_ui.cc +++ chrome/browser/ui/webui/net_export_ui.cc
@@ -20,14 +20,13 @@ @@ -20,14 +20,13 @@
@ -183,17 +131,7 @@ index 1b9b3d857f47..84b875f0e01d 100644
base::WeakPtrFactory<NetExportMessageHandler> weak_ptr_factory_; base::WeakPtrFactory<NetExportMessageHandler> weak_ptr_factory_;
@@ -158,8 +179,7 @@ class NetExportMessageHandler @@ -168,8 +189,10 @@ NetExportMessageHandler::NetExportMessageHandler()
};
NetExportMessageHandler::NetExportMessageHandler()
- : file_writer_(g_browser_process->system_network_context_manager()
- ->GetNetExportFileWriter()),
+ : file_writer_(g_browser_process->net_export_file_writer()),
state_observer_manager_(this),
weak_ptr_factory_(this) {
file_writer_->Initialize();
@@ -168,8 +188,10 @@ NetExportMessageHandler::NetExportMessageHandler()
NetExportMessageHandler::~NetExportMessageHandler() { NetExportMessageHandler::~NetExportMessageHandler() {
// There may be a pending file dialog, it needs to be told that the user // There may be a pending file dialog, it needs to be told that the user
// has gone away so that it doesn't try to call back. // has gone away so that it doesn't try to call back.
@ -204,7 +142,7 @@ index 1b9b3d857f47..84b875f0e01d 100644
file_writer_->StopNetLog(nullptr); file_writer_->StopNetLog(nullptr);
} }
@@ -232,6 +254,7 @@ void NetExportMessageHandler::OnStartNetLog(const base::ListValue* list) { @@ -232,6 +255,7 @@ void NetExportMessageHandler::OnStartNetLog(const base::ListValue* list) {
if (UsingMobileUI()) { if (UsingMobileUI()) {
StartNetLog(base::FilePath()); StartNetLog(base::FilePath());
} else { } else {
@ -212,7 +150,7 @@ index 1b9b3d857f47..84b875f0e01d 100644
base::FilePath initial_dir = last_save_dir.Pointer()->empty() ? base::FilePath initial_dir = last_save_dir.Pointer()->empty() ?
DownloadPrefs::FromBrowserContext( DownloadPrefs::FromBrowserContext(
web_ui()->GetWebContents()->GetBrowserContext())->DownloadPath() : web_ui()->GetWebContents()->GetBrowserContext())->DownloadPath() :
@@ -239,6 +262,9 @@ void NetExportMessageHandler::OnStartNetLog(const base::ListValue* list) { @@ -239,6 +263,9 @@ void NetExportMessageHandler::OnStartNetLog(const base::ListValue* list) {
base::FilePath initial_path = base::FilePath initial_path =
initial_dir.Append(FILE_PATH_LITERAL("chrome-net-export-log.json")); initial_dir.Append(FILE_PATH_LITERAL("chrome-net-export-log.json"));
ShowSelectFileDialog(initial_path); ShowSelectFileDialog(initial_path);
@ -222,7 +160,7 @@ index 1b9b3d857f47..84b875f0e01d 100644
} }
} }
@@ -248,6 +274,7 @@ void NetExportMessageHandler::OnStopNetLog(const base::ListValue* list) { @@ -248,6 +275,7 @@ void NetExportMessageHandler::OnStopNetLog(const base::ListValue* list) {
std::unique_ptr<base::DictionaryValue> ui_thread_polled_data( std::unique_ptr<base::DictionaryValue> ui_thread_polled_data(
new base::DictionaryValue()); new base::DictionaryValue());
@ -230,7 +168,7 @@ index 1b9b3d857f47..84b875f0e01d 100644
Profile* profile = Profile::FromWebUI(web_ui()); Profile* profile = Profile::FromWebUI(web_ui());
SetIfNotNull(ui_thread_polled_data.get(), "prerenderInfo", SetIfNotNull(ui_thread_polled_data.get(), "prerenderInfo",
chrome_browser_net::GetPrerenderInfo(profile)); chrome_browser_net::GetPrerenderInfo(profile));
@@ -257,6 +284,7 @@ void NetExportMessageHandler::OnStopNetLog(const base::ListValue* list) { @@ -257,6 +285,7 @@ void NetExportMessageHandler::OnStopNetLog(const base::ListValue* list) {
SetIfNotNull(ui_thread_polled_data.get(), "serviceProviders", SetIfNotNull(ui_thread_polled_data.get(), "serviceProviders",
chrome_browser_net::GetWindowsServiceProviders()); chrome_browser_net::GetWindowsServiceProviders());
#endif #endif
@ -238,7 +176,7 @@ index 1b9b3d857f47..84b875f0e01d 100644
file_writer_->StopNetLog(std::move(ui_thread_polled_data)); file_writer_->StopNetLog(std::move(ui_thread_polled_data));
} }
@@ -273,6 +301,7 @@ void NetExportMessageHandler::OnShowFile(const base::ListValue* list) { @@ -273,6 +302,7 @@ void NetExportMessageHandler::OnShowFile(const base::ListValue* list) {
base::Bind(&NetExportMessageHandler::ShowFileInShell, AsWeakPtr())); base::Bind(&NetExportMessageHandler::ShowFileInShell, AsWeakPtr()));
} }
@ -246,7 +184,7 @@ index 1b9b3d857f47..84b875f0e01d 100644
void NetExportMessageHandler::FileSelected(const base::FilePath& path, void NetExportMessageHandler::FileSelected(const base::FilePath& path,
int index, int index,
void* params) { void* params) {
@@ -291,6 +320,7 @@ void NetExportMessageHandler::FileSelectionCanceled(void* params) { @@ -291,6 +321,7 @@ void NetExportMessageHandler::FileSelectionCanceled(void* params) {
DCHECK(select_file_dialog_); DCHECK(select_file_dialog_);
select_file_dialog_ = nullptr; select_file_dialog_ = nullptr;
} }
@ -254,7 +192,7 @@ index 1b9b3d857f47..84b875f0e01d 100644
void NetExportMessageHandler::OnNewState(const base::DictionaryValue& state) { void NetExportMessageHandler::OnNewState(const base::DictionaryValue& state) {
NotifyUIWithState(state.CreateDeepCopy()); NotifyUIWithState(state.CreateDeepCopy());
@@ -355,6 +385,7 @@ void NetExportMessageHandler::NotifyUIWithState( @@ -355,6 +386,7 @@ void NetExportMessageHandler::NotifyUIWithState(
*state); *state);
} }
@ -262,7 +200,7 @@ index 1b9b3d857f47..84b875f0e01d 100644
void NetExportMessageHandler::ShowSelectFileDialog( void NetExportMessageHandler::ShowSelectFileDialog(
const base::FilePath& default_path) { const base::FilePath& default_path) {
// User may have clicked more than once before the save dialog appears. // User may have clicked more than once before the save dialog appears.
@@ -373,6 +404,43 @@ void NetExportMessageHandler::ShowSelectFileDialog( @@ -373,6 +405,43 @@ void NetExportMessageHandler::ShowSelectFileDialog(
ui::SelectFileDialog::SELECT_SAVEAS_FILE, base::string16(), default_path, ui::SelectFileDialog::SELECT_SAVEAS_FILE, base::string16(), default_path,
&file_type_info, 0, base::FilePath::StringType(), owning_window, nullptr); &file_type_info, 0, base::FilePath::StringType(), owning_window, nullptr);
} }

View File

@ -1,40 +0,0 @@
diff --git net/base/network_delegate.h net/base/network_delegate.h
index 49fe875c7d22..c1e3df840dc0 100644
--- net/base/network_delegate.h
+++ net/base/network_delegate.h
@@ -17,6 +17,7 @@
#include "net/base/completion_once_callback.h"
#include "net/base/net_export.h"
#include "net/cookies/canonical_cookie.h"
+#include "net/filter/source_stream.h"
#include "net/proxy_resolution/proxy_retry_info.h"
class GURL;
@@ -122,6 +123,10 @@ class NET_EXPORT NetworkDelegate {
bool CanUseReportingClient(const url::Origin& origin,
const GURL& endpoint) const;
+ virtual std::unique_ptr<SourceStream> CreateSourceStream(
+ net::URLRequest* request,
+ std::unique_ptr<SourceStream> upstream) { return upstream; }
+
protected:
THREAD_CHECKER(thread_checker_);
diff --git net/url_request/url_request_job.cc net/url_request/url_request_job.cc
index 3a7efeaf5b04..1a03e0ab8229 100644
--- net/url_request/url_request_job.cc
+++ net/url_request/url_request_job.cc
@@ -438,6 +438,12 @@ void URLRequestJob::NotifyHeadersComplete() {
DCHECK(!source_stream_);
source_stream_ = SetUpSourceStream();
+ // Allow the delegate to add a downstream SourceStream for filtering.
+ if (network_delegate_ && source_stream_) {
+ source_stream_ = network_delegate_->CreateSourceStream(
+ request_, std::move(source_stream_));
+ }
+
if (!source_stream_) {
OnDone(URLRequestStatus(URLRequestStatus::FAILED,
ERR_CONTENT_DECODING_INIT_FAILED),

View File

@ -1,52 +0,0 @@
diff --git net/http/transport_security_state.cc net/http/transport_security_state.cc
index b7a2bca7bf42..5987ee212a12 100644
--- net/http/transport_security_state.cc
+++ net/http/transport_security_state.cc
@@ -1100,8 +1100,12 @@ void TransportSecurityState::ClearReportCachesForTesting() {
sent_expect_ct_reports_cache_.Clear();
}
-// static
-bool TransportSecurityState::IsBuildTimely() {
+// Returns true if the current build is recent enough to ensure that
+// built-in security information (e.g. CT Logs) is fresh enough.
+bool TransportSecurityState::IsBuildTimely() const {
+ if (!enforce_net_security_expiration_)
+ return true;
+
const base::Time build_time = base::GetBuildTime();
// We consider built-in information to be timely for 10 weeks.
return (base::Time::Now() - build_time).InDays() < 70 /* 10 weeks */;
diff --git net/http/transport_security_state.h net/http/transport_security_state.h
index 48ccb74e2e1d..79dc9958d1de 100644
--- net/http/transport_security_state.h
+++ net/http/transport_security_state.h
@@ -530,6 +530,10 @@ class NET_EXPORT TransportSecurityState {
void EnableStaticPinsForTesting() { enable_static_pins_ = true; }
bool has_dynamic_pkp_state() const { return !enabled_pkp_hosts_.empty(); }
+ void set_enforce_net_security_expiration(bool enforce) {
+ enforce_net_security_expiration_ = enforce;
+ }
+
private:
friend class TransportSecurityStateTest;
friend class TransportSecurityStateStaticFuzzer;
@@ -548,7 +552,7 @@ class NET_EXPORT TransportSecurityState {
// IsBuildTimely returns true if the current build is new enough ensure that
// built in security information (i.e. HSTS preloading and pinning
// information) is timely.
- static bool IsBuildTimely();
+ bool IsBuildTimely() const;
// Helper method for actually checking pins.
PKPStatus CheckPublicKeyPinsImpl(
@@ -646,6 +650,8 @@ class NET_EXPORT TransportSecurityState {
// True if public key pinning bypass is enabled for local trust anchors.
bool enable_pkp_bypass_for_local_trust_anchors_;
+ bool enforce_net_security_expiration_ = true;
+
ExpectCTReporter* expect_ct_reporter_ = nullptr;
RequireCTDelegate* require_ct_delegate_ = nullptr;

View File

@ -1,16 +0,0 @@
diff --git net/url_request/url_request.h net/url_request/url_request.h
index f6043de481fa..ca4d2472f572 100644
--- net/url_request/url_request.h
+++ net/url_request/url_request.h
@@ -782,10 +782,10 @@ class NET_EXPORT URLRequest : public base::SupportsUserData {
base::WeakPtr<URLRequest> GetWeakPtr();
- protected:
// Allow the URLRequestJob class to control the is_pending() flag.
void set_is_pending(bool value) { is_pending_ = value; }
+ protected:
// Allow the URLRequestJob class to set our status too.
void set_status(URLRequestStatus status);

View File

@ -921,10 +921,7 @@ class CookieTestSchemeHandler : public TestHandler {
EXPECT_FALSE(got_cookie2_); EXPECT_FALSE(got_cookie2_);
EXPECT_FALSE(got_cookie3_); EXPECT_FALSE(got_cookie3_);
} else { } else {
if (IsNetworkServiceEnabled()) EXPECT_TRUE(got_create_cookie_);
EXPECT_TRUE(got_create_cookie_);
else
EXPECT_FALSE(got_create_cookie_);
EXPECT_TRUE(got_process_request_cookie_); EXPECT_TRUE(got_process_request_cookie_);
EXPECT_TRUE(got_cookie1_); EXPECT_TRUE(got_cookie1_);
EXPECT_TRUE(got_cookie2_); EXPECT_TRUE(got_cookie2_);
@ -1946,34 +1943,15 @@ class CookieAccessTestHandler : public RoutingTestHandler,
IMPLEMENT_REFCOUNTING(CookieAccessTestHandler); IMPLEMENT_REFCOUNTING(CookieAccessTestHandler);
}; };
bool IsTestSupported(CookieAccessTestHandler::TestMode test_mode,
CookieAccessTestHandler::TestBackend backend_mode,
bool custom_scheme,
bool use_global) {
if (!IsNetworkServiceEnabled() &&
backend_mode == CookieAccessTestHandler::RESOURCE_HANDLER &&
custom_scheme) {
// The old network implementation does not support the same functionality
// for intercepting custom scheme requests via GetResourceHandler().
return false;
}
return true;
}
} // namespace } // namespace
#define ACCESS_TEST(name, test_mode, backend_mode, custom_scheme, use_global) \ #define ACCESS_TEST(name, test_mode, backend_mode, custom_scheme, use_global) \
TEST(CookieTest, Access##name) { \ TEST(CookieTest, Access##name) { \
if (!IsTestSupported(CookieAccessTestHandler::test_mode, \ CefRefPtr<CookieAccessTestHandler> handler = new CookieAccessTestHandler( \
CookieAccessTestHandler::backend_mode, custom_scheme, \ CookieAccessTestHandler::test_mode, \
use_global)) { \ CookieAccessTestHandler::backend_mode, custom_scheme, use_global); \
return; \ handler->ExecuteTest(); \
} \ ReleaseAndWaitForDestructor(handler); \
CefRefPtr<CookieAccessTestHandler> handler = new CookieAccessTestHandler( \
CookieAccessTestHandler::test_mode, \
CookieAccessTestHandler::backend_mode, custom_scheme, use_global); \
handler->ExecuteTest(); \
ReleaseAndWaitForDestructor(handler); \
} }
#define ACCESS_TEST_ALL_MODES(name, backend_mode, custom_scheme, use_global) \ #define ACCESS_TEST_ALL_MODES(name, backend_mode, custom_scheme, use_global) \
@ -2396,8 +2374,6 @@ class CookieRestartTestHandler : public RoutingTestHandler,
} // namespace } // namespace
TEST(CookieTest, RestartGlobal) { TEST(CookieTest, RestartGlobal) {
if (!IsNetworkServiceEnabled())
return;
CefRefPtr<CookieRestartTestHandler> handler = CefRefPtr<CookieRestartTestHandler> handler =
new CookieRestartTestHandler(true); new CookieRestartTestHandler(true);
handler->ExecuteTest(); handler->ExecuteTest();
@ -2405,8 +2381,6 @@ TEST(CookieTest, RestartGlobal) {
} }
TEST(CookieTest, RestartInMemory) { TEST(CookieTest, RestartInMemory) {
if (!IsNetworkServiceEnabled())
return;
CefRefPtr<CookieRestartTestHandler> handler = CefRefPtr<CookieRestartTestHandler> handler =
new CookieRestartTestHandler(false); new CookieRestartTestHandler(false);
handler->ExecuteTest(); handler->ExecuteTest();

View File

@ -896,16 +896,10 @@ class RedirectTestHandler : public TestHandler {
// Called due to the nav3 redirect response. // Called due to the nav3 redirect response.
got_nav3_redirect_.yes(); got_nav3_redirect_.yes();
if (IsNetworkServiceEnabled()) { EXPECT_EQ(307, response->GetStatus());
EXPECT_EQ(307, response->GetStatus()); EXPECT_STREQ("Temporary Redirect",
EXPECT_STREQ("Temporary Redirect", response->GetStatusText().ToString().c_str());
response->GetStatusText().ToString().c_str()); EXPECT_STREQ("", response->GetMimeType().ToString().c_str());
EXPECT_STREQ("", response->GetMimeType().ToString().c_str());
} else {
EXPECT_EQ(303, response->GetStatus());
EXPECT_STREQ("See Other", response->GetStatusText().ToString().c_str());
EXPECT_STREQ("text/html", response->GetMimeType().ToString().c_str());
}
} else { } else {
got_invalid_redirect_.yes(); got_invalid_redirect_.yes();
} }
@ -1015,12 +1009,7 @@ TEST(NavigationTest, Redirect) {
ASSERT_TRUE(handler->got_nav4_load_end_); ASSERT_TRUE(handler->got_nav4_load_end_);
ASSERT_FALSE(handler->got_invalid_load_end_); ASSERT_FALSE(handler->got_invalid_load_end_);
ASSERT_TRUE(handler->got_nav1_redirect_); ASSERT_TRUE(handler->got_nav1_redirect_);
if (IsNetworkServiceEnabled()) { ASSERT_FALSE(handler->got_nav2_redirect_);
ASSERT_FALSE(handler->got_nav2_redirect_);
} else {
// This seems like a bug in the old network implementation.
ASSERT_TRUE(handler->got_nav2_redirect_);
}
ASSERT_TRUE(handler->got_nav3_redirect_); ASSERT_TRUE(handler->got_nav3_redirect_);
ASSERT_FALSE(handler->got_invalid_redirect_); ASSERT_FALSE(handler->got_invalid_redirect_);
ASSERT_TRUE(g_got_nav1_request); ASSERT_TRUE(g_got_nav1_request);

View File

@ -38,10 +38,7 @@ class NormalResourceHandler : public CefStreamResourceHandler {
destroy_callback_(destroy_callback) {} destroy_callback_(destroy_callback) {}
~NormalResourceHandler() override { ~NormalResourceHandler() override {
if (IsNetworkServiceEnabled()) EXPECT_EQ(1, cancel_ct_);
EXPECT_EQ(1, cancel_ct_);
else
EXPECT_EQ(0, cancel_ct_);
destroy_callback_.Run(); destroy_callback_.Run();
} }
@ -76,10 +73,7 @@ class IncompleteResourceHandler : public CefResourceHandler {
~IncompleteResourceHandler() override { ~IncompleteResourceHandler() override {
EXPECT_EQ(1, process_request_ct_); EXPECT_EQ(1, process_request_ct_);
if (IsNetworkServiceEnabled()) EXPECT_EQ(1, cancel_ct_);
EXPECT_EQ(1, cancel_ct_);
else
EXPECT_EQ(0, cancel_ct_);
if (test_mode_ == BLOCK_READ_RESPONSE) { if (test_mode_ == BLOCK_READ_RESPONSE) {
EXPECT_EQ(1, get_response_headers_ct_); EXPECT_EQ(1, get_response_headers_ct_);
@ -280,7 +274,7 @@ class BasicResponseTest : public TestHandler {
EXPECT_EQ(browser_id_, browser->GetIdentifier()); EXPECT_EQ(browser_id_, browser->GetIdentifier());
EXPECT_TRUE(frame->IsMain()); EXPECT_TRUE(frame->IsMain());
if (IsNetworkServiceEnabled() && request_id_ == 0U) { if (request_id_ == 0U) {
// This is the first callback that provides a request ID. // This is the first callback that provides a request ID.
request_id_ = request->GetIdentifier(); request_id_ = request->GetIdentifier();
EXPECT_GT(request_id_, 0U); EXPECT_GT(request_id_, 0U);
@ -443,9 +437,7 @@ class BasicResponseTest : public TestHandler {
// Redirect again. // Redirect again.
new_url = GetURL(RESULT_HTML); new_url = GetURL(RESULT_HTML);
} else { } else {
DCHECK(!IsNetworkServiceEnabled()); NOTREACHED();
// The URL redirected to above.
EXPECT_STREQ(GetURL(RESULT_HTML), new_url.ToString().c_str());
} }
} }
@ -560,129 +552,85 @@ class BasicResponseTest : public TestHandler {
} }
void DestroyTest() override { void DestroyTest() override {
if (!IsNetworkServiceEnabled()) {
// Called once for each other callback.
EXPECT_EQ(on_before_resource_load_ct_ + get_resource_handler_ct_ +
on_resource_redirect_ct_ + on_resource_response_ct_ +
get_resource_response_filter_ct_ +
on_resource_load_complete_ct_,
get_resource_request_handler_ct_);
// Only called at the time we handle cookies.
EXPECT_EQ(0, get_cookie_access_filter_ct_);
}
if (mode_ == LOAD || mode_ == MODIFY_BEFORE_RESOURCE_LOAD) { if (mode_ == LOAD || mode_ == MODIFY_BEFORE_RESOURCE_LOAD) {
EXPECT_EQ(1, on_before_browse_ct_); EXPECT_EQ(1, on_before_browse_ct_);
if (IsNetworkServiceEnabled()) { EXPECT_EQ(1, get_resource_request_handler_ct_);
EXPECT_EQ(1, get_resource_request_handler_ct_); EXPECT_EQ(1, get_cookie_access_filter_ct_);
EXPECT_EQ(1, get_cookie_access_filter_ct_);
}
EXPECT_EQ(1, on_before_resource_load_ct_); EXPECT_EQ(1, on_before_resource_load_ct_);
EXPECT_EQ(1, get_resource_handler_ct_); EXPECT_EQ(1, get_resource_handler_ct_);
EXPECT_EQ(0, on_resource_redirect_ct_); EXPECT_EQ(0, on_resource_redirect_ct_);
if (IsNetworkServiceEnabled()) {
// Unhandled requests won't see a call to GetResourceResponseFilter. // Unhandled requests won't see a call to GetResourceResponseFilter
if (unhandled_) // or OnResourceResponse.
EXPECT_EQ(0, get_resource_response_filter_ct_); if (unhandled_) {
else EXPECT_EQ(0, get_resource_response_filter_ct_);
EXPECT_EQ(1, get_resource_response_filter_ct_); EXPECT_EQ(0, on_resource_response_ct_);
} else {
EXPECT_EQ(1, get_resource_response_filter_ct_);
EXPECT_EQ(1, on_resource_response_ct_);
}
} else if (mode_ == RESTART_RESOURCE_RESPONSE) {
EXPECT_EQ(1, on_before_browse_ct_);
EXPECT_EQ(2, get_resource_request_handler_ct_);
EXPECT_EQ(2, get_cookie_access_filter_ct_);
EXPECT_EQ(2, on_before_resource_load_ct_);
EXPECT_EQ(2, get_resource_handler_ct_);
EXPECT_EQ(0, on_resource_redirect_ct_);
// Unhandled requests won't see a call to GetResourceResponseFilter or
// OnResourceResponse. In this case we're restarting from inside
// OnResourceResponse.
if (unhandled_) {
EXPECT_EQ(0, get_resource_response_filter_ct_);
EXPECT_EQ(1, on_resource_response_ct_);
} else {
EXPECT_EQ(1, get_resource_response_filter_ct_);
EXPECT_EQ(2, on_resource_response_ct_);
}
} else if (IsRedirect()) {
EXPECT_EQ(2, on_before_browse_ct_);
EXPECT_EQ(2, get_resource_request_handler_ct_);
EXPECT_EQ(2, get_cookie_access_filter_ct_);
EXPECT_EQ(2, on_before_resource_load_ct_);
if (mode_ == REDIRECT_BEFORE_RESOURCE_LOAD) {
EXPECT_EQ(1, get_resource_handler_ct_);
} else {
EXPECT_EQ(2, get_resource_handler_ct_);
}
EXPECT_EQ(1, on_resource_redirect_ct_);
// Unhandled requests won't see a call to GetResourceResponseFilter.
if (unhandled_) {
EXPECT_EQ(0, get_resource_response_filter_ct_);
} else { } else {
EXPECT_EQ(1, get_resource_response_filter_ct_); EXPECT_EQ(1, get_resource_response_filter_ct_);
} }
// Unhandled requests won't see a call to OnResourceResponse.
if (unhandled_)
EXPECT_EQ(0, on_resource_response_ct_);
else
EXPECT_EQ(1, on_resource_response_ct_);
} else if (mode_ == RESTART_RESOURCE_RESPONSE) {
EXPECT_EQ(1, on_before_browse_ct_);
if (IsNetworkServiceEnabled()) {
EXPECT_EQ(2, get_resource_request_handler_ct_);
EXPECT_EQ(2, get_cookie_access_filter_ct_);
EXPECT_EQ(2, on_before_resource_load_ct_);
} else {
// This seems like a bug in the old network implementation.
EXPECT_EQ(1, on_before_resource_load_ct_);
}
EXPECT_EQ(2, get_resource_handler_ct_);
EXPECT_EQ(0, on_resource_redirect_ct_);
if (IsNetworkServiceEnabled()) {
// Unhandled requests won't see a call to GetResourceResponseFilter.
if (unhandled_)
EXPECT_EQ(0, get_resource_response_filter_ct_);
else
EXPECT_EQ(1, get_resource_response_filter_ct_);
} else {
EXPECT_EQ(2, get_resource_response_filter_ct_);
}
// Unhandled requests won't see a call to OnResourceResponse.
// In this case we're restarting from inside OnResourceResponse.
if (unhandled_)
EXPECT_EQ(1, on_resource_response_ct_);
else
EXPECT_EQ(2, on_resource_response_ct_);
} else if (IsRedirect()) {
EXPECT_EQ(2, on_before_browse_ct_);
if (IsNetworkServiceEnabled()) {
EXPECT_EQ(2, get_resource_request_handler_ct_);
EXPECT_EQ(2, get_cookie_access_filter_ct_);
} else {
// Called at the time that we handle cookies.
EXPECT_EQ(0, get_cookie_access_filter_ct_);
}
EXPECT_EQ(2, on_before_resource_load_ct_);
if (mode_ == REDIRECT_BEFORE_RESOURCE_LOAD)
EXPECT_EQ(1, get_resource_handler_ct_);
else
EXPECT_EQ(2, get_resource_handler_ct_);
if (IsNetworkServiceEnabled()) {
EXPECT_EQ(1, on_resource_redirect_ct_);
} else {
if (mode_ == REDIRECT_RESOURCE_REDIRECT) {
// This seems like a bug in the old network implementation.
EXPECT_EQ(2, on_resource_redirect_ct_);
} else {
EXPECT_EQ(1, on_resource_redirect_ct_);
}
}
if (IsNetworkServiceEnabled()) {
// Unhandled requests won't see a call to GetResourceResponseFilter.
if (unhandled_)
EXPECT_EQ(0, get_resource_response_filter_ct_);
else
EXPECT_EQ(1, get_resource_response_filter_ct_);
} else {
if (mode_ == REDIRECT_RESOURCE_RESPONSE)
EXPECT_EQ(2, get_resource_response_filter_ct_);
else
EXPECT_EQ(1, get_resource_response_filter_ct_);
}
// Unhandled requests won't see a call to OnResourceResponse. // Unhandled requests won't see a call to OnResourceResponse.
if (mode_ == REDIRECT_RESOURCE_RESPONSE) { if (mode_ == REDIRECT_RESOURCE_RESPONSE) {
// In this case we're redirecting from inside OnResourceResponse. // In this case we're redirecting from inside OnResourceResponse.
if (unhandled_) if (unhandled_) {
EXPECT_EQ(1, on_resource_response_ct_); EXPECT_EQ(1, on_resource_response_ct_);
else } else {
EXPECT_EQ(2, on_resource_response_ct_); EXPECT_EQ(2, on_resource_response_ct_);
}
} else { } else {
if (unhandled_) if (unhandled_) {
EXPECT_EQ(0, on_resource_response_ct_); EXPECT_EQ(0, on_resource_response_ct_);
else } else {
EXPECT_EQ(1, on_resource_response_ct_); EXPECT_EQ(1, on_resource_response_ct_);
}
} }
} else if (IsIncomplete()) { } else if (IsIncomplete()) {
EXPECT_EQ(1, on_before_browse_ct_); EXPECT_EQ(1, on_before_browse_ct_);
if (IsNetworkServiceEnabled()) { EXPECT_EQ(1, get_resource_request_handler_ct_);
EXPECT_EQ(1, get_resource_request_handler_ct_); EXPECT_EQ(1, get_cookie_access_filter_ct_);
EXPECT_EQ(1, get_cookie_access_filter_ct_);
}
EXPECT_EQ(1, on_before_resource_load_ct_); EXPECT_EQ(1, on_before_resource_load_ct_);
if (IsIncompleteRequestHandler()) if (IsIncompleteRequestHandler()) {
EXPECT_EQ(1, get_resource_handler_ct_); EXPECT_EQ(1, get_resource_handler_ct_);
else } else {
EXPECT_EQ(0, get_resource_handler_ct_); EXPECT_EQ(0, get_resource_handler_ct_);
}
EXPECT_EQ(0, on_resource_redirect_ct_); EXPECT_EQ(0, on_resource_redirect_ct_);
@ -712,20 +660,23 @@ class BasicResponseTest : public TestHandler {
EXPECT_EQ(resource_handler_created_ct_, resource_handler_destroyed_ct_); EXPECT_EQ(resource_handler_created_ct_, resource_handler_destroyed_ct_);
if (IsAborted()) if (IsAborted()) {
EXPECT_EQ(0, on_resource_load_complete_ct_); EXPECT_EQ(0, on_resource_load_complete_ct_);
else } else {
EXPECT_EQ(1, on_resource_load_complete_ct_); EXPECT_EQ(1, on_resource_load_complete_ct_);
}
if (IsIncomplete() || IsAborted()) if (IsIncomplete() || IsAborted()) {
EXPECT_EQ(0, on_load_end_ct_); EXPECT_EQ(0, on_load_end_ct_);
else } else {
EXPECT_EQ(1, on_load_end_ct_); EXPECT_EQ(1, on_load_end_ct_);
}
if (custom_scheme_ && unhandled_ && !(IsIncomplete() || IsAborted())) if (custom_scheme_ && unhandled_ && !(IsIncomplete() || IsAborted())) {
EXPECT_EQ(1, on_protocol_execution_ct_); EXPECT_EQ(1, on_protocol_execution_ct_);
else } else {
EXPECT_EQ(0, on_protocol_execution_ct_); EXPECT_EQ(0, on_protocol_execution_ct_);
}
TestHandler::DestroyTest(); TestHandler::DestroyTest();
@ -900,7 +851,7 @@ class BasicResponseTest : public TestHandler {
// Browser-side navigation no longer exposes the actual request // Browser-side navigation no longer exposes the actual request
// information. // information.
EXPECT_EQ(0U, request->GetIdentifier()) << callback; EXPECT_EQ(0U, request->GetIdentifier()) << callback;
} else if (IsNetworkServiceEnabled()) { } else {
// All resource-related callbacks share the same request ID. // All resource-related callbacks share the same request ID.
EXPECT_EQ(request_id_, request->GetIdentifier()) << callback; EXPECT_EQ(request_id_, request->GetIdentifier()) << callback;
} }
@ -1080,41 +1031,14 @@ class BasicResponseTest : public TestHandler {
IMPLEMENT_REFCOUNTING(BasicResponseTest); IMPLEMENT_REFCOUNTING(BasicResponseTest);
}; };
bool IsTestSupported(BasicResponseTest::TestMode test_mode,
bool custom_scheme,
bool unhandled) {
if (!IsNetworkServiceEnabled()) {
if (custom_scheme || unhandled) {
// The old network implementation does not support the same functionality
// for custom schemes and unhandled requests.
return false;
}
if (test_mode == BasicResponseTest::ABORT_AFTER_CREATED ||
test_mode == BasicResponseTest::ABORT_BEFORE_BROWSE ||
test_mode == BasicResponseTest::INCOMPLETE_BEFORE_RESOURCE_LOAD ||
test_mode ==
BasicResponseTest::INCOMPLETE_REQUEST_HANDLER_PROCESS_REQUEST ||
test_mode ==
BasicResponseTest::INCOMPLETE_REQUEST_HANDLER_READ_RESPONSE) {
// The old network implementation does not support the same behavior
// for canceling incomplete requests.
return false;
}
}
return true;
}
} // namespace } // namespace
#define BASIC_TEST(name, test_mode, custom, unhandled) \ #define BASIC_TEST(name, test_mode, custom, unhandled) \
TEST(ResourceRequestHandlerTest, Basic##name) { \ TEST(ResourceRequestHandlerTest, Basic##name) { \
if (!IsTestSupported(BasicResponseTest::test_mode, custom, unhandled)) { \ CefRefPtr<BasicResponseTest> handler = new BasicResponseTest( \
return; \ BasicResponseTest::test_mode, custom, unhandled); \
} \ handler->ExecuteTest(); \
CefRefPtr<BasicResponseTest> handler = new BasicResponseTest( \ ReleaseAndWaitForDestructor(handler); \
BasicResponseTest::test_mode, custom, unhandled); \
handler->ExecuteTest(); \
ReleaseAndWaitForDestructor(handler); \
} }
#define BASIC_TEST_ALL_MODES(name, custom, unhandled) \ #define BASIC_TEST_ALL_MODES(name, custom, unhandled) \
@ -1277,7 +1201,7 @@ class SubresourceResponseTest : public RoutingTestHandler {
VerifyFrame(kGetResourceRequestHandler, frame); VerifyFrame(kGetResourceRequestHandler, frame);
if (IsNetworkServiceEnabled() && request_id_ == 0U) { if (request_id_ == 0U) {
// This is the first callback that provides a request ID. // This is the first callback that provides a request ID.
request_id_ = request->GetIdentifier(); request_id_ = request->GetIdentifier();
EXPECT_GT(request_id_, 0U); EXPECT_GT(request_id_, 0U);
@ -1476,9 +1400,7 @@ class SubresourceResponseTest : public RoutingTestHandler {
// Redirect again. // Redirect again.
new_url = GetURL(RESULT_JS); new_url = GetURL(RESULT_JS);
} else { } else {
DCHECK(!IsNetworkServiceEnabled()); NOTREACHED();
// The URL redirected to above.
EXPECT_STREQ(GetURL(RESULT_JS), new_url.ToString().c_str());
} }
} }
@ -1652,106 +1574,61 @@ class SubresourceResponseTest : public RoutingTestHandler {
} }
void DestroyTest() override { void DestroyTest() override {
if (!IsNetworkServiceEnabled()) { // Only called for the main and/or sub frame load.
// Called once for each other callback. if (subframe_) {
EXPECT_EQ(on_before_resource_load_ct_ + get_resource_handler_ct_ + EXPECT_EQ(2, on_before_browse_ct_);
on_resource_redirect_ct_ + on_resource_response_ct_ + } else {
get_resource_response_filter_ct_ + EXPECT_EQ(1, on_before_browse_ct_);
on_resource_load_complete_ct_,
get_resource_request_handler_ct_);
// Only called at the time we handle cookies.
EXPECT_EQ(0, get_cookie_access_filter_ct_);
} }
// Only called for the main and/or sub frame load.
if (subframe_)
EXPECT_EQ(2, on_before_browse_ct_);
else
EXPECT_EQ(1, on_before_browse_ct_);
if (mode_ == LOAD || mode_ == MODIFY_BEFORE_RESOURCE_LOAD) { if (mode_ == LOAD || mode_ == MODIFY_BEFORE_RESOURCE_LOAD) {
if (IsNetworkServiceEnabled()) { EXPECT_EQ(1, get_resource_request_handler_ct_);
EXPECT_EQ(1, get_resource_request_handler_ct_); EXPECT_EQ(1, get_cookie_access_filter_ct_);
EXPECT_EQ(1, get_cookie_access_filter_ct_);
}
EXPECT_EQ(1, on_before_resource_load_ct_); EXPECT_EQ(1, on_before_resource_load_ct_);
EXPECT_EQ(1, get_resource_handler_ct_); EXPECT_EQ(1, get_resource_handler_ct_);
EXPECT_EQ(0, on_resource_redirect_ct_); EXPECT_EQ(0, on_resource_redirect_ct_);
if (IsNetworkServiceEnabled()) { // Unhandled requests won't see a call to GetResourceResponseFilter or
// Unhandled requests won't see a call to GetResourceResponseFilter. // OnResourceResponse.
if (unhandled_) if (unhandled_) {
EXPECT_EQ(0, get_resource_response_filter_ct_); EXPECT_EQ(0, get_resource_response_filter_ct_);
else EXPECT_EQ(0, on_resource_response_ct_);
EXPECT_EQ(1, get_resource_response_filter_ct_);
} else { } else {
EXPECT_EQ(1, get_resource_response_filter_ct_); EXPECT_EQ(1, get_resource_response_filter_ct_);
}
// Unhandled requests won't see a call to OnResourceResponse.
if (unhandled_)
EXPECT_EQ(0, on_resource_response_ct_);
else
EXPECT_EQ(1, on_resource_response_ct_); EXPECT_EQ(1, on_resource_response_ct_);
}
} else if (mode_ == RESTART_RESOURCE_RESPONSE) { } else if (mode_ == RESTART_RESOURCE_RESPONSE) {
if (IsNetworkServiceEnabled()) { EXPECT_EQ(2, get_resource_request_handler_ct_);
EXPECT_EQ(2, get_resource_request_handler_ct_); EXPECT_EQ(2, get_cookie_access_filter_ct_);
} EXPECT_EQ(2, on_before_resource_load_ct_);
if (IsNetworkServiceEnabled()) {
EXPECT_EQ(2, get_cookie_access_filter_ct_);
EXPECT_EQ(2, on_before_resource_load_ct_);
} else {
// This seems like a bug in the old network implementation.
EXPECT_EQ(1, on_before_resource_load_ct_);
}
EXPECT_EQ(2, get_resource_handler_ct_); EXPECT_EQ(2, get_resource_handler_ct_);
EXPECT_EQ(0, on_resource_redirect_ct_); EXPECT_EQ(0, on_resource_redirect_ct_);
if (IsNetworkServiceEnabled()) { // Unhandled requests won't see a call to GetResourceResponseFilter or
// Unhandled requests won't see a call to GetResourceResponseFilter. // OnResourceResponse. In this case we're restarting from inside
if (unhandled_) // OnResourceResponse.
EXPECT_EQ(0, get_resource_response_filter_ct_); if (unhandled_) {
else EXPECT_EQ(0, get_resource_response_filter_ct_);
EXPECT_EQ(1, get_resource_response_filter_ct_);
} else {
EXPECT_EQ(2, get_resource_response_filter_ct_);
}
// Unhandled requests won't see a call to OnResourceResponse.
// In this case we're restarting from inside OnResourceResponse.
if (unhandled_)
EXPECT_EQ(1, on_resource_response_ct_); EXPECT_EQ(1, on_resource_response_ct_);
else } else {
EXPECT_EQ(1, get_resource_response_filter_ct_);
EXPECT_EQ(2, on_resource_response_ct_); EXPECT_EQ(2, on_resource_response_ct_);
}
} else if (IsRedirect()) { } else if (IsRedirect()) {
if (IsNetworkServiceEnabled()) { EXPECT_EQ(2, get_resource_request_handler_ct_);
EXPECT_EQ(2, get_resource_request_handler_ct_); EXPECT_EQ(2, get_cookie_access_filter_ct_);
EXPECT_EQ(2, get_cookie_access_filter_ct_);
}
EXPECT_EQ(2, on_before_resource_load_ct_); EXPECT_EQ(2, on_before_resource_load_ct_);
if (mode_ == REDIRECT_BEFORE_RESOURCE_LOAD) if (mode_ == REDIRECT_BEFORE_RESOURCE_LOAD) {
EXPECT_EQ(1, get_resource_handler_ct_); EXPECT_EQ(1, get_resource_handler_ct_);
else } else {
EXPECT_EQ(2, get_resource_handler_ct_); EXPECT_EQ(2, get_resource_handler_ct_);
if (IsNetworkServiceEnabled()) {
EXPECT_EQ(1, on_resource_redirect_ct_);
} else {
if (mode_ == REDIRECT_RESOURCE_REDIRECT) {
// This seems like a bug in the old network implementation.
EXPECT_EQ(2, on_resource_redirect_ct_);
} else {
EXPECT_EQ(1, on_resource_redirect_ct_);
}
}
if (IsNetworkServiceEnabled()) {
// Unhandled requests won't see a call to GetResourceResponseFilter.
if (unhandled_)
EXPECT_EQ(0, get_resource_response_filter_ct_);
else
EXPECT_EQ(1, get_resource_response_filter_ct_);
} else {
if (mode_ == REDIRECT_RESOURCE_RESPONSE)
EXPECT_EQ(2, get_resource_response_filter_ct_);
else
EXPECT_EQ(1, get_resource_response_filter_ct_);
} }
EXPECT_EQ(1, on_resource_redirect_ct_);
// Unhandled requests won't see a call to GetResourceResponseFilter.
if (unhandled_)
EXPECT_EQ(0, get_resource_response_filter_ct_);
else
EXPECT_EQ(1, get_resource_response_filter_ct_);
// Unhandled requests won't see a call to OnResourceResponse. // Unhandled requests won't see a call to OnResourceResponse.
if (mode_ == REDIRECT_RESOURCE_RESPONSE) { if (mode_ == REDIRECT_RESOURCE_RESPONSE) {
// In this case we're redirecting from inside OnResourceResponse. // In this case we're redirecting from inside OnResourceResponse.
@ -1766,16 +1643,15 @@ class SubresourceResponseTest : public RoutingTestHandler {
EXPECT_EQ(1, on_resource_response_ct_); EXPECT_EQ(1, on_resource_response_ct_);
} }
} else if (IsIncomplete()) { } else if (IsIncomplete()) {
if (IsNetworkServiceEnabled()) { EXPECT_EQ(1, get_resource_request_handler_ct_);
EXPECT_EQ(1, get_resource_request_handler_ct_); EXPECT_EQ(1, get_cookie_access_filter_ct_);
EXPECT_EQ(1, get_cookie_access_filter_ct_);
}
EXPECT_EQ(1, on_before_resource_load_ct_); EXPECT_EQ(1, on_before_resource_load_ct_);
if (IsIncompleteRequestHandler()) if (IsIncompleteRequestHandler()) {
EXPECT_EQ(1, get_resource_handler_ct_); EXPECT_EQ(1, get_resource_handler_ct_);
else } else {
EXPECT_EQ(0, get_resource_handler_ct_); EXPECT_EQ(0, get_resource_handler_ct_);
}
EXPECT_EQ(0, on_resource_redirect_ct_); EXPECT_EQ(0, on_resource_redirect_ct_);
@ -1797,21 +1673,24 @@ class SubresourceResponseTest : public RoutingTestHandler {
if (IsIncomplete()) { if (IsIncomplete()) {
EXPECT_EQ(0, on_load_end_ct_); EXPECT_EQ(0, on_load_end_ct_);
} else { } else {
if (subframe_) if (subframe_) {
EXPECT_EQ(2, on_load_end_ct_); EXPECT_EQ(2, on_load_end_ct_);
else } else {
EXPECT_EQ(1, on_load_end_ct_); EXPECT_EQ(1, on_load_end_ct_);
}
} }
if (unhandled_ || IsIncomplete()) if (unhandled_ || IsIncomplete()) {
EXPECT_EQ(0, on_query_ct_); EXPECT_EQ(0, on_query_ct_);
else } else {
EXPECT_EQ(1, on_query_ct_); EXPECT_EQ(1, on_query_ct_);
}
if (custom_scheme_ && unhandled_ && !IsIncomplete()) if (custom_scheme_ && unhandled_ && !IsIncomplete()) {
EXPECT_EQ(1, on_protocol_execution_ct_); EXPECT_EQ(1, on_protocol_execution_ct_);
else } else {
EXPECT_EQ(0, on_protocol_execution_ct_); EXPECT_EQ(0, on_protocol_execution_ct_);
}
TestHandler::DestroyTest(); TestHandler::DestroyTest();
@ -2047,11 +1926,7 @@ class SubresourceResponseTest : public RoutingTestHandler {
else else
EXPECT_TRUE(frame->IsMain()) << callback; EXPECT_TRUE(frame->IsMain()) << callback;
// This is sometimes -4 (kInvalidFrameId) with the old network EXPECT_EQ(frame_id_, frame->GetIdentifier()) << callback;
// implementation.
if (IsNetworkServiceEnabled()) {
EXPECT_EQ(frame_id_, frame->GetIdentifier()) << callback;
}
} }
void VerifyState(Callback callback, void VerifyState(Callback callback,
@ -2072,10 +1947,8 @@ class SubresourceResponseTest : public RoutingTestHandler {
EXPECT_TRUE(request->IsReadOnly()) << callback; EXPECT_TRUE(request->IsReadOnly()) << callback;
} }
if (IsNetworkServiceEnabled()) { // All resource-related callbacks share the same request ID.
// All resource-related callbacks share the same request ID. EXPECT_EQ(request_id_, request->GetIdentifier()) << callback;
EXPECT_EQ(request_id_, request->GetIdentifier()) << callback;
}
if (IsLoad() || IsIncomplete()) { if (IsLoad() || IsIncomplete()) {
EXPECT_STREQ("GET", request->GetMethod().ToString().c_str()) << callback; EXPECT_STREQ("GET", request->GetMethod().ToString().c_str()) << callback;
@ -2106,16 +1979,8 @@ class SubresourceResponseTest : public RoutingTestHandler {
<< callback; << callback;
} else { } else {
// After the redirect. // After the redirect.
if (!IsNetworkServiceEnabled() && mode_ == REDIRECT_RESOURCE_REDIRECT) { EXPECT_STREQ(GetURL(RESULT_JS), request->GetURL().ToString().c_str())
// With the old network stack we don't have a good signal to know when << callback;
// the final redirect has occurred.
const std::string& url = request->GetURL().ToString();
EXPECT_TRUE(url == GetURL(REDIRECT2_JS) || url == GetURL(RESULT_JS))
<< callback;
} else {
EXPECT_STREQ(GetURL(RESULT_JS), request->GetURL().ToString().c_str())
<< callback;
}
} }
if (response) { if (response) {
@ -2265,37 +2130,10 @@ class SubresourceResponseTest : public RoutingTestHandler {
IMPLEMENT_REFCOUNTING(SubresourceResponseTest); IMPLEMENT_REFCOUNTING(SubresourceResponseTest);
}; };
bool IsTestSupported(SubresourceResponseTest::TestMode test_mode,
bool custom_scheme,
bool unhandled,
bool subframe) {
if (!IsNetworkServiceEnabled()) {
if (custom_scheme || unhandled) {
// The old network implementation does not support the same functionality
// for custom schemes and unhandled requests.
return false;
}
if (test_mode == SubresourceResponseTest::INCOMPLETE_BEFORE_RESOURCE_LOAD ||
test_mode == SubresourceResponseTest::
INCOMPLETE_REQUEST_HANDLER_PROCESS_REQUEST ||
test_mode ==
SubresourceResponseTest::INCOMPLETE_REQUEST_HANDLER_READ_RESPONSE) {
// The old network implementation does not support the same behavior
// for canceling incomplete requests.
return false;
}
}
return true;
}
} // namespace } // namespace
#define SUBRESOURCE_TEST(name, test_mode, custom, unhandled, subframe) \ #define SUBRESOURCE_TEST(name, test_mode, custom, unhandled, subframe) \
TEST(ResourceRequestHandlerTest, Subresource##name) { \ TEST(ResourceRequestHandlerTest, Subresource##name) { \
if (!IsTestSupported(SubresourceResponseTest::test_mode, custom, \
unhandled, subframe)) { \
return; \
} \
CefRefPtr<SubresourceResponseTest> handler = new SubresourceResponseTest( \ CefRefPtr<SubresourceResponseTest> handler = new SubresourceResponseTest( \
SubresourceResponseTest::test_mode, custom, unhandled, subframe); \ SubresourceResponseTest::test_mode, custom, unhandled, subframe); \
handler->ExecuteTest(); \ handler->ExecuteTest(); \
@ -2552,13 +2390,8 @@ class RedirectResponseTest : public TestHandler {
EXPECT_EQ(expected_resource_response_ct_, resource_response_ct_); EXPECT_EQ(expected_resource_response_ct_, resource_response_ct_);
EXPECT_EQ(expected_resource_response_ct_, get_resource_handler_ct_); EXPECT_EQ(expected_resource_response_ct_, get_resource_handler_ct_);
if (IsNetworkServiceEnabled()) { EXPECT_EQ(expected_resource_load_complete_ct_,
EXPECT_EQ(expected_resource_load_complete_ct_, get_resource_response_filter_ct_);
get_resource_response_filter_ct_);
} else {
EXPECT_EQ(expected_resource_response_ct_,
get_resource_response_filter_ct_);
}
EXPECT_EQ(expected_before_resource_load_ct_, before_resource_load_ct_); EXPECT_EQ(expected_before_resource_load_ct_, before_resource_load_ct_);
EXPECT_EQ(expected_resource_redirect_ct_, resource_redirect_ct_); EXPECT_EQ(expected_resource_redirect_ct_, resource_redirect_ct_);
EXPECT_EQ(expected_resource_load_complete_ct_, EXPECT_EQ(expected_resource_load_complete_ct_,
@ -2603,10 +2436,7 @@ class RedirectResponseTest : public TestHandler {
// With NetworkService we don't get an additional (unnecessary) redirect // With NetworkService we don't get an additional (unnecessary) redirect
// callback. // callback.
UrlResourceTest() UrlResourceTest()
: ResourceTest("http://test.com/start_url.js", : ResourceTest("http://test.com/start_url.js", 2U, 2U, 1U) {
IsNetworkServiceEnabled() ? 2U : 3U,
2U,
1U) {
redirect_url_ = "http://test.com/redirect_url.js"; redirect_url_ = "http://test.com/redirect_url.js";
} }
@ -2653,9 +2483,7 @@ class RedirectResponseTest : public TestHandler {
// With NetworkService we restart the request, so we get another call to // With NetworkService we restart the request, so we get another call to
// OnBeforeResourceLoad. // OnBeforeResourceLoad.
HeaderResourceTest() HeaderResourceTest()
: ResourceTest("http://test.com/start_header.js", : ResourceTest("http://test.com/start_header.js", 2U, 2U) {
2U,
IsNetworkServiceEnabled() ? 2U : 1U) {
expected_headers_.insert(std::make_pair("Test-Key1", "Value1")); expected_headers_.insert(std::make_pair("Test-Key1", "Value1"));
expected_headers_.insert(std::make_pair("Test-Key2", "Value2")); expected_headers_.insert(std::make_pair("Test-Key2", "Value2"));
} }
@ -2686,10 +2514,7 @@ class RedirectResponseTest : public TestHandler {
public: public:
// With NetworkService we restart the request, so we get another call to // With NetworkService we restart the request, so we get another call to
// OnBeforeResourceLoad. // OnBeforeResourceLoad.
PostResourceTest() PostResourceTest() : ResourceTest("http://test.com/start_post.js", 2U, 2U) {
: ResourceTest("http://test.com/start_post.js",
2U,
IsNetworkServiceEnabled() ? 2U : 1U) {
CefRefPtr<CefPostDataElement> elem = CefPostDataElement::Create(); CefRefPtr<CefPostDataElement> elem = CefPostDataElement::Create();
const std::string data("Test Post Data"); const std::string data("Test Post Data");
elem->SetToBytes(data.size(), data.c_str()); elem->SetToBytes(data.size(), data.c_str());
@ -3118,14 +2943,9 @@ namespace {
const char kResponseFilterTestUrl[] = "http://tests.com/response_filter.html"; const char kResponseFilterTestUrl[] = "http://tests.com/response_filter.html";
size_t GetResponseBufferSize() { size_t GetResponseBufferSize() {
if (IsNetworkServiceEnabled()) { // Match the default |capacity_num_bytes| value from
// Match the default |capacity_num_bytes| value from // mojo::Core::CreateDataPipe.
// mojo::Core::CreateDataPipe. return 64 * 1024; // 64kb
return 64 * 1024; // 64kb
} else {
// Match |kBufferSize| from net/filter/filter_source_stream.cc.
return 32 * 1024; // 32kb
}
} }
const char kInputHeader[] = "<html><head></head><body>"; const char kInputHeader[] = "<html><head></head><body>";

View File

@ -259,8 +259,7 @@ class ClientSchemeHandler : public CefResourceHandler {
// CEF_SETTINGS_ACCEPT_LANGUAGE value from // CEF_SETTINGS_ACCEPT_LANGUAGE value from
// CefSettings.accept_language_list set in CefTestSuite::GetSettings() // CefSettings.accept_language_list set in CefTestSuite::GetSettings()
// and expanded internally by ComputeAcceptLanguageFromPref. // and expanded internally by ComputeAcceptLanguageFromPref.
EXPECT_STREQ(IsNetworkServiceEnabled() ? "en-GB,en;q=0.9" : "en-GB", EXPECT_STREQ("en-GB,en;q=0.9", accept_language.data());
accept_language.data());
} }
if (handled) { if (handled) {
@ -808,8 +807,7 @@ TEST(SchemeHandlerTest, CustomNonStandardNameNotHandled) {
TEST(SchemeHandlerTest, CustomStandardDomainNotHandled) { TEST(SchemeHandlerTest, CustomStandardDomainNotHandled) {
RegisterTestScheme("customstd", "test"); RegisterTestScheme("customstd", "test");
g_TestResults.url = "customstd://noexist/run.html"; g_TestResults.url = "customstd://noexist/run.html";
g_TestResults.expected_error_code = g_TestResults.expected_error_code = ERR_UNKNOWN_URL_SCHEME;
IsNetworkServiceEnabled() ? ERR_UNKNOWN_URL_SCHEME : ERR_FAILED;
CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&g_TestResults); CefRefPtr<TestSchemeHandler> handler = new TestSchemeHandler(&g_TestResults);
handler->ExecuteTest(); handler->ExecuteTest();
@ -1904,10 +1902,7 @@ TEST(SchemeHandlerTest,
} }
// Test that a custom standard scheme can generate cross-domain XHR requests // Test that a custom standard scheme can generate cross-domain XHR requests
// that perform redirects when using the cross-origin whitelist. This is // that perform redirects when using the cross-origin whitelist.
// because we add an "Access-Control-Allow-Origin" header internally in
// CefResourceDispatcherHostDelegate::OnRequestRedirected() for the redirect
// request.
TEST(SchemeHandlerTest, TEST(SchemeHandlerTest,
CustomStandardXHRDifferentOriginRedirectWithWhitelistAsync1) { CustomStandardXHRDifferentOriginRedirectWithWhitelistAsync1) {
RegisterTestScheme("customstd", "test1"); RegisterTestScheme("customstd", "test1");
@ -2013,10 +2008,7 @@ TEST(SchemeHandlerTest,
} }
// Test that a custom standard scheme can generate cross-domain Fetch requests // Test that a custom standard scheme can generate cross-domain Fetch requests
// that perform redirects when using the cross-origin whitelist. This is // that perform redirects when using the cross-origin whitelist.
// because we add an "Access-Control-Allow-Origin" header internally in
// CefResourceDispatcherHostDelegate::OnRequestRedirected() for the redirect
// request.
TEST(SchemeHandlerTest, TEST(SchemeHandlerTest,
CustomStandardFetchDifferentOriginRedirectWithWhitelist1) { CustomStandardFetchDifferentOriginRedirectWithWhitelist1) {
RegisterTestScheme("customstdfetch", "test1"); RegisterTestScheme("customstdfetch", "test1");

View File

@ -3,7 +3,6 @@
// can be found in the LICENSE file. // can be found in the LICENSE file.
#include "tests/ceftests/test_util.h" #include "tests/ceftests/test_util.h"
#include "include/cef_command_line.h"
#include "include/cef_request_context_handler.h" #include "include/cef_request_context_handler.h"
#include "tests/gtest/include/gtest/gtest.h" #include "tests/gtest/include/gtest/gtest.h"
@ -267,17 +266,6 @@ void TestStringVectorEqual(const std::vector<CefString>& val1,
EXPECT_STREQ(val1[i].ToString().c_str(), val2[i].ToString().c_str()); EXPECT_STREQ(val1[i].ToString().c_str(), val2[i].ToString().c_str());
} }
bool IsNetworkServiceEnabled() {
static int state = -1;
if (state == -1) {
CefRefPtr<CefCommandLine> command_line =
CefCommandLine::GetGlobalCommandLine();
const std::string& value = command_line->GetSwitchValue("disable-features");
state = value.find("NetworkService") == std::string::npos ? 1 : 0;
}
return state ? true : false;
}
CefRefPtr<CefRequestContext> CreateTestRequestContext( CefRefPtr<CefRequestContext> CreateTestRequestContext(
TestRequestContextMode mode, TestRequestContextMode mode,
const std::string& cache_path) { const std::string& cache_path) {

View File

@ -65,9 +65,6 @@ void TestProcessMessageEqual(CefRefPtr<CefProcessMessage> val1,
void TestStringVectorEqual(const std::vector<CefString>& val1, void TestStringVectorEqual(const std::vector<CefString>& val1,
const std::vector<CefString>& val2); const std::vector<CefString>& val2);
// Returns true if the NetworkService is enabled.
bool IsNetworkServiceEnabled();
enum TestRequestContextMode { enum TestRequestContextMode {
TEST_RC_MODE_NONE, TEST_RC_MODE_NONE,
TEST_RC_MODE_GLOBAL, TEST_RC_MODE_GLOBAL,

View File

@ -455,7 +455,7 @@ void VerifyNormalRequest(const RequestRunSettings* settings,
// CEF_SETTINGS_ACCEPT_LANGUAGE value from CefSettings.accept_language_list // CEF_SETTINGS_ACCEPT_LANGUAGE value from CefSettings.accept_language_list
// set in CefTestSuite::GetSettings() and expanded internally by // set in CefTestSuite::GetSettings() and expanded internally by
// ComputeAcceptLanguageFromPref. // ComputeAcceptLanguageFromPref.
EXPECT_STREQ(IsNetworkServiceEnabled() ? "en-GB,en;q=0.9" : "en-GB", EXPECT_STREQ("en-GB,en;q=0.9",
GetHeaderValue(headerMap, "accept-language").c_str()); GetHeaderValue(headerMap, "accept-language").c_str());
if (server_backend) { if (server_backend) {
@ -553,10 +553,7 @@ class RequestSchemeHandler : public CefResourceHandler {
: settings_(settings), destroy_callback_(destroy_callback) {} : settings_(settings), destroy_callback_(destroy_callback) {}
~RequestSchemeHandler() override { ~RequestSchemeHandler() override {
if (IsNetworkServiceEnabled()) { EXPECT_EQ(1, cancel_ct_);
EXPECT_EQ(1, cancel_ct_);
}
destroy_callback_.Run(); destroy_callback_.Run();
} }
@ -636,10 +633,7 @@ class RequestRedirectSchemeHandler : public CefResourceHandler {
destroy_callback_(destroy_callback) {} destroy_callback_(destroy_callback) {}
~RequestRedirectSchemeHandler() override { ~RequestRedirectSchemeHandler() override {
if (IsNetworkServiceEnabled()) { EXPECT_EQ(1, cancel_ct_);
EXPECT_EQ(1, cancel_ct_);
}
destroy_callback_.Run(); destroy_callback_.Run();
} }
@ -707,11 +701,7 @@ class IncompleteSchemeHandler : public CefResourceHandler {
~IncompleteSchemeHandler() override { ~IncompleteSchemeHandler() override {
EXPECT_EQ(1, process_request_ct_); EXPECT_EQ(1, process_request_ct_);
EXPECT_EQ(1, cancel_ct_);
if (IsNetworkServiceEnabled())
EXPECT_EQ(1, cancel_ct_);
else
EXPECT_EQ(0, cancel_ct_);
if (settings_->incomplete_type == if (settings_->incomplete_type ==
RequestRunSettings::INCOMPLETE_READ_RESPONSE) { RequestRunSettings::INCOMPLETE_READ_RESPONSE) {
@ -1558,7 +1548,7 @@ class RequestTestRunner : public base::RefCountedThreadSafe<RequestTestRunner> {
// on stop redirects. // on stop redirects.
settings_.response = CefResponse::Create(); settings_.response = CefResponse::Create();
settings_.response->SetStatus(302); settings_.response->SetStatus(302);
if (IsNetworkServiceEnabled() && is_browser_process_) { if (is_browser_process_) {
settings_.response->SetStatusText("Found"); settings_.response->SetStatusText("Found");
} }
@ -2174,10 +2164,8 @@ class RequestTestRunner : public base::RefCountedThreadSafe<RequestTestRunner> {
CefRefPtr<RequestClient> client = new RequestClient(complete_callback); CefRefPtr<RequestClient> client = new RequestClient(complete_callback);
// Delegation to CefRequestHandler::GetAuthCredentials is only supported // Not delegating to CefRequestHandler::GetAuthCredentials.
// with NetworkService. if (!use_frame_method_ && settings_.expect_authentication) {
if ((!IsNetworkServiceEnabled() || !use_frame_method_) &&
settings_.expect_authentication) {
client->has_authentication_ = true; client->has_authentication_ = true;
client->username_ = settings_.username; client->username_ = settings_.username;
client->password_ = settings_.password; client->password_ = settings_.password;
@ -2891,18 +2879,16 @@ class RequestTestHandler : public TestHandler {
EXPECT_TRUE(got_success_); EXPECT_TRUE(got_success_);
} }
if (IsNetworkServiceEnabled()) { if (test_frame_method_) {
if (test_frame_method_) { // Expect at least 1 call to OnBeforeResourceLoad for every test.
// Expect at least 1 call to OnBeforeResourceLoad for every test. // Redirect tests may get multiple calls.
// Redirect tests may get multiple calls. EXPECT_LE(1, test_frame_resource_load_ct_);
EXPECT_LE(1, test_frame_resource_load_ct_);
}
} }
// CefRequestHandler::GetAuthCredentials should be called after // CefRequestHandler::GetAuthCredentials should be called after
// CefURLRequestClient::GetAuthCredentials when the request has an // CefURLRequestClient::GetAuthCredentials when the request has an
// associated frame. // associated frame.
if (IsNetworkServiceEnabled() && test_in_browser_ && test_frame_method_ && if (test_in_browser_ && test_frame_method_ &&
test_runner_->settings_.expect_authentication) { test_runner_->settings_.expect_authentication) {
EXPECT_EQ(1, auth_credentials_ct_); EXPECT_EQ(1, auth_credentials_ct_);
} else { } else {
@ -3011,20 +2997,10 @@ bool IsTestSupported(RequestTestMode test_mode,
bool test_in_browser, bool test_in_browser,
bool test_server_backend, bool test_server_backend,
bool test_frame_method) { bool test_frame_method) {
if (IsNetworkServiceEnabled()) { if (!test_in_browser && !test_server_backend && !test_frame_method) {
if (!test_in_browser && !test_server_backend && !test_frame_method) { // Requests from the render process can only reach non-server backends when
// When NetworkService is enabled requests from the render process can // using the CefFrame::CreateURLRequest method.
// only reach non-server backends when using the return false;
// CefFrame::CreateURLRequest method.
return false;
}
} else {
if (test_mode == REQTEST_INCOMPLETE_PROCESS_REQUEST ||
test_mode == REQTEST_INCOMPLETE_READ_RESPONSE) {
// The old network implementation does not support the same behavior
// for canceling incomplete requests.
return false;
}
} }
return true; return true;
@ -3251,9 +3227,7 @@ class InvalidURLTestClient : public CefURLRequestClient {
void OnRequestComplete(CefRefPtr<CefURLRequest> client) override { void OnRequestComplete(CefRefPtr<CefURLRequest> client) override {
EXPECT_EQ(UR_FAILED, client->GetRequestStatus()); EXPECT_EQ(UR_FAILED, client->GetRequestStatus());
if (IsNetworkServiceEnabled()) { EXPECT_EQ(ERR_UNKNOWN_URL_SCHEME, client->GetRequestError());
EXPECT_EQ(ERR_UNKNOWN_URL_SCHEME, client->GetRequestError());
}
// Let the call stack unwind before signaling completion. // Let the call stack unwind before signaling completion.
CefPostTask(TID_UI, CefPostTask(TID_UI,