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