зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1173754 - Add a restrict token for search suggestions in the awesomebar. r=mak
This commit is contained in:
Родитель
2654623ec6
Коммит
476f8f0476
|
@ -340,6 +340,7 @@ pref("browser.urlbar.restrict.bookmark", "*");
|
|||
pref("browser.urlbar.restrict.tag", "+");
|
||||
pref("browser.urlbar.restrict.openpage", "%");
|
||||
pref("browser.urlbar.restrict.typed", "~");
|
||||
pref("browser.urlbar.restrict.searches", "$");
|
||||
pref("browser.urlbar.match.title", "#");
|
||||
pref("browser.urlbar.match.url", "@");
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ const PREF_RESTRICT_BOOKMARKS = [ "restrict.bookmark", "*" ];
|
|||
const PREF_RESTRICT_TYPED = [ "restrict.typed", "~" ];
|
||||
const PREF_RESTRICT_TAG = [ "restrict.tag", "+" ];
|
||||
const PREF_RESTRICT_SWITCHTAB = [ "restrict.openpage", "%" ];
|
||||
const PREF_RESTRICT_SEARCHES = [ "restrict.searces", "$" ];
|
||||
const PREF_MATCH_TITLE = [ "match.title", "#" ];
|
||||
const PREF_MATCH_URL = [ "match.url", "@" ];
|
||||
|
||||
|
@ -403,6 +404,7 @@ XPCOMUtils.defineLazyGetter(this, "Prefs", () => {
|
|||
store.restrictTypedToken = prefs.get(...PREF_RESTRICT_TYPED);
|
||||
store.restrictTagToken = prefs.get(...PREF_RESTRICT_TAG);
|
||||
store.restrictOpenPageToken = prefs.get(...PREF_RESTRICT_SWITCHTAB);
|
||||
store.restrictSearchesToken = prefs.get(...PREF_RESTRICT_SEARCHES);
|
||||
store.matchTitleToken = prefs.get(...PREF_MATCH_TITLE);
|
||||
store.matchURLToken = prefs.get(...PREF_MATCH_URL);
|
||||
store.suggestHistory = prefs.get(...PREF_SUGGEST_HISTORY);
|
||||
|
@ -449,7 +451,8 @@ XPCOMUtils.defineLazyGetter(this, "Prefs", () => {
|
|||
[ store.restrictOpenPageToken, "openpage" ],
|
||||
[ store.matchTitleToken, "title" ],
|
||||
[ store.matchURLToken, "url" ],
|
||||
[ store.restrictTypedToken, "typed" ]
|
||||
[ store.restrictTypedToken, "typed" ],
|
||||
[ store.restrictSearchesToken, "searches" ],
|
||||
]);
|
||||
|
||||
// Synchronize suggest.* prefs with autocomplete.enabled every time
|
||||
|
@ -837,10 +840,15 @@ Search.prototype = {
|
|||
if (this.hasBehavior("searches")) {
|
||||
this._searchSuggestionController =
|
||||
PlacesSearchAutocompleteProvider.getSuggestionController(
|
||||
this._originalSearchString,
|
||||
this._searchTokens.join(" "),
|
||||
this._inPrivateWindow,
|
||||
Prefs.maxRichResults
|
||||
);
|
||||
if (this.hasBehavior("restrict")) {
|
||||
// We're done if we're restricting to search suggestions.
|
||||
yield this._consumeAllSearchSuggestions();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
yield this._sleep(Math.round(Prefs.delay / 2));
|
||||
|
@ -877,6 +885,10 @@ Search.prototype = {
|
|||
|
||||
// If we still don't have enough results, fill the remaining space with
|
||||
// search suggestions.
|
||||
yield this._consumeAllSearchSuggestions();
|
||||
}),
|
||||
|
||||
_consumeAllSearchSuggestions: Task.async(function* () {
|
||||
if (this._searchSuggestionController && this.pending) {
|
||||
yield this._searchSuggestionController.fetchCompletePromise;
|
||||
while (this.pending && this._maybeAddSearchSuggestionMatch());
|
||||
|
|
|
@ -3,6 +3,7 @@ Cu.import("resource://gre/modules/FormHistory.jsm");
|
|||
const ENGINE_NAME = "engine-suggestions.xml";
|
||||
const SERVER_PORT = 9000;
|
||||
const SUGGEST_PREF = "browser.urlbar.suggest.searches";
|
||||
const SUGGEST_RESTRICT_TOKEN = "$";
|
||||
|
||||
// Set this to some other function to change how the server converts search
|
||||
// strings into suggestions.
|
||||
|
@ -145,3 +146,98 @@ add_task(function* suffixMatch() {
|
|||
suggestionsFromSearchString = oldFn;
|
||||
yield cleanup();
|
||||
});
|
||||
|
||||
add_task(function* restrictToken() {
|
||||
Services.prefs.setBoolPref(SUGGEST_PREF, true);
|
||||
|
||||
// Add a visit and a bookmark. Actually, make the bookmark visited too so
|
||||
// that it's guaranteed, with its higher frecency, to appear above the search
|
||||
// suggestions.
|
||||
yield PlacesTestUtils.addVisits([
|
||||
{
|
||||
uri: NetUtil.newURI("http://example.com/hello-visit"),
|
||||
title: "hello visit",
|
||||
},
|
||||
{
|
||||
uri: NetUtil.newURI("http://example.com/hello-bookmark"),
|
||||
title: "hello bookmark",
|
||||
},
|
||||
]);
|
||||
|
||||
yield addBookmark({
|
||||
uri: NetUtil.newURI("http://example.com/hello-bookmark"),
|
||||
title: "hello bookmark",
|
||||
});
|
||||
|
||||
// Do an unrestricted search to make sure everything appears in it, including
|
||||
// the visit and bookmark.
|
||||
let searchStr = "hello";
|
||||
yield check_autocomplete({
|
||||
search: searchStr,
|
||||
matches: [
|
||||
{
|
||||
uri: NetUtil.newURI("http://example.com/hello-visit"),
|
||||
title: "hello visit",
|
||||
},
|
||||
{
|
||||
uri: NetUtil.newURI("http://example.com/hello-bookmark"),
|
||||
title: "hello bookmark",
|
||||
style: ["bookmark"],
|
||||
},
|
||||
{
|
||||
uri: makeActionURI(("searchengine"), {
|
||||
engineName: ENGINE_NAME,
|
||||
input: searchStr,
|
||||
searchQuery: searchStr,
|
||||
searchSuggestion: "hello foo",
|
||||
}),
|
||||
title: ENGINE_NAME,
|
||||
style: ["action", "searchengine"],
|
||||
icon: "",
|
||||
},
|
||||
{
|
||||
uri: makeActionURI(("searchengine"), {
|
||||
engineName: ENGINE_NAME,
|
||||
input: searchStr,
|
||||
searchQuery: searchStr,
|
||||
searchSuggestion: "hello bar",
|
||||
}),
|
||||
title: ENGINE_NAME,
|
||||
style: ["action", "searchengine"],
|
||||
icon: "",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// Now do a restricted search to make sure only suggestions appear.
|
||||
searchStr = SUGGEST_RESTRICT_TOKEN + " hello";
|
||||
yield check_autocomplete({
|
||||
search: searchStr,
|
||||
matches: [
|
||||
{
|
||||
uri: makeActionURI(("searchengine"), {
|
||||
engineName: ENGINE_NAME,
|
||||
input: searchStr,
|
||||
searchQuery: searchStr,
|
||||
searchSuggestion: "hello foo",
|
||||
}),
|
||||
title: ENGINE_NAME,
|
||||
style: ["action", "searchengine"],
|
||||
icon: "",
|
||||
},
|
||||
{
|
||||
uri: makeActionURI(("searchengine"), {
|
||||
engineName: ENGINE_NAME,
|
||||
input: searchStr,
|
||||
searchQuery: searchStr,
|
||||
searchSuggestion: "hello bar",
|
||||
}),
|
||||
title: ENGINE_NAME,
|
||||
style: ["action", "searchengine"],
|
||||
icon: "",
|
||||
}
|
||||
],
|
||||
});
|
||||
|
||||
yield cleanup();
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче