Skip to content

Commit

Permalink
Add keyboard-map to the feature policy.
Browse files Browse the repository at this point in the history
This CL adds "keyboard-map" value to the allow attribute list so the
Keyboard interface can be accessed from iframe.
This is discussed here: WICG/keyboard-map#38

i2s: https://groups.google.com/a/chromium.org/g/blink-dev/c/SJD5Z4_E5TQ/m/B-f1WtnYBwAJ?utm_medium=email&utm_source=footer

Bug: 1258242

Change-Id: Ic2427c88c649cd85b257de4f94f63fd3ce63364e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3218437
Reviewed-by: Daniel Cheng <[email protected]>
Reviewed-by: Bo <[email protected]>
Commit-Queue: Anupam Snigdha <[email protected]>
Cr-Commit-Position: refs/heads/main@{#931354}
  • Loading branch information
snianu authored and chromium-wpt-export-bot committed Oct 14, 2021
1 parent 0a8c303 commit 3fd50d5
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/cors/support.js?pipe=sub"></script>
<body>
<script>
'use strict';

promise_test(() => {
let iframe = document.createElement('iframe');
iframe.src = CROSSDOMAIN + 'resources/iframe-keyboard-map-allow-helper.html';
iframe.allow = "keyboard-map";
iframe.onload = () => {
iframe.contentWindow.postMessage('Ready', '*');
}

document.body.appendChild(iframe);

return new Promise((resolve,reject) => {
window.onmessage = message => {
if (message.data == 'Success') {
resolve();
} else if (message.data == 'Failure') {
reject();
}
}
});
}, '[Keyboard Map] getLayoutMap() allowed from within cross-origin iframe');

</script>
29 changes: 29 additions & 0 deletions keyboard-map/navigator-keyboard-map-allowed-from-iframe.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
'use strict';

promise_test(() => {
let iframe = document.createElement('iframe');
iframe.src = 'resources/iframe-keyboard-map-allow-helper.html';
iframe.allow = "keyboard-map";
iframe.onload = () => {
iframe.contentWindow.postMessage('Ready', '*');
}

document.body.appendChild(iframe);

return new Promise((resolve,reject) => {
window.onmessage = message => {
if (message.data == 'Success') {
resolve();
} else if (message.data == 'Failure') {
reject();
}
}
});
}, '[Keyboard Map] getLayoutMap() allowed from within iframe');

</script>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
promise_test(() => {
let iframe = document.createElement('iframe');
iframe.src = 'resources/iframe-keyboard-map-helper.html';
iframe.allow = "keyboard-map 'none'";
iframe.onload = () => {
iframe.contentWindow.postMessage('Ready', '*');
}
Expand Down
16 changes: 16 additions & 0 deletions keyboard-map/resources/iframe-keyboard-map-allow-helper.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<script>
'use strict';

window.onmessage = message => {
if (message.data === 'Ready') {
let onSuccess = () => { parent.postMessage('Success', '*'); };
let onError = error => {
parent.postMessage('Failure', '*');
};

navigator.keyboard.getLayoutMap().then(onSuccess, onError).catch(onError);
}
};

</script>
4 changes: 2 additions & 2 deletions keyboard-map/resources/iframe-keyboard-map-helper.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
if (message.data === 'Ready') {
let onSuccess = () => { parent.postMessage('Failure', '*'); };
let onError = error => {
if (error.name == 'InvalidStateError') {
if (error.name == 'SecurityError') {
parent.postMessage('Success', '*');
} else {
parent.postMessage('Failure', '*');
}
};

navigator.keyboard.getLayoutMap().then(onSuccess, onError);
navigator.keyboard.getLayoutMap().then(onSuccess, onError).catch(onError);
}
};

Expand Down

0 comments on commit 3fd50d5

Please sign in to comment.