--- a/toolkit/components/places/UnifiedComplete.js
+++ b/toolkit/components/places/UnifiedComplete.js
@@ -27,24 +27,16 @@ const PREF_ENABLED = [ "a
const PREF_AUTOFILL = [ "autoFill", true ];
const PREF_AUTOFILL_TYPED = [ "autoFill.typed", true ];
const PREF_AUTOFILL_SEARCHENGINES = [ "autoFill.searchEngines", false ];
const PREF_RESTYLESEARCHES = [ "restyleSearches", false ];
const PREF_DELAY = [ "delay", 50 ];
const PREF_BEHAVIOR = [ "matchBehavior", MATCH_BOUNDARY_ANYWHERE ];
const PREF_FILTER_JS = [ "filter.javascript", true ];
const PREF_MAXRESULTS = [ "maxRichResults", 25 ];
-const PREF_RESTRICT_HISTORY = [ "restrict.history", "^" ];
-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.searches", "$" ];
-const PREF_MATCH_TITLE = [ "match.title", "#" ];
-const PREF_MATCH_URL = [ "match.url", "@" ];
const PREF_SUGGEST_HISTORY = [ "suggest.history", true ];
const PREF_SUGGEST_BOOKMARK = [ "suggest.bookmark", true ];
const PREF_SUGGEST_OPENPAGE = [ "suggest.openpage", true ];
const PREF_SUGGEST_HISTORY_ONLYTYPED = [ "suggest.history.onlyTyped", false ];
const PREF_SUGGEST_SEARCHES = [ "suggest.searches", false ];
const PREF_MAX_CHARS_FOR_SUGGEST = [ "maxCharsForSearchSuggestions", 20];
@@ -98,16 +90,30 @@ const QUERYINDEX_BOOKMARKED = 3;
const QUERYINDEX_BOOKMARKTITLE = 4;
const QUERYINDEX_TAGS = 5;
const QUERYINDEX_VISITCOUNT = 6;
const QUERYINDEX_TYPED = 7;
const QUERYINDEX_PLACEID = 8;
const QUERYINDEX_SWITCHTAB = 9;
const QUERYINDEX_FRECENCY = 10;
+// The special characters below can be typed into the urlbar to either restrict
+// the search to visited history, bookmarked, tagged pages; or force a match on
+// just the title text or url.
+const TOKEN_TO_BEHAVIOR_MAP = new Map([
+ ["^", "history"],
+ ["*", "bookmark"],
+ ["+", "tag"],
+ ["%", "openpage"],
+ ["~", "typed"],
+ ["$", "searches"],
+ ["#", "title"],
+ ["@", "url"],
+]);
+
// If a URL starts with one of these prefixes, then we don't provide search
// suggestions for it.
const DISALLOWED_URLLIKE_PREFIXES = [
"http", "https", "ftp"
];
// This SQL query fragment provides the following:
// - whether the entry is bookmarked (QUERYINDEX_BOOKMARKED)
@@ -444,24 +450,16 @@ XPCOMUtils.defineLazyGetter(this, "Prefs
store.autofill = prefs.get(...PREF_AUTOFILL);
store.autofillTyped = prefs.get(...PREF_AUTOFILL_TYPED);
store.autofillSearchEngines = prefs.get(...PREF_AUTOFILL_SEARCHENGINES);
store.restyleSearches = prefs.get(...PREF_RESTYLESEARCHES);
store.delay = prefs.get(...PREF_DELAY);
store.matchBehavior = prefs.get(...PREF_BEHAVIOR);
store.filterJavaScript = prefs.get(...PREF_FILTER_JS);
store.maxRichResults = prefs.get(...PREF_MAXRESULTS);
- store.restrictHistoryToken = prefs.get(...PREF_RESTRICT_HISTORY);
- store.restrictBookmarkToken = prefs.get(...PREF_RESTRICT_BOOKMARKS);
- 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);
store.suggestBookmark = prefs.get(...PREF_SUGGEST_BOOKMARK);
store.suggestOpenpage = prefs.get(...PREF_SUGGEST_OPENPAGE);
store.suggestTyped = prefs.get(...PREF_SUGGEST_HISTORY_ONLYTYPED);
store.suggestSearches = prefs.get(...PREF_SUGGEST_SEARCHES);
store.maxCharsForSearchSuggestions = prefs.get(...PREF_MAX_CHARS_FOR_SUGGEST);
store.preloadedSitesEnabled = prefs.get(...PREF_PRELOADED_SITES_ENABLED);
store.preloadedSitesExpireDays = prefs.get(...PREF_PRELOADED_SITES_EXPIRE_DAYS);
@@ -493,26 +491,16 @@ XPCOMUtils.defineLazyGetter(this, "Prefs
// Validate matchBehavior; default to MATCH_BOUNDARY_ANYWHERE.
if (store.matchBehavior != MATCH_ANYWHERE &&
store.matchBehavior != MATCH_BOUNDARY &&
store.matchBehavior != MATCH_BEGINNING) {
store.matchBehavior = MATCH_BOUNDARY_ANYWHERE;
}
- store.tokenToBehaviorMap = new Map([
- [ store.restrictHistoryToken, "history" ],
- [ store.restrictBookmarkToken, "bookmark" ],
- [ store.restrictTagToken, "tag" ],
- [ store.restrictOpenPageToken, "openpage" ],
- [ store.matchTitleToken, "title" ],
- [ store.matchURLToken, "url" ],
- [ store.restrictTypedToken, "typed" ],
- [ store.restrictSearchesToken, "searches" ],
- ]);
}
let store = {
_ignoreNotifications: false,
observe(subject, topic, data) {
// Avoid re-entrancy when flipping linked preferences.
if (this._ignoreNotifications)
return;
@@ -853,17 +841,17 @@ Search.prototype = {
* @param tokens
* An array of search tokens.
* @return the filtered list of tokens to search with.
*/
filterTokens(tokens) {
let foundToken = false;
// Set the proper behavior while filtering tokens.
for (let i = tokens.length - 1; i >= 0; i--) {
- let behavior = Prefs.tokenToBehaviorMap.get(tokens[i]);
+ let behavior = TOKEN_TO_BEHAVIOR_MAP.get(tokens[i]);
// Don't remove the token if it didn't match, or if it's an action but
// actions are not enabled.
if (behavior && (behavior != "openpage" || this._enableActions)) {
// Don't use the suggest preferences if it is a token search and
// set the restrict bit to 1 (to intersect the search results).
if (!foundToken) {
foundToken = true;
// Do not take into account previous behavior (e.g.: history, bookmark)
--- a/toolkit/components/places/tests/unifiedcomplete/test_special_search.js
+++ b/toolkit/components/places/tests/unifiedcomplete/test_special_search.js
@@ -117,144 +117,70 @@ add_task(async function test_special_sea
search: "foo ^",
matches: [ { uri: uri2, title: "foo.bar" },
{ uri: uri3, title: "title" },
{ uri: uri4, title: "foo.bar" },
{ uri: uri6, title: "foo.bar" },
{ uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] } ]
});
- do_print("foo | -> history (change pref)");
- changeRestrict("history", "|");
- await check_autocomplete({
- search: "foo |",
- matches: [ { uri: uri2, title: "foo.bar" },
- { uri: uri3, title: "title" },
- { uri: uri4, title: "foo.bar" },
- { uri: uri6, title: "foo.bar" },
- { uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] } ]
- });
-
do_print("foo * -> is star");
- resetRestrict("history");
await check_autocomplete({
search: "foo *",
matches: [ { uri: uri6, title: "foo.bar", style: [ "bookmark" ] },
{ uri: uri7, title: "title", style: [ "bookmark" ] },
{ uri: uri8, title: "foo.bar", style: [ "bookmark" ] },
{ uri: uri9, title: "title", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] },
{ uri: uri10, title: "foo.bar", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] },
{ uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] },
{ uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] } ]
});
- do_print("foo | -> is star (change pref)");
- changeRestrict("bookmark", "|");
- await check_autocomplete({
- search: "foo |",
- matches: [ { uri: uri6, title: "foo.bar", style: [ "bookmark" ] },
- { uri: uri7, title: "title", style: [ "bookmark" ] },
- { uri: uri8, title: "foo.bar", style: [ "bookmark" ] },
- { uri: uri9, title: "title", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] },
- { uri: uri10, title: "foo.bar", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] },
- { uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] },
- { uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] } ]
- });
-
do_print("foo # -> in title");
- resetRestrict("bookmark");
await check_autocomplete({
search: "foo #",
matches: [ { uri: uri2, title: "foo.bar" },
{ uri: uri4, title: "foo.bar" },
{ uri: uri6, title: "foo.bar", style: [ "bookmark" ] },
{ uri: uri8, title: "foo.bar", style: [ "bookmark" ] },
{ uri: uri9, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
{ uri: uri10, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] },
{ uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
{ uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] } ]
});
- do_print("foo | -> in title (change pref)");
- changeRestrict("title", "|");
- await check_autocomplete({
- search: "foo |",
- matches: [ { uri: uri2, title: "foo.bar" },
- { uri: uri4, title: "foo.bar" },
- { uri: uri6, title: "foo.bar", style: [ "bookmark" ] },
- { uri: uri8, title: "foo.bar", style: [ "bookmark" ] },
- { uri: uri9, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
- { uri: uri10, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] },
- { uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
- { uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] } ]
- });
-
do_print("foo @ -> in url");
- resetRestrict("title");
await check_autocomplete({
search: "foo @",
matches: [ { uri: uri3, title: "title" },
{ uri: uri4, title: "foo.bar" },
{ uri: uri7, title: "title", style: [ "bookmark" ] },
{ uri: uri8, title: "foo.bar", style: [ "bookmark" ] },
{ uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
{ uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] } ]
});
- do_print("foo | -> in url (change pref)");
- changeRestrict("url", "|");
- await check_autocomplete({
- search: "foo |",
- matches: [ { uri: uri3, title: "title" },
- { uri: uri4, title: "foo.bar" },
- { uri: uri7, title: "title", style: [ "bookmark" ] },
- { uri: uri8, title: "foo.bar", style: [ "bookmark" ] },
- { uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
- { uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] } ]
- });
-
do_print("foo + -> is tag");
- resetRestrict("url");
await check_autocomplete({
search: "foo +",
matches: [ { uri: uri9, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
{ uri: uri10, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] },
{ uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
{ uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] } ]
});
- do_print("foo | -> is tag (change pref)");
- changeRestrict("tag", "|");
- await check_autocomplete({
- search: "foo |",
- matches: [ { uri: uri9, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
- { uri: uri10, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] },
- { uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
- { uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] } ]
- });
-
do_print("foo ~ -> is typed");
- resetRestrict("tag");
await check_autocomplete({
search: "foo ~",
matches: [ { uri: uri4, title: "foo.bar" },
{ uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] } ]
});
- do_print("foo | -> is typed (change pref)");
- changeRestrict("typed", "|");
- await check_autocomplete({
- search: "foo |",
- matches: [ { uri: uri4, title: "foo.bar" },
- { uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] } ]
- });
-
// Test various pairs of special searches
do_print("foo ^ * -> history, is star");
- resetRestrict("typed");
await check_autocomplete({
search: "foo ^ *",
matches: [ { uri: uri6, title: "foo.bar", style: [ "bookmark" ] },
{ uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] } ]
});
do_print("foo ^ # -> history, in title");
await check_autocomplete({