OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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/date_time_options_handler.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" |
| 9 #include "base/values.h" |
| 10 #include "chrome/browser/chromeos/set_time_dialog.h" |
| 11 #include "chromeos/dbus/dbus_thread_manager.h" |
| 12 #include "chromeos/dbus/system_clock_client.h" |
| 13 #include "content/public/browser/web_contents.h" |
| 14 #include "content/public/browser/web_contents_view.h" |
| 15 #include "content/public/browser/web_ui.h" |
| 16 #include "grit/generated_resources.h" |
| 17 #include "ui/base/l10n/l10n_util.h" |
| 18 |
| 19 namespace chromeos { |
| 20 namespace options { |
| 21 |
| 22 DateTimeOptionsHandler::DateTimeOptionsHandler() |
| 23 : can_set_time_(false), page_initialized_(false) { |
| 24 } |
| 25 |
| 26 DateTimeOptionsHandler::~DateTimeOptionsHandler() { |
| 27 DBusThreadManager::Get()->GetSystemClockClient()->RemoveObserver(this); |
| 28 } |
| 29 |
| 30 void DateTimeOptionsHandler::GetLocalizedValues( |
| 31 base::DictionaryValue* localized_strings) { |
| 32 DCHECK(localized_strings); |
| 33 |
| 34 localized_strings->SetString( |
| 35 "setTimeButton", |
| 36 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_SET_TIME_BUTTON)); |
| 37 localized_strings->SetString( |
| 38 "timeSyncedExplanation", |
| 39 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_TIME_SYNCED_EXPLANATION)); |
| 40 }; |
| 41 |
| 42 void DateTimeOptionsHandler::InitializeHandler() { |
| 43 SystemClockClient* system_clock_client = |
| 44 DBusThreadManager::Get()->GetSystemClockClient(); |
| 45 system_clock_client->AddObserver(this); |
| 46 |
| 47 can_set_time_ = system_clock_client->CanSetTime(); |
| 48 SystemClockCanSetTimeChanged(can_set_time_); |
| 49 } |
| 50 |
| 51 void DateTimeOptionsHandler::InitializePage() { |
| 52 page_initialized_ = true; |
| 53 SystemClockCanSetTimeChanged(can_set_time_); |
| 54 } |
| 55 |
| 56 void DateTimeOptionsHandler::RegisterMessages() { |
| 57 // Callback for set time button. |
| 58 web_ui()->RegisterMessageCallback( |
| 59 "showSetTime", |
| 60 base::Bind(&DateTimeOptionsHandler::HandleShowSetTime, |
| 61 base::Unretained(this))); |
| 62 } |
| 63 |
| 64 void DateTimeOptionsHandler::SystemClockCanSetTimeChanged(bool can_set_time) { |
| 65 if (page_initialized_) { |
| 66 web_ui()->CallJavascriptFunction("BrowserOptions.setCanSetTime", |
| 67 base::FundamentalValue(can_set_time)); |
| 68 } |
| 69 can_set_time_ = can_set_time; |
| 70 } |
| 71 |
| 72 void DateTimeOptionsHandler::HandleShowSetTime(const base::ListValue* args) { |
| 73 // Make sure the clock status hasn't changed since the button was clicked. |
| 74 if (can_set_time_) { |
| 75 SetTimeDialog::ShowDialog( |
| 76 web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow()); |
| 77 } |
| 78 } |
| 79 |
| 80 } // namespace options |
| 81 } // namespace chromeos |
OLD | NEW |