Bug 1458020 - 4. Add camera permission in the parent process; r=snorp

We had a permission error because we were trying to add camera
permission in the child process. Move it to the parent process, where
the permission is actually checked.

MozReview-Commit-ID: 2OE3BznlVTD
This commit is contained in:
Jim Chen 2018-05-18 10:16:04 -04:00
parent 4053e24872
commit 6ed91a89a9
3 changed files with 32 additions and 5 deletions

View File

@ -46,6 +46,26 @@ GeckoViewPermission.prototype = {
}
},
receiveMessage(aMsg) {
switch (aMsg.name) {
case "GeckoView:AddCameraPermission": {
let uri;
try {
// This fails for principals that serialize to "null", e.g. file URIs.
uri = Services.io.newURI(aMsg.data.origin);
} catch (e) {
uri = Services.io.newURI(aMsg.data.documentURI);
}
// Although the lifetime is "session" it will be removed upon
// use so it's more of a one-shot.
Services.perms.add(uri, "MediaManagerVideo",
Services.perms.ALLOW_ACTION,
Services.perms.EXPIRE_SESSION);
break;
}
}
},
handleMediaAskDevicePermission: function(aType, aCallback) {
let perms = [];
if (aType === "video" || aType === "all") {
@ -122,11 +142,10 @@ GeckoViewPermission.prototype = {
if (!video) {
throw new Error("invalid video id");
}
// Although the lifetime is "session" it will be removed upon
// use so it's more of a one-shot.
Services.perms.add(uri, "MediaManagerVideo",
Services.perms.ALLOW_ACTION,
Services.perms.EXPIRE_SESSION);
Services.cpmm.sendAsyncMessage("GeckoView:AddCameraPermission", {
origin: win.origin,
documentURI: win.document.documentURI,
});
allowedDevices.appendElement(video);
}
if (constraints.audio) {

View File

@ -46,6 +46,9 @@ GeckoViewStartup.prototype = {
"getUserMedia:request",
"PeerConnection:request",
],
ppmm: [
"GeckoView:AddCameraPermission",
],
});
if (Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_DEFAULT) {

View File

@ -68,6 +68,11 @@ var GeckoViewUtils = {
observers.forEach(topic => Services.obs.addObserver(observer, topic));
}
if (!this.IS_PARENT_PROCESS) {
// ppmm, mm, and ged are only available in the parent process.
return;
}
let addMMListener = (target, names) => {
let listener = msg => {
target.removeMessageListener(msg.name, listener);