Commit a62ed78c authored by Nate Chapin's avatar Nate Chapin Committed by Commit Bot

Remove usage of ExecutionContextLifecycleObserer::GetFrame() from modules/xr/

Change-Id: I303149a39f40702d6600fa7409f7cfc03146eb65
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2500429
Commit-Queue: Nate Chapin <japhet@chromium.org>
Auto-Submit: Nate Chapin <japhet@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821376}
parent 1421dac0
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h" #include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/dom/frame_request_callback_collection.h" #include "third_party/blink/renderer/core/dom/frame_request_callback_collection.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/imagebitmap/image_bitmap.h" #include "third_party/blink/renderer/core/imagebitmap/image_bitmap.h"
#include "third_party/blink/renderer/core/loader/document_loader.h" #include "third_party/blink/renderer/core/loader/document_loader.h"
...@@ -249,20 +250,14 @@ void XRFrameProvider::ScheduleNonImmersiveFrame( ...@@ -249,20 +250,14 @@ void XRFrameProvider::ScheduleNonImmersiveFrame(
return; return;
} }
LocalFrame* frame = xr_->GetFrame(); LocalDOMWindow* window = xr_->DomWindow();
if (!frame) if (!window)
return;
// TODO(https://crbug.com/856224) Review the lifetime of this object and
// ensure that doc can never be null and remove this check.
Document* doc = frame->GetDocument();
if (!doc)
return; return;
pending_non_immersive_vsync_ = true; pending_non_immersive_vsync_ = true;
// Calls |OnNonImmersiveVSync| // Calls |OnNonImmersiveVSync|
doc->RequestAnimationFrame( window->document()->RequestAnimationFrame(
MakeGarbageCollected<XRFrameProviderRequestCallback>(this)); MakeGarbageCollected<XRFrameProviderRequestCallback>(this));
} }
...@@ -279,11 +274,8 @@ void XRFrameProvider::OnImmersiveFrameData( ...@@ -279,11 +274,8 @@ void XRFrameProvider::OnImmersiveFrameData(
return; return;
} }
LocalFrame* frame = xr_->GetFrame(); LocalDOMWindow* window = xr_->DomWindow();
if (!frame) if (!window)
return;
Document* doc = frame->GetDocument();
if (!doc)
return; return;
if (!first_immersive_frame_time_) { if (!first_immersive_frame_time_) {
...@@ -299,7 +291,8 @@ void XRFrameProvider::OnImmersiveFrameData( ...@@ -299,7 +291,8 @@ void XRFrameProvider::OnImmersiveFrameData(
*first_immersive_frame_time_ + current_frame_time_from_first_frame; *first_immersive_frame_time_ + current_frame_time_from_first_frame;
double high_res_now_ms = double high_res_now_ms =
doc->Loader() window->document()
->Loader()
->GetTiming() ->GetTiming()
.MonotonicTimeToZeroBasedDocumentTime(current_frame_time) .MonotonicTimeToZeroBasedDocumentTime(current_frame_time)
.InMillisecondsF(); .InMillisecondsF();
...@@ -333,7 +326,7 @@ void XRFrameProvider::OnImmersiveFrameData( ...@@ -333,7 +326,7 @@ void XRFrameProvider::OnImmersiveFrameData(
// //
// Used kInternalMedia since 1) this is not spec-ed and 2) this is media // Used kInternalMedia since 1) this is not spec-ed and 2) this is media
// related then tasks should not be throttled or frozen in background tabs. // related then tasks should not be throttled or frozen in background tabs.
frame->GetTaskRunner(blink::TaskType::kInternalMedia) window->GetTaskRunner(blink::TaskType::kInternalMedia)
->PostTask(FROM_HERE, WTF::Bind(&XRFrameProvider::ProcessScheduledFrame, ->PostTask(FROM_HERE, WTF::Bind(&XRFrameProvider::ProcessScheduledFrame,
WrapWeakPersistent(this), std::move(data), WrapWeakPersistent(this), std::move(data),
high_res_now_ms)); high_res_now_ms));
...@@ -349,11 +342,11 @@ void XRFrameProvider::OnNonImmersiveVSync(double high_res_now_ms) { ...@@ -349,11 +342,11 @@ void XRFrameProvider::OnNonImmersiveVSync(double high_res_now_ms) {
if (immersive_session_) if (immersive_session_)
return; return;
LocalFrame* frame = xr_->GetFrame(); LocalDOMWindow* window = xr_->DomWindow();
if (!frame) if (!window)
return; return;
frame->GetTaskRunner(blink::TaskType::kInternalMedia) window->GetTaskRunner(blink::TaskType::kInternalMedia)
->PostTask(FROM_HERE, ->PostTask(FROM_HERE,
WTF::Bind(&XRFrameProvider::ProcessScheduledFrame, WTF::Bind(&XRFrameProvider::ProcessScheduledFrame,
WrapWeakPersistent(this), nullptr, high_res_now_ms)); WrapWeakPersistent(this), nullptr, high_res_now_ms));
...@@ -366,12 +359,8 @@ void XRFrameProvider::OnNonImmersiveFrameData( ...@@ -366,12 +359,8 @@ void XRFrameProvider::OnNonImmersiveFrameData(
DVLOG(2) << __FUNCTION__; DVLOG(2) << __FUNCTION__;
// TODO(https://crbug.com/837834): add unit tests for this code path. // TODO(https://crbug.com/837834): add unit tests for this code path.
LocalDOMWindow* window = xr_->DomWindow();
LocalFrame* frame = xr_->GetFrame(); if (!window)
if (!frame)
return;
Document* doc = frame->GetDocument();
if (!doc)
return; return;
// Look up the request for this session. The session may have ended between // Look up the request for this session. The session may have ended between
...@@ -396,7 +385,7 @@ void XRFrameProvider::OnNonImmersiveFrameData( ...@@ -396,7 +385,7 @@ void XRFrameProvider::OnNonImmersiveFrameData(
// Try to request a regular animation frame to avoid getting stuck. // Try to request a regular animation frame to avoid getting stuck.
DVLOG(1) << __FUNCTION__ << ": NO FRAME DATA!"; DVLOG(1) << __FUNCTION__ << ": NO FRAME DATA!";
request->value = nullptr; request->value = nullptr;
doc->RequestAnimationFrame( window->document()->RequestAnimationFrame(
MakeGarbageCollected<XRFrameProviderRequestCallback>(this)); MakeGarbageCollected<XRFrameProviderRequestCallback>(this));
} }
} }
...@@ -439,10 +428,9 @@ void XRFrameProvider::ProcessScheduledFrame( ...@@ -439,10 +428,9 @@ void XRFrameProvider::ProcessScheduledFrame(
TRACE_EVENT2("gpu", "XRFrameProvider::ProcessScheduledFrame", "frame", TRACE_EVENT2("gpu", "XRFrameProvider::ProcessScheduledFrame", "frame",
frame_id_, "timestamp", high_res_now_ms); frame_id_, "timestamp", high_res_now_ms);
LocalFrame* frame = xr_->GetFrame(); LocalDOMWindow* window = xr_->DomWindow();
if (!frame) { if (!window)
return; return;
}
if (!xr_->IsFrameFocused() && !immersive_session_) { if (!xr_->IsFrameFocused() && !immersive_session_) {
return; // Not currently focused, so we won't expose poses (except to return; // Not currently focused, so we won't expose poses (except to
...@@ -507,7 +495,7 @@ void XRFrameProvider::ProcessScheduledFrame( ...@@ -507,7 +495,7 @@ void XRFrameProvider::ProcessScheduledFrame(
// Run immersive_session_->OnFrame() in a posted task to ensure that // Run immersive_session_->OnFrame() in a posted task to ensure that
// createAnchor promises get a chance to run - the presentation frame state // createAnchor promises get a chance to run - the presentation frame state
// is already updated. // is already updated.
frame->GetTaskRunner(blink::TaskType::kInternalMedia) window->GetTaskRunner(blink::TaskType::kInternalMedia)
->PostTask(FROM_HERE, ->PostTask(FROM_HERE,
WTF::Bind(&XRSession::OnFrame, WTF::Bind(&XRSession::OnFrame,
WrapWeakPersistent(immersive_session_.Get()), WrapWeakPersistent(immersive_session_.Get()),
...@@ -566,7 +554,7 @@ void XRFrameProvider::ProcessScheduledFrame( ...@@ -566,7 +554,7 @@ void XRFrameProvider::ProcessScheduledFrame(
// Note that rather than call session->OnFrame() directly, we dispatch to // Note that rather than call session->OnFrame() directly, we dispatch to
// a helper method who can determine if the state requirements are still // a helper method who can determine if the state requirements are still
// met that would allow the frame to be served. // met that would allow the frame to be served.
frame->GetTaskRunner(blink::TaskType::kInternalMedia) window->GetTaskRunner(blink::TaskType::kInternalMedia)
->PostTask( ->PostTask(
FROM_HERE, FROM_HERE,
WTF::Bind(&XRFrameProvider::OnPreDispatchInlineFrame, WTF::Bind(&XRFrameProvider::OnPreDispatchInlineFrame,
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "third_party/blink/renderer/core/dom/element.h" #include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/dom/events/event_dispatcher.h" #include "third_party/blink/renderer/core/dom/events/event_dispatcher.h"
#include "third_party/blink/renderer/core/dom/events/event_path.h" #include "third_party/blink/renderer/core/dom/events/event_path.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/html/html_frame_element_base.h" #include "third_party/blink/renderer/core/html/html_frame_element_base.h"
#include "third_party/blink/renderer/core/input/event_handling_util.h" #include "third_party/blink/renderer/core/input/event_handling_util.h"
...@@ -277,8 +278,7 @@ void XRInputSource::OnSelectEnd() { ...@@ -277,8 +278,7 @@ void XRInputSource::OnSelectEnd() {
state_.primary_input_pressed = false; state_.primary_input_pressed = false;
LocalFrame* frame = session_->xr()->GetFrame(); if (!session_->xr()->DomWindow())
if (!frame)
return; return;
DVLOG(3) << __func__ << ": dispatch selectend event"; DVLOG(3) << __func__ << ": dispatch selectend event";
...@@ -302,15 +302,16 @@ void XRInputSource::OnSelect() { ...@@ -302,15 +302,16 @@ void XRInputSource::OnSelect() {
OnSelectStart(); OnSelectStart();
} }
LocalFrame* frame = session_->xr()->GetFrame();
LocalFrame::NotifyUserActivation(
frame, mojom::blink::UserActivationNotificationType::kInteraction);
// If SelectStart caused the session to end, we shouldn't try to fire the // If SelectStart caused the session to end, we shouldn't try to fire the
// select event. // select event.
if (!state_.selection_cancelled && !session_->ended()) { LocalDOMWindow* window = session_->xr()->DomWindow();
if (!frame) if (!window)
return; return;
LocalFrame::NotifyUserActivation(
window->GetFrame(),
mojom::blink::UserActivationNotificationType::kInteraction);
if (!state_.selection_cancelled && !session_->ended()) {
DVLOG(3) << __func__ << ": dispatch select event"; DVLOG(3) << __func__ << ": dispatch select event";
XRInputSourceEvent* event = XRInputSourceEvent* event =
CreateInputSourceEvent(event_type_names::kSelect); CreateInputSourceEvent(event_type_names::kSelect);
...@@ -351,8 +352,7 @@ void XRInputSource::OnSqueezeEnd() { ...@@ -351,8 +352,7 @@ void XRInputSource::OnSqueezeEnd() {
state_.primary_squeeze_pressed = false; state_.primary_squeeze_pressed = false;
LocalFrame* frame = session_->xr()->GetFrame(); if (!session_->xr()->DomWindow())
if (!frame)
return; return;
DVLOG(3) << __func__ << ": dispatch squeezeend event"; DVLOG(3) << __func__ << ": dispatch squeezeend event";
...@@ -376,15 +376,18 @@ void XRInputSource::OnSqueeze() { ...@@ -376,15 +376,18 @@ void XRInputSource::OnSqueeze() {
OnSqueezeStart(); OnSqueezeStart();
} }
LocalFrame* frame = session_->xr()->GetFrame(); // If SelectStart caused the session to end, we shouldn't try to fire the
// select event.
LocalDOMWindow* window = session_->xr()->DomWindow();
if (!window)
return;
LocalFrame::NotifyUserActivation( LocalFrame::NotifyUserActivation(
frame, mojom::blink::UserActivationNotificationType::kInteraction); window->GetFrame(),
mojom::blink::UserActivationNotificationType::kInteraction);
// If SelectStart caused the session to end, we shouldn't try to fire the // If SelectStart caused the session to end, we shouldn't try to fire the
// select event. // select event.
if (!state_.squeezing_cancelled && !session_->ended()) { if (!state_.squeezing_cancelled && !session_->ended()) {
if (!frame)
return;
DVLOG(3) << __func__ << ": dispatch squeeze event"; DVLOG(3) << __func__ << ": dispatch squeeze event";
XRInputSourceEvent* event = XRInputSourceEvent* event =
CreateInputSourceEvent(event_type_names::kSqueeze); CreateInputSourceEvent(event_type_names::kSqueeze);
......
...@@ -211,16 +211,15 @@ bool HasRequiredFeaturePolicy(const ExecutionContext* context, ...@@ -211,16 +211,15 @@ bool HasRequiredFeaturePolicy(const ExecutionContext* context,
// Ensure that the immersive session request is allowed, if not // Ensure that the immersive session request is allowed, if not
// return which security error occurred. // return which security error occurred.
// https://immersive-web.github.io/webxr/#immersive-session-request-is-allowed // https://immersive-web.github.io/webxr/#immersive-session-request-is-allowed
const char* CheckImmersiveSessionRequestAllowed(LocalFrame* frame, const char* CheckImmersiveSessionRequestAllowed(LocalDOMWindow* window) {
Document* doc) {
// Ensure that the session was initiated by a user gesture // Ensure that the session was initiated by a user gesture
if (!LocalFrame::HasTransientUserActivation(frame)) { if (!LocalFrame::HasTransientUserActivation(window->GetFrame())) {
return kRequestRequiresUserActivation; return kRequestRequiresUserActivation;
} }
// Check that the document is "trustworthy" // Check that the document is "trustworthy"
// https://immersive-web.github.io/webxr/#trustworthy // https://immersive-web.github.io/webxr/#trustworthy
if (!doc->IsPageVisible()) { if (!window->document()->IsPageVisible()) {
return kPageNotVisible; return kPageNotVisible;
} }
...@@ -480,9 +479,7 @@ void XRSystem::PendingRequestSessionQuery::ReportRequestSessionResult( ...@@ -480,9 +479,7 @@ void XRSystem::PendingRequestSessionQuery::ReportRequestSessionResult(
metrics_recorder) { metrics_recorder) {
using device::mojom::XRSessionFeature; using device::mojom::XRSessionFeature;
LocalFrame* frame = resolver_->GetFrame(); if (!resolver_->DomWindow())
Document* doc = frame ? frame->GetDocument() : nullptr;
if (!doc)
return; return;
auto feature_request_viewer = auto feature_request_viewer =
...@@ -509,7 +506,7 @@ void XRSystem::PendingRequestSessionQuery::ReportRequestSessionResult( ...@@ -509,7 +506,7 @@ void XRSystem::PendingRequestSessionQuery::ReportRequestSessionResult(
.SetFeature_BoundedFloor( .SetFeature_BoundedFloor(
static_cast<int64_t>(feature_request_bounded_floor)) static_cast<int64_t>(feature_request_bounded_floor))
.SetFeature_Unbounded(static_cast<int64_t>(feature_request_unbounded)) .SetFeature_Unbounded(static_cast<int64_t>(feature_request_unbounded))
.Record(doc->UkmRecorder()); .Record(resolver_->DomWindow()->UkmRecorder());
// If the session was successfully created and DOM overlay was requested, // If the session was successfully created and DOM overlay was requested,
// count this as a use of the DOM overlay feature. // count this as a use of the DOM overlay feature.
...@@ -828,7 +825,8 @@ void XRSystem::FocusedFrameChanged() { ...@@ -828,7 +825,8 @@ void XRSystem::FocusedFrameChanged() {
} }
bool XRSystem::IsFrameFocused() { bool XRSystem::IsFrameFocused() {
return FocusChangedObserver::IsFrameFocused(GetFrame()); return FocusChangedObserver::IsFrameFocused(
DomWindow() ? DomWindow()->GetFrame() : nullptr);
} }
ExecutionContext* XRSystem::GetExecutionContext() const { ExecutionContext* XRSystem::GetExecutionContext() const {
...@@ -869,10 +867,8 @@ void XRSystem::ExitPresent(base::OnceClosure on_exited) { ...@@ -869,10 +867,8 @@ void XRSystem::ExitPresent(base::OnceClosure on_exited) {
// because doc->IsXrOverlay() is still true at this point // because doc->IsXrOverlay() is still true at this point
// - renderer processes XR session shutdown (this method) // - renderer processes XR session shutdown (this method)
// - browser re-enters fullscreen unexpectedly // - browser re-enters fullscreen unexpectedly
LocalFrame* frame = GetFrame(); if (LocalDOMWindow* window = DomWindow()) {
if (frame) { Document* doc = window->document();
Document* doc = frame->GetDocument();
DCHECK(doc);
DVLOG(3) << __func__ << ": doc->IsXrOverlay()=" << doc->IsXrOverlay(); DVLOG(3) << __func__ << ": doc->IsXrOverlay()=" << doc->IsXrOverlay();
if (doc->IsXrOverlay()) { if (doc->IsXrOverlay()) {
Element* fullscreen_element = Fullscreen::FullscreenElementFrom(*doc); Element* fullscreen_element = Fullscreen::FullscreenElementFrom(*doc);
...@@ -1003,22 +999,20 @@ ScriptPromise XRSystem::InternalIsSessionSupported( ...@@ -1003,22 +999,20 @@ ScriptPromise XRSystem::InternalIsSessionSupported(
return promise; return promise;
} }
void XRSystem::RequestImmersiveSession(LocalFrame* frame, void XRSystem::RequestImmersiveSession(PendingRequestSessionQuery* query,
Document* doc,
PendingRequestSessionQuery* query,
ExceptionState* exception_state) { ExceptionState* exception_state) {
DVLOG(2) << __func__; DVLOG(2) << __func__;
// Log an immersive session request if we haven't already // Log an immersive session request if we haven't already
if (!did_log_request_immersive_session_) { if (!did_log_request_immersive_session_) {
ukm::builders::XR_WebXR(doc->UkmSourceID()) ukm::builders::XR_WebXR(DomWindow()->UkmSourceID())
.SetDidRequestPresentation(1) .SetDidRequestPresentation(1)
.Record(doc->UkmRecorder()); .Record(DomWindow()->UkmRecorder());
did_log_request_immersive_session_ = true; did_log_request_immersive_session_ = true;
} }
// Make sure the request is allowed // Make sure the request is allowed
auto* immersive_session_request_error = auto* immersive_session_request_error =
CheckImmersiveSessionRequestAllowed(frame, doc); CheckImmersiveSessionRequestAllowed(DomWindow());
if (immersive_session_request_error) { if (immersive_session_request_error) {
DVLOG(2) << __func__ DVLOG(2) << __func__
<< ": rejecting session - immersive session not allowed, reason: " << ": rejecting session - immersive session not allowed, reason: "
...@@ -1069,9 +1063,10 @@ void XRSystem::RequestImmersiveSession(LocalFrame* frame, ...@@ -1069,9 +1063,10 @@ void XRSystem::RequestImmersiveSession(LocalFrame* frame,
// we need to exit and re-enter fullscreen mode to properly apply the // we need to exit and re-enter fullscreen mode to properly apply the
// is_xr_overlay property. Request a fullscreen exit, and continue with // is_xr_overlay property. Request a fullscreen exit, and continue with
// the session request once that completes. // the session request once that completes.
Document* doc = DomWindow()->document();
if (query->DOMOverlayElement() && Fullscreen::FullscreenElementFrom(*doc)) { if (query->DOMOverlayElement() && Fullscreen::FullscreenElementFrom(*doc)) {
bool has_remote_ancestor = false; bool has_remote_ancestor = false;
for (Frame* f = GetFrame(); f; f = f->Tree().Parent()) { for (Frame* f = DomWindow()->GetFrame(); f; f = f->Tree().Parent()) {
if (f->IsRemoteFrame()) { if (f->IsRemoteFrame()) {
has_remote_ancestor = true; has_remote_ancestor = true;
break; break;
...@@ -1108,13 +1103,12 @@ void XRSystem::DoRequestSession( ...@@ -1108,13 +1103,12 @@ void XRSystem::DoRequestSession(
service_->RequestSession(std::move(session_options), std::move(callback)); service_->RequestSession(std::move(session_options), std::move(callback));
} }
void XRSystem::RequestInlineSession(LocalFrame* frame, void XRSystem::RequestInlineSession(PendingRequestSessionQuery* query,
PendingRequestSessionQuery* query,
ExceptionState* exception_state) { ExceptionState* exception_state) {
DVLOG(2) << __func__; DVLOG(2) << __func__;
// Make sure the inline session request was allowed // Make sure the inline session request was allowed
auto* inline_session_request_error = auto* inline_session_request_error =
CheckInlineSessionRequestAllowed(frame, *query); CheckInlineSessionRequestAllowed(DomWindow()->GetFrame(), *query);
if (inline_session_request_error) { if (inline_session_request_error) {
query->RejectWithSecurityError(inline_session_request_error, query->RejectWithSecurityError(inline_session_request_error,
exception_state); exception_state);
...@@ -1222,10 +1216,8 @@ ScriptPromise XRSystem::requestSession(ScriptState* script_state, ...@@ -1222,10 +1216,8 @@ ScriptPromise XRSystem::requestSession(ScriptState* script_state,
DVLOG(2) << __func__; DVLOG(2) << __func__;
// TODO(https://crbug.com/968622): Make sure we don't forget to call // TODO(https://crbug.com/968622): Make sure we don't forget to call
// metrics-related methods when the promise gets resolved/rejected. // metrics-related methods when the promise gets resolved/rejected.
LocalFrame* frame = GetFrame(); if (!DomWindow()) {
Document* doc = frame ? frame->GetDocument() : nullptr; // Reject if the window is inaccessible.
if (!doc) {
// Reject if the frame or doc is inaccessible.
// Do *not* record an UKM event in this case (we won't be able to access the // Do *not* record an UKM event in this case (we won't be able to access the
// Document to get UkmRecorder anyway). // Document to get UkmRecorder anyway).
...@@ -1245,10 +1237,10 @@ ScriptPromise XRSystem::requestSession(ScriptState* script_state, ...@@ -1245,10 +1237,10 @@ ScriptPromise XRSystem::requestSession(ScriptState* script_state,
// We haven't created the query yet, so we can't use it to implicitly log // We haven't created the query yet, so we can't use it to implicitly log
// our metrics for us, so explicitly log it here, as the query requires the // our metrics for us, so explicitly log it here, as the query requires the
// features to be parsed before it can be built. // features to be parsed before it can be built.
ukm::builders::XR_WebXR_SessionRequest(doc->UkmSourceID()) ukm::builders::XR_WebXR_SessionRequest(DomWindow()->UkmSourceID())
.SetMode(static_cast<int64_t>(session_mode)) .SetMode(static_cast<int64_t>(session_mode))
.SetStatus(static_cast<int64_t>(SessionRequestStatus::kOtherError)) .SetStatus(static_cast<int64_t>(SessionRequestStatus::kOtherError))
.Record(doc->UkmRecorder()); .Record(DomWindow()->UkmRecorder());
return ScriptPromise(); return ScriptPromise();
} }
...@@ -1299,7 +1291,7 @@ ScriptPromise XRSystem::requestSession(ScriptState* script_state, ...@@ -1299,7 +1291,7 @@ ScriptPromise XRSystem::requestSession(ScriptState* script_state,
PendingRequestSessionQuery* query = PendingRequestSessionQuery* query =
MakeGarbageCollected<PendingRequestSessionQuery>( MakeGarbageCollected<PendingRequestSessionQuery>(
doc->UkmSourceID(), resolver, session_mode, DomWindow()->UkmSourceID(), resolver, session_mode,
std::move(required_features), std::move(optional_features)); std::move(required_features), std::move(optional_features));
if (query->HasFeature(device::mojom::XRSessionFeature::DOM_OVERLAY)) { if (query->HasFeature(device::mojom::XRSessionFeature::DOM_OVERLAY)) {
...@@ -1315,10 +1307,10 @@ ScriptPromise XRSystem::requestSession(ScriptState* script_state, ...@@ -1315,10 +1307,10 @@ ScriptPromise XRSystem::requestSession(ScriptState* script_state,
switch (session_mode) { switch (session_mode) {
case device::mojom::blink::XRSessionMode::kImmersiveVr: case device::mojom::blink::XRSessionMode::kImmersiveVr:
case device::mojom::blink::XRSessionMode::kImmersiveAr: case device::mojom::blink::XRSessionMode::kImmersiveAr:
RequestImmersiveSession(frame, doc, query, &exception_state); RequestImmersiveSession(query, &exception_state);
break; break;
case device::mojom::blink::XRSessionMode::kInline: case device::mojom::blink::XRSessionMode::kInline:
RequestInlineSession(frame, query, &exception_state); RequestInlineSession(query, &exception_state);
break; break;
} }
...@@ -1474,21 +1466,18 @@ void XRSystem::OnRequestSessionReturned( ...@@ -1474,21 +1466,18 @@ void XRSystem::OnRequestSessionReturned(
session->OnEnvironmentProviderCreated(); session->OnEnvironmentProviderCreated();
LocalFrame* frame = GetFrame(); DCHECK(DomWindow());
DCHECK(frame);
if (query->HasFeature(device::mojom::XRSessionFeature::DOM_OVERLAY)) { if (query->HasFeature(device::mojom::XRSessionFeature::DOM_OVERLAY)) {
DCHECK(query->DOMOverlayElement()); DCHECK(query->DOMOverlayElement());
// The session is using DOM overlay mode. At this point the overlay // The session is using DOM overlay mode. At this point the overlay
// element is already in fullscreen mode, and the session can // element is already in fullscreen mode, and the session can
// proceed. // proceed.
Document* doc = frame->GetDocument();
DCHECK(doc);
session->SetDOMOverlayElement(query->DOMOverlayElement()); session->SetDOMOverlayElement(query->DOMOverlayElement());
// Save the current base background color (restored in ExitPresent), // Save the current base background color (restored in ExitPresent),
// and set a transparent background for the FrameView. // and set a transparent background for the FrameView.
auto* frame_view = doc->GetLayoutView()->GetFrameView(); auto* frame_view =
DomWindow()->document()->GetLayoutView()->GetFrameView();
// SetBaseBackgroundColor updates composited layer mappings. // SetBaseBackgroundColor updates composited layer mappings.
// That DCHECKs IsAllowedToQueryCompositingState which requires // That DCHECKs IsAllowedToQueryCompositingState which requires
// DocumentLifecycle >= kInCompositingUpdate. // DocumentLifecycle >= kInCompositingUpdate.
...@@ -1512,16 +1501,6 @@ void XRSystem::OnRequestSessionReturned( ...@@ -1512,16 +1501,6 @@ void XRSystem::OnRequestSessionReturned(
query->Resolve(session, std::move(metrics_recorder)); query->Resolve(session, std::move(metrics_recorder));
} }
void XRSystem::ReportImmersiveSupported(bool supported) {
Document* doc = GetFrame() ? GetFrame()->GetDocument() : nullptr;
if (doc && !did_log_supports_immersive_ && supported) {
ukm::builders::XR_WebXR ukm_builder(doc->UkmSourceID());
ukm_builder.SetReturnedPresentationCapableDevice(1);
ukm_builder.Record(doc->UkmRecorder());
did_log_supports_immersive_ = true;
}
}
void XRSystem::AddedEventListener( void XRSystem::AddedEventListener(
const AtomicString& event_type, const AtomicString& event_type,
RegisteredEventListener& registered_listener) { RegisteredEventListener& registered_listener) {
...@@ -1652,16 +1631,15 @@ void XRSystem::TryEnsureService() { ...@@ -1652,16 +1631,15 @@ void XRSystem::TryEnsureService() {
} }
// If the current frame isn't attached, don't try to get the service. // If the current frame isn't attached, don't try to get the service.
LocalFrame* frame = GetFrame(); if (!DomWindow()) {
if (!frame || !frame->IsAttached()) {
DVLOG(2) << ": current frame is not attached"; DVLOG(2) << ": current frame is not attached";
return; return;
} }
// See https://bit.ly/2S0zRAS for task types. // See https://bit.ly/2S0zRAS for task types.
frame->GetBrowserInterfaceBroker().GetInterface( DomWindow()->GetBrowserInterfaceBroker().GetInterface(
service_.BindNewPipeAndPassReceiver( service_.BindNewPipeAndPassReceiver(
frame->GetTaskRunner(TaskType::kMiscPlatformAPI))); DomWindow()->GetTaskRunner(TaskType::kMiscPlatformAPI)));
service_.set_disconnect_handler(WTF::Bind(&XRSystem::Dispose, service_.set_disconnect_handler(WTF::Bind(&XRSystem::Dispose,
WrapWeakPersistent(this), WrapWeakPersistent(this),
DisposeType::kDisconnected)); DisposeType::kDisconnected));
......
...@@ -364,13 +364,10 @@ class XRSystem final : public EventTargetWithInlineData, ...@@ -364,13 +364,10 @@ class XRSystem final : public EventTargetWithInlineData,
XRSessionInit* session_init, XRSessionInit* session_init,
mojom::ConsoleMessageLevel error_level); mojom::ConsoleMessageLevel error_level);
void RequestImmersiveSession(LocalFrame* frame, void RequestImmersiveSession(PendingRequestSessionQuery* query,
Document* doc,
PendingRequestSessionQuery* query,
ExceptionState* exception_state); ExceptionState* exception_state);
void RequestInlineSession(LocalFrame* frame, void RequestInlineSession(PendingRequestSessionQuery* query,
PendingRequestSessionQuery* query,
ExceptionState* exception_state); ExceptionState* exception_state);
void DoRequestSession( void DoRequestSession(
...@@ -390,7 +387,6 @@ class XRSystem final : public EventTargetWithInlineData, ...@@ -390,7 +387,6 @@ class XRSystem final : public EventTargetWithInlineData,
void RejectSessionRequest(PendingRequestSessionQuery*); void RejectSessionRequest(PendingRequestSessionQuery*);
void EnsureDevice(); void EnsureDevice();
void ReportImmersiveSupported(bool supported);
void AddedEventListener(const AtomicString& event_type, void AddedEventListener(const AtomicString& event_type,
RegisteredEventListener&) override; RegisteredEventListener&) override;
......
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