blob: 1c5c2f36baa9974fe5aaac2c8ce45fe2eff1b015 [file] [log] [blame]
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/core/frame/picture_in_picture_controller.h"
namespace blink {
class HTMLVideoElement;
class PictureInPictureWindow;
class TreeScope;
struct WebSize;
// The PictureInPictureControllerImpl is keeping the state and implementing the
// logic around the Picture-in-Picture feature. It is meant to be used as well
// by the Picture-in-Picture Web API and internally (eg. media controls). All
// consumers inside Blink modules/ should use this class to access
// Picture-in-Picture. In core/, they should use PictureInPictureController.
// PictureInPictureControllerImpl instance is associated to a Document. It is
// supplement and therefore can be lazy-initiated. Callers should consider
// whether they want to instantiate an object when they make a call.
class PictureInPictureControllerImpl : public PictureInPictureController {
explicit PictureInPictureControllerImpl(Document&);
~PictureInPictureControllerImpl() override;
// Meant to be called internally by PictureInPictureController::From()
// through ModulesInitializer.
static PictureInPictureControllerImpl* Create(Document&);
// Gets, or creates, PictureInPictureControllerImpl supplement on Document.
// Should be called before any other call to make sure a document is attached.
static PictureInPictureControllerImpl& From(Document&);
// Returns whether system allows Picture-in-Picture feature or not for
// the associated document.
bool PictureInPictureEnabled() const;
// Returns whether the document associated with the controller is allowed to
// request Picture-in-Picture.
Status IsDocumentAllowed() const;
// Returns element currently in Picture-in-Picture if any. Null otherwise.
Element* PictureInPictureElement() const;
Element* PictureInPictureElement(TreeScope&) const;
// Implementation of PictureInPictureController.
void EnterPictureInPicture(HTMLVideoElement*,
ScriptPromiseResolver*) override;
void ExitPictureInPicture(HTMLVideoElement*, ScriptPromiseResolver*) override;
void SetPictureInPictureCustomControls(
const std::vector<PictureInPictureControlInfo>&) override;
Status IsElementAllowed(const HTMLVideoElement&) const override;
bool IsPictureInPictureElement(const Element*) const override;
void Trace(blink::Visitor*) override;
void OnEnteredPictureInPicture(HTMLVideoElement*,
const WebSize& picture_in_picture_window_size);
void OnExitedPictureInPicture(ScriptPromiseResolver*) override;
void OnPictureInPictureControlClicked(const WebString& control_id) override;
// The Picture-in-Picture element for the associated document.
Member<HTMLVideoElement> picture_in_picture_element_;
// The Picture-in-Picture window for the associated document.
Member<PictureInPictureWindow> picture_in_picture_window_;
} // namespace blink