зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1376986 - Remove ability to customize restriction tokens. r=mak
MozReview-Commit-ID: 3JuLExJwF6z --HG-- extra : rebase_source : 1121d85ee910eb7e84a346cb1ead4c591e2ca066
This commit is contained in:
Родитель
e2df9b571a
Коммит
2c8564b0b5
|
@ -314,18 +314,6 @@ pref("browser.urlbar.maxRichResults", 10);
|
|||
// autocomplete.xml.
|
||||
pref("browser.urlbar.delay", 50);
|
||||
|
||||
// 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.
|
||||
pref("browser.urlbar.restrict.history", "^");
|
||||
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", "@");
|
||||
|
||||
// The default behavior for the urlbar can be configured to use any combination
|
||||
// of the match filters with each additional filter adding more results (union).
|
||||
pref("browser.urlbar.suggest.history", true);
|
||||
|
|
|
@ -11,6 +11,8 @@ const TEST_URL_BASES = [
|
|||
"http://example.org/browser/browser/base/content/test/urlbar/moz.png#tabmatch"
|
||||
];
|
||||
|
||||
const RESTRICT_TOKEN_OPENPAGE = "%";
|
||||
|
||||
var gController = Cc["@mozilla.org/autocomplete/controller;1"].
|
||||
getService(Ci.nsIAutoCompleteController);
|
||||
|
||||
|
@ -209,5 +211,5 @@ function checkAutocompleteResults(aExpected, aCallback) {
|
|||
};
|
||||
|
||||
info("Searching open pages.");
|
||||
gController.startSearch(Services.prefs.getCharPref("browser.urlbar.restrict.openpage"));
|
||||
gController.startSearch(RESTRICT_TOKEN_OPENPAGE);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const RESTRICT_TOKEN_OPENPAGE = "%";
|
||||
|
||||
var stateBackup = ss.getBrowserState();
|
||||
|
||||
function cleanup() {
|
||||
|
@ -116,5 +118,5 @@ function checkAutocompleteResults(aExpected, aCallback) {
|
|||
};
|
||||
|
||||
info("Searching open pages.");
|
||||
gController.startSearch(Services.prefs.getCharPref("browser.urlbar.restrict.openpage"));
|
||||
gController.startSearch(RESTRICT_TOKEN_OPENPAGE);
|
||||
}
|
||||
|
|
|
@ -32,14 +32,6 @@ 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 ];
|
||||
|
@ -103,6 +95,20 @@ 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 = [
|
||||
|
@ -449,14 +455,6 @@ XPCOMUtils.defineLazyGetter(this, "Prefs", () => {
|
|||
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);
|
||||
|
@ -498,16 +496,6 @@ XPCOMUtils.defineLazyGetter(this, "Prefs", () => {
|
|||
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 = {
|
||||
|
@ -858,7 +846,7 @@ Search.prototype = {
|
|||
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)) {
|
||||
|
|
|
@ -324,29 +324,6 @@ function removeOpenPages(aUri, aCount = 1, aUserContextId = 0) {
|
|||
}
|
||||
}
|
||||
|
||||
function changeRestrict(aType, aChar) {
|
||||
let branch = "browser.urlbar.";
|
||||
// "title" and "url" are different from everything else, so special case them.
|
||||
if (aType == "title" || aType == "url")
|
||||
branch += "match.";
|
||||
else
|
||||
branch += "restrict.";
|
||||
|
||||
do_print("changing restrict for " + aType + " to '" + aChar + "'");
|
||||
Services.prefs.setCharPref(branch + aType, aChar);
|
||||
}
|
||||
|
||||
function resetRestrict(aType) {
|
||||
let branch = "browser.urlbar.";
|
||||
// "title" and "url" are different from everything else, so special case them.
|
||||
if (aType == "title" || aType == "url")
|
||||
branch += "match.";
|
||||
else
|
||||
branch += "restrict.";
|
||||
|
||||
Services.prefs.clearUserPref(branch + aType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip prefixes from the URI that we don't care about for searching.
|
||||
*
|
||||
|
|
|
@ -122,19 +122,7 @@ add_task(async function test_special_searches() {
|
|||
{ 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" ] },
|
||||
|
@ -146,21 +134,7 @@ add_task(async function test_special_searches() {
|
|||
{ 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" },
|
||||
|
@ -173,22 +147,7 @@ add_task(async function test_special_searches() {
|
|||
{ 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" },
|
||||
|
@ -199,20 +158,7 @@ add_task(async function test_special_searches() {
|
|||
{ 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" ] },
|
||||
|
@ -221,35 +167,15 @@ add_task(async function test_special_searches() {
|
|||
{ 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" ] },
|
||||
|
|
Загрузка…
Ссылка в новой задаче