From 88e12f617c5ef1841d7161a6bd8490eb4a8190ad Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 2 Sep 2016 02:42:17 -0400 Subject: [PATCH] Fix `document` property access errors in translation-server For some reason, in the Fx48 translation-server, the processor passed to processDocuments() calls in translators can't access document properties even when they're on the same domain or even the same document. To get around that, rewrap them for the sandbox, but there might be a better fix here. Addresses https://github.com/zotero/translation-server/issues/36 --- .../zotero/xpcom/utilities_translate.js | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/xpcom/utilities_translate.js b/chrome/content/zotero/xpcom/utilities_translate.js index 86f03f6e14..54ec773e76 100644 --- a/chrome/content/zotero/xpcom/utilities_translate.js +++ b/chrome/content/zotero/xpcom/utilities_translate.js @@ -257,7 +257,22 @@ Zotero.Utilities.Translate.prototype.processDocuments = function(urls, processor && this._translate.document.location.toString() === urls[i]) { // Document is attempting to reload itself Zotero.debug("Translate: Attempted to load the current document using processDocuments; using loaded document instead"); - processor(this._translate.document, urls[i]); + // This fixes document permissions issues in translation-server when translators call + // processDocuments() on the original URL (e.g., AOSIC) + // DEBUG: Why is this necessary? (see below also) + if (Zotero.isServer) { + processor( + translate._sandboxManager.wrap( + Zotero.Translate.DOMWrapper.unwrap( + this._translate.document + ) + ), + urls[i] + ); + } + else { + processor(this._translate.document, urls[i]); + } urls.splice(i, 1); i--; } @@ -268,7 +283,11 @@ Zotero.Utilities.Translate.prototype.processDocuments = function(urls, processor if(!processor) return; var newLoc = doc.location; - if(Zotero.isFx && !Zotero.isBookmarklet && (protocol != newLoc.protocol || host != newLoc.host)) { + if((Zotero.isFx && !Zotero.isBookmarklet && (protocol != newLoc.protocol || host != newLoc.host)) + // This fixes document permissions issues in translation-server when translators call + // processDocuments() on same-domain URLs (e.g., some of the Code4Lib tests). + // DEBUG: Is there a better fix for this? + || Zotero.isServer) { // Cross-site; need to wrap processor(translate._sandboxManager.wrap(doc), newLoc.toString()); } else {