/* ***** BEGIN LICENSE BLOCK ***** Copyright © 2009 Center for History and New Media George Mason University, Fairfax, Virginia, USA http://zotero.org This file is part of Zotero. Zotero is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Zotero is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with Zotero. If not, see . Based on nsChromeExtensionHandler example code by Ed Anuff at http://kb.mozillazine.org/Dev_:_Extending_the_Chrome_Protocol ***** END LICENSE BLOCK ***** */ const Cc = Components.classes; const Ci = Components.interfaces; /** XPCOM files to be loaded for all modes **/ const xpcomFilesAll = [ 'zotero', 'date', 'debug', 'error', 'file', 'http', 'mimeTypeHandler', 'openurl', 'ipc', 'progressWindow', 'translation/translate', 'translation/translate_firefox', 'translation/tlds', 'utilities', 'utilities_internal', 'utilities_translate' ]; /** XPCOM files to be loaded only for local translation and DB access **/ const xpcomFilesLocal = [ 'collectionTreeView', 'annotate', 'attachments', 'cite', 'commons', 'cookieSandbox', 'data_access', 'data/dataObjects', 'data/cachedTypes', 'data/item', 'data/items', 'data/collection', 'data/collections', 'data/creator', 'data/creators', 'data/group', 'data/groups', 'data/itemFields', 'data/notes', 'data/libraries', 'data/relation', 'data/relations', 'data/tag', 'data/tags', 'db', 'duplicates', 'fulltext', 'id', 'integration', 'itemTreeView', 'locateManager', 'mime', 'notifier', 'proxy', 'quickCopy', 'report', 'schema', 'search', 'server', 'style', 'sync', 'storage', 'storage/streamListener', 'storage/eventManager', 'storage/queueManager', 'storage/queue', 'storage/request', 'storage/mode', 'storage/zfs', 'storage/webdav', 'timeline', 'uri', 'translation/translate_item', 'translation/translator', 'server_connector' ]; /** XPCOM files to be loaded only for connector translation and DB access **/ const xpcomFilesConnector = [ 'connector/translate_item', 'connector/translator', 'connector/connector', 'connector/connector_firefox', 'connector/cachedTypes', 'connector/repo', 'connector/typeSchemaData' ]; Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); var instanceID = (new Date()).getTime(); var isFirstLoadThisSession = true; var zContext = null; ZoteroContext = function() {} ZoteroContext.prototype = { /** * Convenience method to replicate window.alert() **/ // TODO: is this still used? if so, move to zotero.js "alert":function alert(msg){ this.Zotero.debug("alert() is deprecated from Zotero XPCOM"); Cc["@mozilla.org/embedcomp/prompt-service;1"] .getService(Ci.nsIPromptService) .alert(null, "", msg); }, /** * Convenience method to replicate window.confirm() **/ // TODO: is this still used? if so, move to zotero.js "confirm":function confirm(msg){ this.Zotero.debug("confirm() is deprecated from Zotero XPCOM"); return Cc["@mozilla.org/embedcomp/prompt-service;1"] .getService(Ci.nsIPromptService) .confirm(null, "", msg); }, "Cc":Cc, "Ci":Ci, /** * Convenience method to replicate window.setTimeout() **/ "setTimeout":function setTimeout(func, ms){ this.Zotero.setTimeout(func, ms); }, /** * Switches in or out of connector mode */ "switchConnectorMode":function(isConnector) { if(isConnector !== this.isConnector) { zContext.Zotero.shutdown(); // create a new zContext makeZoteroContext(isConnector); zContext.Zotero.init(); } return zContext; } }; /** * The class from which the Zotero global XPCOM context is constructed * * @constructor * This runs when ZoteroService is first requested to load all applicable scripts and initialize * Zotero. Calls to other XPCOM components must be in here rather than in top-level code, as other * components may not have yet been initialized. */ function makeZoteroContext(isConnector) { if(zContext) { // Swap out old zContext var oldzContext = zContext; // Create new zContext zContext = new ZoteroContext(); // Swap in old Zotero object, so that references don't break, but empty it zContext.Zotero = oldzContext.Zotero; for(var key in zContext.Zotero) delete zContext.Zotero[key]; } else { zContext = new ZoteroContext(); zContext.Zotero = function() {}; } // Load zotero.js first Cc["@mozilla.org/moz/jssubscript-loader;1"] .getService(Ci.mozIJSSubScriptLoader) .loadSubScript("chrome://zotero/content/xpcom/" + xpcomFilesAll[0] + ".js", zContext); // Load CiteProc into Zotero.CiteProc namespace zContext.Zotero.CiteProc = {"Zotero":zContext.Zotero}; Cc["@mozilla.org/moz/jssubscript-loader;1"] .getService(Ci.mozIJSSubScriptLoader) .loadSubScript("chrome://zotero/content/xpcom/citeproc.js", zContext.Zotero.CiteProc); // Load remaining xpcomFiles for (var i=1; i