Commit db2270aa authored by Ken Rockot's avatar Ken Rockot Committed by Commit Bot

Migrate omnibox WebUI to mojom JS modules

Bug: 1004256
Change-Id: I69c86f126dfe7c24e326f23848b26de71de7bf4d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2459570Reviewed-by: default avatarmanuk hovanesian <manukh@chromium.org>
Reviewed-by: default avatarcalamity <calamity@chromium.org>
Commit-Queue: calamity <calamity@chromium.org>
Auto-Submit: Ken Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#818345}
parent 76da3d83
...@@ -2,11 +2,13 @@ ...@@ -2,11 +2,13 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
import("//third_party/closure_compiler/closure_args.gni")
import("//third_party/closure_compiler/compile_js.gni") import("//third_party/closure_compiler/compile_js.gni")
import("//tools/grit/grit_rule.gni") import("//tools/grit/grit_rule.gni")
js_type_check("closure_compile") { js_type_check("closure_compile") {
uses_js_modules = true uses_js_modules = true
closure_flags = mojom_js_args
deps = [ deps = [
":omnibox", ":omnibox",
":omnibox_element", ":omnibox_element",
...@@ -20,7 +22,7 @@ js_library("omnibox") { ...@@ -20,7 +22,7 @@ js_library("omnibox") {
deps = [ deps = [
":omnibox_input", ":omnibox_input",
":omnibox_output", ":omnibox_output",
"//chrome/browser/ui/webui/omnibox:mojo_bindings_js_library_for_compile", "//chrome/browser/ui/webui/omnibox:mojo_bindings_webui_js",
"//ui/webui/resources/js:cr.m", "//ui/webui/resources/js:cr.m",
"//ui/webui/resources/js:load_time_data.m", "//ui/webui/resources/js:load_time_data.m",
"//ui/webui/resources/js:util.m", "//ui/webui/resources/js:util.m",
...@@ -39,14 +41,14 @@ js_library("omnibox_output") { ...@@ -39,14 +41,14 @@ js_library("omnibox_output") {
deps = [ deps = [
":omnibox_element", ":omnibox_element",
":omnibox_input", ":omnibox_input",
"//chrome/browser/ui/webui/omnibox:mojo_bindings_js_library_for_compile", "//chrome/browser/ui/webui/omnibox:mojo_bindings_webui_js",
] ]
externs_list = [ "$externs_path/pending.js" ] externs_list = [ "$externs_path/pending.js" ]
} }
js_library("omnibox_popup") { js_library("omnibox_popup") {
deps = [ deps = [
"//chrome/browser/ui/webui/omnibox:mojo_bindings_js_library_for_compile", "//chrome/browser/ui/webui/omnibox:mojo_bindings_webui_js",
"//ui/webui/resources/cr_components/omnibox:cr_autocomplete_match_list", "//ui/webui/resources/cr_components/omnibox:cr_autocomplete_match_list",
] ]
} }
...@@ -63,5 +65,5 @@ grit("resources") { ...@@ -63,5 +65,5 @@ grit("resources") {
"-E", "-E",
"root_gen_dir=" + rebase_path(root_gen_dir, root_build_dir), "root_gen_dir=" + rebase_path(root_gen_dir, root_build_dir),
] ]
deps = [ "//chrome/browser/ui/webui/omnibox:mojo_bindings_js" ] deps = [ "//chrome/browser/ui/webui/omnibox:mojo_bindings_webui_js" ]
} }
...@@ -2,10 +2,9 @@ ...@@ -2,10 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.js';
import './chrome/browser/ui/webui/omnibox/omnibox.mojom-lite.js';
import './strings.m.js'; import './strings.m.js';
import {OmniboxPageCallbackRouter, OmniboxPageHandler, OmniboxPageHandlerRemote, OmniboxResponse} from '/chrome/browser/ui/webui/omnibox/omnibox.mojom-webui.js';
import {sendWithPromise} from 'chrome://resources/js/cr.m.js'; import {sendWithPromise} from 'chrome://resources/js/cr.m.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js'; import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {$} from 'chrome://resources/js/util.m.js'; import {$} from 'chrome://resources/js/util.m.js';
...@@ -31,7 +30,7 @@ import {OmniboxOutput} from './omnibox_output.js'; ...@@ -31,7 +30,7 @@ import {OmniboxOutput} from './omnibox_output.js';
/** /**
* @typedef {{ * @typedef {{
* inputText: string, * inputText: string,
* callback: function(!mojom.OmniboxResponse):Promise, * callback: function(!OmniboxResponse):Promise,
* display: boolean, * display: boolean,
* }} * }}
*/ */
...@@ -49,7 +48,7 @@ let BatchSpecifier; ...@@ -49,7 +48,7 @@ let BatchSpecifier;
* @typedef {{ * @typedef {{
* queryInputs: QueryInputs, * queryInputs: QueryInputs,
* displayInputs: DisplayInputs, * displayInputs: DisplayInputs,
* responsesHistory: !Array<!Array<!mojom.OmniboxResponse>>, * responsesHistory: !Array<!Array<!OmniboxResponse>>,
* }} * }}
*/ */
let OmniboxExport; let OmniboxExport;
...@@ -66,8 +65,8 @@ let exportDelegate; ...@@ -66,8 +65,8 @@ let exportDelegate;
class BrowserProxy { class BrowserProxy {
/** @param {!OmniboxOutput} omniboxOutput */ /** @param {!OmniboxOutput} omniboxOutput */
constructor(omniboxOutput) { constructor(omniboxOutput) {
/** @private {!mojom.OmniboxPageCallbackRouter} */ /** @private {!OmniboxPageCallbackRouter} */
this.callbackRouter_ = new mojom.OmniboxPageCallbackRouter; this.callbackRouter_ = new OmniboxPageCallbackRouter;
this.callbackRouter_.handleNewAutocompleteResponse.addListener( this.callbackRouter_.handleNewAutocompleteResponse.addListener(
this.handleNewAutocompleteResponse.bind(this)); this.handleNewAutocompleteResponse.bind(this));
...@@ -76,8 +75,8 @@ class BrowserProxy { ...@@ -76,8 +75,8 @@ class BrowserProxy {
this.callbackRouter_.handleAnswerImageData.addListener( this.callbackRouter_.handleAnswerImageData.addListener(
omniboxOutput.updateAnswerImage.bind(omniboxOutput)); omniboxOutput.updateAnswerImage.bind(omniboxOutput));
/** @private {!mojom.OmniboxPageHandlerRemote} */ /** @private {!OmniboxPageHandlerRemote} */
this.handler_ = mojom.OmniboxPageHandler.getRemote(); this.handler_ = OmniboxPageHandler.getRemote();
this.handler_.setClientPage( this.handler_.setClientPage(
this.callbackRouter_.$.bindNewPipeAndPassRemote()); this.callbackRouter_.$.bindNewPipeAndPassRemote());
...@@ -86,7 +85,7 @@ class BrowserProxy { ...@@ -86,7 +85,7 @@ class BrowserProxy {
} }
/** /**
* @param {!mojom.OmniboxResponse} response * @param {!OmniboxResponse} response
* @param {boolean} isPageController * @param {boolean} isPageController
*/ */
handleNewAutocompleteResponse(response, isPageController) { handleNewAutocompleteResponse(response, isPageController) {
......
...@@ -2,11 +2,10 @@ ...@@ -2,11 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.js'; import {ACMatchClassification, AutocompleteMatch, OmniboxResponse} from '/chrome/browser/ui/webui/omnibox/omnibox.mojom-webui.js';
import './chrome/browser/ui/webui/omnibox/omnibox.mojom-lite.js';
import {OmniboxElement} from './omnibox_element.js'; import {OmniboxElement} from './omnibox_element.js';
import {OmniboxInput, DisplayInputs} from './omnibox_input.js'; import {DisplayInputs, OmniboxInput} from './omnibox_input.js';
/** /**
* @typedef {{ * @typedef {{
...@@ -33,7 +32,7 @@ export class OmniboxOutput extends OmniboxElement { ...@@ -33,7 +32,7 @@ export class OmniboxOutput extends OmniboxElement {
/** @private {number} */ /** @private {number} */
this.selectedResponseIndex_ = 0; this.selectedResponseIndex_ = 0;
/** @type {!Array<!Array<!mojom.OmniboxResponse>>} */ /** @type {!Array<!Array<!OmniboxResponse>>} */
this.responsesHistory = []; this.responsesHistory = [];
/** @private {!Array<!OutputResultsGroup>} */ /** @private {!Array<!OutputResultsGroup>} */
this.resultsGroups_ = []; this.resultsGroups_ = [];
...@@ -55,7 +54,7 @@ export class OmniboxOutput extends OmniboxElement { ...@@ -55,7 +54,7 @@ export class OmniboxOutput extends OmniboxElement {
this.updateFilterHighlights_(); this.updateFilterHighlights_();
} }
/** @param {!Array<!Array<!mojom.OmniboxResponse>>} responsesHistory */ /** @param {!Array<!Array<!OmniboxResponse>>} responsesHistory */
setResponsesHistory(responsesHistory) { setResponsesHistory(responsesHistory) {
this.responsesHistory = responsesHistory; this.responsesHistory = responsesHistory;
this.dispatchEvent(new CustomEvent( this.dispatchEvent(new CustomEvent(
...@@ -79,7 +78,7 @@ export class OmniboxOutput extends OmniboxElement { ...@@ -79,7 +78,7 @@ export class OmniboxOutput extends OmniboxElement {
'responses-count-changed', {detail: this.responsesHistory.length})); 'responses-count-changed', {detail: this.responsesHistory.length}));
} }
/** @param {!mojom.OmniboxResponse} response */ /** @param {!OmniboxResponse} response */
addAutocompleteResponse(response) { addAutocompleteResponse(response) {
const lastIndex = this.responsesHistory.length - 1; const lastIndex = this.responsesHistory.length - 1;
this.responsesHistory[lastIndex].push(response); this.responsesHistory[lastIndex].push(response);
...@@ -99,7 +98,7 @@ export class OmniboxOutput extends OmniboxElement { ...@@ -99,7 +98,7 @@ export class OmniboxOutput extends OmniboxElement {
/** /**
* Creates and adds a result group to the UI. * Creates and adds a result group to the UI.
* @private @param {!mojom.OmniboxResponse} response * @private @param {!OmniboxResponse} response
*/ */
createResultsGroup_(response) { createResultsGroup_(response) {
const resultsGroup = OutputResultsGroup.create(response); const resultsGroup = OutputResultsGroup.create(response);
...@@ -187,7 +186,7 @@ export class OmniboxOutput extends OmniboxElement { ...@@ -187,7 +186,7 @@ export class OmniboxOutput extends OmniboxElement {
*/ */
class OutputResultsGroup extends OmniboxElement { class OutputResultsGroup extends OmniboxElement {
/** /**
* @param {!mojom.OmniboxResponse} resultsGroup * @param {!OmniboxResponse} resultsGroup
* @return {!OutputResultsGroup} * @return {!OutputResultsGroup}
*/ */
static create(resultsGroup) { static create(resultsGroup) {
...@@ -200,7 +199,7 @@ class OutputResultsGroup extends OmniboxElement { ...@@ -200,7 +199,7 @@ class OutputResultsGroup extends OmniboxElement {
super('output-results-group-template'); super('output-results-group-template');
} }
/** @param {!mojom.OmniboxResponse} resultsGroup */ /** @param {!OmniboxResponse} resultsGroup */
setResultsGroup(resultsGroup) { setResultsGroup(resultsGroup) {
/** @private {ResultsDetails} */ /** @private {ResultsDetails} */
this.details_ = { this.details_ = {
...@@ -357,7 +356,7 @@ class OutputResultsDetails extends OmniboxElement { ...@@ -357,7 +356,7 @@ class OutputResultsDetails extends OmniboxElement {
*/ */
class OutputResultsTable extends HTMLTableSectionElement { class OutputResultsTable extends HTMLTableSectionElement {
/** /**
* @param {!Array<!mojom.AutocompleteMatch>} results * @param {!Array<!AutocompleteMatch>} results
* @return {!OutputResultsTable} * @return {!OutputResultsTable}
*/ */
static create(results) { static create(results) {
...@@ -373,7 +372,7 @@ class OutputResultsTable extends HTMLTableSectionElement { ...@@ -373,7 +372,7 @@ class OutputResultsTable extends HTMLTableSectionElement {
this.autocompleteMatches = []; this.autocompleteMatches = [];
} }
/** @param {!Array<!mojom.AutocompleteMatch>} results */ /** @param {!Array<!AutocompleteMatch>} results */
set results(results) { set results(results) {
this.autocompleteMatches.forEach(match => match.remove()); this.autocompleteMatches.forEach(match => match.remove());
this.autocompleteMatches = results.map(OutputMatch.create); this.autocompleteMatches = results.map(OutputMatch.create);
...@@ -404,7 +403,7 @@ class OutputMatch extends HTMLTableRowElement { ...@@ -404,7 +403,7 @@ class OutputMatch extends HTMLTableRowElement {
} }
/** /**
* @param {!mojom.AutocompleteMatch} match * @param {!AutocompleteMatch} match
* @return {!OutputMatch} * @return {!OutputMatch}
*/ */
static create(match) { static create(match) {
...@@ -414,7 +413,7 @@ class OutputMatch extends HTMLTableRowElement { ...@@ -414,7 +413,7 @@ class OutputMatch extends HTMLTableRowElement {
return outputMatch; return outputMatch;
} }
/** @param {!mojom.AutocompleteMatch} match */ /** @param {!AutocompleteMatch} match */
set match(match) { set match(match) {
/** @type {!Object<string, !OutputProperty>} */ /** @type {!Object<string, !OutputProperty>} */
this.properties = {}; this.properties = {};
...@@ -703,11 +702,11 @@ class OutputAnswerProperty extends FlexWrappingOutputProperty { ...@@ -703,11 +702,11 @@ class OutputAnswerProperty extends FlexWrappingOutputProperty {
this.values_; this.values_;
OutputAnswerProperty.renderClassifiedText_( OutputAnswerProperty.renderClassifiedText_(
this.contents_, /** @type {string} */ (contents), this.contents_, /** @type {string} */ (contents),
/** @type {!Array<!mojom.ACMatchClassification>} */ /** @type {!Array<!ACMatchClassification>} */
(contentsClassification)); (contentsClassification));
OutputAnswerProperty.renderClassifiedText_( OutputAnswerProperty.renderClassifiedText_(
this.description_, /** @type {string} */ (description), this.description_, /** @type {string} */ (description),
/** @type {!Array<!mojom.ACMatchClassification>} */ /** @type {!Array<!ACMatchClassification>} */
(descriptionClassification)); (descriptionClassification));
this.answer_.textContent = answer; this.answer_.textContent = answer;
this.imageUrl_.textContent = image; this.imageUrl_.textContent = image;
...@@ -723,7 +722,7 @@ class OutputAnswerProperty extends FlexWrappingOutputProperty { ...@@ -723,7 +722,7 @@ class OutputAnswerProperty extends FlexWrappingOutputProperty {
* @private * @private
* @param {!Element} container * @param {!Element} container
* @param {string} string * @param {string} string
* @param {!Array<!mojom.ACMatchClassification>} classes * @param {!Array<!ACMatchClassification>} classes
*/ */
static renderClassifiedText_(container, string, classes) { static renderClassifiedText_(container, string, classes) {
clearChildren(container); clearChildren(container);
...@@ -736,7 +735,7 @@ class OutputAnswerProperty extends FlexWrappingOutputProperty { ...@@ -736,7 +735,7 @@ class OutputAnswerProperty extends FlexWrappingOutputProperty {
/** /**
* @param {string} string * @param {string} string
* @param {!Array<!mojom.ACMatchClassification>} classes * @param {!Array<!ACMatchClassification>} classes
* @return {!Array<{string: string, style: number}>} * @return {!Array<{string: string, style: number}>}
*/ */
static classify(string, classes) { static classify(string, classes) {
......
...@@ -2,9 +2,7 @@ ...@@ -2,9 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.js'; import {OmniboxPageCallbackRouter, OmniboxPageHandler, OmniboxPageHandlerRemote} from '/chrome/browser/ui/webui/omnibox/omnibox.mojom-webui.js';
import './chrome/browser/ui/webui/omnibox/omnibox.mojom-lite.js';
import {AutocompleteMatchListElement} from 'chrome://resources/cr_components/omnibox/cr_autocomplete_match_list.js'; import {AutocompleteMatchListElement} from 'chrome://resources/cr_components/omnibox/cr_autocomplete_match_list.js';
/** /**
...@@ -14,8 +12,8 @@ import {AutocompleteMatchListElement} from 'chrome://resources/cr_components/omn ...@@ -14,8 +12,8 @@ import {AutocompleteMatchListElement} from 'chrome://resources/cr_components/omn
*/ */
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
/** @private {!mojom.OmniboxPageCallbackRouter} */ /** @private {!OmniboxPageCallbackRouter} */
const callbackRouter = new mojom.OmniboxPageCallbackRouter; const callbackRouter = new OmniboxPageCallbackRouter;
// Basically a Hello World proof of concept that writes the Autocomplete // Basically a Hello World proof of concept that writes the Autocomplete
// responses to the whole document. // responses to the whole document.
...@@ -31,7 +29,7 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -31,7 +29,7 @@ document.addEventListener('DOMContentLoaded', () => {
} }
}); });
/** @private {!mojom.OmniboxPageHandlerRemote} */ /** @private {!OmniboxPageHandlerRemote} */
const handler = mojom.OmniboxPageHandler.getRemote(); const handler = OmniboxPageHandler.getRemote();
handler.setClientPage(callbackRouter.$.bindNewPipeAndPassRemote()); handler.setClientPage(callbackRouter.$.bindNewPipeAndPassRemote());
}); });
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
file="omnibox.js" file="omnibox.js"
type="BINDATA" /> type="BINDATA" />
<include name="IDR_OMNIBOX_MOJO_JS" <include name="IDR_OMNIBOX_MOJO_JS"
file="${root_gen_dir}\chrome\browser\ui\webui\omnibox\omnibox.mojom-lite.js" file="${root_gen_dir}\mojom-webui\chrome\browser\ui\webui\omnibox\omnibox.mojom-webui.js"
use_base_dir="false" use_base_dir="false"
type="BINDATA" /> type="BINDATA" />
</includes> </includes>
......
...@@ -6,4 +6,5 @@ import("//mojo/public/tools/bindings/mojom.gni") ...@@ -6,4 +6,5 @@ import("//mojo/public/tools/bindings/mojom.gni")
mojom("mojo_bindings") { mojom("mojo_bindings") {
sources = [ "omnibox.mojom" ] sources = [ "omnibox.mojom" ]
webui_module_path = "/chrome/browser/ui/webui/omnibox"
} }
...@@ -49,7 +49,7 @@ OmniboxUI::OmniboxUI(content::WebUI* web_ui) ...@@ -49,7 +49,7 @@ OmniboxUI::OmniboxUI(content::WebUI* web_ui)
{"omnibox_input.js", IDR_OMNIBOX_INPUT_JS}, {"omnibox_input.js", IDR_OMNIBOX_INPUT_JS},
{"omnibox_output.js", IDR_OMNIBOX_OUTPUT_JS}, {"omnibox_output.js", IDR_OMNIBOX_OUTPUT_JS},
{"omnibox.js", IDR_OMNIBOX_JS}, {"omnibox.js", IDR_OMNIBOX_JS},
{"chrome/browser/ui/webui/omnibox/omnibox.mojom-lite.js", {"chrome/browser/ui/webui/omnibox/omnibox.mojom-webui.js",
IDR_OMNIBOX_MOJO_JS}, IDR_OMNIBOX_MOJO_JS},
}; };
webui::AddResourcePathsBulk(source, kResources); webui::AddResourcePathsBulk(source, kResources);
......
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