Changeset 147624 in webkit


Ignore:
Timestamp:
Apr 4, 2013 6:26:22 AM (11 years ago)
Author:
commit-queue@webkit.org
Message:

[GTK][WK2] MiniBrowser custom URI scheme support
https://bugs.webkit.org/show_bug.cgi?id=112419

Patch by Manuel Rego Casasnovas <Manuel Rego Casasnovas> on 2013-04-04
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.

Location:
trunk/Tools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r147603 r147624  
     12013-04-04  Manuel Rego Casasnovas  <rego@igalia.com>
     2
     3        [GTK][WK2] MiniBrowser custom URI scheme support
     4        https://bugs.webkit.org/show_bug.cgi?id=112419
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        Add support for about URIs in MiniBrowser. An example about page is show
     9        with URI "about:minibrowser", the rest of the cases it will show a
     10        proper message explaining that the about page didn't exist.
     11
     12        Internally it uses "minibrowser-about" prefix instead of "about", but
     13        from the user point of view it works with "about" prefix.
     14
     15        * MiniBrowser/gtk/BrowserWindow.c: Add miniBrowserAboutScheme constant.
     16        (getInternalURI): Method to convert URIs from "about" prefix to
     17        "minibrowser-about".
     18        (getExternalURI): Opposite method.
     19        (webViewURIChanged): Use "about" prefix to show the URI to users.
     20        (webViewEnterFullScreen): Ditto.
     21        (browser_window_load_uri): Use "minibrowser-about" prefix internally.
     22        * MiniBrowser/gtk/main.c: Add miniBrowserAboutScheme constant.
     23        (aboutURISchemeRequestCallback): Callback to manage about calls.
     24        (main): Register the URI scheme to manage about URIs.
     25
    1262013-04-03  Roger Fong  <roger_fong@apple.com>
    227
  • trunk/Tools/MiniBrowser/gtk/BrowserWindow.c

    r141585 r147624  
    6464
    6565static const char *defaultWindowTitle = "WebKitGTK+ MiniBrowser";
     66static const char *miniBrowserAboutScheme = "minibrowser-about";
    6667static const gdouble minimumZoomLevel = 0.5;
    6768static const gdouble maximumZoomLevel = 3;
     
    7172G_DEFINE_TYPE(BrowserWindow, browser_window, GTK_TYPE_WINDOW)
    7273
     74static char *getInternalURI(const char *uri)
     75{
     76    // Internally we use minibrowser-about: as about: prefix is ignored by WebKit.
     77    if (g_str_has_prefix(uri, "about:") && !g_str_equal(uri, "about:blank"))
     78        return g_strconcat(miniBrowserAboutScheme, uri + strlen ("about"), NULL);
     79
     80    return g_strdup(uri);
     81}
     82
     83static char *getExternalURI(const char *uri)
     84{
     85    // From the user point of view we support about: prefix.
     86    if (g_str_has_prefix(uri, miniBrowserAboutScheme))
     87        return g_strconcat("about", uri + strlen(miniBrowserAboutScheme), NULL);
     88
     89    return g_strdup(uri);
     90}
     91
    7392static void browserWindowSetStatusText(BrowserWindow *window, const char *text)
    7493{
     
    119138static void webViewURIChanged(WebKitWebView *webView, GParamSpec *pspec, BrowserWindow *window)
    120139{
    121     gtk_entry_set_text(GTK_ENTRY(window->uriEntry), webkit_web_view_get_uri(webView));
     140    char *externalURI = getExternalURI(webkit_web_view_get_uri(webView));
     141    gtk_entry_set_text(GTK_ENTRY(window->uriEntry), externalURI);
     142    g_free(externalURI);
    122143}
    123144
     
    278299{
    279300#if GTK_CHECK_VERSION(3, 2, 0)
    280     const gchar *titleOrURI = webkit_web_view_get_title(window->webView);
     301    gchar *titleOrURI = g_strdup(webkit_web_view_get_title(window->webView));
    281302    if (!titleOrURI)
    282         titleOrURI = webkit_web_view_get_uri(window->webView);
     303        titleOrURI = getExternalURI(webkit_web_view_get_uri(window->webView));
    283304    gchar *message = g_strdup_printf("%s is now full screen. Press ESC or f to exit.", titleOrURI);
    284305    gtk_label_set_text(GTK_LABEL(window->fullScreenMessageLabel), message);
     306    g_free(titleOrURI);
    285307    g_free(message);
    286308
     
    644666
    645667    if (!g_str_has_prefix(uri, "javascript:")) {
    646         webkit_web_view_load_uri(window->webView, uri);
     668        char *internalURI = getInternalURI(uri);
     669        webkit_web_view_load_uri(window->webView, internalURI);
     670        g_free(internalURI);
    647671        return;
    648672    }
  • trunk/Tools/MiniBrowser/gtk/main.c

    r139305 r147624  
    3333
    3434static const gchar **uriArguments = NULL;
     35static const char *miniBrowserAboutScheme = "minibrowser-about";
    3536
    3637static gchar *argumentToURL(const char *filename)
     
    199200}
    200201
     202static void
     203aboutURISchemeRequestCallback(WebKitURISchemeRequest *request, gpointer userData)
     204{
     205    GInputStream *stream;
     206    gsize streamLength;
     207    const gchar *path;
     208    gchar *contents;
     209
     210    path = webkit_uri_scheme_request_get_path(request);
     211    if (!g_strcmp0(path, "minibrowser"))
     212        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>",
     213            webkit_get_major_version(),
     214            webkit_get_minor_version(),
     215            webkit_get_micro_version());
     216    else
     217        contents = g_strdup_printf("<html><body><p>Invalid about:%s page.</p></body></html>", path);
     218
     219    streamLength = strlen(contents);
     220    stream = g_memory_input_stream_new_from_data(contents, streamLength, g_free);
     221
     222    webkit_uri_scheme_request_finish(request, stream, streamLength, "text/html");
     223    g_object_unref(stream);
     224}
     225
    201226int main(int argc, char *argv[])
    202227{
     
    232257    webkit_web_context_set_favicon_database_directory(webkit_web_context_get_default(), NULL);
    233258
     259    webkit_web_context_register_uri_scheme(webkit_web_context_get_default(), miniBrowserAboutScheme, aboutURISchemeRequestCallback, NULL, NULL);
     260
    234261    if (uriArguments) {
    235262        int i;
Note: See TracChangeset for help on using the changeset viewer.