| 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 "core/events/Event.h" |
| 16 #include "modules/EventTargetModules.h" | 16 #include "modules/EventTargetModules.h" |
| 17 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" | 17 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" |
| 18 #include "modules/serviceworkers/ServiceWorkerError.h" | 18 #include "modules/serviceworkers/ServiceWorkerError.h" |
| 19 #include "platform/serviceworkers/ServiceWorkerRegistrationProxy.h" |
| 19 #include "public/platform/WebServiceWorkerProvider.h" | 20 #include "public/platform/WebServiceWorkerProvider.h" |
| 20 | 21 |
| 21 namespace blink { | 22 namespace blink { |
| 22 | 23 |
| 23 class UndefinedValue { | 24 class UndefinedValue { |
| 24 public: | 25 public: |
| 25 typedef WebServiceWorkerRegistration WebType; | 26 typedef WebServiceWorkerRegistration WebType; |
| 26 static V8UndefinedType take(ScriptPromiseResolver* resolver, WebType* regist
ration) | 27 static V8UndefinedType take(ScriptPromiseResolver* resolver, WebType* regist
ration) |
| 27 { | 28 { |
| 28 ASSERT(!registration); // Anything passed here will be leaked. | 29 ASSERT(!registration); // Anything passed here will be leaked. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 | 74 |
| 74 void ServiceWorkerRegistration::setActive(WebServiceWorker* serviceWorker) | 75 void ServiceWorkerRegistration::setActive(WebServiceWorker* serviceWorker) |
| 75 { | 76 { |
| 76 if (!executionContext()) { | 77 if (!executionContext()) { |
| 77 deleteIfNoExistingOwner(serviceWorker); | 78 deleteIfNoExistingOwner(serviceWorker); |
| 78 return; | 79 return; |
| 79 } | 80 } |
| 80 m_active = ServiceWorker::from(executionContext(), serviceWorker); | 81 m_active = ServiceWorker::from(executionContext(), serviceWorker); |
| 81 } | 82 } |
| 82 | 83 |
| 83 PassRefPtrWillBeRawPtr<ServiceWorkerRegistration> ServiceWorkerRegistration::tak
e(ScriptPromiseResolver* resolver, WebType* registration) | 84 ServiceWorkerRegistration* ServiceWorkerRegistration::take(ScriptPromiseResolver
* resolver, WebType* registration) |
| 84 { | 85 { |
| 85 if (!registration) | 86 if (!registration) |
| 86 return nullptr; | 87 return 0; |
| 87 return getOrCreate(resolver->scriptState()->executionContext(), registration
); | 88 return getOrCreate(resolver->scriptState()->executionContext(), registration
); |
| 88 } | 89 } |
| 89 | 90 |
| 90 void ServiceWorkerRegistration::dispose(WebType* registration) | 91 void ServiceWorkerRegistration::dispose(WebType* registration) |
| 91 { | 92 { |
| 92 delete registration; | 93 delete registration; |
| 93 } | 94 } |
| 94 | 95 |
| 95 String ServiceWorkerRegistration::scope() const | 96 String ServiceWorkerRegistration::scope() const |
| 96 { | 97 { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 112 scopeURL.removeFragmentIdentifier(); | 113 scopeURL.removeFragmentIdentifier(); |
| 113 if (!scope().isEmpty() && !documentOrigin->canRequest(scopeURL)) { | 114 if (!scope().isEmpty() && !documentOrigin->canRequest(scopeURL)) { |
| 114 resolver->reject(DOMException::create(SecurityError, "Can only unregiste
r for scopes in the document's origin.")); | 115 resolver->reject(DOMException::create(SecurityError, "Can only unregiste
r for scopes in the document's origin.")); |
| 115 return promise; | 116 return promise; |
| 116 } | 117 } |
| 117 | 118 |
| 118 m_provider->unregisterServiceWorker(scopeURL, new CallbackPromiseAdapter<Und
efinedValue, ServiceWorkerError>(resolver)); | 119 m_provider->unregisterServiceWorker(scopeURL, new CallbackPromiseAdapter<Und
efinedValue, ServiceWorkerError>(resolver)); |
| 119 return promise; | 120 return promise; |
| 120 } | 121 } |
| 121 | 122 |
| 122 PassRefPtrWillBeRawPtr<ServiceWorkerRegistration> ServiceWorkerRegistration::get
OrCreate(ExecutionContext* executionContext, WebServiceWorkerRegistration* outer
Registration) | 123 ServiceWorkerRegistration* ServiceWorkerRegistration::getOrCreate(ExecutionConte
xt* executionContext, WebServiceWorkerRegistration* outerRegistration) |
| 123 { | 124 { |
| 124 if (!outerRegistration) | 125 if (!outerRegistration) |
| 125 return nullptr; | 126 return 0; |
| 126 | 127 |
| 127 WebServiceWorkerRegistrationProxy* proxy = outerRegistration->proxy(); | 128 WebServiceWorkerRegistrationProxy* proxy = outerRegistration->proxy(); |
| 128 if (proxy) { | 129 if (proxy) { |
| 129 ServiceWorkerRegistration* existingRegistration = *proxy; | 130 ServiceWorkerRegistrationProxy* existingRegistrationProxy = *proxy; |
| 130 if (existingRegistration) { | 131 if (existingRegistrationProxy) { |
| 131 ASSERT(existingRegistration->executionContext() == executionContext)
; | 132 ASSERT(existingRegistrationProxy->registration()->executionContext()
== executionContext); |
| 132 return existingRegistration; | 133 return existingRegistrationProxy->registration(); |
| 133 } | 134 } |
| 134 } | 135 } |
| 135 | 136 |
| 136 RefPtrWillBeRawPtr<ServiceWorkerRegistration> registration = adoptRefWillBeN
oop(new ServiceWorkerRegistration(executionContext, adoptPtr(outerRegistration))
); | 137 ServiceWorkerRegistration* registration = adoptRefCountedGarbageCollectedWil
lBeNoop(new ServiceWorkerRegistration(executionContext, adoptPtr(outerRegistrati
on))); |
| 137 registration->suspendIfNeeded(); | 138 registration->suspendIfNeeded(); |
| 138 return registration.release(); | 139 return registration; |
| 139 } | 140 } |
| 140 | 141 |
| 141 ServiceWorkerRegistration::ServiceWorkerRegistration(ExecutionContext* execution
Context, PassOwnPtr<WebServiceWorkerRegistration> outerRegistration) | 142 ServiceWorkerRegistration::ServiceWorkerRegistration(ExecutionContext* execution
Context, PassOwnPtr<WebServiceWorkerRegistration> outerRegistration) |
| 142 : ActiveDOMObject(executionContext) | 143 : ActiveDOMObject(executionContext) |
| 143 , WebServiceWorkerRegistrationProxy(this) | 144 , WebServiceWorkerRegistrationProxy(ServiceWorkerRegistrationProxy::create(t
his)) |
| 144 , m_outerRegistration(outerRegistration) | 145 , m_outerRegistration(outerRegistration) |
| 145 , m_provider(0) | 146 , m_provider(0) |
| 146 , m_stopped(false) | 147 , m_stopped(false) |
| 147 { | 148 { |
| 148 ASSERT(m_outerRegistration); | 149 ASSERT(m_outerRegistration); |
| 149 ScriptWrappable::init(this); | 150 ScriptWrappable::init(this); |
| 150 | 151 |
| 151 if (!executionContext) | 152 if (!executionContext) |
| 152 return; | 153 return; |
| 153 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) | 154 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 170 | 171 |
| 171 void ServiceWorkerRegistration::stop() | 172 void ServiceWorkerRegistration::stop() |
| 172 { | 173 { |
| 173 if (m_stopped) | 174 if (m_stopped) |
| 174 return; | 175 return; |
| 175 m_stopped = true; | 176 m_stopped = true; |
| 176 m_outerRegistration->proxyStopped(); | 177 m_outerRegistration->proxyStopped(); |
| 177 } | 178 } |
| 178 | 179 |
| 179 } // namespace blink | 180 } // namespace blink |
| OLD | NEW |