@@ -1810,11 +1810,16 @@ class HTMLMediaElement::ChannelLoader final {
18101810 public:
18111811 NS_INLINE_DECL_REFCOUNTING (ChannelLoader);
18121812
1813+ explicit ChannelLoader (const JSCallingLocation& aCallingLocation)
1814+ : mCallingLocation (aCallingLocation) {}
1815+
18131816 void LoadInternal (HTMLMediaElement* aElement) {
18141817 if (mCancelled ) {
18151818 return ;
18161819 }
18171820
1821+ JSCallingLocation::AutoFallback fallback (&mCallingLocation );
1822+
18181823 // determine what security checks need to be performed in AsyncOpen().
18191824 nsSecurityFlags securityFlags =
18201825 aElement->ShouldCheckAllowOrigin ()
@@ -1991,6 +1996,7 @@ class HTMLMediaElement::ChannelLoader final {
19911996 nsCOMPtr<nsIChannel> mChannel ;
19921997
19931998 bool mCancelled = false ;
1999+ JSCallingLocation mCallingLocation ;
19942000};
19952001
19962002class HTMLMediaElement ::ErrorSink {
@@ -2613,9 +2619,9 @@ void HTMLMediaElement::QueueLoadFromSourceTask() {
26132619
26142620 ChangeDelayLoadStatus (true );
26152621 ChangeNetworkState (NETWORK_LOADING);
2616- RefPtr<Runnable> r =
2617- NewRunnableMethod ( " HTMLMediaElement::LoadFromSourceChildren" , this ,
2618- &HTMLMediaElement::LoadFromSourceChildren);
2622+ RefPtr<Runnable> r = NewRunnableMethod<JSCallingLocation>(
2623+ " HTMLMediaElement::LoadFromSourceChildren" , this ,
2624+ &HTMLMediaElement::LoadFromSourceChildren, JSCallingLocation::Get () );
26192625 RunInStableState (r);
26202626}
26212627
@@ -2624,9 +2630,9 @@ void HTMLMediaElement::QueueSelectResourceTask() {
26242630 if (mHaveQueuedSelectResource ) return ;
26252631 mHaveQueuedSelectResource = true ;
26262632 ChangeNetworkState (NETWORK_NO_SOURCE);
2627- RefPtr<Runnable> r =
2628- NewRunnableMethod ( " HTMLMediaElement::SelectResourceWrapper" , this ,
2629- &HTMLMediaElement::SelectResourceWrapper);
2633+ RefPtr<Runnable> r = NewRunnableMethod<JSCallingLocation>(
2634+ " HTMLMediaElement::SelectResourceWrapper" , this ,
2635+ &HTMLMediaElement::SelectResourceWrapper, JSCallingLocation::Get () );
26302636 RunInStableState (r);
26312637}
26322638
@@ -2730,15 +2736,17 @@ void HTMLMediaElement::ResetState() {
27302736 }
27312737}
27322738
2733- void HTMLMediaElement::SelectResourceWrapper () {
2734- SelectResource ();
2739+ void HTMLMediaElement::SelectResourceWrapper (
2740+ const JSCallingLocation& aCallingLocation) {
2741+ SelectResource (aCallingLocation);
27352742 MaybeBeginCloningVisually ();
27362743 mIsRunningSelectResource = false ;
27372744 mHaveQueuedSelectResource = false ;
27382745 mIsDoingExplicitLoad = false ;
27392746}
27402747
2741- void HTMLMediaElement::SelectResource () {
2748+ void HTMLMediaElement::SelectResource (
2749+ const JSCallingLocation& aCallingLocation) {
27422750 if (!mSrcAttrStream && !HasAttr (nsGkAtoms::src) && !HasSourceChildren (this )) {
27432751 // The media element has neither a src attribute nor any source
27442752 // element children, abort the load.
@@ -2755,7 +2763,7 @@ void HTMLMediaElement::SelectResource() {
27552763 // Delay setting mIsRunningSeletResource until after UpdatePreloadAction
27562764 // so that we don't lose our state change by bailing out of the preload
27572765 // state update
2758- UpdatePreloadAction ();
2766+ UpdatePreloadAction (aCallingLocation );
27592767 mIsRunningSelectResource = true ;
27602768
27612769 // If we have a 'src' attribute, use that exclusively.
@@ -2794,15 +2802,15 @@ void HTMLMediaElement::SelectResource() {
27942802 OwnerDoc ()->AddMediaElementWithMSE ();
27952803 }
27962804 DDLINKCHILD (" mediasource" , mMediaSource .get ());
2797- UpdatePreloadAction ();
2805+ UpdatePreloadAction (aCallingLocation );
27982806 if (mPreloadAction == HTMLMediaElement::PRELOAD_NONE && !mMediaSource ) {
27992807 // preload:none media, suspend the load here before we make any
28002808 // network requests.
28012809 SuspendLoad ();
28022810 return ;
28032811 }
28042812
2805- rv = LoadResource ();
2813+ rv = LoadResource (aCallingLocation );
28062814 if (NS_SUCCEEDED(rv)) {
28072815 return ;
28082816 }
@@ -2815,7 +2823,7 @@ void HTMLMediaElement::SelectResource() {
28152823 } else {
28162824 // Otherwise, the source elements will be used.
28172825 mIsLoadingFromSourceChildren = true ;
2818- LoadFromSourceChildren ();
2826+ LoadFromSourceChildren (aCallingLocation );
28192827 }
28202828}
28212829
@@ -2970,7 +2978,8 @@ void HTMLMediaElement::DealWithFailedElement(nsIContent* aSourceElement) {
29702978 &HTMLMediaElement::QueueLoadFromSourceTask));
29712979}
29722980
2973- void HTMLMediaElement::LoadFromSourceChildren () {
2981+ void HTMLMediaElement::LoadFromSourceChildren (
2982+ const JSCallingLocation& aCallingLocation) {
29742983 NS_ASSERTION (mDelayingLoadEvent ,
29752984 " Should delay load event (if in document) during load" );
29762985 NS_ASSERTION (mIsLoadingFromSourceChildren ,
@@ -3087,7 +3096,7 @@ void HTMLMediaElement::LoadFromSourceChildren() {
30873096 return ;
30883097 }
30893098
3090- if (NS_SUCCEEDED(LoadResource ())) {
3099+ if (NS_SUCCEEDED(LoadResource (aCallingLocation ))) {
30913100 return ;
30923101 }
30933102
@@ -3103,7 +3112,8 @@ void HTMLMediaElement::SuspendLoad() {
31033112 ChangeDelayLoadStatus (false );
31043113}
31053114
3106- void HTMLMediaElement::ResumeLoad (PreloadAction aAction) {
3115+ void HTMLMediaElement::ResumeLoad (PreloadAction aAction,
3116+ const JSCallingLocation& aCallingLocation) {
31073117 NS_ASSERTION (mSuspendedForPreloadNone ,
31083118 " Must be halted for preload:none to resume from preload:none "
31093119 " suspended load." );
@@ -3113,15 +3123,15 @@ void HTMLMediaElement::ResumeLoad(PreloadAction aAction) {
31133123 ChangeNetworkState (NETWORK_LOADING);
31143124 if (!mIsLoadingFromSourceChildren ) {
31153125 // We were loading from the element's src attribute.
3116- MediaResult rv = LoadResource ();
3126+ MediaResult rv = LoadResource (aCallingLocation );
31173127 if (NS_FAILED(rv)) {
31183128 NoSupportedMediaSourceError (rv.Description ());
31193129 }
31203130 } else {
31213131 // We were loading from a child <source> element. Try to resume the
31223132 // load of that child, and if that fails, try the next child.
3123- if (NS_FAILED(LoadResource ())) {
3124- LoadFromSourceChildren ();
3133+ if (NS_FAILED(LoadResource (aCallingLocation ))) {
3134+ LoadFromSourceChildren (aCallingLocation );
31253135 }
31263136 }
31273137}
@@ -3151,7 +3161,8 @@ uint32_t HTMLMediaElement::GetPreloadDefaultAuto() const {
31513161 HTMLMediaElement::PRELOAD_ENOUGH);
31523162}
31533163
3154- void HTMLMediaElement::UpdatePreloadAction () {
3164+ void HTMLMediaElement::UpdatePreloadAction (
3165+ const JSCallingLocation& aCallingLocation) {
31553166 PreloadAction nextAction = PRELOAD_UNDEFINED;
31563167 // If autoplay is set, or we're playing, we should always preload data,
31573168 // as we'll need it to play.
@@ -3201,7 +3212,7 @@ void HTMLMediaElement::UpdatePreloadAction() {
32013212 // Our load was previouly suspended due to the media having preload
32023213 // value "none". The preload value has changed to preload:auto, so
32033214 // resume the load.
3204- ResumeLoad (PRELOAD_ENOUGH);
3215+ ResumeLoad (PRELOAD_ENOUGH, aCallingLocation );
32053216 } else {
32063217 // Preload as much of the video as we can, i.e. don't suspend after
32073218 // the first frame.
@@ -3226,12 +3237,13 @@ void HTMLMediaElement::UpdatePreloadAction() {
32263237 // value "none". The preload value has changed to preload:metadata, so
32273238 // resume the load. We'll pause the load again after we've read the
32283239 // metadata.
3229- ResumeLoad (PRELOAD_METADATA);
3240+ ResumeLoad (PRELOAD_METADATA, aCallingLocation );
32303241 }
32313242 }
32323243}
32333244
3234- MediaResult HTMLMediaElement::LoadResource () {
3245+ MediaResult HTMLMediaElement::LoadResource (
3246+ const JSCallingLocation& aCallingLocation) {
32353247 NS_ASSERTION (mDelayingLoadEvent ,
32363248 " Should delay load event (if in document) during load" );
32373249
@@ -3283,7 +3295,7 @@ MediaResult HTMLMediaElement::LoadResource() {
32833295
32843296 AssertReadyStateIsNothing ();
32853297
3286- RefPtr<ChannelLoader> loader = new ChannelLoader;
3298+ RefPtr<ChannelLoader> loader = new ChannelLoader (aCallingLocation) ;
32873299 nsresult rv = loader->Load (this );
32883300 if (NS_SUCCEEDED(rv)) {
32893301 mChannelLoader = std::move (loader);
@@ -4711,7 +4723,7 @@ void HTMLMediaElement::PlayInternal(bool aHandlingUserInput) {
47114723 // invoke the media element's resource selection algorithm.
47124724 MaybeDoLoad ();
47134725 if (mSuspendedForPreloadNone ) {
4714- ResumeLoad (PRELOAD_ENOUGH);
4726+ ResumeLoad (PRELOAD_ENOUGH, JSCallingLocation::Get () );
47154727 }
47164728
47174729 // 4.8.12.8 - Step 5:
@@ -4742,7 +4754,7 @@ void HTMLMediaElement::PlayInternal(bool aHandlingUserInput) {
47424754 // We changed mPaused and mCanAutoplayFlag which can affect
47434755 // AddRemoveSelfReference and our preload status.
47444756 AddRemoveSelfReference ();
4745- UpdatePreloadAction ();
4757+ UpdatePreloadAction (JSCallingLocation::Get () );
47464758 UpdateSrcMediaStreamPlaying ();
47474759 StartMediaControlKeyListenerIfNeeded ();
47484760
@@ -5041,10 +5053,10 @@ void HTMLMediaElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
50415053 }
50425054 // This attribute can affect AddRemoveSelfReference
50435055 AddRemoveSelfReference ();
5044- UpdatePreloadAction ();
5056+ UpdatePreloadAction (JSCallingLocation::Get () );
50455057 }
50465058 } else if (aName == nsGkAtoms::preload) {
5047- UpdatePreloadAction ();
5059+ UpdatePreloadAction (JSCallingLocation::Get () );
50485060 } else if (aName == nsGkAtoms::loop) {
50495061 if (mDecoder ) {
50505062 mDecoder ->SetLooping (!!aValue);
@@ -5092,7 +5104,7 @@ nsresult HTMLMediaElement::BindToTree(BindContext& aContext, nsINode& aParent) {
50925104
50935105 // The preload action depends on the value of the autoplay attribute.
50945106 // It's value may have changed, so update it.
5095- UpdatePreloadAction ();
5107+ UpdatePreloadAction (JSCallingLocation::Get () );
50965108 }
50975109
50985110 NotifyDecoderActivityChanges ();
0 commit comments