Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / webui / signin_internals_ui.cc
bloba14e6c610e72a2abe6f90a05d591a936dc7cb4ce
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/webui/signin_internals_ui.h"
7 #include "base/hash.h"
8 #include "base/profiler/scoped_tracker.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/signin/about_signin_internals_factory.h"
11 #include "chrome/browser/signin/gaia_cookie_manager_service_factory.h"
12 #include "chrome/common/url_constants.h"
13 #include "components/signin/core/browser/about_signin_internals.h"
14 #include "components/signin/core/browser/gaia_cookie_manager_service.h"
15 #include "content/public/browser/web_ui.h"
16 #include "content/public/browser/web_ui_data_source.h"
17 #include "grit/signin_internals_resources.h"
19 namespace {
21 content::WebUIDataSource* CreateSignInInternalsHTMLSource() {
22 content::WebUIDataSource* source =
23 content::WebUIDataSource::Create(chrome::kChromeUISignInInternalsHost);
25 source->SetJsonPath("strings.js");
26 source->AddResourcePath("signin_internals.js", IDR_SIGNIN_INTERNALS_INDEX_JS);
27 source->SetDefaultResource(IDR_SIGNIN_INTERNALS_INDEX_HTML);
28 return source;
31 } // namespace
33 SignInInternalsUI::SignInInternalsUI(content::WebUI* web_ui)
34 : WebUIController(web_ui) {
35 Profile* profile = Profile::FromWebUI(web_ui);
36 content::WebUIDataSource::Add(profile, CreateSignInInternalsHTMLSource());
37 if (profile) {
38 AboutSigninInternals* about_signin_internals =
39 AboutSigninInternalsFactory::GetForProfile(profile);
40 if (about_signin_internals)
41 about_signin_internals->AddSigninObserver(this);
45 SignInInternalsUI::~SignInInternalsUI() {
46 Profile* profile = Profile::FromWebUI(web_ui());
47 if (profile) {
48 AboutSigninInternals* about_signin_internals =
49 AboutSigninInternalsFactory::GetForProfile(profile);
50 if (about_signin_internals) {
51 about_signin_internals->RemoveSigninObserver(this);
56 bool SignInInternalsUI::OverrideHandleWebUIMessage(
57 const GURL& source_url,
58 const std::string& name,
59 const base::ListValue& content) {
60 if (name == "getSigninInfo") {
61 Profile* profile = Profile::FromWebUI(web_ui());
62 if (!profile)
63 return false;
65 AboutSigninInternals* about_signin_internals =
66 AboutSigninInternalsFactory::GetForProfile(profile);
67 // TODO(vishwath): The UI would look better if we passed in a dict with some
68 // reasonable defaults, so the about:signin-internals page doesn't look
69 // empty in incognito mode. Alternatively, we could force about:signin to
70 // open in non-incognito mode always (like about:settings for ex.).
71 if (about_signin_internals) {
72 web_ui()->CallJavascriptFunction(
73 "chrome.signin.getSigninInfo.handleReply",
74 *about_signin_internals->GetSigninStatus());
76 std::vector<gaia::ListedAccount> cookie_accounts;
77 GaiaCookieManagerService* cookie_manager_service =
78 GaiaCookieManagerServiceFactory::GetForProfile(profile);
79 if (cookie_manager_service->ListAccounts(&cookie_accounts)) {
80 about_signin_internals->OnGaiaAccountsInCookieUpdated(
81 cookie_accounts,
82 GoogleServiceAuthError(GoogleServiceAuthError::NONE));
85 return true;
88 return false;
91 void SignInInternalsUI::OnSigninStateChanged(
92 const base::DictionaryValue* info) {
93 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is
94 // fixed.
95 tracked_objects::ScopedTracker tracking_profile(
96 FROM_HERE_WITH_EXPLICIT_FUNCTION(
97 "422460 SignInInternalsUI::OnSigninStateChanged"));
99 web_ui()->CallJavascriptFunction(
100 "chrome.signin.onSigninInfoChanged.fire", *info);
103 void SignInInternalsUI::OnCookieAccountsFetched(
104 const base::DictionaryValue* info) {
105 web_ui()->CallJavascriptFunction(
106 "chrome.signin.onCookieAccountsFetched.fire", *info);