Skip to content

Commit

Permalink
Bug 1756245 - Migrate GeckoViewMedia to actor. r=owlish
Browse files Browse the repository at this point in the history
  • Loading branch information
agi committed May 17, 2022
1 parent 3692ee3 commit a288e5c
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 127 deletions.
7 changes: 7 additions & 0 deletions mobile/android/actors/GeckoViewPermissionChild.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ class GeckoViewPermissionChild extends GeckoViewActorChild {
return this.sendQuery("GetAppPermissions", aPermissions);
}

mediaRecordingStatusChanged(aDevices) {
return this.eventDispatcher.sendRequest({
type: "GeckoView:MediaRecordingStatusChanged",
devices: aDevices,
});
}

async promptPermission(aRequest) {
// Only allow exactly one permission request here.
const types = aRequest.types.QueryInterface(Ci.nsIArray);
Expand Down
96 changes: 82 additions & 14 deletions mobile/android/actors/GeckoViewPermissionProcessChild.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,27 @@ const { GeckoViewUtils } = ChromeUtils.import(
"resource://gre/modules/GeckoViewUtils.jsm"
);
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);

XPCOMUtils.defineLazyServiceGetter(
this,
"MediaManagerService",
"@mozilla.org/mediaManagerService;1",
"nsIMediaManagerService"
);

const STATUS_RECORDING = "recording";
const STATUS_INACTIVE = "inactive";
const TYPE_CAMERA = "camera";
const TYPE_MICROPHONE = "microphone";

class GeckoViewPermissionProcessChild extends JSProcessActorChild {
getActor(window) {
return window.windowGlobalChild.getActor("GeckoViewPermission");
}

/* ---------- nsIObserver ---------- */
async observe(aSubject, aTopic, aData) {
switch (aTopic) {
Expand Down Expand Up @@ -45,7 +64,60 @@ class GeckoViewPermissionProcessChild extends JSProcessActorChild {
);
break;
}
case "recording-device-events": {
this.handleRecordingDeviceEvents(aSubject);
break;
}
}
}

handleRecordingDeviceEvents(aRequest) {
aRequest.QueryInterface(Ci.nsIPropertyBag2);
const contentWindow = aRequest.getProperty("window");
const devices = [];

const getStatusString = function(activityStatus) {
switch (activityStatus) {
case MediaManagerService.STATE_CAPTURE_ENABLED:
case MediaManagerService.STATE_CAPTURE_DISABLED:
return STATUS_RECORDING;
case MediaManagerService.STATE_NOCAPTURE:
return STATUS_INACTIVE;
default:
throw new Error("Unexpected activityStatus value");
}
};

const hasCamera = {};
const hasMicrophone = {};
const screen = {};
const window = {};
const browser = {};
const mediaDevices = {};
MediaManagerService.mediaCaptureWindowState(
contentWindow,
hasCamera,
hasMicrophone,
screen,
window,
browser,
mediaDevices
);
var cameraStatus = getStatusString(hasCamera.value);
var microphoneStatus = getStatusString(hasMicrophone.value);
if (hasCamera.value != MediaManagerService.STATE_NOCAPTURE) {
devices.push({
type: TYPE_CAMERA,
status: cameraStatus,
});
}
if (hasMicrophone.value != MediaManagerService.STATE_NOCAPTURE) {
devices.push({
type: TYPE_MICROPHONE,
status: microphoneStatus,
});
}
this.getActor(contentWindow).mediaRecordingStatusChanged(devices);
}

async handleMediaRequest(aRequest) {
Expand Down Expand Up @@ -84,17 +156,15 @@ class GeckoViewPermissionProcessChild extends JSProcessActorChild {
return null;
}

const response = await window.windowGlobalChild
.getActor("GeckoViewPermission")
.getMediaPermission({
uri: window.document.documentURI,
video: constraints.video
? sources.filter(source => source.type === "videoinput")
: null,
audio: constraints.audio
? sources.filter(source => source.type === "audioinput")
: null,
});
const response = await this.getActor(window).getMediaPermission({
uri: window.document.documentURI,
video: constraints.video
? sources.filter(source => source.type === "videoinput")
: null,
audio: constraints.audio
? sources.filter(source => source.type === "audioinput")
: null,
});

if (!response) {
// Rejected.
Expand All @@ -110,9 +180,7 @@ class GeckoViewPermissionProcessChild extends JSProcessActorChild {
Cu.reportError("Media device error: invalid video id");
return null;
}
await window.windowGlobalChild
.getActor("GeckoViewPermission")
.addCameraPermission();
await this.getActor(window).addCameraPermission();
allowedDevices.appendElement(video);
}
if (constraints.audio) {
Expand Down
7 changes: 1 addition & 6 deletions mobile/android/components/geckoview/GeckoViewStartup.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const JSPROCESSACTORS = {
observers: [
"getUserMedia:ask-device-permission",
"getUserMedia:request",
"recording-device-events",
"PeerConnection:request",
],
},
Expand Down Expand Up @@ -99,12 +100,6 @@ class GeckoViewStartup {
switch (aTopic) {
case "content-process-ready-for-script":
case "app-startup": {
// Parent and content process.
GeckoViewUtils.addLazyGetter(this, "GeckoViewRecordingMedia", {
module: "resource://gre/modules/GeckoViewMedia.jsm",
observers: ["recording-device-events"],
});

GeckoViewUtils.addLazyGetter(this, "GeckoViewConsole", {
module: "resource://gre/modules/GeckoViewConsole.jsm",
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,6 @@ class MediaDelegateXOriginTest : BaseSessionTest() {
}

@Test fun testDeviceRecordingEventAudioAndVideoInXOriginIframe() {
// TODO: Bug 1648153
assumeThat(sessionRule.env.isFission, Matchers.equalTo(false))

// TODO: needs bug 1700243
assumeThat(sessionRule.env.isIsolatedProcess, Matchers.equalTo(false))

Expand All @@ -166,9 +163,6 @@ class MediaDelegateXOriginTest : BaseSessionTest() {
}

@Test fun testDeviceRecordingEventAudioAndVideoInXOriginIframeNoAllow() {
// TODO: Bug 1648153
assumeThat(sessionRule.env.isFission, Matchers.equalTo(false))

mainSession.loadTestPath(GETUSERMEDIA_XORIGIN_CONTAINER_HTML_PATH)
mainSession.waitForPageStop()

Expand Down
100 changes: 0 additions & 100 deletions mobile/android/modules/geckoview/GeckoViewMedia.jsm

This file was deleted.

1 change: 0 additions & 1 deletion mobile/android/modules/geckoview/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ EXTRA_JS_MODULES += [
"GeckoViewConsole.jsm",
"GeckoViewContent.jsm",
"GeckoViewContentBlocking.jsm",
"GeckoViewMedia.jsm",
"GeckoViewMediaControl.jsm",
"GeckoViewModule.jsm",
"GeckoViewNavigation.jsm",
Expand Down

0 comments on commit a288e5c

Please sign in to comment.