| 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/fetch/FetchManager.h" | 6 #include "modules/fetch/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" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "modules/fetch/ResponseInit.h" | 22 #include "modules/fetch/ResponseInit.h" |
| 23 #include "platform/network/ResourceRequest.h" | 23 #include "platform/network/ResourceRequest.h" |
| 24 #include "platform/weborigin/SecurityOrigin.h" | 24 #include "platform/weborigin/SecurityOrigin.h" |
| 25 #include "public/platform/WebURLRequest.h" | 25 #include "public/platform/WebURLRequest.h" |
| 26 #include "wtf/HashSet.h" | 26 #include "wtf/HashSet.h" |
| 27 | 27 |
| 28 namespace blink { | 28 namespace blink { |
| 29 | 29 |
| 30 class FetchManager::Loader : public ThreadableLoaderClient { | 30 class FetchManager::Loader : public ThreadableLoaderClient { |
| 31 public: | 31 public: |
| 32 Loader(ExecutionContext*, FetchManager*, PassRefPtr<ScriptPromiseResolver>,
const FetchRequestData*); | 32 Loader(ExecutionContext*, FetchManager*, PassRefPtrWillBeRawPtr<ScriptPromis
eResolver>, const FetchRequestData*); |
| 33 ~Loader() override; | 33 ~Loader() override; |
| 34 void didReceiveResponse(unsigned long, const ResourceResponse&, PassOwnPtr<W
ebDataConsumerHandle>) override; | 34 void didReceiveResponse(unsigned long, const ResourceResponse&, PassOwnPtr<W
ebDataConsumerHandle>) override; |
| 35 void didReceiveData(const char*, unsigned) override; | 35 void didReceiveData(const char*, unsigned) override; |
| 36 void didFinishLoading(unsigned long, double) override; | 36 void didFinishLoading(unsigned long, double) override; |
| 37 void didFail(const ResourceError&) override; | 37 void didFail(const ResourceError&) override; |
| 38 void didFailAccessControlCheck(const ResourceError&) override; | 38 void didFailAccessControlCheck(const ResourceError&) override; |
| 39 void didFailRedirectCheck() override; | 39 void didFailRedirectCheck() override; |
| 40 | 40 |
| 41 void start(); | 41 void start(); |
| 42 void cleanup(); | 42 void cleanup(); |
| 43 | 43 |
| 44 private: | 44 private: |
| 45 void performBasicFetch(); | 45 void performBasicFetch(); |
| 46 void performNetworkError(const String& message); | 46 void performNetworkError(const String& message); |
| 47 void performHTTPFetch(); | 47 void performHTTPFetch(); |
| 48 void failed(const String& message); | 48 void failed(const String& message); |
| 49 void notifyFinished(); | 49 void notifyFinished(); |
| 50 | 50 |
| 51 ExecutionContext* m_executionContext; | 51 ExecutionContext* m_executionContext; |
| 52 FetchManager* m_fetchManager; | 52 FetchManager* m_fetchManager; |
| 53 RefPtr<ScriptPromiseResolver> m_resolver; | 53 RefPtrWillBePersistent<ScriptPromiseResolver> m_resolver; |
| 54 Persistent<FetchRequestData> m_request; | 54 Persistent<FetchRequestData> m_request; |
| 55 Persistent<BodyStreamBuffer> m_responseBuffer; | 55 Persistent<BodyStreamBuffer> m_responseBuffer; |
| 56 RefPtr<ThreadableLoader> m_loader; | 56 RefPtr<ThreadableLoader> m_loader; |
| 57 bool m_corsFlag; | 57 bool m_corsFlag; |
| 58 bool m_corsPreflightFlag; | 58 bool m_corsPreflightFlag; |
| 59 bool m_failed; | 59 bool m_failed; |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 FetchManager::Loader::Loader(ExecutionContext* executionContext, FetchManager* f
etchManager, PassRefPtr<ScriptPromiseResolver> resolver, const FetchRequestData*
request) | 62 FetchManager::Loader::Loader(ExecutionContext* executionContext, FetchManager* f
etchManager, PassRefPtrWillBeRawPtr<ScriptPromiseResolver> resolver, const Fetch
RequestData* request) |
| 63 : m_executionContext(executionContext) | 63 : m_executionContext(executionContext) |
| 64 , m_fetchManager(fetchManager) | 64 , m_fetchManager(fetchManager) |
| 65 , m_resolver(resolver) | 65 , m_resolver(resolver) |
| 66 , m_request(request->createCopy()) | 66 , m_request(request->createCopy()) |
| 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 } |
| 72 | 72 |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 } | 352 } |
| 353 | 353 |
| 354 FetchManager::~FetchManager() | 354 FetchManager::~FetchManager() |
| 355 { | 355 { |
| 356 if (!m_isStopped) | 356 if (!m_isStopped) |
| 357 stop(); | 357 stop(); |
| 358 } | 358 } |
| 359 | 359 |
| 360 ScriptPromise FetchManager::fetch(ScriptState* scriptState, const FetchRequestDa
ta* request) | 360 ScriptPromise FetchManager::fetch(ScriptState* scriptState, const FetchRequestDa
ta* request) |
| 361 { | 361 { |
| 362 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); | 362 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); |
| 363 ScriptPromise promise = resolver->promise(); | 363 ScriptPromise promise = resolver->promise(); |
| 364 | 364 |
| 365 OwnPtr<Loader> ownLoader(adoptPtr(new Loader(m_executionContext, this, resol
ver.release(), request))); | 365 OwnPtr<Loader> ownLoader(adoptPtr(new Loader(m_executionContext, this, resol
ver.release(), request))); |
| 366 Loader* loader = m_loaders.add(ownLoader.release()).storedValue->get(); | 366 Loader* loader = m_loaders.add(ownLoader.release()).storedValue->get(); |
| 367 loader->start(); | 367 loader->start(); |
| 368 return promise; | 368 return promise; |
| 369 } | 369 } |
| 370 | 370 |
| 371 void FetchManager::stop() | 371 void FetchManager::stop() |
| 372 { | 372 { |
| 373 ASSERT(!m_isStopped); | 373 ASSERT(!m_isStopped); |
| 374 m_isStopped = true; | 374 m_isStopped = true; |
| 375 for (auto& loader : m_loaders) { | 375 for (auto& loader : m_loaders) { |
| 376 loader->cleanup(); | 376 loader->cleanup(); |
| 377 } | 377 } |
| 378 } | 378 } |
| 379 | 379 |
| 380 void FetchManager::onLoaderFinished(Loader* loader) | 380 void FetchManager::onLoaderFinished(Loader* loader) |
| 381 { | 381 { |
| 382 // We don't use remove here, becuase it may cause recursive deletion. | 382 // We don't use remove here, becuase it may cause recursive deletion. |
| 383 OwnPtr<Loader> p = m_loaders.take(loader); | 383 OwnPtr<Loader> p = m_loaders.take(loader); |
| 384 } | 384 } |
| 385 | 385 |
| 386 } // namespace blink | 386 } // namespace blink |
| OLD | NEW |