Changeset 147624 in webkit
- Timestamp:
- Apr 4, 2013 6:26:22 AM (11 years ago)
- Location:
- trunk/Tools
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r147603 r147624 1 2013-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 1 26 2013-04-03 Roger Fong <roger_fong@apple.com> 2 27 -
trunk/Tools/MiniBrowser/gtk/BrowserWindow.c
r141585 r147624 64 64 65 65 static const char *defaultWindowTitle = "WebKitGTK+ MiniBrowser"; 66 static const char *miniBrowserAboutScheme = "minibrowser-about"; 66 67 static const gdouble minimumZoomLevel = 0.5; 67 68 static const gdouble maximumZoomLevel = 3; … … 71 72 G_DEFINE_TYPE(BrowserWindow, browser_window, GTK_TYPE_WINDOW) 72 73 74 static 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 83 static 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 73 92 static void browserWindowSetStatusText(BrowserWindow *window, const char *text) 74 93 { … … 119 138 static void webViewURIChanged(WebKitWebView *webView, GParamSpec *pspec, BrowserWindow *window) 120 139 { 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); 122 143 } 123 144 … … 278 299 { 279 300 #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)); 281 302 if (!titleOrURI) 282 titleOrURI = webkit_web_view_get_uri(window->webView);303 titleOrURI = getExternalURI(webkit_web_view_get_uri(window->webView)); 283 304 gchar *message = g_strdup_printf("%s is now full screen. Press ESC or f to exit.", titleOrURI); 284 305 gtk_label_set_text(GTK_LABEL(window->fullScreenMessageLabel), message); 306 g_free(titleOrURI); 285 307 g_free(message); 286 308 … … 644 666 645 667 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); 647 671 return; 648 672 } -
trunk/Tools/MiniBrowser/gtk/main.c
r139305 r147624 33 33 34 34 static const gchar **uriArguments = NULL; 35 static const char *miniBrowserAboutScheme = "minibrowser-about"; 35 36 36 37 static gchar *argumentToURL(const char *filename) … … 199 200 } 200 201 202 static void 203 aboutURISchemeRequestCallback(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 201 226 int main(int argc, char *argv[]) 202 227 { … … 232 257 webkit_web_context_set_favicon_database_directory(webkit_web_context_get_default(), NULL); 233 258 259 webkit_web_context_register_uri_scheme(webkit_web_context_get_default(), miniBrowserAboutScheme, aboutURISchemeRequestCallback, NULL, NULL); 260 234 261 if (uriArguments) { 235 262 int i;
Note: See TracChangeset
for help on using the changeset viewer.