| 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..e2c534a5b45f45fb008f1c9a15f05085d7747eaf
|
| --- /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 <stdlib.h>
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/values.h"
|
| +#include "content/public/browser/web_ui.h"
|
| +
|
| +namespace {
|
| +
|
| +// Define the name of the callback functions that will be used by JavaScript.
|
| +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) {
|
| +}
|
|
|