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

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

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

Powered by Google App Engine
This is Rietveld 408576698