Bug 966066 - Add principal observer to RTCPeerConnection. r=jib

This commit is contained in:
Martin Thomson 2014-04-25 10:34:00 -04:00
parent 21d09d72b7
commit 5acda6875e
3 changed files with 38 additions and 0 deletions

View File

@ -1470,6 +1470,18 @@ PeerConnectionImpl::SetDtlsConnected(bool aPrivacyRequested)
return NS_OK;
}
#ifdef MOZILLA_INTERNAL_API
void
PeerConnectionImpl::PrincipalChanged(DOMMediaStream* aMediaStream) {
nsIDocument* doc = GetWindow()->GetExtantDoc();
if (doc) {
mMedia->UpdateSinkIdentity_m(doc->NodePrincipal(), mPeerIdentity);
} else {
CSFLogInfo(logTag, "Can't update sink principal; document gone");
}
}
#endif
nsresult
PeerConnectionImpl::AddStream(DOMMediaStream &aMediaStream,
const MediaConstraintsInternal& aConstraints)
@ -1511,6 +1523,8 @@ PeerConnectionImpl::AddStream(DOMMediaStream &aMediaStream,
return res;
}
aMediaStream.AddPrincipalChangeObserver(this);
// TODO(ekr@rtfm.com): these integers should be the track IDs
if (hints & DOMMediaStream::HINT_CONTENTS_AUDIO) {
cc_media_constraints_t* cc_constraints = aConstraints.build();
@ -1539,6 +1553,8 @@ PeerConnectionImpl::RemoveStream(DOMMediaStream& aMediaStream) {
if (NS_FAILED(res))
return res;
aMediaStream.RemovePrincipalChangeObserver(this);
uint32_t hints = aMediaStream.GetHintContents();
if (hints & DOMMediaStream::HINT_CONTENTS_AUDIO) {
@ -1751,6 +1767,12 @@ PeerConnectionImpl::ShutdownMedia()
return;
#ifdef MOZILLA_INTERNAL_API
// before we destroy references to local streams, detach from them
for(uint32_t i = 0; i < media()->LocalStreamsLength(); ++i) {
LocalSourceStreamInfo *info = media()->GetLocalStream(i);
info->GetMediaStream()->RemovePrincipalChangeObserver(this);
}
// End of call to be recorded in Telemetry
if (!mStartTime.IsNull()){
TimeDuration timeDelta = TimeStamp::Now() - mStartTime;

View File

@ -38,6 +38,9 @@
#include "mozilla/dom/RTCStatsReportBinding.h"
#include "nsIPrincipal.h"
#include "mozilla/PeerIdentity.h"
#ifndef USE_FAKE_MEDIA_STREAMS
#include "DOMMediaStream.h"
#endif
#endif
namespace test {
@ -197,6 +200,7 @@ class PeerConnectionImpl MOZ_FINAL : public nsISupports,
#ifdef MOZILLA_INTERNAL_API
public mozilla::DataChannelConnection::DataConnectionListener,
public nsNSSShutDownObject,
public DOMMediaStream::PrincipalChangeObserver,
#endif
public sigslot::has_slots<>
{
@ -552,6 +556,10 @@ public:
RTCStatsQuery *query);
static nsresult ExecuteStatsQuery_s(RTCStatsQuery *query);
// for monitoring changes in stream ownership
// PeerConnectionMedia can't do it because it doesn't know about principals
virtual void PrincipalChanged(DOMMediaStream* aMediaStream) MOZ_OVERRIDE;
#endif
private:

View File

@ -244,6 +244,14 @@ public:
void SetTrackEnabled(mozilla::TrackID aTrackID, bool aEnabled) {}
class PrincipalChangeObserver
{
public:
virtual void PrincipalChanged(Fake_DOMMediaStream* aMediaStream) = 0;
};
void AddPrincipalChangeObserver(void* ignoredObserver) {}
void RemovePrincipalChangeObserver(void* ignoredObserver) {}
private:
nsRefPtr<Fake_MediaStream> mMediaStream;