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

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

Issue 1886333002: Do not use a persistent reference to store srcObject in HTMLMediaElement. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 #include "platform/Histogram.h" 72 #include "platform/Histogram.h"
73 #include "platform/LayoutTestSupport.h" 73 #include "platform/LayoutTestSupport.h"
74 #include "platform/Logging.h" 74 #include "platform/Logging.h"
75 #include "platform/MIMETypeFromURL.h" 75 #include "platform/MIMETypeFromURL.h"
76 #include "platform/MIMETypeRegistry.h" 76 #include "platform/MIMETypeRegistry.h"
77 #include "platform/RuntimeEnabledFeatures.h" 77 #include "platform/RuntimeEnabledFeatures.h"
78 #include "platform/UserGestureIndicator.h" 78 #include "platform/UserGestureIndicator.h"
79 #include "platform/audio/AudioBus.h" 79 #include "platform/audio/AudioBus.h"
80 #include "platform/audio/AudioSourceProviderClient.h" 80 #include "platform/audio/AudioSourceProviderClient.h"
81 #include "platform/graphics/GraphicsLayer.h" 81 #include "platform/graphics/GraphicsLayer.h"
82 #include "platform/mediastream/MediaStreamDescriptor.h"
82 #include "platform/weborigin/SecurityOrigin.h" 83 #include "platform/weborigin/SecurityOrigin.h"
83 #include "public/platform/Platform.h" 84 #include "public/platform/Platform.h"
84 #include "public/platform/WebAudioSourceProvider.h" 85 #include "public/platform/WebAudioSourceProvider.h"
85 #include "public/platform/WebContentDecryptionModule.h" 86 #include "public/platform/WebContentDecryptionModule.h"
86 #include "public/platform/WebInbandTextTrack.h" 87 #include "public/platform/WebInbandTextTrack.h"
88 #include "public/platform/WebMediaPlayerSource.h"
87 #include "public/platform/WebMediaStream.h" 89 #include "public/platform/WebMediaStream.h"
88 #include "public/platform/modules/remoteplayback/WebRemotePlaybackClient.h" 90 #include "public/platform/modules/remoteplayback/WebRemotePlaybackClient.h"
89 #include "public/platform/modules/remoteplayback/WebRemotePlaybackState.h" 91 #include "public/platform/modules/remoteplayback/WebRemotePlaybackState.h"
90 #include "wtf/CurrentTime.h" 92 #include "wtf/CurrentTime.h"
91 #include "wtf/MathExtras.h" 93 #include "wtf/MathExtras.h"
92 #include "wtf/text/CString.h" 94 #include "wtf/text/CString.h"
93 #include <limits> 95 #include <limits>
94 96
95 #ifndef LOG_MEDIA_EVENTS 97 #ifndef LOG_MEDIA_EVENTS
96 // Default to not logging events because so many are generated they can overwhel m the rest of 98 // Default to not logging events because so many are generated they can overwhel m the rest of
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 return new LayoutMedia(this); 558 return new LayoutMedia(this);
557 } 559 }
558 560
559 Node::InsertionNotificationRequest HTMLMediaElement::insertedInto(ContainerNode* insertionPoint) 561 Node::InsertionNotificationRequest HTMLMediaElement::insertedInto(ContainerNode* insertionPoint)
560 { 562 {
561 WTF_LOG(Media, "HTMLMediaElement::insertedInto(%p, %p)", this, insertionPoin t); 563 WTF_LOG(Media, "HTMLMediaElement::insertedInto(%p, %p)", this, insertionPoin t);
562 564
563 HTMLElement::insertedInto(insertionPoint); 565 HTMLElement::insertedInto(insertionPoint);
564 if (insertionPoint->inShadowIncludingDocument()) { 566 if (insertionPoint->inShadowIncludingDocument()) {
565 UseCounter::count(document(), UseCounter::HTMLMediaElementInDocument); 567 UseCounter::count(document(), UseCounter::HTMLMediaElementInDocument);
566 if ((!getAttribute(srcAttr).isEmpty() || m_srcObject.isMediaProviderObje ct()) && m_networkState == NETWORK_EMPTY) { 568 if ((!getAttribute(srcAttr).isEmpty() || m_srcObject) && m_networkState == NETWORK_EMPTY) {
567 m_ignorePreloadNone = false; 569 m_ignorePreloadNone = false;
568 invokeLoadAlgorithm(); 570 invokeLoadAlgorithm();
569 } 571 }
570 } 572 }
571 573
572 return InsertionShouldCallDidNotifySubtreeInsertions; 574 return InsertionShouldCallDidNotifySubtreeInsertions;
573 } 575 }
574 576
575 void HTMLMediaElement::didNotifySubtreeInsertionsToDocument() 577 void HTMLMediaElement::didNotifySubtreeInsertionsToDocument()
576 { 578 {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 MediaError* HTMLMediaElement::error() const 653 MediaError* HTMLMediaElement::error() const
652 { 654 {
653 return m_error; 655 return m_error;
654 } 656 }
655 657
656 void HTMLMediaElement::setSrc(const AtomicString& url) 658 void HTMLMediaElement::setSrc(const AtomicString& url)
657 { 659 {
658 setAttribute(srcAttr, url); 660 setAttribute(srcAttr, url);
659 } 661 }
660 662
661 void HTMLMediaElement::setSrcObject(const WebMediaPlayerSource& srcObject) 663 void HTMLMediaElement::setSrcObject(MediaStreamDescriptor* srcObject)
662 { 664 {
663 // srcObject can be a media-provider object or null.
664 ASSERT(!srcObject.isURL());
665
666 // The srcObject IDL attribute, on setting, must set the element's assigned
667 // media provider object to the new value, and then invoke the element's
668 // media element load algorithm.
669 m_srcObject = srcObject; 665 m_srcObject = srcObject;
670 invokeLoadAlgorithm(); 666 invokeLoadAlgorithm();
671 } 667 }
672 668
673 HTMLMediaElement::NetworkState HTMLMediaElement::getNetworkState() const 669 HTMLMediaElement::NetworkState HTMLMediaElement::getNetworkState() const
674 { 670 {
675 return m_networkState; 671 return m_networkState;
676 } 672 }
677 673
678 String HTMLMediaElement::canPlayType(const String& mimeType) const 674 String HTMLMediaElement::canPlayType(const String& mimeType) const
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 842
847 void HTMLMediaElement::selectMediaResource() 843 void HTMLMediaElement::selectMediaResource()
848 { 844 {
849 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource(%p)", this); 845 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource(%p)", this);
850 846
851 enum Mode { Object, Attribute, Children, Nothing }; 847 enum Mode { Object, Attribute, Children, Nothing };
852 Mode mode = Nothing; 848 Mode mode = Nothing;
853 849
854 // 6 - If the media element has an assigned media provider object, then let 850 // 6 - If the media element has an assigned media provider object, then let
855 // mode be object. 851 // mode be object.
856 if (m_srcObject.isMediaProviderObject()) { 852 if (m_srcObject) {
857 mode = Object; 853 mode = Object;
858 } else if (fastHasAttribute(srcAttr)) { 854 } else if (fastHasAttribute(srcAttr)) {
859 // Otherwise, if the media element has no assigned media provider object 855 // Otherwise, if the media element has no assigned media provider object
860 // but has a src attribute, then let mode be attribute. 856 // but has a src attribute, then let mode be attribute.
861 mode = Attribute; 857 mode = Attribute;
862 } else if (HTMLSourceElement* element = Traversal<HTMLSourceElement>::firstC hild(*this)) { 858 } else if (HTMLSourceElement* element = Traversal<HTMLSourceElement>::firstC hild(*this)) {
863 // Otherwise, if the media element does not have an assigned media 859 // Otherwise, if the media element does not have an assigned media
864 // provider object and does not have a src attribute, but does have a 860 // provider object and does not have a src attribute, but does have a
865 // source element child, then let mode be children and let candidate be 861 // source element child, then let mode be children and let candidate be
866 // the first such source element child in tree order. 862 // the first such source element child in tree order.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 loadNextSourceChild(); 897 loadNextSourceChild();
902 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource(%p), using source element", this); 898 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource(%p), using source element", this);
903 break; 899 break;
904 default: 900 default:
905 ASSERT_NOT_REACHED(); 901 ASSERT_NOT_REACHED();
906 } 902 }
907 } 903 }
908 904
909 void HTMLMediaElement::loadSourceFromObject() 905 void HTMLMediaElement::loadSourceFromObject()
910 { 906 {
911 ASSERT(m_srcObject.isMediaProviderObject()); 907 ASSERT(m_srcObject);
912 m_loadState = LoadingFromSrcObject; 908 m_loadState = LoadingFromSrcObject;
913 909
914 // No type is available when the resource comes from the 'srcObject' 910 // No type is available when the resource comes from the 'srcObject'
915 // attribute. 911 // attribute.
916 ContentType contentType((String())); 912 ContentType contentType((String()));
917 loadResource(m_srcObject, contentType); 913 loadResource(WebMediaPlayerSource(WebMediaStream(m_srcObject)), contentType) ;
918 } 914 }
919 915
920 void HTMLMediaElement::loadSourceFromAttribute() 916 void HTMLMediaElement::loadSourceFromAttribute()
921 { 917 {
922 m_loadState = LoadingFromSrcAttr; 918 m_loadState = LoadingFromSrcAttr;
923 const AtomicString& srcValue = fastGetAttribute(srcAttr); 919 const AtomicString& srcValue = fastGetAttribute(srcAttr);
924 920
925 // If the src attribute's value is the empty string ... jump down to the fai led step below 921 // If the src attribute's value is the empty string ... jump down to the fai led step below
926 if (srcValue.isEmpty()) { 922 if (srcValue.isEmpty()) {
927 mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError); 923 mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 setPlayerPreload(); 991 setPlayerPreload();
996 992
997 if (fastHasAttribute(mutedAttr)) 993 if (fastHasAttribute(mutedAttr))
998 m_muted = true; 994 m_muted = true;
999 updateVolume(); 995 updateVolume();
1000 996
1001 ASSERT(!m_mediaSource); 997 ASSERT(!m_mediaSource);
1002 998
1003 bool attemptLoad = true; 999 bool attemptLoad = true;
1004 1000
1005 bool isObjectOrBlobURL = source.isMediaProviderObject() || url.protocolIs(me diaSourceBlobProtocol); 1001 if (source.isMediaStream() || url.protocolIs(mediaSourceBlobProtocol)) {
1006 if (isObjectOrBlobURL) {
1007 bool isMediaStream = source.isMediaStream() || (source.isURL() && isMedi aStreamURL(url.getString())); 1002 bool isMediaStream = source.isMediaStream() || (source.isURL() && isMedi aStreamURL(url.getString()));
1008 if (isMediaStream) { 1003 if (isMediaStream) {
1009 m_autoplayHelper->removeUserGestureRequirement(GesturelessPlaybackEn abledByStream); 1004 m_autoplayHelper->removeUserGestureRequirement(GesturelessPlaybackEn abledByStream);
1010 } else { 1005 } else {
1011 m_mediaSource = HTMLMediaSource::lookup(url.getString()); 1006 m_mediaSource = HTMLMediaSource::lookup(url.getString());
1012 1007
1013 if (m_mediaSource) { 1008 if (m_mediaSource) {
1014 if (!m_mediaSource->attachToElement(this)) { 1009 if (!m_mediaSource->attachToElement(this)) {
1015 // Forget our reference to the MediaSource, so we leave it a lone 1010 // Forget our reference to the MediaSource, so we leave it a lone
1016 // while processing remainder of load failure. 1011 // while processing remainder of load failure.
1017 m_mediaSource = nullptr; 1012 m_mediaSource = nullptr;
1018 attemptLoad = false; 1013 attemptLoad = false;
1019 } 1014 }
1020 } 1015 }
1021 } 1016 }
1022 } 1017 }
1023 1018
1024 bool canLoadResource = source.isMediaProviderObject() || canLoadURL(url, con tentType); 1019 bool canLoadResource = source.isMediaStream() || canLoadURL(url, contentType );
1025 if (attemptLoad && canLoadResource) { 1020 if (attemptLoad && canLoadResource) {
1026 ASSERT(!webMediaPlayer()); 1021 ASSERT(!webMediaPlayer());
1027 1022
1028 if (effectivePreloadType() == WebMediaPlayer::PreloadNone) { 1023 if (effectivePreloadType() == WebMediaPlayer::PreloadNone) {
1029 WTF_LOG(Media, "HTMLMediaElement::loadResource(%p) : Delaying load b ecause preload == 'none'", this); 1024 WTF_LOG(Media, "HTMLMediaElement::loadResource(%p) : Delaying load b ecause preload == 'none'", this);
1030 deferLoad(); 1025 deferLoad();
1031 } else { 1026 } else {
1032 startPlayerLoad(); 1027 startPlayerLoad();
1033 } 1028 }
1034 } else { 1029 } else {
1035 mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError); 1030 mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError);
1036 } 1031 }
1037 1032
1038 // If there is no poster to display, allow the media engine to render video frames as soon as 1033 // If there is no poster to display, allow the media engine to render video frames as soon as
1039 // they are available. 1034 // they are available.
1040 updateDisplayState(); 1035 updateDisplayState();
1041 1036
1042 if (layoutObject()) 1037 if (layoutObject())
1043 layoutObject()->updateFromElement(); 1038 layoutObject()->updateFromElement();
1044 } 1039 }
1045 1040
1046 void HTMLMediaElement::startPlayerLoad() 1041 void HTMLMediaElement::startPlayerLoad()
1047 { 1042 {
1048 ASSERT(!m_webMediaPlayer); 1043 ASSERT(!m_webMediaPlayer);
1049 1044
1050 WebMediaPlayerSource source; 1045 WebMediaPlayerSource source;
1051 if (m_srcObject.isMediaProviderObject()) { 1046 if (m_srcObject) {
1052 source = m_srcObject; 1047 source = WebMediaPlayerSource(WebMediaStream(m_srcObject));
1053 } else { 1048 } else {
1054 // Filter out user:pass as those two URL components aren't 1049 // Filter out user:pass as those two URL components aren't
1055 // considered for media resource fetches (including for the CORS 1050 // considered for media resource fetches (including for the CORS
1056 // use-credentials mode.) That behavior aligns with Gecko, with IE 1051 // use-credentials mode.) That behavior aligns with Gecko, with IE
1057 // being more restrictive and not allowing fetches to such URLs. 1052 // being more restrictive and not allowing fetches to such URLs.
1058 // 1053 //
1059 // Spec reference: http://whatwg.org/c/#concept-media-load-resource 1054 // Spec reference: http://whatwg.org/c/#concept-media-load-resource
1060 // 1055 //
1061 // FIXME: when the HTML spec switches to specifying resource 1056 // FIXME: when the HTML spec switches to specifying resource
1062 // fetches in terms of Fetch (http://fetch.spec.whatwg.org), and 1057 // fetches in terms of Fetch (http://fetch.spec.whatwg.org), and
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1184 } 1179 }
1185 ASSERT(m_deferredLoadState == WaitingForStopDelayingLoadEventTask); 1180 ASSERT(m_deferredLoadState == WaitingForStopDelayingLoadEventTask);
1186 m_deferredLoadState = WaitingForTrigger; 1181 m_deferredLoadState = WaitingForTrigger;
1187 } 1182 }
1188 1183
1189 WebMediaPlayer::LoadType HTMLMediaElement::loadType() const 1184 WebMediaPlayer::LoadType HTMLMediaElement::loadType() const
1190 { 1185 {
1191 if (m_mediaSource) 1186 if (m_mediaSource)
1192 return WebMediaPlayer::LoadTypeMediaSource; 1187 return WebMediaPlayer::LoadTypeMediaSource;
1193 1188
1194 if (m_srcObject.isMediaStream() || isMediaStreamURL(m_currentSrc.getString() )) 1189 if (m_srcObject || isMediaStreamURL(m_currentSrc.getString()))
1195 return WebMediaPlayer::LoadTypeMediaStream; 1190 return WebMediaPlayer::LoadTypeMediaStream;
1196 1191
1197 return WebMediaPlayer::LoadTypeURL; 1192 return WebMediaPlayer::LoadTypeURL;
1198 } 1193 }
1199 1194
1200 bool HTMLMediaElement::textTracksAreReady() const 1195 bool HTMLMediaElement::textTracksAreReady() const
1201 { 1196 {
1202 // 4.8.10.12.1 Text track model 1197 // 4.8.10.12.1 Text track model
1203 // ... 1198 // ...
1204 // The text tracks of a media element are ready if all the text tracks whose mode was not 1199 // The text tracks of a media element are ready if all the text tracks whose mode was not
(...skipping 2409 matching lines...) Expand 10 before | Expand all | Expand 10 after
3614 visitor->trace(m_mediaSource); 3609 visitor->trace(m_mediaSource);
3615 visitor->trace(m_audioTracks); 3610 visitor->trace(m_audioTracks);
3616 visitor->trace(m_videoTracks); 3611 visitor->trace(m_videoTracks);
3617 visitor->trace(m_cueTimeline); 3612 visitor->trace(m_cueTimeline);
3618 visitor->trace(m_textTracks); 3613 visitor->trace(m_textTracks);
3619 visitor->trace(m_textTracksWhenResourceSelectionBegan); 3614 visitor->trace(m_textTracksWhenResourceSelectionBegan);
3620 visitor->trace(m_playResolvers); 3615 visitor->trace(m_playResolvers);
3621 visitor->trace(m_audioSourceProvider); 3616 visitor->trace(m_audioSourceProvider);
3622 visitor->trace(m_autoplayHelperClient); 3617 visitor->trace(m_autoplayHelperClient);
3623 visitor->trace(m_autoplayHelper); 3618 visitor->trace(m_autoplayHelper);
3619 visitor->trace(m_srcObject);
3624 visitor->template registerWeakMembers<HTMLMediaElement, &HTMLMediaElement::c learWeakMembers>(this); 3620 visitor->template registerWeakMembers<HTMLMediaElement, &HTMLMediaElement::c learWeakMembers>(this);
3625 Supplementable<HTMLMediaElement>::trace(visitor); 3621 Supplementable<HTMLMediaElement>::trace(visitor);
3626 HTMLElement::trace(visitor); 3622 HTMLElement::trace(visitor);
3627 ActiveDOMObject::trace(visitor); 3623 ActiveDOMObject::trace(visitor);
3628 } 3624 }
3629 3625
3630 void HTMLMediaElement::createPlaceholderTracksIfNecessary() 3626 void HTMLMediaElement::createPlaceholderTracksIfNecessary()
3631 { 3627 {
3632 if (!RuntimeEnabledFeatures::audioVideoTracksEnabled()) 3628 if (!RuntimeEnabledFeatures::audioVideoTracksEnabled())
3633 return; 3629 return;
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
3859 3855
3860 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect() co nst 3856 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect() co nst
3861 { 3857 {
3862 IntRect result; 3858 IntRect result;
3863 if (LayoutObject* object = m_element->layoutObject()) 3859 if (LayoutObject* object = m_element->layoutObject())
3864 result = object->absoluteBoundingBoxRect(); 3860 result = object->absoluteBoundingBoxRect();
3865 return result; 3861 return result;
3866 } 3862 }
3867 3863
3868 } // namespace blink 3864 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698