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 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 MediaError* HTMLMediaElement::error() const | 644 MediaError* HTMLMediaElement::error() const |
645 { | 645 { |
646 return m_error; | 646 return m_error; |
647 } | 647 } |
648 | 648 |
649 void HTMLMediaElement::setSrc(const AtomicString& url) | 649 void HTMLMediaElement::setSrc(const AtomicString& url) |
650 { | 650 { |
651 setAttribute(srcAttr, url); | 651 setAttribute(srcAttr, url); |
652 } | 652 } |
653 | 653 |
| 654 void HTMLMediaElement::setSrcObjectURL(const AtomicString& url) |
| 655 { |
| 656 // The srcObject IDL attribute, on setting, must set the element's assigned |
| 657 // media provider object to the new value, and then invoke the element's |
| 658 // media element load algorithm. |
| 659 m_srcObjectURL = url; |
| 660 invokeLoadAlgorithm(); |
| 661 } |
| 662 |
654 HTMLMediaElement::NetworkState HTMLMediaElement::getNetworkState() const | 663 HTMLMediaElement::NetworkState HTMLMediaElement::getNetworkState() const |
655 { | 664 { |
656 return m_networkState; | 665 return m_networkState; |
657 } | 666 } |
658 | 667 |
659 String HTMLMediaElement::canPlayType(const String& mimeType) const | 668 String HTMLMediaElement::canPlayType(const String& mimeType) const |
660 { | 669 { |
661 WebMimeRegistry::SupportsType support = supportsType(ContentType(mimeType)); | 670 WebMimeRegistry::SupportsType support = supportsType(ContentType(mimeType)); |
662 String canPlay; | 671 String canPlay; |
663 | 672 |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 } | 860 } |
852 } | 861 } |
853 | 862 |
854 selectMediaResource(); | 863 selectMediaResource(); |
855 } | 864 } |
856 | 865 |
857 void HTMLMediaElement::selectMediaResource() | 866 void HTMLMediaElement::selectMediaResource() |
858 { | 867 { |
859 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource(%p)", this); | 868 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource(%p)", this); |
860 | 869 |
861 enum Mode { attribute, children }; | 870 enum Mode { Object, Attribute, Children, Nothing }; |
| 871 Mode mode = Nothing; |
862 | 872 |
863 // 3 - If the media element has a src attribute, then let mode be attribute. | 873 // 6 - If the media element has an assigned media provider object, then let |
864 Mode mode = attribute; | 874 // mode be object. |
865 if (!fastHasAttribute(srcAttr)) { | 875 if (!m_srcObjectURL.isEmpty()) { |
866 // Otherwise, if the media element does not have a src attribute but has
a source | 876 mode = Object; |
867 // element child, then let mode be children and let candidate be the fir
st such | 877 } else if (fastHasAttribute(srcAttr)) { |
868 // source element child in tree order. | 878 // Otherwise, if the media element has no assigned media provider object |
869 if (HTMLSourceElement* element = Traversal<HTMLSourceElement>::firstChil
d(*this)) { | 879 // but has a src attribute, then let mode be attribute. |
870 mode = children; | 880 mode = Attribute; |
871 m_nextChildNodeToConsider = element; | 881 } else if (HTMLSourceElement* element = Traversal<HTMLSourceElement>::firstC
hild(*this)) { |
872 m_currentSourceNode = nullptr; | 882 // Otherwise, if the media element does not have an assigned media |
873 } else { | 883 // provider object and does not have a src attribute, but does have a |
874 // Otherwise the media element has neither a src attribute nor a sou
rce element | 884 // source element child, then let mode be children and let candidate be |
875 // child: set the networkState to NETWORK_EMPTY, and abort these ste
ps; the | 885 // the first such source element child in tree order. |
876 // synchronous section ends. | 886 mode = Children; |
877 m_loadState = WaitingForSource; | 887 m_nextChildNodeToConsider = element; |
878 setShouldDelayLoadEvent(false); | 888 m_currentSourceNode = nullptr; |
879 setNetworkState(NETWORK_EMPTY); | 889 } else { |
880 updateDisplayState(); | 890 // Otherwise the media element has no assigned media provider object and |
| 891 // has neither a src attribute nor a source element child: set the |
| 892 // networkState to NETWORK_EMPTY, and abort these steps; the synchronous |
| 893 // section ends. |
| 894 m_loadState = WaitingForSource; |
| 895 setShouldDelayLoadEvent(false); |
| 896 setNetworkState(NETWORK_EMPTY); |
| 897 updateDisplayState(); |
881 | 898 |
882 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource(%p), nothing t
o load", this); | 899 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource(%p), nothing to lo
ad", this); |
883 return; | |
884 } | |
885 } | |
886 | |
887 // 4 - Set the media element's delaying-the-load-event flag to true (this de
lays the load event), | |
888 // and set its networkState to NETWORK_LOADING. | |
889 setShouldDelayLoadEvent(true); | |
890 setNetworkState(NETWORK_LOADING); | |
891 | |
892 // 5 - Queue a task to fire a simple event named loadstart at the media elem
ent. | |
893 scheduleEvent(EventTypeNames::loadstart); | |
894 | |
895 // 6 - If mode is attribute, then run these substeps | |
896 if (mode == attribute) { | |
897 m_loadState = LoadingFromSrcAttr; | |
898 | |
899 const AtomicString& srcValue = fastGetAttribute(srcAttr); | |
900 // If the src attribute's value is the empty string ... jump down to the
failed step below | |
901 if (srcValue.isEmpty()) { | |
902 mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError); | |
903 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource(%p), empty 'sr
c'", this); | |
904 return; | |
905 } | |
906 | |
907 KURL mediaURL = document().completeURL(srcValue); | |
908 if (!isSafeToLoadURL(mediaURL, Complain)) { | |
909 mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError); | |
910 return; | |
911 } | |
912 | |
913 // No type is available when the url comes from the 'src' attribute so M
ediaPlayer | |
914 // will have to pick a media engine based on the file extension. | |
915 ContentType contentType((String())); | |
916 loadResource(mediaURL, contentType); | |
917 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource(%p), using 'src' a
ttribute url", this); | |
918 return; | 900 return; |
919 } | 901 } |
920 | 902 |
921 // Otherwise, the source elements will be used | 903 // 7 - Set the media element's networkState to NETWORK_LOADING. |
922 loadNextSourceChild(); | 904 setNetworkState(NETWORK_LOADING); |
| 905 |
| 906 // 8 - Queue a task to fire a simple event named loadstart at the media elem
ent. |
| 907 scheduleEvent(EventTypeNames::loadstart); |
| 908 |
| 909 // 9 - Run the appropriate steps... |
| 910 switch (mode) { |
| 911 case Object: |
| 912 loadSourceFromObject(); |
| 913 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource(%p), using 'srcObj
ect' attribute", this); |
| 914 break; |
| 915 case Attribute: |
| 916 loadSourceFromAttribute(); |
| 917 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource(%p), using 'src' a
ttribute url", this); |
| 918 break; |
| 919 case Children: |
| 920 loadNextSourceChild(); |
| 921 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource(%p), using source
element", this); |
| 922 break; |
| 923 default: |
| 924 ASSERT_NOT_REACHED(); |
| 925 } |
| 926 } |
| 927 |
| 928 void HTMLMediaElement::loadSourceFromObject() |
| 929 { |
| 930 ASSERT(!m_srcObjectURL.isEmpty()); |
| 931 m_loadState = LoadingFromSrcObject; |
| 932 loadSourceFromURL(m_srcObjectURL); |
| 933 } |
| 934 |
| 935 void HTMLMediaElement::loadSourceFromAttribute() |
| 936 { |
| 937 m_loadState = LoadingFromSrcAttr; |
| 938 const AtomicString& srcValue = fastGetAttribute(srcAttr); |
| 939 |
| 940 // If the src attribute's value is the empty string ... jump down to the fai
led step below |
| 941 if (srcValue.isEmpty()) { |
| 942 mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError); |
| 943 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource(%p), empty 'src'",
this); |
| 944 return; |
| 945 } |
| 946 |
| 947 loadSourceFromURL(srcValue); |
| 948 } |
| 949 |
| 950 void HTMLMediaElement::loadSourceFromURL(const AtomicString& url) |
| 951 { |
| 952 m_loadState = LoadingFromSrcAttr; |
| 953 |
| 954 KURL mediaURL = document().completeURL(url); |
| 955 if (!isSafeToLoadURL(mediaURL, Complain)) { |
| 956 mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError); |
| 957 return; |
| 958 } |
| 959 |
| 960 // No type is available when the url comes from the 'src' or 'srcObject' |
| 961 // attribute so MediaPlayer will have to pick a media engine based on the |
| 962 // file extension. |
| 963 ContentType contentType((String())); |
| 964 loadResource(mediaURL, contentType); |
923 } | 965 } |
924 | 966 |
925 void HTMLMediaElement::loadNextSourceChild() | 967 void HTMLMediaElement::loadNextSourceChild() |
926 { | 968 { |
927 ContentType contentType((String())); | 969 ContentType contentType((String())); |
928 KURL mediaURL = selectNextSourceChild(&contentType, Complain); | 970 KURL mediaURL = selectNextSourceChild(&contentType, Complain); |
929 if (!mediaURL.isValid()) { | 971 if (!mediaURL.isValid()) { |
930 waitForSourceChange(); | 972 waitForSourceChange(); |
931 return; | 973 return; |
932 } | 974 } |
(...skipping 2871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3804 { | 3846 { |
3805 visitor->trace(m_client); | 3847 visitor->trace(m_client); |
3806 } | 3848 } |
3807 | 3849 |
3808 DEFINE_TRACE(HTMLMediaElement::AudioSourceProviderImpl) | 3850 DEFINE_TRACE(HTMLMediaElement::AudioSourceProviderImpl) |
3809 { | 3851 { |
3810 visitor->trace(m_client); | 3852 visitor->trace(m_client); |
3811 } | 3853 } |
3812 | 3854 |
3813 } // namespace blink | 3855 } // namespace blink |
OLD | NEW |