Changeset 109120 in webkit


Ignore:
Timestamp:
Feb 28, 2012 10:24:46 AM (12 years ago)
Author:
Carlos Garcia Campos
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:
Location:
trunk/Source/WebKit2
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r109118 r109120  
     12012-02-28  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Inconsistent state of WebKitWebView when replacing content in WebKit2
     4        https://bugs.webkit.org/show_bug.cgi?id=79775
     5
     6        Reviewed by Martin Robinson.
     7
     8        Use an enum instead of a boolean to track the status of a
     9        replace_content() load operation. We need to know when the load of
     10        the replace content actually starts to not ignore valid load
     11        events of a previous ongoing load operation.
     12
     13        * UIProcess/API/gtk/WebKitWebView.cpp:
     14        (webkitWebViewLoadChanged): Transit to new replace content state
     15        when replacing content depending on the load event.
     16        (webkitWebViewLoadFailed): Ignore load failed events when
     17        replacing content.
     18        (webkitWebViewSetEstimatedLoadProgress): Ignore load progress when
     19        replacing content.
     20        (webkit_web_view_replace_content): Set replace content status to
     21        WillReplaceContent.
     22        * UIProcess/API/gtk/tests/TestWebKitWebView.cpp:
     23        (replaceContentLoadCallback):
     24        (testWebViewReplaceContent):
     25        * UIProcess/API/gtk/tests/WebViewTest.cpp:
     26        (titleChanged):
     27        (WebViewTest::waitUntilTitleChanged): Convenient method to wait
     28        until title changes. Use with replaceConent() since load events
     29        are not emitted when replacing content.
     30        * UIProcess/API/gtk/tests/WebViewTest.h:
     31
    1322012-02-27  Anders Carlsson  <andersca@apple.com>
    233
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp

    r108069 r109120  
    7979};
    8080
     81typedef enum {
     82    NotReplacingContent,
     83    WillReplaceContent,
     84    ReplacingContent,
     85    DidReplaceContent
     86} ReplaceContentStatus;
     87
    8188struct _WebKitWebViewPrivate {
    8289    WebKitWebContext* context;
     
    8592    double estimatedLoadProgress;
    8693    CString activeURI;
    87     bool replacingContent;
     94    ReplaceContentStatus replaceContentStatus;
    8895
    8996    GRefPtr<WebKitBackForwardList> backForwardList;
     
    680687}
    681688
     689static bool updateReplaceContentStatus(WebKitWebView* webView, WebKitLoadEvent loadEvent)
     690{
     691    if (webView->priv->replaceContentStatus == ReplacingContent) {
     692        if (loadEvent == WEBKIT_LOAD_FINISHED)
     693            webView->priv->replaceContentStatus = DidReplaceContent;
     694        return true;
     695    }
     696
     697    if (loadEvent == WEBKIT_LOAD_STARTED) {
     698        if (webView->priv->replaceContentStatus == WillReplaceContent) {
     699            webView->priv->replaceContentStatus = ReplacingContent;
     700            return true;
     701        }
     702        webView->priv->replaceContentStatus = NotReplacingContent;
     703    }
     704
     705    return false;
     706}
     707
    682708void webkitWebViewLoadChanged(WebKitWebView* webView, WebKitLoadEvent loadEvent)
    683709{
    684     if (webView->priv->replacingContent) {
    685         if (loadEvent == WEBKIT_LOAD_FINISHED)
    686             webView->priv->replacingContent = false;
     710    if (updateReplaceContentStatus(webView, loadEvent))
    687711        return;
    688     }
    689712
    690713    if (loadEvent != WEBKIT_LOAD_FINISHED)
     
    695718void webkitWebViewLoadFailed(WebKitWebView* webView, WebKitLoadEvent loadEvent, const char* failingURI, GError *error)
    696719{
    697     if (webView->priv->replacingContent)
     720    if (webView->priv->replaceContentStatus == ReplacingContent)
    698721        return;
    699722
     
    715738void webkitWebViewSetEstimatedLoadProgress(WebKitWebView* webView, double estimatedLoadProgress)
    716739{
    717     if (webView->priv->replacingContent)
     740    if (webView->priv->replaceContentStatus != NotReplacingContent)
    718741        return;
    719742
     
    966989    g_return_if_fail(contentURI);
    967990
    968     webView->priv->replacingContent = true;
     991    webView->priv->replaceContentStatus = WillReplaceContent;
    969992
    970993    WKRetainPtr<WKStringRef> htmlString(AdoptWK, WKStringCreateWithUTF8CString(content));
  • trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp

    r107250 r109120  
    7272}
    7373
    74 static void replaceContentTitleChangedCallback(WebViewTest* test)
    75 {
    76     g_main_loop_quit(test->m_mainLoop);
    77 }
    78 
    79 static void replaceContentLoadCallback()
    80 {
    81     g_assert_not_reached();
     74static void replaceContentLoadCallback(WebKitWebView* webView, WebKitLoadEvent loadEvent, WebViewTest* test)
     75{
     76    // There might be an event from a previous load,
     77    // but never a WEBKIT_LOAD_STARTED after webkit_web_view_replace_content().
     78    g_assert_cmpint(loadEvent, !=, WEBKIT_LOAD_STARTED);
    8279}
    8380
    8481static void testWebViewReplaceContent(WebViewTest* test, gconstpointer)
    8582{
    86     g_signal_connect_swapped(test->m_webView, "notify::title", G_CALLBACK(replaceContentTitleChangedCallback), test);
     83    test->loadHtml("<html><head><title>Replace Content Test</title></head><body>Content to replace</body></html>", 0);
     84    test->waitUntilTitleChangedTo("Replace Content Test");
     85
    8786    g_signal_connect(test->m_webView, "load-changed", G_CALLBACK(replaceContentLoadCallback), test);
    88     g_signal_connect(test->m_webView, "load-failed", G_CALLBACK(replaceContentLoadCallback), test);
    89     test->replaceContent("<html><head><title>Content Replaced</title></head><body>New Content</body></html>",
     87    test->replaceContent("<html><body onload='document.title=\"Content Replaced\"'>New Content</body></html>",
    9088                         "http://foo.com/bar", 0);
    91     g_main_loop_run(test->m_mainLoop);
     89    test->waitUntilTitleChangedTo("Content Replaced");
    9290}
    9391
  • trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp

    r107250 r109120  
    137137}
    138138
     139static void titleChanged(WebKitWebView* webView, GParamSpec*, WebViewTest* test)
     140{
     141    if (!test->m_expectedTitle.isNull() && test->m_expectedTitle != webkit_web_view_get_title(webView))
     142        return;
     143
     144    g_signal_handlers_disconnect_by_func(webView, reinterpret_cast<void*>(titleChanged), test);
     145    g_main_loop_quit(test->m_mainLoop);
     146}
     147
     148void WebViewTest::waitUntilTitleChangedTo(const char* expectedTitle)
     149{
     150    m_expectedTitle = expectedTitle;
     151    g_signal_connect(m_webView, "notify::title", G_CALLBACK(titleChanged), this);
     152    g_main_loop_run(m_mainLoop);
     153    m_expectedTitle = CString();
     154}
     155
     156void WebViewTest::waitUntilTitleChanged()
     157{
     158    waitUntilTitleChangedTo(0);
     159}
     160
    139161static gboolean parentWindowMapped(GtkWidget* widget, GdkEvent*, WebViewTest* test)
    140162{
  • trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h

    r107250 r109120  
    4343    void wait(double seconds);
    4444    void waitUntilLoadFinished();
     45    void waitUntilTitleChangedTo(const char* expectedTitle);
     46    void waitUntilTitleChanged();
    4547    void showInWindowAndWaitUntilMapped();
    4648
     
    5153    CString m_activeURI;
    5254    GtkWidget* m_parentWindow;
     55    CString m_expectedTitle;
    5356};
    5457
Note: See TracChangeset for help on using the changeset viewer.