From fcc55d0ca0642f76010709ea1cb1737186fdbbe9 Mon Sep 17 00:00:00 2001 From: Ursula Sarracini Date: Tue, 31 May 2016 11:06:30 -0400 Subject: [PATCH] feat(addon): #764 SearchProvider manages your engines --- common/action-manager.js | 2 ++ lib/ActivityStreams.js | 13 +++++++++++++ lib/SearchProvider.js | 12 ++++++++++++ 3 files changed, 27 insertions(+) diff --git a/common/action-manager.js b/common/action-manager.js index 9ff3e6dcfb..68f8eb29fe 100644 --- a/common/action-manager.js +++ b/common/action-manager.js @@ -23,6 +23,8 @@ const am = new ActionManager([ "RECEIVE_CURRENT_ENGINE", "SEARCH_STATE_REQUEST", "SEARCH_STATE_RESPONSE", + "NOTIFY_MANAGE_ENGINES", + "NOTIFY_CYCLE_CURRENT_ENGINE", "NOTIFY_ROUTE_CHANGE", "NOTIFY_PERFORMANCE", "NOTIFY_USER_EVENT" diff --git a/lib/ActivityStreams.js b/lib/ActivityStreams.js index 6be14a71ec..ae0511a985 100644 --- a/lib/ActivityStreams.js +++ b/lib/ActivityStreams.js @@ -182,6 +182,15 @@ ActivityStreams.prototype = { SearchProvider.search.performSearch(browser, searchData); }); break; + case am.type("NOTIFY_MANAGE_ENGINES"): // eslint-disable-line + let win = windowMediator.getMostRecentWindow("navigator:browser"); + let gBrowser = win.getBrowser(); + let browser = gBrowser.selectedBrowser; + SearchProvider.search.manageEngines(browser); + break; + case am.type("NOTIFY_CYCLE_CURRENT_ENGINE"): + SearchProvider.search.asyncCycleEngine(msg.data); + break; } }, @@ -249,6 +258,8 @@ ActivityStreams.prototype = { this.on(am.type("NOTIFY_UNBLOCK_ALL"), this._respondToPlacesRequests); this.on(am.type("NOTIFY_BOOKMARK_DELETE"), this._respondToPlacesRequests); this.on(am.type("SEARCH_STATE_REQUEST"), this._respondToSearchRequests); + this.on(am.type("NOTIFY_MANAGE_ENGINES"), this._respondToSearchRequests); + this.on(am.type("NOTIFY_CYCLE_CURRENT_ENGINE"), this._respondToSearchRequests); this.on(am.type("NOTIFY_PERFORM_SEARCH"), this._respondToSearchRequests); this.on(am.type("NOTIFY_ROUTE_CHANGE"), this._onRouteChange); this.on(am.type("NOTIFY_USER_EVENT"), this._handleUserEvent); @@ -276,6 +287,8 @@ ActivityStreams.prototype = { this.off(am.type("NOTIFY_UNBLOCK_ALL"), this._respondToPlacesRequests); this.off(am.type("NOTIFY_BOOKMARK_DELETE"), this._respondToPlacesRequests); this.off(am.type("SEARCH_STATE_REQUEST"), this._respondToSearchRequests); + this.off(am.type("NOTIFY_MANAGE_ENGINES"), this._respondToSearchRequests); + this.off(am.type("NOTIFY_CYCLE_CURRENT_ENGINE"), this._respondToSearchRequests); this.off(am.type("NOTIFY_PERFORM_SEARCH"), this._respondToSearchRequests); this.off(am.type("NOTIFY_ROUTE_CHANGE"), this._onRouteChange); this.off(am.type("NOTIFY_USER_EVENT"), this._handleUserEvent); diff --git a/lib/SearchProvider.js b/lib/SearchProvider.js index ad389fd093..72afac561a 100644 --- a/lib/SearchProvider.js +++ b/lib/SearchProvider.js @@ -68,6 +68,18 @@ NewTabSearchProvider.prototype = { }.bind(this)); }, + manageEngines(browser) { + const browserWindow = browser.ownerDocument.defaultView; + browserWindow.openPreferences("paneSearch"); + }, + + asyncCycleEngine: Task.async(function*(engineName) { + Services.search.currentEngine = Services.search.getEngineByName(engineName); + let state = yield this.state; + let newEngine = state.currentEngine; + this.emit("CURRENT_ENGINE", newEngine); + }), + performSearch(browser, searchData) { ContentSearch._onMessageSearch({target: browser}, searchData); },