Chromium Code Reviews| 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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..feb6a66d952ee9dceb7fa4e5d6d83df618b4c99c |
| --- /dev/null |
| +++ b/chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_handler.cc |
| @@ -0,0 +1,59 @@ |
| +// Copyright 2015 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/chromeos/emulator/device_emulator_message_handler.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/values.h" |
| +#include "content/public/browser/web_ui.h" |
| + |
| +namespace chromeos { |
| + |
| +const char kBatteryPercentFunction[] = "requestBatteryInfo"; |
| +const char kUpdateBatteryPercentFunction[] = "updateBatteryInfo"; |
| +const char kUpdatePowerModeFunction[] = "updatePowerMode"; |
| +const char kBatteryPercentFunctionJSCallback[] = |
| + "device_emulator.returnBatteryInfo"; |
| + |
| +DeviceEmulatorMessageHandler::DeviceEmulatorMessageHandler() { |
| +} |
| + |
| +DeviceEmulatorMessageHandler::~DeviceEmulatorMessageHandler() { |
| +} |
| + |
| +void DeviceEmulatorMessageHandler::RegisterMessages() { |
| + web_ui()->RegisterMessageCallback( |
| + kBatteryPercentFunction, |
| + base::Bind(&DeviceEmulatorMessageHandler::HandleRequestBatteryInfo, |
| + base::Unretained(this))); |
| + web_ui()->RegisterMessageCallback( |
| + kUpdateBatteryPercentFunction, |
| + base::Bind(&DeviceEmulatorMessageHandler::HandleUpdateBatteryInfo, |
| + base::Unretained(this))); |
| + web_ui()->RegisterMessageCallback( |
| + kUpdatePowerModeFunction, |
| + base::Bind(&DeviceEmulatorMessageHandler::HandleUpdatePowerMode, |
| + base::Unretained(this))); |
| +} |
| + |
| +void DeviceEmulatorMessageHandler::HandleRequestBatteryInfo( |
| + const base::ListValue* args) { |
| + // TEST CALL FOR NOW |
| + // TODO: Link this with the other Emulator code |
| + // which will return the actual battery percentage |
| + web_ui()->CallJavascriptFunction(kBatteryPercentFunctionJSCallback, |
| + base::FundamentalValue(rand() % 101)); |
|
michaelpg
2015/06/24 23:33:48
#include <stdlib.h>
rfrappier
2015/06/25 17:09:21
Done.
|
| +} |
| + |
| +void DeviceEmulatorMessageHandler::HandleUpdateBatteryInfo( |
| + const base::ListValue* args) { |
| + int new_percent = -1; |
| + args->GetInteger(0, &new_percent); |
| +} |
| + |
| +void DeviceEmulatorMessageHandler::HandleUpdatePowerMode( |
| + const base::ListValue* args) { |
| +} |
| + |
| +} // namespace chromeos |