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/browser_process.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/webui/signin/user_manager_screen_handler.h"
11 #include "chrome/browser/ui/webui/theme_source.h"
12 #include "chrome/common/url_constants.h"
13 #include "content/public/browser/web_ui.h"
14 #include "content/public/browser/web_ui_data_source.h"
15 #include "grit/browser_resources.h"
16 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/base/webui/web_ui_util.h"
20 const char kStringsJSPath
[] = "strings.js";
21 const char kUserManagerJSPath
[] = "user_manager.js";
23 UserManagerUI::UserManagerUI(content::WebUI
* web_ui
)
24 : WebUIController(web_ui
) {
25 // The web_ui object takes ownership of the handler, and will
26 // destroy it when it (the WebUI) is destroyed.
27 user_manager_screen_handler_
= new UserManagerScreenHandler();
28 web_ui
->AddMessageHandler(user_manager_screen_handler_
);
30 base::DictionaryValue localized_strings
;
31 GetLocalizedStrings(&localized_strings
);
33 Profile
* profile
= Profile::FromWebUI(web_ui
);
34 // Set up the chrome://user-chooser/ source.
35 content::WebUIDataSource::Add(profile
, CreateUIDataSource(localized_strings
));
37 #if defined(ENABLE_THEMES)
38 // Set up the chrome://theme/ source
39 ThemeSource
* theme
= new ThemeSource(profile
);
40 content::URLDataSource::Add(profile
, theme
);
44 UserManagerUI::~UserManagerUI() {
47 content::WebUIDataSource
* UserManagerUI::CreateUIDataSource(
48 const base::DictionaryValue
& localized_strings
) {
49 content::WebUIDataSource
* source
=
50 content::WebUIDataSource::Create(chrome::kChromeUIUserManagerHost
);
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 const std::string
& app_locale
= g_browser_process
->GetApplicationLocale();
64 webui::SetLoadTimeDataDefaults(app_locale
, localized_strings
);
66 #if defined(GOOGLE_CHROME_BUILD)
67 localized_strings
->SetString("buildType", "chrome");
69 localized_strings
->SetString("buildType", "chromium");