Skip to content

Commit

Permalink
Pull changes from upstream master
Browse files Browse the repository at this point in the history
  • Loading branch information
fbennett committed Feb 10, 2018
2 parents 0adac3c + 1aade0f commit ac472f5
Show file tree
Hide file tree
Showing 21 changed files with 579 additions and 102 deletions.
6 changes: 5 additions & 1 deletion chrome/content/zotero/preferences/preferences_sync.js
Expand Up @@ -398,7 +398,6 @@ Zotero_Preferences.Sync = {

onStorageSettingsKeyPress: Zotero.Promise.coroutine(function* (event) {
if (event.keyCode == 13) {
yield this.onStorageSettingsChange();
yield this.verifyStorageServer();
}
}),
Expand Down Expand Up @@ -480,6 +479,11 @@ Zotero_Preferences.Sync = {


verifyStorageServer: Zotero.Promise.coroutine(function* () {
// onchange weirdly isn't triggered when clicking straight from a field to the button,
// so we have to trigger this here (and we don't trigger it for Enter in
// onStorageSettingsKeyPress()).
yield this.onStorageSettingsChange();

Zotero.debug("Verifying storage");

var verifyButton = document.getElementById("storage-verify");
Expand Down
14 changes: 14 additions & 0 deletions chrome/content/zotero/progressMeterWindow.xul
@@ -0,0 +1,14 @@
<?xml version="1.0"?>

<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<?xml-stylesheet href="chrome://zotero/skin/zotero.css" type="text/css"?>

<window id="zotero-progress-meter-window"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
windowtype="alert:alert">

<vbox id="zotero-progress-text-box" flex="1">
<label/>
<progressmeter/>
</vbox>
</window>
5 changes: 5 additions & 0 deletions chrome/content/zotero/xpcom/data/dataCache.js
@@ -0,0 +1,5 @@
"use strict";

Zotero.DataCache = {

};
10 changes: 5 additions & 5 deletions chrome/content/zotero/xpcom/db.js
Expand Up @@ -485,7 +485,7 @@ Zotero.DBConnection.prototype.executeTransaction = Zotero.Promise.coroutine(func
// Run begin callbacks
for (var i=0; i<this._callbacks.begin.length; i++) {
if (this._callbacks.begin[i]) {
this._callbacks.begin[i]();
this._callbacks.begin[i](id);
}
}
var conn = this._getConnection(options) || (yield this._getConnectionAsync(options));
Expand Down Expand Up @@ -516,13 +516,13 @@ Zotero.DBConnection.prototype.executeTransaction = Zotero.Promise.coroutine(func
// Run temporary commit callbacks
var f;
while (f = this._callbacks.current.commit.shift()) {
yield Zotero.Promise.resolve(f());
yield Zotero.Promise.resolve(f(id));
}

// Run commit callbacks
for (var i=0; i<this._callbacks.commit.length; i++) {
if (this._callbacks.commit[i]) {
yield this._callbacks.commit[i]();
yield this._callbacks.commit[i](id);
}
}

Expand All @@ -549,13 +549,13 @@ Zotero.DBConnection.prototype.executeTransaction = Zotero.Promise.coroutine(func
// Run temporary commit callbacks
var f;
while (f = this._callbacks.current.rollback.shift()) {
yield Zotero.Promise.resolve(f());
yield Zotero.Promise.resolve(f(id));
}

// Run rollback callbacks
for (var i=0; i<this._callbacks.rollback.length; i++) {
if (this._callbacks.rollback[i]) {
yield Zotero.Promise.resolve(this._callbacks.rollback[i]());
yield Zotero.Promise.resolve(this._callbacks.rollback[i](id));
}
}

Expand Down
8 changes: 4 additions & 4 deletions chrome/content/zotero/xpcom/fulltext.js
Expand Up @@ -446,7 +446,8 @@ Zotero.Fulltext = Zotero.FullText = new function(){
var totalPages = yield getTotalPagesFromFile(itemID);
}
catch (e) {
Zotero.debug("Error running pdfinfo");
Zotero.debug("Error running " + _pdfInfo.path, 1);
Zotero.logError(e);
}


Expand All @@ -468,9 +469,8 @@ Zotero.Fulltext = Zotero.FullText = new function(){
yield Zotero.Utilities.Internal.exec(exec, args);
}
catch (e) {
Components.utils.reportError(e);
Zotero.debug("Error running pdftotext", 1);
Zotero.debug(e, 1);
Zotero.debug("Error running " + exec.path, 1);
Zotero.logError(e);
return false;
}

Expand Down
5 changes: 5 additions & 0 deletions chrome/content/zotero/xpcom/http.js
Expand Up @@ -1024,6 +1024,7 @@ Zotero.HTTP = new function() {
}

let secInfo = channel.securityInfo;
let msg;
if (secInfo instanceof Ci.nsITransportSecurityInfo) {
secInfo.QueryInterface(Ci.nsITransportSecurityInfo);
if ((secInfo.securityState & Ci.nsIWebProgressListener.STATE_IS_INSECURE)
Expand Down Expand Up @@ -1052,6 +1053,10 @@ Zotero.HTTP = new function() {
== Ci.nsIWebProgressListener.STATE_IS_BROKEN) {
msg = Zotero.getString('sync.error.sslConnectionError');
}
else {
Zotero.debug(secInfo.securityState, 1);
msg = Zotero.getString('sync.error.sslConnectionError');
}
throw new Zotero.HTTP.SecurityException(
msg,
{
Expand Down
55 changes: 23 additions & 32 deletions chrome/content/zotero/xpcom/integration.js
Expand Up @@ -686,7 +686,7 @@ Zotero.Integration.Interface.prototype.setDocPrefs = Zotero.Promise.coroutine(fu
fieldNoteTypes.push(this._session.data.prefs.noteType);
}
} else if(convertBibliographies
&& type === INTEGRATION_TYPE_BIBLIOGRAPHY) {
&& field.type === INTEGRATION_TYPE_BIBLIOGRAPHY) {
fieldsToConvert.push(fields[i]);
fieldNoteTypes.push(0);
}
Expand Down Expand Up @@ -1001,11 +1001,9 @@ Zotero.Integration.Fields.prototype._updateDocument = async function(forceCitati
// If we're not specifically *not* trying to regen text
if (forceCitations != FORCE_CITATIONS_FALSE
// Or metadata has changed thus changing the formatted citation
|| (citation.properties.formattedCitation !== formattedCitation)
// Or we shouldn't ignore citation changes and the citation text has changed
|| (!ignoreCitationChanges && plainCitation !== citation.properties.plainCitation)) {
|| (citation.properties.formattedCitation !== formattedCitation)) {

if (plainCitation !== citation.properties.plainCitation) {
if (!ignoreCitationChanges && plainCitation !== citation.properties.plainCitation) {
// Citation manually modified; ask user if they want to save changes
Zotero.debug("[_updateDocument] Attempting to update manually modified citation.\n"
+ "Original: " + citation.properties.plainCitation + "\n"
Expand Down Expand Up @@ -1038,13 +1036,6 @@ Zotero.Integration.Fields.prototype._updateDocument = async function(forceCitati
var serializedCitation = citation.serialize();
if (serializedCitation != citation.properties.field) {
citationField.setCode(serializedCitation);
if (this._session.data.prefs.fieldType === "ReferenceMark"
&& this._session.data.prefs.noteType != 0 && isRich
&& !citation.properties.dontUpdate) {
// For ReferenceMarks with formatting, we need to set the text again, because
// setting the field code removes formatting from the mark. I don't like this.
citationField.setText(formattedCitation, isRich);
}
}
nUpdated++;
}
Expand Down Expand Up @@ -1158,10 +1149,10 @@ Zotero.Integration.Fields.prototype.addEditCitation = Zotero.Promise.coroutine(f
var previewFn = Zotero.Promise.coroutine(function* (citation) {
let idx = yield fieldIndexPromise;
yield citationsByItemIDPromise;
let citations = this._session.getCiteprocLists();
let citationsPre = citations.slice(0, idx);
let citationsPost = citations.slice(idx+1);

var [citations, fieldToCitationIdxMapping, citationToFieldIdxMapping] = this._session.getCiteprocLists();
let citationsPre = citations.slice(0, fieldToCitationIdxMapping[idx]);
let citationsPost = citations.slice(fieldToCitationIdxMapping[idx]+1);
try {
return this._session.style.previewCitationCluster(citation, citationsPre, citationsPost, "rtf");
} catch(e) {
Expand Down Expand Up @@ -1565,10 +1556,17 @@ Zotero.Integration.Session.prototype.addCitation = Zotero.Promise.coroutine(func

Zotero.Integration.Session.prototype.getCiteprocLists = function() {
var citations = [];
for(let i in this.citationsByIndex) {
citations.push([this.citationsByIndex[i].citationID, this.citationsByIndex[i].properties.noteIndex]);
}
return citations;
var fieldToCitationIdxMapping = [];
var citationToFieldIdxMapping = {};
var i = 0;
// This relies on the order of citationsByIndex keys being stable and sorted in ascending order
// Which it seems to currently be true for every modern JS engine, so we're probably fine
for(let idx in this.citationsByIndex) {
citations.push([this.citationsByIndex[idx].citationID, this.citationsByIndex[idx].properties.noteIndex]);
fieldToCitationIdxMapping[i] = idx;
citationToFieldIdxMapping[idx] = i++;
}
return [citations, fieldToCitationIdxMapping, citationToFieldIdxMapping];
}

/**
Expand All @@ -1580,7 +1578,7 @@ Zotero.Integration.Session.prototype._updateCitations = async function () {
Zotero.debug("Integration: Indices of updated citations");
Zotero.debug(Object.keys(this.updateIndices));

var citations = this.getCiteprocLists();
var [citations, fieldToCitationIdxMapping, citationToFieldIdxMapping] = this.getCiteprocLists();

for (let indexList of [this.newIndices, this.updateIndices]) {
for (let index in indexList) {
Expand All @@ -1592,12 +1590,12 @@ Zotero.Integration.Session.prototype._updateCitations = async function () {
if (!citation) continue;
citation = citation.toJSON();

let citationsPre = citations.slice(0, index);
let citationsPre = citations.slice(0, citationToFieldIdxMapping[index]);
var citationsPost;
if (index in this.newIndices) {
citationsPost = [];
} else {
citationsPost = citations.slice(index+1);
citationsPost = citations.slice(citationToFieldIdxMapping[index]+1);
}

Zotero.debug("Integration: style.processCitationCluster("+citation.toSource()+", "+citationsPre.toSource()+", "+citationsPost.toSource());
Expand All @@ -1606,7 +1604,7 @@ Zotero.Integration.Session.prototype._updateCitations = async function () {
this.bibliographyHasChanged |= info.bibchange;

for (let citationInfo of newCitations) {
let idx = citationInfo[0], text = citationInfo[1];
let idx = fieldToCitationIdxMapping[citationInfo[0]], text = citationInfo[1];
this.updateIndices[idx] = true;
this.citationsByIndex[idx].text = text;
}
Expand Down Expand Up @@ -1656,13 +1654,6 @@ Zotero.Integration.Session.prototype.writeDelayedCitation = Zotero.Promise.corou
}

field.setCode(citation.serialize());
if (this.data.prefs.fieldType === "ReferenceMark"
&& this.data.prefs.noteType != 0 && isRich
&& !citation.properties.dontUpdate) {
// For ReferenceMarks with formatting, we need to set the text again, because
// setting the field code removes formatting from the mark. I don't like this.
field.setText(text, isRich);
}

// Update bibliography with a static string
var fields = yield this.fields.get();
Expand Down Expand Up @@ -2065,7 +2056,7 @@ Zotero.Integration.Field = class {
}
// This is not the best solution in terms of performance
for (let prop in field) {
if (!(prop in this)) {
if (prop[0] != '_' && !(prop in this)) {
this[prop] = field[prop].bind ? field[prop].bind(field) : field[prop];
}
}
Expand Down
28 changes: 16 additions & 12 deletions chrome/content/zotero/xpcom/notifier.js
Expand Up @@ -32,7 +32,7 @@ Zotero.Notifier = new function(){
'collection-item', 'item-tag', 'tag', 'setting', 'group', 'trash',
'bucket', 'relation', 'feed', 'feedItem', 'sync', 'api-key'
];
var _inTransaction;
var _transactionID = false;
var _queue = {};


Expand Down Expand Up @@ -106,7 +106,7 @@ Zotero.Notifier = new function(){
* - New events and types should be added to the order arrays in commit()
**/
this.trigger = Zotero.Promise.coroutine(function* (event, type, ids, extraData, force) {
if (_inTransaction && !force) {
if (_transactionID && !force) {
return this.queue(event, type, ids, extraData);
}

Expand Down Expand Up @@ -173,7 +173,7 @@ Zotero.Notifier = new function(){
queue = queue._queue;
}
else {
if (!_inTransaction) {
if (!_transactionID) {
throw new Error("Can't queue event outside of a transaction");
}
queue = _queue;
Expand Down Expand Up @@ -278,11 +278,11 @@ Zotero.Notifier = new function(){
*
* Note: Be sure the matching commit() gets called (e.g. in a finally{...} block) or
* notifications will break until Firefox is restarted or commit(true)/reset() is called manually
*
* @param {String} [transactionID]
*/
this.begin = function () {
if (!_inTransaction) {
_inTransaction = true;
}
this.begin = function (transactionID = true) {
_transactionID = transactionID;
}


Expand All @@ -291,8 +291,9 @@ Zotero.Notifier = new function(){
*
* @param {Zotero.Notifier.Queue|Zotero.Notifier.Queue[]} [queues] - One or more queues to use
* instead of the internal queue
* @param {String} [transactionID]
*/
this.commit = Zotero.Promise.coroutine(function* (queues) {
this.commit = Zotero.Promise.coroutine(function* (queues, transactionID = true) {
if (queues) {
if (!Array.isArray(queues)) {
queues = [queues];
Expand All @@ -308,7 +309,7 @@ Zotero.Notifier = new function(){
}
}
}
else if (!_inTransaction) {
else if (!_transactionID) {
throw new Error("Can't commit outside of transaction");
}
else {
Expand Down Expand Up @@ -375,7 +376,7 @@ Zotero.Notifier = new function(){
}

if (!queues) {
this.reset();
this.reset(transactionID);
}

if (totals) {
Expand Down Expand Up @@ -407,10 +408,13 @@ Zotero.Notifier = new function(){
/*
* Reset the event queue
*/
this.reset = function () {
this.reset = function (transactionID = true) {
if (transactionID != _transactionID) {
return;
}
//Zotero.debug("Resetting notifier event queue");
_queue = {};
_inTransaction = false;
_transactionID = false;
}
}

Expand Down
8 changes: 4 additions & 4 deletions chrome/content/zotero/xpcom/schema.js
Expand Up @@ -829,7 +829,7 @@ Zotero.Schema = new function(){
index[id].extract = true;
}

let sql = "SELECT fileName, metadataJSON FROM translatorCache";
let sql = "SELECT rowid, fileName, metadataJSON FROM translatorCache";
let rows = yield Zotero.DB.queryAsync(sql);
// If there's anything in the cache, see what we actually need to extract
for (let i = 0; i < rows.length; i++) {
Expand All @@ -842,10 +842,10 @@ Zotero.Schema = new function(){
Zotero.logError(e);
Zotero.debug(json, 1);

// // If JSON is invalid, clear from cache
// If JSON is invalid, clear from cache
yield Zotero.DB.queryAsync(
"DELETE FROM translatorCache WHERE fileName=?",
rows[i].fileName
"DELETE FROM translatorCache WHERE rowid=?",
rows[i].rowid
);
continue;
}
Expand Down

0 comments on commit ac472f5

Please sign in to comment.