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/google/google_util.h" | 14 #include "chrome/browser/google/google_util.h" |
14 #include "chrome/browser/metrics/user_metrics.h" | 15 #include "chrome/browser/metrics/user_metrics.h" |
15 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/common/pref_names.h" | |
17 #include "chrome/common/url_constants.h" | 19 #include "chrome/common/url_constants.h" |
18 #include "content/common/notification_details.h" | 20 #include "content/common/notification_details.h" |
19 #include "content/common/notification_type.h" | 21 #include "content/common/notification_type.h" |
20 #include "googleurl/src/gurl.h" | 22 #include "googleurl/src/gurl.h" |
21 #include "grit/chromium_strings.h" | 23 #include "grit/chromium_strings.h" |
22 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
23 #include "grit/locale_settings.h" | 25 #include "grit/locale_settings.h" |
24 #include "grit/theme_resources.h" | 26 #include "grit/theme_resources.h" |
25 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
26 | 28 |
27 CoreOptionsHandler::CoreOptionsHandler() | 29 CoreOptionsHandler::CoreOptionsHandler() |
28 : handlers_host_(NULL) { | 30 : handlers_host_(NULL) { |
29 } | 31 } |
30 | 32 |
31 CoreOptionsHandler::~CoreOptionsHandler() {} | 33 CoreOptionsHandler::~CoreOptionsHandler() {} |
32 | 34 |
35 void CoreOptionsHandler::Initialize() { | |
36 clear_plugin_lso_data_enabled_.Init(prefs::kClearPluginLSODataEnabled, | |
37 g_browser_process->local_state(), | |
38 this); | |
39 UpdateClearPluginLSOData(); | |
40 } | |
41 | |
33 void CoreOptionsHandler::GetLocalizedValues( | 42 void CoreOptionsHandler::GetLocalizedValues( |
34 DictionaryValue* localized_strings) { | 43 DictionaryValue* localized_strings) { |
35 DCHECK(localized_strings); | 44 DCHECK(localized_strings); |
36 // Main | 45 // Main |
37 localized_strings->SetString("title", | 46 localized_strings->SetString("title", |
38 l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE)); | 47 l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE)); |
39 | 48 |
40 // Managed prefs | 49 // Managed prefs |
41 localized_strings->SetString("managedPrefsBannerText", | 50 localized_strings->SetString("managedPrefsBannerText", |
42 l10n_util::GetStringUTF16(IDS_OPTIONS_MANAGED_PREFS)); | 51 l10n_util::GetStringUTF16(IDS_OPTIONS_MANAGED_PREFS)); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 WebUIMessageHandler* CoreOptionsHandler::Attach(WebUI* web_ui) { | 91 WebUIMessageHandler* CoreOptionsHandler::Attach(WebUI* web_ui) { |
83 WebUIMessageHandler* result = WebUIMessageHandler::Attach(web_ui); | 92 WebUIMessageHandler* result = WebUIMessageHandler::Attach(web_ui); |
84 DCHECK(web_ui_); | 93 DCHECK(web_ui_); |
85 registrar_.Init(web_ui_->GetProfile()->GetPrefs()); | 94 registrar_.Init(web_ui_->GetProfile()->GetPrefs()); |
86 return result; | 95 return result; |
87 } | 96 } |
88 | 97 |
89 void CoreOptionsHandler::Observe(NotificationType type, | 98 void CoreOptionsHandler::Observe(NotificationType type, |
90 const NotificationSource& source, | 99 const NotificationSource& source, |
91 const NotificationDetails& details) { | 100 const NotificationDetails& details) { |
92 if (type == NotificationType::PREF_CHANGED) | 101 if (type == NotificationType::PREF_CHANGED) { |
Evan Stade
2011/04/15 19:15:11
no curlies for single line if statements
Bernhard Bauer
2011/04/17 13:26:54
Done.
| |
93 NotifyPrefChanged(Details<std::string>(details).ptr()); | 102 NotifyPrefChanged(Details<std::string>(details).ptr()); |
103 } | |
94 } | 104 } |
95 | 105 |
96 void CoreOptionsHandler::RegisterMessages() { | 106 void CoreOptionsHandler::RegisterMessages() { |
97 web_ui_->RegisterMessageCallback("coreOptionsInitialize", | 107 web_ui_->RegisterMessageCallback("coreOptionsInitialize", |
98 NewCallback(this, &CoreOptionsHandler::HandleInitialize)); | 108 NewCallback(this, &CoreOptionsHandler::HandleInitialize)); |
99 web_ui_->RegisterMessageCallback("fetchPrefs", | 109 web_ui_->RegisterMessageCallback("fetchPrefs", |
100 NewCallback(this, &CoreOptionsHandler::HandleFetchPrefs)); | 110 NewCallback(this, &CoreOptionsHandler::HandleFetchPrefs)); |
101 web_ui_->RegisterMessageCallback("observePrefs", | 111 web_ui_->RegisterMessageCallback("observePrefs", |
102 NewCallback(this, &CoreOptionsHandler::HandleObservePrefs)); | 112 NewCallback(this, &CoreOptionsHandler::HandleObservePrefs)); |
103 web_ui_->RegisterMessageCallback("setBooleanPref", | 113 web_ui_->RegisterMessageCallback("setBooleanPref", |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
334 | 344 |
335 ClearPref(pref_name, metric); | 345 ClearPref(pref_name, metric); |
336 } | 346 } |
337 | 347 |
338 void CoreOptionsHandler::HandleUserMetricsAction(const ListValue* args) { | 348 void CoreOptionsHandler::HandleUserMetricsAction(const ListValue* args) { |
339 std::string metric = UTF16ToUTF8(ExtractStringValue(args)); | 349 std::string metric = UTF16ToUTF8(ExtractStringValue(args)); |
340 if (!metric.empty()) | 350 if (!metric.empty()) |
341 UserMetricsRecordAction(UserMetricsAction(metric.c_str())); | 351 UserMetricsRecordAction(UserMetricsAction(metric.c_str())); |
342 } | 352 } |
343 | 353 |
354 void CoreOptionsHandler::UpdateClearPluginLSOData() { | |
355 scoped_ptr<Value> enabled( | |
356 Value::CreateBooleanValue(clear_plugin_lso_data_enabled_.GetValue())); | |
357 web_ui_->CallJavascriptFunction( | |
358 "OptionsPage.setClearPluginLSODataEnabled", *enabled); | |
Evan Stade
2011/04/15 19:15:11
I don't think this is necessary. See Preferences.j
Bernhard Bauer
2011/04/17 13:26:54
|clear_plugin_lso_data_enabled_| is bound to local
| |
359 } | |
360 | |
344 void CoreOptionsHandler::NotifyPrefChanged(const std::string* pref_name) { | 361 void CoreOptionsHandler::NotifyPrefChanged(const std::string* pref_name) { |
362 if (*pref_name == prefs::kClearPluginLSODataEnabled) { | |
Evan Stade
2011/04/15 19:15:11
no curlies
Bernhard Bauer
2011/04/17 13:26:54
Done.
| |
363 UpdateClearPluginLSOData(); | |
364 } | |
365 | |
345 PrefService* pref_service = web_ui_->GetProfile()->GetPrefs(); | 366 PrefService* pref_service = web_ui_->GetProfile()->GetPrefs(); |
346 const PrefService::Preference* pref = | 367 const PrefService::Preference* pref = |
347 pref_service->FindPreference(pref_name->c_str()); | 368 pref_service->FindPreference(pref_name->c_str()); |
348 if (pref) { | 369 if (pref) { |
349 for (PreferenceCallbackMap::const_iterator iter = | 370 for (PreferenceCallbackMap::const_iterator iter = |
350 pref_callback_map_.find(*pref_name); | 371 pref_callback_map_.find(*pref_name); |
351 iter != pref_callback_map_.end(); ++iter) { | 372 iter != pref_callback_map_.end(); ++iter) { |
352 const std::wstring& callback_function = iter->second; | 373 const std::wstring& callback_function = iter->second; |
353 ListValue result_value; | 374 ListValue result_value; |
354 result_value.Append(Value::CreateStringValue(pref_name->c_str())); | 375 result_value.Append(Value::CreateStringValue(pref_name->c_str())); |
355 | 376 |
356 DictionaryValue* dict = new DictionaryValue; | 377 DictionaryValue* dict = new DictionaryValue; |
357 dict->Set("value", pref->GetValue()->DeepCopy()); | 378 dict->Set("value", pref->GetValue()->DeepCopy()); |
358 dict->SetBoolean("managed", pref->IsManaged()); | 379 dict->SetBoolean("managed", pref->IsManaged()); |
359 result_value.Append(dict); | 380 result_value.Append(dict); |
360 | 381 |
361 web_ui_->CallJavascriptFunction(WideToASCII(callback_function), | 382 web_ui_->CallJavascriptFunction(WideToASCII(callback_function), |
362 result_value); | 383 result_value); |
363 } | 384 } |
364 } | 385 } |
365 } | 386 } |
OLD | NEW |