Commit 809c3a64 authored by manukh's avatar manukh Committed by Commit Bot

[chrome://omnibox] [omnibox] Handle leading whitespace in inputText.

The debug page compares response and request inputTexts to prevent async
responses for old requests from being shown. This comparison did not
consider that responses' inputTexts are trimmed of whitespace.

This CL likewise trims the requests' inputTexts when comparing the two.

Bug: 1045343
Change-Id: I0e0553fcb2c6d9c21cd5c10194b769120824b6a9

NOTRY=true
To skip android-binary-size bot due to a bug (crbug.com/1045024).
Other try-bots have passed.

Change-Id: I0e0553fcb2c6d9c21cd5c10194b769120824b6a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2019927
Commit-Queue: manuk hovanesian <manukh@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#735408}
parent ace61dab
...@@ -86,19 +86,13 @@ class BrowserProxy { ...@@ -86,19 +86,13 @@ class BrowserProxy {
this.lastRequest; this.lastRequest;
} }
/** /**
* @param {!mojom.OmniboxResponse} response * @param {!mojom.OmniboxResponse} response
* @param {boolean} isPageController * @param {boolean} isPageController
*/ */
handleNewAutocompleteResponse(response, isPageController) { handleNewAutocompleteResponse(response, isPageController) {
// Note: Using inputText is a sufficient fix for the way this is used today, const isForLastPageRequest =
// but in principle it would be better to associate requests with responses this.isForLastPageRequest(response.inputText, isPageController);
// using a unique session identifier, for example by rolling an integer each
// time a request is made. Doing so would require extra bookkeeping on the
// host side, so for now we keep it simple.
const isForLastPageRequest = isPageController && this.lastRequest &&
this.lastRequest.inputText === response.inputText;
// When unfocusing the browser omnibox, the autocomplete controller // When unfocusing the browser omnibox, the autocomplete controller
// sends a response with no combined results. This response is ignored // sends a response with no combined results. This response is ignored
...@@ -127,8 +121,7 @@ class BrowserProxy { ...@@ -127,8 +121,7 @@ class BrowserProxy {
handleNewAutocompleteQuery(isPageController, inputText) { handleNewAutocompleteQuery(isPageController, inputText) {
// If the request originated from the debug page and is not for display, // If the request originated from the debug page and is not for display,
// then we don't want to clear the omniboxOutput. // then we don't want to clear the omniboxOutput.
if (isPageController && this.lastRequest && if (this.isForLastPageRequest(inputText, isPageController) &&
this.lastRequest.inputText === inputText &&
this.lastRequest.display || this.lastRequest.display ||
omniboxInput.connectWindowOmnibox && !isPageController) { omniboxInput.connectWindowOmnibox && !isPageController) {
omniboxOutput.prepareNewQuery(); omniboxOutput.prepareNewQuery();
...@@ -159,6 +152,21 @@ class BrowserProxy { ...@@ -159,6 +152,21 @@ class BrowserProxy {
pageClassification); pageClassification);
}); });
} }
/**
* @param {string} inputText
* @param {boolean} isPageController
* @return {boolean}
*/
isForLastPageRequest(inputText, isPageController) {
// Note: Using inputText is a sufficient fix for the way this is used today,
// but in principle it would be better to associate requests with responses
// using a unique session identifier, for example by rolling an integer each
// time a request is made. Doing so would require extra bookkeeping on the
// host side, so for now we keep it simple.
return isPageController && this.lastRequest !== null &&
this.lastRequest.inputText.trim() === inputText;
}
} }
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment