diff --git a/chrome/content/zotero/xpcom/http.js b/chrome/content/zotero/xpcom/http.js index 07f7f12405..7c1e212532 100644 --- a/chrome/content/zotero/xpcom/http.js +++ b/chrome/content/zotero/xpcom/http.js @@ -990,17 +990,11 @@ Zotero.HTTP = new function() { if(typeof url !== "object") { url = Services.io.newURI(url, null, null).QueryInterface(Components.interfaces.nsIURL); } - - var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] - .createInstance(Components.interfaces.nsIDOMParser); - var secMan = Components.classes["@mozilla.org/scriptsecuritymanager;1"] - .getService(Components.interfaces.nsIScriptSecurityManager); - parser.init(secMan.getCodebasePrincipal(url), url, url); return Zotero.Translate.DOMWrapper.wrap(doc, { - "documentURI":{ "enumerable":true, "value":url.spec }, - "URL":{ "enumerable":true, "value":url.spec }, - "location":{ "enumerable":true, "value":(new Zotero.HTTP.Location(url)) }, - "defaultView":{ "enumerable":true, "value":(new Zotero.HTTP.Window(url)) } + "documentURI":url.spec, + "URL":url.spec, + "location":new Zotero.HTTP.Location(url), + "defaultView":new Zotero.HTTP.Window(url) }); } } \ No newline at end of file diff --git a/chrome/content/zotero/xpcom/translation/translate.js b/chrome/content/zotero/xpcom/translation/translate.js index 358583a2c8..c301ea6ff8 100644 --- a/chrome/content/zotero/xpcom/translation/translate.js +++ b/chrome/content/zotero/xpcom/translation/translate.js @@ -1172,7 +1172,7 @@ Zotero.Translate.Base.prototype = { // translate try { - Function.prototype.apply.apply(this._sandboxManager.sandbox["do"+this._entryFunctionSuffix], [null, this._getParameters()]); + Function.prototype.apply.call(this._sandboxManager.sandbox["do"+this._entryFunctionSuffix], null, this._getParameters()); } catch(e) { this.complete(false, e); return false; @@ -1445,7 +1445,7 @@ Zotero.Translate.Base.prototype = { this.incrementAsyncProcesses("Zotero.Translate#getTranslators"); try { - var returnValue = Function.prototype.apply.apply(this._sandboxManager.sandbox["detect"+this._entryFunctionSuffix], [null, this._getParameters()]); + var returnValue = Function.prototype.apply.call(this._sandboxManager.sandbox["detect"+this._entryFunctionSuffix], null, this._getParameters()); } catch(e) { this.complete(false, e); return; @@ -1718,7 +1718,14 @@ Zotero.Translate.Web.prototype._getSandboxLocation = function() { /** * Pass document and location to detect* and do* functions */ -Zotero.Translate.Web.prototype._getParameters = function() { return [this.document, this.location]; } +Zotero.Translate.Web.prototype._getParameters = function() { + if (Zotero.Translate.DOMWrapper && Zotero.Translate.DOMWrapper.isWrapped(this.document)) { + return [this._sandboxManager.wrap(Zotero.Translate.DOMWrapper.unwrap(this.document), null, + this.document.__wrapperOverrides), this.location]; + } else { + return [this.document, this.location]; + } +}; /** * Prepare translation diff --git a/chrome/content/zotero/xpcom/translation/translate_firefox.js b/chrome/content/zotero/xpcom/translation/translate_firefox.js index 67594daa6b..21d190a315 100644 --- a/chrome/content/zotero/xpcom/translation/translate_firefox.js +++ b/chrome/content/zotero/xpcom/translation/translate_firefox.js @@ -174,6 +174,8 @@ Zotero.Translate.DOMWrapper = new function() { // Handle our special API. if (name == "__wrappedObject") return { value: this.wrappedObject, writeable: false, configurable: false, enumerable: false }; + if (name == "__wrapperOverrides") + return { value: this.overrides, writeable: false, configurable: false, enumerable: false }; // Handle __exposedProps__. if (name == "__exposedProps__") return { value: ExposedPropsWaiver, writable: false, configurable: false, enumerable: false }; @@ -196,7 +198,7 @@ Zotero.Translate.DOMWrapper = new function() { // Hack for overriding some properties if (this.overrides.hasOwnProperty(name)) - return this.overrides[name]; + return { "enumerable": true, "value": this.overrides[name] }; // Case 1: Own Properties. // // This one is easy, thanks to Object.getOwnPropertyDescriptor(). @@ -425,28 +427,29 @@ Zotero.Translate.SandboxManager = function(sandboxLocation) { this._makeContentForwarder = Components.utils.evalInSandbox(expr, sandbox); if (Zotero.platformMajorVersion >= 35) { - var _proxy = Components.utils.evalInSandbox('(function (target, x) {'+ - ' return new Proxy(x, ProxyHandler(target));'+ + var _proxy = Components.utils.evalInSandbox('(function (target, x, overrides) {'+ + ' return new Proxy(x, ProxyHandler(target, overrides));'+ '})', sandbox); - var wrap = this.wrap = function(target, x) { + var wrap = this.wrap = function(target, x, overrides) { if (target === null || (typeof target !== "object" && typeof target !== "function")) return target; if (!x) x = new sandbox.Object(); - return _proxy(target, x); + return _proxy(target, x, overrides); }; var me = this; sandbox.ProxyHandler = this._makeContentForwarder(function() { var target = (this.args.wrappedJSObject || this.args)[0]; + var overrides = (this.args.wrappedJSObject || this.args)[1] || {}; if(target instanceof Components.interfaces.nsISupports) { target = new XPCNativeWrapper(target); } var ret = new sandbox.Object(); ret.wrappedJSObject.has = function(x, prop) { - return prop in target; + return overrides.hasOwnProperty(prop) || prop in target; }; ret.wrappedJSObject.get = function(x, prop, receiver) { if (prop === "__wrappedObject") return target; if (prop === "__wrappingManager") return me; - var y = target[prop]; + var y = overrides.hasOwnProperty(prop) ? overrides[prop] : target[prop]; if (y === null || (typeof y !== "object" && typeof y !== "function")) return y; return wrap(y, typeof y === "function" ? function() { var args = Array.prototype.slice.apply(arguments);