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.
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.
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.
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.
26 #include "core/CoreExport.h"
27 #include "core/fetch/ResourceClient.h"
28 #include "core/fetch/ResourcePtr.h"
29 #include "public/platform/WebDataConsumerHandle.h"
30 #include "wtf/PassOwnPtr.h"
34 class RawResourceClient
;
35 class ResourceFetcher
;
38 class CORE_EXPORT RawResource final
: public Resource
{
40 typedef RawResourceClient ClientType
;
42 static ResourcePtr
<Resource
> fetchSynchronously(FetchRequest
&, ResourceFetcher
*);
43 static ResourcePtr
<RawResource
> fetch(FetchRequest
&, ResourceFetcher
*);
44 static ResourcePtr
<RawResource
> fetchMainResource(FetchRequest
&, ResourceFetcher
*, const SubstituteData
&);
45 static ResourcePtr
<RawResource
> fetchImport(FetchRequest
&, ResourceFetcher
*);
46 static ResourcePtr
<RawResource
> fetchMedia(FetchRequest
&, ResourceFetcher
*);
47 static ResourcePtr
<RawResource
> fetchTextTrack(FetchRequest
&, ResourceFetcher
*);
49 // Exposed for testing
50 RawResource(const ResourceRequest
&, Type
);
52 // FIXME: AssociatedURLLoader shouldn't be a DocumentThreadableLoader and therefore shouldn't
53 // use RawResource. However, it is, and it needs to be able to defer loading.
54 // This can be fixed by splitting CORS preflighting out of DocumentThreacableLoader.
55 void setDefersLoading(bool);
57 bool canReuse(const ResourceRequest
&) const override
;
60 class RawResourceFactory
: public ResourceFactory
{
62 RawResourceFactory(Resource::Type type
)
63 : ResourceFactory(type
) { }
65 Resource
* create(const ResourceRequest
& request
, const String
& charset
) const override
67 return new RawResource(request
, m_type
);
71 void didAddClient(ResourceClient
*) override
;
72 void appendData(const char*, unsigned) override
;
74 bool shouldIgnoreHTTPStatusCodeErrors() const override
{ return true; }
76 void willFollowRedirect(ResourceRequest
&, const ResourceResponse
&) override
;
77 void updateRequest(const ResourceRequest
&) override
;
78 void responseReceived(const ResourceResponse
&, PassOwnPtr
<WebDataConsumerHandle
>) override
;
79 void setSerializedCachedMetadata(const char*, size_t) override
;
80 void didSendData(unsigned long long bytesSent
, unsigned long long totalBytesToBeSent
) override
;
81 void didDownloadData(int) override
;
82 void reportResourceTimingToClients(const ResourceTimingInfo
&) override
;
85 #if ENABLE(SECURITY_ASSERT)
86 inline bool isRawResource(const Resource
& resource
)
88 Resource::Type type
= resource
.type();
89 return type
== Resource::MainResource
|| type
== Resource::Raw
|| type
== Resource::TextTrack
|| type
== Resource::Media
|| type
== Resource::ImportResource
;
92 inline RawResource
* toRawResource(const ResourcePtr
<Resource
>& resource
)
94 ASSERT_WITH_SECURITY_IMPLICATION(!resource
|| isRawResource(*resource
.get()));
95 return static_cast<RawResource
*>(resource
.get());
98 class CORE_EXPORT RawResourceClient
: public ResourceClient
{
100 ~RawResourceClient() override
{}
101 static ResourceClientType
expectedType() { return RawResourceType
; }
102 ResourceClientType
resourceClientType() const final
{ return expectedType(); }
104 virtual void dataSent(Resource
*, unsigned long long /* bytesSent */, unsigned long long /* totalBytesToBeSent */) { }
105 virtual void responseReceived(Resource
*, const ResourceResponse
&, PassOwnPtr
<WebDataConsumerHandle
>) { }
106 virtual void setSerializedCachedMetadata(Resource
*, const char*, size_t) { }
107 virtual void dataReceived(Resource
*, const char* /* data */, unsigned /* length */) { }
108 virtual void redirectReceived(Resource
*, ResourceRequest
&, const ResourceResponse
&) { }
109 virtual void updateRequest(Resource
*, const ResourceRequest
&) { }
110 virtual void dataDownloaded(Resource
*, int) { }
111 virtual void didReceiveResourceTiming(Resource
*, const ResourceTimingInfo
&) { }
116 #endif // RawResource_h