OLD | NEW |
(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 |
OLD | NEW |