Chromium Code Reviews| Index: chrome/browser/ui/webui/settings/chromeos/device_pointer_handler.cc |
| diff --git a/chrome/browser/ui/webui/settings/chromeos/device_pointer_handler.cc b/chrome/browser/ui/webui/settings/chromeos/device_pointer_handler.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..888b2e969fc1dca3c68bb47f4586f9dc8b383dfd |
| --- /dev/null |
| +++ b/chrome/browser/ui/webui/settings/chromeos/device_pointer_handler.cc |
| @@ -0,0 +1,70 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/webui/settings/chromeos/device_pointer_handler.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/sys_info.h" |
| +#include "base/values.h" |
| +#include "chrome/browser/chromeos/system/fake_input_device_settings.h" |
| +#include "content/public/browser/web_ui.h" |
| + |
| +namespace chromeos { |
| +namespace settings { |
| + |
| +PointerHandler::PointerHandler() |
| + : has_touchpad_(false), |
| + has_mouse_(false) {} |
| + |
| +PointerHandler::~PointerHandler() {} |
| + |
| +void PointerHandler::RegisterMessages() { |
| + web_ui()->RegisterMessageCallback( |
| + "initializePointerSettings", |
| + base::Bind(&PointerHandler::HandleInitialize, |
| + base::Unretained(this))); |
| +} |
| + |
| +void PointerHandler::OnJavascriptAllowed() { |
| + // If the handler is being reused, no need to re-create the observer. |
| + if (!pointer_device_observer_) { |
| + if (!base::SysInfo::IsRunningOnChromeOS() && |
| + !system::InputDeviceSettings::DidSetSettingsForTesting()) { |
| + // Create a fake InputDeviceSettings in order to show pointer settings. |
| + system::InputDeviceSettings::GetForTesting(); |
|
stevenjb
2016/06/30 00:07:49
We should move this logic to system::InputDeviceSe
michaelpg
2016/07/09 04:11:30
Done.
|
| + } |
| + |
| + pointer_device_observer_.reset( |
| + new system::PointerDeviceObserver()); |
| + pointer_device_observer_->Init(); |
| + } |
| + |
| + pointer_device_observer_->AddObserver(this); |
| + pointer_device_observer_->CheckDevices(); |
| +} |
| + |
| +void PointerHandler::OnJavascriptDisallowed() { |
| + pointer_device_observer_->RemoveObserver(this); |
| +} |
| + |
| +void PointerHandler::TouchpadExists(bool exists) { |
| + has_touchpad_ = exists; |
|
stevenjb
2016/06/30 00:07:49
Where are these members actually used? i.e. why no
michaelpg
2016/07/09 04:11:30
Vestigial from older patches, removed, thanks!
|
| + CallJavascriptFunction("cr.webUIListenerCallback", |
| + base::StringValue("has-touchpad-changed"), |
| + base::FundamentalValue(has_touchpad_)); |
|
stevenjb
2016/06/30 00:07:49
Sigh. At some point we're going to need to move th
michaelpg
2016/07/09 04:11:30
cr.sendWithPromise is supposed to be the new way o
stevenjb
2016/07/11 17:43:35
Maybe, but some day we will will want this API ava
|
| +} |
| + |
| +void PointerHandler::MouseExists(bool exists) { |
| + has_mouse_ = exists; |
| + CallJavascriptFunction("cr.webUIListenerCallback", |
| + base::StringValue("has-mouse-changed"), |
| + base::FundamentalValue(has_mouse_)); |
| +} |
| + |
| +void PointerHandler::HandleInitialize(const base::ListValue* args) { |
| + AllowJavascript(); |
| +} |
| + |
| +} // namespace settings |
| +} // namespace chromeos |