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 <memory> | 7 #include <memory> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/i18n/time_formatting.h" | 12 #include "base/i18n/time_formatting.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ptr_util.h" | |
| 14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/values.h" | 16 #include "base/values.h" |
| 16 #include "chrome/browser/extensions/api/identity/identity_api.h" | 17 #include "chrome/browser/extensions/api/identity/identity_api.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/common/url_constants.h" | 19 #include "chrome/common/url_constants.h" |
| 19 #include "chrome/grit/browser_resources.h" | 20 #include "chrome/grit/browser_resources.h" |
| 20 #include "chrome/grit/generated_resources.h" | 21 #include "chrome/grit/generated_resources.h" |
| 21 #include "content/public/browser/web_ui.h" | 22 #include "content/public/browser/web_ui.h" |
| 22 #include "content/public/browser/web_ui_controller.h" | 23 #include "content/public/browser/web_ui_controller.h" |
| 23 #include "content/public/browser/web_ui_data_source.h" | 24 #include "content/public/browser/web_ui_data_source.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 // to the caller using Javascript callback function | 89 // to the caller using Javascript callback function |
| 89 // |identity_internals.returnTokens()|. | 90 // |identity_internals.returnTokens()|. |
| 90 void GetInfoForAllTokens(const base::ListValue* args); | 91 void GetInfoForAllTokens(const base::ListValue* args); |
| 91 | 92 |
| 92 // Initiates revoking of the token, based on the extension ID and token | 93 // 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 | 94 // passed as entries in the |args| list. Updates the caller of completion |
| 94 // using Javascript callback function |identity_internals.tokenRevokeDone()|. | 95 // using Javascript callback function |identity_internals.tokenRevokeDone()|. |
| 95 void RevokeToken(const base::ListValue* args); | 96 void RevokeToken(const base::ListValue* args); |
| 96 | 97 |
| 97 // A vector of token revokers that are currently revoking tokens. | 98 // A vector of token revokers that are currently revoking tokens. |
| 98 ScopedVector<IdentityInternalsTokenRevoker> token_revokers_; | 99 std::vector<std::unique_ptr<IdentityInternalsTokenRevoker>> token_revokers_; |
| 99 }; | 100 }; |
| 100 | 101 |
| 101 // Handles the revoking of an access token and helps performing the clean up | 102 // Handles the revoking of an access token and helps performing the clean up |
| 102 // after it is revoked by holding information about the access token and related | 103 // after it is revoked by holding information about the access token and related |
| 103 // extension ID. | 104 // extension ID. |
| 104 class IdentityInternalsTokenRevoker : public GaiaAuthConsumer { | 105 class IdentityInternalsTokenRevoker : public GaiaAuthConsumer { |
| 105 public: | 106 public: |
| 106 // Revokes |access_token| from extension with |extension_id|. | 107 // Revokes |access_token| from extension with |extension_id|. |
| 107 // |profile| is required for its request context. |consumer| will be | 108 // |profile| is required for its request context. |consumer| will be |
| 108 // notified when revocation succeeds via |OnTokenRevokerDone()|. | 109 // notified when revocation succeeds via |OnTokenRevokerDone()|. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 api->EraseCachedToken(token_revoker->extension_id(), | 153 api->EraseCachedToken(token_revoker->extension_id(), |
| 153 token_revoker->access_token()); | 154 token_revoker->access_token()); |
| 154 | 155 |
| 155 // Update view about the token being removed. | 156 // Update view about the token being removed. |
| 156 base::ListValue result; | 157 base::ListValue result; |
| 157 result.AppendString(token_revoker->access_token()); | 158 result.AppendString(token_revoker->access_token()); |
| 158 web_ui()->CallJavascriptFunctionUnsafe("identity_internals.tokenRevokeDone", | 159 web_ui()->CallJavascriptFunctionUnsafe("identity_internals.tokenRevokeDone", |
| 159 result); | 160 result); |
| 160 | 161 |
| 161 // Erase the revoker. | 162 // Erase the revoker. |
| 162 ScopedVector<IdentityInternalsTokenRevoker>::iterator iter = | 163 auto iter = std::find_if( |
| 163 std::find(token_revokers_.begin(), token_revokers_.end(), token_revoker); | 164 token_revokers_.begin(), token_revokers_.end(), |
| 165 [token_revoker]( | |
| 166 const std::unique_ptr<IdentityInternalsTokenRevoker>& ptr) { | |
| 167 return ptr.get() == token_revoker; | |
| 168 }); | |
|
Nico
2017/01/03 18:12:35
same
Avi (use Gerrit)
2017/01/03 22:54:53
Done.
| |
| 164 DCHECK(iter != token_revokers_.end()); | 169 DCHECK(iter != token_revokers_.end()); |
| 165 token_revokers_.erase(iter); | 170 token_revokers_.erase(iter); |
| 166 } | 171 } |
| 167 | 172 |
| 168 const std::string IdentityInternalsUIMessageHandler::GetExtensionName( | 173 const std::string IdentityInternalsUIMessageHandler::GetExtensionName( |
| 169 const extensions::ExtensionTokenKey& token_cache_key) { | 174 const extensions::ExtensionTokenKey& token_cache_key) { |
| 170 const extensions::ExtensionRegistry* registry = | 175 const extensions::ExtensionRegistry* registry = |
| 171 extensions::ExtensionRegistry::Get(Profile::FromWebUI(web_ui())); | 176 extensions::ExtensionRegistry::Get(Profile::FromWebUI(web_ui())); |
| 172 const extensions::Extension* extension = | 177 const extensions::Extension* extension = |
| 173 registry->enabled_extensions().GetByID(token_cache_key.extension_id); | 178 registry->enabled_extensions().GetByID(token_cache_key.extension_id); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 base::Bind(&IdentityInternalsUIMessageHandler::RevokeToken, | 257 base::Bind(&IdentityInternalsUIMessageHandler::RevokeToken, |
| 253 base::Unretained(this))); | 258 base::Unretained(this))); |
| 254 } | 259 } |
| 255 | 260 |
| 256 void IdentityInternalsUIMessageHandler::RevokeToken( | 261 void IdentityInternalsUIMessageHandler::RevokeToken( |
| 257 const base::ListValue* args) { | 262 const base::ListValue* args) { |
| 258 std::string extension_id; | 263 std::string extension_id; |
| 259 std::string access_token; | 264 std::string access_token; |
| 260 args->GetString(kRevokeTokenExtensionOffset, &extension_id); | 265 args->GetString(kRevokeTokenExtensionOffset, &extension_id); |
| 261 args->GetString(kRevokeTokenTokenOffset, &access_token); | 266 args->GetString(kRevokeTokenTokenOffset, &access_token); |
| 262 token_revokers_.push_back(new IdentityInternalsTokenRevoker( | 267 token_revokers_.push_back(base::MakeUnique<IdentityInternalsTokenRevoker>( |
| 263 extension_id, access_token, Profile::FromWebUI(web_ui()), this)); | 268 extension_id, access_token, Profile::FromWebUI(web_ui()), this)); |
| 264 } | 269 } |
| 265 | 270 |
| 266 IdentityInternalsTokenRevoker::IdentityInternalsTokenRevoker( | 271 IdentityInternalsTokenRevoker::IdentityInternalsTokenRevoker( |
| 267 const std::string& extension_id, | 272 const std::string& extension_id, |
| 268 const std::string& access_token, | 273 const std::string& access_token, |
| 269 Profile* profile, | 274 Profile* profile, |
| 270 IdentityInternalsUIMessageHandler* consumer) | 275 IdentityInternalsUIMessageHandler* consumer) |
| 271 : fetcher_(this, GaiaConstants::kChromeSource, | 276 : fetcher_(this, GaiaConstants::kChromeSource, |
| 272 profile->GetRequestContext()), | 277 profile->GetRequestContext()), |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 html_source->AddResourcePath("identity_internals.js", | 321 html_source->AddResourcePath("identity_internals.js", |
| 317 IDR_IDENTITY_INTERNALS_JS); | 322 IDR_IDENTITY_INTERNALS_JS); |
| 318 html_source->SetDefaultResource(IDR_IDENTITY_INTERNALS_HTML); | 323 html_source->SetDefaultResource(IDR_IDENTITY_INTERNALS_HTML); |
| 319 | 324 |
| 320 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source); | 325 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source); |
| 321 | 326 |
| 322 web_ui->AddMessageHandler(new IdentityInternalsUIMessageHandler()); | 327 web_ui->AddMessageHandler(new IdentityInternalsUIMessageHandler()); |
| 323 } | 328 } |
| 324 | 329 |
| 325 IdentityInternalsUI::~IdentityInternalsUI() {} | 330 IdentityInternalsUI::~IdentityInternalsUI() {} |
| OLD | NEW |