[GTK] Add WK2 API to get suggested filename for URI responses
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Aug 2012 16:46:47 +0000 (16:46 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Aug 2012 16:46:47 +0000 (16:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=92967

Patch by Claudio Saavedra <csaavedra@igalia.com> on 2012-08-17
Reviewed by Carlos Garcia Campos.

Webcore has API to get the suggested filename for a response, add
a property and getter for it in WebKitURIResponse.

* UIProcess/API/gtk/WebKitURIResponse.cpp:
(_WebKitURIResponsePrivate): Add a CString holding the value.
(webkitURIResponseGetProperty): Add the gobject bits for the
property.
(webkit_uri_response_class_init): Install the property.
(webkit_uri_response_get_suggested_filename): New getter.
* UIProcess/API/gtk/WebKitURIResponse.h: Declare the public
method.
* UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add the new API
symbols.
* UIProcess/API/gtk/tests/TestResources.cpp:
(testWebResourceSuggestedFilename): Test the new API.
(serverCallback): Add the the content-disposition header
in one case, in order to test it.
(beforeAll): Add the new test.

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.cpp
Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.h
Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt
Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp

index 9cfda8c..12df845 100644 (file)
@@ -1,3 +1,29 @@
+2012-08-17  Claudio Saavedra  <csaavedra@igalia.com>
+
+        [GTK] Add WK2 API to get suggested filename for URI responses
+        https://bugs.webkit.org/show_bug.cgi?id=92967
+
+        Reviewed by Carlos Garcia Campos.
+
+        Webcore has API to get the suggested filename for a response, add
+        a property and getter for it in WebKitURIResponse.
+
+        * UIProcess/API/gtk/WebKitURIResponse.cpp:
+        (_WebKitURIResponsePrivate): Add a CString holding the value.
+        (webkitURIResponseGetProperty): Add the gobject bits for the
+        property.
+        (webkit_uri_response_class_init): Install the property.
+        (webkit_uri_response_get_suggested_filename): New getter.
+        * UIProcess/API/gtk/WebKitURIResponse.h: Declare the public
+        method.
+        * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add the new API
+        symbols.
+        * UIProcess/API/gtk/tests/TestResources.cpp:
+        (testWebResourceSuggestedFilename): Test the new API.
+        (serverCallback): Add the the content-disposition header
+        in one case, in order to test it.
+        (beforeAll): Add the new test.
+
 2012-08-17  Mikhail Pozdnyakov  <mikhail.pozdnyakov@intel.com>
 
         [EFL][wk2] Add unit tests for back-forward list API
index 43ec333..29811fc 100644 (file)
@@ -33,7 +33,8 @@ enum {
     PROP_URI,
     PROP_STATUS_CODE,
     PROP_CONTENT_LENGTH,
-    PROP_MIME_TYPE
+    PROP_MIME_TYPE,
+    PROP_SUGGESTED_FILENAME
 };
 
 using namespace WebKit;
@@ -45,6 +46,7 @@ struct _WebKitURIResponsePrivate {
     WebCore::ResourceResponse resourceResponse;
     CString uri;
     CString mimeType;
+    CString suggestedFilename;
 };
 
 static void webkitURIResponseFinalize(GObject* object)
@@ -70,6 +72,9 @@ static void webkitURIResponseGetProperty(GObject* object, guint propId, GValue*
     case PROP_MIME_TYPE:
         g_value_set_string(value, webkit_uri_response_get_mime_type(response));
         break;
+    case PROP_SUGGESTED_FILENAME:
+        g_value_set_string(value, webkit_uri_response_get_suggested_filename(response));
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
     }
@@ -133,6 +138,19 @@ static void webkit_uri_response_class_init(WebKitURIResponseClass* responseClass
                                                         0,
                                                         WEBKIT_PARAM_READABLE));
 
+    /**
+     * WebKitURIResponse:suggested-filename:
+     *
+     * The suggested filename for the URI response.
+     */
+    g_object_class_install_property(objectClass,
+                                    PROP_SUGGESTED_FILENAME,
+                                    g_param_spec_string("suggested-filename",
+                                                        _("Suggested Filename"),
+                                                        _("The suggested filename for the URI response"),
+                                                        0,
+                                                        WEBKIT_PARAM_READABLE));
+
     g_type_class_add_private(responseClass, sizeof(WebKitURIResponsePrivate));
 }
 
@@ -230,6 +248,28 @@ gboolean webkit_uri_response_get_https_status(WebKitURIResponse* response, GTlsC
     return !!response->priv->resourceResponse.soupMessageCertificate();
 }
 
+/**
+ * webkit_uri_response_get_suggested_filename:
+ * @response: a #WebKitURIResponse
+ *
+ * Get the suggested filename for @response, as specified by
+ * the 'Content-Disposition' HTTP header, or %NULL if it's not
+ * present.
+ *
+ * Returns: (transfer none): the suggested filename or %NULL if
+ *    the 'Content-Disposition' HTTP header is not present.
+ */
+const gchar* webkit_uri_response_get_suggested_filename(WebKitURIResponse* response)
+{
+    g_return_val_if_fail(WEBKIT_IS_URI_RESPONSE(response), 0);
+
+    if (response->priv->resourceResponse.suggestedFilename().isEmpty())
+        return 0;
+
+    response->priv->suggestedFilename = response->priv->resourceResponse.suggestedFilename().utf8();
+    return response->priv->suggestedFilename.data();
+}
+
 WebKitURIResponse* webkitURIResponseCreateForResourceResponse(const WebCore::ResourceResponse& resourceResponse)
 {
     WebKitURIResponse* uriResponse = WEBKIT_URI_RESPONSE(g_object_new(WEBKIT_TYPE_URI_RESPONSE, NULL));
index 1970592..d90cf41 100644 (file)
@@ -53,24 +53,26 @@ struct _WebKitURIResponseClass {
 };
 
 WEBKIT_API GType
-webkit_uri_response_get_type           (void);
+webkit_uri_response_get_type               (void);
 
 WEBKIT_API const gchar *
-webkit_uri_response_get_uri            (WebKitURIResponse    *response);
+webkit_uri_response_get_uri                (WebKitURIResponse    *response);
 
 WEBKIT_API guint
-webkit_uri_response_get_status_code    (WebKitURIResponse    *response);
+webkit_uri_response_get_status_code        (WebKitURIResponse    *response);
 
 WEBKIT_API guint64
-webkit_uri_response_get_content_length (WebKitURIResponse    *response);
+webkit_uri_response_get_content_length     (WebKitURIResponse    *response);
 
 WEBKIT_API const gchar *
-webkit_uri_response_get_mime_type      (WebKitURIResponse    *response);
+webkit_uri_response_get_mime_type          (WebKitURIResponse    *response);
 
 WEBKIT_API gboolean
-webkit_uri_response_get_https_status   (WebKitURIResponse    *response,
-                                        GTlsCertificate     **certificate,
-                                        GTlsCertificateFlags *errors);
+webkit_uri_response_get_https_status       (WebKitURIResponse    *response,
+                                            GTlsCertificate     **certificate,
+                                            GTlsCertificateFlags *errors);
+WEBKIT_API const gchar *
+webkit_uri_response_get_suggested_filename (WebKitURIResponse    *response);
 
 G_END_DECLS
 
index 92da1eb..585e1b0 100644 (file)
@@ -325,6 +325,7 @@ webkit_uri_response_get_status_code
 webkit_uri_response_get_content_length
 webkit_uri_response_get_mime_type
 webkit_uri_response_get_https_status
+webkit_uri_response_get_suggested_filename
 
 <SUBSECTION Standard>
 WebKitURIResponseClass
index dc7a518..3d1e600 100644 (file)
@@ -397,6 +397,17 @@ static void testWebResourceMimeType(SingleResourceLoadTest* test, gconstpointer)
     g_assert_cmpstr(webkit_uri_response_get_mime_type(response), ==, "text/css");
 }
 
+static void testWebResourceSuggestedFilename(SingleResourceLoadTest* test, gconstpointer)
+{
+    test->loadURI(kServer->getURIForPath("/javascript.html").data());
+    WebKitURIResponse* response = test->waitUntilResourceLoadFinishedAndReturnURIResponse();
+    g_assert_cmpstr(webkit_uri_response_get_suggested_filename(response), ==, "JavaScript.js");
+
+    test->loadURI(kServer->getURIForPath("/image.html").data());
+    response = test->waitUntilResourceLoadFinishedAndReturnURIResponse();
+    g_assert(!webkit_uri_response_get_suggested_filename(response));
+}
+
 class ResourceURITrackingTest: public SingleResourceLoadTest {
 public:
     MAKE_GLIB_TEST_FIXTURE(ResourceURITrackingTest);
@@ -588,6 +599,7 @@ static void serverCallback(SoupServer* server, SoupMessage* message, const char*
     } else if (g_str_equal(path, "/javascript.js")) {
         soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, kJavascript, strlen(kJavascript));
         soup_message_headers_append(message->response_headers, "Content-Type", "text/javascript");
+        soup_message_headers_append(message->response_headers, "Content-Disposition", "filename=JavaScript.js");
     } else if (g_str_equal(path, "/blank.ico")) {
         GOwnPtr<char> filePath(g_build_filename(Test::getWebKit1TestResoucesDir().data(), path, NULL));
         char* contents;
@@ -620,6 +632,7 @@ void beforeAll()
     SingleResourceLoadTest::add("WebKitWebResource", "loading", testWebResourceLoading);
     SingleResourceLoadTest::add("WebKitWebResource", "response", testWebResourceResponse);
     SingleResourceLoadTest::add("WebKitWebResource", "mime-type", testWebResourceMimeType);
+    SingleResourceLoadTest::add("WebKitWebResource", "suggested-filename", testWebResourceSuggestedFilename);
     ResourceURITrackingTest::add("WebKitWebResource", "active-uri", testWebResourceActiveURI);
     ResourcesTest::add("WebKitWebResource", "get-data", testWebResourceGetData);
     ResourcesTest::add("WebKitWebView", "replaced-content", testWebViewResourcesReplacedContent);