Created
October 15, 2019 17:32
-
-
Save mikedeboer/cb9f80b0d2959108b6574618209961ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/browser/base/content/contentSearchUI.js b/browser/base/content/contentSearchUI.js | |
--- a/browser/base/content/contentSearchUI.js | |
+++ b/browser/base/content/contentSearchUI.js | |
@@ -46,17 +46,17 @@ this.ContentSearchUIController = (functi | |
searchPurpose, | |
isPrivateWindow, | |
idPrefix = "" | |
) { | |
this.input = inputElement; | |
this._idPrefix = idPrefix; | |
this._healthReportKey = healthReportKey; | |
this._searchPurpose = searchPurpose; | |
- this._isPrivateWindow = isPrivateWindow; | |
+ this._isPrivateWindow = false; | |
let tableID = idPrefix + "searchSuggestionTable"; | |
this.input.autocomplete = "off"; | |
this.input.setAttribute("aria-autocomplete", "true"); | |
this.input.setAttribute("aria-controls", tableID); | |
tableParent.appendChild(this._makeTable(tableID)); | |
this.input.addEventListener("keydown", this); | |
@@ -627,16 +627,18 @@ this.ContentSearchUIController = (functi | |
_onMsgSuggestionsCancelled() { | |
if (!this._table.hidden) { | |
this._hideSuggestions(); | |
} | |
}, | |
_onMsgState(state) { | |
+ this._isPrivateWindow = state.isPrivateWindow; | |
+ | |
this.engines = state.engines; | |
let currentEngine = state.currentEngine; | |
if (this._isPrivateWindow) { | |
currentEngine = state.currentPrivateEngine; | |
} | |
// No point updating the default engine (and the header) if there's no change. | |
diff --git a/browser/modules/ContentSearch.jsm b/browser/modules/ContentSearch.jsm | |
--- a/browser/modules/ContentSearch.jsm | |
+++ b/browser/modules/ContentSearch.jsm | |
@@ -7,31 +7,23 @@ var EXPORTED_SYMBOLS = ["ContentSearch"] | |
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); | |
const { XPCOMUtils } = ChromeUtils.import( | |
"resource://gre/modules/XPCOMUtils.jsm" | |
); | |
XPCOMUtils.defineLazyGlobalGetters(this, ["XMLHttpRequest"]); | |
-ChromeUtils.defineModuleGetter( | |
- this, | |
- "FormHistory", | |
- "resource://gre/modules/FormHistory.jsm" | |
-); | |
-ChromeUtils.defineModuleGetter( | |
- this, | |
- "PrivateBrowsingUtils", | |
- "resource://gre/modules/PrivateBrowsingUtils.jsm" | |
-); | |
-ChromeUtils.defineModuleGetter( | |
- this, | |
- "SearchSuggestionController", | |
- "resource://gre/modules/SearchSuggestionController.jsm" | |
-); | |
+XPCOMUtils.defineLazyModuleGetters(this, { | |
+ BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm", | |
+ FormHistory: "resource://gre/modules/FormHistory.jsm", | |
+ PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.jsm", | |
+ SearchSuggestionController: | |
+ "resource://gre/modules/SearchSuggestionController.jsm", | |
+}); | |
const INBOUND_MESSAGE = "ContentSearch"; | |
const OUTBOUND_MESSAGE = INBOUND_MESSAGE; | |
const MAX_LOCAL_SUGGESTIONS = 3; | |
const MAX_SUGGESTIONS = 6; | |
/** | |
* ContentSearch receives messages named INBOUND_MESSAGE and sends messages | |
@@ -358,17 +350,17 @@ var ContentSearch = { | |
handleError: err => { | |
Cu.reportError("Error adding form history entry: " + err); | |
}, | |
} | |
); | |
return true; | |
}, | |
- async currentStateObj() { | |
+ async currentStateObj(window) { | |
let state = { | |
engines: [], | |
currentEngine: await this._currentEngineObj(false), | |
currentPrivateEngine: await this._currentEngineObj(true), | |
}; | |
let pref = Services.prefs.getCharPref("browser.search.hiddenOneOffs"); | |
let hiddenList = pref ? pref.split(",") : []; | |
@@ -378,16 +370,22 @@ var ContentSearch = { | |
state.engines.push({ | |
name: engine.name, | |
iconData, | |
hidden: hiddenList.includes(engine.name), | |
identifier: engine.identifier, | |
}); | |
} | |
+ | |
+ if (!window) { | |
+ window = BrowserWindowTracker.getTopWindow({ private: true }); | |
+ } | |
+ state.isPrivateWindow = PrivateBrowsingUtils.isContentWindowPrivate(window); | |
+ | |
return state; | |
}, | |
_processEventQueue() { | |
if (this._currentEventPromise || !this._eventQueue.length) { | |
return; | |
} | |
@@ -436,17 +434,17 @@ var ContentSearch = { | |
await this[methodName](msg, msg.data.data); | |
if (!Cu.isDeadWrapper(msg.target)) { | |
msg.target.removeEventListener("SwapDocShells", msg, true); | |
} | |
} | |
}, | |
_onMessageGetState(msg, data) { | |
- return this.currentStateObj().then(state => { | |
+ return this.currentStateObj(msg.target.ownerGlobal).then(state => { | |
this._reply(msg, "State", state); | |
}); | |
}, | |
_onMessageGetStrings(msg, data) { | |
this._reply(msg, "Strings", this.searchSuggestionUIStrings); | |
}, | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment