Chromium Code Reviews| Index: chrome/browser/resources/identity_internals.js |
| diff --git a/chrome/browser/resources/identity_internals.js b/chrome/browser/resources/identity_internals.js |
| index 7e7a01f0b29c935f18351e0f5f11229b329fbbc6..8cd968b2ac2fae4ff693993650acae2cbcc49c7d 100644 |
| --- a/chrome/browser/resources/identity_internals.js |
| +++ b/chrome/browser/resources/identity_internals.js |
| @@ -2,9 +2,15 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -cr.define('identity_internals', function() { |
| +define('main', [ |
| + 'mojo/public/js/bindings/connection', |
| + 'chrome/browser/ui/webui/identity_internals/identity_internals.mojom', |
| +], function(connector, browser) { |
| 'use strict'; |
| + var connection; |
| + var page; |
| + |
| /** |
| * Creates an identity token item. |
| * @param {!Object} tokenInfo Object containing token information. |
| @@ -24,20 +30,20 @@ cr.define('identity_internals', function() { |
| /** @override */ |
| decorate: function() { |
| this.textContent = ''; |
| - this.id = this.data_.accessToken; |
| + this.id = this.data_.access_token; |
| var table = this.ownerDocument.createElement('table'); |
| var tbody = this.ownerDocument.createElement('tbody'); |
| tbody.appendChild(this.createEntry_( |
| - 'accessToken', this.data_.accessToken, 'access-token')); |
| + 'accessToken', this.data_.access_token, 'access-token')); |
| tbody.appendChild(this.createEntry_( |
| - 'extensionName', this.data_.extensionName, 'extension-name')); |
| + 'extensionName', this.data_.extension_name, 'extension-name')); |
| tbody.appendChild(this.createEntry_( |
| - 'extensionId', this.data_.extensionId, 'extension-id')); |
| + 'extensionId', this.data_.extension_id, 'extension-id')); |
| tbody.appendChild(this.createEntry_( |
| - 'tokenStatus', this.data_.status, 'token-status')); |
| + 'tokenStatus', this.data_.token_status, 'token-status')); |
| tbody.appendChild(this.createEntry_( |
| - 'expirationTime', this.data_.expirationTime, 'expiration-time')); |
| + 'expirationTime', this.data_.expiration_time, 'expiration-time')); |
| tbody.appendChild(this.createEntryForScopes_()); |
| table.appendChild(tbody); |
| var tfoot = this.ownerDocument.createElement('tfoot'); |
| @@ -113,8 +119,11 @@ cr.define('identity_internals', function() { |
| var revokeButton = this.ownerDocument.createElement('button'); |
| revokeButton.classList.add('revoke-button'); |
| revokeButton.addEventListener('click', function() { |
| - chrome.send('identityInternalsRevokeToken', |
| - [this.data_.extensionId, this.data_.accessToken]); |
| + var accessToken = this.data_.access_token; |
| + page.browser_.revokeToken(this.data_.extension_id, |
| + accessToken).then(function() { |
| + tokenList_.removeTokenNode_(accessToken); |
| + }); |
| }.bind(this)); |
| revokeButton.textContent = loadTimeData.getString('revoke'); |
| return revokeButton; |
| @@ -156,7 +165,7 @@ cr.define('identity_internals', function() { |
| removeTokenNode_: function(accessToken) { |
| var tokenIndex; |
| for (var index = 0; index < this.data_.length; index++) { |
| - if (this.data_[index].accessToken == accessToken) { |
| + if (this.data_[index].access_token == accessToken) { |
| tokenIndex = index; |
| break; |
| } |
| @@ -175,42 +184,28 @@ cr.define('identity_internals', function() { |
| var tokenList_; |
| - /** |
| - * Initializes the UI by asking the contoller for list of identity tokens. |
| - */ |
| - function initialize() { |
| - chrome.send('identityInternalsGetTokens'); |
| + function InternalsPageImpl(browser) { |
| + this.browser_ = browser; |
| + page = this; |
| + |
| tokenList_ = $('token-list'); |
| tokenList_.data_ = []; |
| tokenList_.__proto__ = TokenList.prototype; |
| tokenList_.decorate(); |
| - } |
| - /** |
| - * Callback function accepting a list of tokens to be displayed. |
| - * @param {!Token[]} tokens A list of tokens to be displayed |
| - */ |
| - function returnTokens(tokens) { |
| - tokenList_.data_ = tokens; |
| - tokenList_.showTokenNodes_(); |
| + page.browser_.getTokens().then(function(results) { |
| + tokenList_.data_ = results.tokens; |
| + tokenList_.showTokenNodes_(); |
| + }); |
| } |
| - /** |
| - * Callback function that removes a token from UI once it has been revoked. |
| - * @param {!Array.<string>} accessTokens Array with a single element, which is |
| - * an access token to be removed. |
| - */ |
| - function tokenRevokeDone(accessTokens) { |
| - assert(accessTokens.length > 0); |
| - tokenList_.removeTokenNode_(accessTokens[0]); |
| - } |
| + InternalsPageImpl.prototype = |
| + Object.create(browser.InternalsPageStub.prototype); |
|
erg
2014/07/11 19:29:54
So I've moved this to callbacks and promises. Howe
|
| - // Return an object with all of the exports. |
| - return { |
| - initialize: initialize, |
| - returnTokens: returnTokens, |
| - tokenRevokeDone: tokenRevokeDone, |
| + return function(handle) { |
| + connection = new connector.Connection( |
| + handle, |
| + InternalsPageImpl, |
| + browser.IdentityInternalsHandlerMojoProxy); |
| }; |
| }); |
| - |
| -document.addEventListener('DOMContentLoaded', identity_internals.initialize); |