Changeset 211146 in webkit
- Timestamp:
- Jan 25, 2017, 8:56:00 AM (10 years ago)
- Location:
- trunk/Tools
- Files:
-
- 4 edited
-
ChangeLog (modified) (1 diff)
-
MiniBrowser/gtk/BrowserWindow.c (modified) (9 diffs)
-
MiniBrowser/gtk/BrowserWindow.h (modified) (1 diff)
-
MiniBrowser/gtk/main.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r211139 r211146 1 2017-01-25 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 [GTK] Add a private browsing mode to MiniBrowser 4 https://bugs.webkit.org/show_bug.cgi?id=167413 5 6 Reviewed by Michael Catanzaro. 7 8 Add -p/--private command line option to create a private instance. Also add CTRL+SHIFT+P shortcut to create 9 private windows, even on non-private instances. 10 11 * MiniBrowser/gtk/BrowserWindow.c: 12 (webViewTitleChanged): Add [Private] to title window for private windows. 13 (webViewCreate): Pass web context to browser_window_new. 14 (openPrivateWindow): Create a new ephemeral web view and add it to a new window. 15 (browserWindowFinalize): Disconnect web context signal handlers. 16 (browser_window_init): Add shortcut for opening private window. 17 (browser_window_new): It now receives the context and connect to download-started here. 18 (browser_window_get_web_context): Return the context. 19 * MiniBrowser/gtk/BrowserWindow.h: 20 * MiniBrowser/gtk/main.c: 21 (createBrowserTab): Create the web view for the window web context. 22 (aboutDataScriptMessageReceivedCallback): Do not use the default web context, but the window one. 23 (aboutDataHandleRequest): Ditto. 24 (aboutURISchemeRequestCallback): Ditto. 25 (main): Create ephemeral web context if private command line option is used. 26 1 27 2017-01-25 Ryosuke Niwa <rniwa@webkit.org> 2 28 -
trunk/Tools/MiniBrowser/gtk/BrowserWindow.c
r211079 r211146 41 41 GtkWindow parent; 42 42 43 WebKitWebContext *webContext; 44 43 45 GtkAccelGroup *accelGroup; 44 46 GtkWidget *mainBox; … … 151 153 { 152 154 const char *title = webkit_web_view_get_title(webView); 153 gtk_window_set_title(GTK_WINDOW(window), title ? title : defaultWindowTitle); 155 if (!title) 156 title = defaultWindowTitle; 157 char *privateTitle = NULL; 158 if (webkit_web_view_is_ephemeral(webView)) 159 privateTitle = g_strdup_printf("[Private] %s", title); 160 gtk_window_set_title(GTK_WINDOW(window), privateTitle ? privateTitle : title); 161 g_free(privateTitle); 154 162 } 155 163 … … 288 296 webkit_web_view_set_settings(newWebView, webkit_web_view_get_settings(webView)); 289 297 290 GtkWidget *newWindow = browser_window_new(GTK_WINDOW(window) );298 GtkWidget *newWindow = browser_window_new(GTK_WINDOW(window), window->webContext); 291 299 browser_window_append_view(BROWSER_WINDOW(newWindow), newWebView); 292 300 g_signal_connect(newWebView, "ready-to-show", G_CALLBACK(webViewReadyToShow), newWindow); … … 485 493 } 486 494 495 static void openPrivateWindow(BrowserWindow *window) 496 { 497 WebKitWebView *webView = browser_tab_get_web_view(window->activeTab); 498 WebKitWebView *newWebView = WEBKIT_WEB_VIEW(g_object_new(WEBKIT_TYPE_WEB_VIEW, 499 "web-context", webkit_web_view_get_context(webView), 500 "settings", webkit_web_view_get_settings(webView), 501 "user-content-manager", webkit_web_view_get_user_content_manager(webView), 502 "is-ephemeral", TRUE, 503 NULL)); 504 GtkWidget *newWindow = browser_window_new(GTK_WINDOW(window), window->webContext); 505 browser_window_append_view(BROWSER_WINDOW(newWindow), newWebView); 506 gtk_widget_show(GTK_WIDGET(newWindow)); 507 } 508 487 509 static void reloadPage(BrowserWindow *window) 488 510 { … … 609 631 { 610 632 BrowserWindow *window = BROWSER_WINDOW(gObject); 633 634 g_signal_handlers_disconnect_matched(window->webContext, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, window); 635 611 636 if (window->favicon) { 612 637 g_object_unref(window->favicon); … … 840 865 gtk_accel_group_connect(window->accelGroup, GDK_KEY_F12, 0, GTK_ACCEL_VISIBLE, 841 866 g_cclosure_new_swap(G_CALLBACK(toggleWebInspector), window, NULL)); 867 gtk_accel_group_connect(window->accelGroup, GDK_KEY_P, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_ACCEL_VISIBLE, 868 g_cclosure_new_swap(G_CALLBACK(openPrivateWindow), window, NULL)); 842 869 843 870 /* Reload page */ … … 891 918 g_cclosure_new_swap(G_CALLBACK(printPage), window, NULL)); 892 919 893 g_signal_connect(webkit_web_context_get_default(), "download-started", G_CALLBACK(downloadStarted), window);894 895 920 GtkWidget *toolbar = gtk_toolbar_new(); 896 921 window->toolbar = toolbar; … … 1018 1043 1019 1044 /* Public API. */ 1020 GtkWidget *browser_window_new(GtkWindow *parent) 1021 { 1045 GtkWidget *browser_window_new(GtkWindow *parent, WebKitWebContext *webContext) 1046 { 1047 g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(webContext), NULL); 1048 1022 1049 BrowserWindow *window = BROWSER_WINDOW(g_object_new(BROWSER_TYPE_WINDOW, 1023 1050 "type", GTK_WINDOW_TOPLEVEL, NULL)); 1024 1051 1052 window->webContext = webContext; 1053 g_signal_connect(window->webContext, "download-started", G_CALLBACK(downloadStarted), window); 1025 1054 if (parent) { 1026 1055 window->parentWindow = parent; … … 1029 1058 1030 1059 return GTK_WIDGET(window); 1060 } 1061 1062 WebKitWebContext *browser_window_get_web_context(BrowserWindow *window) 1063 { 1064 g_return_val_if_fail(BROWSER_IS_WINDOW(window), NULL); 1065 1066 return window->webContext; 1031 1067 } 1032 1068 -
trunk/Tools/MiniBrowser/gtk/BrowserWindow.h
r203271 r211146 46 46 GType browser_window_get_type(void); 47 47 48 GtkWidget* browser_window_new(GtkWindow*); 48 GtkWidget* browser_window_new(GtkWindow*, WebKitWebContext*); 49 WebKitWebContext* browser_window_get_web_context(BrowserWindow*); 49 50 void browser_window_append_view(BrowserWindow*, WebKitWebView*); 50 51 void browser_window_load_uri(BrowserWindow*, const char *uri); -
trunk/Tools/MiniBrowser/gtk/main.c
r211079 r211146 42 42 static const char *sessionFile; 43 43 static char *geometry; 44 static gboolean privateMode; 44 45 45 46 typedef enum { … … 63 64 static WebKitWebView *createBrowserTab(BrowserWindow *window, WebKitSettings *webkitSettings, WebKitUserContentManager *userContentManager) 64 65 { 65 WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new_with_user_content_manager(userContentManager)); 66 if (webkitSettings) 67 webkit_web_view_set_settings(webView, webkitSettings); 66 WebKitWebView *webView = WEBKIT_WEB_VIEW(g_object_new(WEBKIT_TYPE_WEB_VIEW, 67 "web-context", browser_window_get_web_context(window), 68 "settings", webkitSettings, 69 "user-content-manager", userContentManager, 70 NULL)); 71 68 72 if (editorMode) 69 73 webkit_web_view_set_editable(webView, TRUE); … … 91 95 { "session-file", 's', 0, G_OPTION_ARG_FILENAME, &sessionFile, "Session file", "FILE" }, 92 96 { "geometry", 'g', 0, G_OPTION_ARG_STRING, &geometry, "Set the size and position of the window (WIDTHxHEIGHT+X+Y)", "GEOMETRY" }, 97 { "private", 'p', 0, G_OPTION_ARG_NONE, &privateMode, "Run in private browsing mode", NULL }, 93 98 { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &uriArguments, 0, "[URL…]" }, 94 99 { 0, 0, 0, 0, 0, 0, 0 } … … 279 284 } 280 285 281 static void aboutDataScriptMessageReceivedCallback(WebKitUserContentManager *userContentManager, WebKitJavascriptResult *message )286 static void aboutDataScriptMessageReceivedCallback(WebKitUserContentManager *userContentManager, WebKitJavascriptResult *message, WebKitWebContext *webContext) 282 287 { 283 288 JSValueRef jsValue = webkit_javascript_result_get_value(message); … … 308 313 } 309 314 310 WebKitWebsiteDataManager *manager = webkit_web_context_get_website_data_manager(web kit_web_context_get_default());315 WebKitWebsiteDataManager *manager = webkit_web_context_get_website_data_manager(webContext); 311 316 guint64 types = g_ascii_strtoull(tokens[1], NULL, 10); 312 317 if (tokenCount == 2) … … 408 413 } 409 414 410 static void aboutDataHandleRequest(WebKitURISchemeRequest *request )415 static void aboutDataHandleRequest(WebKitURISchemeRequest *request, WebKitWebContext *webContext) 411 416 { 412 417 AboutDataRequest *dataRequest = aboutDataRequestNew(request); 413 WebKitWebsiteDataManager *manager = webkit_web_context_get_website_data_manager(web kit_web_context_get_default());418 WebKitWebsiteDataManager *manager = webkit_web_context_get_website_data_manager(webContext); 414 419 webkit_website_data_manager_fetch(manager, WEBKIT_WEBSITE_DATA_ALL, NULL, (GAsyncReadyCallback)gotWebsiteDataCallback, dataRequest); 415 420 } 416 421 417 static void aboutURISchemeRequestCallback(WebKitURISchemeRequest *request, gpointer userData)422 static void aboutURISchemeRequestCallback(WebKitURISchemeRequest *request, WebKitWebContext *webContext) 418 423 { 419 424 GInputStream *stream; … … 435 440 g_object_unref(stream); 436 441 } else if (!g_strcmp0(path, "data")) 437 aboutDataHandleRequest(request );442 aboutDataHandleRequest(request, webContext); 438 443 else { 439 444 error = g_error_new(MINI_BROWSER_ERROR, MINI_BROWSER_ERROR_INVALID_ABOUT_PATH, "Invalid about:%s page.", path); … … 449 454 g_setenv("WEBKIT_INJECTED_BUNDLE_PATH", WEBKIT_INJECTED_BUNDLE_PATH, FALSE); 450 455 #endif 451 452 const gchar *singleprocess = g_getenv("MINIBROWSER_SINGLEPROCESS");453 webkit_web_context_set_process_model(webkit_web_context_get_default(), (singleprocess && *singleprocess) ?454 WEBKIT_PROCESS_MODEL_SHARED_SECONDARY_PROCESS : WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES);455 456 456 457 GOptionContext *context = g_option_context_new(NULL); … … 475 476 g_option_context_free (context); 476 477 478 WebKitWebContext *webContext = privateMode ? webkit_web_context_new_ephemeral() : webkit_web_context_get_default(); 479 480 const gchar *singleprocess = g_getenv("MINIBROWSER_SINGLEPROCESS"); 481 webkit_web_context_set_process_model(webContext, (singleprocess && *singleprocess) ? 482 WEBKIT_PROCESS_MODEL_SHARED_SECONDARY_PROCESS : WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES); 483 477 484 // Enable the favicon database, by specifying the default directory. 478 webkit_web_context_set_favicon_database_directory(web kit_web_context_get_default(), NULL);479 480 webkit_web_context_register_uri_scheme(web kit_web_context_get_default(), BROWSER_ABOUT_SCHEME, aboutURISchemeRequestCallback, NULL, NULL);485 webkit_web_context_set_favicon_database_directory(webContext, NULL); 486 487 webkit_web_context_register_uri_scheme(webContext, BROWSER_ABOUT_SCHEME, (WebKitURISchemeRequestCallback)aboutURISchemeRequestCallback, webContext, NULL); 481 488 482 489 WebKitUserContentManager *userContentManager = webkit_user_content_manager_new(); 483 490 webkit_user_content_manager_register_script_message_handler(userContentManager, "aboutData"); 484 g_signal_connect(userContentManager, "script-message-received::aboutData", G_CALLBACK(aboutDataScriptMessageReceivedCallback), NULL);485 486 BrowserWindow *mainWindow = BROWSER_WINDOW(browser_window_new(NULL ));491 g_signal_connect(userContentManager, "script-message-received::aboutData", G_CALLBACK(aboutDataScriptMessageReceivedCallback), webContext); 492 493 BrowserWindow *mainWindow = BROWSER_WINDOW(browser_window_new(NULL, webContext)); 487 494 if (geometry) 488 495 gtk_window_parse_geometry(GTK_WINDOW(mainWindow), geometry); … … 523 530 gtk_main(); 524 531 532 if (privateMode) 533 g_object_unref(webContext); 534 525 535 return 0; 526 536 }
Note:
See TracChangeset
for help on using the changeset viewer.