Chromium Code Reviews| 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 30 matching lines...) Expand all Loading... | |
| 41 #include "core/frame/LocalFrame.h" | 41 #include "core/frame/LocalFrame.h" |
| 42 #include "core/frame/Settings.h" | 42 #include "core/frame/Settings.h" |
| 43 #include "core/frame/UseCounter.h" | 43 #include "core/frame/UseCounter.h" |
| 44 #include "core/frame/csp/ContentSecurityPolicy.h" | 44 #include "core/frame/csp/ContentSecurityPolicy.h" |
| 45 #include "core/html/HTMLMediaSource.h" | 45 #include "core/html/HTMLMediaSource.h" |
| 46 #include "core/html/HTMLSourceElement.h" | 46 #include "core/html/HTMLSourceElement.h" |
| 47 #include "core/html/HTMLTrackElement.h" | 47 #include "core/html/HTMLTrackElement.h" |
| 48 #include "core/html/MediaController.h" | 48 #include "core/html/MediaController.h" |
| 49 #include "core/html/MediaError.h" | 49 #include "core/html/MediaError.h" |
| 50 #include "core/html/MediaFragmentURIParser.h" | 50 #include "core/html/MediaFragmentURIParser.h" |
| 51 #include "core/html/MediaProvider.h" | |
| 51 #include "core/html/TimeRanges.h" | 52 #include "core/html/TimeRanges.h" |
| 52 #include "core/html/shadow/MediaControls.h" | 53 #include "core/html/shadow/MediaControls.h" |
| 53 #include "core/html/track/AudioTrack.h" | 54 #include "core/html/track/AudioTrack.h" |
| 54 #include "core/html/track/AudioTrackList.h" | 55 #include "core/html/track/AudioTrackList.h" |
| 55 #include "core/html/track/InbandTextTrack.h" | 56 #include "core/html/track/InbandTextTrack.h" |
| 56 #include "core/html/track/TextTrackCueList.h" | 57 #include "core/html/track/TextTrackCueList.h" |
| 57 #include "core/html/track/TextTrackList.h" | 58 #include "core/html/track/TextTrackList.h" |
| 58 #include "core/html/track/VideoTrack.h" | 59 #include "core/html/track/VideoTrack.h" |
| 59 #include "core/html/track/VideoTrackList.h" | 60 #include "core/html/track/VideoTrackList.h" |
| 60 #include "core/loader/FrameLoader.h" | 61 #include "core/loader/FrameLoader.h" |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 , m_networkState(NETWORK_EMPTY) | 319 , m_networkState(NETWORK_EMPTY) |
| 319 , m_readyState(HAVE_NOTHING) | 320 , m_readyState(HAVE_NOTHING) |
| 320 , m_readyStateMaximum(HAVE_NOTHING) | 321 , m_readyStateMaximum(HAVE_NOTHING) |
| 321 , m_volume(1.0f) | 322 , m_volume(1.0f) |
| 322 , m_lastSeekTime(0) | 323 , m_lastSeekTime(0) |
| 323 , m_previousProgressTime(std::numeric_limits<double>::max()) | 324 , m_previousProgressTime(std::numeric_limits<double>::max()) |
| 324 , m_duration(std::numeric_limits<double>::quiet_NaN()) | 325 , m_duration(std::numeric_limits<double>::quiet_NaN()) |
| 325 , m_lastTimeUpdateEventWallTime(0) | 326 , m_lastTimeUpdateEventWallTime(0) |
| 326 , m_defaultPlaybackStartPosition(0) | 327 , m_defaultPlaybackStartPosition(0) |
| 327 , m_loadState(WaitingForSource) | 328 , m_loadState(WaitingForSource) |
| 329 , m_srcObject(std::nullptr_t()) | |
|
sof
2014/09/18 07:33:17
m_srcObject(nullptr)
perkj_chrome
2014/09/18 14:47:08
Done.
| |
| 328 , m_deferredLoadState(NotDeferred) | 330 , m_deferredLoadState(NotDeferred) |
| 329 , m_deferredLoadTimer(this, &HTMLMediaElement::deferredLoadTimerFired) | 331 , m_deferredLoadTimer(this, &HTMLMediaElement::deferredLoadTimerFired) |
| 330 , m_webLayer(0) | 332 , m_webLayer(0) |
| 331 , m_preload(MediaPlayer::Auto) | 333 , m_preload(MediaPlayer::Auto) |
| 332 , m_displayMode(Unknown) | 334 , m_displayMode(Unknown) |
| 333 , m_cachedTime(MediaPlayer::invalidTime()) | 335 , m_cachedTime(MediaPlayer::invalidTime()) |
| 334 , m_fragmentStartTime(MediaPlayer::invalidTime()) | 336 , m_fragmentStartTime(MediaPlayer::invalidTime()) |
| 335 , m_fragmentEndTime(MediaPlayer::invalidTime()) | 337 , m_fragmentEndTime(MediaPlayer::invalidTime()) |
| 336 , m_pendingActionFlags(0) | 338 , m_pendingActionFlags(0) |
| 337 , m_userGestureRequiredForPlay(false) | 339 , m_userGestureRequiredForPlay(false) |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 672 } | 674 } |
| 673 | 675 |
| 674 m_pendingActionFlags = 0; | 676 m_pendingActionFlags = 0; |
| 675 } | 677 } |
| 676 | 678 |
| 677 PassRefPtrWillBeRawPtr<MediaError> HTMLMediaElement::error() const | 679 PassRefPtrWillBeRawPtr<MediaError> HTMLMediaElement::error() const |
| 678 { | 680 { |
| 679 return m_error; | 681 return m_error; |
| 680 } | 682 } |
| 681 | 683 |
| 684 MediaProvider* HTMLMediaElement::srcObject() const | |
| 685 { | |
| 686 return m_srcObject.get(); | |
| 687 } | |
| 688 | |
| 689 void HTMLMediaElement::setSrcObject(MediaProvider* mediaProvider) | |
| 690 { | |
| 691 WTF_LOG(Media, "HTMLMediaElement::setSrcObject(%p)", this); | |
| 692 m_srcObject = mediaProvider; | |
| 693 clearMediaPlayer(LoadMediaResource); | |
| 694 load(); | |
| 695 } | |
| 696 | |
| 682 void HTMLMediaElement::setSrc(const AtomicString& url) | 697 void HTMLMediaElement::setSrc(const AtomicString& url) |
| 683 { | 698 { |
| 684 setAttribute(srcAttr, url); | 699 setAttribute(srcAttr, url); |
| 685 } | 700 } |
| 686 | 701 |
| 687 HTMLMediaElement::NetworkState HTMLMediaElement::networkState() const | 702 HTMLMediaElement::NetworkState HTMLMediaElement::networkState() const |
| 688 { | 703 { |
| 689 return m_networkState; | 704 return m_networkState; |
| 690 } | 705 } |
| 691 | 706 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 843 } | 858 } |
| 844 } | 859 } |
| 845 | 860 |
| 846 selectMediaResource(); | 861 selectMediaResource(); |
| 847 } | 862 } |
| 848 | 863 |
| 849 void HTMLMediaElement::selectMediaResource() | 864 void HTMLMediaElement::selectMediaResource() |
| 850 { | 865 { |
| 851 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource(%p)", this); | 866 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource(%p)", this); |
| 852 | 867 |
| 853 enum Mode { attribute, children }; | 868 enum Mode { Object, Attribute, Children }; |
| 854 | 869 |
| 855 // 3 - If the media element has a src attribute, then let mode be attribute. | 870 // 6 - If the media element has an assigned media provider object, then let mode be object. |
| 856 Mode mode = attribute; | 871 Mode mode; |
| 857 if (!fastHasAttribute(srcAttr)) { | 872 if (srcObject()) { |
| 858 // Otherwise, if the media element does not have a src attribute but has a source | 873 mode = Object; |
| 859 // element child, then let mode be children and let candidate be the fir st such | 874 } else if (fastHasAttribute(srcAttr)) { |
| 860 // source element child in tree order. | 875 // Otherwise, if the media element has no assigned media provider object but has a src attribute, then let mode be attribute. |
| 861 if (HTMLSourceElement* element = Traversal<HTMLSourceElement>::firstChil d(*this)) { | 876 mode = Attribute; |
| 862 mode = children; | 877 } else if (Traversal<HTMLSourceElement>::firstChild(*this)) { |
| 863 m_nextChildNodeToConsider = element; | 878 // Otherwise, if the media element does not have an assigned media provi der object and does not have a src attribute, |
| 864 m_currentSourceNode = nullptr; | 879 // but does have a source element child, then let mode be children and l et candidate be the first such source element child in tree order. |
| 865 } else { | 880 mode = Children; |
| 866 // Otherwise the media element has neither a src attribute nor a sou rce element | 881 HTMLSourceElement* element = Traversal<HTMLSourceElement>::firstChild(*t his); |
| 867 // child: set the networkState to NETWORK_EMPTY, and abort these ste ps; the | 882 m_nextChildNodeToConsider = element; |
| 868 // synchronous section ends. | 883 m_currentSourceNode = nullptr; |
| 869 m_loadState = WaitingForSource; | 884 } else { |
| 870 setShouldDelayLoadEvent(false); | 885 // Otherwise the media element has no source. |
| 871 m_networkState = NETWORK_EMPTY; | 886 // set the networkState to NETWORK_EMPTY, and abort these steps; the |
| 887 // synchronous section ends. | |
| 888 m_loadState = WaitingForSource; | |
| 889 setShouldDelayLoadEvent(false); | |
| 890 m_networkState = NETWORK_EMPTY; | |
| 872 | 891 |
| 873 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource(%p), nothing t o load", this); | 892 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource(%p), nothing to lo ad", this); |
| 874 return; | 893 return; |
| 875 } | |
| 876 } | 894 } |
| 877 | 895 |
| 878 // 4 - Set the media element's delaying-the-load-event flag to true (this de lays the load event), | 896 // 7 - Set the media element's delaying-the-load-event flag to true (this de lays the load event), |
| 879 // and set its networkState to NETWORK_LOADING. | 897 // and set its networkState to NETWORK_LOADING. |
| 880 setShouldDelayLoadEvent(true); | 898 setShouldDelayLoadEvent(true); |
| 881 m_networkState = NETWORK_LOADING; | 899 m_networkState = NETWORK_LOADING; |
| 882 | 900 |
| 883 // 5 - Queue a task to fire a simple event named loadstart at the media elem ent. | 901 // 8 - Queue a task to fire a simple event named loadstart at the media elem ent. |
| 884 scheduleEvent(EventTypeNames::loadstart); | 902 scheduleEvent(EventTypeNames::loadstart); |
| 885 | 903 |
| 886 // 6 - If mode is attribute, then run these substeps | 904 // 9 - Run the appropriate steps from the following list. |
| 887 if (mode == attribute) { | 905 switch (mode) { |
| 888 m_loadState = LoadingFromSrcAttr; | 906 case Object: |
| 907 loadFromObject(); | |
| 908 break; | |
| 909 case Attribute: | |
| 910 loadFromAttribute(); | |
| 911 break; | |
| 912 case Children: | |
| 913 loadNextSourceChild(); | |
| 914 break; | |
| 915 } | |
| 916 } | |
| 889 | 917 |
| 890 // If the src attribute's value is the empty string ... jump down to the failed step below | 918 void HTMLMediaElement::loadFromObject() |
| 891 KURL mediaURL = getNonEmptyURLAttribute(srcAttr); | 919 { |
| 892 if (mediaURL.isEmpty()) { | 920 m_loadState = LoadingFromSrcObject; |
| 893 mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError); | |
| 894 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource(%p), empty 'sr c'", this); | |
| 895 return; | |
| 896 } | |
| 897 | 921 |
| 898 if (!isSafeToLoadURL(mediaURL, Complain)) { | 922 KURL mediaURL = document().completeURL(m_srcObject->getObjectUrl()); |
| 899 mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError); | 923 ASSERT(isSafeToLoadURL(mediaURL, Complain)); |
| 900 return; | |
| 901 } | |
| 902 | 924 |
| 903 // No type or key system information is available when the url comes | 925 loadResource(mediaURL); |
| 904 // from the 'src' attribute so MediaPlayer | 926 |
| 905 // will have to pick a media engine based on the file extension. | 927 // Set the currentSrc attribute to the empty string. |
| 906 ContentType contentType((String())); | 928 // FIXME |m_currentSrc| is set in loadResource and then reset here. The reas on is that MediaProviders currently |
| 907 loadResource(mediaURL, contentType, String()); | 929 // uses a url for loading, and uses the same algorithm as if the src attribu te is set with createObjectURL. |
| 908 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource(%p), using 'src' a ttribute url", this); | 930 m_currentSrc = KURL(); |
| 931 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource, using 'srcObject' att ribute."); | |
| 932 return; | |
| 933 } | |
| 934 | |
| 935 void HTMLMediaElement::loadFromAttribute() | |
| 936 { | |
| 937 m_loadState = LoadingFromSrcAttr; | |
| 938 | |
| 939 // If the src attribute's value is the empty string ... jump down to the fai led step below | |
| 940 KURL mediaURL = getNonEmptyURLAttribute(srcAttr); | |
| 941 if (mediaURL.isEmpty()) { | |
| 942 mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError); | |
| 943 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource(%p), empty 'src'", this); | |
| 909 return; | 944 return; |
| 910 } | 945 } |
| 911 | 946 |
| 912 // Otherwise, the source elements will be used | 947 if (!isSafeToLoadURL(mediaURL, Complain)) { |
| 913 loadNextSourceChild(); | 948 mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError); |
| 949 return; | |
| 950 } | |
| 951 | |
| 952 loadResource(mediaURL); | |
| 953 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource(%p), using 'src' attri bute url", this); | |
| 954 return; | |
| 914 } | 955 } |
| 915 | 956 |
| 916 void HTMLMediaElement::loadNextSourceChild() | 957 void HTMLMediaElement::loadNextSourceChild() |
| 917 { | 958 { |
| 918 ContentType contentType((String())); | 959 ContentType contentType((String())); |
| 919 String keySystem; | 960 String keySystem; |
| 920 KURL mediaURL = selectNextSourceChild(&contentType, &keySystem, Complain); | 961 KURL mediaURL = selectNextSourceChild(&contentType, &keySystem, Complain); |
| 921 if (!mediaURL.isValid()) { | 962 if (!mediaURL.isValid()) { |
| 922 waitForSourceChange(); | 963 waitForSourceChange(); |
| 923 return; | 964 return; |
| 924 } | 965 } |
| 925 | 966 |
| 926 // Recreate the media player for the new url | 967 // Recreate the media player for the new url |
| 927 createMediaPlayer(); | 968 createMediaPlayer(); |
| 928 | 969 |
| 929 m_loadState = LoadingFromSourceElement; | 970 m_loadState = LoadingFromSourceElement; |
| 930 loadResource(mediaURL, contentType, keySystem); | 971 loadResource(mediaURL, contentType, keySystem); |
| 931 } | 972 } |
| 932 | 973 |
| 974 void HTMLMediaElement::loadResource(const KURL& url) | |
| 975 { | |
| 976 // No type or key system information is available when the url comes | |
| 977 // from the 'src' attribute or a srcObject. | |
| 978 ContentType contentType((String())); | |
|
sof
2014/09/18 07:33:17
redundant ()
perkj_chrome
2014/09/18 14:47:08
This does not compile without the extra parenthesi
sof
2014/09/19 06:26:23
Oh, I see. Why not use emptyString?
| |
| 979 loadResource(url, contentType, String()); | |
| 980 } | |
| 981 | |
| 933 void HTMLMediaElement::loadResource(const KURL& url, ContentType& contentType, c onst String& keySystem) | 982 void HTMLMediaElement::loadResource(const KURL& url, ContentType& contentType, c onst String& keySystem) |
| 934 { | 983 { |
| 935 ASSERT(isSafeToLoadURL(url, Complain)); | 984 ASSERT(isSafeToLoadURL(url, Complain)); |
| 936 | 985 |
| 937 WTF_LOG(Media, "HTMLMediaElement::loadResource(%p, %s, %s, %s)", this, urlFo rLoggingMedia(url).utf8().data(), contentType.raw().utf8().data(), keySystem.utf 8().data()); | 986 WTF_LOG(Media, "HTMLMediaElement::loadResource(%p, %s, %s, %s)", this, urlFo rLoggingMedia(url).utf8().data(), contentType.raw().utf8().data(), keySystem.utf 8().data()); |
| 938 | 987 |
| 939 LocalFrame* frame = document().frame(); | 988 LocalFrame* frame = document().frame(); |
| 940 if (!frame) { | 989 if (!frame) { |
| 941 mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError); | 990 mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError); |
| 942 return; | 991 return; |
| (...skipping 2981 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3924 mediaControls()->mediaElementFocused(); | 3973 mediaControls()->mediaElementFocused(); |
| 3925 } | 3974 } |
| 3926 HTMLElement::defaultEventHandler(event); | 3975 HTMLElement::defaultEventHandler(event); |
| 3927 } | 3976 } |
| 3928 | 3977 |
| 3929 void HTMLMediaElement::trace(Visitor* visitor) | 3978 void HTMLMediaElement::trace(Visitor* visitor) |
| 3930 { | 3979 { |
| 3931 visitor->trace(m_playedTimeRanges); | 3980 visitor->trace(m_playedTimeRanges); |
| 3932 visitor->trace(m_asyncEventQueue); | 3981 visitor->trace(m_asyncEventQueue); |
| 3933 visitor->trace(m_error); | 3982 visitor->trace(m_error); |
| 3934 visitor->trace(m_currentSourceNode); | 3983 visitor->trace(m_currentSourceNode); |
|
sof
2014/09/18 07:33:17
Fields that refer to objects that are on the Oilpa
perkj_chrome
2014/09/18 14:47:08
oops, right- thanks.
| |
| 3935 visitor->trace(m_nextChildNodeToConsider); | 3984 visitor->trace(m_nextChildNodeToConsider); |
| 3936 visitor->trace(m_mediaSource); | 3985 visitor->trace(m_mediaSource); |
| 3937 visitor->trace(m_audioTracks); | 3986 visitor->trace(m_audioTracks); |
| 3938 visitor->trace(m_videoTracks); | 3987 visitor->trace(m_videoTracks); |
| 3939 visitor->trace(m_textTracks); | 3988 visitor->trace(m_textTracks); |
| 3940 visitor->trace(m_textTracksWhenResourceSelectionBegan); | 3989 visitor->trace(m_textTracksWhenResourceSelectionBegan); |
| 3941 visitor->trace(m_mediaController); | 3990 visitor->trace(m_mediaController); |
| 3942 #if ENABLE(WEB_AUDIO) | 3991 #if ENABLE(WEB_AUDIO) |
| 3943 visitor->registerWeakMembers<HTMLMediaElement, &HTMLMediaElement::clearWeakM embers>(this); | 3992 visitor->registerWeakMembers<HTMLMediaElement, &HTMLMediaElement::clearWeakM embers>(this); |
| 3944 #endif | 3993 #endif |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3976 | 4025 |
| 3977 #if ENABLE(WEB_AUDIO) | 4026 #if ENABLE(WEB_AUDIO) |
| 3978 void HTMLMediaElement::clearWeakMembers(Visitor* visitor) | 4027 void HTMLMediaElement::clearWeakMembers(Visitor* visitor) |
| 3979 { | 4028 { |
| 3980 if (!visitor->isAlive(m_audioSourceNode) && audioSourceProvider()) | 4029 if (!visitor->isAlive(m_audioSourceNode) && audioSourceProvider()) |
| 3981 audioSourceProvider()->setClient(0); | 4030 audioSourceProvider()->setClient(0); |
| 3982 } | 4031 } |
| 3983 #endif | 4032 #endif |
| 3984 | 4033 |
| 3985 } | 4034 } |
| OLD | NEW |