Fix remote resource blocking with shared processes
Now that a shared WebKitUserContentManager is shared between web views, the old "load a JS file when remote resource loading is allowed" doesn't work any more. Instead, set a variable on the frame's window object in the web extension notified that a new page has been loaded, and use that instead.
This commit is contained in:
parent
1a391758fa
commit
6c57839ddf
5 changed files with 26 additions and 44 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +0,0 @@
|
|||
/*
|
||||
* Copyright 2016 Michael Gratton <mike@vee.net>
|
||||
*
|
||||
* 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;
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@
|
|||
<file compressed="true" preprocess="xml-stripblanks">application-main-window.ui</file>
|
||||
<file compressed="true" preprocess="xml-stripblanks">certificate_warning_dialog.glade</file>
|
||||
<file compressed="true">components-web-view.js</file>
|
||||
<file compressed="true">components-web-view-allow-remote-images.js</file>
|
||||
<file compressed="true" preprocess="xml-stripblanks">components-attachment-pane.ui</file>
|
||||
<file compressed="true" preprocess="xml-stripblanks">components-attachment-pane-menus.ui</file>
|
||||
<file compressed="true" preprocess="xml-stripblanks">components-attachment-view.ui</file>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue