summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Carl <danielcarl@gmx.de>2021-01-07 23:07:16 +0100
committerDaniel Carl <danielcarl@gmx.de>2021-01-07 23:07:16 +0100
commita8d61308e84f3c6de09ab7ea426563674c25d561 (patch)
tree95ecf22d35fff91d6b8e7f0526d3716dd32882c1 /src
parentc60d65f59788094b8010481cd04f08c9d3b637fd (diff)
Fix none registered webextension in ephemeral mode.
Fixes #652
Diffstat (limited to 'src')
-rw-r--r--src/main.c44
-rw-r--r--src/main.h2
-rw-r--r--src/util.c12
-rw-r--r--src/util.h1
4 files changed, 44 insertions, 15 deletions
diff --git a/src/main.c b/src/main.c
index 5e3c51d..07620b3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1818,6 +1818,7 @@ static void vimb_cleanup(void)
g_free(vb.profile);
g_slist_free_full(vb.cmdargs, g_free);
+ g_clear_object(&vb.webcontext);
}
#endif
@@ -1826,8 +1827,6 @@ static void vimb_cleanup(void)
*/
static void vimb_setup(void)
{
- WebKitWebContext *ctx;
- WebKitCookieManager *cm;
char *path, *dataPath;
/* Prepare files in XDG_CONFIG_HOME */
@@ -1858,22 +1857,31 @@ static void vimb_setup(void)
vb.storage[STORAGE_SEARCH] = file_storage_new(dataPath, "search", vb.incognito);
g_free(dataPath);
- /* Use seperate rendering processed for the webview of the clients in the
- * current instance. This must be called as soon as possible according to
- * the documentation. */
+ WebKitWebsiteDataManager *manager = NULL;
if (vb.incognito) {
- ctx = webkit_web_context_new_ephemeral();
+ manager = webkit_website_data_manager_new_ephemeral();
} else {
- ctx = webkit_web_context_get_default();
+ manager = webkit_website_data_manager_new(
+ "base-data-directory", util_get_data_dir(),
+ "base-cache-directory", util_get_cache_dir(),
+ NULL);
}
- webkit_web_context_set_process_model(ctx, WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES);
- webkit_web_context_set_cache_model(ctx, WEBKIT_CACHE_MODEL_WEB_BROWSER);
+ vb.webcontext = webkit_web_context_new_with_website_data_manager(manager);
+ manager = webkit_web_context_get_website_data_manager(vb.webcontext);
+ /* Use seperate rendering processed for the webview of the clients in the
+ * current instance. This must be called as soon as possible according to
+ * the documentation. */
+ webkit_web_context_set_process_model(vb.webcontext, WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES);
+ webkit_web_context_set_cache_model(vb.webcontext, WEBKIT_CACHE_MODEL_WEB_BROWSER);
+
+ g_signal_connect(vb.webcontext, "initialize-web-extensions", G_CALLBACK(on_webctx_init_web_extension), NULL);
- g_signal_connect(ctx, "initialize-web-extensions", G_CALLBACK(on_webctx_init_web_extension), NULL);
+ /* Add cookie support only if the cookie file exists and web context is
+ * not ephemeral */
+ if (vb.files[FILES_COOKIE] && !webkit_web_context_is_ephemeral(vb.webcontext)) {
+ WebKitCookieManager *cm;
- /* Add cookie support only if the cookie file exists. */
- if (vb.files[FILES_COOKIE]) {
- cm = webkit_web_context_get_cookie_manager(ctx);
+ cm = webkit_web_context_get_cookie_manager(vb.webcontext);
webkit_cookie_manager_set_persistent_storage(
cm,
vb.files[FILES_COOKIE],
@@ -1998,9 +2006,15 @@ static WebKitWebView *webview_new(Client *c, WebKitWebView *webview)
/* create a new webview */
ucm = webkit_user_content_manager_new();
if (webview) {
- new = WEBKIT_WEB_VIEW(webkit_web_view_new_with_related_view(webview));
+ new = WEBKIT_WEB_VIEW(g_object_new(WEBKIT_TYPE_WEB_VIEW,
+ "user-content-manager", ucm,
+ "related-view", webview,
+ NULL));
} else {
- new = WEBKIT_WEB_VIEW(webkit_web_view_new_with_user_content_manager(ucm));
+ new = WEBKIT_WEB_VIEW(g_object_new(WEBKIT_TYPE_WEB_VIEW,
+ "user-content-manager", ucm,
+ "web-context", vb.webcontext,
+ NULL));
}
g_object_connect(
diff --git a/src/main.h b/src/main.h
index 739bd39..9fa47f1 100644
--- a/src/main.h
+++ b/src/main.h
@@ -290,6 +290,8 @@ struct Vimb {
GtkCssProvider *style_provider;
gboolean no_maximize;
gboolean incognito;
+
+ WebKitWebContext *webcontext;
};
gboolean vb_download_set_destination(Client *c, WebKitDownload *download,
diff --git a/src/util.c b/src/util.c
index 56bbb0c..c1a3b10 100644
--- a/src/util.c
+++ b/src/util.c
@@ -353,6 +353,18 @@ char *util_get_data_dir(void)
}
/**
+ * Retrieves the cache directory path according to current used profile.
+ * Returned string must be freed.
+ */
+char *util_get_cache_dir(void)
+{
+ char *path = g_build_filename(g_get_user_cache_dir(), PROJECT, vb.profile, NULL);
+ create_dir_if_not_exists(path);
+
+ return path;
+}
+
+/**
* Retrieves the length bytes from given file.
*
* The memory of returned string have to be freed with g_free().
diff --git a/src/util.h b/src/util.h
index 4d6e573..811af20 100644
--- a/src/util.h
+++ b/src/util.h
@@ -41,6 +41,7 @@ void util_file_prepend_line(const char *file, const char *line,
char *util_file_pop_line(const char *file, int *item_count);
char *util_get_config_dir(void);
char *util_get_data_dir(void);
+char *util_get_cache_dir(void);
char *util_get_file_contents(const char *filename, gsize *length);
gboolean util_file_set_content(const char *file, const char *contents);
char **util_get_lines(const char *filename);