Skip to content

Commit

Permalink
ServiceWorker: Use [SecureContext] instead of manual check
Browse files Browse the repository at this point in the history
Until now, we had to use IsSecureContext() to check whether an execution
context is a secure context manually. But we can use [SecureContext]
instead of the manual check now. After this change, all related APIs
including ServiceWorkerContainer will not be exposed in non-secure
context.

Chrome status: https://www.chromestatus.com/feature/4835970390163456

Bug: 542499, 854058
Change-Id: I0e207fee5c591d595c0e11c121cc8a0f555b5be3
Reviewed-on: https://chromium-review.googlesource.com/818666
Commit-Queue: Jinho Bang <jinho.bang@samsung.com>
Reviewed-by: Matt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568509}
  • Loading branch information
romandev authored and chromium-wpt-export-bot committed Jun 19, 2018
1 parent ea89f99 commit dc2cc22
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 15 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion background-fetch/interfaces-worker.https.html
Expand Up @@ -11,5 +11,5 @@ <h1>idlharness test</h1>
<script>
'use strict';

service_worker_test('interfaces.worker.js', 'Service Worker-scoped tests.');
service_worker_test('interfaces.https.worker.js', 'Service Worker-scoped tests.');
</script>
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -42,7 +42,7 @@

return redirect_and_register(target_url)
.then(result => {
assert_equals(result, 'FAIL: SecurityError');
assert_equals(result, 'FAIL: navigator.serviceWorker is undefined');
});
}, 'register on a non-secure page after redirect from an non-secure url');
</script>
Expand Down
Expand Up @@ -4,18 +4,22 @@
<script>
'use strict';

navigator.serviceWorker.register('empty-worker.js', {scope: 'scope-register'})
.then(
registration => {
registration.unregister().then(() => {
window.opener.postMessage('OK', '*');
});
},
error => {
window.opener.postMessage('FAIL: ' + error.name, '*');
})
.catch(error => {
window.opener.postMessage('ERROR: ' + error.name, '*');
});
if (!navigator.serviceWorker) {
window.opener.postMessage('FAIL: navigator.serviceWorker is undefined', '*');
} else {
navigator.serviceWorker.register('empty-worker.js', {scope: 'scope-register'})
.then(
registration => {
registration.unregister().then(() => {
window.opener.postMessage('OK', '*');
});
},
error => {
window.opener.postMessage('FAIL: ' + error.name, '*');
})
.catch(error => {
window.opener.postMessage('ERROR: ' + error.name, '*');
});
}
</script>
</body>

0 comments on commit dc2cc22

Please sign in to comment.