Index: headless/lib/browser/headless_url_request_context_getter.cc |
diff --git a/blimp/engine/app/blimp_url_request_context_getter.cc b/headless/lib/browser/headless_url_request_context_getter.cc |
similarity index 79% |
copy from blimp/engine/app/blimp_url_request_context_getter.cc |
copy to headless/lib/browser/headless_url_request_context_getter.cc |
index 09a96f9a0d85205bf1bee0222b9fc3cc306d63a3..d05b6d8c3a17abd5f216826d4103aa9b45f08d53 100644 |
--- a/blimp/engine/app/blimp_url_request_context_getter.cc |
+++ b/headless/lib/browser/headless_url_request_context_getter.cc |
@@ -1,10 +1,10 @@ |
-// Copyright 2015 The Chromium Authors. All rights reserved. |
+// 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 "blimp/engine/app/blimp_url_request_context_getter.h" |
+#include "headless/lib/browser/headless_url_request_context_getter.h" |
-#include <algorithm> |
+#include <utility> |
#include "base/command_line.h" |
#include "base/logging.h" |
@@ -15,11 +15,12 @@ |
#include "base/strings/string_util.h" |
#include "base/threading/sequenced_worker_pool.h" |
#include "base/threading/worker_pool.h" |
-#include "blimp/engine/app/blimp_network_delegate.h" |
-#include "blimp/engine/common/blimp_content_client.h" |
+#include "build/build_config.h" |
#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/cookie_store_factory.h" |
#include "content/public/common/content_switches.h" |
+#include "headless/lib/browser/headless_network_delegate.h" |
+#include "headless/lib/browser/headless_url_request_context_getter.h" |
#include "net/base/cache_type.h" |
#include "net/cert/cert_verifier.h" |
#include "net/cookies/cookie_monster.h" |
@@ -30,7 +31,6 @@ |
#include "net/http/http_network_session.h" |
#include "net/http/http_server_properties_impl.h" |
#include "net/http/transport_security_state.h" |
-#include "net/proxy/proxy_config_service.h" |
#include "net/proxy/proxy_service.h" |
#include "net/ssl/channel_id_service.h" |
#include "net/ssl/default_channel_id_store.h" |
@@ -44,8 +44,7 @@ |
#include "net/url_request/url_request_job_factory_impl.h" |
#include "url/url_constants.h" |
-namespace blimp { |
-namespace engine { |
+namespace headless { |
namespace { |
@@ -62,19 +61,21 @@ void InstallProtocolHandlers(net::URLRequestJobFactoryImpl* job_factory, |
} // namespace |
-BlimpURLRequestContextGetter::BlimpURLRequestContextGetter( |
+HeadlessURLRequestContextGetter::HeadlessURLRequestContextGetter( |
bool ignore_certificate_errors, |
const base::FilePath& base_path, |
- const scoped_refptr<base::SingleThreadTaskRunner>& io_loop_task_runner, |
- const scoped_refptr<base::SingleThreadTaskRunner>& file_loop_task_runner, |
+ base::MessageLoop* io_loop, |
+ base::MessageLoop* file_loop, |
content::ProtocolHandlerMap* protocol_handlers, |
content::URLRequestInterceptorScopedVector request_interceptors, |
- net::NetLog* net_log) |
+ net::NetLog* net_log, |
+ const HeadlessBrowser::Options& options) |
: ignore_certificate_errors_(ignore_certificate_errors), |
base_path_(base_path), |
- io_loop_task_runner_(io_loop_task_runner), |
- file_loop_task_runner_(file_loop_task_runner), |
+ io_loop_(io_loop), |
+ file_loop_(file_loop), |
net_log_(net_log), |
+ options_(options), |
request_interceptors_(std::move(request_interceptors)) { |
// Must first be created on the UI thread. |
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
@@ -87,25 +88,27 @@ BlimpURLRequestContextGetter::BlimpURLRequestContextGetter( |
proxy_config_service_ = GetProxyConfigService(); |
} |
-BlimpURLRequestContextGetter::~BlimpURLRequestContextGetter() {} |
+HeadlessURLRequestContextGetter::~HeadlessURLRequestContextGetter() {} |
scoped_ptr<net::NetworkDelegate> |
-BlimpURLRequestContextGetter::CreateNetworkDelegate() { |
- return make_scoped_ptr(new BlimpNetworkDelegate); |
+HeadlessURLRequestContextGetter::CreateNetworkDelegate() { |
+ return make_scoped_ptr(new HeadlessNetworkDelegate); |
} |
scoped_ptr<net::ProxyConfigService> |
-BlimpURLRequestContextGetter::GetProxyConfigService() { |
+HeadlessURLRequestContextGetter::GetProxyConfigService() { |
return net::ProxyService::CreateSystemProxyConfigService( |
- io_loop_task_runner_, file_loop_task_runner_); |
+ io_loop_->task_runner(), file_loop_->task_runner()); |
} |
-scoped_ptr<net::ProxyService> BlimpURLRequestContextGetter::GetProxyService() { |
+scoped_ptr<net::ProxyService> |
+HeadlessURLRequestContextGetter::GetProxyService() { |
return net::ProxyService::CreateUsingSystemProxyResolver( |
std::move(proxy_config_service_), 0, url_request_context_->net_log()); |
} |
-net::URLRequestContext* BlimpURLRequestContextGetter::GetURLRequestContext() { |
+net::URLRequestContext* |
+HeadlessURLRequestContextGetter::GetURLRequestContext() { |
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
if (!url_request_context_) { |
@@ -121,11 +124,11 @@ net::URLRequestContext* BlimpURLRequestContextGetter::GetURLRequestContext() { |
storage_->set_cookie_store( |
content::CreateCookieStore(content::CookieStoreConfig())); |
storage_->set_channel_id_service(make_scoped_ptr( |
- new net::ChannelIDService(new net::DefaultChannelIDStore(NULL), |
+ new net::ChannelIDService(new net::DefaultChannelIDStore(nullptr), |
base::WorkerPool::GetTaskRunner(true)))); |
- storage_->set_http_user_agent_settings( |
- make_scoped_ptr(new net::StaticHttpUserAgentSettings( |
- "en-us,en", GetBlimpEngineUserAgent()))); |
+ // TODO(skyostil): Make language settings configurable. |
+ storage_->set_http_user_agent_settings(make_scoped_ptr( |
+ new net::StaticHttpUserAgentSettings("en-us,en", options_.user_agent))); |
scoped_ptr<net::HostResolver> host_resolver( |
net::HostResolver::CreateDefaultResolver( |
@@ -183,28 +186,35 @@ net::URLRequestContext* BlimpURLRequestContextGetter::GetURLRequestContext() { |
storage_->set_http_network_session( |
make_scoped_ptr(new net::HttpNetworkSession(network_session_params))); |
storage_->set_http_transaction_factory(make_scoped_ptr(new net::HttpCache( |
- storage_->http_network_session(), std::move(main_backend), true))); |
+ storage_->http_network_session(), std::move(main_backend), |
+ true /* set_up_quic_server_info */))); |
scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( |
new net::URLRequestJobFactoryImpl()); |
- // Keep ProtocolHandlers added in sync with |
- // BlimpContentBrowserClient::IsHandledURL(). |
+ |
InstallProtocolHandlers(job_factory.get(), &protocol_handlers_); |
bool set_protocol = job_factory->SetProtocolHandler( |
url::kDataScheme, make_scoped_ptr(new net::DataProtocolHandler)); |
DCHECK(set_protocol); |
+ set_protocol = job_factory->SetProtocolHandler( |
+ url::kFileScheme, |
+ make_scoped_ptr(new net::FileProtocolHandler( |
+ content::BrowserThread::GetBlockingPool() |
+ ->GetTaskRunnerWithShutdownBehavior( |
+ base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)))); |
+ DCHECK(set_protocol); |
- // Set up interceptors in the reverse order so that the last inceptor is at |
- // the end of the linked list of job factories. |
+ // Set up interceptors in the reverse order. |
scoped_ptr<net::URLRequestJobFactory> top_job_factory = |
std::move(job_factory); |
- for (auto i = request_interceptors_.rbegin(); |
+ for (content::URLRequestInterceptorScopedVector::reverse_iterator i = |
+ request_interceptors_.rbegin(); |
i != request_interceptors_.rend(); ++i) { |
top_job_factory.reset(new net::URLRequestInterceptingJobFactory( |
std::move(top_job_factory), make_scoped_ptr(*i))); |
} |
request_interceptors_.weak_clear(); |
- // Save the head of the job factory list at storage_. |
+ |
storage_->set_job_factory(std::move(top_job_factory)); |
} |
@@ -212,14 +222,13 @@ net::URLRequestContext* BlimpURLRequestContextGetter::GetURLRequestContext() { |
} |
scoped_refptr<base::SingleThreadTaskRunner> |
-BlimpURLRequestContextGetter::GetNetworkTaskRunner() const { |
+HeadlessURLRequestContextGetter::GetNetworkTaskRunner() const { |
return content::BrowserThread::GetMessageLoopProxyForThread( |
content::BrowserThread::IO); |
} |
-net::HostResolver* BlimpURLRequestContextGetter::host_resolver() { |
+net::HostResolver* HeadlessURLRequestContextGetter::host_resolver() const { |
return url_request_context_->host_resolver(); |
} |
-} // namespace engine |
-} // namespace blimp |
+} // namespace headless |