From: Mike Hommey Date: Sun, 15 Apr 2012 11:38:32 +0200 Subject: Handle transition to /etc//searchplugins more gracefully Closes: #666675. --- toolkit/components/search/nsSearchService.js | 32 ++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/toolkit/components/search/nsSearchService.js b/toolkit/components/search/nsSearchService.js index 2807835..8fa31ca 100644 --- a/toolkit/components/search/nsSearchService.js +++ b/toolkit/components/search/nsSearchService.js @@ -710,6 +710,7 @@ function getMozParamPref(prefName) * * @see nsIBrowserSearchService.idl */ +let gForceCacheInvalidation = false; let gEnginesLoaded = false; function notifyAction(aEngine, aVerb) { if (gEnginesLoaded) { @@ -2012,6 +2013,20 @@ Engine.prototype = { **/ _initWithJSON: function SRCH_ENG__initWithJSON(aJson) { this.__id = aJson._id; + try { + let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile); + file.initWithPath(this.__id); + let loadDirs = []; + let locations = getDir(NS_APP_SEARCH_DIR_LIST, Ci.nsISimpleEnumerator); + while (locations.hasMoreElements()) { + let dir = locations.getNext().QueryInterface(Ci.nsIFile); + loadDirs.push(dir); + } + if (loadDirs.some(function (element) element.equals(file.parent))) { + this.__id = "[app]/" + file.leafName; + gForceCacheInvalidation = true; + } + } catch (e) { } this._name = aJson._name; this._description = aJson.description; if (aJson._hasPreferredIcon == undefined) @@ -2306,8 +2321,19 @@ Engine.prototype = { this.__installLocation = SEARCH_APP_DIR; else if (this._file.parent.equals(getDir(NS_APP_USER_SEARCH_DIR))) this.__installLocation = SEARCH_PROFILE_DIR; - else - this.__installLocation = SEARCH_IN_EXTENSION; + else { + let loadDirs = []; + let locations = getDir(NS_APP_SEARCH_DIR_LIST, Ci.nsISimpleEnumerator); + while (locations.hasMoreElements()) { + let dir = locations.getNext().QueryInterface(Ci.nsIFile); + loadDirs.push(dir); + } + let parent = this._file.parent; + if (loadDirs.some(function (element) !element.equals(parent))) + this.__installLocation = SEARCH_APP_DIR; + else + this.__installLocation = SEARCH_IN_EXTENSION; + } } return this.__installLocation; @@ -2471,6 +2497,8 @@ function SearchService() { } gEnginesLoaded = true; this._addObservers(); + if (gForceCacheInvalidation) + this._batchCacheInvalidation(); } SearchService.prototype = { classID: Components.ID("{7319788a-fe93-4db3-9f39-818cf08f4256}"),