commit 1a76e328062f5cd96d2c4cc36df9f7caf50a8c0c
parent 72a99d32f3a6c69ede9475290d1a4b999baf0ad6
Author: Simon Kornblith <simon@simonster.com>
Date: Sun, 27 Apr 2014 18:03:08 -0400
Merge pull request #470 from aurimasv/detect-iframe
For detectWeb, ignore translators targeting iframes with same URL
Diffstat:
2 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/chrome/content/zotero/browser.js b/chrome/content/zotero/browser.js
@@ -812,8 +812,10 @@ Zotero_Browser.Tab.prototype._translatorsAvailable = function(translate, transla
//and the page is still there
&& this.page.document.defaultView && !this.page.document.defaultView.closed
//this set of translators is not targeting the same URL as a previous set of translators,
- // because otherwise we want to use the newer set
- && this.page.document.location.href != translate.document.location.href
+ // because otherwise we want to use the newer set,
+ // but only if it's not in a subframe of the previous set
+ && (this.page.document.location.href != translate.document.location.href ||
+ Zotero.Utilities.Internal.isIframeOf(translate.document.defaultView, this.page.document.defaultView))
//the best translator we had was of higher priority than the new set
&& (this.page.translators[0].priority < translators[0].priority
//or the priority was the same, but...
@@ -823,11 +825,15 @@ Zotero_Browser.Tab.prototype._translatorsAvailable = function(translate, transla
|| translate.document.defaultView !== this.page.document.defaultView.top)
))
) {
+ Zotero.debug("Translate: a better translator was already found for this page");
return; //keep what we had
} else {
this.clear(); //clear URL bar icon
}
+ Zotero.debug("Translate: found translators for page\n"
+ + "Best translator: " + translators[0].label + " with priority " + translators[0].priority);
+
this.page.translate = translate;
this.page.translators = translators;
this.page.document = translate.document;
@@ -839,6 +845,8 @@ Zotero_Browser.Tab.prototype._translatorsAvailable = function(translate, transla
this._attemptLocalFileImport(translate.document);
}
+ if(!translators || !translators.length) Zotero.debug("Translate: No translators found");
+
Zotero_Browser.updateStatus();
}
diff --git a/chrome/content/zotero/xpcom/utilities_internal.js b/chrome/content/zotero/xpcom/utilities_internal.js
@@ -301,6 +301,19 @@ Zotero.Utilities.Internal = {
return null;
}
return str;
+ },
+
+ /**
+ * Determine if one Window is a descendant of another Window
+ * @param {DOMWindow} suspected child window
+ * @param {DOMWindow} suspected parent window
+ * @return {boolean}
+ */
+ "isIframeOf":function isIframeOf(childWindow, parentWindow) {
+ while(childWindow.parent !== childWindow) {
+ childWindow = childWindow.parent;
+ if(childWindow === parentWindow) return true;
+ }
}
}