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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/renderer/vr/vr_dispatcher.h"
6
7 #include "content/common/vr_messages.h"
8 #include "content/public/renderer/render_thread.h"
9
10 namespace content {
11
12 VRDispatcher::VRDispatcher(RenderFrame* render_frame)
13 : RenderFrameObserver(render_frame) {
14 }
15
16 VRDispatcher::~VRDispatcher() {
17 }
18
19 bool VRDispatcher::OnMessageReceived(const IPC::Message& message) {
20 bool handled = true;
21
22 IPC_BEGIN_MESSAGE_MAP(VRDispatcher, message)
23 IPC_MESSAGE_HANDLER(VRMsg_GetDevicesSuccess, OnGetDevicesSuccess)
24 IPC_MESSAGE_HANDLER(VRMsg_GetDevicesError, OnGetDevicesError)
25 IPC_MESSAGE_UNHANDLED(handled = false)
26 IPC_END_MESSAGE_MAP()
27
28 return handled;
29 }
30
31 void VRDispatcher::getDevices(blink::WebVRGetDevicesCallback* callback) {
32 int request_id = pending_requests_.Add(callback);
33 Send(new VRHostMsg_GetVRDevices(routing_id(), request_id));
34 }
35
36 void VRDispatcher::getSensorState(unsigned int index,
37 blink::WebHMDSensorState& state) {
38 Send(new VRHostMsg_GetSensorState(routing_id(), index, &state));
39 }
40
41 void VRDispatcher::resetSensor(unsigned int index) {
42 Send(new VRHostMsg_ResetSensor(routing_id(), index));
43 }
44
45 void VRDispatcher::OnGetDevicesSuccess(
46 int request_id,
47 const std::vector<blink::WebVRDevice>& devices) {
48 blink::WebVector<blink::WebVRDevice> web_devices;
49
50 blink::WebVRGetDevicesCallback* callback =
51 pending_requests_.Lookup(request_id);
52 if (!callback)
53 return;
54
55 if (devices.size() > 0)
56 web_devices.assign(&devices.front(), devices.size());
57
58 callback->onSuccess(&web_devices);
59 pending_requests_.Remove(request_id);
60 }
61
62 void VRDispatcher::OnGetDevicesError(int request_id) {
63 blink::WebVRGetDevicesCallback* callback =
64 pending_requests_.Lookup(request_id);
65 if (!callback)
66 return;
67 callback->onError();
68 pending_requests_.Remove(request_id);
69 }
70
71 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698