commit 6c5e155ba710bbafd2d4554aa742ca6e7151f2da
parent 3a4401a99561b2e9310c3d777e59b462612aaaff
Author: Dan Stillman <dstillman@zotero.org>
Date: Thu, 9 Feb 2012 02:18:15 -0500
Merge branch '3.0'
Diffstat:
3 files changed, 95 insertions(+), 0 deletions(-)
diff --git a/chrome/content/zotero/xpcom/standalone.js b/chrome/content/zotero/xpcom/standalone.js
@@ -0,0 +1,87 @@
+/*
+ ***** BEGIN LICENSE BLOCK *****
+
+ Copyright © 2012 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/>.
+
+ ***** END LICENSE BLOCK *****
+*/
+
+Zotero.Standalone = new function() {
+ /**
+ * Stream listener proxy for AMO requests to replace Firefox's app ID with toolkit@mozilla.org.
+ * This means add-ons hosted at AMO will update properly for us.
+ */
+ var AMOStreamListener = function() {};
+ AMOStreamListener.prototype = {
+ "QueryInterface": function(arg) {
+ if (!iid.equals(Components.interfaces.nsIStreamListener)
+ && !iid.equals(Components.interfaces.nsIRequestObserver)
+ && !iid.equals(Components.interfaces.nsISupports)) {
+ throw Components.results.NS_ERROR_NO_INTERFACE;
+ }
+ return this;
+ },
+
+ "onStartRequest": function(aRequest, aContext) {
+ this._stream = Cc["@mozilla.org/binaryinputstream;1"].
+ createInstance(Ci.nsIBinaryInputStream);
+ this._bytes = "";
+ this.oldListener.onStartRequest(aRequest, aContext);
+ },
+
+ "onStopRequest": function(aRequest, aContext, aStatusCode) {
+ var requestFailed = !Components.isSuccessCode(aStatusCode);
+ if(!requestFailed && (aRequest instanceof Ci.nsIHttpChannel))
+ requestFailed = !aRequest.requestSucceeded;
+
+ if(!requestFailed) {
+ var data = this._bytes.replace("{ec8030f7-c20a-464f-9b0e-13a3a9e97384}",
+ "toolkit@mozilla.org", "g")
+ var nBytes = data.length;
+ var inputStream = Cc["@mozilla.org/io/string-input-stream;1"].
+ createInstance(Ci.nsIStringInputStream);
+ inputStream.setData(data, nBytes);
+ this.oldListener.onDataAvailable(aRequest, aContext, inputStream, 0, nBytes);
+ }
+ this.oldListener.onStopRequest(aRequest, aContext, aStatusCode);
+ },
+
+ "onDataAvailable": function(aRequest, aContext, aInputStream, aOffset, aCount) {
+ this._stream.setInputStream(aInputStream);
+ this._bytes += this._stream.readBytes(aCount);
+ }
+ };
+
+ this.init = function() {
+ // Add an observer to handle AMO requests
+ Components.classes["@mozilla.org/observer-service;1"].
+ getService(Components.interfaces.nsIObserverService).
+ addObserver({
+ "observe":function(ch) {
+ if(ch.QueryInterface(Components.interfaces.nsIRequest).URI.host
+ !== "versioncheck.addons.mozilla.org") return;
+ var newListener = new AMOStreamListener;
+ newListener.oldListener = ch.
+ QueryInterface(Components.interfaces.nsITraceableChannel).
+ setNewListener(newListener);
+ }
+ }, "http-on-examine-response", false);
+ }
+}
diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js
@@ -443,6 +443,7 @@ const ZOTERO_CONFIG = {
} else {
Zotero.debug("Loading in full mode");
if(!_initFull()) return false;
+ if(Zotero.isStandalone) Zotero.Standalone.init();
Zotero.initComplete();
}
diff --git a/components/zotero-service.js b/components/zotero-service.js
@@ -255,6 +255,13 @@ function makeZoteroContext(isConnector) {
.loadSubScript("chrome://zotero/content/xpcom/" + rdfXpcomFiles[i] + ".js", zContext.Zotero.RDF.AJAW);
}
+ if(isStandalone()) {
+ // If isStandalone, load standalone.js
+ Cc["@mozilla.org/moz/jssubscript-loader;1"]
+ .getService(Ci.mozIJSSubScriptLoader)
+ .loadSubScript("chrome://zotero/content/xpcom/standalone.js", zContext);
+ }
+
// load nsTransferable (query: do we still use this?)
Cc["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Ci.mozIJSSubScriptLoader)