Bug 983504 - Modify constraints for screen sharing. r=bholley,jib

This commit is contained in:
Matthew A. Miller 2014-07-08 00:01:27 -06:00
parent 5fb1d5ae53
commit 3e4a77c11c
7 changed files with 70 additions and 7 deletions

View File

@ -42,6 +42,19 @@ public:
}
}
}
// treat MediaSource special because it's always required
mRequired.mMediaSource = mMediaSource;
if (mMediaSource != dom::MediaSourceEnum::Camera && mAdvanced.WasPassed()) {
// iterate through advanced, forcing mediaSource to match "root"
auto& array = mAdvanced.Value();
for (uint32_t i = 0; i < array.Length(); i++) {
if (array[i].mMediaSource == dom::MediaSourceEnum::Camera) {
array[i].mMediaSource = mMediaSource;
}
}
}
}
protected:
MediaTrackConstraintSet& Triage(const Kind kind) {
@ -85,6 +98,9 @@ struct VideoTrackConstraintsN :
Triage(Kind::Width).mWidth = mWidth;
Triage(Kind::Height).mHeight = mHeight;
Triage(Kind::FrameRate).mFrameRate = mFrameRate;
// treat MediaSource special because it's always required
mRequired.mMediaSource = mMediaSource;
}
};

View File

@ -310,6 +310,9 @@ VideoDevice::VideoDevice(MediaEngineVideoSource* aSource)
mHasFacingMode = true;
mFacingMode = dom::VideoFacingModeEnum::User;
}
// dom::MediaSourceEnum::Camera;
mMediaSource = aSource->GetMediaSource();
}
AudioDevice::AudioDevice(MediaEngineAudioSource* aSource)
@ -361,6 +364,15 @@ MediaDevice::GetFacingMode(nsAString& aFacingMode)
return NS_OK;
}
NS_IMETHODIMP
MediaDevice::GetMediaSource(nsAString& aMediaSource)
{
aMediaSource.Assign(NS_ConvertUTF8toUTF16(
dom::MediaSourceEnumValues::strings[uint32_t(mMediaSource)].value));
return NS_OK;
}
MediaEngineVideoSource*
VideoDevice::GetSource()
{
@ -714,14 +726,19 @@ static bool SatisfyConstraintSet(const MediaEngineVideoSource *,
const MediaTrackConstraintSet &aConstraints,
nsIMediaDevice &aCandidate)
{
nsString s;
if (aConstraints.mFacingMode.WasPassed()) {
nsString s;
aCandidate.GetFacingMode(s);
if (!s.EqualsASCII(dom::VideoFacingModeEnumValues::strings[
uint32_t(aConstraints.mFacingMode.Value())].value)) {
return false;
}
}
aCandidate.GetMediaSource(s);
if (!s.EqualsASCII(dom::MediaSourceEnumValues::strings[
uint32_t(aConstraints.mMediaSource)].value)) {
return false;
}
// TODO: Add more video-specific constraints
return true;
}
@ -742,7 +759,7 @@ template<class SourceType, class ConstraintsType>
static SourceSet *
GetSources(MediaEngine *engine,
ConstraintsType &aConstraints,
void (MediaEngine::* aEnumerate)(nsTArray<nsRefPtr<SourceType> >*),
void (MediaEngine::* aEnumerate)(dom::MediaSourceEnum, nsTArray<nsRefPtr<SourceType> >*),
const char* media_device_name = nullptr)
{
ScopedDeletePtr<SourceSet> result(new SourceSet);
@ -753,7 +770,7 @@ static SourceSet *
SourceSet candidateSet;
{
nsTArray<nsRefPtr<SourceType> > sources;
(engine->*aEnumerate)(&sources);
(engine->*aEnumerate)(aConstraints.mMediaSource, &sources);
/**
* We're allowing multiple tabs to access the same camera for parity
* with Chrome. See bug 811757 for some of the issues surrounding
@ -1018,8 +1035,8 @@ public:
MOZ_ASSERT(mError);
if (mConstraints.mPicture || IsOn(mConstraints.mVideo)) {
VideoTrackConstraintsN constraints(GetInvariant(mConstraints.mVideo));
ScopedDeletePtr<SourceSet> sources (GetSources(backend, constraints,
&MediaEngine::EnumerateVideoDevices));
ScopedDeletePtr<SourceSet> sources(GetSources(backend, constraints,
&MediaEngine::EnumerateVideoDevices));
if (!sources->Length()) {
Fail(NS_LITERAL_STRING("NO_DEVICES_FOUND"));
@ -1180,8 +1197,8 @@ public:
if (IsOn(mConstraints.mVideo)) {
VideoTrackConstraintsN constraints(GetInvariant(mConstraints.mVideo));
ScopedDeletePtr<SourceSet> s(GetSources(backend, constraints,
&MediaEngine::EnumerateVideoDevices,
mLoopbackVideoDevice.get()));
&MediaEngine::EnumerateVideoDevices,
mLoopbackVideoDevice.get()));
final->MoveElementsFrom(*s);
}
if (IsOn(mConstraints.mAudio)) {
@ -1191,6 +1208,7 @@ public:
mLoopbackAudioDevice.get()));
final->MoveElementsFrom(*s);
}
NS_DispatchToMainThread(new DeviceSuccessCallbackRunnable(mWindowId,
mSuccess, mError,
final.forget()));
@ -1465,6 +1483,15 @@ MediaManager::GetUserMedia(bool aPrivileged,
onError.forget(), windowID, listener, mPrefs);
}
// deny screensharing request if support is disabled
if (c.mVideo.IsMediaTrackConstraints() &&
!Preferences::GetBool("media.getusermedia.screensharing.enabled", false)) {
auto& tc = c.mVideo.GetAsMediaTrackConstraints();
if (tc.mMediaSource != dom::MediaSourceEnum::Camera) {
return runnable->Denied(NS_LITERAL_STRING("PERMISSION_DENIED"));
}
}
#ifdef MOZ_B2G_CAMERA
if (mCameraManager == nullptr) {
mCameraManager = nsDOMCameraManager::CreateInstance(aWindow);

View File

@ -486,6 +486,7 @@ protected:
nsString mID;
bool mHasFacingMode;
dom::VideoFacingModeEnum mFacingMode;
dom::MediaSourceEnum mMediaSource;
nsRefPtr<MediaEngineSource> mSource;
};

View File

@ -13,6 +13,7 @@ interface nsIMediaDevice : nsISupports
readonly attribute DOMString name;
readonly attribute DOMString id;
readonly attribute DOMString facingMode;
readonly attribute DOMString mediaSource;
};
[scriptable, function, uuid(24544878-d35e-4962-8c5f-fb84e97bdfee)]

View File

@ -14,6 +14,12 @@ enum VideoFacingModeEnum {
"right"
};
enum MediaSourceEnum {
"camera",
"screen",
"application"
};
dictionary ConstrainLongRange {
long min = -2147483647; // +1 works around windows compiler bug
long max = 2147483647;

View File

@ -13,17 +13,20 @@ enum SupportedVideoConstraints {
"width",
"height",
"frameRate",
"mediaSource"
};
enum SupportedAudioConstraints {
"other"
};
dictionary MediaTrackConstraintSet {
ConstrainLongRange width;
ConstrainLongRange height;
ConstrainDoubleRange frameRate;
ConstrainVideoFacingMode facingMode;
ConstrainMediaSource mediaSource = "camera";
};
// TODO: Bug 995352 can't nest unions
@ -31,5 +34,8 @@ dictionary MediaTrackConstraintSet {
//typedef (double or ConstrainDoubleRange) ConstrainDouble;
typedef VideoFacingModeEnum ConstrainVideoFacingMode;
typedef MediaSourceEnum ConstrainMediaSource;
// TODO: Bug 767924 sequences in unions
//typedef (VideoFacingModeEnum or sequence<VideoFacingModeEnum>) ConstrainVideoFacingMode;
//typedef (MediaSourceEnum or sequence<MediaSourceEnum>) ConstrainMediaSource;

View File

@ -357,6 +357,12 @@ pref("media.navigator.enabled", true);
#endif
#endif
// do not enable screensharing before addressing security concerns: Bug 1035577
// do not enable screensharing before implementing app/window sharing: Bug 1036653
// do not enable screensharing before source constraints are finalized: Bug 1033885
// do not enable screensharing before UX is ready: Bug 1035577
pref("media.getusermedia.screensharing.enabled", false);
// TextTrack support
pref("media.webvtt.enabled", true);
pref("media.webvtt.regions.enabled", false);