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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); | 127 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); |
128 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 128 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); |
129 ScriptPromise promise = resolver->promise(); | 129 ScriptPromise promise = resolver->promise(); |
130 | 130 |
131 if (!m_provider) { | 131 if (!m_provider) { |
132 resolver->reject(DOMException::create(InvalidStateError, "Failed to regi
ster a ServiceWorker: The document is in an invalid state.")); | 132 resolver->reject(DOMException::create(InvalidStateError, "Failed to regi
ster a ServiceWorker: The document is in an invalid state.")); |
133 return promise; | 133 return promise; |
134 } | 134 } |
135 | 135 |
136 ExecutionContext* executionContext = scriptState->executionContext(); | 136 ExecutionContext* executionContext = scriptState->executionContext(); |
| 137 // FIXME: May be null due to worker termination: http://crbug.com/413518. |
| 138 if (!executionContext) |
| 139 return ScriptPromise(); |
| 140 |
137 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); | 141 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); |
138 String errorMessage; | 142 String errorMessage; |
139 if (!executionContext->isPrivilegedContext(errorMessage)) { | 143 if (!executionContext->isPrivilegedContext(errorMessage)) { |
140 resolver->reject(DOMException::create(NotSupportedError, errorMessage)); | 144 resolver->reject(DOMException::create(NotSupportedError, errorMessage)); |
141 return promise; | 145 return promise; |
142 } | 146 } |
143 | 147 |
144 KURL pageURL = KURL(KURL(), documentOrigin->toString()); | 148 KURL pageURL = KURL(KURL(), documentOrigin->toString()); |
145 if (!pageURL.protocolIsInHTTPFamily()) { | 149 if (!pageURL.protocolIsInHTTPFamily()) { |
146 resolver->reject(DOMException::create(SecurityError, "Failed to register
a ServiceWorker: The URL protocol of the current origin ('" + documentOrigin->t
oString() + "') is not supported.")); | 150 resolver->reject(DOMException::create(SecurityError, "Failed to register
a ServiceWorker: The URL protocol of the current origin ('" + documentOrigin->t
oString() + "') is not supported.")); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); | 190 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); |
187 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 191 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); |
188 ScriptPromise promise = resolver->promise(); | 192 ScriptPromise promise = resolver->promise(); |
189 | 193 |
190 if (!m_provider) { | 194 if (!m_provider) { |
191 resolver->reject(DOMException::create(InvalidStateError, "Failed to get
a ServiceWorkerRegistration: The document is in an invalid state.")); | 195 resolver->reject(DOMException::create(InvalidStateError, "Failed to get
a ServiceWorkerRegistration: The document is in an invalid state.")); |
192 return promise; | 196 return promise; |
193 } | 197 } |
194 | 198 |
195 ExecutionContext* executionContext = scriptState->executionContext(); | 199 ExecutionContext* executionContext = scriptState->executionContext(); |
| 200 // FIXME: May be null due to worker termination: http://crbug.com/413518. |
| 201 if (!executionContext) |
| 202 return ScriptPromise(); |
| 203 |
196 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); | 204 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); |
197 String errorMessage; | 205 String errorMessage; |
198 if (!executionContext->isPrivilegedContext(errorMessage)) { | 206 if (!executionContext->isPrivilegedContext(errorMessage)) { |
199 resolver->reject(DOMException::create(NotSupportedError, errorMessage)); | 207 resolver->reject(DOMException::create(NotSupportedError, errorMessage)); |
200 return promise; | 208 return promise; |
201 } | 209 } |
202 | 210 |
203 KURL pageURL = KURL(KURL(), documentOrigin->toString()); | 211 KURL pageURL = KURL(KURL(), documentOrigin->toString()); |
204 if (!pageURL.protocolIsInHTTPFamily()) { | 212 if (!pageURL.protocolIsInHTTPFamily()) { |
205 resolver->reject(DOMException::create(SecurityError, "Failed to get a Se
rviceWorkerRegistration: The URL protocol of the current origin ('" + documentOr
igin->toString() + "') is not supported.")); | 213 resolver->reject(DOMException::create(SecurityError, "Failed to get a Se
rviceWorkerRegistration: The URL protocol of the current origin ('" + documentOr
igin->toString() + "') is not supported.")); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 return; | 295 return; |
288 | 296 |
289 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { | 297 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { |
290 m_provider = client->provider(); | 298 m_provider = client->provider(); |
291 if (m_provider) | 299 if (m_provider) |
292 m_provider->setClient(this); | 300 m_provider->setClient(this); |
293 } | 301 } |
294 } | 302 } |
295 | 303 |
296 } // namespace blink | 304 } // namespace blink |
OLD | NEW |