Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Unified Diff: chrome/browser/resources/copresence.js

Issue 734243003: Adding the chrome://copresence page (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@state
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/resources/copresence.html ('k') | chrome/browser/ui/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/copresence.js
diff --git a/chrome/browser/resources/copresence.js b/chrome/browser/resources/copresence.js
new file mode 100644
index 0000000000000000000000000000000000000000..9f42895a75963093acf10003c634f744dc0a0228
--- /dev/null
+++ b/chrome/browser/resources/copresence.js
@@ -0,0 +1,107 @@
+// Copyright 2014 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.
+
+/**
+ * Debug information about an active copresence directive.
+ * @typedef {{
+ * type: string,
+ * medium: string,
+ * duration: string
+ * }}
+ */
+var Directive;
+
+/**
+ * Debug information about a recent copresence token.
+ * @typedef {{
+ * id: string,
+ * statuses: string,
+ * medium: string,
+ * time: string
+ * }}
+ */
+var Token;
+
+/**
+ * Callback to refresh the list of directives.
+ * @param {Array<Directive>} directives
+ */
+function refreshDirectives(directives) {
+ var table = $('directives-table').tBodies[0];
+
+ // Fix the directives table to have the correct number of rows.
+ while (table.rows.length < directives.length)
+ table.insertRow();
+ while (table.rows.length > directives.length)
+ table.deleteRow();
+
+ // Populate the directives into the table.
+ directives.forEach(function(directive, index) {
+ var row = table.rows.item(index);
+ while (row.cells.length < 3)
+ row.insertCell();
+
+ row.cells.item(0).textContent = directive.type;
+ row.cells.item(1).textContent = directive.medium;
+ row.cells.item(2).textContent = directive.duration;
+ });
+}
+
+/**
+ * Callback to add or update transmitted tokens.
+ * @param {Token} token
+ */
+function updateTransmittedToken(token) {
+ updateTokenTable($('transmitted-tokens-table'), token);
+}
+
+/**
+ * Callback to add or update received tokens.
+ * @param {Token} token
+ */
+function updateReceivedToken(token) {
+ updateTokenTable($('received-tokens-table'), token);
+}
+
+/**
+ * Add or update a token in the specified table.
+ * @param {HTMLTableElement} table
+ * @param {Token} token
+ */
+function updateTokenTable(table, token) {
+ var rows = table.tBodies[0].rows;
+
+ var index;
+ for (index = 0; index < rows.length; index++) {
+ var row = rows.item(index);
+ if (row.cells[0].textContent == token.id) {
+ updateTokenRow(row, token);
+ break;
+ }
+ }
+
+ if (index == rows.length)
+ updateTokenRow(table.tBodies[0].insertRow(), token);
+}
+
+/**
+ * Update a token on the specified row.
+ * @param {HTMLTableRowElement} row
+ * @param {Token} token
+ */
+function updateTokenRow(row, token) {
+ while (row.cells.length < 4)
+ row.insertCell();
+ row.className = token.statuses;
+
+ row.cells[0].textContent = token.id;
+ row.cells[1].textContent =
+ token.statuses.replace('confirmed', '(Confirmed)');
+ row.cells[2].textContent = token.medium;
+ row.cells[3].textContent = token.time;
+}
+
+document.addEventListener('DOMContentLoaded', function() {
+ chrome.send('populateCopresenceState');
+});
« no previous file with comments | « chrome/browser/resources/copresence.html ('k') | chrome/browser/ui/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698