diff options
Diffstat (limited to 'content/shell/browser')
4 files changed, 61 insertions, 31 deletions
diff --git a/content/shell/browser/shell_browser_context.cc b/content/shell/browser/shell_browser_context.cc index 7a99e8d..308ed38 100644 --- a/content/shell/browser/shell_browser_context.cc +++ b/content/shell/browser/shell_browser_context.cc @@ -12,11 +12,9 @@ #include "base/path_service.h" #include "base/threading/thread.h" #include "content/public/browser/browser_thread.h" -#include "content/public/browser/resource_context.h" #include "content/public/browser/storage_partition.h" #include "content/public/common/content_switches.h" #include "content/shell/browser/shell_download_manager_delegate.h" -#include "content/shell/browser/shell_url_request_context_getter.h" #include "content/shell/common/shell_switches.h" #if defined(OS_WIN) @@ -29,38 +27,32 @@ namespace content { -class ShellBrowserContext::ShellResourceContext : public ResourceContext { - public: - ShellResourceContext() : getter_(NULL) {} - virtual ~ShellResourceContext() {} - - // ResourceContext implementation: - virtual net::HostResolver* GetHostResolver() override { - CHECK(getter_); - return getter_->host_resolver(); - } - virtual net::URLRequestContext* GetRequestContext() override { - CHECK(getter_); - return getter_->GetURLRequestContext(); - } +ShellBrowserContext::ShellResourceContext::ShellResourceContext() + : getter_(NULL) { +} - void set_url_request_context_getter(ShellURLRequestContextGetter* getter) { - getter_ = getter; - } +ShellBrowserContext::ShellResourceContext::~ShellResourceContext() { +} - private: - ShellURLRequestContextGetter* getter_; +net::HostResolver* +ShellBrowserContext::ShellResourceContext::GetHostResolver() { + CHECK(getter_); + return getter_->host_resolver(); +} - DISALLOW_COPY_AND_ASSIGN(ShellResourceContext); -}; +net::URLRequestContext* +ShellBrowserContext::ShellResourceContext::GetRequestContext() { + CHECK(getter_); + return getter_->GetURLRequestContext(); +} ShellBrowserContext::ShellBrowserContext(bool off_the_record, net::NetLog* net_log) - : off_the_record_(off_the_record), + : resource_context_(new ShellResourceContext), + off_the_record_(off_the_record), net_log_(net_log), ignore_certificate_errors_(false), - guest_manager_(NULL), - resource_context_(new ShellResourceContext) { + guest_manager_(NULL) { InitWhileIOAllowed(); } diff --git a/content/shell/browser/shell_browser_context.h b/content/shell/browser/shell_browser_context.h index f015344..81e8b94 100644 --- a/content/shell/browser/shell_browser_context.h +++ b/content/shell/browser/shell_browser_context.h @@ -11,6 +11,8 @@ #include "base/memory/scoped_ptr.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/content_browser_client.h" +#include "content/public/browser/resource_context.h" +#include "content/shell/browser/shell_url_request_context_getter.h" #include "net/url_request/url_request_job_factory.h" namespace net { @@ -20,9 +22,7 @@ class NetLog; namespace content { class DownloadManagerDelegate; -class ResourceContext; class ShellDownloadManagerDelegate; -class ShellURLRequestContextGetter; class ShellBrowserContext : public BrowserContext { public: @@ -63,8 +63,40 @@ class ShellBrowserContext : public BrowserContext { ProtocolHandlerMap* protocol_handlers, URLRequestInterceptorScopedVector request_interceptors); + protected: + // Contains URLRequestContextGetter required for resource loading. + class ShellResourceContext : public ResourceContext { + public: + ShellResourceContext(); + virtual ~ShellResourceContext(); + + // ResourceContext implementation: + virtual net::HostResolver* GetHostResolver() override; + virtual net::URLRequestContext* GetRequestContext() override; + + void set_url_request_context_getter(ShellURLRequestContextGetter* getter) { + getter_ = getter; + } + + private: + ShellURLRequestContextGetter* getter_; + + DISALLOW_COPY_AND_ASSIGN(ShellResourceContext); + }; + + ShellURLRequestContextGetter* url_request_context_getter() { + return url_request_getter_.get(); + } + + // Used by ShellBrowserContext to initiate and set different types of + // URLRequestContextGetter. + void set_url_request_context_getter(ShellURLRequestContextGetter* getter) { + url_request_getter_ = getter; + } + + scoped_ptr<ShellResourceContext> resource_context_; + private: - class ShellResourceContext; // Performs initialization of the ShellBrowserContext while IO is still // allowed on the current thread. @@ -75,7 +107,6 @@ class ShellBrowserContext : public BrowserContext { bool ignore_certificate_errors_; base::FilePath path_; BrowserPluginGuestManager* guest_manager_; - scoped_ptr<ShellResourceContext> resource_context_; scoped_ptr<ShellDownloadManagerDelegate> download_manager_delegate_; scoped_refptr<ShellURLRequestContextGetter> url_request_getter_; diff --git a/content/shell/browser/shell_url_request_context_getter.cc b/content/shell/browser/shell_url_request_context_getter.cc index c606d13..4788d28 100644 --- a/content/shell/browser/shell_url_request_context_getter.cc +++ b/content/shell/browser/shell_url_request_context_getter.cc @@ -91,6 +91,10 @@ ShellURLRequestContextGetter::ShellURLRequestContextGetter( ShellURLRequestContextGetter::~ShellURLRequestContextGetter() { } +net::NetworkDelegate* ShellURLRequestContextGetter::CreateNetworkDelegate() { + return new ShellNetworkDelegate; +} + net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); @@ -99,7 +103,7 @@ net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() { url_request_context_.reset(new net::URLRequestContext()); url_request_context_->set_net_log(net_log_); - network_delegate_.reset(new ShellNetworkDelegate); + network_delegate_.reset(CreateNetworkDelegate()); if (command_line.HasSwitch(switches::kDumpRenderTree)) ShellNetworkDelegate::SetAcceptAllCookies(false); url_request_context_->set_network_delegate(network_delegate_.get()); diff --git a/content/shell/browser/shell_url_request_context_getter.h b/content/shell/browser/shell_url_request_context_getter.h index 810e602..665c964 100644 --- a/content/shell/browser/shell_url_request_context_getter.h +++ b/content/shell/browser/shell_url_request_context_getter.h @@ -44,6 +44,9 @@ 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: |