OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/html/AutoplayExperimentHelper.h" | 5 #include "core/html/AutoplayExperimentHelper.h" |
6 | 6 |
7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
8 #include "core/frame/Settings.h" | 8 #include "core/frame/Settings.h" |
9 #include "core/html/HTMLMediaElement.h" | 9 #include "core/html/HTMLMediaElement.h" |
10 #include "core/layout/LayoutBox.h" | 10 #include "core/layout/LayoutBox.h" |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 // and becameReadyToPlay will handle it, but toggling muted state can, | 288 // and becameReadyToPlay will handle it, but toggling muted state can, |
289 // in some cases, also trigger autoplay if the autoplay attribute is set | 289 // in some cases, also trigger autoplay if the autoplay attribute is set |
290 // after the media is ready to play. | 290 // after the media is ready to play. |
291 autoplayMediaEncountered(); | 291 autoplayMediaEncountered(); |
292 | 292 |
293 client().playInternal(); | 293 client().playInternal(); |
294 | 294 |
295 return true; | 295 return true; |
296 } | 296 } |
297 | 297 |
298 bool AutoplayExperimentHelper::isSameOrigin() const | |
299 { | |
300 bool sameOrigin = true; | |
301 LocalFrame* frame = client().frame(); | |
302 if (!frame) | |
303 return true; | |
304 | |
305 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
| |
306 for (Frame* parentFrame = frame->tree().parent(); parentFrame; parentFrame = parentFrame->tree().parent()) { | |
307 const SecurityOrigin* parentOrigin = parentFrame->securityContext()->get SecurityOrigin(); | |
308 if (!origin->canAccess(parentOrigin)) { | |
309 sameOrigin = false; | |
310 break; | |
311 } | |
312 } | |
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().
| |
313 | |
314 return sameOrigin; | |
315 } | |
316 | |
298 bool AutoplayExperimentHelper::isEligible() const | 317 bool AutoplayExperimentHelper::isEligible() const |
299 { | 318 { |
300 if (m_mode == Mode::ExperimentOff) | 319 if (m_mode == Mode::ExperimentOff) |
301 return false; | 320 return false; |
302 | 321 |
303 // If no user gesture is required, then the experiment doesn't apply. | 322 // If no user gesture is required, then the experiment doesn't apply. |
304 // This is what prevents us from starting playback more than once. | 323 // This is what prevents us from starting playback more than once. |
305 // Since this flag is never set to true once it's cleared, it will block | 324 // Since this flag is never set to true once it's cleared, it will block |
306 // the autoplay experiment forever. | 325 // the autoplay experiment forever. |
307 if (!isUserGestureRequiredForPlay()) | 326 if (!isUserGestureRequiredForPlay()) |
(...skipping 11 matching lines...) Expand all Loading... | |
319 | 338 |
320 if (!m_playPending && !client().shouldAutoplay()) | 339 if (!m_playPending && !client().shouldAutoplay()) |
321 return false; | 340 return false; |
322 | 341 |
323 // Note that the viewport test always returns false on desktop, which is | 342 // Note that the viewport test always returns false on desktop, which is |
324 // why video-autoplay-experiment.html doesn't check -ifmobile . | 343 // why video-autoplay-experiment.html doesn't check -ifmobile . |
325 if (enabled(IfMobile) | 344 if (enabled(IfMobile) |
326 && !client().isLegacyViewportType()) | 345 && !client().isLegacyViewportType()) |
327 return false; | 346 return false; |
328 | 347 |
348 // If we require same-origin, then check the origin. If we additionally | |
349 // require "or muted", then also allow autoplay in that case. | |
350 if (enabled(IfSameOrigin)) { | |
351 if (!isSameOrigin()) { | |
352 if (!enabled(OrMuted) || !client().muted()) { | |
353 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.
| |
354 } | |
355 } | |
356 } | |
357 | |
329 // If we require muted media and this is muted, then it is eligible. | 358 // If we require muted media and this is muted, then it is eligible. |
330 if (enabled(IfMuted)) | 359 if (enabled(IfMuted)) |
331 return client().muted(); | 360 return client().muted(); |
332 | 361 |
333 // Element is eligible for gesture override, maybe muted. | 362 // Element is eligible for gesture override, maybe muted. |
334 return true; | 363 return true; |
335 } | 364 } |
336 | 365 |
337 void AutoplayExperimentHelper::muteIfNeeded() | 366 void AutoplayExperimentHelper::muteIfNeeded() |
338 { | 367 { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
384 if (mode.contains("-foraudio")) | 413 if (mode.contains("-foraudio")) |
385 value |= ForAudio; | 414 value |= ForAudio; |
386 if (mode.contains("-ifpagevisible")) | 415 if (mode.contains("-ifpagevisible")) |
387 value |= IfPageVisible; | 416 value |= IfPageVisible; |
388 if (mode.contains("-ifviewport")) | 417 if (mode.contains("-ifviewport")) |
389 value |= IfViewport; | 418 value |= IfViewport; |
390 if (mode.contains("-ifmuted")) | 419 if (mode.contains("-ifmuted")) |
391 value |= IfMuted; | 420 value |= IfMuted; |
392 if (mode.contains("-ifmobile")) | 421 if (mode.contains("-ifmobile")) |
393 value |= IfMobile; | 422 value |= IfMobile; |
423 if (mode.contains("-ifsameorigin")) | |
424 value |= IfSameOrigin; | |
425 if (mode.contains("-ormuted")) | |
426 value |= OrMuted; | |
394 if (mode.contains("-playmuted")) | 427 if (mode.contains("-playmuted")) |
395 value |= PlayMuted; | 428 value |= PlayMuted; |
396 | 429 |
397 return value; | 430 return value; |
398 } | 431 } |
399 | 432 |
400 void AutoplayExperimentHelper::autoplayMediaEncountered() | 433 void AutoplayExperimentHelper::autoplayMediaEncountered() |
401 { | 434 { |
402 if (!m_autoplayMediaEncountered) { | 435 if (!m_autoplayMediaEncountered) { |
403 m_autoplayMediaEncountered = true; | 436 m_autoplayMediaEncountered = true; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
481 ? AnyVideoElement | 514 ? AnyVideoElement |
482 : AnyAudioElement); | 515 : AnyAudioElement); |
483 } | 516 } |
484 | 517 |
485 bool AutoplayExperimentHelper::isExperimentEnabled() | 518 bool AutoplayExperimentHelper::isExperimentEnabled() |
486 { | 519 { |
487 return m_mode != Mode::ExperimentOff; | 520 return m_mode != Mode::ExperimentOff; |
488 } | 521 } |
489 | 522 |
490 } // namespace blink | 523 } // namespace blink |
OLD | NEW |