Chromium Code Reviews| 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 define('main', [ |
| 6 'mojo/public/js/bindings/connection', | |
| 7 'chrome/browser/ui/webui/identity_internals/identity_internals.mojom', | |
| 8 ], function(connector, browser) { | |
| 6 'use strict'; | 9 'use strict'; |
| 7 | 10 |
| 11 var connection; | |
| 12 var page; | |
| 13 | |
| 8 /** | 14 /** |
| 9 * Creates an identity token item. | 15 * Creates an identity token item. |
| 10 * @param {!Object} tokenInfo Object containing token information. | 16 * @param {!Object} tokenInfo Object containing token information. |
| 11 * @constructor | 17 * @constructor |
| 12 */ | 18 */ |
| 13 function TokenListItem(tokenInfo) { | 19 function TokenListItem(tokenInfo) { |
| 14 var el = cr.doc.createElement('div'); | 20 var el = cr.doc.createElement('div'); |
| 15 el.data_ = tokenInfo; | 21 el.data_ = tokenInfo; |
| 16 el.__proto__ = TokenListItem.prototype; | 22 el.__proto__ = TokenListItem.prototype; |
| 17 el.decorate(); | 23 el.decorate(); |
| 18 return el; | 24 return el; |
| 19 } | 25 } |
| 20 | 26 |
| 21 TokenListItem.prototype = { | 27 TokenListItem.prototype = { |
| 22 __proto__: HTMLDivElement.prototype, | 28 __proto__: HTMLDivElement.prototype, |
| 23 | 29 |
| 24 /** @override */ | 30 /** @override */ |
| 25 decorate: function() { | 31 decorate: function() { |
| 26 this.textContent = ''; | 32 this.textContent = ''; |
| 27 this.id = this.data_.accessToken; | 33 this.id = this.data_.access_token; |
| 28 | 34 |
| 29 var table = this.ownerDocument.createElement('table'); | 35 var table = this.ownerDocument.createElement('table'); |
| 30 var tbody = this.ownerDocument.createElement('tbody'); | 36 var tbody = this.ownerDocument.createElement('tbody'); |
| 31 tbody.appendChild(this.createEntry_( | 37 tbody.appendChild(this.createEntry_( |
| 32 'accessToken', this.data_.accessToken, 'access-token')); | 38 'accessToken', this.data_.access_token, 'access-token')); |
| 33 tbody.appendChild(this.createEntry_( | 39 tbody.appendChild(this.createEntry_( |
| 34 'extensionName', this.data_.extensionName, 'extension-name')); | 40 'extensionName', this.data_.extension_name, 'extension-name')); |
| 35 tbody.appendChild(this.createEntry_( | 41 tbody.appendChild(this.createEntry_( |
| 36 'extensionId', this.data_.extensionId, 'extension-id')); | 42 'extensionId', this.data_.extension_id, 'extension-id')); |
| 37 tbody.appendChild(this.createEntry_( | 43 tbody.appendChild(this.createEntry_( |
| 38 'tokenStatus', this.data_.status, 'token-status')); | 44 'tokenStatus', this.data_.token_status, 'token-status')); |
| 39 tbody.appendChild(this.createEntry_( | 45 tbody.appendChild(this.createEntry_( |
| 40 'expirationTime', this.data_.expirationTime, 'expiration-time')); | 46 'expirationTime', this.data_.expiration_time, 'expiration-time')); |
| 41 tbody.appendChild(this.createEntryForScopes_()); | 47 tbody.appendChild(this.createEntryForScopes_()); |
| 42 table.appendChild(tbody); | 48 table.appendChild(tbody); |
| 43 var tfoot = this.ownerDocument.createElement('tfoot'); | 49 var tfoot = this.ownerDocument.createElement('tfoot'); |
| 44 tfoot.appendChild(this.createButtons_()); | 50 tfoot.appendChild(this.createButtons_()); |
| 45 table.appendChild(tfoot); | 51 table.appendChild(tfoot); |
| 46 this.appendChild(table); | 52 this.appendChild(table); |
| 47 }, | 53 }, |
| 48 | 54 |
| 49 /** | 55 /** |
| 50 * Creates an entry for a single property of the token. | 56 * Creates an entry for a single property of the token. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 /** | 112 /** |
| 107 * Creates a revoke button with an event sending a revoke token message | 113 * Creates a revoke button with an event sending a revoke token message |
| 108 * to the controller. | 114 * to the controller. |
| 109 * @return {!HTMLButtonElement} The created revoke button. | 115 * @return {!HTMLButtonElement} The created revoke button. |
| 110 * @private | 116 * @private |
| 111 */ | 117 */ |
| 112 createRevokeButton_: function() { | 118 createRevokeButton_: function() { |
| 113 var revokeButton = this.ownerDocument.createElement('button'); | 119 var revokeButton = this.ownerDocument.createElement('button'); |
| 114 revokeButton.classList.add('revoke-button'); | 120 revokeButton.classList.add('revoke-button'); |
| 115 revokeButton.addEventListener('click', function() { | 121 revokeButton.addEventListener('click', function() { |
| 116 chrome.send('identityInternalsRevokeToken', | 122 var accessToken = this.data_.access_token; |
| 117 [this.data_.extensionId, this.data_.accessToken]); | 123 page.browser_.revokeToken(this.data_.extension_id, |
| 124 accessToken).then(function() { | |
| 125 tokenList_.removeTokenNode_(accessToken); | |
| 126 }); | |
| 118 }.bind(this)); | 127 }.bind(this)); |
| 119 revokeButton.textContent = loadTimeData.getString('revoke'); | 128 revokeButton.textContent = loadTimeData.getString('revoke'); |
| 120 return revokeButton; | 129 return revokeButton; |
| 121 }, | 130 }, |
| 122 }; | 131 }; |
| 123 | 132 |
| 124 /** | 133 /** |
| 125 * Creates a new list of identity tokens. | 134 * Creates a new list of identity tokens. |
| 126 * @param {Object=} opt_propertyBag Optional properties. | 135 * @param {Object=} opt_propertyBag Optional properties. |
| 127 * @constructor | 136 * @constructor |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 149 | 158 |
| 150 /** | 159 /** |
| 151 * Removes a token node related to the specifed token ID from both the | 160 * Removes a token node related to the specifed token ID from both the |
| 152 * internals data source as well as the user internface. | 161 * internals data source as well as the user internface. |
| 153 * @param {string} accessToken The id of the token to remove. | 162 * @param {string} accessToken The id of the token to remove. |
| 154 * @private | 163 * @private |
| 155 */ | 164 */ |
| 156 removeTokenNode_: function(accessToken) { | 165 removeTokenNode_: function(accessToken) { |
| 157 var tokenIndex; | 166 var tokenIndex; |
| 158 for (var index = 0; index < this.data_.length; index++) { | 167 for (var index = 0; index < this.data_.length; index++) { |
| 159 if (this.data_[index].accessToken == accessToken) { | 168 if (this.data_[index].access_token == accessToken) { |
| 160 tokenIndex = index; | 169 tokenIndex = index; |
| 161 break; | 170 break; |
| 162 } | 171 } |
| 163 } | 172 } |
| 164 | 173 |
| 165 // Remove from the data_ source if token found. | 174 // Remove from the data_ source if token found. |
| 166 if (tokenIndex) | 175 if (tokenIndex) |
| 167 this.data_.splice(tokenIndex, 1); | 176 this.data_.splice(tokenIndex, 1); |
| 168 | 177 |
| 169 // Remove from the user interface. | 178 // Remove from the user interface. |
| 170 var tokenNode = $(accessToken); | 179 var tokenNode = $(accessToken); |
| 171 if (tokenNode) | 180 if (tokenNode) |
| 172 this.removeChild(tokenNode); | 181 this.removeChild(tokenNode); |
| 173 }, | 182 }, |
| 174 }; | 183 }; |
| 175 | 184 |
| 176 var tokenList_; | 185 var tokenList_; |
| 177 | 186 |
| 178 /** | 187 function InternalsPageImpl(browser) { |
| 179 * Initializes the UI by asking the contoller for list of identity tokens. | 188 this.browser_ = browser; |
| 180 */ | 189 page = this; |
| 181 function initialize() { | 190 |
| 182 chrome.send('identityInternalsGetTokens'); | |
| 183 tokenList_ = $('token-list'); | 191 tokenList_ = $('token-list'); |
| 184 tokenList_.data_ = []; | 192 tokenList_.data_ = []; |
| 185 tokenList_.__proto__ = TokenList.prototype; | 193 tokenList_.__proto__ = TokenList.prototype; |
| 186 tokenList_.decorate(); | 194 tokenList_.decorate(); |
| 195 | |
| 196 page.browser_.getTokens().then(function(results) { | |
| 197 tokenList_.data_ = results.tokens; | |
| 198 tokenList_.showTokenNodes_(); | |
| 199 }); | |
| 187 } | 200 } |
| 188 | 201 |
| 189 /** | 202 InternalsPageImpl.prototype = |
| 190 * Callback function accepting a list of tokens to be displayed. | 203 Object.create(browser.InternalsPageStub.prototype); |
|
erg
2014/07/11 19:29:54
So I've moved this to callbacks and promises. Howe
| |
| 191 * @param {!Token[]} tokens A list of tokens to be displayed | |
| 192 */ | |
| 193 function returnTokens(tokens) { | |
| 194 tokenList_.data_ = tokens; | |
| 195 tokenList_.showTokenNodes_(); | |
| 196 } | |
| 197 | 204 |
| 198 /** | 205 return function(handle) { |
| 199 * Callback function that removes a token from UI once it has been revoked. | 206 connection = new connector.Connection( |
| 200 * @param {!Array.<string>} accessTokens Array with a single element, which is | 207 handle, |
| 201 * an access token to be removed. | 208 InternalsPageImpl, |
| 202 */ | 209 browser.IdentityInternalsHandlerMojoProxy); |
| 203 function tokenRevokeDone(accessTokens) { | |
| 204 assert(accessTokens.length > 0); | |
| 205 tokenList_.removeTokenNode_(accessTokens[0]); | |
| 206 } | |
| 207 | |
| 208 // Return an object with all of the exports. | |
| 209 return { | |
| 210 initialize: initialize, | |
| 211 returnTokens: returnTokens, | |
| 212 tokenRevokeDone: tokenRevokeDone, | |
| 213 }; | 210 }; |
| 214 }); | 211 }); |
| 215 | |
| 216 document.addEventListener('DOMContentLoaded', identity_internals.initialize); | |
| OLD | NEW |