Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(455)

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLMediaElement.cpp

Issue 2068053002: Rename Blink constants generated from IDL files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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
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
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
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
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
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
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
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
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(TimerBase*) 1669 void HTMLMediaElement::progressEventTimerFired(TimerBase*)
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
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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1811 return webMediaPlayer() && webMediaPlayer()->hasAudio(); 1811 return webMediaPlayer() && webMediaPlayer()->hasAudio();
1812 } 1812 }
1813 1813
1814 bool HTMLMediaElement::seeking() const 1814 bool HTMLMediaElement::seeking() const
1815 { 1815 {
1816 return m_seeking; 1816 return m_seeking;
1817 } 1817 }
1818 1818
1819 void HTMLMediaElement::refreshCachedTime() const 1819 void HTMLMediaElement::refreshCachedTime() const
1820 { 1820 {
1821 if (!webMediaPlayer() || m_readyState < HAVE_METADATA) 1821 if (!webMediaPlayer() || m_readyState < kHaveMetadata)
1822 return; 1822 return;
1823 1823
1824 m_cachedTime = webMediaPlayer()->currentTime(); 1824 m_cachedTime = webMediaPlayer()->currentTime();
1825 } 1825 }
1826 1826
1827 void HTMLMediaElement::invalidateCachedTime() 1827 void HTMLMediaElement::invalidateCachedTime()
1828 { 1828 {
1829 BLINK_MEDIA_LOG << "invalidateCachedTime(" << (void*)this << ")"; 1829 BLINK_MEDIA_LOG << "invalidateCachedTime(" << (void*)this << ")";
1830 m_cachedTime = std::numeric_limits<double>::quiet_NaN(); 1830 m_cachedTime = std::numeric_limits<double>::quiet_NaN();
1831 } 1831 }
1832 1832
1833 // playback state 1833 // playback state
1834 double HTMLMediaElement::currentTime() const 1834 double HTMLMediaElement::currentTime() const
1835 { 1835 {
1836 if (m_defaultPlaybackStartPosition) 1836 if (m_defaultPlaybackStartPosition)
1837 return m_defaultPlaybackStartPosition; 1837 return m_defaultPlaybackStartPosition;
1838 1838
1839 if (m_readyState == HAVE_NOTHING) 1839 if (m_readyState == kHaveNothing)
1840 return 0; 1840 return 0;
1841 1841
1842 if (m_seeking) { 1842 if (m_seeking) {
1843 BLINK_MEDIA_LOG << "currentTime(" << (void*)this << ") - seeking, return ing " << m_lastSeekTime; 1843 BLINK_MEDIA_LOG << "currentTime(" << (void*)this << ") - seeking, return ing " << m_lastSeekTime;
1844 return m_lastSeekTime; 1844 return m_lastSeekTime;
1845 } 1845 }
1846 1846
1847 if (!std::isnan(m_cachedTime) && m_paused) { 1847 if (!std::isnan(m_cachedTime) && m_paused) {
1848 #if LOG_CACHED_TIME_WARNINGS 1848 #if LOG_CACHED_TIME_WARNINGS
1849 static const double minCachedDeltaForWarning = 0.01; 1849 static const double minCachedDeltaForWarning = 0.01;
1850 double delta = m_cachedTime - webMediaPlayer()->currentTime(); 1850 double delta = m_cachedTime - webMediaPlayer()->currentTime();
1851 if (delta > minCachedDeltaForWarning) 1851 if (delta > minCachedDeltaForWarning)
1852 BLINK_MEDIA_LOG << "currentTime(" << (void*)this << ") - WARNING, ca ched time is " << delta << "seconds off of media time when paused"; 1852 BLINK_MEDIA_LOG << "currentTime(" << (void*)this << ") - WARNING, ca ched time is " << delta << "seconds off of media time when paused";
1853 #endif 1853 #endif
1854 return m_cachedTime; 1854 return m_cachedTime;
1855 } 1855 }
1856 1856
1857 refreshCachedTime(); 1857 refreshCachedTime();
1858 1858
1859 return m_cachedTime; 1859 return m_cachedTime;
1860 } 1860 }
1861 1861
1862 void HTMLMediaElement::setCurrentTime(double time) 1862 void HTMLMediaElement::setCurrentTime(double time)
1863 { 1863 {
1864 // If the media element's readyState is HAVE_NOTHING, then set the default 1864 // If the media element's readyState is kHaveNothing, then set the default
1865 // playback start position to that time. 1865 // playback start position to that time.
1866 if (m_readyState == HAVE_NOTHING) { 1866 if (m_readyState == kHaveNothing) {
1867 m_defaultPlaybackStartPosition = time; 1867 m_defaultPlaybackStartPosition = time;
1868 return; 1868 return;
1869 } 1869 }
1870 1870
1871 seek(time); 1871 seek(time);
1872 } 1872 }
1873 1873
1874 double HTMLMediaElement::duration() const 1874 double HTMLMediaElement::duration() const
1875 { 1875 {
1876 // FIXME: remove m_webMediaPlayer check once we figure out how 1876 // FIXME: remove m_webMediaPlayer check once we figure out how
1877 // m_webMediaPlayer is going out of sync with readystate. 1877 // m_webMediaPlayer is going out of sync with readystate.
1878 // m_webMediaPlayer is cleared but readystate is not set to HAVE_NOTHING. 1878 // m_webMediaPlayer is cleared but readystate is not set to kHaveNothing.
1879 if (!m_webMediaPlayer || m_readyState < HAVE_METADATA) 1879 if (!m_webMediaPlayer || m_readyState < kHaveMetadata)
1880 return std::numeric_limits<double>::quiet_NaN(); 1880 return std::numeric_limits<double>::quiet_NaN();
1881 1881
1882 // FIXME: Refactor so m_duration is kept current (in both MSE and 1882 // FIXME: Refactor so m_duration is kept current (in both MSE and
1883 // non-MSE cases) once we have transitioned from HAVE_NOTHING -> 1883 // non-MSE cases) once we have transitioned from kHaveNothing ->
1884 // HAVE_METADATA. Currently, m_duration may be out of date for at least MSE 1884 // kHaveMetadata. Currently, m_duration may be out of date for at least MSE
1885 // case because MediaSource and SourceBuffer do not notify the element 1885 // case because MediaSource and SourceBuffer do not notify the element
1886 // directly upon duration changes caused by endOfStream, remove, or append 1886 // directly upon duration changes caused by endOfStream, remove, or append
1887 // operations; rather the notification is triggered by the WebMediaPlayer 1887 // operations; rather the notification is triggered by the WebMediaPlayer
1888 // implementation observing that the underlying engine has updated duration 1888 // implementation observing that the underlying engine has updated duration
1889 // and notifying the element to consult its MediaSource for current 1889 // and notifying the element to consult its MediaSource for current
1890 // duration. See http://crbug.com/266644 1890 // duration. See http://crbug.com/266644
1891 1891
1892 if (m_mediaSource) 1892 if (m_mediaSource)
1893 return m_mediaSource->duration(); 1893 return m_mediaSource->duration();
1894 1894
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1934 1934
1935 HTMLMediaElement::DirectionOfPlayback HTMLMediaElement::getDirectionOfPlayback() const 1935 HTMLMediaElement::DirectionOfPlayback HTMLMediaElement::getDirectionOfPlayback() const
1936 { 1936 {
1937 return m_playbackRate >= 0 ? Forward : Backward; 1937 return m_playbackRate >= 0 ? Forward : Backward;
1938 } 1938 }
1939 1939
1940 void HTMLMediaElement::updatePlaybackRate() 1940 void HTMLMediaElement::updatePlaybackRate()
1941 { 1941 {
1942 // FIXME: remove m_webMediaPlayer check once we figure out how 1942 // FIXME: remove m_webMediaPlayer check once we figure out how
1943 // m_webMediaPlayer is going out of sync with readystate. 1943 // m_webMediaPlayer is going out of sync with readystate.
1944 // m_webMediaPlayer is cleared but readystate is not set to HAVE_NOTHING. 1944 // m_webMediaPlayer is cleared but readystate is not set to kHaveNothing.
1945 if (m_webMediaPlayer && potentiallyPlaying()) 1945 if (m_webMediaPlayer && potentiallyPlaying())
1946 webMediaPlayer()->setRate(playbackRate()); 1946 webMediaPlayer()->setRate(playbackRate());
1947 } 1947 }
1948 1948
1949 bool HTMLMediaElement::ended() const 1949 bool HTMLMediaElement::ended() const
1950 { 1950 {
1951 // 4.8.10.8 Playing the media resource 1951 // 4.8.10.8 Playing the media resource
1952 // The ended attribute must return true if the media element has ended 1952 // The ended attribute must return true if the media element has ended
1953 // playback and the direction of playback is forwards, and false otherwise. 1953 // playback and the direction of playback is forwards, and false otherwise.
1954 return endedPlayback() && getDirectionOfPlayback() == Forward; 1954 return endedPlayback() && getDirectionOfPlayback() == Forward;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
2098 document().addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMessageLevel, message)); 2098 document().addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMessageLevel, message));
2099 return NotAllowedError; 2099 return NotAllowedError;
2100 } 2100 }
2101 } else { 2101 } else {
2102 UserGestureIndicator::utilizeUserGesture(); 2102 UserGestureIndicator::utilizeUserGesture();
2103 // We ask the helper to remove the gesture requirement for us, so that 2103 // We ask the helper to remove the gesture requirement for us, so that
2104 // it can record the reason. 2104 // it can record the reason.
2105 m_autoplayHelper->unlockUserGesture(GesturelessPlaybackEnabledByPlayMeth od); 2105 m_autoplayHelper->unlockUserGesture(GesturelessPlaybackEnabledByPlayMeth od);
2106 } 2106 }
2107 2107
2108 if (m_error && m_error->code() == MediaError::MEDIA_ERR_SRC_NOT_SUPPORTED) 2108 if (m_error && m_error->code() == MediaError::kMediaErrSrcNotSupported)
2109 return NotSupportedError; 2109 return NotSupportedError;
2110 2110
2111 playInternal(); 2111 playInternal();
2112 2112
2113 return nullptr; 2113 return nullptr;
2114 } 2114 }
2115 2115
2116 void HTMLMediaElement::playInternal() 2116 void HTMLMediaElement::playInternal()
2117 { 2117 {
2118 BLINK_MEDIA_LOG << "playInternal(" << (void*)this << ")"; 2118 BLINK_MEDIA_LOG << "playInternal(" << (void*)this << ")";
2119 2119
2120 // Always return the buffering strategy to normal when not paused, 2120 // Always return the buffering strategy to normal when not paused,
2121 // regardless of the cause. (In contrast with aggressive buffering which is 2121 // regardless of the cause. (In contrast with aggressive buffering which is
2122 // only enabled by pause(), not pauseInternal().) 2122 // only enabled by pause(), not pauseInternal().)
2123 if (webMediaPlayer()) 2123 if (webMediaPlayer())
2124 webMediaPlayer()->setBufferingStrategy(WebMediaPlayer::BufferingStrategy ::Normal); 2124 webMediaPlayer()->setBufferingStrategy(WebMediaPlayer::BufferingStrategy ::Normal);
2125 2125
2126 // 4.8.10.9. Playing the media resource 2126 // 4.8.10.9. Playing the media resource
2127 if (m_networkState == NETWORK_EMPTY) 2127 if (m_networkState == kNetworkEmpty)
2128 invokeResourceSelectionAlgorithm(); 2128 invokeResourceSelectionAlgorithm();
2129 2129
2130 // Generally "ended" and "looping" are exclusive. Here, the loop attribute 2130 // Generally "ended" and "looping" are exclusive. Here, the loop attribute
2131 // is ignored to seek back to start in case loop was set after playback 2131 // is ignored to seek back to start in case loop was set after playback
2132 // ended. See http://crbug.com/364442 2132 // ended. See http://crbug.com/364442
2133 if (endedPlayback(LoopCondition::Ignored)) 2133 if (endedPlayback(LoopCondition::Ignored))
2134 seek(0); 2134 seek(0);
2135 2135
2136 if (m_paused) { 2136 if (m_paused) {
2137 m_paused = false; 2137 m_paused = false;
2138 invalidateCachedTime(); 2138 invalidateCachedTime();
2139 scheduleEvent(EventTypeNames::play); 2139 scheduleEvent(EventTypeNames::play);
2140 2140
2141 if (m_readyState <= HAVE_CURRENT_DATA) 2141 if (m_readyState <= kHaveCurrentData)
2142 scheduleEvent(EventTypeNames::waiting); 2142 scheduleEvent(EventTypeNames::waiting);
2143 else if (m_readyState >= HAVE_FUTURE_DATA) 2143 else if (m_readyState >= kHaveFutureData)
2144 scheduleNotifyPlaying(); 2144 scheduleNotifyPlaying();
2145 } else if (m_readyState >= HAVE_FUTURE_DATA) { 2145 } else if (m_readyState >= kHaveFutureData) {
2146 scheduleResolvePlayPromises(); 2146 scheduleResolvePlayPromises();
2147 } 2147 }
2148 2148
2149 m_autoplaying = false; 2149 m_autoplaying = false;
2150 2150
2151 setIgnorePreloadNone(); 2151 setIgnorePreloadNone();
2152 updatePlayState(); 2152 updatePlayState();
2153 } 2153 }
2154 2154
2155 void HTMLMediaElement::pause() 2155 void HTMLMediaElement::pause()
2156 { 2156 {
2157 BLINK_MEDIA_LOG << "pause(" << (void*)this << ")"; 2157 BLINK_MEDIA_LOG << "pause(" << (void*)this << ")";
2158 2158
2159 // Only buffer aggressively on a user-initiated pause. Other types of pauses 2159 // Only buffer aggressively on a user-initiated pause. Other types of pauses
2160 // (which go directly to pauseInternal()) should not cause this behavior. 2160 // (which go directly to pauseInternal()) should not cause this behavior.
2161 if (webMediaPlayer() && UserGestureIndicator::utilizeUserGesture()) 2161 if (webMediaPlayer() && UserGestureIndicator::utilizeUserGesture())
2162 webMediaPlayer()->setBufferingStrategy(WebMediaPlayer::BufferingStrategy ::Aggressive); 2162 webMediaPlayer()->setBufferingStrategy(WebMediaPlayer::BufferingStrategy ::Aggressive);
2163 2163
2164 pauseInternal(); 2164 pauseInternal();
2165 } 2165 }
2166 2166
2167 void HTMLMediaElement::pauseInternal() 2167 void HTMLMediaElement::pauseInternal()
2168 { 2168 {
2169 BLINK_MEDIA_LOG << "pauseInternal(" << (void*)this << ")"; 2169 BLINK_MEDIA_LOG << "pauseInternal(" << (void*)this << ")";
2170 2170
2171 if (m_networkState == NETWORK_EMPTY) 2171 if (m_networkState == kNetworkEmpty)
2172 invokeResourceSelectionAlgorithm(); 2172 invokeResourceSelectionAlgorithm();
2173 2173
2174 m_autoplayHelper->pauseMethodCalled(); 2174 m_autoplayHelper->pauseMethodCalled();
2175 2175
2176 m_autoplaying = false; 2176 m_autoplaying = false;
2177 2177
2178 if (!m_paused) { 2178 if (!m_paused) {
2179 m_paused = true; 2179 m_paused = true;
2180 scheduleTimeupdateEvent(false); 2180 scheduleTimeupdateEvent(false);
2181 scheduleEvent(EventTypeNames::pause); 2181 scheduleEvent(EventTypeNames::pause);
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
2793 KURL url = source->getNonEmptyURLAttribute(srcAttr); 2793 KURL url = source->getNonEmptyURLAttribute(srcAttr);
2794 BLINK_MEDIA_LOG << "sourceWasAdded(" << (void*)this << ") - 'src' is " << ur lForLoggingMedia(url); 2794 BLINK_MEDIA_LOG << "sourceWasAdded(" << (void*)this << ") - 'src' is " << ur lForLoggingMedia(url);
2795 2795
2796 // We should only consider a <source> element when there is not src attribut e at all. 2796 // We should only consider a <source> element when there is not src attribut e at all.
2797 if (fastHasAttribute(srcAttr)) 2797 if (fastHasAttribute(srcAttr))
2798 return; 2798 return;
2799 2799
2800 // 4.8.8 - If a source element is inserted as a child of a media element tha t has no src 2800 // 4.8.8 - If a source element is inserted as a child of a media element tha t has no src
2801 // attribute and whose networkState has the value NETWORK_EMPTY, the user ag ent must invoke 2801 // attribute and whose networkState has the value NETWORK_EMPTY, the user ag ent must invoke
2802 // the media element's resource selection algorithm. 2802 // the media element's resource selection algorithm.
2803 if (getNetworkState() == HTMLMediaElement::NETWORK_EMPTY) { 2803 if (getNetworkState() == HTMLMediaElement::kNetworkEmpty) {
2804 invokeResourceSelectionAlgorithm(); 2804 invokeResourceSelectionAlgorithm();
2805 // Ignore current |m_nextChildNodeToConsider| and consider |source|. 2805 // Ignore current |m_nextChildNodeToConsider| and consider |source|.
2806 m_nextChildNodeToConsider = source; 2806 m_nextChildNodeToConsider = source;
2807 return; 2807 return;
2808 } 2808 }
2809 2809
2810 if (m_currentSourceNode && source == m_currentSourceNode->nextSibling()) { 2810 if (m_currentSourceNode && source == m_currentSourceNode->nextSibling()) {
2811 BLINK_MEDIA_LOG << "sourceWasAdded(" << (void*)this << ") - <source> ins erted immediately after current source"; 2811 BLINK_MEDIA_LOG << "sourceWasAdded(" << (void*)this << ") - <source> ins erted immediately after current source";
2812 // Ignore current |m_nextChildNodeToConsider| and consider |source|. 2812 // Ignore current |m_nextChildNodeToConsider| and consider |source|.
2813 m_nextChildNodeToConsider = source; 2813 m_nextChildNodeToConsider = source;
2814 return; 2814 return;
2815 } 2815 }
2816 2816
2817 // Consider current |m_nextChildNodeToConsider| as it is already in the midd le of processing. 2817 // Consider current |m_nextChildNodeToConsider| as it is already in the midd le of processing.
2818 if (m_nextChildNodeToConsider) 2818 if (m_nextChildNodeToConsider)
2819 return; 2819 return;
2820 2820
2821 if (m_loadState != WaitingForSource) 2821 if (m_loadState != WaitingForSource)
2822 return; 2822 return;
2823 2823
2824 // 4.8.9.5, resource selection algorithm, source elements section: 2824 // 4.8.9.5, resource selection algorithm, source elements section:
2825 // 21. Wait until the node after pointer is a node other than the end of the list. (This step might wait forever.) 2825 // 21. Wait until the node after pointer is a node other than the end of the list. (This step might wait forever.)
2826 // 22. Asynchronously await a stable state... 2826 // 22. Asynchronously await a stable state...
2827 // 23. Set the element's delaying-the-load-event flag back to true (this del ays the load event again, in case 2827 // 23. Set the element's delaying-the-load-event flag back to true (this del ays the load event again, in case
2828 // it hasn't been fired yet). 2828 // it hasn't been fired yet).
2829 setShouldDelayLoadEvent(true); 2829 setShouldDelayLoadEvent(true);
2830 2830
2831 // 24. Set the networkState back to NETWORK_LOADING. 2831 // 24. Set the networkState back to NETWORK_LOADING.
2832 setNetworkState(NETWORK_LOADING); 2832 setNetworkState(kNetworkLoading);
2833 2833
2834 // 25. Jump back to the find next candidate step above. 2834 // 25. Jump back to the find next candidate step above.
2835 m_nextChildNodeToConsider = source; 2835 m_nextChildNodeToConsider = source;
2836 scheduleNextSourceChild(); 2836 scheduleNextSourceChild();
2837 } 2837 }
2838 2838
2839 void HTMLMediaElement::sourceWasRemoved(HTMLSourceElement* source) 2839 void HTMLMediaElement::sourceWasRemoved(HTMLSourceElement* source)
2840 { 2840 {
2841 BLINK_MEDIA_LOG << "sourceWasRemoved(" << (void*)this << ", " << source << " )"; 2841 BLINK_MEDIA_LOG << "sourceWasRemoved(" << (void*)this << ", " << source << " )";
2842 2842
(...skipping 18 matching lines...) Expand all
2861 2861
2862 void HTMLMediaElement::timeChanged() 2862 void HTMLMediaElement::timeChanged()
2863 { 2863 {
2864 BLINK_MEDIA_LOG << "timeChanged(" << (void*)this << ")"; 2864 BLINK_MEDIA_LOG << "timeChanged(" << (void*)this << ")";
2865 2865
2866 cueTimeline().updateActiveCues(currentTime()); 2866 cueTimeline().updateActiveCues(currentTime());
2867 2867
2868 invalidateCachedTime(); 2868 invalidateCachedTime();
2869 2869
2870 // 4.8.10.9 steps 12-14. Needed if no ReadyState change is associated with t he seek. 2870 // 4.8.10.9 steps 12-14. Needed if no ReadyState change is associated with t he seek.
2871 if (m_seeking && m_readyState >= HAVE_CURRENT_DATA && !webMediaPlayer()->see king()) 2871 if (m_seeking && m_readyState >= kHaveCurrentData && !webMediaPlayer()->seek ing())
2872 finishSeek(); 2872 finishSeek();
2873 2873
2874 // Always call scheduleTimeupdateEvent when the media engine reports a time discontinuity, 2874 // Always call scheduleTimeupdateEvent when the media engine reports a time discontinuity,
2875 // it will only queue a 'timeupdate' event if we haven't already posted one at the current 2875 // it will only queue a 'timeupdate' event if we haven't already posted one at the current
2876 // movie time. 2876 // movie time.
2877 scheduleTimeupdateEvent(false); 2877 scheduleTimeupdateEvent(false);
2878 2878
2879 double now = currentTime(); 2879 double now = currentTime();
2880 double dur = duration(); 2880 double dur = duration();
2881 2881
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
3003 updateDisplayState(); 3003 updateDisplayState();
3004 if (layoutObject()) 3004 if (layoutObject())
3005 layoutObject()->setShouldDoFullPaintInvalidation(); 3005 layoutObject()->setShouldDoFullPaintInvalidation();
3006 } 3006 }
3007 3007
3008 void HTMLMediaElement::sizeChanged() 3008 void HTMLMediaElement::sizeChanged()
3009 { 3009 {
3010 BLINK_MEDIA_LOG << "sizeChanged(" << (void*)this << ")"; 3010 BLINK_MEDIA_LOG << "sizeChanged(" << (void*)this << ")";
3011 3011
3012 DCHECK(hasVideo()); // "resize" makes no sense in absence of video. 3012 DCHECK(hasVideo()); // "resize" makes no sense in absence of video.
3013 if (m_readyState > HAVE_NOTHING && isHTMLVideoElement()) 3013 if (m_readyState > kHaveNothing && isHTMLVideoElement())
3014 scheduleEvent(EventTypeNames::resize); 3014 scheduleEvent(EventTypeNames::resize);
3015 3015
3016 if (layoutObject()) 3016 if (layoutObject())
3017 layoutObject()->updateFromElement(); 3017 layoutObject()->updateFromElement();
3018 } 3018 }
3019 3019
3020 TimeRanges* HTMLMediaElement::buffered() const 3020 TimeRanges* HTMLMediaElement::buffered() const
3021 { 3021 {
3022 if (m_mediaSource) 3022 if (m_mediaSource)
3023 return m_mediaSource->buffered(); 3023 return m_mediaSource->buffered();
(...skipping 27 matching lines...) Expand all
3051 return m_mediaSource->seekable(); 3051 return m_mediaSource->seekable();
3052 3052
3053 return TimeRanges::create(webMediaPlayer()->seekable()); 3053 return TimeRanges::create(webMediaPlayer()->seekable());
3054 } 3054 }
3055 3055
3056 bool HTMLMediaElement::potentiallyPlaying() const 3056 bool HTMLMediaElement::potentiallyPlaying() const
3057 { 3057 {
3058 // "pausedToBuffer" means the media engine's rate is 0, but only because it had to stop playing 3058 // "pausedToBuffer" means the media engine's rate is 0, but only because it had to stop playing
3059 // when it ran out of buffered data. A movie in this state is "potentially p laying", modulo the 3059 // when it ran out of buffered data. A movie in this state is "potentially p laying", modulo the
3060 // checks in couldPlayIfEnoughData(). 3060 // checks in couldPlayIfEnoughData().
3061 bool pausedToBuffer = m_readyStateMaximum >= HAVE_FUTURE_DATA && m_readyStat e < HAVE_FUTURE_DATA; 3061 bool pausedToBuffer = m_readyStateMaximum >= kHaveFutureData && m_readyState < kHaveFutureData;
3062 return (pausedToBuffer || m_readyState >= HAVE_FUTURE_DATA) && couldPlayIfEn oughData(); 3062 return (pausedToBuffer || m_readyState >= kHaveFutureData) && couldPlayIfEno ughData();
3063 } 3063 }
3064 3064
3065 bool HTMLMediaElement::couldPlayIfEnoughData() const 3065 bool HTMLMediaElement::couldPlayIfEnoughData() const
3066 { 3066 {
3067 return !paused() && !endedPlayback() && !stoppedDueToErrors(); 3067 return !paused() && !endedPlayback() && !stoppedDueToErrors();
3068 } 3068 }
3069 3069
3070 bool HTMLMediaElement::endedPlayback(LoopCondition loopCondition) const 3070 bool HTMLMediaElement::endedPlayback(LoopCondition loopCondition) const
3071 { 3071 {
3072 double dur = duration(); 3072 double dur = duration();
3073 if (std::isnan(dur)) 3073 if (std::isnan(dur))
3074 return false; 3074 return false;
3075 3075
3076 // 4.8.10.8 Playing the media resource 3076 // 4.8.10.8 Playing the media resource
3077 3077
3078 // A media element is said to have ended playback when the element's 3078 // A media element is said to have ended playback when the element's
3079 // readyState attribute is HAVE_METADATA or greater, 3079 // readyState attribute is HAVE_METADATA or greater,
3080 if (m_readyState < HAVE_METADATA) 3080 if (m_readyState < kHaveMetadata)
3081 return false; 3081 return false;
3082 3082
3083 // and the current playback position is the end of the media resource and th e direction 3083 // and the current playback position is the end of the media resource and th e direction
3084 // of playback is forwards, Either the media element does not have a loop at tribute specified, 3084 // of playback is forwards, Either the media element does not have a loop at tribute specified,
3085 double now = currentTime(); 3085 double now = currentTime();
3086 if (getDirectionOfPlayback() == Forward) 3086 if (getDirectionOfPlayback() == Forward)
3087 return dur > 0 && now >= dur && (loopCondition == LoopCondition::Ignored || !loop()); 3087 return dur > 0 && now >= dur && (loopCondition == LoopCondition::Ignored || !loop());
3088 3088
3089 // or the current playback position is the earliest possible position and th e direction 3089 // or the current playback position is the earliest possible position and th e direction
3090 // of playback is backwards 3090 // of playback is backwards
3091 DCHECK_EQ(getDirectionOfPlayback(), Backward); 3091 DCHECK_EQ(getDirectionOfPlayback(), Backward);
3092 return now <= 0; 3092 return now <= 0;
3093 } 3093 }
3094 3094
3095 bool HTMLMediaElement::stoppedDueToErrors() const 3095 bool HTMLMediaElement::stoppedDueToErrors() const
3096 { 3096 {
3097 if (m_readyState >= HAVE_METADATA && m_error) { 3097 if (m_readyState >= kHaveMetadata && m_error) {
3098 TimeRanges* seekableRanges = seekable(); 3098 TimeRanges* seekableRanges = seekable();
3099 if (!seekableRanges->contain(currentTime())) 3099 if (!seekableRanges->contain(currentTime()))
3100 return true; 3100 return true;
3101 } 3101 }
3102 3102
3103 return false; 3103 return false;
3104 } 3104 }
3105 3105
3106 void HTMLMediaElement::updatePlayState() 3106 void HTMLMediaElement::updatePlayState()
3107 { 3107 {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
3198 void HTMLMediaElement::stop() 3198 void HTMLMediaElement::stop()
3199 { 3199 {
3200 BLINK_MEDIA_LOG << "stop(" << (void*)this << ")"; 3200 BLINK_MEDIA_LOG << "stop(" << (void*)this << ")";
3201 3201
3202 // Close the async event queue so that no events are enqueued. 3202 // Close the async event queue so that no events are enqueued.
3203 cancelPendingEventsAndCallbacks(); 3203 cancelPendingEventsAndCallbacks();
3204 m_asyncEventQueue->close(); 3204 m_asyncEventQueue->close();
3205 3205
3206 // Clear everything in the Media Element 3206 // Clear everything in the Media Element
3207 clearMediaPlayer(); 3207 clearMediaPlayer();
3208 m_readyState = HAVE_NOTHING; 3208 m_readyState = kHaveNothing;
3209 m_readyStateMaximum = HAVE_NOTHING; 3209 m_readyStateMaximum = kHaveNothing;
3210 setNetworkState(NETWORK_EMPTY); 3210 setNetworkState(kNetworkEmpty);
3211 setShouldDelayLoadEvent(false); 3211 setShouldDelayLoadEvent(false);
3212 m_currentSourceNode = nullptr; 3212 m_currentSourceNode = nullptr;
3213 invalidateCachedTime(); 3213 invalidateCachedTime();
3214 cueTimeline().updateActiveCues(0); 3214 cueTimeline().updateActiveCues(0);
3215 m_playing = false; 3215 m_playing = false;
3216 m_paused = true; 3216 m_paused = true;
3217 m_seeking = false; 3217 m_seeking = false;
3218 3218
3219 if (layoutObject()) 3219 if (layoutObject())
3220 layoutObject()->updateFromElement(); 3220 layoutObject()->updateFromElement();
3221 3221
3222 stopPeriodicTimers(); 3222 stopPeriodicTimers();
3223 3223
3224 // Ensure that hasPendingActivity() is not preventing garbage collection, si nce otherwise this 3224 // Ensure that hasPendingActivity() is not preventing garbage collection, si nce otherwise this
3225 // media element will simply leak. 3225 // media element will simply leak.
3226 DCHECK(!hasPendingActivity()); 3226 DCHECK(!hasPendingActivity());
3227 } 3227 }
3228 3228
3229 bool HTMLMediaElement::hasPendingActivity() const 3229 bool HTMLMediaElement::hasPendingActivity() const
3230 { 3230 {
3231 // The delaying-the-load-event flag is set by resource selection algorithm w hen looking for a 3231 // The delaying-the-load-event flag is set by resource selection algorithm w hen looking for a
3232 // resource to load, before networkState has reached to NETWORK_LOADING. 3232 // resource to load, before networkState has reached to kNetworkLoading.
3233 if (m_shouldDelayLoadEvent) 3233 if (m_shouldDelayLoadEvent)
3234 return true; 3234 return true;
3235 3235
3236 // When networkState is NETWORK_LOADING, progress and stalled events may be fired. 3236 // When networkState is kNetworkLoading, progress and stalled events may be fired.
3237 if (m_networkState == NETWORK_LOADING) 3237 if (m_networkState == kNetworkLoading)
3238 return true; 3238 return true;
3239 3239
3240 // When playing or if playback may continue, timeupdate events may be fired. 3240 // When playing or if playback may continue, timeupdate events may be fired.
3241 if (couldPlayIfEnoughData()) 3241 if (couldPlayIfEnoughData())
3242 return true; 3242 return true;
3243 3243
3244 // When the seek finishes timeupdate and seeked events will be fired. 3244 // When the seek finishes timeupdate and seeked events will be fired.
3245 if (m_seeking) 3245 if (m_seeking)
3246 return true; 3246 return true;
3247 3247
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after
4020 4020
4021 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect() co nst 4021 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect() co nst
4022 { 4022 {
4023 IntRect result; 4023 IntRect result;
4024 if (LayoutObject* object = m_element->layoutObject()) 4024 if (LayoutObject* object = m_element->layoutObject())
4025 result = object->absoluteBoundingBoxRect(); 4025 result = object->absoluteBoundingBoxRect();
4026 return result; 4026 return result;
4027 } 4027 }
4028 4028
4029 } // namespace blink 4029 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLMediaElement.h ('k') | third_party/WebKit/Source/core/html/HTMLTrackElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698