| 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" | |
| 11 #include "bindings/core/v8/ScriptState.h" | 10 #include "bindings/core/v8/ScriptState.h" |
| 12 #include "core/dom/DOMException.h" | 11 #include "core/dom/DOMException.h" |
| 13 #include "core/dom/ExceptionCode.h" | 12 #include "core/dom/ExceptionCode.h" |
| 14 #include "core/dom/ExecutionContext.h" | 13 #include "core/dom/ExecutionContext.h" |
| 15 #include "core/events/Event.h" | 14 #include "core/events/Event.h" |
| 16 #include "modules/EventTargetModules.h" | 15 #include "modules/EventTargetModules.h" |
| 17 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" | 16 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" |
| 18 #include "modules/serviceworkers/ServiceWorkerError.h" | 17 #include "modules/serviceworkers/ServiceWorkerError.h" |
| 19 #include "public/platform/modules/serviceworker/WebServiceWorkerProvider.h" | 18 #include "public/platform/modules/serviceworker/WebServiceWorkerProvider.h" |
| 20 | 19 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 55 |
| 57 void ServiceWorkerRegistration::setActive(WebServiceWorker* serviceWorker) | 56 void ServiceWorkerRegistration::setActive(WebServiceWorker* serviceWorker) |
| 58 { | 57 { |
| 59 if (!executionContext()) { | 58 if (!executionContext()) { |
| 60 deleteIfNoExistingOwner(serviceWorker); | 59 deleteIfNoExistingOwner(serviceWorker); |
| 61 return; | 60 return; |
| 62 } | 61 } |
| 63 m_active = ServiceWorker::from(executionContext(), serviceWorker); | 62 m_active = ServiceWorker::from(executionContext(), serviceWorker); |
| 64 } | 63 } |
| 65 | 64 |
| 66 ServiceWorkerRegistration* ServiceWorkerRegistration::from(ExecutionContext* exe
cutionContext, WebServiceWorkerRegistration* registration) | 65 ServiceWorkerRegistration* ServiceWorkerRegistration::create(ExecutionContext* e
xecutionContext, PassOwnPtr<WebServiceWorkerRegistration> webRegistration) |
| 67 { | 66 { |
| 68 if (!registration) | 67 if (!webRegistration) |
| 69 return 0; | 68 return nullptr; |
| 70 return getOrCreate(executionContext, registration); | 69 ServiceWorkerRegistration* registration = new ServiceWorkerRegistration(exec
utionContext, webRegistration); |
| 71 } | 70 registration->suspendIfNeeded(); |
| 72 | 71 return registration; |
| 73 ServiceWorkerRegistration* ServiceWorkerRegistration::take(ScriptPromiseResolver
* resolver, WebServiceWorkerRegistration* registration) | |
| 74 { | |
| 75 return from(resolver->scriptState()->executionContext(), registration); | |
| 76 } | |
| 77 | |
| 78 void ServiceWorkerRegistration::dispose(WebServiceWorkerRegistration* registrati
on) | |
| 79 { | |
| 80 if (registration && !registration->proxy()) | |
| 81 delete registration; | |
| 82 } | 72 } |
| 83 | 73 |
| 84 String ServiceWorkerRegistration::scope() const | 74 String ServiceWorkerRegistration::scope() const |
| 85 { | 75 { |
| 86 return m_outerRegistration->scope().string(); | 76 return m_outerRegistration->scope().string(); |
| 87 } | 77 } |
| 88 | 78 |
| 89 ScriptPromise ServiceWorkerRegistration::update(ScriptState* scriptState) | 79 ScriptPromise ServiceWorkerRegistration::update(ScriptState* scriptState) |
| 90 { | 80 { |
| 91 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 81 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 107 | 97 |
| 108 if (!m_provider) { | 98 if (!m_provider) { |
| 109 resolver->reject(DOMException::create(InvalidStateError, "Failed to unre
gister a ServiceWorkerRegistration: No associated provider is available.")); | 99 resolver->reject(DOMException::create(InvalidStateError, "Failed to unre
gister a ServiceWorkerRegistration: No associated provider is available.")); |
| 110 return promise; | 100 return promise; |
| 111 } | 101 } |
| 112 | 102 |
| 113 m_outerRegistration->unregister(m_provider, new CallbackPromiseAdapter<bool,
ServiceWorkerError>(resolver)); | 103 m_outerRegistration->unregister(m_provider, new CallbackPromiseAdapter<bool,
ServiceWorkerError>(resolver)); |
| 114 return promise; | 104 return promise; |
| 115 } | 105 } |
| 116 | 106 |
| 117 ServiceWorkerRegistration* ServiceWorkerRegistration::getOrCreate(ExecutionConte
xt* executionContext, WebServiceWorkerRegistration* outerRegistration) | |
| 118 { | |
| 119 if (!outerRegistration) | |
| 120 return 0; | |
| 121 | |
| 122 ServiceWorkerRegistration* existingRegistration = static_cast<ServiceWorkerR
egistration*>(outerRegistration->proxy()); | |
| 123 if (existingRegistration) { | |
| 124 ASSERT(existingRegistration->executionContext() == executionContext); | |
| 125 return existingRegistration; | |
| 126 } | |
| 127 | |
| 128 ServiceWorkerRegistration* registration = new ServiceWorkerRegistration(exec
utionContext, adoptPtr(outerRegistration)); | |
| 129 registration->suspendIfNeeded(); | |
| 130 return registration; | |
| 131 } | |
| 132 | |
| 133 ServiceWorkerRegistration::ServiceWorkerRegistration(ExecutionContext* execution
Context, PassOwnPtr<WebServiceWorkerRegistration> outerRegistration) | 107 ServiceWorkerRegistration::ServiceWorkerRegistration(ExecutionContext* execution
Context, PassOwnPtr<WebServiceWorkerRegistration> outerRegistration) |
| 134 : ActiveDOMObject(executionContext) | 108 : ActiveDOMObject(executionContext) |
| 135 , m_outerRegistration(outerRegistration) | 109 , m_outerRegistration(outerRegistration) |
| 136 , m_provider(0) | 110 , m_provider(nullptr) |
| 137 , m_stopped(false) | 111 , m_stopped(false) |
| 138 { | 112 { |
| 139 ASSERT(m_outerRegistration); | 113 ASSERT(m_outerRegistration); |
| 114 ASSERT(!m_outerRegistration->proxy()); |
| 140 | 115 |
| 141 if (!executionContext) | 116 if (!executionContext) |
| 142 return; | 117 return; |
| 143 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) | 118 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) |
| 144 m_provider = client->provider(); | 119 m_provider = client->provider(); |
| 145 m_outerRegistration->setProxy(this); | 120 m_outerRegistration->setProxy(this); |
| 146 } | 121 } |
| 147 | 122 |
| 148 ServiceWorkerRegistration::~ServiceWorkerRegistration() | 123 ServiceWorkerRegistration::~ServiceWorkerRegistration() |
| 149 { | 124 { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 166 | 141 |
| 167 void ServiceWorkerRegistration::stop() | 142 void ServiceWorkerRegistration::stop() |
| 168 { | 143 { |
| 169 if (m_stopped) | 144 if (m_stopped) |
| 170 return; | 145 return; |
| 171 m_stopped = true; | 146 m_stopped = true; |
| 172 m_outerRegistration->proxyStopped(); | 147 m_outerRegistration->proxyStopped(); |
| 173 } | 148 } |
| 174 | 149 |
| 175 } // namespace blink | 150 } // namespace blink |
| OLD | NEW |