| 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 } | 123 } |
| 124 | 124 |
| 125 void AutoplayExperimentHelper::loadMethodCalled() | 125 void AutoplayExperimentHelper::loadMethodCalled() |
| 126 { | 126 { |
| 127 if (isLockedPendingUserGesture() && UserGestureIndicator::utilizeUserGesture
()) { | 127 if (isLockedPendingUserGesture() && UserGestureIndicator::utilizeUserGesture
()) { |
| 128 recordAutoplayMetric(AutoplayEnabledThroughLoad); | 128 recordAutoplayMetric(AutoplayEnabledThroughLoad); |
| 129 unlockUserGesture(GesturelessPlaybackEnabledByLoad); | 129 unlockUserGesture(GesturelessPlaybackEnabledByLoad); |
| 130 } | 130 } |
| 131 } | 131 } |
| 132 | 132 |
| 133 void AutoplayExperimentHelper::mutedChanged() |
| 134 { |
| 135 // Mute changes are always allowed if this is unlocked. |
| 136 if (!client().isLockedPendingUserGesture()) |
| 137 return; |
| 138 |
| 139 // Changes with a user gesture are okay. |
| 140 if (UserGestureIndicator::utilizeUserGesture()) |
| 141 return; |
| 142 |
| 143 // If the mute state has changed to 'muted', then it's okay. |
| 144 if (client().muted()) |
| 145 return; |
| 146 |
| 147 // If nothing is playing, then changes are okay too. |
| 148 if (client().paused()) |
| 149 return; |
| 150 |
| 151 // Trying to unmute without a user gesture. |
| 152 |
| 153 // If we don't care about muted state, then it's okay. |
| 154 if (!enabled(IfMuted) && !(client().isCrossOrigin() && enabled(OrMuted))) |
| 155 return; |
| 156 |
| 157 // Unmuting isn't allowed, so pause. |
| 158 client().pauseInternal(); |
| 159 } |
| 160 |
| 133 void AutoplayExperimentHelper::registerForPositionUpdatesIfNeeded() | 161 void AutoplayExperimentHelper::registerForPositionUpdatesIfNeeded() |
| 134 { | 162 { |
| 135 // If we don't require that the player is in the viewport, then we don't | 163 // If we don't require that the player is in the viewport, then we don't |
| 136 // need the listener. | 164 // need the listener. |
| 137 if (!requiresViewportVisibility()) { | 165 if (!requiresViewportVisibility()) { |
| 138 if (!enabled(IfPageVisible)) | 166 if (!enabled(IfPageVisible)) |
| 139 return; | 167 return; |
| 140 } | 168 } |
| 141 | 169 |
| 142 m_client->setRequestPositionUpdates(true); | 170 m_client->setRequestPositionUpdates(true); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 if (mode != IgnorePendingPlayback && !m_playPending && !client().shouldAuto
play()) | 348 if (mode != IgnorePendingPlayback && !m_playPending && !client().shouldAuto
play()) |
| 321 return false; | 349 return false; |
| 322 | 350 |
| 323 // Note that the viewport test always returns false on desktop, which is | 351 // Note that the viewport test always returns false on desktop, which is |
| 324 // why video-autoplay-experiment.html doesn't check -ifmobile . | 352 // why video-autoplay-experiment.html doesn't check -ifmobile . |
| 325 if (enabled(IfMobile) | 353 if (enabled(IfMobile) |
| 326 && !client().isLegacyViewportType()) | 354 && !client().isLegacyViewportType()) |
| 327 return false; | 355 return false; |
| 328 | 356 |
| 329 // If we require same-origin, then check the origin. | 357 // If we require same-origin, then check the origin. |
| 330 if (enabled(IfSameOrigin) && client().isCrossOrigin()) | 358 if (enabled(IfSameOrigin) && client().isCrossOrigin()) { |
| 331 return false; | 359 // We're cross-origin, so block unless it's muted content and OrMuted |
| 360 // is enabled. For good measure, we also block all audio elements. |
| 361 if (client().isHTMLAudioElement() || !client().muted() |
| 362 || !enabled(OrMuted)) { |
| 363 return false; |
| 364 } |
| 365 } |
| 332 | 366 |
| 333 // If we require muted media and this is muted, then it is eligible. | 367 // If we require muted media and this is muted, then it is eligible. |
| 334 if (enabled(IfMuted)) | 368 if (enabled(IfMuted)) |
| 335 return client().muted(); | 369 return client().muted(); |
| 336 | 370 |
| 337 // Element is eligible for gesture override, maybe muted. | 371 // Element is eligible for gesture override, maybe muted. |
| 338 return true; | 372 return true; |
| 339 } | 373 } |
| 340 | 374 |
| 341 void AutoplayExperimentHelper::muteIfNeeded() | 375 void AutoplayExperimentHelper::muteIfNeeded() |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 if (mode.contains("-ifviewport")) | 434 if (mode.contains("-ifviewport")) |
| 401 value |= IfViewport; | 435 value |= IfViewport; |
| 402 if (mode.contains("-ifpartialviewport")) | 436 if (mode.contains("-ifpartialviewport")) |
| 403 value |= IfPartialViewport; | 437 value |= IfPartialViewport; |
| 404 if (mode.contains("-ifmuted")) | 438 if (mode.contains("-ifmuted")) |
| 405 value |= IfMuted; | 439 value |= IfMuted; |
| 406 if (mode.contains("-ifmobile")) | 440 if (mode.contains("-ifmobile")) |
| 407 value |= IfMobile; | 441 value |= IfMobile; |
| 408 if (mode.contains("-ifsameorigin")) | 442 if (mode.contains("-ifsameorigin")) |
| 409 value |= IfSameOrigin; | 443 value |= IfSameOrigin; |
| 444 if (mode.contains("-ormuted")) |
| 445 value |= OrMuted; |
| 410 if (mode.contains("-playmuted")) | 446 if (mode.contains("-playmuted")) |
| 411 value |= PlayMuted; | 447 value |= PlayMuted; |
| 412 | 448 |
| 413 return value; | 449 return value; |
| 414 } | 450 } |
| 415 | 451 |
| 416 void AutoplayExperimentHelper::autoplayMediaEncountered() | 452 void AutoplayExperimentHelper::autoplayMediaEncountered() |
| 417 { | 453 { |
| 418 if (!m_autoplayMediaEncountered) { | 454 if (!m_autoplayMediaEncountered) { |
| 419 m_autoplayMediaEncountered = true; | 455 m_autoplayMediaEncountered = true; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 { | 549 { |
| 514 return client().isHTMLVideoElement() && (enabled(IfViewport) || enabled(IfPa
rtialViewport)); | 550 return client().isHTMLVideoElement() && (enabled(IfViewport) || enabled(IfPa
rtialViewport)); |
| 515 } | 551 } |
| 516 | 552 |
| 517 bool AutoplayExperimentHelper::isExperimentEnabled() | 553 bool AutoplayExperimentHelper::isExperimentEnabled() |
| 518 { | 554 { |
| 519 return m_mode != Mode::ExperimentOff; | 555 return m_mode != Mode::ExperimentOff; |
| 520 } | 556 } |
| 521 | 557 |
| 522 } // namespace blink | 558 } // namespace blink |
| OLD | NEW |