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