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> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
14 #include "base/json/json_reader.h" | 14 #include "base/json/json_reader.h" |
| 15 #include "base/memory/ptr_util.h" |
15 #include "base/metrics/user_metrics.h" | 16 #include "base/metrics/user_metrics.h" |
16 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
17 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
19 #include "base/values.h" | 20 #include "base/values.h" |
20 #include "build/build_config.h" | 21 #include "build/build_config.h" |
21 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
22 #include "chrome/browser/chrome_notification_types.h" | 23 #include "chrome/browser/chrome_notification_types.h" |
23 #include "chrome/browser/extensions/extension_service.h" | 24 #include "chrome/browser/extensions/extension_service.h" |
24 #include "chrome/browser/extensions/extension_util.h" | 25 #include "chrome/browser/extensions/extension_util.h" |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 void CoreOptionsHandler::HandleInitialize(const base::ListValue* args) { | 246 void CoreOptionsHandler::HandleInitialize(const base::ListValue* args) { |
246 DCHECK(handlers_host_); | 247 DCHECK(handlers_host_); |
247 handlers_host_->InitializeHandlers(); | 248 handlers_host_->InitializeHandlers(); |
248 } | 249 } |
249 | 250 |
250 void CoreOptionsHandler::OnFinishedLoading(const base::ListValue* args) { | 251 void CoreOptionsHandler::OnFinishedLoading(const base::ListValue* args) { |
251 DCHECK(handlers_host_); | 252 DCHECK(handlers_host_); |
252 handlers_host_->OnFinishedLoading(); | 253 handlers_host_->OnFinishedLoading(); |
253 } | 254 } |
254 | 255 |
255 base::Value* CoreOptionsHandler::FetchPref(const std::string& pref_name) { | 256 std::unique_ptr<base::Value> CoreOptionsHandler::FetchPref( |
| 257 const std::string& pref_name) { |
256 return CreateValueForPref(pref_name, std::string()); | 258 return CreateValueForPref(pref_name, std::string()); |
257 } | 259 } |
258 | 260 |
259 void CoreOptionsHandler::ObservePref(const std::string& pref_name) { | 261 void CoreOptionsHandler::ObservePref(const std::string& pref_name) { |
260 if (g_browser_process->local_state()->FindPreference(pref_name)) { | 262 if (g_browser_process->local_state()->FindPreference(pref_name)) { |
261 local_state_registrar_.Add( | 263 local_state_registrar_.Add( |
262 pref_name, | 264 pref_name, |
263 base::Bind(&CoreOptionsHandler::OnPreferenceChanged, | 265 base::Bind(&CoreOptionsHandler::OnPreferenceChanged, |
264 base::Unretained(this), | 266 base::Unretained(this), |
265 local_state_registrar_.prefs())); | 267 local_state_registrar_.prefs())); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 base::ListValue result_value; | 359 base::ListValue result_value; |
358 result_value.AppendString(name); | 360 result_value.AppendString(name); |
359 result_value.Append(std::move(value)); | 361 result_value.Append(std::move(value)); |
360 for (PreferenceCallbackMap::const_iterator iter = range.first; | 362 for (PreferenceCallbackMap::const_iterator iter = range.first; |
361 iter != range.second; ++iter) { | 363 iter != range.second; ++iter) { |
362 const std::string& callback_function = iter->second; | 364 const std::string& callback_function = iter->second; |
363 web_ui()->CallJavascriptFunctionUnsafe(callback_function, result_value); | 365 web_ui()->CallJavascriptFunctionUnsafe(callback_function, result_value); |
364 } | 366 } |
365 } | 367 } |
366 | 368 |
367 base::Value* CoreOptionsHandler::CreateValueForPref( | 369 std::unique_ptr<base::Value> CoreOptionsHandler::CreateValueForPref( |
368 const std::string& pref_name, | 370 const std::string& pref_name, |
369 const std::string& controlling_pref_name) { | 371 const std::string& controlling_pref_name) { |
370 const PrefService* pref_service = FindServiceForPref(pref_name); | 372 const PrefService* pref_service = FindServiceForPref(pref_name); |
371 const PrefService::Preference* pref = | 373 const PrefService::Preference* pref = |
372 pref_service->FindPreference(pref_name); | 374 pref_service->FindPreference(pref_name); |
373 if (!pref) { | 375 if (!pref) { |
374 NOTREACHED(); | 376 NOTREACHED(); |
375 return new base::Value(); | 377 return base::MakeUnique<base::Value>(); |
376 } | 378 } |
377 const PrefService::Preference* controlling_pref = | 379 const PrefService::Preference* controlling_pref = |
378 pref_service->FindPreference(controlling_pref_name); | 380 pref_service->FindPreference(controlling_pref_name); |
379 if (!controlling_pref) | 381 if (!controlling_pref) |
380 controlling_pref = pref; | 382 controlling_pref = pref; |
381 | 383 |
382 base::DictionaryValue* dict = new base::DictionaryValue; | 384 auto dict = base::MakeUnique<base::DictionaryValue>(); |
383 dict->Set("value", pref->GetValue()->DeepCopy()); | 385 dict->Set("value", base::MakeUnique<base::Value>(*pref->GetValue())); |
384 if (controlling_pref->IsManaged()) { | 386 if (controlling_pref->IsManaged()) { |
385 dict->SetString("controlledBy", "policy"); | 387 dict->SetString("controlledBy", "policy"); |
386 } else if (controlling_pref->IsExtensionControlled() && | 388 } else if (controlling_pref->IsExtensionControlled() && |
387 CanSetExtensionControlledPrefValue(controlling_pref)) { | 389 CanSetExtensionControlledPrefValue(controlling_pref)) { |
388 Profile* profile = Profile::FromWebUI(web_ui()); | 390 Profile* profile = Profile::FromWebUI(web_ui()); |
389 ExtensionPrefValueMap* extension_pref_value_map = | 391 ExtensionPrefValueMap* extension_pref_value_map = |
390 ExtensionPrefValueMapFactory::GetForBrowserContext(profile); | 392 ExtensionPrefValueMapFactory::GetForBrowserContext(profile); |
391 std::string extension_id = | 393 std::string extension_id = |
392 extension_pref_value_map->GetExtensionControllingPref( | 394 extension_pref_value_map->GetExtensionControllingPref( |
393 controlling_pref->name()); | 395 controlling_pref->name()); |
394 | 396 |
395 const extensions::Extension* extension = | 397 const extensions::Extension* extension = |
396 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( | 398 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( |
397 extension_id, extensions::ExtensionRegistry::EVERYTHING); | 399 extension_id, extensions::ExtensionRegistry::EVERYTHING); |
398 if (extension) { | 400 if (extension) { |
399 dict->SetString("controlledBy", "extension"); | 401 dict->SetString("controlledBy", "extension"); |
400 dict->Set("extension", | 402 dict->Set("extension", extensions::util::GetExtensionInfo(extension)); |
401 extensions::util::GetExtensionInfo(extension).release()); | |
402 } | 403 } |
403 } else if (controlling_pref->IsRecommended()) { | 404 } else if (controlling_pref->IsRecommended()) { |
404 dict->SetString("controlledBy", "recommended"); | 405 dict->SetString("controlledBy", "recommended"); |
405 } | 406 } |
406 | 407 |
407 const base::Value* recommended_value = | 408 const base::Value* recommended_value = |
408 controlling_pref->GetRecommendedValue(); | 409 controlling_pref->GetRecommendedValue(); |
409 if (recommended_value) | 410 if (recommended_value) |
410 dict->Set("recommendedValue", recommended_value->DeepCopy()); | 411 dict->Set("recommendedValue", |
| 412 base::MakeUnique<base::Value>(*recommended_value)); |
411 dict->SetBoolean("disabled", !controlling_pref->IsUserModifiable()); | 413 dict->SetBoolean("disabled", !controlling_pref->IsUserModifiable()); |
412 return dict; | 414 return std::move(dict); |
413 } | 415 } |
414 | 416 |
415 PrefService* CoreOptionsHandler::FindServiceForPref( | 417 PrefService* CoreOptionsHandler::FindServiceForPref( |
416 const std::string& pref_name) { | 418 const std::string& pref_name) { |
417 // Proxy is a peculiar case: on ChromeOS, settings exist in both user | 419 // Proxy is a peculiar case: on ChromeOS, settings exist in both user |
418 // prefs and local state, but chrome://settings should affect only user prefs. | 420 // prefs and local state, but chrome://settings should affect only user prefs. |
419 // Elsewhere the proxy settings are stored in local state. | 421 // Elsewhere the proxy settings are stored in local state. |
420 // See http://crbug.com/157147 | 422 // See http://crbug.com/157147 |
421 PrefService* user_prefs = Profile::FromWebUI(web_ui())->GetPrefs(); | 423 PrefService* user_prefs = Profile::FromWebUI(web_ui())->GetPrefs(); |
422 if (pref_name == proxy_config::prefs::kProxy) | 424 if (pref_name == proxy_config::prefs::kProxy) |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 plugin_status_pref_setter_.IsPepperFlashSettingsEnabled()); | 656 plugin_status_pref_setter_.IsPepperFlashSettingsEnabled()); |
655 web_ui()->CallJavascriptFunctionUnsafe( | 657 web_ui()->CallJavascriptFunctionUnsafe( |
656 "options.OptionsPage.setPepperFlashSettingsEnabled", enabled); | 658 "options.OptionsPage.setPepperFlashSettingsEnabled", enabled); |
657 } | 659 } |
658 | 660 |
659 bool CoreOptionsHandler::IsUserUnsupervised(const base::Value* to_value) { | 661 bool CoreOptionsHandler::IsUserUnsupervised(const base::Value* to_value) { |
660 return !Profile::FromWebUI(web_ui())->IsSupervised(); | 662 return !Profile::FromWebUI(web_ui())->IsSupervised(); |
661 } | 663 } |
662 | 664 |
663 } // namespace options | 665 } // namespace options |
OLD | NEW |