Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / core_options_handler.cc
blobc96baaa56e457ed153c68869af2f818f0b24bf3a
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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/webui/options/core_options_handler.h"
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/json/json_reader.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/strings/string16.h"
12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "base/values.h"
15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/chrome_notification_types.h"
17 #include "chrome/browser/extensions/extension_service.h"
18 #include "chrome/browser/extensions/extension_util.h"
19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/pref_names.h"
22 #include "chrome/common/url_constants.h"
23 #include "chrome/grit/chromium_strings.h"
24 #include "chrome/grit/generated_resources.h"
25 #include "chrome/grit/locale_settings.h"
26 #include "components/url_fixer/url_fixer.h"
27 #include "content/public/browser/notification_details.h"
28 #include "content/public/browser/notification_types.h"
29 #include "content/public/browser/user_metrics.h"
30 #include "content/public/browser/web_ui.h"
31 #include "extensions/browser/extension_pref_value_map.h"
32 #include "extensions/browser/extension_pref_value_map_factory.h"
33 #include "extensions/browser/extension_registry.h"
34 #include "extensions/browser/extension_system.h"
35 #include "extensions/common/extension.h"
36 #include "grit/components_strings.h"
37 #include "ui/base/l10n/l10n_util.h"
38 #include "url/gurl.h"
40 using base::UserMetricsAction;
42 namespace options {
44 namespace {
46 // Whether "controlledBy" property of pref value sent to options web UI needs to
47 // be set to "extension" when the preference is controlled by an extension.
48 bool CanSetExtensionControlledPrefValue(
49 const PrefService::Preference* preference) {
50 #if defined(OS_WIN)
51 // These have more obvious UI than the standard one for extension controlled
52 // values (an extension puzzle piece) on the settings page. To avoiding
53 // showing the extension puzzle piece for these settings, their "controlledBy"
54 // value should never be set to "extension".
55 return preference->name() != prefs::kURLsToRestoreOnStartup &&
56 preference->name() != prefs::kRestoreOnStartup &&
57 preference->name() != prefs::kHomePage &&
58 preference->name() != prefs::kHomePageIsNewTabPage;
59 #else
60 return true;
61 #endif
64 } // namespace
66 CoreOptionsHandler::CoreOptionsHandler()
67 : handlers_host_(NULL) {
70 CoreOptionsHandler::~CoreOptionsHandler() {}
72 void CoreOptionsHandler::InitializeHandler() {
73 Profile* profile = Profile::FromWebUI(web_ui());
75 plugin_status_pref_setter_.Init(
76 profile,
77 base::Bind(&CoreOptionsHandler::OnPreferenceChanged,
78 base::Unretained(this),
79 profile->GetPrefs()));
81 pref_change_filters_[prefs::kBrowserGuestModeEnabled] =
82 base::Bind(&CoreOptionsHandler::IsUserUnsupervised,
83 base::Unretained(this));
84 pref_change_filters_[prefs::kBrowserAddPersonEnabled] =
85 base::Bind(&CoreOptionsHandler::IsUserUnsupervised,
86 base::Unretained(this));
89 void CoreOptionsHandler::InitializePage() {
90 UpdateClearPluginLSOData();
91 UpdatePepperFlashSettingsEnabled();
94 void CoreOptionsHandler::GetLocalizedValues(
95 base::DictionaryValue* localized_strings) {
96 GetStaticLocalizedValues(localized_strings);
99 void CoreOptionsHandler::GetStaticLocalizedValues(
100 base::DictionaryValue* localized_strings) {
101 DCHECK(localized_strings);
102 // Main
103 localized_strings->SetString("optionsPageTitle",
104 l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE));
106 // Controlled settings bubble.
107 localized_strings->SetString("controlledSettingPolicy",
108 l10n_util::GetStringUTF16(IDS_OPTIONS_CONTROLLED_SETTING_POLICY));
109 localized_strings->SetString("controlledSettingExtension",
110 l10n_util::GetStringUTF16(IDS_OPTIONS_CONTROLLED_SETTING_EXTENSION));
111 localized_strings->SetString("controlledSettingExtensionWithName",
112 l10n_util::GetStringUTF16(
113 IDS_OPTIONS_CONTROLLED_SETTING_EXTENSION_WITH_NAME));
114 localized_strings->SetString("controlledSettingManageExtension",
115 l10n_util::GetStringUTF16(
116 IDS_OPTIONS_CONTROLLED_SETTING_MANAGE_EXTENSION));
117 localized_strings->SetString("controlledSettingDisableExtension",
118 l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE));
119 localized_strings->SetString("controlledSettingRecommended",
120 l10n_util::GetStringUTF16(IDS_OPTIONS_CONTROLLED_SETTING_RECOMMENDED));
121 localized_strings->SetString("controlledSettingHasRecommendation",
122 l10n_util::GetStringUTF16(
123 IDS_OPTIONS_CONTROLLED_SETTING_HAS_RECOMMENDATION));
124 localized_strings->SetString("controlledSettingFollowRecommendation",
125 l10n_util::GetStringUTF16(
126 IDS_OPTIONS_CONTROLLED_SETTING_FOLLOW_RECOMMENDATION));
127 localized_strings->SetString("controlledSettingsPolicy",
128 l10n_util::GetStringUTF16(IDS_OPTIONS_CONTROLLED_SETTINGS_POLICY));
129 localized_strings->SetString("controlledSettingsExtension",
130 l10n_util::GetStringUTF16(IDS_OPTIONS_CONTROLLED_SETTINGS_EXTENSION));
131 localized_strings->SetString("controlledSettingsExtensionWithName",
132 l10n_util::GetStringUTF16(
133 IDS_OPTIONS_CONTROLLED_SETTINGS_EXTENSION_WITH_NAME));
135 // Search
136 RegisterTitle(localized_strings, "searchPage", IDS_OPTIONS_SEARCH_PAGE_TITLE);
137 localized_strings->SetString("searchPlaceholder",
138 l10n_util::GetStringUTF16(IDS_OPTIONS_SEARCH_PLACEHOLDER));
139 localized_strings->SetString("searchPageNoMatches",
140 l10n_util::GetStringUTF16(IDS_OPTIONS_SEARCH_PAGE_NO_MATCHES));
141 localized_strings->SetString("searchPageHelpLabel",
142 l10n_util::GetStringUTF16(IDS_OPTIONS_SEARCH_PAGE_HELP_LABEL));
143 localized_strings->SetString("searchPageHelpTitle",
144 l10n_util::GetStringFUTF16(IDS_OPTIONS_SEARCH_PAGE_HELP_TITLE,
145 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
146 localized_strings->SetString("searchPageHelpURL",
147 chrome::kSettingsSearchHelpURL);
149 // About
150 localized_strings->SetBoolean("showAbout",
151 switches::AboutInSettingsEnabled());
152 localized_strings->SetString("aboutButton",
153 l10n_util::GetStringUTF16(IDS_ABOUT_BUTTON));
155 // Common
156 localized_strings->SetString("ok",
157 l10n_util::GetStringUTF16(IDS_OK));
158 localized_strings->SetString("cancel",
159 l10n_util::GetStringUTF16(IDS_CANCEL));
160 localized_strings->SetString("learnMore",
161 l10n_util::GetStringUTF16(IDS_LEARN_MORE));
162 localized_strings->SetString("close",
163 l10n_util::GetStringUTF16(IDS_CLOSE));
164 localized_strings->SetString("done",
165 l10n_util::GetStringUTF16(IDS_DONE));
166 localized_strings->SetString("deletableItemDeleteButtonTitle",
167 l10n_util::GetStringUTF16(IDS_OPTIONS_DELETABLE_ITEM_DELETE_BUTTON));
170 void CoreOptionsHandler::Uninitialize() {
171 std::string last_pref;
172 for (PreferenceCallbackMap::const_iterator iter = pref_callback_map_.begin();
173 iter != pref_callback_map_.end();
174 ++iter) {
175 if (last_pref != iter->first) {
176 StopObservingPref(iter->first);
177 last_pref = iter->first;
182 void CoreOptionsHandler::OnPreferenceChanged(PrefService* service,
183 const std::string& pref_name) {
184 if (pref_name == prefs::kClearPluginLSODataEnabled) {
185 // This preference is stored in Local State, not in the user preferences.
186 UpdateClearPluginLSOData();
187 return;
189 if (pref_name == prefs::kPepperFlashSettingsEnabled) {
190 UpdatePepperFlashSettingsEnabled();
191 return;
193 NotifyPrefChanged(pref_name, std::string());
196 void CoreOptionsHandler::RegisterMessages() {
197 registrar_.Init(Profile::FromWebUI(web_ui())->GetPrefs());
198 local_state_registrar_.Init(g_browser_process->local_state());
200 web_ui()->RegisterMessageCallback("coreOptionsInitialize",
201 base::Bind(&CoreOptionsHandler::HandleInitialize,
202 base::Unretained(this)));
203 web_ui()->RegisterMessageCallback("onFinishedLoadingOptions",
204 base::Bind(&CoreOptionsHandler::OnFinishedLoading,
205 base::Unretained(this)));
206 web_ui()->RegisterMessageCallback("fetchPrefs",
207 base::Bind(&CoreOptionsHandler::HandleFetchPrefs,
208 base::Unretained(this)));
209 web_ui()->RegisterMessageCallback("observePrefs",
210 base::Bind(&CoreOptionsHandler::HandleObservePrefs,
211 base::Unretained(this)));
212 web_ui()->RegisterMessageCallback("setBooleanPref",
213 base::Bind(&CoreOptionsHandler::HandleSetBooleanPref,
214 base::Unretained(this)));
215 web_ui()->RegisterMessageCallback("setIntegerPref",
216 base::Bind(&CoreOptionsHandler::HandleSetIntegerPref,
217 base::Unretained(this)));
218 web_ui()->RegisterMessageCallback("setDoublePref",
219 base::Bind(&CoreOptionsHandler::HandleSetDoublePref,
220 base::Unretained(this)));
221 web_ui()->RegisterMessageCallback("setStringPref",
222 base::Bind(&CoreOptionsHandler::HandleSetStringPref,
223 base::Unretained(this)));
224 web_ui()->RegisterMessageCallback("setURLPref",
225 base::Bind(&CoreOptionsHandler::HandleSetURLPref,
226 base::Unretained(this)));
227 web_ui()->RegisterMessageCallback("setListPref",
228 base::Bind(&CoreOptionsHandler::HandleSetListPref,
229 base::Unretained(this)));
230 web_ui()->RegisterMessageCallback("clearPref",
231 base::Bind(&CoreOptionsHandler::HandleClearPref,
232 base::Unretained(this)));
233 web_ui()->RegisterMessageCallback("coreOptionsUserMetricsAction",
234 base::Bind(&CoreOptionsHandler::HandleUserMetricsAction,
235 base::Unretained(this)));
236 web_ui()->RegisterMessageCallback("disableExtension",
237 base::Bind(&CoreOptionsHandler::HandleDisableExtension,
238 base::Unretained(this)));
241 void CoreOptionsHandler::HandleInitialize(const base::ListValue* args) {
242 DCHECK(handlers_host_);
243 handlers_host_->InitializeHandlers();
246 void CoreOptionsHandler::OnFinishedLoading(const base::ListValue* args) {
247 DCHECK(handlers_host_);
248 handlers_host_->OnFinishedLoading();
251 base::Value* CoreOptionsHandler::FetchPref(const std::string& pref_name) {
252 return CreateValueForPref(pref_name, std::string());
255 void CoreOptionsHandler::ObservePref(const std::string& pref_name) {
256 if (g_browser_process->local_state()->FindPreference(pref_name.c_str())) {
257 local_state_registrar_.Add(
258 pref_name.c_str(),
259 base::Bind(&CoreOptionsHandler::OnPreferenceChanged,
260 base::Unretained(this),
261 local_state_registrar_.prefs()));
263 // TODO(pneubeck): change this to if/else once kProxy is only used as a user
264 // pref. Currently, it is both a user and a local state pref.
265 if (Profile::FromWebUI(web_ui())->GetPrefs()->FindPreference(
266 pref_name.c_str())) {
267 registrar_.Add(
268 pref_name.c_str(),
269 base::Bind(&CoreOptionsHandler::OnPreferenceChanged,
270 base::Unretained(this),
271 registrar_.prefs()));
275 void CoreOptionsHandler::StopObservingPref(const std::string& pref_name) {
276 if (g_browser_process->local_state()->FindPreference(pref_name.c_str()))
277 local_state_registrar_.Remove(pref_name.c_str());
278 else
279 registrar_.Remove(pref_name.c_str());
282 void CoreOptionsHandler::SetPref(const std::string& pref_name,
283 const base::Value* value,
284 const std::string& metric) {
285 PrefService* pref_service = FindServiceForPref(pref_name);
286 PrefChangeFilterMap::iterator iter = pref_change_filters_.find(pref_name);
287 if (iter != pref_change_filters_.end()) {
288 // Also check if the pref is user modifiable (don't even try to run the
289 // filter function if the user is not allowed to change the pref).
290 const PrefService::Preference* pref =
291 pref_service->FindPreference(pref_name.c_str());
292 if ((pref && !pref->IsUserModifiable()) || !iter->second.Run(value)) {
293 // Reject the change; remind the page of the true value.
294 NotifyPrefChanged(pref_name, std::string());
295 return;
299 switch (value->GetType()) {
300 case base::Value::TYPE_BOOLEAN:
301 case base::Value::TYPE_INTEGER:
302 case base::Value::TYPE_DOUBLE:
303 case base::Value::TYPE_STRING:
304 case base::Value::TYPE_LIST:
305 pref_service->Set(pref_name.c_str(), *value);
306 break;
308 default:
309 NOTREACHED();
310 return;
313 ProcessUserMetric(value, metric);
316 void CoreOptionsHandler::ClearPref(const std::string& pref_name,
317 const std::string& metric) {
318 PrefService* pref_service = FindServiceForPref(pref_name);
319 pref_service->ClearPref(pref_name.c_str());
321 if (!metric.empty())
322 content::RecordComputedAction(metric);
325 void CoreOptionsHandler::ProcessUserMetric(const base::Value* value,
326 const std::string& metric) {
327 if (metric.empty())
328 return;
330 std::string metric_string = metric;
331 if (value->IsType(base::Value::TYPE_BOOLEAN)) {
332 bool bool_value;
333 CHECK(value->GetAsBoolean(&bool_value));
334 metric_string += bool_value ? "_Enable" : "_Disable";
337 content::RecordComputedAction(metric_string);
340 void CoreOptionsHandler::NotifyPrefChanged(
341 const std::string& pref_name,
342 const std::string& controlling_pref_name) {
343 scoped_ptr<base::Value> value(
344 CreateValueForPref(pref_name, controlling_pref_name));
345 DispatchPrefChangeNotification(pref_name, value.Pass());
348 void CoreOptionsHandler::DispatchPrefChangeNotification(
349 const std::string& name,
350 scoped_ptr<base::Value> value) {
351 std::pair<PreferenceCallbackMap::const_iterator,
352 PreferenceCallbackMap::const_iterator> range =
353 pref_callback_map_.equal_range(name);
354 base::ListValue result_value;
355 result_value.Append(new base::StringValue(name.c_str()));
356 result_value.Append(value.release());
357 for (PreferenceCallbackMap::const_iterator iter = range.first;
358 iter != range.second; ++iter) {
359 const std::string& callback_function = iter->second;
360 web_ui()->CallJavascriptFunction(callback_function, result_value);
364 base::Value* CoreOptionsHandler::CreateValueForPref(
365 const std::string& pref_name,
366 const std::string& controlling_pref_name) {
367 const PrefService* pref_service = FindServiceForPref(pref_name.c_str());
368 const PrefService::Preference* pref =
369 pref_service->FindPreference(pref_name.c_str());
370 if (!pref) {
371 NOTREACHED();
372 return base::Value::CreateNullValue().release();
374 const PrefService::Preference* controlling_pref =
375 pref_service->FindPreference(controlling_pref_name.c_str());
376 if (!controlling_pref)
377 controlling_pref = pref;
379 base::DictionaryValue* dict = new base::DictionaryValue;
380 dict->Set("value", pref->GetValue()->DeepCopy());
381 if (controlling_pref->IsManaged()) {
382 dict->SetString("controlledBy", "policy");
383 } else if (controlling_pref->IsExtensionControlled() &&
384 CanSetExtensionControlledPrefValue(controlling_pref)) {
385 Profile* profile = Profile::FromWebUI(web_ui());
386 ExtensionPrefValueMap* extension_pref_value_map =
387 ExtensionPrefValueMapFactory::GetForBrowserContext(profile);
388 std::string extension_id =
389 extension_pref_value_map->GetExtensionControllingPref(
390 controlling_pref->name());
392 const extensions::Extension* extension =
393 extensions::ExtensionRegistry::Get(profile)->GetExtensionById(
394 extension_id, extensions::ExtensionRegistry::EVERYTHING);
395 if (extension) {
396 dict->SetString("controlledBy", "extension");
397 dict->Set("extension",
398 extensions::util::GetExtensionInfo(extension).release());
400 } else if (controlling_pref->IsRecommended()) {
401 dict->SetString("controlledBy", "recommended");
404 const base::Value* recommended_value =
405 controlling_pref->GetRecommendedValue();
406 if (recommended_value)
407 dict->Set("recommendedValue", recommended_value->DeepCopy());
408 dict->SetBoolean("disabled", !controlling_pref->IsUserModifiable());
409 return dict;
412 PrefService* CoreOptionsHandler::FindServiceForPref(
413 const std::string& pref_name) {
414 // Proxy is a peculiar case: on ChromeOS, settings exist in both user
415 // prefs and local state, but chrome://settings should affect only user prefs.
416 // Elsewhere the proxy settings are stored in local state.
417 // See http://crbug.com/157147
418 PrefService* user_prefs = Profile::FromWebUI(web_ui())->GetPrefs();
419 if (pref_name == prefs::kProxy)
420 #if defined(OS_CHROMEOS)
421 return user_prefs;
422 #else
423 return g_browser_process->local_state();
424 #endif
426 // Find which PrefService contains the given pref. Pref names should not
427 // be duplicated across services, however if they are, prefer the user's
428 // prefs.
429 if (user_prefs->FindPreference(pref_name.c_str()))
430 return user_prefs;
432 if (g_browser_process->local_state()->FindPreference(pref_name.c_str()))
433 return g_browser_process->local_state();
435 return user_prefs;
438 void CoreOptionsHandler::HandleFetchPrefs(const base::ListValue* args) {
439 // First param is name of callback function, so, there needs to be at least
440 // one more element for the actual preference identifier.
441 DCHECK_GE(static_cast<int>(args->GetSize()), 2);
443 // Get callback JS function name.
444 const base::Value* callback;
445 if (!args->Get(0, &callback) || !callback->IsType(base::Value::TYPE_STRING))
446 return;
448 base::string16 callback_function;
449 if (!callback->GetAsString(&callback_function))
450 return;
452 // Get the list of name for prefs to build the response dictionary.
453 base::DictionaryValue result_value;
454 const base::Value* list_member;
456 for (size_t i = 1; i < args->GetSize(); i++) {
457 if (!args->Get(i, &list_member))
458 break;
460 if (!list_member->IsType(base::Value::TYPE_STRING))
461 continue;
463 std::string pref_name;
464 if (!list_member->GetAsString(&pref_name))
465 continue;
467 result_value.Set(pref_name.c_str(), FetchPref(pref_name));
469 web_ui()->CallJavascriptFunction(base::UTF16ToASCII(callback_function),
470 result_value);
473 void CoreOptionsHandler::HandleObservePrefs(const base::ListValue* args) {
474 // First param is name is JS callback function name, the rest are pref
475 // identifiers that we are observing.
476 DCHECK_GE(static_cast<int>(args->GetSize()), 2);
478 // Get preference change callback function name.
479 std::string callback_func_name;
480 if (!args->GetString(0, &callback_func_name))
481 return;
483 // Get all other parameters - pref identifiers.
484 for (size_t i = 1; i < args->GetSize(); i++) {
485 const base::Value* list_member;
486 if (!args->Get(i, &list_member))
487 break;
489 // Just ignore bad pref identifiers for now.
490 std::string pref_name;
491 if (!list_member->IsType(base::Value::TYPE_STRING) ||
492 !list_member->GetAsString(&pref_name))
493 continue;
495 if (pref_callback_map_.find(pref_name) == pref_callback_map_.end())
496 ObservePref(pref_name);
498 pref_callback_map_.insert(
499 PreferenceCallbackMap::value_type(pref_name, callback_func_name));
503 void CoreOptionsHandler::HandleSetBooleanPref(const base::ListValue* args) {
504 HandleSetPref(args, TYPE_BOOLEAN);
507 void CoreOptionsHandler::HandleSetIntegerPref(const base::ListValue* args) {
508 HandleSetPref(args, TYPE_INTEGER);
511 void CoreOptionsHandler::HandleSetDoublePref(const base::ListValue* args) {
512 HandleSetPref(args, TYPE_DOUBLE);
515 void CoreOptionsHandler::HandleSetStringPref(const base::ListValue* args) {
516 HandleSetPref(args, TYPE_STRING);
519 void CoreOptionsHandler::HandleSetURLPref(const base::ListValue* args) {
520 HandleSetPref(args, TYPE_URL);
523 void CoreOptionsHandler::HandleSetListPref(const base::ListValue* args) {
524 HandleSetPref(args, TYPE_LIST);
527 void CoreOptionsHandler::HandleSetPref(const base::ListValue* args,
528 PrefType type) {
529 DCHECK_GT(static_cast<int>(args->GetSize()), 1);
531 std::string pref_name;
532 if (!args->GetString(0, &pref_name))
533 return;
535 const base::Value* value;
536 if (!args->Get(1, &value))
537 return;
539 scoped_ptr<base::Value> temp_value;
541 switch (type) {
542 case TYPE_BOOLEAN:
543 if (!value->IsType(base::Value::TYPE_BOOLEAN)) {
544 NOTREACHED();
545 return;
547 break;
548 case TYPE_INTEGER: {
549 // In JS all numbers are doubles.
550 double double_value;
551 if (!value->GetAsDouble(&double_value)) {
552 NOTREACHED();
553 return;
555 int int_value = static_cast<int>(double_value);
556 temp_value.reset(new base::FundamentalValue(int_value));
557 value = temp_value.get();
558 break;
560 case TYPE_DOUBLE:
561 if (!value->IsType(base::Value::TYPE_DOUBLE)) {
562 NOTREACHED();
563 return;
565 break;
566 case TYPE_STRING:
567 if (!value->IsType(base::Value::TYPE_STRING)) {
568 NOTREACHED();
569 return;
571 break;
572 case TYPE_URL: {
573 std::string original;
574 if (!value->GetAsString(&original)) {
575 NOTREACHED();
576 return;
578 GURL fixed = url_fixer::FixupURL(original, std::string());
579 temp_value.reset(new base::StringValue(fixed.spec()));
580 value = temp_value.get();
581 break;
583 case TYPE_LIST: {
584 // In case we have a List pref we got a JSON string.
585 std::string json_string;
586 if (!value->GetAsString(&json_string)) {
587 NOTREACHED();
588 return;
590 temp_value.reset(base::JSONReader::DeprecatedRead(json_string));
591 value = temp_value.get();
592 if (!value->IsType(base::Value::TYPE_LIST)) {
593 NOTREACHED();
594 return;
596 break;
598 default:
599 NOTREACHED();
602 std::string metric;
603 if (args->GetSize() > 2 && !args->GetString(2, &metric))
604 LOG(WARNING) << "Invalid metric parameter: " << pref_name;
605 SetPref(pref_name, value, metric);
608 void CoreOptionsHandler::HandleClearPref(const base::ListValue* args) {
609 DCHECK_GT(static_cast<int>(args->GetSize()), 0);
611 std::string pref_name;
612 if (!args->GetString(0, &pref_name))
613 return;
615 std::string metric;
616 if (args->GetSize() > 1) {
617 if (!args->GetString(1, &metric))
618 NOTREACHED();
621 ClearPref(pref_name, metric);
624 void CoreOptionsHandler::HandleUserMetricsAction(const base::ListValue* args) {
625 std::string metric = base::UTF16ToUTF8(ExtractStringValue(args));
626 if (!metric.empty())
627 content::RecordComputedAction(metric);
630 void CoreOptionsHandler::HandleDisableExtension(const base::ListValue* args) {
631 std::string extension_id;
632 if (args->GetString(0, &extension_id)) {
633 ExtensionService* extension_service = extensions::ExtensionSystem::Get(
634 Profile::FromWebUI(web_ui()))->extension_service();
635 DCHECK(extension_service);
636 extension_service->DisableExtension(
637 extension_id, extensions::Extension::DISABLE_USER_ACTION);
638 } else {
639 NOTREACHED();
643 void CoreOptionsHandler::UpdateClearPluginLSOData() {
644 base::FundamentalValue enabled(
645 plugin_status_pref_setter_.IsClearPluginLSODataEnabled());
646 web_ui()->CallJavascriptFunction(
647 "OptionsPage.setClearPluginLSODataEnabled", enabled);
650 void CoreOptionsHandler::UpdatePepperFlashSettingsEnabled() {
651 base::FundamentalValue enabled(
652 plugin_status_pref_setter_.IsPepperFlashSettingsEnabled());
653 web_ui()->CallJavascriptFunction(
654 "OptionsPage.setPepperFlashSettingsEnabled", enabled);
657 bool CoreOptionsHandler::IsUserUnsupervised(const base::Value* to_value) {
658 return !Profile::FromWebUI(web_ui())->IsSupervised();
661 } // namespace options