Commit 86634357 authored by Erik Hetzner's avatar Erik Hetzner

remove old extension

parent bc085ebf
#!/bin/bash
find . -name '.hg' -prune -o \
-name '.hgignore' -prune -o \
-name 'build.sh' -prune -o \
-name '*~' -prune -o \
-print | xargs zip zotero-for-restructured-text.xpi
resource citeproc resource/citeproc/
resource jsbridge resource/
component {2872d428-14f6-11de-ac86-001f5bd9235c} components/jsbridge.js
contract @mozilla.org/jsbridge;1 {2872d428-14f6-11de-ac86-001f5bd9235c}
category profile-after-change JSBridge @mozilla.org/jsbridge;1
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
// Import global modules
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
// Include local modules
Cu.import("resource://jsbridge/modules/Log.jsm");
// Constants for preferences names
const PREF_JSBRIDGE_PORT = "extensions.jsbridge.port";
/**
* XPCOM component to observe different application states and to
* handle the JSBridge server.
*/
function JSBridge() {
this._server = null;
}
JSBridge.prototype = {
classDescription: "JSBridge",
classID: Components.ID("{2872d428-14f6-11de-ac86-001f5bd9235c}"),
contractID: "@mozilla.org/jsbridge;1",
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
_xpcom_categories: [{category: "profile-after-change"}],
/**
* Handler for registered observer notifications.
*
* @param {String} aSubject
* Subject of the observer message (not used)
* @param {String} aTopic
* Topic of the observer message
* @param {Object} aData
* Data of the observer message (not used)
*/
observe: function JSB_observe(aSubject, aTopic, aData) {
Log.dump("Observer topic", aTopic);
switch (aTopic) {
// The server cannot be started before the ui is shown. That means
// we also have to register for the final-ui-startup notification.
case "profile-after-change":
Services.obs.addObserver(this, "quit-application", false);
// The port the server has to be started on is set via a preference
let port = Services.prefs.getIntPref(PREF_JSBRIDGE_PORT);
// Start the server
Cu.import('resource://jsbridge/modules/Server.jsm');
this._server = new Server.Server(port);
this._server.start();
break;
case "quit-application":
Services.obs.removeObserver(this, "quit-application", false);
// Stop the server
this._server.stop();
this._server = null;
break;
}
}
}
const NSGetFactory = XPCOMUtils.generateNSGetFactory([JSBridge]);
<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:id>zotero-for-restructured-text@mystery-lab.com</em:id>
<em:name>Zotero for reStructured Text</em:name>
<em:version>1.1</em:version>
<em:creator>Frank Bennett</em:creator>
<em:description>Wrapper methods to interact with a running Zotero from inside a ReST processor</em:description>
<em:unpack>true</em:unpack>
<em:targetApplication>
<!-- Firefox -->
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>3.5</em:minVersion>
<em:maxVersion>25.*</em:maxVersion>
</Description>
</em:targetApplication>
<em:targetApplication>
<Description>
<em:id>zotero@chnm.gmu.edu</em:id>
<em:minVersion>3.0</em:minVersion>
<em:maxVersion>3.*</em:maxVersion>
</Description>
</em:targetApplication>
</Description>
</RDF>
var EXPORTED_SYMBOLS = ["instantiateCiteProc", "getItemIdBatch", "updateItems", "appendCitationClusterBatch", "makeBibliography", "registerLocalItems"];
var zotero = Components.classes["@zotero.org/Zotero;1"].getService().wrappedJSObject;
/**
* Proxy sys item for passing in to citeproc. Wraps the
* zotero.Cite.System object, but allows for locally registered items.
*/
var mySys = {
retrieveLocale : function (lang) {
return zotero.Cite.System.retrieveLocale(lang);
},
retrieveItem : function(id) {
if (zotero.localItems[id] != undefined) {
return zotero.localItems[id];
} else {
return zotero.Cite.System.retrieveItem(id);
}
}
};
/**
* Escape strings in a javascript object for safe pass-through (7 bit
* only).
*/
function escapeStringValues (o) {
if (Object.prototype.toString.call(o) === '[object Array]') {
return o.map(function (x) { return escapeStringValues(x); });
} else if (typeof o === "string") {
return escape(o);
} else if (typeof o === "object") {
var retval = new Object();
for (var k in o) {
retval[k] = escapeStringValues(o[k]);
}
return retval;
} else {
return o;
}
};
/**
* Encode a string for passing back to Python.
*/
function encode(what) {
return JSON.stringify(escapeStringValues(what));
}
/**
* Return an array of item IDs for an array of keys.
*/
function getItemIdRawBatch (keys) {
return encode(keys.map(getItemIdRaw));
}
/**
* Get the item ID for a particular key.
*/
function getItemIdRaw (keyStr) {
var libraryId = null;
var key = null;
if (!keyStr.match(/^[0-9]+_/)) {
keyStr = "0_" + keyStr;
}
var md = keyStr.match(/^0_(.*)$/);
if (md) {
/* avoid looking things up, local library */
key = md[1];
} else {
var lkh = zotero.Items.parseLibraryKeyHash(keyStr);
libraryId = lkh.libraryId;
key = lkh.key;
}
var item = zotero.Items.getByLibraryAndKey(libraryId, key);
return item.id;
};
/**
* Get a new citeproc object.
*/
function instantiateCiteProc (styleid) {
if (!styleid.match(/^http:/)) {
styleid = 'http://www.zotero.org/styles/' + styleid;
}
var style = zotero.Styles.get(styleid);
/* TODO Allow passing in locale? **/
var locale = zotero.Prefs.get('export.bibliographyLocale');
if(!locale) {
locale = zotero.locale;
if(!locale) {
locale = 'en-US';
}
}
try {
zotero.reStructuredCSL = new zotero.CiteProc.CSL.Engine(mySys, style.getXML(), locale);
} catch(e) {
zotero.logError(e);
throw e;
}
zotero.localItems = {};
zotero.reStructuredCSL.setOutputFormat("html");
};
/**
* Wrapper for citeproc updateItems.
*/
function updateItems (ids) {
zotero.reStructuredCSL.updateItems(ids);
};
/**
* Batch appendCitationCluster.
*/
function appendCitationClusterBatch (citations) {
return encode(citations.map(appendCitationCluster));
}
/**
* Wrapper for appendCitationCluster.
*/
function appendCitationCluster (citation) {
var results;
results = zotero.reStructuredCSL.appendCitationCluster(citation, true);
var index = citation['properties']['index'];
for (var i = 0 ; i <= results.length ; i++) {
if (results[i][0] == index) {
return "" + results[i][1];
}
}
return null;
};
/**
* Wrapper for citeproc makeBibliography.
*/
function makeBibliography (arg) {
var bib = zotero.reStructuredCSL.makeBibliography(arg);
if (bib) {
return encode(bib);
} else {
return "";
}
};
/**
* Register local items. Should be an object.
*/
function registerLocalItems(items) {
for (var id in items) {
var item = items[id];
zotero.localItems[item['id']] = item;
}
};
/**
* Return true if this is an "in text" style, false if it is a
* footnote style.
*/
function isInTextStyle() {
return ('in-text' === zotero.reStructuredCSL.opt.xclass);
};
function getItemIdDynamicBatch(data) {
return encode(data.map(getItemIdDynamic));
}
function getItemIdDynamic(data) {
var creator = data[0];
var title = data[1];
var date = data[2];
var s = new zotero.Search();
s.addCondition("creator", "contains", creator);
if (title != null) {
s.addCondition("title", "contains", title);
}
if (date != null) {
s.addCondition("date", "is", date);
}
var i = s.search();
if (!i) {
return -1 ;
} else {
if (i.length == 0) {
return -1;
} else if (i.length > 1) {
return -2;
} else {
return i[0];
}
}
}
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
var EXPORTED_SYMBOLS = ["Bridge"];
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
// Include local modules
Cu.import("resource://jsbridge/modules/Events.jsm");
Cu.import("resource://jsbridge/modules/Log.jsm");
var globalRegistry = {};
var uuidgen = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator);
function Bridge(session) {
this.session = session;
this.registry = globalRegistry;
}
Bridge.prototype._register = function (_type) {
this.bridgeType = _type;
if (_type === "backchannel")
Events.addBackChannel(this);
};
Bridge.prototype.register = function (uuid, _type) {
Log.dump("Register", uuid + " (" + _type + ")");
try {
this._register(_type);
var passed = true;
} catch (e) {
if (typeof(e) == "string")
var exception = e;
else
var exception = {'name': e.name,
'message': e.message};
this.session.encodeOut({'result': false,
'exception': exception,
'uuid': uuid});
}
if (passed != undefined) {
this.session.encodeOut({'result': true,
'eventType': 'register',
'uuid': uuid});
}
};
Bridge.prototype._describe = function (obj) {
var response = {};
var type = (obj === null) ? "null"
: typeof(obj);
if (type == "object") {
if (obj.length != undefined)
var type = "array";
response.attributes = [];
for (var i in obj) {
response.attributes = response.attributes.concat(i);
}
} else if (type != "function") {
response.data = obj;
}
response.type = type;
return response;
};
Bridge.prototype.describe = function (uuid, obj) {
Log.dump("Describe", uuid + ", " + obj);
var response = this._describe(obj);
response.uuid = uuid;
response.result = true;
this.session.encodeOut(response);
};
Bridge.prototype._set = function (obj) {
var uuid = uuidgen.generateUUID().toString();
this.registry[uuid] = obj;
return uuid;
};
Bridge.prototype.set = function (uuid, obj) {
Log.dump("Set", uuid);
var ruuid = this._set(obj);
this.session.encodeOut({'result': true,
'data': 'bridge.registry["' + ruuid + '"]',
'uuid': uuid});
};
Bridge.prototype._setAttribute = function (obj, name, value) {
obj[name] = value;
return value;
};
Bridge.prototype.setAttribute = function (uuid, obj, name, value) {
Log.dump("Set attribute", uuid + " (" + name + "=" + value + ")");
try {
var result = this._setAttribute(obj, name, value);
} catch (e) {
if (typeof(e) == "string") {
var exception = e;
} else {
var exception = {'name': e.name,
'message': e.message};
}
this.session.encodeOut({'result': false,
'exception': exception,
'uuid':uuid});
}
if (result != undefined) {
this.set(uuid, obj[name]);
}
};
Bridge.prototype._execFunction = function (func, args) {
return func.apply(this.session.sandbox, args);
};
Bridge.prototype.execFunction = function (uuid, func, args) {
Log.dump("Exec function", uuid + " (" + func.name + ")");
try {
var data = this._execFunction(func, args);
var result = true;
} catch (e) {
if (typeof(e) == "string")
var exception = e;
else
var exception = {'name': e.name,
'message': e.message};
this.session.encodeOut({'result': false,
'exception': exception,
'uuid':uuid});
var result = true;
}
if (data != undefined)
this.set(uuid, data);
else if (result == true)
this.session.encodeOut({'result': true,
'data': null,
'uuid':uuid});
else
throw 'jsbridge could not execute function ' + func;
};
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
var EXPORTED_SYMBOLS = ["Events"];
const Cu = Components.utils;
// Include local modules
Cu.import("resource://jsbridge/modules/Log.jsm");
var Events = {
backChannels: [],
addBackChannel: function (aBackChannel) {
Log.dump("Add backchannel", JSON.stringify(aBackChannel));
this.backChannels.push(aBackChannel);
},
fireEvent: function (aName, aObj) {
Log.dump("Fire event", aName);
if (this.backChannels.length == 0) {
throw new Error("No backchannels registered yet to send messages.");
}
this.backChannels.forEach(function (aBackChannel) {
aBackChannel.session.encodeOut({
'eventType': aName,
'result': aObj}
);
});
}
};
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
var EXPORTED_SYMBOLS = ["Log"];
const Cu = Components.utils;
// Import global modules
Cu.import("resource://gre/modules/Services.jsm");
// Constants for preferences names
const PREF_JSBRIDGE_LOG = "extensions.jsbridge.log";
const LOGGING = Services.prefs.prefHasUserValue(PREF_JSBRIDGE_LOG) &&
Services.prefs.getBoolPref(PREF_JSBRIDGE_LOG);
var Log = {
/**
* Dump log message to stdout.
*
* @param {String} aTopic
* Topic of the message to be logged
* @param {String} aMessage
* Message to be logged
*/
dump: function (aTopic, aMessage) {
if (LOGGING) {
dump("* " + aTopic + ": '" + aMessage + "'\n");
}
}
}
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var EXPORTED_SYMBOLS = ["NSPR"];
const Ci = Components.interfaces;
const Cu = Components.utils;
// Import global JS modules
Cu.import("resource://gre/modules/ctypes.jsm");
Cu.import("resource://gre/modules/Services.jsm");
/**
* Object to access the nspr4 library via ctypes
*/
var NSPR = {
init: function () {
let file = Services.dirsvc.get("GreD", Ci.nsILocalFile);
file.append(ctypes.libraryName("nspr4"));
// Open the NSSPR library
NSPR._library = ctypes.open(file.path);
}
}
NSPR.init();
NSPR.Types = {
PRFileDesc: ctypes.StructType("PRFileDesc"),
PRNetAddr: ctypes.StructType("PRNetAddr", [
{'family': ctypes.uint16_t},
{'port': ctypes.uint16_t},
{'ip': ctypes.uint32_t},
{'pad' : ctypes.char.array(8)}
]),
PRSocketOptionData: ctypes.StructType("PRSocketOptionData", [
{'option' : ctypes.int32_t},
{'non_blocking': ctypes.int32_t}
])
}
NSPR.Sockets = {
PR_TRUE: 1,
PR_AF_INET: 2,
PR_IpAddrAny: 1,
PR_IpAddrLoopback: 2,
PR_SockOpt_Nonblocking: 0,
PR_SockOpt_Reuseaddr: 2,
PR_SockOpt_NoDelay: 13,
PR_INTERVAL_NO_WAIT: 0,
PR_INTERVAL_MAX: 100000,
buffer: ctypes.ArrayType(ctypes.char),
PR_SetNetAddr: NSPR._library.declare("PR_SetNetAddr",
ctypes.default_abi,
ctypes.int32_t, // really doesn't return anything
ctypes.int32_t, // val
ctypes.uint16_t, // af
ctypes.uint16_t, // port
NSPR.Types.PRNetAddr.ptr),
PR_OpenTCPSocket: NSPR._library.declare("PR_OpenTCPSocket",
ctypes.default_abi, // cdecl calling convention
NSPR.Types.PRFileDesc.ptr, // return (PRFileDesc*)
ctypes.int32_t), // first arg
PR_SetSocketOption: NSPR._library.declare("PR_SetSocketOption",
ctypes.default_abi,
ctypes.int32_t,
NSPR.Types.PRFileDesc.ptr,
NSPR.Types.PRSocketOptionData.ptr),
PR_Bind: NSPR._library.declare("PR_Bind",
ctypes.default_abi,
ctypes.int32_t,
NSPR.Types.PRFileDesc.ptr,
NSPR.Types.PRNetAddr.ptr),
PR_Listen: NSPR._library.declare("PR_Listen",
ctypes.default_abi,
ctypes.int32_t,
NSPR.Types.PRFileDesc.ptr, // fd
ctypes.int32_t), // backlog
PR_Accept: NSPR._library.declare("PR_Accept",
ctypes.default_abi,
NSPR.Types.PRFileDesc.ptr, // new socket fd
NSPR.Types.PRFileDesc.ptr, // rendezvous socket fd
NSPR.Types.PRNetAddr.ptr, //addr
ctypes.uint32_t), // timeout interval
PR_Close: NSPR._library.declare("PR_Close",
ctypes.default_abi,
ctypes.int32_t,
NSPR.Types.PRFileDesc.ptr),
PR_Recv: NSPR._library.declare("PR_Recv",
ctypes.default_abi,
ctypes.int32_t, // return
NSPR.Types.PRFileDesc.ptr, // socket
ctypes.voidptr_t, // buffer
ctypes.int32_t, // buffer length
ctypes.int32_t, // must be 0, deprecated
ctypes.uint32_t), // timeout interval
PR_Send: NSPR._library.declare("PR_Send",
ctypes.default_abi,
ctypes.int32_t, // return
NSPR.Types.PRFileDesc.ptr, // socket
ctypes.voidptr_t, // buffer
ctypes.int32_t, // buffer length
ctypes.int32_t, // must be 0, deprecated
ctypes.uint32_t) // timeout interval
}
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
var EXPORTED_SYMBOLS = ["Server"];
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
// Import local JS modules
Cu.import("resource://jsbridge/modules/Bridge.jsm");
Cu.import("resource://jsbridge/modules/Log.jsm");
Cu.import("resource://jsbridge/modules/Sockets.jsm");
// Reference to module which is needed for backstage access
const module = this;
var Server = { };
Server.Session = function (client) {
this.client = client;
var sandbox = Cu.Sandbox(module);
sandbox.bridge = new Bridge(this);
client.onMessage(function (data) {
data = toUnicode(data, "utf-8");
Cu.evalInSandbox(data, sandbox);
});
}
Server.Session.prototype.send = function (string) {
if (typeof(string) != "string")
throw "jsbridge can only send strings";
this.client.sendMessage(toUnicode(string, 'utf-8'));
};
Server.Session.prototype.quit = function () {
this.client.close();
};
Server.Session.prototype.encodeOut = function (obj) {
try {
this.send(JSON.stringify(obj));
} catch (e) {
if (typeof(e) == "string")
var exception = e;
else