Diff
Modified: trunk/Source/WebKit2/ChangeLog (126029 => 126030)
--- trunk/Source/WebKit2/ChangeLog 2012-08-20 15:09:22 UTC (rev 126029)
+++ trunk/Source/WebKit2/ChangeLog 2012-08-20 15:10:55 UTC (rev 126030)
@@ -1,3 +1,46 @@
+2012-08-20 Carlos Garcia Campos <cgar...@igalia.com>
+
+ [GTK] Replace webkit_web_view_replace_content with webkit_web_view_load_alternate_html
+ https://bugs.webkit.org/show_bug.cgi?id=94471
+
+ Reviewed by Martin Robinson.
+
+ In WebKit1 there's code to prevent that load signals are emitted
+ when loading internal custom error pages. We added
+ webkit_web_view_replace_content() with the same idea, but it has
+ ended up being problematic, because it allows to add any HTML
+ content (in WebKit1 we assumed internal error pages never failed
+ and always loaded) and it's impossible to know when the load has
+ finished. It also required a lot of logic to handle
+ replace_content as an especial case, in order to hide the fact
+ that it loads content. This patch renames
+ webkit_web_view_replace_content() as
+ webkit_web_view_load_alternate_html() and emit load events
+ normally.
+
+ * UIProcess/API/gtk/WebKitWebView.cpp:
+ (_WebKitWebViewPrivate):
+ (webkitWebViewLoadChanged):
+ (webkitWebViewLoadFailed):
+ (webkitWebViewSetEstimatedLoadProgress):
+ (webkitWebViewResourceLoadStarted):
+ (webkitWebViewGetLoadingWebResource):
+ (webkitWebViewRemoveLoadingWebResource):
+ (webkitWebViewResourceLoadFinished):
+ (webkit_web_view_load_alternate_html):
+ * UIProcess/API/gtk/WebKitWebView.h:
+ * UIProcess/API/gtk/docs/webkit2gtk-sections.txt:
+ * UIProcess/API/gtk/tests/TestLoaderClient.cpp:
+ (testLoadAlternateHTML):
+ (beforeAll):
+ * UIProcess/API/gtk/tests/TestResources.cpp:
+ (beforeAll):
+ * UIProcess/API/gtk/tests/TestWebKitWebView.cpp:
+ (beforeAll):
+ * UIProcess/API/gtk/tests/WebViewTest.cpp:
+ (WebViewTest::loadAlternateHTML):
+ * UIProcess/API/gtk/tests/WebViewTest.h:
+
2012-08-20 Mikhail Pozdnyakov <mikhail.pozdnya...@intel.com>
[EFL][WK2] Add unit tests for WKEinaSharedString
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp (126029 => 126030)
--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp 2012-08-20 15:09:22 UTC (rev 126029)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp 2012-08-20 15:10:55 UTC (rev 126030)
@@ -106,13 +106,6 @@
PROP_ZOOM_LEVEL
};
-typedef enum {
- NotReplacingContent,
- WillReplaceContent,
- ReplacingContent,
- DidReplaceContent
-} ReplaceContentStatus;
-
typedef HashMap<uint64_t, GRefPtr<WebKitWebResource> > LoadingResourcesMap;
typedef HashMap<String, GRefPtr<WebKitWebResource> > ResourcesMap;
@@ -122,7 +115,6 @@
CString customTextEncoding;
double estimatedLoadProgress;
CString activeURI;
- ReplaceContentStatus replaceContentStatus;
bool waitingForMainResource;
gulong mainResourceResponseHandlerID;
@@ -159,7 +151,7 @@
return FALSE;
GOwnPtr<char> htmlString(g_strdup_printf("<html><body>%s</body></html>", error->message));
- webkit_web_view_replace_content(webView, htmlString.get(), failingURI, 0);
+ webkit_web_view_load_alternate_html(webView, htmlString.get(), failingURI, 0);
return TRUE;
}
@@ -1107,25 +1099,6 @@
WEBKIT_TYPE_FORM_SUBMISSION_REQUEST);
}
-static bool updateReplaceContentStatus(WebKitWebView* webView, WebKitLoadEvent loadEvent)
-{
- if (webView->priv->replaceContentStatus == ReplacingContent) {
- if (loadEvent == WEBKIT_LOAD_FINISHED)
- webView->priv->replaceContentStatus = DidReplaceContent;
- return true;
- }
-
- if (loadEvent == WEBKIT_LOAD_STARTED) {
- if (webView->priv->replaceContentStatus == WillReplaceContent) {
- webView->priv->replaceContentStatus = ReplacingContent;
- return true;
- }
- webView->priv->replaceContentStatus = NotReplacingContent;
- }
-
- return false;
-}
-
static void setCertificateToMainResource(WebKitWebView* webView)
{
WebKitWebViewPrivate* priv = webView->priv;
@@ -1169,21 +1142,16 @@
webView->priv->waitingForMainResource = false;
} else if (loadEvent == WEBKIT_LOAD_COMMITTED) {
webView->priv->subresourcesMap.clear();
- if (webView->priv->replaceContentStatus != ReplacingContent) {
- if (!webView->priv->mainResource) {
- // When a page is loaded from the history cache, the main resource load callbacks
- // are called when the main frame load is finished. We want to make sure there's a
- // main resource available when load has been committed, so we delay the emission of
- // load-changed signal until main resource object has been created.
- webView->priv->waitingForMainResource = true;
- } else
- setCertificateToMainResource(webView);
- }
+ if (!webView->priv->mainResource) {
+ // When a page is loaded from the history cache, the main resource load callbacks
+ // are called when the main frame load is finished. We want to make sure there's a
+ // main resource available when load has been committed, so we delay the emission of
+ // load-changed signal until main resource object has been created.
+ webView->priv->waitingForMainResource = true;
+ } else
+ setCertificateToMainResource(webView);
}
- if (updateReplaceContentStatus(webView, loadEvent))
- return;
-
if (webView->priv->waitingForMainResource)
webView->priv->lastDelayedEvent = loadEvent;
else
@@ -1192,9 +1160,6 @@
void webkitWebViewLoadFailed(WebKitWebView* webView, WebKitLoadEvent loadEvent, const char* failingURI, GError *error)
{
- if (webView->priv->replaceContentStatus == ReplacingContent)
- return;
-
gboolean returnValue;
g_signal_emit(webView, signals[LOAD_FAILED], 0, loadEvent, failingURI, error, &returnValue);
g_signal_emit(webView, signals[LOAD_CHANGED], 0, WEBKIT_LOAD_FINISHED);
@@ -1212,9 +1177,6 @@
void webkitWebViewSetEstimatedLoadProgress(WebKitWebView* webView, double estimatedLoadProgress)
{
- if (webView->priv->replaceContentStatus != NotReplacingContent)
- return;
-
if (webView->priv->estimatedLoadProgress == estimatedLoadProgress)
return;
@@ -1349,16 +1311,8 @@
g_signal_connect(priv->mainResource.get(), "notify::response", G_CALLBACK(mainResourceResponseChangedCallback), webView);
}
-static inline bool webkitWebViewIsReplacingContentOrDidReplaceContent(WebKitWebView* webView)
-{
- return (webView->priv->replaceContentStatus == ReplacingContent || webView->priv->replaceContentStatus == DidReplaceContent);
-}
-
void webkitWebViewResourceLoadStarted(WebKitWebView* webView, WKFrameRef wkFrame, uint64_t resourceIdentifier, WebKitURIRequest* request, bool isMainResource)
{
- if (webkitWebViewIsReplacingContentOrDidReplaceContent(webView))
- return;
-
WebKitWebViewPrivate* priv = webView->priv;
WebKitWebResource* resource = webkitWebResourceCreate(wkFrame, request, isMainResource);
if (WKFrameIsMainFrame(wkFrame) && (isMainResource || !priv->mainResource)) {
@@ -1371,9 +1325,6 @@
WebKitWebResource* webkitWebViewGetLoadingWebResource(WebKitWebView* webView, uint64_t resourceIdentifier)
{
- if (webkitWebViewIsReplacingContentOrDidReplaceContent(webView))
- return 0;
-
GRefPtr<WebKitWebResource> resource = webView->priv->loadingResourcesMap.get(resourceIdentifier);
ASSERT(resource.get());
return resource.get();
@@ -1381,9 +1332,6 @@
void webkitWebViewRemoveLoadingWebResource(WebKitWebView* webView, uint64_t resourceIdentifier)
{
- if (webkitWebViewIsReplacingContentOrDidReplaceContent(webView))
- return;
-
WebKitWebViewPrivate* priv = webView->priv;
ASSERT(priv->loadingResourcesMap.contains(resourceIdentifier));
priv->loadingResourcesMap.remove(resourceIdentifier);
@@ -1391,9 +1339,6 @@
WebKitWebResource* webkitWebViewResourceLoadFinished(WebKitWebView* webView, uint64_t resourceIdentifier)
{
- if (webkitWebViewIsReplacingContentOrDidReplaceContent(webView))
- return 0;
-
WebKitWebViewPrivate* priv = webView->priv;
WebKitWebResource* resource = webkitWebViewGetLoadingWebResource(webView, resourceIdentifier);
if (resource != priv->mainResource)
@@ -1597,6 +1542,33 @@
}
/**
+ * webkit_web_view_load_alternate_html:
+ * @web_view: a #WebKitWebView
+ * @content: the new content to display as the main page of the @web_view
+ * @content_uri: the URI for the alternate page content
+ * @base_uri: (allow-none): the base URI for relative locations or %NULL
+ *
+ * Load the given @content string for the URI @content_uri.
+ * This allows clients to display page-loading errors in the #WebKitWebView itself.
+ * When this method is called from #WebKitWebView::load-failed signal to show an
+ * error page, the the back-forward list is maintained appropriately.
+ * For everything else this method works the same way as webkit_web_view_load_html().
+ */
+void webkit_web_view_load_alternate_html(WebKitWebView* webView, const gchar* content, const gchar* contentURI, const gchar* baseURI)
+{
+ g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
+ g_return_if_fail(content);
+ g_return_if_fail(contentURI);
+
+ WKRetainPtr<WKStringRef> htmlString(AdoptWK, WKStringCreateWithUTF8CString(content));
+ WKRetainPtr<WKURLRef> contentURL(AdoptWK, WKURLCreateWithUTF8CString(contentURI));
+ WKRetainPtr<WKURLRef> baseURL = baseURI ? adoptWK(WKURLCreateWithUTF8CString(baseURI)) : 0;
+ WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView));
+ WKPageLoadAlternateHTMLString(toAPI(page), htmlString.get(), baseURL.get(), contentURL.get());
+ webkitWebViewUpdateURI(webView);
+}
+
+/**
* webkit_web_view_load_plain_text:
* @web_view: a #WebKitWebView
* @plain_text: The plain text to load
@@ -1637,36 +1609,6 @@
}
/**
- * webkit_web_view_replace_content:
- * @web_view: a #WebKitWebView
- * @content: the new content to display as the main page of the @web_view
- * @content_uri: the URI for the page content
- * @base_uri: (allow-none): the base URI for relative locations or %NULL
- *
- * Replace the content of @web_view with @content using @content_uri as page URI.
- * This allows clients to display page-loading errors in the #WebKitWebView itself.
- * This is typically called from #WebKitWebView::load-failed signal. The URI passed in
- * @base_uri has to be an absolute URI. The mime type of the document will be "text/html".
- * Signals #WebKitWebView::load-changed and #WebKitWebView::load-failed are not emitted
- * when replacing content of a #WebKitWebView using this method.
- */
-void webkit_web_view_replace_content(WebKitWebView* webView, const gchar* content, const gchar* contentURI, const gchar* baseURI)
-{
- g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
- g_return_if_fail(content);
- g_return_if_fail(contentURI);
-
- webView->priv->replaceContentStatus = WillReplaceContent;
-
- WKRetainPtr<WKStringRef> htmlString(AdoptWK, WKStringCreateWithUTF8CString(content));
- WKRetainPtr<WKURLRef> contentURL(AdoptWK, WKURLCreateWithUTF8CString(contentURI));
- WKRetainPtr<WKURLRef> baseURL = baseURI ? adoptWK(WKURLCreateWithUTF8CString(baseURI)) : 0;
- WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView));
- WKPageLoadAlternateHTMLString(toAPI(page), htmlString.get(), baseURL.get(), contentURL.get());
- webkitWebViewUpdateURI(webView);
-}
-
-/**
* webkit_web_view_get_title:
* @web_view: a #WebKitWebView
*
@@ -1815,6 +1757,10 @@
* the requested URI is "about:blank".
* </para></listitem>
* <listitem><para>
+ * If the load operation was started by webkit_web_view_load_alternate_html(),
+ * the requested URI is content URI provided.
+ * </para></listitem>
+ * <listitem><para>
* If the load operation was started by webkit_web_view_go_back() or
* webkit_web_view_go_forward(), the requested URI is the original URI
* of the previous/next item in the #WebKitBackForwardList of @web_view.
@@ -1838,10 +1784,6 @@
* one and it will not change unless a new load operation is started
* or a navigation action within the same page is performed.
* </para></listitem>
- * <listitem><para>
- * When the page content is replaced using webkit_web_view_replace_content(),
- * the active URI is the content_uri provided.
- * </para></listitem>
* </orderedlist>
*
* You can monitor the active URI by connecting to the notify::uri
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h (126029 => 126030)
--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h 2012-08-20 15:09:22 UTC (rev 126029)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h 2012-08-20 15:10:55 UTC (rev 126030)
@@ -210,8 +210,12 @@
webkit_web_view_load_html (WebKitWebView *web_view,
const gchar *content,
const gchar *base_uri);
-
WEBKIT_API void
+webkit_web_view_load_alternate_html (WebKitWebView *web_view,
+ const gchar *content,
+ const gchar *content_uri,
+ const gchar *base_uri);
+WEBKIT_API void
webkit_web_view_load_plain_text (WebKitWebView *web_view,
const gchar *plain_text);
@@ -222,12 +226,6 @@
WEBKIT_API void
webkit_web_view_stop_loading (WebKitWebView *web_view);
-WEBKIT_API void
-webkit_web_view_replace_content (WebKitWebView *web_view,
- const gchar *content,
- const gchar *content_uri,
- const gchar *base_uri);
-
WEBKIT_API const gchar *
webkit_web_view_get_title (WebKitWebView *web_view);
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt (126029 => 126030)
--- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt 2012-08-20 15:09:22 UTC (rev 126029)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt 2012-08-20 15:10:55 UTC (rev 126030)
@@ -76,9 +76,9 @@
webkit_web_view_get_context
webkit_web_view_load_uri
webkit_web_view_load_html
+webkit_web_view_load_alternate_html
webkit_web_view_load_plain_text
webkit_web_view_load_request
-webkit_web_view_replace_content
webkit_web_view_can_go_back
webkit_web_view_go_back
webkit_web_view_can_go_forward
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestLoaderClient.cpp (126029 => 126030)
--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestLoaderClient.cpp 2012-08-20 15:09:22 UTC (rev 126029)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestLoaderClient.cpp 2012-08-20 15:10:55 UTC (rev 126030)
@@ -70,6 +70,13 @@
assertNormalLoadHappened(test->m_loadEvents);
}
+static void testLoadAlternateHTML(LoadTrackingTest* test, gconstpointer)
+{
+ test->loadAlternateHTML("<html><body>Alternate page</body></html>", "http://error-page.foo/", 0);
+ test->waitUntilLoadFinished();
+ assertNormalLoadHappened(test->m_loadEvents);
+}
+
static void testLoadPlainText(LoadTrackingTest* test, gconstpointer)
{
test->loadPlainText("Hello WebKit-GTK+");
@@ -262,6 +269,7 @@
LoadTrackingTest::add("WebKitWebView", "loading-status", testLoadingStatus);
LoadTrackingTest::add("WebKitWebView", "loading-error", testLoadingError);
LoadTrackingTest::add("WebKitWebView", "load-html", testLoadHtml);
+ LoadTrackingTest::add("WebKitWebView", "load-alternate-html", testLoadAlternateHTML);
LoadTrackingTest::add("WebKitWebView", "load-plain-text", testLoadPlainText);
LoadTrackingTest::add("WebKitWebView", "load-request", testLoadRequest);
LoadStopTrackingTest::add("WebKitWebView", "stop-loading", testLoadCancelled);
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp (126029 => 126030)
--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp 2012-08-20 15:09:22 UTC (rev 126029)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp 2012-08-20 15:10:55 UTC (rev 126030)
@@ -505,32 +505,6 @@
test->checkResourceData(WEBKIT_WEB_RESOURCE(item->data));
}
-static void replacedContentResourceLoadStartedCallback()
-{
- g_assert_not_reached();
-}
-
-static void testWebViewResourcesReplacedContent(ResourcesTest* test, gconstpointer)
-{
- test->loadURI(kServer->getURIForPath("/").data());
- // FIXME: this should be 4 instead of 3, but we don't get the css image resource
- // due to bug https://bugs.webkit.org/show_bug.cgi?id=78510.
- test->waitUntilResourcesLoaded(3);
-
- static const char* replacedHtml =
- "<html><head>"
- " <title>Content Replaced</title>"
- " <link rel='stylesheet' href='' type='text/css'>"
- " <script language='_javascript_' src=''></script>"
- "</head><body _onload_='document.title=\"Loaded\"'>WebKitGTK+ resources on replaced content test</body></html>";
- g_signal_connect(test->m_webView, "resource-load-started", G_CALLBACK(replacedContentResourceLoadStartedCallback), test);
- test->replaceContent(replacedHtml, "http://error-page.foo", 0);
- test->waitUntilTitleChangedTo("Loaded");
-
- g_assert(!webkit_web_view_get_main_resource(test->m_webView));
- g_assert(!webkit_web_view_get_subresources(test->m_webView));
-}
-
static void testWebViewResourcesHistoryCache(SingleResourceLoadTest* test, gconstpointer)
{
test->loadURI(kServer->getURIForPath("/").data());
@@ -635,7 +609,6 @@
SingleResourceLoadTest::add("WebKitWebResource", "suggested-filename", testWebResourceSuggestedFilename);
ResourceURITrackingTest::add("WebKitWebResource", "active-uri", testWebResourceActiveURI);
ResourcesTest::add("WebKitWebResource", "get-data", testWebResourceGetData);
- ResourcesTest::add("WebKitWebView", "replaced-content", testWebViewResourcesReplacedContent);
SingleResourceLoadTest::add("WebKitWebView", "history-cache", testWebViewResourcesHistoryCache);
}
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp (126029 => 126030)
--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp 2012-08-20 15:09:22 UTC (rev 126029)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp 2012-08-20 15:10:55 UTC (rev 126030)
@@ -74,24 +74,6 @@
g_assert(webkit_settings_get_enable_javascript(settings));
}
-static void replaceContentLoadCallback(WebKitWebView* webView, WebKitLoadEvent loadEvent, WebViewTest* test)
-{
- // There might be an event from a previous load,
- // but never a WEBKIT_LOAD_STARTED after webkit_web_view_replace_content().
- g_assert_cmpint(loadEvent, !=, WEBKIT_LOAD_STARTED);
-}
-
-static void testWebViewReplaceContent(WebViewTest* test, gconstpointer)
-{
- test->loadHtml("<html><head><title>Replace Content Test</title></head><body>Content to replace</body></html>", 0);
- test->waitUntilTitleChangedTo("Replace Content Test");
-
- g_signal_connect(test->m_webView, "load-changed", G_CALLBACK(replaceContentLoadCallback), test);
- test->replaceContent("<html><body _onload_='document.title=\"Content Replaced\"'>New Content</body></html>",
- "http://foo.com/bar", 0);
- test->waitUntilTitleChangedTo("Content Replaced");
-}
-
static const char* kAlertDialogMessage = "WebKitGTK+ alert dialog message";
static const char* kConfirmDialogMessage = "WebKitGTK+ confirm dialog message";
static const char* kPromptDialogMessage = "WebKitGTK+ prompt dialog message";
@@ -1048,7 +1030,6 @@
WebViewTest::add("WebKitWebView", "default-context", testWebViewDefaultContext);
WebViewTest::add("WebKitWebView", "custom-charset", testWebViewCustomCharset);
WebViewTest::add("WebKitWebView", "settings", testWebViewSettings);
- WebViewTest::add("WebKitWebView", "replace-content", testWebViewReplaceContent);
UIClientTest::add("WebKitWebView", "create-ready-close", testWebViewCreateReadyClose);
ModalDialogsTest::add("WebKitWebView", "allow-modal-dialogs", testWebViewAllowModalDialogs);
ModalDialogsTest::add("WebKitWebView", "disallow-modal-dialogs", testWebViewDisallowModalDialogs);
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp (126029 => 126030)
--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp 2012-08-20 15:09:22 UTC (rev 126029)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp 2012-08-20 15:10:55 UTC (rev 126030)
@@ -71,10 +71,10 @@
webkit_web_view_load_request(m_webView, request);
}
-void WebViewTest::replaceContent(const char* html, const char* contentURI, const char* baseURI)
+void WebViewTest::loadAlternateHTML(const char* html, const char* contentURI, const char* baseURI)
{
m_activeURI = contentURI;
- webkit_web_view_replace_content(m_webView, html, contentURI, baseURI);
+ webkit_web_view_load_alternate_html(m_webView, html, contentURI, baseURI);
}
void WebViewTest::goBack()
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h (126029 => 126030)
--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h 2012-08-20 15:09:22 UTC (rev 126029)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h 2012-08-20 15:10:55 UTC (rev 126030)
@@ -35,7 +35,7 @@
virtual void loadHtml(const char* html, const char* baseURI);
virtual void loadPlainText(const char* plainText);
virtual void loadRequest(WebKitURIRequest*);
- void replaceContent(const char* html, const char* contentURI, const char* baseURI);
+ void loadAlternateHTML(const char* html, const char* contentURI, const char* baseURI);
void goBack();
void goForward();
void goToBackForwardListItem(WebKitBackForwardListItem*);