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 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); | 136 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 return promise; | 175 return promise; |
177 } | 176 } |
178 | 177 |
179 m_provider->registerServiceWorker(patternURL, scriptURL, new CallbackPromise
Adapter<ServiceWorkerRegistration, ServiceWorkerError>(resolver)); | 178 m_provider->registerServiceWorker(patternURL, scriptURL, new CallbackPromise
Adapter<ServiceWorkerRegistration, ServiceWorkerError>(resolver)); |
180 | 179 |
181 return promise; | 180 return promise; |
182 } | 181 } |
183 | 182 |
184 ScriptPromise ServiceWorkerContainer::getRegistration(ScriptState* scriptState,
const String& documentURL) | 183 ScriptPromise ServiceWorkerContainer::getRegistration(ScriptState* scriptState,
const String& documentURL) |
185 { | 184 { |
186 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); | |
187 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 185 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); |
188 ScriptPromise promise = resolver->promise(); | 186 ScriptPromise promise = resolver->promise(); |
189 | 187 |
190 if (!m_provider) { | 188 if (!m_provider) { |
191 resolver->reject(DOMException::create(InvalidStateError, "Failed to get
a ServiceWorkerRegistration: The document is in an invalid state.")); | 189 resolver->reject(DOMException::create(InvalidStateError, "Failed to get
a ServiceWorkerRegistration: The document is in an invalid state.")); |
192 return promise; | 190 return promise; |
193 } | 191 } |
194 | 192 |
195 ExecutionContext* executionContext = scriptState->executionContext(); | 193 ExecutionContext* executionContext = scriptState->executionContext(); |
196 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); | 194 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); |
(...skipping 14 matching lines...) Expand all Loading... |
211 if (!documentOrigin->canRequest(completedURL)) { | 209 if (!documentOrigin->canRequest(completedURL)) { |
212 RefPtr<SecurityOrigin> documentURLOrigin = SecurityOrigin::create(comple
tedURL); | 210 RefPtr<SecurityOrigin> documentURLOrigin = SecurityOrigin::create(comple
tedURL); |
213 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() + "').")); | 211 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() + "').")); |
214 return promise; | 212 return promise; |
215 } | 213 } |
216 m_provider->getRegistration(completedURL, new GetRegistrationCallback(resolv
er)); | 214 m_provider->getRegistration(completedURL, new GetRegistrationCallback(resolv
er)); |
217 | 215 |
218 return promise; | 216 return promise; |
219 } | 217 } |
220 | 218 |
| 219 ScriptPromise ServiceWorkerContainer::getRegistrations(ScriptState* scriptState) |
| 220 { |
| 221 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); |
| 222 ScriptPromise promise = resolver->promise(); |
| 223 |
| 224 if (!m_provider) { |
| 225 resolver->reject(DOMException::create(InvalidStateError, "Failed to get
ServiceWorkerRegistration objects: The document is in an invalid state.")); |
| 226 return promise; |
| 227 } |
| 228 |
| 229 ExecutionContext* executionContext = scriptState->executionContext(); |
| 230 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); |
| 231 String errorMessage; |
| 232 if (!executionContext->isPrivilegedContext(errorMessage)) { |
| 233 resolver->reject(DOMException::create(NotSupportedError, errorMessage)); |
| 234 return promise; |
| 235 } |
| 236 |
| 237 KURL pageURL = KURL(KURL(), documentOrigin->toString()); |
| 238 if (!pageURL.protocolIsInHTTPFamily()) { |
| 239 resolver->reject(DOMException::create(SecurityError, "Failed to get Serv
iceWorkerRegistration objects: The URL protocol of the current origin ('" + docu
mentOrigin->toString() + "') is not supported.")); |
| 240 return promise; |
| 241 } |
| 242 |
| 243 m_provider->getRegistrations(new CallbackPromiseAdapter<ServiceWorkerRegistr
ationArray, ServiceWorkerError>(resolver)); |
| 244 |
| 245 return promise; |
| 246 } |
| 247 |
221 ServiceWorkerContainer::ReadyProperty* ServiceWorkerContainer::createReadyProper
ty() | 248 ServiceWorkerContainer::ReadyProperty* ServiceWorkerContainer::createReadyProper
ty() |
222 { | 249 { |
223 return new ReadyProperty(executionContext(), this, ReadyProperty::Ready); | 250 return new ReadyProperty(executionContext(), this, ReadyProperty::Ready); |
224 } | 251 } |
225 | 252 |
226 ScriptPromise ServiceWorkerContainer::ready(ScriptState* callerState) | 253 ScriptPromise ServiceWorkerContainer::ready(ScriptState* callerState) |
227 { | 254 { |
228 if (!executionContext()) | 255 if (!executionContext()) |
229 return ScriptPromise(); | 256 return ScriptPromise(); |
230 | 257 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 return; | 314 return; |
288 | 315 |
289 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { | 316 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { |
290 m_provider = client->provider(); | 317 m_provider = client->provider(); |
291 if (m_provider) | 318 if (m_provider) |
292 m_provider->setClient(this); | 319 m_provider->setClient(this); |
293 } | 320 } |
294 } | 321 } |
295 | 322 |
296 } // namespace blink | 323 } // namespace blink |
OLD | NEW |