2 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
31 #ifndef FrameFetchContext_h
32 #define FrameFetchContext_h
34 #include "core/CoreExport.h"
35 #include "core/fetch/FetchContext.h"
36 #include "core/fetch/ResourceFetcher.h"
37 #include "platform/heap/Handle.h"
38 #include "platform/network/ResourceRequest.h"
39 #include "wtf/PassOwnPtr.h"
48 class ResourceResponse
;
49 class ResourceRequest
;
51 class CORE_EXPORT FrameFetchContext final
: public FetchContext
{
53 static ResourceFetcher
* createContextAndFetcher(DocumentLoader
* loader
)
55 return ResourceFetcher::create(new FrameFetchContext(loader
));
58 static void provideDocumentToContext(FetchContext
& context
, Document
* document
)
61 RELEASE_ASSERT(context
.isLiveContext());
62 static_cast<FrameFetchContext
&>(context
).m_document
= document
;
67 bool isLiveContext() { return true; }
69 void addAdditionalRequestHeaders(ResourceRequest
&, FetchResourceType
) override
;
70 void setFirstPartyForCookies(ResourceRequest
&) override
;
71 CachePolicy
cachePolicy() const override
;
72 ResourceRequestCachePolicy
resourceRequestCachePolicy(const ResourceRequest
&, Resource::Type
) const override
;
73 void dispatchDidChangeResourcePriority(unsigned long identifier
, ResourceLoadPriority
, int intraPriorityValue
) override
;
74 void dispatchWillSendRequest(unsigned long identifier
, ResourceRequest
&, const ResourceResponse
& redirectResponse
, const FetchInitiatorInfo
& = FetchInitiatorInfo()) override
;
75 void dispatchDidLoadResourceFromMemoryCache(const Resource
*) override
;
76 void dispatchDidReceiveResponse(unsigned long identifier
, const ResourceResponse
&, ResourceLoader
* = 0) override
;
77 void dispatchDidReceiveData(unsigned long identifier
, const char* data
, int dataLength
, int encodedDataLength
) override
;
78 void dispatchDidDownloadData(unsigned long identifier
, int dataLength
, int encodedDataLength
) override
;
79 void dispatchDidFinishLoading(unsigned long identifier
, double finishTime
, int64_t encodedDataLength
) override
;
80 void dispatchDidFail(unsigned long identifier
, const ResourceError
&, bool isInternalRequest
) override
;
82 bool shouldLoadNewResource(Resource::Type
) const override
;
83 void willStartLoadingResource(ResourceRequest
&) override
;
84 void didLoadResource() override
;
86 void addResourceTiming(const ResourceTimingInfo
&) override
;
87 bool allowImage(bool imagesEnabled
, const KURL
&) const override
;
88 bool canRequest(Resource::Type
, const ResourceRequest
&, const KURL
&, const ResourceLoaderOptions
&, bool forPreload
, FetchRequest::OriginRestriction
) const override
;
90 bool isControlledByServiceWorker() const override
;
91 int64_t serviceWorkerID() const override
;
93 bool isMainFrame() const override
;
94 bool defersLoading() const override
;
95 bool isLoadComplete() const override
;
96 bool pageDismissalEventBeingDispatched() const override
;
97 bool updateTimingInfoForIFrameNavigation(ResourceTimingInfo
*) override
;
98 void sendImagePing(const KURL
&) override
;
99 void addConsoleMessage(const String
&) const override
;
100 SecurityOrigin
* securityOrigin() const override
;
101 void upgradeInsecureRequest(FetchRequest
&) override
;
102 void addClientHintsIfNecessary(FetchRequest
&) override
;
103 void addCSPHeaderIfNecessary(Resource::Type
, FetchRequest
&) override
;
105 bool fetchIncreasePriorities() const override
;
106 ResourceLoadPriority
modifyPriorityForExperiments(ResourceLoadPriority
, Resource::Type
, const FetchRequest
&) override
;
108 void countClientHintsDPR() override
;
109 void countClientHintsResourceWidth() override
;
110 void countClientHintsViewportWidth() override
;
112 DECLARE_VIRTUAL_TRACE();
115 explicit FrameFetchContext(DocumentLoader
*);
116 inline DocumentLoader
* ensureLoaderForNotifications() const;
118 LocalFrame
* frame() const; // Can be null
119 void printAccessDeniedMessage(const KURL
&) const;
120 ResourceRequestBlockedReason
canRequestInternal(Resource::Type
, const ResourceRequest
&, const KURL
&, const ResourceLoaderOptions
&, bool forPreload
, FetchRequest::OriginRestriction
) const;
122 // FIXME: Oilpan: Ideally this should just be a traced Member but that will
123 // currently leak because ComputedStyle and its data are not on the heap.
124 // See crbug.com/383860 for details.
125 RawPtrWillBeWeakMember
<Document
> m_document
;
126 RawPtrWillBeMember
<DocumentLoader
> m_documentLoader
;
128 bool m_imageFetched
: 1;