Commit 13f57be7 authored by nhiroki@chromium.org's avatar nhiroki@chromium.org

ServiceWorker: Abort register() and getRegistration() on non-http(s) page

Currently the ServiceWorker backend does not support register() and
getRegistration() calls on non-HTTP(s) page (eg, "file://"). Such calls
trigger a renderer crash because SWProviderHost does not have a valid
document URL and treats a request as a bad message.

This patch makes SWContainer abort such calls before sending an IPC message.


BUG=432048
TEST=run-webkit-tests fast/serviceworker/access-container-on-local-file.html

Review URL: https://codereview.chromium.org/722583002

git-svn-id: svn://svn.chromium.org/blink/trunk@185210 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 11031592
<!DOCTYPE html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script>
async_test(function(t) {
var script = 'no-such-worker';
navigator.serviceWorker.register(script, { scope: script })
.then(function() {
assert_unreached('register() should fail');
}, function(e) {
assert_throws(
'SecurityError', function() { throw e; },
'register() on local file should fail');
assert_equals(
e.message,
'The URL protocol of the current origin is not supported: file',
'register() should fail due to unsupported URL protocol');
t.done();
})
.catch(t.step_func(function(e) {
assert_unreached(e);
t.done();
}));
}, 'Calling register() on local file');
async_test(function(t) {
navigator.serviceWorker.getRegistration()
.then(function() {
assert_unreached('getRegistration() should fail')
}, function(e) {
assert_throws(
'SecurityError', function() { throw e; },
'getRegistration() on local file should fail');
assert_equals(
e.message,
'The URL protocol of the current origin is not supported: file',
'getRegistration() should fail due to unsupported URL protocol');
t.done();
})
.catch(t.step_func(function(e) {
assert_unreached(e);
t.done();
}));
}, 'Calling getRegistration() on local file');
</script>
...@@ -122,6 +122,12 @@ ScriptPromise ServiceWorkerContainer::registerServiceWorker(ScriptState* scriptS ...@@ -122,6 +122,12 @@ ScriptPromise ServiceWorkerContainer::registerServiceWorker(ScriptState* scriptS
return promise; return promise;
} }
KURL pageURL = KURL(KURL(), documentOrigin->toString());
if (!pageURL.protocolIsInHTTPFamily()) {
resolver->reject(DOMException::create(SecurityError, "The URL protocol of the current origin is not supported: " + pageURL.protocol()));
return promise;
}
KURL patternURL = executionContext->completeURL(options.scope()); KURL patternURL = executionContext->completeURL(options.scope());
patternURL.removeFragmentIdentifier(); patternURL.removeFragmentIdentifier();
if (!documentOrigin->canRequest(patternURL)) { if (!documentOrigin->canRequest(patternURL)) {
...@@ -175,6 +181,12 @@ ScriptPromise ServiceWorkerContainer::getRegistration(ScriptState* scriptState, ...@@ -175,6 +181,12 @@ ScriptPromise ServiceWorkerContainer::getRegistration(ScriptState* scriptState,
return promise; return promise;
} }
KURL pageURL = KURL(KURL(), documentOrigin->toString());
if (!pageURL.protocolIsInHTTPFamily()) {
resolver->reject(DOMException::create(SecurityError, "The URL protocol of the current origin is not supported: " + pageURL.protocol()));
return promise;
}
KURL completedURL = executionContext->completeURL(documentURL); KURL completedURL = executionContext->completeURL(documentURL);
completedURL.removeFragmentIdentifier(); completedURL.removeFragmentIdentifier();
if (!documentOrigin->canRequest(completedURL)) { if (!documentOrigin->canRequest(completedURL)) {
......
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