1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
// 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.
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_PICTURE_IN_PICTURE_CONTROLLER_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_PICTURE_IN_PICTURE_CONTROLLER_H_
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/platform/supplementable.h"
namespace blink {
class HTMLElement;
class HTMLVideoElement;
class PictureInPictureOptions;
class ScriptPromiseResolver;
// PictureInPictureController allows to know if Picture-in-Picture is allowed
// for a video element in Blink outside of modules/ module. It
// is an interface that the module will implement and add a provider for.
class CORE_EXPORT PictureInPictureController
: public GarbageCollected<PictureInPictureController>,
public Supplement<Document> {
USING_GARBAGE_COLLECTED_MIXIN(PictureInPictureController);
public:
static const char kSupplementName[];
virtual ~PictureInPictureController() = default;
// Should be called before any other call to make sure a document is attached.
static PictureInPictureController& From(Document&);
// Returns whether the given element is currently in Picture-in-Picture. It
// returns false if PictureInPictureController is not attached to a document.
static bool IsElementInPictureInPicture(const Element*);
// List of Picture-in-Picture support statuses. If status is kEnabled,
// Picture-in-Picture is enabled for a document or element, otherwise it is
// not supported.
enum class Status {
kEnabled,
kFrameDetached,
kMetadataNotLoaded,
kVideoTrackNotAvailable,
kDisabledBySystem,
kDisabledByFeaturePolicy,
kDisabledByAttribute,
kInvalidWidthOrHeightOption,
};
// Enter Picture-in-Picture for an element with options if any and resolve
// promise if any.
virtual void EnterPictureInPicture(HTMLElement*,
PictureInPictureOptions*,
ScriptPromiseResolver*) = 0;
// Exit Picture-in-Picture for a video element and resolve promise if any.
virtual void ExitPictureInPicture(HTMLVideoElement*,
ScriptPromiseResolver*) = 0;
// Returns whether a given element in a document associated with the
// controller is allowed to request Picture-in-Picture.
virtual Status IsElementAllowed(const HTMLElement&) const = 0;
// Should be called when an element has exited Picture-in-Picture.
virtual void OnExitedPictureInPicture(ScriptPromiseResolver*) = 0;
// Add video element to the list of video elements for the associated document
// that are eligible to Auto Picture-in-Picture.
virtual void AddToAutoPictureInPictureElementsList(HTMLVideoElement*) = 0;
// Remove video element from the list of video elements for the associated
// document that are eligible to Auto Picture-in-Picture.
virtual void RemoveFromAutoPictureInPictureElementsList(
HTMLVideoElement*) = 0;
// Notifies that one of the states used by Picture-in-Picture has changed.
virtual void OnPictureInPictureStateChange() = 0;
void Trace(Visitor*) override;
protected:
explicit PictureInPictureController(Document&);
// Returns whether the given element is currently in Picture-in-Picture.
// It is protected so that clients use the static method
// IsElementInPictureInPicture() that avoids creating the controller.
virtual bool IsPictureInPictureElement(const Element*) const = 0;
DISALLOW_COPY_AND_ASSIGN(PictureInPictureController);
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_PICTURE_IN_PICTURE_CONTROLLER_H_
|