Title: [109120] trunk/Source/WebKit2
Revision
109120
Author
[email protected]
Date
2012-02-28 10:24:46 -0800 (Tue, 28 Feb 2012)

Log Message

[GTK] Inconsistent state of WebKitWebView when replacing content in WebKit2
https://bugs.webkit.org/show_bug.cgi?id=79775

Reviewed by Martin Robinson.

Use an enum instead of a boolean to track the status of a
replace_content() load operation. We need to know when the load of
the replace content actually starts to not ignore valid load
events of a previous ongoing load operation.

* UIProcess/API/gtk/WebKitWebView.cpp:
(webkitWebViewLoadChanged): Transit to new replace content state
when replacing content depending on the load event.
(webkitWebViewLoadFailed): Ignore load failed events when
replacing content.
(webkitWebViewSetEstimatedLoadProgress): Ignore load progress when
replacing content.
(webkit_web_view_replace_content): Set replace content status to
WillReplaceContent.
* UIProcess/API/gtk/tests/TestWebKitWebView.cpp:
(replaceContentLoadCallback):
(testWebViewReplaceContent):
* UIProcess/API/gtk/tests/WebViewTest.cpp:
(titleChanged):
(WebViewTest::waitUntilTitleChanged): Convenient method to wait
until title changes. Use with replaceConent() since load events
are not emitted when replacing content.
* UIProcess/API/gtk/tests/WebViewTest.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (109119 => 109120)


--- trunk/Source/WebKit2/ChangeLog	2012-02-28 18:22:13 UTC (rev 109119)
+++ trunk/Source/WebKit2/ChangeLog	2012-02-28 18:24:46 UTC (rev 109120)
@@ -1,3 +1,34 @@
+2012-02-28  Carlos Garcia Campos  <[email protected]>
+
+        [GTK] Inconsistent state of WebKitWebView when replacing content in WebKit2
+        https://bugs.webkit.org/show_bug.cgi?id=79775
+
+        Reviewed by Martin Robinson.
+
+        Use an enum instead of a boolean to track the status of a
+        replace_content() load operation. We need to know when the load of
+        the replace content actually starts to not ignore valid load
+        events of a previous ongoing load operation.
+
+        * UIProcess/API/gtk/WebKitWebView.cpp:
+        (webkitWebViewLoadChanged): Transit to new replace content state
+        when replacing content depending on the load event.
+        (webkitWebViewLoadFailed): Ignore load failed events when
+        replacing content.
+        (webkitWebViewSetEstimatedLoadProgress): Ignore load progress when
+        replacing content.
+        (webkit_web_view_replace_content): Set replace content status to
+        WillReplaceContent.
+        * UIProcess/API/gtk/tests/TestWebKitWebView.cpp:
+        (replaceContentLoadCallback):
+        (testWebViewReplaceContent):
+        * UIProcess/API/gtk/tests/WebViewTest.cpp:
+        (titleChanged):
+        (WebViewTest::waitUntilTitleChanged): Convenient method to wait
+        until title changes. Use with replaceConent() since load events
+        are not emitted when replacing content.
+        * UIProcess/API/gtk/tests/WebViewTest.h:
+
 2012-02-27  Anders Carlsson  <[email protected]>
 
         Add basic page overlay support to TiledCoreAnimationDrawingArea

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp (109119 => 109120)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp	2012-02-28 18:22:13 UTC (rev 109119)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp	2012-02-28 18:24:46 UTC (rev 109120)
@@ -78,13 +78,20 @@
     PROP_ZOOM_LEVEL
 };
 
+typedef enum {
+    NotReplacingContent,
+    WillReplaceContent,
+    ReplacingContent,
+    DidReplaceContent
+} ReplaceContentStatus;
+
 struct _WebKitWebViewPrivate {
     WebKitWebContext* context;
     CString title;
     CString customTextEncoding;
     double estimatedLoadProgress;
     CString activeURI;
-    bool replacingContent;
+    ReplaceContentStatus replaceContentStatus;
 
     GRefPtr<WebKitBackForwardList> backForwardList;
     GRefPtr<WebKitSettings> settings;
@@ -679,14 +686,30 @@
                      WEBKIT_TYPE_PRINT_OPERATION);
 }
 
-void webkitWebViewLoadChanged(WebKitWebView* webView, WebKitLoadEvent loadEvent)
+static bool updateReplaceContentStatus(WebKitWebView* webView, WebKitLoadEvent loadEvent)
 {
-    if (webView->priv->replacingContent) {
+    if (webView->priv->replaceContentStatus == ReplacingContent) {
         if (loadEvent == WEBKIT_LOAD_FINISHED)
-            webView->priv->replacingContent = false;
-        return;
+            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;
+}
+
+void webkitWebViewLoadChanged(WebKitWebView* webView, WebKitLoadEvent loadEvent)
+{
+    if (updateReplaceContentStatus(webView, loadEvent))
+        return;
+
     if (loadEvent != WEBKIT_LOAD_FINISHED)
         webkitWebViewUpdateURI(webView);
     g_signal_emit(webView, signals[LOAD_CHANGED], 0, loadEvent);
@@ -694,7 +717,7 @@
 
 void webkitWebViewLoadFailed(WebKitWebView* webView, WebKitLoadEvent loadEvent, const char* failingURI, GError *error)
 {
-    if (webView->priv->replacingContent)
+    if (webView->priv->replaceContentStatus == ReplacingContent)
         return;
 
     gboolean returnValue;
@@ -714,7 +737,7 @@
 
 void webkitWebViewSetEstimatedLoadProgress(WebKitWebView* webView, double estimatedLoadProgress)
 {
-    if (webView->priv->replacingContent)
+    if (webView->priv->replaceContentStatus != NotReplacingContent)
         return;
 
     if (webView->priv->estimatedLoadProgress == estimatedLoadProgress)
@@ -965,7 +988,7 @@
     g_return_if_fail(content);
     g_return_if_fail(contentURI);
 
-    webView->priv->replacingContent = true;
+    webView->priv->replaceContentStatus = WillReplaceContent;
 
     WKRetainPtr<WKStringRef> htmlString(AdoptWK, WKStringCreateWithUTF8CString(content));
     WKRetainPtr<WKURLRef> contentURL(AdoptWK, WKURLCreateWithUTF8CString(contentURI));

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp (109119 => 109120)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp	2012-02-28 18:22:13 UTC (rev 109119)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp	2012-02-28 18:24:46 UTC (rev 109120)
@@ -71,24 +71,22 @@
     g_assert(webkit_settings_get_enable_javascript(settings));
 }
 
-static void replaceContentTitleChangedCallback(WebViewTest* test)
+static void replaceContentLoadCallback(WebKitWebView* webView, WebKitLoadEvent loadEvent, WebViewTest* test)
 {
-    g_main_loop_quit(test->m_mainLoop);
+    // 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 replaceContentLoadCallback()
-{
-    g_assert_not_reached();
-}
-
 static void testWebViewReplaceContent(WebViewTest* test, gconstpointer)
 {
-    g_signal_connect_swapped(test->m_webView, "notify::title", G_CALLBACK(replaceContentTitleChangedCallback), test);
+    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);
-    g_signal_connect(test->m_webView, "load-failed", G_CALLBACK(replaceContentLoadCallback), test);
-    test->replaceContent("<html><head><title>Content Replaced</title></head><body>New Content</body></html>",
+    test->replaceContent("<html><body _onload_='document.title=\"Content Replaced\"'>New Content</body></html>",
                          "http://foo.com/bar", 0);
-    g_main_loop_run(test->m_mainLoop);
+    test->waitUntilTitleChangedTo("Content Replaced");
 }
 
 static const char* kAlertDialogMessage = "WebKitGTK+ alert dialog message";

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp (109119 => 109120)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp	2012-02-28 18:22:13 UTC (rev 109119)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp	2012-02-28 18:24:46 UTC (rev 109120)
@@ -136,6 +136,28 @@
     g_main_loop_run(m_mainLoop);
 }
 
+static void titleChanged(WebKitWebView* webView, GParamSpec*, WebViewTest* test)
+{
+    if (!test->m_expectedTitle.isNull() && test->m_expectedTitle != webkit_web_view_get_title(webView))
+        return;
+
+    g_signal_handlers_disconnect_by_func(webView, reinterpret_cast<void*>(titleChanged), test);
+    g_main_loop_quit(test->m_mainLoop);
+}
+
+void WebViewTest::waitUntilTitleChangedTo(const char* expectedTitle)
+{
+    m_expectedTitle = expectedTitle;
+    g_signal_connect(m_webView, "notify::title", G_CALLBACK(titleChanged), this);
+    g_main_loop_run(m_mainLoop);
+    m_expectedTitle = CString();
+}
+
+void WebViewTest::waitUntilTitleChanged()
+{
+    waitUntilTitleChangedTo(0);
+}
+
 static gboolean parentWindowMapped(GtkWidget* widget, GdkEvent*, WebViewTest* test)
 {
     g_signal_handlers_disconnect_by_func(widget, reinterpret_cast<void*>(parentWindowMapped), test);

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h (109119 => 109120)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h	2012-02-28 18:22:13 UTC (rev 109119)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h	2012-02-28 18:24:46 UTC (rev 109120)
@@ -42,6 +42,8 @@
 
     void wait(double seconds);
     void waitUntilLoadFinished();
+    void waitUntilTitleChangedTo(const char* expectedTitle);
+    void waitUntilTitleChanged();
     void showInWindowAndWaitUntilMapped();
 
     void mouseMoveTo(int x, int y, unsigned int mouseModifiers = 0);
@@ -50,6 +52,7 @@
     GMainLoop* m_mainLoop;
     CString m_activeURI;
     GtkWidget* m_parentWindow;
+    CString m_expectedTitle;
 };
 
 #endif // WebViewTest_h
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to