| 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 "FetchManager.h" | 6 #include "FetchManager.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" |
| 11 #include "bindings/core/v8/V8ThrowException.h" | 11 #include "bindings/core/v8/V8ThrowException.h" |
| 12 #include "core/dom/ExceptionCode.h" | 12 #include "core/dom/ExceptionCode.h" |
| 13 #include "core/fetch/FetchUtils.h" | 13 #include "core/fetch/FetchUtils.h" |
| 14 #include "core/fileapi/Blob.h" | 14 #include "core/fileapi/Blob.h" |
| 15 #include "core/frame/csp/ContentSecurityPolicy.h" | 15 #include "core/frame/csp/ContentSecurityPolicy.h" |
| 16 #include "core/loader/ThreadableLoader.h" | 16 #include "core/loader/ThreadableLoader.h" |
| 17 #include "core/loader/ThreadableLoaderClient.h" | 17 #include "core/loader/ThreadableLoaderClient.h" |
| 18 #include "modules/serviceworkers/FetchRequestData.h" | 18 #include "modules/serviceworkers/FetchRequestData.h" |
| 19 #include "modules/serviceworkers/Response.h" | 19 #include "modules/serviceworkers/Response.h" |
| 20 #include "modules/serviceworkers/ResponseInit.h" | 20 #include "modules/serviceworkers/ResponseInit.h" |
| 21 #include "platform/network/ResourceRequest.h" | 21 #include "platform/network/ResourceRequest.h" |
| 22 #include "platform/weborigin/SecurityOrigin.h" | 22 #include "platform/weborigin/SecurityOrigin.h" |
| 23 #include "public/platform/WebURLRequest.h" | 23 #include "public/platform/WebURLRequest.h" |
| 24 #include "wtf/HashSet.h" | 24 #include "wtf/HashSet.h" |
| 25 | 25 |
| 26 namespace blink { | 26 namespace blink { |
| 27 | 27 |
| 28 class FetchManager::Loader : public ThreadableLoaderClient { | 28 class FetchManager::Loader : public ThreadableLoaderClient { |
| 29 public: | 29 public: |
| 30 Loader(ExecutionContext*, FetchManager*, PassRefPtr<ScriptPromiseResolver>,
const FetchRequestData*); | 30 Loader(ExecutionContext*, FetchManager*, PassRefPtrWillBeRawPtr<ScriptPromis
eResolver>, const FetchRequestData*); |
| 31 ~Loader(); | 31 ~Loader(); |
| 32 virtual void didReceiveResponse(unsigned long, const ResourceResponse&, Pass
OwnPtr<WebDataConsumerHandle>); | 32 virtual void didReceiveResponse(unsigned long, const ResourceResponse&, Pass
OwnPtr<WebDataConsumerHandle>); |
| 33 virtual void didFinishLoading(unsigned long, double); | 33 virtual void didFinishLoading(unsigned long, double); |
| 34 virtual void didFail(const ResourceError&); | 34 virtual void didFail(const ResourceError&); |
| 35 virtual void didFailAccessControlCheck(const ResourceError&); | 35 virtual void didFailAccessControlCheck(const ResourceError&); |
| 36 virtual void didFailRedirectCheck(); | 36 virtual void didFailRedirectCheck(); |
| 37 virtual void didDownloadData(int); | 37 virtual void didDownloadData(int); |
| 38 | 38 |
| 39 void start(); | 39 void start(); |
| 40 void cleanup(); | 40 void cleanup(); |
| 41 | 41 |
| 42 private: | 42 private: |
| 43 void performBasicFetch(); | 43 void performBasicFetch(); |
| 44 void performNetworkError(const String& message); | 44 void performNetworkError(const String& message); |
| 45 void performHTTPFetch(); | 45 void performHTTPFetch(); |
| 46 void failed(const String& message); | 46 void failed(const String& message); |
| 47 void notifyFinished(); | 47 void notifyFinished(); |
| 48 | 48 |
| 49 ExecutionContext* m_executionContext; | 49 ExecutionContext* m_executionContext; |
| 50 FetchManager* m_fetchManager; | 50 FetchManager* m_fetchManager; |
| 51 RefPtr<ScriptPromiseResolver> m_resolver; | 51 RefPtrWillBeCrossThreadPersistent<ScriptPromiseResolver> m_resolver; |
| 52 Persistent<FetchRequestData> m_request; | 52 Persistent<FetchRequestData> m_request; |
| 53 RefPtr<ThreadableLoader> m_loader; | 53 RefPtr<ThreadableLoader> m_loader; |
| 54 ResourceResponse m_response; | 54 ResourceResponse m_response; |
| 55 long long m_downloadedBlobLength; | 55 long long m_downloadedBlobLength; |
| 56 bool m_corsFlag; | 56 bool m_corsFlag; |
| 57 bool m_corsPreflightFlag; | 57 bool m_corsPreflightFlag; |
| 58 bool m_failed; | 58 bool m_failed; |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 FetchManager::Loader::Loader(ExecutionContext* executionContext, FetchManager* f
etchManager, PassRefPtr<ScriptPromiseResolver> resolver, const FetchRequestData*
request) | 61 FetchManager::Loader::Loader(ExecutionContext* executionContext, FetchManager* f
etchManager, PassRefPtrWillBeRawPtr<ScriptPromiseResolver> resolver, const Fetch
RequestData* request) |
| 62 : m_executionContext(executionContext) | 62 : m_executionContext(executionContext) |
| 63 , m_fetchManager(fetchManager) | 63 , m_fetchManager(fetchManager) |
| 64 , m_resolver(resolver) | 64 , m_resolver(resolver) |
| 65 , m_request(request->createCopy()) | 65 , m_request(request->createCopy()) |
| 66 , m_downloadedBlobLength(0) | 66 , m_downloadedBlobLength(0) |
| 67 , m_corsFlag(false) | 67 , m_corsFlag(false) |
| 68 , m_corsPreflightFlag(false) | 68 , m_corsPreflightFlag(false) |
| 69 , m_failed(false) | 69 , m_failed(false) |
| 70 { | 70 { |
| 71 } | 71 } |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 | 354 |
| 355 FetchManager::~FetchManager() | 355 FetchManager::~FetchManager() |
| 356 { | 356 { |
| 357 for (HashSet<OwnPtr<Loader> >::iterator it = m_loaders.begin(); it != m_load
ers.end(); ++it) { | 357 for (HashSet<OwnPtr<Loader> >::iterator it = m_loaders.begin(); it != m_load
ers.end(); ++it) { |
| 358 (*it)->cleanup(); | 358 (*it)->cleanup(); |
| 359 } | 359 } |
| 360 } | 360 } |
| 361 | 361 |
| 362 ScriptPromise FetchManager::fetch(ScriptState* scriptState, const FetchRequestDa
ta* request) | 362 ScriptPromise FetchManager::fetch(ScriptState* scriptState, const FetchRequestDa
ta* request) |
| 363 { | 363 { |
| 364 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); | 364 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); |
| 365 ScriptPromise promise = resolver->promise(); | 365 ScriptPromise promise = resolver->promise(); |
| 366 | 366 |
| 367 OwnPtr<Loader> ownLoader(adoptPtr(new Loader(m_executionContext, this, resol
ver.release(), request))); | 367 OwnPtr<Loader> ownLoader(adoptPtr(new Loader(m_executionContext, this, resol
ver.release(), request))); |
| 368 Loader* loader = m_loaders.add(ownLoader.release()).storedValue->get(); | 368 Loader* loader = m_loaders.add(ownLoader.release()).storedValue->get(); |
| 369 loader->start(); | 369 loader->start(); |
| 370 return promise; | 370 return promise; |
| 371 } | 371 } |
| 372 | 372 |
| 373 void FetchManager::onLoaderFinished(Loader* loader) | 373 void FetchManager::onLoaderFinished(Loader* loader) |
| 374 { | 374 { |
| 375 m_loaders.remove(loader); | 375 m_loaders.remove(loader); |
| 376 } | 376 } |
| 377 | 377 |
| 378 } // namespace blink | 378 } // namespace blink |
| OLD | NEW |