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 30 matching lines...) Expand all Loading... |
41 #include "core/dom/MessagePort.h" | 41 #include "core/dom/MessagePort.h" |
42 #include "core/events/MessageEvent.h" | 42 #include "core/events/MessageEvent.h" |
43 #include "modules/serviceworkers/RegistrationOptionList.h" | 43 #include "modules/serviceworkers/RegistrationOptionList.h" |
44 #include "modules/serviceworkers/ServiceWorker.h" | 44 #include "modules/serviceworkers/ServiceWorker.h" |
45 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" | 45 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" |
46 #include "modules/serviceworkers/ServiceWorkerError.h" | 46 #include "modules/serviceworkers/ServiceWorkerError.h" |
47 #include "modules/serviceworkers/ServiceWorkerRegistration.h" | 47 #include "modules/serviceworkers/ServiceWorkerRegistration.h" |
48 #include "platform/RuntimeEnabledFeatures.h" | 48 #include "platform/RuntimeEnabledFeatures.h" |
49 #include "public/platform/WebServiceWorker.h" | 49 #include "public/platform/WebServiceWorker.h" |
50 #include "public/platform/WebServiceWorkerProvider.h" | 50 #include "public/platform/WebServiceWorkerProvider.h" |
| 51 #include "public/platform/WebServiceWorkerRegistration.h" |
51 #include "public/platform/WebString.h" | 52 #include "public/platform/WebString.h" |
52 #include "public/platform/WebURL.h" | 53 #include "public/platform/WebURL.h" |
53 | 54 |
54 using blink::WebServiceWorker; | |
55 using blink::WebServiceWorkerProvider; | |
56 | |
57 namespace blink { | 55 namespace blink { |
58 | 56 |
59 PassRefPtrWillBeRawPtr<ServiceWorkerContainer> ServiceWorkerContainer::create(Ex
ecutionContext* executionContext) | 57 PassRefPtrWillBeRawPtr<ServiceWorkerContainer> ServiceWorkerContainer::create(Ex
ecutionContext* executionContext) |
60 { | 58 { |
61 return adoptRefWillBeNoop(new ServiceWorkerContainer(executionContext)); | 59 return adoptRefWillBeNoop(new ServiceWorkerContainer(executionContext)); |
62 } | 60 } |
63 | 61 |
64 ServiceWorkerContainer::~ServiceWorkerContainer() | 62 ServiceWorkerContainer::~ServiceWorkerContainer() |
65 { | 63 { |
66 ASSERT(!m_provider); | 64 ASSERT(!m_provider); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 186 |
189 // If the WebServiceWorker is up for adoption (does not have a | 187 // If the WebServiceWorker is up for adoption (does not have a |
190 // WebServiceWorkerProxy owner), rejects the adoption by deleting the | 188 // WebServiceWorkerProxy owner), rejects the adoption by deleting the |
191 // WebServiceWorker. | 189 // WebServiceWorker. |
192 static void deleteIfNoExistingOwner(WebServiceWorker* serviceWorker) | 190 static void deleteIfNoExistingOwner(WebServiceWorker* serviceWorker) |
193 { | 191 { |
194 if (serviceWorker && !serviceWorker->proxy()) | 192 if (serviceWorker && !serviceWorker->proxy()) |
195 delete serviceWorker; | 193 delete serviceWorker; |
196 } | 194 } |
197 | 195 |
| 196 static void deleteIfNoExistingOwner(WebServiceWorkerRegistration* registration) |
| 197 { |
| 198 if (registration && !registration->proxy()) |
| 199 delete registration; |
| 200 } |
| 201 |
| 202 void ServiceWorkerContainer::setReadyRegistration(WebServiceWorkerRegistration*
registration) |
| 203 { |
| 204 if (!executionContext()) { |
| 205 deleteIfNoExistingOwner(registration); |
| 206 return; |
| 207 } |
| 208 |
| 209 RefPtrWillBeRawPtr<ServiceWorkerRegistration> readyRegistration = ServiceWor
kerRegistration::from(executionContext(), registration); |
| 210 ASSERT(readyRegistration->active()); |
| 211 |
| 212 if (m_readyRegistration) { |
| 213 ASSERT(m_readyRegistration == readyRegistration); |
| 214 ASSERT(m_ready->state() == ReadyProperty::Resolved); |
| 215 return; |
| 216 } |
| 217 |
| 218 m_readyRegistration = readyRegistration; |
| 219 m_ready->resolve(readyRegistration); |
| 220 } |
| 221 |
198 void ServiceWorkerContainer::setActive(WebServiceWorker* serviceWorker) | 222 void ServiceWorkerContainer::setActive(WebServiceWorker* serviceWorker) |
199 { | 223 { |
200 if (!executionContext()) { | 224 if (!executionContext()) { |
201 deleteIfNoExistingOwner(serviceWorker); | 225 deleteIfNoExistingOwner(serviceWorker); |
202 return; | 226 return; |
203 } | 227 } |
204 RefPtrWillBeRawPtr<ServiceWorker> previousReadyWorker = m_active; | |
205 m_active = ServiceWorker::from(executionContext(), serviceWorker); | 228 m_active = ServiceWorker::from(executionContext(), serviceWorker); |
206 checkReadyChanged(previousReadyWorker.release()); | |
207 } | |
208 | |
209 void ServiceWorkerContainer::checkReadyChanged(PassRefPtrWillBeRawPtr<ServiceWor
ker> previousReadyWorker) | |
210 { | |
211 ServiceWorker* currentReadyWorker = m_active.get(); | |
212 | |
213 if (previousReadyWorker == currentReadyWorker) | |
214 return; | |
215 | |
216 if (m_ready->state() != ReadyProperty::Pending) { | |
217 // Already resolved Promises are now stale because the | |
218 // ready worker changed | |
219 m_ready = createReadyProperty(); | |
220 } | |
221 | |
222 if (currentReadyWorker) | |
223 m_ready->resolve(currentReadyWorker); | |
224 } | 229 } |
225 | 230 |
226 void ServiceWorkerContainer::setController(WebServiceWorker* serviceWorker) | 231 void ServiceWorkerContainer::setController(WebServiceWorker* serviceWorker) |
227 { | 232 { |
228 if (!executionContext()) { | 233 if (!executionContext()) { |
229 deleteIfNoExistingOwner(serviceWorker); | 234 deleteIfNoExistingOwner(serviceWorker); |
230 return; | 235 return; |
231 } | 236 } |
232 m_controller = ServiceWorker::from(executionContext(), serviceWorker); | 237 m_controller = ServiceWorker::from(executionContext(), serviceWorker); |
233 } | 238 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 m_ready = createReadyProperty(); | 277 m_ready = createReadyProperty(); |
273 | 278 |
274 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { | 279 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { |
275 m_provider = client->provider(); | 280 m_provider = client->provider(); |
276 if (m_provider) | 281 if (m_provider) |
277 m_provider->setClient(this); | 282 m_provider->setClient(this); |
278 } | 283 } |
279 } | 284 } |
280 | 285 |
281 } // namespace blink | 286 } // namespace blink |
OLD | NEW |