Commit 63a4a084 authored by Kuo Jen Wei's avatar Kuo Jen Wei Committed by Commit Bot

[CCA] Convert intent.js into ES6 module.

Bug: 141518780
Test: Pass closure compiler check, tast run <DUT> 'camera.CCAUI*' and manually
validate tooltips function of CCA works correctly.

Change-Id: I718ce2f7ac43ef6778091170b00ffb6367f4a9ca
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1982339
Commit-Queue: Kuo Jen Wei <inker@chromium.org>
Auto-Submit: Kuo Jen Wei <inker@chromium.org>
Reviewed-by: default avatarShik Chen <shik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#727453}
parent 103cc678
...@@ -2,22 +2,13 @@ ...@@ -2,22 +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.
'use strict'; import {ChromeHelper} from './mojo/chrome_helper.js';
import {Mode} from './type.js';
/**
* Namespace for the Camera app.
*/
var cca = cca || {};
/**
* Namespace for the ARC++ intent.
*/
cca.intent = cca.intent || {};
/** /**
* Thrown when fails to parse intent url. * Thrown when fails to parse intent url.
*/ */
cca.intent.ParseError = class extends Error { export class ParseError extends Error {
/** /**
* @param {!URL} url Intent url. * @param {!URL} url Intent url.
*/ */
...@@ -29,18 +20,18 @@ cca.intent.ParseError = class extends Error { ...@@ -29,18 +20,18 @@ cca.intent.ParseError = class extends Error {
*/ */
this.url_ = url; this.url_ = url;
this.name = 'ParseError'; this.name = this.constructor.name;
} }
}; }
/** /**
* Intent from ARC++. * Intent from ARC++.
*/ */
cca.intent.Intent = class { export class Intent {
/** /**
* @param {!URL} url * @param {!URL} url
* @param {number} intentId * @param {number} intentId
* @param {cca.Mode} mode * @param {Mode} mode
* @param {boolean} shouldHandleResult * @param {boolean} shouldHandleResult
* @param {boolean} shouldDownScale * @param {boolean} shouldDownScale
* @param {boolean} isSecure * @param {boolean} isSecure
...@@ -60,7 +51,7 @@ cca.intent.Intent = class { ...@@ -60,7 +51,7 @@ cca.intent.Intent = class {
/** /**
* Capture mode of intent. * Capture mode of intent.
* @const {cca.Mode} * @const {Mode}
*/ */
this.mode = mode; this.mode = mode;
...@@ -92,11 +83,11 @@ cca.intent.Intent = class { ...@@ -92,11 +83,11 @@ cca.intent.Intent = class {
} }
/** /**
* @return {!cca.mojo.ChromeHelper} * @return {!ChromeHelper}
* @private * @private
*/ */
get chromeHelper_() { get chromeHelper_() {
return cca.mojo.ChromeHelper.getInstance(); return ChromeHelper.getInstance();
} }
/** /**
...@@ -156,27 +147,30 @@ cca.intent.Intent = class { ...@@ -156,27 +147,30 @@ cca.intent.Intent = class {
/** /**
* @param {!URL} url Url passed along with app launch event. * @param {!URL} url Url passed along with app launch event.
* @return {!cca.intent.Intent} Created intent object. Returns null if input * @return {!Intent} Created intent object. Returns null if input is not a
* is not a valid intent url. * valid intent url.
* @throws {cca.intent.ParseError} * @throws {ParseError}
*/ */
static create(url) { static create(url) {
const params = url.searchParams; const params = url.searchParams;
const getBool = (key) => params.get(key) === '1'; const getBool = (key) => params.get(key) === '1';
let param = params.get('intentId'); let param = params.get('intentId');
if (param === null) { if (param === null) {
throw new cca.intent.ParseError(url); throw new ParseError(url);
} }
const intentId = parseInt(param, 10); const intentId = parseInt(param, 10);
param = params.get('mode'); param = params.get('mode');
if (param === null || !Object.values(cca.Mode).includes(param)) { if (param === null || !Object.values(Mode).includes(param)) {
throw new cca.intent.ParseError(url); throw new ParseError(url);
} }
const mode = /** @type {cca.Mode} */ (param); const mode = /** @type {Mode} */ (param);
return new cca.intent.Intent( return new Intent(
url, intentId, mode, getBool('shouldHandleResult'), url, intentId, mode, getBool('shouldHandleResult'),
getBool('shouldDownScale'), getBool('isSecure')); getBool('shouldDownScale'), getBool('isSecure'));
} }
}; }
/** @const */
cca.intent.Intent = Intent;
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
var cca = { var cca = {
device: {}, device: {},
intent: {},
mojo: {}, mojo: {},
nav: {}, nav: {},
perf: {}, perf: {},
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<script type="module" src="../js/mojo/chrome_helper.js"></script> <script type="module" src="../js/mojo/chrome_helper.js"></script>
<script type="module" src="../js/type.js"></script> <script type="module" src="../js/type.js"></script>
<script type="module" src="../js/perf.js"></script> <script type="module" src="../js/perf.js"></script>
<script defer src="../js/intent.js"></script> <script type="module" src="../js/intent.js"></script>
<script defer src="../js/background_ops.js"></script> <script defer src="../js/background_ops.js"></script>
<script defer src="../js/background.js"></script> <script defer src="../js/background.js"></script>
</head> </head>
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
<script type="module" src="../js/type.js"></script> <script type="module" src="../js/type.js"></script>
<script type="module" src="../js/perf.js"></script> <script type="module" src="../js/perf.js"></script>
<script defer src="../js/metrics.js"></script> <script defer src="../js/metrics.js"></script>
<script defer src="../js/intent.js"></script> <script type="module" src="../js/intent.js"></script>
<script type="module" src="../js/util.js"></script> <script type="module" src="../js/util.js"></script>
<script type="module" src="../js/toast.js"></script> <script type="module" src="../js/toast.js"></script>
<script type="module" src="../js/tooltip.js"></script> <script type="module" src="../js/tooltip.js"></script>
......
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