Index: headless/lib/browser/headless_url_request_context_getter.cc |
diff --git a/content/shell/browser/shell_url_request_context_getter.cc b/headless/lib/browser/headless_url_request_context_getter.cc |
similarity index 71% |
copy from content/shell/browser/shell_url_request_context_getter.cc |
copy to headless/lib/browser/headless_url_request_context_getter.cc |
index f1eaa013fd94e9689c9c7c0cd8bbaa03d0c3bb0d..937b4069ae9272ad6fa285fdbc440234ac386421 100644 |
--- a/content/shell/browser/shell_url_request_context_getter.cc |
+++ b/headless/lib/browser/headless_url_request_context_getter.cc |
@@ -1,11 +1,9 @@ |
-// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Copyright 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 "content/shell/browser/shell_url_request_context_getter.h" |
+#include "headless/lib/browser/headless_url_request_context_getter.h" |
-#include "base/command_line.h" |
-#include "base/logging.h" |
#include "base/memory/scoped_ptr.h" |
#include "base/single_thread_task_runner.h" |
#include "base/strings/string_number_conversions.h" |
@@ -16,9 +14,6 @@ |
#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/cookie_store_factory.h" |
#include "content/public/common/content_switches.h" |
-#include "content/shell/browser/shell_network_delegate.h" |
-#include "content/shell/common/shell_content_client.h" |
-#include "content/shell/common/shell_switches.h" |
#include "net/base/cache_type.h" |
#include "net/cert/cert_verifier.h" |
#include "net/cookies/cookie_monster.h" |
@@ -41,14 +36,15 @@ |
#include "net/url_request/url_request_intercepting_job_factory.h" |
#include "net/url_request/url_request_job_factory_impl.h" |
#include "url/url_constants.h" |
+#include "headless/lib/browser/headless_network_delegate.h" |
-namespace content { |
+namespace headless { |
namespace { |
void InstallProtocolHandlers(net::URLRequestJobFactoryImpl* job_factory, |
- ProtocolHandlerMap* protocol_handlers) { |
- for (ProtocolHandlerMap::iterator it = |
+ content::ProtocolHandlerMap* protocol_handlers) { |
+ for (content::ProtocolHandlerMap::iterator it = |
protocol_handlers->begin(); |
it != protocol_handlers->end(); |
++it) { |
@@ -61,13 +57,13 @@ void InstallProtocolHandlers(net::URLRequestJobFactoryImpl* job_factory, |
} // namespace |
-ShellURLRequestContextGetter::ShellURLRequestContextGetter( |
+HeadlessURLRequestContextGetter::HeadlessURLRequestContextGetter( |
bool ignore_certificate_errors, |
const base::FilePath& base_path, |
base::MessageLoop* io_loop, |
base::MessageLoop* file_loop, |
- ProtocolHandlerMap* protocol_handlers, |
- URLRequestInterceptorScopedVector request_interceptors, |
+ content::ProtocolHandlerMap* protocol_handlers, |
+ content::URLRequestInterceptorScopedVector request_interceptors, |
net::NetLog* net_log) |
: ignore_certificate_errors_(ignore_certificate_errors), |
base_path_(base_path), |
@@ -76,7 +72,7 @@ ShellURLRequestContextGetter::ShellURLRequestContextGetter( |
net_log_(net_log), |
request_interceptors_(request_interceptors.Pass()) { |
// Must first be created on the UI thread. |
- DCHECK_CURRENTLY_ON(BrowserThread::UI); |
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
std::swap(protocol_handlers_, *protocol_handlers); |
@@ -86,45 +82,43 @@ ShellURLRequestContextGetter::ShellURLRequestContextGetter( |
proxy_config_service_ = GetProxyConfigService(); |
} |
-ShellURLRequestContextGetter::~ShellURLRequestContextGetter() { |
+HeadlessURLRequestContextGetter::~HeadlessURLRequestContextGetter() { |
} |
scoped_ptr<net::NetworkDelegate> |
-ShellURLRequestContextGetter::CreateNetworkDelegate() { |
- return make_scoped_ptr(new ShellNetworkDelegate); |
+HeadlessURLRequestContextGetter::CreateNetworkDelegate() { |
+ return make_scoped_ptr(new HeadlessNetworkDelegate); |
} |
scoped_ptr<net::ProxyConfigService> |
-ShellURLRequestContextGetter::GetProxyConfigService() { |
+HeadlessURLRequestContextGetter::GetProxyConfigService() { |
return net::ProxyService::CreateSystemProxyConfigService( |
io_loop_->task_runner(), file_loop_->task_runner()); |
} |
-scoped_ptr<net::ProxyService> ShellURLRequestContextGetter::GetProxyService() { |
+scoped_ptr<net::ProxyService> HeadlessURLRequestContextGetter::GetProxyService() { |
// TODO(jam): use v8 if possible, look at chrome code. |
return net::ProxyService::CreateUsingSystemProxyResolver( |
proxy_config_service_.Pass(), 0, url_request_context_->net_log()); |
} |
-net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() { |
- DCHECK_CURRENTLY_ON(BrowserThread::IO); |
+net::URLRequestContext* HeadlessURLRequestContextGetter::GetURLRequestContext() { |
+ DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
if (!url_request_context_) { |
- const base::CommandLine& command_line = |
- *base::CommandLine::ForCurrentProcess(); |
- |
url_request_context_.reset(new net::URLRequestContext()); |
url_request_context_->set_net_log(net_log_); |
network_delegate_ = CreateNetworkDelegate(); |
url_request_context_->set_network_delegate(network_delegate_.get()); |
storage_.reset( |
new net::URLRequestContextStorage(url_request_context_.get())); |
- storage_->set_cookie_store(CreateCookieStore(CookieStoreConfig())); |
+ storage_->set_cookie_store(content::CreateCookieStore(content::CookieStoreConfig())); |
storage_->set_channel_id_service(make_scoped_ptr( |
new net::ChannelIDService(new net::DefaultChannelIDStore(NULL), |
base::WorkerPool::GetTaskRunner(true)))); |
+ // TODO: headless user agent fix |
storage_->set_http_user_agent_settings(make_scoped_ptr( |
- new net::StaticHttpUserAgentSettings("en-us,en", GetShellUserAgent()))); |
+ new net::StaticHttpUserAgentSettings("en-us,en", "HeadlessUserAgent"))); |
scoped_ptr<net::HostResolver> host_resolver( |
net::HostResolver::CreateDefaultResolver( |
@@ -144,16 +138,10 @@ net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() { |
scoped_ptr<net::HttpCache::DefaultBackend> main_backend( |
new net::HttpCache::DefaultBackend( |
net::DISK_CACHE, |
-#if defined(OS_ANDROID) |
- // TODO(rdsmith): Remove when default backend for Android is |
- // changed to simple cache. |
- net::CACHE_BACKEND_SIMPLE, |
-#else |
net::CACHE_BACKEND_DEFAULT, |
-#endif |
cache_path, |
0, |
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE))); |
+ content::BrowserThread::GetMessageLoopProxyForThread(content::BrowserThread::CACHE))); |
net::HttpNetworkSession::Params network_session_params; |
network_session_params.cert_verifier = |
@@ -176,25 +164,6 @@ net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() { |
url_request_context_->net_log(); |
network_session_params.ignore_certificate_errors = |
ignore_certificate_errors_; |
- if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) { |
- int value; |
- base::StringToInt(command_line.GetSwitchValueASCII( |
- switches::kTestingFixedHttpPort), &value); |
- network_session_params.testing_fixed_http_port = value; |
- } |
- if (command_line.HasSwitch(switches::kTestingFixedHttpsPort)) { |
- int value; |
- base::StringToInt(command_line.GetSwitchValueASCII( |
- switches::kTestingFixedHttpsPort), &value); |
- network_session_params.testing_fixed_https_port = value; |
- } |
- if (command_line.HasSwitch(switches::kHostResolverRules)) { |
- scoped_ptr<net::MappedHostResolver> mapped_host_resolver( |
- new net::MappedHostResolver(host_resolver.Pass())); |
- mapped_host_resolver->SetRulesFromString( |
- command_line.GetSwitchValueASCII(switches::kHostResolverRules)); |
- host_resolver = mapped_host_resolver.Pass(); |
- } |
// Give |storage_| ownership at the end in case it's |mapped_host_resolver|. |
storage_->set_host_resolver(host_resolver.Pass()); |
@@ -210,8 +179,7 @@ net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() { |
scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( |
new net::URLRequestJobFactoryImpl()); |
- // Keep ProtocolHandlers added in sync with |
- // ShellContentBrowserClient::IsHandledURL(). |
+ |
InstallProtocolHandlers(job_factory.get(), &protocol_handlers_); |
bool set_protocol = job_factory->SetProtocolHandler( |
url::kDataScheme, make_scoped_ptr(new net::DataProtocolHandler)); |
@@ -220,7 +188,7 @@ net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() { |
set_protocol = job_factory->SetProtocolHandler( |
url::kFileScheme, |
make_scoped_ptr(new net::FileProtocolHandler( |
- BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( |
+ content::BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( |
base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)))); |
DCHECK(set_protocol); |
#endif |
@@ -228,7 +196,7 @@ net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() { |
// Set up interceptors in the reverse order. |
scoped_ptr<net::URLRequestJobFactory> top_job_factory = |
job_factory.Pass(); |
- for (URLRequestInterceptorScopedVector::reverse_iterator i = |
+ for (content::URLRequestInterceptorScopedVector::reverse_iterator i = |
request_interceptors_.rbegin(); |
i != request_interceptors_.rend(); |
++i) { |
@@ -244,12 +212,12 @@ net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() { |
} |
scoped_refptr<base::SingleThreadTaskRunner> |
- ShellURLRequestContextGetter::GetNetworkTaskRunner() const { |
- return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
+ HeadlessURLRequestContextGetter::GetNetworkTaskRunner() const { |
+ return content::BrowserThread::GetMessageLoopProxyForThread(content::BrowserThread::IO); |
} |
-net::HostResolver* ShellURLRequestContextGetter::host_resolver() { |
+net::HostResolver* HeadlessURLRequestContextGetter::host_resolver() { |
return url_request_context_->host_resolver(); |
} |
-} // namespace content |
+} // namespace headless |