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.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" 16 17 namespace { 18 19 content::WebUIDataSource* CreateSignInInternalsHTMLSource() { 20 content::WebUIDataSource* source = 21 content::WebUIDataSource::Create(chrome::kChromeUISignInInternalsHost); 22 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); 27 return source; 28 } 29 30 } // namespace 31 32 SignInInternalsUI::SignInInternalsUI(content::WebUI* web_ui) 33 : WebUIController(web_ui) { 34 Profile* profile = Profile::FromWebUI(web_ui); 35 content::WebUIDataSource::Add(profile, CreateSignInInternalsHTMLSource()); 36 if (profile) { 37 AboutSigninInternals* about_signin_internals = 38 AboutSigninInternalsFactory::GetForProfile(profile); 39 if (about_signin_internals) 40 about_signin_internals->AddSigninObserver(this); 41 } 42 } 43 44 SignInInternalsUI::~SignInInternalsUI() { 45 Profile* profile = Profile::FromWebUI(web_ui()); 46 if (profile) { 47 AboutSigninInternals* about_signin_internals = 48 AboutSigninInternalsFactory::GetForProfile(profile); 49 if (about_signin_internals) { 50 about_signin_internals->RemoveSigninObserver(this); 51 } 52 } 53 } 54 55 bool SignInInternalsUI::OverrideHandleWebUIMessage(const GURL& source_url, 56 const std::string& name, 57 const ListValue& content) { 58 if (name == "getSigninInfo") { 59 Profile* profile = Profile::FromWebUI(web_ui()); 60 if (!profile) 61 return false; 62 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 const std::string& reply_handler = 71 "chrome.signin.getSigninInfo.handleReply"; 72 web_ui()->CallJavascriptFunction( 73 reply_handler, *about_signin_internals->GetSigninStatus()); 74 75 return true; 76 } 77 } 78 return false; 79 } 80 81 void SignInInternalsUI::OnSigninStateChanged(scoped_ptr<DictionaryValue> info) { 82 const std::string& event_handler = "chrome.signin.onSigninInfoChanged.fire"; 83 web_ui()->CallJavascriptFunction(event_handler, *info); 84 } 85