Commit 058e3d26 authored by François Beaufort's avatar François Beaufort Committed by Commit Bot

Allow Auto Picture-in-Picture for Chrome extensions

Change-Id: I81252edcac31490248001c59623b1da220136451
Reviewed-on: https://chromium-review.googlesource.com/c/1480455
Commit-Queue: François Beaufort <beaufort.francois@gmail.com>
Reviewed-by: default avatarMounir Lamouri <mlamouri@chromium.org>
Cr-Commit-Position: refs/heads/master@{#634844}
parent 90ffaeaa
...@@ -249,18 +249,27 @@ HTMLVideoElement* PictureInPictureControllerImpl::AutoPictureInPictureElement() ...@@ -249,18 +249,27 @@ HTMLVideoElement* PictureInPictureControllerImpl::AutoPictureInPictureElement()
: auto_picture_in_picture_elements_.back(); : auto_picture_in_picture_elements_.back();
} }
void PictureInPictureControllerImpl::PageVisibilityChanged() { bool PictureInPictureControllerImpl::IsAutoPictureInPictureAllowed() const {
DCHECK(GetSupplementable()); // Chrome extensions are allowed to trigger Auto Picture-in-Picture.
if (GetSupplementable()->Url().ProtocolIs("chrome-extension"))
return true;
// Auto Picture-in-Picture is allowed only in a PWA window. // Otherwise, Auto Picture-in-Picture is allowed only in a PWA window.
if (!GetSupplementable()->GetFrame() || if (!GetSupplementable()->GetFrame() ||
GetSupplementable()->GetFrame()->View()->DisplayMode() == GetSupplementable()->GetFrame()->View()->DisplayMode() ==
WebDisplayMode::kWebDisplayModeBrowser) { WebDisplayMode::kWebDisplayModeBrowser) {
return; return false;
} }
// Auto Picture-in-Picture is allowed only in the scope of a PWA. // And if in a PWA window, Auto Picture-in-Picture is allowed only in the
if (!GetSupplementable()->IsInWebAppScope()) // scope of the PWA.
return (GetSupplementable()->IsInWebAppScope());
}
void PictureInPictureControllerImpl::PageVisibilityChanged() {
DCHECK(GetSupplementable());
if (!IsAutoPictureInPictureAllowed())
return; return;
// If page becomes visible and Picture-in-Picture element has entered // If page becomes visible and Picture-in-Picture element has entered
......
...@@ -62,6 +62,11 @@ class MODULES_EXPORT PictureInPictureControllerImpl ...@@ -62,6 +62,11 @@ class MODULES_EXPORT PictureInPictureControllerImpl
// recently. // recently.
HTMLVideoElement* AutoPictureInPictureElement() const; HTMLVideoElement* AutoPictureInPictureElement() const;
// Returns whether Auto Picture-in-Picture is allowed. It returns true if
// it's a Chrome extension or if is's a PWA window in its web app scope.
// Otherwise it returns false.
bool IsAutoPictureInPictureAllowed() const;
// Implementation of PictureInPictureController. // Implementation of PictureInPictureController.
void EnterPictureInPicture(HTMLVideoElement*, void EnterPictureInPicture(HTMLVideoElement*,
ScriptPromiseResolver*) override; ScriptPromiseResolver*) 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