#include "base/threading/sequenced_worker_pool.h"
#include "base/threading/worker_pool.h"
#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/cookie_store_factory.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/url_constants.h"
#include "net/cert/cert_verifier.h"
#include "net/http/http_network_session.h"
#include "net/http/http_server_properties_impl.h"
#include "net/proxy/proxy_service.h"
-#include "net/ssl/default_server_bound_cert_store.h"
-#include "net/ssl/server_bound_cert_service.h"
+#include "net/ssl/channel_id_service.h"
+#include "net/ssl/default_channel_id_store.h"
#include "net/ssl/ssl_config_service_defaults.h"
#include "net/url_request/data_protocol_handler.h"
#include "net/url_request/file_protocol_handler.h"
-#include "net/url_request/protocol_intercept_job_factory.h"
#include "net/url_request/static_http_user_agent_settings.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_storage.h"
+#include "net/url_request/url_request_intercepting_job_factory.h"
+#include "net/url_request/url_request_interceptor.h"
#include "net/url_request/url_request_job_factory_impl.h"
+#include "xwalk/application/common/constants.h"
#include "xwalk/runtime/browser/runtime_network_delegate.h"
#if defined(OS_ANDROID)
const base::FilePath& base_path,
base::MessageLoop* io_loop,
base::MessageLoop* file_loop,
- content::ProtocolHandlerMap* protocol_handlers)
+ content::ProtocolHandlerMap* protocol_handlers,
+ content::URLRequestInterceptorScopedVector request_interceptors)
: ignore_certificate_errors_(ignore_certificate_errors),
base_path_(base_path),
io_loop_(io_loop),
- file_loop_(file_loop) {
+ file_loop_(file_loop),
+ request_interceptors_(request_interceptors.Pass()) {
// Must first be created on the UI thread.
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// the URLRequestContextStorage on the IO thread in GetURLRequestContext().
proxy_config_service_.reset(
net::ProxyService::CreateSystemProxyConfigService(
- io_loop_->message_loop_proxy(), file_loop_));
+ io_loop_->message_loop_proxy(), file_loop_->message_loop_proxy()));
}
RuntimeURLRequestContextGetter::~RuntimeURLRequestContextGetter() {
#if defined(OS_ANDROID)
storage_->set_cookie_store(xwalk::GetCookieMonster());
#else
- storage_->set_cookie_store(new net::CookieMonster(NULL, NULL));
+ content::CookieStoreConfig cookie_config(base_path_.Append(
+ application::kCookieDatabaseFilename),
+ content::CookieStoreConfig::PERSISTANT_SESSION_COOKIES,
+ NULL, NULL);
+ net::CookieStore* cookie_store = content::CreateCookieStore(cookie_config);
+
+ std::vector<const char*> cookieable_schemes(
+ net::CookieMonster::kDefaultCookieableSchemes,
+ net::CookieMonster::kDefaultCookieableSchemes +
+ net::CookieMonster::kDefaultCookieableSchemesCount - 1);
+ cookieable_schemes.push_back(application::kApplicationScheme);
+ cookieable_schemes.push_back(content::kChromeDevToolsScheme);
+
+ cookie_store->GetCookieMonster()->SetCookieableSchemes(
+ &cookieable_schemes[0], cookieable_schemes.size());
+ storage_->set_cookie_store(cookie_store);
#endif
- storage_->set_server_bound_cert_service(new net::ServerBoundCertService(
- new net::DefaultServerBoundCertStore(NULL),
+ storage_->set_channel_id_service(new net::ChannelIDService(
+ new net::DefaultChannelIDStore(NULL),
base::WorkerPool::GetTaskRunner(true)));
storage_->set_http_user_agent_settings(
- new net::StaticHttpUserAgentSettings("en-us,en", EmptyString()));
+ new net::StaticHttpUserAgentSettings("en-us,en", base::EmptyString()));
scoped_ptr<net::HostResolver> host_resolver(
net::HostResolver::CreateDefaultResolver(NULL));
url_request_context_->cert_verifier();
network_session_params.transport_security_state =
url_request_context_->transport_security_state();
- network_session_params.server_bound_cert_service =
- url_request_context_->server_bound_cert_service();
+ network_session_params.channel_id_service =
+ url_request_context_->channel_id_service();
network_session_params.proxy_service =
url_request_context_->proxy_service();
network_session_params.ssl_config_service =
// Step 2:
// Add new basic schemes.
set_protocol = job_factory_impl->SetProtocolHandler(
- chrome::kDataScheme,
+ url::kDataScheme,
new net::DataProtocolHandler);
DCHECK(set_protocol);
set_protocol = job_factory_impl->SetProtocolHandler(
- chrome::kFileScheme,
+ url::kFileScheme,
new net::FileProtocolHandler(
content::BrowserThread::GetBlockingPool()->
GetTaskRunnerWithShutdownBehavior(
// Step 3:
// Add the scheme interceptors.
- // Create a chain of URLRequestJobFactories. The handlers will be invoked
- // in the order in which they appear in the protocol_handlers vector.
- typedef std::vector<net::URLRequestJobFactory::ProtocolHandler*>
- ProtocolHandlerVector;
- ProtocolHandlerVector protocol_interceptors;
+ // in the order in which they appear in the |request_interceptors| vector.
+ typedef std::vector<net::URLRequestInterceptor*>
+ URLRequestInterceptorVector;
+ URLRequestInterceptorVector request_interceptors;
#if defined(OS_ANDROID)
- protocol_interceptors.push_back(
- CreateContentSchemeProtocolHandler().release());
- protocol_interceptors.push_back(
- CreateAssetFileProtocolHandler().release());
- protocol_interceptors.push_back(
- CreateAppSchemeProtocolHandler().release());
+ request_interceptors.push_back(
+ CreateContentSchemeRequestInterceptor().release());
+ request_interceptors.push_back(
+ CreateAssetFileRequestInterceptor().release());
+ request_interceptors.push_back(
+ CreateAppSchemeRequestInterceptor().release());
// The XWalkRequestInterceptor must come after the content and asset
// file job factories. This for WebViewClassic compatibility where it
// was not possible to intercept resource loads to resolvable content://
// This logical dependency is also the reason why the Content
// ProtocolHandler has to be added as a ProtocolInterceptJobFactory rather
// than via SetProtocolHandler.
- protocol_interceptors.push_back(new XWalkRequestInterceptor());
+ request_interceptors.push_back(new XWalkRequestInterceptor());
#endif
// The chain of responsibility will execute the handlers in reverse to the
// order in which the elements of the chain are created.
scoped_ptr<net::URLRequestJobFactory> job_factory(
job_factory_impl.PassAs<net::URLRequestJobFactory>());
- for (ProtocolHandlerVector::reverse_iterator
- i = protocol_interceptors.rbegin();
- i != protocol_interceptors.rend();
+ for (URLRequestInterceptorVector::reverse_iterator
+ i = request_interceptors.rbegin();
+ i != request_interceptors.rend();
++i) {
- job_factory.reset(new net::ProtocolInterceptJobFactory(
+ job_factory.reset(new net::URLRequestInterceptingJobFactory(
job_factory.Pass(), make_scoped_ptr(*i)));
}
- storage_->set_job_factory(job_factory.release());
+ // Set up interceptors in the reverse order.
+ scoped_ptr<net::URLRequestJobFactory> top_job_factory =
+ job_factory.PassAs<net::URLRequestJobFactory>();
+ for (content::URLRequestInterceptorScopedVector::reverse_iterator i =
+ request_interceptors_.rbegin();
+ i != request_interceptors_.rend();
+ ++i) {
+ top_job_factory.reset(new net::URLRequestInterceptingJobFactory(
+ top_job_factory.Pass(), make_scoped_ptr(*i)));
+ }
+ request_interceptors_.weak_clear();
+
+ storage_->set_job_factory(top_job_factory.release());
}
return url_request_context_.get();