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"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/signin/about_signin_internals.h"
10 #include "chrome/browser/signin/about_signin_internals_factory.h"
11 #include "chrome/common/url_constants.h"
12 #include "content/public/browser/web_ui.h"
13 #include "content/public/browser/web_ui_data_source.h"
14 #include "grit/signin_internals_resources.h"
15 #include "ui/base/resource/resource_bundle.h"
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",
25 IDR_SIGNIN_INTERNALS_INDEX_JS
);
26 source
->SetDefaultResource(IDR_SIGNIN_INTERNALS_INDEX_HTML
);
32 SignInInternalsUI::SignInInternalsUI(content::WebUI
* web_ui
)
33 : WebUIController(web_ui
) {
34 Profile
* profile
= Profile::FromWebUI(web_ui
);
35 content::WebUIDataSource::Add(profile
, CreateSignInInternalsHTMLSource());
37 AboutSigninInternals
* about_signin_internals
=
38 AboutSigninInternalsFactory::GetForProfile(profile
);
39 if (about_signin_internals
)
40 about_signin_internals
->AddSigninObserver(this);
44 SignInInternalsUI::~SignInInternalsUI() {
45 Profile
* profile
= Profile::FromWebUI(web_ui());
47 AboutSigninInternals
* about_signin_internals
=
48 AboutSigninInternalsFactory::GetForProfile(profile
);
49 if (about_signin_internals
) {
50 about_signin_internals
->RemoveSigninObserver(this);
55 bool SignInInternalsUI::OverrideHandleWebUIMessage(
56 const GURL
& source_url
,
57 const std::string
& name
,
58 const base::ListValue
& content
) {
59 if (name
== "getSigninInfo") {
60 Profile
* profile
= Profile::FromWebUI(web_ui());
64 AboutSigninInternals
* about_signin_internals
=
65 AboutSigninInternalsFactory::GetForProfile(profile
);
66 // TODO(vishwath): The UI would look better if we passed in a dict with some
67 // reasonable defaults, so the about:signin-internals page doesn't look
68 // empty in incognito mode. Alternatively, we could force about:signin to
69 // open in non-incognito mode always (like about:settings for ex.).
70 if (about_signin_internals
) {
71 const std::string
& reply_handler
=
72 "chrome.signin.getSigninInfo.handleReply";
73 web_ui()->CallJavascriptFunction(
74 reply_handler
, *about_signin_internals
->GetSigninStatus());
82 void SignInInternalsUI::OnSigninStateChanged(
83 scoped_ptr
<base::DictionaryValue
> info
) {
84 const std::string
& event_handler
= "chrome.signin.onSigninInfoChanged.fire";
85 web_ui()->CallJavascriptFunction(event_handler
, *info
);