Bug 1436523 - Change DeviceEnumerationType to scoped enum, add extra logging. r=achronop

Update the DeviceEnumerationType enum to scoped style enum for safety and
consistency. Add extra logging to aid in debugging test issues.

MozReview-Commit-ID: cm5bdlIcEG

--HG--
extra : rebase_source : bfcae3d49f809edfd0ed6ab3e516b8be0c0d517e
This commit is contained in:
Bryce Van Dyk 2018-03-16 15:09:26 -04:00
Родитель fdb3397eee
Коммит b1fb8c3b44
2 изменённых файлов: 67 добавлений и 38 удалений

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

@ -1858,8 +1858,8 @@ already_AddRefed<MediaManager::PledgeSourceSet>
MediaManager::EnumerateRawDevices(uint64_t aWindowId,
MediaSourceEnum aVideoType,
MediaSourceEnum aAudioType,
DeviceEnumerationType aVideoEnumType /* = Normal */,
DeviceEnumerationType aAudioEnumType /* = Normal */)
DeviceEnumerationType aVideoEnumType /* = DeviceEnumerationType::Normal */,
DeviceEnumerationType aAudioEnumType /* = DeviceEnumerationType::Normal */)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aVideoType != MediaSourceEnum::Other ||
@ -1869,15 +1869,24 @@ MediaManager::EnumerateRawDevices(uint64_t aWindowId,
// the requested device is not fake and thus the assert will pass. However,
// if the device is fake, aVideoType == MediaSourceEnum::Camera will be
// checked as well, ensuring that fake devices are of the camera type.
MOZ_ASSERT(aVideoEnumType != Fake || aVideoType == MediaSourceEnum::Camera,
MOZ_ASSERT(aVideoEnumType != DeviceEnumerationType::Fake ||
aVideoType == MediaSourceEnum::Camera,
"If fake cams are requested video type should be camera!");
MOZ_ASSERT(aVideoEnumType != Loopback || aVideoType == MediaSourceEnum::Camera,
MOZ_ASSERT(aVideoEnumType != DeviceEnumerationType::Loopback ||
aVideoType == MediaSourceEnum::Camera,
"If loopback video is requested video type should be camera!");
MOZ_ASSERT(aAudioEnumType != Fake || aAudioType == MediaSourceEnum::Microphone,
MOZ_ASSERT(aAudioEnumType != DeviceEnumerationType::Fake ||
aAudioType == MediaSourceEnum::Microphone,
"If fake mics are requested audio type should be microphone!");
MOZ_ASSERT(aAudioEnumType != Loopback || aAudioType == MediaSourceEnum::Microphone,
MOZ_ASSERT(aAudioEnumType != DeviceEnumerationType::Loopback ||
aAudioType == MediaSourceEnum::Microphone,
"If loopback audio is requested audio type should be microphone!");
LOG(("%s: aWindowId=%" PRIu64 ", aVideoType=%" PRIu8 ", aAudioType=%" PRIu8
", aVideoEnumType=%" PRIu8 ", aAudioEnumType=%" PRIu8,
__func__, aWindowId,
static_cast<uint8_t>(aVideoType), static_cast<uint8_t>(aAudioType),
static_cast<uint8_t>(aVideoEnumType), static_cast<uint8_t>(aAudioEnumType)));
RefPtr<PledgeSourceSet> p = new PledgeSourceSet();
uint32_t id = mOutstandingPledges.Append(*p);
@ -1885,17 +1894,17 @@ MediaManager::EnumerateRawDevices(uint64_t aWindowId,
bool hasAudio = aAudioType != MediaSourceEnum::Other;
// True of at least one of video or audio is a fake device
bool fakeDeviceRequested = (aVideoEnumType == Fake && hasVideo) ||
(aAudioEnumType == Fake && hasAudio);
bool fakeDeviceRequested = (aVideoEnumType == DeviceEnumerationType::Fake && hasVideo) ||
(aAudioEnumType == DeviceEnumerationType::Fake && hasAudio);
// True if at least one of video or audio is a real device
bool realDeviceRequested = (aVideoEnumType != Fake && hasVideo) ||
(aAudioEnumType != Fake && hasAudio);
bool realDeviceRequested = (aVideoEnumType != DeviceEnumerationType::Fake && hasVideo) ||
(aAudioEnumType != DeviceEnumerationType::Fake && hasAudio);
nsAutoCString videoLoopDev, audioLoopDev;
if (hasVideo && aVideoEnumType == Loopback) {
if (hasVideo && aVideoEnumType == DeviceEnumerationType::Loopback) {
Preferences::GetCString("media.video_loopback_dev", videoLoopDev);
}
if (hasAudio && aAudioEnumType == Loopback) {
if (hasAudio && aAudioEnumType == DeviceEnumerationType::Loopback) {
Preferences::GetCString("media.audio_loopback_dev", audioLoopDev);
}
@ -1919,7 +1928,9 @@ MediaManager::EnumerateRawDevices(uint64_t aWindowId,
if (hasVideo) {
SourceSet videos;
GetSources(aVideoEnumType == Fake ? fakeBackend : realBackend,
LOG(("EnumerateRawDevices Task: Getting video sources with %s backend",
aVideoEnumType == DeviceEnumerationType::Fake ? "fake" : "real"));
GetSources(aVideoEnumType == DeviceEnumerationType::Fake ? fakeBackend : realBackend,
aWindowId, aVideoType, videos, videoLoopDev.get());
for (auto& source : videos) {
result->AppendElement(source);
@ -1927,7 +1938,9 @@ MediaManager::EnumerateRawDevices(uint64_t aWindowId,
}
if (hasAudio) {
SourceSet audios;
GetSources(aAudioEnumType == Fake ? fakeBackend : realBackend,
LOG(("EnumerateRawDevices Task: Getting audio sources with %s backend",
aVideoEnumType == DeviceEnumerationType::Fake ? "fake" : "real"));
GetSources(aAudioEnumType == DeviceEnumerationType::Fake ? fakeBackend : realBackend,
aWindowId, aAudioType, audios, audioLoopDev.get());
for (auto& source : audios) {
result->AppendElement(source);
@ -2741,8 +2754,8 @@ MediaManager::GetUserMedia(nsPIDOMWindowInner* aWindow,
bool hasVideo = videoType != MediaSourceEnum::Other;
bool hasAudio = audioType != MediaSourceEnum::Other;
DeviceEnumerationType videoEnumerationType = Normal;
DeviceEnumerationType audioEnumerationType = Normal;
DeviceEnumerationType videoEnumerationType = DeviceEnumerationType::Normal;
DeviceEnumerationType audioEnumerationType = DeviceEnumerationType::Normal;
// Handle loopback and fake requests. For gUM we don't consider resist
// fingerprinting as users should be prompted anyway.
@ -2754,9 +2767,9 @@ MediaManager::GetUserMedia(nsPIDOMWindowInner* aWindow,
Preferences::GetCString("media.video_loopback_dev", videoLoopDev);
// Loopback prefs take precedence over fake prefs
if (!videoLoopDev.IsEmpty()) {
videoEnumerationType = Loopback;
videoEnumerationType = DeviceEnumerationType::Loopback;
} else if (wantFakes) {
videoEnumerationType = Fake;
videoEnumerationType = DeviceEnumerationType::Fake;
}
}
// Audio
@ -2764,18 +2777,27 @@ MediaManager::GetUserMedia(nsPIDOMWindowInner* aWindow,
Preferences::GetCString("media.audio_loopback_dev", audioLoopDev);
// Loopback prefs take precedence over fake prefs
if (!audioLoopDev.IsEmpty()) {
audioEnumerationType = Loopback;
audioEnumerationType = DeviceEnumerationType::Loopback;
} else if (wantFakes) {
audioEnumerationType = Fake;
audioEnumerationType = DeviceEnumerationType::Fake;
}
}
bool realDevicesRequested = (videoEnumerationType != Fake && hasVideo) ||
(audioEnumerationType != Fake && hasAudio);
bool realDevicesRequested = (videoEnumerationType != DeviceEnumerationType::Fake && hasVideo) ||
(audioEnumerationType != DeviceEnumerationType::Fake && hasAudio);
bool askPermission =
(!privileged || Preferences::GetBool("media.navigator.permission.force")) &&
(realDevicesRequested || Preferences::GetBool("media.navigator.permission.fake"));
LOG(("%s: Preparing to enumerate devices. windowId=%" PRIu64
", videoType=%" PRIu8 ", audioType=%" PRIu8
", videoEnumerationType=%" PRIu8 ", audioEnumerationType=%" PRIu8
", askPermission=%s",
__func__, windowID,
static_cast<uint8_t>(videoType), static_cast<uint8_t>(audioType),
static_cast<uint8_t>(videoEnumerationType), static_cast<uint8_t>(audioEnumerationType),
askPermission ? "true" : "false"));
RefPtr<PledgeSourceSet> p = EnumerateDevicesImpl(windowID, videoType,
audioType,
videoEnumerationType,
@ -2996,10 +3018,16 @@ already_AddRefed<MediaManager::PledgeSourceSet>
MediaManager::EnumerateDevicesImpl(uint64_t aWindowId,
MediaSourceEnum aVideoType,
MediaSourceEnum aAudioType,
DeviceEnumerationType aVideoEnumType /* = Normal */,
DeviceEnumerationType aAudioEnumType /* = Normal */)
DeviceEnumerationType aVideoEnumType /* = DeviceEnumerationType::Normal */,
DeviceEnumerationType aAudioEnumType /* = DeviceEnumerationType::Normal */)
{
MOZ_ASSERT(NS_IsMainThread());
LOG(("%s: aWindowId=%" PRIu64 ", aVideoType=%" PRIu8 ", aAudioType=%" PRIu8
", aVideoEnumType=%" PRIu8 ", aAudioEnumType=%" PRIu8,
__func__, aWindowId,
static_cast<uint8_t>(aVideoType), static_cast<uint8_t>(aAudioType),
static_cast<uint8_t>(aVideoEnumType), static_cast<uint8_t>(aAudioEnumType)));
nsPIDOMWindowInner* window =
nsGlobalWindowInner::GetInnerWindowWithId(aWindowId)->AsInner();
@ -3066,7 +3094,8 @@ MediaManager::EnumerateDevicesImpl(uint64_t aWindowId,
// their IDs.
if (aVideoType == MediaSourceEnum::Camera &&
aAudioType == MediaSourceEnum::Microphone &&
(aVideoEnumType != Fake || aAudioEnumType != Fake)) {
(aVideoEnumType != DeviceEnumerationType::Fake ||
aAudioEnumType != DeviceEnumerationType::Fake)) {
mgr->mDeviceIDs.Clear();
for (auto& device : *devices) {
nsString id;
@ -3121,14 +3150,14 @@ MediaManager::EnumerateDevices(nsPIDOMWindowInner* aWindow,
RefPtr<SourceListener> sourceListener = new SourceListener();
windowListener->Register(sourceListener);
DeviceEnumerationType videoEnumerationType = Normal;
DeviceEnumerationType audioEnumerationType = Normal;
DeviceEnumerationType videoEnumerationType = DeviceEnumerationType::Normal;
DeviceEnumerationType audioEnumerationType = DeviceEnumerationType::Normal;
bool resistFingerprinting = nsContentUtils::ResistFingerprinting(aCallerType);
// In order of precedence: resist fingerprinting > loopback > fake pref
if (resistFingerprinting) {
videoEnumerationType = Fake;
audioEnumerationType = Fake;
videoEnumerationType = DeviceEnumerationType::Fake;
audioEnumerationType = DeviceEnumerationType::Fake;
} else {
// Handle loopback and fake requests
nsAutoCString videoLoopDev, audioLoopDev;
@ -3137,17 +3166,17 @@ MediaManager::EnumerateDevices(nsPIDOMWindowInner* aWindow,
Preferences::GetCString("media.video_loopback_dev", videoLoopDev);
// Loopback prefs take precedence over fake prefs
if (!videoLoopDev.IsEmpty()) {
videoEnumerationType = Loopback;
videoEnumerationType = DeviceEnumerationType::Loopback;
} else if (wantFakes) {
videoEnumerationType = Fake;
videoEnumerationType = DeviceEnumerationType::Fake;
}
// Audio
Preferences::GetCString("media.audio_loopback_dev", audioLoopDev);
// Loopback prefs take precedence over fake prefs
if (!audioLoopDev.IsEmpty()) {
audioEnumerationType = Loopback;
audioEnumerationType = DeviceEnumerationType::Loopback;
} else if (wantFakes) {
audioEnumerationType = Fake;
audioEnumerationType = DeviceEnumerationType::Fake;
}
}

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

@ -231,7 +231,7 @@ public: // TODO: make private once we upgrade to GCC 4.8+ on linux.
static void AnonymizeDevices(SourceSet& aDevices, const nsACString& aOriginKey);
static already_AddRefed<nsIWritableVariant> ToJSArray(SourceSet& aDevices);
private:
enum DeviceEnumerationType {
enum class DeviceEnumerationType :uint8_t {
Normal, // Enumeration should not return loopback or fake devices
Fake, // Enumeration should return fake device(s)
Loopback /* Enumeration should return loopback device(s) (possibly in
@ -241,14 +241,14 @@ private:
EnumerateRawDevices(uint64_t aWindowId,
dom::MediaSourceEnum aVideoType,
dom::MediaSourceEnum aAudioType,
DeviceEnumerationType aVideoEnumType = Normal ,
DeviceEnumerationType aAudioEnumType = Normal);
DeviceEnumerationType aVideoEnumType = DeviceEnumerationType::Normal,
DeviceEnumerationType aAudioEnumType = DeviceEnumerationType::Normal);
already_AddRefed<PledgeSourceSet>
EnumerateDevicesImpl(uint64_t aWindowId,
dom::MediaSourceEnum aVideoType,
dom::MediaSourceEnum aAudioType,
DeviceEnumerationType aVideoEnumType = Normal,
DeviceEnumerationType aAudioEnumType = Normal);
DeviceEnumerationType aVideoEnumType = DeviceEnumerationType::Normal,
DeviceEnumerationType aAudioEnumType = DeviceEnumerationType::Normal);
already_AddRefed<PledgeChar>
SelectSettings(
dom::MediaStreamConstraints& aConstraints,