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 @@
#include "content/browser/frame_host/popup_menu_helper_mac.h"
#endif
#if defined(ENABLE_WEBVR)
#include "device/vr/vr_service_impl.h" // nogncheck
#endif
using base::TimeDelta;
......@@ -239,6 +237,11 @@ class RemoterFactoryImpl final : public media::mojom::RemoterFactory {
};
#endif // BUILDFLAG(ENABLE_MEDIA_REMOTING)
template <typename Interface>
void IgnoreInterfaceRequest(mojo::InterfaceRequest<Interface> request) {
// Intentionally ignore the interface request.
}
} // namespace
// static
......@@ -2308,7 +2311,11 @@ void RenderFrameHostImpl::RegisterMojoInterfaces() {
#if defined(ENABLE_WEBVR)
GetInterfaceRegistry()->AddInterface<device::mojom::VRService>(
base::Bind(&device::VRServiceImpl::Create));
#else
GetInterfaceRegistry()->AddInterface<device::mojom::VRService>(
base::Bind(&IgnoreInterfaceRequest<device::mojom::VRService>));
#endif
if (base::FeatureList::IsEnabled(features::kGenericSensor)) {
GetInterfaceRegistry()->AddInterface(
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)
m_binding(this) {
navigatorVR->document()->frame()->interfaceProvider()->getInterface(
mojo::MakeRequest(&m_service));
m_service.set_connection_error_handler(convertToBaseCallback(
WTF::bind(&VRController::dispose, wrapWeakPersistent(this))));
m_service->SetClient(
m_binding.CreateInterfacePtrAndBind(),
convertToBaseCallback(
......@@ -32,15 +34,10 @@ VRController::VRController(NavigatorVR* navigatorVR)
VRController::~VRController() {}
void VRController::getDisplays(ScriptPromiseResolver* resolver) {
if (!m_service) {
DOMException* exception = DOMException::create(
InvalidStateError, "The service is no longer active.");
resolver->reject(exception);
return;
}
// If we've previously synced the VRDisplays just return the current list.
if (m_displaySynced) {
// If we've previously synced the VRDisplays or no longer have a valid service
// connection just return the current list. In the case of the service being
// disconnected this will be an empty array.
if (!m_service || m_displaySynced) {
resolver->resolve(m_displays);
return;
}
......@@ -106,6 +103,11 @@ void VRController::dispose() {
// Shutdown all displays' message pipe
for (size_t i = 0; i < m_displays.size(); ++i)
m_displays[i]->dispose();
m_displays.clear();
// Ensure that any outstanding getDisplays promises are resolved.
onGetDisplays();
}
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