зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1645324 - Move the omnibox heuristic result to the omnibox provider. r=adw
Differential Revision: https://phabricator.services.mozilla.com/D80295
This commit is contained in:
Родитель
2830a9e611
Коммит
0b5b53d828
|
@ -47,6 +47,7 @@ const heuristicOrder = [
|
|||
// Test providers are handled in sort(),
|
||||
// Extension providers are handled in sort(),
|
||||
"UrlbarProviderSearchTips",
|
||||
"Omnibox",
|
||||
"UnifiedComplete",
|
||||
"HeuristicFallback",
|
||||
];
|
||||
|
|
|
@ -55,7 +55,7 @@ class ProviderOmnibox extends UrlbarProvider {
|
|||
* @returns {integer} one of the types from UrlbarUtils.PROVIDER_TYPE.*
|
||||
*/
|
||||
get type() {
|
||||
return UrlbarUtils.PROVIDER_TYPE.EXTENSION;
|
||||
return UrlbarUtils.PROVIDER_TYPE.HEURISTIC;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -120,8 +120,25 @@ class ProviderOmnibox extends UrlbarProvider {
|
|||
let instance = {};
|
||||
this.queries.set(queryContext, instance);
|
||||
|
||||
// Fetch heuristic result.
|
||||
let keyword = queryContext.tokens[0].value;
|
||||
let description = ExtensionSearchHandler.getDescription(keyword);
|
||||
let heuristicResult = new UrlbarResult(
|
||||
UrlbarUtils.RESULT_TYPE.OMNIBOX,
|
||||
UrlbarUtils.RESULT_SOURCE.OTHER_NETWORK,
|
||||
...UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, {
|
||||
title: [description, UrlbarUtils.HIGHLIGHT.TYPED],
|
||||
content: [queryContext.searchString, UrlbarUtils.HIGHLIGHT.TYPED],
|
||||
keyword: [queryContext.tokens[0].value, UrlbarUtils.HIGHLIGHT.TYPED],
|
||||
icon: UrlbarUtils.ICON.EXTENSION,
|
||||
})
|
||||
);
|
||||
heuristicResult.heuristic = true;
|
||||
addCallback(this, heuristicResult);
|
||||
|
||||
// Fetch non-heuristic results.
|
||||
let data = {
|
||||
keyword: queryContext.tokens[0].value,
|
||||
keyword,
|
||||
text: queryContext.searchString,
|
||||
inPrivateWindow: queryContext.isPrivate,
|
||||
};
|
||||
|
@ -130,6 +147,9 @@ class ProviderOmnibox extends UrlbarProvider {
|
|||
suggestions => {
|
||||
for (let suggestion of suggestions) {
|
||||
let content = `${queryContext.tokens[0].value} ${suggestion.content}`;
|
||||
if (content == heuristicResult.payload.content) {
|
||||
continue;
|
||||
}
|
||||
let result = new UrlbarResult(
|
||||
UrlbarUtils.RESULT_TYPE.OMNIBOX,
|
||||
UrlbarUtils.RESULT_SOURCE.OTHER_NETWORK,
|
||||
|
|
|
@ -263,17 +263,6 @@ function makeUrlbarResult(tokens, info) {
|
|||
})
|
||||
);
|
||||
}
|
||||
case "extension":
|
||||
return new UrlbarResult(
|
||||
UrlbarUtils.RESULT_TYPE.OMNIBOX,
|
||||
UrlbarUtils.RESULT_SOURCE.OTHER_NETWORK,
|
||||
...UrlbarResult.payloadAndSimpleHighlights(tokens, {
|
||||
title: [info.comment, UrlbarUtils.HIGHLIGHT.TYPED],
|
||||
content: [action.params.content, UrlbarUtils.HIGHLIGHT.TYPED],
|
||||
keyword: [action.params.keyword, UrlbarUtils.HIGHLIGHT.TYPED],
|
||||
icon: [info.icon],
|
||||
})
|
||||
);
|
||||
case "remotetab":
|
||||
return new UrlbarResult(
|
||||
UrlbarUtils.RESULT_TYPE.REMOTE_TAB,
|
||||
|
|
|
@ -340,7 +340,6 @@ XPCOMUtils.defineLazyGlobalGetters(this, ["fetch"]);
|
|||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
AboutPagesUtils: "resource://gre/modules/AboutPagesUtils.jsm",
|
||||
BrowserUtils: "resource://gre/modules/BrowserUtils.jsm",
|
||||
ExtensionSearchHandler: "resource://gre/modules/ExtensionSearchHandler.jsm",
|
||||
ObjectUtils: "resource://gre/modules/ObjectUtils.jsm",
|
||||
PlacesRemoteTabsAutocompleteProvider:
|
||||
"resource://gre/modules/PlacesRemoteTabsAutocompleteProvider.jsm",
|
||||
|
@ -760,9 +759,9 @@ function Search(
|
|||
// actually the first thing in the search string. If a prefix or restriction
|
||||
// character occurs first, then the heurstic token is null. We use the
|
||||
// heuristic token to help determine the heuristic result. It may be a Places
|
||||
// keyword, a search engine alias, an extension keyword, or simply a URL or
|
||||
// part of the search string the user has typed. We won't know until we
|
||||
// create the heuristic result.
|
||||
// keyword, a search engine alias, or simply a URL or part of the search
|
||||
// string the user has typed. We won't know until we create the heuristic
|
||||
// result.
|
||||
let firstToken = !!this._searchTokens.length && this._searchTokens[0].value;
|
||||
this._heuristicToken =
|
||||
firstToken && this._trimmedOriginalSearchString.startsWith(firstToken)
|
||||
|
@ -1272,16 +1271,6 @@ Search.prototype = {
|
|||
// We always try to make the first result a special "heuristic" result. The
|
||||
// heuristics below determine what type of result it will be, if any.
|
||||
|
||||
if (this._heuristicToken) {
|
||||
// It may be a keyword registered by an extension.
|
||||
let matched = await this._matchExtensionHeuristicResult(
|
||||
this._heuristicToken
|
||||
);
|
||||
if (matched) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.pending && this._enableActions && this._heuristicToken) {
|
||||
// It may be a search engine with an alias - which works like a keyword.
|
||||
let matched = await this._matchSearchEngineAlias(this._heuristicToken);
|
||||
|
@ -1369,18 +1358,6 @@ Search.prototype = {
|
|||
return gotResult;
|
||||
},
|
||||
|
||||
_matchExtensionHeuristicResult(keyword) {
|
||||
if (
|
||||
ExtensionSearchHandler.isKeywordRegistered(keyword) &&
|
||||
substringAfter(this._originalSearchString, keyword)
|
||||
) {
|
||||
let description = ExtensionSearchHandler.getDescription(keyword);
|
||||
this._addExtensionMatch(this._originalSearchString, description);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
async _matchPlacesKeyword(keyword) {
|
||||
let entry = await PlacesUtils.keywords.fetch(keyword);
|
||||
if (!entry) {
|
||||
|
@ -1521,20 +1498,6 @@ Search.prototype = {
|
|||
return true;
|
||||
},
|
||||
|
||||
_addExtensionMatch(content, comment) {
|
||||
this._addMatch({
|
||||
value: makeActionUrl("extension", {
|
||||
content,
|
||||
keyword: this._heuristicToken,
|
||||
}),
|
||||
comment,
|
||||
icon: "chrome://browser/content/extension.svg",
|
||||
style: "action extension",
|
||||
frecency: Infinity,
|
||||
type: UrlbarUtils.RESULT_GROUP.EXTENSION,
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds a search engine match.
|
||||
*
|
||||
|
|
Загрузка…
Ссылка в новой задаче