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

Side by Side Diff: content/renderer/vr_dispatcher.cc

Issue 829803003: Adding Chrome-side WebVR interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved cardboard-java gyp and gn config into third_party Created 5 years, 8 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_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,
24 OnGetDevicesSuccess)
25 IPC_MESSAGE_HANDLER(VRMsg_GetDevicesError,
26 OnGetDevicesError)
27 IPC_MESSAGE_UNHANDLED(handled = false)
28 IPC_END_MESSAGE_MAP()
29
30 return handled;
31 }
32
33 void VRDispatcher::getDevices(blink::WebVRGetDevicesCallback* callback) {
34 int request_id = pending_requests_.Add(callback);
35 Send(new VRHostMsg_GetVRDevices(routing_id(), request_id));
36 }
37
38 void VRDispatcher::getSensorState(
39 unsigned int index, blink::WebHMDSensorState& state) {
40 Send(new VRHostMsg_GetSensorState(routing_id(), index, &state));
41 }
42
43 void VRDispatcher::resetSensor(unsigned int index) {
44 Send(new VRHostMsg_ResetSensor(routing_id(), index));
45 }
46
47 void VRDispatcher::OnGetDevicesSuccess(int request_id,
48 const std::vector<blink::WebVRDevice>& devices) {
49 blink::WebVector<blink::WebVRDevice> web_devices;
50
51 blink::WebVRGetDevicesCallback* callback =
52 pending_requests_.Lookup(request_id);
53 if (!callback)
54 return;
55
56 if (devices.size() > 0)
57 web_devices.assign(&devices.front(), devices.size());
58
59 callback->onSuccess(&web_devices);
60 pending_requests_.Remove(request_id);
61 }
62
63 void VRDispatcher::OnGetDevicesError(int request_id) {
64 blink::WebVRGetDevicesCallback* callback =
65 pending_requests_.Lookup(request_id);
66 if (!callback)
67 return;
68 callback->onError();
69 pending_requests_.Remove(request_id);
70 }
71
72
73 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698