Skip to content

Commit b2a2b07

Browse files
authored
fix: also pass securityOrigin to media permissions request handler (electron#31357)
1 parent a751845 commit b2a2b07

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

docs/api/session.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@ win.webContents.session.setCertificateVerifyProc((request, callback) => {
618618
* `permissionGranted` Boolean - Allow or deny the permission.
619619
* `details` Object - Some properties are only available on certain permission types.
620620
* `externalURL` String (optional) - The url of the `openExternal` request.
621+
* `securityOrigin` String (optional) - The security origin of the `media` request.
621622
* `mediaTypes` String[] (optional) - The types of media access being requested, elements can be `video`
622623
or `audio`
623624
* `requestingUrl` String - The last URL the requesting frame loaded

shell/browser/web_contents_permission_helper.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ void WebContentsPermissionHelper::RequestMediaAccessPermission(
140140
media_types->Append("video");
141141
}
142142
details.SetList("mediaTypes", std::move(media_types));
143+
details.SetString("securityOrigin", request.security_origin.spec());
143144

144145
// The permission type doesn't matter here, AUDIO_CAPTURE/VIDEO_CAPTURE
145146
// are presented as same type in content_converter.h.

spec-main/chromium-spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,7 @@ describe('chromium features', () => {
947947
afterEach(closeAllWindows);
948948
afterEach(() => {
949949
session.defaultSession.setPermissionCheckHandler(null);
950+
session.defaultSession.setPermissionRequestHandler(null);
950951
});
951952

952953
it('can return labels of enumerated devices', async () => {
@@ -996,6 +997,32 @@ describe('chromium features', () => {
996997
const [, secondDeviceIds] = await emittedOnce(ipcMain, 'deviceIds', () => w.webContents.reload());
997998
expect(firstDeviceIds).to.not.deep.equal(secondDeviceIds);
998999
});
1000+
1001+
it('provides a securityOrigin to the request handler', async () => {
1002+
session.defaultSession.setPermissionRequestHandler(
1003+
(wc, permission, callback, details) => {
1004+
if (details.securityOrigin !== undefined) {
1005+
callback(true);
1006+
} else {
1007+
callback(false);
1008+
}
1009+
}
1010+
);
1011+
const w = new BrowserWindow({ show: false });
1012+
w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
1013+
const labels = await w.webContents.executeJavaScript(`navigator.mediaDevices.getUserMedia({
1014+
video: {
1015+
mandatory: {
1016+
chromeMediaSource: "desktop",
1017+
minWidth: 1280,
1018+
maxWidth: 1280,
1019+
minHeight: 720,
1020+
maxHeight: 720
1021+
}
1022+
}
1023+
}).then((stream) => stream.getVideoTracks())`);
1024+
expect(labels.some((l: any) => l)).to.be.true();
1025+
});
9991026
});
10001027

10011028
describe('window.opener access', () => {

0 commit comments

Comments
 (0)