| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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/options2/personal_options_handler2.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/basictypes.h" | |
| 10 #include "base/bind.h" | |
| 11 #include "base/path_service.h" | |
| 12 #include "base/stl_util.h" | |
| 13 #include "base/string_number_conversions.h" | |
| 14 #include "base/utf_string_conversions.h" | |
| 15 #include "base/values.h" | |
| 16 #include "build/build_config.h" | |
| 17 #include "chrome/browser/browser_process.h" | |
| 18 #include "chrome/browser/profiles/profile.h" | |
| 19 #include "chrome/browser/profiles/profile_manager.h" | |
| 20 #include "chrome/browser/themes/theme_service.h" | |
| 21 #include "chrome/browser/themes/theme_service_factory.h" | |
| 22 #include "chrome/common/chrome_notification_types.h" | |
| 23 #include "chrome/common/chrome_paths.h" | |
| 24 #include "chrome/common/net/gaia/google_service_auth_error.h" | |
| 25 #include "chrome/common/url_constants.h" | |
| 26 #include "content/public/browser/navigation_controller.h" | |
| 27 #include "content/public/browser/notification_service.h" | |
| 28 #include "content/public/browser/user_metrics.h" | |
| 29 #include "grit/chromium_strings.h" | |
| 30 #include "grit/generated_resources.h" | |
| 31 #include "grit/locale_settings.h" | |
| 32 #include "grit/theme_resources.h" | |
| 33 #include "ui/base/l10n/l10n_util.h" | |
| 34 | |
| 35 #if defined(OS_CHROMEOS) | |
| 36 #include "chrome/browser/chromeos/login/user_manager.h" | |
| 37 #include "chrome/browser/chromeos/options/take_photo_dialog.h" | |
| 38 #include "chrome/browser/ui/browser_window.h" | |
| 39 #include "chrome/browser/ui/views/window.h" | |
| 40 #include "third_party/skia/include/core/SkBitmap.h" | |
| 41 #endif // defined(OS_CHROMEOS) | |
| 42 #if defined(TOOLKIT_GTK) | |
| 43 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | |
| 44 #endif // defined(TOOLKIT_GTK) | |
| 45 | |
| 46 using content::UserMetricsAction; | |
| 47 | |
| 48 namespace options2 { | |
| 49 | |
| 50 PersonalOptionsHandler::PersonalOptionsHandler() { | |
| 51 #if defined(OS_CHROMEOS) | |
| 52 registrar_.Add(this, | |
| 53 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, | |
| 54 content::NotificationService::AllSources()); | |
| 55 #endif | |
| 56 } | |
| 57 | |
| 58 PersonalOptionsHandler::~PersonalOptionsHandler() { | |
| 59 } | |
| 60 | |
| 61 void PersonalOptionsHandler::GetLocalizedValues( | |
| 62 DictionaryValue* localized_strings) { | |
| 63 DCHECK(localized_strings); | |
| 64 | |
| 65 RegisterTitle(localized_strings, "personalPage", | |
| 66 IDS_OPTIONS_CONTENT_TAB_LABEL); | |
| 67 | |
| 68 localized_strings->SetString("autologinEnabled", | |
| 69 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_AUTOLOGIN)); | |
| 70 | |
| 71 localized_strings->SetString("browsingData", | |
| 72 l10n_util::GetStringUTF16(IDS_OPTIONS_BROWSING_DATA_GROUP_NAME)); | |
| 73 localized_strings->SetString("importData", | |
| 74 l10n_util::GetStringUTF16(IDS_OPTIONS_IMPORT_DATA_BUTTON)); | |
| 75 | |
| 76 localized_strings->SetString("themesGallery", | |
| 77 l10n_util::GetStringUTF16(IDS_THEMES_GALLERY_BUTTON)); | |
| 78 localized_strings->SetString("themesGalleryURL", | |
| 79 l10n_util::GetStringUTF16(IDS_THEMES_GALLERY_URL)); | |
| 80 | |
| 81 #if defined(TOOLKIT_GTK) | |
| 82 localized_strings->SetString("appearance", | |
| 83 l10n_util::GetStringUTF16(IDS_APPEARANCE_GROUP_NAME)); | |
| 84 localized_strings->SetString("themesGTKButton", | |
| 85 l10n_util::GetStringUTF16(IDS_THEMES_GTK_BUTTON)); | |
| 86 localized_strings->SetString("themesSetClassic", | |
| 87 l10n_util::GetStringUTF16(IDS_THEMES_SET_CLASSIC)); | |
| 88 localized_strings->SetString("showWindowDecorations", | |
| 89 l10n_util::GetStringUTF16(IDS_SHOW_WINDOW_DECORATIONS_RADIO)); | |
| 90 localized_strings->SetString("hideWindowDecorations", | |
| 91 l10n_util::GetStringUTF16(IDS_HIDE_WINDOW_DECORATIONS_RADIO)); | |
| 92 #else | |
| 93 localized_strings->SetString("themes", | |
| 94 l10n_util::GetStringUTF16(IDS_THEMES_GROUP_NAME)); | |
| 95 localized_strings->SetString("themesReset", | |
| 96 l10n_util::GetStringUTF16(IDS_THEMES_RESET_BUTTON)); | |
| 97 #endif | |
| 98 | |
| 99 // Sync select control. | |
| 100 ListValue* sync_select_list = new ListValue; | |
| 101 ListValue* datatypes = new ListValue; | |
| 102 datatypes->Append(Value::CreateBooleanValue(false)); | |
| 103 datatypes->Append( | |
| 104 Value::CreateStringValue( | |
| 105 l10n_util::GetStringUTF8(IDS_SYNC_OPTIONS_SELECT_DATATYPES))); | |
| 106 sync_select_list->Append(datatypes); | |
| 107 ListValue* everything = new ListValue; | |
| 108 everything->Append(Value::CreateBooleanValue(true)); | |
| 109 everything->Append( | |
| 110 Value::CreateStringValue( | |
| 111 l10n_util::GetStringUTF8(IDS_SYNC_OPTIONS_SELECT_EVERYTHING))); | |
| 112 sync_select_list->Append(everything); | |
| 113 localized_strings->Set("syncSelectList", sync_select_list); | |
| 114 | |
| 115 // Sync page. | |
| 116 localized_strings->SetString("syncPage", | |
| 117 l10n_util::GetStringUTF16(IDS_SYNC_NTP_SYNC_SECTION_TITLE)); | |
| 118 localized_strings->SetString("sync_title", | |
| 119 l10n_util::GetStringUTF16(IDS_CUSTOMIZE_SYNC_DESCRIPTION)); | |
| 120 localized_strings->SetString("syncsettings", | |
| 121 l10n_util::GetStringUTF16(IDS_SYNC_DATATYPE_PREFERENCES)); | |
| 122 localized_strings->SetString("syncbookmarks", | |
| 123 l10n_util::GetStringUTF16(IDS_SYNC_DATATYPE_BOOKMARKS)); | |
| 124 localized_strings->SetString("synctypedurls", | |
| 125 l10n_util::GetStringUTF16(IDS_SYNC_DATATYPE_TYPED_URLS)); | |
| 126 localized_strings->SetString("syncpasswords", | |
| 127 l10n_util::GetStringUTF16(IDS_SYNC_DATATYPE_PASSWORDS)); | |
| 128 localized_strings->SetString("syncextensions", | |
| 129 l10n_util::GetStringUTF16(IDS_SYNC_DATATYPE_EXTENSIONS)); | |
| 130 localized_strings->SetString("syncautofill", | |
| 131 l10n_util::GetStringUTF16(IDS_SYNC_DATATYPE_AUTOFILL)); | |
| 132 localized_strings->SetString("syncthemes", | |
| 133 l10n_util::GetStringUTF16(IDS_SYNC_DATATYPE_THEMES)); | |
| 134 localized_strings->SetString("syncapps", | |
| 135 l10n_util::GetStringUTF16(IDS_SYNC_DATATYPE_APPS)); | |
| 136 localized_strings->SetString("syncsessions", | |
| 137 l10n_util::GetStringUTF16(IDS_SYNC_DATATYPE_TABS)); | |
| 138 | |
| 139 #if defined(OS_CHROMEOS) | |
| 140 localized_strings->SetString("account", | |
| 141 l10n_util::GetStringUTF16(IDS_OPTIONS_PERSONAL_ACCOUNT_GROUP_NAME)); | |
| 142 localized_strings->SetString("enableScreenlock", | |
| 143 l10n_util::GetStringUTF16(IDS_OPTIONS_ENABLE_SCREENLOCKER_CHECKBOX)); | |
| 144 localized_strings->SetString("changePicture", | |
| 145 l10n_util::GetStringUTF16(IDS_OPTIONS_CHANGE_PICTURE)); | |
| 146 if (chromeos::UserManager::Get()->user_is_logged_in()) { | |
| 147 localized_strings->SetString("username", | |
| 148 chromeos::UserManager::Get()->logged_in_user().email()); | |
| 149 } | |
| 150 #endif | |
| 151 } | |
| 152 | |
| 153 void PersonalOptionsHandler::RegisterMessages() { | |
| 154 web_ui()->RegisterMessageCallback( | |
| 155 "themesReset", | |
| 156 base::Bind(&PersonalOptionsHandler::ThemesReset, | |
| 157 base::Unretained(this))); | |
| 158 #if defined(TOOLKIT_GTK) | |
| 159 web_ui()->RegisterMessageCallback( | |
| 160 "themesSetGTK", | |
| 161 base::Bind(&PersonalOptionsHandler::ThemesSetGTK, | |
| 162 base::Unretained(this))); | |
| 163 #endif | |
| 164 } | |
| 165 | |
| 166 void PersonalOptionsHandler::Observe( | |
| 167 int type, | |
| 168 const content::NotificationSource& source, | |
| 169 const content::NotificationDetails& details) { | |
| 170 if (type == chrome::NOTIFICATION_BROWSER_THEME_CHANGED) { | |
| 171 ObserveThemeChanged(); | |
| 172 #if defined(OS_CHROMEOS) | |
| 173 } else if (type == chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED) { | |
| 174 UpdateAccountPicture(); | |
| 175 #endif | |
| 176 } else { | |
| 177 OptionsPageUIHandler::Observe(type, source, details); | |
| 178 } | |
| 179 } | |
| 180 | |
| 181 void PersonalOptionsHandler::ObserveThemeChanged() { | |
| 182 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 183 #if defined(TOOLKIT_GTK) | |
| 184 GtkThemeService* theme_service = GtkThemeService::GetFrom(profile); | |
| 185 bool is_gtk_theme = theme_service->UsingNativeTheme(); | |
| 186 base::FundamentalValue gtk_enabled(!is_gtk_theme); | |
| 187 web_ui()->CallJavascriptFunction( | |
| 188 "options.PersonalOptions.setGtkThemeButtonEnabled", gtk_enabled); | |
| 189 #else | |
| 190 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile); | |
| 191 bool is_gtk_theme = false; | |
| 192 #endif | |
| 193 | |
| 194 bool is_classic_theme = !is_gtk_theme && theme_service->UsingDefaultTheme(); | |
| 195 base::FundamentalValue enabled(!is_classic_theme); | |
| 196 web_ui()->CallJavascriptFunction( | |
| 197 "options.PersonalOptions.setThemesResetButtonEnabled", enabled); | |
| 198 } | |
| 199 | |
| 200 void PersonalOptionsHandler::Initialize() { | |
| 201 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 202 | |
| 203 // Listen for theme installation. | |
| 204 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | |
| 205 content::Source<ThemeService>( | |
| 206 ThemeServiceFactory::GetForProfile(profile))); | |
| 207 ObserveThemeChanged(); | |
| 208 } | |
| 209 | |
| 210 void PersonalOptionsHandler::ThemesReset(const ListValue* args) { | |
| 211 content::RecordAction(UserMetricsAction("Options_ThemesReset")); | |
| 212 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 213 ThemeServiceFactory::GetForProfile(profile)->UseDefaultTheme(); | |
| 214 } | |
| 215 | |
| 216 #if defined(TOOLKIT_GTK) | |
| 217 void PersonalOptionsHandler::ThemesSetGTK(const ListValue* args) { | |
| 218 content::RecordAction(UserMetricsAction("Options_GtkThemeSet")); | |
| 219 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 220 ThemeServiceFactory::GetForProfile(profile)->SetNativeTheme(); | |
| 221 } | |
| 222 #endif | |
| 223 | |
| 224 #if defined(OS_CHROMEOS) | |
| 225 void PersonalOptionsHandler::UpdateAccountPicture() { | |
| 226 std::string email = chromeos::UserManager::Get()->logged_in_user().email(); | |
| 227 if (!email.empty()) { | |
| 228 web_ui()->CallJavascriptFunction("PersonalOptions.updateAccountPicture"); | |
| 229 base::StringValue email_value(email); | |
| 230 web_ui()->CallJavascriptFunction("AccountsOptions.updateAccountPicture", | |
| 231 email_value); | |
| 232 } | |
| 233 } | |
| 234 #endif | |
| 235 | |
| 236 } // namespace options2 | |
| OLD | NEW |