Index: third_party/WebKit/Source/core/html/media/AutoplayPolicy.h |
diff --git a/third_party/WebKit/Source/core/html/media/AutoplayPolicy.h b/third_party/WebKit/Source/core/html/media/AutoplayPolicy.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f5fa274266486617f35b4587ede222381e8ff599 |
--- /dev/null |
+++ b/third_party/WebKit/Source/core/html/media/AutoplayPolicy.h |
@@ -0,0 +1,90 @@ |
+// Copyright 2017 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 AutoplayPolicy_h |
+#define AutoplayPolicy_h |
+ |
+#include "bindings/core/v8/Nullable.h" |
+#include "core/dom/ExceptionCode.h" |
+#include "platform/heap/Handle.h" |
+ |
+namespace blink { |
+ |
+class Document; |
+class ElementVisibilityObserver; |
+class HTMLMediaElement; |
+ |
+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.
|
+ public: |
+ AutoplayPolicy(HTMLMediaElement*); |
+ ~AutoplayPolicy(); |
+ |
+ // Called when the media element is moved to a new document. |
+ void DidMoveToNewDocument(Document& old_document); |
+ |
+ // Returns whether the media element is eligible to autoplay muted. |
+ bool IsEligibleForAutoplayMuted() const; |
+ |
+ // Start/stop autoplaying the video element whenever its visible. |
+ void StartAutoplayMutedWhenVisible(); |
+ void StopAutoplayMutedWhenVisible(); |
+ |
+ // Checks if autoplay is allowed from play method. This will utilize user |
+ // 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.
|
+ Nullable<ExceptionCode> CheckPlayMethodAllowed(); |
+ |
+ // Returns whether an umute action should pause an autoplaying element. |
+ bool CheckUnmuteShouldPauseAutoplay(); |
+ |
+ bool IsAutoplayingMuted(); |
+ |
+ // Return true if and only if a user gesture is required to unlock this |
+ // media element for unrestricted autoplay/script control. Don't confuse |
+ // this with isGestureNeededForPlayback(). The latter is usually what one |
+ // should use, if checking to see if an action is allowed. |
+ bool IsLockedPendingUserGesture() const; |
+ |
+ bool IsLockedPendingUserGestureIfCrossOriginExperimentEnabled() const; |
+ |
+ // Unlock user gesture if a user gesture can be utilized. |
+ void TryUnlockingUserGesture(); |
+ |
+ // If the user gesture is required, then this will remove it. Note that |
+ // one should not generally call this method directly; use the one on |
+ // m_helper and give it a reason. |
+ void UnlockUserGesture(); |
+ |
+ // Return true if and only if a user gesture is requried for playback. Even |
+ // if isLockedPendingUserGesture() return true, this might return false if |
+ // the requirement is currently overridden. This does not check if a user |
+ // gesture is currently being processed. |
+ bool IsGestureNeededForPlayback() const; |
+ |
+ bool IsGestureNeededForPlaybackIfCrossOriginExperimentEnabled() const; |
+ |
+ bool IsGestureNeededForPlaybackIfPendingUserGestureIsLocked() const; |
+ |
+ // Return true if and only if the settings allow autoplay of media on this |
+ // frame. |
+ bool IsAutoplayAllowedPerSettings() const; |
+ |
+ // Called when the video visibility changes while autoplaying muted, will |
+ // pause the video when invisible and resume the video when visible. |
+ void OnVisibilityChangedForAutoplay(bool is_visible); |
+ |
+ private: |
+ 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.
|
+ |
+ bool locked_pending_user_gesture_; |
+ bool locked_pending_user_gesture_if_cross_origin_experiment_enabled_; |
+ |
+ Member<HTMLMediaElement> element_; |
+ Member<ElementVisibilityObserver> autoplay_visibility_observer_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(AutoplayPolicy); |
+}; |
+ |
+} // namespace blink |
+ |
+#endif // AutoplayPolicy_h |