зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1208371 - Make PeerConnectionImpl pass its principal to MediaStreamTrack through a new RemoteTrackSource. r=mt
MozReview-Commit-ID: BxjQCHnmbDd --HG-- extra : rebase_source : 475db7268fcb7b377c942c0999ab02967aa8a606
This commit is contained in:
Родитель
7d39fb28c3
Коммит
4ce83c6b90
|
@ -495,23 +495,6 @@ PeerConnectionImpl::MakeMediaStream()
|
|||
|
||||
RefPtr<DOMMediaStream> stream =
|
||||
DOMMediaStream::CreateSourceStream(GetWindow(), graph);
|
||||
#if !defined(MOZILLA_EXTERNAL_LINKAGE)
|
||||
// Make the stream data (audio/video samples) accessible to the receiving page.
|
||||
// We're only certain that privacy hasn't been requested if we're connected.
|
||||
if (mDtlsConnected && !PrivacyRequested()) {
|
||||
nsIDocument* doc = GetWindow()->GetExtantDoc();
|
||||
if (!doc) {
|
||||
return nullptr;
|
||||
}
|
||||
stream->CombineWithPrincipal(doc->NodePrincipal());
|
||||
} else {
|
||||
// we're either certain that we need isolation for the streams, OR
|
||||
// we're not sure and we can fix the stream in SetDtlsConnected
|
||||
nsCOMPtr<nsIPrincipal> principal =
|
||||
do_CreateInstance(NS_NULLPRINCIPAL_CONTRACTID);
|
||||
stream->CombineWithPrincipal(principal);
|
||||
}
|
||||
#endif
|
||||
|
||||
CSFLogDebug(logTag, "Created media stream %p, inner: %p", stream.get(), stream->GetInputStream());
|
||||
|
||||
|
@ -1795,6 +1778,24 @@ PeerConnectionImpl::CreateNewRemoteTracks(RefPtr<PeerConnectionObserver>& aPco)
|
|||
size_t numNewVideoTracks = 0;
|
||||
size_t numPreexistingTrackIds = 0;
|
||||
|
||||
#if !defined(MOZILLA_EXTERNAL_LINKAGE)
|
||||
// Set the principal used for creating the tracks. This makes the stream
|
||||
// data (audio/video samples) accessible to the receiving page. We're
|
||||
// only certain that privacy hasn't been requested if we're connected.
|
||||
nsCOMPtr<nsIPrincipal> principal;
|
||||
if (mDtlsConnected && !PrivacyRequested()) {
|
||||
nsIDocument* doc = GetWindow()->GetExtantDoc();
|
||||
MOZ_ASSERT(doc);
|
||||
if (doc) {
|
||||
principal = doc->NodePrincipal();
|
||||
}
|
||||
} else {
|
||||
// we're either certain that we need isolation for the streams, OR
|
||||
// we're not sure and we can fix the stream in SetDtlsConnected
|
||||
principal = do_CreateInstance(NS_NULLPRINCIPAL_CONTRACTID);
|
||||
}
|
||||
#endif
|
||||
|
||||
for (auto j = tracks.begin(); j != tracks.end(); ++j) {
|
||||
RefPtr<JsepTrack> track = *j;
|
||||
if (!info->HasTrack(track->GetTrackId())) {
|
||||
|
@ -1808,16 +1809,22 @@ PeerConnectionImpl::CreateNewRemoteTracks(RefPtr<PeerConnectionObserver>& aPco)
|
|||
}
|
||||
info->AddTrack(track->GetTrackId());
|
||||
#if !defined(MOZILLA_EXTERNAL_LINKAGE)
|
||||
RefPtr<MediaStreamTrackSource> source =
|
||||
new BasicUnstoppableTrackSource(MediaSourceEnum::Other);
|
||||
RefPtr<RemoteTrackSource> source = new RemoteTrackSource(principal);
|
||||
DebugOnly<bool> sourceSet =
|
||||
info->SetTrackSource(track->GetTrackId(), source);
|
||||
NS_ASSERTION(sourceSet, "TrackSource was added in the wrong order. "
|
||||
"Did someone add a track from elsewhere?");
|
||||
TrackID trackID = info->GetNumericTrackId(track->GetTrackId());
|
||||
if (track->GetMediaType() == SdpMediaSection::kAudio) {
|
||||
info->GetMediaStream()->CreateOwnDOMTrack(
|
||||
info->GetNumericTrackId(track->GetTrackId()),
|
||||
MediaSegment::AUDIO, nsString(), source);
|
||||
info->GetMediaStream()->CreateOwnDOMTrack(trackID,
|
||||
MediaSegment::AUDIO,
|
||||
nsString(),
|
||||
source);
|
||||
} else {
|
||||
info->GetMediaStream()->CreateOwnDOMTrack(
|
||||
info->GetNumericTrackId(track->GetTrackId()),
|
||||
MediaSegment::VIDEO, nsString(), source);
|
||||
info->GetMediaStream()->CreateOwnDOMTrack(trackID,
|
||||
MediaSegment::VIDEO,
|
||||
nsString(),
|
||||
source);
|
||||
}
|
||||
#endif
|
||||
CSFLogDebug(logTag, "Added remote track %s/%s",
|
||||
|
|
|
@ -1215,10 +1215,13 @@ LocalSourceStreamInfo::UpdateSinkIdentity_m(nsIPrincipal* aPrincipal,
|
|||
|
||||
void RemoteSourceStreamInfo::UpdatePrincipal_m(nsIPrincipal* aPrincipal)
|
||||
{
|
||||
// this blasts away the existing principal
|
||||
// we only do this when we become certain that the stream is safe to make
|
||||
// accessible to the script principal
|
||||
mMediaStream->SetPrincipal(aPrincipal);
|
||||
// This blasts away the existing principal.
|
||||
// We only do this when we become certain that the all tracks are safe to make
|
||||
// accessible to the script principal.
|
||||
for (RefPtr<RemoteTrackSource>& source : mTrackSources) {
|
||||
MOZ_RELEASE_ASSERT(source);
|
||||
source->SetPrincipal(aPrincipal);
|
||||
}
|
||||
}
|
||||
#endif // MOZILLA_INTERNAL_API
|
||||
|
||||
|
|
|
@ -146,6 +146,31 @@ private:
|
|||
const std::string& trackId);
|
||||
};
|
||||
|
||||
#if !defined(MOZILLA_EXTERNAL_LINKAGE)
|
||||
class RemoteTrackSource : public dom::MediaStreamTrackSource
|
||||
{
|
||||
public:
|
||||
explicit RemoteTrackSource(nsIPrincipal* aPrincipal)
|
||||
: dom::MediaStreamTrackSource(aPrincipal, true) {}
|
||||
|
||||
dom::MediaSourceEnum GetMediaSource() const override
|
||||
{
|
||||
return dom::MediaSourceEnum::Other;
|
||||
}
|
||||
|
||||
void Stop() override { NS_ERROR("Can't stop a remote source!"); }
|
||||
|
||||
void SetPrincipal(nsIPrincipal* aPrincipal)
|
||||
{
|
||||
mPrincipal = aPrincipal;
|
||||
PrincipalChanged();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual ~RemoteTrackSource() {}
|
||||
};
|
||||
#endif
|
||||
|
||||
class RemoteSourceStreamInfo : public SourceStreamInfo {
|
||||
~RemoteSourceStreamInfo() {}
|
||||
public:
|
||||
|
@ -161,6 +186,18 @@ class RemoteSourceStreamInfo : public SourceStreamInfo {
|
|||
|
||||
#if !defined(MOZILLA_EXTERNAL_LINKAGE)
|
||||
void UpdatePrincipal_m(nsIPrincipal* aPrincipal);
|
||||
|
||||
// Track sources may only be set in the same order as tracks were added.
|
||||
// Returns true if the source was added, false otherwise.
|
||||
bool SetTrackSource(const std::string& track, RemoteTrackSource* source)
|
||||
{
|
||||
size_t nextIndex = mTrackSources.size();
|
||||
if (mTrackIdMap.size() < nextIndex || mTrackIdMap[nextIndex] != track) {
|
||||
return false;
|
||||
}
|
||||
mTrackSources.push_back(source);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RemoteSourceStreamInfo)
|
||||
|
@ -213,6 +250,12 @@ class RemoteSourceStreamInfo : public SourceStreamInfo {
|
|||
// and its dependencies can go away.
|
||||
std::vector<std::string> mTrackIdMap;
|
||||
|
||||
#if !defined(MOZILLA_EXTERNAL_LINKAGE)
|
||||
// MediaStreamTrackSources associated with this remote stream.
|
||||
// We use them for updating their principal if that's needed.
|
||||
std::vector<RefPtr<RemoteTrackSource>> mTrackSources;
|
||||
#endif
|
||||
|
||||
// True iff SetPullEnabled(true) has been called on the DOMMediaStream. This
|
||||
// happens when offer/answer concludes.
|
||||
bool mReceiving;
|
||||
|
|
Загрузка…
Ссылка в новой задаче