diff --git a/toolkit/components/thumbnails/PageThumbUtils.jsm b/toolkit/components/thumbnails/PageThumbUtils.jsm index 521adf57b3df..237bdb349749 100644 --- a/toolkit/components/thumbnails/PageThumbUtils.jsm +++ b/toolkit/components/thumbnails/PageThumbUtils.jsm @@ -344,7 +344,7 @@ var PageThumbUtils = { }, shouldStoreContentThumbnail(aDocument, aDocShell) { - if (BrowserUtils.isToolbarVisible(aDocShell, "findbar")) { + if (BrowserUtils.isFindbarVisible(aDocShell)) { return false; } diff --git a/toolkit/modules/BrowserUtils.jsm b/toolkit/modules/BrowserUtils.jsm index 71dcf6abdc10..d340bfdd3b82 100644 --- a/toolkit/modules/BrowserUtils.jsm +++ b/toolkit/modules/BrowserUtils.jsm @@ -266,60 +266,12 @@ var BrowserUtils = { ); }, - _visibleToolbarsMap: new WeakMap(), - - /** - * Return true if any or a specific toolbar that interacts with the content - * document is visible. - * - * @param {nsIDocShell} docShell The docShell instance that a toolbar should - * be interacting with - * @param {String} which Identifier of a specific toolbar - * @return {Boolean} - */ - isToolbarVisible(docShell, which) { - let window = this.getRootWindow(docShell); - if (!this._visibleToolbarsMap.has(window)) { - return false; - } - let toolbars = this._visibleToolbarsMap.get(window); - return !!toolbars && toolbars.has(which); - }, - - /** - * Track whether a toolbar is visible for a given a docShell. - * - * @param {nsIDocShell} docShell The docShell instance that a toolbar should - * be interacting with - * @param {String} which Identifier of a specific toolbar - * @param {Boolean} [visible] Whether the toolbar is visible. Optional, - * defaults to `true`. - */ - trackToolbarVisibility(docShell, which, visible = true) { - // We have to get the root window object, because XPConnect WrappedNatives - // can't be used as WeakMap keys. - let window = this.getRootWindow(docShell); - let toolbars = this._visibleToolbarsMap.get(window); - if (!toolbars) { - toolbars = new Set(); - this._visibleToolbarsMap.set(window, toolbars); - } - if (!visible) { - toolbars.delete(which); - } else { - toolbars.add(which); - } - }, - - /** - * Retrieve the root window object (i.e. the top-most content global) for a - * specific docShell object. - * - * @param {nsIDocShell} docShell - * @return {nsIDOMWindow} - */ - getRootWindow(docShell) { - return docShell.browsingContext.top.window; + isFindbarVisible(docShell) { + const FINDER_JSM = "resource://gre/modules/Finder.jsm"; + return ( + Cu.isModuleLoaded(FINDER_JSM) && + ChromeUtils.import(FINDER_JSM).Finder.isFindbarVisible(docShell) + ); }, /** diff --git a/toolkit/modules/Finder.jsm b/toolkit/modules/Finder.jsm index bf544fe09246..6d5d8ed0f32c 100644 --- a/toolkit/modules/Finder.jsm +++ b/toolkit/modules/Finder.jsm @@ -15,11 +15,6 @@ const { XPCOMUtils } = ChromeUtils.import( const { Rect } = ChromeUtils.import("resource://gre/modules/Geometry.jsm"); const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); -ChromeUtils.defineModuleGetter( - this, - "BrowserUtils", - "resource://gre/modules/BrowserUtils.jsm" -); ChromeUtils.defineModuleGetter( this, "FinderIterator", @@ -42,6 +37,8 @@ XPCOMUtils.defineLazyServiceGetter( const kSelectionMaxLen = 150; const kMatchesCountLimitPref = "accessibility.typeaheadfind.matchesCountLimit"; +const activeFinderRoots = new WeakSet(); + function Finder(docShell) { this._fastFind = Cc["@mozilla.org/typeaheadfind;1"].createInstance( Ci.nsITypeAheadFind @@ -492,11 +489,15 @@ Finder.prototype = { this.enableSelection(); this.highlighter.highlight(false); this.iterator.reset(); - BrowserUtils.trackToolbarVisibility(this._docShell, "findbar", false); + activeFinderRoots.delete(this._docShell.browsingContext.top); }, onFindbarOpen() { - BrowserUtils.trackToolbarVisibility(this._docShell, "findbar", true); + activeFinderRoots.add(this._docShell.browsingContext.top); + }, + + isFindbarVisible(docShell) { + return activeFinderRoots.has(docShell.browsingContext.top); }, onModalHighlightChange(useModalHighlight) {