Commit 7f264909 authored by carlosgc@webkit.org's avatar carlosgc@webkit.org

[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):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@96614 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 736fb651
2011-10-04 Carlos Garcia Campos <cgarcia@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 <jonlee@apple.com>
Extend DOM WheelEvent to differentiate between physical and logical scroll directions
......
......@@ -222,6 +222,39 @@ void webkit_web_view_load_uri(WebKitWebView* webView, const gchar* uri)
WKRelease(url);
}
/**
* 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
......
......@@ -66,33 +66,39 @@ struct _WebKitWebViewClass {
};
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
......
......@@ -223,6 +223,35 @@ static void testLoadingError(WebLoadingFixture *fixture, gconstpointer data)
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 @@ int main(int argc, char **argv)
webLoadingFixtureSetup,
testLoadingError,
webLoadingFixtureTeardown);
g_test_add("/webkit2/loading/alternate_content",
WebLoadingFixture, NULL,
webLoadingFixtureSetup,
testLoadAlternateContent,
webLoadingFixtureTeardown);
return g_test_run();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment