diff --git a/src/client/components/components-web-view.vala b/src/client/components/components-web-view.vala index c630505e..5a945c52 100644 --- a/src/client/components/components-web-view.vala +++ b/src/client/components/components-web-view.vala @@ -65,7 +65,6 @@ public abstract class Components.WebView : WebKit.WebView, Geary.BaseInterface { private static WebKit.UserStyleSheet? user_stylesheet = null; private static WebKit.UserScript? script = null; - private static WebKit.UserScript? allow_remote_images = null; /** @@ -119,9 +118,6 @@ public abstract class Components.WebView : WebKit.WebView, Geary.BaseInterface { WebView.script = load_app_script( "components-web-view.js" ); - WebView.allow_remote_images = load_app_script( - "components-web-view-allow-remote-images.js" - ); foreach (string name in new string[] { USER_CSS, USER_CSS_LEGACY }) { GLib.File stylesheet = user_dir.get_child(name); @@ -406,13 +402,7 @@ public abstract class Components.WebView : WebKit.WebView, Geary.BaseInterface { * effect. */ public void allow_remote_image_loading() { - // Use a separate script here since we need to update the - // value of window.geary.allow_remote_image_loading after it - // was first created by components-web-view.js (which is loaded at - // the start of page load), but before the page load is - // started (so that any remote images present are actually - // loaded). - this.user_content_manager.add_script(WebView.allow_remote_images); + this.run_javascript.begin("_gearyAllowRemoteResourceLoads = true", null); } /** diff --git a/src/client/web-process/web-process-extension.vala b/src/client/web-process/web-process-extension.vala index b2b29bf9..4bba5154 100644 --- a/src/client/web-process/web-process-extension.vala +++ b/src/client/web-process/web-process-extension.vala @@ -32,22 +32,14 @@ public class GearyWebExtension : Object { private const string[] ALLOWED_SCHEMES = { "cid", "geary", "data", "blob" }; + private const string REMOTE_LOAD_VAR = "_gearyAllowRemoteResourceLoads"; + private WebKit.WebExtension extension; public GearyWebExtension(WebKit.WebExtension extension) { this.extension = extension; - extension.page_created.connect((extension, web_page) => { - web_page.console_message_sent.connect(on_console_message); - web_page.send_request.connect(on_send_request); - // XXX investigate whether the earliest supported - // version of WK supports the DOM "selectionchanged" - // event, and if so use that rather that doing it in - // here in the extension - web_page.get_editor().selection_changed.connect(() => { - selection_changed(web_page); - }); - }); + extension.page_created.connect(on_page_created); } // XXX Conditionally enable while we still depend on WK2 <2.12 @@ -89,14 +81,7 @@ public class GearyWebExtension : Object { WebKit.Frame frame = page.get_main_frame(); JSC.Context context = frame.get_js_context(); try { - JSC.Value ret = execute_script( - context, - "geary.allowRemoteImages", - GLib.Log.FILE, - GLib.Log.METHOD, - GLib.Log.LINE - ); - should_load = Util.JS.to_bool(ret); + should_load = Util.JS.to_bool(context.get_value(REMOTE_LOAD_VAR)); } catch (GLib.Error err) { debug( "Error checking PageState::allowRemoteImages: %s", @@ -154,4 +139,24 @@ public class GearyWebExtension : Object { return ret; } + private void on_page_created(WebKit.WebExtension extension, + WebKit.WebPage page) { + WebKit.Frame frame = page.get_main_frame(); + JSC.Context context = frame.get_js_context(); + context.set_value( + REMOTE_LOAD_VAR, + new JSC.Value.boolean(context, false) + ); + + page.console_message_sent.connect(on_console_message); + page.send_request.connect(on_send_request); + // XXX investigate whether the earliest supported + // version of WK supports the DOM "selectionchanged" + // event, and if so use that rather that doing it in + // here in the extension + page.get_editor().selection_changed.connect(() => { + selection_changed(page); + }); + } + } diff --git a/ui/components-web-view-allow-remote-images.js b/ui/components-web-view-allow-remote-images.js deleted file mode 100644 index 1fb05606..00000000 --- a/ui/components-web-view-allow-remote-images.js +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright 2016 Michael Gratton - * - * This software is licensed under the GNU Lesser General Public License - * (version 2.1 or later). See the COPYING file in this distribution. - */ - -/** - * Enables remote image loading in a client web view. - */ -geary.allowRemoteImages = true; diff --git a/ui/components-web-view.js b/ui/components-web-view.js index 90f4cc14..80e86d7c 100644 --- a/ui/components-web-view.js +++ b/ui/components-web-view.js @@ -14,7 +14,6 @@ let PageState = function() { }; PageState.prototype = { init: function() { - this.allowRemoteImages = false; this.isLoaded = false; this.undoEnabled = false; this.redoEnabled = false; @@ -108,7 +107,7 @@ PageState.prototype = { window.webkit.messageHandlers.contentLoaded.postMessage(null); }, loadRemoteImages: function() { - this.allowRemoteImages = true; + window._gearyAllowRemoteResourceLoads = true; let images = document.getElementsByTagName("IMG"); for (let i = 0; i < images.length; i++) { let img = images.item(i); diff --git a/ui/org.gnome.Geary.gresource.xml b/ui/org.gnome.Geary.gresource.xml index fef3b445..4e78a446 100644 --- a/ui/org.gnome.Geary.gresource.xml +++ b/ui/org.gnome.Geary.gresource.xml @@ -10,7 +10,6 @@ application-main-window.ui certificate_warning_dialog.glade components-web-view.js - components-web-view-allow-remote-images.js components-attachment-pane.ui components-attachment-pane-menus.ui components-attachment-view.ui