From c565ecf9b21e028b3a0fbf4df38d88db9c00aee6 Mon Sep 17 00:00:00 2001
From: Domenic Denicola
Date: Fri, 26 Aug 2016 16:11:39 -0400
Subject: [PATCH] Parse URLs relative to the relevant settings object, not
entry
Fixes #922. Web platform tests at https://github.com/w3c/web-platform-tests/pull/3449. Part of the overall effort in https://github.com/whatwg/html/issues/1431.
In the process, fixes some ambiguity about how to parse URLs in the Link header, as previous it parsed relative to the entry settings object, which did not exist during this algorithm.
---
spec/service_worker/index.bs | 28 +++++++++++++---------------
spec/service_worker/index.html | 29 +++++++++++++++--------------
2 files changed, 28 insertions(+), 29 deletions(-)
diff --git a/spec/service_worker/index.bs b/spec/service_worker/index.bs
index 21c48790..2ba24199 100644
--- a/spec/service_worker/index.bs
+++ b/spec/service_worker/index.bs
@@ -61,8 +61,6 @@ spec: html; type: dfn
text: browsing context
text: discard a document
text: document base url
- text: effective script origin
- text: entry settings object
text: environment settings object
text: event handler
text: event handler event type
@@ -212,7 +210,7 @@ spec: html; urlPrefix: https://html.spec.whatwg.org/multipage/
text: origin; for: resource; url: origin-2
text: browsing context is discarded
urlPrefix: infrastructure.html
- text: read only array; url: dfn-read-only-array
+ text: inserted into a document; url: insert-an-element-into-a-document
text: StructuredCloneWithTransfer
urlPrefix: interaction.html
text: has focus steps
@@ -784,9 +782,9 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
- Let p be a promise.
- Let client be the context object's service worker client.
- - Let scriptURL be the result of parsing scriptURL with entry settings object's API base URL.
+ - Let scriptURL be the result of parsing scriptURL with the context object's relevant settings object's API base URL.
- Let scopeURL be null.
- - If options.{{RegistrationOptions/scope}} is present, set scopeURL to options.{{RegistrationOptions/scope}}.
+ - If options.{{RegistrationOptions/scope}} is present, set scopeURL to the result of parsing options.{{RegistrationOptions/scope}} with the context object's relevant settings object's API base URL.
- Invoke [[#start-register-algorithm]] with scopeURL, scriptURL, p, client, client's creation URL and options.{{RegistrationOptions/type}}.
- Return p.
@@ -799,7 +797,7 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
- Let client be the context object's service worker client.
- - Let clientURL be the result of parsing clientURL with entry settings object's API base URL.
+ - Let clientURL be the result of parsing clientURL with the context object's relevant settings object's API base URL.
- If clientURL is failure, return a promise rejected with a
TypeError
.
- If the origin of clientURL is not client's origin, return a promise rejected with a "{{SecurityError}}" exception.
- Let promise be a new promise.
@@ -2125,20 +2123,22 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
- Let request be the request for which this header was received in the response.
- If request's client is not a secure context, abort these steps.
- Let scriptURL be the result of parsing the target IRI of the
Link
header.
- - Let scopeURL be the "
scope
" target attribute of the Link
header, or null if no such attribute is present.
+ - Let scopeURL be null.
+
- If the "
scope
" target attribute of the Link
header is present, set scopeURL to the result of parsing the "scope
" target attribute with scriptURL.
- Let workerType be the "
workertype
" target attribute of the Link
header, or "classic
" if no such attribute is present.
- If workerType is not a valid {{WorkerType}} value, abort these steps.
- Invoke [[#start-register-algorithm]] with scopeURL, scriptURL, a new promise, null, contextURL and workerType.
- When a serviceworker link's <{link}> element is inserted into a document, a serviceworker link is created on a <{link}> element that is already in a Document, or the <{link/href}> or <{link/scope}> attributes of the <{link}> element of a serviceworker link is changed, the user agent should run these steps:
+ When a serviceworker link's <{link}> element is inserted into a document, a serviceworker link is created on a <{link}> element that is already in a document tree, or the <{link/href}> or <{link/scope}> attributes of the <{link}> element of a serviceworker link is changed, the user agent should run these steps:
- If the <{link/href}> attribute is the empty string, abort these steps.
- Let client be the document's service worker client.
- If client is not a secure context, queue a task to fire a simple event named
error
at the <{link}> element, and abort these steps.
- - Let scriptURL be the result of parsing the <{link/href}> attribute with document's document base URL.
- - Let scopeURL be the <{link/scope}> attribute, or null if the <{link/scope}> attribute is omitted.
+ - Let scriptURL be the result of parsing the <{link/href}> attribute with the <{link}> element's node document's document base URL.
+ - Let scopeURL null.
+
- If the <{link/scope}> attribute is present, set scopeURL to the result of parsing the <{link/scope}> attribute with the <{link}> element's node document's document base URL.
- Let workerType be the <{link/workertype}> attribute, or "
classic
" if the <{link/workertype}> attribute is omitted.
- If workerType is not a valid {{WorkerType}} value, queue a task to fire a simple event named
error
at the <{link}> element, and abort these steps.
- Let promise be a new promise.
@@ -3141,8 +3141,8 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
- Input
- - scopeURLString, a string
- - scriptURL, a URL
+ - scopeURL, a URL or failure or null
+ - scriptURL, a URL or failure
- promise, a promise
- client, a service worker client
- referrer, a URL
@@ -3154,11 +3154,9 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
- If scriptURL is failure, reject promise with a
TypeError
and abort these steps.
- If scriptURL's scheme is not one of "
http
" and "https
", reject promise with a TypeError
and abort these steps.
- If any of the strings in scriptURL's path contains either ASCII case-insensitive "
%2f
" or ASCII case-insensitive "%5c
", reject promise with a TypeError
and abort these steps.
- - Let scopeURL be null.
- - If scopeURLString is null, set scopeURL to the result of parsing a string "
./
" with scriptURL.
+ - If scopeURL is null, set scopeURL to the result of parsing the string "
./
" with scriptURL.
The scope url for the registration is set to the location of the service worker script by default.
- - Else, set scopeURL to the result of parsing scopeURLString with entry settings object's API base URL.
- If scopeURL is failure, reject promise with a
TypeError
and abort these steps.
- If scopeURL's scheme is not one of "
http
" and "https
", reject promise with a TypeError
and abort these steps.
- If any of the strings in scopeURL's path contains either ASCII case-insensitive "
%2f
" or ASCII case-insensitive "%5c
", reject promise with a TypeError
and abort these steps.
diff --git a/spec/service_worker/index.html b/spec/service_worker/index.html
index d320ee41..33ce34c8 100644
--- a/spec/service_worker/index.html
+++ b/spec/service_worker/index.html
@@ -2081,9 +2081,9 @@ promise.
- Let client be the context object’s service worker client.
-
- Let scriptURL be the result of parsing scriptURL with entry settings object’s API base URL.
+
- Let scriptURL be the result of parsing scriptURL with the context object’s relevant settings object’s API base URL.
- Let scopeURL be null.
-
- If options.
scope
is present, set scopeURL to options.scope
.
+ - If options.
scope
is present, set scopeURL to the result of parsing options.scope
with the context object’s relevant settings object’s API base URL.
- Invoke Start Register with scopeURL, scriptURL, p, client, client’s creation URL and options.
type
.
- Return p.
@@ -2093,7 +2093,7 @@ getRegistration(clientURL)
method must run these steps:
- Let client be the context object’s service worker client.
-
- Let clientURL be the result of parsing clientURL with entry settings object’s API base URL.
+
- Let clientURL be the result of parsing clientURL with the context object’s relevant settings object’s API base URL.
- If clientURL is failure, return a promise rejected with a
TypeError
.
- If the origin of clientURL is not client’s origin, return a promise rejected with a "
SecurityError
" exception.
- Let promise be a new promise.
@@ -3212,18 +3212,20 @@
Let request be the request for which this header was received in the response.
- If request’s client is not a secure context, abort these steps.
- Let scriptURL be the result of parsing the target IRI of the
Link
header.
- - Let scopeURL be the "
scope
" target attribute of the Link
header, or null if no such attribute is present.
+ - Let scopeURL be null.
+
- If the "
scope
" target attribute of the Link
header is present, set scopeURL to the result of parsing the "scope
" target attribute with scriptURL.
- Let workerType be the "
workertype
" target attribute of the Link
header, or "classic
" if no such attribute is present.
- If workerType is not a valid
WorkerType
value, abort these steps.
- Invoke Start Register with scopeURL, scriptURL, a new promise, null, contextURL and workerType.
- When a serviceworker link’s link
element is inserted into a document, a serviceworker link is created on a link
element that is already in a Document, or the href
or scope
attributes of the link
element of a serviceworker link is changed, the user agent should run these steps:
+ When a serviceworker link’s link
element is inserted into a document, a serviceworker link is created on a link
element that is already in a document tree, or the href
or scope
attributes of the link
element of a serviceworker link is changed, the user agent should run these steps:
- If the
href
attribute is the empty string, abort these steps.
- Let client be the document’s service worker client.
- If client is not a secure context, queue a task to fire a simple event named
error
at the link
element, and abort these steps.
- - Let scriptURL be the result of parsing the
href
attribute with document’s document base URL.
- - Let scopeURL be the
scope
attribute, or null if the scope
attribute is omitted.
+ - Let scriptURL be the result of parsing the
href
attribute with the link
element’s node document’s document base URL.
+ - Let scopeURL null.
+
- If the
scope
attribute is present, set scopeURL to the result of parsing the scope
attribute with the link
element’s node document’s document base URL.
- Let workerType be the
workertype
attribute, or "classic
" if the workertype
attribute is omitted.
- If workerType is not a valid
WorkerType
value, queue a task to fire a simple event named error
at the link
element, and abort these steps.
- Let promise be a new promise.
@@ -4080,8 +4082,8 @@
Start Register
- Input
-
- scopeURLString, a string
-
- scriptURL, a URL
+
- scopeURL, a URL or failure or null
+
- scriptURL, a URL or failure
- promise, a promise
- client, a service worker client
- referrer, a URL
@@ -4093,11 +4095,9 @@