Move command line handler to zotero-service.js so that it will have access to zContext even before Zotero is finished initializing. This is necessary for automatic connector switching on Windows.
This commit is contained in:
parent
00fdeb3bf9
commit
c40ba095ea
|
@ -55,14 +55,13 @@ style chrome://browser/content/browser.xul chrome://zotero/skin/zotero.css
|
||||||
style chrome://global/content/customizeToolbar.xul chrome://zotero/skin/zotero.css
|
style chrome://global/content/customizeToolbar.xul chrome://zotero/skin/zotero.css
|
||||||
|
|
||||||
component {e4c61080-ec2d-11da-8ad9-0800200c9a66} components/zotero-service.js
|
component {e4c61080-ec2d-11da-8ad9-0800200c9a66} components/zotero-service.js
|
||||||
|
component {531828f8-a16c-46be-b9aa-14845c3b010f} components/zotero-service.js
|
||||||
contract @zotero.org/Zotero;1 {e4c61080-ec2d-11da-8ad9-0800200c9a66}
|
contract @zotero.org/Zotero;1 {e4c61080-ec2d-11da-8ad9-0800200c9a66}
|
||||||
|
contract @mozilla.org/commandlinehandler/general-startup;1?type=zotero {531828f8-a16c-46be-b9aa-14845c3b010f}
|
||||||
|
category command-line-handler m-zotero @mozilla.org/commandlinehandler/general-startup;1?type=zotero
|
||||||
|
|
||||||
component {06a2ed11-d0a4-4ff0-a56f-a44545eee6ea} components/zotero-autocomplete.js
|
component {06a2ed11-d0a4-4ff0-a56f-a44545eee6ea} components/zotero-autocomplete.js
|
||||||
contract @mozilla.org/autocomplete/search;1?name=zotero {06a2ed11-d0a4-4ff0-a56f-a44545eee6ea}
|
contract @mozilla.org/autocomplete/search;1?name=zotero {06a2ed11-d0a4-4ff0-a56f-a44545eee6ea}
|
||||||
|
|
||||||
component {9BC3D762-9038-486A-9D70-C997AF848A7C} components/zotero-protocol-handler.js
|
component {9BC3D762-9038-486A-9D70-C997AF848A7C} components/zotero-protocol-handler.js
|
||||||
contract @mozilla.org/network/protocol;1?name=zotero {9BC3D762-9038-486A-9D70-C997AF848A7C}
|
contract @mozilla.org/network/protocol;1?name=zotero {9BC3D762-9038-486A-9D70-C997AF848A7C}
|
||||||
|
|
||||||
component {531828f8-a16c-46be-b9aa-14845c3b010f} components/zotero-command-line-handler.js
|
|
||||||
contract @mozilla.org/commandlinehandler/general-startup;1?type=zotero {531828f8-a16c-46be-b9aa-14845c3b010f}
|
|
||||||
category command-line-handler m-zotero @mozilla.org/commandlinehandler/general-startup;1?type=zotero
|
|
|
@ -1,123 +0,0 @@
|
||||||
/*
|
|
||||||
***** 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 <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
|
|
||||||
Based on nsChromeExtensionHandler example code by Ed Anuff at
|
|
||||||
http://kb.mozillazine.org/Dev_:_Extending_the_Chrome_Protocol
|
|
||||||
|
|
||||||
***** END LICENSE BLOCK *****
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
Based on nsICommandLineHandler example code at
|
|
||||||
https://developer.mozilla.org/en/Chrome/Command_Line
|
|
||||||
*/
|
|
||||||
|
|
||||||
const clh_contractID = "@mozilla.org/commandlinehandler/general-startup;1?type=zotero";
|
|
||||||
const clh_CID = Components.ID("{531828f8-a16c-46be-b9aa-14845c3b010f}");
|
|
||||||
const clh_category = "m-zotero";
|
|
||||||
const clh_description = "Zotero Command Line Handler";
|
|
||||||
|
|
||||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The XPCOM component that implements nsICommandLineHandler.
|
|
||||||
*/
|
|
||||||
function ZoteroCommandLineHandler() {}
|
|
||||||
ZoteroCommandLineHandler.prototype = {
|
|
||||||
/* nsISupports */
|
|
||||||
QueryInterface : XPCOMUtils.generateQI([Components.interfaces.nsICommandLineHandler,
|
|
||||||
Components.interfaces.nsIFactory, Components.interfaces.nsISupports]),
|
|
||||||
|
|
||||||
/* nsICommandLineHandler */
|
|
||||||
handle : function(cmdLine) {
|
|
||||||
// handler for Zotero integration commands
|
|
||||||
// this is typically used on Windows only, via WM_COPYDATA rather than the command line
|
|
||||||
var agent = cmdLine.handleFlagWithParam("ZoteroIntegrationAgent", false);
|
|
||||||
if(agent) {
|
|
||||||
// Don't open a new window
|
|
||||||
cmdLine.preventDefault = true;
|
|
||||||
|
|
||||||
var command = cmdLine.handleFlagWithParam("ZoteroIntegrationCommand", false);
|
|
||||||
var docId = cmdLine.handleFlagWithParam("ZoteroIntegrationDocument", false);
|
|
||||||
|
|
||||||
// Not quite sure why this is necessary to get the appropriate scoping
|
|
||||||
var Zotero = this.Zotero;
|
|
||||||
Zotero.setTimeout(function() { Zotero.Integration.execCommand(agent, command, docId) }, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// handler for Windows IPC commands
|
|
||||||
var param = cmdLine.handleFlagWithParam("ZoteroIPC", false);
|
|
||||||
if(param) {
|
|
||||||
// Don't open a new window
|
|
||||||
cmdLine.preventDefault = true;
|
|
||||||
this.Zotero.IPC.parsePipeInput(param);
|
|
||||||
}
|
|
||||||
|
|
||||||
// special handler for "zotero" URIs at the command line to prevent them from opening a new
|
|
||||||
// window
|
|
||||||
if(this.Zotero.isStandalone) {
|
|
||||||
var param = cmdLine.handleFlagWithParam("url", false);
|
|
||||||
if(param) {
|
|
||||||
var uri = cmdLine.resolveURI(param);
|
|
||||||
if(uri.schemeIs("zotero")) {
|
|
||||||
// Check for existing window and focus it
|
|
||||||
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
|
||||||
.getService(Components.interfaces.nsIWindowMediator);
|
|
||||||
var win = wm.getMostRecentWindow("navigator:browser");
|
|
||||||
if(win) {
|
|
||||||
cmdLine.preventDefault = true;
|
|
||||||
win.focus();
|
|
||||||
Components.classes["@mozilla.org/network/protocol;1?name=zotero"]
|
|
||||||
.createInstance(Components.interfaces.nsIProtocolHandler).newChannel(uri);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
classDescription: clh_description,
|
|
||||||
classID: clh_CID,
|
|
||||||
contractID: clh_contractID,
|
|
||||||
service: true,
|
|
||||||
_xpcom_categories: [{category:"command-line-handler", entry:clh_category}],
|
|
||||||
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsICommandLineHandler,
|
|
||||||
Components.interfaces.nsISupports])
|
|
||||||
};
|
|
||||||
|
|
||||||
ZoteroCommandLineHandler.prototype.__defineGetter__("Zotero", function() {
|
|
||||||
if(!this._Zotero) {
|
|
||||||
this._Zotero = Components.classes["@zotero.org/Zotero;1"]
|
|
||||||
.getService(Components.interfaces.nsISupports).wrappedJSObject;
|
|
||||||
}
|
|
||||||
return this._Zotero;
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* XPCOMUtils.generateNSGetFactory was introduced in Mozilla 2 (Firefox 4).
|
|
||||||
* XPCOMUtils.generateNSGetModule is for Mozilla 1.9.2 (Firefox 3.6).
|
|
||||||
*/
|
|
||||||
if (XPCOMUtils.generateNSGetFactory) {
|
|
||||||
var NSGetFactory = XPCOMUtils.generateNSGetFactory([ZoteroCommandLineHandler]);
|
|
||||||
} else {
|
|
||||||
var NSGetModule = XPCOMUtils.generateNSGetModule([ZoteroCommandLineHandler]);
|
|
||||||
}
|
|
|
@ -27,11 +27,6 @@
|
||||||
***** END LICENSE BLOCK *****
|
***** END LICENSE BLOCK *****
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const ZOTERO_CONTRACTID = '@zotero.org/Zotero;1';
|
|
||||||
const ZOTERO_CLASSNAME = 'Zotero';
|
|
||||||
const ZOTERO_CID = Components.ID('{e4c61080-ec2d-11da-8ad9-0800200c9a66}');
|
|
||||||
const ZOTERO_IID = Components.interfaces.chnmIZoteroService; //unused
|
|
||||||
|
|
||||||
const Cc = Components.classes;
|
const Cc = Components.classes;
|
||||||
const Ci = Components.interfaces;
|
const Ci = Components.interfaces;
|
||||||
|
|
||||||
|
@ -266,7 +261,7 @@ function makeZoteroContext(isConnector) {
|
||||||
/**
|
/**
|
||||||
* The class representing the Zotero service, and affiliated XPCOM goop
|
* The class representing the Zotero service, and affiliated XPCOM goop
|
||||||
*/
|
*/
|
||||||
function ZoteroService(){
|
function ZoteroService() {
|
||||||
try {
|
try {
|
||||||
if(isFirstLoadThisSession) {
|
if(isFirstLoadThisSession) {
|
||||||
makeZoteroContext(false);
|
makeZoteroContext(false);
|
||||||
|
@ -295,24 +290,90 @@ function ZoteroService(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// XPCOM goop
|
|
||||||
//
|
|
||||||
|
|
||||||
ZoteroService.prototype = {
|
ZoteroService.prototype = {
|
||||||
contractID: ZOTERO_CONTRACTID,
|
contractID: '@zotero.org/Zotero;1',
|
||||||
classDescription: ZOTERO_CLASSNAME,
|
classDescription: 'Zotero',
|
||||||
classID: ZOTERO_CID,
|
classID: Components.ID('{e4c61080-ec2d-11da-8ad9-0800200c9a66}'),
|
||||||
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsISupports,
|
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsISupports,
|
||||||
Components.interfaces.nsIProtocolHandler])
|
Components.interfaces.nsIProtocolHandler])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The class representing the Zotero command line handler
|
||||||
|
*/
|
||||||
|
function ZoteroCommandLineHandler() {}
|
||||||
|
ZoteroCommandLineHandler.prototype = {
|
||||||
|
/* nsISupports */
|
||||||
|
QueryInterface : XPCOMUtils.generateQI([Components.interfaces.nsICommandLineHandler,
|
||||||
|
Components.interfaces.nsIFactory, Components.interfaces.nsISupports]),
|
||||||
|
|
||||||
|
/* nsICommandLineHandler */
|
||||||
|
handle : function(cmdLine) {
|
||||||
|
// handler for Zotero integration commands
|
||||||
|
// this is typically used on Windows only, via WM_COPYDATA rather than the command line
|
||||||
|
var agent = cmdLine.handleFlagWithParam("ZoteroIntegrationAgent", false);
|
||||||
|
if(agent) {
|
||||||
|
// Don't open a new window
|
||||||
|
cmdLine.preventDefault = true;
|
||||||
|
|
||||||
|
var command = cmdLine.handleFlagWithParam("ZoteroIntegrationCommand", false);
|
||||||
|
var docId = cmdLine.handleFlagWithParam("ZoteroIntegrationDocument", false);
|
||||||
|
|
||||||
|
// Not quite sure why this is necessary to get the appropriate scoping
|
||||||
|
var Zotero = this.Zotero;
|
||||||
|
Zotero.setTimeout(function() { Zotero.Integration.execCommand(agent, command, docId) }, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// handler for Windows IPC commands
|
||||||
|
var param = cmdLine.handleFlagWithParam("ZoteroIPC", false);
|
||||||
|
if(param) {
|
||||||
|
// Don't open a new window
|
||||||
|
cmdLine.preventDefault = true;
|
||||||
|
this.Zotero.IPC.parsePipeInput(param);
|
||||||
|
}
|
||||||
|
|
||||||
|
// special handler for "zotero" URIs at the command line to prevent them from opening a new
|
||||||
|
// window
|
||||||
|
if(this.Zotero.isStandalone) {
|
||||||
|
var param = cmdLine.handleFlagWithParam("url", false);
|
||||||
|
if(param) {
|
||||||
|
var uri = cmdLine.resolveURI(param);
|
||||||
|
if(uri.schemeIs("zotero")) {
|
||||||
|
// Check for existing window and focus it
|
||||||
|
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
||||||
|
.getService(Components.interfaces.nsIWindowMediator);
|
||||||
|
var win = wm.getMostRecentWindow("navigator:browser");
|
||||||
|
if(win) {
|
||||||
|
cmdLine.preventDefault = true;
|
||||||
|
win.focus();
|
||||||
|
Components.classes["@mozilla.org/network/protocol;1?name=zotero"]
|
||||||
|
.createInstance(Components.interfaces.nsIProtocolHandler).newChannel(uri);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
contractID: "@mozilla.org/commandlinehandler/general-startup;1?type=zotero",
|
||||||
|
classDescription: "Zotero Command Line Handler",
|
||||||
|
classID: Components.ID("{531828f8-a16c-46be-b9aa-14845c3b010f}"),
|
||||||
|
service: true,
|
||||||
|
_xpcom_categories: [{category:"command-line-handler", entry:"m-zotero"}],
|
||||||
|
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsICommandLineHandler,
|
||||||
|
Components.interfaces.nsISupports])
|
||||||
|
};
|
||||||
|
|
||||||
|
ZoteroCommandLineHandler.prototype.__defineGetter__("Zotero", function() {
|
||||||
|
if(!zContext) new ZoteroService();
|
||||||
|
return zContext.Zotero;
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XPCOMUtils.generateNSGetFactory was introduced in Mozilla 2 (Firefox 4).
|
* XPCOMUtils.generateNSGetFactory was introduced in Mozilla 2 (Firefox 4).
|
||||||
* XPCOMUtils.generateNSGetModule is for Mozilla 1.9.2 (Firefox 3.6).
|
* XPCOMUtils.generateNSGetModule is for Mozilla 1.9.2 (Firefox 3.6).
|
||||||
*/
|
*/
|
||||||
if (XPCOMUtils.generateNSGetFactory) {
|
if (XPCOMUtils.generateNSGetFactory) {
|
||||||
var NSGetFactory = XPCOMUtils.generateNSGetFactory([ZoteroService]);
|
var NSGetFactory = XPCOMUtils.generateNSGetFactory([ZoteroService, ZoteroCommandLineHandler]);
|
||||||
} else {
|
} else {
|
||||||
var NSGetModule = XPCOMUtils.generateNSGetModule([ZoteroService]);
|
var NSGetModule = XPCOMUtils.generateNSGetModule([ZoteroService, ZoteroCommandLineHandler]);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user