Skip to content

Commit

Permalink
[GTK] Add WK2 API to get suggested filename for URI responses
Browse files Browse the repository at this point in the history
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.

Canonical link: https://commits.webkit.org/112161@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@125910 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
csaavedra authored and webkit-commit-queue committed Aug 17, 2012
1 parent 9b6f1c0 commit acda9ce
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 9 deletions.
26 changes: 26 additions & 0 deletions Source/WebKit2/ChangeLog
@@ -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
Expand Down
42 changes: 41 additions & 1 deletion Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.cpp
Expand Up @@ -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;
Expand All @@ -45,6 +46,7 @@ struct _WebKitURIResponsePrivate {
WebCore::ResourceResponse resourceResponse;
CString uri;
CString mimeType;
CString suggestedFilename;
};

static void webkitURIResponseFinalize(GObject* object)
Expand All @@ -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);
}
Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -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));
Expand Down
18 changes: 10 additions & 8 deletions Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.h
Expand Up @@ -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

Expand Down
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit acda9ce

Please sign in to comment.