Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: third_party/WebKit/Source/core/fetch/RawResource.h

Issue 2584423002: Loading: move core/fetch to platform/loader/fetch (Closed)
Patch Set: rebase Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de)
3 Copyright (C) 2001 Dirk Mueller <mueller@kde.org>
4 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
5 Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
21 */
22
23 #ifndef RawResource_h
24 #define RawResource_h
25
26 #include "core/CoreExport.h"
27 #include "core/fetch/Resource.h"
28 #include "core/fetch/ResourceClient.h"
29 #include "public/platform/WebDataConsumerHandle.h"
30 #include "wtf/WeakPtr.h"
31 #include <memory>
32
33 namespace blink {
34 class FetchRequest;
35 class RawResourceClient;
36 class ResourceFetcher;
37 class SubstituteData;
38
39 class CORE_EXPORT RawResource final : public Resource {
40 public:
41 using ClientType = RawResourceClient;
42
43 static Resource* fetchSynchronously(FetchRequest&, ResourceFetcher*);
44 static RawResource* fetch(FetchRequest&, ResourceFetcher*);
45 static RawResource* fetchMainResource(FetchRequest&,
46 ResourceFetcher*,
47 const SubstituteData&);
48 static RawResource* fetchImport(FetchRequest&, ResourceFetcher*);
49 static RawResource* fetchMedia(FetchRequest&, ResourceFetcher*);
50 static RawResource* fetchTextTrack(FetchRequest&, ResourceFetcher*);
51 static RawResource* fetchManifest(FetchRequest&, ResourceFetcher*);
52
53 // Exposed for testing
54 static RawResource* create(const ResourceRequest& request, Type type) {
55 return new RawResource(request, type, ResourceLoaderOptions());
56 }
57
58 // FIXME: AssociatedURLLoader shouldn't be a DocumentThreadableLoader and
59 // therefore shouldn't use RawResource. However, it is, and it needs to be
60 // able to defer loading. This can be fixed by splitting CORS preflighting out
61 // of DocumentThreadableLoader.
62 void setDefersLoading(bool);
63
64 bool canReuse(const ResourceRequest&) const override;
65
66 private:
67 class RawResourceFactory : public ResourceFactory {
68 public:
69 explicit RawResourceFactory(Resource::Type type) : ResourceFactory(type) {}
70
71 Resource* create(const ResourceRequest& request,
72 const ResourceLoaderOptions& options,
73 const String& charset) const override {
74 return new RawResource(request, m_type, options);
75 }
76 };
77
78 RawResource(const ResourceRequest&, Type, const ResourceLoaderOptions&);
79
80 void didAddClient(ResourceClient*) override;
81 void appendData(const char*, size_t) override;
82
83 bool shouldIgnoreHTTPStatusCodeErrors() const override {
84 return !isLinkPreload();
85 }
86
87 bool willFollowRedirect(const ResourceRequest&,
88 const ResourceResponse&) override;
89 void willNotFollowRedirect() override;
90 void responseReceived(const ResourceResponse&,
91 std::unique_ptr<WebDataConsumerHandle>) override;
92 void setSerializedCachedMetadata(const char*, size_t) override;
93 void didSendData(unsigned long long bytesSent,
94 unsigned long long totalBytesToBeSent) override;
95 void didDownloadData(int) override;
96 void reportResourceTimingToClients(const ResourceTimingInfo&) override;
97 };
98
99 #if ENABLE(SECURITY_ASSERT)
100 inline bool isRawResource(const Resource& resource) {
101 Resource::Type type = resource.getType();
102 return type == Resource::MainResource || type == Resource::Raw ||
103 type == Resource::TextTrack || type == Resource::Media ||
104 type == Resource::Manifest || type == Resource::ImportResource;
105 }
106 #endif
107 inline RawResource* toRawResource(Resource* resource) {
108 SECURITY_DCHECK(!resource || isRawResource(*resource));
109 return static_cast<RawResource*>(resource);
110 }
111
112 class CORE_EXPORT RawResourceClient : public ResourceClient {
113 public:
114 static bool isExpectedType(ResourceClient* client) {
115 return client->getResourceClientType() == RawResourceType;
116 }
117 ResourceClientType getResourceClientType() const final {
118 return RawResourceType;
119 }
120
121 // The order of the callbacks is as follows:
122 // [Case 1] A successful load:
123 // 0+ redirectReceived() and/or dataSent()
124 // 1 responseReceived()
125 // 0-1 setSerializedCachedMetadata()
126 // 0+ dataReceived() or dataDownloaded(), but never both
127 // 1 notifyFinished() with errorOccurred() = false
128 // [Case 2] When redirect is blocked:
129 // 0+ redirectReceived() and/or dataSent()
130 // 1 redirectBlocked()
131 // 1 notifyFinished() with errorOccurred() = true
132 // [Case 3] Other failures:
133 // notifyFinished() with errorOccurred() = true is called at any time
134 // (unless notifyFinished() is already called).
135 // In all cases:
136 // No callbacks are made after notifyFinished() or
137 // removeClient() is called.
138 virtual void dataSent(Resource*,
139 unsigned long long /* bytesSent */,
140 unsigned long long /* totalBytesToBeSent */) {}
141 virtual void responseReceived(Resource*,
142 const ResourceResponse&,
143 std::unique_ptr<WebDataConsumerHandle>) {}
144 virtual void setSerializedCachedMetadata(Resource*, const char*, size_t) {}
145 virtual void dataReceived(Resource*,
146 const char* /* data */,
147 size_t /* length */) {}
148 virtual bool redirectReceived(Resource*,
149 const ResourceRequest&,
150 const ResourceResponse&) {
151 return true;
152 }
153 virtual void redirectBlocked() {}
154 virtual void dataDownloaded(Resource*, int) {}
155 virtual void didReceiveResourceTiming(Resource*, const ResourceTimingInfo&) {}
156 };
157
158 // Checks the sequence of callbacks of RawResourceClient. This can be used only
159 // when a RawResourceClient is added as a client to at most one RawResource.
160 class CORE_EXPORT RawResourceClientStateChecker final {
161 public:
162 RawResourceClientStateChecker();
163 ~RawResourceClientStateChecker();
164
165 // Call before addClient()/removeClient() is called.
166 void willAddClient();
167 void willRemoveClient();
168
169 // Call RawResourceClientStateChecker::f() at the beginning of
170 // RawResourceClient::f().
171 void redirectReceived();
172 void redirectBlocked();
173 void dataSent();
174 void responseReceived();
175 void setSerializedCachedMetadata();
176 void dataReceived();
177 void dataDownloaded();
178 void notifyFinished(Resource*);
179
180 private:
181 enum State {
182 NotAddedAsClient,
183 Started,
184 RedirectBlocked,
185 ResponseReceived,
186 SetSerializedCachedMetadata,
187 DataReceived,
188 DataDownloaded,
189 NotifyFinished
190 };
191 State m_state;
192 };
193
194 } // namespace blink
195
196 #endif // RawResource_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698