Home | History | Annotate | Download | only in chromeos
      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
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/ui/webui/options/chromeos/system_options_handler.h"
      6 
      7 #include <string>
      8 
      9 #include "base/basictypes.h"
     10 #include "base/callback.h"
     11 #include "base/string_number_conversions.h"
     12 #include "base/utf_string_conversions.h"
     13 #include "base/values.h"
     14 #include "chrome/browser/browser_process.h"
     15 #include "chrome/browser/chromeos/language_preferences.h"
     16 #include "chrome/browser/prefs/pref_service.h"
     17 #include "chrome/browser/ui/webui/options/chromeos/system_settings_provider.h"
     18 #include "chrome/common/pref_names.h"
     19 #include "grit/chromium_strings.h"
     20 #include "grit/generated_resources.h"
     21 #include "grit/locale_settings.h"
     22 #include "grit/theme_resources.h"
     23 #include "ui/base/l10n/l10n_util.h"
     24 
     25 SystemOptionsHandler::SystemOptionsHandler()
     26     : chromeos::CrosOptionsPageUIHandler(
     27         new chromeos::SystemSettingsProvider()) {
     28 }
     29 
     30 SystemOptionsHandler::~SystemOptionsHandler() {
     31 }
     32 
     33 void SystemOptionsHandler::GetLocalizedValues(
     34     DictionaryValue* localized_strings) {
     35   DCHECK(localized_strings);
     36 
     37   RegisterTitle(localized_strings, "systemPage", IDS_OPTIONS_SYSTEM_TAB_LABEL);
     38   localized_strings->SetString("datetime_title",
     39       l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_SECTION_TITLE_DATETIME));
     40   localized_strings->SetString("timezone",
     41       l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_TIMEZONE_DESCRIPTION));
     42   localized_strings->SetString("use_24hour_clock",
     43       l10n_util::GetStringUTF16(
     44           IDS_OPTIONS_SETTINGS_USE_24HOUR_CLOCK_DESCRIPTION));
     45 
     46   localized_strings->SetString("touchpad",
     47       l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_SECTION_TITLE_TOUCHPAD));
     48   localized_strings->SetString("enable_tap_to_click",
     49       l10n_util::GetStringUTF16(
     50           IDS_OPTIONS_SETTINGS_TAP_TO_CLICK_ENABLED_DESCRIPTION));
     51   localized_strings->SetString("sensitivity",
     52       l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_SENSITIVITY_DESCRIPTION));
     53   localized_strings->SetString("sensitivity_less",
     54       l10n_util::GetStringUTF16(
     55           IDS_OPTIONS_SETTINGS_SENSITIVITY_LESS_DESCRIPTION));
     56   localized_strings->SetString("sensitivity_more",
     57       l10n_util::GetStringUTF16(
     58           IDS_OPTIONS_SETTINGS_SENSITIVITY_MORE_DESCRIPTION));
     59 
     60   localized_strings->SetString("language",
     61       l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_SECTION_TITLE_LANGUAGE));
     62   localized_strings->SetString("language_customize",
     63       l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_CUSTOMIZE));
     64   localized_strings->SetString("modifier_keys_customize",
     65       l10n_util::GetStringUTF16(
     66           IDS_OPTIONS_SETTINGS_LANGUAGES_MODIFIER_KEYS_CUSTOMIZE));
     67 
     68   localized_strings->SetString("accessibility_title",
     69       l10n_util::GetStringUTF16(
     70           IDS_OPTIONS_SETTINGS_SECTION_TITLE_ACCESSIBILITY));
     71   localized_strings->SetString("accessibility",
     72       l10n_util::GetStringUTF16(
     73           IDS_OPTIONS_SETTINGS_ACCESSIBILITY_DESCRIPTION));
     74 
     75   localized_strings->Set("timezoneList",
     76       reinterpret_cast<chromeos::SystemSettingsProvider*>(
     77           settings_provider_.get())->GetTimezoneList());
     78 }
     79 
     80 void SystemOptionsHandler::Initialize() {
     81   DCHECK(web_ui_);
     82   PrefService* pref_service = g_browser_process->local_state();
     83   bool acc_enabled = pref_service->GetBoolean(prefs::kAccessibilityEnabled);
     84   FundamentalValue checked(acc_enabled);
     85   web_ui_->CallJavascriptFunction(
     86       "options.SystemOptions.SetAccessibilityCheckboxState", checked);
     87 }
     88 
     89 void SystemOptionsHandler::RegisterMessages() {
     90   DCHECK(web_ui_);
     91   web_ui_->RegisterMessageCallback("accessibilityChange",
     92       NewCallback(this, &SystemOptionsHandler::AccessibilityChangeCallback));
     93 }
     94 
     95 void SystemOptionsHandler::AccessibilityChangeCallback(const ListValue* args) {
     96   std::string checked_str;
     97   args->GetString(0, &checked_str);
     98   bool accessibility_enabled = (checked_str == "true");
     99   PrefService* pref_service = g_browser_process->local_state();
    100   pref_service->SetBoolean(prefs::kAccessibilityEnabled, accessibility_enabled);
    101 }
    102