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

Side by Side Diff: chrome/browser/resources/copresence.js

Issue 2130803002: Deleting the copresence API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 5 months 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/resources/copresence.html ('k') | chrome/browser/ui/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * Debug information about an active copresence directive.
7 * @typedef {{
8 * type: string,
9 * medium: string,
10 * duration: string
11 * }}
12 */
13 var Directive;
14
15 /**
16 * Debug information about a recent copresence token.
17 * @typedef {{
18 * id: string,
19 * statuses: string,
20 * medium: string,
21 * time: string
22 * }}
23 */
24 var Token;
25
26 /**
27 * Callback to refresh the list of directives.
28 * @param {Array<Directive>} directives
29 */
30 function refreshDirectives(directives) {
31 var table = $('directives-table').tBodies[0];
32
33 // Fix the directives table to have the correct number of rows.
34 while (table.rows.length < directives.length)
35 table.insertRow();
36 while (table.rows.length > directives.length)
37 table.deleteRow();
38
39 // Populate the directives into the table.
40 directives.forEach(function(directive, index) {
41 var row = table.rows.item(index);
42 while (row.cells.length < 3)
43 row.insertCell();
44
45 row.cells.item(0).textContent = directive.type;
46 row.cells.item(1).textContent = directive.medium;
47 row.cells.item(2).textContent = directive.duration;
48 });
49 }
50
51 /**
52 * Callback to add or update transmitted tokens.
53 * @param {Token} token
54 */
55 function updateTransmittedToken(token) {
56 updateTokenTable($('transmitted-tokens-table'), token);
57 }
58
59 /**
60 * Callback to add or update received tokens.
61 * @param {Token} token
62 */
63 function updateReceivedToken(token) {
64 updateTokenTable($('received-tokens-table'), token);
65 }
66
67 /**
68 * Callback to clear out the token tables.
69 */
70 function clearTokens() {
71 clearTable($('transmitted-tokens-table'));
72 clearTable($('received-tokens-table'));
73 }
74
75 /**
76 * Add or update a token in the specified table.
77 * @param {HTMLTableElement} table
78 * @param {Token} token
79 */
80 function updateTokenTable(table, token) {
81 var rows = table.tBodies[0].rows;
82
83 var index;
84 for (index = 0; index < rows.length; index++) {
85 var row = rows.item(index);
86 if (row.cells[0].textContent == token.id) {
87 updateTokenRow(row, token);
88 break;
89 }
90 }
91
92 if (index == rows.length)
93 updateTokenRow(table.tBodies[0].insertRow(), token);
94 }
95
96 /**
97 * Update a token on the specified row.
98 * @param {HTMLTableRowElement} row
99 * @param {Token} token
100 */
101 function updateTokenRow(row, token) {
102 while (row.cells.length < 4)
103 row.insertCell();
104 row.className = token.statuses;
105
106 row.cells[0].textContent = token.id;
107 row.cells[1].textContent =
108 token.statuses.replace('confirmed', '(Confirmed)');
109 row.cells[2].textContent = token.medium;
110 row.cells[3].textContent = token.time;
111 }
112
113 /**
114 * Delete all the rows in a table.
115 * @param {HTMLTableElement} table
116 */
117 function clearTable(table) {
118 var body = table.tBodies[0];
119 while (body.rows.length > 0)
120 body.deleteRow();
121 }
122
123 document.addEventListener('DOMContentLoaded', function() {
124 chrome.send('populateCopresenceState');
125
126 $('reset-button').addEventListener('click', function() {
127 if (confirm(loadTimeData.getString('confirm_delete')))
128 chrome.send('clearCopresenceState');
129 });
130 });
OLDNEW
« 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