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/core_options_handler.h" | 5 #include "chrome/browser/ui/webui/options/core_options_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
17 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
18 #include "chrome/browser/extensions/extension_util.h" | 18 #include "chrome/browser/extensions/extension_util.h" |
19 #include "chrome/browser/metrics/metrics_reporting_state.h" | |
20 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
22 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
23 #include "chrome/grit/chromium_strings.h" | 22 #include "chrome/grit/chromium_strings.h" |
24 #include "chrome/grit/generated_resources.h" | 23 #include "chrome/grit/generated_resources.h" |
25 #include "chrome/grit/locale_settings.h" | 24 #include "chrome/grit/locale_settings.h" |
26 #include "components/url_fixer/url_fixer.h" | 25 #include "components/url_fixer/url_fixer.h" |
27 #include "content/public/browser/notification_details.h" | 26 #include "content/public/browser/notification_details.h" |
28 #include "content/public/browser/notification_types.h" | 27 #include "content/public/browser/notification_types.h" |
29 #include "content/public/browser/user_metrics.h" | 28 #include "content/public/browser/user_metrics.h" |
30 #include "content/public/browser/web_ui.h" | 29 #include "content/public/browser/web_ui.h" |
31 #include "extensions/browser/extension_pref_value_map.h" | 30 #include "extensions/browser/extension_pref_value_map.h" |
32 #include "extensions/browser/extension_pref_value_map_factory.h" | 31 #include "extensions/browser/extension_pref_value_map_factory.h" |
33 #include "extensions/browser/extension_registry.h" | 32 #include "extensions/browser/extension_registry.h" |
34 #include "extensions/browser/extension_system.h" | 33 #include "extensions/browser/extension_system.h" |
35 #include "extensions/common/extension.h" | 34 #include "extensions/common/extension.h" |
36 #include "grit/components_strings.h" | 35 #include "grit/components_strings.h" |
37 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
38 #include "url/gurl.h" | 37 #include "url/gurl.h" |
39 | 38 |
40 using base::UserMetricsAction; | 39 using base::UserMetricsAction; |
41 | 40 |
42 namespace options { | 41 namespace options { |
43 | 42 |
44 namespace { | 43 namespace { |
45 | 44 |
46 // Only allow changes to the metrics reporting checkbox if we were succesfully | |
47 // able to change the service. | |
48 bool AllowMetricsReportingChange(const base::Value* to_value) { | |
49 bool enable; | |
50 if (!to_value->GetAsBoolean(&enable)) { | |
51 NOTREACHED(); | |
52 return false; | |
53 } | |
54 | |
55 return enable == ResolveMetricsReportingEnabled(enable); | |
56 } | |
57 | |
58 // Whether "controlledBy" property of pref value sent to options web UI needs to | 45 // Whether "controlledBy" property of pref value sent to options web UI needs to |
59 // be set to "extension" when the preference is controlled by an extension. | 46 // be set to "extension" when the preference is controlled by an extension. |
60 bool CanSetExtensionControlledPrefValue( | 47 bool CanSetExtensionControlledPrefValue( |
61 const PrefService::Preference* preference) { | 48 const PrefService::Preference* preference) { |
62 #if defined(OS_WIN) | 49 #if defined(OS_WIN) |
63 // These have more obvious UI than the standard one for extension controlled | 50 // These have more obvious UI than the standard one for extension controlled |
64 // values (an extension puzzle piece) on the settings page. To avoiding | 51 // values (an extension puzzle piece) on the settings page. To avoiding |
65 // showing the extension puzzle piece for these settings, their "controlledBy" | 52 // showing the extension puzzle piece for these settings, their "controlledBy" |
66 // value should never be set to "extension". | 53 // value should never be set to "extension". |
67 return preference->name() != prefs::kURLsToRestoreOnStartup && | 54 return preference->name() != prefs::kURLsToRestoreOnStartup && |
(...skipping 15 matching lines...) Expand all Loading... |
83 | 70 |
84 void CoreOptionsHandler::InitializeHandler() { | 71 void CoreOptionsHandler::InitializeHandler() { |
85 Profile* profile = Profile::FromWebUI(web_ui()); | 72 Profile* profile = Profile::FromWebUI(web_ui()); |
86 | 73 |
87 plugin_status_pref_setter_.Init( | 74 plugin_status_pref_setter_.Init( |
88 profile, | 75 profile, |
89 base::Bind(&CoreOptionsHandler::OnPreferenceChanged, | 76 base::Bind(&CoreOptionsHandler::OnPreferenceChanged, |
90 base::Unretained(this), | 77 base::Unretained(this), |
91 profile->GetPrefs())); | 78 profile->GetPrefs())); |
92 | 79 |
93 pref_change_filters_[prefs::kMetricsReportingEnabled] = | |
94 base::Bind(&AllowMetricsReportingChange); | |
95 pref_change_filters_[prefs::kBrowserGuestModeEnabled] = | 80 pref_change_filters_[prefs::kBrowserGuestModeEnabled] = |
96 base::Bind(&CoreOptionsHandler::IsUserUnsupervised, | 81 base::Bind(&CoreOptionsHandler::IsUserUnsupervised, |
97 base::Unretained(this)); | 82 base::Unretained(this)); |
98 pref_change_filters_[prefs::kBrowserAddPersonEnabled] = | 83 pref_change_filters_[prefs::kBrowserAddPersonEnabled] = |
99 base::Bind(&CoreOptionsHandler::IsUserUnsupervised, | 84 base::Bind(&CoreOptionsHandler::IsUserUnsupervised, |
100 base::Unretained(this)); | 85 base::Unretained(this)); |
101 } | 86 } |
102 | 87 |
103 void CoreOptionsHandler::InitializePage() { | 88 void CoreOptionsHandler::InitializePage() { |
104 UpdateClearPluginLSOData(); | 89 UpdateClearPluginLSOData(); |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 plugin_status_pref_setter_.IsPepperFlashSettingsEnabled()); | 646 plugin_status_pref_setter_.IsPepperFlashSettingsEnabled()); |
662 web_ui()->CallJavascriptFunction( | 647 web_ui()->CallJavascriptFunction( |
663 "OptionsPage.setPepperFlashSettingsEnabled", enabled); | 648 "OptionsPage.setPepperFlashSettingsEnabled", enabled); |
664 } | 649 } |
665 | 650 |
666 bool CoreOptionsHandler::IsUserUnsupervised(const base::Value* to_value) { | 651 bool CoreOptionsHandler::IsUserUnsupervised(const base::Value* to_value) { |
667 return !Profile::FromWebUI(web_ui())->IsSupervised(); | 652 return !Profile::FromWebUI(web_ui())->IsSupervised(); |
668 } | 653 } |
669 | 654 |
670 } // namespace options | 655 } // namespace options |
OLD | NEW |