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:
Dan Stillman 2019-01-13 18:01:08 -05:00
parent a8a4d13b72
commit 76978aa912
4 changed files with 50 additions and 62 deletions

View file

@ -9,6 +9,11 @@
<style>
body {
margin: 0;
background: white;
}
a {
text-decoration: underline;
}
header {

View file

@ -36,9 +36,9 @@ Zotero.Report.HTML = new function () {
+ ' <head>\n'
+ ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\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" media="screen,projection" href="zotero://report/detail_screen.css"/>\n'
+ ' <link rel="stylesheet" type="text/css" media="print" href="zotero://report/detail_print.css"/>\n'
+ ' <link rel="stylesheet" type="text/css" href="' + _getCSSDataURI('detail') + '"/>\n'
+ ' <link rel="stylesheet" type="text/css" media="screen,projection" href="' + _getCSSDataURI('detail_screen') + '"/>\n'
+ ' <link rel="stylesheet" type="text/css" media="print" href="' + _getCSSDataURI('detail_print') + '"/>\n'
+ ' </head>\n'
+ ' <body>\n'
+ ' <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) {
var table = false;
var content = '\t\t\t\t<table>\n';

View file

@ -1,3 +1,11 @@
body {
background: white;
}
a {
text-decoration: underline;
}
body {
padding: 0;
}

View file

@ -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_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 Ci = Components.interfaces;
const Cr = Components.results;
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
const ios = Services.io;
// Dummy chrome URL used to obtain a valid chrome channel
// This one was chosen at random and should be able to be substituted
// for any other well known chrome URL in the browser installation
const DUMMY_CHROME_URL = "chrome://mozapps/content/xpinstall/xpinstallConfirm.xul";
const DUMMY_CHROME_URL = "chrome://zotero/content/zoteroPane.xul";
var Zotero = Components.classes["@zotero.org/Zotero;1"]
.getService(Components.interfaces.nsISupports)
.wrappedJSObject;
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
function ZoteroProtocolHandler() {
this.wrappedJSObject = this;
this._principal = null;
@ -94,19 +91,16 @@ function ZoteroProtocolHandler() {
return new AsyncChannel(uri, function* () {
var userLibraryID = Zotero.Libraries.userLibraryID;
var path = uri.path;
var path = uri.pathQueryRef;
if (!path) {
return 'Invalid URL';
}
// Strip leading '/'
path = path.substr(1);
path = path.substr('//report/'.length);
// Proxy CSS files
if (path.endsWith('.css')) {
var chromeURL = 'chrome://zotero/skin/report/' + path;
Zotero.debug(chromeURL);
var ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
let uri = ios.newURI(chromeURL, null, null);
var chromeReg = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
.getService(Components.interfaces.nsIChromeRegistry);
@ -447,6 +441,7 @@ function ZoteroProtocolHandler() {
return Zotero.Utilities.Internal.getAsyncInputStream(
Zotero.Report.HTML.listGenerator(items, combineChildItems),
function () {
Zotero.logError(e);
return '<span style="color: red; font-weight: bold">Error generating report</span>';
}
);
@ -477,7 +472,7 @@ function ZoteroProtocolHandler() {
return new AsyncChannel(uri, function* () {
var userLibraryID = Zotero.Libraries.userLibraryID;
path = uri.spec.match(/zotero:\/\/[^/]+(.*)/)[1];
var path = uri.spec.match(/zotero:\/\/[^/]+(.*)/)[1];
if (!path) {
this.contentType = 'text/html';
return 'Invalid URL';
@ -658,7 +653,7 @@ function ZoteroProtocolHandler() {
//
// 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';
if(!timelineDate){
@ -735,8 +730,6 @@ function ZoteroProtocolHandler() {
// Proxy annotation icons
if (id.match(/^annotation.*\.(png|html|css|gif)$/)) {
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);
var chromeReg = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
.getService(Components.interfaces.nsIChromeRegistry);
@ -798,12 +791,11 @@ function ZoteroProtocolHandler() {
doAction: Zotero.Promise.coroutine(function* (uri) {
var userLibraryID = Zotero.Libraries.userLibraryID;
var path = uri.path;
var path = uri.pathQueryRef;
if (!path) {
return 'Invalid URL';
}
// Strip leading '/'
path = path.substr(1);
path = path.substr('//select/'.length);
var mimeType, content = '';
var params = {
@ -969,11 +961,9 @@ function ZoteroProtocolHandler() {
var ConnectorChannel = function(uri, data) {
var secMan = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
.getService(Components.interfaces.nsIScriptSecurityManager);
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
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._isPending = true;
@ -1039,8 +1029,6 @@ function ZoteroProtocolHandler() {
this.loadAsChrome = false;
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"]
.getService(Components.interfaces.nsIScriptSecurityManager);
var Zotero = Components.classes["@zotero.org/Zotero;1"]
@ -1048,8 +1036,8 @@ function ZoteroProtocolHandler() {
.wrappedJSObject;
try {
var originalURI = uri.path;
originalURI = decodeURIComponent(originalURI.substr(originalURI.indexOf("/")+1));
var originalURI = uri.pathQueryRef.substr('zotero://connector/'.length);
originalURI = decodeURIComponent(originalURI);
if(!Zotero.Server.Connector.Data[originalURI]) {
return null;
} else {
@ -1078,12 +1066,11 @@ function ZoteroProtocolHandler() {
doAction: async function (uri) {
var userLibraryID = Zotero.Libraries.userLibraryID;
var uriPath = uri.path;
var uriPath = uri.pathQueryRef;
if (!uriPath) {
return 'Invalid URL';
}
// Strip leading '/'
uriPath = uriPath.substr(1);
uriPath = uriPath.substr('//open-pdf/'.length);
var mimeType, content = '';
var params = {
@ -1225,17 +1212,14 @@ ZoteroProtocolHandler.prototype = {
return false;
},
newURI : function(spec, charset, baseURI) {
var newURL = Components.classes["@mozilla.org/network/standard-url;1"]
.createInstance(Components.interfaces.nsIStandardURL);
newURL.init(1, -1, spec, charset, baseURI);
return newURL.QueryInterface(Components.interfaces.nsIURI);
newURI: function (spec, charset, baseURI) {
return Components.classes["@mozilla.org/network/simple-uri-mutator;1"]
.createInstance(Components.interfaces.nsIURIMutator)
.setSpec(spec)
.finalize();
},
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"]
.getService(Components.interfaces.nsIProtocolHandler);
@ -1255,18 +1239,8 @@ ZoteroProtocolHandler.prototype = {
return extChannel;
}
if (!this._principal) {
if (ext.loadAsChrome) {
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
}
if (!this._principal && ext.loadAsChrome) {
this._principal = Services.scriptSecurityManager.getSystemPrincipal();
}
var extChannel = ext.newChannel(uri);
@ -1367,14 +1341,7 @@ AsyncChannel.prototype = {
//Zotero.debug("AsyncChannel's asyncOpen called");
var t = new Date;
// Proxy requests to other zotero:// URIs
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);
}
var data;
try {
if (!data) {
data = yield Zotero.spawn(channel._generator, channel)
@ -1408,7 +1375,7 @@ AsyncChannel.prototype = {
else if (data instanceof Ci.nsIFile || data instanceof Ci.nsIURI) {
if (data instanceof Ci.nsIFile) {
//Zotero.debug("AsyncChannel: Got file from generator");
data = ioService.newFileURI(data);
data = ios.newFileURI(data);
}
else {
//Zotero.debug("AsyncChannel: Got URI from generator");