gjdwebserver-overlay/mail-client/geary/files/0077-Conversation.WebView-Convert-to-using-messages-for-J.patch
Gerben Jan Dijkman 63f719a806 Added files
2021-03-01 15:30:25 +01:00

143 lines
5.4 KiB
Diff

From 7b0146274ccaad18115a66ded6753cb68bd22357 Mon Sep 17 00:00:00 2001
From: Michael Gratton <mike@vee.net>
Date: Fri, 28 Aug 2020 11:45:35 +1000
Subject: [PATCH 077/124] =?UTF-8?q?Conversation.WebView:=20Convert=20to=20?=
=?UTF-8?q?using=20messages=20for=20JS=20=E2=86=92=20client=20comms?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../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 d77af642..a1ba21a6 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 451db288..1d730d47 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,
--
2.29.2