| 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 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 , ActiveScriptWrappable(this) | 399 , ActiveScriptWrappable(this) |
| 400 , ActiveDOMObject(&document) | 400 , ActiveDOMObject(&document) |
| 401 , m_loadTimer(this, &HTMLMediaElement::loadTimerFired) | 401 , m_loadTimer(this, &HTMLMediaElement::loadTimerFired) |
| 402 , m_progressEventTimer(this, &HTMLMediaElement::progressEventTimerFired) | 402 , m_progressEventTimer(this, &HTMLMediaElement::progressEventTimerFired) |
| 403 , m_playbackProgressTimer(this, &HTMLMediaElement::playbackProgressTimerFire
d) | 403 , m_playbackProgressTimer(this, &HTMLMediaElement::playbackProgressTimerFire
d) |
| 404 , m_audioTracksTimer(this, &HTMLMediaElement::audioTracksTimerFired) | 404 , m_audioTracksTimer(this, &HTMLMediaElement::audioTracksTimerFired) |
| 405 , m_playedTimeRanges() | 405 , m_playedTimeRanges() |
| 406 , m_asyncEventQueue(GenericEventQueue::create(this)) | 406 , m_asyncEventQueue(GenericEventQueue::create(this)) |
| 407 , m_playbackRate(1.0f) | 407 , m_playbackRate(1.0f) |
| 408 , m_defaultPlaybackRate(1.0f) | 408 , m_defaultPlaybackRate(1.0f) |
| 409 , m_networkState(NETWORK_EMPTY) | 409 , m_networkState(kNetworkEmpty) |
| 410 , m_readyState(HAVE_NOTHING) | 410 , m_readyState(kHaveNothing) |
| 411 , m_readyStateMaximum(HAVE_NOTHING) | 411 , m_readyStateMaximum(kHaveNothing) |
| 412 , m_volume(1.0f) | 412 , m_volume(1.0f) |
| 413 , m_lastSeekTime(0) | 413 , m_lastSeekTime(0) |
| 414 , m_previousProgressTime(std::numeric_limits<double>::max()) | 414 , m_previousProgressTime(std::numeric_limits<double>::max()) |
| 415 , m_duration(std::numeric_limits<double>::quiet_NaN()) | 415 , m_duration(std::numeric_limits<double>::quiet_NaN()) |
| 416 , m_lastTimeUpdateEventWallTime(0) | 416 , m_lastTimeUpdateEventWallTime(0) |
| 417 , m_lastTimeUpdateEventMovieTime(0) | 417 , m_lastTimeUpdateEventMovieTime(0) |
| 418 , m_defaultPlaybackStartPosition(0) | 418 , m_defaultPlaybackStartPosition(0) |
| 419 , m_loadState(WaitingForSource) | 419 , m_loadState(WaitingForSource) |
| 420 , m_deferredLoadState(NotDeferred) | 420 , m_deferredLoadState(NotDeferred) |
| 421 , m_deferredLoadTimer(this, &HTMLMediaElement::deferredLoadTimerFired) | 421 , m_deferredLoadTimer(this, &HTMLMediaElement::deferredLoadTimerFired) |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 return new LayoutMedia(this); | 592 return new LayoutMedia(this); |
| 593 } | 593 } |
| 594 | 594 |
| 595 Node::InsertionNotificationRequest HTMLMediaElement::insertedInto(ContainerNode*
insertionPoint) | 595 Node::InsertionNotificationRequest HTMLMediaElement::insertedInto(ContainerNode*
insertionPoint) |
| 596 { | 596 { |
| 597 BLINK_MEDIA_LOG << "insertedInto(" << (void*)this << ", " << insertionPoint
<< ")"; | 597 BLINK_MEDIA_LOG << "insertedInto(" << (void*)this << ", " << insertionPoint
<< ")"; |
| 598 | 598 |
| 599 HTMLElement::insertedInto(insertionPoint); | 599 HTMLElement::insertedInto(insertionPoint); |
| 600 if (insertionPoint->isConnected()) { | 600 if (insertionPoint->isConnected()) { |
| 601 UseCounter::count(document(), UseCounter::HTMLMediaElementInDocument); | 601 UseCounter::count(document(), UseCounter::HTMLMediaElementInDocument); |
| 602 if ((!getAttribute(srcAttr).isEmpty() || m_srcObject) && m_networkState
== NETWORK_EMPTY) { | 602 if ((!getAttribute(srcAttr).isEmpty() || m_srcObject) && m_networkState
== kNetworkEmpty) { |
| 603 m_ignorePreloadNone = false; | 603 m_ignorePreloadNone = false; |
| 604 invokeLoadAlgorithm(); | 604 invokeLoadAlgorithm(); |
| 605 } | 605 } |
| 606 } | 606 } |
| 607 | 607 |
| 608 return InsertionShouldCallDidNotifySubtreeInsertions; | 608 return InsertionShouldCallDidNotifySubtreeInsertions; |
| 609 } | 609 } |
| 610 | 610 |
| 611 void HTMLMediaElement::didNotifySubtreeInsertionsToDocument() | 611 void HTMLMediaElement::didNotifySubtreeInsertionsToDocument() |
| 612 { | 612 { |
| 613 configureMediaControls(); | 613 configureMediaControls(); |
| 614 } | 614 } |
| 615 | 615 |
| 616 void HTMLMediaElement::removedFrom(ContainerNode* insertionPoint) | 616 void HTMLMediaElement::removedFrom(ContainerNode* insertionPoint) |
| 617 { | 617 { |
| 618 BLINK_MEDIA_LOG << "removedFrom(" << (void*)this << ", " << insertionPoint <
< ")"; | 618 BLINK_MEDIA_LOG << "removedFrom(" << (void*)this << ", " << insertionPoint <
< ")"; |
| 619 | 619 |
| 620 HTMLElement::removedFrom(insertionPoint); | 620 HTMLElement::removedFrom(insertionPoint); |
| 621 if (insertionPoint->inActiveDocument()) { | 621 if (insertionPoint->inActiveDocument()) { |
| 622 configureMediaControls(); | 622 configureMediaControls(); |
| 623 if (m_networkState > NETWORK_EMPTY) | 623 if (m_networkState > kNetworkEmpty) |
| 624 pauseInternal(); | 624 pauseInternal(); |
| 625 } | 625 } |
| 626 } | 626 } |
| 627 | 627 |
| 628 void HTMLMediaElement::attachLayoutTree(const AttachContext& context) | 628 void HTMLMediaElement::attachLayoutTree(const AttachContext& context) |
| 629 { | 629 { |
| 630 HTMLElement::attachLayoutTree(context); | 630 HTMLElement::attachLayoutTree(context); |
| 631 | 631 |
| 632 if (layoutObject()) | 632 if (layoutObject()) |
| 633 layoutObject()->updateFromElement(); | 633 layoutObject()->updateFromElement(); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 m_currentSourceNode = nullptr; | 762 m_currentSourceNode = nullptr; |
| 763 | 763 |
| 764 // 2 - If there are any tasks from the media element's media element event t
ask source in | 764 // 2 - If there are any tasks from the media element's media element event t
ask source in |
| 765 // one of the task queues, then remove those tasks. | 765 // one of the task queues, then remove those tasks. |
| 766 cancelPendingEventsAndCallbacks(); | 766 cancelPendingEventsAndCallbacks(); |
| 767 | 767 |
| 768 rejectPlayPromises(AbortError, "The play() request was interrupted by a new
load request."); | 768 rejectPlayPromises(AbortError, "The play() request was interrupted by a new
load request."); |
| 769 | 769 |
| 770 // 3 - If the media element's networkState is set to NETWORK_LOADING or NETW
ORK_IDLE, queue | 770 // 3 - If the media element's networkState is set to NETWORK_LOADING or NETW
ORK_IDLE, queue |
| 771 // a task to fire a simple event named abort at the media element. | 771 // a task to fire a simple event named abort at the media element. |
| 772 if (m_networkState == NETWORK_LOADING || m_networkState == NETWORK_IDLE) | 772 if (m_networkState == kNetworkLoading || m_networkState == kNetworkIdle) |
| 773 scheduleEvent(EventTypeNames::abort); | 773 scheduleEvent(EventTypeNames::abort); |
| 774 | 774 |
| 775 resetMediaPlayerAndMediaSource(); | 775 resetMediaPlayerAndMediaSource(); |
| 776 | 776 |
| 777 // 4 - If the media element's networkState is not set to NETWORK_EMPTY, then
run these substeps | 777 // 4 - If the media element's networkState is not set to NETWORK_EMPTY, then
run these substeps |
| 778 if (m_networkState != NETWORK_EMPTY) { | 778 if (m_networkState != kNetworkEmpty) { |
| 779 // 4.1 - Queue a task to fire a simple event named emptied at the media
element. | 779 // 4.1 - Queue a task to fire a simple event named emptied at the media
element. |
| 780 scheduleEvent(EventTypeNames::emptied); | 780 scheduleEvent(EventTypeNames::emptied); |
| 781 | 781 |
| 782 // 4.2 - If a fetching process is in progress for the media element, the
user agent should stop it. | 782 // 4.2 - If a fetching process is in progress for the media element, the
user agent should stop it. |
| 783 setNetworkState(NETWORK_EMPTY); | 783 setNetworkState(kNetworkEmpty); |
| 784 | 784 |
| 785 // 4.3 - Forget the media element's media-resource-specific tracks. | 785 // 4.3 - Forget the media element's media-resource-specific tracks. |
| 786 forgetResourceSpecificTracks(); | 786 forgetResourceSpecificTracks(); |
| 787 | 787 |
| 788 // 4.4 - If readyState is not set to HAVE_NOTHING, then set it to that s
tate. | 788 // 4.4 - If readyState is not set to HAVE_NOTHING, then set it to that s
tate. |
| 789 m_readyState = HAVE_NOTHING; | 789 m_readyState = kHaveNothing; |
| 790 m_readyStateMaximum = HAVE_NOTHING; | 790 m_readyStateMaximum = kHaveNothing; |
| 791 | 791 |
| 792 // 4.5 - If the paused attribute is false, then set it to true. | 792 // 4.5 - If the paused attribute is false, then set it to true. |
| 793 m_paused = true; | 793 m_paused = true; |
| 794 | 794 |
| 795 // 4.6 - If seeking is true, set it to false. | 795 // 4.6 - If seeking is true, set it to false. |
| 796 m_seeking = false; | 796 m_seeking = false; |
| 797 | 797 |
| 798 // 4.7 - Set the current playback position to 0. | 798 // 4.7 - Set the current playback position to 0. |
| 799 // Set the official playback position to 0. | 799 // Set the official playback position to 0. |
| 800 // If this changed the official playback position, then queue a ta
sk to fire a simple event named timeupdate at the media element. | 800 // If this changed the official playback position, then queue a ta
sk to fire a simple event named timeupdate at the media element. |
| 801 // FIXME: Add support for firing this event. | 801 // FIXME: Add support for firing this event. |
| 802 | 802 |
| 803 // 4.8 - Set the initial playback position to 0. | 803 // 4.8 - Set the initial playback position to 0. |
| 804 // FIXME: Make this less subtle. The position only becomes 0 because the
ready state is HAVE_NOTHING. | 804 // FIXME: Make this less subtle. The position only becomes 0 because the
ready state is kHaveNothing. |
| 805 invalidateCachedTime(); | 805 invalidateCachedTime(); |
| 806 | 806 |
| 807 // 4.9 - Set the timeline offset to Not-a-Number (NaN). | 807 // 4.9 - Set the timeline offset to Not-a-Number (NaN). |
| 808 // 4.10 - Update the duration attribute to Not-a-Number (NaN). | 808 // 4.10 - Update the duration attribute to Not-a-Number (NaN). |
| 809 | 809 |
| 810 cueTimeline().updateActiveCues(0); | 810 cueTimeline().updateActiveCues(0); |
| 811 } else if (!m_paused) { | 811 } else if (!m_paused) { |
| 812 // TODO(foolip): There is a proposal to always reset the paused state | 812 // TODO(foolip): There is a proposal to always reset the paused state |
| 813 // in the media element load algorithm, to avoid a bogus play() promise | 813 // in the media element load algorithm, to avoid a bogus play() promise |
| 814 // rejection: https://github.com/whatwg/html/issues/869 | 814 // rejection: https://github.com/whatwg/html/issues/869 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 828 invokeResourceSelectionAlgorithm(); | 828 invokeResourceSelectionAlgorithm(); |
| 829 | 829 |
| 830 // 8 - Note: Playback of any previously playing media resource for this elem
ent stops. | 830 // 8 - Note: Playback of any previously playing media resource for this elem
ent stops. |
| 831 } | 831 } |
| 832 | 832 |
| 833 void HTMLMediaElement::invokeResourceSelectionAlgorithm() | 833 void HTMLMediaElement::invokeResourceSelectionAlgorithm() |
| 834 { | 834 { |
| 835 BLINK_MEDIA_LOG << "invokeResourceSelectionAlgorithm(" << (void*)this << ")"
; | 835 BLINK_MEDIA_LOG << "invokeResourceSelectionAlgorithm(" << (void*)this << ")"
; |
| 836 // The resource selection algorithm | 836 // The resource selection algorithm |
| 837 // 1 - Set the networkState to NETWORK_NO_SOURCE | 837 // 1 - Set the networkState to NETWORK_NO_SOURCE |
| 838 setNetworkState(NETWORK_NO_SOURCE); | 838 setNetworkState(kNetworkNoSource); |
| 839 | 839 |
| 840 // 2 - Set the element's show poster flag to true | 840 // 2 - Set the element's show poster flag to true |
| 841 // TODO(srirama.m): Introduce show poster flag and update it as per spec | 841 // TODO(srirama.m): Introduce show poster flag and update it as per spec |
| 842 | 842 |
| 843 m_playedTimeRanges = TimeRanges::create(); | 843 m_playedTimeRanges = TimeRanges::create(); |
| 844 | 844 |
| 845 // FIXME: Investigate whether these can be moved into m_networkState != NETW
ORK_EMPTY block above | 845 // FIXME: Investigate whether these can be moved into m_networkState != kNet
workEmpty block above |
| 846 // so they are closer to the relevant spec steps. | 846 // so they are closer to the relevant spec steps. |
| 847 m_lastSeekTime = 0; | 847 m_lastSeekTime = 0; |
| 848 m_duration = std::numeric_limits<double>::quiet_NaN(); | 848 m_duration = std::numeric_limits<double>::quiet_NaN(); |
| 849 | 849 |
| 850 // 3 - Set the media element's delaying-the-load-event flag to true (this de
lays the load event) | 850 // 3 - Set the media element's delaying-the-load-event flag to true (this de
lays the load event) |
| 851 setShouldDelayLoadEvent(true); | 851 setShouldDelayLoadEvent(true); |
| 852 if (mediaControls()) | 852 if (mediaControls()) |
| 853 mediaControls()->reset(); | 853 mediaControls()->reset(); |
| 854 | 854 |
| 855 // 4 - Await a stable state, allowing the task that invoked this algorithm t
o continue | 855 // 4 - Await a stable state, allowing the task that invoked this algorithm t
o continue |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 // Otherwise, if the media element does not have an assigned media | 893 // Otherwise, if the media element does not have an assigned media |
| 894 // provider object and does not have a src attribute, but does have a | 894 // provider object and does not have a src attribute, but does have a |
| 895 // source element child, then let mode be children and let candidate be | 895 // source element child, then let mode be children and let candidate be |
| 896 // the first such source element child in tree order. | 896 // the first such source element child in tree order. |
| 897 mode = Children; | 897 mode = Children; |
| 898 m_nextChildNodeToConsider = element; | 898 m_nextChildNodeToConsider = element; |
| 899 m_currentSourceNode = nullptr; | 899 m_currentSourceNode = nullptr; |
| 900 } else { | 900 } else { |
| 901 // Otherwise the media element has no assigned media provider object and | 901 // Otherwise the media element has no assigned media provider object and |
| 902 // has neither a src attribute nor a source element child: set the | 902 // has neither a src attribute nor a source element child: set the |
| 903 // networkState to NETWORK_EMPTY, and abort these steps; the synchronous | 903 // networkState to kNetworkEmpty, and abort these steps; the synchronous |
| 904 // section ends. | 904 // section ends. |
| 905 m_loadState = WaitingForSource; | 905 m_loadState = WaitingForSource; |
| 906 setShouldDelayLoadEvent(false); | 906 setShouldDelayLoadEvent(false); |
| 907 setNetworkState(NETWORK_EMPTY); | 907 setNetworkState(kNetworkEmpty); |
| 908 updateDisplayState(); | 908 updateDisplayState(); |
| 909 | 909 |
| 910 BLINK_MEDIA_LOG << "selectMediaResource(" << (void*)this << "), nothing
to load"; | 910 BLINK_MEDIA_LOG << "selectMediaResource(" << (void*)this << "), nothing
to load"; |
| 911 return; | 911 return; |
| 912 } | 912 } |
| 913 | 913 |
| 914 // 7 - Set the media element's networkState to NETWORK_LOADING. | 914 // 7 - Set the media element's networkState to NETWORK_LOADING. |
| 915 setNetworkState(NETWORK_LOADING); | 915 setNetworkState(kNetworkLoading); |
| 916 | 916 |
| 917 // 8 - Queue a task to fire a simple event named loadstart at the media elem
ent. | 917 // 8 - Queue a task to fire a simple event named loadstart at the media elem
ent. |
| 918 scheduleEvent(EventTypeNames::loadstart); | 918 scheduleEvent(EventTypeNames::loadstart); |
| 919 | 919 |
| 920 // 9 - Run the appropriate steps... | 920 // 9 - Run the appropriate steps... |
| 921 switch (mode) { | 921 switch (mode) { |
| 922 case Object: | 922 case Object: |
| 923 loadSourceFromObject(); | 923 loadSourceFromObject(); |
| 924 BLINK_MEDIA_LOG << "selectMediaResource(" << (void*)this << ", using 'sr
cObject' attribute"; | 924 BLINK_MEDIA_LOG << "selectMediaResource(" << (void*)this << ", using 'sr
cObject' attribute"; |
| 925 break; | 925 break; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 995 BLINK_MEDIA_LOG << "loadResource(" << (void*)this << ", " << urlForLoggi
ngMedia(url) << ", " << contentType.raw() << ")"; | 995 BLINK_MEDIA_LOG << "loadResource(" << (void*)this << ", " << urlForLoggi
ngMedia(url) << ", " << contentType.raw() << ")"; |
| 996 } | 996 } |
| 997 | 997 |
| 998 LocalFrame* frame = document().frame(); | 998 LocalFrame* frame = document().frame(); |
| 999 if (!frame) { | 999 if (!frame) { |
| 1000 mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError); | 1000 mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError); |
| 1001 return; | 1001 return; |
| 1002 } | 1002 } |
| 1003 | 1003 |
| 1004 // The resource fetch algorithm | 1004 // The resource fetch algorithm |
| 1005 setNetworkState(NETWORK_LOADING); | 1005 setNetworkState(kNetworkLoading); |
| 1006 | 1006 |
| 1007 m_autoplayHelper->loadingStarted(); | 1007 m_autoplayHelper->loadingStarted(); |
| 1008 | 1008 |
| 1009 // Set m_currentSrc *before* changing to the cache url, the fact that we are
loading from the app | 1009 // Set m_currentSrc *before* changing to the cache url, the fact that we are
loading from the app |
| 1010 // cache is an internal detail not exposed through the media element API. | 1010 // cache is an internal detail not exposed through the media element API. |
| 1011 m_currentSrc = url; | 1011 m_currentSrc = url; |
| 1012 | 1012 |
| 1013 if (m_audioSourceNode) | 1013 if (m_audioSourceNode) |
| 1014 m_audioSourceNode->onCurrentSrcChanged(m_currentSrc); | 1014 m_audioSourceNode->onCurrentSrcChanged(m_currentSrc); |
| 1015 | 1015 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1168 | 1168 |
| 1169 // resource fetch algorithm step 3 - continued from deferLoad(). | 1169 // resource fetch algorithm step 3 - continued from deferLoad(). |
| 1170 | 1170 |
| 1171 // 5. Wait for an implementation-defined event (e.g. the user requesting tha
t the media element begin playback). | 1171 // 5. Wait for an implementation-defined event (e.g. the user requesting tha
t the media element begin playback). |
| 1172 // This is assumed to be whatever 'event' ended up calling this method. | 1172 // This is assumed to be whatever 'event' ended up calling this method. |
| 1173 cancelDeferredLoad(); | 1173 cancelDeferredLoad(); |
| 1174 // 6. Set the element's delaying-the-load-event flag back to true (this | 1174 // 6. Set the element's delaying-the-load-event flag back to true (this |
| 1175 // delays the load event again, in case it hasn't been fired yet). | 1175 // delays the load event again, in case it hasn't been fired yet). |
| 1176 setShouldDelayLoadEvent(true); | 1176 setShouldDelayLoadEvent(true); |
| 1177 // 7. Set the networkState to NETWORK_LOADING. | 1177 // 7. Set the networkState to NETWORK_LOADING. |
| 1178 setNetworkState(NETWORK_LOADING); | 1178 setNetworkState(kNetworkLoading); |
| 1179 | 1179 |
| 1180 startProgressEventTimer(); | 1180 startProgressEventTimer(); |
| 1181 | 1181 |
| 1182 startPlayerLoad(); | 1182 startPlayerLoad(); |
| 1183 } | 1183 } |
| 1184 | 1184 |
| 1185 void HTMLMediaElement::startDeferredLoad() | 1185 void HTMLMediaElement::startDeferredLoad() |
| 1186 { | 1186 { |
| 1187 if (m_deferredLoadState == WaitingForTrigger) { | 1187 if (m_deferredLoadState == WaitingForTrigger) { |
| 1188 executeDeferredLoad(); | 1188 executeDeferredLoad(); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1310 } | 1310 } |
| 1311 | 1311 |
| 1312 void HTMLMediaElement::waitForSourceChange() | 1312 void HTMLMediaElement::waitForSourceChange() |
| 1313 { | 1313 { |
| 1314 BLINK_MEDIA_LOG << "waitForSourceChange(" << (void*)this << ")"; | 1314 BLINK_MEDIA_LOG << "waitForSourceChange(" << (void*)this << ")"; |
| 1315 | 1315 |
| 1316 stopPeriodicTimers(); | 1316 stopPeriodicTimers(); |
| 1317 m_loadState = WaitingForSource; | 1317 m_loadState = WaitingForSource; |
| 1318 | 1318 |
| 1319 // 6.17 - Waiting: Set the element's networkState attribute to the NETWORK_N
O_SOURCE value | 1319 // 6.17 - Waiting: Set the element's networkState attribute to the NETWORK_N
O_SOURCE value |
| 1320 setNetworkState(NETWORK_NO_SOURCE); | 1320 setNetworkState(kNetworkNoSource); |
| 1321 | 1321 |
| 1322 // 6.18 - Set the element's delaying-the-load-event flag to false. This stop
s delaying the load event. | 1322 // 6.18 - Set the element's delaying-the-load-event flag to false. This stop
s delaying the load event. |
| 1323 setShouldDelayLoadEvent(false); | 1323 setShouldDelayLoadEvent(false); |
| 1324 | 1324 |
| 1325 updateDisplayState(); | 1325 updateDisplayState(); |
| 1326 | 1326 |
| 1327 if (layoutObject()) | 1327 if (layoutObject()) |
| 1328 layoutObject()->updateFromElement(); | 1328 layoutObject()->updateFromElement(); |
| 1329 } | 1329 } |
| 1330 | 1330 |
| 1331 void HTMLMediaElement::noneSupported() | 1331 void HTMLMediaElement::noneSupported() |
| 1332 { | 1332 { |
| 1333 BLINK_MEDIA_LOG << "noneSupported(" << (void*)this << ")"; | 1333 BLINK_MEDIA_LOG << "noneSupported(" << (void*)this << ")"; |
| 1334 | 1334 |
| 1335 stopPeriodicTimers(); | 1335 stopPeriodicTimers(); |
| 1336 m_loadState = WaitingForSource; | 1336 m_loadState = WaitingForSource; |
| 1337 m_currentSourceNode = nullptr; | 1337 m_currentSourceNode = nullptr; |
| 1338 | 1338 |
| 1339 // 4.8.13.5 | 1339 // 4.8.13.5 |
| 1340 // The dedicated media source failure steps are the following steps: | 1340 // The dedicated media source failure steps are the following steps: |
| 1341 | 1341 |
| 1342 // 1 - Set the error attribute to a new MediaError object whose code attribu
te is set to | 1342 // 1 - Set the error attribute to a new MediaError object whose code attribu
te is set to |
| 1343 // MEDIA_ERR_SRC_NOT_SUPPORTED. | 1343 // MEDIA_ERR_SRC_NOT_SUPPORTED. |
| 1344 m_error = MediaError::create(MediaError::MEDIA_ERR_SRC_NOT_SUPPORTED); | 1344 m_error = MediaError::create(MediaError::kMediaErrSrcNotSupported); |
| 1345 | 1345 |
| 1346 // 2 - Forget the media element's media-resource-specific text tracks. | 1346 // 2 - Forget the media element's media-resource-specific text tracks. |
| 1347 forgetResourceSpecificTracks(); | 1347 forgetResourceSpecificTracks(); |
| 1348 | 1348 |
| 1349 // 3 - Set the element's networkState attribute to the NETWORK_NO_SOURCE val
ue. | 1349 // 3 - Set the element's networkState attribute to the NETWORK_NO_SOURCE val
ue. |
| 1350 setNetworkState(NETWORK_NO_SOURCE); | 1350 setNetworkState(kNetworkNoSource); |
| 1351 | 1351 |
| 1352 // 4 - Set the element's show poster flag to true. | 1352 // 4 - Set the element's show poster flag to true. |
| 1353 updateDisplayState(); | 1353 updateDisplayState(); |
| 1354 | 1354 |
| 1355 // 5 - Fire a simple event named error at the media element. | 1355 // 5 - Fire a simple event named error at the media element. |
| 1356 scheduleEvent(EventTypeNames::error); | 1356 scheduleEvent(EventTypeNames::error); |
| 1357 | 1357 |
| 1358 // 6 - Reject pending play promises with NotSupportedError. | 1358 // 6 - Reject pending play promises with NotSupportedError. |
| 1359 scheduleRejectPlayPromises(NotSupportedError); | 1359 scheduleRejectPlayPromises(NotSupportedError); |
| 1360 | 1360 |
| 1361 closeMediaSource(); | 1361 closeMediaSource(); |
| 1362 | 1362 |
| 1363 // 7 - Set the element's delaying-the-load-event flag to false. This stops d
elaying the load event. | 1363 // 7 - Set the element's delaying-the-load-event flag to false. This stops d
elaying the load event. |
| 1364 setShouldDelayLoadEvent(false); | 1364 setShouldDelayLoadEvent(false); |
| 1365 | 1365 |
| 1366 if (layoutObject()) | 1366 if (layoutObject()) |
| 1367 layoutObject()->updateFromElement(); | 1367 layoutObject()->updateFromElement(); |
| 1368 } | 1368 } |
| 1369 | 1369 |
| 1370 void HTMLMediaElement::mediaEngineError(MediaError* err) | 1370 void HTMLMediaElement::mediaEngineError(MediaError* err) |
| 1371 { | 1371 { |
| 1372 DCHECK_GE(m_readyState, HAVE_METADATA); | 1372 DCHECK_GE(m_readyState, kHaveMetadata); |
| 1373 BLINK_MEDIA_LOG << "mediaEngineError(" << (void*)this << ", " << static_cast
<int>(err->code()) << ")"; | 1373 BLINK_MEDIA_LOG << "mediaEngineError(" << (void*)this << ", " << static_cast
<int>(err->code()) << ")"; |
| 1374 | 1374 |
| 1375 // 1 - The user agent should cancel the fetching process. | 1375 // 1 - The user agent should cancel the fetching process. |
| 1376 stopPeriodicTimers(); | 1376 stopPeriodicTimers(); |
| 1377 m_loadState = WaitingForSource; | 1377 m_loadState = WaitingForSource; |
| 1378 | 1378 |
| 1379 // 2 - Set the error attribute to a new MediaError object whose code attribu
te is | 1379 // 2 - Set the error attribute to a new MediaError object whose code attribu
te is |
| 1380 // set to MEDIA_ERR_NETWORK/MEDIA_ERR_DECODE. | 1380 // set to MEDIA_ERR_NETWORK/MEDIA_ERR_DECODE. |
| 1381 m_error = err; | 1381 m_error = err; |
| 1382 | 1382 |
| 1383 // 3 - Queue a task to fire a simple event named error at the media element. | 1383 // 3 - Queue a task to fire a simple event named error at the media element. |
| 1384 scheduleEvent(EventTypeNames::error); | 1384 scheduleEvent(EventTypeNames::error); |
| 1385 | 1385 |
| 1386 // 4 - Set the element's networkState attribute to the NETWORK_IDLE value. | 1386 // 4 - Set the element's networkState attribute to the NETWORK_IDLE value. |
| 1387 setNetworkState(NETWORK_IDLE); | 1387 setNetworkState(kNetworkIdle); |
| 1388 | 1388 |
| 1389 // 5 - Set the element's delaying-the-load-event flag to false. This stops d
elaying the load event. | 1389 // 5 - Set the element's delaying-the-load-event flag to false. This stops d
elaying the load event. |
| 1390 setShouldDelayLoadEvent(false); | 1390 setShouldDelayLoadEvent(false); |
| 1391 | 1391 |
| 1392 // 6 - Abort the overall resource selection algorithm. | 1392 // 6 - Abort the overall resource selection algorithm. |
| 1393 m_currentSourceNode = nullptr; | 1393 m_currentSourceNode = nullptr; |
| 1394 } | 1394 } |
| 1395 | 1395 |
| 1396 void HTMLMediaElement::cancelPendingEventsAndCallbacks() | 1396 void HTMLMediaElement::cancelPendingEventsAndCallbacks() |
| 1397 { | 1397 { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1411 { | 1411 { |
| 1412 setNetworkState(webMediaPlayer()->getNetworkState()); | 1412 setNetworkState(webMediaPlayer()->getNetworkState()); |
| 1413 } | 1413 } |
| 1414 | 1414 |
| 1415 void HTMLMediaElement::mediaLoadingFailed(WebMediaPlayer::NetworkState error) | 1415 void HTMLMediaElement::mediaLoadingFailed(WebMediaPlayer::NetworkState error) |
| 1416 { | 1416 { |
| 1417 stopPeriodicTimers(); | 1417 stopPeriodicTimers(); |
| 1418 | 1418 |
| 1419 // If we failed while trying to load a <source> element, the movie was never
parsed, and there are more | 1419 // If we failed while trying to load a <source> element, the movie was never
parsed, and there are more |
| 1420 // <source> children, schedule the next one | 1420 // <source> children, schedule the next one |
| 1421 if (m_readyState < HAVE_METADATA && m_loadState == LoadingFromSourceElement)
{ | 1421 if (m_readyState < kHaveMetadata && m_loadState == LoadingFromSourceElement)
{ |
| 1422 | 1422 |
| 1423 // resource selection algorithm | 1423 // resource selection algorithm |
| 1424 // Step 9.Otherwise.9 - Failed with elements: Queue a task, using the DO
M manipulation task source, to fire a simple event named error at the candidate
element. | 1424 // Step 9.Otherwise.9 - Failed with elements: Queue a task, using the DO
M manipulation task source, to fire a simple event named error at the candidate
element. |
| 1425 if (m_currentSourceNode) | 1425 if (m_currentSourceNode) |
| 1426 m_currentSourceNode->scheduleErrorEvent(); | 1426 m_currentSourceNode->scheduleErrorEvent(); |
| 1427 else | 1427 else |
| 1428 BLINK_MEDIA_LOG << "setNetworkState(" << (void*)this << ") - error e
vent not sent, <source> was removed"; | 1428 BLINK_MEDIA_LOG << "setNetworkState(" << (void*)this << ") - error e
vent not sent, <source> was removed"; |
| 1429 | 1429 |
| 1430 // 9.Otherwise.10 - Asynchronously await a stable state. The synchronous
section consists of all the remaining steps of this algorithm until the algorit
hm says the synchronous section has ended. | 1430 // 9.Otherwise.10 - Asynchronously await a stable state. The synchronous
section consists of all the remaining steps of this algorithm until the algorit
hm says the synchronous section has ended. |
| 1431 | 1431 |
| 1432 // 9.Otherwise.11 - Forget the media element's media-resource-specific t
racks. | 1432 // 9.Otherwise.11 - Forget the media element's media-resource-specific t
racks. |
| 1433 forgetResourceSpecificTracks(); | 1433 forgetResourceSpecificTracks(); |
| 1434 | 1434 |
| 1435 if (havePotentialSourceChild()) { | 1435 if (havePotentialSourceChild()) { |
| 1436 BLINK_MEDIA_LOG << "setNetworkState(" << (void*)this << ") - schedul
ing next <source>"; | 1436 BLINK_MEDIA_LOG << "setNetworkState(" << (void*)this << ") - schedul
ing next <source>"; |
| 1437 scheduleNextSourceChild(); | 1437 scheduleNextSourceChild(); |
| 1438 } else { | 1438 } else { |
| 1439 BLINK_MEDIA_LOG << "setNetworkState(" << (void*)this << ") - no more
<source> elements, waiting"; | 1439 BLINK_MEDIA_LOG << "setNetworkState(" << (void*)this << ") - no more
<source> elements, waiting"; |
| 1440 waitForSourceChange(); | 1440 waitForSourceChange(); |
| 1441 } | 1441 } |
| 1442 | 1442 |
| 1443 return; | 1443 return; |
| 1444 } | 1444 } |
| 1445 | 1445 |
| 1446 if (error == WebMediaPlayer::NetworkStateNetworkError && m_readyState >= HAV
E_METADATA) | 1446 if (error == WebMediaPlayer::NetworkStateNetworkError && m_readyState >= kHa
veMetadata) |
| 1447 mediaEngineError(MediaError::create(MediaError::MEDIA_ERR_NETWORK)); | 1447 mediaEngineError(MediaError::create(MediaError::kMediaErrNetwork)); |
| 1448 else if (error == WebMediaPlayer::NetworkStateDecodeError) | 1448 else if (error == WebMediaPlayer::NetworkStateDecodeError) |
| 1449 mediaEngineError(MediaError::create(MediaError::MEDIA_ERR_DECODE)); | 1449 mediaEngineError(MediaError::create(MediaError::kMediaErrDecode)); |
| 1450 else if ((error == WebMediaPlayer::NetworkStateFormatError | 1450 else if ((error == WebMediaPlayer::NetworkStateFormatError |
| 1451 || error == WebMediaPlayer::NetworkStateNetworkError) | 1451 || error == WebMediaPlayer::NetworkStateNetworkError) |
| 1452 && m_loadState == LoadingFromSrcAttr) | 1452 && m_loadState == LoadingFromSrcAttr) |
| 1453 noneSupported(); | 1453 noneSupported(); |
| 1454 | 1454 |
| 1455 updateDisplayState(); | 1455 updateDisplayState(); |
| 1456 if (mediaControls()) | 1456 if (mediaControls()) |
| 1457 mediaControls()->reset(); | 1457 mediaControls()->reset(); |
| 1458 } | 1458 } |
| 1459 | 1459 |
| 1460 void HTMLMediaElement::setNetworkState(WebMediaPlayer::NetworkState state) | 1460 void HTMLMediaElement::setNetworkState(WebMediaPlayer::NetworkState state) |
| 1461 { | 1461 { |
| 1462 BLINK_MEDIA_LOG << "setNetworkState(" << (void*)this << ", " << static_cast<
int>(state) << ") - current state is " << static_cast<int>(m_networkState); | 1462 BLINK_MEDIA_LOG << "setNetworkState(" << (void*)this << ", " << static_cast<
int>(state) << ") - current state is " << static_cast<int>(m_networkState); |
| 1463 | 1463 |
| 1464 if (state == WebMediaPlayer::NetworkStateEmpty) { | 1464 if (state == WebMediaPlayer::NetworkStateEmpty) { |
| 1465 // Just update the cached state and leave, we can't do anything. | 1465 // Just update the cached state and leave, we can't do anything. |
| 1466 setNetworkState(NETWORK_EMPTY); | 1466 setNetworkState(kNetworkEmpty); |
| 1467 return; | 1467 return; |
| 1468 } | 1468 } |
| 1469 | 1469 |
| 1470 if (state == WebMediaPlayer::NetworkStateFormatError | 1470 if (state == WebMediaPlayer::NetworkStateFormatError |
| 1471 || state == WebMediaPlayer::NetworkStateNetworkError | 1471 || state == WebMediaPlayer::NetworkStateNetworkError |
| 1472 || state == WebMediaPlayer::NetworkStateDecodeError) { | 1472 || state == WebMediaPlayer::NetworkStateDecodeError) { |
| 1473 mediaLoadingFailed(state); | 1473 mediaLoadingFailed(state); |
| 1474 return; | 1474 return; |
| 1475 } | 1475 } |
| 1476 | 1476 |
| 1477 if (state == WebMediaPlayer::NetworkStateIdle) { | 1477 if (state == WebMediaPlayer::NetworkStateIdle) { |
| 1478 if (m_networkState > NETWORK_IDLE) { | 1478 if (m_networkState > kNetworkIdle) { |
| 1479 changeNetworkStateFromLoadingToIdle(); | 1479 changeNetworkStateFromLoadingToIdle(); |
| 1480 setShouldDelayLoadEvent(false); | 1480 setShouldDelayLoadEvent(false); |
| 1481 } else { | 1481 } else { |
| 1482 setNetworkState(NETWORK_IDLE); | 1482 setNetworkState(kNetworkIdle); |
| 1483 } | 1483 } |
| 1484 } | 1484 } |
| 1485 | 1485 |
| 1486 if (state == WebMediaPlayer::NetworkStateLoading) { | 1486 if (state == WebMediaPlayer::NetworkStateLoading) { |
| 1487 if (m_networkState < NETWORK_LOADING || m_networkState == NETWORK_NO_SOU
RCE) | 1487 if (m_networkState < kNetworkLoading || m_networkState == kNetworkNoSour
ce) |
| 1488 startProgressEventTimer(); | 1488 startProgressEventTimer(); |
| 1489 setNetworkState(NETWORK_LOADING); | 1489 setNetworkState(kNetworkLoading); |
| 1490 } | 1490 } |
| 1491 | 1491 |
| 1492 if (state == WebMediaPlayer::NetworkStateLoaded) { | 1492 if (state == WebMediaPlayer::NetworkStateLoaded) { |
| 1493 if (m_networkState != NETWORK_IDLE) | 1493 if (m_networkState != kNetworkIdle) |
| 1494 changeNetworkStateFromLoadingToIdle(); | 1494 changeNetworkStateFromLoadingToIdle(); |
| 1495 } | 1495 } |
| 1496 } | 1496 } |
| 1497 | 1497 |
| 1498 void HTMLMediaElement::changeNetworkStateFromLoadingToIdle() | 1498 void HTMLMediaElement::changeNetworkStateFromLoadingToIdle() |
| 1499 { | 1499 { |
| 1500 m_progressEventTimer.stop(); | 1500 m_progressEventTimer.stop(); |
| 1501 | 1501 |
| 1502 // Schedule one last progress event so we guarantee that at least one is fir
ed | 1502 // Schedule one last progress event so we guarantee that at least one is fir
ed |
| 1503 // for files that load very quickly. | 1503 // for files that load very quickly. |
| 1504 if (webMediaPlayer() && webMediaPlayer()->didLoadingProgress()) | 1504 if (webMediaPlayer() && webMediaPlayer()->didLoadingProgress()) |
| 1505 scheduleEvent(EventTypeNames::progress); | 1505 scheduleEvent(EventTypeNames::progress); |
| 1506 scheduleEvent(EventTypeNames::suspend); | 1506 scheduleEvent(EventTypeNames::suspend); |
| 1507 setNetworkState(NETWORK_IDLE); | 1507 setNetworkState(kNetworkIdle); |
| 1508 } | 1508 } |
| 1509 | 1509 |
| 1510 void HTMLMediaElement::readyStateChanged() | 1510 void HTMLMediaElement::readyStateChanged() |
| 1511 { | 1511 { |
| 1512 setReadyState(static_cast<ReadyState>(webMediaPlayer()->getReadyState())); | 1512 setReadyState(static_cast<ReadyState>(webMediaPlayer()->getReadyState())); |
| 1513 } | 1513 } |
| 1514 | 1514 |
| 1515 void HTMLMediaElement::setReadyState(ReadyState state) | 1515 void HTMLMediaElement::setReadyState(ReadyState state) |
| 1516 { | 1516 { |
| 1517 BLINK_MEDIA_LOG << "setReadyState(" << (void*)this << ", " << static_cast<in
t>(state) << ") - current state is " << static_cast<int>(m_readyState); | 1517 BLINK_MEDIA_LOG << "setReadyState(" << (void*)this << ", " << static_cast<in
t>(state) << ") - current state is " << static_cast<int>(m_readyState); |
| 1518 | 1518 |
| 1519 // Set "wasPotentiallyPlaying" BEFORE updating m_readyState, potentiallyPlay
ing() uses it | 1519 // Set "wasPotentiallyPlaying" BEFORE updating m_readyState, potentiallyPlay
ing() uses it |
| 1520 bool wasPotentiallyPlaying = potentiallyPlaying(); | 1520 bool wasPotentiallyPlaying = potentiallyPlaying(); |
| 1521 | 1521 |
| 1522 ReadyState oldState = m_readyState; | 1522 ReadyState oldState = m_readyState; |
| 1523 ReadyState newState = state; | 1523 ReadyState newState = state; |
| 1524 | 1524 |
| 1525 bool tracksAreReady = textTracksAreReady(); | 1525 bool tracksAreReady = textTracksAreReady(); |
| 1526 | 1526 |
| 1527 if (newState == oldState && m_tracksAreReady == tracksAreReady) | 1527 if (newState == oldState && m_tracksAreReady == tracksAreReady) |
| 1528 return; | 1528 return; |
| 1529 | 1529 |
| 1530 m_tracksAreReady = tracksAreReady; | 1530 m_tracksAreReady = tracksAreReady; |
| 1531 | 1531 |
| 1532 if (tracksAreReady) { | 1532 if (tracksAreReady) { |
| 1533 m_readyState = newState; | 1533 m_readyState = newState; |
| 1534 } else { | 1534 } else { |
| 1535 // If a media file has text tracks the readyState may not progress beyon
d HAVE_FUTURE_DATA until | 1535 // If a media file has text tracks the readyState may not progress beyon
d kHaveFutureData until |
| 1536 // the text tracks are ready, regardless of the state of the media file. | 1536 // the text tracks are ready, regardless of the state of the media file. |
| 1537 if (newState <= HAVE_METADATA) | 1537 if (newState <= kHaveMetadata) |
| 1538 m_readyState = newState; | 1538 m_readyState = newState; |
| 1539 else | 1539 else |
| 1540 m_readyState = HAVE_CURRENT_DATA; | 1540 m_readyState = kHaveCurrentData; |
| 1541 } | 1541 } |
| 1542 | 1542 |
| 1543 if (oldState > m_readyStateMaximum) | 1543 if (oldState > m_readyStateMaximum) |
| 1544 m_readyStateMaximum = oldState; | 1544 m_readyStateMaximum = oldState; |
| 1545 | 1545 |
| 1546 if (m_networkState == NETWORK_EMPTY) | 1546 if (m_networkState == kNetworkEmpty) |
| 1547 return; | 1547 return; |
| 1548 | 1548 |
| 1549 if (m_seeking) { | 1549 if (m_seeking) { |
| 1550 // 4.8.10.9, step 9 note: If the media element was potentially playing i
mmediately before | 1550 // 4.8.10.9, step 9 note: If the media element was potentially playing i
mmediately before |
| 1551 // it started seeking, but seeking caused its readyState attribute to ch
ange to a value | 1551 // it started seeking, but seeking caused its readyState attribute to ch
ange to a value |
| 1552 // lower than HAVE_FUTURE_DATA, then a waiting will be fired at the elem
ent. | 1552 // lower than kHaveFutureData, then a waiting will be fired at the eleme
nt. |
| 1553 if (wasPotentiallyPlaying && m_readyState < HAVE_FUTURE_DATA) | 1553 if (wasPotentiallyPlaying && m_readyState < kHaveFutureData) |
| 1554 scheduleEvent(EventTypeNames::waiting); | 1554 scheduleEvent(EventTypeNames::waiting); |
| 1555 | 1555 |
| 1556 // 4.8.10.9 steps 12-14 | 1556 // 4.8.10.9 steps 12-14 |
| 1557 if (m_readyState >= HAVE_CURRENT_DATA) | 1557 if (m_readyState >= kHaveCurrentData) |
| 1558 finishSeek(); | 1558 finishSeek(); |
| 1559 } else { | 1559 } else { |
| 1560 if (wasPotentiallyPlaying && m_readyState < HAVE_FUTURE_DATA) { | 1560 if (wasPotentiallyPlaying && m_readyState < kHaveFutureData) { |
| 1561 // 4.8.10.8 | 1561 // 4.8.10.8 |
| 1562 scheduleTimeupdateEvent(false); | 1562 scheduleTimeupdateEvent(false); |
| 1563 scheduleEvent(EventTypeNames::waiting); | 1563 scheduleEvent(EventTypeNames::waiting); |
| 1564 } | 1564 } |
| 1565 } | 1565 } |
| 1566 | 1566 |
| 1567 if (m_readyState >= HAVE_METADATA && oldState < HAVE_METADATA) { | 1567 if (m_readyState >= kHaveMetadata && oldState < kHaveMetadata) { |
| 1568 createPlaceholderTracksIfNecessary(); | 1568 createPlaceholderTracksIfNecessary(); |
| 1569 | 1569 |
| 1570 selectInitialTracksIfNecessary(); | 1570 selectInitialTracksIfNecessary(); |
| 1571 | 1571 |
| 1572 MediaFragmentURIParser fragmentParser(m_currentSrc); | 1572 MediaFragmentURIParser fragmentParser(m_currentSrc); |
| 1573 m_fragmentEndTime = fragmentParser.endTime(); | 1573 m_fragmentEndTime = fragmentParser.endTime(); |
| 1574 | 1574 |
| 1575 m_duration = duration(); | 1575 m_duration = duration(); |
| 1576 scheduleEvent(EventTypeNames::durationchange); | 1576 scheduleEvent(EventTypeNames::durationchange); |
| 1577 | 1577 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1597 } | 1597 } |
| 1598 | 1598 |
| 1599 if (mediaControls()) | 1599 if (mediaControls()) |
| 1600 mediaControls()->reset(); | 1600 mediaControls()->reset(); |
| 1601 if (layoutObject()) | 1601 if (layoutObject()) |
| 1602 layoutObject()->updateFromElement(); | 1602 layoutObject()->updateFromElement(); |
| 1603 } | 1603 } |
| 1604 | 1604 |
| 1605 bool shouldUpdateDisplayState = false; | 1605 bool shouldUpdateDisplayState = false; |
| 1606 | 1606 |
| 1607 if (m_readyState >= HAVE_CURRENT_DATA && oldState < HAVE_CURRENT_DATA && !m_
haveFiredLoadedData) { | 1607 if (m_readyState >= kHaveCurrentData && oldState < kHaveCurrentData && !m_ha
veFiredLoadedData) { |
| 1608 m_haveFiredLoadedData = true; | 1608 m_haveFiredLoadedData = true; |
| 1609 shouldUpdateDisplayState = true; | 1609 shouldUpdateDisplayState = true; |
| 1610 scheduleEvent(EventTypeNames::loadeddata); | 1610 scheduleEvent(EventTypeNames::loadeddata); |
| 1611 setShouldDelayLoadEvent(false); | 1611 setShouldDelayLoadEvent(false); |
| 1612 } | 1612 } |
| 1613 | 1613 |
| 1614 bool isPotentiallyPlaying = potentiallyPlaying(); | 1614 bool isPotentiallyPlaying = potentiallyPlaying(); |
| 1615 if (m_readyState == HAVE_FUTURE_DATA && oldState <= HAVE_CURRENT_DATA && tra
cksAreReady) { | 1615 if (m_readyState == kHaveFutureData && oldState <= kHaveCurrentData && track
sAreReady) { |
| 1616 scheduleEvent(EventTypeNames::canplay); | 1616 scheduleEvent(EventTypeNames::canplay); |
| 1617 if (isPotentiallyPlaying) | 1617 if (isPotentiallyPlaying) |
| 1618 scheduleNotifyPlaying(); | 1618 scheduleNotifyPlaying(); |
| 1619 shouldUpdateDisplayState = true; | 1619 shouldUpdateDisplayState = true; |
| 1620 } | 1620 } |
| 1621 | 1621 |
| 1622 if (m_readyState == HAVE_ENOUGH_DATA && oldState < HAVE_ENOUGH_DATA && track
sAreReady) { | 1622 if (m_readyState == kHaveEnoughData && oldState < kHaveEnoughData && tracksA
reReady) { |
| 1623 if (oldState <= HAVE_CURRENT_DATA) { | 1623 if (oldState <= kHaveCurrentData) { |
| 1624 scheduleEvent(EventTypeNames::canplay); | 1624 scheduleEvent(EventTypeNames::canplay); |
| 1625 if (isPotentiallyPlaying) | 1625 if (isPotentiallyPlaying) |
| 1626 scheduleNotifyPlaying(); | 1626 scheduleNotifyPlaying(); |
| 1627 } | 1627 } |
| 1628 | 1628 |
| 1629 // Check for autoplay, and record metrics about it if needed. | 1629 // Check for autoplay, and record metrics about it if needed. |
| 1630 if (shouldAutoplay(RecordMetricsBehavior::DoRecord)) { | 1630 if (shouldAutoplay(RecordMetricsBehavior::DoRecord)) { |
| 1631 recordAutoplaySourceMetric(AutoplaySourceAttribute); | 1631 recordAutoplaySourceMetric(AutoplaySourceAttribute); |
| 1632 | 1632 |
| 1633 // If the autoplay experiment says that it's okay to play now, | 1633 // If the autoplay experiment says that it's okay to play now, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1661 if (mediaControls()) | 1661 if (mediaControls()) |
| 1662 mediaControls()->refreshClosedCaptionsButtonVisibility(); | 1662 mediaControls()->refreshClosedCaptionsButtonVisibility(); |
| 1663 } | 1663 } |
| 1664 | 1664 |
| 1665 updatePlayState(); | 1665 updatePlayState(); |
| 1666 cueTimeline().updateActiveCues(currentTime()); | 1666 cueTimeline().updateActiveCues(currentTime()); |
| 1667 } | 1667 } |
| 1668 | 1668 |
| 1669 void HTMLMediaElement::progressEventTimerFired(Timer<HTMLMediaElement>*) | 1669 void HTMLMediaElement::progressEventTimerFired(Timer<HTMLMediaElement>*) |
| 1670 { | 1670 { |
| 1671 if (m_networkState != NETWORK_LOADING) | 1671 if (m_networkState != kNetworkLoading) |
| 1672 return; | 1672 return; |
| 1673 | 1673 |
| 1674 double time = WTF::currentTime(); | 1674 double time = WTF::currentTime(); |
| 1675 double timedelta = time - m_previousProgressTime; | 1675 double timedelta = time - m_previousProgressTime; |
| 1676 | 1676 |
| 1677 if (webMediaPlayer() && webMediaPlayer()->didLoadingProgress()) { | 1677 if (webMediaPlayer() && webMediaPlayer()->didLoadingProgress()) { |
| 1678 scheduleEvent(EventTypeNames::progress); | 1678 scheduleEvent(EventTypeNames::progress); |
| 1679 m_previousProgressTime = time; | 1679 m_previousProgressTime = time; |
| 1680 m_sentStalledEvent = false; | 1680 m_sentStalledEvent = false; |
| 1681 if (layoutObject()) | 1681 if (layoutObject()) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1708 } | 1708 } |
| 1709 | 1709 |
| 1710 void HTMLMediaElement::seek(double time) | 1710 void HTMLMediaElement::seek(double time) |
| 1711 { | 1711 { |
| 1712 BLINK_MEDIA_LOG << "seek(" << (void*)this << ", " << time << ")"; | 1712 BLINK_MEDIA_LOG << "seek(" << (void*)this << ", " << time << ")"; |
| 1713 | 1713 |
| 1714 // 2 - If the media element's readyState is HAVE_NOTHING, abort these steps. | 1714 // 2 - If the media element's readyState is HAVE_NOTHING, abort these steps. |
| 1715 // FIXME: remove m_webMediaPlayer check once we figure out how | 1715 // FIXME: remove m_webMediaPlayer check once we figure out how |
| 1716 // m_webMediaPlayer is going out of sync with readystate. | 1716 // m_webMediaPlayer is going out of sync with readystate. |
| 1717 // m_webMediaPlayer is cleared but readystate is not set to HAVE_NOTHING. | 1717 // m_webMediaPlayer is cleared but readystate is not set to HAVE_NOTHING. |
| 1718 if (!m_webMediaPlayer || m_readyState == HAVE_NOTHING) | 1718 if (!m_webMediaPlayer || m_readyState == kHaveNothing) |
| 1719 return; | 1719 return; |
| 1720 | 1720 |
| 1721 // Ignore preload none and start load if necessary. | 1721 // Ignore preload none and start load if necessary. |
| 1722 setIgnorePreloadNone(); | 1722 setIgnorePreloadNone(); |
| 1723 | 1723 |
| 1724 // Get the current time before setting m_seeking, m_lastSeekTime is returned
once it is set. | 1724 // Get the current time before setting m_seeking, m_lastSeekTime is returned
once it is set. |
| 1725 refreshCachedTime(); | 1725 refreshCachedTime(); |
| 1726 // This is needed to avoid getting default playback start position from curr
entTime(). | 1726 // This is needed to avoid getting default playback start position from curr
entTime(). |
| 1727 double now = m_cachedTime; | 1727 double now = m_cachedTime; |
| 1728 | 1728 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1813 return webMediaPlayer() && webMediaPlayer()->hasAudio(); | 1813 return webMediaPlayer() && webMediaPlayer()->hasAudio(); |
| 1814 } | 1814 } |
| 1815 | 1815 |
| 1816 bool HTMLMediaElement::seeking() const | 1816 bool HTMLMediaElement::seeking() const |
| 1817 { | 1817 { |
| 1818 return m_seeking; | 1818 return m_seeking; |
| 1819 } | 1819 } |
| 1820 | 1820 |
| 1821 void HTMLMediaElement::refreshCachedTime() const | 1821 void HTMLMediaElement::refreshCachedTime() const |
| 1822 { | 1822 { |
| 1823 if (!webMediaPlayer() || m_readyState < HAVE_METADATA) | 1823 if (!webMediaPlayer() || m_readyState < kHaveMetadata) |
| 1824 return; | 1824 return; |
| 1825 | 1825 |
| 1826 m_cachedTime = webMediaPlayer()->currentTime(); | 1826 m_cachedTime = webMediaPlayer()->currentTime(); |
| 1827 } | 1827 } |
| 1828 | 1828 |
| 1829 void HTMLMediaElement::invalidateCachedTime() | 1829 void HTMLMediaElement::invalidateCachedTime() |
| 1830 { | 1830 { |
| 1831 BLINK_MEDIA_LOG << "invalidateCachedTime(" << (void*)this << ")"; | 1831 BLINK_MEDIA_LOG << "invalidateCachedTime(" << (void*)this << ")"; |
| 1832 m_cachedTime = std::numeric_limits<double>::quiet_NaN(); | 1832 m_cachedTime = std::numeric_limits<double>::quiet_NaN(); |
| 1833 } | 1833 } |
| 1834 | 1834 |
| 1835 // playback state | 1835 // playback state |
| 1836 double HTMLMediaElement::currentTime() const | 1836 double HTMLMediaElement::currentTime() const |
| 1837 { | 1837 { |
| 1838 if (m_defaultPlaybackStartPosition) | 1838 if (m_defaultPlaybackStartPosition) |
| 1839 return m_defaultPlaybackStartPosition; | 1839 return m_defaultPlaybackStartPosition; |
| 1840 | 1840 |
| 1841 if (m_readyState == HAVE_NOTHING) | 1841 if (m_readyState == kHaveNothing) |
| 1842 return 0; | 1842 return 0; |
| 1843 | 1843 |
| 1844 if (m_seeking) { | 1844 if (m_seeking) { |
| 1845 BLINK_MEDIA_LOG << "currentTime(" << (void*)this << ") - seeking, return
ing " << m_lastSeekTime; | 1845 BLINK_MEDIA_LOG << "currentTime(" << (void*)this << ") - seeking, return
ing " << m_lastSeekTime; |
| 1846 return m_lastSeekTime; | 1846 return m_lastSeekTime; |
| 1847 } | 1847 } |
| 1848 | 1848 |
| 1849 if (!std::isnan(m_cachedTime) && m_paused) { | 1849 if (!std::isnan(m_cachedTime) && m_paused) { |
| 1850 #if LOG_CACHED_TIME_WARNINGS | 1850 #if LOG_CACHED_TIME_WARNINGS |
| 1851 static const double minCachedDeltaForWarning = 0.01; | 1851 static const double minCachedDeltaForWarning = 0.01; |
| 1852 double delta = m_cachedTime - webMediaPlayer()->currentTime(); | 1852 double delta = m_cachedTime - webMediaPlayer()->currentTime(); |
| 1853 if (delta > minCachedDeltaForWarning) | 1853 if (delta > minCachedDeltaForWarning) |
| 1854 BLINK_MEDIA_LOG << "currentTime(" << (void*)this << ") - WARNING, ca
ched time is " << delta << "seconds off of media time when paused"; | 1854 BLINK_MEDIA_LOG << "currentTime(" << (void*)this << ") - WARNING, ca
ched time is " << delta << "seconds off of media time when paused"; |
| 1855 #endif | 1855 #endif |
| 1856 return m_cachedTime; | 1856 return m_cachedTime; |
| 1857 } | 1857 } |
| 1858 | 1858 |
| 1859 refreshCachedTime(); | 1859 refreshCachedTime(); |
| 1860 | 1860 |
| 1861 return m_cachedTime; | 1861 return m_cachedTime; |
| 1862 } | 1862 } |
| 1863 | 1863 |
| 1864 void HTMLMediaElement::setCurrentTime(double time) | 1864 void HTMLMediaElement::setCurrentTime(double time) |
| 1865 { | 1865 { |
| 1866 // If the media element's readyState is HAVE_NOTHING, then set the default | 1866 // If the media element's readyState is kHaveNothing, then set the default |
| 1867 // playback start position to that time. | 1867 // playback start position to that time. |
| 1868 if (m_readyState == HAVE_NOTHING) { | 1868 if (m_readyState == kHaveNothing) { |
| 1869 m_defaultPlaybackStartPosition = time; | 1869 m_defaultPlaybackStartPosition = time; |
| 1870 return; | 1870 return; |
| 1871 } | 1871 } |
| 1872 | 1872 |
| 1873 seek(time); | 1873 seek(time); |
| 1874 } | 1874 } |
| 1875 | 1875 |
| 1876 double HTMLMediaElement::duration() const | 1876 double HTMLMediaElement::duration() const |
| 1877 { | 1877 { |
| 1878 // FIXME: remove m_webMediaPlayer check once we figure out how | 1878 // FIXME: remove m_webMediaPlayer check once we figure out how |
| 1879 // m_webMediaPlayer is going out of sync with readystate. | 1879 // m_webMediaPlayer is going out of sync with readystate. |
| 1880 // m_webMediaPlayer is cleared but readystate is not set to HAVE_NOTHING. | 1880 // m_webMediaPlayer is cleared but readystate is not set to kHaveNothing. |
| 1881 if (!m_webMediaPlayer || m_readyState < HAVE_METADATA) | 1881 if (!m_webMediaPlayer || m_readyState < kHaveMetadata) |
| 1882 return std::numeric_limits<double>::quiet_NaN(); | 1882 return std::numeric_limits<double>::quiet_NaN(); |
| 1883 | 1883 |
| 1884 // FIXME: Refactor so m_duration is kept current (in both MSE and | 1884 // FIXME: Refactor so m_duration is kept current (in both MSE and |
| 1885 // non-MSE cases) once we have transitioned from HAVE_NOTHING -> | 1885 // non-MSE cases) once we have transitioned from kHaveNothing -> |
| 1886 // HAVE_METADATA. Currently, m_duration may be out of date for at least MSE | 1886 // kHaveMetadata. Currently, m_duration may be out of date for at least MSE |
| 1887 // case because MediaSource and SourceBuffer do not notify the element | 1887 // case because MediaSource and SourceBuffer do not notify the element |
| 1888 // directly upon duration changes caused by endOfStream, remove, or append | 1888 // directly upon duration changes caused by endOfStream, remove, or append |
| 1889 // operations; rather the notification is triggered by the WebMediaPlayer | 1889 // operations; rather the notification is triggered by the WebMediaPlayer |
| 1890 // implementation observing that the underlying engine has updated duration | 1890 // implementation observing that the underlying engine has updated duration |
| 1891 // and notifying the element to consult its MediaSource for current | 1891 // and notifying the element to consult its MediaSource for current |
| 1892 // duration. See http://crbug.com/266644 | 1892 // duration. See http://crbug.com/266644 |
| 1893 | 1893 |
| 1894 if (m_mediaSource) | 1894 if (m_mediaSource) |
| 1895 return m_mediaSource->duration(); | 1895 return m_mediaSource->duration(); |
| 1896 | 1896 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1936 | 1936 |
| 1937 HTMLMediaElement::DirectionOfPlayback HTMLMediaElement::getDirectionOfPlayback()
const | 1937 HTMLMediaElement::DirectionOfPlayback HTMLMediaElement::getDirectionOfPlayback()
const |
| 1938 { | 1938 { |
| 1939 return m_playbackRate >= 0 ? Forward : Backward; | 1939 return m_playbackRate >= 0 ? Forward : Backward; |
| 1940 } | 1940 } |
| 1941 | 1941 |
| 1942 void HTMLMediaElement::updatePlaybackRate() | 1942 void HTMLMediaElement::updatePlaybackRate() |
| 1943 { | 1943 { |
| 1944 // FIXME: remove m_webMediaPlayer check once we figure out how | 1944 // FIXME: remove m_webMediaPlayer check once we figure out how |
| 1945 // m_webMediaPlayer is going out of sync with readystate. | 1945 // m_webMediaPlayer is going out of sync with readystate. |
| 1946 // m_webMediaPlayer is cleared but readystate is not set to HAVE_NOTHING. | 1946 // m_webMediaPlayer is cleared but readystate is not set to kHaveNothing. |
| 1947 if (m_webMediaPlayer && potentiallyPlaying()) | 1947 if (m_webMediaPlayer && potentiallyPlaying()) |
| 1948 webMediaPlayer()->setRate(playbackRate()); | 1948 webMediaPlayer()->setRate(playbackRate()); |
| 1949 } | 1949 } |
| 1950 | 1950 |
| 1951 bool HTMLMediaElement::ended() const | 1951 bool HTMLMediaElement::ended() const |
| 1952 { | 1952 { |
| 1953 // 4.8.10.8 Playing the media resource | 1953 // 4.8.10.8 Playing the media resource |
| 1954 // The ended attribute must return true if the media element has ended | 1954 // The ended attribute must return true if the media element has ended |
| 1955 // playback and the direction of playback is forwards, and false otherwise. | 1955 // playback and the direction of playback is forwards, and false otherwise. |
| 1956 return endedPlayback() && getDirectionOfPlayback() == Forward; | 1956 return endedPlayback() && getDirectionOfPlayback() == Forward; |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2101 return NotAllowedError; | 2101 return NotAllowedError; |
| 2102 } | 2102 } |
| 2103 } else { | 2103 } else { |
| 2104 UserGestureIndicator::utilizeUserGesture(); | 2104 UserGestureIndicator::utilizeUserGesture(); |
| 2105 // We ask the helper to remove the gesture requirement for us, so that | 2105 // We ask the helper to remove the gesture requirement for us, so that |
| 2106 // it can record the reason. | 2106 // it can record the reason. |
| 2107 Platform::current()->recordAction(UserMetricsAction("Media_Play_WithGest
ure")); | 2107 Platform::current()->recordAction(UserMetricsAction("Media_Play_WithGest
ure")); |
| 2108 m_autoplayHelper->unlockUserGesture(GesturelessPlaybackEnabledByPlayMeth
od); | 2108 m_autoplayHelper->unlockUserGesture(GesturelessPlaybackEnabledByPlayMeth
od); |
| 2109 } | 2109 } |
| 2110 | 2110 |
| 2111 if (m_error && m_error->code() == MediaError::MEDIA_ERR_SRC_NOT_SUPPORTED) | 2111 if (m_error && m_error->code() == MediaError::kMediaErrSrcNotSupported) |
| 2112 return NotSupportedError; | 2112 return NotSupportedError; |
| 2113 | 2113 |
| 2114 playInternal(); | 2114 playInternal(); |
| 2115 | 2115 |
| 2116 return nullptr; | 2116 return nullptr; |
| 2117 } | 2117 } |
| 2118 | 2118 |
| 2119 void HTMLMediaElement::playInternal() | 2119 void HTMLMediaElement::playInternal() |
| 2120 { | 2120 { |
| 2121 BLINK_MEDIA_LOG << "playInternal(" << (void*)this << ")"; | 2121 BLINK_MEDIA_LOG << "playInternal(" << (void*)this << ")"; |
| 2122 | 2122 |
| 2123 // Always return the buffering strategy to normal when not paused, | 2123 // Always return the buffering strategy to normal when not paused, |
| 2124 // regardless of the cause. (In contrast with aggressive buffering which is | 2124 // regardless of the cause. (In contrast with aggressive buffering which is |
| 2125 // only enabled by pause(), not pauseInternal().) | 2125 // only enabled by pause(), not pauseInternal().) |
| 2126 if (webMediaPlayer()) | 2126 if (webMediaPlayer()) |
| 2127 webMediaPlayer()->setBufferingStrategy(WebMediaPlayer::BufferingStrategy
::Normal); | 2127 webMediaPlayer()->setBufferingStrategy(WebMediaPlayer::BufferingStrategy
::Normal); |
| 2128 | 2128 |
| 2129 // 4.8.10.9. Playing the media resource | 2129 // 4.8.10.9. Playing the media resource |
| 2130 if (m_networkState == NETWORK_EMPTY) | 2130 if (m_networkState == kNetworkEmpty) |
| 2131 invokeResourceSelectionAlgorithm(); | 2131 invokeResourceSelectionAlgorithm(); |
| 2132 | 2132 |
| 2133 // Generally "ended" and "looping" are exclusive. Here, the loop attribute | 2133 // Generally "ended" and "looping" are exclusive. Here, the loop attribute |
| 2134 // is ignored to seek back to start in case loop was set after playback | 2134 // is ignored to seek back to start in case loop was set after playback |
| 2135 // ended. See http://crbug.com/364442 | 2135 // ended. See http://crbug.com/364442 |
| 2136 if (endedPlayback(LoopCondition::Ignored)) | 2136 if (endedPlayback(LoopCondition::Ignored)) |
| 2137 seek(0); | 2137 seek(0); |
| 2138 | 2138 |
| 2139 if (m_paused) { | 2139 if (m_paused) { |
| 2140 m_paused = false; | 2140 m_paused = false; |
| 2141 invalidateCachedTime(); | 2141 invalidateCachedTime(); |
| 2142 scheduleEvent(EventTypeNames::play); | 2142 scheduleEvent(EventTypeNames::play); |
| 2143 | 2143 |
| 2144 if (m_readyState <= HAVE_CURRENT_DATA) | 2144 if (m_readyState <= kHaveCurrentData) |
| 2145 scheduleEvent(EventTypeNames::waiting); | 2145 scheduleEvent(EventTypeNames::waiting); |
| 2146 else if (m_readyState >= HAVE_FUTURE_DATA) | 2146 else if (m_readyState >= kHaveFutureData) |
| 2147 scheduleNotifyPlaying(); | 2147 scheduleNotifyPlaying(); |
| 2148 } else if (m_readyState >= HAVE_FUTURE_DATA) { | 2148 } else if (m_readyState >= kHaveFutureData) { |
| 2149 scheduleResolvePlayPromises(); | 2149 scheduleResolvePlayPromises(); |
| 2150 } | 2150 } |
| 2151 | 2151 |
| 2152 m_autoplaying = false; | 2152 m_autoplaying = false; |
| 2153 | 2153 |
| 2154 setIgnorePreloadNone(); | 2154 setIgnorePreloadNone(); |
| 2155 updatePlayState(); | 2155 updatePlayState(); |
| 2156 } | 2156 } |
| 2157 | 2157 |
| 2158 void HTMLMediaElement::pause() | 2158 void HTMLMediaElement::pause() |
| 2159 { | 2159 { |
| 2160 BLINK_MEDIA_LOG << "pause(" << (void*)this << ")"; | 2160 BLINK_MEDIA_LOG << "pause(" << (void*)this << ")"; |
| 2161 | 2161 |
| 2162 // Only buffer aggressively on a user-initiated pause. Other types of pauses | 2162 // Only buffer aggressively on a user-initiated pause. Other types of pauses |
| 2163 // (which go directly to pauseInternal()) should not cause this behavior. | 2163 // (which go directly to pauseInternal()) should not cause this behavior. |
| 2164 if (webMediaPlayer() && UserGestureIndicator::utilizeUserGesture()) | 2164 if (webMediaPlayer() && UserGestureIndicator::utilizeUserGesture()) |
| 2165 webMediaPlayer()->setBufferingStrategy(WebMediaPlayer::BufferingStrategy
::Aggressive); | 2165 webMediaPlayer()->setBufferingStrategy(WebMediaPlayer::BufferingStrategy
::Aggressive); |
| 2166 | 2166 |
| 2167 pauseInternal(); | 2167 pauseInternal(); |
| 2168 } | 2168 } |
| 2169 | 2169 |
| 2170 void HTMLMediaElement::pauseInternal() | 2170 void HTMLMediaElement::pauseInternal() |
| 2171 { | 2171 { |
| 2172 BLINK_MEDIA_LOG << "pauseInternal(" << (void*)this << ")"; | 2172 BLINK_MEDIA_LOG << "pauseInternal(" << (void*)this << ")"; |
| 2173 | 2173 |
| 2174 if (m_networkState == NETWORK_EMPTY) | 2174 if (m_networkState == kNetworkEmpty) |
| 2175 invokeResourceSelectionAlgorithm(); | 2175 invokeResourceSelectionAlgorithm(); |
| 2176 | 2176 |
| 2177 m_autoplayHelper->pauseMethodCalled(); | 2177 m_autoplayHelper->pauseMethodCalled(); |
| 2178 | 2178 |
| 2179 m_autoplaying = false; | 2179 m_autoplaying = false; |
| 2180 | 2180 |
| 2181 if (!m_paused) { | 2181 if (!m_paused) { |
| 2182 m_paused = true; | 2182 m_paused = true; |
| 2183 scheduleTimeupdateEvent(false); | 2183 scheduleTimeupdateEvent(false); |
| 2184 scheduleEvent(EventTypeNames::pause); | 2184 scheduleEvent(EventTypeNames::pause); |
| (...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2805 KURL url = source->getNonEmptyURLAttribute(srcAttr); | 2805 KURL url = source->getNonEmptyURLAttribute(srcAttr); |
| 2806 BLINK_MEDIA_LOG << "sourceWasAdded(" << (void*)this << ") - 'src' is " << ur
lForLoggingMedia(url); | 2806 BLINK_MEDIA_LOG << "sourceWasAdded(" << (void*)this << ") - 'src' is " << ur
lForLoggingMedia(url); |
| 2807 | 2807 |
| 2808 // We should only consider a <source> element when there is not src attribut
e at all. | 2808 // We should only consider a <source> element when there is not src attribut
e at all. |
| 2809 if (fastHasAttribute(srcAttr)) | 2809 if (fastHasAttribute(srcAttr)) |
| 2810 return; | 2810 return; |
| 2811 | 2811 |
| 2812 // 4.8.8 - If a source element is inserted as a child of a media element tha
t has no src | 2812 // 4.8.8 - If a source element is inserted as a child of a media element tha
t has no src |
| 2813 // attribute and whose networkState has the value NETWORK_EMPTY, the user ag
ent must invoke | 2813 // attribute and whose networkState has the value NETWORK_EMPTY, the user ag
ent must invoke |
| 2814 // the media element's resource selection algorithm. | 2814 // the media element's resource selection algorithm. |
| 2815 if (getNetworkState() == HTMLMediaElement::NETWORK_EMPTY) { | 2815 if (getNetworkState() == HTMLMediaElement::kNetworkEmpty) { |
| 2816 invokeResourceSelectionAlgorithm(); | 2816 invokeResourceSelectionAlgorithm(); |
| 2817 // Ignore current |m_nextChildNodeToConsider| and consider |source|. | 2817 // Ignore current |m_nextChildNodeToConsider| and consider |source|. |
| 2818 m_nextChildNodeToConsider = source; | 2818 m_nextChildNodeToConsider = source; |
| 2819 return; | 2819 return; |
| 2820 } | 2820 } |
| 2821 | 2821 |
| 2822 if (m_currentSourceNode && source == m_currentSourceNode->nextSibling()) { | 2822 if (m_currentSourceNode && source == m_currentSourceNode->nextSibling()) { |
| 2823 BLINK_MEDIA_LOG << "sourceWasAdded(" << (void*)this << ") - <source> ins
erted immediately after current source"; | 2823 BLINK_MEDIA_LOG << "sourceWasAdded(" << (void*)this << ") - <source> ins
erted immediately after current source"; |
| 2824 // Ignore current |m_nextChildNodeToConsider| and consider |source|. | 2824 // Ignore current |m_nextChildNodeToConsider| and consider |source|. |
| 2825 m_nextChildNodeToConsider = source; | 2825 m_nextChildNodeToConsider = source; |
| 2826 return; | 2826 return; |
| 2827 } | 2827 } |
| 2828 | 2828 |
| 2829 // Consider current |m_nextChildNodeToConsider| as it is already in the midd
le of processing. | 2829 // Consider current |m_nextChildNodeToConsider| as it is already in the midd
le of processing. |
| 2830 if (m_nextChildNodeToConsider) | 2830 if (m_nextChildNodeToConsider) |
| 2831 return; | 2831 return; |
| 2832 | 2832 |
| 2833 if (m_loadState != WaitingForSource) | 2833 if (m_loadState != WaitingForSource) |
| 2834 return; | 2834 return; |
| 2835 | 2835 |
| 2836 // 4.8.9.5, resource selection algorithm, source elements section: | 2836 // 4.8.9.5, resource selection algorithm, source elements section: |
| 2837 // 21. Wait until the node after pointer is a node other than the end of the
list. (This step might wait forever.) | 2837 // 21. Wait until the node after pointer is a node other than the end of the
list. (This step might wait forever.) |
| 2838 // 22. Asynchronously await a stable state... | 2838 // 22. Asynchronously await a stable state... |
| 2839 // 23. Set the element's delaying-the-load-event flag back to true (this del
ays the load event again, in case | 2839 // 23. Set the element's delaying-the-load-event flag back to true (this del
ays the load event again, in case |
| 2840 // it hasn't been fired yet). | 2840 // it hasn't been fired yet). |
| 2841 setShouldDelayLoadEvent(true); | 2841 setShouldDelayLoadEvent(true); |
| 2842 | 2842 |
| 2843 // 24. Set the networkState back to NETWORK_LOADING. | 2843 // 24. Set the networkState back to NETWORK_LOADING. |
| 2844 setNetworkState(NETWORK_LOADING); | 2844 setNetworkState(kNetworkLoading); |
| 2845 | 2845 |
| 2846 // 25. Jump back to the find next candidate step above. | 2846 // 25. Jump back to the find next candidate step above. |
| 2847 m_nextChildNodeToConsider = source; | 2847 m_nextChildNodeToConsider = source; |
| 2848 scheduleNextSourceChild(); | 2848 scheduleNextSourceChild(); |
| 2849 } | 2849 } |
| 2850 | 2850 |
| 2851 void HTMLMediaElement::sourceWasRemoved(HTMLSourceElement* source) | 2851 void HTMLMediaElement::sourceWasRemoved(HTMLSourceElement* source) |
| 2852 { | 2852 { |
| 2853 BLINK_MEDIA_LOG << "sourceWasRemoved(" << (void*)this << ", " << source << "
)"; | 2853 BLINK_MEDIA_LOG << "sourceWasRemoved(" << (void*)this << ", " << source << "
)"; |
| 2854 | 2854 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2873 | 2873 |
| 2874 void HTMLMediaElement::timeChanged() | 2874 void HTMLMediaElement::timeChanged() |
| 2875 { | 2875 { |
| 2876 BLINK_MEDIA_LOG << "timeChanged(" << (void*)this << ")"; | 2876 BLINK_MEDIA_LOG << "timeChanged(" << (void*)this << ")"; |
| 2877 | 2877 |
| 2878 cueTimeline().updateActiveCues(currentTime()); | 2878 cueTimeline().updateActiveCues(currentTime()); |
| 2879 | 2879 |
| 2880 invalidateCachedTime(); | 2880 invalidateCachedTime(); |
| 2881 | 2881 |
| 2882 // 4.8.10.9 steps 12-14. Needed if no ReadyState change is associated with t
he seek. | 2882 // 4.8.10.9 steps 12-14. Needed if no ReadyState change is associated with t
he seek. |
| 2883 if (m_seeking && m_readyState >= HAVE_CURRENT_DATA && !webMediaPlayer()->see
king()) | 2883 if (m_seeking && m_readyState >= kHaveCurrentData && !webMediaPlayer()->seek
ing()) |
| 2884 finishSeek(); | 2884 finishSeek(); |
| 2885 | 2885 |
| 2886 // Always call scheduleTimeupdateEvent when the media engine reports a time
discontinuity, | 2886 // Always call scheduleTimeupdateEvent when the media engine reports a time
discontinuity, |
| 2887 // it will only queue a 'timeupdate' event if we haven't already posted one
at the current | 2887 // it will only queue a 'timeupdate' event if we haven't already posted one
at the current |
| 2888 // movie time. | 2888 // movie time. |
| 2889 scheduleTimeupdateEvent(false); | 2889 scheduleTimeupdateEvent(false); |
| 2890 | 2890 |
| 2891 double now = currentTime(); | 2891 double now = currentTime(); |
| 2892 double dur = duration(); | 2892 double dur = duration(); |
| 2893 | 2893 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3016 updateDisplayState(); | 3016 updateDisplayState(); |
| 3017 if (layoutObject()) | 3017 if (layoutObject()) |
| 3018 layoutObject()->setShouldDoFullPaintInvalidation(); | 3018 layoutObject()->setShouldDoFullPaintInvalidation(); |
| 3019 } | 3019 } |
| 3020 | 3020 |
| 3021 void HTMLMediaElement::sizeChanged() | 3021 void HTMLMediaElement::sizeChanged() |
| 3022 { | 3022 { |
| 3023 BLINK_MEDIA_LOG << "sizeChanged(" << (void*)this << ")"; | 3023 BLINK_MEDIA_LOG << "sizeChanged(" << (void*)this << ")"; |
| 3024 | 3024 |
| 3025 DCHECK(hasVideo()); // "resize" makes no sense in absence of video. | 3025 DCHECK(hasVideo()); // "resize" makes no sense in absence of video. |
| 3026 if (m_readyState > HAVE_NOTHING && isHTMLVideoElement()) | 3026 if (m_readyState > kHaveNothing && isHTMLVideoElement()) |
| 3027 scheduleEvent(EventTypeNames::resize); | 3027 scheduleEvent(EventTypeNames::resize); |
| 3028 | 3028 |
| 3029 if (layoutObject()) | 3029 if (layoutObject()) |
| 3030 layoutObject()->updateFromElement(); | 3030 layoutObject()->updateFromElement(); |
| 3031 } | 3031 } |
| 3032 | 3032 |
| 3033 TimeRanges* HTMLMediaElement::buffered() const | 3033 TimeRanges* HTMLMediaElement::buffered() const |
| 3034 { | 3034 { |
| 3035 if (m_mediaSource) | 3035 if (m_mediaSource) |
| 3036 return m_mediaSource->buffered(); | 3036 return m_mediaSource->buffered(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 3064 return m_mediaSource->seekable(); | 3064 return m_mediaSource->seekable(); |
| 3065 | 3065 |
| 3066 return TimeRanges::create(webMediaPlayer()->seekable()); | 3066 return TimeRanges::create(webMediaPlayer()->seekable()); |
| 3067 } | 3067 } |
| 3068 | 3068 |
| 3069 bool HTMLMediaElement::potentiallyPlaying() const | 3069 bool HTMLMediaElement::potentiallyPlaying() const |
| 3070 { | 3070 { |
| 3071 // "pausedToBuffer" means the media engine's rate is 0, but only because it
had to stop playing | 3071 // "pausedToBuffer" means the media engine's rate is 0, but only because it
had to stop playing |
| 3072 // when it ran out of buffered data. A movie in this state is "potentially p
laying", modulo the | 3072 // when it ran out of buffered data. A movie in this state is "potentially p
laying", modulo the |
| 3073 // checks in couldPlayIfEnoughData(). | 3073 // checks in couldPlayIfEnoughData(). |
| 3074 bool pausedToBuffer = m_readyStateMaximum >= HAVE_FUTURE_DATA && m_readyStat
e < HAVE_FUTURE_DATA; | 3074 bool pausedToBuffer = m_readyStateMaximum >= kHaveFutureData && m_readyState
< kHaveFutureData; |
| 3075 return (pausedToBuffer || m_readyState >= HAVE_FUTURE_DATA) && couldPlayIfEn
oughData(); | 3075 return (pausedToBuffer || m_readyState >= kHaveFutureData) && couldPlayIfEno
ughData(); |
| 3076 } | 3076 } |
| 3077 | 3077 |
| 3078 bool HTMLMediaElement::couldPlayIfEnoughData() const | 3078 bool HTMLMediaElement::couldPlayIfEnoughData() const |
| 3079 { | 3079 { |
| 3080 return !paused() && !endedPlayback() && !stoppedDueToErrors(); | 3080 return !paused() && !endedPlayback() && !stoppedDueToErrors(); |
| 3081 } | 3081 } |
| 3082 | 3082 |
| 3083 bool HTMLMediaElement::endedPlayback(LoopCondition loopCondition) const | 3083 bool HTMLMediaElement::endedPlayback(LoopCondition loopCondition) const |
| 3084 { | 3084 { |
| 3085 double dur = duration(); | 3085 double dur = duration(); |
| 3086 if (std::isnan(dur)) | 3086 if (std::isnan(dur)) |
| 3087 return false; | 3087 return false; |
| 3088 | 3088 |
| 3089 // 4.8.10.8 Playing the media resource | 3089 // 4.8.10.8 Playing the media resource |
| 3090 | 3090 |
| 3091 // A media element is said to have ended playback when the element's | 3091 // A media element is said to have ended playback when the element's |
| 3092 // readyState attribute is HAVE_METADATA or greater, | 3092 // readyState attribute is HAVE_METADATA or greater, |
| 3093 if (m_readyState < HAVE_METADATA) | 3093 if (m_readyState < kHaveMetadata) |
| 3094 return false; | 3094 return false; |
| 3095 | 3095 |
| 3096 // and the current playback position is the end of the media resource and th
e direction | 3096 // and the current playback position is the end of the media resource and th
e direction |
| 3097 // of playback is forwards, Either the media element does not have a loop at
tribute specified, | 3097 // of playback is forwards, Either the media element does not have a loop at
tribute specified, |
| 3098 double now = currentTime(); | 3098 double now = currentTime(); |
| 3099 if (getDirectionOfPlayback() == Forward) | 3099 if (getDirectionOfPlayback() == Forward) |
| 3100 return dur > 0 && now >= dur && (loopCondition == LoopCondition::Ignored
|| !loop()); | 3100 return dur > 0 && now >= dur && (loopCondition == LoopCondition::Ignored
|| !loop()); |
| 3101 | 3101 |
| 3102 // or the current playback position is the earliest possible position and th
e direction | 3102 // or the current playback position is the earliest possible position and th
e direction |
| 3103 // of playback is backwards | 3103 // of playback is backwards |
| 3104 DCHECK_EQ(getDirectionOfPlayback(), Backward); | 3104 DCHECK_EQ(getDirectionOfPlayback(), Backward); |
| 3105 return now <= 0; | 3105 return now <= 0; |
| 3106 } | 3106 } |
| 3107 | 3107 |
| 3108 bool HTMLMediaElement::stoppedDueToErrors() const | 3108 bool HTMLMediaElement::stoppedDueToErrors() const |
| 3109 { | 3109 { |
| 3110 if (m_readyState >= HAVE_METADATA && m_error) { | 3110 if (m_readyState >= kHaveMetadata && m_error) { |
| 3111 TimeRanges* seekableRanges = seekable(); | 3111 TimeRanges* seekableRanges = seekable(); |
| 3112 if (!seekableRanges->contain(currentTime())) | 3112 if (!seekableRanges->contain(currentTime())) |
| 3113 return true; | 3113 return true; |
| 3114 } | 3114 } |
| 3115 | 3115 |
| 3116 return false; | 3116 return false; |
| 3117 } | 3117 } |
| 3118 | 3118 |
| 3119 void HTMLMediaElement::updatePlayState() | 3119 void HTMLMediaElement::updatePlayState() |
| 3120 { | 3120 { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3214 void HTMLMediaElement::stop() | 3214 void HTMLMediaElement::stop() |
| 3215 { | 3215 { |
| 3216 BLINK_MEDIA_LOG << "stop(" << (void*)this << ")"; | 3216 BLINK_MEDIA_LOG << "stop(" << (void*)this << ")"; |
| 3217 | 3217 |
| 3218 // Close the async event queue so that no events are enqueued. | 3218 // Close the async event queue so that no events are enqueued. |
| 3219 cancelPendingEventsAndCallbacks(); | 3219 cancelPendingEventsAndCallbacks(); |
| 3220 m_asyncEventQueue->close(); | 3220 m_asyncEventQueue->close(); |
| 3221 | 3221 |
| 3222 // Clear everything in the Media Element | 3222 // Clear everything in the Media Element |
| 3223 clearMediaPlayer(); | 3223 clearMediaPlayer(); |
| 3224 m_readyState = HAVE_NOTHING; | 3224 m_readyState = kHaveNothing; |
| 3225 m_readyStateMaximum = HAVE_NOTHING; | 3225 m_readyStateMaximum = kHaveNothing; |
| 3226 setNetworkState(NETWORK_EMPTY); | 3226 setNetworkState(kNetworkEmpty); |
| 3227 setShouldDelayLoadEvent(false); | 3227 setShouldDelayLoadEvent(false); |
| 3228 m_currentSourceNode = nullptr; | 3228 m_currentSourceNode = nullptr; |
| 3229 invalidateCachedTime(); | 3229 invalidateCachedTime(); |
| 3230 cueTimeline().updateActiveCues(0); | 3230 cueTimeline().updateActiveCues(0); |
| 3231 m_playing = false; | 3231 m_playing = false; |
| 3232 m_paused = true; | 3232 m_paused = true; |
| 3233 m_seeking = false; | 3233 m_seeking = false; |
| 3234 | 3234 |
| 3235 if (layoutObject()) | 3235 if (layoutObject()) |
| 3236 layoutObject()->updateFromElement(); | 3236 layoutObject()->updateFromElement(); |
| 3237 | 3237 |
| 3238 stopPeriodicTimers(); | 3238 stopPeriodicTimers(); |
| 3239 | 3239 |
| 3240 // Ensure that hasPendingActivity() is not preventing garbage collection, si
nce otherwise this | 3240 // Ensure that hasPendingActivity() is not preventing garbage collection, si
nce otherwise this |
| 3241 // media element will simply leak. | 3241 // media element will simply leak. |
| 3242 DCHECK(!hasPendingActivity()); | 3242 DCHECK(!hasPendingActivity()); |
| 3243 } | 3243 } |
| 3244 | 3244 |
| 3245 bool HTMLMediaElement::hasPendingActivity() const | 3245 bool HTMLMediaElement::hasPendingActivity() const |
| 3246 { | 3246 { |
| 3247 // The delaying-the-load-event flag is set by resource selection algorithm w
hen looking for a | 3247 // The delaying-the-load-event flag is set by resource selection algorithm w
hen looking for a |
| 3248 // resource to load, before networkState has reached to NETWORK_LOADING. | 3248 // resource to load, before networkState has reached to kNetworkLoading. |
| 3249 if (m_shouldDelayLoadEvent) | 3249 if (m_shouldDelayLoadEvent) |
| 3250 return true; | 3250 return true; |
| 3251 | 3251 |
| 3252 // When networkState is NETWORK_LOADING, progress and stalled events may be
fired. | 3252 // When networkState is kNetworkLoading, progress and stalled events may be
fired. |
| 3253 if (m_networkState == NETWORK_LOADING) | 3253 if (m_networkState == kNetworkLoading) |
| 3254 return true; | 3254 return true; |
| 3255 | 3255 |
| 3256 // When playing or if playback may continue, timeupdate events may be fired. | 3256 // When playing or if playback may continue, timeupdate events may be fired. |
| 3257 if (couldPlayIfEnoughData()) | 3257 if (couldPlayIfEnoughData()) |
| 3258 return true; | 3258 return true; |
| 3259 | 3259 |
| 3260 // When the seek finishes timeupdate and seeked events will be fired. | 3260 // When the seek finishes timeupdate and seeked events will be fired. |
| 3261 if (m_seeking) | 3261 if (m_seeking) |
| 3262 return true; | 3262 return true; |
| 3263 | 3263 |
| (...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4036 | 4036 |
| 4037 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect() co
nst | 4037 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect() co
nst |
| 4038 { | 4038 { |
| 4039 IntRect result; | 4039 IntRect result; |
| 4040 if (LayoutObject* object = m_element->layoutObject()) | 4040 if (LayoutObject* object = m_element->layoutObject()) |
| 4041 result = object->absoluteBoundingBoxRect(); | 4041 result = object->absoluteBoundingBoxRect(); |
| 4042 return result; | 4042 return result; |
| 4043 } | 4043 } |
| 4044 | 4044 |
| 4045 } // namespace blink | 4045 } // namespace blink |
| OLD | NEW |