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

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

Issue 545933002: Implement HTMLMediaElement::srcObject. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Now uses Functional. Created 6 years, 3 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 30 matching lines...) Expand all
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
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_lastTimeUpdateEventMovieTime(std::numeric_limits<double>::max()) 327 , m_lastTimeUpdateEventMovieTime(std::numeric_limits<double>::max())
327 , m_loadState(WaitingForSource) 328 , m_loadState(WaitingForSource)
329 , m_srcObject(std::nullptr_t())
philipj_slow 2014/09/16 13:39:50 You don't need to explicitly init these smart poin
perkj_chrome 2014/09/17 19:26:13 Well, WTF::RawPtr does not allow you to not set a
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_cachedTimeWallClockUpdateTime(0) 336 , m_cachedTimeWallClockUpdateTime(0)
335 , m_minimumWallClockTimeToCacheMediaTime(0) 337 , m_minimumWallClockTimeToCacheMediaTime(0)
336 , m_fragmentStartTime(MediaPlayer::invalidTime()) 338 , m_fragmentStartTime(MediaPlayer::invalidTime())
337 , m_fragmentEndTime(MediaPlayer::invalidTime()) 339 , m_fragmentEndTime(MediaPlayer::invalidTime())
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 } 677 }
676 678
677 m_pendingActionFlags = 0; 679 m_pendingActionFlags = 0;
678 } 680 }
679 681
680 PassRefPtrWillBeRawPtr<MediaError> HTMLMediaElement::error() const 682 PassRefPtrWillBeRawPtr<MediaError> HTMLMediaElement::error() const
681 { 683 {
682 return m_error; 684 return m_error;
683 } 685 }
684 686
687 void HTMLMediaElement::setSrcObject(RawPtr<MediaProvider> mediaProvider)
688 {
689 WTF_LOG(Media, "HTMLMediaElement::setSrcObject()");
philipj_slow 2014/09/16 13:39:50 Please include the %p this pointer as well.
perkj_chrome 2014/09/17 19:26:13 Done.
690 m_srcObject = mediaProvider;
691 clearMediaPlayer(LoadMediaResource);
692 scheduleDelayedAction(LoadMediaResource);
philipj_slow 2014/09/16 13:39:50 The spec says "On setting, it must set the element
perkj_chrome 2014/09/17 19:26:13 Now calls load() and test is added to mediastream-
693 }
694
695 MediaProvider* HTMLMediaElement::srcObject() const
philipj_slow 2014/09/16 13:39:50 Please invert order here too.
perkj_chrome 2014/09/17 19:26:13 Done.
696 {
697 return m_srcObject.get();
698 }
699
685 void HTMLMediaElement::setSrc(const AtomicString& url) 700 void HTMLMediaElement::setSrc(const AtomicString& url)
686 { 701 {
687 setAttribute(srcAttr, url); 702 setAttribute(srcAttr, url);
688 } 703 }
689 704
690 HTMLMediaElement::NetworkState HTMLMediaElement::networkState() const 705 HTMLMediaElement::NetworkState HTMLMediaElement::networkState() const
691 { 706 {
692 return m_networkState; 707 return m_networkState;
693 } 708 }
694 709
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 } 863 }
849 } 864 }
850 865
851 selectMediaResource(); 866 selectMediaResource();
852 } 867 }
853 868
854 void HTMLMediaElement::selectMediaResource() 869 void HTMLMediaElement::selectMediaResource()
855 { 870 {
856 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource"); 871 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource");
857 872
858 enum Mode { attribute, children }; 873 enum Mode {Object, Attribute, Children};
859 874
860 // 3 - If the media element has a src attribute, then let mode be attribute. 875 // 3 - Decide which source to load.
philipj_slow 2014/09/16 13:39:51 Please copy the steps from the spec. This should b
perkj_chrome 2014/09/17 19:26:13 Done.
861 Mode mode = attribute; 876 // If the media element has a srcObject let the mode be object.
862 if (!fastHasAttribute(srcAttr)) { 877 // If it has a src attribute, let the mode be attribute.
863 // Otherwise, if the media element does not have a src attribute but has a source 878 // If it has a source element, let the mode be Children.
864 // element child, then let mode be children and let candidate be the fir st such 879 Mode mode = Object;
philipj_slow 2014/09/16 13:39:51 Remove the default init unless it's needed to squa
perkj_chrome 2014/09/17 19:26:13 I can try. I am afraid it will hit me on one platf
865 // source element child in tree order. 880 if (srcObject()) {
866 if (HTMLSourceElement* element = Traversal<HTMLSourceElement>::firstChil d(*this)) { 881 mode = Object;
867 mode = children; 882 } else if (fastHasAttribute(srcAttr)) {
868 m_nextChildNodeToConsider = element; 883 mode = Attribute;
869 m_currentSourceNode = nullptr; 884 } else if (Traversal<HTMLSourceElement>::firstChild(*this)) {
870 } else { 885 mode = Children;
871 // Otherwise the media element has neither a src attribute nor a sou rce element 886 HTMLSourceElement* element = Traversal<HTMLSourceElement>::firstChild(*t his);
872 // child: set the networkState to NETWORK_EMPTY, and abort these ste ps; the 887 m_nextChildNodeToConsider = element;
873 // synchronous section ends. 888 m_currentSourceNode = nullptr;
874 m_loadState = WaitingForSource; 889 } else {
875 setShouldDelayLoadEvent(false); 890 // Otherwise the media element has no source.
876 m_networkState = NETWORK_EMPTY; 891 // set the networkState to NETWORK_EMPTY, and abort these steps; the
892 // synchronous section ends.
893 m_loadState = WaitingForSource;
894 setShouldDelayLoadEvent(false);
895 m_networkState = NETWORK_EMPTY;
877 896
878 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource, nothing to lo ad"); 897 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource, nothing to load") ;
879 return; 898 return;
880 }
881 } 899 }
882 900
883 // 4 - Set the media element's delaying-the-load-event flag to true (this de lays the load event), 901 // 4 - Set the media element's delaying-the-load-event flag to true (this de lays the load event),
884 // and set its networkState to NETWORK_LOADING. 902 // and set its networkState to NETWORK_LOADING.
885 setShouldDelayLoadEvent(true); 903 setShouldDelayLoadEvent(true);
886 m_networkState = NETWORK_LOADING; 904 m_networkState = NETWORK_LOADING;
887 905
888 // 5 - Queue a task to fire a simple event named loadstart at the media elem ent. 906 // 5 - Queue a task to fire a simple event named loadstart at the media elem ent.
889 scheduleEvent(EventTypeNames::loadstart); 907 scheduleEvent(EventTypeNames::loadstart);
890 908
891 // 6 - If mode is attribute, then run these substeps 909 // 6 - Load the correct source.
philipj_slow 2014/09/16 13:39:50 Should say "Run the appropriate steps from the fol
perkj_chrome 2014/09/17 19:26:13 Done.
892 if (mode == attribute) { 910 switch (mode) {
893 m_loadState = LoadingFromSrcAttr; 911 case Object:
912 loadSourceFromObject();
philipj_slow 2014/09/16 13:39:50 I think just loadFromObject() and loadFromAttribut
perkj_chrome 2014/09/17 19:26:13 Done.
913 break;
914 case Attribute:
915 loadSourceFromAttribute();
916 break;
917 case Children:
918 loadNextSourceChild();
919 break;
920 }
921 }
894 922
895 // If the src attribute's value is the empty string ... jump down to the failed step below 923 void HTMLMediaElement::loadSourceFromObject()
896 KURL mediaURL = getNonEmptyURLAttribute(srcAttr); 924 {
897 if (mediaURL.isEmpty()) { 925 m_loadState = LoadingFromSrcObject;
philipj_slow 2014/09/16 13:39:50 Can you annotate this function with comments from
perkj_chrome 2014/09/17 19:26:13 Added test of currentSrc to mediastream-srcobject.
898 mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError);
899 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource, empty 'src'") ;
900 return;
901 }
902 926
903 if (!isSafeToLoadURL(mediaURL, Complain)) { 927 KURL mediaURL = document().completeURL(m_srcObject->getObjectUrl());
philipj_slow 2014/09/16 13:39:51 This is a little bit peculiar, since the point of
perkj_chrome 2014/09/17 19:26:13 Agree, this cl adds the interface MediaProvider so
904 mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError);
905 return;
906 }
907 928
908 // No type or key system information is available when the url comes 929 if (!isSafeToLoadURL(mediaURL, Complain)) {
909 // from the 'src' attribute so MediaPlayer 930 mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError);
philipj_slow 2014/09/16 13:39:51 This bit needs a test. It can cause HTMLMediaEleme
perkj_chrome 2014/09/17 19:26:13 I don't see how it would ever return anything but
910 // will have to pick a media engine based on the file extension.
911 ContentType contentType((String()));
912 loadResource(mediaURL, contentType, String());
913 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource, using 'src' attri bute url");
914 return; 931 return;
915 } 932 }
916 933
917 // Otherwise, the source elements will be used 934 // No type or key system information is available when the url comes
philipj_slow 2014/09/16 13:39:51 This is repeated, can you add a shared void loadRe
perkj_chrome 2014/09/17 19:26:13 Done.
918 loadNextSourceChild(); 935 // from the 'srcObject' so MediaPlayer
936 // will have to pick a media engine based on the file extension.
937 ContentType contentType((String()));
938 loadResource(mediaURL, contentType, String());
939 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource, using 'srcObject' att ribute.");
940 return;
941 }
942
943 void HTMLMediaElement::loadSourceFromAttribute()
944 {
945 m_loadState = LoadingFromSrcAttr;
946
947 // If the src attribute's value is the empty string ... jump down to the fai led step below
948 KURL mediaURL = getNonEmptyURLAttribute(srcAttr);
949 if (mediaURL.isEmpty()) {
950 mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError);
951 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource, empty 'src'");
952 return;
953 }
954
955 if (!isSafeToLoadURL(mediaURL, Complain)) {
956 mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError);
957 return;
958 }
959
960 // No type or key system information is available when the url comes
961 // from the 'src' attribute so MediaPlayer
962 // will have to pick a media engine based on the file extension.
963 ContentType contentType((String()));
964 loadResource(mediaURL, contentType, String());
965 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource, using 'src' attribute url");
966 return;
919 } 967 }
920 968
921 void HTMLMediaElement::loadNextSourceChild() 969 void HTMLMediaElement::loadNextSourceChild()
922 { 970 {
923 ContentType contentType((String())); 971 ContentType contentType((String()));
924 String keySystem; 972 String keySystem;
925 KURL mediaURL = selectNextSourceChild(&contentType, &keySystem, Complain); 973 KURL mediaURL = selectNextSourceChild(&contentType, &keySystem, Complain);
926 if (!mediaURL.isValid()) { 974 if (!mediaURL.isValid()) {
927 waitForSourceChange(); 975 waitForSourceChange();
928 return; 976 return;
(...skipping 3060 matching lines...) Expand 10 before | Expand all | Expand 10 after
3989 4037
3990 #if ENABLE(WEB_AUDIO) 4038 #if ENABLE(WEB_AUDIO)
3991 void HTMLMediaElement::clearWeakMembers(Visitor* visitor) 4039 void HTMLMediaElement::clearWeakMembers(Visitor* visitor)
3992 { 4040 {
3993 if (!visitor->isAlive(m_audioSourceNode) && audioSourceProvider()) 4041 if (!visitor->isAlive(m_audioSourceNode) && audioSourceProvider())
3994 audioSourceProvider()->setClient(0); 4042 audioSourceProvider()->setClient(0);
3995 } 4043 }
3996 #endif 4044 #endif
3997 4045
3998 } 4046 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698