Index: third_party/WebKit/Source/modules/vr/VRController.cpp |
diff --git a/third_party/WebKit/Source/modules/vr/VRController.cpp b/third_party/WebKit/Source/modules/vr/VRController.cpp |
index 36aa47c5b8dcc414b32a940ddd4bdb11a5a0442e..4ea5b9251abd0129cc6ddc5358646b5e1aa1f613 100644 |
--- a/third_party/WebKit/Source/modules/vr/VRController.cpp |
+++ b/third_party/WebKit/Source/modules/vr/VRController.cpp |
@@ -5,7 +5,10 @@ |
#include "modules/vr/VRController.h" |
#include "core/frame/LocalFrame.h" |
+#include "modules/vr/VRGetDevicesCallback.h" |
#include "platform/RuntimeEnabledFeatures.h" |
+#include "platform/mojo/MojoHelper.h" |
+#include "public/platform/ServiceRegistry.h" |
namespace blink { |
@@ -13,12 +16,10 @@ VRController::~VRController() |
{ |
} |
-void VRController::provideTo(LocalFrame& frame, WebVRClient* client) |
+void VRController::provideTo(LocalFrame& frame, ServiceRegistry* registry) |
{ |
ASSERT(RuntimeEnabledFeatures::webVREnabled()); |
- |
- VRController* controller = new VRController(frame, client); |
- Supplement<LocalFrame>::provideTo(frame, supplementName(), controller); |
+ Supplement<LocalFrame>::provideTo(frame, supplementName(), registry ? new VRController(frame, registry) : nullptr); |
} |
VRController* VRController::from(LocalFrame& frame) |
@@ -26,10 +27,11 @@ VRController* VRController::from(LocalFrame& frame) |
return static_cast<VRController*>(Supplement<LocalFrame>::from(frame, supplementName())); |
} |
-VRController::VRController(LocalFrame& frame, WebVRClient* client) |
+VRController::VRController(LocalFrame& frame, ServiceRegistry* registry) |
: LocalFrameLifecycleObserver(&frame) |
- , m_client(client) |
{ |
+ ASSERT(!m_service.is_bound()); |
+ registry->connectToRemoteService(mojo::GetProxy(&m_service)); |
} |
const char* VRController::supplementName() |
@@ -37,38 +39,50 @@ const char* VRController::supplementName() |
return "VRController"; |
} |
-void VRController::getDevices(WebVRGetDevicesCallback* callback) |
+void VRController::getDevices(std::unique_ptr<VRGetDevicesCallback> callback) |
{ |
- // When detached, the client is no longer valid. |
- if (!m_client) { |
+ if (!m_service) { |
callback->onError(); |
- delete callback; |
return; |
} |
- // Client is expected to take ownership of the callback |
- m_client->getDevices(callback); |
+ m_pendingGetDevicesCallbacks.append(std::move(callback)); |
+ m_service->GetDevices(sameThreadBindForMojo(&VRController::OnGetDevices, this)); |
} |
void VRController::getSensorState(unsigned index, WebHMDSensorState& into) |
{ |
- // When detached, the client is no longer valid. |
- if (!m_client) |
+ if (!m_service) |
return; |
- m_client->getSensorState(index, into); |
+ |
+ mojom::VRSensorStatePtr state; |
+ m_service->GetSensorState(index, &state); |
+ into = state.To<WebHMDSensorState>(); |
} |
void VRController::resetSensor(unsigned index) |
{ |
- // When detached, the client is no longer valid. |
- if (!m_client) |
+ if (!m_service) |
return; |
- m_client->resetSensor(index); |
+ m_service->ResetSensor(index); |
} |
void VRController::willDetachFrameHost() |
{ |
- m_client = nullptr; |
+ // TODO(kphanee): Detach from the mojo service connection. |
+} |
+ |
+void VRController::OnGetDevices(const mojo::Array<mojom::VRDeviceInfoPtr>& devices) |
+{ |
+ WebVector<WebVRDevice> webDevices(devices.size()); |
+ |
+ std::unique_ptr<VRGetDevicesCallback> callback = m_pendingGetDevicesCallbacks.takeFirst(); |
+ if (!callback) |
+ return; |
+ |
+ for (size_t i = 0; i < devices.size(); ++i) |
+ webDevices[i] = devices[i].To<WebVRDevice>(); |
+ callback->onSuccess(webDevices); |
} |
DEFINE_TRACE(VRController) |