Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / webui / signin_internals_ui.cc
blobf01cac7e7feed87fdc90e8189708217160d4f96f
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/common/url_constants.h"
12 #include "components/signin/core/browser/about_signin_internals.h"
13 #include "content/public/browser/web_ui.h"
14 #include "content/public/browser/web_ui_data_source.h"
15 #include "grit/signin_internals_resources.h"
17 namespace {
19 content::WebUIDataSource* CreateSignInInternalsHTMLSource() {
20 content::WebUIDataSource* source =
21 content::WebUIDataSource::Create(chrome::kChromeUISignInInternalsHost);
23 source->SetJsonPath("strings.js");
24 source->AddResourcePath("signin_internals.js", IDR_SIGNIN_INTERNALS_INDEX_JS);
25 source->SetDefaultResource(IDR_SIGNIN_INTERNALS_INDEX_HTML);
26 return source;
29 } // namespace
31 SignInInternalsUI::SignInInternalsUI(content::WebUI* web_ui)
32 : WebUIController(web_ui) {
33 Profile* profile = Profile::FromWebUI(web_ui);
34 content::WebUIDataSource::Add(profile, CreateSignInInternalsHTMLSource());
35 if (profile) {
36 AboutSigninInternals* about_signin_internals =
37 AboutSigninInternalsFactory::GetForProfile(profile);
38 if (about_signin_internals)
39 about_signin_internals->AddSigninObserver(this);
43 SignInInternalsUI::~SignInInternalsUI() {
44 Profile* profile = Profile::FromWebUI(web_ui());
45 if (profile) {
46 AboutSigninInternals* about_signin_internals =
47 AboutSigninInternalsFactory::GetForProfile(profile);
48 if (about_signin_internals) {
49 about_signin_internals->RemoveSigninObserver(this);
54 bool SignInInternalsUI::OverrideHandleWebUIMessage(
55 const GURL& source_url,
56 const std::string& name,
57 const base::ListValue& content) {
58 if (name == "getSigninInfo") {
59 Profile* profile = Profile::FromWebUI(web_ui());
60 if (!profile)
61 return false;
63 AboutSigninInternals* about_signin_internals =
64 AboutSigninInternalsFactory::GetForProfile(profile);
65 // TODO(vishwath): The UI would look better if we passed in a dict with some
66 // reasonable defaults, so the about:signin-internals page doesn't look
67 // empty in incognito mode. Alternatively, we could force about:signin to
68 // open in non-incognito mode always (like about:settings for ex.).
69 if (about_signin_internals) {
70 web_ui()->CallJavascriptFunction(
71 "chrome.signin.getSigninInfo.handleReply",
72 *about_signin_internals->GetSigninStatus());
73 about_signin_internals->GetCookieAccountsAsync();
75 return true;
78 return false;
81 void SignInInternalsUI::OnSigninStateChanged(
82 const base::DictionaryValue* info) {
83 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is
84 // fixed.
85 tracked_objects::ScopedTracker tracking_profile(
86 FROM_HERE_WITH_EXPLICIT_FUNCTION(
87 "422460 SignInInternalsUI::OnSigninStateChanged"));
89 web_ui()->CallJavascriptFunction(
90 "chrome.signin.onSigninInfoChanged.fire", *info);
93 void SignInInternalsUI::OnCookieAccountsFetched(
94 const base::DictionaryValue* info) {
95 web_ui()->CallJavascriptFunction(
96 "chrome.signin.onCookieAccountsFetched.fire", *info);