summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormkwst <mkwst@chromium.org>2014-10-16 00:36:52 -0700
committerCommit bot <commit-bot@chromium.org>2014-10-16 07:37:11 +0000
commit94388f795c709fc4a9f84da800d407b2b8257166 (patch)
treef78369bf8ed1309f583f5ce121450208391edc17
parent1c493cf5ec7f771d2222f9a453d6278916b9fc46 (diff)
downloadchromium_src-94388f795c709fc4a9f84da800d407b2b8257166.zip
chromium_src-94388f795c709fc4a9f84da800d407b2b8257166.tar.gz
chromium_src-94388f795c709fc4a9f84da800d407b2b8257166.tar.bz2
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}
-rw-r--r--content/content_shell.gypi2
-rw-r--r--content/shell/BUILD.gn6
-rw-r--r--content/shell/browser/layout_test/layout_test_browser_context.cc16
-rw-r--r--content/shell/browser/layout_test/layout_test_browser_context.h5
-rw-r--r--content/shell/browser/layout_test/layout_test_url_request_context_getter.cc52
-rw-r--r--content/shell/browser/layout_test/layout_test_url_request_context_getter.h56
-rw-r--r--content/shell/browser/shell_browser_context.cc14
-rw-r--r--content/shell/browser/shell_browser_context.h6
-rw-r--r--content/shell/browser/shell_url_request_context_getter.cc30
-rw-r--r--content/shell/browser/shell_url_request_context_getter.h10
10 files changed, 173 insertions, 24 deletions
diff --git a/content/content_shell.gypi b/content/content_shell.gypi
index f2d9446..5303404 100644
--- a/content/content_shell.gypi
+++ b/content/content_shell.gypi
@@ -104,6 +104,8 @@
'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.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.h',
'shell/browser/shell_android.cc',
diff --git a/content/shell/BUILD.gn b/content/shell/BUILD.gn
index 6d31062..54f824c 100644
--- a/content/shell/BUILD.gn
+++ b/content/shell/BUILD.gn
@@ -45,14 +45,16 @@ static_library("content_shell_lib") {
"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.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.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.h",
"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_url_request_context_getter.cc",
+ "browser/layout_test/layout_test_url_request_context_getter.h",
"browser/notify_done_forwarder.cc",
"browser/notify_done_forwarder.h",
"browser/shell_android.cc",
diff --git a/content/shell/browser/layout_test/layout_test_browser_context.cc b/content/shell/browser/layout_test/layout_test_browser_context.cc
index fff7d40..9392be1 100644
--- a/content/shell/browser/layout_test/layout_test_browser_context.cc
+++ b/content/shell/browser/layout_test/layout_test_browser_context.cc
@@ -9,8 +9,10 @@
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/path_service.h"
+#include "content/public/browser/browser_thread.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_url_request_context_getter.h"
#include "content/shell/browser/shell_url_request_context_getter.h"
#if defined(OS_WIN)
@@ -32,6 +34,20 @@ LayoutTestBrowserContext::LayoutTestBrowserContext(bool off_the_record,
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*
LayoutTestBrowserContext::GetDownloadManagerDelegate() {
if (!download_manager_delegate_.get()) {
diff --git a/content/shell/browser/layout_test/layout_test_browser_context.h b/content/shell/browser/layout_test/layout_test_browser_context.h
index 30b7a42..3e0e999 100644
--- a/content/shell/browser/layout_test/layout_test_browser_context.h
+++ b/content/shell/browser/layout_test/layout_test_browser_context.h
@@ -24,6 +24,11 @@ class LayoutTestBrowserContext : public ShellBrowserContext {
// BrowserContext implementation.
virtual DownloadManagerDelegate* GetDownloadManagerDelegate() override;
+ protected:
+ virtual ShellURLRequestContextGetter* CreateURLRequestContextGetter(
+ ProtocolHandlerMap* protocol_handlers,
+ URLRequestInterceptorScopedVector request_interceptors) override;
+
private:
DISALLOW_COPY_AND_ASSIGN(LayoutTestBrowserContext);
};
diff --git a/content/shell/browser/layout_test/layout_test_url_request_context_getter.cc b/content/shell/browser/layout_test/layout_test_url_request_context_getter.cc
new file mode 100644
index 0000000..506ce54
--- /dev/null
+++ b/content/shell/browser/layout_test/layout_test_url_request_context_getter.cc
@@ -0,0 +1,52 @@
+// 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
diff --git a/content/shell/browser/layout_test/layout_test_url_request_context_getter.h b/content/shell/browser/layout_test/layout_test_url_request_context_getter.h
new file mode 100644
index 0000000..8b6233d
--- /dev/null
+++ b/content/shell/browser/layout_test/layout_test_url_request_context_getter.h
@@ -0,0 +1,56 @@
+// 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_
diff --git a/content/shell/browser/shell_browser_context.cc b/content/shell/browser/shell_browser_context.cc
index b6a2ab5..8a97911 100644
--- a/content/shell/browser/shell_browser_context.cc
+++ b/content/shell/browser/shell_browser_context.cc
@@ -117,11 +117,11 @@ net::URLRequestContextGetter* ShellBrowserContext::GetRequestContext() {
return GetDefaultStoragePartition(this)->GetURLRequestContext();
}
-net::URLRequestContextGetter* ShellBrowserContext::CreateRequestContext(
+ShellURLRequestContextGetter*
+ShellBrowserContext::CreateURLRequestContextGetter(
ProtocolHandlerMap* protocol_handlers,
URLRequestInterceptorScopedVector request_interceptors) {
- DCHECK(!url_request_getter_.get());
- url_request_getter_ = new ShellURLRequestContextGetter(
+ return new ShellURLRequestContextGetter(
ignore_certificate_errors_,
GetPath(),
BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO),
@@ -129,6 +129,14 @@ net::URLRequestContextGetter* ShellBrowserContext::CreateRequestContext(
protocol_handlers,
request_interceptors.Pass(),
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());
return url_request_getter_.get();
}
diff --git a/content/shell/browser/shell_browser_context.h b/content/shell/browser/shell_browser_context.h
index b840d78..b7fb41b 100644
--- a/content/shell/browser/shell_browser_context.h
+++ b/content/shell/browser/shell_browser_context.h
@@ -90,10 +90,16 @@ class ShellBrowserContext : public BrowserContext {
// Used by ShellBrowserContext to initiate and set different types of
// URLRequestContextGetter.
+ virtual ShellURLRequestContextGetter* CreateURLRequestContextGetter(
+ ProtocolHandlerMap* protocol_handlers,
+ URLRequestInterceptorScopedVector request_interceptors);
void set_url_request_context_getter(ShellURLRequestContextGetter* 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_;
bool ignore_certificate_errors_;
scoped_ptr<ShellDownloadManagerDelegate> download_manager_delegate_;
diff --git a/content/shell/browser/shell_url_request_context_getter.cc b/content/shell/browser/shell_url_request_context_getter.cc
index 4788d28..5fb5f99 100644
--- a/content/shell/browser/shell_url_request_context_getter.cc
+++ b/content/shell/browser/shell_url_request_context_getter.cc
@@ -81,11 +81,7 @@ ShellURLRequestContextGetter::ShellURLRequestContextGetter(
// 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
// the URLRequestContextStorage on the IO thread in GetURLRequestContext().
- if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) {
- proxy_config_service_.reset(
- net::ProxyService::CreateSystemProxyConfigService(
- io_loop_->message_loop_proxy(), file_loop_->message_loop_proxy()));
- }
+ proxy_config_service_.reset(GetProxyConfigService());
}
ShellURLRequestContextGetter::~ShellURLRequestContextGetter() {
@@ -95,6 +91,17 @@ net::NetworkDelegate* ShellURLRequestContextGetter::CreateNetworkDelegate() {
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() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
@@ -104,8 +111,6 @@ net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() {
url_request_context_.reset(new net::URLRequestContext());
url_request_context_->set_net_log(net_log_);
network_delegate_.reset(CreateNetworkDelegate());
- if (command_line.HasSwitch(switches::kDumpRenderTree))
- ShellNetworkDelegate::SetAcceptAllCookies(false);
url_request_context_->set_network_delegate(network_delegate_.get());
storage_.reset(
new net::URLRequestContextStorage(url_request_context_.get()));
@@ -123,16 +128,7 @@ net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() {
storage_->set_cert_verifier(net::CertVerifier::CreateDefault());
storage_->set_transport_security_state(new net::TransportSecurityState);
- if (command_line.HasSwitch(switches::kDumpRenderTree)) {
- 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_proxy_service(GetProxyService());
storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults);
storage_->set_http_auth_handler_factory(
net::HttpAuthHandlerFactory::CreateDefault(host_resolver.get()));
diff --git a/content/shell/browser/shell_url_request_context_getter.h b/content/shell/browser/shell_url_request_context_getter.h
index 665c964..3887d38 100644
--- a/content/shell/browser/shell_url_request_context_getter.h
+++ b/content/shell/browser/shell_url_request_context_getter.h
@@ -10,6 +10,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.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_job_factory.h"
@@ -23,6 +24,7 @@ class MappedHostResolver;
class NetworkDelegate;
class NetLog;
class ProxyConfigService;
+class ProxyService;
class URLRequestContextStorage;
}
@@ -44,14 +46,18 @@ class ShellURLRequestContextGetter : public net::URLRequestContextGetter {
virtual scoped_refptr<base::SingleThreadTaskRunner>
GetNetworkTaskRunner() const override;
- // Used by subclasses to create their own implementation of NetworkDelegate.
- virtual net::NetworkDelegate* CreateNetworkDelegate();
net::HostResolver* host_resolver();
protected:
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:
bool ignore_certificate_errors_;
base::FilePath base_path_;