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

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 class AutoplayPolicy final : public GarbageCollected<AutoplayPolicy> {
20 public:
21 AutoplayPolicy(HTMLMediaElement*);
mlamouri (slow - plz ping) 2017/04/19 14:09:55 explicit?
Zhiqiang Zhang (Slow) 2017/04/20 10:30:45 Done.
22
23 AutoplayUmaHelper& GetAutoplayUmaHelper() { return *autoplay_uma_helper_; }
mlamouri (slow - plz ping) 2017/04/19 14:09:55 Doesn't seem to be called at all
Zhiqiang Zhang (Slow) 2017/04/20 10:30:45 Done.
24
25 void VideoWillBeDrawnToCanvas() const;
26
27 // Called when the media element is moved to a new document.
28 void DidMoveToNewDocument(Document& old_document);
29
30 // Returns whether the media element is eligible to autoplay muted.
31 bool IsEligibleForAutoplayMuted() const;
mlamouri (slow - plz ping) 2017/04/19 14:09:56 It doesn't seem to be called outside of `AutoplayP
Zhiqiang Zhang (Slow) 2017/04/20 10:30:45 Moved to private.
32
33 // Start/stop autoplaying the video element whenever its visible.
34 void StartAutoplayMutedWhenVisible();
35 void StopAutoplayMutedWhenVisible();
mlamouri (slow - plz ping) 2017/04/19 14:09:55 StartAutoplayMutedWhenVisible() isn't called outsi
Zhiqiang Zhang (Slow) 2017/04/20 10:30:45 Ah, yes. Added comments above, and moved Start...(
36
37 // Request autoplay by attribute. This method will check the autoplay
38 // restrictions and record metrics. This method can only be called once per
39 // time the readyState changes to HAVE_ENOUGH_DATA.
40 bool RequestAutoplayByAttribute();
41
42 // Request the playback via play() method. This method will check the autoplay
43 // restrictions and record metrics. This method can only be called once
44 // per call of play().
45 Nullable<ExceptionCode> RequestPlay();
46
47 // Returns whether an umute action should pause an autoplaying element. The
48 // method will check autoplay restrictions and record metrics. This method can
49 // only be called once per call of setMuted().
50 bool RequestAutoplayUnmute();
51
52 bool IsAutoplayingMuted();
mlamouri (slow - plz ping) 2017/04/19 14:09:56 Could this be `const`?
Zhiqiang Zhang (Slow) 2017/04/20 10:30:45 Done.
53
54 // Return true if and only if a user gesture is required to unlock this
55 // media element for unrestricted autoplay/script control. Don't confuse
56 // this with isGestureNeededForPlayback(). The latter is usually what one
57 // should use, if checking to see if an action is allowed.
58 bool IsLockedPendingUserGesture() const;
mlamouri (slow - plz ping) 2017/04/19 14:09:56 I can't see this being called outside of this clas
Zhiqiang Zhang (Slow) 2017/04/20 10:30:46 Moved to private
59
60 bool IsLockedPendingUserGestureIfCrossOriginExperimentEnabled() const;
mlamouri (slow - plz ping) 2017/04/19 14:09:55 ditto
Zhiqiang Zhang (Slow) 2017/04/20 10:30:45 Moved to private
61
62 // Unlock user gesture if a user gesture can be utilized.
63 void TryUnlockingUserGesture();
64
65 // If the user gesture is required, then this will remove it. Note that
66 // one should not generally call this method directly; use the one on
67 // m_helper and give it a reason.
68 void UnlockUserGesture();
69
70 // Return true if and only if a user gesture is requried for playback. Even
71 // if isLockedPendingUserGesture() return true, this might return false if
72 // the requirement is currently overridden. This does not check if a user
73 // gesture is currently being processed.
74 bool IsGestureNeededForPlayback() const;
75
76 bool IsGestureNeededForPlaybackIfCrossOriginExperimentEnabled() const;
mlamouri (slow - plz ping) 2017/04/19 14:09:55 This doesn't seem to be called by anything outside
Zhiqiang Zhang (Slow) 2017/04/20 10:30:45 Moved to private
77
78 bool IsGestureNeededForPlaybackIfPendingUserGestureIsLocked() const;
mlamouri (slow - plz ping) 2017/04/19 14:09:56 Same here
Zhiqiang Zhang (Slow) 2017/04/20 10:30:45 Moved to private
79
80 // Return true if and only if the settings allow autoplay of media on this
81 // frame.
82 bool IsAutoplayAllowedPerSettings() const;
mlamouri (slow - plz ping) 2017/04/19 14:09:55 and here
Zhiqiang Zhang (Slow) 2017/04/20 10:30:45 This one is used by AutoplayUmaHelper :)
83
84 // Called when the video visibility changes while autoplaying muted, will
85 // pause the video when invisible and resume the video when visible.
86 void OnVisibilityChangedForAutoplay(bool is_visible);
mlamouri (slow - plz ping) 2017/04/19 14:09:56 and here :)
Zhiqiang Zhang (Slow) 2017/04/20 10:30:45 Moved to private
87
88 DECLARE_VIRTUAL_TRACE();
89
90 private:
91 friend class AutoplayUmaHelperTest;
92
93 bool ShouldAutoplay();
94
95 bool locked_pending_user_gesture_;
96 bool locked_pending_user_gesture_if_cross_origin_experiment_enabled_;
mlamouri (slow - plz ping) 2017/04/19 14:09:56 Maybe these bool should be initialised here?
Zhiqiang Zhang (Slow) 2017/04/20 10:30:45 Done. Not sure if it matters as we initialize then
97
98 Member<HTMLMediaElement> element_;
99 Member<ElementVisibilityObserver> autoplay_visibility_observer_;
100
101 Member<AutoplayUmaHelper> autoplay_uma_helper_;
102
103 DISALLOW_COPY_AND_ASSIGN(AutoplayPolicy);
104 };
105
106 } // namespace blink
107
108 #endif // AutoplayPolicy_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698