portalHelper: Simplify our non-use of cache

Instead of using directories that we'll destroy when done, use the new
"ephemeral" data manager feature, through the JavaScript version of:
webkit_web_context_new_ephemeral()

We also throw an error on startup, in the logs, if WebKitGTK is too old.

https://bugzilla.gnome.org/show_bug.cgi?id=780453
This commit is contained in:
Bastien Nocera 2017-03-23 16:54:28 +01:00
parent adbec80596
commit 6557ae0a2b

View File

@ -12,7 +12,6 @@ const WebKit = imports.gi.WebKit2;
const _ = Gettext.gettext; const _ = Gettext.gettext;
const Config = imports.misc.config; const Config = imports.misc.config;
const FileUtils = imports.misc.fileUtils;
const PortalHelperResult = { const PortalHelperResult = {
CANCELLED: 0, CANCELLED: 0,
@ -141,12 +140,8 @@ const PortalWindow = new Lang.Class({
this._doneCallback = doneCallback; this._doneCallback = doneCallback;
this._lastRecheck = 0; this._lastRecheck = 0;
this._recheckAtExit = false; this._recheckAtExit = false;
let cacheDir = GLib.Dir.make_tmp("gnome-shell-portal-helper-XXXXXXXX");
this._cacheDir = Gio.File.new_for_path(cacheDir);
let dataManager = new WebKit.WebsiteDataManager({ base_data_directory: cacheDir, this._webContext = WebKit.WebContext.new_ephemeral();
base_cache_directory: cacheDir });
this._webContext = new WebKit.WebContext({ website_data_manager: dataManager });
this._webContext.set_cache_model(WebKit.CacheModel.DOCUMENT_VIEWER); this._webContext.set_cache_model(WebKit.CacheModel.DOCUMENT_VIEWER);
this._webView = WebKit.WebView.new_with_context(this._webContext); this._webView = WebKit.WebView.new_with_context(this._webContext);
@ -169,7 +164,6 @@ const PortalWindow = new Lang.Class({
destroyWindow: function() { destroyWindow: function() {
this.destroy(); this.destroy();
FileUtils.recursivelyDeleteDir(this._cacheDir, true);
}, },
_syncUri: function() { _syncUri: function() {
@ -363,6 +357,11 @@ function initEnvironment() {
function main(argv) { function main(argv) {
initEnvironment(); initEnvironment();
if (!WebKit.WebContext.new_ephemeral) {
log('WebKitGTK 2.16 is required for the portal-helper, see https://bugzilla.gnome.org/show_bug.cgi?id=780453');
return 1;
}
Gettext.bindtextdomain(Config.GETTEXT_PACKAGE, Config.LOCALEDIR); Gettext.bindtextdomain(Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
Gettext.textdomain(Config.GETTEXT_PACKAGE); Gettext.textdomain(Config.GETTEXT_PACKAGE);