Bug 1732409 make getUserMedia() permission prompt requirement independent of "media.navigator.streams.fake" r=jib

"media.navigator.permission.disabled" exists for controlling the permission
prompt separately.

This will allow consolidation of camera and microphone preference handling
into EnumerateRawDevices().  Although auto-disabling permission with
"media.navigator.streams.fake" is sometimes useful for tests, it is actually
easier to consider them independently because sometimes the auto-disabling
needs to be overridden.

The logic to disable the permission prompt with content-exposed fake:true
parameter is maintained as is.

The CamerasParent usage of "media.navigator.permission.fake" seems to have
been a misunderstanding in
https://hg.mozilla.org/mozilla-central/rev/c5d6c3e00c91dd0595a12b145c66cf4f2a890591#l6.129

Differential Revision: https://phabricator.services.mozilla.com/D132897
This commit is contained in:
Karl Tomlinson 2021-12-26 01:38:58 +00:00
Родитель 300a8443dd
Коммит 0332d2ebf0
6 изменённых файлов: 12 добавлений и 15 удалений

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

@ -2685,14 +2685,15 @@ RefPtr<MediaManager::StreamPromise> MediaManager::GetUserMedia(
audioEnumerationType = DeviceEnumerationType::Fake; audioEnumerationType = DeviceEnumerationType::Fake;
} }
} }
// fake:true is effective only for microphone and camera devices, so
bool realDevicesRequested = // permission must be requested for screen capture even if fake:true is set.
(videoEnumerationType != DeviceEnumerationType::Fake && hasVideo) || bool hasOnlyForcedFakes =
(audioEnumerationType != DeviceEnumerationType::Fake && hasAudio); forceFakes && (!hasVideo || videoType == MediaSourceEnum::Camera) &&
(!hasAudio || audioType == MediaSourceEnum::Microphone);
bool askPermission = bool askPermission =
(!privileged || (!privileged ||
Preferences::GetBool("media.navigator.permission.force")) && Preferences::GetBool("media.navigator.permission.force")) &&
(realDevicesRequested || (!hasOnlyForcedFakes ||
Preferences::GetBool("media.navigator.permission.fake")); Preferences::GetBool("media.navigator.permission.fake"));
LOG("%s: Preparing to enumerate devices. windowId=%" PRIu64 LOG("%s: Preparing to enumerate devices. windowId=%" PRIu64

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

@ -67,7 +67,6 @@ function setupTestPreferences() {
["media.autoplay.blocking_policy", 0], ["media.autoplay.blocking_policy", 0],
["media.autoplay.block-event.enabled", true], ["media.autoplay.block-event.enabled", true],
["media.autoplay.block-webaudio", true], ["media.autoplay.block-webaudio", true],
["media.navigator.permission.fake", true],
], ],
}); });
} }

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

@ -721,10 +721,9 @@ mozilla::ipc::IPCResult CamerasParent::RecvAllocateCapture(
if (!allowed) { if (!allowed) {
// Developer preference for turning off permission check. // Developer preference for turning off permission check.
if (Preferences::GetBool("media.navigator.permission.disabled", if (Preferences::GetBool("media.navigator.permission.disabled",
false) || false)) {
Preferences::GetBool("media.navigator.permission.fake")) {
allowed = true; allowed = true;
LOG("No permission but checks are disabled or fake sources active"); LOG("No permission but checks are disabled");
} else { } else {
LOG("No camera permission for this origin"); LOG("No camera permission for this origin");
} }

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

@ -72,11 +72,8 @@ async function pushGetUserMediaTestPrefs({
); );
} }
} }
if (loopbackAudio || loopbackVideo) { // Prevent presentation of the gUM permission prompt.
// Prevent gUM permission prompt. Since loopback devices are considered testPrefs.push(["media.navigator.permission.disabled", true]);
// real devices we need to set prefs so the gUM prompt isn't presented.
testPrefs.push(["media.navigator.permission.disabled", true]);
}
return SpecialPowers.pushPrefEnv({ set: testPrefs }); return SpecialPowers.pushPrefEnv({ set: testPrefs });
} }

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

@ -28,7 +28,6 @@ let getDevices = async constraints => {
runTest(async () => { runTest(async () => {
await pushPrefs(["media.navigator.permission.disabled", true], await pushPrefs(["media.navigator.permission.disabled", true],
["media.navigator.permission.fake", true],
["media.navigator.permission.force", true]); ["media.navigator.permission.force", true]);
let devices = await getDevices({video: { mediaSource: "window" }}); let devices = await getDevices({video: { mediaSource: "window" }});
ok(devices.length, "Found one or more windows."); ok(devices.length, "Found one or more windows.");

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

@ -21,6 +21,8 @@ user_pref("extensions.update.notifyUser", false);
user_pref("focusmanager.testmode", true); user_pref("focusmanager.testmode", true);
// Enable fake media streams for getUserMedia // Enable fake media streams for getUserMedia
user_pref("media.navigator.streams.fake", true); user_pref("media.navigator.streams.fake", true);
// Disable permission prompt for getUserMedia
user_pref("media.navigator.permission.disabled", true);
// Enable pre-fetching of resources // Enable pre-fetching of resources
user_pref("network.preload", true); user_pref("network.preload", true);
// Enable direct connection // Enable direct connection