• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/fetch/ResourceClient.h"
27 #include "core/fetch/ResourcePtr.h"
28 
29 namespace WebCore {
30 class RawResourceCallback;
31 class RawResourceClient;
32 
33 class RawResource : public Resource {
34 public:
35     typedef RawResourceClient ClientType;
36 
37     RawResource(const ResourceRequest&, Type);
38 
39     // FIXME: AssociatedURLLoader shouldn't be a DocumentThreadableLoader and therefore shouldn't
40     // use RawResource. However, it is, and it needs to be able to defer loading.
41     // This can be fixed by splitting CORS preflighting out of DocumentThreacableLoader.
42     virtual void setDefersLoading(bool);
43 
44     virtual void setDataBufferingPolicy(DataBufferingPolicy);
45 
46     void clear();
47 
48     virtual bool canReuse(const ResourceRequest&) const;
49 
50 private:
51     virtual void didAddClient(ResourceClient*);
52     virtual void appendData(const char*, int) OVERRIDE;
53 
shouldIgnoreHTTPStatusCodeErrors()54     virtual bool shouldIgnoreHTTPStatusCodeErrors() const { return true; }
55 
56     virtual void willSendRequest(ResourceRequest&, const ResourceResponse&);
57     virtual void responseReceived(const ResourceResponse&);
58     virtual void didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent);
59     virtual void didDownloadData(int);
60 
61     struct RedirectPair {
62     public:
RedirectPairRedirectPair63         explicit RedirectPair(const ResourceRequest& request, const ResourceResponse& redirectResponse)
64             : m_request(request)
65             , m_redirectResponse(redirectResponse)
66         {
67         }
68 
69         const ResourceRequest m_request;
70         const ResourceResponse m_redirectResponse;
71     };
72 
73     Vector<RedirectPair> m_redirectChain;
74 };
75 
76 #ifdef SECURITY_ASSERT_ENABLED
isRawResource(const Resource & resource)77 inline bool isRawResource(const Resource& resource)
78 {
79     Resource::Type type = resource.type();
80     return type == Resource::MainResource || type == Resource::Raw || type == Resource::TextTrack || type == Resource::ImportResource;
81 }
82 #endif
toRawResource(const ResourcePtr<Resource> & resource)83 inline RawResource* toRawResource(const ResourcePtr<Resource>& resource)
84 {
85     ASSERT_WITH_SECURITY_IMPLICATION(!resource || isRawResource(*resource.get()));
86     return static_cast<RawResource*>(resource.get());
87 }
88 
89 class RawResourceClient : public ResourceClient {
90 public:
~RawResourceClient()91     virtual ~RawResourceClient() { }
expectedType()92     static ResourceClientType expectedType() { return RawResourceType; }
resourceClientType()93     virtual ResourceClientType resourceClientType() const { return expectedType(); }
94 
dataSent(Resource *,unsigned long long,unsigned long long)95     virtual void dataSent(Resource*, unsigned long long /* bytesSent */, unsigned long long /* totalBytesToBeSent */) { }
responseReceived(Resource *,const ResourceResponse &)96     virtual void responseReceived(Resource*, const ResourceResponse&) { }
dataReceived(Resource *,const char *,int)97     virtual void dataReceived(Resource*, const char* /* data */, int /* length */) { }
redirectReceived(Resource *,ResourceRequest &,const ResourceResponse &)98     virtual void redirectReceived(Resource*, ResourceRequest&, const ResourceResponse&) { }
dataDownloaded(Resource *,int)99     virtual void dataDownloaded(Resource*, int) { }
100 };
101 
102 }
103 
104 #endif // RawResource_h
105