Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / signin_internals_ui.cc
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.
4
5 #include "chrome/browser/ui/webui/signin_internals_ui.h"
6
7 #include "base/hash.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/signin/about_signin_internals_factory.h"
10 #include "chrome/common/url_constants.h"
11 #include "components/signin/core/browser/about_signin_internals.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
16 namespace {
17
18 content::WebUIDataSource* CreateSignInInternalsHTMLSource() {
19   content::WebUIDataSource* source =
20       content::WebUIDataSource::Create(chrome::kChromeUISignInInternalsHost);
21
22   source->SetJsonPath("strings.js");
23   source->AddResourcePath("signin_internals.js", IDR_SIGNIN_INTERNALS_INDEX_JS);
24   source->SetDefaultResource(IDR_SIGNIN_INTERNALS_INDEX_HTML);
25   return source;
26 }
27
28 } //  namespace
29
30 SignInInternalsUI::SignInInternalsUI(content::WebUI* web_ui)
31     : WebUIController(web_ui) {
32   Profile* profile = Profile::FromWebUI(web_ui);
33   content::WebUIDataSource::Add(profile, CreateSignInInternalsHTMLSource());
34   if (profile) {
35     AboutSigninInternals* about_signin_internals =
36         AboutSigninInternalsFactory::GetForProfile(profile);
37     if (about_signin_internals)
38       about_signin_internals->AddSigninObserver(this);
39   }
40 }
41
42 SignInInternalsUI::~SignInInternalsUI() {
43   Profile* profile = Profile::FromWebUI(web_ui());
44   if (profile) {
45     AboutSigninInternals* about_signin_internals =
46         AboutSigninInternalsFactory::GetForProfile(profile);
47     if (about_signin_internals) {
48       about_signin_internals->RemoveSigninObserver(this);
49     }
50   }
51 }
52
53 bool SignInInternalsUI::OverrideHandleWebUIMessage(
54     const GURL& source_url,
55     const std::string& name,
56     const base::ListValue& content) {
57   if (name == "getSigninInfo") {
58     Profile* profile = Profile::FromWebUI(web_ui());
59     if (!profile)
60       return false;
61
62     AboutSigninInternals* about_signin_internals =
63         AboutSigninInternalsFactory::GetForProfile(profile);
64     // TODO(vishwath): The UI would look better if we passed in a dict with some
65     // reasonable defaults, so the about:signin-internals page doesn't look
66     // empty in incognito mode. Alternatively, we could force about:signin to
67     // open in non-incognito mode always (like about:settings for ex.).
68     if (about_signin_internals) {
69       web_ui()->CallJavascriptFunction(
70           "chrome.signin.getSigninInfo.handleReply",
71           *about_signin_internals->GetSigninStatus());
72       about_signin_internals->GetCookieAccountsAsync();
73
74       return true;
75     }
76   }
77   return false;
78 }
79
80 void SignInInternalsUI::OnSigninStateChanged(
81     const base::DictionaryValue* info) {
82   web_ui()->CallJavascriptFunction(
83       "chrome.signin.onSigninInfoChanged.fire", *info);
84 }
85
86 void SignInInternalsUI::OnCookieAccountsFetched(
87     const base::DictionaryValue* info) {
88   web_ui()->CallJavascriptFunction(
89       "chrome.signin.onCookieAccountsFetched.fire", *info);
90 }