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" |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 DispatchPrefChangeNotification(pref_name, value.Pass()); | 278 DispatchPrefChangeNotification(pref_name, value.Pass()); |
279 } | 279 } |
280 | 280 |
281 void CoreOptionsHandler::DispatchPrefChangeNotification( | 281 void CoreOptionsHandler::DispatchPrefChangeNotification( |
282 const std::string& name, | 282 const std::string& name, |
283 scoped_ptr<base::Value> value) { | 283 scoped_ptr<base::Value> value) { |
284 std::pair<PreferenceCallbackMap::const_iterator, | 284 std::pair<PreferenceCallbackMap::const_iterator, |
285 PreferenceCallbackMap::const_iterator> range = | 285 PreferenceCallbackMap::const_iterator> range = |
286 pref_callback_map_.equal_range(name); | 286 pref_callback_map_.equal_range(name); |
287 ListValue result_value; | 287 ListValue result_value; |
288 result_value.Append(base::Value::CreateStringValue(name.c_str())); | 288 result_value.Append(new base::StringValue(name.c_str())); |
289 result_value.Append(value.release()); | 289 result_value.Append(value.release()); |
290 for (PreferenceCallbackMap::const_iterator iter = range.first; | 290 for (PreferenceCallbackMap::const_iterator iter = range.first; |
291 iter != range.second; ++iter) { | 291 iter != range.second; ++iter) { |
292 const std::string& callback_function = iter->second; | 292 const std::string& callback_function = iter->second; |
293 web_ui()->CallJavascriptFunction(callback_function, result_value); | 293 web_ui()->CallJavascriptFunction(callback_function, result_value); |
294 } | 294 } |
295 } | 295 } |
296 | 296 |
297 base::Value* CoreOptionsHandler::CreateValueForPref( | 297 base::Value* CoreOptionsHandler::CreateValueForPref( |
298 const std::string& pref_name, | 298 const std::string& pref_name, |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 | 456 |
457 switch (type) { | 457 switch (type) { |
458 case TYPE_BOOLEAN: | 458 case TYPE_BOOLEAN: |
459 CHECK_EQ(base::Value::TYPE_BOOLEAN, value->GetType()); | 459 CHECK_EQ(base::Value::TYPE_BOOLEAN, value->GetType()); |
460 break; | 460 break; |
461 case TYPE_INTEGER: { | 461 case TYPE_INTEGER: { |
462 // In JS all numbers are doubles. | 462 // In JS all numbers are doubles. |
463 double double_value; | 463 double double_value; |
464 CHECK(value->GetAsDouble(&double_value)); | 464 CHECK(value->GetAsDouble(&double_value)); |
465 int int_value = static_cast<int>(double_value); | 465 int int_value = static_cast<int>(double_value); |
466 temp_value.reset(base::Value::CreateIntegerValue(int_value)); | 466 temp_value.reset(new base::FundamentalValue(int_value)); |
467 value = temp_value.get(); | 467 value = temp_value.get(); |
468 break; | 468 break; |
469 } | 469 } |
470 case TYPE_DOUBLE: | 470 case TYPE_DOUBLE: |
471 CHECK_EQ(base::Value::TYPE_DOUBLE, value->GetType()); | 471 CHECK_EQ(base::Value::TYPE_DOUBLE, value->GetType()); |
472 break; | 472 break; |
473 case TYPE_STRING: | 473 case TYPE_STRING: |
474 CHECK_EQ(base::Value::TYPE_STRING, value->GetType()); | 474 CHECK_EQ(base::Value::TYPE_STRING, value->GetType()); |
475 break; | 475 break; |
476 case TYPE_URL: { | 476 case TYPE_URL: { |
477 std::string original; | 477 std::string original; |
478 CHECK(value->GetAsString(&original)); | 478 CHECK(value->GetAsString(&original)); |
479 GURL fixed = URLFixerUpper::FixupURL(original, std::string()); | 479 GURL fixed = URLFixerUpper::FixupURL(original, std::string()); |
480 temp_value.reset(base::Value::CreateStringValue(fixed.spec())); | 480 temp_value.reset(new base::StringValue(fixed.spec())); |
481 value = temp_value.get(); | 481 value = temp_value.get(); |
482 break; | 482 break; |
483 } | 483 } |
484 case TYPE_LIST: { | 484 case TYPE_LIST: { |
485 // In case we have a List pref we got a JSON string. | 485 // In case we have a List pref we got a JSON string. |
486 std::string json_string; | 486 std::string json_string; |
487 CHECK(value->GetAsString(&json_string)); | 487 CHECK(value->GetAsString(&json_string)); |
488 temp_value.reset( | 488 temp_value.reset( |
489 base::JSONReader::Read(json_string)); | 489 base::JSONReader::Read(json_string)); |
490 value = temp_value.get(); | 490 value = temp_value.get(); |
(...skipping 26 matching lines...) Expand all Loading... |
517 ClearPref(pref_name, metric); | 517 ClearPref(pref_name, metric); |
518 } | 518 } |
519 | 519 |
520 void CoreOptionsHandler::HandleUserMetricsAction(const ListValue* args) { | 520 void CoreOptionsHandler::HandleUserMetricsAction(const ListValue* args) { |
521 std::string metric = UTF16ToUTF8(ExtractStringValue(args)); | 521 std::string metric = UTF16ToUTF8(ExtractStringValue(args)); |
522 if (!metric.empty()) | 522 if (!metric.empty()) |
523 content::RecordComputedAction(metric); | 523 content::RecordComputedAction(metric); |
524 } | 524 } |
525 | 525 |
526 void CoreOptionsHandler::UpdateClearPluginLSOData() { | 526 void CoreOptionsHandler::UpdateClearPluginLSOData() { |
527 scoped_ptr<base::Value> enabled( | 527 base::FundamentalValue enabled( |
528 base::Value::CreateBooleanValue( | 528 plugin_status_pref_setter_.IsClearPluginLSODataEnabled()); |
529 plugin_status_pref_setter_.IsClearPluginLSODataEnabled())); | |
530 web_ui()->CallJavascriptFunction( | 529 web_ui()->CallJavascriptFunction( |
531 "OptionsPage.setClearPluginLSODataEnabled", *enabled); | 530 "OptionsPage.setClearPluginLSODataEnabled", enabled); |
532 } | 531 } |
533 | 532 |
534 void CoreOptionsHandler::UpdatePepperFlashSettingsEnabled() { | 533 void CoreOptionsHandler::UpdatePepperFlashSettingsEnabled() { |
535 scoped_ptr<base::Value> enabled( | 534 base::FundamentalValue enabled( |
536 base::Value::CreateBooleanValue( | 535 plugin_status_pref_setter_.IsPepperFlashSettingsEnabled()); |
537 plugin_status_pref_setter_.IsPepperFlashSettingsEnabled())); | |
538 web_ui()->CallJavascriptFunction( | 536 web_ui()->CallJavascriptFunction( |
539 "OptionsPage.setPepperFlashSettingsEnabled", *enabled); | 537 "OptionsPage.setPepperFlashSettingsEnabled", enabled); |
540 } | 538 } |
541 | 539 |
542 } // namespace options | 540 } // namespace options |
OLD | NEW |