Chromium Code Reviews| Index: third_party/WebKit/Source/core/html/HTMLMediaElement.cpp |
| diff --git a/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp b/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp |
| index b7232536c0f2f395ea56279a99c7895630bab6df..416d7318daf3984a02ce67d5fdf591039c51d7de 100644 |
| --- a/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp |
| +++ b/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp |
| @@ -471,8 +471,10 @@ void HTMLMediaElement::didMoveToNewDocument(Document& oldDocument) |
| // A proper fix would provide a mechanism to allow this object to refresh |
| // the MediaPlayer's LocalFrame and FrameLoader references on |
| // document changes so that playback can be resumed properly. |
| - clearMediaPlayer(LoadMediaResource); |
| - scheduleDelayedAction(LoadMediaResource); |
| + prepareForLoad(); |
|
philipj_slow
2015/12/18 15:12:24
I think that this bit is made worse by this CL, ex
|
| + m_pendingActionFlags |= LoadMediaResource; |
| + if (!m_loadTimer.isActive()) |
| + m_loadTimer.startOneShot(0, BLINK_FROM_HERE); |
| // Decrement the load event delay count on oldDocument now that m_webMediaPlayer has been destroyed |
| // and there is no risk of dispatching a load event from within the destructor. |
| @@ -501,8 +503,10 @@ void HTMLMediaElement::parseAttribute(const QualifiedName& name, const AtomicStr |
| if (name == srcAttr) { |
| // Trigger a reload, as long as the 'src' attribute is present. |
| if (!value.isNull()) { |
| - clearMediaPlayer(LoadMediaResource); |
| - scheduleDelayedAction(LoadMediaResource); |
| + prepareForLoad(); |
| + m_pendingActionFlags |= LoadMediaResource; |
| + if (!m_loadTimer.isActive()) |
| + m_loadTimer.startOneShot(0, BLINK_FROM_HERE); |
| } |
| } else if (name == controlsAttr) { |
| configureMediaControls(); |
| @@ -715,18 +719,8 @@ void HTMLMediaElement::prepareForLoad() |
| { |
| WTF_LOG(Media, "HTMLMediaElement::prepareForLoad(%p)", this); |
| - // Perform the cleanup required for the resource load algorithm to run. |
| - stopPeriodicTimers(); |
| - m_loadTimer.stop(); |
| - cancelDeferredLoad(); |
| - // FIXME: Figure out appropriate place to reset LoadTextTrackResource if necessary and set m_pendingActionFlags to 0 here. |
| - m_pendingActionFlags &= ~LoadMediaResource; |
| - m_sentEndEvent = false; |
| - m_sentStalledEvent = false; |
| - m_haveFiredLoadedData = false; |
| - m_completelyLoaded = false; |
| - m_havePreparedToPlay = false; |
| - m_displayMode = Unknown; |
| + NetworkState networkState = m_networkState; |
| + resetMediaElement(LoadMediaResource); |
| // 1 - Abort any already-running instance of the resource selection algorithm for this element. |
| m_loadState = WaitingForSource; |
| @@ -738,13 +732,11 @@ void HTMLMediaElement::prepareForLoad() |
| // 3 - If the media element's networkState is set to NETWORK_LOADING or NETWORK_IDLE, queue |
| // a task to fire a simple event named abort at the media element. |
| - if (m_networkState == NETWORK_LOADING || m_networkState == NETWORK_IDLE) |
| + if (networkState == NETWORK_LOADING || networkState == NETWORK_IDLE) |
| scheduleEvent(EventTypeNames::abort); |
| - resetMediaPlayerAndMediaSource(); |
| - |
| // 4 - If the media element's networkState is not set to NETWORK_EMPTY, then run these substeps |
| - if (m_networkState != NETWORK_EMPTY) { |
| + if (networkState != NETWORK_EMPTY) { |
| // 4.1 - Queue a task to fire a simple event named emptied at the media element. |
| scheduleEvent(EventTypeNames::emptied); |
| @@ -2986,7 +2978,7 @@ void HTMLMediaElement::clearMediaPlayerAndAudioSourceProviderClientWithoutLockin |
| } |
| } |
| -void HTMLMediaElement::clearMediaPlayer(int flags) |
| +void HTMLMediaElement::resetMediaElement(int flags) |
| { |
| forgetResourceSpecificTracks(); |
| @@ -2999,6 +2991,11 @@ void HTMLMediaElement::clearMediaPlayer(int flags) |
| clearMediaPlayerAndAudioSourceProviderClientWithoutLocking(); |
| } |
| +#if ENABLE(WEB_AUDIO) |
| + if (m_audioSourceNode) |
| + audioSourceProvider().setClient(m_audioSourceNode); |
| +#endif |
| + |
| stopPeriodicTimers(); |
| m_loadTimer.stop(); |
| @@ -3008,6 +3005,26 @@ void HTMLMediaElement::clearMediaPlayer(int flags) |
| // We can't cast if we don't have a media player. |
| m_remoteRoutesAvailable = false; |
| m_playingRemotely = false; |
| + |
| + // FIXME: Figure out appropriate place to reset LoadTextTrackResource if necessary and set m_pendingActionFlags to 0 here. |
| + m_sentEndEvent = false; |
| + m_sentStalledEvent = false; |
| + m_haveFiredLoadedData = false; |
| + m_completelyLoaded = false; |
| + m_havePreparedToPlay = false; |
| + m_displayMode = Unknown; |
| + |
| + m_readyState = HAVE_NOTHING; |
| + m_readyStateMaximum = HAVE_NOTHING; |
| + setNetworkState(NETWORK_EMPTY); |
| + setShouldDelayLoadEvent(false); |
| + m_currentSourceNode = nullptr; |
| + invalidateCachedTime(); |
| + cueTimeline().updateActiveCues(0); |
| + m_playing = false; |
| + m_paused = true; |
| + m_seeking = false; |
| + |
| if (mediaControls()) |
| mediaControls()->refreshCastButtonVisibilityWithoutUpdate(); |
| @@ -3025,24 +3042,12 @@ void HTMLMediaElement::stop() |
| cancelPendingEventsAndCallbacks(); |
| m_asyncEventQueue->close(); |
| - // Stop the playback without generating events |
| - clearMediaPlayer(-1); |
| - m_readyState = HAVE_NOTHING; |
| - m_readyStateMaximum = HAVE_NOTHING; |
| - setNetworkState(NETWORK_EMPTY); |
| - setShouldDelayLoadEvent(false); |
| - m_currentSourceNode = nullptr; |
| - invalidateCachedTime(); |
| - cueTimeline().updateActiveCues(0); |
| - m_playing = false; |
| - m_paused = true; |
| - m_seeking = false; |
| + // Clear everything in the Media Element |
| + resetMediaElement(-1); |
| if (layoutObject()) |
| layoutObject()->updateFromElement(); |
| - stopPeriodicTimers(); |
| - |
| // Ensure that hasPendingActivity() is not preventing garbage collection, since otherwise this |
| // media element will simply leak. |
| ASSERT(!hasPendingActivity()); |
| @@ -3391,7 +3396,7 @@ void* HTMLMediaElement::preDispatchEventHandler(Event* event) |
| return nullptr; |
| } |
| -// TODO(srirama.m): Refactor this and clearMediaPlayer to the extent possible. |
| +// TODO(srirama.m): Merge it to resetMediaElement if possible and remove it. |
| void HTMLMediaElement::resetMediaPlayerAndMediaSource() |
| { |
| closeMediaSource(); |