| Index: content/renderer/vr_dispatcher.cc
|
| diff --git a/content/renderer/vr_dispatcher.cc b/content/renderer/vr_dispatcher.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..0a7a58aa0ff2017285b13062fb32e63674b5b444
|
| --- /dev/null
|
| +++ b/content/renderer/vr_dispatcher.cc
|
| @@ -0,0 +1,73 @@
|
| +// 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_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
|
|
|