Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: third_party/WebKit/Source/core/html/media/AutoplayPolicy.h

Issue 2813303005: [Blink>Media] Moving autoplay logic to AutoplayPolicy (Closed)
Patch Set: addressed nits Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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() const;
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 DECLARE_VIRTUAL_TRACE();
60
61 private:
62 friend class AutoplayUmaHelper;
63 friend class AutoplayUmaHelperTest;
64
65 // Start autoplaying the video element whenever its visible.
66 void StartAutoplayMutedWhenVisible();
67
68 // Returns whether the media element is eligible to autoplay muted.
69 bool IsEligibleForAutoplayMuted() const;
70
71 bool ShouldAutoplay();
72
73 // If the user gesture is required, then this will remove it. Note that
74 // one should not generally call this method directly; use the one on
75 // m_helper and give it a reason.
76 void UnlockUserGesture();
77
78 // Return true if and only if a user gesture is required to unlock this
79 // media element for unrestricted autoplay/script control. Don't confuse
80 // this with isGestureNeededForPlayback(). The latter is usually what one
81 // should use, if checking to see if an action is allowed.
82 bool IsLockedPendingUserGesture() const;
83
84 bool IsLockedPendingUserGestureIfCrossOriginExperimentEnabled() const;
85
86 bool IsGestureNeededForPlaybackIfCrossOriginExperimentEnabled() const;
87
88 bool IsGestureNeededForPlaybackIfPendingUserGestureIsLocked() const;
89
90 // Return true if and only if the settings allow autoplay of media on this
91 // frame.
92 bool IsAutoplayAllowedPerSettings() const;
93
94 bool IsAutoplayingMutedInternal(bool muted) const;
95
96 // Called when the video visibility changes while autoplaying muted, will
97 // pause the video when invisible and resume the video when visible.
98 void OnVisibilityChangedForAutoplay(bool is_visible);
99
100 bool locked_pending_user_gesture_ : 1;
101 bool locked_pending_user_gesture_if_cross_origin_experiment_enabled_ : 1;
102
103 Member<HTMLMediaElement> element_;
104 Member<ElementVisibilityObserver> autoplay_visibility_observer_;
105
106 Member<AutoplayUmaHelper> autoplay_uma_helper_;
107
108 DISALLOW_COPY_AND_ASSIGN(AutoplayPolicy);
109 };
110
111 } // namespace blink
112
113 #endif // AutoplayPolicy_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLMediaElement.cpp ('k') | third_party/WebKit/Source/core/html/media/AutoplayPolicy.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698