Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1723)

Unified Diff: chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_handler.cc

Issue 2006083002: Use fake Input Device Settings with chrome://device-emulator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@DevicePageTestsFixes
Patch Set: make dependent on a11y fix Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_handler.cc
diff --git a/chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_handler.cc b/chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_handler.cc
index 07ab29251d853741af7eed6129ca9a269699d1a6..42937e44491d31227f2a530ba0726dd5b4ff601e 100644
--- a/chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_handler.cc
+++ b/chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_handler.cc
@@ -13,6 +13,8 @@
#include "base/macros.h"
#include "base/strings/string_number_conversions.h"
#include "base/values.h"
+#include "chrome/browser/chromeos/system/fake_input_device_settings.h"
+#include "chrome/browser/chromeos/system/input_device_settings.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_cras_audio_client.h"
#include "chromeos/dbus/fake_power_manager_client.h"
@@ -44,6 +46,8 @@ const char kUpdateTimeToEmpty[] = "updateTimeToEmpty";
const char kUpdateTimeToFull[] = "updateTimeToFull";
const char kUpdatePowerSources[] = "updatePowerSources";
const char kUpdatePowerSourceId[] = "updatePowerSourceId";
+const char kSetHasTouchpad[] = "setHasTouchpad";
+const char kSetHasMouse[] = "setHasMouse";
// Define callback functions that will update the JavaScript variable
// and the web UI.
@@ -61,6 +65,10 @@ const char kUpdateBluetoothInfoJSCallback[] =
"device_emulator.bluetoothSettings.updateBluetoothInfo";
const char kUpdatePowerPropertiesJSCallback[] =
"device_emulator.batterySettings.updatePowerProperties";
+const char kTouchpadExistsCallback[] =
+ "device_emulator.inputDeviceSettings.setTouchpadExists";
+const char kMouseExistsCallback[] =
+ "device_emulator.inputDeviceSettings.setMouseExists";
const char kPairedPropertyName[] = "Paired";
@@ -200,7 +208,8 @@ DeviceEmulatorMessageHandler::DeviceEmulatorMessageHandler()
->GetCrasAudioClient())),
fake_power_manager_client_(static_cast<chromeos::FakePowerManagerClient*>(
chromeos::DBusThreadManager::Get()
- ->GetPowerManagerClient())) {}
+ ->GetPowerManagerClient())),
+ weak_ptr_factory_(this) {}
DeviceEmulatorMessageHandler::~DeviceEmulatorMessageHandler() {
}
@@ -337,6 +346,24 @@ void DeviceEmulatorMessageHandler::HandleRemoveAudioNode(
fake_cras_audio_client_->RemoveAudioNodeFromList(id);
}
+void DeviceEmulatorMessageHandler::HandleSetHasTouchpad(
+ const base::ListValue* args) {
+ bool has_touchpad;
+ CHECK(args->GetBoolean(0, &has_touchpad));
+
+ system::InputDeviceSettings::Get()->GetFakeInterface()->set_touchpad_exists(
+ has_touchpad);
+}
+
+void DeviceEmulatorMessageHandler::HandleSetHasMouse(
+ const base::ListValue* args) {
+ bool has_mouse;
+ CHECK(args->GetBoolean(0, &has_mouse));
+
+ system::InputDeviceSettings::Get()->GetFakeInterface()->set_mouse_exists(
+ has_mouse);
+}
+
void DeviceEmulatorMessageHandler::UpdateBatteryPercent(
const base::ListValue* args) {
int new_percent;
@@ -508,12 +535,27 @@ void DeviceEmulatorMessageHandler::RegisterMessages() {
kRemoveBluetoothDevice,
base::Bind(&DeviceEmulatorMessageHandler::HandleRemoveBluetoothDevice,
base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(
+ kSetHasTouchpad,
+ base::Bind(&DeviceEmulatorMessageHandler::HandleSetHasTouchpad,
+ base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(
+ kSetHasMouse,
+ base::Bind(&DeviceEmulatorMessageHandler::HandleSetHasMouse,
+ base::Unretained(this)));
}
void DeviceEmulatorMessageHandler::OnJavascriptAllowed() {
bluetooth_observer_.reset(new BluetoothObserver(this));
cras_audio_observer_.reset(new CrasAudioObserver(this));
power_observer_.reset(new PowerObserver(this));
+
+ system::InputDeviceSettings::Get()->TouchpadExists(
+ base::Bind(&DeviceEmulatorMessageHandler::TouchpadExists,
+ weak_ptr_factory_.GetWeakPtr()));
+ system::InputDeviceSettings::Get()->MouseExists(
+ base::Bind(&DeviceEmulatorMessageHandler::MouseExists,
+ weak_ptr_factory_.GetWeakPtr()));
}
void DeviceEmulatorMessageHandler::OnJavascriptDisallowed() {
@@ -584,4 +626,18 @@ DeviceEmulatorMessageHandler::GetDeviceInfo(
return device;
}
+void DeviceEmulatorMessageHandler::TouchpadExists(bool exists) {
+ if (!IsJavascriptAllowed())
+ return;
+ web_ui()->CallJavascriptFunctionUnsafe(kTouchpadExistsCallback,
+ base::FundamentalValue(exists));
+}
+
+void DeviceEmulatorMessageHandler::MouseExists(bool exists) {
+ if (!IsJavascriptAllowed())
+ return;
+ web_ui()->CallJavascriptFunctionUnsafe(kMouseExistsCallback,
+ base::FundamentalValue(exists));
+}
+
} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698