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. 4 5 #include "chrome/browser/ui/webui/signin/user_manager_ui.h" 6 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" 17 18 // JS file names. 19 const char kStringsJSPath[] = "strings.js"; 20 const char kUserManagerJSPath[] = "user_manager.js"; 21 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_); 28 29 base::DictionaryValue localized_strings; 30 GetLocalizedStrings(&localized_strings); 31 32 Profile* profile = Profile::FromWebUI(web_ui); 33 // Set up the chrome://user-chooser/ source. 34 content::WebUIDataSource::Add(profile, CreateUIDataSource(localized_strings)); 35 36 #if defined(ENABLE_THEMES) 37 // Set up the chrome://theme/ source 38 ThemeSource* theme = new ThemeSource(profile); 39 content::URLDataSource::Add(profile, theme); 40 #endif 41 } 42 43 UserManagerUI::~UserManagerUI() { 44 } 45 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); 53 54 source->SetDefaultResource(IDR_USER_MANAGER_HTML); 55 source->AddResourcePath(kUserManagerJSPath, IDR_USER_MANAGER_JS); 56 57 return source; 58 } 59 60 void UserManagerUI::GetLocalizedStrings( 61 base::DictionaryValue* localized_strings) { 62 user_manager_screen_handler_->GetLocalizedValues(localized_strings); 63 webui::SetFontAndTextDirection(localized_strings); 64 65 #if defined(GOOGLE_CHROME_BUILD) 66 localized_strings->SetString("buildType", "chrome"); 67 #else 68 localized_strings->SetString("buildType", "chromium"); 69 #endif 70 } 71 72