Changeset 126030 in webkit
- Timestamp:
- Aug 20, 2012 8:10:55 AM (12 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r126019 r126030 1 2012-08-20 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 [GTK] Replace webkit_web_view_replace_content with webkit_web_view_load_alternate_html 4 https://bugs.webkit.org/show_bug.cgi?id=94471 5 6 Reviewed by Martin Robinson. 7 8 In WebKit1 there's code to prevent that load signals are emitted 9 when loading internal custom error pages. We added 10 webkit_web_view_replace_content() with the same idea, but it has 11 ended up being problematic, because it allows to add any HTML 12 content (in WebKit1 we assumed internal error pages never failed 13 and always loaded) and it's impossible to know when the load has 14 finished. It also required a lot of logic to handle 15 replace_content as an especial case, in order to hide the fact 16 that it loads content. This patch renames 17 webkit_web_view_replace_content() as 18 webkit_web_view_load_alternate_html() and emit load events 19 normally. 20 21 * UIProcess/API/gtk/WebKitWebView.cpp: 22 (_WebKitWebViewPrivate): 23 (webkitWebViewLoadChanged): 24 (webkitWebViewLoadFailed): 25 (webkitWebViewSetEstimatedLoadProgress): 26 (webkitWebViewResourceLoadStarted): 27 (webkitWebViewGetLoadingWebResource): 28 (webkitWebViewRemoveLoadingWebResource): 29 (webkitWebViewResourceLoadFinished): 30 (webkit_web_view_load_alternate_html): 31 * UIProcess/API/gtk/WebKitWebView.h: 32 * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: 33 * UIProcess/API/gtk/tests/TestLoaderClient.cpp: 34 (testLoadAlternateHTML): 35 (beforeAll): 36 * UIProcess/API/gtk/tests/TestResources.cpp: 37 (beforeAll): 38 * UIProcess/API/gtk/tests/TestWebKitWebView.cpp: 39 (beforeAll): 40 * UIProcess/API/gtk/tests/WebViewTest.cpp: 41 (WebViewTest::loadAlternateHTML): 42 * UIProcess/API/gtk/tests/WebViewTest.h: 43 1 44 2012-08-20 Mikhail Pozdnyakov <mikhail.pozdnyakov@intel.com> 2 45 -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp
r125890 r126030 107 107 }; 108 108 109 typedef enum {110 NotReplacingContent,111 WillReplaceContent,112 ReplacingContent,113 DidReplaceContent114 } ReplaceContentStatus;115 116 109 typedef HashMap<uint64_t, GRefPtr<WebKitWebResource> > LoadingResourcesMap; 117 110 typedef HashMap<String, GRefPtr<WebKitWebResource> > ResourcesMap; … … 123 116 double estimatedLoadProgress; 124 117 CString activeURI; 125 ReplaceContentStatus replaceContentStatus;126 118 127 119 bool waitingForMainResource; … … 160 152 161 153 GOwnPtr<char> htmlString(g_strdup_printf("<html><body>%s</body></html>", error->message)); 162 webkit_web_view_ replace_content(webView, htmlString.get(), failingURI, 0);154 webkit_web_view_load_alternate_html(webView, htmlString.get(), failingURI, 0); 163 155 164 156 return TRUE; … … 1108 1100 } 1109 1101 1110 static bool updateReplaceContentStatus(WebKitWebView* webView, WebKitLoadEvent loadEvent)1111 {1112 if (webView->priv->replaceContentStatus == ReplacingContent) {1113 if (loadEvent == WEBKIT_LOAD_FINISHED)1114 webView->priv->replaceContentStatus = DidReplaceContent;1115 return true;1116 }1117 1118 if (loadEvent == WEBKIT_LOAD_STARTED) {1119 if (webView->priv->replaceContentStatus == WillReplaceContent) {1120 webView->priv->replaceContentStatus = ReplacingContent;1121 return true;1122 }1123 webView->priv->replaceContentStatus = NotReplacingContent;1124 }1125 1126 return false;1127 }1128 1129 1102 static void setCertificateToMainResource(WebKitWebView* webView) 1130 1103 { … … 1170 1143 } else if (loadEvent == WEBKIT_LOAD_COMMITTED) { 1171 1144 webView->priv->subresourcesMap.clear(); 1172 if (webView->priv->replaceContentStatus != ReplacingContent) { 1173 if (!webView->priv->mainResource) { 1174 // When a page is loaded from the history cache, the main resource load callbacks 1175 // are called when the main frame load is finished. We want to make sure there's a 1176 // main resource available when load has been committed, so we delay the emission of 1177 // load-changed signal until main resource object has been created. 1178 webView->priv->waitingForMainResource = true; 1179 } else 1180 setCertificateToMainResource(webView); 1181 } 1145 if (!webView->priv->mainResource) { 1146 // When a page is loaded from the history cache, the main resource load callbacks 1147 // are called when the main frame load is finished. We want to make sure there's a 1148 // main resource available when load has been committed, so we delay the emission of 1149 // load-changed signal until main resource object has been created. 1150 webView->priv->waitingForMainResource = true; 1151 } else 1152 setCertificateToMainResource(webView); 1182 1153 } 1183 1184 if (updateReplaceContentStatus(webView, loadEvent))1185 return;1186 1154 1187 1155 if (webView->priv->waitingForMainResource) … … 1193 1161 void webkitWebViewLoadFailed(WebKitWebView* webView, WebKitLoadEvent loadEvent, const char* failingURI, GError *error) 1194 1162 { 1195 if (webView->priv->replaceContentStatus == ReplacingContent)1196 return;1197 1198 1163 gboolean returnValue; 1199 1164 g_signal_emit(webView, signals[LOAD_FAILED], 0, loadEvent, failingURI, error, &returnValue); … … 1213 1178 void webkitWebViewSetEstimatedLoadProgress(WebKitWebView* webView, double estimatedLoadProgress) 1214 1179 { 1215 if (webView->priv->replaceContentStatus != NotReplacingContent)1216 return;1217 1218 1180 if (webView->priv->estimatedLoadProgress == estimatedLoadProgress) 1219 1181 return; … … 1350 1312 } 1351 1313 1352 static inline bool webkitWebViewIsReplacingContentOrDidReplaceContent(WebKitWebView* webView)1353 {1354 return (webView->priv->replaceContentStatus == ReplacingContent || webView->priv->replaceContentStatus == DidReplaceContent);1355 }1356 1357 1314 void webkitWebViewResourceLoadStarted(WebKitWebView* webView, WKFrameRef wkFrame, uint64_t resourceIdentifier, WebKitURIRequest* request, bool isMainResource) 1358 1315 { 1359 if (webkitWebViewIsReplacingContentOrDidReplaceContent(webView))1360 return;1361 1362 1316 WebKitWebViewPrivate* priv = webView->priv; 1363 1317 WebKitWebResource* resource = webkitWebResourceCreate(wkFrame, request, isMainResource); … … 1372 1326 WebKitWebResource* webkitWebViewGetLoadingWebResource(WebKitWebView* webView, uint64_t resourceIdentifier) 1373 1327 { 1374 if (webkitWebViewIsReplacingContentOrDidReplaceContent(webView))1375 return 0;1376 1377 1328 GRefPtr<WebKitWebResource> resource = webView->priv->loadingResourcesMap.get(resourceIdentifier); 1378 1329 ASSERT(resource.get()); … … 1382 1333 void webkitWebViewRemoveLoadingWebResource(WebKitWebView* webView, uint64_t resourceIdentifier) 1383 1334 { 1384 if (webkitWebViewIsReplacingContentOrDidReplaceContent(webView))1385 return;1386 1387 1335 WebKitWebViewPrivate* priv = webView->priv; 1388 1336 ASSERT(priv->loadingResourcesMap.contains(resourceIdentifier)); … … 1392 1340 WebKitWebResource* webkitWebViewResourceLoadFinished(WebKitWebView* webView, uint64_t resourceIdentifier) 1393 1341 { 1394 if (webkitWebViewIsReplacingContentOrDidReplaceContent(webView))1395 return 0;1396 1397 1342 WebKitWebViewPrivate* priv = webView->priv; 1398 1343 WebKitWebResource* resource = webkitWebViewGetLoadingWebResource(webView, resourceIdentifier); … … 1598 1543 1599 1544 /** 1600 * webkit_web_view_load_plain_text: 1601 * @web_view: a #WebKitWebView 1602 * @plain_text: The plain text to load 1603 * 1604 * Load the specified @plain_text string into @web_view. The mime type of 1605 * document will be "text/plain". You can monitor the load 1606 * operation by connecting to #WebKitWebView::load-changed signal. 1607 */ 1608 void webkit_web_view_load_plain_text(WebKitWebView* webView, const gchar* plainText) 1609 { 1610 g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); 1611 g_return_if_fail(plainText); 1612 1613 WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView)); 1614 WKRetainPtr<WKStringRef> plainTextRef(AdoptWK, WKStringCreateWithUTF8CString(plainText)); 1615 WKPageLoadPlainTextString(toAPI(page), plainTextRef.get()); 1616 } 1617 1618 /** 1619 * webkit_web_view_load_request: 1620 * @web_view: a #WebKitWebView 1621 * @request: a #WebKitURIRequest to load 1622 * 1623 * Requests loading of the specified #WebKitURIRequest. 1624 * You can monitor the load operation by connecting to 1625 * #WebKitWebView::load-changed signal. 1626 */ 1627 void webkit_web_view_load_request(WebKitWebView* webView, WebKitURIRequest* request) 1628 { 1629 g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); 1630 g_return_if_fail(WEBKIT_IS_URI_REQUEST(request)); 1631 1632 WKRetainPtr<WKURLRef> wkURL(AdoptWK, WKURLCreateWithUTF8CString(webkit_uri_request_get_uri(request))); 1633 WKRetainPtr<WKURLRequestRef> wkRequest(AdoptWK, WKURLRequestCreateWithWKURL(wkURL.get())); 1634 WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView)); 1635 WKPageLoadURLRequest(toAPI(page), wkRequest.get()); 1636 webkitWebViewUpdateURI(webView); 1637 } 1638 1639 /** 1640 * webkit_web_view_replace_content: 1545 * webkit_web_view_load_alternate_html: 1641 1546 * @web_view: a #WebKitWebView 1642 1547 * @content: the new content to display as the main page of the @web_view 1643 * @content_uri: the URI for the page content1548 * @content_uri: the URI for the alternate page content 1644 1549 * @base_uri: (allow-none): the base URI for relative locations or %NULL 1645 1550 * 1646 * Replace the content of @web_view with @content using @content_uri as page URI.1551 * Load the given @content string for the URI @content_uri. 1647 1552 * This allows clients to display page-loading errors in the #WebKitWebView itself. 1648 * This is typically called from #WebKitWebView::load-failed signal. The URI passed in 1649 * @base_uri has to be an absolute URI. The mime type of the document will be "text/html". 1650 * Signals #WebKitWebView::load-changed and #WebKitWebView::load-failed are not emitted 1651 * when replacing content of a #WebKitWebView using this method. 1652 */ 1653 void webkit_web_view_replace_content(WebKitWebView* webView, const gchar* content, const gchar* contentURI, const gchar* baseURI) 1553 * When this method is called from #WebKitWebView::load-failed signal to show an 1554 * error page, the the back-forward list is maintained appropriately. 1555 * For everything else this method works the same way as webkit_web_view_load_html(). 1556 */ 1557 void webkit_web_view_load_alternate_html(WebKitWebView* webView, const gchar* content, const gchar* contentURI, const gchar* baseURI) 1654 1558 { 1655 1559 g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); 1656 1560 g_return_if_fail(content); 1657 1561 g_return_if_fail(contentURI); 1658 1659 webView->priv->replaceContentStatus = WillReplaceContent;1660 1562 1661 1563 WKRetainPtr<WKStringRef> htmlString(AdoptWK, WKStringCreateWithUTF8CString(content)); … … 1664 1566 WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView)); 1665 1567 WKPageLoadAlternateHTMLString(toAPI(page), htmlString.get(), baseURL.get(), contentURL.get()); 1568 webkitWebViewUpdateURI(webView); 1569 } 1570 1571 /** 1572 * webkit_web_view_load_plain_text: 1573 * @web_view: a #WebKitWebView 1574 * @plain_text: The plain text to load 1575 * 1576 * Load the specified @plain_text string into @web_view. The mime type of 1577 * document will be "text/plain". You can monitor the load 1578 * operation by connecting to #WebKitWebView::load-changed signal. 1579 */ 1580 void webkit_web_view_load_plain_text(WebKitWebView* webView, const gchar* plainText) 1581 { 1582 g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); 1583 g_return_if_fail(plainText); 1584 1585 WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView)); 1586 WKRetainPtr<WKStringRef> plainTextRef(AdoptWK, WKStringCreateWithUTF8CString(plainText)); 1587 WKPageLoadPlainTextString(toAPI(page), plainTextRef.get()); 1588 } 1589 1590 /** 1591 * webkit_web_view_load_request: 1592 * @web_view: a #WebKitWebView 1593 * @request: a #WebKitURIRequest to load 1594 * 1595 * Requests loading of the specified #WebKitURIRequest. 1596 * You can monitor the load operation by connecting to 1597 * #WebKitWebView::load-changed signal. 1598 */ 1599 void webkit_web_view_load_request(WebKitWebView* webView, WebKitURIRequest* request) 1600 { 1601 g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); 1602 g_return_if_fail(WEBKIT_IS_URI_REQUEST(request)); 1603 1604 WKRetainPtr<WKURLRef> wkURL(AdoptWK, WKURLCreateWithUTF8CString(webkit_uri_request_get_uri(request))); 1605 WKRetainPtr<WKURLRequestRef> wkRequest(AdoptWK, WKURLRequestCreateWithWKURL(wkURL.get())); 1606 WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView)); 1607 WKPageLoadURLRequest(toAPI(page), wkRequest.get()); 1666 1608 webkitWebViewUpdateURI(webView); 1667 1609 } … … 1814 1756 * If the load operation was started by webkit_web_view_load_html(), 1815 1757 * the requested URI is "about:blank". 1758 * </para></listitem> 1759 * <listitem><para> 1760 * If the load operation was started by webkit_web_view_load_alternate_html(), 1761 * the requested URI is content URI provided. 1816 1762 * </para></listitem> 1817 1763 * <listitem><para> … … 1839 1785 * or a navigation action within the same page is performed. 1840 1786 * </para></listitem> 1841 * <listitem><para>1842 * When the page content is replaced using webkit_web_view_replace_content(),1843 * the active URI is the content_uri provided.1844 * </para></listitem>1845 1787 * </orderedlist> 1846 1788 * -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h
r125890 r126030 211 211 const gchar *content, 212 212 const gchar *base_uri); 213 214 WEBKIT_API void 215 webkit_web_view_load_plain_text (WebKitWebView *web_view, 216 const gchar *plain_text); 217 218 WEBKIT_API void 219 webkit_web_view_load_request (WebKitWebView *web_view, 220 WebKitURIRequest *request); 221 222 WEBKIT_API void 223 webkit_web_view_stop_loading (WebKitWebView *web_view); 224 225 WEBKIT_API void 226 webkit_web_view_replace_content (WebKitWebView *web_view, 213 WEBKIT_API void 214 webkit_web_view_load_alternate_html (WebKitWebView *web_view, 227 215 const gchar *content, 228 216 const gchar *content_uri, 229 217 const gchar *base_uri); 218 WEBKIT_API void 219 webkit_web_view_load_plain_text (WebKitWebView *web_view, 220 const gchar *plain_text); 221 222 WEBKIT_API void 223 webkit_web_view_load_request (WebKitWebView *web_view, 224 WebKitURIRequest *request); 225 226 WEBKIT_API void 227 webkit_web_view_stop_loading (WebKitWebView *web_view); 230 228 231 229 WEBKIT_API const gchar * -
trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt
r126017 r126030 77 77 webkit_web_view_load_uri 78 78 webkit_web_view_load_html 79 webkit_web_view_load_alternate_html 79 80 webkit_web_view_load_plain_text 80 81 webkit_web_view_load_request 81 webkit_web_view_replace_content82 82 webkit_web_view_can_go_back 83 83 webkit_web_view_go_back -
trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestLoaderClient.cpp
r124456 r126030 71 71 } 72 72 73 static void testLoadAlternateHTML(LoadTrackingTest* test, gconstpointer) 74 { 75 test->loadAlternateHTML("<html><body>Alternate page</body></html>", "http://error-page.foo/", 0); 76 test->waitUntilLoadFinished(); 77 assertNormalLoadHappened(test->m_loadEvents); 78 } 79 73 80 static void testLoadPlainText(LoadTrackingTest* test, gconstpointer) 74 81 { … … 263 270 LoadTrackingTest::add("WebKitWebView", "loading-error", testLoadingError); 264 271 LoadTrackingTest::add("WebKitWebView", "load-html", testLoadHtml); 272 LoadTrackingTest::add("WebKitWebView", "load-alternate-html", testLoadAlternateHTML); 265 273 LoadTrackingTest::add("WebKitWebView", "load-plain-text", testLoadPlainText); 266 274 LoadTrackingTest::add("WebKitWebView", "load-request", testLoadRequest); -
trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp
r125910 r126030 504 504 for (GList* item = subresources.get(); item; item = g_list_next(item)) 505 505 test->checkResourceData(WEBKIT_WEB_RESOURCE(item->data)); 506 }507 508 static void replacedContentResourceLoadStartedCallback()509 {510 g_assert_not_reached();511 }512 513 static void testWebViewResourcesReplacedContent(ResourcesTest* test, gconstpointer)514 {515 test->loadURI(kServer->getURIForPath("/").data());516 // FIXME: this should be 4 instead of 3, but we don't get the css image resource517 // due to bug https://bugs.webkit.org/show_bug.cgi?id=78510.518 test->waitUntilResourcesLoaded(3);519 520 static const char* replacedHtml =521 "<html><head>"522 " <title>Content Replaced</title>"523 " <link rel='stylesheet' href='data:text/css,body { margin: 0px; padding: 0px; }' type='text/css'>"524 " <script language='javascript' src='data:application/javascript,function foo () { var a = 1; }'></script>"525 "</head><body onload='document.title=\"Loaded\"'>WebKitGTK+ resources on replaced content test</body></html>";526 g_signal_connect(test->m_webView, "resource-load-started", G_CALLBACK(replacedContentResourceLoadStartedCallback), test);527 test->replaceContent(replacedHtml, "http://error-page.foo", 0);528 test->waitUntilTitleChangedTo("Loaded");529 530 g_assert(!webkit_web_view_get_main_resource(test->m_webView));531 g_assert(!webkit_web_view_get_subresources(test->m_webView));532 506 } 533 507 … … 636 610 ResourceURITrackingTest::add("WebKitWebResource", "active-uri", testWebResourceActiveURI); 637 611 ResourcesTest::add("WebKitWebResource", "get-data", testWebResourceGetData); 638 ResourcesTest::add("WebKitWebView", "replaced-content", testWebViewResourcesReplacedContent);639 612 SingleResourceLoadTest::add("WebKitWebView", "history-cache", testWebViewResourcesHistoryCache); 640 613 } -
trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp
r125267 r126030 75 75 } 76 76 77 static void replaceContentLoadCallback(WebKitWebView* webView, WebKitLoadEvent loadEvent, WebViewTest* test)78 {79 // There might be an event from a previous load,80 // but never a WEBKIT_LOAD_STARTED after webkit_web_view_replace_content().81 g_assert_cmpint(loadEvent, !=, WEBKIT_LOAD_STARTED);82 }83 84 static void testWebViewReplaceContent(WebViewTest* test, gconstpointer)85 {86 test->loadHtml("<html><head><title>Replace Content Test</title></head><body>Content to replace</body></html>", 0);87 test->waitUntilTitleChangedTo("Replace Content Test");88 89 g_signal_connect(test->m_webView, "load-changed", G_CALLBACK(replaceContentLoadCallback), test);90 test->replaceContent("<html><body onload='document.title=\"Content Replaced\"'>New Content</body></html>",91 "http://foo.com/bar", 0);92 test->waitUntilTitleChangedTo("Content Replaced");93 }94 95 77 static const char* kAlertDialogMessage = "WebKitGTK+ alert dialog message"; 96 78 static const char* kConfirmDialogMessage = "WebKitGTK+ confirm dialog message"; … … 1049 1031 WebViewTest::add("WebKitWebView", "custom-charset", testWebViewCustomCharset); 1050 1032 WebViewTest::add("WebKitWebView", "settings", testWebViewSettings); 1051 WebViewTest::add("WebKitWebView", "replace-content", testWebViewReplaceContent);1052 1033 UIClientTest::add("WebKitWebView", "create-ready-close", testWebViewCreateReadyClose); 1053 1034 ModalDialogsTest::add("WebKitWebView", "allow-modal-dialogs", testWebViewAllowModalDialogs); -
trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp
r126017 r126030 72 72 } 73 73 74 void WebViewTest:: replaceContent(const char* html, const char* contentURI, const char* baseURI)74 void WebViewTest::loadAlternateHTML(const char* html, const char* contentURI, const char* baseURI) 75 75 { 76 76 m_activeURI = contentURI; 77 webkit_web_view_ replace_content(m_webView, html, contentURI, baseURI);77 webkit_web_view_load_alternate_html(m_webView, html, contentURI, baseURI); 78 78 } 79 79 -
trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h
r126017 r126030 36 36 virtual void loadPlainText(const char* plainText); 37 37 virtual void loadRequest(WebKitURIRequest*); 38 void replaceContent(const char* html, const char* contentURI, const char* baseURI);38 void loadAlternateHTML(const char* html, const char* contentURI, const char* baseURI); 39 39 void goBack(); 40 40 void goForward();
Note: See TracChangeset
for help on using the changeset viewer.