Commit dab2e9a7 authored by Jazz Xu's avatar Jazz Xu Committed by Commit Bot

GMC: Fix pip button not showing up when media loading is slow.

This CL fix the issue by updating pip availability when media loading
is complete.

Bug: 1051142
Change-Id: Iea84f73aca6af85d951f4e7ca20240b597ef0ab3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2044657
Commit-Queue: Tommy Steimel <steimel@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarMounir Lamouri <mlamouri@chromium.org>
Reviewed-by: default avatarDavid Bokan <bokan@chromium.org>
Reviewed-by: default avatarTommy Steimel <steimel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#741693}
parent 360d48b9
...@@ -394,6 +394,8 @@ void HTMLVideoElement::OnLoadFinished() { ...@@ -394,6 +394,8 @@ void HTMLVideoElement::OnLoadFinished() {
WrapWeakPersistent(this))); WrapWeakPersistent(this)));
lazy_load_intersection_observer_->observe(this); lazy_load_intersection_observer_->observe(this);
} }
UpdatePictureInPictureAvailability();
} }
void HTMLVideoElement::PaintCurrentFrame( void HTMLVideoElement::PaintCurrentFrame(
......
...@@ -52,11 +52,11 @@ PictureInPictureControllerImpl& PictureInPictureControllerImpl::From( ...@@ -52,11 +52,11 @@ PictureInPictureControllerImpl& PictureInPictureControllerImpl::From(
} }
bool PictureInPictureControllerImpl::PictureInPictureEnabled() const { bool PictureInPictureControllerImpl::PictureInPictureEnabled() const {
return IsDocumentAllowed() == Status::kEnabled; return IsDocumentAllowed(/*report_failure=*/true) == Status::kEnabled;
} }
PictureInPictureController::Status PictureInPictureController::Status
PictureInPictureControllerImpl::IsDocumentAllowed() const { PictureInPictureControllerImpl::IsDocumentAllowed(bool report_failure) const {
DCHECK(GetSupplementable()); DCHECK(GetSupplementable());
// If document has been detached from a frame, return kFrameDetached status. // If document has been detached from a frame, return kFrameDetached status.
...@@ -75,7 +75,8 @@ PictureInPictureControllerImpl::IsDocumentAllowed() const { ...@@ -75,7 +75,8 @@ PictureInPictureControllerImpl::IsDocumentAllowed() const {
if (RuntimeEnabledFeatures::PictureInPictureAPIEnabled() && if (RuntimeEnabledFeatures::PictureInPictureAPIEnabled() &&
!GetSupplementable()->IsFeatureEnabled( !GetSupplementable()->IsFeatureEnabled(
blink::mojom::blink::FeaturePolicyFeature::kPictureInPicture, blink::mojom::blink::FeaturePolicyFeature::kPictureInPicture,
ReportOptions::kReportOnFailure)) { report_failure ? ReportOptions::kReportOnFailure
: ReportOptions::kDoNotReport)) {
return Status::kDisabledByFeaturePolicy; return Status::kDisabledByFeaturePolicy;
} }
...@@ -98,13 +99,19 @@ PictureInPictureControllerImpl::VerifyElementAndOptions( ...@@ -98,13 +99,19 @@ PictureInPictureControllerImpl::VerifyElementAndOptions(
} }
} }
return IsElementAllowed(element); return IsElementAllowed(element, /*report_failure=*/true);
} }
PictureInPictureController::Status PictureInPictureController::Status
PictureInPictureControllerImpl::IsElementAllowed( PictureInPictureControllerImpl::IsElementAllowed(
const HTMLElement& element) const { const HTMLElement& element) const {
PictureInPictureController::Status status = IsDocumentAllowed(); return IsElementAllowed(element, /*report_failure=*/false);
}
PictureInPictureController::Status
PictureInPictureControllerImpl::IsElementAllowed(const HTMLElement& element,
bool report_failure) const {
PictureInPictureController::Status status = IsDocumentAllowed(report_failure);
if (status != Status::kEnabled) if (status != Status::kEnabled)
return status; return status;
...@@ -199,7 +206,7 @@ void PictureInPictureControllerImpl::OnEnteredPictureInPicture( ...@@ -199,7 +206,7 @@ void PictureInPictureControllerImpl::OnEnteredPictureInPicture(
mojo::Remote<mojom::blink::PictureInPictureSession>( mojo::Remote<mojom::blink::PictureInPictureSession>(
std::move(session_remote)); std::move(session_remote));
if (IsElementAllowed(*element) != Status::kEnabled) { if (IsElementAllowed(*element, /*report_failure=*/true) != Status::kEnabled) {
if (resolver) { if (resolver) {
resolver->Reject(MakeGarbageCollected<DOMException>( resolver->Reject(MakeGarbageCollected<DOMException>(
DOMExceptionCode::kInvalidStateError, "")); DOMExceptionCode::kInvalidStateError, ""));
...@@ -334,7 +341,8 @@ bool PictureInPictureControllerImpl::IsEnterAutoPictureInPictureAllowed() ...@@ -334,7 +341,8 @@ bool PictureInPictureControllerImpl::IsEnterAutoPictureInPictureAllowed()
return false; return false;
// Allow if video is allowed to enter Picture-in-Picture. // Allow if video is allowed to enter Picture-in-Picture.
return (IsElementAllowed(*AutoPictureInPictureElement()) == Status::kEnabled); return (IsElementAllowed(*AutoPictureInPictureElement(),
/*report_failure=*/true) == Status::kEnabled);
} }
bool PictureInPictureControllerImpl::IsExitAutoPictureInPictureAllowed() const { bool PictureInPictureControllerImpl::IsExitAutoPictureInPictureAllowed() const {
......
...@@ -51,7 +51,7 @@ class MODULES_EXPORT PictureInPictureControllerImpl ...@@ -51,7 +51,7 @@ class MODULES_EXPORT PictureInPictureControllerImpl
// Returns whether the document associated with the controller is allowed to // Returns whether the document associated with the controller is allowed to
// request Picture-in-Picture. // request Picture-in-Picture.
Status IsDocumentAllowed() const; Status IsDocumentAllowed(bool report_failure) const;
// Returns whether the combination of element and options can be in // Returns whether the combination of element and options can be in
// Picture-in-Picture. // Picture-in-Picture.
...@@ -106,6 +106,7 @@ class MODULES_EXPORT PictureInPictureControllerImpl ...@@ -106,6 +106,7 @@ class MODULES_EXPORT PictureInPictureControllerImpl
mojo::PendingRemote<mojom::blink::PictureInPictureSession>, mojo::PendingRemote<mojom::blink::PictureInPictureSession>,
const gfx::Size&); const gfx::Size&);
void OnExitedPictureInPicture(ScriptPromiseResolver*) override; void OnExitedPictureInPicture(ScriptPromiseResolver*) override;
Status IsElementAllowed(const HTMLElement&, bool report_failure) const;
// Makes sure the `picture_in_picture_service_` is set. Returns whether it was // Makes sure the `picture_in_picture_service_` is set. Returns whether it was
// initialized successfully. // initialized successfully.
......
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