Bug 1401460 - update principals in OnStartRequest().
See comment 0 for the rationale.
The principal will not change after OnStartRequest().
MozReview-Commit-ID: K2HyWBBzGmC
--- a/dom/media/ChannelMediaResource.cpp
+++ b/dom/media/ChannelMediaResource.cpp
@@ -259,16 +259,21 @@ ChannelMediaResource::OnStartRequest(nsI
// and the server isn't sending Accept-Ranges:bytes then we don't
// support seeking. We also can't seek in compressed streams.
seekable = !isCompressed && acceptsRanges;
} else {
// Not an HTTP channel. Assume data will be sent from position zero.
startOffset = 0;
}
+ // Update principals before OnDataAvailable() putting the data in the cache.
+ // This is important, we want to make sure all principals are updated before
+ // any consumer can see the new data.
+ UpdatePrincipal();
+
mCacheStream.NotifyDataStarted(mLoadID, startOffset);
mCacheStream.SetTransportSeekable(seekable);
mChannelStatistics.Start();
mReopenOnError = false;
mSuspendAgent.UpdateSuspendedStatusIfNeeded();
// Fires an initial progress event.
@@ -408,22 +413,16 @@ nsresult
ChannelMediaResource::OnDataAvailable(uint32_t aLoadID,
nsIInputStream* aStream,
uint32_t aCount)
{
// This might happen off the main thread.
// Don't assert |mChannel.get() == aRequest| since reading mChannel here off
// the main thread is a data race.
- // Update principals before putting the data in the cache. This is important,
- // we want to make sure all principals are updated before any consumer can see
- // the new data.
- // TODO: Handle the case where OnDataAvailable() runs off the main thread.
- UpdatePrincipal();
-
RefPtr<ChannelMediaResource> self = this;
nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction(
"ChannelMediaResource::OnDataAvailable",
[self, aCount]() { self->mChannelStatistics.AddBytes(aCount); });
mCallback->AbstractMainThread()->Dispatch(r.forget());
Closure closure{ aLoadID, this };
uint32_t count = aCount;
@@ -779,19 +778,20 @@ ChannelMediaResource::CacheClientNotifyP
mCallback->NotifyPrincipalChanged();
}
void
ChannelMediaResource::UpdatePrincipal()
{
MOZ_ASSERT(NS_IsMainThread());
+ MOZ_ASSERT(mChannel);
nsCOMPtr<nsIPrincipal> principal;
nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
- if (secMan && mChannel) {
+ if (secMan) {
secMan->GetChannelResultPrincipal(mChannel, getter_AddRefs(principal));
mCacheStream.UpdatePrincipal(principal);
}
}
void
ChannelMediaResource::CacheClientNotifySuspendedStatusChanged()
{