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

Unified Diff: content/renderer/vr/vr_dispatcher.cc

Issue 829803003: Adding Chrome-side WebVR interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing feedback from mdempsky Created 5 years, 7 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: content/renderer/vr/vr_dispatcher.cc
diff --git a/content/renderer/vr/vr_dispatcher.cc b/content/renderer/vr/vr_dispatcher.cc
new file mode 100644
index 0000000000000000000000000000000000000000..768170446288864371699081a463b127faf2a437
--- /dev/null
+++ b/content/renderer/vr/vr_dispatcher.cc
@@ -0,0 +1,71 @@
+// 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 "content/renderer/vr/vr_dispatcher.h"
+
+#include "content/common/vr_messages.h"
+#include "content/public/renderer/render_thread.h"
+
+namespace content {
+
+VRDispatcher::VRDispatcher(RenderFrame* render_frame)
+ : RenderFrameObserver(render_frame) {
+}
+
+VRDispatcher::~VRDispatcher() {
+}
+
+bool VRDispatcher::OnMessageReceived(const IPC::Message& message) {
+ bool handled = true;
+
+ IPC_BEGIN_MESSAGE_MAP(VRDispatcher, message)
+ IPC_MESSAGE_HANDLER(VRMsg_GetDevicesSuccess, OnGetDevicesSuccess)
+ IPC_MESSAGE_HANDLER(VRMsg_GetDevicesError, OnGetDevicesError)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+
+ return handled;
+}
+
+void VRDispatcher::getDevices(blink::WebVRGetDevicesCallback* callback) {
+ int request_id = pending_requests_.Add(callback);
+ Send(new VRHostMsg_GetVRDevices(routing_id(), request_id));
+}
+
+void VRDispatcher::getSensorState(unsigned int index,
+ blink::WebHMDSensorState& state) {
+ Send(new VRHostMsg_GetSensorState(routing_id(), index, &state));
+}
+
+void VRDispatcher::resetSensor(unsigned int index) {
+ Send(new VRHostMsg_ResetSensor(routing_id(), index));
+}
+
+void VRDispatcher::OnGetDevicesSuccess(
+ int request_id,
+ const std::vector<blink::WebVRDevice>& devices) {
+ blink::WebVector<blink::WebVRDevice> web_devices;
+
+ blink::WebVRGetDevicesCallback* callback =
+ pending_requests_.Lookup(request_id);
+ if (!callback)
+ return;
+
+ if (devices.size() > 0)
+ web_devices.assign(&devices.front(), devices.size());
+
+ callback->onSuccess(&web_devices);
+ pending_requests_.Remove(request_id);
+}
+
+void VRDispatcher::OnGetDevicesError(int request_id) {
+ blink::WebVRGetDevicesCallback* callback =
+ pending_requests_.Lookup(request_id);
+ if (!callback)
+ return;
+ callback->onError();
+ pending_requests_.Remove(request_id);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698