Bug 1393369. P1 - virtualize MediaDecoder::GetCurrentPrincipal() so the sub-classes know how to calculate the current principal.
MozReview-Commit-ID: EOUtPE4hfgO
--- a/dom/media/ChannelMediaDecoder.cpp
+++ b/dom/media/ChannelMediaDecoder.cpp
@@ -482,16 +482,23 @@ ChannelMediaDecoder::ShouldThrottleDownl
if (!stats.mDownloadRateReliable || !stats.mPlaybackRateReliable) {
return false;
}
uint32_t factor =
std::max(2u, Preferences::GetUint("media.throttle-factor", 2));
return stats.mDownloadRate > factor * stats.mPlaybackRate;
}
+already_AddRefed<nsIPrincipal>
+ChannelMediaDecoder::GetCurrentPrincipal()
+{
+ MOZ_ASSERT(NS_IsMainThread());
+ return mResource ? mResource->GetCurrentPrincipal() : nullptr;
+}
+
bool
ChannelMediaDecoder::IsTransportSeekable()
{
MOZ_ASSERT(NS_IsMainThread());
return mResource->IsTransportSeekable();
}
void
--- a/dom/media/ChannelMediaDecoder.h
+++ b/dom/media/ChannelMediaDecoder.h
@@ -73,16 +73,17 @@ public:
// Create a new decoder of the same type as this one.
already_AddRefed<ChannelMediaDecoder> Clone(MediaDecoderInit& aInit);
nsresult Load(nsIChannel* aChannel,
bool aIsPrivateBrowsing,
nsIStreamListener** aStreamListener);
+ already_AddRefed<nsIPrincipal> GetCurrentPrincipal() override;
bool IsTransportSeekable() override;
void SetLoadInBackground(bool aLoadInBackground) override;
void Suspend() override;
void Resume() override;
private:
MediaResource* GetResource() const override final;
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -695,25 +695,16 @@ MediaDecoder::CallSeek(const SeekTarget&
double
MediaDecoder::GetCurrentTime()
{
MOZ_ASSERT(NS_IsMainThread());
AbstractThread::AutoEnter context(AbstractMainThread());
return mLogicalPosition;
}
-already_AddRefed<nsIPrincipal>
-MediaDecoder::GetCurrentPrincipal()
-{
- MOZ_ASSERT(NS_IsMainThread());
- MediaResource* r = GetResource();
- AbstractThread::AutoEnter context(AbstractMainThread());
- return r ? r->GetCurrentPrincipal() : nullptr;
-}
-
void
MediaDecoder::OnMetadataUpdate(TimedMetadata&& aMetadata)
{
MOZ_ASSERT(NS_IsMainThread());
AbstractThread::AutoEnter context(AbstractMainThread());
GetOwner()->RemoveMediaTracks();
MetadataLoaded(MakeUnique<MediaInfo>(*aMetadata.mInfo),
UniquePtr<MetadataTags>(aMetadata.mTags.forget()),
--- a/dom/media/MediaDecoder.h
+++ b/dom/media/MediaDecoder.h
@@ -116,17 +116,17 @@ public:
// The decoder should notify its owner to drop the reference to the decoder
// to prevent further calls into the decoder.
void NotifyXPCOMShutdown();
// Called if the media file encounters a network error.
void NetworkError();
// Return the principal of the current URI being played or downloaded.
- virtual already_AddRefed<nsIPrincipal> GetCurrentPrincipal();
+ virtual already_AddRefed<nsIPrincipal> GetCurrentPrincipal() = 0;
// Return the time position in the video stream being
// played measured in seconds.
virtual double GetCurrentTime();
// Seek to the time position in (seconds) from the start of the video.
// If aDoFastSeek is true, we'll seek to the sync point/keyframe preceeding
// the seek target.
--- a/dom/media/hls/HLSDecoder.cpp
+++ b/dom/media/hls/HLSDecoder.cpp
@@ -87,16 +87,23 @@ HLSDecoder::Load(nsIChannel* aChannel)
}
SetStateMachine(CreateStateMachine());
NS_ENSURE_TRUE(GetStateMachine(), NS_ERROR_FAILURE);
return InitializeStateMachine();
}
+already_AddRefed<nsIPrincipal>
+HLSDecoder::GetCurrentPrincipal()
+{
+ MOZ_ASSERT(NS_IsMainThread());
+ return mResource ? mResource->GetCurrentPrincipal() : nullptr;
+}
+
nsresult
HLSDecoder::Play()
{
MOZ_ASSERT(NS_IsMainThread());
HLS_DEBUG("HLSDecoder", "MediaElement called Play");
auto resourceWrapper = mResource->GetResourceWrapper();
resourceWrapper->Play();
return MediaDecoder::Play();
--- a/dom/media/hls/HLSDecoder.h
+++ b/dom/media/hls/HLSDecoder.h
@@ -32,16 +32,17 @@ public:
static bool IsSupportedType(const MediaContainerType& aContainerType);
nsresult Load(nsIChannel* aChannel);
nsresult Play() override;
void Pause() override;
+ already_AddRefed<nsIPrincipal> GetCurrentPrincipal() override;
bool IsTransportSeekable() override { return true; }
void Suspend() override;
void Resume() override;
private:
MediaResource* GetResource() const override final;
MediaDecoderStateMachine* CreateStateMachine();
--- a/dom/media/mediasource/MediaSourceDecoder.cpp
+++ b/dom/media/mediasource/MediaSourceDecoder.cpp
@@ -357,12 +357,19 @@ MediaSourceDecoder::NotifyInitDataArrive
MOZ_ASSERT(NS_IsMainThread());
AbstractThread::AutoEnter context(AbstractMainThread());
if (mDemuxer) {
mDemuxer->NotifyInitDataArrived();
}
}
+already_AddRefed<nsIPrincipal>
+MediaSourceDecoder::GetCurrentPrincipal()
+{
+ MOZ_ASSERT(NS_IsMainThread());
+ return mResource ? mResource->GetCurrentPrincipal() : nullptr;
+}
+
#undef MSE_DEBUG
#undef MSE_DEBUGV
} // namespace mozilla
--- a/dom/media/mediasource/MediaSourceDecoder.h
+++ b/dom/media/mediasource/MediaSourceDecoder.h
@@ -44,16 +44,18 @@ public:
void SetInitialDuration(int64_t aDuration);
void SetMediaSourceDuration(double aDuration);
MediaSourceDemuxer* GetDemuxer()
{
return mDemuxer;
}
+ already_AddRefed<nsIPrincipal> GetCurrentPrincipal() override;
+
bool IsTransportSeekable() override { return true; }
// Returns a string describing the state of the MediaSource internal
// buffered data. Used for debugging purposes.
void GetMozDebugReaderData(nsACString& aString) override;
void AddSizeOfResources(ResourceSizes* aSizes) override;