[Qt][WK2] Implement decidePolicyForResponse in our PolicyClient
authorjesus@webkit.org <jesus@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 17 Oct 2011 12:41:23 +0000 (12:41 +0000)
committerjesus@webkit.org <jesus@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 17 Oct 2011 12:41:23 +0000 (12:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=69832

Reviewed by Kenneth Rohde Christiansen.

We implement decidePolicyForResponse in our PolicyClient in order to
decide whether a given ResourceResponse should be downloaded or loaded.

* Shared/qt/WebCoreArgumentCodersQt.cpp:
(CoreIPC::::encode):
(CoreIPC::::decode):
Implement serialization of ResourceResponse.

* UIProcess/qt/ClientImpl.cpp:
(qt_wk_decidePolicyForResponse):
* UIProcess/qt/ClientImpl.h:
* UIProcess/qt/QtWebPageProxy.cpp:
(QtWebPageProxy::init):

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

Source/WebKit2/ChangeLog
Source/WebKit2/Shared/qt/WebCoreArgumentCodersQt.cpp
Source/WebKit2/UIProcess/qt/ClientImpl.cpp
Source/WebKit2/UIProcess/qt/ClientImpl.h
Source/WebKit2/UIProcess/qt/QtWebPageProxy.cpp

index c737041..6d66452 100644 (file)
@@ -1,3 +1,24 @@
+2011-10-14  Jesus Sanchez-Palencia  <jesus.palencia@openbossa.org>
+
+        [Qt][WK2] Implement decidePolicyForResponse in our PolicyClient
+        https://bugs.webkit.org/show_bug.cgi?id=69832
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        We implement decidePolicyForResponse in our PolicyClient in order to
+        decide whether a given ResourceResponse should be downloaded or loaded.
+
+        * Shared/qt/WebCoreArgumentCodersQt.cpp:
+        (CoreIPC::::encode):
+        (CoreIPC::::decode):
+        Implement serialization of ResourceResponse.
+
+        * UIProcess/qt/ClientImpl.cpp:
+        (qt_wk_decidePolicyForResponse):
+        * UIProcess/qt/ClientImpl.h:
+        * UIProcess/qt/QtWebPageProxy.cpp:
+        (QtWebPageProxy::init):
+
 2011-10-17  Nayan Kumar K  <nayankk@motorola.com>
 
         [WebKit2][gtk] Rename WEBKIT_POLICY_ERROR_CANNOT_SHOW_URL to WEBKIT_POLICY_ERROR_CANNOT_SHOW_URI
index 23f99e9..1fc15c5 100644 (file)
@@ -26,7 +26,6 @@
 #include "config.h"
 #include "WebCoreArgumentCoders.h"
 
-#include <WebCore/NotImplemented.h>
 #include <WebCore/ResourceError.h>
 #include <WebCore/ResourceRequest.h>
 #include <WebCore/ResourceResponse.h>
@@ -58,15 +57,37 @@ bool ArgumentCoder<ResourceRequest>::decode(ArgumentDecoder* decoder, ResourceRe
 
 void ArgumentCoder<ResourceResponse>::encode(ArgumentEncoder* encoder, const ResourceResponse& resourceResponse)
 {
-    notImplemented();
+    encoder->encode(resourceResponse.url().string());
+    encoder->encode(resourceResponse.mimeType());
+    encoder->encode(static_cast<int64_t>(resourceResponse.expectedContentLength()));
+    encoder->encode(resourceResponse.textEncodingName());
 }
 
 bool ArgumentCoder<ResourceResponse>::decode(ArgumentDecoder* decoder, ResourceResponse& resourceResponse)
 {
-    notImplemented();
+    ResourceResponse response;
 
-    // FIXME: Ditto.
-    resourceResponse = ResourceResponse();
+    String url;
+    if (!decoder->decode(url))
+        return false;
+    response.setURL(KURL(WebCore::ParsedURLString, url));
+
+    String mimeType;
+    if (!decoder->decode(mimeType))
+        return false;
+    response.setMimeType(mimeType);
+
+    int64_t contentLength;
+    if (!decoder->decode(contentLength))
+        return false;
+    response.setExpectedContentLength(contentLength);
+
+    String textEncodingName;
+    if (!decoder->decode(textEncodingName))
+        return false;
+    response.setTextEncodingName(textEncodingName);
+
+    resourceResponse = response;
     return true;
 }
 
index 341ed07..c003dfc 100644 (file)
@@ -252,3 +252,30 @@ void qt_wk_decidePolicyForNavigationAction(WKPageRef page, WKFrameRef frame, WKF
         break;
     }
 }
+
+void qt_wk_decidePolicyForResponse(WKPageRef page, WKFrameRef frame, WKURLResponseRef response, WKURLRequestRef request, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo)
+{
+    String type = toImpl(response)->resourceResponse().mimeType();
+    type.makeLower();
+    bool canShowMIMEType = toImpl(frame)->canShowMIMEType(type);
+
+    if (WKPageGetMainFrame(page) == frame) {
+        if (canShowMIMEType) {
+            WKFramePolicyListenerUse(listener);
+            return;
+        }
+
+        // If we can't use (show) it then we should download it.
+        WKFramePolicyListenerDownload(listener);
+        return;
+    }
+
+    // We should ignore downloadable top-level content for subframes, with an exception for text/xml and application/xml so we can still support Acid3 test.
+    // It makes the browser intentionally behave differently when it comes to text(application)/xml content in subframes vs. mainframe.
+    if (!canShowMIMEType && !(type == "text/xml" || type == "application/xml")) {
+        WKFramePolicyListenerIgnore(listener);
+        return;
+    }
+
+    WKFramePolicyListenerUse(listener);
+}
index 36f2e4c..bb3209f 100644 (file)
@@ -48,6 +48,7 @@ void qt_wk_mouseDidMoveOverElement(WKPageRef, WKHitTestResultRef, WKEventModifie
 
 // Policy client.
 void qt_wk_decidePolicyForNavigationAction(WKPageRef, WKFrameRef, WKFrameNavigationType, WKEventModifiers, WKEventMouseButton, WKURLRequestRef, WKFramePolicyListenerRef, WKTypeRef userData, const void* clientInfo);
+void qt_wk_decidePolicyForResponse(WKPageRef, WKFrameRef, WKURLResponseRef, WKURLRequestRef, WKFramePolicyListenerRef, WKTypeRef userData, const void* clientInfo);
 
 #ifdef __cplusplus
 }
index 7b45224..2b5e66a 100644 (file)
@@ -156,6 +156,7 @@ void QtWebPageProxy::init()
         policyClient.version = kWKPagePolicyClientCurrentVersion;
         policyClient.clientInfo = m_policyInterface;
         policyClient.decidePolicyForNavigationAction = qt_wk_decidePolicyForNavigationAction;
+        policyClient.decidePolicyForResponse = qt_wk_decidePolicyForResponse;
         WKPageSetPagePolicyClient(toAPI(m_webPageProxy.get()), &policyClient);
     }
 }