Title: [149182] trunk/Source/WebKit/blackberry
Revision
149182
Author
mary...@torchmobile.com.cn
Date
2013-04-26 06:59:15 -0700 (Fri, 26 Apr 2013)

Log Message

[BlackBerry] Should check if it's cached resource before download
https://bugs.webkit.org/show_bug.cgi?id=115101

Reviewed by Rob Buis.

Since main resource maybe cached, if user want to save the resource, we first check
if it's cached. If yes, don't need to initiate a fresh load again, but get the
cached resource data out to save.

RIM bug# 324003, internally reviewed by Charles Wei.

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

Modified Paths

Diff

Modified: trunk/Source/WebKit/blackberry/ChangeLog (149181 => 149182)


--- trunk/Source/WebKit/blackberry/ChangeLog	2013-04-26 13:20:55 UTC (rev 149181)
+++ trunk/Source/WebKit/blackberry/ChangeLog	2013-04-26 13:59:15 UTC (rev 149182)
@@ -1,5 +1,21 @@
 2013-04-26  Mary Wu  <mary...@torchmobile.com.cn>
 
+        [BlackBerry] Should check if it's cached resource before download
+        https://bugs.webkit.org/show_bug.cgi?id=115101
+
+        Reviewed by Rob Buis.
+
+        Since main resource maybe cached, if user want to save the resource, we first check
+        if it's cached. If yes, don't need to initiate a fresh load again, but get the
+        cached resource data out to save.
+
+        RIM bug# 324003, internally reviewed by Charles Wei.
+
+        * WebCoreSupport/FrameLoaderClientBlackBerry.cpp:
+        (WebCore::FrameLoaderClientBlackBerry::convertMainResourceLoadToDownload):
+
+2013-04-26  Mary Wu  <mary...@torchmobile.com.cn>
+
         [BlackBerry] Clean up load interface in WebPage
         https://bugs.webkit.org/show_bug.cgi?id=113267
 

Modified: trunk/Source/WebKit/blackberry/WebCoreSupport/FrameLoaderClientBlackBerry.cpp (149181 => 149182)


--- trunk/Source/WebKit/blackberry/WebCoreSupport/FrameLoaderClientBlackBerry.cpp	2013-04-26 13:20:55 UTC (rev 149181)
+++ trunk/Source/WebKit/blackberry/WebCoreSupport/FrameLoaderClientBlackBerry.cpp	2013-04-26 13:59:15 UTC (rev 149182)
@@ -50,6 +50,7 @@
 #include "PluginDatabase.h"
 #include "PluginView.h"
 #include "ProgressTracker.h"
+#include "ResourceBuffer.h"
 #include "ScopePointer.h"
 #if ENABLE(BLACKBERRY_CREDENTIAL_PERSIST)
 #include "Settings.h"
@@ -69,7 +70,9 @@
 #include <BlackBerryPlatformLog.h>
 #include <BlackBerryPlatformMessageClient.h>
 #include <BlackBerryPlatformScreen.h>
+#include <BlackBerryPlatformStringBuilder.h>
 #include <_javascript_Core/APICast.h>
+#include <network/DataStream.h>
 #include <network/FilterStream.h>
 #include <network/NetworkRequest.h>
 #include <wtf/text/Base64.h>
@@ -1187,21 +1190,44 @@
     m_webPagePrivate->load(request.url().string(), BlackBerry::Platform::String::emptyString(), "GET", NetworkRequest::UseProtocolCachePolicy, 0, 0, 0, 0, false, false, true, "", suggestedName);
 }
 
-void FrameLoaderClientBlackBerry::convertMainResourceLoadToDownload(DocumentLoader* documentLoader, const ResourceRequest& request, const ResourceResponse& r)
+void FrameLoaderClientBlackBerry::convertMainResourceLoadToDownload(DocumentLoader* documentLoader, const ResourceRequest& request, const ResourceResponse& response)
 {
-    BlackBerry::Platform::FilterStream* stream = NetworkManager::instance()->streamForHandle(documentLoader->mainResourceLoader()->handle());
-    // There are cases where there won't have a FilterStream
-    // associated with a ResourceHandle. For instance, Blob objects
-    // have their own ResourceHandle class which won't call startJob
-    // to do the proper setup. Do it here.
-    if (!stream) {
-        int playerId = static_cast<FrameLoaderClientBlackBerry*>(m_frame->loader()->client())->playerId();
-        NetworkManager::instance()->startJob(playerId, documentLoader->mainResourceLoader()->handle(), request, m_frame, false);
-        stream = NetworkManager::instance()->streamForHandle(documentLoader->mainResourceLoader()->handle());
+    ASSERT(documentLoader);
+    ResourceBuffer* buff = documentLoader->mainResourceData().get();
+
+    if (!buff) {
+        // If no cached, like policyDownload resource which don't go render at all, just direct to downloadStream.
+        ASSERT(documentLoader->mainResourceLoader() && documentLoader->mainResourceLoader()->handle());
+        ResourceHandle* handle = documentLoader->mainResourceLoader()->handle();
+        BlackBerry::Platform::FilterStream* stream = NetworkManager::instance()->streamForHandle(handle);
+        // There are cases where there won't have a FilterStream
+        // associated with a ResourceHandle. For instance, Blob objects
+        // have their own ResourceHandle class which won't call startJob
+        // to do the proper setup. Do it here.
+        if (!stream) {
+            int playerId = static_cast<FrameLoaderClientBlackBerry*>(m_frame->loader()->client())->playerId();
+            NetworkManager::instance()->startJob(playerId, handle, request, m_frame, false);
+            stream = NetworkManager::instance()->streamForHandle(handle);
+        }
+        ASSERT(stream);
+
+        m_webPagePrivate->m_client->downloadRequested(stream, response.suggestedFilename());
+        return;
     }
-    ASSERT(stream);
 
-    m_webPagePrivate->m_client->downloadRequested(stream, r.suggestedFilename());
+    // For main page resource which has cached, get from cached resource.
+    BlackBerry::Platform::StringBuilder url;
+    STATIC_LOCAL_STRING(s_create, "data:");
+    url.append(s_create);
+    url.append(BlackBerry::Platform::String::fromUtf8(response.mimeType().utf8().data()));
+    STATIC_LOCAL_STRING(s_base64, ";base64,");
+    url.append(s_base64);
+    url.append(BlackBerry::Platform::String::fromUtf8(base64Encode(CString(buff->data(), buff->size())).utf8().data()));
+    NetworkRequest req;
+    req.setRequestUrl(url.string(), BlackBerry::Platform::String::fromAscii("GET"));
+    BlackBerry::Platform::DataStream *stream = new BlackBerry::Platform::DataStream(req);
+    m_webPagePrivate->m_client->downloadRequested(stream, response.suggestedFilename());
+    stream->streamOpen();
 }
 
 void FrameLoaderClientBlackBerry::dispatchDidReceiveIcon()
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to