Title: [96614] trunk/Source/WebKit2
Revision
96614
Author
carlo...@webkit.org
Date
2011-10-04 11:11:55 -0700 (Tue, 04 Oct 2011)

Log Message

[GTK] Add webkit_web_view_load_alternate_html() to WebKit2 GTK+ API
https://bugs.webkit.org/show_bug.cgi?id=69254

Reviewed by Martin Robinson.

* UIProcess/API/gtk/WebKitWebView.cpp:
(webkit_web_view_load_alternate_html):
* UIProcess/API/gtk/WebKitWebView.h:
* UIProcess/API/gtk/tests/testloading.c:
(loadAlternateContentLoadFinished):
(loadAlternateContentLoadFailed):
(testLoadAlternateContent):
(main):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (96613 => 96614)


--- trunk/Source/WebKit2/ChangeLog	2011-10-04 18:06:44 UTC (rev 96613)
+++ trunk/Source/WebKit2/ChangeLog	2011-10-04 18:11:55 UTC (rev 96614)
@@ -1,3 +1,19 @@
+2011-10-04  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [GTK] Add webkit_web_view_load_alternate_html() to WebKit2 GTK+ API
+        https://bugs.webkit.org/show_bug.cgi?id=69254
+
+        Reviewed by Martin Robinson.
+
+        * UIProcess/API/gtk/WebKitWebView.cpp:
+        (webkit_web_view_load_alternate_html):
+        * UIProcess/API/gtk/WebKitWebView.h:
+        * UIProcess/API/gtk/tests/testloading.c:
+        (loadAlternateContentLoadFinished):
+        (loadAlternateContentLoadFailed):
+        (testLoadAlternateContent):
+        (main):
+
 2011-10-03  Jon Lee  <jon...@apple.com>
 
         Extend DOM WheelEvent to differentiate between physical and logical scroll directions

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


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp	2011-10-04 18:06:44 UTC (rev 96613)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp	2011-10-04 18:11:55 UTC (rev 96614)
@@ -223,6 +223,39 @@
 }
 
 /**
+ * webkit_web_view_load_alternate_html:
+ * @web_view: a #WebKitWebView
+ * @content: the alternate content to display as the main page of the @web_view
+ * @base_uri: the base URI for relative locations
+ * @unreachable_uri: the URI for the alternate page content
+ *
+ * Request loading of an alternate content for a URI that is unreachable. This allows clients
+ * to display page-loading errors in the #WebKitWebView itself. This is typically called from
+ * #WebKitWebLoaderClient::provisional-load-failed or #WebKitWebLoaderClient::load-failed
+ * signals.
+ * When called from those signals this method will preserve the back-forward list. The URI passed in
+ * @base_uri has to be an absolute URI.
+ * You can monitor the status of the load operation using the
+ * #WebKitWebLoaderClient of @web_view. See webkit_web_view_get_loader_client().
+ */
+void webkit_web_view_load_alternate_html(WebKitWebView* webView, const gchar* content, const gchar* baseURI, const gchar* unreachableURI)
+{
+    g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
+    g_return_if_fail(content);
+
+    WKStringRef htmlString = WKStringCreateWithUTF8CString(content);
+    WKURLRef baseURL = baseURI ? WKURLCreateWithUTF8CString(baseURI) : 0;
+    WKURLRef unreachableURL = unreachableURI ? WKURLCreateWithUTF8CString(unreachableURI) : 0;
+    WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView));
+    WKPageLoadAlternateHTMLString(toAPI(page), htmlString, baseURL, unreachableURL);
+    WKRelease(htmlString);
+    if (baseURL)
+        WKRelease(baseURL);
+    if (unreachableURL)
+        WKRelease(unreachableURL);
+}
+
+/**
  * webkit_web_view_go_back:
  * @web_view: a #WebKitWebView
  *

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h (96613 => 96614)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h	2011-10-04 18:06:44 UTC (rev 96613)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h	2011-10-04 18:11:55 UTC (rev 96614)
@@ -66,34 +66,40 @@
 };
 
 WK_EXPORT GType
-webkit_web_view_get_type          (void);
+webkit_web_view_get_type            (void);
 
 WK_EXPORT GtkWidget *
-webkit_web_view_new               (void);
+webkit_web_view_new                 (void);
 
 WK_EXPORT GtkWidget *
-webkit_web_view_new_with_context  (WebKitWebContext      *context);
+webkit_web_view_new_with_context    (WebKitWebContext      *context);
 
 WK_EXPORT WebKitWebContext *
-webkit_web_view_get_context       (WebKitWebView         *web_view);
+webkit_web_view_get_context         (WebKitWebView         *web_view);
 
 WK_EXPORT WebKitWebLoaderClient *
-webkit_web_view_get_loader_client (WebKitWebView         *web_view);
+webkit_web_view_get_loader_client   (WebKitWebView         *web_view);
 
 WK_EXPORT void
-webkit_web_view_set_loader_client (WebKitWebView         *web_view,
-                                   WebKitWebLoaderClient *loader_client);
+webkit_web_view_set_loader_client   (WebKitWebView         *web_view,
+                                     WebKitWebLoaderClient *loader_client);
 
 WK_EXPORT void
-webkit_web_view_load_uri          (WebKitWebView         *web_view,
-                                   const gchar           *uri);
+webkit_web_view_load_uri            (WebKitWebView         *web_view,
+                                     const gchar           *uri);
 
 WK_EXPORT void
-webkit_web_view_go_back           (WebKitWebView         *web_view);
+webkit_web_view_load_alternate_html (WebKitWebView         *web_view,
+                                     const gchar           *content,
+                                     const gchar           *base_uri,
+                                     const gchar           *unreachable_uri);
 
 WK_EXPORT void
-webkit_web_view_go_forward        (WebKitWebView         *web_view);
+webkit_web_view_go_back             (WebKitWebView         *web_view);
 
+WK_EXPORT void
+webkit_web_view_go_forward          (WebKitWebView         *web_view);
+
 G_END_DECLS
 
 #endif

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/testloading.c (96613 => 96614)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/testloading.c	2011-10-04 18:06:44 UTC (rev 96613)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/testloading.c	2011-10-04 18:11:55 UTC (rev 96614)
@@ -223,6 +223,35 @@
     g_assert(fixture->hasBeenFailed);
 }
 
+static gboolean loadAlternateContentLoadFinished(WebKitWebLoaderClient *client, WebLoadingFixture *fixture)
+{
+    g_main_loop_quit(fixture->loop);
+
+    return TRUE;
+}
+
+static gboolean loadAlternateContentLoadFailed(WebKitWebLoaderClient *client, const gchar *failingURI, GError *error, WebLoadingFixture *fixture)
+{
+    g_assert_not_reached();
+    return TRUE;
+}
+
+static void testLoadAlternateContent(WebLoadingFixture *fixture, gconstpointer data)
+{
+    char *uriString;
+    WebKitWebLoaderClient *client = webkit_web_view_get_loader_client(fixture->webView);
+
+    g_signal_connect(client, "load-finished", G_CALLBACK(loadAlternateContentLoadFinished), fixture);
+    g_signal_connect(client, "provisional-load-failed", G_CALLBACK(loadAlternateContentLoadFailed), fixture);
+    g_signal_connect(client, "load-failed", G_CALLBACK(loadAlternateContentLoadFailed), fixture);
+
+    uriString = getURIForPath("/alternate");
+    webkit_web_view_load_alternate_html(fixture->webView, "<html><body>Alternate Content</body></html>", NULL, uriString);
+    g_free(uriString);
+
+    g_main_loop_run(fixture->loop);
+}
+
 int main(int argc, char **argv)
 {
     SoupServer *server;
@@ -251,6 +280,11 @@
                webLoadingFixtureSetup,
                testLoadingError,
                webLoadingFixtureTeardown);
+    g_test_add("/webkit2/loading/alternate_content",
+               WebLoadingFixture, NULL,
+               webLoadingFixtureSetup,
+               testLoadAlternateContent,
+               webLoadingFixtureTeardown);
 
     return g_test_run();
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to