OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 cr.define('identity_internals', function() { | 5 cr.define('identity_internals', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 /** | 8 /** |
9 * Creates an identity token item. | 9 * Creates an identity token item. |
10 * @param {Object} tokenInfo Object containing token information. | 10 * @param {!Object} tokenInfo Object containing token information. |
11 * @constructor | 11 * @constructor |
12 */ | 12 */ |
13 function TokenListItem(tokenInfo) { | 13 function TokenListItem(tokenInfo) { |
14 var el = cr.doc.createElement('div'); | 14 var el = cr.doc.createElement('div'); |
15 el.data_ = tokenInfo; | 15 el.data_ = tokenInfo; |
16 el.__proto__ = TokenListItem.prototype; | 16 el.__proto__ = TokenListItem.prototype; |
17 el.decorate(); | 17 el.decorate(); |
18 return el; | 18 return el; |
19 } | 19 } |
20 | 20 |
21 TokenListItem.prototype = { | 21 TokenListItem.prototype = { |
22 __proto__: HTMLDivElement.prototype, | 22 __proto__: HTMLDivElement.prototype, |
23 | 23 |
24 /** @override */ | 24 /** @override */ |
25 decorate: function() { | 25 decorate: function() { |
26 this.textContent = ''; | 26 this.textContent = ''; |
27 this.id = this.data_.tokenId; | 27 this.id = this.data_.accessToken; |
28 | 28 |
29 var table = this.ownerDocument.createElement('table'); | 29 var table = this.ownerDocument.createElement('table'); |
30 var tbody = this.ownerDocument.createElement('tbody'); | 30 var tbody = this.ownerDocument.createElement('tbody'); |
31 tbody.appendChild(this.createEntry_( | 31 tbody.appendChild(this.createEntry_( |
32 'tokenId', this.data_.tokenId, 'token-id')); | 32 'accessToken', this.data_.accessToken, 'access-token')); |
33 tbody.appendChild(this.createEntry_( | 33 tbody.appendChild(this.createEntry_( |
34 'extensionName', this.data_.extensionName, 'extension-name')); | 34 'extensionName', this.data_.extensionName, 'extension-name')); |
35 tbody.appendChild(this.createEntry_( | 35 tbody.appendChild(this.createEntry_( |
36 'extensionId', this.data_.extensionId, 'extension-id')); | 36 'extensionId', this.data_.extensionId, 'extension-id')); |
37 tbody.appendChild(this.createEntry_( | 37 tbody.appendChild(this.createEntry_( |
38 'tokenStatus', this.data_.status, 'token-status')); | 38 'tokenStatus', this.data_.status, 'token-status')); |
39 tbody.appendChild(this.createEntry_( | 39 tbody.appendChild(this.createEntry_( |
40 'expirationTime', this.data_.expirationTime, 'expiration-time')); | 40 'expirationTime', this.data_.expirationTime, 'expiration-time')); |
41 tbody.appendChild(this.createEntryForScopes_()); | 41 tbody.appendChild(this.createEntryForScopes_()); |
42 table.appendChild(tbody); | 42 table.appendChild(tbody); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 * Creates a revoke button with an event sending a revoke token message | 107 * Creates a revoke button with an event sending a revoke token message |
108 * to the controller. | 108 * to the controller. |
109 * @return {!HTMLButtonElement} The created revoke button. | 109 * @return {!HTMLButtonElement} The created revoke button. |
110 * @private | 110 * @private |
111 */ | 111 */ |
112 createRevokeButton_: function() { | 112 createRevokeButton_: function() { |
113 var revokeButton = this.ownerDocument.createElement('button'); | 113 var revokeButton = this.ownerDocument.createElement('button'); |
114 revokeButton.classList.add('revoke-button'); | 114 revokeButton.classList.add('revoke-button'); |
115 revokeButton.addEventListener('click', function() { | 115 revokeButton.addEventListener('click', function() { |
116 chrome.send('identityInternalsRevokeToken', | 116 chrome.send('identityInternalsRevokeToken', |
117 [this.data_.extensionId, this.data_.tokenId]); | 117 [this.data_.extensionId, this.data_.accessToken]); |
118 }.bind(this)); | 118 }.bind(this)); |
119 revokeButton.textContent = loadTimeData.getString('revoke'); | 119 revokeButton.textContent = loadTimeData.getString('revoke'); |
120 return revokeButton; | 120 return revokeButton; |
121 }, | 121 }, |
122 }; | 122 }; |
123 | 123 |
124 /** | 124 /** |
125 * Creates a new list of identity tokens. | 125 * Creates a new list of identity tokens. |
126 * @param {Object=} opt_propertyBag Optional properties. | 126 * @param {Object=} opt_propertyBag Optional properties. |
127 * @constructor | 127 * @constructor |
(...skipping 15 matching lines...) Expand all Loading... |
143 */ | 143 */ |
144 showTokenNodes_: function() { | 144 showTokenNodes_: function() { |
145 this.data_.forEach(function(tokenInfo) { | 145 this.data_.forEach(function(tokenInfo) { |
146 this.appendChild(new TokenListItem(tokenInfo)); | 146 this.appendChild(new TokenListItem(tokenInfo)); |
147 }, this); | 147 }, this); |
148 }, | 148 }, |
149 | 149 |
150 /** | 150 /** |
151 * Removes a token node related to the specifed token ID from both the | 151 * Removes a token node related to the specifed token ID from both the |
152 * internals data source as well as the user internface. | 152 * internals data source as well as the user internface. |
153 * @param {string} tokenId The id of the token to remove. | 153 * @param {string} accessToken The id of the token to remove. |
154 * @private | 154 * @private |
155 */ | 155 */ |
156 removeTokenNode_: function(tokenId) { | 156 removeTokenNode_: function(accessToken) { |
157 var tokenIndex; | 157 var tokenIndex; |
158 for (var index = 0; index < this.data_.length; index++) { | 158 for (var index = 0; index < this.data_.length; index++) { |
159 if (this.data_[index].tokenId == tokenId) { | 159 if (this.data_[index].accessToken == accessToken) { |
160 tokenIndex = index; | 160 tokenIndex = index; |
161 break; | 161 break; |
162 } | 162 } |
163 } | 163 } |
164 | 164 |
165 // Remove from the data_ source if token found. | 165 // Remove from the data_ source if token found. |
166 if (tokenIndex) | 166 if (tokenIndex) |
167 this.data_.splice(tokenIndex, 1); | 167 this.data_.splice(tokenIndex, 1); |
168 | 168 |
169 // Remove from the user interface. | 169 // Remove from the user interface. |
170 var tokenNode = $(tokenId); | 170 var tokenNode = $(accessToken); |
171 if (tokenNode) | 171 if (tokenNode) |
172 this.removeChild(tokenNode); | 172 this.removeChild(tokenNode); |
173 }, | 173 }, |
174 }; | 174 }; |
175 | 175 |
176 var tokenList_; | 176 var tokenList_; |
177 | 177 |
178 /** | 178 /** |
179 * Initializes the UI by asking the contoller for list of identity tokens. | 179 * Initializes the UI by asking the contoller for list of identity tokens. |
180 */ | 180 */ |
181 function initialize() { | 181 function initialize() { |
182 chrome.send('identityInternalsGetTokens'); | 182 chrome.send('identityInternalsGetTokens'); |
183 tokenList_ = $('token-list'); | 183 tokenList_ = $('token-list'); |
184 tokenList_.data_ = []; | 184 tokenList_.data_ = []; |
185 tokenList_.__proto__ = TokenList.prototype; | 185 tokenList_.__proto__ = TokenList.prototype; |
186 tokenList_.decorate(); | 186 tokenList_.decorate(); |
187 } | 187 } |
188 | 188 |
189 /** | 189 /** |
190 * Callback function accepting a list of tokens to be displayed. | 190 * Callback function accepting a list of tokens to be displayed. |
191 * @param {Token[]} tokens A list of tokens to be displayed | 191 * @param {!Token[]} tokens A list of tokens to be displayed |
192 */ | 192 */ |
193 function returnTokens(tokens) { | 193 function returnTokens(tokens) { |
194 tokenList_.data_ = tokens; | 194 tokenList_.data_ = tokens; |
195 tokenList_.showTokenNodes_(); | 195 tokenList_.showTokenNodes_(); |
196 } | 196 } |
197 | 197 |
198 /** | 198 /** |
199 * Callback function that removes a token from UI once it has been revoked. | 199 * Callback function that removes a token from UI once it has been revoked. |
200 * @param {!Array.<string>} tokenIds Array with a single element, which is a | 200 * @param {!Array.<string>} accessTokens Array with a single element, which is |
201 * token ID, of the token to be removed. | 201 * an access token to be removed. |
202 */ | 202 */ |
203 function tokenRevokeDone(tokenIds) { | 203 function tokenRevokeDone(accessTokens) { |
204 assert(tokenIds.length > 0); | 204 assert(accessTokens.length > 0); |
205 tokenList_.removeTokenNode_(tokenIds[0]); | 205 tokenList_.removeTokenNode_(accessTokens[0]); |
206 } | 206 } |
207 | 207 |
208 // Return an object with all of the exports. | 208 // Return an object with all of the exports. |
209 return { | 209 return { |
210 initialize: initialize, | 210 initialize: initialize, |
211 returnTokens: returnTokens, | 211 returnTokens: returnTokens, |
212 tokenRevokeDone: tokenRevokeDone, | 212 tokenRevokeDone: tokenRevokeDone, |
213 }; | 213 }; |
214 }); | 214 }); |
215 | 215 |
216 document.addEventListener('DOMContentLoaded', identity_internals.initialize); | 216 document.addEventListener('DOMContentLoaded', identity_internals.initialize); |
OLD | NEW |