Skip to content
This repository has been archived by the owner on Feb 29, 2020. It is now read-only.

Commit

Permalink
feat(addon): #763 SearchProvider adds and removes form history
Browse files Browse the repository at this point in the history
  • Loading branch information
sarracini committed May 30, 2016
1 parent 0ef6ea7 commit 2b2e8e6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions common/action-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const am = new ActionManager([
"RECEIVE_CURRENT_ENGINE",
"SEARCH_STATE_REQUEST",
"SEARCH_STATE_RESPONSE",
"NOTIFY_REMOVE_FORM_HISTORY_ENTRY",
"NOTIFY_ROUTE_CHANGE",
"NOTIFY_PERFORMANCE",
"NOTIFY_USER_EVENT"
Expand Down
9 changes: 9 additions & 0 deletions lib/ActivityStreams.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ ActivityStreams.prototype = {
SearchProvider.search.performSearch(browser, searchData);
});
break;
case am.type("NOTIFY_REMOVE_FORM_HISTORY_ENTRY"): //eslint-disable-line
let win = windowMediator.getMostRecentWindow("navigator:browser");
let gBrowser = win.getBrowser();
let browser = gBrowser.selectedBrowser;
let entry = msg.data;
SearchProvider.search.removeFormHistoryEntry(browser, entry);
break;
}
},

Expand Down Expand Up @@ -249,6 +256,7 @@ 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_REMOVE_FORM_HISTORY_ENTRY"), 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);
Expand Down Expand Up @@ -276,6 +284,7 @@ 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_REMOVE_FORM_HISTORY_ENTRY"), 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);
Expand Down
22 changes: 20 additions & 2 deletions lib/SearchProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ NewTabSearchProvider.prototype = {
Services.obs.removeObserver(this, CURRENT_ENGINE, true);
},

removeFormHistoryEntry(browser, entry) {
if ("removeFormHistoryEntry" in ContentSearch) {
// ContentSearch.jsm from Firefox 49+
ContentSearch.removeFormHistoryEntry({target: browser}, entry);
} else {
// legacy ContentSearch
ContentSearch._onMessageRemoveFormHistoryEntry({target: browser}, entry);
}
},

get state() {
return Task.spawn(function*() {
let state;
Expand All @@ -69,8 +79,16 @@ NewTabSearchProvider.prototype = {
},

performSearch(browser, searchData) {
ContentSearch._onMessageSearch({target: browser}, searchData);
},
if ("performSearch" in ContentSearch) {
// ContentSearch.jsm from Firefox 49+
ContentSearch.performSearch({target: browser}, searchData);
ContentSearch.addFormHistoryEntry({target: browser}, searchData.searchString);
} else {
// legacy ContentSearch
ContentSearch._onMessageSearch({target: browser}, searchData);
ContentSearch._onMessageAddFormHistoryEntry({target: browser}, searchData);
}
},
};

const gSearch = new NewTabSearchProvider();
Expand Down

0 comments on commit 2b2e8e6

Please sign in to comment.