Commit d83aedbf authored by bajones's avatar bajones Committed by Commit bot

Ensure navigator.getVRDisplays always resolves.

In the case that the backing VR service is not available the call will now
resolve to an empty array.

BUG=678283
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_site_isolation

Review-Url: https://codereview.chromium.org/2614873002
Cr-Commit-Position: refs/heads/master@{#442117}
parent fa763730
...@@ -125,9 +125,7 @@ ...@@ -125,9 +125,7 @@
#include "content/browser/frame_host/popup_menu_helper_mac.h" #include "content/browser/frame_host/popup_menu_helper_mac.h"
#endif #endif
#if defined(ENABLE_WEBVR)
#include "device/vr/vr_service_impl.h" // nogncheck #include "device/vr/vr_service_impl.h" // nogncheck
#endif
using base::TimeDelta; using base::TimeDelta;
...@@ -239,6 +237,11 @@ class RemoterFactoryImpl final : public media::mojom::RemoterFactory { ...@@ -239,6 +237,11 @@ class RemoterFactoryImpl final : public media::mojom::RemoterFactory {
}; };
#endif // BUILDFLAG(ENABLE_MEDIA_REMOTING) #endif // BUILDFLAG(ENABLE_MEDIA_REMOTING)
template <typename Interface>
void IgnoreInterfaceRequest(mojo::InterfaceRequest<Interface> request) {
// Intentionally ignore the interface request.
}
} // namespace } // namespace
// static // static
...@@ -2308,7 +2311,11 @@ void RenderFrameHostImpl::RegisterMojoInterfaces() { ...@@ -2308,7 +2311,11 @@ void RenderFrameHostImpl::RegisterMojoInterfaces() {
#if defined(ENABLE_WEBVR) #if defined(ENABLE_WEBVR)
GetInterfaceRegistry()->AddInterface<device::mojom::VRService>( GetInterfaceRegistry()->AddInterface<device::mojom::VRService>(
base::Bind(&device::VRServiceImpl::Create)); base::Bind(&device::VRServiceImpl::Create));
#else
GetInterfaceRegistry()->AddInterface<device::mojom::VRService>(
base::Bind(&IgnoreInterfaceRequest<device::mojom::VRService>));
#endif #endif
if (base::FeatureList::IsEnabled(features::kGenericSensor)) { if (base::FeatureList::IsEnabled(features::kGenericSensor)) {
GetInterfaceRegistry()->AddInterface( GetInterfaceRegistry()->AddInterface(
base::Bind(&device::SensorProviderImpl::Create, base::Bind(&device::SensorProviderImpl::Create,
......
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
promise_test(t => navigator.getVRDisplays().then(devices => {
assert_true(devices != null);
assert_true(devices instanceof Array);
assert_greater_than_equal(0, devices.length);
if (devices.length > 0)
assert_true(devices[0] instanceof VRDisplay);
}), "Test that getVRDisplays always resolves with at least an empty sequence.");
</script>
...@@ -23,6 +23,8 @@ VRController::VRController(NavigatorVR* navigatorVR) ...@@ -23,6 +23,8 @@ VRController::VRController(NavigatorVR* navigatorVR)
m_binding(this) { m_binding(this) {
navigatorVR->document()->frame()->interfaceProvider()->getInterface( navigatorVR->document()->frame()->interfaceProvider()->getInterface(
mojo::MakeRequest(&m_service)); mojo::MakeRequest(&m_service));
m_service.set_connection_error_handler(convertToBaseCallback(
WTF::bind(&VRController::dispose, wrapWeakPersistent(this))));
m_service->SetClient( m_service->SetClient(
m_binding.CreateInterfacePtrAndBind(), m_binding.CreateInterfacePtrAndBind(),
convertToBaseCallback( convertToBaseCallback(
...@@ -32,15 +34,10 @@ VRController::VRController(NavigatorVR* navigatorVR) ...@@ -32,15 +34,10 @@ VRController::VRController(NavigatorVR* navigatorVR)
VRController::~VRController() {} VRController::~VRController() {}
void VRController::getDisplays(ScriptPromiseResolver* resolver) { void VRController::getDisplays(ScriptPromiseResolver* resolver) {
if (!m_service) { // If we've previously synced the VRDisplays or no longer have a valid service
DOMException* exception = DOMException::create( // connection just return the current list. In the case of the service being
InvalidStateError, "The service is no longer active."); // disconnected this will be an empty array.
resolver->reject(exception); if (!m_service || m_displaySynced) {
return;
}
// If we've previously synced the VRDisplays just return the current list.
if (m_displaySynced) {
resolver->resolve(m_displays); resolver->resolve(m_displays);
return; return;
} }
...@@ -106,6 +103,11 @@ void VRController::dispose() { ...@@ -106,6 +103,11 @@ void VRController::dispose() {
// Shutdown all displays' message pipe // Shutdown all displays' message pipe
for (size_t i = 0; i < m_displays.size(); ++i) for (size_t i = 0; i < m_displays.size(); ++i)
m_displays[i]->dispose(); m_displays[i]->dispose();
m_displays.clear();
// Ensure that any outstanding getDisplays promises are resolved.
onGetDisplays();
} }
DEFINE_TRACE(VRController) { DEFINE_TRACE(VRController) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment