[geary/bug/728002-webkit2: 123/140] Set a specific disk cache dir for the web process.



commit 3e203a9c1963cc013a1fbdcb690f59064dd55ea2
Author: Michael James Gratton <mike vee net>
Date:   Fri Jan 27 14:40:55 2017 +1100

    Set a specific disk cache dir for the web process.
    
    * src/client/application/geary-controller.vala
      (GearyController::open_async): Pass new cache dir through to
      ClientWebView::init_web_context. Update avatar cache dir name to remove
      redundancy.
    
    * src/client/components/client-web-view.vala
      (ClientWebView::init_web_context): Add additional cache dir para and
      update call sites. Use to construct a WebsiteDataManager
      instance. Construct a new WebContext using the data manager, and use
      that instead of the default one when creating new ClientWebView
      instances.

 src/client/application/geary-controller.vala       |    3 +-
 src/client/components/client-web-view.vala         |   26 ++++++++++++++++++-
 .../components/client-web-view-test-case.vala      |    1 +
 3 files changed, 27 insertions(+), 3 deletions(-)
---
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index b80e051..4168d94 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -192,6 +192,7 @@ public class GearyController : Geary.BaseObject {
         ClientWebView.init_web_context(
             this.application.config,
             this.application.get_web_extensions_dir(),
+            this.application.get_user_cache_directory().get_child("web-resources"),
             Args.log_debug
         );
         try {
@@ -208,7 +209,7 @@ public class GearyController : Geary.BaseObject {
         // per-session, and we don't want to have to load the cache
         // for each conversation load.
         File avatar_cache_dir = this.application.get_user_cache_directory()
-            .get_child("avatar_cache");
+            .get_child("avatars");
         this.avatar_cache = new Soup.Cache(
             avatar_cache_dir.get_path(),
             Soup.CacheType.SINGLE_USER
diff --git a/src/client/components/client-web-view.vala b/src/client/components/client-web-view.vala
index 086a177..c0b07aa 100644
--- a/src/client/components/client-web-view.vala
+++ b/src/client/components/client-web-view.vala
@@ -32,6 +32,19 @@ public class ClientWebView : WebKit.WebView {
     private const double ZOOM_DEFAULT = 1.0;
     private const double ZOOM_FACTOR = 0.1;
 
+
+    // Workaround WK binding ctor not accepting any args
+    private class WebsiteDataManager : WebKit.WebsiteDataManager {
+
+        public WebsiteDataManager(string base_cache_directory) {
+            Object(base_cache_directory: base_cache_directory);
+        }
+
+    }
+
+
+    private static WebKit.WebContext? default_context = null;
+
     private static WebKit.UserScript? script = null;
     private static WebKit.UserScript? allow_remote_images = null;
 
@@ -40,10 +53,13 @@ public class ClientWebView : WebKit.WebView {
      */
     public static void init_web_context(Configuration config,
                                         File web_extension_dir,
+                                        File cache_dir,
                                         bool enable_logging) {
-        WebKit.WebContext context = WebKit.WebContext.get_default();
+        WebsiteDataManager data_manager = new WebsiteDataManager(cache_dir.get_path());
+        WebKit.WebContext context = new WebKit.WebContext.with_website_data_manager(data_manager);
         context.set_process_model(WebKit.ProcessModel.SHARED_SECONDARY_PROCESS);
         context.set_cache_model(WebKit.CacheModel.DOCUMENT_BROWSER);
+
         context.register_uri_scheme("cid", (req) => {
                 ClientWebView? view = req.get_web_view() as ClientWebView;
                 if (view != null) {
@@ -69,6 +85,8 @@ public class ClientWebView : WebKit.WebView {
         config.settings.changed[Configuration.SPELL_CHECK_LANGUAGES].connect(() => {
                 update_spellcheck(context, config);
             });
+
+        ClientWebView.default_context = context;
     }
 
     /**
@@ -227,7 +245,11 @@ public class ClientWebView : WebKit.WebView {
              custom_manager ?? new WebKit.UserContentManager();
         content_manager.add_script(ClientWebView.script);
 
-        Object(user_content_manager: content_manager, settings: setts);
+        Object(
+            web_context: ClientWebView.default_context,
+            user_content_manager: content_manager,
+            settings: setts
+        );
 
         // XXX get the allow prefix from the extension somehow
 
diff --git a/test/client/components/client-web-view-test-case.vala 
b/test/client/components/client-web-view-test-case.vala
index 7324a99..da44e4f 100644
--- a/test/client/components/client-web-view-test-case.vala
+++ b/test/client/components/client-web-view-test-case.vala
@@ -22,6 +22,7 @@ public abstract class ClientWebViewTestCase<V> : Gee.TestCase {
         ClientWebView.init_web_context(
             this.config,
             File.new_for_path(_BUILD_ROOT_DIR).get_child("src"),
+            File.new_for_path("/tmp"), // XXX use something better here
             true
         );
         try {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]