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 ServiceWorkerContainer* ServiceWorkerContainer::create(ExecutionContext* executi
onContext) | 57 ServiceWorkerContainer* ServiceWorkerContainer::create(ExecutionContext* executi
onContext) |
60 { | 58 { |
61 return new ServiceWorkerContainer(executionContext); | 59 return new ServiceWorkerContainer(executionContext); |
62 } | 60 } |
63 | 61 |
64 ServiceWorkerContainer::~ServiceWorkerContainer() | 62 ServiceWorkerContainer::~ServiceWorkerContainer() |
65 { | 63 { |
66 ASSERT(!m_provider); | 64 ASSERT(!m_provider); |
67 } | 65 } |
68 | 66 |
69 void ServiceWorkerContainer::willBeDetachedFromFrame() | 67 void ServiceWorkerContainer::willBeDetachedFromFrame() |
70 { | 68 { |
71 if (m_provider) { | 69 if (m_provider) { |
72 m_provider->setClient(0); | 70 m_provider->setClient(0); |
73 m_provider = nullptr; | 71 m_provider = nullptr; |
74 } | 72 } |
75 } | 73 } |
76 | 74 |
77 void ServiceWorkerContainer::trace(Visitor* visitor) | 75 void ServiceWorkerContainer::trace(Visitor* visitor) |
78 { | 76 { |
79 visitor->trace(m_active); | 77 visitor->trace(m_active); |
80 visitor->trace(m_controller); | 78 visitor->trace(m_controller); |
81 visitor->trace(m_installing); | 79 visitor->trace(m_installing); |
82 visitor->trace(m_waiting); | 80 visitor->trace(m_waiting); |
| 81 visitor->trace(m_readyRegistration); |
83 visitor->trace(m_ready); | 82 visitor->trace(m_ready); |
84 } | 83 } |
85 | 84 |
86 ScriptPromise ServiceWorkerContainer::registerServiceWorker(ScriptState* scriptS
tate, const String& url, const Dictionary& dictionary) | 85 ScriptPromise ServiceWorkerContainer::registerServiceWorker(ScriptState* scriptS
tate, const String& url, const Dictionary& dictionary) |
87 { | 86 { |
88 RegistrationOptionList options(dictionary); | 87 RegistrationOptionList options(dictionary); |
89 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); | 88 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); |
90 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); | 89 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); |
91 ScriptPromise promise = resolver->promise(); | 90 ScriptPromise promise = resolver->promise(); |
92 | 91 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 187 |
189 // If the WebServiceWorker is up for adoption (does not have a | 188 // If the WebServiceWorker is up for adoption (does not have a |
190 // WebServiceWorkerProxy owner), rejects the adoption by deleting the | 189 // WebServiceWorkerProxy owner), rejects the adoption by deleting the |
191 // WebServiceWorker. | 190 // WebServiceWorker. |
192 static void deleteIfNoExistingOwner(WebServiceWorker* serviceWorker) | 191 static void deleteIfNoExistingOwner(WebServiceWorker* serviceWorker) |
193 { | 192 { |
194 if (serviceWorker && !serviceWorker->proxy()) | 193 if (serviceWorker && !serviceWorker->proxy()) |
195 delete serviceWorker; | 194 delete serviceWorker; |
196 } | 195 } |
197 | 196 |
| 197 static void deleteIfNoExistingOwner(WebServiceWorkerRegistration* registration) |
| 198 { |
| 199 if (registration && !registration->proxy()) |
| 200 delete registration; |
| 201 } |
| 202 |
| 203 void ServiceWorkerContainer::setReadyRegistration(WebServiceWorkerRegistration*
registration) |
| 204 { |
| 205 if (!executionContext()) { |
| 206 deleteIfNoExistingOwner(registration); |
| 207 return; |
| 208 } |
| 209 |
| 210 ServiceWorkerRegistration* readyRegistration = ServiceWorkerRegistration::fr
om(executionContext(), registration); |
| 211 ASSERT(readyRegistration->active()); |
| 212 |
| 213 if (m_readyRegistration) { |
| 214 ASSERT(m_readyRegistration == readyRegistration); |
| 215 ASSERT(m_ready->state() == ReadyProperty::Resolved); |
| 216 return; |
| 217 } |
| 218 |
| 219 m_readyRegistration = readyRegistration; |
| 220 m_ready->resolve(readyRegistration); |
| 221 } |
| 222 |
198 void ServiceWorkerContainer::setActive(WebServiceWorker* serviceWorker) | 223 void ServiceWorkerContainer::setActive(WebServiceWorker* serviceWorker) |
199 { | 224 { |
200 if (!executionContext()) { | 225 if (!executionContext()) { |
201 deleteIfNoExistingOwner(serviceWorker); | 226 deleteIfNoExistingOwner(serviceWorker); |
202 return; | 227 return; |
203 } | 228 } |
204 RefPtrWillBeRawPtr<ServiceWorker> previousReadyWorker = m_active; | |
205 m_active = ServiceWorker::from(executionContext(), serviceWorker); | 229 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 } | 230 } |
225 | 231 |
226 void ServiceWorkerContainer::setController(WebServiceWorker* serviceWorker) | 232 void ServiceWorkerContainer::setController(WebServiceWorker* serviceWorker) |
227 { | 233 { |
228 if (!executionContext()) { | 234 if (!executionContext()) { |
229 deleteIfNoExistingOwner(serviceWorker); | 235 deleteIfNoExistingOwner(serviceWorker); |
230 return; | 236 return; |
231 } | 237 } |
232 m_controller = ServiceWorker::from(executionContext(), serviceWorker); | 238 m_controller = ServiceWorker::from(executionContext(), serviceWorker); |
233 } | 239 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 m_ready = createReadyProperty(); | 278 m_ready = createReadyProperty(); |
273 | 279 |
274 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { | 280 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { |
275 m_provider = client->provider(); | 281 m_provider = client->provider(); |
276 if (m_provider) | 282 if (m_provider) |
277 m_provider->setClient(this); | 283 m_provider->setClient(this); |
278 } | 284 } |
279 } | 285 } |
280 | 286 |
281 } // namespace blink | 287 } // namespace blink |
OLD | NEW |