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 <memory> |
7 #include <set> | 8 #include <set> |
8 #include <string> | 9 #include <string> |
9 | 10 |
10 #include "base/bind.h" | 11 #include "base/bind.h" |
11 #include "base/i18n/time_formatting.h" | 12 #include "base/i18n/time_formatting.h" |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
14 #include "base/values.h" | 15 #include "base/values.h" |
15 #include "chrome/browser/extensions/api/identity/identity_api.h" | 16 #include "chrome/browser/extensions/api/identity/identity_api.h" |
16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 const base::string16 GetStatus( | 72 const base::string16 GetStatus( |
72 const extensions::IdentityTokenCacheValue& token_cache_value); | 73 const extensions::IdentityTokenCacheValue& token_cache_value); |
73 | 74 |
74 // Gets a string representation of an expiration time of the access token in | 75 // Gets a string representation of an expiration time of the access token in |
75 // |token_cache_value|. | 76 // |token_cache_value|. |
76 const std::string GetExpirationTime( | 77 const std::string GetExpirationTime( |
77 const extensions::IdentityTokenCacheValue& token_cache_value); | 78 const extensions::IdentityTokenCacheValue& token_cache_value); |
78 | 79 |
79 // Converts a pair of |token_cache_key| and |token_cache_value| to a | 80 // Converts a pair of |token_cache_key| and |token_cache_value| to a |
80 // DictionaryValue object with corresponding information in a localized and | 81 // DictionaryValue object with corresponding information in a localized and |
81 // readable form and returns a pointer to created object. Caller gets the | 82 // readable form and returns a pointer to created object. |
82 // ownership of the returned object. | 83 std::unique_ptr<base::DictionaryValue> GetInfoForToken( |
83 base::DictionaryValue* GetInfoForToken( | |
84 const extensions::ExtensionTokenKey& token_cache_key, | 84 const extensions::ExtensionTokenKey& token_cache_key, |
85 const extensions::IdentityTokenCacheValue& token_cache_value); | 85 const extensions::IdentityTokenCacheValue& token_cache_value); |
86 | 86 |
87 // Gets all of the tokens stored in IdentityAPI token cache and returns them | 87 // Gets all of the tokens stored in IdentityAPI token cache and returns them |
88 // to the caller using Javascript callback function | 88 // to the caller using Javascript callback function |
89 // |identity_internals.returnTokens()|. | 89 // |identity_internals.returnTokens()|. |
90 void GetInfoForAllTokens(const base::ListValue* args); | 90 void GetInfoForAllTokens(const base::ListValue* args); |
91 | 91 |
92 // Initiates revoking of the token, based on the extension ID and token | 92 // Initiates revoking of the token, based on the extension ID and token |
93 // passed as entries in the |args| list. Updates the caller of completion | 93 // passed as entries in the |args| list. Updates the caller of completion |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 NOTREACHED(); | 202 NOTREACHED(); |
203 return base::string16(); | 203 return base::string16(); |
204 } | 204 } |
205 | 205 |
206 const std::string IdentityInternalsUIMessageHandler::GetExpirationTime( | 206 const std::string IdentityInternalsUIMessageHandler::GetExpirationTime( |
207 const extensions::IdentityTokenCacheValue& token_cache_value) { | 207 const extensions::IdentityTokenCacheValue& token_cache_value) { |
208 return base::UTF16ToUTF8(base::TimeFormatFriendlyDateAndTime( | 208 return base::UTF16ToUTF8(base::TimeFormatFriendlyDateAndTime( |
209 token_cache_value.expiration_time())); | 209 token_cache_value.expiration_time())); |
210 } | 210 } |
211 | 211 |
212 base::DictionaryValue* IdentityInternalsUIMessageHandler::GetInfoForToken( | 212 std::unique_ptr<base::DictionaryValue> |
| 213 IdentityInternalsUIMessageHandler::GetInfoForToken( |
213 const extensions::ExtensionTokenKey& token_cache_key, | 214 const extensions::ExtensionTokenKey& token_cache_key, |
214 const extensions::IdentityTokenCacheValue& token_cache_value) { | 215 const extensions::IdentityTokenCacheValue& token_cache_value) { |
215 base::DictionaryValue* token_data = new base::DictionaryValue(); | 216 std::unique_ptr<base::DictionaryValue> token_data( |
| 217 new base::DictionaryValue()); |
216 token_data->SetString(kExtensionId, token_cache_key.extension_id); | 218 token_data->SetString(kExtensionId, token_cache_key.extension_id); |
217 token_data->SetString(kExtensionName, GetExtensionName(token_cache_key)); | 219 token_data->SetString(kExtensionName, GetExtensionName(token_cache_key)); |
218 token_data->Set(kScopes, GetScopes(token_cache_key)); | 220 token_data->Set(kScopes, GetScopes(token_cache_key)); |
219 token_data->SetString(kStatus, GetStatus(token_cache_value)); | 221 token_data->SetString(kStatus, GetStatus(token_cache_value)); |
220 token_data->SetString(kAccessToken, token_cache_value.token()); | 222 token_data->SetString(kAccessToken, token_cache_value.token()); |
221 token_data->SetString(kTokenExpirationTime, | 223 token_data->SetString(kTokenExpirationTime, |
222 GetExpirationTime(token_cache_value)); | 224 GetExpirationTime(token_cache_value)); |
223 return token_data; | 225 return token_data; |
224 } | 226 } |
225 | 227 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 html_source->AddResourcePath("identity_internals.js", | 316 html_source->AddResourcePath("identity_internals.js", |
315 IDR_IDENTITY_INTERNALS_JS); | 317 IDR_IDENTITY_INTERNALS_JS); |
316 html_source->SetDefaultResource(IDR_IDENTITY_INTERNALS_HTML); | 318 html_source->SetDefaultResource(IDR_IDENTITY_INTERNALS_HTML); |
317 | 319 |
318 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source); | 320 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source); |
319 | 321 |
320 web_ui->AddMessageHandler(new IdentityInternalsUIMessageHandler()); | 322 web_ui->AddMessageHandler(new IdentityInternalsUIMessageHandler()); |
321 } | 323 } |
322 | 324 |
323 IdentityInternalsUI::~IdentityInternalsUI() {} | 325 IdentityInternalsUI::~IdentityInternalsUI() {} |
OLD | NEW |