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

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

Issue 1205753002: Create chrome://device-emulator and add the ability to get a battery percentage and send an updated… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Create chrome://device-emulator and add the ability to get a battery percentage and send an updated… Created 5 years, 6 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
new file mode 100644
index 0000000000000000000000000000000000000000..29be1f6b9ee5df2a6928657d1954aabdacdc56b0
--- /dev/null
+++ b/chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_handler.cc
@@ -0,0 +1,55 @@
+// 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"
+
+// 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";
+
+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) {
+}

Powered by Google App Engine
This is Rietveld 408576698