diff options
Diffstat (limited to 'src/core/url_request_context_getter_qt.cpp')
-rw-r--r-- | src/core/url_request_context_getter_qt.cpp | 106 |
1 files changed, 67 insertions, 39 deletions
diff --git a/src/core/url_request_context_getter_qt.cpp b/src/core/url_request_context_getter_qt.cpp index c2e592bc5..609be75d3 100644 --- a/src/core/url_request_context_getter_qt.cpp +++ b/src/core/url_request_context_getter_qt.cpp @@ -41,7 +41,6 @@ #include "base/threading/worker_pool.h" #include "base/threading/sequenced_worker_pool.h" #include "content/public/browser/browser_thread.h" -#include "content/public/browser/cookie_crypto_delegate.h" #include "content/public/browser/cookie_store_factory.h" #include "content/public/common/content_switches.h" #include "net/base/cache_type.h" @@ -67,12 +66,16 @@ #include "net/url_request/ftp_protocol_handler.h" #include "net/ftp/ftp_network_layer.h" +#include "api/qwebengineurlschemehandler.h" #include "browser_context_adapter.h" #include "custom_protocol_handler.h" -#include "custom_url_scheme_handler.h" +#include "cookie_monster_delegate_qt.h" #include "content_client_qt.h" #include "network_delegate_qt.h" +#include "proxy_config_service_qt.h" #include "qrc_protocol_handler_qt.h" +#include "qwebenginecookiestore.h" +#include "qwebenginecookiestore_p.h" #include "type_conversion.h" namespace QtWebEngineCore { @@ -84,6 +87,7 @@ using content::BrowserThread; URLRequestContextGetterQt::URLRequestContextGetterQt(BrowserContextAdapter *browserContext, content::ProtocolHandlerMap *protocolHandlers) : m_ignoreCertificateErrors(false) , m_browserContext(browserContext) + , m_cookieDelegate(new CookieMonsterDelegateQt()) { std::swap(m_protocolHandlers, *protocolHandlers); @@ -100,7 +104,7 @@ net::URLRequestContext *URLRequestContextGetterQt::GetURLRequestContext() if (!m_urlRequestContext) { m_urlRequestContext.reset(new net::URLRequestContext()); - m_networkDelegate.reset(new NetworkDelegateQt); + m_networkDelegate.reset(new NetworkDelegateQt(this)); m_urlRequestContext->set_network_delegate(m_networkDelegate.get()); generateStorage(); @@ -117,10 +121,10 @@ void URLRequestContextGetterQt::updateStorageSettings() // 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(). - m_proxyConfigService = net::ProxyService::CreateSystemProxyConfigService( + m_proxyConfigService = new ProxyConfigServiceQt(net::ProxyService::CreateSystemProxyConfigService( content::BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), content::BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE) - ); + )); if (m_storage) content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, base::Bind(&URLRequestContextGetterQt::generateStorage, this)); } @@ -157,34 +161,27 @@ void URLRequestContextGetterQt::generateStorage() generateCookieStore(); generateUserAgent(); - m_storage->set_channel_id_service(new net::ChannelIDService( + m_storage->set_channel_id_service(scoped_ptr<net::ChannelIDService>(new net::ChannelIDService( new net::DefaultChannelIDStore(NULL), - base::WorkerPool::GetTaskRunner(true))); + base::WorkerPool::GetTaskRunner(true)))); m_storage->set_cert_verifier(net::CertVerifier::CreateDefault()); scoped_ptr<net::HostResolver> host_resolver(net::HostResolver::CreateDefaultResolver(NULL)); // The System Proxy Resolver has issues on Windows with unconfigured network cards, - // which is why we want to use the v8 one. However, V8ProxyResolver doesn't work reliably with - // --single-process (See also the warnings in net/proxy/proxy_resolver_v8.h). - base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); - if (command_line.HasSwitch(switches::kSingleProcess)) { - m_storage->set_proxy_service( - net::ProxyService::CreateUsingSystemProxyResolver(proxyConfigService, 0, NULL)); - } else { - if (!m_dhcpProxyScriptFetcherFactory) - m_dhcpProxyScriptFetcherFactory.reset(new net::DhcpProxyScriptFetcherFactory); - - net::ProxyResolverV8::EnsureIsolateCreated(); - m_storage->set_proxy_service(net::CreateProxyServiceUsingV8ProxyResolver( - proxyConfigService, - new net::ProxyScriptFetcherImpl(m_urlRequestContext.get()), - m_dhcpProxyScriptFetcherFactory->Create(m_urlRequestContext.get()), - host_resolver.get(), - NULL /* NetLog */, - m_networkDelegate.get())); - } + // which is why we want to use the v8 one + if (!m_dhcpProxyScriptFetcherFactory) + m_dhcpProxyScriptFetcherFactory.reset(new net::DhcpProxyScriptFetcherFactory); + + m_storage->set_proxy_service(net::CreateProxyServiceUsingV8ProxyResolver( + proxyConfigService, + new net::ProxyScriptFetcherImpl(m_urlRequestContext.get()), + m_dhcpProxyScriptFetcherFactory->Create(m_urlRequestContext.get()), + host_resolver.get(), + NULL /* NetLog */, + m_networkDelegate.get())); + m_storage->set_ssl_config_service(new net::SSLConfigServiceDefaults); m_storage->set_transport_security_state(new net::TransportSecurityState()); @@ -213,6 +210,8 @@ void URLRequestContextGetterQt::generateCookieStore() // Unset it first to get a chance to destroy and flush the old cookie store before before opening a new on possibly the same file. m_storage->set_cookie_store(0); + m_cookieDelegate->setCookieMonster(0); + m_cookieDelegate->setClient(m_browserContext->cookieStore()); net::CookieStore* cookieStore = 0; switch (m_browserContext->persistentCookiesPolicy()) { @@ -221,7 +220,8 @@ void URLRequestContextGetterQt::generateCookieStore() content::CreateCookieStore(content::CookieStoreConfig( base::FilePath(), content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, - NULL, NULL) + NULL, + m_cookieDelegate.get()) ); break; case BrowserContextAdapter::AllowPersistentCookies: @@ -229,7 +229,8 @@ void URLRequestContextGetterQt::generateCookieStore() content::CreateCookieStore(content::CookieStoreConfig( toFilePath(m_browserContext->cookiesPath()), content::CookieStoreConfig::PERSISTANT_SESSION_COOKIES, - NULL, NULL) + NULL, + m_cookieDelegate.get()) ); break; case BrowserContextAdapter::ForcePersistentCookies: @@ -237,11 +238,16 @@ void URLRequestContextGetterQt::generateCookieStore() content::CreateCookieStore(content::CookieStoreConfig( toFilePath(m_browserContext->cookiesPath()), content::CookieStoreConfig::RESTORED_SESSION_COOKIES, - NULL, NULL) + NULL, + m_cookieDelegate.get()) ); break; } m_storage->set_cookie_store(cookieStore); + + net::CookieMonster * const cookieMonster = cookieStore->GetCookieMonster(); + cookieMonster->SetCookieableSchemes(kCookieableSchemes, arraysize(kCookieableSchemes)); + m_cookieDelegate->setCookieMonster(cookieMonster); } void URLRequestContextGetterQt::updateUserAgent() @@ -250,13 +256,32 @@ void URLRequestContextGetterQt::updateUserAgent() content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, base::Bind(&URLRequestContextGetterQt::generateUserAgent, this)); } +class HttpUserAgentSettingsQt : public net::HttpUserAgentSettings +{ + const BrowserContextAdapter *m_browserContext; +public: + HttpUserAgentSettingsQt(const BrowserContextAdapter *ctx) + : m_browserContext(ctx) + { + } + + std::string GetAcceptLanguage() const Q_DECL_OVERRIDE + { + return m_browserContext->httpAcceptLanguage().toStdString(); + } + + std::string GetUserAgent() const Q_DECL_OVERRIDE + { + return m_browserContext->httpUserAgent().toStdString(); + } +}; + void URLRequestContextGetterQt::generateUserAgent() { Q_ASSERT(m_urlRequestContext); Q_ASSERT(m_storage); - m_storage->set_http_user_agent_settings( - new net::StaticHttpUserAgentSettings("en-us,en", m_browserContext->httpUserAgent().toStdString())); + m_storage->set_http_user_agent_settings(new HttpUserAgentSettingsQt(m_browserContext)); } void URLRequestContextGetterQt::updateHttpCache() @@ -365,11 +390,13 @@ void URLRequestContextGetterQt::generateJobFactory() Q_ASSERT(!m_jobFactory); m_jobFactory.reset(new net::URLRequestJobFactoryImpl()); - // Chromium has a few protocol handlers ready for us, only pick blob: and throw away the rest. - content::ProtocolHandlerMap::iterator it = m_protocolHandlers.find(url::kBlobScheme); - Q_ASSERT(it != m_protocolHandlers.end()); - m_jobFactory->SetProtocolHandler(it->first, it->second.release()); - m_protocolHandlers.clear(); + { + // Chromium has a few protocol handlers ready for us, only pick blob: and throw away the rest. + content::ProtocolHandlerMap::iterator it = m_protocolHandlers.find(url::kBlobScheme); + Q_ASSERT(it != m_protocolHandlers.end()); + m_jobFactory->SetProtocolHandler(it->first, it->second.release()); + m_protocolHandlers.clear(); + } m_jobFactory->SetProtocolHandler(url::kDataScheme, new net::DataProtocolHandler()); m_jobFactory->SetProtocolHandler(url::kFileScheme, new net::FileProtocolHandler( @@ -379,9 +406,10 @@ void URLRequestContextGetterQt::generateJobFactory() m_jobFactory->SetProtocolHandler(url::kFtpScheme, new net::FtpProtocolHandler(new net::FtpNetworkLayer(m_urlRequestContext->host_resolver()))); - Q_FOREACH (CustomUrlSchemeHandler* handler, m_browserContext->customUrlSchemeHandlers()) { - m_jobFactory->SetProtocolHandler(handler->scheme().toStdString(), handler->createProtocolHandler()); - } + QHash<QByteArray, QWebEngineUrlSchemeHandler*>::const_iterator it = m_browserContext->customUrlSchemeHandlers().constBegin(); + const QHash<QByteArray, QWebEngineUrlSchemeHandler*>::const_iterator end = m_browserContext->customUrlSchemeHandlers().constEnd(); + for (; it != end; ++it) + m_jobFactory->SetProtocolHandler(it.key().toStdString(), new CustomProtocolHandler(it.value())); m_urlRequestContext->set_job_factory(m_jobFactory.get()); } |