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.
This commit is contained in:
Michael James Gratton 2017-01-27 14:40:55 +11:00
parent 7135f3b2fb
commit 3e203a9c19
3 changed files with 27 additions and 3 deletions

View file

@ -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

View file

@ -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

View file

@ -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 {