| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 // includes deleting the |token_revoker|, removing the token from Identity API | 51 // includes deleting the |token_revoker|, removing the token from Identity API |
| 52 // cache and updating the UI that the token is gone. | 52 // cache and updating the UI that the token is gone. |
| 53 void OnTokenRevokerDone(IdentityInternalsTokenRevoker* token_revoker); | 53 void OnTokenRevokerDone(IdentityInternalsTokenRevoker* token_revoker); |
| 54 | 54 |
| 55 // WebUIMessageHandler implementation. | 55 // WebUIMessageHandler implementation. |
| 56 virtual void RegisterMessages() OVERRIDE; | 56 virtual void RegisterMessages() OVERRIDE; |
| 57 | 57 |
| 58 private: | 58 private: |
| 59 // Gets the name of an extension referred to by |token_cache_key| as a string. | 59 // Gets the name of an extension referred to by |token_cache_key| as a string. |
| 60 const std::string GetExtensionName( | 60 const std::string GetExtensionName( |
| 61 const extensions::IdentityAPI::TokenCacheKey& token_cache_key); | 61 const extensions::ExtensionTokenKey& token_cache_key); |
| 62 | 62 |
| 63 // Gets a list of scopes specified in |token_cache_key| and returns a pointer | 63 // Gets a list of scopes specified in |token_cache_key| and returns a pointer |
| 64 // to a ListValue containing the scopes. The caller gets ownership of the | 64 // to a ListValue containing the scopes. The caller gets ownership of the |
| 65 // returned object. | 65 // returned object. |
| 66 ListValue* GetScopes( | 66 ListValue* GetScopes( |
| 67 const extensions::IdentityAPI::TokenCacheKey& token_cache_key); | 67 const extensions::ExtensionTokenKey& token_cache_key); |
| 68 | 68 |
| 69 // Gets a localized status of the access token in |token_cache_value|. | 69 // Gets a localized status of the access token in |token_cache_value|. |
| 70 const base::string16 GetStatus( | 70 const base::string16 GetStatus( |
| 71 const extensions::IdentityTokenCacheValue& token_cache_value); | 71 const extensions::IdentityTokenCacheValue& token_cache_value); |
| 72 | 72 |
| 73 // Gets a string representation of an expiration time of the access token in | 73 // Gets a string representation of an expiration time of the access token in |
| 74 // |token_cache_value|. | 74 // |token_cache_value|. |
| 75 const std::string GetExpirationTime( | 75 const std::string GetExpirationTime( |
| 76 const extensions::IdentityTokenCacheValue& token_cache_value); | 76 const extensions::IdentityTokenCacheValue& token_cache_value); |
| 77 | 77 |
| 78 // Converts a pair of |token_cache_key| and |token_cache_value| to a | 78 // Converts a pair of |token_cache_key| and |token_cache_value| to a |
| 79 // DictionaryValue object with corresponding information in a localized and | 79 // DictionaryValue object with corresponding information in a localized and |
| 80 // readable form and returns a pointer to created object. Caller gets the | 80 // readable form and returns a pointer to created object. Caller gets the |
| 81 // ownership of the returned object. | 81 // ownership of the returned object. |
| 82 DictionaryValue* GetInfoForToken( | 82 DictionaryValue* GetInfoForToken( |
| 83 const extensions::IdentityAPI::TokenCacheKey& token_cache_key, | 83 const extensions::ExtensionTokenKey& token_cache_key, |
| 84 const extensions::IdentityTokenCacheValue& token_cache_value); | 84 const extensions::IdentityTokenCacheValue& token_cache_value); |
| 85 | 85 |
| 86 // Gets all of the tokens stored in IdentityAPI token cache and returns them | 86 // Gets all of the tokens stored in IdentityAPI token cache and returns them |
| 87 // to the caller using Javascript callback function | 87 // to the caller using Javascript callback function |
| 88 // |identity_internals.returnTokens()|. | 88 // |identity_internals.returnTokens()|. |
| 89 void GetInfoForAllTokens(const ListValue* args); | 89 void GetInfoForAllTokens(const ListValue* args); |
| 90 | 90 |
| 91 // Initiates revoking of the token, based on the extension ID and token | 91 // Initiates revoking of the token, based on the extension ID and token |
| 92 // passed as entries in the |args| list. Updates the caller of completion | 92 // passed as entries in the |args| list. Updates the caller of completion |
| 93 // using Javascript callback function |identity_internals.tokenRevokeDone()|. | 93 // using Javascript callback function |identity_internals.tokenRevokeDone()|. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 result); | 151 result); |
| 152 | 152 |
| 153 // Erase the revoker. | 153 // Erase the revoker. |
| 154 ScopedVector<IdentityInternalsTokenRevoker>::iterator iter = | 154 ScopedVector<IdentityInternalsTokenRevoker>::iterator iter = |
| 155 std::find(token_revokers_.begin(), token_revokers_.end(), token_revoker); | 155 std::find(token_revokers_.begin(), token_revokers_.end(), token_revoker); |
| 156 DCHECK(iter != token_revokers_.end()); | 156 DCHECK(iter != token_revokers_.end()); |
| 157 token_revokers_.erase(iter); | 157 token_revokers_.erase(iter); |
| 158 } | 158 } |
| 159 | 159 |
| 160 const std::string IdentityInternalsUIMessageHandler::GetExtensionName( | 160 const std::string IdentityInternalsUIMessageHandler::GetExtensionName( |
| 161 const extensions::IdentityAPI::TokenCacheKey& token_cache_key) { | 161 const extensions::ExtensionTokenKey& token_cache_key) { |
| 162 ExtensionService* extension_service = extensions::ExtensionSystem::Get( | 162 ExtensionService* extension_service = extensions::ExtensionSystem::Get( |
| 163 Profile::FromWebUI(web_ui()))->extension_service(); | 163 Profile::FromWebUI(web_ui()))->extension_service(); |
| 164 const extensions::Extension* extension = | 164 const extensions::Extension* extension = |
| 165 extension_service->extensions()->GetByID(token_cache_key.extension_id); | 165 extension_service->extensions()->GetByID(token_cache_key.extension_id); |
| 166 if (!extension) | 166 if (!extension) |
| 167 return std::string(); | 167 return std::string(); |
| 168 return extension->name(); | 168 return extension->name(); |
| 169 } | 169 } |
| 170 | 170 |
| 171 ListValue* IdentityInternalsUIMessageHandler::GetScopes( | 171 ListValue* IdentityInternalsUIMessageHandler::GetScopes( |
| 172 const extensions::IdentityAPI::TokenCacheKey& token_cache_key) { | 172 const extensions::ExtensionTokenKey& token_cache_key) { |
| 173 ListValue* scopes_value = new ListValue(); | 173 ListValue* scopes_value = new ListValue(); |
| 174 for (std::set<std::string>::const_iterator | 174 for (std::set<std::string>::const_iterator |
| 175 iter = token_cache_key.scopes.begin(); | 175 iter = token_cache_key.scopes.begin(); |
| 176 iter != token_cache_key.scopes.end(); ++iter) { | 176 iter != token_cache_key.scopes.end(); ++iter) { |
| 177 scopes_value->AppendString(*iter); | 177 scopes_value->AppendString(*iter); |
| 178 } | 178 } |
| 179 return scopes_value; | 179 return scopes_value; |
| 180 } | 180 } |
| 181 | 181 |
| 182 const base::string16 IdentityInternalsUIMessageHandler::GetStatus( | 182 const base::string16 IdentityInternalsUIMessageHandler::GetStatus( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 195 return base::string16(); | 195 return base::string16(); |
| 196 } | 196 } |
| 197 | 197 |
| 198 const std::string IdentityInternalsUIMessageHandler::GetExpirationTime( | 198 const std::string IdentityInternalsUIMessageHandler::GetExpirationTime( |
| 199 const extensions::IdentityTokenCacheValue& token_cache_value) { | 199 const extensions::IdentityTokenCacheValue& token_cache_value) { |
| 200 return UTF16ToUTF8(base::TimeFormatFriendlyDateAndTime( | 200 return UTF16ToUTF8(base::TimeFormatFriendlyDateAndTime( |
| 201 token_cache_value.expiration_time())); | 201 token_cache_value.expiration_time())); |
| 202 } | 202 } |
| 203 | 203 |
| 204 DictionaryValue* IdentityInternalsUIMessageHandler::GetInfoForToken( | 204 DictionaryValue* IdentityInternalsUIMessageHandler::GetInfoForToken( |
| 205 const extensions::IdentityAPI::TokenCacheKey& token_cache_key, | 205 const extensions::ExtensionTokenKey& token_cache_key, |
| 206 const extensions::IdentityTokenCacheValue& token_cache_value) { | 206 const extensions::IdentityTokenCacheValue& token_cache_value) { |
| 207 DictionaryValue* token_data = new DictionaryValue(); | 207 DictionaryValue* token_data = new DictionaryValue(); |
| 208 token_data->SetString(kExtensionId, token_cache_key.extension_id); | 208 token_data->SetString(kExtensionId, token_cache_key.extension_id); |
| 209 token_data->SetString(kExtensionName, GetExtensionName(token_cache_key)); | 209 token_data->SetString(kExtensionName, GetExtensionName(token_cache_key)); |
| 210 token_data->Set(kScopes, GetScopes(token_cache_key)); | 210 token_data->Set(kScopes, GetScopes(token_cache_key)); |
| 211 token_data->SetString(kStatus, GetStatus(token_cache_value)); | 211 token_data->SetString(kStatus, GetStatus(token_cache_value)); |
| 212 token_data->SetString(kAccessToken, token_cache_value.token()); | 212 token_data->SetString(kAccessToken, token_cache_value.token()); |
| 213 token_data->SetString(kTokenExpirationTime, | 213 token_data->SetString(kTokenExpirationTime, |
| 214 GetExpirationTime(token_cache_value)); | 214 GetExpirationTime(token_cache_value)); |
| 215 return token_data; | 215 return token_data; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 html_source->AddResourcePath("identity_internals.js", | 301 html_source->AddResourcePath("identity_internals.js", |
| 302 IDR_IDENTITY_INTERNALS_JS); | 302 IDR_IDENTITY_INTERNALS_JS); |
| 303 html_source->SetDefaultResource(IDR_IDENTITY_INTERNALS_HTML); | 303 html_source->SetDefaultResource(IDR_IDENTITY_INTERNALS_HTML); |
| 304 | 304 |
| 305 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source); | 305 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source); |
| 306 | 306 |
| 307 web_ui->AddMessageHandler(new IdentityInternalsUIMessageHandler()); | 307 web_ui->AddMessageHandler(new IdentityInternalsUIMessageHandler()); |
| 308 } | 308 } |
| 309 | 309 |
| 310 IdentityInternalsUI::~IdentityInternalsUI() {} | 310 IdentityInternalsUI::~IdentityInternalsUI() {} |
| 311 | |
| OLD | NEW |