Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(468)

Side by Side Diff: Source/modules/serviceworkers/ServiceWorkerContainer.cpp

Issue 894983002: ServiceWorker: Make "ready" fetches registration from browser process(1/3). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: pass layout tests Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 else if (m_resolver->executionContext() && !m_resolver->executionContext ()->activeDOMObjectsAreStopped()) 74 else if (m_resolver->executionContext() && !m_resolver->executionContext ()->activeDOMObjectsAreStopped())
75 m_resolver->resolve(); 75 m_resolver->resolve();
76 } 76 }
77 virtual void onError(WebServiceWorkerError* error) override { m_adapter.onEr ror(error); } 77 virtual void onError(WebServiceWorkerError* error) override { m_adapter.onEr ror(error); }
78 private: 78 private:
79 RefPtrWillBePersistent<ScriptPromiseResolver> m_resolver; 79 RefPtrWillBePersistent<ScriptPromiseResolver> m_resolver;
80 CallbackPromiseAdapter<ServiceWorkerRegistration, ServiceWorkerError> m_adap ter; 80 CallbackPromiseAdapter<ServiceWorkerRegistration, ServiceWorkerError> m_adap ter;
81 WTF_MAKE_NONCOPYABLE(GetRegistrationCallback); 81 WTF_MAKE_NONCOPYABLE(GetRegistrationCallback);
82 }; 82 };
83 83
84 class ServiceWorkerContainer::GetRegistrationForReadyCallback : public WebServic eWorkerProvider::WebServiceWorkerGetRegistrationForReadyCallbacks {
85 public:
86 explicit GetRegistrationForReadyCallback(ReadyProperty* ready)
87 : m_ready(ready) { }
88 ~GetRegistrationForReadyCallback() { }
89 void onSuccess(WebServiceWorkerRegistration* registration) override
90 {
91 ASSERT(registration);
92 ASSERT(m_ready->state() == ReadyProperty::Pending);
93 if (m_ready->executionContext() && !m_ready->executionContext()->activeD OMObjectsAreStopped())
94 m_ready->resolve(ServiceWorkerRegistration::from(m_ready->executionC ontext(), registration));
95 }
96 private:
97 Persistent<ReadyProperty> m_ready;
98 WTF_MAKE_NONCOPYABLE(GetRegistrationForReadyCallback);
99 };
100
84 ServiceWorkerContainer* ServiceWorkerContainer::create(ExecutionContext* executi onContext) 101 ServiceWorkerContainer* ServiceWorkerContainer::create(ExecutionContext* executi onContext)
85 { 102 {
86 return new ServiceWorkerContainer(executionContext); 103 return new ServiceWorkerContainer(executionContext);
87 } 104 }
88 105
89 ServiceWorkerContainer::~ServiceWorkerContainer() 106 ServiceWorkerContainer::~ServiceWorkerContainer()
90 { 107 {
91 ASSERT(!m_provider); 108 ASSERT(!m_provider);
92 } 109 }
93 110
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 { 243 {
227 if (!executionContext()) 244 if (!executionContext())
228 return ScriptPromise(); 245 return ScriptPromise();
229 246
230 if (!callerState->world().isMainWorld()) { 247 if (!callerState->world().isMainWorld()) {
231 // FIXME: Support .ready from isolated worlds when 248 // FIXME: Support .ready from isolated worlds when
232 // ScriptPromiseProperty can vend Promises in isolated worlds. 249 // ScriptPromiseProperty can vend Promises in isolated worlds.
233 return ScriptPromise::rejectWithDOMException(callerState, DOMException:: create(NotSupportedError, "'ready' is only supported in pages.")); 250 return ScriptPromise::rejectWithDOMException(callerState, DOMException:: create(NotSupportedError, "'ready' is only supported in pages."));
234 } 251 }
235 252
253 if (!m_ready) {
254 m_ready = createReadyProperty();
255 if (m_provider)
256 m_provider->getRegistrationForReady(new GetRegistrationForReadyCallb ack(m_ready.get()));
257 }
258
236 return m_ready->promise(callerState->world()); 259 return m_ready->promise(callerState->world());
237 } 260 }
238 261
239 // If the WebServiceWorker is up for adoption (does not have a 262 // If the WebServiceWorker is up for adoption (does not have a
240 // WebServiceWorkerProxy owner), rejects the adoption by deleting the 263 // WebServiceWorkerProxy owner), rejects the adoption by deleting the
241 // WebServiceWorker. 264 // WebServiceWorker.
242 static void deleteIfNoExistingOwner(WebServiceWorker* serviceWorker) 265 static void deleteIfNoExistingOwner(WebServiceWorker* serviceWorker)
243 { 266 {
244 if (serviceWorker && !serviceWorker->proxy()) 267 if (serviceWorker && !serviceWorker->proxy())
245 delete serviceWorker; 268 delete serviceWorker;
246 } 269 }
247 270
248 void ServiceWorkerContainer::setController(WebServiceWorker* serviceWorker, bool shouldNotifyControllerChange) 271 void ServiceWorkerContainer::setController(WebServiceWorker* serviceWorker, bool shouldNotifyControllerChange)
249 { 272 {
250 if (!executionContext()) { 273 if (!executionContext()) {
251 deleteIfNoExistingOwner(serviceWorker); 274 deleteIfNoExistingOwner(serviceWorker);
252 return; 275 return;
253 } 276 }
254 m_controller = ServiceWorker::from(executionContext(), serviceWorker); 277 m_controller = ServiceWorker::from(executionContext(), serviceWorker);
255 if (shouldNotifyControllerChange) 278 if (shouldNotifyControllerChange)
256 dispatchEvent(Event::create(EventTypeNames::controllerchange)); 279 dispatchEvent(Event::create(EventTypeNames::controllerchange));
257 } 280 }
258 281
282 // FIXME: Remove this after Chrome side CL landed.
259 void ServiceWorkerContainer::setReadyRegistration(WebServiceWorkerRegistration* registration) 283 void ServiceWorkerContainer::setReadyRegistration(WebServiceWorkerRegistration* registration)
260 { 284 {
261 if (!executionContext()) { 285 if (!executionContext()) {
262 ServiceWorkerRegistration::dispose(registration); 286 ServiceWorkerRegistration::dispose(registration);
263 return; 287 return;
264 } 288 }
265 289
266 ServiceWorkerRegistration* readyRegistration = ServiceWorkerRegistration::fr om(executionContext(), registration); 290 ServiceWorkerRegistration* readyRegistration = ServiceWorkerRegistration::fr om(executionContext(), registration);
267 ASSERT(readyRegistration->active()); 291 ASSERT(readyRegistration->active());
268 292
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 } 335 }
312 336
313 ServiceWorkerContainer::ServiceWorkerContainer(ExecutionContext* executionContex t) 337 ServiceWorkerContainer::ServiceWorkerContainer(ExecutionContext* executionContex t)
314 : ContextLifecycleObserver(executionContext) 338 : ContextLifecycleObserver(executionContext)
315 , m_provider(0) 339 , m_provider(0)
316 { 340 {
317 341
318 if (!executionContext) 342 if (!executionContext)
319 return; 343 return;
320 344
345 // FIXME: Remove this after Chrome side CL landed.
321 m_ready = createReadyProperty(); 346 m_ready = createReadyProperty();
322 347
323 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro m(executionContext)) { 348 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro m(executionContext)) {
324 m_provider = client->provider(); 349 m_provider = client->provider();
325 if (m_provider) 350 if (m_provider)
326 m_provider->setClient(this); 351 m_provider->setClient(this);
327 } 352 }
328 } 353 }
329 354
330 } // namespace blink 355 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/serviceworkers/ServiceWorkerContainer.h ('k') | public/platform/WebServiceWorkerProvider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698