Chromium Code Reviews| Index: third_party/WebKit/Source/core/html/media/AutoplayPolicy.cpp |
| diff --git a/third_party/WebKit/Source/core/html/media/AutoplayPolicy.cpp b/third_party/WebKit/Source/core/html/media/AutoplayPolicy.cpp |
| index 68dff512c7606574427e3ad58f376d98088a7b5c..8a4ff64c79bde6c3ce7f417f37b1b1f0be153a0c 100644 |
| --- a/third_party/WebKit/Source/core/html/media/AutoplayPolicy.cpp |
| +++ b/third_party/WebKit/Source/core/html/media/AutoplayPolicy.cpp |
| @@ -19,7 +19,7 @@ namespace blink { |
| namespace { |
| -bool IsDocumentCrossOrigin(Document& document) { |
| +bool IsDocumentCrossOrigin(const Document& document) { |
| const LocalFrame* frame = document.GetFrame(); |
| return frame && frame->IsCrossOriginSubframe(); |
| } |
| @@ -27,7 +27,7 @@ bool IsDocumentCrossOrigin(Document& document) { |
| // Returns whether |document| is whitelisted for autoplay. If true, the user |
| // gesture lock will be initilized as false, indicating that the element is |
| // allowed to autoplay unmuted without user gesture. |
| -bool IsDocumentWhitelisted(Document& document) { |
| +bool IsDocumentWhitelisted(const Document& document) { |
| DCHECK(document.GetSettings()); |
| const String& whitelist_scope = |
| @@ -40,25 +40,34 @@ bool IsDocumentWhitelisted(Document& document) { |
| // Return true if and only if the document settings specifies media playback |
| // requires user gesture. |
| -bool ComputeLockedPendingUserGesture(Document& document) { |
| - if (!document.GetSettings()) |
| - return false; |
| - |
| - if (IsDocumentWhitelisted(document)) { |
| - return false; |
| - } |
| - |
| - if (document.GetSettings() |
| - ->GetCrossOriginMediaPlaybackRequiresUserGesture() && |
| - IsDocumentCrossOrigin(document)) { |
| - return true; |
| +bool ComputeLockedPendingUserGesture(const Document& document) { |
| + switch (AutoplayPolicy::GetAutoplayPolicyForDocument(document)) { |
| + case AutoplayPolicy::Type::kNoUserGestureRequired: |
| + return false; |
| + case AutoplayPolicy::Type::kCrossOriginUserGestureRequired: |
| + return IsDocumentCrossOrigin(document); |
| + case AutoplayPolicy::Type::kUserGestureRequired: |
| + return true; |
| } |
| - return document.GetSettings()->GetMediaPlaybackRequiresUserGesture(); |
| + NOTREACHED(); |
| + return true; |
| } |
| } // anonymous namespace |
| +// static |
| +AutoplayPolicy::Type AutoplayPolicy::GetAutoplayPolicyForDocument( |
| + const Document& document) { |
| + if (document.GetSettings()) |
|
dcheng
2017/04/27 15:57:17
Should this be !document.GetSettings()?
|
| + return Type::kNoUserGestureRequired; |
| + |
| + if (IsDocumentWhitelisted(document)) |
| + return Type::kNoUserGestureRequired; |
| + |
| + return document.GetSettings()->GetAutoplayPolicy(); |
| +} |
| + |
| AutoplayPolicy::AutoplayPolicy(HTMLMediaElement* element) |
| : locked_pending_user_gesture_(false), |
| locked_pending_user_gesture_if_cross_origin_experiment_enabled_(true), |