Commit 7753bf7a authored by Francois Beaufort's avatar Francois Beaufort Committed by Commit Bot

[DevTools] Handle new Camera PanTiltZoom permission

This CL adds the camera pan tilt zoom permission to devtools browser
protocol.

Spec: https://github.com/w3c/permissions/pull/204

Bug: 1136778
Change-Id: Ic11990413e2ceeeceb7da5c03930cd4049189b97
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2460898Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Reviewed-by: default avatarSigurd Schneider <sigurds@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: François Beaufort <beaufort.francois@gmail.com>
Cr-Commit-Position: refs/heads/master@{#816497}
parent 35231f04
...@@ -146,7 +146,10 @@ Response PermissionDescriptorToPermissionType( ...@@ -146,7 +146,10 @@ Response PermissionDescriptorToPermissionType(
if (name == "geolocation") { if (name == "geolocation") {
*permission_type = PermissionType::GEOLOCATION; *permission_type = PermissionType::GEOLOCATION;
} else if (name == "camera") { } else if (name == "camera") {
*permission_type = PermissionType::VIDEO_CAPTURE; if (descriptor->GetPanTiltZoom(false))
*permission_type = PermissionType::CAMERA_PAN_TILT_ZOOM;
else
*permission_type = PermissionType::VIDEO_CAPTURE;
} else if (name == "microphone") { } else if (name == "microphone") {
*permission_type = PermissionType::AUDIO_CAPTURE; *permission_type = PermissionType::AUDIO_CAPTURE;
} else if (name == "notifications") { } else if (name == "notifications") {
...@@ -224,6 +227,9 @@ Response FromProtocolPermissionType( ...@@ -224,6 +227,9 @@ Response FromProtocolPermissionType(
*out_type = PermissionType::AUDIO_CAPTURE; *out_type = PermissionType::AUDIO_CAPTURE;
} else if (type == protocol::Browser::PermissionTypeEnum::VideoCapture) { } else if (type == protocol::Browser::PermissionTypeEnum::VideoCapture) {
*out_type = PermissionType::VIDEO_CAPTURE; *out_type = PermissionType::VIDEO_CAPTURE;
} else if (type ==
protocol::Browser::PermissionTypeEnum::VideoCapturePanTiltZoom) {
*out_type = PermissionType::CAMERA_PAN_TILT_ZOOM;
} else if (type == protocol::Browser::PermissionTypeEnum::BackgroundSync) { } else if (type == protocol::Browser::PermissionTypeEnum::BackgroundSync) {
*out_type = PermissionType::BACKGROUND_SYNC; *out_type = PermissionType::BACKGROUND_SYNC;
} else if (type == protocol::Browser::PermissionTypeEnum::Flash) { } else if (type == protocol::Browser::PermissionTypeEnum::Flash) {
......
...@@ -826,6 +826,7 @@ domain Browser ...@@ -826,6 +826,7 @@ domain Browser
protectedMediaIdentifier protectedMediaIdentifier
sensors sensors
videoCapture videoCapture
videoCapturePanTiltZoom
idleDetection idleDetection
wakeLockScreen wakeLockScreen
wakeLockSystem wakeLockSystem
...@@ -850,6 +851,8 @@ domain Browser ...@@ -850,6 +851,8 @@ domain Browser
optional boolean userVisibleOnly optional boolean userVisibleOnly
# For "clipboard" permission, may specify allowWithoutSanitization. # For "clipboard" permission, may specify allowWithoutSanitization.
optional boolean allowWithoutSanitization optional boolean allowWithoutSanitization
# For "camera" permission, may specify panTiltZoom.
optional boolean panTiltZoom
# Set permission settings for given origin. # Set permission settings for given origin.
experimental command setPermission experimental command setPermission
......
Test that permissions could be granted Test that permissions could be granted
- Granted: ["geolocation"] - Granted: ["geolocation"]
- Granted: ["audioCapture"] - Granted: ["audioCapture"]
- Granted: ["geolocation","audioCapture"] - Granted: ["geolocation","audioCapture","videoCapturePanTiltZoom"]
- Failed to grant: ["eee"] error: Unknown permission type: eee - Failed to grant: ["eee"] error: Unknown permission type: eee
- Resetting all permissions - Resetting all permissions
[ [
...@@ -12,12 +12,16 @@ Test that permissions could be granted ...@@ -12,12 +12,16 @@ Test that permissions could be granted
[4] : CHANGED 'geolocation': denied [4] : CHANGED 'geolocation': denied
] ]
[ [
[0] : geolocation: granted [0] : {"name":"geolocation"}: granted
[1] : geolocation: denied [1] : {"name":"geolocation"}: denied
[2] : microphone: granted [2] : {"name":"microphone"}: granted
[3] : geolocation: granted [3] : {"name":"geolocation"}: granted
[4] : microphone: granted [4] : {"name":"microphone"}: granted
[5] : geolocation: denied [5] : {"name":"camera","panTiltZoom":true}: granted
[6] : microphone: denied [6] : {"name":"geolocation"}: denied
[7] : {"name":"microphone"}: denied
[8] : {"name":"camera","panTiltZoom":true}: denied
[9] : {"name":"camera","panTiltZoom":false}: denied
[10] : {"name":"camera"}: denied
] ]
...@@ -17,19 +17,21 @@ ...@@ -17,19 +17,21 @@
}); });
await grant('geolocation'); await grant('geolocation');
await waitPermission('geolocation', 'granted'); await waitPermission({name: 'geolocation'}, 'granted');
await grant('audioCapture'); await grant('audioCapture');
await Promise.all([ await Promise.all([
waitPermission('geolocation', 'denied'), waitPermission({name: 'geolocation'}, 'denied'),
waitPermission('microphone', 'granted'), waitPermission({name: 'microphone'}, 'granted'),
]); ]);
await grant('geolocation', 'audioCapture', 'videoCapturePanTiltZoom');
await grant('geolocation', 'audioCapture');
await Promise.all([ await Promise.all([
waitPermission('geolocation', 'granted'), waitPermission({name: 'geolocation'}, 'granted'),
waitPermission('microphone', 'granted'), waitPermission({name: 'microphone'}, 'granted'),
waitPermission({name: 'camera', panTiltZoom: true}, 'granted'),
waitPermission({name: 'camera', panTiltZoom: false}, 'granted'),
waitPermission({name: 'camera'}, 'granted'),
]); ]);
await grant('eee'); await grant('eee');
...@@ -37,8 +39,11 @@ ...@@ -37,8 +39,11 @@
testRunner.log('- Resetting all permissions'); testRunner.log('- Resetting all permissions');
await dp.Browser.resetPermissions(); await dp.Browser.resetPermissions();
await Promise.all([ await Promise.all([
waitPermission('geolocation', 'denied'), waitPermission({name: 'geolocation'}, 'denied'),
waitPermission('microphone', 'denied'), waitPermission({name: 'microphone'}, 'denied'),
waitPermission({name: 'camera', panTiltZoom: true}, 'denied'),
waitPermission({name: 'camera', panTiltZoom: false}, 'denied'),
waitPermission({name: 'camera'}, 'denied'),
]); ]);
testRunner.log(await session.evaluate(() => window.subscriptionChanges)); testRunner.log(await session.evaluate(() => window.subscriptionChanges));
...@@ -57,14 +62,14 @@ ...@@ -57,14 +62,14 @@
testRunner.log('- Granted: ' + JSON.stringify(permissions)); testRunner.log('- Granted: ' + JSON.stringify(permissions));
} }
async function waitPermission(name, state) { async function waitPermission(descriptor, state) {
await session.evaluateAsync(async (permission, state) => { await session.evaluateAsync(async (descriptor, state) => {
const result = await navigator.permissions.query({name: permission}); const result = await navigator.permissions.query(descriptor);
if (result.state && result.state === state) if (result.state && result.state === state)
window.messages.push(`${permission}: ${result.state}`); window.messages.push(`${JSON.stringify(descriptor)}: ${result.state}`);
else else
window.messages.push(`Failed to set ${permission} to state: ${state}`); window.messages.push(`Failed to set ${permission} to state: ${state}`);
}, name, state); }, descriptor, state);
} }
}) })
...@@ -10,6 +10,7 @@ Test that permissions can be changed ...@@ -10,6 +10,7 @@ Test that permissions can be changed
- Set: {"name":"midi","sysex":false} to denied - Set: {"name":"midi","sysex":false} to denied
- Set: {"name":"midi","sysex":false} to prompt - Set: {"name":"midi","sysex":false} to prompt
- Set: {"name":"push","userVisibleOnly":true} to granted - Set: {"name":"push","userVisibleOnly":true} to granted
- Set: {"name":"camera","panTiltZoom":true} to granted
- Set: {"name":"geolocation"} to granted - Set: {"name":"geolocation"} to granted
- Set: {"name":"geolocation"} to denied - Set: {"name":"geolocation"} to denied
[ [
...@@ -26,6 +27,7 @@ Test that permissions can be changed ...@@ -26,6 +27,7 @@ Test that permissions can be changed
[10] : {"name":"midi","sysex":false}: prompt [10] : {"name":"midi","sysex":false}: prompt
[11] : {"name":"midi","sysex":true}: prompt [11] : {"name":"midi","sysex":true}: prompt
[12] : {"name":"push","userVisibleOnly":true}: granted [12] : {"name":"push","userVisibleOnly":true}: granted
[13] : {"name":"geolocation"}: granted [13] : {"name":"camera","panTiltZoom":true}: granted
[14] : {"name":"geolocation"}: granted
] ]
...@@ -66,9 +66,14 @@ ...@@ -66,9 +66,14 @@
await dp.Browser.resetPermissions(); await dp.Browser.resetPermissions();
// Test "push" permissions userVisibleOnly=true is supported. // Test "push" permissions userVisibleOnly=true is supported.
await set({name: 'push', userVisibleOnly: true}, 'granted'), await set({name: 'push', userVisibleOnly: true}, 'granted');
await waitPermission({name: 'push', userVisibleOnly: true}, 'granted'), await waitPermission({name: 'push', userVisibleOnly: true}, 'granted');
await dp.Browser.resetPermissions() await dp.Browser.resetPermissions();
// Test "camera" permission panTiltZoom=true is supported.
await set({name: 'camera', panTiltZoom: true}, 'granted');
await waitPermission({name: 'camera', panTiltZoom: true}, 'granted');
await dp.Browser.resetPermissions();
// Cross-origin test. // Cross-origin test.
await setWithName('geolocation', 'granted'); await setWithName('geolocation', 'granted');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment