OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef WorkerFetchContext_h |
| 6 #define WorkerFetchContext_h |
| 7 |
| 8 #include <memory> |
| 9 #include "core/CoreExport.h" |
| 10 #include "platform/Supplementable.h" |
| 11 #include "platform/loader/fetch/FetchContext.h" |
| 12 #include "platform/wtf/Forward.h" |
| 13 |
| 14 namespace blink { |
| 15 |
| 16 class ResourceFetcher; |
| 17 class WebTaskRunner; |
| 18 class WebURLLoader; |
| 19 class WebWorkerFetchContext; |
| 20 class WorkerClients; |
| 21 class WorkerGlobalScope; |
| 22 |
| 23 CORE_EXPORT void ProvideWorkerFetchContextToWorker( |
| 24 WorkerClients*, |
| 25 std::unique_ptr<WebWorkerFetchContext>); |
| 26 |
| 27 // The WorkerFetchContext is a FetchContext for workers (dedicated, shared and |
| 28 // service workers). This class is used only when off-main-thread-fetch is |
| 29 // enabled, and is still under development. |
| 30 // TODO(horo): Implement all methods of FetchContext. crbug.com/443374 |
| 31 class WorkerFetchContext final : public FetchContext { |
| 32 public: |
| 33 static WorkerFetchContext* Create(WorkerGlobalScope&); |
| 34 virtual ~WorkerFetchContext(); |
| 35 |
| 36 ResourceFetcher* GetResourceFetcher(); |
| 37 |
| 38 // FetchContext implementation: |
| 39 WebURLLoader* CreateURLLoader() override; |
| 40 void PrepareRequest(ResourceRequest&, RedirectType) override; |
| 41 bool IsControlledByServiceWorker() const override; |
| 42 int64_t ServiceWorkerID() const override; |
| 43 ResourceRequestBlockedReason CanRequest( |
| 44 Resource::Type, |
| 45 const ResourceRequest&, |
| 46 const KURL&, |
| 47 const ResourceLoaderOptions&, |
| 48 SecurityViolationReportingPolicy, |
| 49 FetchParameters::OriginRestriction) const override; |
| 50 void AddAdditionalRequestHeaders(ResourceRequest&, |
| 51 FetchResourceType) override; |
| 52 void DispatchWillSendRequest(unsigned long, |
| 53 ResourceRequest&, |
| 54 const ResourceResponse&, |
| 55 const FetchInitiatorInfo&) override; |
| 56 void DispatchDidReceiveResponse(unsigned long identifier, |
| 57 const ResourceResponse&, |
| 58 WebURLRequest::FrameType, |
| 59 WebURLRequest::RequestContext, |
| 60 Resource*, |
| 61 ResourceResponseType) override; |
| 62 void DispatchDidReceiveData(unsigned long identifier, |
| 63 const char* data, |
| 64 int dataLength) override; |
| 65 void DispatchDidReceiveEncodedData(unsigned long identifier, |
| 66 int encodedDataLength) override; |
| 67 void DispatchDidFinishLoading(unsigned long identifier, |
| 68 double finishTime, |
| 69 int64_t encodedDataLength, |
| 70 int64_t decodedBodyLength) override; |
| 71 void DispatchDidFail(unsigned long identifier, |
| 72 const ResourceError&, |
| 73 int64_t encodedDataLength, |
| 74 bool isInternalRequest) override; |
| 75 ResourceRequestBlockedReason AllowResponse( |
| 76 Resource::Type, |
| 77 const ResourceRequest&, |
| 78 const KURL&, |
| 79 const ResourceLoaderOptions&) const override; |
| 80 void AddResourceTiming(const ResourceTimingInfo&) override; |
| 81 RefPtr<WebTaskRunner> LoadingTaskRunner() const override; |
| 82 RefPtr<WebTaskRunner> TimerTaskRunner() const override; |
| 83 Resource::ResourceCallback* GetResourceCallback() override; |
| 84 |
| 85 DECLARE_VIRTUAL_TRACE(); |
| 86 |
| 87 private: |
| 88 class WorkerResourceCallback; |
| 89 WorkerFetchContext(WorkerGlobalScope&, |
| 90 std::unique_ptr<WebWorkerFetchContext>); |
| 91 void InitializeOnWorkerThread(WorkerGlobalScope&); |
| 92 |
| 93 ResourceRequestBlockedReason CanRequestInternal( |
| 94 Resource::Type, |
| 95 const ResourceRequest&, |
| 96 const KURL&, |
| 97 const ResourceLoaderOptions&, |
| 98 SecurityViolationReportingPolicy, |
| 99 FetchParameters::OriginRestriction, |
| 100 ResourceRequest::RedirectStatus) const; |
| 101 |
| 102 Member<WorkerGlobalScope> worker_global_scope_; |
| 103 std::unique_ptr<WebWorkerFetchContext> web_context_; |
| 104 Member<ResourceFetcher> resource_fetcher_; |
| 105 RefPtr<WebTaskRunner> loading_task_runner_; |
| 106 RefPtr<WebTaskRunner> timer_task_runner_; |
| 107 Member<WorkerResourceCallback> resource_callback_; |
| 108 }; |
| 109 |
| 110 } // namespace blink |
| 111 |
| 112 #endif // WorkerFetchContext_h |
OLD | NEW |