OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef AutoplayPolicy_h | |
6 #define AutoplayPolicy_h | |
7 | |
8 #include "bindings/core/v8/Nullable.h" | |
9 #include "core/dom/ExceptionCode.h" | |
10 #include "platform/heap/Handle.h" | |
11 | |
12 namespace blink { | |
13 | |
14 class AutoplayUmaHelper; | |
15 class Document; | |
16 class ElementVisibilityObserver; | |
17 class HTMLMediaElement; | |
18 | |
19 // AutoplayPolicy is the class for handles autoplay logics. | |
20 class AutoplayPolicy final : public GarbageCollected<AutoplayPolicy> { | |
21 public: | |
22 explicit AutoplayPolicy(HTMLMediaElement*); | |
23 | |
24 void VideoWillBeDrawnToCanvas() const; | |
25 | |
26 // Called when the media element is moved to a new document. | |
27 void DidMoveToNewDocument(Document& old_document); | |
28 | |
29 // Stop autoplaying the video element whenever its visible. | |
30 // TODO(mlamouri): hide these methods from HTMLMediaElement. | |
31 void StopAutoplayMutedWhenVisible(); | |
32 | |
33 // Request autoplay by attribute. This method will check the autoplay | |
34 // restrictions and record metrics. This method can only be called once per | |
35 // time the readyState changes to HAVE_ENOUGH_DATA. | |
36 bool RequestAutoplayByAttribute(); | |
37 | |
38 // Request the playback via play() method. This method will check the autoplay | |
39 // restrictions and record metrics. This method can only be called once | |
40 // per call of play(). | |
41 Nullable<ExceptionCode> RequestPlay(); | |
42 | |
43 // Returns whether an umute action should pause an autoplaying element. The | |
44 // method will check autoplay restrictions and record metrics. This method can | |
45 // only be called once per call of setMuted(). | |
46 bool RequestAutoplayUnmute(); | |
47 | |
48 bool IsAutoplayingMuted(bool muted) const; | |
mlamouri (slow - plz ping)
2017/04/20 15:51:06
could you have |IsAutoplayingMutedInternal| with t
| |
49 | |
50 // Unlock user gesture if a user gesture can be utilized. | |
51 void TryUnlockingUserGesture(); | |
52 | |
53 // Return true if and only if a user gesture is requried for playback. Even | |
54 // if isLockedPendingUserGesture() return true, this might return false if | |
55 // the requirement is currently overridden. This does not check if a user | |
56 // gesture is currently being processed. | |
57 bool IsGestureNeededForPlayback() const; | |
58 | |
59 // Return true if and only if the settings allow autoplay of media on this | |
60 // frame. | |
61 bool IsAutoplayAllowedPerSettings() const; | |
62 | |
63 DECLARE_VIRTUAL_TRACE(); | |
64 | |
65 private: | |
66 friend class AutoplayUmaHelperTest; | |
67 | |
68 // Start autoplaying the video element whenever its visible. | |
69 void StartAutoplayMutedWhenVisible(); | |
70 | |
71 // Returns whether the media element is eligible to autoplay muted. | |
72 bool IsEligibleForAutoplayMuted() const; | |
73 | |
74 bool ShouldAutoplay(); | |
75 | |
76 // If the user gesture is required, then this will remove it. Note that | |
77 // one should not generally call this method directly; use the one on | |
78 // m_helper and give it a reason. | |
79 void UnlockUserGesture(); | |
80 | |
81 // Return true if and only if a user gesture is required to unlock this | |
82 // media element for unrestricted autoplay/script control. Don't confuse | |
83 // this with isGestureNeededForPlayback(). The latter is usually what one | |
84 // should use, if checking to see if an action is allowed. | |
85 bool IsLockedPendingUserGesture() const; | |
86 | |
87 bool IsLockedPendingUserGestureIfCrossOriginExperimentEnabled() const; | |
88 | |
89 bool IsGestureNeededForPlaybackIfCrossOriginExperimentEnabled() const; | |
90 | |
91 bool IsGestureNeededForPlaybackIfPendingUserGestureIsLocked() const; | |
92 | |
93 // Called when the video visibility changes while autoplaying muted, will | |
94 // pause the video when invisible and resume the video when visible. | |
95 void OnVisibilityChangedForAutoplay(bool is_visible); | |
96 | |
97 bool locked_pending_user_gesture_ : 1; | |
98 bool locked_pending_user_gesture_if_cross_origin_experiment_enabled_ : 1; | |
99 | |
100 Member<HTMLMediaElement> element_; | |
101 Member<ElementVisibilityObserver> autoplay_visibility_observer_; | |
102 | |
103 Member<AutoplayUmaHelper> autoplay_uma_helper_; | |
104 | |
105 DISALLOW_COPY_AND_ASSIGN(AutoplayPolicy); | |
106 }; | |
107 | |
108 } // namespace blink | |
109 | |
110 #endif // AutoplayPolicy_h | |
OLD | NEW |