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 #include "chrome/browser/ui/webui/identity_internals_ui.h" | 5 #include "chrome/browser/ui/webui/identity_internals_ui.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 // Properties of the Javascript object representing a token. | 29 // Properties of the Javascript object representing a token. |
| 30 const char kExtensionId[] = "extensionId"; | 30 const char kExtensionId[] = "extensionId"; |
| 31 const char kExtensionName[] = "extensionName"; | 31 const char kExtensionName[] = "extensionName"; |
| 32 const char kScopes[] = "scopes"; | 32 const char kScopes[] = "scopes"; |
| 33 const char kStatus[] = "status"; | 33 const char kStatus[] = "status"; |
| 34 const char kTokenExpirationTime[] = "expirationTime"; | 34 const char kTokenExpirationTime[] = "expirationTime"; |
| 35 const char kTokenId[] = "tokenId"; | 35 const char kAccessToken[] = "accessToken"; |
| 36 | 36 |
| 37 // RevokeToken message parameter offsets. | 37 // RevokeToken message parameter offsets. |
| 38 const int kRevokeTokenExtensionOffset = 0; | 38 const int kRevokeTokenExtensionOffset = 0; |
| 39 const int kRevokeTokenTokenOffset = 1; | 39 const int kRevokeTokenTokenOffset = 1; |
| 40 | 40 |
| 41 class IdentityInternalsTokenRevoker; | 41 class IdentityInternalsTokenRevoker; |
| 42 | 42 |
| 43 // Class acting as a controller of the chrome://identity-internals WebUI. | |
| 43 class IdentityInternalsUIMessageHandler : public content::WebUIMessageHandler { | 44 class IdentityInternalsUIMessageHandler : public content::WebUIMessageHandler { |
| 44 public: | 45 public: |
| 45 IdentityInternalsUIMessageHandler(); | 46 IdentityInternalsUIMessageHandler(); |
| 46 virtual ~IdentityInternalsUIMessageHandler(); | 47 virtual ~IdentityInternalsUIMessageHandler(); |
| 47 | 48 |
| 48 // Ensures that a proper clean up happens after a token is revoked. That | 49 // Ensures that a proper clean up happens after a token is revoked. That |
| 49 // includes deleting the |token_revoker|, removing the token from Identity API | 50 // includes deleting the |token_revoker|, removing the token from Identity API |
| 50 // cache and updating the UI that the token is gone. | 51 // cache and updating the UI that the token is gone. |
| 51 void OnTokenRevokerDone(IdentityInternalsTokenRevoker* token_revoker); | 52 void OnTokenRevokerDone(IdentityInternalsTokenRevoker* token_revoker); |
| 52 | 53 |
| 53 // WebUIMessageHandler implementation. | 54 // WebUIMessageHandler implementation. |
| 54 virtual void RegisterMessages() OVERRIDE; | 55 virtual void RegisterMessages() OVERRIDE; |
| 55 | 56 |
| 56 private: | 57 private: |
| 58 // Gets a name of an extension referred to by |token_cache_key| as a string. | |
|
Michael Courage
2013/06/20 09:40:54
tinynit: s/Gets a/Gets the/
fgorski
2013/06/20 16:28:48
Done.
| |
| 57 const std::string GetExtensionName( | 59 const std::string GetExtensionName( |
| 58 const extensions::IdentityAPI::TokenCacheKey& token_cache_key); | 60 const extensions::IdentityAPI::TokenCacheKey& token_cache_key); |
| 59 | 61 |
| 62 // Gets a list of scopes specified in |token_cache_key| and returns a pointer | |
| 63 // to a ListValue containing the scopes. The caller gets ownership of the | |
| 64 // returned object. | |
| 60 ListValue* GetScopes( | 65 ListValue* GetScopes( |
| 61 const extensions::IdentityAPI::TokenCacheKey& token_cache_key); | 66 const extensions::IdentityAPI::TokenCacheKey& token_cache_key); |
| 62 | 67 |
| 68 // Gets a localized status of the access token in |token_cache_value|. | |
| 63 const base::string16 GetStatus( | 69 const base::string16 GetStatus( |
| 64 const extensions::IdentityTokenCacheValue& token_cache_value); | 70 const extensions::IdentityTokenCacheValue& token_cache_value); |
| 65 | 71 |
| 72 // Gets a string representation of an expiration time of the access token in | |
| 73 // |token_cache_value|. | |
| 66 const std::string GetExpirationTime( | 74 const std::string GetExpirationTime( |
| 67 const extensions::IdentityTokenCacheValue& token_cache_value); | 75 const extensions::IdentityTokenCacheValue& token_cache_value); |
| 68 | 76 |
| 77 // Converts a pair of |token_cache_key| and |token_cache_value| to a | |
| 78 // DictionaryValue object with corresponding information in a localized and | |
| 79 // readible form and returns a pointer to created object. Caller gets the | |
|
Michael Courage
2013/06/20 09:40:54
nits:
s/readible/readable/
returns a pointer to _t
fgorski
2013/06/20 16:28:48
Done.
| |
| 80 // ownership of the returned object. | |
| 69 DictionaryValue* GetInfoForToken( | 81 DictionaryValue* GetInfoForToken( |
| 70 const extensions::IdentityAPI::TokenCacheKey& token_cache_key, | 82 const extensions::IdentityAPI::TokenCacheKey& token_cache_key, |
| 71 const extensions::IdentityTokenCacheValue& token_cache_value); | 83 const extensions::IdentityTokenCacheValue& token_cache_value); |
| 72 | 84 |
| 85 // Gets all of the tokens stored in IdenityAPI token cache and returns them | |
|
Michael Courage
2013/06/20 09:40:54
s/IdenityAPI/IdentityAPI/
fgorski
2013/06/20 16:28:48
Done.
| |
| 86 // to the caller using Javascript callback function | |
| 87 // |identity_internals.returnTokens()|. | |
| 73 void GetInfoForAllTokens(const ListValue* args); | 88 void GetInfoForAllTokens(const ListValue* args); |
| 74 | 89 |
| 75 // Initiates revoking of the token, based on the extension ID and token | 90 // Initiates revoking of the token, based on the extension ID and token |
| 76 // passed as entries in the args list. | 91 // passed as entries in the |args| list. Updates the caller of completion |
| 92 // using Javascript callback function |identity_internals.tokenRevokeDone()|. | |
| 77 void RevokeToken(const ListValue* args); | 93 void RevokeToken(const ListValue* args); |
| 78 | 94 |
| 79 // A vector of token revokers that are currently revoking tokens. | 95 // A vector of token revokers that are currently revoking tokens. |
| 80 ScopedVector<IdentityInternalsTokenRevoker> token_revokers_; | 96 ScopedVector<IdentityInternalsTokenRevoker> token_revokers_; |
| 81 }; | 97 }; |
| 82 | 98 |
| 83 // Handles the revoking of an access token and helps performing the clean up | 99 // Handles the revoking of an access token and helps performing the clean up |
| 84 // after it is revoked by holding information about the access token and related | 100 // after it is revoked by holding information about the access token and related |
| 85 // extension ID. | 101 // extension ID. |
| 86 class IdentityInternalsTokenRevoker : public GaiaAuthConsumer { | 102 class IdentityInternalsTokenRevoker : public GaiaAuthConsumer { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 } | 201 } |
| 186 | 202 |
| 187 DictionaryValue* IdentityInternalsUIMessageHandler::GetInfoForToken( | 203 DictionaryValue* IdentityInternalsUIMessageHandler::GetInfoForToken( |
| 188 const extensions::IdentityAPI::TokenCacheKey& token_cache_key, | 204 const extensions::IdentityAPI::TokenCacheKey& token_cache_key, |
| 189 const extensions::IdentityTokenCacheValue& token_cache_value) { | 205 const extensions::IdentityTokenCacheValue& token_cache_value) { |
| 190 DictionaryValue* token_data = new DictionaryValue(); | 206 DictionaryValue* token_data = new DictionaryValue(); |
| 191 token_data->SetString(kExtensionId, token_cache_key.extension_id); | 207 token_data->SetString(kExtensionId, token_cache_key.extension_id); |
| 192 token_data->SetString(kExtensionName, GetExtensionName(token_cache_key)); | 208 token_data->SetString(kExtensionName, GetExtensionName(token_cache_key)); |
| 193 token_data->Set(kScopes, GetScopes(token_cache_key)); | 209 token_data->Set(kScopes, GetScopes(token_cache_key)); |
| 194 token_data->SetString(kStatus, GetStatus(token_cache_value)); | 210 token_data->SetString(kStatus, GetStatus(token_cache_value)); |
| 195 token_data->SetString(kTokenId, token_cache_value.token()); | 211 token_data->SetString(kAccessToken, token_cache_value.token()); |
| 196 token_data->SetString(kTokenExpirationTime, | 212 token_data->SetString(kTokenExpirationTime, |
| 197 GetExpirationTime(token_cache_value)); | 213 GetExpirationTime(token_cache_value)); |
| 198 return token_data; | 214 return token_data; |
| 199 } | 215 } |
| 200 | 216 |
| 201 void IdentityInternalsUIMessageHandler::GetInfoForAllTokens( | 217 void IdentityInternalsUIMessageHandler::GetInfoForAllTokens( |
| 202 const ListValue* args) { | 218 const ListValue* args) { |
| 203 ListValue results; | 219 ListValue results; |
| 204 extensions::IdentityAPI::CachedTokens tokens = | 220 extensions::IdentityAPI::CachedTokens tokens = |
| 205 extensions::IdentityAPI::GetFactoryInstance()->GetForProfile( | 221 extensions::IdentityAPI::GetFactoryInstance()->GetForProfile( |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 255 IdentityInternalsUI::IdentityInternalsUI(content::WebUI* web_ui) | 271 IdentityInternalsUI::IdentityInternalsUI(content::WebUI* web_ui) |
| 256 : content::WebUIController(web_ui) { | 272 : content::WebUIController(web_ui) { |
| 257 // chrome://identity-internals source. | 273 // chrome://identity-internals source. |
| 258 content::WebUIDataSource* html_source = | 274 content::WebUIDataSource* html_source = |
| 259 content::WebUIDataSource::Create(chrome::kChromeUIIdentityInternalsHost); | 275 content::WebUIDataSource::Create(chrome::kChromeUIIdentityInternalsHost); |
| 260 html_source->SetUseJsonJSFormatV2(); | 276 html_source->SetUseJsonJSFormatV2(); |
| 261 | 277 |
| 262 // Localized strings | 278 // Localized strings |
| 263 html_source->AddLocalizedString("tokenCacheHeader", | 279 html_source->AddLocalizedString("tokenCacheHeader", |
| 264 IDS_IDENTITY_INTERNALS_TOKEN_CACHE_TEXT); | 280 IDS_IDENTITY_INTERNALS_TOKEN_CACHE_TEXT); |
| 265 html_source->AddLocalizedString("tokenId", | 281 html_source->AddLocalizedString("accessToken", |
| 266 IDS_IDENTITY_INTERNALS_TOKEN_ID); | 282 IDS_IDENTITY_INTERNALS_ACCESS_TOKEN); |
| 267 html_source->AddLocalizedString("extensionName", | 283 html_source->AddLocalizedString("extensionName", |
| 268 IDS_IDENTITY_INTERNALS_EXTENSION_NAME); | 284 IDS_IDENTITY_INTERNALS_EXTENSION_NAME); |
| 269 html_source->AddLocalizedString("extensionId", | 285 html_source->AddLocalizedString("extensionId", |
| 270 IDS_IDENTITY_INTERNALS_EXTENSION_ID); | 286 IDS_IDENTITY_INTERNALS_EXTENSION_ID); |
| 271 html_source->AddLocalizedString("tokenStatus", | 287 html_source->AddLocalizedString("tokenStatus", |
| 272 IDS_IDENTITY_INTERNALS_TOKEN_STATUS); | 288 IDS_IDENTITY_INTERNALS_TOKEN_STATUS); |
| 273 html_source->AddLocalizedString("expirationTime", | 289 html_source->AddLocalizedString("expirationTime", |
| 274 IDS_IDENTITY_INTERNALS_EXPIRATION_TIME); | 290 IDS_IDENTITY_INTERNALS_EXPIRATION_TIME); |
| 275 html_source->AddLocalizedString("scopes", | 291 html_source->AddLocalizedString("scopes", |
| 276 IDS_IDENTITY_INTERNALS_SCOPES); | 292 IDS_IDENTITY_INTERNALS_SCOPES); |
| 277 html_source->AddLocalizedString("revoke", | 293 html_source->AddLocalizedString("revoke", |
| 278 IDS_IDENTITY_INTERNALS_REVOKE); | 294 IDS_IDENTITY_INTERNALS_REVOKE); |
| 279 html_source->SetJsonPath("strings.js"); | 295 html_source->SetJsonPath("strings.js"); |
| 280 | 296 |
| 281 // Required resources | 297 // Required resources |
| 282 html_source->AddResourcePath("identity_internals.css", | 298 html_source->AddResourcePath("identity_internals.css", |
| 283 IDR_IDENTITY_INTERNALS_CSS); | 299 IDR_IDENTITY_INTERNALS_CSS); |
| 284 html_source->AddResourcePath("identity_internals.js", | 300 html_source->AddResourcePath("identity_internals.js", |
| 285 IDR_IDENTITY_INTERNALS_JS); | 301 IDR_IDENTITY_INTERNALS_JS); |
| 286 html_source->SetDefaultResource(IDR_IDENTITY_INTERNALS_HTML); | 302 html_source->SetDefaultResource(IDR_IDENTITY_INTERNALS_HTML); |
| 287 | 303 |
| 288 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source); | 304 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source); |
| 289 | 305 |
| 290 web_ui->AddMessageHandler(new IdentityInternalsUIMessageHandler()); | 306 web_ui->AddMessageHandler(new IdentityInternalsUIMessageHandler()); |
| 291 } | 307 } |
| 292 | 308 |
| 293 IdentityInternalsUI::~IdentityInternalsUI() {} | 309 IdentityInternalsUI::~IdentityInternalsUI() {} |
| 294 | 310 |
| OLD | NEW |