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 17 matching lines...) Expand all Loading... | |
28 #include "bindings/core/v8/ExceptionState.h" | 28 #include "bindings/core/v8/ExceptionState.h" |
29 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 29 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
30 #include "bindings/core/v8/ScriptController.h" | 30 #include "bindings/core/v8/ScriptController.h" |
31 #include "bindings/core/v8/ScriptEventListener.h" | 31 #include "bindings/core/v8/ScriptEventListener.h" |
32 #include "bindings/core/v8/ScriptPromiseResolver.h" | 32 #include "bindings/core/v8/ScriptPromiseResolver.h" |
33 #include "core/HTMLNames.h" | 33 #include "core/HTMLNames.h" |
34 #include "core/css/MediaList.h" | 34 #include "core/css/MediaList.h" |
35 #include "core/dom/Attribute.h" | 35 #include "core/dom/Attribute.h" |
36 #include "core/dom/ElementTraversal.h" | 36 #include "core/dom/ElementTraversal.h" |
37 #include "core/dom/Fullscreen.h" | 37 #include "core/dom/Fullscreen.h" |
38 #include "core/dom/Microtask.h" | |
38 #include "core/dom/shadow/ShadowRoot.h" | 39 #include "core/dom/shadow/ShadowRoot.h" |
39 #include "core/events/Event.h" | 40 #include "core/events/Event.h" |
40 #include "core/frame/LocalFrame.h" | 41 #include "core/frame/LocalFrame.h" |
41 #include "core/frame/Settings.h" | 42 #include "core/frame/Settings.h" |
42 #include "core/frame/UseCounter.h" | 43 #include "core/frame/UseCounter.h" |
43 #include "core/frame/csp/ContentSecurityPolicy.h" | 44 #include "core/frame/csp/ContentSecurityPolicy.h" |
44 #include "core/html/HTMLMediaSource.h" | 45 #include "core/html/HTMLMediaSource.h" |
45 #include "core/html/HTMLSourceElement.h" | 46 #include "core/html/HTMLSourceElement.h" |
46 #include "core/html/HTMLTrackElement.h" | 47 #include "core/html/HTMLTrackElement.h" |
47 #include "core/html/MediaError.h" | 48 #include "core/html/MediaError.h" |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 case WebMediaPlayer::PreloadAuto: | 262 case WebMediaPlayer::PreloadAuto: |
262 return "auto"; | 263 return "auto"; |
263 } | 264 } |
264 | 265 |
265 ASSERT_NOT_REACHED(); | 266 ASSERT_NOT_REACHED(); |
266 return String(); | 267 return String(); |
267 } | 268 } |
268 | 269 |
269 } // anonymous namespace | 270 } // anonymous namespace |
270 | 271 |
272 class HTMLMediaElement::Task : public WebTaskRunner::Task { | |
273 public: | |
274 static PassOwnPtr<Task> create(HTMLMediaElement* mediaElement) | |
275 { | |
276 return adoptPtr(new Task(mediaElement)); | |
277 } | |
278 | |
279 Task(HTMLMediaElement* mediaElement) | |
280 : m_mediaElement(mediaElement) | |
281 , m_weakFactory(this) | |
282 { | |
283 v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate(); | |
284 v8::HandleScope scope(isolate); | |
285 if (ScriptState::hasCurrentScriptState(isolate)) | |
286 m_scriptState = ScriptState::current(isolate); | |
287 else | |
288 m_scriptState = ScriptState::forMainWorld(m_mediaElement->document() .frame()); | |
289 } | |
290 | |
291 void run() override | |
292 { | |
293 WTF_LOG(Media, "HTMLMediaElement::Task::run(%p)", m_mediaElement.get()); | |
294 if (!m_mediaElement) | |
295 return; | |
296 | |
297 if (m_scriptState->contextIsValid()) { | |
298 ScriptState::Scope scope(m_scriptState.get()); | |
299 m_mediaElement->continueResourceSelectionAlgorithm(); | |
300 } else { | |
301 m_mediaElement->continueResourceSelectionAlgorithm(); | |
302 } | |
303 } | |
304 | |
305 void clearTaskInfo() | |
306 { | |
307 m_mediaElement = nullptr; | |
308 m_scriptState.clear(); | |
309 } | |
310 | |
311 WeakPtr<Task> createWeakPtr() | |
312 { | |
313 return m_weakFactory.createWeakPtr(); | |
314 } | |
315 | |
316 private: | |
317 RawPtrWillBeWeakPersistent<HTMLMediaElement> m_mediaElement; | |
318 RefPtr<ScriptState> m_scriptState; | |
319 WeakPtrFactory<Task> m_weakFactory; | |
320 }; | |
321 | |
271 void HTMLMediaElement::recordAutoplayMetric(AutoplayMetrics metric) | 322 void HTMLMediaElement::recordAutoplayMetric(AutoplayMetrics metric) |
272 { | 323 { |
273 DEFINE_STATIC_LOCAL(EnumerationHistogram, autoplayHistogram, ("Blink.MediaEl ement.Autoplay", NumberOfAutoplayMetrics)); | 324 DEFINE_STATIC_LOCAL(EnumerationHistogram, autoplayHistogram, ("Blink.MediaEl ement.Autoplay", NumberOfAutoplayMetrics)); |
274 autoplayHistogram.count(metric); | 325 autoplayHistogram.count(metric); |
275 } | 326 } |
276 | 327 |
277 WebMimeRegistry::SupportsType HTMLMediaElement::supportsType(const ContentType& contentType) | 328 WebMimeRegistry::SupportsType HTMLMediaElement::supportsType(const ContentType& contentType) |
278 { | 329 { |
279 DEFINE_STATIC_LOCAL(const String, codecs, ("codecs")); | 330 DEFINE_STATIC_LOCAL(const String, codecs, ("codecs")); |
280 | 331 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
391 | 442 |
392 setShouldDelayLoadEvent(false); | 443 setShouldDelayLoadEvent(false); |
393 | 444 |
394 if (m_textTracks) | 445 if (m_textTracks) |
395 m_textTracks->clearOwner(); | 446 m_textTracks->clearOwner(); |
396 m_audioTracks->shutdown(); | 447 m_audioTracks->shutdown(); |
397 m_videoTracks->shutdown(); | 448 m_videoTracks->shutdown(); |
398 | 449 |
399 closeMediaSource(); | 450 closeMediaSource(); |
400 | 451 |
452 if (m_pendingTask) | |
453 m_pendingTask->clearTaskInfo(); | |
454 | |
401 removeElementFromDocumentMap(this, &document()); | 455 removeElementFromDocumentMap(this, &document()); |
402 | 456 |
403 // Destroying the player may cause a resource load to be canceled, | 457 // Destroying the player may cause a resource load to be canceled, |
404 // which could result in LocalDOMWindow::dispatchWindowLoadEvent() being | 458 // which could result in LocalDOMWindow::dispatchWindowLoadEvent() being |
405 // called via ResourceFetch::didLoadResource() then | 459 // called via ResourceFetch::didLoadResource() then |
406 // FrameLoader::checkCompleted(). To prevent load event dispatching during | 460 // FrameLoader::checkCompleted(). To prevent load event dispatching during |
407 // object destruction, we use Document::incrementLoadEventDelayCount(). | 461 // object destruction, we use Document::incrementLoadEventDelayCount(). |
408 // See http://crbug.com/275223 for more details. | 462 // See http://crbug.com/275223 for more details. |
409 document().incrementLoadEventDelayCount(); | 463 document().incrementLoadEventDelayCount(); |
410 | 464 |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
740 // FIXME: Figure out appropriate place to reset LoadTextTrackResource if nec essary and set m_pendingActionFlags to 0 here. | 794 // FIXME: Figure out appropriate place to reset LoadTextTrackResource if nec essary and set m_pendingActionFlags to 0 here. |
741 m_pendingActionFlags &= ~LoadMediaResource; | 795 m_pendingActionFlags &= ~LoadMediaResource; |
742 m_sentEndEvent = false; | 796 m_sentEndEvent = false; |
743 m_sentStalledEvent = false; | 797 m_sentStalledEvent = false; |
744 m_haveFiredLoadedData = false; | 798 m_haveFiredLoadedData = false; |
745 m_displayMode = Unknown; | 799 m_displayMode = Unknown; |
746 | 800 |
747 // 1 - Abort any already-running instance of the resource selection algorith m for this element. | 801 // 1 - Abort any already-running instance of the resource selection algorith m for this element. |
748 m_loadState = WaitingForSource; | 802 m_loadState = WaitingForSource; |
749 m_currentSourceNode = nullptr; | 803 m_currentSourceNode = nullptr; |
804 if (m_pendingTask) { | |
805 m_pendingTask->clearTaskInfo(); | |
806 m_pendingTask.clear(); | |
807 } | |
750 | 808 |
751 // 2 - If there are any tasks from the media element's media element event t ask source in | 809 // 2 - If there are any tasks from the media element's media element event t ask source in |
752 // one of the task queues, then remove those tasks. | 810 // one of the task queues, then remove those tasks. |
753 cancelPendingEventsAndCallbacks(); | 811 cancelPendingEventsAndCallbacks(); |
754 | 812 |
755 rejectPlayPromises(AbortError, "The play() request was interrupted by a new load request."); | 813 rejectPlayPromises(AbortError, "The play() request was interrupted by a new load request."); |
756 | 814 |
757 // 3 - If the media element's networkState is set to NETWORK_LOADING or NETW ORK_IDLE, queue | 815 // 3 - If the media element's networkState is set to NETWORK_LOADING or NETW ORK_IDLE, queue |
758 // a task to fire a simple event named abort at the media element. | 816 // a task to fire a simple event named abort at the media element. |
759 if (m_networkState == NETWORK_LOADING || m_networkState == NETWORK_IDLE) | 817 if (m_networkState == NETWORK_LOADING || m_networkState == NETWORK_IDLE) |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
826 // so they are closer to the relevant spec steps. | 884 // so they are closer to the relevant spec steps. |
827 m_lastSeekTime = 0; | 885 m_lastSeekTime = 0; |
828 m_duration = std::numeric_limits<double>::quiet_NaN(); | 886 m_duration = std::numeric_limits<double>::quiet_NaN(); |
829 | 887 |
830 // 3 - Set the media element's delaying-the-load-event flag to true (this de lays the load event) | 888 // 3 - Set the media element's delaying-the-load-event flag to true (this de lays the load event) |
831 setShouldDelayLoadEvent(true); | 889 setShouldDelayLoadEvent(true); |
832 if (mediaControls()) | 890 if (mediaControls()) |
833 mediaControls()->reset(); | 891 mediaControls()->reset(); |
834 | 892 |
835 // 4 - Await a stable state, allowing the task that invoked this algorithm t o continue | 893 // 4 - Await a stable state, allowing the task that invoked this algorithm t o continue |
836 // TODO(srirama.m): Remove scheduleNextSourceChild() and post a microtask in stead. | 894 OwnPtr<Task> task = Task::create(this); |
837 // See http://crbug.com/593289 for more details. | 895 m_pendingTask = task->createWeakPtr(); |
838 scheduleNextSourceChild(); | 896 Microtask::enqueueMicrotask(task.release()); |
philipj_slow
2016/03/16 13:40:20
If you have a look at RTCPeerConnection.cpp and HT
philipj_slow
2016/03/16 15:35:10
OK, so one problem could be where the spec says "A
Srirama
2016/03/16 17:41:17
Infact when i started i just copied it from ImageL
philipj_slow
2016/03/17 11:30:55
OK. So this problem has come up several times rece
| |
897 m_pendingActionFlags |= LoadMediaResource; | |
898 } | |
899 | |
900 void HTMLMediaElement::continueResourceSelectionAlgorithm() | |
philipj_slow
2016/03/16 13:40:20
All of this method looks a bit strange, should it
Srirama
2016/03/16 14:25:40
Without these changes all the media/track test cas
Srirama
2016/03/16 14:35:23
loadtimer started by scheduleTextTrackResourceLoad
philipj_slow
2016/03/16 15:35:10
I think that really honorUserPreferencesForAutomat
Srirama
2016/03/16 17:41:17
Even i was going through it and wondering why it w
| |
901 { | |
902 m_pendingTask.clear(); | |
903 if (m_pendingActionFlags & LoadTextTrackResource) | |
904 honorUserPreferencesForAutomaticTextTrackSelection(); | |
905 | |
906 if (m_pendingActionFlags & LoadMediaResource) { | |
907 if (m_loadState == LoadingFromSourceElement) | |
908 loadNextSourceChild(); | |
909 else | |
910 loadInternal(); | |
911 } | |
912 | |
913 m_pendingActionFlags = 0; | |
839 } | 914 } |
840 | 915 |
841 void HTMLMediaElement::loadInternal() | 916 void HTMLMediaElement::loadInternal() |
842 { | 917 { |
843 // HTMLMediaElement::textTracksAreReady will need "... the text tracks whose mode was not in the | 918 // HTMLMediaElement::textTracksAreReady will need "... the text tracks whose mode was not in the |
844 // disabled state when the element's resource selection algorithm last start ed". | 919 // disabled state when the element's resource selection algorithm last start ed". |
845 m_textTracksWhenResourceSelectionBegan.clear(); | 920 m_textTracksWhenResourceSelectionBegan.clear(); |
846 if (m_textTracks) { | 921 if (m_textTracks) { |
847 for (unsigned i = 0; i < m_textTracks->length(); ++i) { | 922 for (unsigned i = 0; i < m_textTracks->length(); ++i) { |
848 TextTrack* track = m_textTracks->anonymousIndexedGetter(i); | 923 TextTrack* track = m_textTracks->anonymousIndexedGetter(i); |
(...skipping 2330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3179 | 3254 |
3180 // When connected to a MediaSource, e.g. setting MediaSource.duration will c ause a | 3255 // When connected to a MediaSource, e.g. setting MediaSource.duration will c ause a |
3181 // durationchange event to be fired. | 3256 // durationchange event to be fired. |
3182 if (m_mediaSource) | 3257 if (m_mediaSource) |
3183 return true; | 3258 return true; |
3184 | 3259 |
3185 // Wait for any pending events to be fired. | 3260 // Wait for any pending events to be fired. |
3186 if (m_asyncEventQueue->hasPendingEvents()) | 3261 if (m_asyncEventQueue->hasPendingEvents()) |
3187 return true; | 3262 return true; |
3188 | 3263 |
3264 // Wait for any pending microtask to be fired. | |
3265 if (m_pendingTask) | |
3266 return true; | |
3267 | |
3189 return false; | 3268 return false; |
3190 } | 3269 } |
3191 | 3270 |
3192 bool HTMLMediaElement::isFullscreen() const | 3271 bool HTMLMediaElement::isFullscreen() const |
3193 { | 3272 { |
3194 return Fullscreen::isActiveFullScreenElement(*this); | 3273 return Fullscreen::isActiveFullScreenElement(*this); |
3195 } | 3274 } |
3196 | 3275 |
3197 void HTMLMediaElement::enterFullscreen() | 3276 void HTMLMediaElement::enterFullscreen() |
3198 { | 3277 { |
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3804 { | 3883 { |
3805 visitor->trace(m_client); | 3884 visitor->trace(m_client); |
3806 } | 3885 } |
3807 | 3886 |
3808 DEFINE_TRACE(HTMLMediaElement::AudioSourceProviderImpl) | 3887 DEFINE_TRACE(HTMLMediaElement::AudioSourceProviderImpl) |
3809 { | 3888 { |
3810 visitor->trace(m_client); | 3889 visitor->trace(m_client); |
3811 } | 3890 } |
3812 | 3891 |
3813 } // namespace blink | 3892 } // namespace blink |
OLD | NEW |