Commit 2fc0dcec authored by Kuo Jen Wei's avatar Kuo Jen Wei Committed by Commit Bot

CCA: Use bracket property accessors for all undefined property

CCA has 3 kinds of property currently undefined to closure compiler:
1. Properties set by external browsing context.
2. Properties defined in dataset.
3. properties defined under * type.
This CL use bracket property accessors to access these properties for
avoiding being caught in closure compiler strict mode check.

Bug: 1122444
Test: tast run <DUT> "camera.CCAUI*"
Change-Id: I8f57adc6ca536629377af4976bb45515b4efc2be
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2383590
Commit-Queue: Inker Kuo <inker@chromium.org>
Reviewed-by: default avatarShik Chen <shik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803347}
parent d17ece3a
...@@ -206,7 +206,7 @@ class CCAWindow { ...@@ -206,7 +206,7 @@ class CCAWindow {
this.testingCallbacks_.onClosed(windowUrl); this.testingCallbacks_.onClosed(windowUrl);
} }
}); });
appWindow.contentWindow.backgroundOps = this; appWindow.contentWindow['backgroundOps'] = this;
if (this.testingCallbacks_ !== null) { if (this.testingCallbacks_ !== null) {
this.testingCallbacks_.onCreated(windowUrl); this.testingCallbacks_.onCreated(windowUrl);
} }
...@@ -588,8 +588,9 @@ chrome.app.runtime.onLaunched.addListener((launchData) => { ...@@ -588,8 +588,9 @@ chrome.app.runtime.onLaunched.addListener((launchData) => {
background = new Background(); background = new Background();
} }
try { try {
if (launchData.url) { const /** (string|undefined) */ url = launchData['url'];
const intent = Intent.create(new URL(launchData.url)); if (url !== undefined) {
const intent = Intent.create(new URL(url));
background.launchIntent(intent); background.launchIntent(intent);
} else { } else {
background.launchApp(); background.launchApp();
......
...@@ -251,7 +251,7 @@ export class VideoConstraintsPreferrer extends ConstraintsPreferrer { ...@@ -251,7 +251,7 @@ export class VideoConstraintsPreferrer extends ConstraintsPreferrer {
*/ */
restoreFpsPreference_() { restoreFpsPreference_() {
browserProxy.localStorageGet({deviceVideoFps: {}}) browserProxy.localStorageGet({deviceVideoFps: {}})
.then((values) => this.prefFpses_ = values.deviceVideoFps); .then((values) => this.prefFpses_ = values['deviceVideoFps']);
} }
/** /**
......
...@@ -7,7 +7,7 @@ import { ...@@ -7,7 +7,7 @@ import {
ForegroundOps, // eslint-disable-line no-unused-vars ForegroundOps, // eslint-disable-line no-unused-vars
} from './background_ops.js'; } from './background_ops.js';
import {browserProxy} from './browser_proxy/browser_proxy.js'; import {browserProxy} from './browser_proxy/browser_proxy.js';
import {assert} from './chrome_util.js'; import {assert, assertInstanceof} from './chrome_util.js';
import { import {
PhotoConstraintsPreferrer, PhotoConstraintsPreferrer,
VideoConstraintsPreferrer, VideoConstraintsPreferrer,
...@@ -131,22 +131,26 @@ export class App { ...@@ -131,22 +131,26 @@ export class App {
*/ */
setupToggles_() { setupToggles_() {
browserProxy.localStorageGet({expert: false}) browserProxy.localStorageGet({expert: false})
.then(({expert}) => state.set(state.State.EXPERT, expert)); .then((values) => state.set(state.State.EXPERT, values['expert']));
dom.getAll('input', HTMLInputElement).forEach((element) => { dom.getAll('input', HTMLInputElement).forEach((element) => {
element.addEventListener( element.addEventListener('keypress', (event) => {
'keypress', const e = assertInstanceof(event, KeyboardEvent);
(event) => if (util.getShortcutIdentifier(e) === 'Enter') {
util.getShortcutIdentifier(event) === 'Enter' && element.click()); element.click();
}
});
const payload = (element) => ({[element.dataset.key]: element.checked}); const payload = (element) =>
({[element.dataset['key']]: element.checked});
const save = (element) => { const save = (element) => {
if (element.dataset.key !== undefined) { if (element.dataset['key'] !== undefined) {
browserProxy.localStorageSet(payload(element)); browserProxy.localStorageSet(payload(element));
} }
}; };
element.addEventListener('change', (event) => { element.addEventListener('change', (event) => {
if (element.dataset.state !== undefined) { if (element.dataset['state'] !== undefined) {
state.set(state.assertState(element.dataset.state), element.checked); state.set(
state.assertState(element.dataset['state']), element.checked);
} }
if (event.isTrusted) { if (event.isTrusted) {
save(element); save(element);
...@@ -160,12 +164,12 @@ export class App { ...@@ -160,12 +164,12 @@ export class App {
} }
} }
}); });
if (element.dataset.key !== undefined) { if (element.dataset['key'] !== undefined) {
// Restore the previously saved state on startup. // Restore the previously saved state on startup.
browserProxy.localStorageGet(payload(element)) browserProxy.localStorageGet(payload(element))
.then( .then(
(values) => (values) => util.toggleChecked(
util.toggleChecked(element, values[element.dataset.key])); element, values[element.dataset['key']]));
} }
}); });
} }
...@@ -228,7 +232,7 @@ export class App { ...@@ -228,7 +232,7 @@ export class App {
*/ */
onKeyPressed_(event) { onKeyPressed_(event) {
tooltip.hide(); // Hide shown tooltip on any keypress. tooltip.hide(); // Hide shown tooltip on any keypress.
nav.onKeyPressed(event); nav.onKeyPressed(assertInstanceof(event, KeyboardEvent));
} }
/** /**
......
...@@ -95,8 +95,8 @@ export function initMetrics() { ...@@ -95,8 +95,8 @@ export function initMetrics() {
}, i[r].l = 1 * new Date(); }, i[r].l = 1 * new Date();
const a = s.createElement(o); const a = s.createElement(o);
const m = s.getElementsByTagName(o)[0]; const m = s.getElementsByTagName(o)[0];
a.async = 1; a['async'] = 1;
a.src = g; a['src'] = g;
m.parentNode.insertBefore(a, m); m.parentNode.insertBefore(a, m);
})(window, document, 'script', '../js/lib/analytics.js', 'ga'); })(window, document, 'script', '../js/lib/analytics.js', 'ga');
...@@ -317,7 +317,8 @@ export class PerfEventParam { ...@@ -317,7 +317,8 @@ export class PerfEventParam {
* @param {!PerfEventParam} param * @param {!PerfEventParam} param
*/ */
export function sendPerfEvent({event, duration, extras = {}}) { export function sendPerfEvent({event, duration, extras = {}}) {
const {resolution = '', facing = ''} = extras; const resolution = extras['resolution'] || '';
const facing = extras['facing'] || '';
sendEvent( sendEvent(
{ {
eventCategory: 'perf', eventCategory: 'perf',
......
...@@ -53,7 +53,7 @@ function activate(index) { ...@@ -53,7 +53,7 @@ function activate(index) {
const view = allViews[index]; const view = allViews[index];
view.root.setAttribute('aria-hidden', 'false'); view.root.setAttribute('aria-hidden', 'false');
dom.getAllFrom(view.root, '[tabindex]', HTMLElement).forEach((element) => { dom.getAllFrom(view.root, '[tabindex]', HTMLElement).forEach((element) => {
element.setAttribute('tabindex', element.dataset.tabindex); element.setAttribute('tabindex', element.dataset['tabindex']);
element.removeAttribute('data-tabindex'); element.removeAttribute('data-tabindex');
}); });
view.focus(); view.focus();
...@@ -67,7 +67,7 @@ function inactivate(index) { ...@@ -67,7 +67,7 @@ function inactivate(index) {
const view = allViews[index]; const view = allViews[index];
view.root.setAttribute('aria-hidden', 'true'); view.root.setAttribute('aria-hidden', 'true');
dom.getAllFrom(view.root, '[tabindex]', HTMLElement).forEach((element) => { dom.getAllFrom(view.root, '[tabindex]', HTMLElement).forEach((element) => {
element.dataset.tabindex = element.getAttribute('tabindex'); element.dataset['tabindex'] = element.getAttribute('tabindex');
element.setAttribute('tabindex', '-1'); element.setAttribute('tabindex', '-1');
}); });
document.activeElement.blur(); document.activeElement.blur();
......
...@@ -16,7 +16,8 @@ export function play(selector) { ...@@ -16,7 +16,8 @@ export function play(selector) {
let cancel; let cancel;
const p = new Promise((resolve, reject) => { const p = new Promise((resolve, reject) => {
const element = dom.get(selector, HTMLAudioElement); const element = dom.get(selector, HTMLAudioElement);
const timeout = setTimeout(resolve, Number(element.dataset.timeout || 0)); const timeout =
setTimeout(resolve, Number(element.dataset['timeout'] || 0));
cancel = () => { cancel = () => {
clearTimeout(timeout); clearTimeout(timeout);
reject(new Error('cancel')); reject(new Error('cancel'));
......
...@@ -258,7 +258,7 @@ export class Modes { ...@@ -258,7 +258,7 @@ export class Modes {
}); });
element.addEventListener('change', async (event) => { element.addEventListener('change', async (event) => {
if (element.checked) { if (element.checked) {
const mode = element.dataset.mode; const mode = /** @type {!Mode} */ (element.dataset['mode']);
this.updateModeUI_(mode); this.updateModeUI_(mode);
state.set(state.State.MODE_SWITCHING, true); state.set(state.State.MODE_SWITCHING, true);
const isSuccess = await this.doSwitchMode_(); const isSuccess = await this.doSwitchMode_();
...@@ -387,7 +387,9 @@ export class Modes { ...@@ -387,7 +387,9 @@ export class Modes {
dom.getAll('div.mode-item', HTMLDivElement).forEach((element) => { dom.getAll('div.mode-item', HTMLDivElement).forEach((element) => {
const radio = dom.getFrom(element, 'input[type=radio]', HTMLInputElement); const radio = dom.getFrom(element, 'input[type=radio]', HTMLInputElement);
element.classList.toggle( element.classList.toggle(
'hide', !supportedModes.includes(radio.dataset.mode)); 'hide',
!supportedModes.includes(
/** @type {!Mode} */ (radio.dataset['mode'])));
}); });
this.modesGroup_.classList.toggle('scrollable', supportedModes.length > 3); this.modesGroup_.classList.toggle('scrollable', supportedModes.length > 3);
this.modesGroup_.classList.remove('hide'); this.modesGroup_.classList.remove('hide');
......
...@@ -100,7 +100,7 @@ export class Options { ...@@ -100,7 +100,7 @@ export class Options {
// Restore saved mirroring states per video device. // Restore saved mirroring states per video device.
browserProxy.localStorageGet({mirroringToggles: {}}) browserProxy.localStorageGet({mirroringToggles: {}})
.then((values) => this.mirroringToggles_ = values.mirroringToggles); .then((values) => this.mirroringToggles_ = values['mirroringToggles']);
// Remove the deprecated values. // Remove the deprecated values.
browserProxy.localStorageRemove( browserProxy.localStorageRemove(
['effectIndex', 'toggleMulti', 'toggleMirror']); ['effectIndex', 'toggleMulti', 'toggleMirror']);
......
...@@ -84,7 +84,7 @@ export class BaseSettings extends View { ...@@ -84,7 +84,7 @@ export class BaseSettings extends View {
openSubSettings(name) { openSubSettings(name) {
// Dismiss master-settings if sub-settings was dismissed by background // Dismiss master-settings if sub-settings was dismissed by background
// click. // click.
nav.open(name).then((cond) => cond && cond.bkgnd && this.leave(cond)); nav.open(name).then((cond) => cond && cond['bkgnd'] && this.leave(cond));
} }
} }
...@@ -405,7 +405,7 @@ export class ResolutionSettings extends BaseSettings { ...@@ -405,7 +405,7 @@ export class ResolutionSettings extends BaseSettings {
* @param {function(!Resolution, !ResolutionList): string} optTextTempl * @param {function(!Resolution, !ResolutionList): string} optTextTempl
*/ */
const prepItem = (item, id, {prefResol, resols}, optTextTempl) => { const prepItem = (item, id, {prefResol, resols}, optTextTempl) => {
item.dataset.deviceId = id; item.dataset['deviceId'] = id;
item.classList.toggle('multi-option', resols.length > 1); item.classList.toggle('multi-option', resols.length > 1);
item.querySelector('.description>span').textContent = item.querySelector('.description>span').textContent =
optTextTempl(prefResol, resols); optTextTempl(prefResol, resols);
...@@ -435,7 +435,7 @@ export class ResolutionSettings extends BaseSettings { ...@@ -435,7 +435,7 @@ export class ResolutionSettings extends BaseSettings {
const prevFocus = /** @type {?HTMLElement} */ ( const prevFocus = /** @type {?HTMLElement} */ (
this.resMenu_.querySelector('.menu-item.external-camera:focus')); this.resMenu_.querySelector('.menu-item.external-camera:focus'));
/** @type {?string} */ /** @type {?string} */
const prevFId = prevFocus && prevFocus.dataset.deviceId; const prevFId = prevFocus && prevFocus.dataset['deviceId'];
const /** number */ focusIdx = const /** number */ focusIdx =
this.externalSettings_.findIndex(({deviceId}) => deviceId === prevFId); this.externalSettings_.findIndex(({deviceId}) => deviceId === prevFId);
const fTitle = /** @type {?HTMLElement} */ (this.resMenu_.querySelector( const fTitle = /** @type {?HTMLElement} */ (this.resMenu_.querySelector(
...@@ -445,7 +445,7 @@ export class ResolutionSettings extends BaseSettings { ...@@ -445,7 +445,7 @@ export class ResolutionSettings extends BaseSettings {
dom.getAllFrom(this.resMenu_, '.menu-item.external-camera', HTMLElement) dom.getAllFrom(this.resMenu_, '.menu-item.external-camera', HTMLElement)
.forEach( .forEach(
(element) => element.dataset.deviceId !== focusedId && (element) => element.dataset['deviceId'] !== focusedId &&
element.parentNode.removeChild(element)); element.parentNode.removeChild(element));
this.externalSettings_.forEach((config, index) => { this.externalSettings_.forEach((config, index) => {
...@@ -486,7 +486,7 @@ export class ResolutionSettings extends BaseSettings { ...@@ -486,7 +486,7 @@ export class ResolutionSettings extends BaseSettings {
photoItem = /** @type {!HTMLElement}*/ (fTitle.nextElementSibling); photoItem = /** @type {!HTMLElement}*/ (fTitle.nextElementSibling);
videoItem = /** @type {!HTMLElement}*/ (photoItem.nextElementSibling); videoItem = /** @type {!HTMLElement}*/ (photoItem.nextElementSibling);
} }
titleItem.dataset.deviceId = deviceId; titleItem.dataset['deviceId'] = deviceId;
prepItem(photoItem, deviceId, config.photo, this.photoOptTextTempl_); prepItem(photoItem, deviceId, config.photo, this.photoOptTextTempl_);
prepItem(videoItem, deviceId, config.video, this.videoOptTextTempl_); prepItem(videoItem, deviceId, config.video, this.videoOptTextTempl_);
}); });
...@@ -629,9 +629,9 @@ export class ResolutionSettings extends BaseSettings { ...@@ -629,9 +629,9 @@ export class ResolutionSettings extends BaseSettings {
document.importNode(this.resItemTempl_.content, true)); document.importNode(this.resItemTempl_.content, true));
const input = dom.getFrom(item, 'input', HTMLInputElement); const input = dom.getFrom(item, 'input', HTMLInputElement);
item.querySelector('span').textContent = optTextTempl(r, resolutions); item.querySelector('span').textContent = optTextTempl(r, resolutions);
input.name = menu.dataset.name; input.name = menu.dataset['name'];
input.dataset.width = r.width; input.dataset['width'] = r.width.toString();
input.dataset.height = r.height; input.dataset['height'] = r.height.toString();
if (r.equals(selectedR)) { if (r.equals(selectedR)) {
captionText.textContent = optTextTempl(r, resolutions); captionText.textContent = optTextTempl(r, resolutions);
input.checked = true; input.checked = true;
......
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