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

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

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

Powered by Google App Engine
This is Rietveld 408576698