| 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 "modules/serviceworkers/ServiceWorkerRegistration.h" | 5 #include "modules/serviceworkers/ServiceWorkerRegistration.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
| 8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
| 9 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
| 10 #include "core/dom/DOMException.h" | 10 #include "core/dom/DOMException.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 std::unique_ptr<WebServiceWorkerRegistration::Handle> handle) { | 68 std::unique_ptr<WebServiceWorkerRegistration::Handle> handle) { |
| 69 ASSERT(handle); | 69 ASSERT(handle); |
| 70 | 70 |
| 71 ServiceWorkerRegistration* existingRegistration = | 71 ServiceWorkerRegistration* existingRegistration = |
| 72 static_cast<ServiceWorkerRegistration*>(handle->registration()->proxy()); | 72 static_cast<ServiceWorkerRegistration*>(handle->registration()->proxy()); |
| 73 if (existingRegistration) { | 73 if (existingRegistration) { |
| 74 ASSERT(existingRegistration->getExecutionContext() == executionContext); | 74 ASSERT(existingRegistration->getExecutionContext() == executionContext); |
| 75 return existingRegistration; | 75 return existingRegistration; |
| 76 } | 76 } |
| 77 | 77 |
| 78 ServiceWorkerRegistration* newRegistration = | 78 return new ServiceWorkerRegistration(executionContext, std::move(handle)); |
| 79 new ServiceWorkerRegistration(executionContext, std::move(handle)); | |
| 80 newRegistration->suspendIfNeeded(); | |
| 81 return newRegistration; | |
| 82 } | 79 } |
| 83 | 80 |
| 84 NavigationPreloadManager* ServiceWorkerRegistration::navigationPreload() { | 81 NavigationPreloadManager* ServiceWorkerRegistration::navigationPreload() { |
| 85 if (!m_navigationPreload) | 82 if (!m_navigationPreload) |
| 86 m_navigationPreload = NavigationPreloadManager::create(this); | 83 m_navigationPreload = NavigationPreloadManager::create(this); |
| 87 return m_navigationPreload; | 84 return m_navigationPreload; |
| 88 } | 85 } |
| 89 | 86 |
| 90 String ServiceWorkerRegistration::scope() const { | 87 String ServiceWorkerRegistration::scope() const { |
| 91 return m_handle->registration()->scope().string(); | 88 return m_handle->registration()->scope().string(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 m_handle->registration()->unregister( | 122 m_handle->registration()->unregister( |
| 126 client->provider(), | 123 client->provider(), |
| 127 WTF::makeUnique<CallbackPromiseAdapter<bool, ServiceWorkerError>>( | 124 WTF::makeUnique<CallbackPromiseAdapter<bool, ServiceWorkerError>>( |
| 128 resolver)); | 125 resolver)); |
| 129 return promise; | 126 return promise; |
| 130 } | 127 } |
| 131 | 128 |
| 132 ServiceWorkerRegistration::ServiceWorkerRegistration( | 129 ServiceWorkerRegistration::ServiceWorkerRegistration( |
| 133 ExecutionContext* executionContext, | 130 ExecutionContext* executionContext, |
| 134 std::unique_ptr<WebServiceWorkerRegistration::Handle> handle) | 131 std::unique_ptr<WebServiceWorkerRegistration::Handle> handle) |
| 135 : SuspendableObject(executionContext), | 132 : ContextLifecycleObserver(executionContext), |
| 136 m_handle(std::move(handle)), | 133 m_handle(std::move(handle)), |
| 137 m_stopped(false) { | 134 m_stopped(false) { |
| 138 ASSERT(m_handle); | 135 ASSERT(m_handle); |
| 139 ASSERT(!m_handle->registration()->proxy()); | 136 ASSERT(!m_handle->registration()->proxy()); |
| 140 | 137 |
| 141 if (!executionContext) | 138 if (!executionContext) |
| 142 return; | 139 return; |
| 143 m_handle->registration()->setProxy(this); | 140 m_handle->registration()->setProxy(this); |
| 144 } | 141 } |
| 145 | 142 |
| 146 ServiceWorkerRegistration::~ServiceWorkerRegistration() {} | 143 ServiceWorkerRegistration::~ServiceWorkerRegistration() {} |
| 147 | 144 |
| 148 void ServiceWorkerRegistration::dispose() { | 145 void ServiceWorkerRegistration::dispose() { |
| 149 // Promptly clears a raw reference from content/ to an on-heap object | 146 // Promptly clears a raw reference from content/ to an on-heap object |
| 150 // so that content/ doesn't access it in a lazy sweeping phase. | 147 // so that content/ doesn't access it in a lazy sweeping phase. |
| 151 m_handle.reset(); | 148 m_handle.reset(); |
| 152 } | 149 } |
| 153 | 150 |
| 154 DEFINE_TRACE(ServiceWorkerRegistration) { | 151 DEFINE_TRACE(ServiceWorkerRegistration) { |
| 155 visitor->trace(m_installing); | 152 visitor->trace(m_installing); |
| 156 visitor->trace(m_waiting); | 153 visitor->trace(m_waiting); |
| 157 visitor->trace(m_active); | 154 visitor->trace(m_active); |
| 158 visitor->trace(m_navigationPreload); | 155 visitor->trace(m_navigationPreload); |
| 159 EventTargetWithInlineData::trace(visitor); | 156 EventTargetWithInlineData::trace(visitor); |
| 160 SuspendableObject::trace(visitor); | 157 ContextLifecycleObserver::trace(visitor); |
| 161 Supplementable<ServiceWorkerRegistration>::trace(visitor); | 158 Supplementable<ServiceWorkerRegistration>::trace(visitor); |
| 162 } | 159 } |
| 163 | 160 |
| 164 void ServiceWorkerRegistration::contextDestroyed() { | 161 void ServiceWorkerRegistration::contextDestroyed() { |
| 165 if (m_stopped) | 162 if (m_stopped) |
| 166 return; | 163 return; |
| 167 m_stopped = true; | 164 m_stopped = true; |
| 168 m_handle->registration()->proxyStopped(); | 165 m_handle->registration()->proxyStopped(); |
| 169 } | 166 } |
| 170 | 167 |
| 171 } // namespace blink | 168 } // namespace blink |
| OLD | NEW |