OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 { | 110 { |
111 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); | 111 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); |
112 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); | 112 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); |
113 ScriptPromise promise = resolver->promise(); | 113 ScriptPromise promise = resolver->promise(); |
114 | 114 |
115 if (!m_provider) { | 115 if (!m_provider) { |
116 resolver->reject(DOMException::create(InvalidStateError, "The document i
s in an invalid state.")); | 116 resolver->reject(DOMException::create(InvalidStateError, "The document i
s in an invalid state.")); |
117 return promise; | 117 return promise; |
118 } | 118 } |
119 | 119 |
120 // FIXME: This should use the container's execution context, not | |
121 // the callers. | |
122 ExecutionContext* executionContext = scriptState->executionContext(); | 120 ExecutionContext* executionContext = scriptState->executionContext(); |
123 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); | 121 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); |
124 String errorMessage; | 122 String errorMessage; |
125 if (!documentOrigin->canAccessFeatureRequiringSecureOrigin(errorMessage)) { | 123 if (!documentOrigin->canAccessFeatureRequiringSecureOrigin(errorMessage)) { |
126 resolver->reject(DOMException::create(NotSupportedError, errorMessage)); | 124 resolver->reject(DOMException::create(NotSupportedError, errorMessage)); |
127 return promise; | 125 return promise; |
128 } | 126 } |
129 | 127 |
130 KURL pageURL = KURL(KURL(), documentOrigin->toString()); | 128 KURL pageURL = KURL(KURL(), documentOrigin->toString()); |
131 if (!pageURL.protocolIsInHTTPFamily()) { | 129 if (!pageURL.protocolIsInHTTPFamily()) { |
132 resolver->reject(DOMException::create(SecurityError, "The URL protocol o
f the current origin is not supported: " + pageURL.protocol())); | 130 resolver->reject(DOMException::create(SecurityError, "The URL protocol o
f the current origin is not supported: " + pageURL.protocol())); |
133 return promise; | 131 return promise; |
134 } | 132 } |
135 | 133 |
136 KURL patternURL = executionContext->completeURL(options.scope()); | 134 KURL patternURL = callingExecutionContext(scriptState->isolate())->completeU
RL(options.scope()); |
137 patternURL.removeFragmentIdentifier(); | 135 patternURL.removeFragmentIdentifier(); |
138 if (!documentOrigin->canRequest(patternURL)) { | 136 if (!documentOrigin->canRequest(patternURL)) { |
139 resolver->reject(DOMException::create(SecurityError, "The scope must mat
ch the current origin.")); | 137 resolver->reject(DOMException::create(SecurityError, "The scope must mat
ch the current origin.")); |
140 return promise; | 138 return promise; |
141 } | 139 } |
142 | 140 |
143 KURL scriptURL = executionContext->completeURL(url); | 141 KURL scriptURL = callingExecutionContext(scriptState->isolate())->completeUR
L(url); |
144 scriptURL.removeFragmentIdentifier(); | 142 scriptURL.removeFragmentIdentifier(); |
145 if (!documentOrigin->canRequest(scriptURL)) { | 143 if (!documentOrigin->canRequest(scriptURL)) { |
146 resolver->reject(DOMException::create(SecurityError, "The origin of the
script must match the current origin.")); | 144 resolver->reject(DOMException::create(SecurityError, "The origin of the
script must match the current origin.")); |
147 return promise; | 145 return promise; |
148 } | 146 } |
149 | 147 |
150 if (!patternURL.string().startsWith(scriptURL.baseAsString())) { | 148 if (!patternURL.string().startsWith(scriptURL.baseAsString())) { |
151 resolver->reject(DOMException::create(SecurityError, "The scope must be
under the directory of the script URL.")); | 149 resolver->reject(DOMException::create(SecurityError, "The scope must be
under the directory of the script URL.")); |
152 return promise; | 150 return promise; |
153 } | 151 } |
(...skipping 20 matching lines...) Expand all Loading... |
174 { | 172 { |
175 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); | 173 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); |
176 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); | 174 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); |
177 ScriptPromise promise = resolver->promise(); | 175 ScriptPromise promise = resolver->promise(); |
178 | 176 |
179 if (!m_provider) { | 177 if (!m_provider) { |
180 resolver->reject(DOMException::create(InvalidStateError, "The document i
s in an invalid state.")); | 178 resolver->reject(DOMException::create(InvalidStateError, "The document i
s in an invalid state.")); |
181 return promise; | 179 return promise; |
182 } | 180 } |
183 | 181 |
184 // FIXME: This should use the container's execution context, not | |
185 // the callers. | |
186 ExecutionContext* executionContext = scriptState->executionContext(); | 182 ExecutionContext* executionContext = scriptState->executionContext(); |
187 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); | 183 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); |
188 String errorMessage; | 184 String errorMessage; |
189 if (!documentOrigin->canAccessFeatureRequiringSecureOrigin(errorMessage)) { | 185 if (!documentOrigin->canAccessFeatureRequiringSecureOrigin(errorMessage)) { |
190 resolver->reject(DOMException::create(NotSupportedError, errorMessage)); | 186 resolver->reject(DOMException::create(NotSupportedError, errorMessage)); |
191 return promise; | 187 return promise; |
192 } | 188 } |
193 | 189 |
194 KURL pageURL = KURL(KURL(), documentOrigin->toString()); | 190 KURL pageURL = KURL(KURL(), documentOrigin->toString()); |
195 if (!pageURL.protocolIsInHTTPFamily()) { | 191 if (!pageURL.protocolIsInHTTPFamily()) { |
196 resolver->reject(DOMException::create(SecurityError, "The URL protocol o
f the current origin is not supported: " + pageURL.protocol())); | 192 resolver->reject(DOMException::create(SecurityError, "The URL protocol o
f the current origin is not supported: " + pageURL.protocol())); |
197 return promise; | 193 return promise; |
198 } | 194 } |
199 | 195 |
200 KURL completedURL = executionContext->completeURL(documentURL); | 196 KURL completedURL = callingExecutionContext(scriptState->isolate())->complet
eURL(documentURL); |
201 completedURL.removeFragmentIdentifier(); | 197 completedURL.removeFragmentIdentifier(); |
202 if (!documentOrigin->canRequest(completedURL)) { | 198 if (!documentOrigin->canRequest(completedURL)) { |
203 resolver->reject(DOMException::create(SecurityError, "The documentURL mu
st match the current origin.")); | 199 resolver->reject(DOMException::create(SecurityError, "The documentURL mu
st match the current origin.")); |
204 return promise; | 200 return promise; |
205 } | 201 } |
206 m_provider->getRegistration(completedURL, new GetRegistrationCallback(resolv
er)); | 202 m_provider->getRegistration(completedURL, new GetRegistrationCallback(resolv
er)); |
207 | 203 |
208 return promise; | 204 return promise; |
209 } | 205 } |
210 | 206 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 m_ready = createReadyProperty(); | 308 m_ready = createReadyProperty(); |
313 | 309 |
314 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { | 310 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { |
315 m_provider = client->provider(); | 311 m_provider = client->provider(); |
316 if (m_provider) | 312 if (m_provider) |
317 m_provider->setClient(this); | 313 m_provider->setClient(this); |
318 } | 314 } |
319 } | 315 } |
320 | 316 |
321 } // namespace blink | 317 } // namespace blink |
OLD | NEW |