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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 DEFINE_TRACE(ServiceWorkerContainer) | 117 DEFINE_TRACE(ServiceWorkerContainer) |
118 { | 118 { |
119 visitor->trace(m_controller); | 119 visitor->trace(m_controller); |
120 visitor->trace(m_ready); | 120 visitor->trace(m_ready); |
121 RefCountedGarbageCollectedEventTargetWithInlineData<ServiceWorkerContainer>:
:trace(visitor); | 121 RefCountedGarbageCollectedEventTargetWithInlineData<ServiceWorkerContainer>:
:trace(visitor); |
122 ContextLifecycleObserver::trace(visitor); | 122 ContextLifecycleObserver::trace(visitor); |
123 } | 123 } |
124 | 124 |
125 ScriptPromise ServiceWorkerContainer::registerServiceWorker(ScriptState* scriptS
tate, const String& url, const RegistrationOptions& options) | 125 ScriptPromise ServiceWorkerContainer::registerServiceWorker(ScriptState* scriptS
tate, const String& url, const RegistrationOptions& options) |
126 { | 126 { |
127 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); | |
128 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 127 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); |
129 ScriptPromise promise = resolver->promise(); | 128 ScriptPromise promise = resolver->promise(); |
130 | 129 |
131 if (!m_provider) { | 130 if (!m_provider) { |
132 resolver->reject(DOMException::create(InvalidStateError, "Failed to regi
ster a ServiceWorker: The document is in an invalid state.")); | 131 resolver->reject(DOMException::create(InvalidStateError, "Failed to regi
ster a ServiceWorker: The document is in an invalid state.")); |
133 return promise; | 132 return promise; |
134 } | 133 } |
135 | 134 |
136 ExecutionContext* executionContext = scriptState->executionContext(); | 135 ExecutionContext* executionContext = scriptState->executionContext(); |
137 // FIXME: May be null due to worker termination: http://crbug.com/413518. | 136 // FIXME: May be null due to worker termination: http://crbug.com/413518. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 return promise; | 179 return promise; |
181 } | 180 } |
182 | 181 |
183 m_provider->registerServiceWorker(patternURL, scriptURL, new CallbackPromise
Adapter<ServiceWorkerRegistration, ServiceWorkerError>(resolver)); | 182 m_provider->registerServiceWorker(patternURL, scriptURL, new CallbackPromise
Adapter<ServiceWorkerRegistration, ServiceWorkerError>(resolver)); |
184 | 183 |
185 return promise; | 184 return promise; |
186 } | 185 } |
187 | 186 |
188 ScriptPromise ServiceWorkerContainer::getRegistration(ScriptState* scriptState,
const String& documentURL) | 187 ScriptPromise ServiceWorkerContainer::getRegistration(ScriptState* scriptState,
const String& documentURL) |
189 { | 188 { |
190 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); | |
191 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 189 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); |
192 ScriptPromise promise = resolver->promise(); | 190 ScriptPromise promise = resolver->promise(); |
193 | 191 |
194 if (!m_provider) { | 192 if (!m_provider) { |
195 resolver->reject(DOMException::create(InvalidStateError, "Failed to get
a ServiceWorkerRegistration: The document is in an invalid state.")); | 193 resolver->reject(DOMException::create(InvalidStateError, "Failed to get
a ServiceWorkerRegistration: The document is in an invalid state.")); |
196 return promise; | 194 return promise; |
197 } | 195 } |
198 | 196 |
199 ExecutionContext* executionContext = scriptState->executionContext(); | 197 ExecutionContext* executionContext = scriptState->executionContext(); |
200 // FIXME: May be null due to worker termination: http://crbug.com/413518. | 198 // FIXME: May be null due to worker termination: http://crbug.com/413518. |
(...skipping 18 matching lines...) Expand all Loading... |
219 if (!documentOrigin->canRequest(completedURL)) { | 217 if (!documentOrigin->canRequest(completedURL)) { |
220 RefPtr<SecurityOrigin> documentURLOrigin = SecurityOrigin::create(comple
tedURL); | 218 RefPtr<SecurityOrigin> documentURLOrigin = SecurityOrigin::create(comple
tedURL); |
221 resolver->reject(DOMException::create(SecurityError, "Failed to get a Se
rviceWorkerRegistration: The origin of the provided documentURL ('" + documentUR
LOrigin->toString() + "') does not match the current origin ('" + documentOrigin
->toString() + "').")); | 219 resolver->reject(DOMException::create(SecurityError, "Failed to get a Se
rviceWorkerRegistration: The origin of the provided documentURL ('" + documentUR
LOrigin->toString() + "') does not match the current origin ('" + documentOrigin
->toString() + "').")); |
222 return promise; | 220 return promise; |
223 } | 221 } |
224 m_provider->getRegistration(completedURL, new GetRegistrationCallback(resolv
er)); | 222 m_provider->getRegistration(completedURL, new GetRegistrationCallback(resolv
er)); |
225 | 223 |
226 return promise; | 224 return promise; |
227 } | 225 } |
228 | 226 |
| 227 ScriptPromise ServiceWorkerContainer::getRegistrations(ScriptState* scriptState) |
| 228 { |
| 229 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); |
| 230 ScriptPromise promise = resolver->promise(); |
| 231 |
| 232 if (!m_provider) { |
| 233 resolver->reject(DOMException::create(InvalidStateError, "Failed to get
ServiceWorkerRegistration objects: The document is in an invalid state.")); |
| 234 return promise; |
| 235 } |
| 236 |
| 237 ExecutionContext* executionContext = scriptState->executionContext(); |
| 238 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); |
| 239 String errorMessage; |
| 240 if (!executionContext->isPrivilegedContext(errorMessage)) { |
| 241 resolver->reject(DOMException::create(NotSupportedError, errorMessage)); |
| 242 return promise; |
| 243 } |
| 244 |
| 245 KURL pageURL = KURL(KURL(), documentOrigin->toString()); |
| 246 if (!pageURL.protocolIsInHTTPFamily()) { |
| 247 resolver->reject(DOMException::create(SecurityError, "Failed to get Serv
iceWorkerRegistration objects: The URL protocol of the current origin ('" + docu
mentOrigin->toString() + "') is not supported.")); |
| 248 return promise; |
| 249 } |
| 250 |
| 251 m_provider->getRegistrations(new CallbackPromiseAdapter<ServiceWorkerRegistr
ationArray, ServiceWorkerError>(resolver)); |
| 252 |
| 253 return promise; |
| 254 } |
| 255 |
229 ServiceWorkerContainer::ReadyProperty* ServiceWorkerContainer::createReadyProper
ty() | 256 ServiceWorkerContainer::ReadyProperty* ServiceWorkerContainer::createReadyProper
ty() |
230 { | 257 { |
231 return new ReadyProperty(executionContext(), this, ReadyProperty::Ready); | 258 return new ReadyProperty(executionContext(), this, ReadyProperty::Ready); |
232 } | 259 } |
233 | 260 |
234 ScriptPromise ServiceWorkerContainer::ready(ScriptState* callerState) | 261 ScriptPromise ServiceWorkerContainer::ready(ScriptState* callerState) |
235 { | 262 { |
236 if (!executionContext()) | 263 if (!executionContext()) |
237 return ScriptPromise(); | 264 return ScriptPromise(); |
238 | 265 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 return; | 322 return; |
296 | 323 |
297 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { | 324 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { |
298 m_provider = client->provider(); | 325 m_provider = client->provider(); |
299 if (m_provider) | 326 if (m_provider) |
300 m_provider->setClient(this); | 327 m_provider->setClient(this); |
301 } | 328 } |
302 } | 329 } |
303 | 330 |
304 } // namespace blink | 331 } // namespace blink |
OLD | NEW |