Fx60: Fix protocol handler
These will need to be redone for Electron, but this keeps them working in the meantime.
This commit is contained in:
parent
a8a4d13b72
commit
76978aa912
4 changed files with 50 additions and 62 deletions
|
@ -9,6 +9,11 @@
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
background: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
header {
|
header {
|
||||||
|
|
|
@ -36,9 +36,9 @@ Zotero.Report.HTML = new function () {
|
||||||
+ ' <head>\n'
|
+ ' <head>\n'
|
||||||
+ ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n'
|
+ ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n'
|
||||||
+ ' <title>' + Zotero.getString('report.title.default') + '</title>\n'
|
+ ' <title>' + Zotero.getString('report.title.default') + '</title>\n'
|
||||||
+ ' <link rel="stylesheet" type="text/css" href="zotero://report/detail.css"/>\n'
|
+ ' <link rel="stylesheet" type="text/css" href="' + _getCSSDataURI('detail') + '"/>\n'
|
||||||
+ ' <link rel="stylesheet" type="text/css" media="screen,projection" href="zotero://report/detail_screen.css"/>\n'
|
+ ' <link rel="stylesheet" type="text/css" media="screen,projection" href="' + _getCSSDataURI('detail_screen') + '"/>\n'
|
||||||
+ ' <link rel="stylesheet" type="text/css" media="print" href="zotero://report/detail_print.css"/>\n'
|
+ ' <link rel="stylesheet" type="text/css" media="print" href="' + _getCSSDataURI('detail_print') + '"/>\n'
|
||||||
+ ' </head>\n'
|
+ ' </head>\n'
|
||||||
+ ' <body>\n'
|
+ ' <body>\n'
|
||||||
+ ' <ul class="report' + (combineChildItems ? ' combineChildItems' : '') + '">';
|
+ ' <ul class="report' + (combineChildItems ? ' combineChildItems' : '') + '">';
|
||||||
|
@ -130,6 +130,14 @@ Zotero.Report.HTML = new function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
function _getCSSDataURI(file) {
|
||||||
|
return 'data:text/css;base64,'
|
||||||
|
+ Zotero.Utilities.Internal.Base64.encode(
|
||||||
|
Zotero.File.getResource(`chrome://zotero/skin/report/${file}.css`)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function _generateMetadataTable(obj) {
|
function _generateMetadataTable(obj) {
|
||||||
var table = false;
|
var table = false;
|
||||||
var content = '\t\t\t\t<table>\n';
|
var content = '\t\t\t\t<table>\n';
|
||||||
|
|
|
@ -1,3 +1,11 @@
|
||||||
|
body {
|
||||||
|
background: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,24 +32,21 @@ const ZOTERO_PROTOCOL_CID = Components.ID("{9BC3D762-9038-486A-9D70-C997AF848A7C
|
||||||
const ZOTERO_PROTOCOL_CONTRACTID = "@mozilla.org/network/protocol;1?name=" + ZOTERO_SCHEME;
|
const ZOTERO_PROTOCOL_CONTRACTID = "@mozilla.org/network/protocol;1?name=" + ZOTERO_SCHEME;
|
||||||
const ZOTERO_PROTOCOL_NAME = "Zotero Chrome Extension Protocol";
|
const ZOTERO_PROTOCOL_NAME = "Zotero Chrome Extension Protocol";
|
||||||
|
|
||||||
|
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||||
|
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||||
|
|
||||||
const Cc = Components.classes;
|
const Cc = Components.classes;
|
||||||
const Ci = Components.interfaces;
|
const Ci = Components.interfaces;
|
||||||
const Cr = Components.results;
|
const Cr = Components.results;
|
||||||
|
const ios = Services.io;
|
||||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
||||||
|
|
||||||
// Dummy chrome URL used to obtain a valid chrome channel
|
// Dummy chrome URL used to obtain a valid chrome channel
|
||||||
// This one was chosen at random and should be able to be substituted
|
const DUMMY_CHROME_URL = "chrome://zotero/content/zoteroPane.xul";
|
||||||
// for any other well known chrome URL in the browser installation
|
|
||||||
const DUMMY_CHROME_URL = "chrome://mozapps/content/xpinstall/xpinstallConfirm.xul";
|
|
||||||
|
|
||||||
var Zotero = Components.classes["@zotero.org/Zotero;1"]
|
var Zotero = Components.classes["@zotero.org/Zotero;1"]
|
||||||
.getService(Components.interfaces.nsISupports)
|
.getService(Components.interfaces.nsISupports)
|
||||||
.wrappedJSObject;
|
.wrappedJSObject;
|
||||||
|
|
||||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
|
||||||
.getService(Components.interfaces.nsIIOService);
|
|
||||||
|
|
||||||
function ZoteroProtocolHandler() {
|
function ZoteroProtocolHandler() {
|
||||||
this.wrappedJSObject = this;
|
this.wrappedJSObject = this;
|
||||||
this._principal = null;
|
this._principal = null;
|
||||||
|
@ -94,19 +91,16 @@ function ZoteroProtocolHandler() {
|
||||||
return new AsyncChannel(uri, function* () {
|
return new AsyncChannel(uri, function* () {
|
||||||
var userLibraryID = Zotero.Libraries.userLibraryID;
|
var userLibraryID = Zotero.Libraries.userLibraryID;
|
||||||
|
|
||||||
var path = uri.path;
|
var path = uri.pathQueryRef;
|
||||||
if (!path) {
|
if (!path) {
|
||||||
return 'Invalid URL';
|
return 'Invalid URL';
|
||||||
}
|
}
|
||||||
// Strip leading '/'
|
path = path.substr('//report/'.length);
|
||||||
path = path.substr(1);
|
|
||||||
|
|
||||||
// Proxy CSS files
|
// Proxy CSS files
|
||||||
if (path.endsWith('.css')) {
|
if (path.endsWith('.css')) {
|
||||||
var chromeURL = 'chrome://zotero/skin/report/' + path;
|
var chromeURL = 'chrome://zotero/skin/report/' + path;
|
||||||
Zotero.debug(chromeURL);
|
Zotero.debug(chromeURL);
|
||||||
var ios = Components.classes["@mozilla.org/network/io-service;1"]
|
|
||||||
.getService(Components.interfaces.nsIIOService);
|
|
||||||
let uri = ios.newURI(chromeURL, null, null);
|
let uri = ios.newURI(chromeURL, null, null);
|
||||||
var chromeReg = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
|
var chromeReg = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
|
||||||
.getService(Components.interfaces.nsIChromeRegistry);
|
.getService(Components.interfaces.nsIChromeRegistry);
|
||||||
|
@ -447,6 +441,7 @@ function ZoteroProtocolHandler() {
|
||||||
return Zotero.Utilities.Internal.getAsyncInputStream(
|
return Zotero.Utilities.Internal.getAsyncInputStream(
|
||||||
Zotero.Report.HTML.listGenerator(items, combineChildItems),
|
Zotero.Report.HTML.listGenerator(items, combineChildItems),
|
||||||
function () {
|
function () {
|
||||||
|
Zotero.logError(e);
|
||||||
return '<span style="color: red; font-weight: bold">Error generating report</span>';
|
return '<span style="color: red; font-weight: bold">Error generating report</span>';
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -477,7 +472,7 @@ function ZoteroProtocolHandler() {
|
||||||
return new AsyncChannel(uri, function* () {
|
return new AsyncChannel(uri, function* () {
|
||||||
var userLibraryID = Zotero.Libraries.userLibraryID;
|
var userLibraryID = Zotero.Libraries.userLibraryID;
|
||||||
|
|
||||||
path = uri.spec.match(/zotero:\/\/[^/]+(.*)/)[1];
|
var path = uri.spec.match(/zotero:\/\/[^/]+(.*)/)[1];
|
||||||
if (!path) {
|
if (!path) {
|
||||||
this.contentType = 'text/html';
|
this.contentType = 'text/html';
|
||||||
return 'Invalid URL';
|
return 'Invalid URL';
|
||||||
|
@ -658,7 +653,7 @@ function ZoteroProtocolHandler() {
|
||||||
//
|
//
|
||||||
// Generate main HTML page
|
// Generate main HTML page
|
||||||
//
|
//
|
||||||
content = Zotero.File.getContentsFromURL('chrome://zotero/skin/timeline/timeline.html');
|
var content = Zotero.File.getContentsFromURL('chrome://zotero/skin/timeline/timeline.html');
|
||||||
this.contentType = 'text/html';
|
this.contentType = 'text/html';
|
||||||
|
|
||||||
if(!timelineDate){
|
if(!timelineDate){
|
||||||
|
@ -735,8 +730,6 @@ function ZoteroProtocolHandler() {
|
||||||
// Proxy annotation icons
|
// Proxy annotation icons
|
||||||
if (id.match(/^annotation.*\.(png|html|css|gif)$/)) {
|
if (id.match(/^annotation.*\.(png|html|css|gif)$/)) {
|
||||||
var chromeURL = 'chrome://zotero/skin/' + id;
|
var chromeURL = 'chrome://zotero/skin/' + id;
|
||||||
var ios = Components.classes["@mozilla.org/network/io-service;1"].
|
|
||||||
getService(Components.interfaces.nsIIOService);
|
|
||||||
let uri = ios.newURI(chromeURL, null, null);
|
let uri = ios.newURI(chromeURL, null, null);
|
||||||
var chromeReg = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
|
var chromeReg = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
|
||||||
.getService(Components.interfaces.nsIChromeRegistry);
|
.getService(Components.interfaces.nsIChromeRegistry);
|
||||||
|
@ -798,12 +791,11 @@ function ZoteroProtocolHandler() {
|
||||||
doAction: Zotero.Promise.coroutine(function* (uri) {
|
doAction: Zotero.Promise.coroutine(function* (uri) {
|
||||||
var userLibraryID = Zotero.Libraries.userLibraryID;
|
var userLibraryID = Zotero.Libraries.userLibraryID;
|
||||||
|
|
||||||
var path = uri.path;
|
var path = uri.pathQueryRef;
|
||||||
if (!path) {
|
if (!path) {
|
||||||
return 'Invalid URL';
|
return 'Invalid URL';
|
||||||
}
|
}
|
||||||
// Strip leading '/'
|
path = path.substr('//select/'.length);
|
||||||
path = path.substr(1);
|
|
||||||
var mimeType, content = '';
|
var mimeType, content = '';
|
||||||
|
|
||||||
var params = {
|
var params = {
|
||||||
|
@ -969,11 +961,9 @@ function ZoteroProtocolHandler() {
|
||||||
var ConnectorChannel = function(uri, data) {
|
var ConnectorChannel = function(uri, data) {
|
||||||
var secMan = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
|
var secMan = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
|
||||||
.getService(Components.interfaces.nsIScriptSecurityManager);
|
.getService(Components.interfaces.nsIScriptSecurityManager);
|
||||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
|
||||||
.getService(Components.interfaces.nsIIOService);
|
|
||||||
|
|
||||||
this.name = uri;
|
this.name = uri;
|
||||||
this.URI = ioService.newURI(uri, "UTF-8", null);
|
this.URI = ios.newURI(uri, "UTF-8", null);
|
||||||
this.owner = (secMan.getCodebasePrincipal || secMan.getSimpleCodebasePrincipal)(this.URI);
|
this.owner = (secMan.getCodebasePrincipal || secMan.getSimpleCodebasePrincipal)(this.URI);
|
||||||
this._isPending = true;
|
this._isPending = true;
|
||||||
|
|
||||||
|
@ -1039,8 +1029,6 @@ function ZoteroProtocolHandler() {
|
||||||
this.loadAsChrome = false;
|
this.loadAsChrome = false;
|
||||||
|
|
||||||
this.newChannel = function(uri) {
|
this.newChannel = function(uri) {
|
||||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
|
||||||
.getService(Components.interfaces.nsIIOService);
|
|
||||||
var secMan = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
|
var secMan = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
|
||||||
.getService(Components.interfaces.nsIScriptSecurityManager);
|
.getService(Components.interfaces.nsIScriptSecurityManager);
|
||||||
var Zotero = Components.classes["@zotero.org/Zotero;1"]
|
var Zotero = Components.classes["@zotero.org/Zotero;1"]
|
||||||
|
@ -1048,8 +1036,8 @@ function ZoteroProtocolHandler() {
|
||||||
.wrappedJSObject;
|
.wrappedJSObject;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var originalURI = uri.path;
|
var originalURI = uri.pathQueryRef.substr('zotero://connector/'.length);
|
||||||
originalURI = decodeURIComponent(originalURI.substr(originalURI.indexOf("/")+1));
|
originalURI = decodeURIComponent(originalURI);
|
||||||
if(!Zotero.Server.Connector.Data[originalURI]) {
|
if(!Zotero.Server.Connector.Data[originalURI]) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1078,12 +1066,11 @@ function ZoteroProtocolHandler() {
|
||||||
doAction: async function (uri) {
|
doAction: async function (uri) {
|
||||||
var userLibraryID = Zotero.Libraries.userLibraryID;
|
var userLibraryID = Zotero.Libraries.userLibraryID;
|
||||||
|
|
||||||
var uriPath = uri.path;
|
var uriPath = uri.pathQueryRef;
|
||||||
if (!uriPath) {
|
if (!uriPath) {
|
||||||
return 'Invalid URL';
|
return 'Invalid URL';
|
||||||
}
|
}
|
||||||
// Strip leading '/'
|
uriPath = uriPath.substr('//open-pdf/'.length);
|
||||||
uriPath = uriPath.substr(1);
|
|
||||||
var mimeType, content = '';
|
var mimeType, content = '';
|
||||||
|
|
||||||
var params = {
|
var params = {
|
||||||
|
@ -1225,17 +1212,14 @@ ZoteroProtocolHandler.prototype = {
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
newURI : function(spec, charset, baseURI) {
|
newURI: function (spec, charset, baseURI) {
|
||||||
var newURL = Components.classes["@mozilla.org/network/standard-url;1"]
|
return Components.classes["@mozilla.org/network/simple-uri-mutator;1"]
|
||||||
.createInstance(Components.interfaces.nsIStandardURL);
|
.createInstance(Components.interfaces.nsIURIMutator)
|
||||||
newURL.init(1, -1, spec, charset, baseURI);
|
.setSpec(spec)
|
||||||
return newURL.QueryInterface(Components.interfaces.nsIURI);
|
.finalize();
|
||||||
},
|
},
|
||||||
|
|
||||||
newChannel : function(uri) {
|
newChannel : function(uri) {
|
||||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
|
||||||
.getService(Components.interfaces.nsIIOService);
|
|
||||||
|
|
||||||
var chromeService = Components.classes["@mozilla.org/network/protocol;1?name=chrome"]
|
var chromeService = Components.classes["@mozilla.org/network/protocol;1?name=chrome"]
|
||||||
.getService(Components.interfaces.nsIProtocolHandler);
|
.getService(Components.interfaces.nsIProtocolHandler);
|
||||||
|
|
||||||
|
@ -1255,18 +1239,8 @@ ZoteroProtocolHandler.prototype = {
|
||||||
return extChannel;
|
return extChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this._principal) {
|
if (!this._principal && ext.loadAsChrome) {
|
||||||
if (ext.loadAsChrome) {
|
this._principal = Services.scriptSecurityManager.getSystemPrincipal();
|
||||||
var chromeURI = chromeService.newURI(DUMMY_CHROME_URL, null, null);
|
|
||||||
var chromeChannel = chromeService.newChannel(chromeURI);
|
|
||||||
|
|
||||||
// Cache System Principal from chrome request
|
|
||||||
// so proxied pages load with chrome privileges
|
|
||||||
this._principal = chromeChannel.owner;
|
|
||||||
|
|
||||||
var chromeRequest = chromeChannel.QueryInterface(Components.interfaces.nsIRequest);
|
|
||||||
chromeRequest.cancel(0x804b0002); // BINDING_ABORTED
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var extChannel = ext.newChannel(uri);
|
var extChannel = ext.newChannel(uri);
|
||||||
|
@ -1367,14 +1341,7 @@ AsyncChannel.prototype = {
|
||||||
//Zotero.debug("AsyncChannel's asyncOpen called");
|
//Zotero.debug("AsyncChannel's asyncOpen called");
|
||||||
var t = new Date;
|
var t = new Date;
|
||||||
|
|
||||||
// Proxy requests to other zotero:// URIs
|
var data;
|
||||||
let uri2 = this.URI.clone();
|
|
||||||
if (uri2.path.startsWith('/proxy/')) {
|
|
||||||
let re = new RegExp(uri2.scheme + '://' + uri2.host + '/proxy/([^/]+)(.*)');
|
|
||||||
let matches = uri2.spec.match(re);
|
|
||||||
uri2.spec = uri2.scheme + '://' + matches[1] + '/' + (matches[2] ? matches[2] : '');
|
|
||||||
var data = Zotero.File.getContentsFromURL(uri2.spec);
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
if (!data) {
|
if (!data) {
|
||||||
data = yield Zotero.spawn(channel._generator, channel)
|
data = yield Zotero.spawn(channel._generator, channel)
|
||||||
|
@ -1408,7 +1375,7 @@ AsyncChannel.prototype = {
|
||||||
else if (data instanceof Ci.nsIFile || data instanceof Ci.nsIURI) {
|
else if (data instanceof Ci.nsIFile || data instanceof Ci.nsIURI) {
|
||||||
if (data instanceof Ci.nsIFile) {
|
if (data instanceof Ci.nsIFile) {
|
||||||
//Zotero.debug("AsyncChannel: Got file from generator");
|
//Zotero.debug("AsyncChannel: Got file from generator");
|
||||||
data = ioService.newFileURI(data);
|
data = ios.newFileURI(data);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//Zotero.debug("AsyncChannel: Got URI from generator");
|
//Zotero.debug("AsyncChannel: Got URI from generator");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue