[geary/mcatanzaro/#1168] web-process-extension: register GearyWebExtension JS in the right place
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/mcatanzaro/#1168] web-process-extension: register GearyWebExtension JS in the right place
- Date: Thu, 4 Mar 2021 23:32:01 +0000 (UTC)
commit 6a0ad7218249e8f5b6ab13840ea973a8270bd4fb
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Thu Mar 4 17:25:41 2021 -0600
web-process-extension: register GearyWebExtension JS in the right place
We need to register our JS when the window-object-cleared signal is
emitted. Previously we did this when the WebPage object is created, but
this only worked due to luck. Since WebKit r271642, it no longer works.
window-object-cleared is emitted right after page-created, meaning that
right after Geary registers its JS, it all gets wiped away. Oops.
Fixes #1168
src/client/web-process/web-process-extension.vala | 57 ++++++++++++-----------
1 file changed, 31 insertions(+), 26 deletions(-)
---
diff --git a/src/client/web-process/web-process-extension.vala
b/src/client/web-process/web-process-extension.vala
index 6785903e0..5a7599e68 100644
--- a/src/client/web-process/web-process-extension.vala
+++ b/src/client/web-process/web-process-extension.vala
@@ -48,6 +48,7 @@ public class GearyWebExtension : Object {
public GearyWebExtension(WebKit.WebExtension extension) {
this.extension = extension;
extension.page_created.connect(on_page_created);
+ WebKit.ScriptWorld.get_default().window_object_cleared.connect(on_window_object_cleared);
}
private void on_console_message(WebKit.WebPage page,
@@ -134,32 +135,6 @@ public class GearyWebExtension : Object {
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();
-
- var extension_class = context.register_class(
- this.get_type().name(),
- null,
- null,
- null
- );
- extension_class.add_method(
- EXTENSION_CLASS_SEND,
- (instance, values) => {
- return this.on_page_send_message(page, values);
- },
- GLib.Type.NONE
- );
- context.set_value(
- EXTENSION_CLASS_VAR,
- new JSC.Value.object(context, extension_class, extension_class)
- );
-
- 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);
page.user_message_received.connect(on_page_message_received);
@@ -269,4 +244,34 @@ public class GearyWebExtension : Object {
return true;
}
+ private void on_window_object_cleared(WebKit.ScriptWorld world,
+ WebKit.WebPage page,
+ WebKit.Frame frame)
+ {
+ JSC.Context context = frame.get_js_context();
+
+ var extension_class = context.register_class(
+ this.get_type().name(),
+ null,
+ null,
+ null
+ );
+ extension_class.add_method(
+ EXTENSION_CLASS_SEND,
+ (instance, values) => {
+ return this.on_page_send_message(page, values);
+ },
+ GLib.Type.NONE
+ );
+ context.set_value(
+ EXTENSION_CLASS_VAR,
+ new JSC.Value.object(context, extension_class, extension_class)
+ );
+
+ context.set_value(
+ REMOTE_LOAD_VAR,
+ new JSC.Value.boolean(context, false)
+ );
+ }
+
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]