Commit 6d9a9636 authored by John Lee's avatar John Lee Committed by Commit Bot

WebUI: Auto-generate icon.m.js

This will be used in the Tab Strip WebUI to retrieve favicons for tabs,
and the Tab Strip WebUI uses JS modules.

Bug: 965770
Change-Id: I34e2cc4c7dbb1913e946b055a48d12c69a87acfb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1748113Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Commit-Queue: John Lee <johntlee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#687364}
parent e7e2864c
......@@ -141,6 +141,7 @@ js_library("find_shortcut_behavior") {
js_modulizer("modulize") {
input_files = [
"assert.js",
"icon.js",
"i18n_behavior.js",
"load_time_data.js",
"parse_html_subset.js",
......@@ -158,6 +159,7 @@ js_type_check("closure_compile_modules") {
":assert.m",
":cr.m",
":i18n_behavior.m",
":icon.m",
":load_time_data.m",
":parse_html_subset.m",
":promise_resolver.m",
......@@ -180,6 +182,13 @@ js_library("cr.m") {
externs_list = [ "$externs_path/chrome_send.js" ]
}
js_library("icon.m") {
sources = [
"$root_gen_dir/ui/webui/resources/js/icon.m.js",
]
extra_deps = [ ":modulize" ]
}
js_library("i18n_behavior.m") {
sources = [
"$root_gen_dir/ui/webui/resources/js/i18n_behavior.m.js",
......
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// #import {isChromeOS, isIOS, isLinux, isMac, isWindows} from './cr.m.js';
cr.define('cr.icon', function() {
/**
* @return {!Array<number>} The scale factors supported by this platform for
......@@ -35,7 +37,7 @@ cr.define('cr.icon', function() {
* @param {string} s The URL to generate the CSS url for.
* @return {string} The CSS url string.
*/
function getUrlForCss(s) {
/* #export */ function getUrlForCss(s) {
// http://www.w3.org/TR/css3-values/#uris
// Parentheses, commas, whitespace characters, single quotes (') and double
// quotes (") appearing in a URI must be escaped with a backslash
......@@ -54,7 +56,7 @@ cr.define('cr.icon', function() {
* @param {string} filePath
* @return {string}
*/
function getFileIconUrl(filePath) {
/* #export */ function getFileIconUrl(filePath) {
const url = new URL('chrome://fileicon/');
url.searchParams.set('path', filePath);
url.searchParams.set('scale', window.devicePixelRatio + 'x');
......@@ -101,7 +103,7 @@ cr.define('cr.icon', function() {
* @param {string} path The path of the image.
* @return {string} The url, or an image set of URLs.
*/
function getImage(path) {
/* #export */ function getImage(path) {
const chromeThemePath = 'chrome://theme';
const isChromeThemeUrl =
(path.slice(0, chromeThemePath.length) == chromeThemePath);
......@@ -128,7 +130,8 @@ cr.define('cr.icon', function() {
*
* @return {string} -webkit-image-set for the favicon.
*/
function getFavicon(url, isSyncedUrlForHistoryUi, remoteIconUrlForUma = '') {
/* #export */ function getFavicon(
url, isSyncedUrlForHistoryUi, remoteIconUrlForUma = '') {
// Note: URL param keys used below must match those in the description of
// chrome://favicon2 format in components/favicon_base/favicon_url_parser.h.
const faviconUrl = new URL('chrome://favicon2/');
......@@ -151,6 +154,7 @@ cr.define('cr.icon', function() {
return getImageSet(faviconUrl.toString());
}
// #cr_define_end
return {
getFavicon: getFavicon,
getFileIconUrl: getFileIconUrl,
......
......@@ -89,6 +89,9 @@ without changes to the corresponding grd file. -->
<include name="IDR_WEBUI_JS_CR_UI_FOCUS_OUTLINE_MANAGER_M_JS"
file="${root_gen_dir}/ui/webui/resources/js/cr/ui/focus_outline_manager.m.js"
use_base_dir="false" type="BINDATA" compress="gzip" />
<include name="IDR_WEBUI_JS_ICON_M_JS"
file="${root_gen_dir}/ui/webui/resources/js/icon.m.js"
use_base_dir="false" type="BINDATA" compress="gzip" />
<include name="IDR_WEBUI_JS_LOAD_TIME_DATA_M_JS"
file="${root_gen_dir}/ui/webui/resources/js/load_time_data.m.js"
use_base_dir="false" type="BINDATA" compress="gzip" />
......
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