1 // Copyright 2013 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/user_manager_ui.h"
7 #include "base/values.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/webui/signin/user_manager_screen_handler.h"
10 #include "chrome/browser/ui/webui/theme_source.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/browser_resources.h"
15 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/base/webui/web_ui_util.h"
19 const char kStringsJSPath
[] = "strings.js";
20 const char kUserManagerJSPath
[] = "user_manager.js";
22 UserManagerUI::UserManagerUI(content::WebUI
* web_ui
)
23 : WebUIController(web_ui
) {
24 // The web_ui object takes ownership of the handler, and will
25 // destroy it when it (the WebUI) is destroyed.
26 user_manager_screen_handler_
= new UserManagerScreenHandler();
27 web_ui
->AddMessageHandler(user_manager_screen_handler_
);
29 base::DictionaryValue localized_strings
;
30 GetLocalizedStrings(&localized_strings
);
32 Profile
* profile
= Profile::FromWebUI(web_ui
);
33 // Set up the chrome://user-chooser/ source.
34 content::WebUIDataSource::Add(profile
, CreateUIDataSource(localized_strings
));
36 #if defined(ENABLE_THEMES)
37 // Set up the chrome://theme/ source
38 ThemeSource
* theme
= new ThemeSource(profile
);
39 content::URLDataSource::Add(profile
, theme
);
43 UserManagerUI::~UserManagerUI() {
46 content::WebUIDataSource
* UserManagerUI::CreateUIDataSource(
47 const base::DictionaryValue
& localized_strings
) {
48 content::WebUIDataSource
* source
=
49 content::WebUIDataSource::Create(chrome::kChromeUIUserManagerHost
);
50 source
->SetUseJsonJSFormatV2();
51 source
->AddLocalizedStrings(localized_strings
);
52 source
->SetJsonPath(kStringsJSPath
);
54 source
->SetDefaultResource(IDR_USER_MANAGER_HTML
);
55 source
->AddResourcePath(kUserManagerJSPath
, IDR_USER_MANAGER_JS
);
60 void UserManagerUI::GetLocalizedStrings(
61 base::DictionaryValue
* localized_strings
) {
62 user_manager_screen_handler_
->GetLocalizedValues(localized_strings
);
63 webui::SetFontAndTextDirection(localized_strings
);
65 #if defined(GOOGLE_CHROME_BUILD)
66 localized_strings
->SetString("buildType", "chrome");
68 localized_strings
->SetString("buildType", "chromium");