| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #ifndef FetchContext_h | |
| 32 #define FetchContext_h | |
| 33 | |
| 34 #include "core/CoreExport.h" | |
| 35 #include "core/fetch/CachePolicy.h" | |
| 36 #include "core/fetch/FetchInitiatorInfo.h" | |
| 37 #include "core/fetch/FetchRequest.h" | |
| 38 #include "core/fetch/Resource.h" | |
| 39 #include "platform/heap/Handle.h" | |
| 40 #include "platform/network/ResourceLoadPriority.h" | |
| 41 #include "platform/network/ResourceRequest.h" | |
| 42 #include "wtf/Forward.h" | |
| 43 #include "wtf/Noncopyable.h" | |
| 44 | |
| 45 namespace blink { | |
| 46 | |
| 47 class ClientHintsPreferences; | |
| 48 class KURL; | |
| 49 class MHTMLArchive; | |
| 50 class ResourceError; | |
| 51 class ResourceResponse; | |
| 52 class ResourceTimingInfo; | |
| 53 class WebTaskRunner; | |
| 54 enum class WebCachePolicy; | |
| 55 | |
| 56 enum FetchResourceType { FetchMainResource, FetchSubresource }; | |
| 57 | |
| 58 // The FetchContext is an interface for performing context specific processing | |
| 59 // in response to events in the ResourceFetcher. The ResourceFetcher or its job | |
| 60 // class, ResourceLoader, may call the methods on a FetchContext. | |
| 61 // | |
| 62 // Any processing that depends on core/ components outside core/fetch/ should | |
| 63 // be implemented on a subclass of this interface, and then exposed to the | |
| 64 // ResourceFetcher via this interface. | |
| 65 class CORE_EXPORT FetchContext | |
| 66 : public GarbageCollectedFinalized<FetchContext> { | |
| 67 WTF_MAKE_NONCOPYABLE(FetchContext); | |
| 68 | |
| 69 public: | |
| 70 enum LogMessageType { LogErrorMessage, LogWarningMessage }; | |
| 71 | |
| 72 static FetchContext& nullInstance(); | |
| 73 | |
| 74 virtual ~FetchContext() {} | |
| 75 DEFINE_INLINE_VIRTUAL_TRACE() {} | |
| 76 | |
| 77 virtual bool isLiveContext() { return false; } | |
| 78 | |
| 79 virtual void addAdditionalRequestHeaders(ResourceRequest&, FetchResourceType); | |
| 80 virtual CachePolicy getCachePolicy() const; | |
| 81 // Returns the cache policy for the resource. ResourceRequest is not passed as | |
| 82 // a const reference as a header needs to be added for doc.write blocking | |
| 83 // intervention. | |
| 84 virtual WebCachePolicy resourceRequestCachePolicy( | |
| 85 ResourceRequest&, | |
| 86 Resource::Type, | |
| 87 FetchRequest::DeferOption) const; | |
| 88 | |
| 89 virtual void dispatchDidChangeResourcePriority(unsigned long identifier, | |
| 90 ResourceLoadPriority, | |
| 91 int intraPriorityValue); | |
| 92 // The last callback before a request is actually sent to the browser process. | |
| 93 virtual void dispatchWillSendRequest( | |
| 94 unsigned long identifier, | |
| 95 ResourceRequest&, | |
| 96 const ResourceResponse& redirectResponse, | |
| 97 const FetchInitiatorInfo& = FetchInitiatorInfo()); | |
| 98 virtual void dispatchDidLoadResourceFromMemoryCache( | |
| 99 unsigned long identifier, | |
| 100 Resource*, | |
| 101 WebURLRequest::FrameType, | |
| 102 WebURLRequest::RequestContext); | |
| 103 virtual void dispatchDidReceiveResponse(unsigned long identifier, | |
| 104 const ResourceResponse&, | |
| 105 WebURLRequest::FrameType, | |
| 106 WebURLRequest::RequestContext, | |
| 107 Resource*); | |
| 108 virtual void dispatchDidReceiveData(unsigned long identifier, | |
| 109 const char* data, | |
| 110 int dataLength); | |
| 111 virtual void dispatchDidReceiveEncodedData(unsigned long identifier, | |
| 112 int encodedDataLength); | |
| 113 virtual void dispatchDidDownloadData(unsigned long identifier, | |
| 114 int dataLength, | |
| 115 int encodedDataLength); | |
| 116 virtual void dispatchDidFinishLoading(unsigned long identifier, | |
| 117 double finishTime, | |
| 118 int64_t encodedDataLength); | |
| 119 virtual void dispatchDidFail(unsigned long identifier, | |
| 120 const ResourceError&, | |
| 121 int64_t encodedDataLength, | |
| 122 bool isInternalRequest); | |
| 123 | |
| 124 virtual bool shouldLoadNewResource(Resource::Type) const { return false; } | |
| 125 // Called when a resource load is first requested, which may not be when the | |
| 126 // load actually begins. | |
| 127 // TODO(toyoshim): Consider to use enum. See https://crbug.com/675883. | |
| 128 virtual void willStartLoadingResource(unsigned long identifier, | |
| 129 ResourceRequest&, | |
| 130 Resource::Type, | |
| 131 const AtomicString& fetchInitiatorName, | |
| 132 bool forPreload); | |
| 133 virtual void didLoadResource(Resource*); | |
| 134 | |
| 135 virtual void addResourceTiming(const ResourceTimingInfo&); | |
| 136 virtual bool allowImage(bool, const KURL&) const { return false; } | |
| 137 // TODO(toyoshim): Consider to use enum. See https://crbug.com/675883. | |
| 138 virtual ResourceRequestBlockedReason canRequest( | |
| 139 Resource::Type, | |
| 140 const ResourceRequest&, | |
| 141 const KURL&, | |
| 142 const ResourceLoaderOptions&, | |
| 143 bool forPreload, | |
| 144 FetchRequest::OriginRestriction) const { | |
| 145 return ResourceRequestBlockedReason::Other; | |
| 146 } | |
| 147 virtual ResourceRequestBlockedReason allowResponse( | |
| 148 Resource::Type, | |
| 149 const ResourceRequest&, | |
| 150 const KURL&, | |
| 151 const ResourceLoaderOptions&) const { | |
| 152 return ResourceRequestBlockedReason::Other; | |
| 153 } | |
| 154 | |
| 155 virtual bool isControlledByServiceWorker() const { return false; } | |
| 156 virtual int64_t serviceWorkerID() const { return -1; } | |
| 157 | |
| 158 virtual bool isMainFrame() const { return true; } | |
| 159 virtual bool defersLoading() const { return false; } | |
| 160 virtual bool isLoadComplete() const { return false; } | |
| 161 virtual bool pageDismissalEventBeingDispatched() const { return false; } | |
| 162 virtual bool updateTimingInfoForIFrameNavigation(ResourceTimingInfo*) { | |
| 163 return false; | |
| 164 } | |
| 165 virtual void sendImagePing(const KURL&); | |
| 166 virtual void addConsoleMessage(const String&, | |
| 167 LogMessageType = LogErrorMessage) const; | |
| 168 virtual SecurityOrigin* getSecurityOrigin() const { return nullptr; } | |
| 169 | |
| 170 // Populates the ResourceRequest using the given values and information | |
| 171 // stored in the FetchContext implementation. Used by ResourceFetcher to | |
| 172 // prepare a ResourceRequest instance at the start of resource loading. | |
| 173 virtual void populateResourceRequest(Resource::Type, | |
| 174 const ClientHintsPreferences&, | |
| 175 const FetchRequest::ResourceWidth&, | |
| 176 ResourceRequest&); | |
| 177 // Sets the first party for cookies and requestor origin using information | |
| 178 // stored in the FetchContext implementation. | |
| 179 virtual void setFirstPartyCookieAndRequestorOrigin(ResourceRequest&); | |
| 180 | |
| 181 virtual MHTMLArchive* archive() const { return nullptr; } | |
| 182 | |
| 183 virtual ResourceLoadPriority modifyPriorityForExperiments( | |
| 184 ResourceLoadPriority priority) { | |
| 185 return priority; | |
| 186 } | |
| 187 | |
| 188 virtual RefPtr<WebTaskRunner> loadingTaskRunner() const { return nullptr; } | |
| 189 | |
| 190 protected: | |
| 191 FetchContext() {} | |
| 192 }; | |
| 193 | |
| 194 } // namespace blink | |
| 195 | |
| 196 #endif | |
| OLD | NEW |