Skip to content

Commit

Permalink
browser(webkit): support --user-data-dir on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s committed Jan 23, 2020
1 parent ac2ba3c commit 6f04a3e
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 26 deletions.
2 changes: 1 addition & 1 deletion browser_patches/webkit/BUILD_NUMBER
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1106
1107
88 changes: 63 additions & 25 deletions browser_patches/webkit/patches/bootstrap.diff
Original file line number Diff line number Diff line change
Expand Up @@ -9351,10 +9351,10 @@ index 31d29091985f34a65134a2b0e7cb3ace1dae441d..571ceac8a4b291fa6e91eb8b17065c0a
};
diff --git a/Source/WebKit/UIProcess/glib/InspectorBrowserAgentClientGLib.cpp b/Source/WebKit/UIProcess/glib/InspectorBrowserAgentClientGLib.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..d3f969edbd888c4f9265c04e07814d0a3e337802
index 0000000000000000000000000000000000000000..0a4fadb6b4bc560c103d55d70bf0d61c3c03622f
--- /dev/null
+++ b/Source/WebKit/UIProcess/glib/InspectorBrowserAgentClientGLib.cpp
@@ -0,0 +1,132 @@
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2019 Microsoft Corporation.
+ *
Expand Down Expand Up @@ -9427,20 +9427,25 @@ index 0000000000000000000000000000000000000000..d3f969edbd888c4f9265c04e07814d0a
+RefPtr<WebPageProxy> InspectorBrowserAgentClientGlib::createPage(WTF::String& error, const BrowserContext& browserContext)
+{
+ auto sessionID = browserContext.dataStore->sessionID();
+ WebKitWebContext* context;
+ if (!sessionID || webkitWebContextGetProcessPool(webkit_web_context_get_default()).websiteDataStore()->sessionID() == sessionID)
+ context = webkit_web_context_get_default();
+ else
+ context = m_idToContext.get(sessionID);
+
+ if (context == nullptr) {
+ WebKitWebContext* context = m_idToContext.get(sessionID);
+ if (!context && !browserContext.dataStore->isPersistent()) {
+ ASSERT_NOT_REACHED();
+ error = "Context with provided id not found";
+ return nullptr;
+ }
+
+ RefPtr<WebPageProxy> page = webkitBrowserInspectorCreateNewPageInContext(context);
+ if (page == nullptr)
+ if (page == nullptr) {
+ error = "Failed to create new page in the context";
+ return nullptr;
+ }
+
+ if (context == nullptr && sessionID != page->sessionID()) {
+ ASSERT_NOT_REACHED();
+ error = " Failed to create new page in default context";
+ return nullptr;
+ }
+
+ return page;
+}
+
Expand Down Expand Up @@ -11452,7 +11457,7 @@ index 1570d65effb5d601ee3c44a2a7461436f4691c2c..456f96cf589320efa70a76f76e230b67

typedef struct _BrowserWindow BrowserWindow;
diff --git a/Tools/MiniBrowser/gtk/main.c b/Tools/MiniBrowser/gtk/main.c
index 4c5147dcd38a53e2feaeaae0fce38f92dc60eba6..17854dbfb1a3223e091ab90c0ca1bfc1e1f13d44 100644
index 4c5147dcd38a53e2feaeaae0fce38f92dc60eba6..19a6d2cd9605a83b5233604be9d371f61c8529dd 100644
--- a/Tools/MiniBrowser/gtk/main.c
+++ b/Tools/MiniBrowser/gtk/main.c
@@ -53,6 +53,9 @@ static const char *cookiesFile;
Expand All @@ -11475,12 +11480,17 @@ index 4c5147dcd38a53e2feaeaae0fce38f92dc60eba6..17854dbfb1a3223e091ab90c0ca1bfc1
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &uriArguments, 0, "[URL…]" },
{ 0, 0, 0, 0, 0, 0, 0 }
};
@@ -498,6 +504,29 @@ static void filterSavedCallback(WebKitUserContentFilterStore *store, GAsyncResul
@@ -498,6 +504,36 @@ static void filterSavedCallback(WebKitUserContentFilterStore *store, GAsyncResul
g_main_loop_quit(data->mainLoop);
}

+static WebKitWebContext *persistentWebContext = NULL;
+
+static WebKitWebView *createNewPage(WebKitBrowserInspector *browser_inspector, WebKitWebContext *context)
+{
+ if (context == NULL)
+ context = persistentWebContext;
+
+ WebKitWebView *newWebView = WEBKIT_WEB_VIEW(g_object_new(WEBKIT_TYPE_WEB_VIEW,
+ "web-context", context,
+ "is-ephemeral", webkit_web_context_is_ephemeral(context),
Expand All @@ -11494,8 +11504,10 @@ index 4c5147dcd38a53e2feaeaae0fce38f92dc60eba6..17854dbfb1a3223e091ab90c0ca1bfc1
+ return newWebView;
+}
+
+static void configureBrowserInspectorPipe()
+static void configureBrowserInspectorPipe(WebKitWebContext *webContext)
+{
+ persistentWebContext = webContext;
+
+ WebKitBrowserInspector* browserInspector = webkit_browser_inspector_get_default();
+ g_signal_connect(browserInspector, "create-new-page", G_CALLBACK(createNewPage), NULL);
+
Expand All @@ -11505,16 +11517,16 @@ index 4c5147dcd38a53e2feaeaae0fce38f92dc60eba6..17854dbfb1a3223e091ab90c0ca1bfc1
int main(int argc, char *argv[])
{
#if ENABLE_DEVELOPER_MODE
@@ -541,10 +570,22 @@ int main(int argc, char *argv[])
@@ -541,10 +577,22 @@ int main(int argc, char *argv[])
return 0;
}

- WebKitWebsiteDataManager *manager = (privateMode || automationMode) ? webkit_website_data_manager_new_ephemeral() : webkit_website_data_manager_new(NULL);
+ WebKitWebsiteDataManager *manager;
+ if (inspectorPipe) {
+ manager = webkit_web_context_get_website_data_manager(webkit_web_context_get_default());
+ g_object_ref(manager);
+ } else if (privateMode || automationMode) {
+ if (userDataDir) {
+ manager = webkit_website_data_manager_new("base-data-directory", userDataDir, "base-cache-directory", userDataDir, NULL);
+ cookiesFile = g_build_filename(userDataDir, "cookies.txt", NULL);
+ } else if (inspectorPipe || privateMode || automationMode) {
+ manager = webkit_website_data_manager_new_ephemeral();
+ } else {
+ manager = webkit_website_data_manager_new(NULL);
Expand All @@ -11524,7 +11536,7 @@ index 4c5147dcd38a53e2feaeaae0fce38f92dc60eba6..17854dbfb1a3223e091ab90c0ca1bfc1
g_object_unref(manager);

+ if (inspectorPipe)
+ configureBrowserInspectorPipe();
+ configureBrowserInspectorPipe(webContext);
+
if (cookiesPolicy) {
WebKitCookieManager *cookieManager = webkit_web_context_get_cookie_manager(webContext);
Expand Down Expand Up @@ -11830,7 +11842,7 @@ index 245f319abf2595e154d03e1ee8b3250d7f46aafd..9cae87b23deade7c163f34aade2b2aed
${WPEBACKEND_FDO_INCLUDE_DIRS}
)
diff --git a/Tools/MiniBrowser/wpe/main.cpp b/Tools/MiniBrowser/wpe/main.cpp
index 2d183d394123bd84545dc51f53eb9be796fb8873..867e7d08fd5f922e32e09550ac19a21d0c8fb7d1 100644
index 2d183d394123bd84545dc51f53eb9be796fb8873..f986983d92c195302c1d6b65098011de77dd0d13 100644
--- a/Tools/MiniBrowser/wpe/main.cpp
+++ b/Tools/MiniBrowser/wpe/main.cpp
@@ -25,7 +25,7 @@
Expand Down Expand Up @@ -11894,7 +11906,7 @@ index 2d183d394123bd84545dc51f53eb9be796fb8873..867e7d08fd5f922e32e09550ac19a21d
{
auto backend = createViewBackend(1280, 720);
struct wpe_view_backend* wpeBackend = backend->backend();
@@ -164,14 +184,48 @@ static WebKitWebView* createWebView(WebKitWebView* webView, WebKitNavigationActi
@@ -164,14 +184,54 @@ static WebKitWebView* createWebView(WebKitWebView* webView, WebKitNavigationActi
delete static_cast<WPEToolingBackends::ViewBackend*>(data);
}, backend.release());

Expand Down Expand Up @@ -11931,13 +11943,19 @@ index 2d183d394123bd84545dc51f53eb9be796fb8873..867e7d08fd5f922e32e09550ac19a21d
+ return createWebViewImpl(webView, nullptr);
+}
+
+static WebKitWebContext *persistentWebContext = NULL;
+
+static WebKitWebView* createNewPage(WebKitBrowserInspector*, WebKitWebContext *webContext)
+{
+ if (!webContext)
+ webContext = persistentWebContext;
+ return createWebViewImpl(nullptr, webContext);
+}
+
+static void configureBrowserInspector(GMainLoop* mainLoop)
+static void configureBrowserInspector(GMainLoop* mainLoop, WebKitWebContext *webContext)
+{
+ persistentWebContext = webContext;
+
+ WebKitBrowserInspector* browserInspector = webkit_browser_inspector_get_default();
+ g_signal_connect(browserInspector, "create-new-page", G_CALLBACK(createNewPage), NULL);
+ webkit_browser_inspector_initialize_pipe(mainLoop);
Expand All @@ -11946,17 +11964,37 @@ index 2d183d394123bd84545dc51f53eb9be796fb8873..867e7d08fd5f922e32e09550ac19a21d
int main(int argc, char *argv[])
{
#if ENABLE_DEVELOPER_MODE
@@ -280,6 +334,9 @@ int main(int argc, char *argv[])
@@ -215,7 +275,18 @@ int main(int argc, char *argv[])
return 1;
}

- auto* webContext = (privateMode || automationMode) ? webkit_web_context_new_ephemeral() : webkit_web_context_get_default();
+ WebKitWebsiteDataManager *manager;
+ if (userDataDir) {
+ manager = webkit_website_data_manager_new("base-data-directory", userDataDir, "base-cache-directory", userDataDir, NULL);
+ cookiesFile = g_build_filename(userDataDir, "cookies.txt", NULL);
+ } else if (inspectorPipe || privateMode || automationMode) {
+ manager = webkit_website_data_manager_new_ephemeral();
+ } else {
+ manager = webkit_website_data_manager_new(NULL);
+ }
+
+ WebKitWebContext *webContext = g_object_new(WEBKIT_TYPE_WEB_CONTEXT, "website-data-manager", manager, "process-swap-on-cross-site-navigation-enabled", TRUE, NULL);
+ g_object_unref(manager);

if (cookiesPolicy) {
auto* cookieManager = webkit_web_context_get_cookie_manager(webContext);
@@ -280,6 +351,9 @@ int main(int argc, char *argv[])
delete static_cast<WPEToolingBackends::ViewBackend*>(data);
}, backend.release());

+ if (inspectorPipe)
+ configureBrowserInspector(loop);
+ configureBrowserInspector(loop, webContext);
+
auto* webView = WEBKIT_WEB_VIEW(g_object_new(WEBKIT_TYPE_WEB_VIEW,
"backend", viewBackend,
"web-context", webContext,
@@ -318,7 +375,7 @@ int main(int argc, char *argv[])
@@ -318,7 +392,7 @@ int main(int argc, char *argv[])
g_object_unref(file);
webkit_web_view_load_uri(webView, url);
g_free(url);
Expand Down

0 comments on commit 6f04a3e

Please sign in to comment.