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 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
327 , m_lastSeekTime(0) | 327 , m_lastSeekTime(0) |
328 , m_previousProgressTime(std::numeric_limits<double>::max()) | 328 , m_previousProgressTime(std::numeric_limits<double>::max()) |
329 , m_duration(std::numeric_limits<double>::quiet_NaN()) | 329 , m_duration(std::numeric_limits<double>::quiet_NaN()) |
330 , m_lastTimeUpdateEventWallTime(0) | 330 , m_lastTimeUpdateEventWallTime(0) |
331 , m_lastTimeUpdateEventMovieTime(0) | 331 , m_lastTimeUpdateEventMovieTime(0) |
332 , m_defaultPlaybackStartPosition(0) | 332 , m_defaultPlaybackStartPosition(0) |
333 , m_loadState(WaitingForSource) | 333 , m_loadState(WaitingForSource) |
334 , m_deferredLoadState(NotDeferred) | 334 , m_deferredLoadState(NotDeferred) |
335 , m_deferredLoadTimer(this, &HTMLMediaElement::deferredLoadTimerFired) | 335 , m_deferredLoadTimer(this, &HTMLMediaElement::deferredLoadTimerFired) |
336 , m_webLayer(nullptr) | 336 , m_webLayer(nullptr) |
337 , m_preload(MediaPlayer::Auto) | |
338 , m_displayMode(Unknown) | 337 , m_displayMode(Unknown) |
339 , m_cachedTime(std::numeric_limits<double>::quiet_NaN()) | 338 , m_cachedTime(std::numeric_limits<double>::quiet_NaN()) |
340 , m_fragmentEndTime(std::numeric_limits<double>::quiet_NaN()) | 339 , m_fragmentEndTime(std::numeric_limits<double>::quiet_NaN()) |
341 , m_pendingActionFlags(0) | 340 , m_pendingActionFlags(0) |
342 , m_userGestureRequiredForPlay(false) | 341 , m_userGestureRequiredForPlay(false) |
343 , m_playing(false) | 342 , m_playing(false) |
344 , m_shouldDelayLoadEvent(false) | 343 , m_shouldDelayLoadEvent(false) |
345 , m_haveFiredLoadedData(false) | 344 , m_haveFiredLoadedData(false) |
346 , m_autoplaying(true) | 345 , m_autoplaying(true) |
347 , m_muted(false) | 346 , m_muted(false) |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
527 { | 526 { |
528 if (name == srcAttr) { | 527 if (name == srcAttr) { |
529 // Trigger a reload, as long as the 'src' attribute is present. | 528 // Trigger a reload, as long as the 'src' attribute is present. |
530 if (!value.isNull()) { | 529 if (!value.isNull()) { |
531 clearMediaPlayer(LoadMediaResource); | 530 clearMediaPlayer(LoadMediaResource); |
532 scheduleDelayedAction(LoadMediaResource); | 531 scheduleDelayedAction(LoadMediaResource); |
533 } | 532 } |
534 } else if (name == controlsAttr) { | 533 } else if (name == controlsAttr) { |
535 configureMediaControls(); | 534 configureMediaControls(); |
536 } else if (name == preloadAttr) { | 535 } else if (name == preloadAttr) { |
537 if (equalIgnoringCase(value, "none")) { | |
538 m_preload = MediaPlayer::None; | |
539 } else if (equalIgnoringCase(value, "metadata")) { | |
540 m_preload = MediaPlayer::MetaData; | |
541 } else { | |
542 // The spec does not define an "invalid value default" but "auto" is suggested as the | |
543 // "missing value default", so use it for everything except "none" a nd "metadata" | |
544 m_preload = MediaPlayer::Auto; | |
545 } | |
546 | |
547 // The attribute must be ignored if the autoplay attribute is present | |
548 if (m_player) | 536 if (m_player) |
549 setPlayerPreload(); | 537 setPlayerPreload(); |
550 | |
551 } else if (name == mediagroupAttr && RuntimeEnabledFeatures::mediaController Enabled()) { | 538 } else if (name == mediagroupAttr && RuntimeEnabledFeatures::mediaController Enabled()) { |
552 setMediaGroup(value); | 539 setMediaGroup(value); |
553 } else { | 540 } else { |
554 HTMLElement::parseAttribute(name, value); | 541 HTMLElement::parseAttribute(name, value); |
555 } | 542 } |
556 } | 543 } |
557 | 544 |
558 void HTMLMediaElement::finishParsingChildren() | 545 void HTMLMediaElement::finishParsingChildren() |
559 { | 546 { |
560 HTMLElement::finishParsingChildren(); | 547 HTMLElement::finishParsingChildren(); |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
985 m_mediaSource = nullptr; | 972 m_mediaSource = nullptr; |
986 attemptLoad = false; | 973 attemptLoad = false; |
987 } | 974 } |
988 } | 975 } |
989 } | 976 } |
990 } | 977 } |
991 | 978 |
992 if (attemptLoad && canLoadURL(url, contentType, keySystem)) { | 979 if (attemptLoad && canLoadURL(url, contentType, keySystem)) { |
993 ASSERT(!webMediaPlayer()); | 980 ASSERT(!webMediaPlayer()); |
994 | 981 |
995 if (!m_havePreparedToPlay && !autoplay() && m_preload == MediaPlayer::No ne) { | 982 if (!m_havePreparedToPlay && !autoplay() && preloadType() == MediaPlayer ::None) { |
996 WTF_LOG(Media, "HTMLMediaElement::loadResource(%p) : Delaying load b ecause preload == 'none'", this); | 983 WTF_LOG(Media, "HTMLMediaElement::loadResource(%p) : Delaying load b ecause preload == 'none'", this); |
997 deferLoad(); | 984 deferLoad(); |
998 } else { | 985 } else { |
999 startPlayerLoad(); | 986 startPlayerLoad(); |
1000 } | 987 } |
1001 } else { | 988 } else { |
1002 mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError); | 989 mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError); |
1003 } | 990 } |
1004 | 991 |
1005 // If there is no poster to display, allow the media engine to render video frames as soon as | 992 // If there is no poster to display, allow the media engine to render video frames as soon as |
(...skipping 25 matching lines...) Expand all Loading... | |
1031 if (!requestURL.pass().isEmpty()) | 1018 if (!requestURL.pass().isEmpty()) |
1032 requestURL.setPass(String()); | 1019 requestURL.setPass(String()); |
1033 | 1020 |
1034 m_player->load(loadType(), requestURL, corsMode()); | 1021 m_player->load(loadType(), requestURL, corsMode()); |
1035 } | 1022 } |
1036 | 1023 |
1037 void HTMLMediaElement::setPlayerPreload() | 1024 void HTMLMediaElement::setPlayerPreload() |
1038 { | 1025 { |
1039 m_player->setPreload(effectivePreloadType()); | 1026 m_player->setPreload(effectivePreloadType()); |
1040 | 1027 |
1041 if (loadIsDeferred() && m_preload != MediaPlayer::None) | 1028 if (loadIsDeferred() && preloadType() != MediaPlayer::None) |
1042 startDeferredLoad(); | 1029 startDeferredLoad(); |
1043 } | 1030 } |
1044 | 1031 |
1045 bool HTMLMediaElement::loadIsDeferred() const | 1032 bool HTMLMediaElement::loadIsDeferred() const |
1046 { | 1033 { |
1047 return m_deferredLoadState != NotDeferred; | 1034 return m_deferredLoadState != NotDeferred; |
1048 } | 1035 } |
1049 | 1036 |
1050 void HTMLMediaElement::deferLoad() | 1037 void HTMLMediaElement::deferLoad() |
1051 { | 1038 { |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1608 | 1595 |
1609 void HTMLMediaElement::seek(double time) | 1596 void HTMLMediaElement::seek(double time) |
1610 { | 1597 { |
1611 WTF_LOG(Media, "HTMLMediaElement::seek(%p, %f)", this, time); | 1598 WTF_LOG(Media, "HTMLMediaElement::seek(%p, %f)", this, time); |
1612 | 1599 |
1613 // 2 - If the media element's readyState is HAVE_NOTHING, abort these steps. | 1600 // 2 - If the media element's readyState is HAVE_NOTHING, abort these steps. |
1614 if (m_readyState == HAVE_NOTHING) | 1601 if (m_readyState == HAVE_NOTHING) |
1615 return; | 1602 return; |
1616 | 1603 |
1617 // If the media engine has been told to postpone loading data, let it go ahe ad now. | 1604 // If the media engine has been told to postpone loading data, let it go ahe ad now. |
1618 if (m_preload < MediaPlayer::Auto && m_readyState < HAVE_FUTURE_DATA) | 1605 if (preloadType() < MediaPlayer::Auto && m_readyState < HAVE_FUTURE_DATA) |
1619 prepareToPlay(); | 1606 prepareToPlay(); |
1620 | 1607 |
1621 // Get the current time before setting m_seeking, m_lastSeekTime is returned once it is set. | 1608 // Get the current time before setting m_seeking, m_lastSeekTime is returned once it is set. |
1622 refreshCachedTime(); | 1609 refreshCachedTime(); |
1623 // This is needed to avoid getting default playback start position from curr entTime(). | 1610 // This is needed to avoid getting default playback start position from curr entTime(). |
1624 double now = m_cachedTime; | 1611 double now = m_cachedTime; |
1625 | 1612 |
1626 // 3 - If the element's seeking IDL attribute is true, then another instance of this algorithm is | 1613 // 3 - If the element's seeking IDL attribute is true, then another instance of this algorithm is |
1627 // already running. Abort that other instance of the algorithm without waiti ng for the step that | 1614 // already running. Abort that other instance of the algorithm without waiti ng for the step that |
1628 // it is running to complete. | 1615 // it is running to complete. |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1873 return endedPlayback() && directionOfPlayback() == Forward; | 1860 return endedPlayback() && directionOfPlayback() == Forward; |
1874 } | 1861 } |
1875 | 1862 |
1876 bool HTMLMediaElement::autoplay() const | 1863 bool HTMLMediaElement::autoplay() const |
1877 { | 1864 { |
1878 return fastHasAttribute(autoplayAttr); | 1865 return fastHasAttribute(autoplayAttr); |
1879 } | 1866 } |
1880 | 1867 |
1881 String HTMLMediaElement::preload() const | 1868 String HTMLMediaElement::preload() const |
1882 { | 1869 { |
1883 switch (m_preload) { | 1870 switch (preloadType()) { |
1884 case MediaPlayer::None: | 1871 case MediaPlayer::None: |
1885 return "none"; | 1872 return "none"; |
1886 break; | |
1887 case MediaPlayer::MetaData: | 1873 case MediaPlayer::MetaData: |
1888 return "metadata"; | 1874 return "metadata"; |
1889 break; | |
1890 case MediaPlayer::Auto: | 1875 case MediaPlayer::Auto: |
1891 return "auto"; | 1876 return "auto"; |
1892 break; | |
1893 } | 1877 } |
1894 | 1878 |
1895 ASSERT_NOT_REACHED(); | 1879 ASSERT_NOT_REACHED(); |
1896 return String(); | 1880 return String(); |
1897 } | 1881 } |
1898 | 1882 |
1899 void HTMLMediaElement::setPreload(const AtomicString& preload) | 1883 void HTMLMediaElement::setPreload(const AtomicString& preload) |
1900 { | 1884 { |
1901 WTF_LOG(Media, "HTMLMediaElement::setPreload(%p, %s)", this, preload.utf8(). data()); | 1885 WTF_LOG(Media, "HTMLMediaElement::setPreload(%p, %s)", this, preload.utf8(). data()); |
1902 setAttribute(preloadAttr, preload); | 1886 setAttribute(preloadAttr, preload); |
1903 } | 1887 } |
1904 | 1888 |
1889 MediaPlayer::Preload HTMLMediaElement::preloadType() const | |
1890 { | |
1891 // TODO(philipj): The spec requires case-sensitive string matching: | |
1892 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=28951 | |
1893 const AtomicString& preload = getAttribute(preloadAttr); | |
fs
2015/07/15 11:07:50
Nit: fastGetAttribute?
philipj_slow
2015/07/15 12:30:25
Yes of course, thanks :)
| |
1894 if (equalIgnoringCase(preload, "none")) { | |
1895 UseCounter::count(document(), UseCounter::HTMLMediaElementPreloadNone); | |
1896 return MediaPlayer::None; | |
1897 } | |
1898 if (equalIgnoringCase(preload, "metadata")) { | |
1899 UseCounter::count(document(), UseCounter::HTMLMediaElementPreloadMetadat a); | |
1900 return MediaPlayer::MetaData; | |
1901 } | |
1902 if (equalIgnoringCase(preload, "auto")) { | |
1903 UseCounter::count(document(), UseCounter::HTMLMediaElementPreloadAuto); | |
1904 return MediaPlayer::Auto; | |
1905 } | |
1906 | |
1907 // "The attribute's missing value default is user-agent defined, though the | |
1908 // Metadata state is suggested as a compromise between reducing server load | |
1909 // and providing an optimal user experience." | |
1910 | |
1911 // The spec does not define an invalid value default: | |
1912 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=28950 | |
1913 | |
1914 // TODO(philipj): Try to make "metadata" the default preload state: | |
1915 // https://crbug.com/310450 | |
1916 UseCounter::count(document(), UseCounter::HTMLMediaElementPreloadDefault); | |
1917 return MediaPlayer::Auto; | |
1918 } | |
1919 | |
1905 MediaPlayer::Preload HTMLMediaElement::effectivePreloadType() const | 1920 MediaPlayer::Preload HTMLMediaElement::effectivePreloadType() const |
1906 { | 1921 { |
1907 return autoplay() ? MediaPlayer::Auto : m_preload; | 1922 return autoplay() ? MediaPlayer::Auto : preloadType(); |
1908 } | 1923 } |
1909 | 1924 |
1910 void HTMLMediaElement::play() | 1925 void HTMLMediaElement::play() |
1911 { | 1926 { |
1912 WTF_LOG(Media, "HTMLMediaElement::play(%p)", this); | 1927 WTF_LOG(Media, "HTMLMediaElement::play(%p)", this); |
1913 | 1928 |
1914 if (!UserGestureIndicator::processingUserGesture()) { | 1929 if (!UserGestureIndicator::processingUserGesture()) { |
1915 autoplayMediaEncountered(); | 1930 autoplayMediaEncountered(); |
1916 if (m_userGestureRequiredForPlay) { | 1931 if (m_userGestureRequiredForPlay) { |
1917 String message = ExceptionMessages::failedToExecute("play", "HTMLMed iaElement", "API can only be initiated by a user gesture."); | 1932 String message = ExceptionMessages::failedToExecute("play", "HTMLMed iaElement", "API can only be initiated by a user gesture."); |
(...skipping 1772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3690 | 3705 |
3691 #if ENABLE(WEB_AUDIO) | 3706 #if ENABLE(WEB_AUDIO) |
3692 void HTMLMediaElement::clearWeakMembers(Visitor* visitor) | 3707 void HTMLMediaElement::clearWeakMembers(Visitor* visitor) |
3693 { | 3708 { |
3694 if (!Heap::isHeapObjectAlive(m_audioSourceNode) && audioSourceProvider()) | 3709 if (!Heap::isHeapObjectAlive(m_audioSourceNode) && audioSourceProvider()) |
3695 audioSourceProvider()->setClient(nullptr); | 3710 audioSourceProvider()->setClient(nullptr); |
3696 } | 3711 } |
3697 #endif | 3712 #endif |
3698 | 3713 |
3699 } | 3714 } |
OLD | NEW |