[BlackBerry] Set correct ResourceRequest target type.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Mar 2012 07:24:58 +0000 (07:24 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Mar 2012 07:24:58 +0000 (07:24 +0000)
https://bugs.webkit.org/show_bug.cgi?id=80430

Patch by Lianghui Chen <liachen@rim.com> on 2012-03-06
Reviewed by Rob Buis.

Source/WebCore:

For loads started by AppCache, they are based on the manifest file,
it is not definitely sure what target it is for, so we just guess
based on its mimetype or file extension.

* loader/appcache/ApplicationCacheGroup.cpp:
(WebCore::ApplicationCacheGroup::createResourceHandle):
* loader/cache/CachedResource.cpp:
(WebCore):
(WebCore::CachedResource::load):
* platform/network/blackberry/ResourceRequest.h:
(ResourceRequest):
* platform/network/blackberry/ResourceRequestBlackBerry.cpp:
(WebCore):
(WebCore::mimeTypeRequestTypeMap):
(WebCore::ResourceRequest::targetTypeFromMimeType):
* workers/DefaultSharedWorkerRepository.cpp:
(WebCore::SharedWorkerScriptLoader::load):
* workers/Worker.cpp:
(WebCore::Worker::create):
* workers/WorkerContext.cpp:
(WebCore::WorkerContext::importScripts):
* workers/WorkerScriptLoader.cpp:
(WebCore::WorkerScriptLoader::createResourceRequest):
* workers/WorkerScriptLoader.h:
(WorkerScriptLoader):

Source/WebKit/blackberry:

Removed unused code in dispatchWillSendRequest(). These codes are too
late as the target type has already been referred to when calling
ResourceRequest::initializePlatformRequest().

* WebCoreSupport/FrameLoaderClientBlackBerry.cpp:
(WebCore::FrameLoaderClientBlackBerry::dispatchWillSendRequest):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@110023 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
Source/WebCore/ChangeLog
Source/WebCore/loader/appcache/ApplicationCacheGroup.cpp
Source/WebCore/loader/cache/CachedResource.cpp
Source/WebCore/platform/network/blackberry/ResourceRequest.h
Source/WebCore/platform/network/blackberry/ResourceRequestBlackBerry.cpp
Source/WebCore/workers/DefaultSharedWorkerRepository.cpp
Source/WebCore/workers/Worker.cpp
Source/WebCore/workers/WorkerContext.cpp
Source/WebCore/workers/WorkerScriptLoader.cpp
Source/WebCore/workers/WorkerScriptLoader.h
Source/WebKit/blackberry/ChangeLog
Source/WebKit/blackberry/WebCoreSupport/FrameLoaderClientBlackBerry.cpp

index 5b7c73666faa1746a400133ed51bcea283b391dc..7b7789cfeed9f0b489f1c4aea8ca8db60fe23b5b 100644 (file)
@@ -1,3 +1,36 @@
+2012-03-06  Lianghui Chen  <liachen@rim.com>
+
+        [BlackBerry] Set correct ResourceRequest target type.
+        https://bugs.webkit.org/show_bug.cgi?id=80430
+
+        Reviewed by Rob Buis.
+
+        For loads started by AppCache, they are based on the manifest file,
+        it is not definitely sure what target it is for, so we just guess
+        based on its mimetype or file extension.
+
+        * loader/appcache/ApplicationCacheGroup.cpp:
+        (WebCore::ApplicationCacheGroup::createResourceHandle):
+        * loader/cache/CachedResource.cpp:
+        (WebCore):
+        (WebCore::CachedResource::load):
+        * platform/network/blackberry/ResourceRequest.h:
+        (ResourceRequest):
+        * platform/network/blackberry/ResourceRequestBlackBerry.cpp:
+        (WebCore):
+        (WebCore::mimeTypeRequestTypeMap):
+        (WebCore::ResourceRequest::targetTypeFromMimeType):
+        * workers/DefaultSharedWorkerRepository.cpp:
+        (WebCore::SharedWorkerScriptLoader::load):
+        * workers/Worker.cpp:
+        (WebCore::Worker::create):
+        * workers/WorkerContext.cpp:
+        (WebCore::WorkerContext::importScripts):
+        * workers/WorkerScriptLoader.cpp:
+        (WebCore::WorkerScriptLoader::createResourceRequest):
+        * workers/WorkerScriptLoader.h:
+        (WorkerScriptLoader):
+
 2012-03-06  Dana Jansens  <danakj@chromium.org>
 
         [chromium] Add clipping to scissor rect to CCOcclusionTracker
index 013a78ddd29a6fbe043fc19066b03f5bc2e303a1..e6229c44d54600cf54a6cb54ca36ba3821ede206 100644 (file)
@@ -490,6 +490,22 @@ PassRefPtr<ResourceHandle> ApplicationCacheGroup::createResourceHandle(const KUR
         }
     }
 
+#if PLATFORM(BLACKBERRY)
+    ResourceRequest::TargetType target = ResourceRequest::TargetIsUnspecified;
+    if (newestCachedResource) {
+        const String& mimeType = newestCachedResource->response().mimeType();
+        if (!mimeType.isEmpty())
+            target = ResourceRequest::targetTypeFromMimeType(mimeType);
+    }
+    if (target == ResourceRequest::TargetIsUnspecified) {
+        String mimeType = mimeTypeFromDataURL(url);
+        if (!mimeType.isEmpty())
+            target = ResourceRequest::targetTypeFromMimeType(mimeType);
+    }
+
+    request.setTargetType(target);
+#endif
+
     RefPtr<ResourceHandle> handle = ResourceHandle::create(m_frame->loader()->networkingContext(), request, this, false, true);
 #if ENABLE(INSPECTOR)
     // Because willSendRequest only gets called during redirects, we initialize
index e9c6198040b41371d9e9aafd58bd7d9222a84acd..a74dbd6aa41c51aaebc4f84c9bc927acd0e6f7a3 100755 (executable)
@@ -91,7 +91,7 @@ static ResourceLoadPriority defaultPriorityForResourceType(CachedResource::Type
     return ResourceLoadPriorityLow;
 }
 
-#if PLATFORM(CHROMIUM)
+#if PLATFORM(CHROMIUM) || PLATFORM(BLACKBERRY)
 static ResourceRequest::TargetType cachedResourceTypeToTargetType(CachedResource::Type type)
 {
     switch (type) {
@@ -191,7 +191,7 @@ void CachedResource::load(CachedResourceLoader* cachedResourceLoader, const Reso
     m_options = options;
     m_loading = true;
 
-#if PLATFORM(CHROMIUM)
+#if PLATFORM(CHROMIUM) || PLATFORM(BLACKBERRY)
     if (m_resourceRequest.targetType() == ResourceRequest::TargetIsUnspecified)
         m_resourceRequest.setTargetType(cachedResourceTypeToTargetType(type()));
 #endif
index cd9760db48261be6ff8192f6ab124b7a8267399d..7072eb1f35134adc3641bd1541b16cdac18017ab 100644 (file)
@@ -118,6 +118,8 @@ public:
     TargetType targetType() const { return m_targetType; }
     void setTargetType(TargetType type) { m_targetType = type; }
 
+    static TargetType targetTypeFromMimeType(const String& mimeType);
+
 private:
     friend class ResourceRequestBase;
 
index d86b88cf1dbc1deea4e8596a3954335e22aef266..5b6792fa7f1226cd098be9ee26b82bd7f3cdbdfd 100644 (file)
@@ -22,6 +22,7 @@
 #include "BlobRegistryImpl.h"
 #include <BlackBerryPlatformClient.h>
 #include <network/NetworkRequest.h>
+#include <wtf/HashMap.h>
 #include <wtf/text/CString.h>
 
 using BlackBerry::Platform::NetworkRequest;
@@ -84,6 +85,47 @@ static inline NetworkRequest::TargetType platformTargetTypeForRequest(const Reso
     }
 }
 
+typedef HashMap<String, ResourceRequest::TargetType> MimeTypeResourceRequestTypeMap;
+
+static const MimeTypeResourceRequestTypeMap& mimeTypeRequestTypeMap()
+{
+    static MimeTypeResourceRequestTypeMap* map = 0;
+    if (!map) {
+        map = new MimeTypeResourceRequestTypeMap;
+
+        if (map) {
+            // The list here should match extensionMap[] in MIMETypeRegistryBlackBerry.cpp
+            map->add(String("text/css"), ResourceRequest::TargetIsStyleSheet);
+            map->add(String("application/x-javascript"), ResourceRequest::TargetIsScript);
+            map->add(String("image/bmp"), ResourceRequest::TargetIsImage);
+            map->add(String("image/gif"), ResourceRequest::TargetIsImage);
+            map->add(String("image/x-icon"), ResourceRequest::TargetIsImage);
+            map->add(String("image/jpeg"), ResourceRequest::TargetIsImage);
+            map->add(String("image/png"), ResourceRequest::TargetIsImage);
+            map->add(String("image/x-portable-bitmap"), ResourceRequest::TargetIsImage);
+            map->add(String("image/x-portable-graymap"), ResourceRequest::TargetIsImage);
+            map->add(String("image/x-portable-pixmap"), ResourceRequest::TargetIsImage);
+            map->add(String("image/svg+xml"), ResourceRequest::TargetIsImage);
+            map->add(String("image/tiff"), ResourceRequest::TargetIsImage);
+            map->add(String("image/x-xbitmap"), ResourceRequest::TargetIsImage);
+            map->add(String("image/x-xpm"), ResourceRequest::TargetIsImage);
+        }
+    }
+
+    return *map;
+}
+
+ResourceRequest::TargetType ResourceRequest::targetTypeFromMimeType(const String& mimeType)
+{
+    const MimeTypeResourceRequestTypeMap& map = mimeTypeRequestTypeMap();
+
+    MimeTypeResourceRequestTypeMap::const_iterator iter = map.find(mimeType);
+    if (iter == map.end())
+        return ResourceRequest::TargetIsUnspecified;
+
+    return iter->second;
+}
+
 void ResourceRequest::initializePlatformRequest(NetworkRequest& platformRequest, bool isInitial) const
 {
     // If this is the initial load, skip the request body and headers.
index 4ae30e4e3dee537a4f07907c862895533fe78eb1..773ccd95d7f7c6b7041ff397a86b6c436819c1d9 100644 (file)
@@ -298,7 +298,7 @@ void SharedWorkerScriptLoader::load(const KURL& url)
 
     // Mark this object as active for the duration of the load.
     m_scriptLoader = WorkerScriptLoader::create();
-#if PLATFORM(CHROMIUM)
+#if PLATFORM(CHROMIUM) || PLATFORM(BLACKBERRY)
     m_scriptLoader->setTargetType(ResourceRequest::TargetIsSharedWorker);
 #endif
     m_scriptLoader->loadAsynchronously(m_worker->scriptExecutionContext(), url, DenyCrossOriginRequests, this);
index ec965a4e7b6f598dcc713b3fac65c86b4eb78d56..1d440f5485b69354d53b17204340773170779e08 100644 (file)
@@ -70,7 +70,7 @@ PassRefPtr<Worker> Worker::create(ScriptExecutionContext* context, const String&
     worker->setPendingActivity(worker.get());
 
     worker->m_scriptLoader = WorkerScriptLoader::create();
-#if PLATFORM(CHROMIUM)
+#if PLATFORM(CHROMIUM) || PLATFORM(BLACKBERRY)
     worker->m_scriptLoader->setTargetType(ResourceRequest::TargetIsWorker);
 #endif
     worker->m_scriptLoader->loadAsynchronously(context, scriptURL, DenyCrossOriginRequests, worker.get());
index ed3438843675c3c41790920eb0236964efa34a2b..f72f09f97b3032838d2ba0237c783111a8a112ac 100644 (file)
@@ -243,7 +243,7 @@ void WorkerContext::importScripts(const Vector<String>& urls, ExceptionCode& ec)
 
     for (Vector<KURL>::const_iterator it = completedURLs.begin(); it != end; ++it) {
         RefPtr<WorkerScriptLoader> scriptLoader(WorkerScriptLoader::create());
-#if PLATFORM(CHROMIUM)
+#if PLATFORM(CHROMIUM) || PLATFORM(BLACKBERRY)
         scriptLoader->setTargetType(ResourceRequest::TargetIsScript);
 #endif
         scriptLoader->loadSynchronously(scriptExecutionContext(), *it, AllowCrossOriginRequests);
index 95476f878504d8d4e582aa55884fa6bdefb3100c..3296f4e540c55d34c5e53addea835ffbbc20ed91 100644 (file)
@@ -109,7 +109,7 @@ PassOwnPtr<ResourceRequest> WorkerScriptLoader::createResourceRequest()
 {
     OwnPtr<ResourceRequest> request = adoptPtr(new ResourceRequest(m_url));
     request->setHTTPMethod("GET");
-#if PLATFORM(CHROMIUM)
+#if PLATFORM(CHROMIUM) || PLATFORM(BLACKBERRY)
     request->setTargetType(m_targetType);
 #endif
     return request.release();
index d6e7de37bbbf6cd18f03aaaa19ee94adbf127db4..85c4ea81fc548765b6b3698203f0e78c1f32543b 100644 (file)
@@ -72,7 +72,7 @@ namespace WebCore {
         virtual void didFail(const ResourceError&);
         virtual void didFailRedirectCheck();
 
-#if PLATFORM(CHROMIUM)
+#if PLATFORM(CHROMIUM) || PLATFORM(BLACKBERRY)
         void setTargetType(ResourceRequest::TargetType targetType) { m_targetType = targetType; }
 #endif
 
index eea93a1a0598e9c9dd11ff11402945a276c6b954..7b99329c62e54107ea37aa2a021a337bc3c033fc 100644 (file)
@@ -1,3 +1,17 @@
+2012-03-06  Lianghui Chen  <liachen@rim.com>
+
+        [BlackBerry] Set correct ResourceRequest target type.
+        https://bugs.webkit.org/show_bug.cgi?id=80430
+
+        Reviewed by Rob Buis.
+
+        Removed unused code in dispatchWillSendRequest(). These codes are too
+        late as the target type has already been referred to when calling
+        ResourceRequest::initializePlatformRequest().
+
+        * WebCoreSupport/FrameLoaderClientBlackBerry.cpp:
+        (WebCore::FrameLoaderClientBlackBerry::dispatchWillSendRequest):
+
 2012-03-06  Lianghui Chen  <liachen@rim.com>
 
         [BlackBerry] Remove unused and unneeded WebPageClient::downloadRequested(NetworkRequest&)
index 7ab1e71b7ef134109d38022bffde1fd6a9e7c217..0eef1f3daf78ec2fbe9beb7bf86573457d821831 100644 (file)
@@ -969,12 +969,6 @@ void FrameLoaderClientBlackBerry::dispatchWillSendRequest(DocumentLoader* docLoa
             finalUrl.characters(), finalUrl.length());
     }
 
-    // FIXME: Update the request type. See PR #119792.
-    if (docLoader->frameLoader()->isLoadingMainFrame())
-        request.setTargetType(ResourceRequest::TargetIsMainFrame);
-    else
-        request.setTargetType(ResourceRequest::TargetIsSubframe);
-
     FrameLoader* loader = m_frame->loader();
     ASSERT(loader);
     if (isBackForwardLoadType(loader->loadType())) {