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..05cc4f55aba9270112efbe4396dcec4bfa242c47 |
| --- /dev/null |
| +++ b/chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_handler.cc |
| @@ -0,0 +1,60 @@ |
| +// 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 <stdlib.h> |
|
oshima
2015/06/26 16:22:07
you don't need this, do you?
rfrappier
2015/06/26 16:33:08
It worked without it, but comment #6 indicated tha
oshima
2015/06/26 17:19:49
oh, I missed rand() below. Yes, this should be her
rfrappier
2015/06/26 17:29:13
Done.
|
| + |
| +#include "base/bind.h" |
| +#include "base/values.h" |
| +#include "chromeos/dbus/power_manager/power_supply_properties.pb.h" |
|
oshima
2015/06/26 16:22:07
and this?
rfrappier
2015/06/26 16:33:08
This will be used later for handling the power sup
oshima
2015/06/26 17:19:49
Please add when necessary. It can confuse reviewer
rfrappier
2015/06/26 17:29:13
Done.
rfrappier
2015/06/26 17:29:13
Okay, will remove for now.
|
| +#include "content/public/browser/web_ui.h" |
| + |
| +namespace { |
| + |
| +// Define the name of the callback functions that will be used by JavaScript |
|
oshima
2015/06/26 16:22:07
. at the end
rfrappier
2015/06/26 16:33:08
Done.
|
| +const char kBatteryPercentFunction[] = "requestBatteryInfo"; |
| +const char kUpdateBatteryPercentFunction[] = "updateBatteryInfo"; |
| +const char kUpdatePowerModeFunction[] = "updatePowerSource"; |
| +const char kBatteryPercentFunctionJSCallback[] = |
| + "device_emulator.setBatteryInfo"; |
| + |
| +} // namespace |
| + |
| +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::HandleUpdatePowerSource, |
| + base::Unretained(this))); |
| +} |
| + |
| +void DeviceEmulatorMessageHandler::HandleRequestBatteryInfo( |
| + const base::ListValue* args) { |
| + web_ui()->CallJavascriptFunction(kBatteryPercentFunctionJSCallback, |
| + base::FundamentalValue(rand() % 101)); |
| +} |
| + |
| +void DeviceEmulatorMessageHandler::HandleUpdateBatteryInfo( |
| + const base::ListValue* args) { |
| + int new_percent = -1; |
| + args->GetInteger(0, &new_percent); |
| +} |
| + |
| +void DeviceEmulatorMessageHandler::HandleUpdatePowerSource( |
| + const base::ListValue* args) { |
| +} |