Commit 8521257c authored by dpapad's avatar dpapad Committed by Commit Bot

SyncInternals WebUI: Fix style violations and enable PRESUBMIT checks.

Specifically:
 - Replace var with let/const (using lebab)
 - Fix missing/extra semicolon violations
 - Fix missing curly braces violations
 - Fix double quotes violations
 - Fix JS naming violations
 - clang-format
 - Add PRESUBMIT to catch these automatically moving forward.

Bug: 986001,792774
Change-Id: I1d180fd3557243e08b0009c4fdc122ffa742b505
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1716094
Auto-Submit: Demetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Marc Treib <treib@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#680372}
parent 6fc9fbac
# 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.
def CheckChangeOnUpload(input_api, output_api):
return _CommonChecks(input_api, output_api)
def CheckChangeOnCommit(input_api, output_api):
return _CommonChecks(input_api, output_api)
def _CommonChecks(input_api, output_api):
results = []
results += input_api.canned_checks.CheckPatchFormatted(input_api, output_api,
check_js=True)
try:
import sys
old_sys_path = sys.path[:]
cwd = input_api.PresubmitLocalPath()
sys.path += [input_api.os_path.join(cwd, '..', '..', '..', '..', 'tools')]
from web_dev_style import presubmit_support
results += presubmit_support.CheckStyle(input_api, output_api)
finally:
sys.path = old_sys_path
return results
...@@ -11,8 +11,8 @@ cr.define('chrome.sync.about_tab', function() { ...@@ -11,8 +11,8 @@ cr.define('chrome.sync.about_tab', function() {
this.removeAttribute('highlighted'); this.removeAttribute('highlighted');
} }
var oldStr = oldVal.toString(); const oldStr = oldVal.toString();
var newStr = newVal.toString(); const newStr = newVal.toString();
if (oldStr != '' && oldStr != newStr) { if (oldStr != '' && oldStr != newStr) {
// Note the addListener function does not end up creating duplicate // Note the addListener function does not end up creating duplicate
// listeners. There can be only one listener per event at a time. // listeners. There can be only one listener per event at a time.
...@@ -24,7 +24,7 @@ cr.define('chrome.sync.about_tab', function() { ...@@ -24,7 +24,7 @@ cr.define('chrome.sync.about_tab', function() {
function refreshAboutInfo(aboutInfo) { function refreshAboutInfo(aboutInfo) {
chrome.sync.aboutInfo = aboutInfo; chrome.sync.aboutInfo = aboutInfo;
var aboutInfoDiv = $('about-info'); const aboutInfoDiv = $('about-info');
jstProcess(new JsEvalContext(aboutInfo), aboutInfoDiv); jstProcess(new JsEvalContext(aboutInfo), aboutInfoDiv);
} }
...@@ -33,13 +33,13 @@ cr.define('chrome.sync.about_tab', function() { ...@@ -33,13 +33,13 @@ cr.define('chrome.sync.about_tab', function() {
} }
function onAboutInfoCountersUpdated(e) { function onAboutInfoCountersUpdated(e) {
var details = e.details; const details = e.details;
var modelType = details.modelType; const modelType = details.modelType;
var counters = details.counters; const counters = details.counters;
var type_status_array = chrome.sync.aboutInfo.type_status; const typeStatusArray = chrome.sync.aboutInfo.type_status;
type_status_array.forEach(function(row) { typeStatusArray.forEach(function(row) {
if (row.name == modelType) { if (row.name == modelType) {
// There are three types of counters, only "status" counters have these // There are three types of counters, only "status" counters have these
// fields. Keep the old values if updated fields are not present. // fields. Keep the old values if updated fields are not present.
...@@ -52,8 +52,7 @@ cr.define('chrome.sync.about_tab', function() { ...@@ -52,8 +52,7 @@ cr.define('chrome.sync.about_tab', function() {
} }
}); });
jstProcess( jstProcess(
new JsEvalContext({ type_status: type_status_array }), new JsEvalContext({type_status: typeStatusArray}), $('typeInfo'));
$('typeInfo'));
} }
/** /**
...@@ -74,17 +73,17 @@ cr.define('chrome.sync.about_tab', function() { ...@@ -74,17 +73,17 @@ cr.define('chrome.sync.about_tab', function() {
} }
/** Container for accumulated sync protocol events. */ /** Container for accumulated sync protocol events. */
var protocolEvents = []; const protocolEvents = [];
/** We may receive re-delivered events. Keep a record of ones we've seen. */ /** We may receive re-delivered events. Keep a record of ones we've seen. */
var knownEventTimestamps = {}; const knownEventTimestamps = {};
/** /**
* Callback for incoming protocol events. * Callback for incoming protocol events.
* @param {Event} e The protocol event. * @param {Event} e The protocol event.
*/ */
function onReceivedProtocolEvent(e) { function onReceivedProtocolEvent(e) {
var details = e.details; const details = e.details;
// Return early if we've seen this event before. Assumes that timestamps // Return early if we've seen this event before. Assumes that timestamps
// are sufficiently high resolution to uniquely identify an event. // are sufficiently high resolution to uniquely identify an event.
...@@ -95,24 +94,25 @@ cr.define('chrome.sync.about_tab', function() { ...@@ -95,24 +94,25 @@ cr.define('chrome.sync.about_tab', function() {
knownEventTimestamps[details.time] = true; knownEventTimestamps[details.time] = true;
protocolEvents.push(details); protocolEvents.push(details);
var trafficContainer = $('traffic-event-container'); const trafficContainer = $('traffic-event-container');
// Scroll to the bottom if we were already at the bottom. Otherwise, leave // Scroll to the bottom if we were already at the bottom. Otherwise, leave
// the scrollbar alone. // the scrollbar alone.
var shouldScrollDown = isScrolledToBottom(trafficContainer); const shouldScrollDown = isScrolledToBottom(trafficContainer);
var context = new JsEvalContext({ events: protocolEvents }); const context = new JsEvalContext({events: protocolEvents});
jstProcess(context, trafficContainer); jstProcess(context, trafficContainer);
if (shouldScrollDown) if (shouldScrollDown) {
scrollToBottom(trafficContainer); scrollToBottom(trafficContainer);
}
} }
/** /**
* Initializes state and callbacks for the protocol event log UI. * Initializes state and callbacks for the protocol event log UI.
*/ */
function initProtocolEventLog() { function initProtocolEventLog() {
var includeSpecificsCheckbox = $('capture-specifics'); const includeSpecificsCheckbox = $('capture-specifics');
includeSpecificsCheckbox.addEventListener('change', function(event) { includeSpecificsCheckbox.addEventListener('change', function(event) {
chrome.sync.setIncludeSpecifics(includeSpecificsCheckbox.checked); chrome.sync.setIncludeSpecifics(includeSpecificsCheckbox.checked);
}); });
...@@ -123,7 +123,7 @@ cr.define('chrome.sync.about_tab', function() { ...@@ -123,7 +123,7 @@ cr.define('chrome.sync.about_tab', function() {
// Make the prototype jscontent element disappear. // Make the prototype jscontent element disappear.
jstProcess({}, $('traffic-event-container')); jstProcess({}, $('traffic-event-container'));
var triggerRefreshButton = $('trigger-refresh'); const triggerRefreshButton = $('trigger-refresh');
triggerRefreshButton.addEventListener('click', function(event) { triggerRefreshButton.addEventListener('click', function(event) {
chrome.sync.triggerRefresh(); chrome.sync.triggerRefresh();
}); });
...@@ -135,15 +135,15 @@ cr.define('chrome.sync.about_tab', function() { ...@@ -135,15 +135,15 @@ cr.define('chrome.sync.about_tab', function() {
function initStatusDumpButton() { function initStatusDumpButton() {
$('status-data').hidden = true; $('status-data').hidden = true;
var dumpStatusButton = $('dump-status'); const dumpStatusButton = $('dump-status');
dumpStatusButton.addEventListener('click', function(event) { dumpStatusButton.addEventListener('click', function(event) {
var aboutInfo = chrome.sync.aboutInfo; const aboutInfo = chrome.sync.aboutInfo;
if (!$('include-ids').checked) { if (!$('include-ids').checked) {
aboutInfo.details = chrome.sync.aboutInfo.details.filter(function(el) { aboutInfo.details = chrome.sync.aboutInfo.details.filter(function(el) {
return !el.is_sensitive; return !el.is_sensitive;
}); });
} }
var data = ''; let data = '';
data += new Date().toString() + '\n'; data += new Date().toString() + '\n';
data += '======\n'; data += '======\n';
data += 'Status\n'; data += 'Status\n';
...@@ -154,7 +154,7 @@ cr.define('chrome.sync.about_tab', function() { ...@@ -154,7 +154,7 @@ cr.define('chrome.sync.about_tab', function() {
$('status-data').hidden = false; $('status-data').hidden = false;
}); });
var importStatusButton = $('import-status'); const importStatusButton = $('import-status');
importStatusButton.addEventListener('click', function(event) { importStatusButton.addEventListener('click', function(event) {
$('status-data').hidden = false; $('status-data').hidden = false;
if ($('status-text').value.length == 0) { if ($('status-text').value.length == 0) {
...@@ -164,8 +164,8 @@ cr.define('chrome.sync.about_tab', function() { ...@@ -164,8 +164,8 @@ cr.define('chrome.sync.about_tab', function() {
} }
// First remove any characters before the '{'. // First remove any characters before the '{'.
var data = $('status-text').value; let data = $('status-text').value;
var firstBrace = data.indexOf('{'); const firstBrace = data.indexOf('{');
if (firstBrace < 0) { if (firstBrace < 0) {
$('status-text').value = 'Invalid sync status dump.'; $('status-text').value = 'Invalid sync status dump.';
return; return;
...@@ -181,7 +181,7 @@ cr.define('chrome.sync.about_tab', function() { ...@@ -181,7 +181,7 @@ cr.define('chrome.sync.about_tab', function() {
'onCountersUpdated', 'onCountersUpdated',
onAboutInfoCountersUpdated); onAboutInfoCountersUpdated);
var aboutInfo = JSON.parse(data); const aboutInfo = JSON.parse(data);
refreshAboutInfo(aboutInfo); refreshAboutInfo(aboutInfo);
}); });
} }
...@@ -195,12 +195,12 @@ cr.define('chrome.sync.about_tab', function() { ...@@ -195,12 +195,12 @@ cr.define('chrome.sync.about_tab', function() {
// We ignore proto clicks to keep it copyable. // We ignore proto clicks to keep it copyable.
return; return;
} }
var traffic_event_div = e.target; let trafficEventDiv = e.target;
// Click might be on div's child. // Click might be on div's child.
if (traffic_event_div.nodeName != "DIV") { if (trafficEventDiv.nodeName != 'DIV') {
traffic_event_div = traffic_event_div.parentNode; trafficEventDiv = trafficEventDiv.parentNode;
} }
traffic_event_div.classList.toggle('traffic-event-entry-expanded'); trafficEventDiv.classList.toggle('traffic-event-entry-expanded');
} }
/** /**
......
...@@ -30,7 +30,7 @@ cr.define('chrome.sync', function() { ...@@ -30,7 +30,7 @@ cr.define('chrome.sync', function() {
}; };
/** @return {!Timer} An object which measures elapsed time. */ /** @return {!Timer} An object which measures elapsed time. */
var makeTimer = function() { const makeTimer = function() {
return new Timer; return new Timer;
}; };
...@@ -38,8 +38,8 @@ cr.define('chrome.sync', function() { ...@@ -38,8 +38,8 @@ cr.define('chrome.sync', function() {
* @param {string} name The name of the event type. * @param {string} name The name of the event type.
* @param {!Object} details A collection of event-specific details. * @param {!Object} details A collection of event-specific details.
*/ */
var dispatchEvent = function(name, details) { const dispatchEvent = function(name, details) {
var e = new Event(name); const e = new Event(name);
e.details = details; e.details = details;
chrome.sync.events.dispatchEvent(e); chrome.sync.events.dispatchEvent(e);
}; };
...@@ -48,7 +48,7 @@ cr.define('chrome.sync', function() { ...@@ -48,7 +48,7 @@ cr.define('chrome.sync', function() {
* Registers to receive a stream of events through * Registers to receive a stream of events through
* chrome.sync.dispatchEvent(). * chrome.sync.dispatchEvent().
*/ */
var registerForEvents = function() { const registerForEvents = function() {
chrome.send('registerForEvents'); chrome.send('registerForEvents');
}; };
...@@ -56,15 +56,15 @@ cr.define('chrome.sync', function() { ...@@ -56,15 +56,15 @@ cr.define('chrome.sync', function() {
* Registers to receive a stream of status counter update events * Registers to receive a stream of status counter update events
* chrome.sync.dispatchEvent(). * chrome.sync.dispatchEvent().
*/ */
var registerForPerTypeCounters = function() { const registerForPerTypeCounters = function() {
chrome.send('registerForPerTypeCounters'); chrome.send('registerForPerTypeCounters');
} };
/** /**
* Asks the browser to refresh our snapshot of sync state. Should result * Asks the browser to refresh our snapshot of sync state. Should result
* in an onAboutInfoUpdated event being emitted. * in an onAboutInfoUpdated event being emitted.
*/ */
var requestUpdatedAboutInfo = function() { const requestUpdatedAboutInfo = function() {
chrome.send('requestUpdatedAboutInfo'); chrome.send('requestUpdatedAboutInfo');
}; };
...@@ -72,7 +72,7 @@ cr.define('chrome.sync', function() { ...@@ -72,7 +72,7 @@ cr.define('chrome.sync', function() {
* Asks the browser to send us the list of registered types. Should result * Asks the browser to send us the list of registered types. Should result
* in an onReceivedListOfTypes event being emitted. * in an onReceivedListOfTypes event being emitted.
*/ */
var requestListOfTypes = function() { const requestListOfTypes = function() {
chrome.send('requestListOfTypes'); chrome.send('requestListOfTypes');
}; };
...@@ -81,14 +81,14 @@ cr.define('chrome.sync', function() { ...@@ -81,14 +81,14 @@ cr.define('chrome.sync', function() {
* flag. Should result in an onReceivedIncludeSpecificsInitialState event * flag. Should result in an onReceivedIncludeSpecificsInitialState event
* being emitted. * being emitted.
*/ */
var requestIncludeSpecificsInitialState = function() { const requestIncludeSpecificsInitialState = function() {
chrome.send('requestIncludeSpecificsInitialState'); chrome.send('requestIncludeSpecificsInitialState');
} };
/** /**
* Asks the browser if we should show the User Events tab or not. * Asks the browser if we should show the User Events tab or not.
*/ */
var requestUserEventsVisibility = function() { const requestUserEventsVisibility = function() {
chrome.send('requestUserEventsVisibility'); chrome.send('requestUserEventsVisibility');
}; };
...@@ -99,7 +99,7 @@ cr.define('chrome.sync', function() { ...@@ -99,7 +99,7 @@ cr.define('chrome.sync', function() {
* @param {boolean} includeSpecifics Whether protocol events include * @param {boolean} includeSpecifics Whether protocol events include
* specifics. * specifics.
*/ */
var setIncludeSpecifics = function(includeSpecifics) { const setIncludeSpecifics = function(includeSpecifics) {
chrome.send('setIncludeSpecifics', [includeSpecifics]); chrome.send('setIncludeSpecifics', [includeSpecifics]);
}; };
...@@ -109,35 +109,35 @@ cr.define('chrome.sync', function() { ...@@ -109,35 +109,35 @@ cr.define('chrome.sync', function() {
* @param {string} eventTimeUsec Timestamp for the new event. * @param {string} eventTimeUsec Timestamp for the new event.
* @param {string} navigationId Timestamp of linked sessions navigation. * @param {string} navigationId Timestamp of linked sessions navigation.
*/ */
var writeUserEvent = function(eventTimeUsec, navigationId) { const writeUserEvent = function(eventTimeUsec, navigationId) {
chrome.send('writeUserEvent', [eventTimeUsec, navigationId]); chrome.send('writeUserEvent', [eventTimeUsec, navigationId]);
}; };
/** /**
* Triggers a RequestStart call on the SyncService. * Triggers a RequestStart call on the SyncService.
*/ */
var requestStart = function() { const requestStart = function() {
chrome.send('requestStart'); chrome.send('requestStart');
}; };
/** /**
* Triggers a RequestStop(KEEP_DATA) call on the SyncService. * Triggers a RequestStop(KEEP_DATA) call on the SyncService.
*/ */
var requestStopKeepData = function() { const requestStopKeepData = function() {
chrome.send('requestStopKeepData'); chrome.send('requestStopKeepData');
}; };
/** /**
* Triggers a RequestStop(CLEAR_DATA) call on the SyncService. * Triggers a RequestStop(CLEAR_DATA) call on the SyncService.
*/ */
var requestStopClearData = function() { const requestStopClearData = function() {
chrome.send('requestStopClearData'); chrome.send('requestStopClearData');
}; };
/** /**
* Triggers a GetUpdates call for all enabled datatypes. * Triggers a GetUpdates call for all enabled datatypes.
*/ */
var triggerRefresh = function() { const triggerRefresh = function() {
chrome.send('triggerRefresh'); chrome.send('triggerRefresh');
}; };
...@@ -145,14 +145,14 @@ cr.define('chrome.sync', function() { ...@@ -145,14 +145,14 @@ cr.define('chrome.sync', function() {
* Counter to uniquely identify requests while they're in progress. * Counter to uniquely identify requests while they're in progress.
* Used in the implementation of GetAllNodes. * Used in the implementation of GetAllNodes.
*/ */
var requestId = 0; let requestId = 0;
/** /**
* A map from counter values to asynchronous request callbacks. * A map from counter values to asynchronous request callbacks.
* Used in the implementation of GetAllNodes. * Used in the implementation of GetAllNodes.
* @type {!Object<!Function>} * @type {!Object<!Function>}
*/ */
var requestCallbacks = {}; const requestCallbacks = {};
/** /**
* Asks the browser to send us a copy of all existing sync nodes. * Asks the browser to send us a copy of all existing sync nodes.
...@@ -160,7 +160,7 @@ cr.define('chrome.sync', function() { ...@@ -160,7 +160,7 @@ cr.define('chrome.sync', function() {
* *
* @param {function(!Object)} callback The function to call with the response. * @param {function(!Object)} callback The function to call with the response.
*/ */
var getAllNodes = function(callback) { const getAllNodes = function(callback) {
requestId++; requestId++;
requestCallbacks[requestId] = callback; requestCallbacks[requestId] = callback;
chrome.send('getAllNodes', [requestId]); chrome.send('getAllNodes', [requestId]);
...@@ -172,7 +172,7 @@ cr.define('chrome.sync', function() { ...@@ -172,7 +172,7 @@ cr.define('chrome.sync', function() {
* @param {number} id The requestId passed in with the request. * @param {number} id The requestId passed in with the request.
* @param {Object} response The response to the request. * @param {Object} response The response to the request.
*/ */
var getAllNodesCallback = function(id, response) { const getAllNodesCallback = function(id, response) {
requestCallbacks[id](response); requestCallbacks[id](response);
delete requestCallbacks[id]; delete requestCallbacks[id];
}; };
......
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
// found in the LICENSE file. // found in the LICENSE file.
(function() { (function() {
var dumpToTextButton = $('dump-to-text'); const dumpToTextButton = $('dump-to-text');
var dataDump = $('data-dump'); const dataDump = $('data-dump');
dumpToTextButton.addEventListener('click', function(event) { dumpToTextButton.addEventListener('click', function(event) {
// TODO(akalin): Add info like Chrome version, OS, date dumped, etc. // TODO(akalin): Add info like Chrome version, OS, date dumped, etc.
var data = ''; let data = '';
data += '======\n'; data += '======\n';
data += 'Status\n'; data += 'Status\n';
data += '======\n'; data += '======\n';
...@@ -32,7 +32,7 @@ dumpToTextButton.addEventListener('click', function(event) { ...@@ -32,7 +32,7 @@ dumpToTextButton.addEventListener('click', function(event) {
dataDump.textContent = data; dataDump.textContent = data;
}); });
var allFields = [ const allFields = [
'ID', 'ID',
'IS_UNSYNCED', 'IS_UNSYNCED',
'IS_UNAPPLIED_UPDATE', 'IS_UNAPPLIED_UPDATE',
...@@ -51,9 +51,9 @@ var allFields = [ ...@@ -51,9 +51,9 @@ var allFields = [
function versionToDateString(version) { function versionToDateString(version) {
// TODO(mmontgomery): ugly? Hacky? Is there a better way? // TODO(mmontgomery): ugly? Hacky? Is there a better way?
var epochLength = Date.now().toString().length; const epochLength = Date.now().toString().length;
var epochTime = parseInt(version.slice(0, epochLength), 10); const epochTime = parseInt(version.slice(0, epochLength), 10);
var date = new Date(epochTime); const date = new Date(epochTime);
return date.toString(); return date.toString();
} }
...@@ -63,22 +63,25 @@ function versionToDateString(version) { ...@@ -63,22 +63,25 @@ function versionToDateString(version) {
*/ */
function serializeNode(node) { function serializeNode(node) {
return allFields.map(function(field) { return allFields.map(function(field) {
var fieldVal; let fieldVal;
if (field == 'SERVER_VERSION_TIME') { if (field == 'SERVER_VERSION_TIME') {
var version = node['SERVER_VERSION']; const version = node['SERVER_VERSION'];
if (version != null) { if (version != null) {
fieldVal = versionToDateString(version); fieldVal = versionToDateString(version);
} }
} if (field == 'BASE_VERSION_TIME') { }
var version = node['BASE_VERSION']; if (field == 'BASE_VERSION_TIME') {
const version = node['BASE_VERSION'];
if (version != null) { if (version != null) {
fieldVal = versionToDateString(version); fieldVal = versionToDateString(version);
} }
} else if ((field == 'SERVER_SPECIFICS' || field == 'SPECIFICS') && } else if (
(!$('include-specifics').checked)) { (field == 'SERVER_SPECIFICS' || field == 'SPECIFICS') &&
(!$('include-specifics').checked)) {
fieldVal = 'REDACTED'; fieldVal = 'REDACTED';
} else if ((field == 'SERVER_SPECIFICS' || field == 'SPECIFICS') && } else if (
$('include-specifics').checked) { (field == 'SERVER_SPECIFICS' || field == 'SPECIFICS') &&
$('include-specifics').checked) {
fieldVal = JSON.stringify(node[field]); fieldVal = JSON.stringify(node[field]);
} else { } else {
fieldVal = node[field]; fieldVal = node[field];
...@@ -92,7 +95,7 @@ function serializeNode(node) { ...@@ -92,7 +95,7 @@ function serializeNode(node) {
* @return {boolean} True if the type's checkbox is selected. * @return {boolean} True if the type's checkbox is selected.
*/ */
function isSelectedDatatype(type) { function isSelectedDatatype(type) {
var typeCheckbox = $(type); const typeCheckbox = $(type);
// Some types, such as 'Top level folder', appear in the list of nodes // Some types, such as 'Top level folder', appear in the list of nodes
// but not in the list of selectable items. // but not in the list of selectable items.
if (typeCheckbox == null) { if (typeCheckbox == null) {
...@@ -102,28 +105,26 @@ function isSelectedDatatype(type) { ...@@ -102,28 +105,26 @@ function isSelectedDatatype(type) {
} }
function makeBlobUrl(data) { function makeBlobUrl(data) {
var textBlob = new Blob([data], {type: 'octet/stream'}); const textBlob = new Blob([data], {type: 'octet/stream'});
var blobUrl = window.URL.createObjectURL(textBlob); const blobUrl = window.URL.createObjectURL(textBlob);
return blobUrl; return blobUrl;
} }
function makeDownloadName() { function makeDownloadName() {
// Format is sync-data-dump-$epoch-$year-$month-$day-$OS.csv. // Format is sync-data-dump-$epoch-$year-$month-$day-$OS.csv.
var now = new Date(); const now = new Date();
var friendlyDate = [now.getFullYear(), const friendlyDate =
now.getMonth() + 1, [now.getFullYear(), now.getMonth() + 1, now.getDate()].join('-');
now.getDate()].join('-'); const name = [
var name = ['sync-data-dump', 'sync-data-dump', friendlyDate, Date.now(), navigator.platform
friendlyDate, ].join('-');
Date.now(),
navigator.platform].join('-');
return [name, 'csv'].join('.'); return [name, 'csv'].join('.');
} }
function makeDateUserAgentHeader() { function makeDateUserAgentHeader() {
var now = new Date(); const now = new Date();
var userAgent = window.navigator.userAgent; const userAgent = window.navigator.userAgent;
var dateUaHeader = [now.toISOString(), userAgent].join(','); const dateUaHeader = [now.toISOString(), userAgent].join(',');
return dateUaHeader; return dateUaHeader;
} }
...@@ -135,14 +136,14 @@ function makeDateUserAgentHeader() { ...@@ -135,14 +136,14 @@ function makeDateUserAgentHeader() {
*/ */
function triggerDataDownload(nodesMap) { function triggerDataDownload(nodesMap) {
// Prepend a header with ISO date and useragent. // Prepend a header with ISO date and useragent.
var output = [makeDateUserAgentHeader()]; let output = [makeDateUserAgentHeader()];
output.push('====='); output.push('=====');
var aboutInfo = JSON.stringify(chrome.sync.aboutInfo, null, 2); const aboutInfo = JSON.stringify(chrome.sync.aboutInfo, null, 2);
output.push(aboutInfo); output.push(aboutInfo);
// Filter out non-selected types. // Filter out non-selected types.
var selectedTypesNodes = nodesMap.filter(function(x) { const selectedTypesNodes = nodesMap.filter(function(x) {
return isSelectedDatatype(x.type); return isSelectedDatatype(x.type);
}); });
...@@ -154,25 +155,25 @@ function triggerDataDownload(nodesMap) { ...@@ -154,25 +155,25 @@ function triggerDataDownload(nodesMap) {
output = output.join('\n'); output = output.join('\n');
var anchor = $('dump-to-file-anchor'); const anchor = $('dump-to-file-anchor');
anchor.href = makeBlobUrl(output); anchor.href = makeBlobUrl(output);
anchor.download = makeDownloadName(); anchor.download = makeDownloadName();
anchor.click(); anchor.click();
} }
function createTypesCheckboxes(types) { function createTypesCheckboxes(types) {
var containerElt = $('node-type-checkboxes'); const containerElt = $('node-type-checkboxes');
types.map(function(type) { types.map(function(type) {
var div = document.createElement('div'); const div = document.createElement('div');
var checkbox = document.createElement('input'); const checkbox = document.createElement('input');
checkbox.id = type; checkbox.id = type;
checkbox.type = 'checkbox'; checkbox.type = 'checkbox';
checkbox.checked = 'yes'; checkbox.checked = 'yes';
div.appendChild(checkbox); div.appendChild(checkbox);
var label = document.createElement('label'); const label = document.createElement('label');
// Assigning to label.for doesn't work. // Assigning to label.for doesn't work.
label.setAttribute('for', type); label.setAttribute('for', type);
label.innerText = type; label.innerText = type;
...@@ -183,7 +184,7 @@ function createTypesCheckboxes(types) { ...@@ -183,7 +184,7 @@ function createTypesCheckboxes(types) {
} }
function onReceivedListOfTypes(e) { function onReceivedListOfTypes(e) {
var types = e.details.types; const types = e.details.types;
types.sort(); types.sort();
createTypesCheckboxes(types); createTypesCheckboxes(types);
chrome.sync.events.removeEventListener( chrome.sync.events.removeEventListener(
...@@ -207,7 +208,7 @@ document.addEventListener('DOMContentLoaded', function() { ...@@ -207,7 +208,7 @@ document.addEventListener('DOMContentLoaded', function() {
chrome.sync.requestIncludeSpecificsInitialState(); chrome.sync.requestIncludeSpecificsInitialState();
}); });
var dumpToFileLink = $('dump-to-file'); const dumpToFileLink = $('dump-to-file');
dumpToFileLink.addEventListener('click', function(event) { dumpToFileLink.addEventListener('click', function(event) {
chrome.sync.getAllNodes(triggerDataDownload); chrome.sync.getAllNodes(triggerDataDownload);
}); });
......
...@@ -6,14 +6,14 @@ cr.define('chrome.sync.events_tab', function() { ...@@ -6,14 +6,14 @@ cr.define('chrome.sync.events_tab', function() {
'use strict'; 'use strict';
function toggleDisplay(event) { function toggleDisplay(event) {
var originatingButton = event.target; const originatingButton = event.target;
if (originatingButton.className != 'toggle-button') { if (originatingButton.className != 'toggle-button') {
return; return;
} }
var detailsNode = originatingButton.parentNode.getElementsByClassName( const detailsNode =
'details')[0]; originatingButton.parentNode.getElementsByClassName('details')[0];
var detailsColumn = detailsNode.parentNode; const detailsColumn = detailsNode.parentNode;
var detailsRow = detailsColumn.parentNode; const detailsRow = detailsColumn.parentNode;
if (!detailsRow.classList.contains('expanded')) { if (!detailsRow.classList.contains('expanded')) {
detailsRow.classList.toggle('expanded'); detailsRow.classList.toggle('expanded');
...@@ -24,16 +24,16 @@ cr.define('chrome.sync.events_tab', function() { ...@@ -24,16 +24,16 @@ cr.define('chrome.sync.events_tab', function() {
detailsColumn.removeAttribute('colspan'); detailsColumn.removeAttribute('colspan');
detailsRow.classList.toggle('expanded'); detailsRow.classList.toggle('expanded');
} }
}; }
function displaySyncEvents() { function displaySyncEvents() {
var entries = chrome.sync.log.entries; const entries = chrome.sync.log.entries;
var eventTemplateContext = { const eventTemplateContext = {
eventList: entries, eventList: entries,
}; };
var context = new JsEvalContext(eventTemplateContext); const context = new JsEvalContext(eventTemplateContext);
jstProcess(context, $('sync-events')); jstProcess(context, $('sync-events'));
}; }
function onLoad() { function onLoad() {
$('sync-events').addEventListener('click', toggleDisplay); $('sync-events').addEventListener('click', toggleDisplay);
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
cr.define('chrome.sync', function() { cr.define('chrome.sync', function() {
'use strict'; 'use strict';
var eventsByCategory = { const eventsByCategory = {
notifier: [ notifier: [
'onIncomingNotification', 'onIncomingNotification',
'onNotificationStateChange', 'onNotificationStateChange',
...@@ -50,7 +50,7 @@ cr.define('chrome.sync', function() { ...@@ -50,7 +50,7 @@ cr.define('chrome.sync', function() {
class Log extends cr.EventTarget { class Log extends cr.EventTarget {
constructor() { constructor() {
super(); super();
var self = this; const self = this;
/** /**
* The recorded log entries. * The recorded log entries.
...@@ -61,15 +61,15 @@ cr.define('chrome.sync', function() { ...@@ -61,15 +61,15 @@ cr.define('chrome.sync', function() {
/** /**
* Creates a callback function to be invoked when an event arrives. * Creates a callback function to be invoked when an event arrives.
*/ */
var makeCallback = function(categoryName, eventName) { const makeCallback = function(categoryName, eventName) {
return function(e) { return function(e) {
self.log_(categoryName, eventName, e.details); self.log_(categoryName, eventName, e.details);
}; };
}; };
for (var categoryName in eventsByCategory) { for (const categoryName in eventsByCategory) {
for (var i = 0; i < eventsByCategory[categoryName].length; ++i) { for (let i = 0; i < eventsByCategory[categoryName].length; ++i) {
var eventName = eventsByCategory[categoryName][i]; const eventName = eventsByCategory[categoryName][i];
chrome.sync.events.addEventListener( chrome.sync.events.addEventListener(
eventName, eventName,
makeCallback(categoryName, eventName)); makeCallback(categoryName, eventName));
...@@ -86,7 +86,7 @@ cr.define('chrome.sync', function() { ...@@ -86,7 +86,7 @@ cr.define('chrome.sync', function() {
* @param {!Object} details A dictionary of event-specific details. * @param {!Object} details A dictionary of event-specific details.
*/ */
log_(submodule, event, details) { log_(submodule, event, details) {
var entry = { const entry = {
submodule: submodule, submodule: submodule,
event: event, event: event,
date: new Date(), date: new Date(),
...@@ -96,7 +96,7 @@ cr.define('chrome.sync', function() { ...@@ -96,7 +96,7 @@ cr.define('chrome.sync', function() {
entry.textDetails = JSON.stringify(entry.details, null, 2); entry.textDetails = JSON.stringify(entry.details, null, 2);
this.entries.push(entry); this.entries.push(entry);
// Fire append event. // Fire append event.
var e = cr.doc.createEvent('CustomEvent'); const e = cr.doc.createEvent('CustomEvent');
e.initCustomEvent('append', false, false, entry); e.initCustomEvent('append', false, false, entry);
this.dispatchEvent(e); this.dispatchEvent(e);
} }
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* *
* @param {!Object} node The node to check. * @param {!Object} node The node to check.
*/ */
var isTypeRootNode = function(node) { const isTypeRootNode = function(node) {
return node.PARENT_ID == 'r' && node.UNIQUE_SERVER_TAG != ''; return node.PARENT_ID == 'r' && node.UNIQUE_SERVER_TAG != '';
}; };
...@@ -22,11 +22,10 @@ ...@@ -22,11 +22,10 @@
* @param {!Object} parent node. * @param {!Object} parent node.
* @param {!Object} node The node to check. * @param {!Object} node The node to check.
*/ */
var isChildOf = function(parentNode, node) { const isChildOf = function(parentNode, node) {
if (node.PARENT_ID != '') { if (node.PARENT_ID != '') {
return node.PARENT_ID == parentNode.ID; return node.PARENT_ID == parentNode.ID;
} } else {
else {
return node.modelType == parentNode.modelType; return node.modelType == parentNode.modelType;
} }
}; };
...@@ -40,7 +39,7 @@ ...@@ -40,7 +39,7 @@
* If this proves to be slow and expensive, we should experiment with moving * If this proves to be slow and expensive, we should experiment with moving
* this functionality to C++ instead. * this functionality to C++ instead.
*/ */
var nodeComparator = function(nodeA, nodeB) { const nodeComparator = function(nodeA, nodeB) {
if (nodeA.hasOwnProperty('positionIndex') && if (nodeA.hasOwnProperty('positionIndex') &&
nodeB.hasOwnProperty('positionIndex')) { nodeB.hasOwnProperty('positionIndex')) {
return nodeA.positionIndex - nodeB.positionIndex; return nodeA.positionIndex - nodeB.positionIndex;
...@@ -56,7 +55,7 @@ ...@@ -56,7 +55,7 @@
* @param {!Object} node The struct representing the node we want to display. * @param {!Object} node The struct representing the node we want to display.
*/ */
function updateNodeDetailView(node) { function updateNodeDetailView(node) {
var nodeDetailsView = $('node-details'); const nodeDetailsView = $('node-details');
nodeDetailsView.hidden = false; nodeDetailsView.hidden = false;
jstProcess(new JsEvalContext(node.entry_), nodeDetailsView); jstProcess(new JsEvalContext(node.entry_), nodeDetailsView);
} }
...@@ -77,8 +76,8 @@ ...@@ -77,8 +76,8 @@
* chrome.sync.getAllNodes(). * chrome.sync.getAllNodes().
* @extends {cr.ui.TreeItem} * @extends {cr.ui.TreeItem}
*/ */
var SyncNodeTreeItem = function(node) { const SyncNodeTreeItem = function(node) {
var treeItem = new cr.ui.TreeItem(); const treeItem = new cr.ui.TreeItem();
treeItem.__proto__ = SyncNodeTreeItem.prototype; treeItem.__proto__ = SyncNodeTreeItem.prototype;
treeItem.entry_ = node; treeItem.entry_ = node;
...@@ -103,14 +102,14 @@ ...@@ -103,14 +102,14 @@
* Finds the children of this node and appends them to the tree. * Finds the children of this node and appends them to the tree.
*/ */
handleExpand_: function(event) { handleExpand_: function(event) {
var treeItem = this; const treeItem = this;
if (treeItem.expanded_) { if (treeItem.expanded_) {
return; return;
} }
treeItem.expanded_ = true; treeItem.expanded_ = true;
var children = treeItem.tree.allNodes.filter( const children = treeItem.tree.allNodes.filter(
isChildOf.bind(undefined, treeItem.entry_)); isChildOf.bind(undefined, treeItem.entry_));
children.sort(nodeComparator); children.sort(nodeComparator);
...@@ -129,7 +128,7 @@ ...@@ -129,7 +128,7 @@
* @constructor * @constructor
* @extends {cr.ui.Tree} * @extends {cr.ui.Tree}
*/ */
var SyncNodeTree = cr.ui.define('tree'); const SyncNodeTree = cr.ui.define('tree');
SyncNodeTree.prototype = { SyncNodeTree.prototype = {
__proto__: cr.ui.Tree.prototype, __proto__: cr.ui.Tree.prototype,
...@@ -141,12 +140,12 @@ ...@@ -141,12 +140,12 @@
}, },
populate: function(nodes) { populate: function(nodes) {
var tree = this; const tree = this;
// We store the full set of nodes in the SyncNodeTree object. // We store the full set of nodes in the SyncNodeTree object.
tree.allNodes = nodes; tree.allNodes = nodes;
var roots = tree.allNodes.filter(isTypeRootNode); const roots = tree.allNodes.filter(isTypeRootNode);
roots.sort(nodeComparator); roots.sort(nodeComparator);
roots.forEach(function(typeRoot) { roots.forEach(function(typeRoot) {
...@@ -165,12 +164,12 @@ ...@@ -165,12 +164,12 @@
* Clears any existing UI state. Useful prior to a refresh. * Clears any existing UI state. Useful prior to a refresh.
*/ */
function clear() { function clear() {
var treeContainer = $('sync-node-tree-container'); const treeContainer = $('sync-node-tree-container');
while (treeContainer.firstChild) { while (treeContainer.firstChild) {
treeContainer.removeChild(treeContainer.firstChild); treeContainer.removeChild(treeContainer.firstChild);
} }
var nodeDetailsView = $('node-details'); const nodeDetailsView = $('node-details');
nodeDetailsView.hidden = true; nodeDetailsView.hidden = true;
} }
...@@ -185,12 +184,16 @@ ...@@ -185,12 +184,16 @@
chrome.sync.getAllNodes(function(nodeMap) { chrome.sync.getAllNodes(function(nodeMap) {
// Put all nodes into one big list that ignores the type. // Put all nodes into one big list that ignores the type.
var nodes = nodeMap. const nodes = nodeMap
map(function(x) { return x.nodes; }). .map(function(x) {
reduce(function(a, b) { return a.concat(b); }); return x.nodes;
})
var treeContainer = $('sync-node-tree-container'); .reduce(function(a, b) {
var tree = document.createElement('tree'); return a.concat(b);
});
const treeContainer = $('sync-node-tree-container');
const tree = document.createElement('tree');
tree.setAttribute('id', 'sync-node-tree'); tree.setAttribute('id', 'sync-node-tree');
tree.setAttribute('icon-visibility', 'parent'); tree.setAttribute('icon-visibility', 'parent');
treeContainer.appendChild(tree); treeContainer.appendChild(tree);
...@@ -205,16 +208,16 @@ ...@@ -205,16 +208,16 @@
document.addEventListener('DOMContentLoaded', function(e) { document.addEventListener('DOMContentLoaded', function(e) {
$('node-browser-refresh-button').addEventListener('click', refresh); $('node-browser-refresh-button').addEventListener('click', refresh);
var Splitter = cr.ui.Splitter; const Splitter = cr.ui.Splitter;
var customSplitter = cr.ui.define('div'); const customSplitter = cr.ui.define('div');
customSplitter.prototype = { customSplitter.prototype = {
__proto__: Splitter.prototype, __proto__: Splitter.prototype,
handleSplitterDragEnd: function(e) { handleSplitterDragEnd: function(e) {
Splitter.prototype.handleSplitterDragEnd.apply(this, arguments); Splitter.prototype.handleSplitterDragEnd.apply(this, arguments);
var treeElement = $("sync-node-tree-container"); const treeElement = $('sync-node-tree-container');
var newWidth = parseFloat(treeElement.style.width); const newWidth = parseFloat(treeElement.style.width);
treeElement.style.minWidth = Math.max(newWidth, 50) + "px"; treeElement.style.minWidth = Math.max(newWidth, 50) + "px";
} }
}; };
......
...@@ -5,13 +5,13 @@ ...@@ -5,13 +5,13 @@
// require: cr.js // require: cr.js
cr.define('chrome.sync', function() { cr.define('chrome.sync', function() {
var currSearchId = 0; let currSearchId = 0;
var setQueryString = function(queryControl, query) { const setQueryString = function(queryControl, query) {
queryControl.value = query; queryControl.value = query;
}; };
var createDoQueryFunction = function(queryControl, submitControl, query) { const createDoQueryFunction = function(queryControl, submitControl, query) {
return function() { return function() {
setQueryString(queryControl, query); setQueryString(queryControl, query);
submitControl.click(); submitControl.click();
...@@ -27,12 +27,12 @@ cr.define('chrome.sync', function() { ...@@ -27,12 +27,12 @@ cr.define('chrome.sync', function() {
* @param {!HTMLInputElement} queryControl The <input> object of * @param {!HTMLInputElement} queryControl The <input> object of
* type=search where user's query is typed. * type=search where user's query is typed.
*/ */
var decorateQuickQueryControls = function(quickLinkArray, submitControl, const decorateQuickQueryControls = function(
queryControl) { quickLinkArray, submitControl, queryControl) {
for (var index = 0; index < quickLinkArray.length; ++index) { for (let index = 0; index < quickLinkArray.length; ++index) {
var quickQuery = quickLinkArray[index].getAttribute('data-query'); const quickQuery = quickLinkArray[index].getAttribute('data-query');
var quickQueryFunction = createDoQueryFunction(queryControl, const quickQueryFunction =
submitControl, quickQuery); createDoQueryFunction(queryControl, submitControl, quickQuery);
quickLinkArray[index].addEventListener('click', quickQueryFunction); quickLinkArray[index].addEventListener('click', quickQueryFunction);
} }
}; };
...@@ -44,15 +44,19 @@ cr.define('chrome.sync', function() { ...@@ -44,15 +44,19 @@ cr.define('chrome.sync', function() {
* @param {!Function} callback The callback called with the search results. * @param {!Function} callback The callback called with the search results.
* not called if doSearch() is called again while the search is running. * not called if doSearch() is called again while the search is running.
*/ */
var doSearch = function(query, callback) { const doSearch = function(query, callback) {
var searchId = ++currSearchId; const searchId = ++currSearchId;
try { try {
var regex = new RegExp(query); const regex = new RegExp(query);
chrome.sync.getAllNodes(function(node_map) { chrome.sync.getAllNodes(function(node_map) {
// Put all nodes into one big list that ignores the type. // Put all nodes into one big list that ignores the type.
var nodes = node_map. const nodes = node_map
map(function(x) { return x.nodes; }). .map(function(x) {
reduce(function(a, b) { return a.concat(b); }); return x.nodes;
})
.reduce(function(a, b) {
return a.concat(b);
});
if (currSearchId != searchId) { if (currSearchId != searchId) {
return; return;
...@@ -84,10 +88,10 @@ cr.define('chrome.sync', function() { ...@@ -84,10 +88,10 @@ cr.define('chrome.sync', function() {
*/ */
function decorateSearchControls(queryControl, submitControl, statusControl, function decorateSearchControls(queryControl, submitControl, statusControl,
resultsControl, detailsControl) { resultsControl, detailsControl) {
var resultsDataModel = new cr.ui.ArrayDataModel([]); const resultsDataModel = new cr.ui.ArrayDataModel([]);
var searchFunction = function() { const searchFunction = function() {
var query = queryControl.value; const query = queryControl.value;
statusControl.textContent = ''; statusControl.textContent = '';
resultsDataModel.splice(0, resultsDataModel.length); resultsDataModel.splice(0, resultsDataModel.length);
if (!query) { if (!query) {
...@@ -95,7 +99,7 @@ cr.define('chrome.sync', function() { ...@@ -95,7 +99,7 @@ cr.define('chrome.sync', function() {
} }
statusControl.textContent = 'Searching for ' + query + '...'; statusControl.textContent = 'Searching for ' + query + '...';
queryControl.removeAttribute('error'); queryControl.removeAttribute('error');
var timer = chrome.sync.makeTimer(); const timer = chrome.sync.makeTimer();
doSearch(query, function(nodes, error) { doSearch(query, function(nodes, error) {
if (error) { if (error) {
statusControl.textContent = 'Error: ' + error; statusControl.textContent = 'Error: ' + error;
...@@ -107,7 +111,7 @@ cr.define('chrome.sync', function() { ...@@ -107,7 +111,7 @@ cr.define('chrome.sync', function() {
queryControl.removeAttribute('error'); queryControl.removeAttribute('error');
// TODO(akalin): Write a nicer list display. // TODO(akalin): Write a nicer list display.
for (var i = 0; i < nodes.length; ++i) { for (let i = 0; i < nodes.length; ++i) {
nodes[i].toString = function() { nodes[i].toString = function() {
return this.NON_UNIQUE_NAME; return this.NON_UNIQUE_NAME;
}; };
...@@ -129,7 +133,7 @@ cr.define('chrome.sync', function() { ...@@ -129,7 +133,7 @@ cr.define('chrome.sync', function() {
resultsControl.dataModel = resultsDataModel; resultsControl.dataModel = resultsDataModel;
resultsControl.selectionModel.addEventListener('change', function(event) { resultsControl.selectionModel.addEventListener('change', function(event) {
detailsControl.textContent = ''; detailsControl.textContent = '';
var selected = resultsControl.selectedItem; const selected = resultsControl.selectedItem;
if (selected) { if (selected) {
detailsControl.textContent = JSON.stringify(selected, null, 2); detailsControl.textContent = JSON.stringify(selected, null, 2);
} }
......
...@@ -2,95 +2,97 @@ ...@@ -2,95 +2,97 @@
// 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.
cr.exportPath('chrome.sync.traffic_log_tab', new class { cr.exportPath(
constructor() { 'chrome.sync.traffic_log_tab', new (class {
this.protocolEvents = []; constructor() {
this.knownEventTimestamps = new Set(); this.protocolEvents = [];
this.knownEventTimestamps = new Set();
/** @type {!HTMLElement} */
this.container; /** @type {!HTMLElement} */
} this.container;
}
/**
* Helper to determine if the window is scrolled to its bottom limit. /**
* @return {boolean} true if the container is scrolled to the bottom * Helper to determine if the window is scrolled to its bottom limit.
* @private * @return {boolean} true if the container is scrolled to the bottom
*/ * @private
_isScrolledToBottom() { */
return (window.innerHeight + window.scrollY) >= document.body.offsetHeight; _isScrolledToBottom() {
} return (window.innerHeight + window.scrollY) >=
document.body.offsetHeight;
/** }
* Helper to scroll the window to its bottom.
* @private /**
*/ * Helper to scroll the window to its bottom.
_scrollToBottom() { * @private
window.scrollTo(0, document.body.scrollHeight); */
} _scrollToBottom() {
window.scrollTo(0, document.body.scrollHeight);
/** }
* Callback for incoming protocol events.
* @param {Event} e The protocol event. /**
* @private * Callback for incoming protocol events.
*/ * @param {Event} e The protocol event.
_onReceivedProtocolEvent(e) { * @private
var details = e.details; */
_onReceivedProtocolEvent(e) {
if (this.knownEventTimestamps.has(details.time)) { const details = e.details;
return;
} if (this.knownEventTimestamps.has(details.time)) {
return;
this.knownEventTimestamps.add(details.time); }
this.protocolEvents.push(details);
this.knownEventTimestamps.add(details.time);
var shouldScrollDown = this._isScrolledToBottom(); this.protocolEvents.push(details);
jstProcess( const shouldScrollDown = this._isScrolledToBottom();
new JsEvalContext({ events: this.protocolEvents }),
this.container); jstProcess(
new JsEvalContext({events: this.protocolEvents}), this.container);
if (shouldScrollDown) {
this._scrollToBottom(); if (shouldScrollDown) {
} this._scrollToBottom();
} }
}
/**
* Toggles the given traffic event entry div's "expanded" state. /**
* @param {!Event} e the click event that triggered the toggle. * Toggles the given traffic event entry div's "expanded" state.
* @private * @param {!Event} e the click event that triggered the toggle.
*/ * @private
_expandListener(e) { */
if (e.target.classList.contains("proto")) { _expandListener(e) {
// We ignore proto clicks to keep it copyable. if (e.target.classList.contains('proto')) {
return; // We ignore proto clicks to keep it copyable.
} return;
var traffic_event_div = e.target; }
// Click might be on div's child. let trafficEventDiv = e.target;
if (traffic_event_div.nodeName != "DIV") { // Click might be on div's child.
traffic_event_div = traffic_event_div.parentNode; if (trafficEventDiv.nodeName != 'DIV') {
} trafficEventDiv = trafficEventDiv.parentNode;
traffic_event_div.classList.toggle( }
'traffic-event-entry-expanded-fullscreen'); trafficEventDiv.classList.toggle(
} 'traffic-event-entry-expanded-fullscreen');
}
/**
* Attaches a listener to the given traffic event entry div. /**
* @param {HTMLElement} element * Attaches a listener to the given traffic event entry div.
*/ * @param {HTMLElement} element
addExpandListener(element) { */
element.addEventListener('click', this._expandListener, false); addExpandListener(element) {
} element.addEventListener('click', this._expandListener, false);
}
onLoad() {
this.container = getRequiredElement('traffic-event-fullscreen-container'); onLoad() {
this.container =
chrome.sync.events.addEventListener( getRequiredElement('traffic-event-fullscreen-container');
'onProtocolEvent', this._onReceivedProtocolEvent.bind(this));
chrome.sync.events.addEventListener(
// Make the prototype jscontent element disappear. 'onProtocolEvent', this._onReceivedProtocolEvent.bind(this));
jstProcess(new JsEvalContext({}), this.container);
} // Make the prototype jscontent element disappear.
}); jstProcess(new JsEvalContext({}), this.container);
}
}));
document.addEventListener( document.addEventListener(
'DOMContentLoaded', 'DOMContentLoaded',
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
cr.define('chrome.sync.types', function() { cr.define('chrome.sync.types', function() {
var typeCountersMap = {}; const typeCountersMap = {};
/** /**
* Redraws the counters table taking advantage of the most recent * Redraws the counters table taking advantage of the most recent
...@@ -11,8 +11,8 @@ cr.define('chrome.sync.types', function() { ...@@ -11,8 +11,8 @@ cr.define('chrome.sync.types', function() {
* *
* Makes use of typeCountersMap, which is defined in the containing scope. * Makes use of typeCountersMap, which is defined in the containing scope.
*/ */
var refreshTypeCountersDisplay = function() { const refreshTypeCountersDisplay = function() {
var typeCountersArray = []; const typeCountersArray = [];
// Transform our map into an array to make jstemplate happy. // Transform our map into an array to make jstemplate happy.
Object.keys(typeCountersMap).sort().forEach(function(t) { Object.keys(typeCountersMap).sort().forEach(function(t) {
...@@ -34,8 +34,8 @@ cr.define('chrome.sync.types', function() { ...@@ -34,8 +34,8 @@ cr.define('chrome.sync.types', function() {
* *
* @param {!Object} e An event containing the list of known sync types. * @param {!Object} e An event containing the list of known sync types.
*/ */
var onReceivedListOfTypes = function(e) { const onReceivedListOfTypes = function(e) {
var types = e.details.types; const types = e.details.types;
types.map(function(type) { types.map(function(type) {
if (!typeCountersMap.hasOwnProperty(type)) { if (!typeCountersMap.hasOwnProperty(type)) {
typeCountersMap[type] = {}; typeCountersMap[type] = {};
...@@ -52,23 +52,24 @@ cr.define('chrome.sync.types', function() { ...@@ -52,23 +52,24 @@ cr.define('chrome.sync.types', function() {
* *
* @param {!Object} e An event containing an updated counter. * @param {!Object} e An event containing an updated counter.
*/ */
var onCountersUpdated = function(e) { const onCountersUpdated = function(e) {
var details = e.details; const details = e.details;
var modelType = details.modelType; const modelType = details.modelType;
var counters = details.counters; const counters = details.counters;
if (typeCountersMap.hasOwnProperty(modelType)) if (typeCountersMap.hasOwnProperty(modelType)) {
for (var k in counters) { for (const k in counters) {
typeCountersMap[modelType][k] = counters[k]; typeCountersMap[modelType][k] = counters[k];
} }
}
refreshTypeCountersDisplay(); refreshTypeCountersDisplay();
}; };
/** /**
* Initializes state and callbacks for the per-type counters and status UI. * Initializes state and callbacks for the per-type counters and status UI.
*/ */
var initTypeCounters = function() { const initTypeCounters = function() {
chrome.sync.events.addEventListener( chrome.sync.events.addEventListener(
'onCountersUpdated', 'onCountersUpdated',
onCountersUpdated); onCountersUpdated);
...@@ -80,7 +81,7 @@ cr.define('chrome.sync.types', function() { ...@@ -80,7 +81,7 @@ cr.define('chrome.sync.types', function() {
chrome.sync.registerForPerTypeCounters(); chrome.sync.registerForPerTypeCounters();
}; };
var onLoad = function() { const onLoad = function() {
initTypeCounters(); initTypeCounters();
}; };
......
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