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 |
| 17 namespace chromeos { |
| 18 namespace options { |
| 19 |
| 20 DateTimeOptionsHandler::DateTimeOptionsHandler() |
| 21 : can_set_time_(false), page_initialized_(false) { |
| 22 } |
| 23 |
| 24 DateTimeOptionsHandler::~DateTimeOptionsHandler() { |
| 25 DBusThreadManager::Get()->GetSystemClockClient()->RemoveObserver(this); |
| 26 } |
| 27 |
| 28 void DateTimeOptionsHandler::RegisterMessages() { |
| 29 // Callback for set time button. |
| 30 web_ui()->RegisterMessageCallback( |
| 31 "showSetTime", |
| 32 base::Bind(&DateTimeOptionsHandler::HandleShowSetTime, |
| 33 base::Unretained(this))); |
| 34 } |
| 35 |
| 36 void DateTimeOptionsHandler::InitializeHandler() { |
| 37 SystemClockClient* system_clock_client = |
| 38 DBusThreadManager::Get()->GetSystemClockClient(); |
| 39 system_clock_client->AddObserver(this); |
| 40 |
| 41 can_set_time_ = system_clock_client->CanSetTime(); |
| 42 SystemClockCanSetTimeChanged(can_set_time_); |
| 43 } |
| 44 |
| 45 void DateTimeOptionsHandler::InitializePage() { |
| 46 page_initialized_ = true; |
| 47 SystemClockCanSetTimeChanged(can_set_time_); |
| 48 } |
| 49 |
| 50 void DateTimeOptionsHandler::SystemClockCanSetTimeChanged(bool can_set_time) { |
| 51 if (page_initialized_) { |
| 52 web_ui()->CallJavascriptFunction("BrowserOptions.setCanSetTime", |
| 53 base::FundamentalValue(can_set_time)); |
| 54 } |
| 55 can_set_time_ = can_set_time; |
| 56 } |
| 57 |
| 58 void DateTimeOptionsHandler::HandleShowSetTime(const base::ListValue* args) { |
| 59 // Make sure the clock status hasn't changed since the button was clicked. |
| 60 if (can_set_time_) { |
| 61 SetTimeDialog::ShowDialog( |
| 62 web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow()); |
| 63 } |
| 64 } |
| 65 |
| 66 } // namespace options |
| 67 } // namespace chromeos |
OLD | NEW |