| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 const PrefService::Preference* pref = | 295 const PrefService::Preference* pref = |
| 296 pref_service->FindPreference(pref_name); | 296 pref_service->FindPreference(pref_name); |
| 297 if ((pref && !pref->IsUserModifiable()) || !iter->second.Run(value)) { | 297 if ((pref && !pref->IsUserModifiable()) || !iter->second.Run(value)) { |
| 298 // Reject the change; remind the page of the true value. | 298 // Reject the change; remind the page of the true value. |
| 299 NotifyPrefChanged(pref_name, std::string()); | 299 NotifyPrefChanged(pref_name, std::string()); |
| 300 return; | 300 return; |
| 301 } | 301 } |
| 302 } | 302 } |
| 303 | 303 |
| 304 switch (value->GetType()) { | 304 switch (value->GetType()) { |
| 305 case base::Value::TYPE_BOOLEAN: | 305 case base::Value::Type::BOOLEAN: |
| 306 case base::Value::TYPE_INTEGER: | 306 case base::Value::Type::INTEGER: |
| 307 case base::Value::TYPE_DOUBLE: | 307 case base::Value::Type::DOUBLE: |
| 308 case base::Value::TYPE_STRING: | 308 case base::Value::Type::STRING: |
| 309 case base::Value::TYPE_LIST: | 309 case base::Value::Type::LIST: |
| 310 pref_service->Set(pref_name, *value); | 310 pref_service->Set(pref_name, *value); |
| 311 break; | 311 break; |
| 312 | 312 |
| 313 default: | 313 default: |
| 314 NOTREACHED(); | 314 NOTREACHED(); |
| 315 return; | 315 return; |
| 316 } | 316 } |
| 317 | 317 |
| 318 ProcessUserMetric(value, metric); | 318 ProcessUserMetric(value, metric); |
| 319 } | 319 } |
| 320 | 320 |
| 321 void CoreOptionsHandler::ClearPref(const std::string& pref_name, | 321 void CoreOptionsHandler::ClearPref(const std::string& pref_name, |
| 322 const std::string& metric) { | 322 const std::string& metric) { |
| 323 PrefService* pref_service = FindServiceForPref(pref_name); | 323 PrefService* pref_service = FindServiceForPref(pref_name); |
| 324 pref_service->ClearPref(pref_name); | 324 pref_service->ClearPref(pref_name); |
| 325 | 325 |
| 326 if (!metric.empty()) | 326 if (!metric.empty()) |
| 327 content::RecordComputedAction(metric); | 327 content::RecordComputedAction(metric); |
| 328 } | 328 } |
| 329 | 329 |
| 330 void CoreOptionsHandler::ProcessUserMetric(const base::Value* value, | 330 void CoreOptionsHandler::ProcessUserMetric(const base::Value* value, |
| 331 const std::string& metric) { | 331 const std::string& metric) { |
| 332 if (metric.empty()) | 332 if (metric.empty()) |
| 333 return; | 333 return; |
| 334 | 334 |
| 335 std::string metric_string = metric; | 335 std::string metric_string = metric; |
| 336 if (value->IsType(base::Value::TYPE_BOOLEAN)) { | 336 if (value->IsType(base::Value::Type::BOOLEAN)) { |
| 337 bool bool_value; | 337 bool bool_value; |
| 338 CHECK(value->GetAsBoolean(&bool_value)); | 338 CHECK(value->GetAsBoolean(&bool_value)); |
| 339 metric_string += bool_value ? "_Enable" : "_Disable"; | 339 metric_string += bool_value ? "_Enable" : "_Disable"; |
| 340 } | 340 } |
| 341 | 341 |
| 342 content::RecordComputedAction(metric_string); | 342 content::RecordComputedAction(metric_string); |
| 343 } | 343 } |
| 344 | 344 |
| 345 void CoreOptionsHandler::NotifyPrefChanged( | 345 void CoreOptionsHandler::NotifyPrefChanged( |
| 346 const std::string& pref_name, | 346 const std::string& pref_name, |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 return user_prefs; | 440 return user_prefs; |
| 441 } | 441 } |
| 442 | 442 |
| 443 void CoreOptionsHandler::HandleFetchPrefs(const base::ListValue* args) { | 443 void CoreOptionsHandler::HandleFetchPrefs(const base::ListValue* args) { |
| 444 // First param is name of callback function, so, there needs to be at least | 444 // First param is name of callback function, so, there needs to be at least |
| 445 // one more element for the actual preference identifier. | 445 // one more element for the actual preference identifier. |
| 446 DCHECK_GE(static_cast<int>(args->GetSize()), 2); | 446 DCHECK_GE(static_cast<int>(args->GetSize()), 2); |
| 447 | 447 |
| 448 // Get callback JS function name. | 448 // Get callback JS function name. |
| 449 const base::Value* callback; | 449 const base::Value* callback; |
| 450 if (!args->Get(0, &callback) || !callback->IsType(base::Value::TYPE_STRING)) | 450 if (!args->Get(0, &callback) || !callback->IsType(base::Value::Type::STRING)) |
| 451 return; | 451 return; |
| 452 | 452 |
| 453 base::string16 callback_function; | 453 base::string16 callback_function; |
| 454 if (!callback->GetAsString(&callback_function)) | 454 if (!callback->GetAsString(&callback_function)) |
| 455 return; | 455 return; |
| 456 | 456 |
| 457 // Get the list of name for prefs to build the response dictionary. | 457 // Get the list of name for prefs to build the response dictionary. |
| 458 base::DictionaryValue result_value; | 458 base::DictionaryValue result_value; |
| 459 const base::Value* list_member; | 459 const base::Value* list_member; |
| 460 | 460 |
| 461 for (size_t i = 1; i < args->GetSize(); i++) { | 461 for (size_t i = 1; i < args->GetSize(); i++) { |
| 462 if (!args->Get(i, &list_member)) | 462 if (!args->Get(i, &list_member)) |
| 463 break; | 463 break; |
| 464 | 464 |
| 465 if (!list_member->IsType(base::Value::TYPE_STRING)) | 465 if (!list_member->IsType(base::Value::Type::STRING)) |
| 466 continue; | 466 continue; |
| 467 | 467 |
| 468 std::string pref_name; | 468 std::string pref_name; |
| 469 if (!list_member->GetAsString(&pref_name)) | 469 if (!list_member->GetAsString(&pref_name)) |
| 470 continue; | 470 continue; |
| 471 | 471 |
| 472 result_value.Set(pref_name, FetchPref(pref_name)); | 472 result_value.Set(pref_name, FetchPref(pref_name)); |
| 473 } | 473 } |
| 474 web_ui()->CallJavascriptFunctionUnsafe(base::UTF16ToASCII(callback_function), | 474 web_ui()->CallJavascriptFunctionUnsafe(base::UTF16ToASCII(callback_function), |
| 475 result_value); | 475 result_value); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 486 return; | 486 return; |
| 487 | 487 |
| 488 // Get all other parameters - pref identifiers. | 488 // Get all other parameters - pref identifiers. |
| 489 for (size_t i = 1; i < args->GetSize(); i++) { | 489 for (size_t i = 1; i < args->GetSize(); i++) { |
| 490 const base::Value* list_member; | 490 const base::Value* list_member; |
| 491 if (!args->Get(i, &list_member)) | 491 if (!args->Get(i, &list_member)) |
| 492 break; | 492 break; |
| 493 | 493 |
| 494 // Just ignore bad pref identifiers for now. | 494 // Just ignore bad pref identifiers for now. |
| 495 std::string pref_name; | 495 std::string pref_name; |
| 496 if (!list_member->IsType(base::Value::TYPE_STRING) || | 496 if (!list_member->IsType(base::Value::Type::STRING) || |
| 497 !list_member->GetAsString(&pref_name)) | 497 !list_member->GetAsString(&pref_name)) |
| 498 continue; | 498 continue; |
| 499 | 499 |
| 500 if (pref_callback_map_.find(pref_name) == pref_callback_map_.end()) | 500 if (pref_callback_map_.find(pref_name) == pref_callback_map_.end()) |
| 501 ObservePref(pref_name); | 501 ObservePref(pref_name); |
| 502 | 502 |
| 503 pref_callback_map_.insert( | 503 pref_callback_map_.insert( |
| 504 PreferenceCallbackMap::value_type(pref_name, callback_func_name)); | 504 PreferenceCallbackMap::value_type(pref_name, callback_func_name)); |
| 505 } | 505 } |
| 506 } | 506 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 return; | 538 return; |
| 539 | 539 |
| 540 const base::Value* value; | 540 const base::Value* value; |
| 541 if (!args->Get(1, &value)) | 541 if (!args->Get(1, &value)) |
| 542 return; | 542 return; |
| 543 | 543 |
| 544 std::unique_ptr<base::Value> temp_value; | 544 std::unique_ptr<base::Value> temp_value; |
| 545 | 545 |
| 546 switch (type) { | 546 switch (type) { |
| 547 case TYPE_BOOLEAN: | 547 case TYPE_BOOLEAN: |
| 548 if (!value->IsType(base::Value::TYPE_BOOLEAN)) { | 548 if (!value->IsType(base::Value::Type::BOOLEAN)) { |
| 549 NOTREACHED(); | 549 NOTREACHED(); |
| 550 return; | 550 return; |
| 551 } | 551 } |
| 552 break; | 552 break; |
| 553 case TYPE_INTEGER: { | 553 case TYPE_INTEGER: { |
| 554 // In JS all numbers are doubles. | 554 // In JS all numbers are doubles. |
| 555 double double_value; | 555 double double_value; |
| 556 if (!value->GetAsDouble(&double_value)) { | 556 if (!value->GetAsDouble(&double_value)) { |
| 557 NOTREACHED(); | 557 NOTREACHED(); |
| 558 return; | 558 return; |
| 559 } | 559 } |
| 560 int int_value = static_cast<int>(double_value); | 560 int int_value = static_cast<int>(double_value); |
| 561 temp_value.reset(new base::FundamentalValue(int_value)); | 561 temp_value.reset(new base::FundamentalValue(int_value)); |
| 562 value = temp_value.get(); | 562 value = temp_value.get(); |
| 563 break; | 563 break; |
| 564 } | 564 } |
| 565 case TYPE_DOUBLE: | 565 case TYPE_DOUBLE: |
| 566 if (!value->IsType(base::Value::TYPE_DOUBLE)) { | 566 if (!value->IsType(base::Value::Type::DOUBLE)) { |
| 567 NOTREACHED(); | 567 NOTREACHED(); |
| 568 return; | 568 return; |
| 569 } | 569 } |
| 570 break; | 570 break; |
| 571 case TYPE_STRING: | 571 case TYPE_STRING: |
| 572 if (!value->IsType(base::Value::TYPE_STRING)) { | 572 if (!value->IsType(base::Value::Type::STRING)) { |
| 573 NOTREACHED(); | 573 NOTREACHED(); |
| 574 return; | 574 return; |
| 575 } | 575 } |
| 576 break; | 576 break; |
| 577 case TYPE_URL: { | 577 case TYPE_URL: { |
| 578 std::string original; | 578 std::string original; |
| 579 if (!value->GetAsString(&original)) { | 579 if (!value->GetAsString(&original)) { |
| 580 NOTREACHED(); | 580 NOTREACHED(); |
| 581 return; | 581 return; |
| 582 } | 582 } |
| 583 GURL fixed = url_formatter::FixupURL(original, std::string()); | 583 GURL fixed = url_formatter::FixupURL(original, std::string()); |
| 584 temp_value.reset(new base::StringValue(fixed.spec())); | 584 temp_value.reset(new base::StringValue(fixed.spec())); |
| 585 value = temp_value.get(); | 585 value = temp_value.get(); |
| 586 break; | 586 break; |
| 587 } | 587 } |
| 588 case TYPE_LIST: { | 588 case TYPE_LIST: { |
| 589 // In case we have a List pref we got a JSON string. | 589 // In case we have a List pref we got a JSON string. |
| 590 std::string json_string; | 590 std::string json_string; |
| 591 if (!value->GetAsString(&json_string)) { | 591 if (!value->GetAsString(&json_string)) { |
| 592 NOTREACHED(); | 592 NOTREACHED(); |
| 593 return; | 593 return; |
| 594 } | 594 } |
| 595 temp_value = base::JSONReader::Read(json_string); | 595 temp_value = base::JSONReader::Read(json_string); |
| 596 value = temp_value.get(); | 596 value = temp_value.get(); |
| 597 if (!value || !value->IsType(base::Value::TYPE_LIST)) { | 597 if (!value || !value->IsType(base::Value::Type::LIST)) { |
| 598 NOTREACHED(); | 598 NOTREACHED(); |
| 599 return; | 599 return; |
| 600 } | 600 } |
| 601 break; | 601 break; |
| 602 } | 602 } |
| 603 default: | 603 default: |
| 604 NOTREACHED(); | 604 NOTREACHED(); |
| 605 } | 605 } |
| 606 | 606 |
| 607 std::string metric; | 607 std::string metric; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 plugin_status_pref_setter_.IsPepperFlashSettingsEnabled()); | 657 plugin_status_pref_setter_.IsPepperFlashSettingsEnabled()); |
| 658 web_ui()->CallJavascriptFunctionUnsafe( | 658 web_ui()->CallJavascriptFunctionUnsafe( |
| 659 "options.OptionsPage.setPepperFlashSettingsEnabled", enabled); | 659 "options.OptionsPage.setPepperFlashSettingsEnabled", enabled); |
| 660 } | 660 } |
| 661 | 661 |
| 662 bool CoreOptionsHandler::IsUserUnsupervised(const base::Value* to_value) { | 662 bool CoreOptionsHandler::IsUserUnsupervised(const base::Value* to_value) { |
| 663 return !Profile::FromWebUI(web_ui())->IsSupervised(); | 663 return !Profile::FromWebUI(web_ui())->IsSupervised(); |
| 664 } | 664 } |
| 665 | 665 |
| 666 } // namespace options | 666 } // namespace options |
| OLD | NEW |