Changeset 118786 in webkit


Ignore:
Timestamp:
May 29, 2012 9:09:46 AM (12 years ago)
Author:
Carlos Garcia Campos
Message:

[GTK] Add webkit_web_view_can_show_mime_type() to WebKit2 GTK+ API
https://bugs.webkit.org/show_bug.cgi?id=85998

Reviewed by Martin Robinson.

And use it in the default handler of WebKitWebView::decide-policy
signal to decide whether to use or ignore a response policy
decision depending on whether the mime type of the response can be
displayed in the WebView or not.

  • UIProcess/API/gtk/WebKitURIResponse.cpp:

(webkitURIResponseGetProperty): Add getter for mime-type property.
(webkit_uri_response_class_init): Add mime-type property.
(webkit_uri_response_get_mime_type): Return the mime type of the
response.

  • UIProcess/API/gtk/WebKitURIResponse.h:
  • UIProcess/API/gtk/WebKitWebView.cpp:

(webkitWebViewDecidePolicy): In case of response policy decisions,
use the URI response to decide what to do: download if the
response is an attachment, use if the mime type is supported by
the web view or ignore otherwise.
(webkit_web_view_can_show_mime_type): Returns whether the given
mime type can be displayed in the WebView or not.

  • UIProcess/API/gtk/WebKitWebView.h:
  • UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add new symbols.
  • UIProcess/API/gtk/tests/TestResources.cpp:

(testWebResourceResponse):
(testWebResourceMimeType):
(serverCallback):
(beforeAll):

  • UIProcess/API/gtk/tests/TestWebKitWebView.cpp:

(testWebViewCanShowMIMEType):
(beforeAll):

Location:
trunk/Source/WebKit2
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r118774 r118786  
     12012-05-29  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Add webkit_web_view_can_show_mime_type() to WebKit2 GTK+ API
     4        https://bugs.webkit.org/show_bug.cgi?id=85998
     5
     6        Reviewed by Martin Robinson.
     7
     8        And use it in the default handler of WebKitWebView::decide-policy
     9        signal to decide whether to use or ignore a response policy
     10        decision depending on whether the mime type of the response can be
     11        displayed in the WebView or not.
     12
     13        * UIProcess/API/gtk/WebKitURIResponse.cpp:
     14        (webkitURIResponseGetProperty): Add getter for mime-type property.
     15        (webkit_uri_response_class_init): Add mime-type property.
     16        (webkit_uri_response_get_mime_type): Return the mime type of the
     17        response.
     18        * UIProcess/API/gtk/WebKitURIResponse.h:
     19        * UIProcess/API/gtk/WebKitWebView.cpp:
     20        (webkitWebViewDecidePolicy): In case of response policy decisions,
     21        use the URI response to decide what to do: download if the
     22        response is an attachment, use if the mime type is supported by
     23        the web view or ignore otherwise.
     24        (webkit_web_view_can_show_mime_type): Returns whether the given
     25        mime type can be displayed in the WebView or not.
     26        * UIProcess/API/gtk/WebKitWebView.h:
     27        * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add new symbols.
     28        * UIProcess/API/gtk/tests/TestResources.cpp:
     29        (testWebResourceResponse):
     30        (testWebResourceMimeType):
     31        (serverCallback):
     32        (beforeAll):
     33        * UIProcess/API/gtk/tests/TestWebKitWebView.cpp:
     34        (testWebViewCanShowMIMEType):
     35        (beforeAll):
     36
    1372012-05-29  David Barr  <davidbarr@chromium.org>
    238
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.cpp

    r105704 r118786  
    3131    PROP_URI,
    3232    PROP_STATUS_CODE,
    33     PROP_CONTENT_LENGTH
     33    PROP_CONTENT_LENGTH,
     34    PROP_MIME_TYPE
    3435};
    3536
     
    4142    WebCore::ResourceResponse resourceResponse;
    4243    CString uri;
     44    CString mimeType;
    4345};
    4446
     
    6264    case PROP_CONTENT_LENGTH:
    6365        g_value_set_uint64(value, webkit_uri_response_get_content_length(response));
     66        break;
     67    case PROP_MIME_TYPE:
     68        g_value_set_string(value, webkit_uri_response_get_mime_type(response));
    6469        break;
    6570    default:
     
    113118                                                        WEBKIT_PARAM_READABLE));
    114119
     120    /**
     121     * WebKitURIResponse:mime-type:
     122     *
     123     * The MIME type of the response.
     124     */
     125    g_object_class_install_property(objectClass,
     126                                    PROP_MIME_TYPE,
     127                                    g_param_spec_string("mime-type",
     128                                                        _("MIME Type"),
     129                                                        _("The MIME type of the response"),
     130                                                        0,
     131                                                        WEBKIT_PARAM_READABLE));
     132
    115133    g_type_class_add_private(responseClass, sizeof(WebKitURIResponsePrivate));
    116134}
     
    171189}
    172190
     191/**
     192 * webkit_uri_response_get_mime_type:
     193 * @response: a #WebKitURIResponse
     194 *
     195 * Returns: the MIME type of the #WebKitURIResponse
     196 */
     197const gchar* webkit_uri_response_get_mime_type(WebKitURIResponse* response)
     198{
     199    g_return_val_if_fail(WEBKIT_IS_URI_RESPONSE(response), 0);
     200
     201    response->priv->mimeType = response->priv->resourceResponse.mimeType().utf8();
     202    return response->priv->mimeType.data();
     203}
     204
    173205WebKitURIResponse* webkitURIResponseCreateForResourceResponse(const WebCore::ResourceResponse& resourceResponse)
    174206{
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.h

    r101350 r118786  
    6565webkit_uri_response_get_content_length (WebKitURIResponse *response);
    6666
     67WEBKIT_API const gchar *
     68webkit_uri_response_get_mime_type      (WebKitURIResponse *response);
     69
    6770G_END_DECLS
    6871
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp

    r118732 r118786  
    3434#include "WebKitPrivate.h"
    3535#include "WebKitResourceLoadClient.h"
     36#include "WebKitResponsePolicyDecision.h"
    3637#include "WebKitScriptDialogPrivate.h"
    3738#include "WebKitSettingsPrivate.h"
    3839#include "WebKitUIClient.h"
     40#include "WebKitURIResponsePrivate.h"
    3941#include "WebKitWebContextPrivate.h"
    4042#include "WebKitWebInspectorPrivate.h"
     
    191193}
    192194
    193 static gboolean webkitWebViewDecidePolicy(WebKitWebView*, WebKitPolicyDecision* decision, WebKitPolicyDecisionType)
    194 {
    195     webkit_policy_decision_use(decision);
     195static gboolean webkitWebViewDecidePolicy(WebKitWebView* webView, WebKitPolicyDecision* decision, WebKitPolicyDecisionType decisionType)
     196{
     197    if (decisionType != WEBKIT_POLICY_DECISION_TYPE_RESPONSE) {
     198        webkit_policy_decision_use(decision);
     199        return TRUE;
     200    }
     201
     202    WebKitURIResponse* response = webkit_response_policy_decision_get_response(WEBKIT_RESPONSE_POLICY_DECISION(decision));
     203    const ResourceResponse resourceResponse = webkitURIResponseGetResourceResponse(response);
     204    if (resourceResponse.isAttachment()) {
     205        webkit_policy_decision_download(decision);
     206        return TRUE;
     207    }
     208
     209    if (webkit_web_view_can_show_mime_type(webView, webkit_uri_response_get_mime_type(response)))
     210        webkit_policy_decision_use(decision);
     211    else
     212        webkit_policy_decision_ignore(decision);
     213
    196214    return TRUE;
    197215}
     
    20272045    return webView->priv->inspector.get();
    20282046}
     2047
     2048/**
     2049 * webkit_web_view_can_show_mime_type:
     2050 * @web_view: a #WebKitWebView
     2051 * @mime_type: a MIME type
     2052 *
     2053 * Whether or not a MIME type can be displayed in @web_view.
     2054 *
     2055 * Returns: %TRUE if the MIME type @mime_type can be displayed or %FALSE otherwise
     2056 */
     2057gboolean webkit_web_view_can_show_mime_type(WebKitWebView* webView, const char* mimeType)
     2058{
     2059    g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
     2060    g_return_val_if_fail(mimeType, FALSE);
     2061
     2062    WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView));
     2063    return page->canShowMIMEType(String::fromUTF8(mimeType));
     2064}
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h

    r118522 r118786  
    307307webkit_web_view_get_inspector                      (WebKitWebView             *web_view);
    308308
     309WEBKIT_API gboolean
     310webkit_web_view_can_show_mime_type                 (WebKitWebView             *web_view,
     311                                                    const gchar               *mime_type);
     312
    309313G_END_DECLS
    310314
  • trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt

    r118522 r118786  
    9696webkit_web_view_run_javascript
    9797webkit_web_view_run_javascript_finish
     98webkit_web_view_can_show_mime_type
    9899
    99100<SUBSECTION WebKitJavascriptResult>
     
    303304webkit_uri_response_get_status_code
    304305webkit_uri_response_get_content_length
     306webkit_uri_response_get_mime_type
    305307
    306308<SUBSECTION Standard>
  • trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp

    r117735 r118786  
    301301    }
    302302
    303     int waitUntilResourceLoadFinsihedAndReturnHTTPStatusResponse()
     303    WebKitURIResponse* waitUntilResourceLoadFinsihedAndReturnURIResponse()
    304304    {
    305305        waitUntilResourceLoadFinsihed();
    306306        g_assert(m_resource);
    307         WebKitURIResponse* response = webkit_web_resource_get_response(m_resource.get());
    308         g_assert(response);
    309         return webkit_uri_response_get_status_code(response);
     307        return webkit_web_resource_get_response(m_resource.get());
    310308    }
    311309
     
    356354    // No cached resource: First load.
    357355    test->loadURI(kServer->getURIForPath("/javascript.html").data());
    358     gint statusCode = test->waitUntilResourceLoadFinsihedAndReturnHTTPStatusResponse();
    359     g_assert_cmpint(statusCode, ==, SOUP_STATUS_OK);
     356    WebKitURIResponse* response = test->waitUntilResourceLoadFinsihedAndReturnURIResponse();
     357    g_assert_cmpint(webkit_uri_response_get_status_code(response), ==, SOUP_STATUS_OK);
    360358
    361359    // No cached resource: Second load.
    362360    test->loadURI(kServer->getURIForPath("/javascript.html").data());
    363     statusCode = test->waitUntilResourceLoadFinsihedAndReturnHTTPStatusResponse();
    364     g_assert_cmpint(statusCode, ==, SOUP_STATUS_OK);
     361    response = test->waitUntilResourceLoadFinsihedAndReturnURIResponse();
     362    g_assert_cmpint(webkit_uri_response_get_status_code(response), ==, SOUP_STATUS_OK);
    365363
    366364    // No cached resource: Reload.
    367365    webkit_web_view_reload(test->m_webView);
    368     statusCode = test->waitUntilResourceLoadFinsihedAndReturnHTTPStatusResponse();
    369     g_assert_cmpint(statusCode, ==, SOUP_STATUS_OK);
     366    response = test->waitUntilResourceLoadFinsihedAndReturnURIResponse();
     367    g_assert_cmpint(webkit_uri_response_get_status_code(response), ==, SOUP_STATUS_OK);
    370368
    371369    // Cached resource: First load.
    372370    test->loadURI(kServer->getURIForPath("/image.html").data());
    373     statusCode = test->waitUntilResourceLoadFinsihedAndReturnHTTPStatusResponse();
    374     g_assert_cmpint(statusCode, ==, SOUP_STATUS_OK);
     371    response = test->waitUntilResourceLoadFinsihedAndReturnURIResponse();
     372    g_assert_cmpint(webkit_uri_response_get_status_code(response), ==, SOUP_STATUS_OK);
    375373
    376374    // Cached resource: Second load.
    377375    test->loadURI(kServer->getURIForPath("/image.html").data());
    378     statusCode = test->waitUntilResourceLoadFinsihedAndReturnHTTPStatusResponse();
    379     g_assert_cmpint(statusCode, ==, SOUP_STATUS_OK);
     376    response = test->waitUntilResourceLoadFinsihedAndReturnURIResponse();
     377    g_assert_cmpint(webkit_uri_response_get_status_code(response), ==, SOUP_STATUS_OK);
    380378
    381379    // Cached resource: Reload.
    382380    webkit_web_view_reload(test->m_webView);
    383     statusCode = test->waitUntilResourceLoadFinsihedAndReturnHTTPStatusResponse();
    384     g_assert_cmpint(statusCode, ==, SOUP_STATUS_NOT_MODIFIED);
     381    response = test->waitUntilResourceLoadFinsihedAndReturnURIResponse();
     382    g_assert_cmpint(webkit_uri_response_get_status_code(response), ==, SOUP_STATUS_NOT_MODIFIED);
     383}
     384
     385static void testWebResourceMimeType(SingleResourceLoadTest* test, gconstpointer)
     386{
     387    test->loadURI(kServer->getURIForPath("/javascript.html").data());
     388    WebKitURIResponse* response = test->waitUntilResourceLoadFinsihedAndReturnURIResponse();
     389    g_assert_cmpstr(webkit_uri_response_get_mime_type(response), ==, "text/javascript");
     390
     391    test->loadURI(kServer->getURIForPath("/image.html").data());
     392    response = test->waitUntilResourceLoadFinsihedAndReturnURIResponse();
     393    g_assert_cmpstr(webkit_uri_response_get_mime_type(response), ==, "image/vnd.microsoft.icon");
     394
     395    test->loadURI(kServer->getURIForPath("/redirected-css.html").data());
     396    response = test->waitUntilResourceLoadFinsihedAndReturnURIResponse();
     397    g_assert_cmpstr(webkit_uri_response_get_mime_type(response), ==, "text/css");
    385398}
    386399
     
    556569    } else if (g_str_equal(path, "/javascript.js")) {
    557570        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, kJavascript, strlen(kJavascript));
     571        soup_message_headers_append(message->response_headers, "Content-Type", "text/javascript");
    558572    } else if (g_str_equal(path, "/blank.ico")) {
    559573        GOwnPtr<char> filePath(g_build_filename(Test::getWebKit1TestResoucesDir().data(), path, NULL));
     
    570584            "}";
    571585        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, simpleCSS, strlen(simpleCSS));
     586        soup_message_headers_append(message->response_headers, "Content-Type", "text/css");
    572587    } else if (g_str_equal(path, "/redirected.css")) {
    573588        soup_message_set_status(message, SOUP_STATUS_MOVED_PERMANENTLY);
     
    586601    SingleResourceLoadTest::add("WebKitWebResource", "loading", testWebResourceLoading);
    587602    SingleResourceLoadTest::add("WebKitWebResource", "response", testWebResourceResponse);
     603    SingleResourceLoadTest::add("WebKitWebResource", "mime-type", testWebResourceMimeType);
    588604    ResourceURITrackingTest::add("WebKitWebResource", "active-uri", testWebResourceActiveURI);
    589605    ResourcesTest::add("WebKitWebResource", "get-data", testWebResourceGetData);
  • trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp

    r117735 r118786  
    707707}
    708708
     709static void testWebViewCanShowMIMEType(WebViewTest* test, gconstpointer)
     710{
     711    // Supported MIME types.
     712    g_assert(webkit_web_view_can_show_mime_type(test->m_webView, "text/html"));
     713    g_assert(webkit_web_view_can_show_mime_type(test->m_webView, "text/plain"));
     714    g_assert(webkit_web_view_can_show_mime_type(test->m_webView, "image/jpeg"));
     715    g_assert(webkit_web_view_can_show_mime_type(test->m_webView, "audio/ogg"));
     716    g_assert(webkit_web_view_can_show_mime_type(test->m_webView, "video/ogg"));
     717    g_assert(webkit_web_view_can_show_mime_type(test->m_webView, "application/x-shockwave-flash"));
     718
     719    // Unsupported MIME types.
     720    g_assert(!webkit_web_view_can_show_mime_type(test->m_webView, "text/vcard"));
     721    g_assert(!webkit_web_view_can_show_mime_type(test->m_webView, "application/pdf"));
     722    g_assert(!webkit_web_view_can_show_mime_type(test->m_webView, "application/zip"));
     723    g_assert(!webkit_web_view_can_show_mime_type(test->m_webView, "application/octet-stream"));
     724}
     725
    709726void beforeAll()
    710727{
     
    721738    FileChooserTest::add("WebKitWebView", "file-chooser-request", testWebViewFileChooserRequest);
    722739    FullScreenClientTest::add("WebKitWebView", "fullscreen", testWebViewFullScreen);
     740    WebViewTest::add("WebKitWebView", "can-show-mime-type", testWebViewCanShowMIMEType);
    723741}
    724742
Note: See TracChangeset for help on using the changeset viewer.