OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/string16.h" | 9 #include "base/string16.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/google/google_util.h" | 14 #include "chrome/browser/google/google_util.h" |
15 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
18 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
19 #include "chrome/common/url_constants.h" | 19 #include "chrome/common/url_constants.h" |
20 #include "content/browser/user_metrics.h" | 20 #include "content/browser/user_metrics.h" |
21 #include "content/common/content_notification_types.h" | 21 #include "content/common/content_notification_types.h" |
22 #include "content/common/notification_details.h" | 22 #include "content/common/notification_details.h" |
23 #include "googleurl/src/gurl.h" | 23 #include "googleurl/src/gurl.h" |
24 #include "grit/chromium_strings.h" | 24 #include "grit/chromium_strings.h" |
25 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
26 #include "grit/locale_settings.h" | 26 #include "grit/locale_settings.h" |
27 #include "grit/theme_resources.h" | 27 #include "grit/theme_resources.h" |
28 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
29 | 29 |
| 30 namespace { |
| 31 |
| 32 DictionaryValue* CreateValueForPref(const PrefService::Preference* pref) { |
| 33 DictionaryValue* dict = new DictionaryValue; |
| 34 dict->Set("value", pref->GetValue()->DeepCopy()); |
| 35 if (pref->IsManaged()) { |
| 36 dict->SetString("controlledBy", "policy"); |
| 37 } else if (pref->IsExtensionControlled()) { |
| 38 dict->SetString("controlledBy", "extension"); |
| 39 } |
| 40 dict->SetBoolean("disabled", !pref->IsUserModifiable()); |
| 41 return dict; |
| 42 } |
| 43 |
| 44 } // namespace |
| 45 |
30 CoreOptionsHandler::CoreOptionsHandler() | 46 CoreOptionsHandler::CoreOptionsHandler() |
31 : handlers_host_(NULL) { | 47 : handlers_host_(NULL) { |
32 } | 48 } |
33 | 49 |
34 CoreOptionsHandler::~CoreOptionsHandler() {} | 50 CoreOptionsHandler::~CoreOptionsHandler() {} |
35 | 51 |
36 void CoreOptionsHandler::Initialize() { | 52 void CoreOptionsHandler::Initialize() { |
37 clear_plugin_lso_data_enabled_.Init(prefs::kClearPluginLSODataEnabled, | 53 clear_plugin_lso_data_enabled_.Init(prefs::kClearPluginLSODataEnabled, |
38 g_browser_process->local_state(), | 54 g_browser_process->local_state(), |
39 this); | 55 this); |
40 UpdateClearPluginLSOData(); | 56 UpdateClearPluginLSOData(); |
41 } | 57 } |
42 | 58 |
43 void CoreOptionsHandler::GetLocalizedValues( | 59 void CoreOptionsHandler::GetLocalizedValues( |
44 DictionaryValue* localized_strings) { | 60 DictionaryValue* localized_strings) { |
45 DCHECK(localized_strings); | 61 DCHECK(localized_strings); |
46 // Main | 62 // Main |
47 localized_strings->SetString("title", | 63 localized_strings->SetString("title", |
48 l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE)); | 64 l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE)); |
49 | 65 |
50 // Managed prefs | 66 // Managed prefs |
51 localized_strings->SetString("managedPrefsBannerText", | 67 localized_strings->SetString("policyManagedPrefsBannerText", |
52 l10n_util::GetStringUTF16(IDS_OPTIONS_MANAGED_PREFS)); | 68 l10n_util::GetStringUTF16(IDS_OPTIONS_POLICY_MANAGED_PREFS)); |
| 69 localized_strings->SetString("extensionManagedPrefsBannerText", |
| 70 l10n_util::GetStringUTF16(IDS_OPTIONS_EXTENSION_MANAGED_PREFS)); |
| 71 localized_strings->SetString("policyAndExtensionManagedPrefsBannerText", |
| 72 l10n_util::GetStringUTF16(IDS_OPTIONS_POLICY_EXTENSION_MANAGED_PREFS)); |
53 | 73 |
54 // Search | 74 // Search |
55 RegisterTitle(localized_strings, "searchPage", IDS_OPTIONS_SEARCH_PAGE_TITLE); | 75 RegisterTitle(localized_strings, "searchPage", IDS_OPTIONS_SEARCH_PAGE_TITLE); |
56 localized_strings->SetString("searchPlaceholder", | 76 localized_strings->SetString("searchPlaceholder", |
57 l10n_util::GetStringUTF16(IDS_OPTIONS_SEARCH_PLACEHOLDER)); | 77 l10n_util::GetStringUTF16(IDS_OPTIONS_SEARCH_PLACEHOLDER)); |
58 localized_strings->SetString("searchPageNoMatches", | 78 localized_strings->SetString("searchPageNoMatches", |
59 l10n_util::GetStringUTF16(IDS_OPTIONS_SEARCH_PAGE_NO_MATCHES)); | 79 l10n_util::GetStringUTF16(IDS_OPTIONS_SEARCH_PAGE_NO_MATCHES)); |
60 localized_strings->SetString("searchPageHelpLabel", | 80 localized_strings->SetString("searchPageHelpLabel", |
61 l10n_util::GetStringUTF16(IDS_OPTIONS_SEARCH_PAGE_HELP_LABEL)); | 81 l10n_util::GetStringUTF16(IDS_OPTIONS_SEARCH_PAGE_HELP_LABEL)); |
62 localized_strings->SetString("searchPageHelpTitle", | 82 localized_strings->SetString("searchPageHelpTitle", |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 void CoreOptionsHandler::HandleInitialize(const ListValue* args) { | 149 void CoreOptionsHandler::HandleInitialize(const ListValue* args) { |
130 DCHECK(handlers_host_); | 150 DCHECK(handlers_host_); |
131 handlers_host_->InitializeHandlers(); | 151 handlers_host_->InitializeHandlers(); |
132 } | 152 } |
133 | 153 |
134 Value* CoreOptionsHandler::FetchPref(const std::string& pref_name) { | 154 Value* CoreOptionsHandler::FetchPref(const std::string& pref_name) { |
135 PrefService* pref_service = web_ui_->GetProfile()->GetPrefs(); | 155 PrefService* pref_service = web_ui_->GetProfile()->GetPrefs(); |
136 | 156 |
137 const PrefService::Preference* pref = | 157 const PrefService::Preference* pref = |
138 pref_service->FindPreference(pref_name.c_str()); | 158 pref_service->FindPreference(pref_name.c_str()); |
| 159 if (!pref) |
| 160 return Value::CreateNullValue(); |
139 | 161 |
140 Value* return_value; | 162 return CreateValueForPref(pref); |
141 if (pref) { | |
142 DictionaryValue* dict = new DictionaryValue; | |
143 dict->Set("value", pref->GetValue()->DeepCopy()); | |
144 dict->SetBoolean("managed", pref->IsManaged()); | |
145 dict->SetBoolean("extensionControlled", pref->IsExtensionControlled()); | |
146 dict->SetBoolean("disabled", !pref->IsUserModifiable()); | |
147 return_value = dict; | |
148 } else { | |
149 return_value = Value::CreateNullValue(); | |
150 } | |
151 return return_value; | |
152 } | 163 } |
153 | 164 |
154 void CoreOptionsHandler::ObservePref(const std::string& pref_name) { | 165 void CoreOptionsHandler::ObservePref(const std::string& pref_name) { |
155 registrar_.Add(pref_name.c_str(), this); | 166 registrar_.Add(pref_name.c_str(), this); |
156 } | 167 } |
157 | 168 |
158 void CoreOptionsHandler::SetPref(const std::string& pref_name, | 169 void CoreOptionsHandler::SetPref(const std::string& pref_name, |
159 const Value* value, | 170 const Value* value, |
160 const std::string& metric) { | 171 const std::string& metric) { |
161 PrefService* pref_service = web_ui_->GetProfile()->GetPrefs(); | 172 PrefService* pref_service = web_ui_->GetProfile()->GetPrefs(); |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 void CoreOptionsHandler::NotifyPrefChanged(const std::string* pref_name) { | 373 void CoreOptionsHandler::NotifyPrefChanged(const std::string* pref_name) { |
363 if (*pref_name == prefs::kClearPluginLSODataEnabled) { | 374 if (*pref_name == prefs::kClearPluginLSODataEnabled) { |
364 // This preference is stored in Local State, not in the user preferences. | 375 // This preference is stored in Local State, not in the user preferences. |
365 UpdateClearPluginLSOData(); | 376 UpdateClearPluginLSOData(); |
366 return; | 377 return; |
367 } | 378 } |
368 | 379 |
369 PrefService* pref_service = web_ui_->GetProfile()->GetPrefs(); | 380 PrefService* pref_service = web_ui_->GetProfile()->GetPrefs(); |
370 const PrefService::Preference* pref = | 381 const PrefService::Preference* pref = |
371 pref_service->FindPreference(pref_name->c_str()); | 382 pref_service->FindPreference(pref_name->c_str()); |
372 if (pref) { | 383 if (!pref) |
373 for (PreferenceCallbackMap::const_iterator iter = | 384 return; |
374 pref_callback_map_.find(*pref_name); | |
375 iter != pref_callback_map_.end(); ++iter) { | |
376 const std::wstring& callback_function = iter->second; | |
377 ListValue result_value; | |
378 result_value.Append(Value::CreateStringValue(pref_name->c_str())); | |
379 | 385 |
380 DictionaryValue* dict = new DictionaryValue; | 386 for (PreferenceCallbackMap::const_iterator iter = |
381 dict->Set("value", pref->GetValue()->DeepCopy()); | 387 pref_callback_map_.find(*pref_name); |
382 dict->SetBoolean("managed", pref->IsManaged()); | 388 iter != pref_callback_map_.end(); ++iter) { |
383 dict->SetBoolean("extensionControlled", pref->IsExtensionControlled()); | 389 const std::wstring& callback_function = iter->second; |
384 dict->SetBoolean("disabled", !pref->IsUserModifiable()); | 390 ListValue result_value; |
385 result_value.Append(dict); | 391 result_value.Append(Value::CreateStringValue(pref_name->c_str())); |
386 | 392 |
387 web_ui_->CallJavascriptFunction(WideToASCII(callback_function), | 393 result_value.Append(CreateValueForPref(pref)); |
388 result_value); | 394 |
389 } | 395 web_ui_->CallJavascriptFunction(WideToASCII(callback_function), |
| 396 result_value); |
390 } | 397 } |
391 } | 398 } |
OLD | NEW |