[geary/mjog/558-webkit-shared-process-redux: 95/102] Conversation.WebView: Convert to using messages for JS → client comms




commit 7b0146274ccaad18115a66ded6753cb68bd22357
Author: Michael Gratton <mike vee net>
Date:   Fri Aug 28 11:45:35 2020 +1000

    Conversation.WebView: Convert to using messages for JS → client comms

 .../conversation-viewer/conversation-web-view.vala | 71 +++++++++++-----------
 ui/conversation-web-view.js                        |  4 +-
 2 files changed, 38 insertions(+), 37 deletions(-)
---
diff --git a/src/client/conversation-viewer/conversation-web-view.vala 
b/src/client/conversation-viewer/conversation-web-view.vala
index d77af6429..a1ba21a63 100644
--- a/src/client/conversation-viewer/conversation-web-view.vala
+++ b/src/client/conversation-viewer/conversation-web-view.vala
@@ -1,6 +1,6 @@
 /*
- * Copyright 2016 Software Freedom Conservancy Inc.
- * Copyright 2017 Michael Gratton <mike vee net>
+ * Copyright © 2016 Software Freedom Conservancy Inc.
+ * Copyright © 2017-2020 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.
@@ -9,7 +9,7 @@
 public class ConversationWebView : Components.WebView {
 
 
-    private const string DECEPTIVE_LINK_CLICKED = "deceptiveLinkClicked";
+    private const string DECEPTIVE_LINK_CLICKED = "deceptive_link_clicked";
 
     // Key codes we don't forward on to the super class on key press
     // since we want to override them elsewhere, especially
@@ -221,48 +221,47 @@ public class ConversationWebView : Components.WebView {
     }
 
     private void init() {
-        register_message_handler(
+        register_message_callback(
             DECEPTIVE_LINK_CLICKED, on_deceptive_link_clicked
         );
 
         this.notify["preferred-height"].connect(() => queue_resize());
     }
 
-    private void on_deceptive_link_clicked(WebKit.JavascriptResult result) {
-        try {
-            JSC.Value object = result.get_js_value();
-            uint reason = (uint) Util.JS.to_int32(
-                Util.JS.get_property(object, "reason")
-            );
-
-            string href = Util.JS.to_string(
-                Util.JS.get_property(object, "href")
-            );
+    private void on_deceptive_link_clicked(GLib.Variant? parameters) {
+        var dict = new GLib.VariantDict(parameters);
+        uint reason = (uint) dict.lookup_value(
+            "reason", GLib.VariantType.DOUBLE
+        ).get_double();
 
-            string text = Util.JS.to_string(
-                Util.JS.get_property(object, "text")
-            );
-
-            JSC.Value js_location = Util.JS.get_property(object, "location");
+        string href = dict.lookup_value(
+            "href", GLib.VariantType.STRING
+        ).get_string();
 
-            Gdk.Rectangle location = Gdk.Rectangle();
-            location.x = Util.JS.to_int32(
-                Util.JS.get_property(js_location, "x")
-            );
-            location.y = Util.JS.to_int32(
-                Util.JS.get_property(js_location, "y")
-            );
-            location.width = Util.JS.to_int32(
-                Util.JS.get_property(js_location, "width")
-            );
-            location.height = Util.JS.to_int32(
-                Util.JS.get_property(js_location, "height")
-            );
+        string text = dict.lookup_value(
+            "text", GLib.VariantType.STRING
+        ).get_string();
 
-            deceptive_link_clicked((DeceptiveText) reason, text, href, location);
-        } catch (Util.JS.Error err) {
-            debug("Could not get deceptive link param: %s", err.message);
-        }
+        Gdk.Rectangle location = Gdk.Rectangle();
+        var location_dict = new GLib.VariantDict(
+            dict.lookup_value("location", GLib.VariantType.VARDICT)
+        );
+        location.x = (int) location_dict.lookup_value(
+            "x", GLib.VariantType.DOUBLE
+        ).get_double();
+        location.y = (int) location_dict.lookup_value(
+            "y", GLib.VariantType.DOUBLE
+        ).get_double();
+        location.width = (int) location_dict.lookup_value(
+            "width", GLib.VariantType.DOUBLE
+        ).get_double();
+        location.height = (int) location_dict.lookup_value(
+            "height", GLib.VariantType.DOUBLE
+        ).get_double();
+
+        deceptive_link_clicked(
+            (DeceptiveText) reason, text, href, location
+        );
     }
 
 }
diff --git a/ui/conversation-web-view.js b/ui/conversation-web-view.js
index 451db288c..1d730d475 100644
--- a/ui/conversation-web-view.js
+++ b/ui/conversation-web-view.js
@@ -26,6 +26,8 @@ ConversationPageState.prototype = {
     init: function() {
         PageState.prototype.init.apply(this, []);
 
+        this._deceptiveLinkClicked = MessageSender("deceptive_link_clicked");
+
         let state = this;
         document.addEventListener("click", function(e) {
             if (e.target.tagName == "A" &&
@@ -267,7 +269,7 @@ ConversationPageState.prototype = {
             let reason = ConversationPageState.isDeceptiveText(text, href);
             if (reason != ConversationPageState.NOT_DECEPTIVE) {
                 cancelClick = true;
-                window.webkit.messageHandlers.deceptiveLinkClicked.postMessage({
+                this._deceptiveLinkClicked({
                     reason: reason,
                     text: text,
                     href: href,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]