Commit 6e70f4e9 authored by manukh's avatar manukh Committed by Commit Bot

[omnibox] [chrome://omnibox] Persist display options between page loads.

We previously considered persisting all inputs, but decided to hold off
because 1) it would make asking users to extract data more error prone,
and 2) having options to 'reset inputs' and 'toggle persistence' would
be too complicated.

Since then, I've come into the habit of 1) open chrome://omnibox, 2)
enable 'connect window to omnibox', 3) enable 'thin rows', and then 4)
type my input. This becomes cumbersome when opening multiple
chrome://omnibox tabs, e.g., to compare results.

To satisfy both requirements, this CL persists display options only.
Since query inputs aren't persisted, the extracted JSON won't be
affected, and 'reset inputs' and 'toggle persistence' options won't be
required.

Change-Id: I8b2f4d17ce840f6b4d1cec4df8b446122b7e28eb

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

Change-Id: I8b2f4d17ce840f6b4d1cec4df8b446122b7e28eb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2002983
Commit-Queue: manuk hovanesian <manukh@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734518}
parent be2702ba
...@@ -193,6 +193,8 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -193,6 +193,8 @@ document.addEventListener('DOMContentLoaded', () => {
omniboxOutput.addEventListener( omniboxOutput.addEventListener(
'responses-count-changed', e => omniboxInput.responsesCount = e.detail); 'responses-count-changed', e => omniboxInput.responsesCount = e.detail);
omniboxOutput.updateDisplayInputs(omniboxInput.displayInputs);
}); });
class ExportDelegate { class ExportDelegate {
......
...@@ -33,7 +33,7 @@ export let DisplayInputs; ...@@ -33,7 +33,7 @@ export let DisplayInputs;
export class OmniboxInput extends OmniboxElement { export class OmniboxInput extends OmniboxElement {
constructor() { constructor() {
super('omnibox-input-template'); super('omnibox-input-template');
this.displayInputs = OmniboxInput.defaultDisplayInputs; this.restoreInputs_();
} }
/** @override */ /** @override */
...@@ -41,6 +41,24 @@ export class OmniboxInput extends OmniboxElement { ...@@ -41,6 +41,24 @@ export class OmniboxInput extends OmniboxElement {
this.setupElementListeners_(); this.setupElementListeners_();
} }
/** @private */
storeInputs_() {
const inputs = {
connectWindowOmnibox: this.connectWindowOmnibox,
displayInputs: this.displayInputs,
};
window.localStorage.setItem('preserved-inputs', JSON.stringify(inputs));
}
/** @private */
restoreInputs_() {
const inputsString = window.localStorage.getItem('preserved-inputs');
const inputs = inputsString && JSON.parse(inputsString) || {};
this.$('#connect-window-omnibox').checked = inputs.connectWindowOmnibox;
this.displayInputs =
inputs.displayInputs || OmniboxInput.defaultDisplayInputs;
}
/** @private */ /** @private */
setupElementListeners_() { setupElementListeners_() {
['#input-text', ['#input-text',
...@@ -62,6 +80,9 @@ export class OmniboxInput extends OmniboxElement { ...@@ -62,6 +80,9 @@ export class OmniboxInput extends OmniboxElement {
.addEventListener( .addEventListener(
'input', this.positionCursorPositionIndicators_.bind(this)); 'input', this.positionCursorPositionIndicators_.bind(this));
this.$('#connect-window-omnibox')
.addEventListener('input', this.storeInputs_.bind(this));
this.$('#response-selection') this.$('#response-selection')
.addEventListener('input', this.onResponseSelectionChanged_.bind(this)); .addEventListener('input', this.onResponseSelectionChanged_.bind(this));
this.$('#response-selection') this.$('#response-selection')
...@@ -188,6 +209,11 @@ export class OmniboxInput extends OmniboxElement { ...@@ -188,6 +209,11 @@ export class OmniboxInput extends OmniboxElement {
return this.$('#connect-window-omnibox').checked; return this.$('#connect-window-omnibox').checked;
} }
/** @private @param {boolean} connectWindowOmnibox */
set connectWindowOmnibox_(connectWindowOmnibox) {
this.$('#connect-window-omnibox').checked = connectWindowOmnibox;
}
/** @private */ /** @private */
onResponseSelectionChanged_() { onResponseSelectionChanged_() {
const {value, max} = this.$('#response-selection'); const {value, max} = this.$('#response-selection');
...@@ -216,6 +242,7 @@ export class OmniboxInput extends OmniboxElement { ...@@ -216,6 +242,7 @@ export class OmniboxInput extends OmniboxElement {
/** @private */ /** @private */
onDisplayInputsChanged_() { onDisplayInputsChanged_() {
this.storeInputs_();
this.dispatchEvent(new CustomEvent( this.dispatchEvent(new CustomEvent(
'display-inputs-changed', {detail: this.displayInputs})); 'display-inputs-changed', {detail: this.displayInputs}));
} }
...@@ -325,7 +352,11 @@ export class OmniboxInput extends OmniboxElement { ...@@ -325,7 +352,11 @@ export class OmniboxInput extends OmniboxElement {
} }
} }
/** @private @param {!File} file */ /**
* @private
* @param {!File} file
* @return {!Promise}
*/
static readFile_(file) { static readFile_(file) {
return new Promise(resolve => { return new Promise(resolve => {
const reader = new FileReader(); const reader = new FileReader();
......
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