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 "modules/serviceworkers/Cache.h" | 6 #include "modules/serviceworkers/Cache.h" |
7 | 7 |
8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
10 #include "bindings/core/v8/ScriptState.h" | 10 #include "bindings/core/v8/ScriptState.h" |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea
te(NotSupportedError, "Cache is not implemented")); | 154 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea
te(NotSupportedError, "Cache is not implemented")); |
155 } | 155 } |
156 | 156 |
157 } // namespace | 157 } // namespace |
158 | 158 |
159 Cache* Cache::create(WebServiceWorkerCache* webCache) | 159 Cache* Cache::create(WebServiceWorkerCache* webCache) |
160 { | 160 { |
161 return new Cache(webCache); | 161 return new Cache(webCache); |
162 } | 162 } |
163 | 163 |
164 ScriptPromise Cache::match(ScriptState* scriptState, Request* request, const Cac
heQueryOptions& options) | 164 ScriptPromise Cache::match(ScriptState* scriptState, const RequestInfo& request,
const CacheQueryOptions& options, ExceptionState& exceptionState) |
165 { | 165 { |
166 return matchImpl(scriptState, request, options); | 166 ASSERT(!request.isNull()); |
| 167 if (request.isRequest()) |
| 168 return matchImpl(scriptState, request.getAsRequest(), options); |
| 169 Request* newRequest = Request::create(scriptState->executionContext(), reque
st.getAsUSVString(), exceptionState); |
| 170 if (exceptionState.hadException()) |
| 171 return ScriptPromise(); |
| 172 return matchImpl(scriptState, newRequest, options); |
167 } | 173 } |
168 | 174 |
169 ScriptPromise Cache::match(ScriptState* scriptState, const String& requestString
, const CacheQueryOptions& options, ExceptionState& exceptionState) | 175 ScriptPromise Cache::matchAll(ScriptState* scriptState, const RequestInfo& reque
st, const CacheQueryOptions& options, ExceptionState& exceptionState) |
170 { | 176 { |
171 Request* request = Request::create(scriptState->executionContext(), requestS
tring, exceptionState); | 177 ASSERT(!request.isNull()); |
| 178 if (request.isRequest()) |
| 179 return matchAllImpl(scriptState, request.getAsRequest(), options); |
| 180 Request* newRequest = Request::create(scriptState->executionContext(), reque
st.getAsUSVString(), exceptionState); |
172 if (exceptionState.hadException()) | 181 if (exceptionState.hadException()) |
173 return ScriptPromise(); | 182 return ScriptPromise(); |
174 return matchImpl(scriptState, request, options); | 183 return matchAllImpl(scriptState, newRequest, options); |
175 } | 184 } |
176 | 185 |
177 ScriptPromise Cache::matchAll(ScriptState* scriptState, Request* request, const
CacheQueryOptions& options) | 186 ScriptPromise Cache::add(ScriptState* scriptState, const RequestInfo& request, E
xceptionState& exceptionState) |
178 { | 187 { |
179 return matchAllImpl(scriptState, request, options); | 188 ASSERT(!request.isNull()); |
180 } | 189 if (request.isRequest()) |
181 | 190 return addImpl(scriptState, request.getAsRequest()); |
182 ScriptPromise Cache::matchAll(ScriptState* scriptState, const String& requestStr
ing, const CacheQueryOptions& options, ExceptionState& exceptionState) | 191 Request* newRequest = Request::create(scriptState->executionContext(), reque
st.getAsUSVString(), exceptionState); |
183 { | |
184 Request* request = Request::create(scriptState->executionContext(), requestS
tring, exceptionState); | |
185 if (exceptionState.hadException()) | 192 if (exceptionState.hadException()) |
186 return ScriptPromise(); | 193 return ScriptPromise(); |
187 return matchAllImpl(scriptState, request, options); | 194 return addImpl(scriptState, newRequest); |
188 } | |
189 | |
190 ScriptPromise Cache::add(ScriptState* scriptState, Request* request) | |
191 { | |
192 return addImpl(scriptState, request); | |
193 } | |
194 | |
195 ScriptPromise Cache::add(ScriptState* scriptState, const String& requestString,
ExceptionState& exceptionState) | |
196 { | |
197 Request* request = Request::create(scriptState->executionContext(), requestS
tring, exceptionState); | |
198 if (exceptionState.hadException()) | |
199 return ScriptPromise(); | |
200 return addImpl(scriptState, request); | |
201 } | 195 } |
202 | 196 |
203 ScriptPromise Cache::addAll(ScriptState* scriptState, const Vector<ScriptValue>&
rawRequests) | 197 ScriptPromise Cache::addAll(ScriptState* scriptState, const Vector<ScriptValue>&
rawRequests) |
204 { | 198 { |
205 // FIXME: Implement this. | 199 // FIXME: Implement this. |
206 return rejectAsNotImplemented(scriptState); | 200 return rejectAsNotImplemented(scriptState); |
207 } | 201 } |
208 | 202 |
209 ScriptPromise Cache::deleteFunction(ScriptState* scriptState, Request* request,
const CacheQueryOptions& options) | 203 ScriptPromise Cache::deleteFunction(ScriptState* scriptState, const RequestInfo&
request, const CacheQueryOptions& options, ExceptionState& exceptionState) |
210 { | 204 { |
211 return deleteImpl(scriptState, request, options); | 205 ASSERT(!request.isNull()); |
| 206 if (request.isRequest()) |
| 207 return deleteImpl(scriptState, request.getAsRequest(), options); |
| 208 Request* newRequest = Request::create(scriptState->executionContext(), reque
st.getAsUSVString(), exceptionState); |
| 209 if (exceptionState.hadException()) |
| 210 return ScriptPromise(); |
| 211 return deleteImpl(scriptState, newRequest, options); |
212 } | 212 } |
213 | 213 |
214 ScriptPromise Cache::deleteFunction(ScriptState* scriptState, const String& requ
estString, const CacheQueryOptions& options, ExceptionState& exceptionState) | 214 ScriptPromise Cache::put(ScriptState* scriptState, const RequestInfo& request, R
esponse* response, ExceptionState& exceptionState) |
215 { | 215 { |
216 Request* request = Request::create(scriptState->executionContext(), requestS
tring, exceptionState); | 216 ASSERT(!request.isNull()); |
| 217 if (request.isRequest()) |
| 218 return putImpl(scriptState, request.getAsRequest(), response); |
| 219 Request* newRequest = Request::create(scriptState->executionContext(), reque
st.getAsUSVString(), exceptionState); |
217 if (exceptionState.hadException()) | 220 if (exceptionState.hadException()) |
218 return ScriptPromise(); | 221 return ScriptPromise(); |
219 return deleteImpl(scriptState, request, options); | 222 return putImpl(scriptState, newRequest, response); |
220 } | 223 } |
221 | 224 |
222 ScriptPromise Cache::put(ScriptState* scriptState, Request* request, Response* r
esponse) | 225 ScriptPromise Cache::keys(ScriptState* scriptState, ExceptionState&) |
223 { | |
224 return putImpl(scriptState, request, response); | |
225 } | |
226 | |
227 ScriptPromise Cache::put(ScriptState* scriptState, const String& requestString,
Response* response, ExceptionState& exceptionState) | |
228 { | |
229 Request* request = Request::create(scriptState->executionContext(), requestS
tring, exceptionState); | |
230 if (exceptionState.hadException()) | |
231 return ScriptPromise(); | |
232 return putImpl(scriptState, request, response); | |
233 } | |
234 | |
235 ScriptPromise Cache::keys(ScriptState* scriptState) | |
236 { | 226 { |
237 return keysImpl(scriptState); | 227 return keysImpl(scriptState); |
238 } | 228 } |
239 | 229 |
240 ScriptPromise Cache::keys(ScriptState* scriptState, Request* request, const Cach
eQueryOptions& options) | 230 ScriptPromise Cache::keys(ScriptState* scriptState, const RequestInfo& request,
const CacheQueryOptions& options, ExceptionState& exceptionState) |
241 { | 231 { |
242 return keysImpl(scriptState, request, options); | 232 ASSERT(!request.isNull()); |
243 } | 233 if (request.isRequest()) |
244 | 234 return keysImpl(scriptState, request.getAsRequest(), options); |
245 ScriptPromise Cache::keys(ScriptState* scriptState, const String& requestString,
const CacheQueryOptions& options, ExceptionState& exceptionState) | 235 Request* newRequest = Request::create(scriptState->executionContext(), reque
st.getAsUSVString(), exceptionState); |
246 { | |
247 Request* request = Request::create(scriptState->executionContext(), requestS
tring, exceptionState); | |
248 if (exceptionState.hadException()) | 236 if (exceptionState.hadException()) |
249 return ScriptPromise(); | 237 return ScriptPromise(); |
250 return keysImpl(scriptState, request, options); | 238 return keysImpl(scriptState, newRequest, options); |
251 } | 239 } |
252 | 240 |
253 Cache::Cache(WebServiceWorkerCache* webCache) | 241 Cache::Cache(WebServiceWorkerCache* webCache) |
254 : m_webCache(adoptPtr(webCache)) { } | 242 : m_webCache(adoptPtr(webCache)) { } |
255 | 243 |
256 ScriptPromise Cache::matchImpl(ScriptState* scriptState, const Request* request,
const CacheQueryOptions& options) | 244 ScriptPromise Cache::matchImpl(ScriptState* scriptState, const Request* request,
const CacheQueryOptions& options) |
257 { | 245 { |
258 WebServiceWorkerRequest webRequest; | 246 WebServiceWorkerRequest webRequest; |
259 request->populateWebServiceWorkerRequest(webRequest); | 247 request->populateWebServiceWorkerRequest(webRequest); |
260 | 248 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 WebServiceWorkerRequest webRequest; | 335 WebServiceWorkerRequest webRequest; |
348 request->populateWebServiceWorkerRequest(webRequest); | 336 request->populateWebServiceWorkerRequest(webRequest); |
349 | 337 |
350 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); | 338 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); |
351 const ScriptPromise promise = resolver->promise(); | 339 const ScriptPromise promise = resolver->promise(); |
352 m_webCache->dispatchKeys(new CacheWithRequestsCallbacks(resolver), 0, toWebQ
ueryParams(options)); | 340 m_webCache->dispatchKeys(new CacheWithRequestsCallbacks(resolver), 0, toWebQ
ueryParams(options)); |
353 return promise; | 341 return promise; |
354 } | 342 } |
355 | 343 |
356 } // namespace blink | 344 } // namespace blink |
OLD | NEW |