Commit 94388f79 authored by mkwst's avatar mkwst Committed by Commit bot

Content Shell: Introduce LayoutTestURLRequestContextGetter.

This patch moves the DRT-specific bits of ShellURLRequestContextGetter
out into a layout-test-only subclass.

BUG=420994

Review URL: https://codereview.chromium.org/651883002

Cr-Commit-Position: refs/heads/master@{#299864}
parent 1c493cf5
...@@ -104,6 +104,8 @@ ...@@ -104,6 +104,8 @@
'shell/browser/layout_test/layout_test_javascript_dialog_manager.h', 'shell/browser/layout_test/layout_test_javascript_dialog_manager.h',
'shell/browser/layout_test/layout_test_resource_dispatcher_host_delegate.cc', 'shell/browser/layout_test/layout_test_resource_dispatcher_host_delegate.cc',
'shell/browser/layout_test/layout_test_resource_dispatcher_host_delegate.h', 'shell/browser/layout_test/layout_test_resource_dispatcher_host_delegate.h',
'shell/browser/layout_test/layout_test_url_request_context_getter.cc',
'shell/browser/layout_test/layout_test_url_request_context_getter.h',
'shell/browser/notify_done_forwarder.cc', 'shell/browser/notify_done_forwarder.cc',
'shell/browser/notify_done_forwarder.h', 'shell/browser/notify_done_forwarder.h',
'shell/browser/shell_android.cc', 'shell/browser/shell_android.cc',
......
...@@ -45,14 +45,16 @@ static_library("content_shell_lib") { ...@@ -45,14 +45,16 @@ static_library("content_shell_lib") {
"browser/layout_test/layout_test_browser_context.h", "browser/layout_test/layout_test_browser_context.h",
"browser/layout_test/layout_test_browser_main_parts.cc", "browser/layout_test/layout_test_browser_main_parts.cc",
"browser/layout_test/layout_test_browser_main_parts.h", "browser/layout_test/layout_test_browser_main_parts.h",
"browser/layout_test/layout_test_download_manager_delegate.cc",
"browser/layout_test/layout_test_download_manager_delegate.h",
"browser/layout_test/layout_test_devtools_frontend.cc", "browser/layout_test/layout_test_devtools_frontend.cc",
"browser/layout_test/layout_test_devtools_frontend.h", "browser/layout_test/layout_test_devtools_frontend.h",
"browser/layout_test/layout_test_download_manager_delegate.cc",
"browser/layout_test/layout_test_download_manager_delegate.h",
"browser/layout_test/layout_test_javascript_dialog_manager.cc", "browser/layout_test/layout_test_javascript_dialog_manager.cc",
"browser/layout_test/layout_test_javascript_dialog_manager.h", "browser/layout_test/layout_test_javascript_dialog_manager.h",
"browser/layout_test/layout_test_resource_dispatcher_host_delegate.cc", "browser/layout_test/layout_test_resource_dispatcher_host_delegate.cc",
"browser/layout_test/layout_test_resource_dispatcher_host_delegate.h", "browser/layout_test/layout_test_resource_dispatcher_host_delegate.h",
"browser/layout_test/layout_test_url_request_context_getter.cc",
"browser/layout_test/layout_test_url_request_context_getter.h",
"browser/notify_done_forwarder.cc", "browser/notify_done_forwarder.cc",
"browser/notify_done_forwarder.h", "browser/notify_done_forwarder.h",
"browser/shell_android.cc", "browser/shell_android.cc",
......
...@@ -9,8 +9,10 @@ ...@@ -9,8 +9,10 @@
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/resource_context.h" #include "content/public/browser/resource_context.h"
#include "content/shell/browser/layout_test/layout_test_download_manager_delegate.h" #include "content/shell/browser/layout_test/layout_test_download_manager_delegate.h"
#include "content/shell/browser/layout_test/layout_test_url_request_context_getter.h"
#include "content/shell/browser/shell_url_request_context_getter.h" #include "content/shell/browser/shell_url_request_context_getter.h"
#if defined(OS_WIN) #if defined(OS_WIN)
...@@ -32,6 +34,20 @@ LayoutTestBrowserContext::LayoutTestBrowserContext(bool off_the_record, ...@@ -32,6 +34,20 @@ LayoutTestBrowserContext::LayoutTestBrowserContext(bool off_the_record,
LayoutTestBrowserContext::~LayoutTestBrowserContext() { LayoutTestBrowserContext::~LayoutTestBrowserContext() {
} }
ShellURLRequestContextGetter*
LayoutTestBrowserContext::CreateURLRequestContextGetter(
ProtocolHandlerMap* protocol_handlers,
URLRequestInterceptorScopedVector request_interceptors) {
return new LayoutTestURLRequestContextGetter(
ignore_certificate_errors(),
GetPath(),
BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO),
BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE),
protocol_handlers,
request_interceptors.Pass(),
net_log());
}
DownloadManagerDelegate* DownloadManagerDelegate*
LayoutTestBrowserContext::GetDownloadManagerDelegate() { LayoutTestBrowserContext::GetDownloadManagerDelegate() {
if (!download_manager_delegate_.get()) { if (!download_manager_delegate_.get()) {
......
...@@ -24,6 +24,11 @@ class LayoutTestBrowserContext : public ShellBrowserContext { ...@@ -24,6 +24,11 @@ class LayoutTestBrowserContext : public ShellBrowserContext {
// BrowserContext implementation. // BrowserContext implementation.
virtual DownloadManagerDelegate* GetDownloadManagerDelegate() override; virtual DownloadManagerDelegate* GetDownloadManagerDelegate() override;
protected:
virtual ShellURLRequestContextGetter* CreateURLRequestContextGetter(
ProtocolHandlerMap* protocol_handlers,
URLRequestInterceptorScopedVector request_interceptors) override;
private: private:
DISALLOW_COPY_AND_ASSIGN(LayoutTestBrowserContext); DISALLOW_COPY_AND_ASSIGN(LayoutTestBrowserContext);
}; };
......
// Copyright 2013 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 "content/shell/browser/layout_test/layout_test_url_request_context_getter.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "content/public/browser/browser_thread.h"
#include "content/shell/browser/shell_network_delegate.h"
#include "net/proxy/proxy_service.h"
namespace content {
LayoutTestURLRequestContextGetter::LayoutTestURLRequestContextGetter(
bool ignore_certificate_errors,
const base::FilePath& base_path,
base::MessageLoop* io_loop,
base::MessageLoop* file_loop,
ProtocolHandlerMap* protocol_handlers,
URLRequestInterceptorScopedVector request_interceptors,
net::NetLog* net_log)
: ShellURLRequestContextGetter(ignore_certificate_errors,
base_path,
io_loop,
file_loop,
protocol_handlers,
request_interceptors.Pass(),
net_log) {
// Must first be created on the UI thread.
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
}
LayoutTestURLRequestContextGetter::~LayoutTestURLRequestContextGetter() {
}
net::NetworkDelegate*
LayoutTestURLRequestContextGetter::CreateNetworkDelegate() {
ShellNetworkDelegate::SetAcceptAllCookies(false);
return new ShellNetworkDelegate;
}
net::ProxyConfigService*
LayoutTestURLRequestContextGetter::GetProxyConfigService() {
return nullptr;
}
net::ProxyService* LayoutTestURLRequestContextGetter::GetProxyService() {
return net::ProxyService::CreateDirect();
}
} // namespace content
// Copyright 2013 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 CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_URL_REQUEST_CONTEXT_GETTER_H_
#define CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_URL_REQUEST_CONTEXT_GETTER_H_
#include "base/compiler_specific.h"
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "content/public/browser/content_browser_client.h"
#include "content/shell/browser/shell_url_request_context_getter.h"
#include "net/url_request/url_request_job_factory.h"
namespace base {
class MessageLoop;
}
namespace net {
class HostResolver;
class MappedHostResolver;
class NetworkDelegate;
class NetLog;
class ProxyConfigService;
class URLRequestContextStorage;
}
namespace content {
class LayoutTestURLRequestContextGetter : public ShellURLRequestContextGetter {
public:
LayoutTestURLRequestContextGetter(
bool ignore_certificate_errors,
const base::FilePath& base_path,
base::MessageLoop* io_loop,
base::MessageLoop* file_loop,
ProtocolHandlerMap* protocol_handlers,
URLRequestInterceptorScopedVector request_interceptors,
net::NetLog* net_log);
protected:
virtual ~LayoutTestURLRequestContextGetter();
// ShellURLRequestContextGetter implementation.
virtual net::NetworkDelegate* CreateNetworkDelegate() override;
virtual net::ProxyConfigService* GetProxyConfigService() override;
virtual net::ProxyService* GetProxyService() override;
private:
DISALLOW_COPY_AND_ASSIGN(LayoutTestURLRequestContextGetter);
};
} // namespace content
#endif // CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_URL_REQUEST_CONTEXT_GETTER_H_
...@@ -117,11 +117,11 @@ net::URLRequestContextGetter* ShellBrowserContext::GetRequestContext() { ...@@ -117,11 +117,11 @@ net::URLRequestContextGetter* ShellBrowserContext::GetRequestContext() {
return GetDefaultStoragePartition(this)->GetURLRequestContext(); return GetDefaultStoragePartition(this)->GetURLRequestContext();
} }
net::URLRequestContextGetter* ShellBrowserContext::CreateRequestContext( ShellURLRequestContextGetter*
ShellBrowserContext::CreateURLRequestContextGetter(
ProtocolHandlerMap* protocol_handlers, ProtocolHandlerMap* protocol_handlers,
URLRequestInterceptorScopedVector request_interceptors) { URLRequestInterceptorScopedVector request_interceptors) {
DCHECK(!url_request_getter_.get()); return new ShellURLRequestContextGetter(
url_request_getter_ = new ShellURLRequestContextGetter(
ignore_certificate_errors_, ignore_certificate_errors_,
GetPath(), GetPath(),
BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO), BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO),
...@@ -129,6 +129,14 @@ net::URLRequestContextGetter* ShellBrowserContext::CreateRequestContext( ...@@ -129,6 +129,14 @@ net::URLRequestContextGetter* ShellBrowserContext::CreateRequestContext(
protocol_handlers, protocol_handlers,
request_interceptors.Pass(), request_interceptors.Pass(),
net_log_); net_log_);
}
net::URLRequestContextGetter* ShellBrowserContext::CreateRequestContext(
ProtocolHandlerMap* protocol_handlers,
URLRequestInterceptorScopedVector request_interceptors) {
DCHECK(!url_request_getter_.get());
url_request_getter_ = CreateURLRequestContextGetter(
protocol_handlers, request_interceptors.Pass());
resource_context_->set_url_request_context_getter(url_request_getter_.get()); resource_context_->set_url_request_context_getter(url_request_getter_.get());
return url_request_getter_.get(); return url_request_getter_.get();
} }
......
...@@ -90,10 +90,16 @@ class ShellBrowserContext : public BrowserContext { ...@@ -90,10 +90,16 @@ class ShellBrowserContext : public BrowserContext {
// Used by ShellBrowserContext to initiate and set different types of // Used by ShellBrowserContext to initiate and set different types of
// URLRequestContextGetter. // URLRequestContextGetter.
virtual ShellURLRequestContextGetter* CreateURLRequestContextGetter(
ProtocolHandlerMap* protocol_handlers,
URLRequestInterceptorScopedVector request_interceptors);
void set_url_request_context_getter(ShellURLRequestContextGetter* getter) { void set_url_request_context_getter(ShellURLRequestContextGetter* getter) {
url_request_getter_ = getter; url_request_getter_ = getter;
} }
bool ignore_certificate_errors() const { return ignore_certificate_errors_; }
net::NetLog* net_log() const { return net_log_; }
scoped_ptr<ShellResourceContext> resource_context_; scoped_ptr<ShellResourceContext> resource_context_;
bool ignore_certificate_errors_; bool ignore_certificate_errors_;
scoped_ptr<ShellDownloadManagerDelegate> download_manager_delegate_; scoped_ptr<ShellDownloadManagerDelegate> download_manager_delegate_;
......
...@@ -81,11 +81,7 @@ ShellURLRequestContextGetter::ShellURLRequestContextGetter( ...@@ -81,11 +81,7 @@ ShellURLRequestContextGetter::ShellURLRequestContextGetter(
// We must create the proxy config service on the UI loop on Linux because it // We must create the proxy config service on the UI loop on Linux because it
// must synchronously run on the glib message loop. This will be passed to // must synchronously run on the glib message loop. This will be passed to
// the URLRequestContextStorage on the IO thread in GetURLRequestContext(). // the URLRequestContextStorage on the IO thread in GetURLRequestContext().
if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) { proxy_config_service_.reset(GetProxyConfigService());
proxy_config_service_.reset(
net::ProxyService::CreateSystemProxyConfigService(
io_loop_->message_loop_proxy(), file_loop_->message_loop_proxy()));
}
} }
ShellURLRequestContextGetter::~ShellURLRequestContextGetter() { ShellURLRequestContextGetter::~ShellURLRequestContextGetter() {
...@@ -95,6 +91,17 @@ net::NetworkDelegate* ShellURLRequestContextGetter::CreateNetworkDelegate() { ...@@ -95,6 +91,17 @@ net::NetworkDelegate* ShellURLRequestContextGetter::CreateNetworkDelegate() {
return new ShellNetworkDelegate; return new ShellNetworkDelegate;
} }
net::ProxyConfigService* ShellURLRequestContextGetter::GetProxyConfigService() {
return net::ProxyService::CreateSystemProxyConfigService(
io_loop_->message_loop_proxy(), file_loop_->message_loop_proxy());
}
net::ProxyService* ShellURLRequestContextGetter::GetProxyService() {
// TODO(jam): use v8 if possible, look at chrome code.
return net::ProxyService::CreateUsingSystemProxyResolver(
proxy_config_service_.release(), 0, url_request_context_->net_log());
}
net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() { net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
...@@ -104,8 +111,6 @@ net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() { ...@@ -104,8 +111,6 @@ net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() {
url_request_context_.reset(new net::URLRequestContext()); url_request_context_.reset(new net::URLRequestContext());
url_request_context_->set_net_log(net_log_); url_request_context_->set_net_log(net_log_);
network_delegate_.reset(CreateNetworkDelegate()); network_delegate_.reset(CreateNetworkDelegate());
if (command_line.HasSwitch(switches::kDumpRenderTree))
ShellNetworkDelegate::SetAcceptAllCookies(false);
url_request_context_->set_network_delegate(network_delegate_.get()); url_request_context_->set_network_delegate(network_delegate_.get());
storage_.reset( storage_.reset(
new net::URLRequestContextStorage(url_request_context_.get())); new net::URLRequestContextStorage(url_request_context_.get()));
...@@ -123,16 +128,7 @@ net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() { ...@@ -123,16 +128,7 @@ net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() {
storage_->set_cert_verifier(net::CertVerifier::CreateDefault()); storage_->set_cert_verifier(net::CertVerifier::CreateDefault());
storage_->set_transport_security_state(new net::TransportSecurityState); storage_->set_transport_security_state(new net::TransportSecurityState);
if (command_line.HasSwitch(switches::kDumpRenderTree)) { storage_->set_proxy_service(GetProxyService());
storage_->set_proxy_service(net::ProxyService::CreateDirect());
} else {
// TODO(jam): use v8 if possible, look at chrome code.
storage_->set_proxy_service(
net::ProxyService::CreateUsingSystemProxyResolver(
proxy_config_service_.release(),
0,
url_request_context_->net_log()));
}
storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults); storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults);
storage_->set_http_auth_handler_factory( storage_->set_http_auth_handler_factory(
net::HttpAuthHandlerFactory::CreateDefault(host_resolver.get())); net::HttpAuthHandlerFactory::CreateDefault(host_resolver.get()));
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "content/public/browser/content_browser_client.h" #include "content/public/browser/content_browser_client.h"
#include "net/proxy/proxy_config_service.h"
#include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_context_getter.h"
#include "net/url_request/url_request_job_factory.h" #include "net/url_request/url_request_job_factory.h"
...@@ -23,6 +24,7 @@ class MappedHostResolver; ...@@ -23,6 +24,7 @@ class MappedHostResolver;
class NetworkDelegate; class NetworkDelegate;
class NetLog; class NetLog;
class ProxyConfigService; class ProxyConfigService;
class ProxyService;
class URLRequestContextStorage; class URLRequestContextStorage;
} }
...@@ -44,14 +46,18 @@ class ShellURLRequestContextGetter : public net::URLRequestContextGetter { ...@@ -44,14 +46,18 @@ class ShellURLRequestContextGetter : public net::URLRequestContextGetter {
virtual scoped_refptr<base::SingleThreadTaskRunner> virtual scoped_refptr<base::SingleThreadTaskRunner>
GetNetworkTaskRunner() const override; GetNetworkTaskRunner() const override;
// Used by subclasses to create their own implementation of NetworkDelegate.
virtual net::NetworkDelegate* CreateNetworkDelegate();
net::HostResolver* host_resolver(); net::HostResolver* host_resolver();
protected: protected:
virtual ~ShellURLRequestContextGetter(); virtual ~ShellURLRequestContextGetter();
// Used by subclasses to create their own implementation of NetworkDelegate
// and net::ProxyService.
virtual net::NetworkDelegate* CreateNetworkDelegate();
virtual net::ProxyConfigService* GetProxyConfigService();
virtual net::ProxyService* GetProxyService();
private: private:
bool ignore_certificate_errors_; bool ignore_certificate_errors_;
base::FilePath base_path_; base::FilePath base_path_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment