Changeset 118786 in webkit
- Timestamp:
- May 29, 2012 9:09:46 AM (12 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r118774 r118786 1 2012-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 1 37 2012-05-29 David Barr <davidbarr@chromium.org> 2 38 -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.cpp
r105704 r118786 31 31 PROP_URI, 32 32 PROP_STATUS_CODE, 33 PROP_CONTENT_LENGTH 33 PROP_CONTENT_LENGTH, 34 PROP_MIME_TYPE 34 35 }; 35 36 … … 41 42 WebCore::ResourceResponse resourceResponse; 42 43 CString uri; 44 CString mimeType; 43 45 }; 44 46 … … 62 64 case PROP_CONTENT_LENGTH: 63 65 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)); 64 69 break; 65 70 default: … … 113 118 WEBKIT_PARAM_READABLE)); 114 119 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 115 133 g_type_class_add_private(responseClass, sizeof(WebKitURIResponsePrivate)); 116 134 } … … 171 189 } 172 190 191 /** 192 * webkit_uri_response_get_mime_type: 193 * @response: a #WebKitURIResponse 194 * 195 * Returns: the MIME type of the #WebKitURIResponse 196 */ 197 const 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 173 205 WebKitURIResponse* webkitURIResponseCreateForResourceResponse(const WebCore::ResourceResponse& resourceResponse) 174 206 { -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.h
r101350 r118786 65 65 webkit_uri_response_get_content_length (WebKitURIResponse *response); 66 66 67 WEBKIT_API const gchar * 68 webkit_uri_response_get_mime_type (WebKitURIResponse *response); 69 67 70 G_END_DECLS 68 71 -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp
r118732 r118786 34 34 #include "WebKitPrivate.h" 35 35 #include "WebKitResourceLoadClient.h" 36 #include "WebKitResponsePolicyDecision.h" 36 37 #include "WebKitScriptDialogPrivate.h" 37 38 #include "WebKitSettingsPrivate.h" 38 39 #include "WebKitUIClient.h" 40 #include "WebKitURIResponsePrivate.h" 39 41 #include "WebKitWebContextPrivate.h" 40 42 #include "WebKitWebInspectorPrivate.h" … … 191 193 } 192 194 193 static gboolean webkitWebViewDecidePolicy(WebKitWebView*, WebKitPolicyDecision* decision, WebKitPolicyDecisionType) 194 { 195 webkit_policy_decision_use(decision); 195 static 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 196 214 return TRUE; 197 215 } … … 2027 2045 return webView->priv->inspector.get(); 2028 2046 } 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 */ 2057 gboolean 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 307 307 webkit_web_view_get_inspector (WebKitWebView *web_view); 308 308 309 WEBKIT_API gboolean 310 webkit_web_view_can_show_mime_type (WebKitWebView *web_view, 311 const gchar *mime_type); 312 309 313 G_END_DECLS 310 314 -
trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt
r118522 r118786 96 96 webkit_web_view_run_javascript 97 97 webkit_web_view_run_javascript_finish 98 webkit_web_view_can_show_mime_type 98 99 99 100 <SUBSECTION WebKitJavascriptResult> … … 303 304 webkit_uri_response_get_status_code 304 305 webkit_uri_response_get_content_length 306 webkit_uri_response_get_mime_type 305 307 306 308 <SUBSECTION Standard> -
trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp
r117735 r118786 301 301 } 302 302 303 int waitUntilResourceLoadFinsihedAndReturnHTTPStatusResponse()303 WebKitURIResponse* waitUntilResourceLoadFinsihedAndReturnURIResponse() 304 304 { 305 305 waitUntilResourceLoadFinsihed(); 306 306 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()); 310 308 } 311 309 … … 356 354 // No cached resource: First load. 357 355 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); 360 358 361 359 // No cached resource: Second load. 362 360 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); 365 363 366 364 // No cached resource: Reload. 367 365 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); 370 368 371 369 // Cached resource: First load. 372 370 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); 375 373 376 374 // Cached resource: Second load. 377 375 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); 380 378 381 379 // Cached resource: Reload. 382 380 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 385 static 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"); 385 398 } 386 399 … … 556 569 } else if (g_str_equal(path, "/javascript.js")) { 557 570 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"); 558 572 } else if (g_str_equal(path, "/blank.ico")) { 559 573 GOwnPtr<char> filePath(g_build_filename(Test::getWebKit1TestResoucesDir().data(), path, NULL)); … … 570 584 "}"; 571 585 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"); 572 587 } else if (g_str_equal(path, "/redirected.css")) { 573 588 soup_message_set_status(message, SOUP_STATUS_MOVED_PERMANENTLY); … … 586 601 SingleResourceLoadTest::add("WebKitWebResource", "loading", testWebResourceLoading); 587 602 SingleResourceLoadTest::add("WebKitWebResource", "response", testWebResourceResponse); 603 SingleResourceLoadTest::add("WebKitWebResource", "mime-type", testWebResourceMimeType); 588 604 ResourceURITrackingTest::add("WebKitWebResource", "active-uri", testWebResourceActiveURI); 589 605 ResourcesTest::add("WebKitWebResource", "get-data", testWebResourceGetData); -
trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp
r117735 r118786 707 707 } 708 708 709 static 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 709 726 void beforeAll() 710 727 { … … 721 738 FileChooserTest::add("WebKitWebView", "file-chooser-request", testWebViewFileChooserRequest); 722 739 FullScreenClientTest::add("WebKitWebView", "fullscreen", testWebViewFullScreen); 740 WebViewTest::add("WebKitWebView", "can-show-mime-type", testWebViewCanShowMIMEType); 723 741 } 724 742
Note: See TracChangeset
for help on using the changeset viewer.