OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/webui/signin/user_manager_ui.h" | 5 #include "chrome/browser/ui/webui/signin/md_user_manager_ui.h" |
6 | |
7 #include <string> | |
6 | 8 |
7 #include "base/values.h" | 9 #include "base/values.h" |
8 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/ui/webui/signin/signin_create_profile_handler.h" | |
10 #include "chrome/browser/ui/webui/signin/user_manager_screen_handler.h" | 13 #include "chrome/browser/ui/webui/signin/user_manager_screen_handler.h" |
11 #include "chrome/browser/ui/webui/theme_source.h" | 14 #include "chrome/browser/ui/webui/theme_source.h" |
12 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
13 #include "content/public/browser/web_ui.h" | 16 #include "content/public/browser/web_ui.h" |
14 #include "content/public/browser/web_ui_data_source.h" | 17 #include "content/public/browser/web_ui_data_source.h" |
15 #include "grit/browser_resources.h" | 18 #include "grit/browser_resources.h" |
19 #include "grit/settings_resources.h" | |
16 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
17 #include "ui/base/webui/web_ui_util.h" | 21 #include "ui/base/webui/web_ui_util.h" |
18 | 22 |
19 // JS file names. | 23 MDUserManagerUI::MDUserManagerUI(content::WebUI* web_ui) |
20 const char kStringsJSPath[] = "strings.js"; | 24 : WebUIController(web_ui) { |
21 const char kUserManagerJSPath[] = "user_manager.js"; | |
22 | |
23 UserManagerUI::UserManagerUI(content::WebUI* web_ui) | |
24 : WebUIController(web_ui) { | |
25 // The web_ui object takes ownership of the handler, and will | 25 // The web_ui object takes ownership of the handler, and will |
Dan Beam
2016/02/25 01:04:40
these handlers
Moe
2016/02/25 16:03:02
Done.
| |
26 // destroy it when it (the WebUI) is destroyed. | 26 // destroy it when it (the WebUI) is destroyed. |
Dan Beam
2016/02/25 01:04:40
destroy them
Moe
2016/02/25 16:03:02
Done.
| |
27 user_manager_screen_handler_ = new UserManagerScreenHandler(); | 27 user_manager_screen_handler_ = new UserManagerScreenHandler(); |
28 signin_create_profile_handler_ = new SigninCreateProfileHandler(); | |
Dan Beam
2016/02/25 01:04:40
nit: put these in initializer list
Moe
2016/02/25 16:03:02
Done.
| |
28 web_ui->AddMessageHandler(user_manager_screen_handler_); | 29 web_ui->AddMessageHandler(user_manager_screen_handler_); |
30 web_ui->AddMessageHandler(signin_create_profile_handler_); | |
29 | 31 |
30 base::DictionaryValue localized_strings; | 32 base::DictionaryValue localized_strings; |
31 GetLocalizedStrings(&localized_strings); | 33 GetLocalizedStrings(&localized_strings); |
32 | 34 |
33 Profile* profile = Profile::FromWebUI(web_ui); | 35 Profile* profile = Profile::FromWebUI(web_ui); |
34 // Set up the chrome://user-chooser/ source. | 36 // Set up the chrome://user-chooser/ source. |
35 content::WebUIDataSource::Add(profile, CreateUIDataSource(localized_strings)); | 37 content::WebUIDataSource::Add(profile, CreateUIDataSource(localized_strings)); |
36 | 38 |
37 #if defined(ENABLE_THEMES) | 39 #if defined(ENABLE_THEMES) |
38 // Set up the chrome://theme/ source | 40 // Set up the chrome://theme/ source |
39 ThemeSource* theme = new ThemeSource(profile); | 41 ThemeSource* theme = new ThemeSource(profile); |
40 content::URLDataSource::Add(profile, theme); | 42 content::URLDataSource::Add(profile, theme); |
41 #endif | 43 #endif |
42 } | 44 } |
43 | 45 |
44 UserManagerUI::~UserManagerUI() { | 46 MDUserManagerUI::~MDUserManagerUI() {} |
45 } | |
46 | 47 |
47 content::WebUIDataSource* UserManagerUI::CreateUIDataSource( | 48 content::WebUIDataSource* MDUserManagerUI::CreateUIDataSource( |
48 const base::DictionaryValue& localized_strings) { | 49 const base::DictionaryValue& localized_strings) { |
49 content::WebUIDataSource* source = | 50 content::WebUIDataSource* source = |
50 content::WebUIDataSource::Create(chrome::kChromeUIUserManagerHost); | 51 content::WebUIDataSource::Create(chrome::kChromeUIMDUserManagerHost); |
51 source->AddLocalizedStrings(localized_strings); | 52 source->AddLocalizedStrings(localized_strings); |
52 source->SetJsonPath(kStringsJSPath); | 53 source->SetJsonPath("strings.js"); |
53 | 54 |
54 source->SetDefaultResource(IDR_USER_MANAGER_HTML); | 55 // TODO (mahmadi): Add resource paths. |
55 source->AddResourcePath(kUserManagerJSPath, IDR_USER_MANAGER_JS); | |
56 | 56 |
57 return source; | 57 return source; |
58 } | 58 } |
59 | 59 |
60 void UserManagerUI::GetLocalizedStrings( | 60 void MDUserManagerUI::GetLocalizedStrings( |
61 base::DictionaryValue* localized_strings) { | 61 base::DictionaryValue* localized_strings) { |
62 user_manager_screen_handler_->GetLocalizedValues(localized_strings); | 62 user_manager_screen_handler_->GetLocalizedValues(localized_strings); |
63 signin_create_profile_handler_->GetLocalizedValues(localized_strings); | |
63 const std::string& app_locale = g_browser_process->GetApplicationLocale(); | 64 const std::string& app_locale = g_browser_process->GetApplicationLocale(); |
64 webui::SetLoadTimeDataDefaults(app_locale, localized_strings); | 65 webui::SetLoadTimeDataDefaults(app_locale, localized_strings); |
65 | 66 |
66 #if defined(GOOGLE_CHROME_BUILD) | 67 #if defined(GOOGLE_CHROME_BUILD) |
67 localized_strings->SetString("buildType", "chrome"); | 68 localized_strings->SetString("buildType", "chrome"); |
68 #else | 69 #else |
69 localized_strings->SetString("buildType", "chromium"); | 70 localized_strings->SetString("buildType", "chromium"); |
70 #endif | 71 #endif |
71 } | 72 } |
72 | |
OLD | NEW |