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 "core/dom/ExecutionContext.h" |
| 11 #include "core/workers/WorkerClients.h" |
| 12 #include "core/workers/WorkerGlobalScope.h" |
| 13 #include "platform/Supplementable.h" |
| 14 #include "platform/loader/fetch/FetchContext.h" |
| 15 #include "wtf/Forward.h" |
| 16 |
| 17 namespace blink { |
| 18 |
| 19 class ExecutionContext; |
| 20 class ResourceFetcher; |
| 21 class WebTaskRunner; |
| 22 class WebURLLoader; |
| 23 class WebWorkerFetchContext; |
| 24 class WebWorkerFetchContextInfo; |
| 25 |
| 26 class CORE_EXPORT WorkerFetchContextInfo final |
| 27 : public GarbageCollectedFinalized<WorkerFetchContextInfo>, |
| 28 public Supplement<WorkerClients> { |
| 29 USING_GARBAGE_COLLECTED_MIXIN(WorkerFetchContextInfo); |
| 30 |
| 31 public: |
| 32 static WorkerFetchContextInfo* create( |
| 33 std::unique_ptr<WebWorkerFetchContextInfo>); |
| 34 static WorkerFetchContextInfo* from(WorkerClients&); |
| 35 static const char* supplementName(); |
| 36 virtual ~WorkerFetchContextInfo(); |
| 37 |
| 38 bool isDataSaverEnabled() const { return m_DataSaverEnabled; } |
| 39 void setDataSaverEnabled(bool enabled) { m_DataSaverEnabled = enabled; } |
| 40 bool isStrictMixedContentCheckingEnabled() const { |
| 41 return m_strictMixedContentCheckingEnabled; |
| 42 } |
| 43 void setStrictMixedContentCheckingEnabled(bool enabled) { |
| 44 m_strictMixedContentCheckingEnabled = enabled; |
| 45 } |
| 46 |
| 47 std::unique_ptr<WebWorkerFetchContext> CreateContext(); |
| 48 |
| 49 DEFINE_INLINE_VIRTUAL_TRACE() { Supplement<WorkerClients>::trace(visitor); } |
| 50 |
| 51 private: |
| 52 explicit WorkerFetchContextInfo(std::unique_ptr<WebWorkerFetchContextInfo>); |
| 53 |
| 54 std::unique_ptr<WebWorkerFetchContextInfo> m_info; |
| 55 bool m_DataSaverEnabled = false; |
| 56 bool m_strictMixedContentCheckingEnabled = false; |
| 57 }; |
| 58 |
| 59 CORE_EXPORT void provideWorkerFetchContextInfoToWorker( |
| 60 WorkerClients*, |
| 61 std::unique_ptr<WebWorkerFetchContextInfo>); |
| 62 |
| 63 class WorkerFetchContext final : public FetchContext { |
| 64 public: |
| 65 static WorkerFetchContext* create(WorkerGlobalScope&, |
| 66 WorkerFetchContextInfo*); |
| 67 static WorkerFetchContext* from(ExecutionContext&); |
| 68 |
| 69 virtual ~WorkerFetchContext(); |
| 70 |
| 71 DECLARE_TRACE(); |
| 72 bool isControlledByServiceWorker() const override; |
| 73 int64_t serviceWorkerID() const override; |
| 74 ResourceRequestBlockedReason canRequest( |
| 75 Resource::Type, |
| 76 const ResourceRequest&, |
| 77 const KURL&, |
| 78 const ResourceLoaderOptions&, |
| 79 SecurityViolationReportingPolicy, |
| 80 FetchRequest::OriginRestriction) const override; |
| 81 |
| 82 void addAdditionalRequestHeaders(ResourceRequest&, |
| 83 FetchResourceType) override; |
| 84 |
| 85 void prepareRequest(ResourceRequest&, RedirectType) override; |
| 86 void dispatchWillSendRequest(unsigned long, |
| 87 ResourceRequest&, |
| 88 const ResourceResponse&, |
| 89 const FetchInitiatorInfo&) override; |
| 90 void dispatchDidReceiveResponse(unsigned long identifier, |
| 91 const ResourceResponse&, |
| 92 WebURLRequest::FrameType, |
| 93 WebURLRequest::RequestContext, |
| 94 Resource*, |
| 95 ResourceResponseType) override; |
| 96 void dispatchDidReceiveData(unsigned long identifier, |
| 97 const char* data, |
| 98 int dataLength) override; |
| 99 void dispatchDidReceiveEncodedData(unsigned long identifier, |
| 100 int encodedDataLength) override; |
| 101 void dispatchDidFinishLoading(unsigned long identifier, |
| 102 double finishTime, |
| 103 int64_t encodedDataLength, |
| 104 int64_t decodedBodyLength) override; |
| 105 void dispatchDidFail(unsigned long identifier, |
| 106 const ResourceError&, |
| 107 int64_t encodedDataLength, |
| 108 bool isInternalRequest) override; |
| 109 |
| 110 ResourceRequestBlockedReason allowResponse( |
| 111 Resource::Type, |
| 112 const ResourceRequest&, |
| 113 const KURL&, |
| 114 const ResourceLoaderOptions&) const override; |
| 115 void addResourceTiming(const ResourceTimingInfo&) override; |
| 116 |
| 117 WebURLLoader* createURLLoader() override; |
| 118 RefPtr<WebTaskRunner> loadingTaskRunner() const override; |
| 119 RefPtr<WebTaskRunner> timerTaskRunner() const override; |
| 120 Resource::ResourceCallback* resourceCallback() override; |
| 121 ResourceFetcher* getResourceFetcher(); |
| 122 |
| 123 private: |
| 124 class WorkerResourceCallback; |
| 125 explicit WorkerFetchContext(WorkerGlobalScope&, |
| 126 std::unique_ptr<WebWorkerFetchContext>, |
| 127 bool dataSaverEnabled, |
| 128 bool strictMixedContentCheckingEnabled); |
| 129 void initializeOnWorkerThread(); |
| 130 |
| 131 ResourceRequestBlockedReason canRequestInternal( |
| 132 Resource::Type, |
| 133 const ResourceRequest&, |
| 134 const KURL&, |
| 135 const ResourceLoaderOptions&, |
| 136 SecurityViolationReportingPolicy, |
| 137 FetchRequest::OriginRestriction, |
| 138 ResourceRequest::RedirectStatus) const; |
| 139 |
| 140 Member<WorkerGlobalScope> m_workerGlobalScope; |
| 141 Member<ResourceFetcher> m_resourceFetcher; |
| 142 std::unique_ptr<WebWorkerFetchContext> m_context; |
| 143 RefPtr<WebTaskRunner> m_loadingTaskRunner; |
| 144 RefPtr<WebTaskRunner> m_timerTaskRunner; |
| 145 const bool m_dataSaverEnabled; |
| 146 const bool m_strictMixedContentCheckingEnabled; |
| 147 Member<WorkerResourceCallback> m_resourceCallback; |
| 148 }; |
| 149 |
| 150 } // namespace blink |
| 151 |
| 152 #endif // WorkerFetchContext_h |
OLD | NEW |