Chromium Code Reviews| Index: third_party/WebKit/Source/core/html/AutoplayExperimentHelper.cpp |
| diff --git a/third_party/WebKit/Source/core/html/AutoplayExperimentHelper.cpp b/third_party/WebKit/Source/core/html/AutoplayExperimentHelper.cpp |
| index 46e4df6327b5081d86421ee2b5b016e5e24639b7..895ffd1127df1eb21d28c09a03e3868783f702d0 100644 |
| --- a/third_party/WebKit/Source/core/html/AutoplayExperimentHelper.cpp |
| +++ b/third_party/WebKit/Source/core/html/AutoplayExperimentHelper.cpp |
| @@ -295,6 +295,25 @@ bool AutoplayExperimentHelper::maybeStartPlaying() |
| return true; |
| } |
| +bool AutoplayExperimentHelper::isSameOrigin() const |
| +{ |
| + bool sameOrigin = true; |
| + LocalFrame* frame = client().frame(); |
| + if (!frame) |
| + return true; |
| + |
| + const SecurityOrigin* origin = frame->securityContext()->getSecurityOrigin(); |
|
ojan
2016/04/26 01:13:57
Can you move this into a helper function on Frame.
liberato (no reviews please)
2016/04/26 18:30:24
moved into a helper function. however, i used mou
|
| + for (Frame* parentFrame = frame->tree().parent(); parentFrame; parentFrame = parentFrame->tree().parent()) { |
| + const SecurityOrigin* parentOrigin = parentFrame->securityContext()->getSecurityOrigin(); |
| + if (!origin->canAccess(parentOrigin)) { |
| + sameOrigin = false; |
| + break; |
| + } |
| + } |
|
mlamouri (slow - plz ping)
2016/04/26 14:41:40
I think you only want to check top() here. This is
liberato (no reviews please)
2016/04/26 18:30:24
done, and updated UseCounter::count...frame().
|
| + |
| + return sameOrigin; |
| +} |
| + |
| bool AutoplayExperimentHelper::isEligible() const |
| { |
| if (m_mode == Mode::ExperimentOff) |
| @@ -326,6 +345,16 @@ bool AutoplayExperimentHelper::isEligible() const |
| && !client().isLegacyViewportType()) |
| return false; |
| + // If we require same-origin, then check the origin. If we additionally |
| + // require "or muted", then also allow autoplay in that case. |
| + if (enabled(IfSameOrigin)) { |
| + if (!isSameOrigin()) { |
| + if (!enabled(OrMuted) || !client().muted()) { |
| + return false; |
|
mlamouri (slow - plz ping)
2016/04/26 14:41:40
Quite a bit of nesting, maybe you can merge `enabl
liberato (no reviews please)
2016/04/26 18:30:24
Done.
|
| + } |
| + } |
| + } |
| + |
| // If we require muted media and this is muted, then it is eligible. |
| if (enabled(IfMuted)) |
| return client().muted(); |
| @@ -391,6 +420,10 @@ AutoplayExperimentHelper::Mode AutoplayExperimentHelper::fromString(const String |
| value |= IfMuted; |
| if (mode.contains("-ifmobile")) |
| value |= IfMobile; |
| + if (mode.contains("-ifsameorigin")) |
| + value |= IfSameOrigin; |
| + if (mode.contains("-ormuted")) |
| + value |= OrMuted; |
| if (mode.contains("-playmuted")) |
| value |= PlayMuted; |