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/callback.h" |
9 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
11 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
12 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
14 #include "base/values.h" | 15 #include "base/values.h" |
15 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
17 #include "chrome/browser/extensions/extension_service.h" | 18 #include "chrome/browser/extensions/extension_service.h" |
18 #include "chrome/browser/extensions/extension_util.h" | 19 #include "chrome/browser/extensions/extension_util.h" |
19 #include "chrome/browser/metrics/metrics_reporting_state.h" | |
20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
22 #include "chrome/common/url_constants.h" | 22 #include "chrome/common/url_constants.h" |
23 #include "chrome/grit/chromium_strings.h" | 23 #include "chrome/grit/chromium_strings.h" |
24 #include "chrome/grit/generated_resources.h" | 24 #include "chrome/grit/generated_resources.h" |
25 #include "chrome/grit/locale_settings.h" | 25 #include "chrome/grit/locale_settings.h" |
26 #include "components/url_fixer/url_fixer.h" | 26 #include "components/url_fixer/url_fixer.h" |
27 #include "content/public/browser/notification_details.h" | 27 #include "content/public/browser/notification_details.h" |
28 #include "content/public/browser/notification_types.h" | 28 #include "content/public/browser/notification_types.h" |
29 #include "content/public/browser/user_metrics.h" | 29 #include "content/public/browser/user_metrics.h" |
30 #include "content/public/browser/web_ui.h" | 30 #include "content/public/browser/web_ui.h" |
31 #include "extensions/browser/extension_pref_value_map.h" | 31 #include "extensions/browser/extension_pref_value_map.h" |
32 #include "extensions/browser/extension_pref_value_map_factory.h" | 32 #include "extensions/browser/extension_pref_value_map_factory.h" |
33 #include "extensions/browser/extension_registry.h" | 33 #include "extensions/browser/extension_registry.h" |
34 #include "extensions/browser/extension_system.h" | 34 #include "extensions/browser/extension_system.h" |
35 #include "extensions/common/extension.h" | 35 #include "extensions/common/extension.h" |
36 #include "grit/components_strings.h" | 36 #include "grit/components_strings.h" |
37 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
38 #include "url/gurl.h" | 38 #include "url/gurl.h" |
39 | 39 |
40 using base::UserMetricsAction; | 40 using base::UserMetricsAction; |
41 | 41 |
42 namespace options { | 42 namespace options { |
43 | 43 |
44 namespace { | 44 namespace { |
45 | 45 |
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 | 46 // 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. | 47 // be set to "extension" when the preference is controlled by an extension. |
60 bool CanSetExtensionControlledPrefValue( | 48 bool CanSetExtensionControlledPrefValue( |
61 const PrefService::Preference* preference) { | 49 const PrefService::Preference* preference) { |
62 #if defined(OS_WIN) | 50 #if defined(OS_WIN) |
63 // These have more obvious UI than the standard one for extension controlled | 51 // These have more obvious UI than the standard one for extension controlled |
64 // values (an extension puzzle piece) on the settings page. To avoiding | 52 // values (an extension puzzle piece) on the settings page. To avoiding |
65 // showing the extension puzzle piece for these settings, their "controlledBy" | 53 // showing the extension puzzle piece for these settings, their "controlledBy" |
66 // value should never be set to "extension". | 54 // value should never be set to "extension". |
67 return preference->name() != prefs::kURLsToRestoreOnStartup && | 55 return preference->name() != prefs::kURLsToRestoreOnStartup && |
(...skipping 14 matching lines...) Expand all Loading... |
82 CoreOptionsHandler::~CoreOptionsHandler() {} | 70 CoreOptionsHandler::~CoreOptionsHandler() {} |
83 | 71 |
84 void CoreOptionsHandler::InitializeHandler() { | 72 void CoreOptionsHandler::InitializeHandler() { |
85 Profile* profile = Profile::FromWebUI(web_ui()); | 73 Profile* profile = Profile::FromWebUI(web_ui()); |
86 | 74 |
87 plugin_status_pref_setter_.Init( | 75 plugin_status_pref_setter_.Init( |
88 profile, | 76 profile, |
89 base::Bind(&CoreOptionsHandler::OnPreferenceChanged, | 77 base::Bind(&CoreOptionsHandler::OnPreferenceChanged, |
90 base::Unretained(this), | 78 base::Unretained(this), |
91 profile->GetPrefs())); | 79 profile->GetPrefs())); |
92 | |
93 pref_change_filters_[prefs::kMetricsReportingEnabled] = | |
94 base::Bind(&AllowMetricsReportingChange); | |
95 } | 80 } |
96 | 81 |
97 void CoreOptionsHandler::InitializePage() { | 82 void CoreOptionsHandler::InitializePage() { |
98 UpdateClearPluginLSOData(); | 83 UpdateClearPluginLSOData(); |
99 UpdatePepperFlashSettingsEnabled(); | 84 UpdatePepperFlashSettingsEnabled(); |
100 } | 85 } |
101 | 86 |
102 void CoreOptionsHandler::GetLocalizedValues( | 87 void CoreOptionsHandler::GetLocalizedValues( |
103 base::DictionaryValue* localized_strings) { | 88 base::DictionaryValue* localized_strings) { |
104 GetStaticLocalizedValues(localized_strings); | 89 GetStaticLocalizedValues(localized_strings); |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 } | 636 } |
652 | 637 |
653 void CoreOptionsHandler::UpdatePepperFlashSettingsEnabled() { | 638 void CoreOptionsHandler::UpdatePepperFlashSettingsEnabled() { |
654 base::FundamentalValue enabled( | 639 base::FundamentalValue enabled( |
655 plugin_status_pref_setter_.IsPepperFlashSettingsEnabled()); | 640 plugin_status_pref_setter_.IsPepperFlashSettingsEnabled()); |
656 web_ui()->CallJavascriptFunction( | 641 web_ui()->CallJavascriptFunction( |
657 "OptionsPage.setPepperFlashSettingsEnabled", enabled); | 642 "OptionsPage.setPepperFlashSettingsEnabled", enabled); |
658 } | 643 } |
659 | 644 |
660 } // namespace options | 645 } // namespace options |
OLD | NEW |