Chromium Code Reviews| 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 Document; | |
| 15 class ElementVisibilityObserver; | |
| 16 class HTMLMediaElement; | |
| 17 | |
| 18 class AutoplayPolicy final : public GarbageCollectedFinalized<AutoplayPolicy> { | |
|
mlamouri (slow - plz ping)
2017/04/18 13:28:29
Why do you need this to be GCFinalized? Sounds lik
Zhiqiang Zhang (Slow)
2017/04/18 16:56:45
Done.
| |
| 19 public: | |
| 20 AutoplayPolicy(HTMLMediaElement*); | |
| 21 ~AutoplayPolicy(); | |
| 22 | |
| 23 // Called when the media element is moved to a new document. | |
| 24 void DidMoveToNewDocument(Document& old_document); | |
| 25 | |
| 26 // Returns whether the media element is eligible to autoplay muted. | |
| 27 bool IsEligibleForAutoplayMuted() const; | |
| 28 | |
| 29 // Start/stop autoplaying the video element whenever its visible. | |
| 30 void StartAutoplayMutedWhenVisible(); | |
| 31 void StopAutoplayMutedWhenVisible(); | |
| 32 | |
| 33 // Checks if autoplay is allowed from play method. This will utilize user | |
| 34 // gesture and record UMAs, so can only be called per call of play(). | |
|
mlamouri (slow - plz ping)
2017/04/18 13:28:28
"called _once_ per call" ?
Zhiqiang Zhang (Slow)
2017/04/18 16:56:45
Done.
| |
| 35 Nullable<ExceptionCode> CheckPlayMethodAllowed(); | |
| 36 | |
| 37 // Returns whether an umute action should pause an autoplaying element. | |
| 38 bool CheckUnmuteShouldPauseAutoplay(); | |
| 39 | |
| 40 bool IsAutoplayingMuted(); | |
| 41 | |
| 42 // Return true if and only if a user gesture is required to unlock this | |
| 43 // media element for unrestricted autoplay/script control. Don't confuse | |
| 44 // this with isGestureNeededForPlayback(). The latter is usually what one | |
| 45 // should use, if checking to see if an action is allowed. | |
| 46 bool IsLockedPendingUserGesture() const; | |
| 47 | |
| 48 bool IsLockedPendingUserGestureIfCrossOriginExperimentEnabled() const; | |
| 49 | |
| 50 // Unlock user gesture if a user gesture can be utilized. | |
| 51 void TryUnlockingUserGesture(); | |
| 52 | |
| 53 // If the user gesture is required, then this will remove it. Note that | |
| 54 // one should not generally call this method directly; use the one on | |
| 55 // m_helper and give it a reason. | |
| 56 void UnlockUserGesture(); | |
| 57 | |
| 58 // Return true if and only if a user gesture is requried for playback. Even | |
| 59 // if isLockedPendingUserGesture() return true, this might return false if | |
| 60 // the requirement is currently overridden. This does not check if a user | |
| 61 // gesture is currently being processed. | |
| 62 bool IsGestureNeededForPlayback() const; | |
| 63 | |
| 64 bool IsGestureNeededForPlaybackIfCrossOriginExperimentEnabled() const; | |
| 65 | |
| 66 bool IsGestureNeededForPlaybackIfPendingUserGestureIsLocked() const; | |
| 67 | |
| 68 // Return true if and only if the settings allow autoplay of media on this | |
| 69 // frame. | |
| 70 bool IsAutoplayAllowedPerSettings() const; | |
| 71 | |
| 72 // Called when the video visibility changes while autoplaying muted, will | |
| 73 // pause the video when invisible and resume the video when visible. | |
| 74 void OnVisibilityChangedForAutoplay(bool is_visible); | |
| 75 | |
| 76 private: | |
| 77 DECLARE_VIRTUAL_TRACE(); | |
|
mlamouri (slow - plz ping)
2017/04/18 13:28:28
This is usually public, move this just above `priv
Zhiqiang Zhang (Slow)
2017/04/18 16:56:45
Done.
| |
| 78 | |
| 79 bool locked_pending_user_gesture_; | |
| 80 bool locked_pending_user_gesture_if_cross_origin_experiment_enabled_; | |
| 81 | |
| 82 Member<HTMLMediaElement> element_; | |
| 83 Member<ElementVisibilityObserver> autoplay_visibility_observer_; | |
| 84 | |
| 85 DISALLOW_COPY_AND_ASSIGN(AutoplayPolicy); | |
| 86 }; | |
| 87 | |
| 88 } // namespace blink | |
| 89 | |
| 90 #endif // AutoplayPolicy_h | |
| OLD | NEW |