| 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                                       if (window.revokeTokenTest) | 
|  | 127                                           window.revokeTokenTest(); | 
|  | 128                                   }); | 
| 118       }.bind(this)); | 129       }.bind(this)); | 
| 119       revokeButton.textContent = loadTimeData.getString('revoke'); | 130       revokeButton.textContent = loadTimeData.getString('revoke'); | 
| 120       return revokeButton; | 131       return revokeButton; | 
| 121     }, | 132     }, | 
| 122   }; | 133   }; | 
| 123 | 134 | 
| 124   /** | 135   /** | 
| 125    * Creates a new list of identity tokens. | 136    * Creates a new list of identity tokens. | 
| 126    * @param {Object=} opt_propertyBag Optional properties. | 137    * @param {Object=} opt_propertyBag Optional properties. | 
| 127    * @constructor | 138    * @constructor | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
| 149 | 160 | 
| 150     /** | 161     /** | 
| 151      * Removes a token node related to the specifed token ID from both the | 162      * Removes a token node related to the specifed token ID from both the | 
| 152      * internals data source as well as the user internface. | 163      * internals data source as well as the user internface. | 
| 153      * @param {string} accessToken The id of the token to remove. | 164      * @param {string} accessToken The id of the token to remove. | 
| 154      * @private | 165      * @private | 
| 155      */ | 166      */ | 
| 156     removeTokenNode_: function(accessToken) { | 167     removeTokenNode_: function(accessToken) { | 
| 157       var tokenIndex; | 168       var tokenIndex; | 
| 158       for (var index = 0; index < this.data_.length; index++) { | 169       for (var index = 0; index < this.data_.length; index++) { | 
| 159         if (this.data_[index].accessToken == accessToken) { | 170         if (this.data_[index].access_token == accessToken) { | 
| 160           tokenIndex = index; | 171           tokenIndex = index; | 
| 161           break; | 172           break; | 
| 162         } | 173         } | 
| 163       } | 174       } | 
| 164 | 175 | 
| 165       // Remove from the data_ source if token found. | 176       // Remove from the data_ source if token found. | 
| 166       if (tokenIndex) | 177       if (tokenIndex) | 
| 167         this.data_.splice(tokenIndex, 1); | 178         this.data_.splice(tokenIndex, 1); | 
| 168 | 179 | 
| 169       // Remove from the user interface. | 180       // Remove from the user interface. | 
| 170       var tokenNode = $(accessToken); | 181       var tokenNode = $(accessToken); | 
| 171       if (tokenNode) | 182       if (tokenNode) | 
| 172         this.removeChild(tokenNode); | 183         this.removeChild(tokenNode); | 
| 173     }, | 184     }, | 
| 174   }; | 185   }; | 
| 175 | 186 | 
| 176   var tokenList_; | 187   var tokenList_; | 
| 177 | 188 | 
| 178   /** | 189   function InternalsPageImpl(browser) { | 
| 179    * Initializes the UI by asking the contoller for list of identity tokens. | 190     this.browser_ = browser; | 
| 180    */ | 191     page = this; | 
| 181   function initialize() { | 192 | 
| 182     chrome.send('identityInternalsGetTokens'); |  | 
| 183     tokenList_ = $('token-list'); | 193     tokenList_ = $('token-list'); | 
| 184     tokenList_.data_ = []; | 194     tokenList_.data_ = []; | 
| 185     tokenList_.__proto__ = TokenList.prototype; | 195     tokenList_.__proto__ = TokenList.prototype; | 
| 186     tokenList_.decorate(); | 196     tokenList_.decorate(); | 
|  | 197 | 
|  | 198     page.browser_.getTokens().then(function(results) { | 
|  | 199         tokenList_.data_ = results.tokens; | 
|  | 200         tokenList_.showTokenNodes_(); | 
|  | 201     }); | 
| 187   } | 202   } | 
| 188 | 203 | 
| 189   /** | 204   InternalsPageImpl.prototype = | 
| 190    * Callback function accepting a list of tokens to be displayed. | 205       Object.create(browser.InternalsPageStub.prototype); | 
| 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 | 206 | 
| 198   /** | 207   return function(handle) { | 
| 199    * Callback function that removes a token from UI once it has been revoked. | 208     connection = new connector.Connection( | 
| 200    * @param {!Array.<string>} accessTokens Array with a single element, which is | 209         handle, | 
| 201    * an access token to be removed. | 210         InternalsPageImpl, | 
| 202    */ | 211         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   }; | 212   }; | 
| 214 }); | 213 }); | 
| 215 |  | 
| 216 document.addEventListener('DOMContentLoaded', identity_internals.initialize); |  | 
| OLD | NEW | 
|---|