Bug 1284909 - Allow raw deviceId constraints in gUM when caller is chrome. r=jesup

MozReview-Commit-ID: IB0BhGKbdam

--HG--
extra : rebase_source : 9ed1f4218e66bd3c96d044cacce167cbde79e775
This commit is contained in:
Jan-Ivar Bruaroey 2016-08-19 16:39:54 -04:00
Родитель 6aa106320d
Коммит de3b766278
4 изменённых файлов: 43 добавлений и 23 удалений

Просмотреть файл

@ -799,7 +799,8 @@ MediaDevice::FitnessDistance(nsString aN,
uint32_t
MediaDevice::GetBestFitnessDistance(
const nsTArray<const NormalizedConstraintSet*>& aConstraintSets)
const nsTArray<const NormalizedConstraintSet*>& aConstraintSets,
bool aIsChrome)
{
nsString mediaSource;
GetMediaSource(mediaSource);
@ -818,7 +819,11 @@ MediaDevice::GetBestFitnessDistance(
// Forward request to underlying object to interrogate per-mode capabilities.
// Pass in device's origin-specific id for deviceId constraint comparison.
nsString id;
GetId(id);
if (aIsChrome) {
GetRawId(id);
} else {
GetId(id);
}
return mSource->GetBestFitnessDistance(aConstraintSets, id);
}
@ -1333,6 +1338,7 @@ static auto& MediaManager_AnonymizeDevices = MediaManager::AnonymizeDevices;
already_AddRefed<MediaManager::PledgeChar>
MediaManager::SelectSettings(
MediaStreamConstraints& aConstraints,
bool aIsChrome,
RefPtr<Refcountable<UniquePtr<SourceSet>>>& aSources)
{
MOZ_ASSERT(NS_IsMainThread());
@ -1342,7 +1348,8 @@ MediaManager::SelectSettings(
// Algorithm accesses device capabilities code and must run on media thread.
// Modifies passed-in aSources.
MediaManager::PostTask(NewTaskFrom([id, aConstraints, aSources]() mutable {
MediaManager::PostTask(NewTaskFrom([id, aConstraints,
aSources, aIsChrome]() mutable {
auto& sources = **aSources;
// Since the advanced part of the constraints algorithm needs to know when
@ -1368,11 +1375,13 @@ MediaManager::SelectSettings(
if (needVideo && videos.Length()) {
badConstraint = MediaConstraintsHelper::SelectSettings(
NormalizedConstraints(GetInvariant(aConstraints.mVideo)), videos);
NormalizedConstraints(GetInvariant(aConstraints.mVideo)), videos,
aIsChrome);
}
if (!badConstraint && needAudio && audios.Length()) {
badConstraint = MediaConstraintsHelper::SelectSettings(
NormalizedConstraints(GetInvariant(aConstraints.mAudio)), audios);
NormalizedConstraints(GetInvariant(aConstraints.mAudio)), audios,
aIsChrome);
}
if (!badConstraint &&
!needVideo == !videos.Length() &&
@ -1414,6 +1423,7 @@ public:
uint64_t aWindowID, GetUserMediaCallbackMediaStreamListener *aListener,
MediaEnginePrefs &aPrefs,
const nsCString& aOrigin,
bool aIsChrome,
MediaManager::SourceSet* aSourceSet)
: mConstraints(aConstraints)
, mOnSuccess(aOnSuccess)
@ -1422,6 +1432,7 @@ public:
, mListener(aListener)
, mPrefs(aPrefs)
, mOrigin(aOrigin)
, mIsChrome(aIsChrome)
, mDeviceChosen(false)
, mSourceSet(aSourceSet)
, mManager(MediaManager::GetInstance())
@ -1473,7 +1484,7 @@ public:
nsTArray<RefPtr<AudioDevice>> audios;
audios.AppendElement(mAudioDevice);
badConstraint = MediaConstraintsHelper::SelectSettings(
NormalizedConstraints(constraints), audios);
NormalizedConstraints(constraints), audios, mIsChrome);
}
}
}
@ -1486,7 +1497,7 @@ public:
nsTArray<RefPtr<VideoDevice>> videos;
videos.AppendElement(mVideoDevice);
badConstraint = MediaConstraintsHelper::SelectSettings(
NormalizedConstraints(constraints), videos);
NormalizedConstraints(constraints), videos, mIsChrome);
}
if (mAudioDevice) {
mAudioDevice->Deallocate();
@ -1517,8 +1528,8 @@ public:
NS_DispatchToMainThread(do_AddRef(
new GetUserMediaStreamRunnable(mOnSuccess, mOnFailure, mWindowID,
mListener, mOrigin, mConstraints,
mAudioDevice, mVideoDevice,
mListener, mOrigin,
mConstraints, mAudioDevice, mVideoDevice,
peerIdentity)));
MOZ_ASSERT(!mOnSuccess);
MOZ_ASSERT(!mOnFailure);
@ -1600,6 +1611,7 @@ private:
RefPtr<VideoDevice> mVideoDevice;
MediaEnginePrefs mPrefs;
nsCString mOrigin;
bool mIsChrome;
bool mDeviceChosen;
public:
@ -2208,7 +2220,7 @@ MediaManager::GetUserMedia(nsPIDOMWindowInner* aWindow,
false) && !IsVistaOrLater()) ||
#endif
(!privileged && !HostIsHttps(*docURI)) ||
!HostHasPermission(*docURI)) {
(!isChrome && !HostHasPermission(*docURI))) {
RefPtr<MediaStreamError> error =
new MediaStreamError(aWindow,
NS_LITERAL_STRING("NotAllowedError"));
@ -2378,7 +2390,7 @@ MediaManager::GetUserMedia(nsPIDOMWindowInner* aWindow,
RefPtr<PledgeSourceSet> p = EnumerateDevicesImpl(windowID, videoType,
audioType, fake);
p->Then([this, onSuccess, onFailure, windowID, c, listener, askPermission,
prefs, isHTTPS, callID, origin](SourceSet*& aDevices) mutable {
prefs, isHTTPS, callID, origin, isChrome](SourceSet*& aDevices) mutable {
RefPtr<Refcountable<UniquePtr<SourceSet>>> devices(
new Refcountable<UniquePtr<SourceSet>>(aDevices)); // grab result
@ -2390,11 +2402,11 @@ MediaManager::GetUserMedia(nsPIDOMWindowInner* aWindow,
}
// Apply any constraints. This modifies the passed-in list.
RefPtr<PledgeChar> p2 = SelectSettings(c, devices);
RefPtr<PledgeChar> p2 = SelectSettings(c, isChrome, devices);
p2->Then([this, onSuccess, onFailure, windowID, c,
listener, askPermission, prefs, isHTTPS,
callID, origin, devices](const char*& badConstraint) mutable {
listener, askPermission, prefs, isHTTPS, callID,
origin, isChrome, devices](const char*& badConstraint) mutable {
// Ensure that the captured 'this' pointer and our windowID are still good.
auto* globalWindow = nsGlobalWindow::GetInnerWindowWithId(windowID);
@ -2441,6 +2453,7 @@ MediaManager::GetUserMedia(nsPIDOMWindowInner* aWindow,
onFailure.forget(),
windowID, listener,
prefs, origin,
isChrome,
devices->release()));
// Store the task w/callbacks.
mActiveCallbacks.Put(callID, task.forget());
@ -3489,10 +3502,11 @@ GetUserMediaCallbackMediaStreamListener::ApplyConstraintsToTrack(
RefPtr<MediaManager> mgr = MediaManager::GetInstance();
uint32_t id = mgr->mOutstandingVoidPledges.Append(*p);
uint64_t windowId = aWindow->WindowID();
bool isChrome = nsContentUtils::IsCallerChrome();
MediaManager::PostTask(NewTaskFrom([id, windowId,
audioDevice, videoDevice,
aConstraints]() mutable {
aConstraints, isChrome]() mutable {
MOZ_ASSERT(MediaManager::IsInMediaThread());
RefPtr<MediaManager> mgr = MediaManager::GetInstance();
const char* badConstraint = nullptr;
@ -3504,7 +3518,7 @@ GetUserMediaCallbackMediaStreamListener::ApplyConstraintsToTrack(
nsTArray<RefPtr<AudioDevice>> audios;
audios.AppendElement(audioDevice);
badConstraint = MediaConstraintsHelper::SelectSettings(
NormalizedConstraints(aConstraints), audios);
NormalizedConstraints(aConstraints), audios, isChrome);
}
} else {
rv = videoDevice->Restart(aConstraints, mgr->mPrefs, &badConstraint);
@ -3512,7 +3526,7 @@ GetUserMediaCallbackMediaStreamListener::ApplyConstraintsToTrack(
nsTArray<RefPtr<VideoDevice>> videos;
videos.AppendElement(videoDevice);
badConstraint = MediaConstraintsHelper::SelectSettings(
NormalizedConstraints(aConstraints), videos);
NormalizedConstraints(aConstraints), videos, isChrome);
}
}
NS_DispatchToMainThread(NewRunnableFrom([id, windowId, rv,

Просмотреть файл

@ -72,7 +72,8 @@ public:
void SetId(const nsAString& aID);
void SetRawId(const nsAString& aID);
virtual uint32_t GetBestFitnessDistance(
const nsTArray<const NormalizedConstraintSet*>& aConstraintSets);
const nsTArray<const NormalizedConstraintSet*>& aConstraintSets,
bool aIsChrome);
virtual Source* GetSource() = 0;
nsresult Allocate(const dom::MediaTrackConstraints &aConstraints,
const MediaEnginePrefs &aPrefs,
@ -289,6 +290,7 @@ private:
already_AddRefed<PledgeChar>
SelectSettings(
dom::MediaStreamConstraints& aConstraints,
bool aIsChrome,
RefPtr<media::Refcountable<UniquePtr<SourceSet>>>& aSources);
StreamListeners* AddWindowID(uint64_t aWindowId);

Просмотреть файл

@ -441,7 +441,8 @@ MediaConstraintsHelper::FindBadConstraint(
mDeviceId(MockDevice::HasThreadSafeRefCnt::value ? aDeviceId : nsString()) {}
uint32_t GetBestFitnessDistance(
const nsTArray<const NormalizedConstraintSet*>& aConstraintSets)
const nsTArray<const NormalizedConstraintSet*>& aConstraintSets,
bool aIsChrome)
{
return mMediaEngineSource->GetBestFitnessDistance(aConstraintSets,
mDeviceId);

Просмотреть файл

@ -310,7 +310,7 @@ protected:
MOZ_ASSERT(aDevices.Length());
for (auto& device : aDevices) {
if (device->GetBestFitnessDistance(sets) != UINT32_MAX) {
if (device->GetBestFitnessDistance(sets, false) != UINT32_MAX) {
return true;
}
}
@ -323,7 +323,8 @@ public:
template<class DeviceType>
static const char*
SelectSettings(const NormalizedConstraints &aConstraints,
nsTArray<RefPtr<DeviceType>>& aDevices)
nsTArray<RefPtr<DeviceType>>& aDevices,
bool aIsChrome)
{
auto& c = aConstraints;
@ -339,7 +340,8 @@ public:
std::multimap<uint32_t, RefPtr<DeviceType>> ordered;
for (uint32_t i = 0; i < aDevices.Length();) {
uint32_t distance = aDevices[i]->GetBestFitnessDistance(aggregateConstraints);
uint32_t distance = aDevices[i]->GetBestFitnessDistance(aggregateConstraints,
aIsChrome);
if (distance == UINT32_MAX) {
unsatisfactory.AppendElement(aDevices[i]);
aDevices.RemoveElementAt(i);
@ -365,7 +367,8 @@ public:
aggregateConstraints.AppendElement(&c.mAdvanced[i]);
nsTArray<RefPtr<DeviceType>> rejects;
for (uint32_t j = 0; j < aDevices.Length();) {
if (aDevices[j]->GetBestFitnessDistance(aggregateConstraints) == UINT32_MAX) {
if (aDevices[j]->GetBestFitnessDistance(aggregateConstraints,
aIsChrome) == UINT32_MAX) {
rejects.AppendElement(aDevices[j]);
aDevices.RemoveElementAt(j);
} else {