Commit 7ff915cf authored by Alex Cooper's avatar Alex Cooper Committed by Commit Bot

Deprecate xr.supportsSession in favor of xr.isSessionSupported

Bug: 1003147
Change-Id: I5f7147f0d6439ca7d93a93713d369090d0053e4e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1823817
Commit-Queue: Alexander Cooper <alcooper@chromium.org>
Reviewed-by: default avatarDavid Bokan <bokan@chromium.org>
Reviewed-by: default avatarAlexander Cooper <alcooper@chromium.org>
Cr-Commit-Position: refs/heads/master@{#700862}
parent c5c7f7fc
...@@ -2416,6 +2416,7 @@ enum WebFeature { ...@@ -2416,6 +2416,7 @@ enum WebFeature {
kThirdPartyBroadcastChannel = 3033, kThirdPartyBroadcastChannel = 3033,
kMediaSourceGroupEndTimestampDecreaseWithinMediaSegment = 3034, kMediaSourceGroupEndTimestampDecreaseWithinMediaSegment = 3034,
kTextFragmentAnchorTapToDismiss = 3035, kTextFragmentAnchorTapToDismiss = 3035,
kXRIsSessionSupported = 3036,
// Add new features immediately above this line. Don't change assigned // Add new features immediately above this line. Don't change assigned
// numbers of any item, and don't reuse removed slots. // numbers of any item, and don't reuse removed slots.
......
...@@ -666,6 +666,12 @@ DeprecationInfo GetDeprecationInfo(WebFeature feature) { ...@@ -666,6 +666,12 @@ DeprecationInfo GetDeprecationInfo(WebFeature feature) {
"elements other than textarea", "elements other than textarea",
kM79, "5070237827334144")}; kM79, "5070237827334144")};
case WebFeature::kXRSupportsSession:
return {"XRSupportsSession", kM80,
ReplacedBy(
"supportsSession()",
"isSessionSupported() and check the resolved boolean value")};
// Features that aren't deprecated don't have a deprecation message. // Features that aren't deprecated don't have a deprecation message.
default: default:
return {"NotDeprecated", kUnknown, ""}; return {"NotDeprecated", kUnknown, ""};
......
...@@ -230,15 +230,28 @@ const char* XR::CheckInlineSessionRequestAllowed( ...@@ -230,15 +230,28 @@ const char* XR::CheckInlineSessionRequestAllowed(
XR::PendingSupportsSessionQuery::PendingSupportsSessionQuery( XR::PendingSupportsSessionQuery::PendingSupportsSessionQuery(
ScriptPromiseResolver* resolver, ScriptPromiseResolver* resolver,
XRSession::SessionMode session_mode) XRSession::SessionMode session_mode,
: resolver_(resolver), mode_(session_mode) {} bool throw_on_unsupported)
: resolver_(resolver),
mode_(session_mode),
throw_on_unsupported_(throw_on_unsupported) {}
void XR::PendingSupportsSessionQuery::Trace(blink::Visitor* visitor) { void XR::PendingSupportsSessionQuery::Trace(blink::Visitor* visitor) {
visitor->Trace(resolver_); visitor->Trace(resolver_);
} }
void XR::PendingSupportsSessionQuery::Resolve() { void XR::PendingSupportsSessionQuery::Resolve(bool supported,
resolver_->Resolve(); ExceptionState* exception_state) {
if (throw_on_unsupported_) {
if (supported) {
resolver_->Resolve();
} else {
RejectWithDOMException(DOMExceptionCode::kNotSupportedError,
kSessionNotSupported, exception_state);
}
} else {
resolver_->Resolve(supported);
}
} }
void XR::PendingSupportsSessionQuery::RejectWithDOMException( void XR::PendingSupportsSessionQuery::RejectWithDOMException(
...@@ -485,6 +498,19 @@ void XR::ExitPresent() { ...@@ -485,6 +498,19 @@ void XR::ExitPresent() {
ScriptPromise XR::supportsSession(ScriptState* script_state, ScriptPromise XR::supportsSession(ScriptState* script_state,
const String& mode, const String& mode,
ExceptionState& exception_state) { ExceptionState& exception_state) {
return InternalIsSessionSupported(script_state, mode, exception_state, true);
}
ScriptPromise XR::isSessionSupported(ScriptState* script_state,
const String& mode,
ExceptionState& exception_state) {
return InternalIsSessionSupported(script_state, mode, exception_state, false);
}
ScriptPromise XR::InternalIsSessionSupported(ScriptState* script_state,
const String& mode,
ExceptionState& exception_state,
bool throw_on_unsupported) {
LocalFrame* frame = GetFrame(); LocalFrame* frame = GetFrame();
Document* doc = frame ? frame->GetDocument() : nullptr; Document* doc = frame ? frame->GetDocument() : nullptr;
if (!doc) { if (!doc) {
...@@ -499,7 +525,8 @@ ScriptPromise XR::supportsSession(ScriptState* script_state, ...@@ -499,7 +525,8 @@ ScriptPromise XR::supportsSession(ScriptState* script_state,
XRSession::SessionMode session_mode = stringToSessionMode(mode); XRSession::SessionMode session_mode = stringToSessionMode(mode);
PendingSupportsSessionQuery* query = PendingSupportsSessionQuery* query =
MakeGarbageCollected<PendingSupportsSessionQuery>(resolver, session_mode); MakeGarbageCollected<PendingSupportsSessionQuery>(resolver, session_mode,
throw_on_unsupported);
if (session_mode == XRSession::kModeImmersiveAR && if (session_mode == XRSession::kModeImmersiveAR &&
!RuntimeEnabledFeatures::WebXRARModuleEnabled(doc)) { !RuntimeEnabledFeatures::WebXRARModuleEnabled(doc)) {
...@@ -519,13 +546,12 @@ ScriptPromise XR::supportsSession(ScriptState* script_state, ...@@ -519,13 +546,12 @@ ScriptPromise XR::supportsSession(ScriptState* script_state,
if (session_mode == XRSession::kModeInline) { if (session_mode == XRSession::kModeInline) {
// `inline` sessions are always supported if not blocked by feature policy. // `inline` sessions are always supported if not blocked by feature policy.
query->Resolve(); query->Resolve(true);
} else { } else {
if (!service_) { if (!service_) {
// If we don't have a service at the time we reach this call it indicates // If we don't have a service at the time we reach this call it indicates
// that there's no WebXR hardware. Reject as not supported. // that there's no WebXR hardware. Reject as not supported.
query->RejectWithDOMException(DOMExceptionCode::kNotSupportedError, query->Resolve(false, &exception_state);
kSessionNotSupported, &exception_state);
return promise; return promise;
} }
...@@ -750,13 +776,7 @@ void XR::OnSupportsSessionReturned(PendingSupportsSessionQuery* query, ...@@ -750,13 +776,7 @@ void XR::OnSupportsSessionReturned(PendingSupportsSessionQuery* query,
// promise, so remove it from our outstanding list. // promise, so remove it from our outstanding list.
DCHECK(outstanding_support_queries_.Contains(query)); DCHECK(outstanding_support_queries_.Contains(query));
outstanding_support_queries_.erase(query); outstanding_support_queries_.erase(query);
query->Resolve(supports_session);
if (supports_session) {
query->Resolve();
} else {
query->RejectWithDOMException(DOMExceptionCode::kNotSupportedError,
kSessionNotSupported, nullptr);
}
} }
void XR::OnRequestSessionReturned( void XR::OnRequestSessionReturned(
......
...@@ -46,6 +46,9 @@ class XR final : public EventTargetWithInlineData, ...@@ -46,6 +46,9 @@ class XR final : public EventTargetWithInlineData,
ScriptPromise supportsSession(ScriptState*, ScriptPromise supportsSession(ScriptState*,
const String&, const String&,
ExceptionState& exception_state); ExceptionState& exception_state);
ScriptPromise isSessionSupported(ScriptState*,
const String&,
ExceptionState& exception_state);
ScriptPromise requestSession(ScriptState*, ScriptPromise requestSession(ScriptState*,
const String&, const String&,
XRSessionInit*, XRSessionInit*,
...@@ -177,11 +180,13 @@ class XR final : public EventTargetWithInlineData, ...@@ -177,11 +180,13 @@ class XR final : public EventTargetWithInlineData,
class PendingSupportsSessionQuery final class PendingSupportsSessionQuery final
: public GarbageCollected<PendingSupportsSessionQuery> { : public GarbageCollected<PendingSupportsSessionQuery> {
public: public:
PendingSupportsSessionQuery(ScriptPromiseResolver*, XRSession::SessionMode); PendingSupportsSessionQuery(ScriptPromiseResolver*,
XRSession::SessionMode,
bool throw_on_unsupported);
virtual ~PendingSupportsSessionQuery() = default; virtual ~PendingSupportsSessionQuery() = default;
// Resolves underlying promise. // Resolves underlying promise.
void Resolve(); void Resolve(bool supported, ExceptionState* exception_state = nullptr);
// Rejects underlying promise with a DOMException. // Rejects underlying promise with a DOMException.
// Do not call this with |DOMExceptionCode::kSecurityError|, use // Do not call this with |DOMExceptionCode::kSecurityError|, use
...@@ -204,6 +209,8 @@ class XR final : public EventTargetWithInlineData, ...@@ -204,6 +209,8 @@ class XR final : public EventTargetWithInlineData,
void RejectWithTypeError(const String& message, void RejectWithTypeError(const String& message,
ExceptionState* exception_state); ExceptionState* exception_state);
bool ThrowOnUnsupported() const { return throw_on_unsupported_; }
XRSession::SessionMode mode() const; XRSession::SessionMode mode() const;
virtual void Trace(blink::Visitor*); virtual void Trace(blink::Visitor*);
...@@ -212,9 +219,17 @@ class XR final : public EventTargetWithInlineData, ...@@ -212,9 +219,17 @@ class XR final : public EventTargetWithInlineData,
Member<ScriptPromiseResolver> resolver_; Member<ScriptPromiseResolver> resolver_;
const XRSession::SessionMode mode_; const XRSession::SessionMode mode_;
// Only set when calling the deprecated supportsSession method.
const bool throw_on_unsupported_ = false;
DISALLOW_COPY_AND_ASSIGN(PendingSupportsSessionQuery); DISALLOW_COPY_AND_ASSIGN(PendingSupportsSessionQuery);
}; };
ScriptPromise InternalIsSessionSupported(ScriptState*,
const String&,
ExceptionState& exception_state,
bool throw_on_unsupported);
const char* CheckInlineSessionRequestAllowed( const char* CheckInlineSessionRequestAllowed(
LocalFrame* frame, LocalFrame* frame,
Document* doc, Document* doc,
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
RuntimeEnabled=WebXR RuntimeEnabled=WebXR
] interface XR : EventTarget { ] interface XR : EventTarget {
attribute EventHandler ondevicechange; attribute EventHandler ondevicechange;
[CallWith=ScriptState, MeasureAs=XRSupportsSession, RaisesException] Promise<void> supportsSession(XRSessionMode mode); [CallWith=ScriptState, DeprecateAs=XRSupportsSession, RaisesException] Promise<void> supportsSession(XRSessionMode mode);
[CallWith=ScriptState, MeasureAs=XRIsSessionSupported, RaisesException] Promise<boolean> isSessionSupported(XRSessionMode mode);
[CallWith=ScriptState, MeasureAs=XRRequestSession, RaisesException] Promise<XRSession> requestSession(XRSessionMode mode, optional XRSessionInit options); [CallWith=ScriptState, MeasureAs=XRRequestSession, RaisesException] Promise<XRSession> requestSession(XRSessionMode mode, optional XRSessionInit options);
}; };
This is a testharness.js-based test. This is a testharness.js-based test.
Found 204 tests; 199 PASS, 5 FAIL, 0 TIMEOUT, 0 NOTRUN. Found 204 tests; 202 PASS, 2 FAIL, 0 TIMEOUT, 0 NOTRUN.
PASS idl_test setup PASS idl_test setup
PASS idl_test validation PASS idl_test validation
PASS Partial interface Navigator: original interface defined PASS Partial interface Navigator: original interface defined
...@@ -24,13 +24,13 @@ PASS XR interface object name ...@@ -24,13 +24,13 @@ PASS XR interface object name
PASS XR interface: existence and properties of interface prototype object PASS XR interface: existence and properties of interface prototype object
PASS XR interface: existence and properties of interface prototype object's "constructor" property PASS XR interface: existence and properties of interface prototype object's "constructor" property
PASS XR interface: existence and properties of interface prototype object's @@unscopables property PASS XR interface: existence and properties of interface prototype object's @@unscopables property
FAIL XR interface: operation isSessionSupported(XRSessionMode) assert_own_property: interface prototype object missing non-static operation expected property "isSessionSupported" missing PASS XR interface: operation isSessionSupported(XRSessionMode)
PASS XR interface: operation requestSession(XRSessionMode, XRSessionInit) PASS XR interface: operation requestSession(XRSessionMode, XRSessionInit)
PASS XR interface: attribute ondevicechange PASS XR interface: attribute ondevicechange
PASS XR must be primary interface of navigator.xr PASS XR must be primary interface of navigator.xr
PASS Stringification of navigator.xr PASS Stringification of navigator.xr
FAIL XR interface: navigator.xr must inherit property "isSessionSupported(XRSessionMode)" with the proper type assert_inherits: property "isSessionSupported" not found in prototype chain PASS XR interface: navigator.xr must inherit property "isSessionSupported(XRSessionMode)" with the proper type
FAIL XR interface: calling isSessionSupported(XRSessionMode) on navigator.xr with too few arguments must throw TypeError assert_inherits: property "isSessionSupported" not found in prototype chain PASS XR interface: calling isSessionSupported(XRSessionMode) on navigator.xr with too few arguments must throw TypeError
PASS XR interface: navigator.xr must inherit property "requestSession(XRSessionMode, XRSessionInit)" with the proper type PASS XR interface: navigator.xr must inherit property "requestSession(XRSessionMode, XRSessionInit)" with the proper type
PASS XR interface: calling requestSession(XRSessionMode, XRSessionInit) on navigator.xr with too few arguments must throw TypeError PASS XR interface: calling requestSession(XRSessionMode, XRSessionInit) on navigator.xr with too few arguments must throw TypeError
PASS XR interface: navigator.xr must inherit property "ondevicechange" with the proper type PASS XR interface: navigator.xr must inherit property "ondevicechange" with the proper type
......
<!DOCTYPE html>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="resources/webxr_util.js"></script>
<script src="resources/webxr_test_constants.js"></script>
<script>
xr_promise_test(
"isSessionSupported resolves to true when immersive options supported",
(t) => {
return navigator.xr.test.simulateDeviceConnection(TRACKED_IMMERSIVE_DEVICE)
.then( (controller) => {
return navigator.xr.isSessionSupported('immersive-vr').then((supported) => {
t.step(() => {
assert_true(supported);
});
});
});
});
</script>
</body>
<!DOCTYPE html>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="resources/webxr_util.js"></script>
<script src="resources/webxr_test_constants.js"></script>
<script>
xr_promise_test(
"isSessionSupported resolves to false when options not supported",
(t) => {
return navigator.xr.test.simulateDeviceConnection(VALID_NON_IMMERSIVE_DEVICE)
.then( (controller) => {
return navigator.xr.isSessionSupported('immersive-vr').then((supported) => {
t.step(() => {
assert_false(supported);
});
});
});
});
</script>
</body>
<!DOCTYPE html>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="resources/webxr_util.js"></script>
<script src="resources/webxr_test_constants.js"></script>
<script>
xr_promise_test(
"isSessionSupported resolves to true when inline options supported",
(t) => {
return navigator.xr.test.simulateDeviceConnection(TRACKED_IMMERSIVE_DEVICE)
.then( (controller) => {
// Inline sessions should be supported.
return navigator.xr.isSessionSupported('inline').then((supported) => {
t.step(() => {
assert_true(supported);
});
});
});
});
</script>
</body>
...@@ -10899,6 +10899,7 @@ interface XR : EventTarget ...@@ -10899,6 +10899,7 @@ interface XR : EventTarget
attribute @@toStringTag attribute @@toStringTag
getter ondevicechange getter ondevicechange
method constructor method constructor
method isSessionSupported
method requestSession method requestSession
method supportsSession method supportsSession
setter ondevicechange setter ondevicechange
......
...@@ -24751,6 +24751,7 @@ Called by update_net_error_codes.py.--> ...@@ -24751,6 +24751,7 @@ Called by update_net_error_codes.py.-->
<int value="3034" <int value="3034"
label="MediaSourceGroupEndTimestampDecreaseWithinMediaSegment"/> label="MediaSourceGroupEndTimestampDecreaseWithinMediaSegment"/>
<int value="3035" label="TextFragmentAnchorTapToDismiss"/> <int value="3035" label="TextFragmentAnchorTapToDismiss"/>
<int value="3036" label="XRIsSessionSupported"/>
</enum> </enum>
<enum name="FeaturePolicyAllowlistType"> <enum name="FeaturePolicyAllowlistType">
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