From 506482551dbb3523a31b04db9488d07d5a1ba20f Mon Sep 17 00:00:00 2001 From: Abe Jellinek Date: Thu, 14 Dec 2023 15:01:55 -0500 Subject: [PATCH] Register protocol handler dynamically Fixes reader but not reports yet. --- chrome.manifest | 3 -- .../content/zotero/ZoteroProtocolHandler.jsm | 43 ++++++++++--------- chrome/content/zotero/xpcom/zotero.js | 5 +++ 3 files changed, 27 insertions(+), 24 deletions(-) rename components/zotero-protocol-handler.js => chrome/content/zotero/ZoteroProtocolHandler.jsm (97%) diff --git a/chrome.manifest b/chrome.manifest index 8f3cefea97..bf39691f25 100644 --- a/chrome.manifest +++ b/chrome.manifest @@ -66,9 +66,6 @@ skin zotero default chrome/skin/default/zotero/ component {06a2ed11-d0a4-4ff0-a56f-a44545eee6ea} components/zotero-autocomplete.js contract @mozilla.org/autocomplete/search;1?name=zotero {06a2ed11-d0a4-4ff0-a56f-a44545eee6ea} -component {9BC3D762-9038-486A-9D70-C997AF848A7C} components/zotero-protocol-handler.js process=main -contract @mozilla.org/network/protocol;1?name=zotero {9BC3D762-9038-486A-9D70-C997AF848A7C} process=main - # Scaffold content scaffold chrome/content/scaffold/ locale scaffold en-US chrome/locale/en-US/scaffold/ diff --git a/components/zotero-protocol-handler.js b/chrome/content/zotero/ZoteroProtocolHandler.jsm similarity index 97% rename from components/zotero-protocol-handler.js rename to chrome/content/zotero/ZoteroProtocolHandler.jsm index 98c11ad492..4a32f38ae8 100644 --- a/components/zotero-protocol-handler.js +++ b/chrome/content/zotero/ZoteroProtocolHandler.jsm @@ -27,6 +27,8 @@ ***** END LICENSE BLOCK ***** */ +const EXPORTED_SYMBOLS = ['ZoteroProtocolHandler']; + const ZOTERO_SCHEME = "zotero"; const ZOTERO_PROTOCOL_CID = Components.ID("{9BC3D762-9038-486A-9D70-C997AF848A7C}"); const ZOTERO_PROTOCOL_CONTRACTID = "@mozilla.org/network/protocol;1?name=" + ZOTERO_SCHEME; @@ -44,9 +46,7 @@ const ios = Services.io; // Dummy chrome URL used to obtain a valid chrome channel const DUMMY_CHROME_URL = "chrome://zotero/content/zoteroPane.xul"; -var Zotero = Components.classes["@zotero.org/Zotero;1"] - .getService(Components.interfaces.nsISupports) - .wrappedJSObject; +var { Zotero } = ChromeUtils.importESModule("chrome://zotero/content/zotero.mjs"); function ZoteroProtocolHandler() { this.wrappedJSObject = this; @@ -1261,22 +1261,14 @@ ZoteroProtocolHandler.prototype = { get scheme() { return ZOTERO_SCHEME; }, - get protocolFlags() { - /*Components.interfaces.nsIProtocolHandler.URI_NORELATIVE | - Components.interfaces.nsIProtocolHandler.URI_NOAUTH | - // DEBUG: This should be URI_IS_LOCAL_FILE, and MUST be if any - // extensions that modify data are added - // - https://www.zotero.org/trac/ticket/1156 - // - Components.interfaces.nsIProtocolHandler.URI_IS_LOCAL_FILE, - //Components.interfaces.nsIProtocolHandler.URI_LOADABLE_BY_ANYONE,*/ - - return Ci.nsIProtocolHandler.URI_NORELATIVE + protocolFlags: + Ci.nsIProtocolHandler.URI_NORELATIVE + | Ci.nsIProtocolHandler.URI_NOAUTH + | Ci.nsIProtocolHandler.URI_INHERITS_SECURITY_CONTEXT + | Ci.nsIProtocolHandler.URI_LOADABLE_BY_ANYONE + | Ci.nsIProtocolHandler.URI_NON_PERSISTABLE | Ci.nsIProtocolHandler.URI_IS_LOCAL_RESOURCE - // URI_IS_UI_RESOURCE: more secure than URI_LOADABLE_BY_ANYONE, less secure than URI_DANGEROUS_TO_LOAD - // This is the security level used by the chrome:// protocol - | Ci.nsIProtocolHandler.URI_IS_UI_RESOURCE; - }, + | Ci.nsIProtocolHandler.URI_SYNC_LOAD_IS_OK, get defaultPort() { return -1; }, @@ -1370,6 +1362,18 @@ ZoteroProtocolHandler.prototype = { QueryInterface: ChromeUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIProtocolHandler]), }; +/** + * @static + */ +ZoteroProtocolHandler.init = function () { + Services.io.registerProtocolHandler( + 'zotero', + new ZoteroProtocolHandler(), + ZoteroProtocolHandler.prototype.protocolFlags, + ZoteroProtocolHandler.prototype.defaultPort + ); +}; + /** * nsIChannel implementation that takes a promise-yielding generator that returns a @@ -1569,6 +1573,3 @@ AsyncChannel.prototype = { /*pdf.js wants this || iid.equals(Components.interfaces.nsIWritablePropertyBag)) {*/ }; - - -var NSGetFactory = ComponentUtils.generateNSGetFactory([ZoteroProtocolHandler]); diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index 673b3dde8f..33b665e1bc 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -669,6 +669,11 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js"); throw e; } + const { ZoteroProtocolHandler } = ChromeUtils.import( + `chrome://zotero/content/ZoteroProtocolHandler.jsm` + ); + ZoteroProtocolHandler.init(); + yield Zotero.Users.init(); yield Zotero.Libraries.init();