diff options
Diffstat (limited to 'chrome/browser/ui/webui')
14 files changed, 349 insertions, 427 deletions
diff --git a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc index cbe8486..ee64a13 100644 --- a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc +++ b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc @@ -32,7 +32,7 @@ #include "chrome/browser/ui/webui/gcm_internals_ui.h" #include "chrome/browser/ui/webui/help/help_ui.h" #include "chrome/browser/ui/webui/history_ui.h" -#include "chrome/browser/ui/webui/identity_internals/identity_internals_ui.h" +#include "chrome/browser/ui/webui/identity_internals_ui.h" #include "chrome/browser/ui/webui/inspect_ui.h" #include "chrome/browser/ui/webui/instant_ui.h" #include "chrome/browser/ui/webui/invalidations_ui.h" diff --git a/chrome/browser/ui/webui/identity_internals/BUILD.gn b/chrome/browser/ui/webui/identity_internals/BUILD.gn deleted file mode 100644 index 0e47e6d..0000000 --- a/chrome/browser/ui/webui/identity_internals/BUILD.gn +++ /dev/null @@ -1,12 +0,0 @@ -# Copyright 2014 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -import("//mojo/public/tools/bindings/mojom.gni") - -# GYP version: chrome/chrome_web_ui_mojo_bindings.gyp:webui_mojo_bindings -mojom("mojo_bindings") { - sources = [ - "identity_internals.mojom", - ] -} diff --git a/chrome/browser/ui/webui/identity_internals/identity_internals.mojom b/chrome/browser/ui/webui/identity_internals/identity_internals.mojom deleted file mode 100644 index 34624ec..0000000 --- a/chrome/browser/ui/webui/identity_internals/identity_internals.mojom +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Data structure passed from the browser process to the webui page with all -// data about an individual identity token. -struct IdentityTokenMojo { - string access_token; - string extension_name; - string extension_id; - string token_status; - string expiration_time; - string[] scopes; -}; - -[Client=InternalsPage] -interface IdentityInternalsHandlerMojo { - GetTokens() => (IdentityTokenMojo[] tokens); - RevokeToken(string extension_id, string access_token) => (); -}; - -// Empty interface to represent the page. -// -// TODO(erg): Once the javascript bindings no longer require the page to have -// an interface, remove this. -interface InternalsPage { -}; diff --git a/chrome/browser/ui/webui/identity_internals/identity_internals_token_revoker.cc b/chrome/browser/ui/webui/identity_internals/identity_internals_token_revoker.cc deleted file mode 100644 index f40401d6..0000000 --- a/chrome/browser/ui/webui/identity_internals/identity_internals_token_revoker.cc +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/webui/identity_internals/identity_internals_token_revoker.h" - -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/webui/identity_internals/identity_internals_ui_handler.h" -#include "google_apis/gaia/gaia_constants.h" - -IdentityInternalsTokenRevoker::IdentityInternalsTokenRevoker( - const std::string& extension_id, - const std::string& access_token, - const mojo::Callback<void()>& callback, - Profile* profile, - IdentityInternalsUIHandler* consumer) - : fetcher_(this, GaiaConstants::kChromeSource, - profile->GetRequestContext()), - extension_id_(extension_id), - access_token_(access_token), - callback_(callback), - consumer_(consumer) { - DCHECK(consumer_); - fetcher_.StartRevokeOAuth2Token(access_token); -} - -IdentityInternalsTokenRevoker::~IdentityInternalsTokenRevoker() {} - -void IdentityInternalsTokenRevoker::OnOAuth2RevokeTokenCompleted() { - consumer_->OnTokenRevokerDone(this); -} diff --git a/chrome/browser/ui/webui/identity_internals/identity_internals_token_revoker.h b/chrome/browser/ui/webui/identity_internals/identity_internals_token_revoker.h deleted file mode 100644 index 58c957c..0000000 --- a/chrome/browser/ui/webui/identity_internals/identity_internals_token_revoker.h +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_WEBUI_IDENTITY_INTERNALS_IDENTITY_INTERNALS_TOKEN_REVOKER_H_ -#define CHROME_BROWSER_UI_WEBUI_IDENTITY_INTERNALS_IDENTITY_INTERNALS_TOKEN_REVOKER_H_ - -#include <string> - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "google_apis/gaia/gaia_auth_fetcher.h" -#include "mojo/public/cpp/bindings/callback.h" - -class IdentityInternalsUIHandler; -class Profile; - -// Handles the revoking of an access token and helps performing the clean up -// after it is revoked by holding information about the access token and related -// extension ID. -class IdentityInternalsTokenRevoker : public GaiaAuthConsumer { - public: - // Revokes |access_token| from extension with |extension_id|. - // |profile| is required for its request context. |consumer| will be - // notified when revocation succeeds via |OnTokenRevokerDone()|. - IdentityInternalsTokenRevoker(const std::string& extension_id, - const std::string& access_token, - const mojo::Callback<void()>& callback, - Profile* profile, - IdentityInternalsUIHandler* consumer); - virtual ~IdentityInternalsTokenRevoker(); - - // Returns the access token being revoked. - const std::string& access_token() const { return access_token_; } - - // Returns the ID of the extension the access token is related to. - const std::string& extension_id() const { return extension_id_; } - - const mojo::Callback<void()>& callback() const { return callback_; } - - // GaiaAuthConsumer implementation. - virtual void OnOAuth2RevokeTokenCompleted() OVERRIDE; - - private: - // An object used to start a token revoke request. - GaiaAuthFetcher fetcher_; - - // An ID of an extension the access token is related to. - const std::string extension_id_; - - // The access token to revoke. - const std::string access_token_; - - // Callback for when we complete. - const mojo::Callback<void()> callback_; - - // An object that needs to be notified once the access token is revoked. - IdentityInternalsUIHandler* consumer_; // weak. - - DISALLOW_COPY_AND_ASSIGN(IdentityInternalsTokenRevoker); -}; - -#endif // CHROME_BROWSER_UI_WEBUI_IDENTITY_INTERNALS_IDENTITY_INTERNALS_TOKEN_REVOKER_H_ diff --git a/chrome/browser/ui/webui/identity_internals/identity_internals_ui.cc b/chrome/browser/ui/webui/identity_internals/identity_internals_ui.cc deleted file mode 100644 index 23b310a..0000000 --- a/chrome/browser/ui/webui/identity_internals/identity_internals_ui.cc +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/webui/identity_internals/identity_internals_ui.h" - -#include <string> - -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/webui/identity_internals/identity_internals_ui_handler.h" -#include "chrome/common/url_constants.h" -#include "content/public/browser/web_ui.h" -#include "content/public/browser/web_ui_controller.h" -#include "content/public/browser/web_ui_data_source.h" -#include "grit/browser_resources.h" -#include "grit/generated_resources.h" -#include "ui/base/l10n/l10n_util.h" - - -IdentityInternalsUI::IdentityInternalsUI(content::WebUI* web_ui) - : MojoWebUIController(web_ui) { - // chrome://identity-internals source. - content::WebUIDataSource* html_source = - content::WebUIDataSource::Create(chrome::kChromeUIIdentityInternalsHost); - html_source->SetUseJsonJSFormatV2(); - - // Localized strings - html_source->AddLocalizedString("tokenCacheHeader", - IDS_IDENTITY_INTERNALS_TOKEN_CACHE_TEXT); - html_source->AddLocalizedString("accessToken", - IDS_IDENTITY_INTERNALS_ACCESS_TOKEN); - html_source->AddLocalizedString("extensionName", - IDS_IDENTITY_INTERNALS_EXTENSION_NAME); - html_source->AddLocalizedString("extensionId", - IDS_IDENTITY_INTERNALS_EXTENSION_ID); - html_source->AddLocalizedString("tokenStatus", - IDS_IDENTITY_INTERNALS_TOKEN_STATUS); - html_source->AddLocalizedString("expirationTime", - IDS_IDENTITY_INTERNALS_EXPIRATION_TIME); - html_source->AddLocalizedString("scopes", - IDS_IDENTITY_INTERNALS_SCOPES); - html_source->AddLocalizedString("revoke", - IDS_IDENTITY_INTERNALS_REVOKE); - html_source->SetJsonPath("strings.js"); - - // Required resources - html_source->AddResourcePath("identity_internals.css", - IDR_IDENTITY_INTERNALS_CSS); - html_source->AddResourcePath("identity_internals.js", - IDR_IDENTITY_INTERNALS_JS); - html_source->SetDefaultResource(IDR_IDENTITY_INTERNALS_HTML); - - content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source); - - AddMojoResourcePath( - "chrome/browser/ui/webui/identity_internals/identity_internals.mojom", - IDR_IDENTITY_INTERNALS_MOJO_JS); -} - -IdentityInternalsUI::~IdentityInternalsUI() {} - -scoped_ptr<MojoWebUIHandler> IdentityInternalsUI::CreateUIHandler( - mojo::ScopedMessagePipeHandle handle_to_page) { - return scoped_ptr<MojoWebUIHandler>(mojo::BindToPipe( - new IdentityInternalsUIHandler(Profile::FromWebUI(web_ui())), - handle_to_page.Pass())); -} diff --git a/chrome/browser/ui/webui/identity_internals/identity_internals_ui.h b/chrome/browser/ui/webui/identity_internals/identity_internals_ui.h deleted file mode 100644 index 0fbe98a..0000000 --- a/chrome/browser/ui/webui/identity_internals/identity_internals_ui.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_WEBUI_IDENTITY_INTERNALS_IDENTITY_INTERNALS_UI_H_ -#define CHROME_BROWSER_UI_WEBUI_IDENTITY_INTERNALS_IDENTITY_INTERNALS_UI_H_ - -#include "base/basictypes.h" -#include "chrome/browser/ui/webui/mojo_web_ui_controller.h" - -class IdentityInternalsUITest; - -// The WebUI for chrome://identity-internals -class IdentityInternalsUI : public MojoWebUIController { - public: - explicit IdentityInternalsUI(content::WebUI* web_ui); - virtual ~IdentityInternalsUI(); - - private: - // MojoWebUIController overrides: - virtual scoped_ptr<MojoWebUIHandler> CreateUIHandler( - mojo::ScopedMessagePipeHandle handle_to_page) OVERRIDE; - - DISALLOW_COPY_AND_ASSIGN(IdentityInternalsUI); -}; - -#endif // CHROME_BROWSER_UI_WEBUI_IDENTITY_INTERNALS_IDENTITY_INTERNALS_UI_H_ diff --git a/chrome/browser/ui/webui/identity_internals/identity_internals_ui_handler.cc b/chrome/browser/ui/webui/identity_internals/identity_internals_ui_handler.cc deleted file mode 100644 index 8a486d5..0000000 --- a/chrome/browser/ui/webui/identity_internals/identity_internals_ui_handler.cc +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/webui/identity_internals/identity_internals_ui_handler.h" - -#include "base/i18n/time_formatting.h" -#include "base/strings/utf_string_conversions.h" -#include "chrome/browser/extensions/extension_service.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/webui/identity_internals/identity_internals_token_revoker.h" -#include "extensions/browser/extension_system.h" -#include "grit/browser_resources.h" -#include "grit/generated_resources.h" -#include "ui/base/l10n/l10n_util.h" - -IdentityInternalsUIHandler::IdentityInternalsUIHandler(Profile* profile) - : profile_(profile) {} - -IdentityInternalsUIHandler::~IdentityInternalsUIHandler() {} - -void IdentityInternalsUIHandler::OnTokenRevokerDone( - IdentityInternalsTokenRevoker* token_revoker) { - // Remove token from the cache. - extensions::IdentityAPI::GetFactoryInstance() - ->Get(profile_) - ->EraseCachedToken(token_revoker->extension_id(), - token_revoker->access_token()); - - // Update view about the token being removed. - token_revoker->callback().Run(); - - // Erase the revoker. - ScopedVector<IdentityInternalsTokenRevoker>::iterator iter = - std::find(token_revokers_.begin(), token_revokers_.end(), token_revoker); - DCHECK(iter != token_revokers_.end()); - token_revokers_.erase(iter); -} - -void IdentityInternalsUIHandler::GetTokens( - const mojo::Callback<void(mojo::Array<IdentityTokenMojoPtr>)>& callback) { - extensions::IdentityAPI::CachedTokens tokens = - extensions::IdentityAPI::GetFactoryInstance() - ->Get(profile_)->GetAllCachedTokens(); - callback.Run(ConvertCachedTokens(tokens).Pass()); -} - -void IdentityInternalsUIHandler::RevokeToken( - const mojo::String& extension_id, - const mojo::String& access_token, - const mojo::Callback<void()>& callback) { - token_revokers_.push_back(new IdentityInternalsTokenRevoker( - extension_id, access_token, callback, profile_, this)); -} - -mojo::Array<IdentityTokenMojoPtr> -IdentityInternalsUIHandler::ConvertCachedTokens( - const extensions::IdentityAPI::CachedTokens& tokens) { - mojo::Array<IdentityTokenMojoPtr> array(tokens.size()); - size_t index = 0; - for (extensions::IdentityAPI::CachedTokens::const_iterator - it = tokens.begin(); it != tokens.end(); ++it, index++) { - IdentityTokenMojoPtr item(IdentityTokenMojo::New()); - item->access_token = it->second.token(); - item->extension_name = GetExtensionName(it->first); - item->extension_id = it->first.extension_id; - item->token_status = GetStatus(it->second); - item->expiration_time = GetExpirationTime(it->second); - item->scopes = GetScopes(it->first).Pass(); - - array[index] = item.Pass(); - } - - return array.Pass(); -} - -const std::string IdentityInternalsUIHandler::GetExtensionName( - const extensions::ExtensionTokenKey& token_cache_key) { - ExtensionService* extension_service = extensions::ExtensionSystem::Get( - profile_)->extension_service(); - const extensions::Extension* extension = - extension_service->extensions()->GetByID(token_cache_key.extension_id); - if (!extension) - return std::string(); - return extension->name(); -} - -mojo::Array<mojo::String> IdentityInternalsUIHandler::GetScopes( - const extensions::ExtensionTokenKey& token_cache_key) { - mojo::Array<mojo::String> array(token_cache_key.scopes.size()); - size_t index = 0; - for (std::set<std::string>::const_iterator - it = token_cache_key.scopes.begin(); - it != token_cache_key.scopes.end(); ++it, index++) { - array[index] = mojo::String(*it); - } - return array.Pass(); -} - -const std::string IdentityInternalsUIHandler::GetStatus( - const extensions::IdentityTokenCacheValue& token_cache_value) { - switch (token_cache_value.status()) { - case extensions::IdentityTokenCacheValue::CACHE_STATUS_ADVICE: - // Fallthrough to NOT FOUND case, as ADVICE is short lived. - case extensions::IdentityTokenCacheValue::CACHE_STATUS_NOTFOUND: - return l10n_util::GetStringUTF8( - IDS_IDENTITY_INTERNALS_TOKEN_NOT_FOUND); - case extensions::IdentityTokenCacheValue::CACHE_STATUS_TOKEN: - return l10n_util::GetStringUTF8( - IDS_IDENTITY_INTERNALS_TOKEN_PRESENT); - } - NOTREACHED(); - return std::string(); -} - -const std::string IdentityInternalsUIHandler::GetExpirationTime( - const extensions::IdentityTokenCacheValue& token_cache_value) { - return base::UTF16ToUTF8(base::TimeFormatFriendlyDateAndTime( - token_cache_value.expiration_time())); -} diff --git a/chrome/browser/ui/webui/identity_internals/identity_internals_ui_handler.h b/chrome/browser/ui/webui/identity_internals/identity_internals_ui_handler.h deleted file mode 100644 index 400e521..0000000 --- a/chrome/browser/ui/webui/identity_internals/identity_internals_ui_handler.h +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_WEBUI_IDENTITY_INTERNALS_IDENTITY_INTERNALS_UI_HANDLER_H_ -#define CHROME_BROWSER_UI_WEBUI_IDENTITY_INTERNALS_IDENTITY_INTERNALS_UI_HANDLER_H_ - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "chrome/browser/extensions/api/identity/identity_api.h" -#include "chrome/browser/ui/webui/identity_internals/identity_internals.mojom.h" -#include "chrome/browser/ui/webui/mojo_web_ui_handler.h" - -class Profile; -class IdentityInternalsTokenRevoker; - -// Class acting as a controller of the chrome://identity-internals WebUI. -class IdentityInternalsUIHandler - : public mojo::InterfaceImpl<IdentityInternalsHandlerMojo>, - public MojoWebUIHandler { - public: - explicit IdentityInternalsUIHandler(Profile* profile); - virtual ~IdentityInternalsUIHandler(); - - // Ensures that a proper clean up happens after a token is revoked. That - // includes deleting the |token_revoker|, removing the token from Identity API - // cache and updating the UI that the token is gone. - void OnTokenRevokerDone(IdentityInternalsTokenRevoker* token_revoker); - - // Overridden from IdentityInternalsHandlerMojo: - virtual void GetTokens( - const mojo::Callback<void(mojo::Array<IdentityTokenMojoPtr>)>& callback) - OVERRIDE; - virtual void RevokeToken(const mojo::String& extension_id, - const mojo::String& access_token, - const mojo::Callback<void()>& callback) OVERRIDE; - - private: - // We use an explicit conversion function instead of TypeConverter because - // creating an IdentityTokenMojo relies on having the Profile* as state. - mojo::Array<IdentityTokenMojoPtr> ConvertCachedTokens( - const extensions::IdentityAPI::CachedTokens& tokens); - - // Gets the name of an extension referred to by |token_cache_key| as a string. - const std::string GetExtensionName( - const extensions::ExtensionTokenKey& token_cache_key); - - // Gets a list of scopes specified in |token_cache_key| and returns a pointer - // to a ListValue containing the scopes. The caller gets ownership of the - // returned object. - mojo::Array<mojo::String> GetScopes( - const extensions::ExtensionTokenKey& token_cache_key); - - // Gets a localized status of the access token in |token_cache_value|. - const std::string GetStatus( - const extensions::IdentityTokenCacheValue& token_cache_value); - - // Gets a string representation of an expiration time of the access token in - // |token_cache_value|. - const std::string GetExpirationTime( - const extensions::IdentityTokenCacheValue& token_cache_value); - - Profile* profile_; - - // A vector of token revokers that are currently revoking tokens. - ScopedVector<IdentityInternalsTokenRevoker> token_revokers_; - - DISALLOW_COPY_AND_ASSIGN(IdentityInternalsUIHandler); -}; - -#endif // CHROME_BROWSER_UI_WEBUI_IDENTITY_INTERNALS_IDENTITY_INTERNALS_UI_HANDLER_H_ diff --git a/chrome/browser/ui/webui/identity_internals_ui.cc b/chrome/browser/ui/webui/identity_internals_ui.cc new file mode 100644 index 0000000..16607b1 --- /dev/null +++ b/chrome/browser/ui/webui/identity_internals_ui.cc @@ -0,0 +1,314 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/ui/webui/identity_internals_ui.h" + +#include <set> +#include <string> + +#include "base/bind.h" +#include "base/i18n/time_formatting.h" +#include "base/strings/utf_string_conversions.h" +#include "base/values.h" +#include "chrome/browser/extensions/api/identity/identity_api.h" +#include "chrome/browser/extensions/extension_service.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/common/url_constants.h" +#include "content/public/browser/web_ui.h" +#include "content/public/browser/web_ui_controller.h" +#include "content/public/browser/web_ui_data_source.h" +#include "content/public/browser/web_ui_message_handler.h" +#include "extensions/browser/extension_system.h" +#include "google_apis/gaia/gaia_auth_fetcher.h" +#include "google_apis/gaia/gaia_constants.h" +#include "grit/browser_resources.h" +#include "grit/generated_resources.h" +#include "ui/base/l10n/l10n_util.h" + +namespace { + +// Properties of the Javascript object representing a token. +const char kExtensionId[] = "extensionId"; +const char kExtensionName[] = "extensionName"; +const char kScopes[] = "scopes"; +const char kStatus[] = "status"; +const char kTokenExpirationTime[] = "expirationTime"; +const char kAccessToken[] = "accessToken"; + +// RevokeToken message parameter offsets. +const int kRevokeTokenExtensionOffset = 0; +const int kRevokeTokenTokenOffset = 1; + +class IdentityInternalsTokenRevoker; + +// Class acting as a controller of the chrome://identity-internals WebUI. +class IdentityInternalsUIMessageHandler : public content::WebUIMessageHandler { + public: + IdentityInternalsUIMessageHandler(); + virtual ~IdentityInternalsUIMessageHandler(); + + // Ensures that a proper clean up happens after a token is revoked. That + // includes deleting the |token_revoker|, removing the token from Identity API + // cache and updating the UI that the token is gone. + void OnTokenRevokerDone(IdentityInternalsTokenRevoker* token_revoker); + + // WebUIMessageHandler implementation. + virtual void RegisterMessages() OVERRIDE; + + private: + // Gets the name of an extension referred to by |token_cache_key| as a string. + const std::string GetExtensionName( + const extensions::ExtensionTokenKey& token_cache_key); + + // Gets a list of scopes specified in |token_cache_key| and returns a pointer + // to a ListValue containing the scopes. The caller gets ownership of the + // returned object. + base::ListValue* GetScopes( + const extensions::ExtensionTokenKey& token_cache_key); + + // Gets a localized status of the access token in |token_cache_value|. + const base::string16 GetStatus( + const extensions::IdentityTokenCacheValue& token_cache_value); + + // Gets a string representation of an expiration time of the access token in + // |token_cache_value|. + const std::string GetExpirationTime( + const extensions::IdentityTokenCacheValue& token_cache_value); + + // Converts a pair of |token_cache_key| and |token_cache_value| to a + // DictionaryValue object with corresponding information in a localized and + // readable form and returns a pointer to created object. Caller gets the + // ownership of the returned object. + base::DictionaryValue* GetInfoForToken( + const extensions::ExtensionTokenKey& token_cache_key, + const extensions::IdentityTokenCacheValue& token_cache_value); + + // Gets all of the tokens stored in IdentityAPI token cache and returns them + // to the caller using Javascript callback function + // |identity_internals.returnTokens()|. + void GetInfoForAllTokens(const base::ListValue* args); + + // Initiates revoking of the token, based on the extension ID and token + // passed as entries in the |args| list. Updates the caller of completion + // using Javascript callback function |identity_internals.tokenRevokeDone()|. + void RevokeToken(const base::ListValue* args); + + // A vector of token revokers that are currently revoking tokens. + ScopedVector<IdentityInternalsTokenRevoker> token_revokers_; +}; + +// Handles the revoking of an access token and helps performing the clean up +// after it is revoked by holding information about the access token and related +// extension ID. +class IdentityInternalsTokenRevoker : public GaiaAuthConsumer { + public: + // Revokes |access_token| from extension with |extension_id|. + // |profile| is required for its request context. |consumer| will be + // notified when revocation succeeds via |OnTokenRevokerDone()|. + IdentityInternalsTokenRevoker(const std::string& extension_id, + const std::string& access_token, + Profile* profile, + IdentityInternalsUIMessageHandler* consumer); + virtual ~IdentityInternalsTokenRevoker(); + + // Returns the access token being revoked. + const std::string& access_token() const { return access_token_; } + + // Returns the ID of the extension the access token is related to. + const std::string& extension_id() const { return extension_id_; } + + // GaiaAuthConsumer implementation. + virtual void OnOAuth2RevokeTokenCompleted() OVERRIDE; + + private: + // An object used to start a token revoke request. + GaiaAuthFetcher fetcher_; + // An ID of an extension the access token is related to. + const std::string extension_id_; + // The access token to revoke. + const std::string access_token_; + // An object that needs to be notified once the access token is revoked. + IdentityInternalsUIMessageHandler* consumer_; // weak. + + DISALLOW_COPY_AND_ASSIGN(IdentityInternalsTokenRevoker); +}; + +IdentityInternalsUIMessageHandler::IdentityInternalsUIMessageHandler() {} + +IdentityInternalsUIMessageHandler::~IdentityInternalsUIMessageHandler() {} + +void IdentityInternalsUIMessageHandler::OnTokenRevokerDone( + IdentityInternalsTokenRevoker* token_revoker) { + // Remove token from the cache. + extensions::IdentityAPI::GetFactoryInstance() + ->Get(Profile::FromWebUI(web_ui())) + ->EraseCachedToken(token_revoker->extension_id(), + token_revoker->access_token()); + + // Update view about the token being removed. + base::ListValue result; + result.AppendString(token_revoker->access_token()); + web_ui()->CallJavascriptFunction("identity_internals.tokenRevokeDone", + result); + + // Erase the revoker. + ScopedVector<IdentityInternalsTokenRevoker>::iterator iter = + std::find(token_revokers_.begin(), token_revokers_.end(), token_revoker); + DCHECK(iter != token_revokers_.end()); + token_revokers_.erase(iter); +} + +const std::string IdentityInternalsUIMessageHandler::GetExtensionName( + const extensions::ExtensionTokenKey& token_cache_key) { + ExtensionService* extension_service = extensions::ExtensionSystem::Get( + Profile::FromWebUI(web_ui()))->extension_service(); + const extensions::Extension* extension = + extension_service->extensions()->GetByID(token_cache_key.extension_id); + if (!extension) + return std::string(); + return extension->name(); +} + +base::ListValue* IdentityInternalsUIMessageHandler::GetScopes( + const extensions::ExtensionTokenKey& token_cache_key) { + base::ListValue* scopes_value = new base::ListValue(); + for (std::set<std::string>::const_iterator + iter = token_cache_key.scopes.begin(); + iter != token_cache_key.scopes.end(); ++iter) { + scopes_value->AppendString(*iter); + } + return scopes_value; +} + +const base::string16 IdentityInternalsUIMessageHandler::GetStatus( + const extensions::IdentityTokenCacheValue& token_cache_value) { + switch (token_cache_value.status()) { + case extensions::IdentityTokenCacheValue::CACHE_STATUS_ADVICE: + // Fallthrough to NOT FOUND case, as ADVICE is short lived. + case extensions::IdentityTokenCacheValue::CACHE_STATUS_NOTFOUND: + return l10n_util::GetStringUTF16( + IDS_IDENTITY_INTERNALS_TOKEN_NOT_FOUND); + case extensions::IdentityTokenCacheValue::CACHE_STATUS_TOKEN: + return l10n_util::GetStringUTF16( + IDS_IDENTITY_INTERNALS_TOKEN_PRESENT); + } + NOTREACHED(); + return base::string16(); +} + +const std::string IdentityInternalsUIMessageHandler::GetExpirationTime( + const extensions::IdentityTokenCacheValue& token_cache_value) { + return base::UTF16ToUTF8(base::TimeFormatFriendlyDateAndTime( + token_cache_value.expiration_time())); +} + +base::DictionaryValue* IdentityInternalsUIMessageHandler::GetInfoForToken( + const extensions::ExtensionTokenKey& token_cache_key, + const extensions::IdentityTokenCacheValue& token_cache_value) { + base::DictionaryValue* token_data = new base::DictionaryValue(); + token_data->SetString(kExtensionId, token_cache_key.extension_id); + token_data->SetString(kExtensionName, GetExtensionName(token_cache_key)); + token_data->Set(kScopes, GetScopes(token_cache_key)); + token_data->SetString(kStatus, GetStatus(token_cache_value)); + token_data->SetString(kAccessToken, token_cache_value.token()); + token_data->SetString(kTokenExpirationTime, + GetExpirationTime(token_cache_value)); + return token_data; +} + +void IdentityInternalsUIMessageHandler::GetInfoForAllTokens( + const base::ListValue* args) { + base::ListValue results; + extensions::IdentityAPI::CachedTokens tokens = + extensions::IdentityAPI::GetFactoryInstance() + ->Get(Profile::FromWebUI(web_ui())) + ->GetAllCachedTokens(); + for (extensions::IdentityAPI::CachedTokens::const_iterator + iter = tokens.begin(); iter != tokens.end(); ++iter) { + results.Append(GetInfoForToken(iter->first, iter->second)); + } + + web_ui()->CallJavascriptFunction("identity_internals.returnTokens", results); +} + +void IdentityInternalsUIMessageHandler::RegisterMessages() { + web_ui()->RegisterMessageCallback("identityInternalsGetTokens", + base::Bind(&IdentityInternalsUIMessageHandler::GetInfoForAllTokens, + base::Unretained(this))); + web_ui()->RegisterMessageCallback("identityInternalsRevokeToken", + base::Bind(&IdentityInternalsUIMessageHandler::RevokeToken, + base::Unretained(this))); +} + +void IdentityInternalsUIMessageHandler::RevokeToken( + const base::ListValue* args) { + std::string extension_id; + std::string access_token; + args->GetString(kRevokeTokenExtensionOffset, &extension_id); + args->GetString(kRevokeTokenTokenOffset, &access_token); + token_revokers_.push_back(new IdentityInternalsTokenRevoker( + extension_id, access_token, Profile::FromWebUI(web_ui()), this)); +} + +IdentityInternalsTokenRevoker::IdentityInternalsTokenRevoker( + const std::string& extension_id, + const std::string& access_token, + Profile* profile, + IdentityInternalsUIMessageHandler* consumer) + : fetcher_(this, GaiaConstants::kChromeSource, + profile->GetRequestContext()), + extension_id_(extension_id), + access_token_(access_token), + consumer_(consumer) { + DCHECK(consumer_); + fetcher_.StartRevokeOAuth2Token(access_token); +} + +IdentityInternalsTokenRevoker::~IdentityInternalsTokenRevoker() {} + +void IdentityInternalsTokenRevoker::OnOAuth2RevokeTokenCompleted() { + consumer_->OnTokenRevokerDone(this); +} + +} // namespace + +IdentityInternalsUI::IdentityInternalsUI(content::WebUI* web_ui) + : content::WebUIController(web_ui) { + // chrome://identity-internals source. + content::WebUIDataSource* html_source = + content::WebUIDataSource::Create(chrome::kChromeUIIdentityInternalsHost); + html_source->SetUseJsonJSFormatV2(); + + // Localized strings + html_source->AddLocalizedString("tokenCacheHeader", + IDS_IDENTITY_INTERNALS_TOKEN_CACHE_TEXT); + html_source->AddLocalizedString("accessToken", + IDS_IDENTITY_INTERNALS_ACCESS_TOKEN); + html_source->AddLocalizedString("extensionName", + IDS_IDENTITY_INTERNALS_EXTENSION_NAME); + html_source->AddLocalizedString("extensionId", + IDS_IDENTITY_INTERNALS_EXTENSION_ID); + html_source->AddLocalizedString("tokenStatus", + IDS_IDENTITY_INTERNALS_TOKEN_STATUS); + html_source->AddLocalizedString("expirationTime", + IDS_IDENTITY_INTERNALS_EXPIRATION_TIME); + html_source->AddLocalizedString("scopes", + IDS_IDENTITY_INTERNALS_SCOPES); + html_source->AddLocalizedString("revoke", + IDS_IDENTITY_INTERNALS_REVOKE); + html_source->SetJsonPath("strings.js"); + + // Required resources + html_source->AddResourcePath("identity_internals.css", + IDR_IDENTITY_INTERNALS_CSS); + html_source->AddResourcePath("identity_internals.js", + IDR_IDENTITY_INTERNALS_JS); + html_source->SetDefaultResource(IDR_IDENTITY_INTERNALS_HTML); + + content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source); + + web_ui->AddMessageHandler(new IdentityInternalsUIMessageHandler()); +} + +IdentityInternalsUI::~IdentityInternalsUI() {} diff --git a/chrome/browser/ui/webui/identity_internals_ui.h b/chrome/browser/ui/webui/identity_internals_ui.h new file mode 100644 index 0000000..929b610 --- /dev/null +++ b/chrome/browser/ui/webui/identity_internals_ui.h @@ -0,0 +1,23 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_WEBUI_IDENTITY_INTERNALS_UI_H_ +#define CHROME_BROWSER_UI_WEBUI_IDENTITY_INTERNALS_UI_H_ + +#include "content/public/browser/web_ui_controller.h" + +class IdentityInternalsUITest; + +// The WebUI for chrome://identity-internals +class IdentityInternalsUI + : public content::WebUIController { + public: + explicit IdentityInternalsUI(content::WebUI* web_ui); + virtual ~IdentityInternalsUI(); + + private: + DISALLOW_COPY_AND_ASSIGN(IdentityInternalsUI); +}; + +#endif // CHROME_BROWSER_UI_WEBUI_IDENTITY_INTERNALS_UI_H_ diff --git a/chrome/browser/ui/webui/identity_internals/identity_internals_ui_browsertest.cc b/chrome/browser/ui/webui/identity_internals_ui_browsertest.cc index 577a1d9..82f47b9 100644 --- a/chrome/browser/ui/webui/identity_internals/identity_internals_ui_browsertest.cc +++ b/chrome/browser/ui/webui/identity_internals_ui_browsertest.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/ui/webui/identity_internals/identity_internals_ui_browsertest.h" +#include "chrome/browser/ui/webui/identity_internals_ui_browsertest.h" #include "base/strings/string_number_conversions.h" #include "base/time/time.h" @@ -15,7 +15,6 @@ namespace { const char kChromeWebStoreId[] = "ahfgeienlihckogmohjhadlkjgocpleb"; const int kOneHour = 3600; - } // namespace IdentityInternalsUIBrowserTest::IdentityInternalsUIBrowserTest() {} diff --git a/chrome/browser/ui/webui/identity_internals/identity_internals_ui_browsertest.h b/chrome/browser/ui/webui/identity_internals_ui_browsertest.h index e093fc0..d2abf18 100644 --- a/chrome/browser/ui/webui/identity_internals/identity_internals_ui_browsertest.h +++ b/chrome/browser/ui/webui/identity_internals_ui_browsertest.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_UI_WEBUI_IDENTITY_INTERNALS_IDENTITY_INTERNALS_UI_BROWSERTEST_H_ -#define CHROME_BROWSER_UI_WEBUI_IDENTITY_INTERNALS_IDENTITY_INTERNALS_UI_BROWSERTEST_H_ +#ifndef CHROME_BROWSER_UI_WEBUI_IDENTITY_INTERNALS_UI_BROWSERTEST_H_ +#define CHROME_BROWSER_UI_WEBUI_IDENTITY_INTERNALS_UI_BROWSERTEST_H_ #include <string> #include <vector> @@ -29,4 +29,4 @@ class IdentityInternalsUIBrowserTest : public WebUIBrowserTest { DISALLOW_COPY_AND_ASSIGN(IdentityInternalsUIBrowserTest); }; -#endif // CHROME_BROWSER_UI_WEBUI_IDENTITY_INTERNALS_IDENTITY_INTERNALS_UI_BROWSERTEST_H_ +#endif // CHROME_BROWSER_UI_WEBUI_IDENTITY_INTERNALS_UI_BROWSERTEST_H_ diff --git a/chrome/browser/ui/webui/identity_internals/identity_internals_ui_browsertest.js b/chrome/browser/ui/webui/identity_internals_ui_browsertest.js index 4fba259..f71a760 100644 --- a/chrome/browser/ui/webui/identity_internals/identity_internals_ui_browsertest.js +++ b/chrome/browser/ui/webui/identity_internals_ui_browsertest.js @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -GEN('#include "chrome/browser/ui/webui/identity_internals/identity_internals_ui_browsertest.h"'); +GEN('#include "chrome/browser/ui/webui/identity_internals_ui_browsertest.h"'); /** * Test C++ fixture for downloads WebUI testing. @@ -24,7 +24,7 @@ BaseIdentityInternalsWebUITest.prototype = { /** * Browse to the downloads page & call our preLoad(). */ - browsePreloadAndWaitForMain: 'chrome://identity-internals', + browsePreload: 'chrome://identity-internals', /** @override */ typedefCppFixture: 'IdentityInternalsUIBrowserTest', @@ -245,8 +245,11 @@ IdentityInternalsWebUITestAsync.prototype = { TEST_F('IdentityInternalsWebUITestAsync', 'revokeToken', function() { var tokenListBefore = this.getTokens(); expectEquals(2, tokenListBefore.length); - window.revokeTokenTest = this.continueTest( + var tokenRevokeDone = identity_internals.tokenRevokeDone; + identity_internals.tokenRevokeDone = this.continueTest( WhenTestDone.ALWAYS, function(accessTokens) { + tokenRevokeDone.call(identity_internals, accessTokens); + identity_internals.tokenRevokeDone = tokenRevokeDone; var tokenListAfter = this.getTokens(); expectEquals(1, tokenListAfter.length); expectEquals(this.getAccessToken(tokenListBefore[0]), @@ -254,3 +257,4 @@ TEST_F('IdentityInternalsWebUITestAsync', 'revokeToken', function() { }.bind(this)); this.getRevokeButton(tokenListBefore[1]).click(); }); + |