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 4b0c964be78172ce5cc7eae3c9642c835a39a006..43456ef4690856abfbbf77753312d3fe25e7f6d2 100644 |
| --- a/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp |
| +++ b/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp |
| @@ -388,7 +388,7 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document& docum |
| : HTMLElement(tagName, document) |
| , ActiveScriptWrappable(this) |
| , ActiveDOMObject(&document) |
| - , m_loadTimer(this, &HTMLMediaElement::loadTimerFired) |
| + , m_textTrackLoadTimer(this, &HTMLMediaElement::textTrackLoadTimerFired) |
| , m_progressEventTimer(this, &HTMLMediaElement::progressEventTimerFired) |
| , m_playbackProgressTimer(this, &HTMLMediaElement::playbackProgressTimerFired) |
| , m_audioTracksTimer(this, &HTMLMediaElement::audioTracksTimerFired) |
| @@ -413,7 +413,6 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document& docum |
| , m_displayMode(Unknown) |
| , m_cachedTime(std::numeric_limits<double>::quiet_NaN()) |
| , m_fragmentEndTime(std::numeric_limits<double>::quiet_NaN()) |
| - , m_pendingActionFlags(0) |
| , m_lockedPendingUserGesture(false) |
| , m_playing(false) |
| , m_shouldDelayLoadEvent(false) |
| @@ -436,6 +435,8 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document& docum |
| , m_textTracks(nullptr) |
| , m_playPromiseResolveTask(CancellableTaskFactory::create(this, &HTMLMediaElement::resolveScheduledPlayPromises)) |
| , m_playPromiseRejectTask(CancellableTaskFactory::create(this, &HTMLMediaElement::rejectScheduledPlayPromises)) |
| + , m_resourceSelectionAlgorithmContinuationTask(CancellableTaskFactory::create(this, &HTMLMediaElement::continueResourceSelectionAlgorithm)) |
| + , m_loadNextSourceChildAfterErrorTask(CancellableTaskFactory::create(this, &HTMLMediaElement::loadNextSourceChildAfterError)) |
| , m_audioSourceNode(nullptr) |
| , m_autoplayHelperClient(AutoplayHelperClientImpl::create(this)) |
| , m_autoplayHelper(AutoplayExperimentHelper::create(m_autoplayHelperClient.get())) |
| @@ -635,17 +636,8 @@ void HTMLMediaElement::scheduleTextTrackResourceLoad() |
| { |
| BLINK_MEDIA_LOG << "scheduleTextTrackResourceLoad(" << (void*)this << ")"; |
| - m_pendingActionFlags |= LoadTextTrackResource; |
| - |
| - if (!m_loadTimer.isActive()) |
| - m_loadTimer.startOneShot(0, BLINK_FROM_HERE); |
| -} |
| - |
| -void HTMLMediaElement::scheduleNextSourceChild() |
| -{ |
| - // Schedule the timer to try the next <source> element WITHOUT resetting state ala invokeLoadAlgorithm. |
| - m_pendingActionFlags |= LoadMediaResource; |
| - m_loadTimer.startOneShot(0, BLINK_FROM_HERE); |
| + if (!m_textTrackLoadTimer.isActive()) |
| + m_textTrackLoadTimer.startOneShot(0, BLINK_FROM_HERE); |
| } |
| void HTMLMediaElement::scheduleEvent(const AtomicString& eventName) |
| @@ -661,19 +653,10 @@ void HTMLMediaElement::scheduleEvent(Event* event) |
| m_asyncEventQueue->enqueueEvent(event); |
| } |
| -void HTMLMediaElement::loadTimerFired(TimerBase*) |
| +void HTMLMediaElement::textTrackLoadTimerFired(TimerBase*) |
| { |
| - if (m_pendingActionFlags & LoadTextTrackResource) |
| - honorUserPreferencesForAutomaticTextTrackSelection(); |
| - |
| - if (m_pendingActionFlags & LoadMediaResource) { |
| - if (m_loadState == LoadingFromSourceElement) |
| - loadNextSourceChild(); |
| - else |
| - loadInternal(); |
| - } |
| - |
| - m_pendingActionFlags = 0; |
| + BLINK_MEDIA_LOG << "HTMLMediaElement::textTrackLoadTimerFired(" << (void*)this << ")"; |
| + honorUserPreferencesForAutomaticTextTrackSelection(); |
| } |
| MediaError* HTMLMediaElement::error() const |
| @@ -741,15 +724,14 @@ void HTMLMediaElement::invokeLoadAlgorithm() |
| // 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_sentStalledEvent = false; |
| m_haveFiredLoadedData = false; |
| m_displayMode = Unknown; |
| // 1 - Abort any already-running instance of the resource selection algorithm for this element. |
| + m_resourceSelectionAlgorithmContinuationTask->cancel(); |
| + m_loadNextSourceChildAfterErrorTask->cancel(); |
| m_loadState = WaitingForSource; |
| m_currentSourceNode = nullptr; |
| @@ -870,9 +852,13 @@ void HTMLMediaElement::invokeResourceSelectionAlgorithm() |
| mediaControls()->reset(); |
| // 4 - Await a stable state, allowing the task that invoked this algorithm to continue |
| - // TODO(srirama.m): Remove scheduleNextSourceChild() and post a microtask instead. |
| - // See http://crbug.com/593289 for more details. |
| - scheduleNextSourceChild(); |
| + Platform::current()->currentThread()->getWebTaskRunner()->postTask(BLINK_FROM_HERE, m_resourceSelectionAlgorithmContinuationTask->cancelAndCreate()); |
|
foolip
2016/09/02 10:31:00
Just to be clear, this and the below use of Platfo
|
| +} |
| + |
| +void HTMLMediaElement::continueResourceSelectionAlgorithm() |
| +{ |
| + BLINK_MEDIA_LOG << "HTMLMediaElement::continueResourceSelectionAlgorithm(" << (void*)this << ")"; |
| + loadInternal(); |
| } |
| void HTMLMediaElement::loadInternal() |
| @@ -1002,6 +988,13 @@ void HTMLMediaElement::loadNextSourceChild() |
| loadResource(WebMediaPlayerSource(WebURL(mediaURL)), contentType); |
| } |
| +void HTMLMediaElement::loadNextSourceChildAfterError() |
| +{ |
| + // 9.Otherwise.11 - Forget the media element's media-resource-specific tracks. |
| + forgetResourceSpecificTracks(); |
| + loadNextSourceChild(); |
| +} |
| + |
| void HTMLMediaElement::loadResource(const WebMediaPlayerSource& source, const ContentType& contentType) |
| { |
| DCHECK(isMainThread()); |
| @@ -1440,13 +1433,9 @@ void HTMLMediaElement::mediaLoadingFailed(WebMediaPlayer::NetworkState error) |
| BLINK_MEDIA_LOG << "setNetworkState(" << (void*)this << ") - error event not sent, <source> was removed"; |
| // 9.Otherwise.10 - Asynchronously await a stable state. The synchronous section consists of all the remaining steps of this algorithm until the algorithm says the synchronous section has ended. |
| - |
| - // 9.Otherwise.11 - Forget the media element's media-resource-specific tracks. |
| - forgetResourceSpecificTracks(); |
| - |
| if (havePotentialSourceChild()) { |
| BLINK_MEDIA_LOG << "setNetworkState(" << (void*)this << ") - scheduling next <source>"; |
| - scheduleNextSourceChild(); |
| + Platform::current()->currentThread()->getWebTaskRunner()->postTask(BLINK_FROM_HERE, m_loadNextSourceChildAfterErrorTask->cancelAndCreate()); |
| } else { |
| BLINK_MEDIA_LOG << "setNetworkState(" << (void*)this << ") - no more <source> elements, waiting"; |
| waitForSourceChange(); |
| @@ -2855,7 +2844,7 @@ void HTMLMediaElement::sourceWasAdded(HTMLSourceElement* source) |
| // 25. Jump back to the find next candidate step above. |
| m_nextChildNodeToConsider = source; |
| - scheduleNextSourceChild(); |
| + loadNextSourceChild(); |
| } |
| void HTMLMediaElement::sourceWasRemoved(HTMLSourceElement* source) |
| @@ -3203,9 +3192,8 @@ void HTMLMediaElement::clearMediaPlayer() |
| } |
| stopPeriodicTimers(); |
| - m_loadTimer.stop(); |
| + m_textTrackLoadTimer.stop(); |
| - m_pendingActionFlags = 0; |
| m_loadState = WaitingForSource; |
| // We can't cast if we don't have a media player. |