| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 69 |
| 70 void ServiceWorkerRegistration::setActive(WebServiceWorker* serviceWorker) | 70 void ServiceWorkerRegistration::setActive(WebServiceWorker* serviceWorker) |
| 71 { | 71 { |
| 72 if (!executionContext()) { | 72 if (!executionContext()) { |
| 73 deleteIfNoExistingOwner(serviceWorker); | 73 deleteIfNoExistingOwner(serviceWorker); |
| 74 return; | 74 return; |
| 75 } | 75 } |
| 76 m_active = ServiceWorker::from(executionContext(), serviceWorker); | 76 m_active = ServiceWorker::from(executionContext(), serviceWorker); |
| 77 } | 77 } |
| 78 | 78 |
| 79 PassRefPtrWillBeRawPtr<ServiceWorkerRegistration> ServiceWorkerRegistration::tak
e(ScriptPromiseResolver* resolver, WebType* registration) | 79 ServiceWorkerRegistration* ServiceWorkerRegistration::take(ScriptPromiseResolver
* resolver, WebType* registration) |
| 80 { | 80 { |
| 81 if (!registration) | 81 if (!registration) |
| 82 return nullptr; | 82 return 0; |
| 83 return getOrCreate(resolver->scriptState()->executionContext(), registration
); | 83 return getOrCreate(resolver->scriptState()->executionContext(), registration
); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void ServiceWorkerRegistration::dispose(WebType* registration) | 86 void ServiceWorkerRegistration::dispose(WebType* registration) |
| 87 { | 87 { |
| 88 delete registration; | 88 delete registration; |
| 89 } | 89 } |
| 90 | 90 |
| 91 String ServiceWorkerRegistration::scope() const | 91 String ServiceWorkerRegistration::scope() const |
| 92 { | 92 { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 108 scopeURL.removeFragmentIdentifier(); | 108 scopeURL.removeFragmentIdentifier(); |
| 109 if (!scope().isEmpty() && !documentOrigin->canRequest(scopeURL)) { | 109 if (!scope().isEmpty() && !documentOrigin->canRequest(scopeURL)) { |
| 110 resolver->reject(DOMException::create(SecurityError, "Can only unregiste
r for scopes in the document's origin.")); | 110 resolver->reject(DOMException::create(SecurityError, "Can only unregiste
r for scopes in the document's origin.")); |
| 111 return promise; | 111 return promise; |
| 112 } | 112 } |
| 113 | 113 |
| 114 m_provider->unregisterServiceWorker(scopeURL, new CallbackPromiseAdapter<Boo
leanValue, ServiceWorkerError>(resolver)); | 114 m_provider->unregisterServiceWorker(scopeURL, new CallbackPromiseAdapter<Boo
leanValue, ServiceWorkerError>(resolver)); |
| 115 return promise; | 115 return promise; |
| 116 } | 116 } |
| 117 | 117 |
| 118 PassRefPtrWillBeRawPtr<ServiceWorkerRegistration> ServiceWorkerRegistration::get
OrCreate(ExecutionContext* executionContext, WebServiceWorkerRegistration* outer
Registration) | 118 ServiceWorkerRegistration* ServiceWorkerRegistration::getOrCreate(ExecutionConte
xt* executionContext, WebServiceWorkerRegistration* outerRegistration) |
| 119 { | 119 { |
| 120 if (!outerRegistration) | 120 if (!outerRegistration) |
| 121 return nullptr; | 121 return 0; |
| 122 | 122 |
| 123 WebServiceWorkerRegistrationProxy* proxy = outerRegistration->proxy(); | 123 WebServiceWorkerRegistrationProxy* proxy = outerRegistration->proxy(); |
| 124 if (proxy) { | 124 if (proxy) { |
| 125 ServiceWorkerRegistration* existingRegistration = *proxy; | 125 ServiceWorkerRegistration* existingRegistration = *proxy; |
| 126 if (existingRegistration) { | 126 if (existingRegistration) { |
| 127 ASSERT(existingRegistration->executionContext() == executionContext)
; | 127 ASSERT(existingRegistration->executionContext() == executionContext)
; |
| 128 return existingRegistration; | 128 return existingRegistration; |
| 129 } | 129 } |
| 130 } | 130 } |
| 131 | 131 |
| 132 RefPtrWillBeRawPtr<ServiceWorkerRegistration> registration = adoptRefWillBeN
oop(new ServiceWorkerRegistration(executionContext, adoptPtr(outerRegistration))
); | 132 ServiceWorkerRegistration* registration = adoptRefCountedGarbageCollectedWil
lBeNoop(new ServiceWorkerRegistration(executionContext, adoptPtr(outerRegistrati
on))); |
| 133 registration->suspendIfNeeded(); | 133 registration->suspendIfNeeded(); |
| 134 return registration.release(); | 134 return registration; |
| 135 } | 135 } |
| 136 | 136 |
| 137 ServiceWorkerRegistration::ServiceWorkerRegistration(ExecutionContext* execution
Context, PassOwnPtr<WebServiceWorkerRegistration> outerRegistration) | 137 ServiceWorkerRegistration::ServiceWorkerRegistration(ExecutionContext* execution
Context, PassOwnPtr<WebServiceWorkerRegistration> outerRegistration) |
| 138 : ActiveDOMObject(executionContext) | 138 : ActiveDOMObject(executionContext) |
| 139 , WebServiceWorkerRegistrationProxy(this) | 139 , WebServiceWorkerRegistrationProxy(this) |
| 140 , m_outerRegistration(outerRegistration) | 140 , m_outerRegistration(outerRegistration) |
| 141 , m_provider(0) | 141 , m_provider(0) |
| 142 , m_stopped(false) | 142 , m_stopped(false) |
| 143 { | 143 { |
| 144 ASSERT(m_outerRegistration); | 144 ASSERT(m_outerRegistration); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 166 | 166 |
| 167 void ServiceWorkerRegistration::stop() | 167 void ServiceWorkerRegistration::stop() |
| 168 { | 168 { |
| 169 if (m_stopped) | 169 if (m_stopped) |
| 170 return; | 170 return; |
| 171 m_stopped = true; | 171 m_stopped = true; |
| 172 m_outerRegistration->proxyStopped(); | 172 m_outerRegistration->proxyStopped(); |
| 173 } | 173 } |
| 174 | 174 |
| 175 } // namespace blink | 175 } // namespace blink |
| OLD | NEW |