- Revision
- 125910
- Author
- commit-qu...@webkit.org
- Date
- 2012-08-17 09:46:47 -0700 (Fri, 17 Aug 2012)
Log Message
[GTK] Add WK2 API to get suggested filename for URI responses
https://bugs.webkit.org/show_bug.cgi?id=92967
Patch by Claudio Saavedra <csaave...@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.
Modified Paths
Diff
Modified: trunk/Source/WebKit2/ChangeLog (125909 => 125910)
--- trunk/Source/WebKit2/ChangeLog 2012-08-17 16:09:37 UTC (rev 125909)
+++ trunk/Source/WebKit2/ChangeLog 2012-08-17 16:46:47 UTC (rev 125910)
@@ -1,3 +1,29 @@
+2012-08-17 Claudio Saavedra <csaave...@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.pozdnya...@intel.com>
[EFL][wk2] Add unit tests for back-forward list API
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.cpp (125909 => 125910)
--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.cpp 2012-08-17 16:09:37 UTC (rev 125909)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.cpp 2012-08-17 16:46:47 UTC (rev 125910)
@@ -33,7 +33,8 @@
PROP_URI,
PROP_STATUS_CODE,
PROP_CONTENT_LENGTH,
- PROP_MIME_TYPE
+ PROP_MIME_TYPE,
+ PROP_SUGGESTED_FILENAME
};
using namespace WebKit;
@@ -45,6 +46,7 @@
WebCore::ResourceResponse resourceResponse;
CString uri;
CString mimeType;
+ CString suggestedFilename;
};
static void webkitURIResponseFinalize(GObject* object)
@@ -70,6 +72,9 @@
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 @@
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 @@
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));
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.h (125909 => 125910)
--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.h 2012-08-17 16:09:37 UTC (rev 125909)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.h 2012-08-17 16:46:47 UTC (rev 125910)
@@ -53,24 +53,26 @@
};
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
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt (125909 => 125910)
--- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt 2012-08-17 16:09:37 UTC (rev 125909)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt 2012-08-17 16:46:47 UTC (rev 125910)
@@ -325,6 +325,7 @@
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
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp (125909 => 125910)
--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp 2012-08-17 16:09:37 UTC (rev 125909)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp 2012-08-17 16:46:47 UTC (rev 125910)
@@ -397,6 +397,17 @@
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 @@
} 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 @@
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);