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 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
334 | 343 |
335 ClearPref(pref_name, metric); | 344 ClearPref(pref_name, metric); |
336 } | 345 } |
337 | 346 |
338 void CoreOptionsHandler::HandleUserMetricsAction(const ListValue* args) { | 347 void CoreOptionsHandler::HandleUserMetricsAction(const ListValue* args) { |
339 std::string metric = UTF16ToUTF8(ExtractStringValue(args)); | 348 std::string metric = UTF16ToUTF8(ExtractStringValue(args)); |
340 if (!metric.empty()) | 349 if (!metric.empty()) |
341 UserMetricsRecordAction(UserMetricsAction(metric.c_str())); | 350 UserMetricsRecordAction(UserMetricsAction(metric.c_str())); |
342 } | 351 } |
343 | 352 |
353 void CoreOptionsHandler::UpdateClearPluginLSOData() { | |
354 scoped_ptr<Value> enabled( | |
355 Value::CreateBooleanValue(clear_plugin_lso_data_enabled_.GetValue())); | |
356 web_ui_->CallJavascriptFunction( | |
357 "OptionsPage.setClearPluginLSODataEnabled", *enabled); | |
358 } | |
359 | |
344 void CoreOptionsHandler::NotifyPrefChanged(const std::string* pref_name) { | 360 void CoreOptionsHandler::NotifyPrefChanged(const std::string* pref_name) { |
361 if (*pref_name == prefs::kClearPluginLSODataEnabled) | |
Evan Stade
2011/04/18 17:43:05
can you comment that this is part of local_state a
| |
362 UpdateClearPluginLSOData(); | |
Evan Stade
2011/04/18 17:43:05
early return
| |
363 | |
345 PrefService* pref_service = web_ui_->GetProfile()->GetPrefs(); | 364 PrefService* pref_service = web_ui_->GetProfile()->GetPrefs(); |
346 const PrefService::Preference* pref = | 365 const PrefService::Preference* pref = |
347 pref_service->FindPreference(pref_name->c_str()); | 366 pref_service->FindPreference(pref_name->c_str()); |
348 if (pref) { | 367 if (pref) { |
349 for (PreferenceCallbackMap::const_iterator iter = | 368 for (PreferenceCallbackMap::const_iterator iter = |
350 pref_callback_map_.find(*pref_name); | 369 pref_callback_map_.find(*pref_name); |
351 iter != pref_callback_map_.end(); ++iter) { | 370 iter != pref_callback_map_.end(); ++iter) { |
352 const std::wstring& callback_function = iter->second; | 371 const std::wstring& callback_function = iter->second; |
353 ListValue result_value; | 372 ListValue result_value; |
354 result_value.Append(Value::CreateStringValue(pref_name->c_str())); | 373 result_value.Append(Value::CreateStringValue(pref_name->c_str())); |
355 | 374 |
356 DictionaryValue* dict = new DictionaryValue; | 375 DictionaryValue* dict = new DictionaryValue; |
357 dict->Set("value", pref->GetValue()->DeepCopy()); | 376 dict->Set("value", pref->GetValue()->DeepCopy()); |
358 dict->SetBoolean("managed", pref->IsManaged()); | 377 dict->SetBoolean("managed", pref->IsManaged()); |
359 result_value.Append(dict); | 378 result_value.Append(dict); |
360 | 379 |
361 web_ui_->CallJavascriptFunction(WideToASCII(callback_function), | 380 web_ui_->CallJavascriptFunction(WideToASCII(callback_function), |
362 result_value); | 381 result_value); |
363 } | 382 } |
364 } | 383 } |
365 } | 384 } |
OLD | NEW |