diff --git a/chrome/content/zotero/actors/ActorManager.jsm b/chrome/content/zotero/actors/ActorManager.jsm index 4cbba710d0..5f0d5cec13 100644 --- a/chrome/content/zotero/actors/ActorManager.jsm +++ b/chrome/content/zotero/actors/ActorManager.jsm @@ -29,7 +29,6 @@ ChromeUtils.registerWindowActor("FeedAbstract", { moduleURI: "chrome://zotero/content/actors/FeedAbstractChild.jsm", events: { DOMDocElementInserted: {}, - click: {}, } }, messageManagerGroups: ["feedAbstract"] @@ -47,3 +46,16 @@ ChromeUtils.registerWindowActor("ZoteroPrint", { } }); +ChromeUtils.registerWindowActor("ExternalLinkHandler", { + parent: { + moduleURI: "chrome://zotero/content/actors/ExternalLinkHandlerParent.jsm", + }, + child: { + moduleURI: "chrome://zotero/content/actors/ExternalLinkHandlerChild.jsm", + events: { + click: {}, + } + }, + messageManagerGroups: ["feedAbstract", "basicViewer"] +}); + diff --git a/chrome/content/zotero/actors/ExternalLinkHandlerChild.jsm b/chrome/content/zotero/actors/ExternalLinkHandlerChild.jsm new file mode 100644 index 0000000000..711abc07ed --- /dev/null +++ b/chrome/content/zotero/actors/ExternalLinkHandlerChild.jsm @@ -0,0 +1,26 @@ +var EXPORTED_SYMBOLS = ["ExternalLinkHandlerChild"]; + + +class ExternalLinkHandlerChild extends JSWindowActorChild { + async handleEvent(event) { + switch (event.type) { + case "click": { + let { button, target } = event; + if (button !== 0) { + break; + } + if ((target.localName === 'a' || target.localName === 'area') && target.href + || target.localName === 'label' && target.classList.contains('text-link')) { + event.stopPropagation(); + event.preventDefault(); + await this._sendLaunchURL(target.href || target.getAttribute('href')); + } + break; + } + } + } + + async _sendLaunchURL(url) { + await this.sendAsyncMessage("launchURL", url); + } +} diff --git a/chrome/content/zotero/actors/ExternalLinkHandlerParent.jsm b/chrome/content/zotero/actors/ExternalLinkHandlerParent.jsm new file mode 100644 index 0000000000..9c94642dac --- /dev/null +++ b/chrome/content/zotero/actors/ExternalLinkHandlerParent.jsm @@ -0,0 +1,16 @@ +var EXPORTED_SYMBOLS = ["ExternalLinkHandlerParent"]; + +ChromeUtils.defineESModuleGetters(this, { + Zotero: "chrome://zotero/content/zotero.mjs" +}); + +class ExternalLinkHandlerParent extends JSWindowActorParent { + async receiveMessage({ name, data }) { + switch (name) { + case "launchURL": { + Zotero.launchURL(data); + return; + } + } + } +} diff --git a/chrome/content/zotero/standalone/basicViewer.js b/chrome/content/zotero/standalone/basicViewer.js index ef5b742069..992f8686d4 100644 --- a/chrome/content/zotero/standalone/basicViewer.js +++ b/chrome/content/zotero/standalone/basicViewer.js @@ -68,14 +68,6 @@ window.addEventListener("keypress", function (event) { } }); -// Handle