This source file includes following definitions.
- CreateSignInInternalsHTMLSource
- OverrideHandleWebUIMessage
- OnSigninStateChanged
#include "chrome/browser/ui/webui/signin_internals_ui.h"
#include "base/hash.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/about_signin_internals_factory.h"
#include "chrome/common/url_constants.h"
#include "components/signin/core/browser/about_signin_internals.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h"
#include "grit/signin_internals_resources.h"
#include "ui/base/resource/resource_bundle.h"
namespace {
content::WebUIDataSource* CreateSignInInternalsHTMLSource() {
content::WebUIDataSource* source =
content::WebUIDataSource::Create(chrome::kChromeUISignInInternalsHost);
source->SetJsonPath("strings.js");
source->AddResourcePath("signin_internals.js",
IDR_SIGNIN_INTERNALS_INDEX_JS);
source->SetDefaultResource(IDR_SIGNIN_INTERNALS_INDEX_HTML);
return source;
}
}
SignInInternalsUI::SignInInternalsUI(content::WebUI* web_ui)
: WebUIController(web_ui) {
Profile* profile = Profile::FromWebUI(web_ui);
content::WebUIDataSource::Add(profile, CreateSignInInternalsHTMLSource());
if (profile) {
AboutSigninInternals* about_signin_internals =
AboutSigninInternalsFactory::GetForProfile(profile);
if (about_signin_internals)
about_signin_internals->AddSigninObserver(this);
}
}
SignInInternalsUI::~SignInInternalsUI() {
Profile* profile = Profile::FromWebUI(web_ui());
if (profile) {
AboutSigninInternals* about_signin_internals =
AboutSigninInternalsFactory::GetForProfile(profile);
if (about_signin_internals) {
about_signin_internals->RemoveSigninObserver(this);
}
}
}
bool SignInInternalsUI::OverrideHandleWebUIMessage(
const GURL& source_url,
const std::string& name,
const base::ListValue& content) {
if (name == "getSigninInfo") {
Profile* profile = Profile::FromWebUI(web_ui());
if (!profile)
return false;
AboutSigninInternals* about_signin_internals =
AboutSigninInternalsFactory::GetForProfile(profile);
if (about_signin_internals) {
const std::string& reply_handler =
"chrome.signin.getSigninInfo.handleReply";
web_ui()->CallJavascriptFunction(
reply_handler, *about_signin_internals->GetSigninStatus());
return true;
}
}
return false;
}
void SignInInternalsUI::OnSigninStateChanged(
scoped_ptr<base::DictionaryValue> info) {
const std::string& event_handler = "chrome.signin.onSigninInfoChanged.fire";
web_ui()->CallJavascriptFunction(event_handler, *info);
}