diff --git a/src/client/components/components-web-view.vala b/src/client/components/components-web-view.vala index e11a3f79..ff6b379f 100644 --- a/src/client/components/components-web-view.vala +++ b/src/client/components/components-web-view.vala @@ -11,8 +11,8 @@ * * This provides common functionality expected by the client for * displaying HTML, such as common WebKit settings, desktop font - * integration, Inspector support, and remote and inline image - * handling. + * integration, Inspector support, and remote and inline resource + * handling for content such as images and videos. */ public abstract class Components.WebView : WebKit.WebView, Geary.BaseInterface { @@ -23,7 +23,7 @@ public abstract class Components.WebView : WebKit.WebView, Geary.BaseInterface { /** URI for internal message body page loads. */ public const string INTERNAL_URL_BODY = INTERNAL_URL_PREFIX + "body"; - /** URI Scheme and delimiter for images loaded by Content-ID. */ + /** URI Scheme and delimiter for resources loaded by Content-ID. */ public const string CID_URL_PREFIX = "cid:"; // Keep these in sync with GearyWebExtension @@ -35,7 +35,7 @@ public abstract class Components.WebView : WebKit.WebView, Geary.BaseInterface { private const string CONTENT_LOADED = "content_loaded"; private const string DOCUMENT_MODIFIED = "document_modified"; private const string PREFERRED_HEIGHT_CHANGED = "preferred_height_changed"; - private const string REMOTE_IMAGE_LOAD_BLOCKED = "remote_image_load_blocked"; + private const string REMOTE_RESOURCE_LOAD_BLOCKED = "remote_resource_load_blocked"; private const string SELECTION_CHANGED = "selection_changed"; private const double ZOOM_DEFAULT = 1.0; @@ -251,6 +251,17 @@ public abstract class Components.WebView : WebKit.WebView, Geary.BaseInterface { } } + /** + * Determines if any remote resources are loaded during page load. + * + * This must be set before HTML loaded to have any effect, that + * is, before calling {@link load_html}. Afterwards, you must call + * {@link load_remote_resources} instead. + */ + public bool enable_loading_remote_resources { + get; set; default = false; + } + public string document_font { get { return _document_font; @@ -312,8 +323,8 @@ public abstract class Components.WebView : WebKit.WebView, Geary.BaseInterface { /** Emitted when the view has loaded a resource added to it. */ public signal void internal_resource_loaded(string name); - /** Emitted when a remote image load was disallowed. */ - public signal void remote_image_load_blocked(); + /** Emitted when a remote resource load was disallowed. */ + public signal void remote_resource_load_blocked(); protected WebView(Application.Configuration config, @@ -420,20 +431,16 @@ public abstract class Components.WebView : WebKit.WebView, Geary.BaseInterface { } /** - * Allows loading any remote images found during page load. + * Load any remote resources that were previously blocked. * - * This must be called before HTML content is loaded to have any - * effect. + * This method will ensure any remote resources that were blocked + * during initial HTML page load are now loaded. + * + * @see enable_loading_remote_resources */ - public void allow_remote_image_loading() { - this.run_javascript.begin("_gearyAllowRemoteResourceLoads = true", null); - } - - /** - * Load any remote images previously that were blocked. - */ - public void load_remote_images() { - this.call_void.begin(Util.JS.callable("loadRemoteImages"), null); + public void load_remote_resources() { + this.enable_loading_remote_resources = true; + this.call_void.begin(Util.JS.callable("loadRemoteResources"), null); } /** @@ -599,7 +606,7 @@ public abstract class Components.WebView : WebKit.WebView, Geary.BaseInterface { PREFERRED_HEIGHT_CHANGED, on_preferred_height_changed ); register_message_callback( - REMOTE_IMAGE_LOAD_BLOCKED, on_remote_image_load_blocked + REMOTE_RESOURCE_LOAD_BLOCKED, on_remote_resource_load_blocked ); register_message_callback( SELECTION_CHANGED, on_selection_changed @@ -797,8 +804,8 @@ public abstract class Components.WebView : WebKit.WebView, Geary.BaseInterface { document_modified(); } - private void on_remote_image_load_blocked(GLib.Variant? parameters) { - remote_image_load_blocked(); + private void on_remote_resource_load_blocked(GLib.Variant? parameters) { + remote_resource_load_blocked(); } private void on_content_loaded(GLib.Variant? parameters) { diff --git a/src/client/conversation-viewer/conversation-message.vala b/src/client/conversation-viewer/conversation-message.vala index becf3bf7..27e2bb82 100644 --- a/src/client/conversation-viewer/conversation-message.vala +++ b/src/client/conversation-viewer/conversation-message.vala @@ -596,7 +596,7 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface { this.web_view.notify["has-selection"].connect(on_selection_changed); this.web_view.notify["is-loading"].connect(on_is_loading_notify); this.web_view.resource_load_started.connect(on_resource_load_started); - this.web_view.remote_image_load_blocked.connect(on_remote_images_blocked); + this.web_view.remote_resource_load_blocked.connect(on_remote_resources_blocked); this.web_view.internal_resource_loaded.connect(trigger_internal_resource_loaded); this.web_view.content_loaded.connect(trigger_content_loaded); this.web_view.set_hexpand(true); @@ -877,9 +877,9 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface { this.primary_contact != null && this.primary_contact.load_remote_resources ); - if (this.load_remote_resources || contact_load_images) { - this.web_view.allow_remote_image_loading(); - } + this.web_view.enable_loading_remote_resources = ( + this.load_remote_resources || contact_load_images + ); show_placeholder_pane(null); @@ -1154,7 +1154,7 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface { this.remote_resources_requested = 0; this.remote_resources_loaded = 0; if (this.web_view != null) { - this.web_view.load_remote_images(); + this.web_view.load_remote_resources(); } if (update_email_flag) { flag_remote_images(); @@ -1398,7 +1398,7 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface { selection_changed(this.web_view.has_selection); } - private void on_remote_images_blocked() { + private void on_remote_resources_blocked() { if (this.remote_images_info_bar == null) { this.remote_images_info_bar = new Components.InfoBar( // Translators: Info bar status message diff --git a/src/client/web-process/web-process-extension.vala b/src/client/web-process/web-process-extension.vala index 5a7599e6..33a4fc26 100644 --- a/src/client/web-process/web-process-extension.vala +++ b/src/client/web-process/web-process-extension.vala @@ -72,13 +72,13 @@ public class GearyWebExtension : Object { // Always load internal resources should_load = true; } else { - // Only load anything else if remote image loading is + // Only load anything else if remote resources loading is // permitted - if (should_load_remote_images(page)) { + if (should_load_remote_resources(page)) { should_load = true; } else { page.send_message_to_view.begin( - new WebKit.UserMessage("remote_image_load_blocked", null), + new WebKit.UserMessage("remote_resource_load_blocked", null), null ); } @@ -87,7 +87,7 @@ public class GearyWebExtension : Object { return should_load ? Gdk.EVENT_PROPAGATE : Gdk.EVENT_STOP; // LOL } - private bool should_load_remote_images(WebKit.WebPage page) { + private bool should_load_remote_resources(WebKit.WebPage page) { bool should_load = false; WebKit.Frame frame = page.get_main_frame(); JSC.Context context = frame.get_js_context(); diff --git a/ui/components-web-view.js b/ui/components-web-view.js index 9b026dcd..97fb2d49 100644 --- a/ui/components-web-view.js +++ b/ui/components-web-view.js @@ -72,7 +72,7 @@ PageState.prototype = { this.updatePreferredHeight(); this._contentLoaded(); }, - loadRemoteImages: function() { + loadRemoteResources: function() { window._gearyAllowRemoteResourceLoads = true; let images = document.getElementsByTagName("IMG"); for (let i = 0; i < images.length; i++) {