| 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 21 matching lines...) Expand all Loading... |
| 32 #include "platform/network/ResourceResponse.h" | 32 #include "platform/network/ResourceResponse.h" |
| 33 #include "platform/weborigin/SecurityOrigin.h" | 33 #include "platform/weborigin/SecurityOrigin.h" |
| 34 #include "public/platform/WebURLRequest.h" | 34 #include "public/platform/WebURLRequest.h" |
| 35 #include "wtf/HashSet.h" | 35 #include "wtf/HashSet.h" |
| 36 | 36 |
| 37 namespace blink { | 37 namespace blink { |
| 38 | 38 |
| 39 class FetchManager::Loader final : public NoBaseWillBeGarbageCollectedFinalized<
FetchManager::Loader>, public ThreadableLoaderClient, public ContextLifecycleObs
erver { | 39 class FetchManager::Loader final : public NoBaseWillBeGarbageCollectedFinalized<
FetchManager::Loader>, public ThreadableLoaderClient, public ContextLifecycleObs
erver { |
| 40 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(FetchManager::Loader); | 40 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(FetchManager::Loader); |
| 41 public: | 41 public: |
| 42 static PassOwnPtrWillBeRawPtr<Loader> create(ExecutionContext* executionCont
ext, FetchManager* fetchManager, PassRefPtrWillBeRawPtr<ScriptPromiseResolver> r
esolver, FetchRequestData* request) | 42 static PassOwnPtrWillBeRawPtr<Loader> create(ExecutionContext* executionCont
ext, FetchManager* fetchManager, ScriptPromiseResolver* resolver, FetchRequestDa
ta* request) |
| 43 { | 43 { |
| 44 return adoptPtrWillBeNoop(new Loader(executionContext, fetchManager, res
olver, request)); | 44 return adoptPtrWillBeNoop(new Loader(executionContext, fetchManager, res
olver, request)); |
| 45 } | 45 } |
| 46 | 46 |
| 47 ~Loader() override; | 47 ~Loader() override; |
| 48 DECLARE_VIRTUAL_TRACE(); | 48 DECLARE_VIRTUAL_TRACE(); |
| 49 | 49 |
| 50 void didReceiveResponse(unsigned long, const ResourceResponse&, PassOwnPtr<W
ebDataConsumerHandle>) override; | 50 void didReceiveResponse(unsigned long, const ResourceResponse&, PassOwnPtr<W
ebDataConsumerHandle>) override; |
| 51 void didFinishLoading(unsigned long, double) override; | 51 void didFinishLoading(unsigned long, double) override; |
| 52 void didFail(const ResourceError&) override; | 52 void didFail(const ResourceError&) override; |
| 53 void didFailAccessControlCheck(const ResourceError&) override; | 53 void didFailAccessControlCheck(const ResourceError&) override; |
| 54 void didFailRedirectCheck() override; | 54 void didFailRedirectCheck() override; |
| 55 | 55 |
| 56 void start(); | 56 void start(); |
| 57 void dispose(); | 57 void dispose(); |
| 58 | 58 |
| 59 private: | 59 private: |
| 60 Loader(ExecutionContext*, FetchManager*, PassRefPtrWillBeRawPtr<ScriptPromis
eResolver>, FetchRequestData*); | 60 Loader(ExecutionContext*, FetchManager*, ScriptPromiseResolver*, FetchReques
tData*); |
| 61 | 61 |
| 62 void performBasicFetch(); | 62 void performBasicFetch(); |
| 63 void performNetworkError(const String& message); | 63 void performNetworkError(const String& message); |
| 64 void performHTTPFetch(bool corsFlag, bool corsPreflightFlag); | 64 void performHTTPFetch(bool corsFlag, bool corsPreflightFlag); |
| 65 void failed(const String& message); | 65 void failed(const String& message); |
| 66 void notifyFinished(); | 66 void notifyFinished(); |
| 67 Document* document() const; | 67 Document* document() const; |
| 68 | 68 |
| 69 RawPtrWillBeMember<FetchManager> m_fetchManager; | 69 RawPtrWillBeMember<FetchManager> m_fetchManager; |
| 70 RefPtrWillBeMember<ScriptPromiseResolver> m_resolver; | 70 PersistentWillBeMember<ScriptPromiseResolver> m_resolver; |
| 71 PersistentWillBeMember<FetchRequestData> m_request; | 71 PersistentWillBeMember<FetchRequestData> m_request; |
| 72 RefPtr<ThreadableLoader> m_loader; | 72 RefPtr<ThreadableLoader> m_loader; |
| 73 bool m_failed; | 73 bool m_failed; |
| 74 bool m_finished; | 74 bool m_finished; |
| 75 int m_responseHttpStatusCode; | 75 int m_responseHttpStatusCode; |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 FetchManager::Loader::Loader(ExecutionContext* executionContext, FetchManager* f
etchManager, PassRefPtrWillBeRawPtr<ScriptPromiseResolver> resolver, FetchReques
tData* request) | 78 FetchManager::Loader::Loader(ExecutionContext* executionContext, FetchManager* f
etchManager, ScriptPromiseResolver* resolver, FetchRequestData* request) |
| 79 : ContextLifecycleObserver(executionContext) | 79 : ContextLifecycleObserver(executionContext) |
| 80 , m_fetchManager(fetchManager) | 80 , m_fetchManager(fetchManager) |
| 81 , m_resolver(resolver) | 81 , m_resolver(resolver) |
| 82 , m_request(request) | 82 , m_request(request) |
| 83 , m_failed(false) | 83 , m_failed(false) |
| 84 , m_finished(false) | 84 , m_finished(false) |
| 85 , m_responseHttpStatusCode(0) | 85 , m_responseHttpStatusCode(0) |
| 86 { | 86 { |
| 87 } | 87 } |
| 88 | 88 |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 FetchManager::~FetchManager() | 418 FetchManager::~FetchManager() |
| 419 { | 419 { |
| 420 #if !ENABLE(OILPAN) | 420 #if !ENABLE(OILPAN) |
| 421 if (!m_isStopped) | 421 if (!m_isStopped) |
| 422 stop(); | 422 stop(); |
| 423 #endif | 423 #endif |
| 424 } | 424 } |
| 425 | 425 |
| 426 ScriptPromise FetchManager::fetch(ScriptState* scriptState, FetchRequestData* re
quest) | 426 ScriptPromise FetchManager::fetch(ScriptState* scriptState, FetchRequestData* re
quest) |
| 427 { | 427 { |
| 428 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 428 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 429 ScriptPromise promise = resolver->promise(); | 429 ScriptPromise promise = resolver->promise(); |
| 430 | 430 |
| 431 request->setContext(WebURLRequest::RequestContextFetch); | 431 request->setContext(WebURLRequest::RequestContextFetch); |
| 432 | 432 |
| 433 OwnPtrWillBeRawPtr<Loader> ownLoader = Loader::create(m_executionContext, th
is, resolver.release(), request); | 433 OwnPtrWillBeRawPtr<Loader> ownLoader = Loader::create(m_executionContext, th
is, resolver, request); |
| 434 Loader* loader = m_loaders.add(ownLoader.release()).storedValue->get(); | 434 Loader* loader = m_loaders.add(ownLoader.release()).storedValue->get(); |
| 435 loader->start(); | 435 loader->start(); |
| 436 return promise; | 436 return promise; |
| 437 } | 437 } |
| 438 | 438 |
| 439 void FetchManager::stop() | 439 void FetchManager::stop() |
| 440 { | 440 { |
| 441 ASSERT(!m_isStopped); | 441 ASSERT(!m_isStopped); |
| 442 m_isStopped = true; | 442 m_isStopped = true; |
| 443 for (auto& loader : m_loaders) | 443 for (auto& loader : m_loaders) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 454 | 454 |
| 455 DEFINE_TRACE(FetchManager) | 455 DEFINE_TRACE(FetchManager) |
| 456 { | 456 { |
| 457 #if ENABLE(OILPAN) | 457 #if ENABLE(OILPAN) |
| 458 visitor->trace(m_executionContext); | 458 visitor->trace(m_executionContext); |
| 459 visitor->trace(m_loaders); | 459 visitor->trace(m_loaders); |
| 460 #endif | 460 #endif |
| 461 } | 461 } |
| 462 | 462 |
| 463 } // namespace blink | 463 } // namespace blink |
| OLD | NEW |