From b2536d0df5e394f0842a4a2982cce055ffda2a3c Mon Sep 17 00:00:00 2001 From: Gavin Sharp Date: Fri, 20 Aug 2010 17:40:16 -0400 Subject: [PATCH] Bug 587691: need a way to access the original default engine (the normal "defaultEngine" can change if the original is hidden by the user), r=Ryan, a=blocker --- netwerk/base/public/nsIBrowserSearchService.idl | 12 +++++++++--- toolkit/components/search/nsSearchService.js | 16 +++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/netwerk/base/public/nsIBrowserSearchService.idl b/netwerk/base/public/nsIBrowserSearchService.idl index 0abac5d7432..9be32e5a58a 100644 --- a/netwerk/base/public/nsIBrowserSearchService.idl +++ b/netwerk/base/public/nsIBrowserSearchService.idl @@ -312,17 +312,23 @@ interface nsIBrowserSearchService : nsISupports void removeEngine(in nsISearchEngine engine); /** - * The default search engine. May be null if there are no visible - * search engines installed. + * The default search engine. Returns the first visible engine if the default + * engine is hidden. May be null if there are no visible search engines. */ readonly attribute nsISearchEngine defaultEngine; /** * The currently active search engine. May be null if there are no visible - * search engines installed. + * search engines. */ attribute nsISearchEngine currentEngine; + /** + * The original default engine. This differs from the "defaultEngine" + * attribute in that it always returns a given build's default engine, + * regardless of whether it is hidden. + */ + readonly attribute nsISearchEngine originalDefaultEngine; }; %{ C++ diff --git a/toolkit/components/search/nsSearchService.js b/toolkit/components/search/nsSearchService.js index 060a3ea39e6..68824250813 100644 --- a/toolkit/components/search/nsSearchService.js +++ b/toolkit/components/search/nsSearchService.js @@ -3356,14 +3356,16 @@ SearchService.prototype = { } }, - get defaultEngine() { + get originalDefaultEngine() { const defPref = BROWSER_SEARCH_PREF + "defaultenginename"; - // Get the default engine - this pref should always exist, but the engine - // might be hidden - this._defaultEngine = this.getEngineByName(getLocalizedPref(defPref, "")); - if (!this._defaultEngine || this._defaultEngine.hidden) - this._defaultEngine = this._getSortedEngines(false)[0] || null; - return this._defaultEngine; + return this.getEngineByName(getLocalizedPref(defPref, "")); + }, + + get defaultEngine() { + let defaultEngine = this.originalDefaultEngine; + if (!defaultEngine || defaultEngine.hidden) + defaultEngine = this._getSortedEngines(false)[0] || null; + return defaultEngine; }, get currentEngine() {