summaryrefslogtreecommitdiffstats
path: root/comm/mail/actors/MailLinkChild.jsm
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /comm/mail/actors/MailLinkChild.jsm
parentInitial commit. (diff)
downloadthunderbird-upstream.tar.xz
thunderbird-upstream.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'comm/mail/actors/MailLinkChild.jsm')
-rw-r--r--comm/mail/actors/MailLinkChild.jsm42
1 files changed, 42 insertions, 0 deletions
diff --git a/comm/mail/actors/MailLinkChild.jsm b/comm/mail/actors/MailLinkChild.jsm
new file mode 100644
index 0000000000..401b869fad
--- /dev/null
+++ b/comm/mail/actors/MailLinkChild.jsm
@@ -0,0 +1,42 @@
+/* vim: set ts=2 sw=2 et tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, you can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const EXPORTED_SYMBOLS = ["MailLinkChild"];
+
+const PROTOCOLS = ["mailto:", "mid:", "news:", "snews:"];
+
+class MailLinkChild extends JSWindowActorChild {
+ handleEvent(event) {
+ let href = event.target.href;
+ let location = this.document.location;
+ if (
+ !href ||
+ // Do nothing if not the main button clicked.
+ event.button > 0 ||
+ // Do nothing if in the compose window.
+ location.href == "about:blank?compose"
+ ) {
+ return;
+ }
+
+ let url = new URL(href);
+ let protocol = url.protocol;
+ if (
+ PROTOCOLS.includes(protocol) ||
+ // A link to an attachment, e.g. cid: link.
+ (["imap:", "mailbox:"].includes(protocol) &&
+ url.searchParams.get("part") &&
+ // Prevent opening new tab for internal pdf link.
+ (!location.search.includes("part=") ||
+ url.origin != location.origin ||
+ url.pathname != location.pathname))
+ ) {
+ this.sendAsyncMessage(protocol, href);
+ event.preventDefault();
+ }
+ }
+}