Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 virtual ~AutoplayHelperClientImpl(); | 295 virtual ~AutoplayHelperClientImpl(); |
| 296 | 296 |
| 297 using RecordMetricsBehavior = HTMLMediaElement::RecordMetricsBehavior; | 297 using RecordMetricsBehavior = HTMLMediaElement::RecordMetricsBehavior; |
| 298 | 298 |
| 299 double currentTime() const override { return m_element->currentTime(); } | 299 double currentTime() const override { return m_element->currentTime(); } |
| 300 double duration() const override { return m_element->duration(); } | 300 double duration() const override { return m_element->duration(); } |
| 301 bool ended() const override { return m_element->ended(); } | 301 bool ended() const override { return m_element->ended(); } |
| 302 bool muted() const override { return m_element->muted(); } | 302 bool muted() const override { return m_element->muted(); } |
| 303 void setMuted(bool muted) override { m_element->setMuted(muted); } | 303 void setMuted(bool muted) override { m_element->setMuted(muted); } |
| 304 void playInternal() override { m_element->playInternal(); } | 304 void playInternal() override { m_element->playInternal(); } |
| 305 bool isUserGestureRequiredForPlay() const override { return m_element->isUse rGestureRequiredForPlay(); } | 305 bool isLockedPendingUserGesture() const override { return m_element->isLocke dPendingUserGesture(); } |
| 306 void removeUserGestureRequirement() override { m_element->removeUserGestureR equirement(); } | 306 void removeUserGestureRequirement() override { m_element->removeUserGestureR equirement(); } |
| 307 void recordAutoplayMetric(AutoplayMetrics metric) override { m_element->reco rdAutoplayMetric(metric); } | 307 void recordAutoplayMetric(AutoplayMetrics metric) override { m_element->reco rdAutoplayMetric(metric); } |
| 308 bool shouldAutoplay() override | 308 bool shouldAutoplay() override |
| 309 { | 309 { |
| 310 return m_element->shouldAutoplay(RecordMetricsBehavior::DoNotRecord); | 310 return m_element->shouldAutoplay(RecordMetricsBehavior::DoNotRecord); |
| 311 } | 311 } |
| 312 bool isHTMLVideoElement() const override { return m_element->isHTMLVideoElem ent(); } | 312 bool isHTMLVideoElement() const override { return m_element->isHTMLVideoElem ent(); } |
| 313 bool isHTMLAudioElement() const override { return m_element->isHTMLAudioElem ent(); } | 313 bool isHTMLAudioElement() const override { return m_element->isHTMLAudioElem ent(); } |
| 314 | 314 |
| 315 // Document | 315 // Document |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 405 , m_lastTimeUpdateEventMovieTime(0) | 405 , m_lastTimeUpdateEventMovieTime(0) |
| 406 , m_defaultPlaybackStartPosition(0) | 406 , m_defaultPlaybackStartPosition(0) |
| 407 , m_loadState(WaitingForSource) | 407 , m_loadState(WaitingForSource) |
| 408 , m_deferredLoadState(NotDeferred) | 408 , m_deferredLoadState(NotDeferred) |
| 409 , m_deferredLoadTimer(this, &HTMLMediaElement::deferredLoadTimerFired) | 409 , m_deferredLoadTimer(this, &HTMLMediaElement::deferredLoadTimerFired) |
| 410 , m_webLayer(nullptr) | 410 , m_webLayer(nullptr) |
| 411 , m_displayMode(Unknown) | 411 , m_displayMode(Unknown) |
| 412 , m_cachedTime(std::numeric_limits<double>::quiet_NaN()) | 412 , m_cachedTime(std::numeric_limits<double>::quiet_NaN()) |
| 413 , m_fragmentEndTime(std::numeric_limits<double>::quiet_NaN()) | 413 , m_fragmentEndTime(std::numeric_limits<double>::quiet_NaN()) |
| 414 , m_pendingActionFlags(0) | 414 , m_pendingActionFlags(0) |
| 415 , m_userGestureRequiredForPlay(false) | 415 , m_lockedPendingUserGesture(false) |
| 416 , m_playing(false) | 416 , m_playing(false) |
| 417 , m_shouldDelayLoadEvent(false) | 417 , m_shouldDelayLoadEvent(false) |
| 418 , m_haveFiredLoadedData(false) | 418 , m_haveFiredLoadedData(false) |
| 419 , m_autoplaying(true) | 419 , m_autoplaying(true) |
| 420 , m_muted(false) | 420 , m_muted(false) |
| 421 , m_paused(true) | 421 , m_paused(true) |
| 422 , m_seeking(false) | 422 , m_seeking(false) |
| 423 , m_sentStalledEvent(false) | 423 , m_sentStalledEvent(false) |
| 424 , m_ignorePreloadNone(false) | 424 , m_ignorePreloadNone(false) |
| 425 , m_textTracksVisible(false) | 425 , m_textTracksVisible(false) |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 440 , m_remotePlaybackClient(nullptr) | 440 , m_remotePlaybackClient(nullptr) |
| 441 { | 441 { |
| 442 ThreadState::current()->registerPreFinalizer(this); | 442 ThreadState::current()->registerPreFinalizer(this); |
| 443 | 443 |
| 444 WTF_LOG(Media, "HTMLMediaElement::HTMLMediaElement(%p)", this); | 444 WTF_LOG(Media, "HTMLMediaElement::HTMLMediaElement(%p)", this); |
| 445 | 445 |
| 446 // If any experiment is enabled, then we want to enable a user gesture by | 446 // If any experiment is enabled, then we want to enable a user gesture by |
| 447 // default, otherwise the experiment does nothing. | 447 // default, otherwise the experiment does nothing. |
| 448 if ((document.settings() && document.settings()->mediaPlaybackRequiresUserGe sture()) | 448 if ((document.settings() && document.settings()->mediaPlaybackRequiresUserGe sture()) |
| 449 || m_autoplayHelper->isExperimentEnabled()) { | 449 || m_autoplayHelper->isExperimentEnabled()) { |
| 450 m_userGestureRequiredForPlay = true; | 450 m_lockedPendingUserGesture = true; |
| 451 } | 451 } |
| 452 | 452 |
| 453 setHasCustomStyleCallbacks(); | 453 setHasCustomStyleCallbacks(); |
| 454 addElementToDocumentMap(this, &document); | 454 addElementToDocumentMap(this, &document); |
| 455 | 455 |
| 456 UseCounter::count(document, UseCounter::HTMLMediaElement); | 456 UseCounter::count(document, UseCounter::HTMLMediaElement); |
| 457 } | 457 } |
| 458 | 458 |
| 459 HTMLMediaElement::~HTMLMediaElement() | 459 HTMLMediaElement::~HTMLMediaElement() |
| 460 { | 460 { |
| (...skipping 1152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1613 if (isPotentiallyPlaying) | 1613 if (isPotentiallyPlaying) |
| 1614 scheduleNotifyPlaying(); | 1614 scheduleNotifyPlaying(); |
| 1615 } | 1615 } |
| 1616 | 1616 |
| 1617 // Check for autoplay, and record metrics about it if needed. | 1617 // Check for autoplay, and record metrics about it if needed. |
| 1618 if (shouldAutoplay(RecordMetricsBehavior::DoRecord)) { | 1618 if (shouldAutoplay(RecordMetricsBehavior::DoRecord)) { |
| 1619 // If the autoplay experiment says that it's okay to play now, | 1619 // If the autoplay experiment says that it's okay to play now, |
| 1620 // then don't require a user gesture. | 1620 // then don't require a user gesture. |
| 1621 m_autoplayHelper->becameReadyToPlay(); | 1621 m_autoplayHelper->becameReadyToPlay(); |
| 1622 | 1622 |
| 1623 if (!m_userGestureRequiredForPlay) { | 1623 if (!isGestureNeededForPlayback()) { |
| 1624 m_paused = false; | 1624 m_paused = false; |
| 1625 invalidateCachedTime(); | 1625 invalidateCachedTime(); |
| 1626 scheduleEvent(EventTypeNames::play); | 1626 scheduleEvent(EventTypeNames::play); |
| 1627 scheduleNotifyPlaying(); | 1627 scheduleNotifyPlaying(); |
| 1628 m_autoplaying = false; | 1628 m_autoplaying = false; |
| 1629 } | 1629 } |
| 1630 } | 1630 } |
| 1631 | 1631 |
| 1632 scheduleEvent(EventTypeNames::canplaythrough); | 1632 scheduleEvent(EventTypeNames::canplaythrough); |
| 1633 | 1633 |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2036 ScriptPromise promise = resolver->promise(); | 2036 ScriptPromise promise = resolver->promise(); |
| 2037 | 2037 |
| 2038 m_playResolvers.append(resolver); | 2038 m_playResolvers.append(resolver); |
| 2039 return promise; | 2039 return promise; |
| 2040 } | 2040 } |
| 2041 | 2041 |
| 2042 Nullable<ExceptionCode> HTMLMediaElement::play() | 2042 Nullable<ExceptionCode> HTMLMediaElement::play() |
| 2043 { | 2043 { |
| 2044 WTF_LOG(Media, "HTMLMediaElement::play(%p)", this); | 2044 WTF_LOG(Media, "HTMLMediaElement::play(%p)", this); |
| 2045 | 2045 |
| 2046 m_autoplayHelper->playMethodCalled(); | 2046 m_autoplayHelper->playMethodCalled(!m_paused); |
| 2047 | 2047 |
| 2048 if (!UserGestureIndicator::processingUserGesture()) { | 2048 if (!UserGestureIndicator::processingUserGesture()) { |
| 2049 if (m_userGestureRequiredForPlay) { | 2049 if (isGestureNeededForPlayback()) { |
| 2050 // If playback is deferred, then don't start playback but don't | |
| 2051 // fail yet either. | |
| 2052 if (m_autoplayHelper->isPlaybackDeferred()) | |
|
mlamouri (slow - plz ping)
2016/05/05 13:45:40
I'm a bit confused. What does that mean? When will
liberato (no reviews please)
2016/05/05 17:48:57
if the element needs a user gesture, and is off-sc
| |
| 2053 return nullptr; | |
| 2054 | |
| 2055 // If we're already playing, then this play would do nothing anyway. | |
| 2056 // Call playInternal to handle scheduling the promise resolution. | |
| 2057 if (!m_paused) { | |
| 2058 playInternal(); | |
| 2059 return nullptr; | |
| 2060 } | |
| 2061 | |
| 2050 recordAutoplayMetric(PlayMethodFailed); | 2062 recordAutoplayMetric(PlayMethodFailed); |
| 2051 String message = ExceptionMessages::failedToExecute("play", "HTMLMed iaElement", "API can only be initiated by a user gesture."); | 2063 String message = ExceptionMessages::failedToExecute("play", "HTMLMed iaElement", "API can only be initiated by a user gesture."); |
| 2052 document().addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMessageLevel, message)); | 2064 document().addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMessageLevel, message)); |
| 2053 return NotAllowedError; | 2065 return NotAllowedError; |
| 2054 } | 2066 } |
| 2055 } else { | 2067 } else { |
| 2056 UserGestureIndicator::utilizeUserGesture(); | 2068 UserGestureIndicator::utilizeUserGesture(); |
| 2057 // We ask the helper to remove the gesture requirement for us, so that | 2069 // We ask the helper to remove the gesture requirement for us, so that |
| 2058 // it can record the reason. | 2070 // it can record the reason. |
| 2059 Platform::current()->recordAction(UserMetricsAction("Media_Play_WithGest ure")); | 2071 Platform::current()->recordAction(UserMetricsAction("Media_Play_WithGest ure")); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2233 | 2245 |
| 2234 void HTMLMediaElement::setMuted(bool muted) | 2246 void HTMLMediaElement::setMuted(bool muted) |
| 2235 { | 2247 { |
| 2236 WTF_LOG(Media, "HTMLMediaElement::setMuted(%p, %s)", this, boolString(muted) ); | 2248 WTF_LOG(Media, "HTMLMediaElement::setMuted(%p, %s)", this, boolString(muted) ); |
| 2237 | 2249 |
| 2238 if (m_muted == muted) | 2250 if (m_muted == muted) |
| 2239 return; | 2251 return; |
| 2240 | 2252 |
| 2241 m_muted = muted; | 2253 m_muted = muted; |
| 2242 | 2254 |
| 2243 m_autoplayHelper->mutedChanged(); | |
| 2244 | |
| 2245 updateVolume(); | 2255 updateVolume(); |
| 2246 | 2256 |
| 2247 if (muted) | 2257 if (muted) |
| 2248 Platform::current()->recordAction(UserMetricsAction("Media_Playback_Mute _On")); | 2258 Platform::current()->recordAction(UserMetricsAction("Media_Playback_Mute _On")); |
| 2249 else | 2259 else |
| 2250 Platform::current()->recordAction(UserMetricsAction("Media_Playback_Mute _Off")); | 2260 Platform::current()->recordAction(UserMetricsAction("Media_Playback_Mute _Off")); |
| 2251 | 2261 |
| 2252 scheduleEvent(EventTypeNames::volumechange); | 2262 scheduleEvent(EventTypeNames::volumechange); |
| 2253 } | 2263 } |
| 2254 | 2264 |
| (...skipping 1388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3643 | 3653 |
| 3644 // Enable the first audio track if an audio track hasn't been enabled yet. | 3654 // Enable the first audio track if an audio track hasn't been enabled yet. |
| 3645 if (audioTracks().length() > 0 && !audioTracks().hasEnabledTrack()) | 3655 if (audioTracks().length() > 0 && !audioTracks().hasEnabledTrack()) |
| 3646 audioTracks().anonymousIndexedGetter(0)->setEnabled(true); | 3656 audioTracks().anonymousIndexedGetter(0)->setEnabled(true); |
| 3647 | 3657 |
| 3648 // Select the first video track if a video track hasn't been selected yet. | 3658 // Select the first video track if a video track hasn't been selected yet. |
| 3649 if (videoTracks().length() > 0 && videoTracks().selectedIndex() == -1) | 3659 if (videoTracks().length() > 0 && videoTracks().selectedIndex() == -1) |
| 3650 videoTracks().anonymousIndexedGetter(0)->setSelected(true); | 3660 videoTracks().anonymousIndexedGetter(0)->setSelected(true); |
| 3651 } | 3661 } |
| 3652 | 3662 |
| 3653 bool HTMLMediaElement::isUserGestureRequiredForPlay() const | 3663 bool HTMLMediaElement::isLockedPendingUserGesture() const |
| 3654 { | 3664 { |
| 3655 return m_userGestureRequiredForPlay; | 3665 return m_lockedPendingUserGesture; |
| 3656 } | 3666 } |
| 3657 | 3667 |
| 3658 void HTMLMediaElement::removeUserGestureRequirement() | 3668 void HTMLMediaElement::removeUserGestureRequirement() |
|
mlamouri (slow - plz ping)
2016/05/05 13:45:40
Should this be renamed?
liberato (no reviews please)
2016/05/05 17:48:57
good point, unlockWithUserGesture().
| |
| 3659 { | 3669 { |
| 3660 m_userGestureRequiredForPlay = false; | 3670 m_lockedPendingUserGesture = false; |
| 3671 } | |
| 3672 | |
| 3673 bool HTMLMediaElement::isGestureNeededForPlayback() const | |
| 3674 { | |
| 3675 return m_lockedPendingUserGesture | |
| 3676 && !m_autoplayHelper->isGestureRequirementOverridden(); | |
| 3661 } | 3677 } |
| 3662 | 3678 |
| 3663 void HTMLMediaElement::setNetworkState(NetworkState state) | 3679 void HTMLMediaElement::setNetworkState(NetworkState state) |
| 3664 { | 3680 { |
| 3665 if (m_networkState != state) { | 3681 if (m_networkState != state) { |
| 3666 m_networkState = state; | 3682 m_networkState = state; |
| 3667 if (MediaControls* controls = mediaControls()) | 3683 if (MediaControls* controls = mediaControls()) |
| 3668 controls->networkStateChanged(); | 3684 controls->networkStateChanged(); |
| 3669 } | 3685 } |
| 3670 } | 3686 } |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3865 | 3881 |
| 3866 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect() co nst | 3882 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect() co nst |
| 3867 { | 3883 { |
| 3868 IntRect result; | 3884 IntRect result; |
| 3869 if (LayoutObject* object = m_element->layoutObject()) | 3885 if (LayoutObject* object = m_element->layoutObject()) |
| 3870 result = object->absoluteBoundingBoxRect(); | 3886 result = object->absoluteBoundingBoxRect(); |
| 3871 return result; | 3887 return result; |
| 3872 } | 3888 } |
| 3873 | 3889 |
| 3874 } // namespace blink | 3890 } // namespace blink |
| OLD | NEW |