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" | |
18 #include "modules/serviceworkers/ServiceWorkerError.h" | 17 #include "modules/serviceworkers/ServiceWorkerError.h" |
19 #include "public/platform/WebServiceWorkerProvider.h" | |
20 | 18 |
21 namespace blink { | 19 namespace blink { |
22 | 20 |
23 class BooleanValue { | 21 class BooleanValue { |
24 public: | 22 public: |
25 typedef bool WebType; | 23 typedef bool WebType; |
26 static bool take(ScriptPromiseResolver* resolver, WebType* boolean) | 24 static bool take(ScriptPromiseResolver* resolver, WebType* boolean) |
27 { | 25 { |
28 return *boolean; | 26 return *boolean; |
29 } | 27 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 String ServiceWorkerRegistration::scope() const | 95 String ServiceWorkerRegistration::scope() const |
98 { | 96 { |
99 return m_outerRegistration->scope().string(); | 97 return m_outerRegistration->scope().string(); |
100 } | 98 } |
101 | 99 |
102 ScriptPromise ServiceWorkerRegistration::unregister(ScriptState* scriptState) | 100 ScriptPromise ServiceWorkerRegistration::unregister(ScriptState* scriptState) |
103 { | 101 { |
104 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 102 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); |
105 ScriptPromise promise = resolver->promise(); | 103 ScriptPromise promise = resolver->promise(); |
106 | 104 |
107 if (!m_provider) { | |
108 resolver->reject(DOMException::create(InvalidStateError, "Failed to unre
gister a ServiceWorkerRegistration: No associated provider is available.")); | |
109 return promise; | |
110 } | |
111 | |
112 RefPtr<SecurityOrigin> documentOrigin = scriptState->executionContext()->sec
urityOrigin(); | 105 RefPtr<SecurityOrigin> documentOrigin = scriptState->executionContext()->sec
urityOrigin(); |
113 KURL scopeURL = scriptState->executionContext()->completeURL(scope()); | 106 KURL scopeURL = scriptState->executionContext()->completeURL(scope()); |
114 scopeURL.removeFragmentIdentifier(); | 107 scopeURL.removeFragmentIdentifier(); |
115 if (!scope().isEmpty() && !documentOrigin->canRequest(scopeURL)) { | 108 if (!scope().isEmpty() && !documentOrigin->canRequest(scopeURL)) { |
116 RefPtr<SecurityOrigin> scopeOrigin = SecurityOrigin::create(scopeURL); | 109 RefPtr<SecurityOrigin> scopeOrigin = SecurityOrigin::create(scopeURL); |
117 resolver->reject(DOMException::create(SecurityError, "Failed to unregist
er a ServiceWorkerRegistration: The origin of the registration's scope ('" + sco
peOrigin->toString() + "') does not match the current origin ('" + documentOrigi
n->toString() + "').")); | 110 resolver->reject(DOMException::create(SecurityError, "Failed to unregist
er a ServiceWorkerRegistration: The origin of the registration's scope ('" + sco
peOrigin->toString() + "') does not match the current origin ('" + documentOrigi
n->toString() + "').")); |
118 return promise; | 111 return promise; |
119 } | 112 } |
120 | 113 |
121 m_provider->unregisterServiceWorker(scopeURL, new CallbackPromiseAdapter<Boo
leanValue, ServiceWorkerError>(resolver)); | 114 m_outerRegistration->unregister(new CallbackPromiseAdapter<BooleanValue, Ser
viceWorkerError>(resolver)); |
122 return promise; | 115 return promise; |
123 } | 116 } |
124 | 117 |
125 ServiceWorkerRegistration* ServiceWorkerRegistration::getOrCreate(ExecutionConte
xt* executionContext, WebServiceWorkerRegistration* outerRegistration) | 118 ServiceWorkerRegistration* ServiceWorkerRegistration::getOrCreate(ExecutionConte
xt* executionContext, WebServiceWorkerRegistration* outerRegistration) |
126 { | 119 { |
127 if (!outerRegistration) | 120 if (!outerRegistration) |
128 return 0; | 121 return 0; |
129 | 122 |
130 ServiceWorkerRegistration* existingRegistration = static_cast<ServiceWorkerR
egistration*>(outerRegistration->proxy()); | 123 ServiceWorkerRegistration* existingRegistration = static_cast<ServiceWorkerR
egistration*>(outerRegistration->proxy()); |
131 if (existingRegistration) { | 124 if (existingRegistration) { |
132 ASSERT(existingRegistration->executionContext() == executionContext); | 125 ASSERT(existingRegistration->executionContext() == executionContext); |
133 return existingRegistration; | 126 return existingRegistration; |
134 } | 127 } |
135 | 128 |
136 ServiceWorkerRegistration* registration = new ServiceWorkerRegistration(exec
utionContext, adoptPtr(outerRegistration)); | 129 ServiceWorkerRegistration* registration = new ServiceWorkerRegistration(exec
utionContext, adoptPtr(outerRegistration)); |
137 registration->suspendIfNeeded(); | 130 registration->suspendIfNeeded(); |
138 return registration; | 131 return registration; |
139 } | 132 } |
140 | 133 |
141 ServiceWorkerRegistration::ServiceWorkerRegistration(ExecutionContext* execution
Context, PassOwnPtr<WebServiceWorkerRegistration> outerRegistration) | 134 ServiceWorkerRegistration::ServiceWorkerRegistration(ExecutionContext* execution
Context, PassOwnPtr<WebServiceWorkerRegistration> outerRegistration) |
142 : ActiveDOMObject(executionContext) | 135 : ActiveDOMObject(executionContext) |
143 , m_outerRegistration(outerRegistration) | 136 , m_outerRegistration(outerRegistration) |
144 , m_provider(0) | |
145 , m_stopped(false) | 137 , m_stopped(false) |
146 { | 138 { |
147 ASSERT(m_outerRegistration); | 139 ASSERT(m_outerRegistration); |
148 ThreadState::current()->registerPreFinalizer(*this); | 140 ThreadState::current()->registerPreFinalizer(*this); |
149 | 141 |
150 if (!executionContext) | 142 if (!executionContext) |
151 return; | 143 return; |
152 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) | |
153 m_provider = client->provider(); | |
154 m_outerRegistration->setProxy(this); | 144 m_outerRegistration->setProxy(this); |
155 } | 145 } |
156 | 146 |
157 ServiceWorkerRegistration::~ServiceWorkerRegistration() | 147 ServiceWorkerRegistration::~ServiceWorkerRegistration() |
158 { | 148 { |
159 ASSERT(!m_outerRegistration); | 149 ASSERT(!m_outerRegistration); |
160 } | 150 } |
161 | 151 |
162 void ServiceWorkerRegistration::dispose() | 152 void ServiceWorkerRegistration::dispose() |
163 { | 153 { |
(...skipping 18 matching lines...) Expand all Loading... |
182 | 172 |
183 void ServiceWorkerRegistration::stop() | 173 void ServiceWorkerRegistration::stop() |
184 { | 174 { |
185 if (m_stopped) | 175 if (m_stopped) |
186 return; | 176 return; |
187 m_stopped = true; | 177 m_stopped = true; |
188 m_outerRegistration->proxyStopped(); | 178 m_outerRegistration->proxyStopped(); |
189 } | 179 } |
190 | 180 |
191 } // namespace blink | 181 } // namespace blink |
OLD | NEW |