Bug 1588464 - Add a delay to Search in a private window to reduce flicker. r=Standard8

Differential Revision: https://phabricator.services.mozilla.com/D49266

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Marco Bonardo 2019-10-16 22:07:26 +00:00
Родитель eddf83bc7a
Коммит e24c974e7d
1 изменённых файлов: 23 добавлений и 17 удалений

Просмотреть файл

@ -16,6 +16,7 @@ const { XPCOMUtils } = ChromeUtils.import(
XPCOMUtils.defineLazyModuleGetters(this, {
Log: "resource://gre/modules/Log.jsm",
Services: "resource://gre/modules/Services.jsm",
SkippableTimer: "resource:///modules/UrlbarUtils.jsm",
UrlbarProvider: "resource:///modules/UrlbarUtils.jsm",
UrlbarResult: "resource:///modules/UrlbarResult.jsm",
UrlbarUtils: "resource:///modules/UrlbarUtils.jsm",
@ -106,24 +107,29 @@ class ProviderPrivateSearch extends UrlbarProvider {
separatePrivateDefault && engine != (await Services.search.getDefault());
logger.info(`isPrivateEngine: ${isPrivateEngine}`);
addCallback(
this,
new UrlbarResult(
UrlbarUtils.RESULT_TYPE.SEARCH,
UrlbarUtils.RESULT_SOURCE.SEARCH_LOCAL,
...UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, {
engine: [engine.name, UrlbarUtils.HIGHLIGHT.TYPED],
query: [
queryContext.searchString.trim(),
UrlbarUtils.HIGHLIGHT.TYPED,
],
icon: [engine.iconURI ? engine.iconURI.spec : null],
inPrivateWindow: true,
isPrivateEngine,
suggestedIndex: 1,
})
)
// This is a delay added before returning results, to avoid flicker.
// Our result must appear only when all results are searches, but if search
// results arrive first, then the muxer would insert our result and then
// immediately remove it when non-search results arrive.
await new SkippableTimer({
name: "ProviderPrivateSearch",
time: 100,
logger,
}).promise;
let result = new UrlbarResult(
UrlbarUtils.RESULT_TYPE.SEARCH,
UrlbarUtils.RESULT_SOURCE.SEARCH_LOCAL,
...UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, {
engine: [engine.name, UrlbarUtils.HIGHLIGHT.TYPED],
query: [queryContext.searchString.trim(), UrlbarUtils.HIGHLIGHT.TYPED],
icon: [engine.iconURI ? engine.iconURI.spec : null],
inPrivateWindow: true,
isPrivateEngine,
})
);
result.suggestedIndex = 1;
addCallback(this, result);
this.queries.delete(queryContext);
}