| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/options/browser_options_handler.h" | 5 #include "chrome/browser/ui/webui/options/browser_options_handler.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/environment.h" | 14 #include "base/environment.h" |
| 15 #include "base/memory/singleton.h" | 15 #include "base/memory/singleton.h" |
| 16 #include "base/metrics/field_trial.h" | 16 #include "base/metrics/field_trial.h" |
| 17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
| 18 #include "base/prefs/pref_service.h" | 18 #include "base/prefs/pref_service.h" |
| 19 #include "base/prefs/scoped_user_pref_update.h" | 19 #include "base/prefs/scoped_user_pref_update.h" |
| 20 #include "base/stl_util.h" | 20 #include "base/stl_util.h" |
| 21 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 23 #include "base/value_conversions.h" | 23 #include "base/value_conversions.h" |
| 24 #include "base/values.h" | 24 #include "base/values.h" |
| 25 #include "chrome/browser/auto_launch_trial.h" | |
| 26 #include "chrome/browser/browser_process.h" | 25 #include "chrome/browser/browser_process.h" |
| 27 #include "chrome/browser/chrome_notification_types.h" | 26 #include "chrome/browser/chrome_notification_types.h" |
| 28 #include "chrome/browser/custom_home_pages_table_model.h" | 27 #include "chrome/browser/custom_home_pages_table_model.h" |
| 29 #include "chrome/browser/download/download_prefs.h" | 28 #include "chrome/browser/download/download_prefs.h" |
| 30 #include "chrome/browser/gpu/gpu_mode_manager.h" | 29 #include "chrome/browser/gpu/gpu_mode_manager.h" |
| 31 #include "chrome/browser/lifetime/application_lifetime.h" | 30 #include "chrome/browser/lifetime/application_lifetime.h" |
| 32 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | 31 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" |
| 33 #include "chrome/browser/metrics/metrics_reporting_state.h" | 32 #include "chrome/browser/metrics/metrics_reporting_state.h" |
| 34 #include "chrome/browser/net/prediction_options.h" | 33 #include "chrome/browser/net/prediction_options.h" |
| 35 #include "chrome/browser/prefs/session_startup_pref.h" | 34 #include "chrome/browser/prefs/session_startup_pref.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 #include "chromeos/dbus/dbus_thread_manager.h" | 126 #include "chromeos/dbus/dbus_thread_manager.h" |
| 128 #include "chromeos/dbus/power_manager_client.h" | 127 #include "chromeos/dbus/power_manager_client.h" |
| 129 #include "components/user_manager/user.h" | 128 #include "components/user_manager/user.h" |
| 130 #include "components/user_manager/user_manager.h" | 129 #include "components/user_manager/user_manager.h" |
| 131 #include "ui/chromeos/accessibility_types.h" | 130 #include "ui/chromeos/accessibility_types.h" |
| 132 #include "ui/gfx/image/image_skia.h" | 131 #include "ui/gfx/image/image_skia.h" |
| 133 #endif // defined(OS_CHROMEOS) | 132 #endif // defined(OS_CHROMEOS) |
| 134 | 133 |
| 135 #if defined(OS_WIN) | 134 #if defined(OS_WIN) |
| 136 #include "chrome/browser/extensions/settings_api_helpers.h" | 135 #include "chrome/browser/extensions/settings_api_helpers.h" |
| 137 #include "chrome/installer/util/auto_launch_util.h" | |
| 138 #include "content/public/browser/browser_url_handler.h" | 136 #include "content/public/browser/browser_url_handler.h" |
| 139 #endif // defined(OS_WIN) | 137 #endif // defined(OS_WIN) |
| 140 | 138 |
| 141 #if defined(ENABLE_SERVICE_DISCOVERY) | 139 #if defined(ENABLE_SERVICE_DISCOVERY) |
| 142 #include "chrome/browser/local_discovery/privet_notifications.h" | 140 #include "chrome/browser/local_discovery/privet_notifications.h" |
| 143 #endif | 141 #endif |
| 144 | 142 |
| 145 #if defined(USE_ASH) | 143 #if defined(USE_ASH) |
| 146 #include "ash/shell.h" | 144 #include "ash/shell.h" |
| 147 #endif | 145 #endif |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 { "advancedSectionTitleCloudPrint", IDS_GOOGLE_CLOUD_PRINT }, | 220 { "advancedSectionTitleCloudPrint", IDS_GOOGLE_CLOUD_PRINT }, |
| 223 { "advancedSectionTitleContent", | 221 { "advancedSectionTitleContent", |
| 224 IDS_OPTIONS_ADVANCED_SECTION_TITLE_CONTENT }, | 222 IDS_OPTIONS_ADVANCED_SECTION_TITLE_CONTENT }, |
| 225 { "advancedSectionTitleLanguages", | 223 { "advancedSectionTitleLanguages", |
| 226 IDS_OPTIONS_ADVANCED_SECTION_TITLE_LANGUAGES }, | 224 IDS_OPTIONS_ADVANCED_SECTION_TITLE_LANGUAGES }, |
| 227 { "advancedSectionTitleNetwork", | 225 { "advancedSectionTitleNetwork", |
| 228 IDS_OPTIONS_ADVANCED_SECTION_TITLE_NETWORK }, | 226 IDS_OPTIONS_ADVANCED_SECTION_TITLE_NETWORK }, |
| 229 { "advancedSectionTitlePrivacy", | 227 { "advancedSectionTitlePrivacy", |
| 230 IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY }, | 228 IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY }, |
| 231 { "advancedSectionTitleSystem", IDS_OPTIONS_ADVANCED_SECTION_TITLE_SYSTEM }, | 229 { "advancedSectionTitleSystem", IDS_OPTIONS_ADVANCED_SECTION_TITLE_SYSTEM }, |
| 232 { "autoLaunchText", IDS_AUTOLAUNCH_TEXT }, | |
| 233 { "autoOpenFileTypesInfo", IDS_OPTIONS_OPEN_FILE_TYPES_AUTOMATICALLY }, | 230 { "autoOpenFileTypesInfo", IDS_OPTIONS_OPEN_FILE_TYPES_AUTOMATICALLY }, |
| 234 { "autoOpenFileTypesResetToDefault", | 231 { "autoOpenFileTypesResetToDefault", |
| 235 IDS_OPTIONS_AUTOOPENFILETYPES_RESETTODEFAULT }, | 232 IDS_OPTIONS_AUTOOPENFILETYPES_RESETTODEFAULT }, |
| 236 { "autofillEnabled", IDS_OPTIONS_AUTOFILL_ENABLE }, | 233 { "autofillEnabled", IDS_OPTIONS_AUTOFILL_ENABLE }, |
| 237 { "autologinEnabled", IDS_OPTIONS_PASSWORDS_AUTOLOGIN }, | 234 { "autologinEnabled", IDS_OPTIONS_PASSWORDS_AUTOLOGIN }, |
| 238 { "certificatesManageButton", IDS_OPTIONS_CERTIFICATES_MANAGE_BUTTON }, | 235 { "certificatesManageButton", IDS_OPTIONS_CERTIFICATES_MANAGE_BUTTON }, |
| 239 { "changeHomePage", IDS_OPTIONS_CHANGE_HOME_PAGE }, | 236 { "changeHomePage", IDS_OPTIONS_CHANGE_HOME_PAGE }, |
| 240 { "childLabel", IDS_PROFILES_LIST_CHILD_LABEL }, | 237 { "childLabel", IDS_PROFILES_LIST_CHILD_LABEL }, |
| 241 { "currentUserOnly", IDS_OPTIONS_CURRENT_USER_ONLY }, | 238 { "currentUserOnly", IDS_OPTIONS_CURRENT_USER_ONLY }, |
| 242 { "customizeSync", IDS_OPTIONS_CUSTOMIZE_SYNC_BUTTON_LABEL }, | 239 { "customizeSync", IDS_OPTIONS_CUSTOMIZE_SYNC_BUTTON_LABEL }, |
| (...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 905 #endif | 902 #endif |
| 906 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 903 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
| 907 content::Source<ThemeService>( | 904 content::Source<ThemeService>( |
| 908 ThemeServiceFactory::GetForProfile(profile))); | 905 ThemeServiceFactory::GetForProfile(profile))); |
| 909 registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, | 906 registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, |
| 910 content::Source<Profile>(profile)); | 907 content::Source<Profile>(profile)); |
| 911 AddTemplateUrlServiceObserver(); | 908 AddTemplateUrlServiceObserver(); |
| 912 | 909 |
| 913 #if defined(OS_WIN) | 910 #if defined(OS_WIN) |
| 914 ExtensionRegistry::Get(Profile::FromWebUI(web_ui()))->AddObserver(this); | 911 ExtensionRegistry::Get(Profile::FromWebUI(web_ui()))->AddObserver(this); |
| 915 | |
| 916 const base::CommandLine& command_line = | |
| 917 *base::CommandLine::ForCurrentProcess(); | |
| 918 if (!command_line.HasSwitch(switches::kUserDataDir)) { | |
| 919 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | |
| 920 base::Bind(&BrowserOptionsHandler::CheckAutoLaunch, | |
| 921 weak_ptr_factory_.GetWeakPtr(), | |
| 922 profile->GetPath())); | |
| 923 } | |
| 924 #endif | 912 #endif |
| 925 | 913 |
| 926 // No preferences below this point may be modified by guest profiles. | 914 // No preferences below this point may be modified by guest profiles. |
| 927 if (Profile::FromWebUI(web_ui())->IsGuestSession()) | 915 if (Profile::FromWebUI(web_ui())->IsGuestSession()) |
| 928 return; | 916 return; |
| 929 | 917 |
| 930 auto_open_files_.Init( | 918 auto_open_files_.Init( |
| 931 prefs::kDownloadExtensionsToOpen, prefs, | 919 prefs::kDownloadExtensionsToOpen, prefs, |
| 932 base::Bind(&BrowserOptionsHandler::SetupAutoOpenFileTypes, | 920 base::Bind(&BrowserOptionsHandler::SetupAutoOpenFileTypes, |
| 933 base::Unretained(this))); | 921 base::Unretained(this))); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 policy::ConsumerManagementService* consumer_management = | 1030 policy::ConsumerManagementService* consumer_management = |
| 1043 g_browser_process->platform_part()->browser_policy_connector_chromeos()-> | 1031 g_browser_process->platform_part()->browser_policy_connector_chromeos()-> |
| 1044 GetConsumerManagementService(); | 1032 GetConsumerManagementService(); |
| 1045 if (consumer_management) { | 1033 if (consumer_management) { |
| 1046 OnConsumerManagementStatusChanged(); | 1034 OnConsumerManagementStatusChanged(); |
| 1047 consumer_management->AddObserver(this); | 1035 consumer_management->AddObserver(this); |
| 1048 } | 1036 } |
| 1049 #endif | 1037 #endif |
| 1050 } | 1038 } |
| 1051 | 1039 |
| 1052 // static | |
| 1053 void BrowserOptionsHandler::CheckAutoLaunch( | |
| 1054 base::WeakPtr<BrowserOptionsHandler> weak_this, | |
| 1055 const base::FilePath& profile_path) { | |
| 1056 #if defined(OS_WIN) | |
| 1057 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | |
| 1058 | |
| 1059 // Auto-launch is not supported for secondary profiles yet. | |
| 1060 if (profile_path.BaseName().value() != | |
| 1061 base::ASCIIToUTF16(chrome::kInitialProfile)) { | |
| 1062 return; | |
| 1063 } | |
| 1064 | |
| 1065 // Pass in weak pointer to this to avoid race if BrowserOptionsHandler is | |
| 1066 // deleted. | |
| 1067 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 1068 base::Bind(&BrowserOptionsHandler::CheckAutoLaunchCallback, | |
| 1069 weak_this, | |
| 1070 auto_launch_trial::IsInAutoLaunchGroup(), | |
| 1071 auto_launch_util::AutoStartRequested( | |
| 1072 profile_path.BaseName().value(), | |
| 1073 true, // Window requested. | |
| 1074 base::FilePath()))); | |
| 1075 #endif | |
| 1076 } | |
| 1077 | |
| 1078 void BrowserOptionsHandler::CheckAutoLaunchCallback( | |
| 1079 bool is_in_auto_launch_group, | |
| 1080 bool will_launch_at_login) { | |
| 1081 #if defined(OS_WIN) | |
| 1082 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 1083 | |
| 1084 if (is_in_auto_launch_group) { | |
| 1085 web_ui()->RegisterMessageCallback("toggleAutoLaunch", | |
| 1086 base::Bind(&BrowserOptionsHandler::ToggleAutoLaunch, | |
| 1087 base::Unretained(this))); | |
| 1088 | |
| 1089 base::FundamentalValue enabled(will_launch_at_login); | |
| 1090 web_ui()->CallJavascriptFunction("BrowserOptions.updateAutoLaunchState", | |
| 1091 enabled); | |
| 1092 } | |
| 1093 #endif | |
| 1094 } | |
| 1095 | |
| 1096 bool BrowserOptionsHandler::ShouldShowSetDefaultBrowser() { | 1040 bool BrowserOptionsHandler::ShouldShowSetDefaultBrowser() { |
| 1097 #if defined(OS_CHROMEOS) | 1041 #if defined(OS_CHROMEOS) |
| 1098 // We're always the default browser on ChromeOS. | 1042 // We're always the default browser on ChromeOS. |
| 1099 return false; | 1043 return false; |
| 1100 #else | 1044 #else |
| 1101 Profile* profile = Profile::FromWebUI(web_ui()); | 1045 Profile* profile = Profile::FromWebUI(web_ui()); |
| 1102 return !profile->IsGuestSession(); | 1046 return !profile->IsGuestSession(); |
| 1103 #endif | 1047 #endif |
| 1104 } | 1048 } |
| 1105 | 1049 |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1322 const base::FilePath& profile_path, | 1266 const base::FilePath& profile_path, |
| 1323 const base::string16& old_profile_name) { | 1267 const base::string16& old_profile_name) { |
| 1324 SendProfilesInfo(); | 1268 SendProfilesInfo(); |
| 1325 } | 1269 } |
| 1326 | 1270 |
| 1327 void BrowserOptionsHandler::OnProfileAvatarChanged( | 1271 void BrowserOptionsHandler::OnProfileAvatarChanged( |
| 1328 const base::FilePath& profile_path) { | 1272 const base::FilePath& profile_path) { |
| 1329 SendProfilesInfo(); | 1273 SendProfilesInfo(); |
| 1330 } | 1274 } |
| 1331 | 1275 |
| 1332 void BrowserOptionsHandler::ToggleAutoLaunch(const base::ListValue* args) { | |
| 1333 #if defined(OS_WIN) | |
| 1334 if (!auto_launch_trial::IsInAutoLaunchGroup()) | |
| 1335 return; | |
| 1336 | |
| 1337 bool enable; | |
| 1338 CHECK_EQ(args->GetSize(), 1U); | |
| 1339 CHECK(args->GetBoolean(0, &enable)); | |
| 1340 | |
| 1341 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 1342 content::BrowserThread::PostTask( | |
| 1343 content::BrowserThread::FILE, FROM_HERE, | |
| 1344 enable ? | |
| 1345 base::Bind(&auto_launch_util::EnableForegroundStartAtLogin, | |
| 1346 profile->GetPath().BaseName().value(), base::FilePath()) : | |
| 1347 base::Bind(&auto_launch_util::DisableForegroundStartAtLogin, | |
| 1348 profile->GetPath().BaseName().value())); | |
| 1349 #endif // OS_WIN | |
| 1350 } | |
| 1351 | |
| 1352 scoped_ptr<base::ListValue> BrowserOptionsHandler::GetProfilesInfoList() { | 1276 scoped_ptr<base::ListValue> BrowserOptionsHandler::GetProfilesInfoList() { |
| 1353 ProfileInfoCache& cache = | 1277 ProfileInfoCache& cache = |
| 1354 g_browser_process->profile_manager()->GetProfileInfoCache(); | 1278 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 1355 scoped_ptr<base::ListValue> profile_info_list(new base::ListValue); | 1279 scoped_ptr<base::ListValue> profile_info_list(new base::ListValue); |
| 1356 base::FilePath current_profile_path = | 1280 base::FilePath current_profile_path = |
| 1357 web_ui()->GetWebContents()->GetBrowserContext()->GetPath(); | 1281 web_ui()->GetWebContents()->GetBrowserContext()->GetPath(); |
| 1358 | 1282 |
| 1359 for (size_t i = 0, e = cache.GetNumberOfProfiles(); i < e; ++i) { | 1283 for (size_t i = 0, e = cache.GetNumberOfProfiles(); i < e; ++i) { |
| 1360 // The items in |profile_value| are also described in | 1284 // The items in |profile_value| are also described in |
| 1361 // chrome/browser/resources/options/browser_options.js in a @typedef for | 1285 // chrome/browser/resources/options/browser_options.js in a @typedef for |
| (...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2185 void BrowserOptionsHandler::OnPolicyUpdated(const policy::PolicyNamespace& ns, | 2109 void BrowserOptionsHandler::OnPolicyUpdated(const policy::PolicyNamespace& ns, |
| 2186 const policy::PolicyMap& previous, | 2110 const policy::PolicyMap& previous, |
| 2187 const policy::PolicyMap& current) { | 2111 const policy::PolicyMap& current) { |
| 2188 std::set<std::string> different_keys; | 2112 std::set<std::string> different_keys; |
| 2189 current.GetDifferingKeys(previous, &different_keys); | 2113 current.GetDifferingKeys(previous, &different_keys); |
| 2190 if (ContainsKey(different_keys, policy::key::kMetricsReportingEnabled)) | 2114 if (ContainsKey(different_keys, policy::key::kMetricsReportingEnabled)) |
| 2191 SetupMetricsReportingCheckbox(); | 2115 SetupMetricsReportingCheckbox(); |
| 2192 } | 2116 } |
| 2193 | 2117 |
| 2194 } // namespace options | 2118 } // namespace options |
| OLD | NEW |