| 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" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 deleteIfNoExistingOwner(serviceWorker); | 81 deleteIfNoExistingOwner(serviceWorker); |
| 82 return; | 82 return; |
| 83 } | 83 } |
| 84 m_active = ServiceWorker::from(executionContext(), serviceWorker); | 84 m_active = ServiceWorker::from(executionContext(), serviceWorker); |
| 85 } | 85 } |
| 86 | 86 |
| 87 PassRefPtrWillBeRawPtr<ServiceWorkerRegistration> ServiceWorkerRegistration::tak
e(ScriptPromiseResolver* resolver, WebType* registration) | 87 PassRefPtrWillBeRawPtr<ServiceWorkerRegistration> ServiceWorkerRegistration::tak
e(ScriptPromiseResolver* resolver, WebType* registration) |
| 88 { | 88 { |
| 89 if (!registration) | 89 if (!registration) |
| 90 return nullptr; | 90 return nullptr; |
| 91 return create(resolver->scriptState()->executionContext(), adoptPtr(registra
tion)); | 91 return getOrCreate(resolver->scriptState()->executionContext(), adoptPtr(reg
istration)); |
| 92 } | 92 } |
| 93 | 93 |
| 94 void ServiceWorkerRegistration::dispose(WebType* registration) | 94 void ServiceWorkerRegistration::dispose(WebType* registration) |
| 95 { | 95 { |
| 96 delete registration; | 96 delete registration; |
| 97 } | 97 } |
| 98 | 98 |
| 99 String ServiceWorkerRegistration::scope() const | 99 String ServiceWorkerRegistration::scope() const |
| 100 { | 100 { |
| 101 return m_outerRegistration->scope().string(); | 101 return m_outerRegistration->scope().string(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 116 scopeURL.removeFragmentIdentifier(); | 116 scopeURL.removeFragmentIdentifier(); |
| 117 if (!scope().isEmpty() && !documentOrigin->canRequest(scopeURL)) { | 117 if (!scope().isEmpty() && !documentOrigin->canRequest(scopeURL)) { |
| 118 resolver->reject(DOMException::create(SecurityError, "Can only unregiste
r for scopes in the document's origin.")); | 118 resolver->reject(DOMException::create(SecurityError, "Can only unregiste
r for scopes in the document's origin.")); |
| 119 return promise; | 119 return promise; |
| 120 } | 120 } |
| 121 | 121 |
| 122 m_provider->unregisterServiceWorker(scopeURL, new CallbackPromiseAdapter<Und
efinedValue, ServiceWorkerError>(resolver)); | 122 m_provider->unregisterServiceWorker(scopeURL, new CallbackPromiseAdapter<Und
efinedValue, ServiceWorkerError>(resolver)); |
| 123 return promise; | 123 return promise; |
| 124 } | 124 } |
| 125 | 125 |
| 126 PassRefPtrWillBeRawPtr<ServiceWorkerRegistration> ServiceWorkerRegistration::cre
ate(ExecutionContext* executionContext, PassOwnPtr<WebServiceWorkerRegistration>
outerRegistration) | 126 PassRefPtrWillBeRawPtr<ServiceWorkerRegistration> ServiceWorkerRegistration::get
OrCreate(ExecutionContext* executionContext, PassOwnPtr<WebServiceWorkerRegistra
tion> outerRegistration) |
| 127 { | 127 { |
| 128 if (!outerRegistration) |
| 129 return nullptr; |
| 130 |
| 131 WebServiceWorkerRegistrationProxy* proxy = outerRegistration->proxy(); |
| 132 if (proxy) { |
| 133 ServiceWorkerRegistration* existingRegistration = *proxy; |
| 134 if (existingRegistration) { |
| 135 ASSERT(existingRegistration->executionContext() == executionContext)
; |
| 136 return existingRegistration; |
| 137 } |
| 138 } |
| 139 |
| 128 RefPtrWillBeRawPtr<ServiceWorkerRegistration> registration = adoptRefWillBeR
efCountedGarbageCollected(new ServiceWorkerRegistration(executionContext, outerR
egistration)); | 140 RefPtrWillBeRawPtr<ServiceWorkerRegistration> registration = adoptRefWillBeR
efCountedGarbageCollected(new ServiceWorkerRegistration(executionContext, outerR
egistration)); |
| 129 registration->suspendIfNeeded(); | 141 registration->suspendIfNeeded(); |
| 130 return registration.release(); | 142 return registration.release(); |
| 131 } | 143 } |
| 132 | 144 |
| 133 ServiceWorkerRegistration::ServiceWorkerRegistration(ExecutionContext* execution
Context, PassOwnPtr<WebServiceWorkerRegistration> outerRegistration) | 145 ServiceWorkerRegistration::ServiceWorkerRegistration(ExecutionContext* execution
Context, PassOwnPtr<WebServiceWorkerRegistration> outerRegistration) |
| 134 : ActiveDOMObject(executionContext) | 146 : ActiveDOMObject(executionContext) |
| 147 , WebServiceWorkerRegistrationProxy(this) |
| 135 , m_outerRegistration(outerRegistration) | 148 , m_outerRegistration(outerRegistration) |
| 136 , m_provider(0) | 149 , m_provider(0) |
| 137 { | 150 { |
| 138 ASSERT(m_outerRegistration); | 151 ASSERT(m_outerRegistration); |
| 139 ScriptWrappable::init(this); | 152 ScriptWrappable::init(this); |
| 140 | 153 |
| 141 if (!executionContext) | 154 if (!executionContext) |
| 142 return; | 155 return; |
| 143 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) | 156 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) |
| 144 m_provider = client->provider(); | 157 m_provider = client->provider(); |
| 145 m_outerRegistration->setProxy(this); | 158 m_outerRegistration->setProxy(this); |
| 146 } | 159 } |
| 147 | 160 |
| 148 void ServiceWorkerRegistration::trace(Visitor* visitor) | 161 void ServiceWorkerRegistration::trace(Visitor* visitor) |
| 149 { | 162 { |
| 150 visitor->trace(m_installing); | 163 visitor->trace(m_installing); |
| 151 visitor->trace(m_waiting); | 164 visitor->trace(m_waiting); |
| 152 visitor->trace(m_active); | 165 visitor->trace(m_active); |
| 153 EventTargetWithInlineData::trace(visitor); | 166 EventTargetWithInlineData::trace(visitor); |
| 154 } | 167 } |
| 155 | 168 |
| 156 } // namespace blink | 169 } // namespace blink |
| OLD | NEW |