Commit a2263faa authored by Josh Nohle's avatar Josh Nohle Committed by Commit Bot

Add closure compiler checks to chrome://proximity-auth page

We fix the closure compiler errors on the page.

Bug: 993373
Change-Id: If2b884ddb55efa27fd2c2c1c764fe1c6dda80dcd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1752246
Commit-Queue: Josh Nohle <nohle@chromium.org>
Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#691746}
parent f1e939a2
...@@ -1308,7 +1308,10 @@ if (closure_compile) { ...@@ -1308,7 +1308,10 @@ if (closure_compile) {
"ui/webui/resources:closure_compile", "ui/webui/resources:closure_compile",
] ]
if (is_chromeos) { if (is_chromeos) {
data_deps += [ "ui/file_manager:closure_compile" ] data_deps += [
"chromeos/components:closure_compile",
"ui/file_manager:closure_compile",
]
} }
if (is_android) { if (is_android) {
data_deps += [ "components/offline_pages/resources:closure_compile" ] data_deps += [ "components/offline_pages/resources:closure_compile" ]
......
...@@ -28,3 +28,9 @@ test("chromeos_components_unittests") { ...@@ -28,3 +28,9 @@ test("chromeos_components_unittests") {
"//mojo/core/embedder", "//mojo/core/embedder",
] ]
} }
group("closure_compile") {
deps = [
"//chromeos/components/multidevice/debug_webui/resources:closure_compile",
]
}
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//third_party/closure_compiler/compile_js.gni")
assert(is_chromeos, "Proximity Auth is Chrome OS only")
js_type_check("closure_compile") {
deps = [
":logs",
":proximity_auth",
":webui",
]
}
js_library("webui") {
externs_list = [ "$externs_path/chrome_send.js" ]
}
js_library("logs") {
deps = [
":webui",
]
}
js_library("proximity_auth") {
deps = [
":logs",
":webui",
"//chromeos/services/multidevice_setup/public/mojom:mojom_js_library_for_compile",
]
}
...@@ -3,7 +3,18 @@ ...@@ -3,7 +3,18 @@
* found in the LICENSE file. * found in the LICENSE file.
*/ */
Logs = { /**
* @typedef {{
* text: string,
* time: string,
* file: string,
* line: number,
* severity: number,
*}}
*/
let Log;
const Logs = {
controller_: null, controller_: null,
/** /**
...@@ -19,7 +30,7 @@ Logs = { ...@@ -19,7 +30,7 @@ Logs = {
var saveLogsButton = document.getElementById('save-logs-button'); var saveLogsButton = document.getElementById('save-logs-button');
saveLogsButton.onclick = () => { saveLogsButton.onclick = () => {
this.saveLogs(); Logs.saveLogs();
}; };
WebUI.getLogMessages(); WebUI.getLogMessages();
...@@ -49,9 +60,10 @@ Logs = { ...@@ -49,9 +60,10 @@ Logs = {
* contained in this object will be invoked by the browser for each operation * contained in this object will be invoked by the browser for each operation
* performed on the native LogBuffer. * performed on the native LogBuffer.
*/ */
LogBufferInterface = { const LogBufferInterface = {
/** /**
* Called when a new log message is added. * Called when a new log message is added.
* @param {!Log} log
*/ */
onLogMessageAdded: function(log) { onLogMessageAdded: function(log) {
if (Logs.controller_) { if (Logs.controller_) {
...@@ -71,6 +83,7 @@ LogBufferInterface = { ...@@ -71,6 +83,7 @@ LogBufferInterface = {
/** /**
* Called in response to chrome.send('getLogMessages') with the log messages * Called in response to chrome.send('getLogMessages') with the log messages
* currently in the buffer. * currently in the buffer.
* @param {!Array<Log>} messages
*/ */
onGotLogMessages: function(messages) { onGotLogMessages: function(messages) {
if (Logs.controller_) { if (Logs.controller_) {
...@@ -115,6 +128,7 @@ class LogsListController { ...@@ -115,6 +128,7 @@ class LogsListController {
/** /**
* Adds a log to the logs list. * Adds a log to the logs list.
* @param {!Log} log
*/ */
add(log) { add(log) {
var directories = log.file.split('/'); var directories = log.file.split('/');
...@@ -135,6 +149,7 @@ class LogsListController { ...@@ -135,6 +149,7 @@ class LogsListController {
/** /**
* Initializes the log list from an array of logs. * Initializes the log list from an array of logs.
* @param {!Array<!Log>} logs
*/ */
set(logs) { set(logs) {
this.clear(); this.clear();
......
...@@ -3,7 +3,47 @@ ...@@ -3,7 +3,47 @@
* found in the LICENSE file. * found in the LICENSE file.
*/ */
ProximityAuth = { /**
* An object containing information about the Chromebook's latest Enrollment or
* DeviceSync call to the CryptAuth server.
* @typedef {{
* lastSuccessTime: number,
* nextRefreshTime: number,
* recoveringFromFailure: boolean,
* operationInProgress: boolean,
* }}
*/
let SyncState;
/**
* @typedef {{
* userPresent: number,
* secureScreenLock: number,
* trustAgent: number,
*}}
*/
let RemoteState;
/**
* An object containing data for devices returned by CryptAuth DeviceSync.
* @typedef {{
* publicKey: string,
* publicKeyTruncated: string,
* friendlyDeviceName: string,
* noPiiName: string,
* unlockKey: boolean,
* hasMobileHotspot: boolean,
* connectionStatus: string,
* featureStates: string,
* remoteState: (!RemoteState|undefined),
* isArcPlusPlusEnrollment: (boolean|undefined),
* isPixelPhone: (boolean|undefined),
* bluetoothAddress: (string|undefined),
* }}
*/
let RemoteDevice;
const ProximityAuth = {
cryptauthController_: null, cryptauthController_: null,
remoteDevicesController_: null, remoteDevicesController_: null,
findEligibleDevicesController_: null, findEligibleDevicesController_: null,
...@@ -60,6 +100,7 @@ class CryptAuthController { ...@@ -60,6 +100,7 @@ class CryptAuthController {
/** /**
* Sets the local device's ID. Note that this value is truncated since the * Sets the local device's ID. Note that this value is truncated since the
* full value is very long and does not cleanly fit on the screen. * full value is very long and does not cleanly fit on the screen.
* @param {string} deviceIdTruncated
*/ */
setLocalDeviceId(deviceIdTruncated) { setLocalDeviceId(deviceIdTruncated) {
this.elements_.localDeviceId.textContent = deviceIdTruncated; this.elements_.localDeviceId.textContent = deviceIdTruncated;
...@@ -67,6 +108,7 @@ class CryptAuthController { ...@@ -67,6 +108,7 @@ class CryptAuthController {
/** /**
* Update the enrollment state in the UI. * Update the enrollment state in the UI.
* @param {!SyncState} state
*/ */
updateEnrollmentState(state) { updateEnrollmentState(state) {
this.elements_.lastEnrollment.textContent = this.elements_.lastEnrollment.textContent =
...@@ -74,9 +116,9 @@ class CryptAuthController { ...@@ -74,9 +116,9 @@ class CryptAuthController {
this.elements_.nextEnrollment.textContent = this.elements_.nextEnrollment.textContent =
this.getNextRefreshString_(state); this.getNextRefreshString_(state);
if (state['recoveringFromFailure']) { if (state.recoveringFromFailure) {
this.elements_.enrollmentTitle.setAttribute('state', 'failure'); this.elements_.enrollmentTitle.setAttribute('state', 'failure');
} else if (state['operationInProgress']) { } else if (state.operationInProgress) {
this.elements_.enrollmentTitle.setAttribute('state', 'in-progress'); this.elements_.enrollmentTitle.setAttribute('state', 'in-progress');
} else { } else {
this.elements_.enrollmentTitle.setAttribute('state', 'synced'); this.elements_.enrollmentTitle.setAttribute('state', 'synced');
...@@ -85,6 +127,7 @@ class CryptAuthController { ...@@ -85,6 +127,7 @@ class CryptAuthController {
/** /**
* Updates the device sync state in the UI. * Updates the device sync state in the UI.
* @param {!SyncState} state
*/ */
updateDeviceSyncState(state) { updateDeviceSyncState(state) {
this.elements_.lastDeviceSync.textContent = this.elements_.lastDeviceSync.textContent =
...@@ -92,9 +135,9 @@ class CryptAuthController { ...@@ -92,9 +135,9 @@ class CryptAuthController {
this.elements_.nextDeviceSync.textContent = this.elements_.nextDeviceSync.textContent =
this.getNextRefreshString_(state); this.getNextRefreshString_(state);
if (state['recoveringFromFailure']) { if (state.recoveringFromFailure) {
this.elements_.deviceSyncTitle.setAttribute('state', 'failure'); this.elements_.deviceSyncTitle.setAttribute('state', 'failure');
} else if (state['operationInProgress']) { } else if (state.operationInProgress) {
this.elements_.deviceSyncTitle.setAttribute('state', 'in-progress'); this.elements_.deviceSyncTitle.setAttribute('state', 'in-progress');
} else { } else {
this.elements_.deviceSyncTitle.setAttribute('state', 'synced'); this.elements_.deviceSyncTitle.setAttribute('state', 'synced');
...@@ -103,6 +146,8 @@ class CryptAuthController { ...@@ -103,6 +146,8 @@ class CryptAuthController {
/** /**
* Returns the formatted string of the time of the last sync to be displayed. * Returns the formatted string of the time of the last sync to be displayed.
* @param {!SyncState} syncState
* @return {string}
*/ */
getLastSyncTimeString_(syncState, neverSyncedString) { getLastSyncTimeString_(syncState, neverSyncedString) {
if (syncState.lastSuccessTime == 0) if (syncState.lastSuccessTime == 0)
...@@ -113,6 +158,8 @@ class CryptAuthController { ...@@ -113,6 +158,8 @@ class CryptAuthController {
/** /**
* Returns the formatted string of the next time to refresh to be displayed. * Returns the formatted string of the next time to refresh to be displayed.
* @param {!SyncState} syncState
* @return {string}
*/ */
getNextRefreshString_(syncState) { getNextRefreshString_(syncState) {
var deltaMillis = syncState.nextRefreshTime; var deltaMillis = syncState.nextRefreshTime;
...@@ -180,6 +227,7 @@ class CryptAuthController { ...@@ -180,6 +227,7 @@ class CryptAuthController {
/** /**
* Shows a "MultiDevice Setup" notification of the given type. * Shows a "MultiDevice Setup" notification of the given type.
* @param {!chromeos.multideviceSetup.mojom.EventTypeForDebugging} type
*/ */
showMultiDeviceSetupPromoNotification_(type) { showMultiDeviceSetupPromoNotification_(type) {
this.multiDeviceSetup.triggerEventForDebugging(type).then( this.multiDeviceSetup.triggerEventForDebugging(type).then(
...@@ -212,6 +260,7 @@ class DeviceListController { ...@@ -212,6 +260,7 @@ class DeviceListController {
/** /**
* Updates the UI with the given remote devices. * Updates the UI with the given remote devices.
* @param {!Array<!RemoteDevice>} remoteDevices
*/ */
updateRemoteDevices(remoteDevices) { updateRemoteDevices(remoteDevices) {
var existingItems = var existingItems =
...@@ -230,40 +279,42 @@ class DeviceListController { ...@@ -230,40 +279,42 @@ class DeviceListController {
/** /**
* Creates a DOM element for a given remote device. * Creates a DOM element for a given remote device.
* @param {!RemoteDevice} remoteDevice
* @return {!Node}
*/ */
createRemoteDeviceItem_(remoteDevice) { createRemoteDeviceItem_(remoteDevice) {
var isUnlockKey = !!remoteDevice['unlockKey']; var isUnlockKey = !!remoteDevice.unlockKey;
var hasMobileHotspot = !!remoteDevice['hasMobileHotspot']; var hasMobileHotspot = !!remoteDevice.hasMobileHotspot;
var isArcPlusPlusEnrollment = !!remoteDevice['isArcPlusPlusEnrollment']; var isArcPlusPlusEnrollment = !!remoteDevice.isArcPlusPlusEnrollment;
var isPixelPhone = !!remoteDevice['isPixelPhone']; var isPixelPhone = !!remoteDevice.isPixelPhone;
var t = this.remoteDeviceTemplate_.content; var t = this.remoteDeviceTemplate_.content;
t.querySelector('.device-connection-status').setAttribute( t.querySelector('.device-connection-status').setAttribute(
'state', remoteDevice['connectionStatus']); 'state', remoteDevice.connectionStatus);
t.querySelector('.device-name').textContent = t.querySelector('.device-name').textContent =
remoteDevice['friendlyDeviceName']; remoteDevice.friendlyDeviceName;
t.querySelector('.no-pii-name').textContent = t.querySelector('.no-pii-name').textContent =
remoteDevice['noPiiName']; remoteDevice.noPiiName;
t.querySelector('.device-id').textContent = t.querySelector('.device-id').textContent =
remoteDevice['publicKeyTruncated']; remoteDevice.publicKeyTruncated;
t.querySelector('.software-features').textContent = t.querySelector('.software-features').textContent =
remoteDevice['featureStates']; remoteDevice.featureStates;
t.querySelector('.is-unlock-key').textContent = isUnlockKey; t.querySelector('.is-unlock-key').textContent = isUnlockKey;
t.querySelector('.supports-mobile-hotspot').textContent = hasMobileHotspot; t.querySelector('.supports-mobile-hotspot').textContent = hasMobileHotspot;
t.querySelector('.is-arc-plus-plus-enrollment').textContent = t.querySelector('.is-arc-plus-plus-enrollment').textContent =
isArcPlusPlusEnrollment; isArcPlusPlusEnrollment;
t.querySelector('.is-pixel-phone').textContent = isPixelPhone; t.querySelector('.is-pixel-phone').textContent = isPixelPhone;
if (!!remoteDevice['bluetoothAddress']) { if (!!remoteDevice.bluetoothAddress) {
t.querySelector('.bluetooth-address-row').classList.remove('hidden'); t.querySelector('.bluetooth-address-row').classList.remove('hidden');
t.querySelector('.bluetooth-address').textContent = t.querySelector('.bluetooth-address').textContent =
remoteDevice['bluetoothAddress']; remoteDevice.bluetoothAddress;
} }
var scanButton = t.querySelector('.device-scan'); var scanButton = t.querySelector('.device-scan');
scanButton.classList.toggle( scanButton.classList.toggle(
'hidden', !this.showScanButton_ || !isUnlockKey); 'hidden', !this.showScanButton_ || !isUnlockKey);
scanButton.textContent = scanButton.textContent =
remoteDevice['connectionStatus'] == 'disconnected' remoteDevice.connectionStatus == 'disconnected'
? 'EasyUnlock Scan' : 'EasyUnlock Disconnect'; ? 'EasyUnlock Scan' : 'EasyUnlock Disconnect';
t.querySelector('.device-toggle-key').classList.toggle( t.querySelector('.device-toggle-key').classList.toggle(
'hidden', !this.showToggleUnlockKeyButton_ || !isUnlockKey); 'hidden', !this.showToggleUnlockKeyButton_ || !isUnlockKey);
...@@ -272,16 +323,17 @@ class DeviceListController { ...@@ -272,16 +323,17 @@ class DeviceListController {
// Initialize buttons on new element. // Initialize buttons on new element.
element.querySelector('.device-scan').onclick = element.querySelector('.device-scan').onclick =
this.scanForDevice_.bind(this, remoteDevice['publicKey']); this.scanForDevice_.bind(this, remoteDevice.publicKey);
element.querySelector('.device-toggle-key').onclick = element.querySelector('.device-toggle-key').onclick =
this.toggleUnlockKey_.bind( this.toggleUnlockKey_.bind(
this, remoteDevice['publicKey'], !remoteDevice['unlockKey']); this, remoteDevice.publicKey, !remoteDevice.unlockKey);
return element; return element;
} }
/** /**
* Button handler to start scanning and connecting to a device. * Button handler to start scanning and connecting to a device.
* @param {string} publicKey
*/ */
scanForDevice_(publicKey) { scanForDevice_(publicKey) {
WebUI.toggleConnection(publicKey); WebUI.toggleConnection(publicKey);
...@@ -289,6 +341,8 @@ class DeviceListController { ...@@ -289,6 +341,8 @@ class DeviceListController {
/** /**
* Button handler to toggle a device as an unlock key. * Button handler to toggle a device as an unlock key.
* @param {string} publicKey
* @param {boolean} makeUnlockKey
*/ */
toggleUnlockKey_(publicKey, makeUnlockKey) { toggleUnlockKey_(publicKey, makeUnlockKey) {
console.log(publicKey); console.log(publicKey);
...@@ -311,6 +365,8 @@ class EligibleDevicesController { ...@@ -311,6 +365,8 @@ class EligibleDevicesController {
/** /**
* Updates the UI with the fetched eligible and ineligible devices. * Updates the UI with the fetched eligible and ineligible devices.
* @param {!Array<!RemoteDevice>} eligibleDevices
* @param {!Array<!RemoteDevice>} ineligibleDevices
*/ */
updateEligibleDevices(eligibleDevices, ineligibleDevices) { updateEligibleDevices(eligibleDevices, ineligibleDevices) {
this.eligibleDeviceList_.updateRemoteDevices(eligibleDevices); this.eligibleDeviceList_.updateRemoteDevices(eligibleDevices);
...@@ -328,7 +384,13 @@ class EligibleDevicesController { ...@@ -328,7 +384,13 @@ class EligibleDevicesController {
/** /**
* Interface for the native WebUI to call into our JS. * Interface for the native WebUI to call into our JS.
*/ */
LocalStateInterface = { const LocalStateInterface = {
/**
* @param {string} localDeviceId
* @param {!SyncState} enrollmentState
* @param {!SyncState} deviceSyncState
* @param {!Array<!RemoteDevice>} remoteDevices
*/
onGotLocalState: function( onGotLocalState: function(
localDeviceId, enrollmentState, deviceSyncState, remoteDevices) { localDeviceId, enrollmentState, deviceSyncState, remoteDevices) {
LocalStateInterface.setLocalDeviceId(localDeviceId); LocalStateInterface.setLocalDeviceId(localDeviceId);
...@@ -337,18 +399,22 @@ LocalStateInterface = { ...@@ -337,18 +399,22 @@ LocalStateInterface = {
LocalStateInterface.onRemoteDevicesChanged(remoteDevices); LocalStateInterface.onRemoteDevicesChanged(remoteDevices);
}, },
/** @param {string} localDeviceId */
setLocalDeviceId: function(localDeviceId) { setLocalDeviceId: function(localDeviceId) {
ProximityAuth.cryptauthController_.setLocalDeviceId(localDeviceId); ProximityAuth.cryptauthController_.setLocalDeviceId(localDeviceId);
}, },
/** @param {!SyncState} enrollmentState */
onEnrollmentStateChanged: function(enrollmentState) { onEnrollmentStateChanged: function(enrollmentState) {
ProximityAuth.cryptauthController_.updateEnrollmentState(enrollmentState); ProximityAuth.cryptauthController_.updateEnrollmentState(enrollmentState);
}, },
/** @param {!SyncState} deviceSyncState */
onDeviceSyncStateChanged: function(deviceSyncState) { onDeviceSyncStateChanged: function(deviceSyncState) {
ProximityAuth.cryptauthController_.updateDeviceSyncState(deviceSyncState); ProximityAuth.cryptauthController_.updateDeviceSyncState(deviceSyncState);
}, },
/** @param {!Array<!RemoteDevice>} remoteDevices */
onRemoteDevicesChanged: function(remoteDevices) { onRemoteDevicesChanged: function(remoteDevices) {
ProximityAuth.remoteDevicesController_.updateRemoteDevices(remoteDevices); ProximityAuth.remoteDevicesController_.updateRemoteDevices(remoteDevices);
} }
...@@ -357,7 +423,11 @@ LocalStateInterface = { ...@@ -357,7 +423,11 @@ LocalStateInterface = {
/** /**
* Interface for the native WebUI to call into our JS. * Interface for the native WebUI to call into our JS.
*/ */
CryptAuthInterface = { const CryptAuthInterface = {
/**
* @param {!Array<!RemoteDevice>} eligibleDevices
* @param {!Array<!RemoteDevice>} ineligibleDevices
*/
onGotEligibleDevices: function(eligibleDevices, ineligibleDevices) { onGotEligibleDevices: function(eligibleDevices, ineligibleDevices) {
ProximityAuth.eligibleDevicesController_.updateEligibleDevices( ProximityAuth.eligibleDevicesController_.updateEligibleDevices(
eligibleDevices, ineligibleDevices); eligibleDevices, ineligibleDevices);
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
/** /**
* JavaScript hooks into the native WebUI handler. * JavaScript hooks into the native WebUI handler.
*/ */
WebUI = { const WebUI = {
getLogMessages: function() { getLogMessages: function() {
chrome.send('getLogMessages'); chrome.send('getLogMessages');
}, },
......
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