Modified: trunk/Tools/ChangeLog (147623 => 147624)
--- trunk/Tools/ChangeLog 2013-04-04 13:20:17 UTC (rev 147623)
+++ trunk/Tools/ChangeLog 2013-04-04 13:26:22 UTC (rev 147624)
@@ -1,3 +1,28 @@
+2013-04-04 Manuel Rego Casasnovas <[email protected]>
+
+ [GTK][WK2] MiniBrowser custom URI scheme support
+ https://bugs.webkit.org/show_bug.cgi?id=112419
+
+ Reviewed by Carlos Garcia Campos.
+
+ Add support for about URIs in MiniBrowser. An example about page is show
+ with URI "about:minibrowser", the rest of the cases it will show a
+ proper message explaining that the about page didn't exist.
+
+ Internally it uses "minibrowser-about" prefix instead of "about", but
+ from the user point of view it works with "about" prefix.
+
+ * MiniBrowser/gtk/BrowserWindow.c: Add miniBrowserAboutScheme constant.
+ (getInternalURI): Method to convert URIs from "about" prefix to
+ "minibrowser-about".
+ (getExternalURI): Opposite method.
+ (webViewURIChanged): Use "about" prefix to show the URI to users.
+ (webViewEnterFullScreen): Ditto.
+ (browser_window_load_uri): Use "minibrowser-about" prefix internally.
+ * MiniBrowser/gtk/main.c: Add miniBrowserAboutScheme constant.
+ (aboutURISchemeRequestCallback): Callback to manage about calls.
+ (main): Register the URI scheme to manage about URIs.
+
2013-04-03 Roger Fong <[email protected]>
Re-enable WinEWS tests.
Modified: trunk/Tools/MiniBrowser/gtk/BrowserWindow.c (147623 => 147624)
--- trunk/Tools/MiniBrowser/gtk/BrowserWindow.c 2013-04-04 13:20:17 UTC (rev 147623)
+++ trunk/Tools/MiniBrowser/gtk/BrowserWindow.c 2013-04-04 13:26:22 UTC (rev 147624)
@@ -63,6 +63,7 @@
};
static const char *defaultWindowTitle = "WebKitGTK+ MiniBrowser";
+static const char *miniBrowserAboutScheme = "minibrowser-about";
static const gdouble minimumZoomLevel = 0.5;
static const gdouble maximumZoomLevel = 3;
static const gdouble zoomStep = 1.2;
@@ -70,6 +71,24 @@
G_DEFINE_TYPE(BrowserWindow, browser_window, GTK_TYPE_WINDOW)
+static char *getInternalURI(const char *uri)
+{
+ // Internally we use minibrowser-about: as about: prefix is ignored by WebKit.
+ if (g_str_has_prefix(uri, "about:") && !g_str_equal(uri, "about:blank"))
+ return g_strconcat(miniBrowserAboutScheme, uri + strlen ("about"), NULL);
+
+ return g_strdup(uri);
+}
+
+static char *getExternalURI(const char *uri)
+{
+ // From the user point of view we support about: prefix.
+ if (g_str_has_prefix(uri, miniBrowserAboutScheme))
+ return g_strconcat("about", uri + strlen(miniBrowserAboutScheme), NULL);
+
+ return g_strdup(uri);
+}
+
static void browserWindowSetStatusText(BrowserWindow *window, const char *text)
{
#if GTK_CHECK_VERSION(3, 2, 0)
@@ -118,7 +137,9 @@
static void webViewURIChanged(WebKitWebView *webView, GParamSpec *pspec, BrowserWindow *window)
{
- gtk_entry_set_text(GTK_ENTRY(window->uriEntry), webkit_web_view_get_uri(webView));
+ char *externalURI = getExternalURI(webkit_web_view_get_uri(webView));
+ gtk_entry_set_text(GTK_ENTRY(window->uriEntry), externalURI);
+ g_free(externalURI);
}
static void webViewTitleChanged(WebKitWebView *webView, GParamSpec *pspec, BrowserWindow *window)
@@ -277,11 +298,12 @@
static gboolean webViewEnterFullScreen(WebKitWebView *webView, BrowserWindow *window)
{
#if GTK_CHECK_VERSION(3, 2, 0)
- const gchar *titleOrURI = webkit_web_view_get_title(window->webView);
+ gchar *titleOrURI = g_strdup(webkit_web_view_get_title(window->webView));
if (!titleOrURI)
- titleOrURI = webkit_web_view_get_uri(window->webView);
+ titleOrURI = getExternalURI(webkit_web_view_get_uri(window->webView));
gchar *message = g_strdup_printf("%s is now full screen. Press ESC or f to exit.", titleOrURI);
gtk_label_set_text(GTK_LABEL(window->fullScreenMessageLabel), message);
+ g_free(titleOrURI);
g_free(message);
gtk_widget_show(window->fullScreenMessageLabel);
@@ -643,7 +665,9 @@
g_return_if_fail(uri);
if (!g_str_has_prefix(uri, "_javascript_:")) {
- webkit_web_view_load_uri(window->webView, uri);
+ char *internalURI = getInternalURI(uri);
+ webkit_web_view_load_uri(window->webView, internalURI);
+ g_free(internalURI);
return;
}
Modified: trunk/Tools/MiniBrowser/gtk/main.c (147623 => 147624)
--- trunk/Tools/MiniBrowser/gtk/main.c 2013-04-04 13:20:17 UTC (rev 147623)
+++ trunk/Tools/MiniBrowser/gtk/main.c 2013-04-04 13:26:22 UTC (rev 147624)
@@ -32,6 +32,7 @@
#include <webkit2/webkit2.h>
static const gchar **uriArguments = NULL;
+static const char *miniBrowserAboutScheme = "minibrowser-about";
static gchar *argumentToURL(const char *filename)
{
@@ -198,6 +199,30 @@
return TRUE;
}
+static void
+aboutURISchemeRequestCallback(WebKitURISchemeRequest *request, gpointer userData)
+{
+ GInputStream *stream;
+ gsize streamLength;
+ const gchar *path;
+ gchar *contents;
+
+ path = webkit_uri_scheme_request_get_path(request);
+ if (!g_strcmp0(path, "minibrowser"))
+ contents = g_strdup_printf("<html><body><h1>WebKitGTK+ MiniBrowser</h1><p>The WebKit2 test browser of the GTK+ port.</p><p>WebKit version: %d.%d.%d</p></body></html>",
+ webkit_get_major_version(),
+ webkit_get_minor_version(),
+ webkit_get_micro_version());
+ else
+ contents = g_strdup_printf("<html><body><p>Invalid about:%s page.</p></body></html>", path);
+
+ streamLength = strlen(contents);
+ stream = g_memory_input_stream_new_from_data(contents, streamLength, g_free);
+
+ webkit_uri_scheme_request_finish(request, stream, streamLength, "text/html");
+ g_object_unref(stream);
+}
+
int main(int argc, char *argv[])
{
gtk_init(&argc, &argv);
@@ -231,6 +256,8 @@
// Enable the favicon database, by specifying the default directory.
webkit_web_context_set_favicon_database_directory(webkit_web_context_get_default(), NULL);
+ webkit_web_context_register_uri_scheme(webkit_web_context_get_default(), miniBrowserAboutScheme, aboutURISchemeRequestCallback, NULL, NULL);
+
if (uriArguments) {
int i;