Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "ServiceWorkerRegistration.h" | 6 #include "ServiceWorkerRegistration.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 8 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
| 9 #include "bindings/core/v8/ScriptPromise.h" | 9 #include "bindings/core/v8/ScriptPromise.h" |
| 10 #include "bindings/core/v8/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 11 #include "bindings/core/v8/ScriptState.h" | 11 #include "bindings/core/v8/ScriptState.h" |
| 12 #include "core/dom/DOMException.h" | 12 #include "core/dom/DOMException.h" |
| 13 #include "core/dom/ExceptionCode.h" | 13 #include "core/dom/ExceptionCode.h" |
| 14 #include "core/dom/ExecutionContext.h" | 14 #include "core/dom/ExecutionContext.h" |
| 15 #include "core/events/Event.h" | |
| 15 #include "modules/EventTargetModules.h" | 16 #include "modules/EventTargetModules.h" |
| 16 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" | 17 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" |
| 17 #include "modules/serviceworkers/ServiceWorkerError.h" | 18 #include "modules/serviceworkers/ServiceWorkerError.h" |
| 18 #include "public/platform/WebServiceWorkerProvider.h" | 19 #include "public/platform/WebServiceWorkerProvider.h" |
| 19 | 20 |
| 20 namespace blink { | 21 namespace blink { |
| 21 | 22 |
| 22 class UndefinedValue { | 23 class UndefinedValue { |
| 23 public: | 24 public: |
| 24 #ifdef DISABLE_SERVICE_WORKER_REGISTRATION | 25 #ifdef DISABLE_SERVICE_WORKER_REGISTRATION |
| 25 typedef WebServiceWorker WebType; | 26 typedef WebServiceWorker WebType; |
| 26 #else | 27 #else |
| 27 typedef WebServiceWorkerRegistration WebType; | 28 typedef WebServiceWorkerRegistration WebType; |
| 28 #endif | 29 #endif |
| 29 static V8UndefinedType take(ScriptPromiseResolver* resolver, WebType* regist ration) | 30 static V8UndefinedType take(ScriptPromiseResolver* resolver, WebType* regist ration) |
| 30 { | 31 { |
| 31 ASSERT(!registration); // Anything passed here will be leaked. | 32 ASSERT(!registration); // Anything passed here will be leaked. |
| 32 return V8UndefinedType(); | 33 return V8UndefinedType(); |
| 33 } | 34 } |
| 34 static void dispose(WebType* registration) | 35 static void dispose(WebType* registration) |
| 35 { | 36 { |
| 36 ASSERT(!registration); // Anything passed here will be leaked. | 37 ASSERT(!registration); // Anything passed here will be leaked. |
| 37 } | 38 } |
| 38 | 39 |
| 39 private: | 40 private: |
| 40 UndefinedValue(); | 41 UndefinedValue(); |
| 41 }; | 42 }; |
| 42 | 43 |
| 44 static void deleteIfNoExistingOwner(blink::WebServiceWorker* serviceWorker) | |
|
tkent
2014/08/11 01:31:32
Remove blink::
nhiroki
2014/08/11 02:26:06
Done.
| |
| 45 { | |
| 46 if (serviceWorker && !serviceWorker->proxy()) | |
| 47 delete serviceWorker; | |
| 48 } | |
| 49 | |
| 43 const AtomicString& ServiceWorkerRegistration::interfaceName() const | 50 const AtomicString& ServiceWorkerRegistration::interfaceName() const |
| 44 { | 51 { |
| 45 return EventTargetNames::ServiceWorkerRegistration; | 52 return EventTargetNames::ServiceWorkerRegistration; |
| 46 } | 53 } |
| 47 | 54 |
| 55 void ServiceWorkerRegistration::dispatchUpdateFoundEvent() | |
| 56 { | |
| 57 dispatchEvent(Event::create(EventTypeNames::updatefound)); | |
| 58 } | |
| 59 | |
| 60 void ServiceWorkerRegistration::setInstalling(WebServiceWorker* serviceWorker) | |
| 61 { | |
| 62 if (!executionContext()) { | |
| 63 deleteIfNoExistingOwner(serviceWorker); | |
| 64 return; | |
| 65 } | |
| 66 m_installing = ServiceWorker::from(executionContext(), serviceWorker); | |
| 67 } | |
| 68 | |
| 69 void ServiceWorkerRegistration::setWaiting(WebServiceWorker* serviceWorker) | |
| 70 { | |
| 71 if (!executionContext()) { | |
| 72 deleteIfNoExistingOwner(serviceWorker); | |
| 73 return; | |
| 74 } | |
| 75 m_waiting = ServiceWorker::from(executionContext(), serviceWorker); | |
| 76 } | |
| 77 | |
| 78 void ServiceWorkerRegistration::setActive(WebServiceWorker* serviceWorker) | |
| 79 { | |
| 80 if (!executionContext()) { | |
| 81 deleteIfNoExistingOwner(serviceWorker); | |
| 82 return; | |
| 83 } | |
| 84 m_active = ServiceWorker::from(executionContext(), serviceWorker); | |
| 85 } | |
| 86 | |
| 48 PassRefPtrWillBeRawPtr<ServiceWorkerRegistration> ServiceWorkerRegistration::tak e(ScriptPromiseResolver* resolver, WebType* registration) | 87 PassRefPtrWillBeRawPtr<ServiceWorkerRegistration> ServiceWorkerRegistration::tak e(ScriptPromiseResolver* resolver, WebType* registration) |
| 49 { | 88 { |
| 50 if (!registration) | 89 if (!registration) |
| 51 return nullptr; | 90 return nullptr; |
| 52 return create(resolver->scriptState()->executionContext(), adoptPtr(registra tion)); | 91 return create(resolver->scriptState()->executionContext(), adoptPtr(registra tion)); |
| 53 } | 92 } |
| 54 | 93 |
| 94 void ServiceWorkerRegistration::dispose(WebType* registration) | |
| 95 { | |
| 96 delete registration; | |
| 97 } | |
| 98 | |
| 55 String ServiceWorkerRegistration::scope() const | 99 String ServiceWorkerRegistration::scope() const |
| 56 { | 100 { |
| 57 return m_outerRegistration->scope().string(); | 101 return m_outerRegistration->scope().string(); |
| 58 } | 102 } |
| 59 | 103 |
| 60 ScriptPromise ServiceWorkerRegistration::unregister(ScriptState* scriptState) | 104 ScriptPromise ServiceWorkerRegistration::unregister(ScriptState* scriptState) |
| 61 { | 105 { |
| 62 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); | 106 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); |
| 63 ScriptPromise promise = resolver->promise(); | 107 ScriptPromise promise = resolver->promise(); |
| 64 | 108 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 91 , m_outerRegistration(outerRegistration) | 135 , m_outerRegistration(outerRegistration) |
| 92 , m_provider(0) | 136 , m_provider(0) |
| 93 { | 137 { |
| 94 ASSERT(m_outerRegistration); | 138 ASSERT(m_outerRegistration); |
| 95 ScriptWrappable::init(this); | 139 ScriptWrappable::init(this); |
| 96 | 140 |
| 97 if (!executionContext) | 141 if (!executionContext) |
| 98 return; | 142 return; |
| 99 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro m(executionContext)) | 143 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro m(executionContext)) |
| 100 m_provider = client->provider(); | 144 m_provider = client->provider(); |
| 145 m_outerRegistration->setProxy(this); | |
| 101 } | 146 } |
| 102 | 147 |
| 103 } // namespace blink | 148 } // namespace blink |
| OLD | NEW |