Changeset 104129 in webkit


Ignore:
Timestamp:
Jan 5, 2012 2:08:07 AM (12 years ago)
Author:
Carlos Garcia Campos
Message:

[GTK] Rename webkit_web_view_load_alternate_html as webkit_web_view_replace_content in WebKit2 GTK+
https://bugs.webkit.org/show_bug.cgi?id=75433

Reviewed by Martin Robinson.

Source/WebKit2:

  • UIProcess/API/gtk/WebKitWebView.cpp:

(webkitWebViewLoadFail): Use webkit_web_view_replace_content().
(webkitWebViewLoadChanged): Do not emit load-changed signal when
replacing content.
(webkitWebViewLoadFailed): Do not emit load-failed signal when
replacing content.
(webkitWebViewSetEstimatedLoadProgress): Do not emit
notify::estimated-load-progress signal when replacing content.
(webkit_web_view_replace_content):

  • UIProcess/API/gtk/WebKitWebView.h:
  • UIProcess/API/gtk/docs/webkit2gtk-sections.txt:
  • UIProcess/API/gtk/tests/TestWebKitWebLoaderClient.cpp:

(beforeAll):

  • UIProcess/API/gtk/tests/TestWebKitWebView.cpp:

(replaceContentTitleChangedCallback):
(replaceContentLoadCallback):
(testWebViewReplaceContent):
(beforeAll):

  • UIProcess/API/gtk/tests/WebViewTest.cpp:

(WebViewTest::replaceContent):

  • UIProcess/API/gtk/tests/WebViewTest.h:

Tools:

  • MiniBrowser/gtk/BrowserWindow.c:

(webViewLoadFailed): Reset the progress bar when load fails.
(browserWindowConstructed): Connect to load-failed signal.

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r104122 r104129  
     12012-01-05  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Rename webkit_web_view_load_alternate_html as webkit_web_view_replace_content in WebKit2 GTK+
     4        https://bugs.webkit.org/show_bug.cgi?id=75433
     5
     6        Reviewed by Martin Robinson.
     7
     8        * UIProcess/API/gtk/WebKitWebView.cpp:
     9        (webkitWebViewLoadFail): Use webkit_web_view_replace_content().
     10        (webkitWebViewLoadChanged): Do not emit load-changed signal when
     11        replacing content.
     12        (webkitWebViewLoadFailed): Do not emit load-failed signal when
     13        replacing content.
     14        (webkitWebViewSetEstimatedLoadProgress): Do not emit
     15        notify::estimated-load-progress signal when replacing content.
     16        (webkit_web_view_replace_content):
     17        * UIProcess/API/gtk/WebKitWebView.h:
     18        * UIProcess/API/gtk/docs/webkit2gtk-sections.txt:
     19        * UIProcess/API/gtk/tests/TestWebKitWebLoaderClient.cpp:
     20        (beforeAll):
     21        * UIProcess/API/gtk/tests/TestWebKitWebView.cpp:
     22        (replaceContentTitleChangedCallback):
     23        (replaceContentLoadCallback):
     24        (testWebViewReplaceContent):
     25        (beforeAll):
     26        * UIProcess/API/gtk/tests/WebViewTest.cpp:
     27        (WebViewTest::replaceContent):
     28        * UIProcess/API/gtk/tests/WebViewTest.h:
     29
    1302012-01-05  Keunsoon Lee  <keunsoon.lee@samsung.com>
    231
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp

    r103938 r104129  
    7777    double estimatedLoadProgress;
    7878    CString activeURI;
     79    bool replacingContent;
    7980
    8081    GRefPtr<WebKitWebLoaderClient> loaderClient;
     
    9798
    9899    GOwnPtr<char> htmlString(g_strdup_printf("<html><body>%s</body></html>", error->message));
    99     webkit_web_view_load_alternate_html(webView, htmlString.get(), 0, failingURI);
     100    webkit_web_view_replace_content(webView, htmlString.get(), failingURI, 0);
    100101
    101102    return TRUE;
     
    540541void webkitWebViewLoadChanged(WebKitWebView* webView, WebKitLoadEvent loadEvent)
    541542{
     543    if (webView->priv->replacingContent) {
     544        if (loadEvent == WEBKIT_LOAD_FINISHED)
     545            webView->priv->replacingContent = false;
     546        return;
     547    }
     548
    542549    if (loadEvent != WEBKIT_LOAD_FINISHED)
    543550        webkitWebViewUpdateURI(webView);
     
    547554void webkitWebViewLoadFailed(WebKitWebView* webView, WebKitLoadEvent loadEvent, const char* failingURI, GError *error)
    548555{
     556    if (webView->priv->replacingContent)
     557        return;
     558
    549559    gboolean returnValue;
    550560    g_signal_emit(webView, signals[LOAD_FAILED], 0, loadEvent, failingURI, error, &returnValue);
     
    564574void webkitWebViewSetEstimatedLoadProgress(WebKitWebView* webView, double estimatedLoadProgress)
    565575{
     576    if (webView->priv->replacingContent)
     577        return;
     578
    566579    if (webView->priv->estimatedLoadProgress == estimatedLoadProgress)
    567580        return;
     581
    568582    webView->priv->estimatedLoadProgress = estimatedLoadProgress;
    569583    g_object_notify(G_OBJECT(webView), "estimated-load-progress");
     
    734748
    735749/**
    736  * webkit_web_view_load_alternate_html:
    737  * @web_view: a #WebKitWebView
    738  * @content: the alternate content to display as the main page of the @web_view
    739  * @base_uri: the base URI for relative locations
    740  * @unreachable_uri: the URI for the alternate page content
    741  *
    742  * Request loading of an alternate content for a URI that is unreachable. This allows clients
    743  * to display page-loading errors in the #WebKitWebView itself. This is typically called from
    744  * #WebKitWebView::load-failed signal.
    745  * When called from that signal this method will preserve the back-forward list. The URI passed in
    746  * @base_uri has to be an absolute URI.
    747  * You can monitor the load operation by connecting to
    748  * #WebKitWebView::load-changed signal.
    749  */
    750 void webkit_web_view_load_alternate_html(WebKitWebView* webView, const gchar* content, const gchar* baseURI, const gchar* unreachableURI)
    751 {
    752     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
    753     g_return_if_fail(content);
    754 
    755     WKRetainPtr<WKStringRef> htmlString(AdoptWK, WKStringCreateWithUTF8CString(content));
    756     WKRetainPtr<WKURLRef> baseURL = baseURI ? adoptWK(WKURLCreateWithUTF8CString(baseURI)) : 0;
    757     WKRetainPtr<WKURLRef> unreachableURL = unreachableURI ? adoptWK(WKURLCreateWithUTF8CString(unreachableURI)) : 0;
    758     WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView));
    759     WKPageLoadAlternateHTMLString(toAPI(page), htmlString.get(), baseURL.get(), unreachableURL.get());
    760     webkitWebViewUpdateURI(webView);
    761 }
    762 
    763 /**
    764750 * webkit_web_view_load_request:
    765751 * @web_view: a #WebKitWebView
     
    779765    WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView));
    780766    WKPageLoadURLRequest(toAPI(page), wkRequest.get());
     767    webkitWebViewUpdateURI(webView);
     768}
     769
     770/**
     771 * webkit_web_view_replace_content:
     772 * @web_view: a #WebKitWebView
     773 * @content: the new content to display as the main page of the @web_view
     774 * @content_uri: the URI for the page content
     775 * @base_uri: (allow-none): the base URI for relative locations or %NULL
     776 *
     777 * Replace the content of @web_view with @content using @content_uri as page URI.
     778 * This allows clients to display page-loading errors in the #WebKitWebView itself.
     779 * This is typically called from #WebKitWebView::load-failed signal. The URI passed in
     780 * @base_uri has to be an absolute URI. The mime type of the document will be "text/html".
     781 * Signals #WebKitWebView::load-changed and #WebKitWebView::load-failed are not emitted
     782 * when replacing content of a #WebKitWebView using this method.
     783 */
     784void webkit_web_view_replace_content(WebKitWebView* webView, const gchar* content, const gchar* contentURI, const gchar* baseURI)
     785{
     786    g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
     787    g_return_if_fail(content);
     788    g_return_if_fail(contentURI);
     789
     790    webView->priv->replacingContent = true;
     791
     792    WKRetainPtr<WKStringRef> htmlString(AdoptWK, WKStringCreateWithUTF8CString(content));
     793    WKRetainPtr<WKURLRef> contentURL(AdoptWK, WKURLCreateWithUTF8CString(contentURI));
     794    WKRetainPtr<WKURLRef> baseURL = baseURI ? adoptWK(WKURLCreateWithUTF8CString(baseURI)) : 0;
     795    WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView));
     796    WKPageLoadAlternateHTMLString(toAPI(page), htmlString.get(), baseURL.get(), contentURL.get());
    781797    webkitWebViewUpdateURI(webView);
    782798}
     
    927943 *   </para></listitem>
    928944 *   <listitem><para>
    929  *     If the load operation was started by webkit_web_view_load_alternate_html(),
     945 *     If the load operation was started by webkit_web_view_load_html(),
    930946 *     the requested URI is "about:blank".
    931947 *   </para></listitem>
     
    954970 *   or a navigation action within the same page is performed.
    955971 * </para></listitem>
     972 * <listitem><para>
     973 *   When the page content is replaced using webkit_web_view_replace_content(),
     974 *   the active URI is the content_uri provided.
     975 * </para></listitem>
    956976 * </orderedlist>
    957977 *
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h

    r103938 r104129  
    140140
    141141WEBKIT_API void
    142 webkit_web_view_load_alternate_html          (WebKitWebView             *web_view,
    143                                               const gchar               *content,
    144                                               const gchar               *base_uri,
    145                                               const gchar               *unreachable_uri);
    146 WEBKIT_API void
    147142webkit_web_view_load_request                 (WebKitWebView             *web_view,
    148143                                              WebKitURIRequest          *request);
     
    150145WEBKIT_API void
    151146webkit_web_view_stop_loading                 (WebKitWebView             *web_view);
     147
     148WEBKIT_API void
     149webkit_web_view_replace_content              (WebKitWebView             *web_view,
     150                                              const gchar               *content,
     151                                              const gchar               *content_uri,
     152                                              const gchar               *base_uri);
    152153
    153154WEBKIT_API const gchar *
  • trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt

    r103938 r104129  
    5454webkit_web_view_load_html
    5555webkit_web_view_load_plain_text
    56 webkit_web_view_load_alternate_html
    5756webkit_web_view_load_request
     57webkit_web_view_replace_content
    5858webkit_web_view_can_go_back
    5959webkit_web_view_go_back
  • trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebLoaderClient.cpp

    r103938 r104129  
    7979}
    8080
    81 static void testLoadAlternateContent(LoadTrackingTest* test, gconstpointer)
    82 {
    83     test->loadAlternateHTML("<html><body>Alternate Content</body></html>", 0, kServer->getURIForPath("/alternate").data());
    84     test->waitUntilLoadFinished();
    85     assertNormalLoadHappenedAndClearEvents(test->m_loadEvents);
    86 }
    87 
    8881static void testLoadRequest(LoadTrackingTest* test, gconstpointer)
    8982{
     
    252245    LoadTrackingTest::add("WebKitWebView", "load-html", testLoadHtml);
    253246    LoadTrackingTest::add("WebKitWebView", "load-plain-text", testLoadPlainText);
    254     LoadTrackingTest::add("WebKitWebView", "load-alternate-content", testLoadAlternateContent);
    255247    LoadTrackingTest::add("WebKitWebView", "load-request", testLoadRequest);
    256248    LoadStopTrackingTest::add("WebKitWebView", "stop-loading", testLoadCancelled);
  • trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp

    r103938 r104129  
    6868}
    6969
     70static void replaceContentTitleChangedCallback(WebViewTest* test)
     71{
     72    g_main_loop_quit(test->m_mainLoop);
     73}
     74
     75static void replaceContentLoadCallback()
     76{
     77    g_assert_not_reached();
     78}
     79
     80static void testWebViewReplaceContent(WebViewTest* test, gconstpointer)
     81{
     82    g_signal_connect_swapped(test->m_webView, "notify::title", G_CALLBACK(replaceContentTitleChangedCallback), test);
     83    g_signal_connect(test->m_webView, "load-changed", G_CALLBACK(replaceContentLoadCallback), test);
     84    g_signal_connect(test->m_webView, "load-failed", G_CALLBACK(replaceContentLoadCallback), test);
     85    test->replaceContent("<html><head><title>Content Replaced</title></head><body>New Content</body></html>",
     86                         "http://foo.com/bar", 0);
     87    g_main_loop_run(test->m_mainLoop);
     88}
     89
    7090static const char* kAlertDialogMessage = "WebKitGTK+ alert dialog message";
    7191static const char* kConfirmDialogMessage = "WebKitGTK+ confirm dialog message";
     
    343363    WebViewTest::add("WebKitWebView", "custom-charset", testWebViewCustomCharset);
    344364    WebViewTest::add("WebKitWebView", "settings", testWebViewSettings);
     365    WebViewTest::add("WebKitWebView", "replace-content", testWebViewReplaceContent);
    345366    UIClientTest::add("WebKitWebView", "create-ready-close", testWebViewCreateReadyClose);
    346367    UIClientTest::add("WebKitWebView", "javascript-dialogs", testWebViewJavaScriptDialogs);
  • trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp

    r101248 r104129  
    5959}
    6060
    61 void WebViewTest::loadAlternateHTML(const char* html, const char* baseURI, const char* unreachableURI)
    62 {
    63     m_activeURI = "about:blank";
    64     webkit_web_view_load_alternate_html(m_webView, html, baseURI, unreachableURI);
    65 }
    66 
    6761void WebViewTest::loadRequest(WebKitURIRequest* request)
    6862{
    6963    m_activeURI = webkit_uri_request_get_uri(request);
    7064    webkit_web_view_load_request(m_webView, request);
     65}
     66
     67void WebViewTest::replaceContent(const char* html, const char* contentURI, const char* baseURI)
     68{
     69    // FIXME: The active uri should be the contentURI,
     70    // but WebPageProxy doesn't return the unreachableURL
     71    // when the page has been loaded with AlternateHTML()
     72    // See https://bugs.webkit.org/show_bug.cgi?id=75465.
     73#if 0
     74    m_activeURI = contentURI;
     75#else
     76    m_activeURI = "about:blank";
     77#endif
     78    webkit_web_view_replace_content(m_webView, html, contentURI, baseURI);
    7179}
    7280
  • trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h

    r101248 r104129  
    3535    void loadHtml(const char* html, const char* baseURI);
    3636    void loadPlainText(const char* plainText);
    37     void loadAlternateHTML(const char* html, const char* baseURI, const char* unreachableURI);
    3837    void loadRequest(WebKitURIRequest*);
     38    void replaceContent(const char* html, const char* contentURI, const char* baseURI);
    3939    void goBack();
    4040    void goForward();
  • trunk/Tools/ChangeLog

    r104115 r104129  
     12012-01-05  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Rename webkit_web_view_load_alternate_html as webkit_web_view_replace_content in WebKit2 GTK+
     4        https://bugs.webkit.org/show_bug.cgi?id=75433
     5
     6        Reviewed by Martin Robinson.
     7
     8        * MiniBrowser/gtk/BrowserWindow.c:
     9        (webViewLoadFailed): Reset the progress bar when load fails.
     10        (browserWindowConstructed): Connect to load-failed signal.
     11
    1122012-01-04  Dan Bernstein  <mitz@apple.com>
    213
  • trunk/Tools/MiniBrowser/gtk/BrowserWindow.c

    r103906 r104129  
    230230}
    231231
     232static gboolean webViewLoadFailed(WebKitWebView *webView, WebKitLoadEvent loadEvent, const char *failingURI, GError *error, BrowserWindow *window)
     233{
     234    gtk_entry_set_progress_fraction(GTK_ENTRY(window->uriEntry), 0.);
     235    return FALSE;
     236}
     237
    232238static void browserWindowFinalize(GObject *gObject)
    233239{
     
    327333    g_signal_connect(window->webView, "notify::title", G_CALLBACK(webViewTitleChanged), window);
    328334    g_signal_connect(window->webView, "create", G_CALLBACK(webViewCreate), window);
     335    g_signal_connect(window->webView, "load-failed", G_CALLBACK(webViewLoadFailed), window);
    329336
    330337    WebKitBackForwardList *backForwadlist = webkit_web_view_get_back_forward_list(window->webView);
Note: See TracChangeset for help on using the changeset viewer.