From b84030fc8163cde1f8f055973ef63d3e1670bf52 Mon Sep 17 00:00:00 2001 From: Steve Block Date: Mon, 29 Nov 2010 17:18:33 +0000 Subject: [PATCH] Use one WebRequestContext per WebView This change switches from using a pair of WebRequestContexts (one for private browsing, one for regular browsing) to using one WebRequestContext per WebView. This is required to allow us to set the userAgent on each WebView. The WebRequestContext is now owned by the WebView. Bug: 3113804 Change-Id: Iba2b1490e7ce4ff65c08a04a310963fa2c7e4f83 --- WebCore/platform/network/NetworkingContext.h | 1 - .../network/android/ResourceHandleAndroid.cpp | 6 +- .../network/android/ResourceLoaderAndroid.h | 2 +- .../WebCoreSupport/FrameLoaderClientAndroid.h | 7 +- .../FrameNetworkingContextAndroid.cpp | 5 - .../WebCoreSupport/FrameNetworkingContextAndroid.h | 1 - .../WebCoreSupport/ResourceLoaderAndroid.cpp | 9 +- WebKit/android/WebCoreSupport/WebCache.cpp | 2 + WebKit/android/WebCoreSupport/WebRequest.cpp | 3 +- WebKit/android/WebCoreSupport/WebRequest.h | 7 +- .../android/WebCoreSupport/WebRequestContext.cpp | 114 ++++++++------------- WebKit/android/WebCoreSupport/WebRequestContext.h | 15 ++- WebKit/android/WebCoreSupport/WebUrlLoader.cpp | 6 +- WebKit/android/WebCoreSupport/WebUrlLoader.h | 3 +- .../android/WebCoreSupport/WebUrlLoaderClient.cpp | 6 +- WebKit/android/WebCoreSupport/WebUrlLoaderClient.h | 3 +- .../WebCoreSupport/autofill/WebAutoFill.cpp | 4 +- WebKit/android/jni/WebSettings.cpp | 4 +- WebKit/android/jni/WebViewCore.cpp | 18 ++++ WebKit/android/jni/WebViewCore.h | 14 ++- 20 files changed, 111 insertions(+), 119 deletions(-) diff --git a/WebCore/platform/network/NetworkingContext.h b/WebCore/platform/network/NetworkingContext.h index 47ec87a0d..e0cb4c5d2 100644 --- a/WebCore/platform/network/NetworkingContext.h +++ b/WebCore/platform/network/NetworkingContext.h @@ -66,7 +66,6 @@ public: #if PLATFORM(ANDROID) virtual MainResourceLoader* mainResourceLoader() const = 0; - virtual bool isPrivateBrowsingEnabled() const = 0; virtual FrameLoaderClient* frameLoaderClient() const = 0; #endif diff --git a/WebCore/platform/network/android/ResourceHandleAndroid.cpp b/WebCore/platform/network/android/ResourceHandleAndroid.cpp index 8e426437e..412efda45 100644 --- a/WebCore/platform/network/android/ResourceHandleAndroid.cpp +++ b/WebCore/platform/network/android/ResourceHandleAndroid.cpp @@ -54,9 +54,8 @@ bool ResourceHandle::start(NetworkingContext* context) MainResourceLoader* mainLoader = context->mainResourceLoader(); bool isMainResource = static_cast(mainLoader) == static_cast(client()); - bool isPrivateBrowsing = context->isPrivateBrowsingEnabled(); - PassRefPtr loader = ResourceLoaderAndroid::start(this, d->m_firstRequest, context->frameLoaderClient(), isMainResource, false, isPrivateBrowsing); + PassRefPtr loader = ResourceLoaderAndroid::start(this, d->m_firstRequest, context->frameLoaderClient(), isMainResource, false); if (loader) { d->m_loader = loader; @@ -156,13 +155,12 @@ void ResourceHandle::loadResourceSynchronously(NetworkingContext* context, const { SyncLoader s(error, response, data); RefPtr h = adoptRef(new ResourceHandle(request, &s, false, false)); - bool isPrivateBrowsing = context->isPrivateBrowsingEnabled(); // This blocks until the load is finished. // Use the request owned by the ResourceHandle. This has had the username // and password (if present) stripped from the URL in // ResourceHandleInternal::ResourceHandleInternal(). This matches the // behaviour in the asynchronous case. - ResourceLoaderAndroid::start(h.get(), request, context->frameLoaderClient(), false, true, isPrivateBrowsing); + ResourceLoaderAndroid::start(h.get(), request, context->frameLoaderClient(), false, true); } } // namespace WebCore diff --git a/WebCore/platform/network/android/ResourceLoaderAndroid.h b/WebCore/platform/network/android/ResourceLoaderAndroid.h index 93617f446..f627d6240 100644 --- a/WebCore/platform/network/android/ResourceLoaderAndroid.h +++ b/WebCore/platform/network/android/ResourceLoaderAndroid.h @@ -37,7 +37,7 @@ class ResourceHandle; class ResourceLoaderAndroid : public RefCounted { public: - static PassRefPtr start(ResourceHandle*, const ResourceRequest&, FrameLoaderClient*, bool isMainResource, bool isSync, bool isPrivateBrowsing); + static PassRefPtr start(ResourceHandle*, const ResourceRequest&, FrameLoaderClient*, bool isMainResource, bool isSync); virtual ~ResourceLoaderAndroid() { } virtual void cancel() = 0; diff --git a/WebKit/android/WebCoreSupport/FrameLoaderClientAndroid.h b/WebKit/android/WebCoreSupport/FrameLoaderClientAndroid.h index 125b2fae4..964ac6e1a 100644 --- a/WebKit/android/WebCoreSupport/FrameLoaderClientAndroid.h +++ b/WebKit/android/WebCoreSupport/FrameLoaderClientAndroid.h @@ -168,8 +168,13 @@ namespace android { virtual PassRefPtr createDocumentLoader(const ResourceRequest&, const SubstituteData&); virtual void setTitle(const String& title, const KURL&); + // This provides the userAgent to WebCore. It is used by WebCore to + // populate navigator.userAgent and to set the HTTP header in + // ResourceRequest objects. We also set a userAgent on WebRequestContext + // for the Chromium HTTP stack, which overrides the value on the + // ResourceRequest. virtual String userAgent(const KURL&); - + virtual void savePlatformDataToCachedFrame(WebCore::CachedFrame*); virtual void transitionToCommittedFromCachedFrame(WebCore::CachedFrame*); virtual void transitionToCommittedForNewPage(); diff --git a/WebKit/android/WebCoreSupport/FrameNetworkingContextAndroid.cpp b/WebKit/android/WebCoreSupport/FrameNetworkingContextAndroid.cpp index 1d982cd63..a5fe49491 100644 --- a/WebKit/android/WebCoreSupport/FrameNetworkingContextAndroid.cpp +++ b/WebKit/android/WebCoreSupport/FrameNetworkingContextAndroid.cpp @@ -44,11 +44,6 @@ MainResourceLoader* FrameNetworkingContextAndroid::mainResourceLoader() const return frame()->loader()->activeDocumentLoader()->mainResourceLoader(); } -bool FrameNetworkingContextAndroid::isPrivateBrowsingEnabled() const -{ - return frame()->settings() && frame()->settings()->privateBrowsingEnabled(); -} - FrameLoaderClient* FrameNetworkingContextAndroid::frameLoaderClient() const { return frame()->loader()->client(); diff --git a/WebKit/android/WebCoreSupport/FrameNetworkingContextAndroid.h b/WebKit/android/WebCoreSupport/FrameNetworkingContextAndroid.h index d1b2ad2e9..d0ff9794f 100644 --- a/WebKit/android/WebCoreSupport/FrameNetworkingContextAndroid.h +++ b/WebKit/android/WebCoreSupport/FrameNetworkingContextAndroid.h @@ -46,7 +46,6 @@ private: FrameNetworkingContextAndroid(WebCore::Frame*); virtual WebCore::MainResourceLoader* mainResourceLoader() const; - virtual bool isPrivateBrowsingEnabled() const; virtual WebCore::FrameLoaderClient* frameLoaderClient() const; }; diff --git a/WebKit/android/WebCoreSupport/ResourceLoaderAndroid.cpp b/WebKit/android/WebCoreSupport/ResourceLoaderAndroid.cpp index d04d71a69..92a59a13a 100644 --- a/WebKit/android/WebCoreSupport/ResourceLoaderAndroid.cpp +++ b/WebKit/android/WebCoreSupport/ResourceLoaderAndroid.cpp @@ -26,23 +26,26 @@ #include #include +#include "Frame.h" #include "FrameLoaderClientAndroid.h" #include "WebCoreFrameBridge.h" #include "WebCoreResourceLoader.h" #include "WebUrlLoader.h" +#include "WebViewCore.h" using namespace android; namespace WebCore { PassRefPtr ResourceLoaderAndroid::start( - ResourceHandle* handle, const ResourceRequest& request, FrameLoaderClient* client, bool isMainResource, bool isSync, bool isPrivateBrowsing) + ResourceHandle* handle, const ResourceRequest& request, FrameLoaderClient* client, bool isMainResource, bool isSync) { // Called on main thread + FrameLoaderClientAndroid* clientAndroid = static_cast(client); #if USE(CHROME_NETWORK_STACK) - return WebUrlLoader::start(client, handle, request, isSync, isPrivateBrowsing); + WebViewCore* webViewCore = WebViewCore::getWebViewCore(clientAndroid->getFrame()->view()); + return WebUrlLoader::start(client, handle, request, isSync, webViewCore->webRequestContext()); #else - FrameLoaderClientAndroid* clientAndroid = static_cast (client); return clientAndroid->webFrame()->startLoadingResource(handle, request, isMainResource, isSync); #endif } diff --git a/WebKit/android/WebCoreSupport/WebCache.cpp b/WebKit/android/WebCoreSupport/WebCache.cpp index d062bdcd9..16ec70f45 100644 --- a/WebKit/android/WebCoreSupport/WebCache.cpp +++ b/WebKit/android/WebCoreSupport/WebCache.cpp @@ -57,6 +57,8 @@ static const std::string& rootDirectory() static std::string storageDirectory(bool isPrivateBrowsing) { + // TODO: Where is the right place to put the db for private browsing? Should + // it be kept in memory? static const char* const kDirectory = "/webviewCacheChromium"; static const char* const kDirectoryPrivate = "/webviewCacheChromiumPrivate"; diff --git a/WebKit/android/WebCoreSupport/WebRequest.cpp b/WebKit/android/WebCoreSupport/WebRequest.cpp index b7f2c8be9..468a3cd1c 100644 --- a/WebKit/android/WebCoreSupport/WebRequest.cpp +++ b/WebKit/android/WebCoreSupport/WebRequest.cpp @@ -145,7 +145,7 @@ void WebRequest::appendBytesToUpload(WTF::Vector* data) delete data; } -void WebRequest::start(bool isPrivateBrowsing) +void WebRequest::start(WebRequestContext* context) { ASSERT(m_loadState == Created, "Start called on a WebRequest not in CREATED state: (%s)", m_url.c_str()); @@ -161,7 +161,6 @@ void WebRequest::start(bool isPrivateBrowsing) if (m_request->url().SchemeIs("browser")) return handleBrowserURL(m_request->url()); - URLRequestContext* context = WebRequestContext::get(isPrivateBrowsing); m_request->set_context(context); m_request->Start(); diff --git a/WebKit/android/WebCoreSupport/WebRequest.h b/WebKit/android/WebCoreSupport/WebRequest.h index fb756ab9f..c78546c34 100644 --- a/WebKit/android/WebCoreSupport/WebRequest.h +++ b/WebKit/android/WebCoreSupport/WebRequest.h @@ -27,7 +27,7 @@ #define WebRequest_h #include "ChromiumIncludes.h" -#include "wtf/Vector.h" +#include class MessageLoop; @@ -44,8 +44,9 @@ enum LoadState { }; class UrlInterceptResponse; -class WebResourceRequest; class WebFrame; +class WebRequestContext; +class WebResourceRequest; class WebUrlLoaderClient; // All methods in this class must be called on the io thread @@ -65,7 +66,7 @@ public: void appendBytesToUpload(Vector* data); void appendFileToUpload(const std::string& filename); - void start(bool isPrivateBrowsing); + void start(WebRequestContext*); void cancel(); // From URLRequest::Delegate diff --git a/WebKit/android/WebCoreSupport/WebRequestContext.cpp b/WebKit/android/WebCoreSupport/WebRequestContext.cpp index 9d0f6c98c..3268abb50 100644 --- a/WebKit/android/WebCoreSupport/WebRequestContext.cpp +++ b/WebKit/android/WebCoreSupport/WebRequestContext.cpp @@ -34,49 +34,58 @@ #include #include -namespace { -// TODO: The userAgent should not be a static, as it can be set per WebView. -// http://b/3113804 -std::string userAgent(""); -Lock userAgentLock; - -std::string acceptLanguageStdString(""); -WTF::String acceptLanguageWtfString(""); -WTF::Mutex acceptLanguageMutex; -} +static std::string acceptLanguageStdString(""); +static WTF::String acceptLanguageWtfString(""); +static WTF::Mutex acceptLanguageMutex; + +static int numPrivateBrowsingInstances; +static WTF::Mutex numPrivateBrowsingInstancesMutex; using namespace WTF; namespace android { -static scoped_refptr privateBrowsingContext(0); -static WTF::Mutex privateBrowsingContextMutex; - -WebRequestContext::WebRequestContext() +WebRequestContext::WebRequestContext(bool isPrivateBrowsing) + : m_isPrivateBrowsing(isPrivateBrowsing) { + // Initialize chromium logging, needs to be done before any chromium code is called. + initChromiumLogging(); + + WebCache* cache = WebCache::get(m_isPrivateBrowsing); + host_resolver_ = cache->hostResolver(); + http_transaction_factory_ = cache->cache(); + + WebCookieJar* cookieJar = WebCookieJar::get(m_isPrivateBrowsing); + cookie_store_ = cookieJar->cookieStore(); + cookie_policy_ = cookieJar; + // Also hardcoded in FrameLoader.java accept_charset_ = "utf-8, iso-8859-1, utf-16, *;q=0.7"; + + if (m_isPrivateBrowsing) { + MutexLocker lock(numPrivateBrowsingInstancesMutex); + numPrivateBrowsingInstances++; + } } WebRequestContext::~WebRequestContext() { + if (m_isPrivateBrowsing) { + MutexLocker lock(numPrivateBrowsingInstancesMutex); + numPrivateBrowsingInstances--; + } } -void WebRequestContext::setUserAgent(String string) +void WebRequestContext::setUserAgent(const String& string) { - // The useragent is set on the WebCore thread and read on the network - // stack's IO thread. - AutoLock aLock(userAgentLock); - userAgent = string.utf8().data(); + MutexLocker lock(m_userAgentMutex); + m_userAgent = string.utf8().data(); } const std::string& WebRequestContext::GetUserAgent(const GURL& url) const { - // The useragent is set on the WebCore thread and read on the network - // stack's IO thread. - AutoLock aLock(userAgentLock); - ASSERT(userAgent != ""); - return userAgent; + MutexLocker lock(m_userAgentMutex); + return m_userAgent; } void WebRequestContext::setAcceptLanguage(const String& string) @@ -98,48 +107,6 @@ const String& WebRequestContext::acceptLanguage() return acceptLanguageWtfString; } -WebRequestContext* WebRequestContext::getImpl(bool isPrivateBrowsing) -{ - WebRequestContext* context = new WebRequestContext(); - - WebCache* cache = WebCache::get(isPrivateBrowsing); - context->host_resolver_ = cache->hostResolver(); - context->http_transaction_factory_ = cache->cache(); - - WebCookieJar* cookieJar = WebCookieJar::get(isPrivateBrowsing); - context->cookie_store_ = cookieJar->cookieStore(); - context->cookie_policy_ = cookieJar; - - return context; -} - -WebRequestContext* WebRequestContext::getRegularContext() -{ - static scoped_refptr regularContext(0); - if (!regularContext) - regularContext = getImpl(false); - return regularContext; -} - -WebRequestContext* WebRequestContext::getPrivateBrowsingContext() -{ - MutexLocker lock(privateBrowsingContextMutex); - - // TODO: Where is the right place to put the temporary db? Should it be - // kept in memory? - if (!privateBrowsingContext) - privateBrowsingContext = getImpl(true); - return privateBrowsingContext; -} - -WebRequestContext* WebRequestContext::get(bool isPrivateBrowsing) -{ - // Initialize chromium logging, needs to be done before any chromium code is called - initChromiumLogging(); - - return isPrivateBrowsing ? getPrivateBrowsingContext() : getRegularContext(); -} - void WebRequestContext::removeFileOrDirectory(const char* filename) { struct stat filetype; @@ -169,16 +136,15 @@ bool WebRequestContext::cleanupPrivateBrowsingFiles() // This is called on the UI thread. // TODO: This should be done on a different thread. Moving to the WebKit // thread should be straightforward and safe. See b/3243891. - MutexLocker lock(privateBrowsingContextMutex); + MutexLocker lock(numPrivateBrowsingInstancesMutex); - if (!privateBrowsingContext || privateBrowsingContext->HasOneRef()) { - privateBrowsingContext = 0; + // If there are private browsing contexts in use, do nothing. + if (numPrivateBrowsingInstances) + return false; - WebCookieJar::cleanup(true); - WebCache::cleanup(true); - return true; - } - return false; + WebCookieJar::cleanup(true); + WebCache::cleanup(true); + return true; } } // namespace android diff --git a/WebKit/android/WebCoreSupport/WebRequestContext.h b/WebKit/android/WebCoreSupport/WebRequestContext.h index ec1561bdd..5827ce2bc 100644 --- a/WebKit/android/WebCoreSupport/WebRequestContext.h +++ b/WebKit/android/WebCoreSupport/WebRequestContext.h @@ -33,20 +33,18 @@ namespace android { -// This class is generally not threadsafe. .get() is not threadsafe - instances -// are created on the WebCore thread only. +// This class is generally not threadsafe. class WebRequestContext : public URLRequestContext { public: // URLRequestContext overrides. virtual const std::string& GetUserAgent(const GURL&) const; virtual const std::string& GetAcceptLanguage() const; - // Lazily create the relevant context. This class holds a reference. - static WebRequestContext* get(bool isPrivateBrowsing); + WebRequestContext(bool isPrivateBrowsing); // These methods are threadsafe. static bool cleanupPrivateBrowsingFiles(); - static void setUserAgent(WTF::String); + void setUserAgent(const WTF::String&); static void setAcceptLanguage(const WTF::String&); static const WTF::String& acceptLanguage(); @@ -59,10 +57,9 @@ private: WebRequestContext(); ~WebRequestContext(); - static WebRequestContext* getImpl(bool isPrivateBrowsing); - static WebRequestContext* getRegularContext(); - static WebRequestContext* getPrivateBrowsingContext(); - + std::string m_userAgent; + mutable WTF::Mutex m_userAgentMutex; + bool m_isPrivateBrowsing; }; } // namespace android diff --git a/WebKit/android/WebCoreSupport/WebUrlLoader.cpp b/WebKit/android/WebCoreSupport/WebUrlLoader.cpp index 8c943a099..f634633ec 100644 --- a/WebKit/android/WebCoreSupport/WebUrlLoader.cpp +++ b/WebKit/android/WebCoreSupport/WebUrlLoader.cpp @@ -44,8 +44,8 @@ WebUrlLoader::~WebUrlLoader() { } -PassRefPtr WebUrlLoader::start(FrameLoaderClient* client, WebCore::ResourceHandle* resourceHandle, - const WebCore::ResourceRequest& resourceRequest, bool isSync, bool isPrivateBrowsing) +PassRefPtr WebUrlLoader::start(FrameLoaderClient* client, WebCore::ResourceHandle* resourceHandle, + const WebCore::ResourceRequest& resourceRequest, bool isSync, WebRequestContext* context) { FrameLoaderClientAndroid* androidClient = static_cast(client); WebFrame* webFrame = androidClient->webFrame(); @@ -58,7 +58,7 @@ PassRefPtr WebUrlLoader::start(FrameLoaderClient* client, WebCore: webFrame->maybeSavePassword(androidClient->getFrame(), resourceRequest); RefPtr loader = WebUrlLoader::create(webFrame, resourceHandle, resourceRequest); - loader->m_loaderClient->start(isSync, isPrivateBrowsing); + loader->m_loaderClient->start(isSync, context); return loader.release(); } diff --git a/WebKit/android/WebCoreSupport/WebUrlLoader.h b/WebKit/android/WebCoreSupport/WebUrlLoader.h index 2e76c1452..d9515f890 100644 --- a/WebKit/android/WebCoreSupport/WebUrlLoader.h +++ b/WebKit/android/WebCoreSupport/WebUrlLoader.h @@ -34,11 +34,12 @@ using namespace WebCore; namespace android { class WebUrlLoaderClient; class WebFrame; +class WebRequestContext; class WebUrlLoader : public ResourceLoaderAndroid { public: virtual ~WebUrlLoader(); - static PassRefPtr start(FrameLoaderClient* client, WebCore::ResourceHandle*, const WebCore::ResourceRequest&, bool sync, bool isPrivateBrowsing); + static PassRefPtr start(FrameLoaderClient* client, WebCore::ResourceHandle*, const WebCore::ResourceRequest&, bool sync, WebRequestContext*); virtual void cancel(); virtual void downloadFile(); diff --git a/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp b/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp index d7df2796f..50defc23d 100644 --- a/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp +++ b/WebKit/android/WebCoreSupport/WebUrlLoaderClient.cpp @@ -147,7 +147,7 @@ WebUrlLoaderClient::WebUrlLoaderClient(WebFrame* webFrame, WebCore::ResourceHand } } -bool WebUrlLoaderClient::start(bool sync, bool isPrivateBrowsing) +bool WebUrlLoaderClient::start(bool sync, WebRequestContext* context) { base::Thread* thread = ioThread(); if (!thread) { @@ -157,7 +157,7 @@ bool WebUrlLoaderClient::start(bool sync, bool isPrivateBrowsing) m_sync = sync; if (m_sync) { AutoLock autoLock(*syncLock()); - thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(m_request.get(), &WebRequest::start, isPrivateBrowsing)); + thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(m_request.get(), &WebRequest::start, context)); // Run callbacks until the queue is exhausted and m_finished is true. while(!m_finished) { @@ -176,7 +176,7 @@ bool WebUrlLoaderClient::start(bool sync, bool isPrivateBrowsing) m_resourceHandle = 0; } else { // Asynchronous start. - thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(m_request.get(), &WebRequest::start, isPrivateBrowsing)); + thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(m_request.get(), &WebRequest::start, context)); } return true; } diff --git a/WebKit/android/WebCoreSupport/WebUrlLoaderClient.h b/WebKit/android/WebCoreSupport/WebUrlLoaderClient.h index 56d4289ac..d69bea699 100644 --- a/WebKit/android/WebCoreSupport/WebUrlLoaderClient.h +++ b/WebKit/android/WebCoreSupport/WebUrlLoaderClient.h @@ -52,6 +52,7 @@ namespace android { class WebFrame; class WebRequest; +class WebRequestContext; // This class handles communication between the IO thread where loading happens // and the webkit main thread. @@ -65,7 +66,7 @@ public: WebUrlLoaderClient(WebFrame*, WebCore::ResourceHandle*, const WebCore::ResourceRequest&); // Called from WebCore, will be forwarded to the IO thread - bool start(bool sync, bool isPrivateBrowsing); + bool start(bool sync, WebRequestContext*); void cancel(); void downloadFile(); void pauseLoad(bool pause) {} // Android method, does nothing for now diff --git a/WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp b/WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp index 73a846042..2d92b4b7e 100644 --- a/WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp +++ b/WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp @@ -61,7 +61,9 @@ void WebAutoFill::init() return; mFormManager = new FormManager(); - AndroidURLRequestContextGetter::Get()->SetURLRequestContext(WebRequestContext::get(false /* isPrivateBrowsing */)); + // We use the WebView's WebRequestContext, which may be a private browsing context. + ASSERT(mWebViewCore); + AndroidURLRequestContextGetter::Get()->SetURLRequestContext(mWebViewCore->webRequestContext()); AndroidURLRequestContextGetter::Get()->SetIOThread(WebUrlLoaderClient::ioThread()); mTabContents = new TabContents(); mAutoFillManager = new AutoFillManager(mTabContents.get()); diff --git a/WebKit/android/jni/WebSettings.cpp b/WebKit/android/jni/WebSettings.cpp index 737f10772..6b40b65b0 100644 --- a/WebKit/android/jni/WebSettings.cpp +++ b/WebKit/android/jni/WebSettings.cpp @@ -51,6 +51,7 @@ #include "WorkerContextExecutionProxy.h" #endif #include "WebRequestContext.h" +#include "WebViewCore.h" #include #include @@ -364,7 +365,8 @@ public: str = (jstring)env->GetObjectField(obj, gFieldIds->mUserAgent); WebFrame::getWebFrame(pFrame)->setUserAgent(jstringToWtfString(env, str)); #if USE(CHROME_NETWORK_STACK) - WebRequestContext::setUserAgent(jstringToWtfString(env, str)); + WebViewCore::getWebViewCore(pFrame->view())->setWebRequestContextUserAgent(); + str = (jstring)env->GetObjectField(obj, gFieldIds->mAcceptLanguage); WebRequestContext::setAcceptLanguage(jstringToWtfString(env, str)); #endif diff --git a/WebKit/android/jni/WebViewCore.cpp b/WebKit/android/jni/WebViewCore.cpp index 82ec3e242..ed397d3d0 100644 --- a/WebKit/android/jni/WebViewCore.cpp +++ b/WebKit/android/jni/WebViewCore.cpp @@ -3336,6 +3336,24 @@ bool WebViewCore::drawIsPaused() const gWebViewCoreFields.m_drawIsPaused); } +#if USE(CHROME_NETWORK_STACK) +void WebViewCore::setWebRequestContextUserAgent() +{ + if (m_webRequestContext) + m_webRequestContext->setUserAgent(WebFrame::getWebFrame(m_mainFrame)->userAgentForURL(0)); // URL not used +} + +WebRequestContext* WebViewCore::webRequestContext() +{ + if (!m_webRequestContext) { + Settings* settings = mainFrame()->settings(); + m_webRequestContext = new WebRequestContext(settings && settings->privateBrowsingEnabled()); + setWebRequestContextUserAgent(); + } + return m_webRequestContext.get(); +} +#endif + //---------------------------------------------------------------------- // Native JNI methods //---------------------------------------------------------------------- diff --git a/WebKit/android/jni/WebViewCore.h b/WebKit/android/jni/WebViewCore.h index 53cca797c..427826177 100644 --- a/WebKit/android/jni/WebViewCore.h +++ b/WebKit/android/jni/WebViewCore.h @@ -26,12 +26,11 @@ #ifndef WEBVIEWCORE_H #define WEBVIEWCORE_H -#include "android_npapi.h" -#include "FileChooser.h" #include "CacheBuilder.h" #include "CachedHistory.h" #include "DeviceMotionAndOrientationManager.h" #include "DOMSelection.h" +#include "FileChooser.h" #include "PictureSet.h" #include "PlatformGraphicsContext.h" #include "SkColor.h" @@ -40,6 +39,9 @@ #include "Timer.h" #include "WebCoreRefObject.h" #include "WebCoreJni.h" +#include "WebRequestContext.h" +#include "android_npapi.h" + #include #include #include @@ -536,6 +538,8 @@ namespace android { bool isPaused() const { return m_isPaused; } void setIsPaused(bool isPaused) { m_isPaused = isPaused; } bool drawIsPaused() const; + void setWebRequestContextUserAgent(); + WebRequestContext* webRequestContext(); // end of shared members // internal functions @@ -619,16 +623,16 @@ namespace android { bool setSelection(DOMSelection* selection, Text* textNode, int direction); bool setSelection(DOMSelection* selection, Node* startNode, Node* endNode, int startOffset, int endOffset); Node* m_currentNodeDomNavigationAxis; - #if ENABLE(TOUCH_EVENTS) bool m_forwardingTouchEvents; #endif - #if DEBUG_NAV_UI uint32_t m_now; #endif - DeviceMotionAndOrientationManager m_deviceMotionAndOrientationManager; +#if USE(CHROME_NETWORK_STACK) + scoped_refptr m_webRequestContext; +#endif private: // called from constructor, to add this to a global list -- 2.11.0