Changeset 125910 in webkit


Ignore:
Timestamp:
Aug 17, 2012 9:46:47 AM (12 years ago)
Author:
commit-queue@webkit.org
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 <Claudio Saavedra> 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.

Location:
trunk/Source/WebKit2
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r125905 r125910  
     12012-08-17  Claudio Saavedra  <csaavedra@igalia.com>
     2
     3        [GTK] Add WK2 API to get suggested filename for URI responses
     4        https://bugs.webkit.org/show_bug.cgi?id=92967
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        Webcore has API to get the suggested filename for a response, add
     9        a property and getter for it in WebKitURIResponse.
     10
     11        * UIProcess/API/gtk/WebKitURIResponse.cpp:
     12        (_WebKitURIResponsePrivate): Add a CString holding the value.
     13        (webkitURIResponseGetProperty): Add the gobject bits for the
     14        property.
     15        (webkit_uri_response_class_init): Install the property.
     16        (webkit_uri_response_get_suggested_filename): New getter.
     17        * UIProcess/API/gtk/WebKitURIResponse.h: Declare the public
     18        method.
     19        * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add the new API
     20        symbols.
     21        * UIProcess/API/gtk/tests/TestResources.cpp:
     22        (testWebResourceSuggestedFilename): Test the new API.
     23        (serverCallback): Add the the content-disposition header
     24        in one case, in order to test it.
     25        (beforeAll): Add the new test.
     26
    1272012-08-17  Mikhail Pozdnyakov  <mikhail.pozdnyakov@intel.com>
    228
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.cpp

    r122547 r125910  
    3434    PROP_STATUS_CODE,
    3535    PROP_CONTENT_LENGTH,
    36     PROP_MIME_TYPE
     36    PROP_MIME_TYPE,
     37    PROP_SUGGESTED_FILENAME
    3738};
    3839
     
    4647    CString uri;
    4748    CString mimeType;
     49    CString suggestedFilename;
    4850};
    4951
     
    7072    case PROP_MIME_TYPE:
    7173        g_value_set_string(value, webkit_uri_response_get_mime_type(response));
     74        break;
     75    case PROP_SUGGESTED_FILENAME:
     76        g_value_set_string(value, webkit_uri_response_get_suggested_filename(response));
    7277        break;
    7378    default:
     
    134139                                                        WEBKIT_PARAM_READABLE));
    135140
     141    /**
     142     * WebKitURIResponse:suggested-filename:
     143     *
     144     * The suggested filename for the URI response.
     145     */
     146    g_object_class_install_property(objectClass,
     147                                    PROP_SUGGESTED_FILENAME,
     148                                    g_param_spec_string("suggested-filename",
     149                                                        _("Suggested Filename"),
     150                                                        _("The suggested filename for the URI response"),
     151                                                        0,
     152                                                        WEBKIT_PARAM_READABLE));
     153
    136154    g_type_class_add_private(responseClass, sizeof(WebKitURIResponsePrivate));
    137155}
     
    231249}
    232250
     251/**
     252 * webkit_uri_response_get_suggested_filename:
     253 * @response: a #WebKitURIResponse
     254 *
     255 * Get the suggested filename for @response, as specified by
     256 * the 'Content-Disposition' HTTP header, or %NULL if it's not
     257 * present.
     258 *
     259 * Returns: (transfer none): the suggested filename or %NULL if
     260 *    the 'Content-Disposition' HTTP header is not present.
     261 */
     262const gchar* webkit_uri_response_get_suggested_filename(WebKitURIResponse* response)
     263{
     264    g_return_val_if_fail(WEBKIT_IS_URI_RESPONSE(response), 0);
     265
     266    if (response->priv->resourceResponse.suggestedFilename().isEmpty())
     267        return 0;
     268
     269    response->priv->suggestedFilename = response->priv->resourceResponse.suggestedFilename().utf8();
     270    return response->priv->suggestedFilename.data();
     271}
     272
    233273WebKitURIResponse* webkitURIResponseCreateForResourceResponse(const WebCore::ResourceResponse& resourceResponse)
    234274{
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.h

    r122547 r125910  
    5454
    5555WEBKIT_API GType
    56 webkit_uri_response_get_type           (void);
     56webkit_uri_response_get_type               (void);
    5757
    5858WEBKIT_API const gchar *
    59 webkit_uri_response_get_uri            (WebKitURIResponse    *response);
     59webkit_uri_response_get_uri                (WebKitURIResponse    *response);
    6060
    6161WEBKIT_API guint
    62 webkit_uri_response_get_status_code    (WebKitURIResponse    *response);
     62webkit_uri_response_get_status_code        (WebKitURIResponse    *response);
    6363
    6464WEBKIT_API guint64
    65 webkit_uri_response_get_content_length (WebKitURIResponse    *response);
     65webkit_uri_response_get_content_length     (WebKitURIResponse    *response);
    6666
    6767WEBKIT_API const gchar *
    68 webkit_uri_response_get_mime_type      (WebKitURIResponse    *response);
     68webkit_uri_response_get_mime_type          (WebKitURIResponse    *response);
    6969
    7070WEBKIT_API gboolean
    71 webkit_uri_response_get_https_status   (WebKitURIResponse    *response,
    72                                         GTlsCertificate     **certificate,
    73                                         GTlsCertificateFlags *errors);
     71webkit_uri_response_get_https_status       (WebKitURIResponse    *response,
     72                                            GTlsCertificate     **certificate,
     73                                            GTlsCertificateFlags *errors);
     74WEBKIT_API const gchar *
     75webkit_uri_response_get_suggested_filename (WebKitURIResponse    *response);
    7476
    7577G_END_DECLS
  • trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt

    r125267 r125910  
    326326webkit_uri_response_get_mime_type
    327327webkit_uri_response_get_https_status
     328webkit_uri_response_get_suggested_filename
    328329
    329330<SUBSECTION Standard>
  • trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp

    r122960 r125910  
    396396    response = test->waitUntilResourceLoadFinishedAndReturnURIResponse();
    397397    g_assert_cmpstr(webkit_uri_response_get_mime_type(response), ==, "text/css");
     398}
     399
     400static void testWebResourceSuggestedFilename(SingleResourceLoadTest* test, gconstpointer)
     401{
     402    test->loadURI(kServer->getURIForPath("/javascript.html").data());
     403    WebKitURIResponse* response = test->waitUntilResourceLoadFinishedAndReturnURIResponse();
     404    g_assert_cmpstr(webkit_uri_response_get_suggested_filename(response), ==, "JavaScript.js");
     405
     406    test->loadURI(kServer->getURIForPath("/image.html").data());
     407    response = test->waitUntilResourceLoadFinishedAndReturnURIResponse();
     408    g_assert(!webkit_uri_response_get_suggested_filename(response));
    398409}
    399410
     
    589600        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, kJavascript, strlen(kJavascript));
    590601        soup_message_headers_append(message->response_headers, "Content-Type", "text/javascript");
     602        soup_message_headers_append(message->response_headers, "Content-Disposition", "filename=JavaScript.js");
    591603    } else if (g_str_equal(path, "/blank.ico")) {
    592604        GOwnPtr<char> filePath(g_build_filename(Test::getWebKit1TestResoucesDir().data(), path, NULL));
     
    621633    SingleResourceLoadTest::add("WebKitWebResource", "response", testWebResourceResponse);
    622634    SingleResourceLoadTest::add("WebKitWebResource", "mime-type", testWebResourceMimeType);
     635    SingleResourceLoadTest::add("WebKitWebResource", "suggested-filename", testWebResourceSuggestedFilename);
    623636    ResourceURITrackingTest::add("WebKitWebResource", "active-uri", testWebResourceActiveURI);
    624637    ResourcesTest::add("WebKitWebResource", "get-data", testWebResourceGetData);
Note: See TracChangeset for help on using the changeset viewer.