<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[211146] trunk/Tools</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/211146">211146</a></dd>
<dt>Author</dt> <dd>carlosgc@webkit.org</dd>
<dt>Date</dt> <dd>2017-01-25 08:56:00 -0800 (Wed, 25 Jan 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>[GTK] Add a private browsing mode to MiniBrowser
https://bugs.webkit.org/show_bug.cgi?id=167413

Reviewed by Michael Catanzaro.

Add -p/--private command line option to create a private instance. Also add CTRL+SHIFT+P shortcut to create
private windows, even on non-private instances.

* MiniBrowser/gtk/BrowserWindow.c:
(webViewTitleChanged): Add [Private] to title window for private windows.
(webViewCreate): Pass web context to browser_window_new.
(openPrivateWindow): Create a new ephemeral web view and add it to a new window.
(browserWindowFinalize): Disconnect web context signal handlers.
(browser_window_init): Add shortcut for opening private window.
(browser_window_new): It now receives the context and connect to download-started here.
(browser_window_get_web_context): Return the context.
* MiniBrowser/gtk/BrowserWindow.h:
* MiniBrowser/gtk/main.c:
(createBrowserTab): Create the web view for the window web context.
(aboutDataScriptMessageReceivedCallback): Do not use the default web context, but the window one.
(aboutDataHandleRequest): Ditto.
(aboutURISchemeRequestCallback): Ditto.
(main): Create ephemeral web context if private command line option is used.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsMiniBrowsergtkBrowserWindowc">trunk/Tools/MiniBrowser/gtk/BrowserWindow.c</a></li>
<li><a href="#trunkToolsMiniBrowsergtkBrowserWindowh">trunk/Tools/MiniBrowser/gtk/BrowserWindow.h</a></li>
<li><a href="#trunkToolsMiniBrowsergtkmainc">trunk/Tools/MiniBrowser/gtk/main.c</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (211145 => 211146)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2017-01-25 16:54:28 UTC (rev 211145)
+++ trunk/Tools/ChangeLog        2017-01-25 16:56:00 UTC (rev 211146)
</span><span class="lines">@@ -1,3 +1,29 @@
</span><ins>+2017-01-25  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
+
+        [GTK] Add a private browsing mode to MiniBrowser
+        https://bugs.webkit.org/show_bug.cgi?id=167413
+
+        Reviewed by Michael Catanzaro.
+
+        Add -p/--private command line option to create a private instance. Also add CTRL+SHIFT+P shortcut to create
+        private windows, even on non-private instances.
+
+        * MiniBrowser/gtk/BrowserWindow.c:
+        (webViewTitleChanged): Add [Private] to title window for private windows.
+        (webViewCreate): Pass web context to browser_window_new.
+        (openPrivateWindow): Create a new ephemeral web view and add it to a new window.
+        (browserWindowFinalize): Disconnect web context signal handlers.
+        (browser_window_init): Add shortcut for opening private window.
+        (browser_window_new): It now receives the context and connect to download-started here.
+        (browser_window_get_web_context): Return the context.
+        * MiniBrowser/gtk/BrowserWindow.h:
+        * MiniBrowser/gtk/main.c:
+        (createBrowserTab): Create the web view for the window web context.
+        (aboutDataScriptMessageReceivedCallback): Do not use the default web context, but the window one.
+        (aboutDataHandleRequest): Ditto.
+        (aboutURISchemeRequestCallback): Ditto.
+        (main): Create ephemeral web context if private command line option is used.
+
</ins><span class="cx"> 2017-01-25  Ryosuke Niwa  &lt;rniwa@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         collectMatchingElementsInFlatTree should not find elements inside an user agent shadow tree
</span></span></pre></div>
<a id="trunkToolsMiniBrowsergtkBrowserWindowc"></a>
<div class="modfile"><h4>Modified: trunk/Tools/MiniBrowser/gtk/BrowserWindow.c (211145 => 211146)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/MiniBrowser/gtk/BrowserWindow.c        2017-01-25 16:54:28 UTC (rev 211145)
+++ trunk/Tools/MiniBrowser/gtk/BrowserWindow.c        2017-01-25 16:56:00 UTC (rev 211146)
</span><span class="lines">@@ -40,6 +40,8 @@
</span><span class="cx"> struct _BrowserWindow {
</span><span class="cx">     GtkWindow parent;
</span><span class="cx"> 
</span><ins>+    WebKitWebContext *webContext;
+
</ins><span class="cx">     GtkAccelGroup *accelGroup;
</span><span class="cx">     GtkWidget *mainBox;
</span><span class="cx">     GtkWidget *toolbar;
</span><span class="lines">@@ -150,7 +152,13 @@
</span><span class="cx"> static void webViewTitleChanged(WebKitWebView *webView, GParamSpec *pspec, BrowserWindow *window)
</span><span class="cx"> {
</span><span class="cx">     const char *title = webkit_web_view_get_title(webView);
</span><del>-    gtk_window_set_title(GTK_WINDOW(window), title ? title : defaultWindowTitle);
</del><ins>+    if (!title)
+        title = defaultWindowTitle;
+    char *privateTitle = NULL;
+    if (webkit_web_view_is_ephemeral(webView))
+        privateTitle = g_strdup_printf(&quot;[Private] %s&quot;, title);
+    gtk_window_set_title(GTK_WINDOW(window), privateTitle ? privateTitle : title);
+    g_free(privateTitle);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static gboolean resetEntryProgress(BrowserWindow *window)
</span><span class="lines">@@ -287,7 +295,7 @@
</span><span class="cx">     WebKitWebView *newWebView = WEBKIT_WEB_VIEW(webkit_web_view_new_with_related_view(webView));
</span><span class="cx">     webkit_web_view_set_settings(newWebView, webkit_web_view_get_settings(webView));
</span><span class="cx"> 
</span><del>-    GtkWidget *newWindow = browser_window_new(GTK_WINDOW(window));
</del><ins>+    GtkWidget *newWindow = browser_window_new(GTK_WINDOW(window), window-&gt;webContext);
</ins><span class="cx">     browser_window_append_view(BROWSER_WINDOW(newWindow), newWebView);
</span><span class="cx">     g_signal_connect(newWebView, &quot;ready-to-show&quot;, G_CALLBACK(webViewReadyToShow), newWindow);
</span><span class="cx">     g_signal_connect(newWebView, &quot;run-as-modal&quot;, G_CALLBACK(webViewRunAsModal), newWindow);
</span><span class="lines">@@ -484,6 +492,20 @@
</span><span class="cx">     browser_tab_toggle_inspector(window-&gt;activeTab);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static void openPrivateWindow(BrowserWindow *window)
+{
+    WebKitWebView *webView = browser_tab_get_web_view(window-&gt;activeTab);
+    WebKitWebView *newWebView = WEBKIT_WEB_VIEW(g_object_new(WEBKIT_TYPE_WEB_VIEW,
+        &quot;web-context&quot;, webkit_web_view_get_context(webView),
+        &quot;settings&quot;, webkit_web_view_get_settings(webView),
+        &quot;user-content-manager&quot;, webkit_web_view_get_user_content_manager(webView),
+        &quot;is-ephemeral&quot;, TRUE,
+        NULL));
+    GtkWidget *newWindow = browser_window_new(GTK_WINDOW(window), window-&gt;webContext);
+    browser_window_append_view(BROWSER_WINDOW(newWindow), newWebView);
+    gtk_widget_show(GTK_WIDGET(newWindow));
+}
+
</ins><span class="cx"> static void reloadPage(BrowserWindow *window)
</span><span class="cx"> {
</span><span class="cx">     WebKitWebView *webView = browser_tab_get_web_view(window-&gt;activeTab);
</span><span class="lines">@@ -608,6 +630,9 @@
</span><span class="cx"> static void browserWindowFinalize(GObject *gObject)
</span><span class="cx"> {
</span><span class="cx">     BrowserWindow *window = BROWSER_WINDOW(gObject);
</span><ins>+
+    g_signal_handlers_disconnect_matched(window-&gt;webContext, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, window);
+
</ins><span class="cx">     if (window-&gt;favicon) {
</span><span class="cx">         g_object_unref(window-&gt;favicon);
</span><span class="cx">         window-&gt;favicon = NULL;
</span><span class="lines">@@ -839,6 +864,8 @@
</span><span class="cx">         g_cclosure_new_swap(G_CALLBACK(toggleWebInspector), window, NULL));
</span><span class="cx">     gtk_accel_group_connect(window-&gt;accelGroup, GDK_KEY_F12, 0, GTK_ACCEL_VISIBLE,
</span><span class="cx">         g_cclosure_new_swap(G_CALLBACK(toggleWebInspector), window, NULL));
</span><ins>+    gtk_accel_group_connect(window-&gt;accelGroup, GDK_KEY_P, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_ACCEL_VISIBLE,
+        g_cclosure_new_swap(G_CALLBACK(openPrivateWindow), window, NULL));
</ins><span class="cx"> 
</span><span class="cx">     /* Reload page */
</span><span class="cx">     gtk_accel_group_connect(window-&gt;accelGroup, GDK_KEY_F5, 0, GTK_ACCEL_VISIBLE,
</span><span class="lines">@@ -890,8 +917,6 @@
</span><span class="cx">     gtk_accel_group_connect(window-&gt;accelGroup, GDK_KEY_P, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE,
</span><span class="cx">         g_cclosure_new_swap(G_CALLBACK(printPage), window, NULL));
</span><span class="cx"> 
</span><del>-    g_signal_connect(webkit_web_context_get_default(), &quot;download-started&quot;, G_CALLBACK(downloadStarted), window);
-
</del><span class="cx">     GtkWidget *toolbar = gtk_toolbar_new();
</span><span class="cx">     window-&gt;toolbar = toolbar;
</span><span class="cx">     gtk_orientable_set_orientation(GTK_ORIENTABLE(toolbar), GTK_ORIENTATION_HORIZONTAL);
</span><span class="lines">@@ -1017,11 +1042,15 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /* Public API. */
</span><del>-GtkWidget *browser_window_new(GtkWindow *parent)
</del><ins>+GtkWidget *browser_window_new(GtkWindow *parent, WebKitWebContext *webContext)
</ins><span class="cx"> {
</span><ins>+    g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(webContext), NULL);
+
</ins><span class="cx">     BrowserWindow *window = BROWSER_WINDOW(g_object_new(BROWSER_TYPE_WINDOW,
</span><span class="cx">         &quot;type&quot;, GTK_WINDOW_TOPLEVEL, NULL));
</span><span class="cx"> 
</span><ins>+    window-&gt;webContext = webContext;
+    g_signal_connect(window-&gt;webContext, &quot;download-started&quot;, G_CALLBACK(downloadStarted), window);
</ins><span class="cx">     if (parent) {
</span><span class="cx">         window-&gt;parentWindow = parent;
</span><span class="cx">         g_object_add_weak_pointer(G_OBJECT(parent), (gpointer *)&amp;window-&gt;parentWindow);
</span><span class="lines">@@ -1030,6 +1059,13 @@
</span><span class="cx">     return GTK_WIDGET(window);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+WebKitWebContext *browser_window_get_web_context(BrowserWindow *window)
+{
+    g_return_val_if_fail(BROWSER_IS_WINDOW(window), NULL);
+
+    return window-&gt;webContext;
+}
+
</ins><span class="cx"> void browser_window_append_view(BrowserWindow *window, WebKitWebView *webView)
</span><span class="cx"> {
</span><span class="cx">     g_return_if_fail(BROWSER_IS_WINDOW(window));
</span></span></pre></div>
<a id="trunkToolsMiniBrowsergtkBrowserWindowh"></a>
<div class="modfile"><h4>Modified: trunk/Tools/MiniBrowser/gtk/BrowserWindow.h (211145 => 211146)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/MiniBrowser/gtk/BrowserWindow.h        2017-01-25 16:54:28 UTC (rev 211145)
+++ trunk/Tools/MiniBrowser/gtk/BrowserWindow.h        2017-01-25 16:56:00 UTC (rev 211146)
</span><span class="lines">@@ -45,7 +45,8 @@
</span><span class="cx"> 
</span><span class="cx"> GType browser_window_get_type(void);
</span><span class="cx"> 
</span><del>-GtkWidget* browser_window_new(GtkWindow*);
</del><ins>+GtkWidget* browser_window_new(GtkWindow*, WebKitWebContext*);
+WebKitWebContext* browser_window_get_web_context(BrowserWindow*);
</ins><span class="cx"> void browser_window_append_view(BrowserWindow*, WebKitWebView*);
</span><span class="cx"> void browser_window_load_uri(BrowserWindow*, const char *uri);
</span><span class="cx"> void browser_window_load_session(BrowserWindow *, const char *sessionFile);
</span></span></pre></div>
<a id="trunkToolsMiniBrowsergtkmainc"></a>
<div class="modfile"><h4>Modified: trunk/Tools/MiniBrowser/gtk/main.c (211145 => 211146)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/MiniBrowser/gtk/main.c        2017-01-25 16:54:28 UTC (rev 211145)
+++ trunk/Tools/MiniBrowser/gtk/main.c        2017-01-25 16:56:00 UTC (rev 211146)
</span><span class="lines">@@ -41,6 +41,7 @@
</span><span class="cx"> static gboolean editorMode;
</span><span class="cx"> static const char *sessionFile;
</span><span class="cx"> static char *geometry;
</span><ins>+static gboolean privateMode;
</ins><span class="cx"> 
</span><span class="cx"> typedef enum {
</span><span class="cx">     MINI_BROWSER_ERROR_INVALID_ABOUT_PATH
</span><span class="lines">@@ -62,9 +63,12 @@
</span><span class="cx"> 
</span><span class="cx"> static WebKitWebView *createBrowserTab(BrowserWindow *window, WebKitSettings *webkitSettings, WebKitUserContentManager *userContentManager)
</span><span class="cx"> {
</span><del>-    WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new_with_user_content_manager(userContentManager));
-    if (webkitSettings)
-        webkit_web_view_set_settings(webView, webkitSettings);
</del><ins>+    WebKitWebView *webView = WEBKIT_WEB_VIEW(g_object_new(WEBKIT_TYPE_WEB_VIEW,
+        &quot;web-context&quot;, browser_window_get_web_context(window),
+        &quot;settings&quot;, webkitSettings,
+        &quot;user-content-manager&quot;, userContentManager,
+        NULL));
+
</ins><span class="cx">     if (editorMode)
</span><span class="cx">         webkit_web_view_set_editable(webView, TRUE);
</span><span class="cx"> 
</span><span class="lines">@@ -90,6 +94,7 @@
</span><span class="cx">     { &quot;editor-mode&quot;, 'e', 0, G_OPTION_ARG_NONE, &amp;editorMode, &quot;Run in editor mode&quot;, NULL },
</span><span class="cx">     { &quot;session-file&quot;, 's', 0, G_OPTION_ARG_FILENAME, &amp;sessionFile, &quot;Session file&quot;, &quot;FILE&quot; },
</span><span class="cx">     { &quot;geometry&quot;, 'g', 0, G_OPTION_ARG_STRING, &amp;geometry, &quot;Set the size and position of the window (WIDTHxHEIGHT+X+Y)&quot;, &quot;GEOMETRY&quot; },
</span><ins>+    { &quot;private&quot;, 'p', 0, G_OPTION_ARG_NONE, &amp;privateMode, &quot;Run in private browsing mode&quot;, NULL },
</ins><span class="cx">     { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &amp;uriArguments, 0, &quot;[URL…]&quot; },
</span><span class="cx">     { 0, 0, 0, 0, 0, 0, 0 }
</span><span class="cx"> };
</span><span class="lines">@@ -278,7 +283,7 @@
</span><span class="cx">         webkit_web_view_reload(webkit_uri_scheme_request_get_web_view(dataRequest-&gt;request));
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static void aboutDataScriptMessageReceivedCallback(WebKitUserContentManager *userContentManager, WebKitJavascriptResult *message)
</del><ins>+static void aboutDataScriptMessageReceivedCallback(WebKitUserContentManager *userContentManager, WebKitJavascriptResult *message, WebKitWebContext *webContext)
</ins><span class="cx"> {
</span><span class="cx">     JSValueRef jsValue = webkit_javascript_result_get_value(message);
</span><span class="cx">     JSStringRef jsString = JSValueToStringCopy(webkit_javascript_result_get_global_context(message), jsValue, NULL);
</span><span class="lines">@@ -307,7 +312,7 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    WebKitWebsiteDataManager *manager = webkit_web_context_get_website_data_manager(webkit_web_context_get_default());
</del><ins>+    WebKitWebsiteDataManager *manager = webkit_web_context_get_website_data_manager(webContext);
</ins><span class="cx">     guint64 types = g_ascii_strtoull(tokens[1], NULL, 10);
</span><span class="cx">     if (tokenCount == 2)
</span><span class="cx">         webkit_website_data_manager_clear(manager, types, 0, NULL, (GAsyncReadyCallback)websiteDataClearedCallback, dataRequest);
</span><span class="lines">@@ -407,14 +412,14 @@
</span><span class="cx">     g_list_free_full(dataList, (GDestroyNotify)webkit_website_data_unref);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static void aboutDataHandleRequest(WebKitURISchemeRequest *request)
</del><ins>+static void aboutDataHandleRequest(WebKitURISchemeRequest *request, WebKitWebContext *webContext)
</ins><span class="cx"> {
</span><span class="cx">     AboutDataRequest *dataRequest = aboutDataRequestNew(request);
</span><del>-    WebKitWebsiteDataManager *manager = webkit_web_context_get_website_data_manager(webkit_web_context_get_default());
</del><ins>+    WebKitWebsiteDataManager *manager = webkit_web_context_get_website_data_manager(webContext);
</ins><span class="cx">     webkit_website_data_manager_fetch(manager, WEBKIT_WEBSITE_DATA_ALL, NULL, (GAsyncReadyCallback)gotWebsiteDataCallback, dataRequest);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static void aboutURISchemeRequestCallback(WebKitURISchemeRequest *request, gpointer userData)
</del><ins>+static void aboutURISchemeRequestCallback(WebKitURISchemeRequest *request, WebKitWebContext *webContext)
</ins><span class="cx"> {
</span><span class="cx">     GInputStream *stream;
</span><span class="cx">     gsize streamLength;
</span><span class="lines">@@ -434,7 +439,7 @@
</span><span class="cx">         webkit_uri_scheme_request_finish(request, stream, streamLength, &quot;text/html&quot;);
</span><span class="cx">         g_object_unref(stream);
</span><span class="cx">     } else if (!g_strcmp0(path, &quot;data&quot;))
</span><del>-        aboutDataHandleRequest(request);
</del><ins>+        aboutDataHandleRequest(request, webContext);
</ins><span class="cx">     else {
</span><span class="cx">         error = g_error_new(MINI_BROWSER_ERROR, MINI_BROWSER_ERROR_INVALID_ABOUT_PATH, &quot;Invalid about:%s page.&quot;, path);
</span><span class="cx">         webkit_uri_scheme_request_finish_error(request, error);
</span><span class="lines">@@ -449,10 +454,6 @@
</span><span class="cx">     g_setenv(&quot;WEBKIT_INJECTED_BUNDLE_PATH&quot;, WEBKIT_INJECTED_BUNDLE_PATH, FALSE);
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-    const gchar *singleprocess = g_getenv(&quot;MINIBROWSER_SINGLEPROCESS&quot;);
-    webkit_web_context_set_process_model(webkit_web_context_get_default(), (singleprocess &amp;&amp; *singleprocess) ?
-        WEBKIT_PROCESS_MODEL_SHARED_SECONDARY_PROCESS : WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES);
-
</del><span class="cx">     GOptionContext *context = g_option_context_new(NULL);
</span><span class="cx">     g_option_context_add_main_entries(context, commandLineOptions, 0);
</span><span class="cx">     g_option_context_add_group(context, gtk_get_option_group(TRUE));
</span><span class="lines">@@ -474,16 +475,22 @@
</span><span class="cx">     }
</span><span class="cx">     g_option_context_free (context);
</span><span class="cx"> 
</span><ins>+    WebKitWebContext *webContext = privateMode ? webkit_web_context_new_ephemeral() : webkit_web_context_get_default();
+
+    const gchar *singleprocess = g_getenv(&quot;MINIBROWSER_SINGLEPROCESS&quot;);
+    webkit_web_context_set_process_model(webContext, (singleprocess &amp;&amp; *singleprocess) ?
+        WEBKIT_PROCESS_MODEL_SHARED_SECONDARY_PROCESS : WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES);
+
</ins><span class="cx">     // Enable the favicon database, by specifying the default directory.
</span><del>-    webkit_web_context_set_favicon_database_directory(webkit_web_context_get_default(), NULL);
</del><ins>+    webkit_web_context_set_favicon_database_directory(webContext, NULL);
</ins><span class="cx"> 
</span><del>-    webkit_web_context_register_uri_scheme(webkit_web_context_get_default(), BROWSER_ABOUT_SCHEME, aboutURISchemeRequestCallback, NULL, NULL);
</del><ins>+    webkit_web_context_register_uri_scheme(webContext, BROWSER_ABOUT_SCHEME, (WebKitURISchemeRequestCallback)aboutURISchemeRequestCallback, webContext, NULL);
</ins><span class="cx"> 
</span><span class="cx">     WebKitUserContentManager *userContentManager = webkit_user_content_manager_new();
</span><span class="cx">     webkit_user_content_manager_register_script_message_handler(userContentManager, &quot;aboutData&quot;);
</span><del>-    g_signal_connect(userContentManager, &quot;script-message-received::aboutData&quot;, G_CALLBACK(aboutDataScriptMessageReceivedCallback), NULL);
</del><ins>+    g_signal_connect(userContentManager, &quot;script-message-received::aboutData&quot;, G_CALLBACK(aboutDataScriptMessageReceivedCallback), webContext);
</ins><span class="cx"> 
</span><del>-    BrowserWindow *mainWindow = BROWSER_WINDOW(browser_window_new(NULL));
</del><ins>+    BrowserWindow *mainWindow = BROWSER_WINDOW(browser_window_new(NULL, webContext));
</ins><span class="cx">     if (geometry)
</span><span class="cx">         gtk_window_parse_geometry(GTK_WINDOW(mainWindow), geometry);
</span><span class="cx"> 
</span><span class="lines">@@ -522,5 +529,8 @@
</span><span class="cx"> 
</span><span class="cx">     gtk_main();
</span><span class="cx"> 
</span><ins>+    if (privateMode)
+        g_object_unref(webContext);
+
</ins><span class="cx">     return 0;
</span><span class="cx"> }
</span></span></pre>
</div>
</div>

</body>
</html>