[GTK] Add API to WebKitResponsePolicyDecision to check if the MIME type can be shown
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Jan 2014 08:42:07 +0000 (08:42 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Jan 2014 08:42:07 +0000 (08:42 +0000)
https://bugs.webkit.org/show_bug.cgi?id=124652

Reviewed by Martin Robinson.

Source/WebKit2:

* UIProcess/API/gtk/WebKitPolicyClient.cpp:
(decidePolicyForResponse): Pass canShowMIMEType to
webkitResponsePolicyDecisionCreate.
* UIProcess/API/gtk/WebKitResponsePolicyDecision.cpp:
(webkit_response_policy_decision_is_mime_type_supported): Return
canShowMIMEType.
(webkitResponsePolicyDecisionCreate): Set the canShowMIMEType
member from the given parameter.
* UIProcess/API/gtk/WebKitResponsePolicyDecision.h:
* UIProcess/API/gtk/WebKitResponsePolicyDecisionPrivate.h:
* UIProcess/API/gtk/WebKitWebView.cpp:
(webkitWebViewDecidePolicy): Use the new API instead of
webkit_web_view_can_show_mime_type() since it's more efficient.
* UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add new symbol.
* UIProcess/API/gtk/tests/TestWebKitPolicyClient.cpp:
(testResponsePolicy): Test the new API.

Tools:

* MiniBrowser/gtk/BrowserWindow.c:
(webViewDecidePolicy): Use the new API instead of
webkit_web_view_can_show_mime_type().

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/gtk/WebKitPolicyClient.cpp
Source/WebKit2/UIProcess/API/gtk/WebKitResponsePolicyDecision.cpp
Source/WebKit2/UIProcess/API/gtk/WebKitResponsePolicyDecision.h
Source/WebKit2/UIProcess/API/gtk/WebKitResponsePolicyDecisionPrivate.h
Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp
Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt
Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitPolicyClient.cpp
Tools/ChangeLog
Tools/MiniBrowser/gtk/BrowserWindow.c

index 47a6cf4..3b04a84 100644 (file)
@@ -1,5 +1,29 @@
 2014-01-02  Carlos Garcia Campos  <cgarcia@igalia.com>
 
+        [GTK] Add API to WebKitResponsePolicyDecision to check if the MIME type can be shown
+        https://bugs.webkit.org/show_bug.cgi?id=124652
+
+        Reviewed by Martin Robinson.
+
+        * UIProcess/API/gtk/WebKitPolicyClient.cpp:
+        (decidePolicyForResponse): Pass canShowMIMEType to
+        webkitResponsePolicyDecisionCreate.
+        * UIProcess/API/gtk/WebKitResponsePolicyDecision.cpp:
+        (webkit_response_policy_decision_is_mime_type_supported): Return
+        canShowMIMEType.
+        (webkitResponsePolicyDecisionCreate): Set the canShowMIMEType
+        member from the given parameter.
+        * UIProcess/API/gtk/WebKitResponsePolicyDecision.h:
+        * UIProcess/API/gtk/WebKitResponsePolicyDecisionPrivate.h:
+        * UIProcess/API/gtk/WebKitWebView.cpp:
+        (webkitWebViewDecidePolicy): Use the new API instead of
+        webkit_web_view_can_show_mime_type() since it's more efficient.
+        * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add new symbol.
+        * UIProcess/API/gtk/tests/TestWebKitPolicyClient.cpp:
+        (testResponsePolicy): Test the new API.
+
+2014-01-02  Carlos Garcia Campos  <cgarcia@igalia.com>
+
         REGRESSION(r160304): [GTK] Disable libtool fast install
         https://bugs.webkit.org/show_bug.cgi?id=126381
 
index 5fdcbe5..1eb6b1e 100644 (file)
@@ -60,7 +60,7 @@ static void decidePolicyForNewWindowAction(WKPageRef page, WKFrameRef frame, WKF
 static void decidePolicyForResponse(WKPageRef page, WKFrameRef frame, WKURLResponseRef response, WKURLRequestRef request, bool canShowMIMEType, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo)
 {
     GRefPtr<WebKitResponsePolicyDecision> decision =
-        adoptGRef(webkitResponsePolicyDecisionCreate(toImpl(request), toImpl(response), toImpl(listener)));
+        adoptGRef(webkitResponsePolicyDecisionCreate(toImpl(request), toImpl(response), canShowMIMEType, toImpl(listener)));
     webkitWebViewMakePolicyDecision(WEBKIT_WEB_VIEW(clientInfo),
                                     WEBKIT_POLICY_DECISION_TYPE_RESPONSE,
                                     WEBKIT_POLICY_DECISION(decision.get()));
index be7a841..b6054b8 100644 (file)
@@ -48,6 +48,7 @@ using namespace WebKit;
 struct _WebKitResponsePolicyDecisionPrivate {
     GRefPtr<WebKitURIRequest> request;
     GRefPtr<WebKitURIResponse> response;
+    bool canShowMIMEType;
 };
 
 WEBKIT_DEFINE_TYPE(WebKitResponsePolicyDecision, webkit_response_policy_decision, WEBKIT_TYPE_POLICY_DECISION)
@@ -137,11 +138,29 @@ WebKitURIResponse* webkit_response_policy_decision_get_response(WebKitResponsePo
     return decision->priv->response.get();
 }
 
-WebKitResponsePolicyDecision* webkitResponsePolicyDecisionCreate(API::URLRequest* request, API::URLResponse* response, WebFramePolicyListenerProxy* listener)
+/**
+ * webkit_response_policy_decision_is_mime_type_supported:
+ * @decision: a #WebKitResponsePolicyDecision
+ *
+ * Gets whether the MIME type of the response can be displayed in the #WebKitWebView
+ * that triggered this policy decision request. See also webkit_web_view_can_show_mime_type().
+ *
+ * Returns: %TRUE if the MIME type of the response is supported or %FALSE otherwise
+ *
+ * Since: 2.4
+ */
+gboolean webkit_response_policy_decision_is_mime_type_supported(WebKitResponsePolicyDecision* decision)
+{
+    g_return_val_if_fail(WEBKIT_IS_RESPONSE_POLICY_DECISION(decision), FALSE);
+    return decision->priv->canShowMIMEType;
+}
+
+WebKitResponsePolicyDecision* webkitResponsePolicyDecisionCreate(API::URLRequest* request, API::URLResponse* response, bool canShowMIMEType, WebFramePolicyListenerProxy* listener)
 {
     WebKitResponsePolicyDecision* decision = WEBKIT_RESPONSE_POLICY_DECISION(g_object_new(WEBKIT_TYPE_RESPONSE_POLICY_DECISION, NULL));
     decision->priv->request = adoptGRef(webkitURIRequestCreateForResourceRequest(request->resourceRequest()));
     decision->priv->response = adoptGRef(webkitURIResponseCreateForResourceResponse(response->resourceResponse()));
+    decision->priv->canShowMIMEType = canShowMIMEType;
     webkitPolicyDecisionSetListener(WEBKIT_POLICY_DECISION(decision), listener);
     return decision;
 }
index 4a689fb..b4e8fe2 100644 (file)
@@ -60,13 +60,16 @@ struct _WebKitResponsePolicyDecisionClass {
 };
 
 WEBKIT_API GType
-webkit_response_policy_decision_get_type            (void);
+webkit_response_policy_decision_get_type               (void);
 
 WEBKIT_API WebKitURIRequest *
-webkit_response_policy_decision_get_request         (WebKitResponsePolicyDecision *decision);
+webkit_response_policy_decision_get_request            (WebKitResponsePolicyDecision *decision);
 
 WEBKIT_API WebKitURIResponse *
-webkit_response_policy_decision_get_response        (WebKitResponsePolicyDecision *decision);
+webkit_response_policy_decision_get_response           (WebKitResponsePolicyDecision *decision);
+
+WEBKIT_API gboolean
+webkit_response_policy_decision_is_mime_type_supported (WebKitResponsePolicyDecision *decision);
 
 G_END_DECLS
 
index a77ec22..ff83a7d 100644 (file)
@@ -23,6 +23,6 @@
 #include "WebKitPrivate.h"
 #include "WebKitResponsePolicyDecision.h"
 
-WebKitResponsePolicyDecision* webkitResponsePolicyDecisionCreate(API::URLRequest*, API::URLResponse*, WebKit::WebFramePolicyListenerProxy*);
+WebKitResponsePolicyDecision* webkitResponsePolicyDecisionCreate(API::URLRequest*, API::URLResponse*, bool canShowMIMEType, WebKit::WebFramePolicyListenerProxy*);
 
 #endif // WebKitResponsePolicyDecisionPrivate_h
index 7e62759..6597b3b 100644 (file)
@@ -279,7 +279,7 @@ static gboolean webkitWebViewDecidePolicy(WebKitWebView* webView, WebKitPolicyDe
         return TRUE;
     }
 
-    if (webkit_web_view_can_show_mime_type(webView, webkit_uri_response_get_mime_type(response)))
+    if (webkit_response_policy_decision_is_mime_type_supported(WEBKIT_RESPONSE_POLICY_DECISION(decision)))
         webkit_policy_decision_use(decision);
     else
         webkit_policy_decision_ignore(decision);
index 3c49a67..090e91e 100644 (file)
@@ -568,6 +568,7 @@ webkit_navigation_policy_decision_get_type
 WebKitResponsePolicyDecision
 webkit_response_policy_decision_get_request
 webkit_response_policy_decision_get_response
+webkit_response_policy_decision_is_mime_type_supported
 
 <SUBSECTION Standard>
 WebKitResponsePolicyDecisionClass
index abbfd65..209ea04 100644 (file)
@@ -157,6 +157,16 @@ static void testResponsePolicy(PolicyClientTest* test, gconstpointer)
     g_assert_cmpint(test->m_loadEvents[1], ==, LoadTrackingTest::LoadCommitted);
     g_assert_cmpint(test->m_loadEvents[2], ==, LoadTrackingTest::LoadFinished);
 
+    WebKitResponsePolicyDecision* decision = WEBKIT_RESPONSE_POLICY_DECISION(test->m_previousPolicyDecision.get());
+    WebKitURIRequest* request = webkit_response_policy_decision_get_request(decision);
+    g_assert(WEBKIT_IS_URI_REQUEST(request));
+    ASSERT_CMP_CSTRING(webkit_uri_request_get_uri(request), ==, kServer->getURIForPath("/"));
+    WebKitURIResponse* response = webkit_response_policy_decision_get_response(decision);
+    g_assert(WEBKIT_IS_URI_RESPONSE(response));
+    ASSERT_CMP_CSTRING(webkit_uri_response_get_uri(response), ==, kServer->getURIForPath("/"));
+    g_assert(webkit_web_view_can_show_mime_type(test->m_webView, webkit_uri_response_get_mime_type(response)) ==
+        webkit_response_policy_decision_is_mime_type_supported(decision));
+
     test->m_respondToPolicyDecisionAsynchronously = true;
     test->loadURI(kServer->getURIForPath("/").data());
     test->waitUntilLoadFinished();
index e431786..2ca0167 100644 (file)
@@ -1,5 +1,16 @@
 2014-01-02  Carlos Garcia Campos  <cgarcia@igalia.com>
 
+        [GTK] Add API to WebKitResponsePolicyDecision to check if the MIME type can be shown
+        https://bugs.webkit.org/show_bug.cgi?id=124652
+
+        Reviewed by Martin Robinson.
+
+        * MiniBrowser/gtk/BrowserWindow.c:
+        (webViewDecidePolicy): Use the new API instead of
+        webkit_web_view_can_show_mime_type().
+
+2014-01-02  Carlos Garcia Campos  <cgarcia@igalia.com>
+
         REGRESSION(r160304): [GTK] Disable libtool fast install
         https://bugs.webkit.org/show_bug.cgi?id=126381
 
index 8586fe5..ddffddd 100644 (file)
@@ -378,10 +378,7 @@ static gboolean webViewDecidePolicy(WebKitWebView *webView, WebKitPolicyDecision
     }
     case WEBKIT_POLICY_DECISION_TYPE_RESPONSE: {
         WebKitResponsePolicyDecision *responseDecision = WEBKIT_RESPONSE_POLICY_DECISION(decision);
-        WebKitURIResponse *response = webkit_response_policy_decision_get_response(responseDecision);
-        const char *mimeType = webkit_uri_response_get_mime_type(response);
-
-        if (webkit_web_view_can_show_mime_type(webView, mimeType))
+        if (webkit_response_policy_decision_is_mime_type_supported(responseDecision))
             return FALSE;
 
         WebKitWebResource *mainResource = webkit_web_view_get_main_resource(webView);