Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / fetch / RawResource.h
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 #include "public/platform/WebDataConsumerHandle.h"
29 #include "wtf/PassOwnPtr.h"
30
31 namespace blink {
32 class RawResourceClient;
33
34 class RawResource final : public Resource {
35 public:
36     typedef RawResourceClient ClientType;
37
38     RawResource(const ResourceRequest&, Type);
39
40     // FIXME: AssociatedURLLoader shouldn't be a DocumentThreadableLoader and therefore shouldn't
41     // use RawResource. However, it is, and it needs to be able to defer loading.
42     // This can be fixed by splitting CORS preflighting out of DocumentThreacableLoader.
43     void setDefersLoading(bool);
44
45     bool canReuse(const ResourceRequest&) const override;
46
47 private:
48     void didAddClient(ResourceClient*) override;
49     void appendData(const char*, unsigned) override;
50
51     bool shouldIgnoreHTTPStatusCodeErrors() const override { return true; }
52
53     void willFollowRedirect(ResourceRequest&, const ResourceResponse&) override;
54     void updateRequest(const ResourceRequest&) override;
55     void responseReceived(const ResourceResponse&, PassOwnPtr<WebDataConsumerHandle>) override;
56     void didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent) override;
57     void didDownloadData(int) override;
58 };
59
60 #if ENABLE(SECURITY_ASSERT)
61 inline bool isRawResource(const Resource& resource)
62 {
63     Resource::Type type = resource.type();
64     return type == Resource::MainResource || type == Resource::Raw || type == Resource::TextTrack || type == Resource::Media || type == Resource::ImportResource;
65 }
66 #endif
67 inline RawResource* toRawResource(const ResourcePtr<Resource>& resource)
68 {
69     ASSERT_WITH_SECURITY_IMPLICATION(!resource || isRawResource(*resource.get()));
70     return static_cast<RawResource*>(resource.get());
71 }
72
73 class RawResourceClient : public ResourceClient {
74 public:
75     virtual ~RawResourceClient() { }
76     static ResourceClientType expectedType() { return RawResourceType; }
77     virtual ResourceClientType resourceClientType() const override final { return expectedType(); }
78
79     virtual void dataSent(Resource*, unsigned long long /* bytesSent */, unsigned long long /* totalBytesToBeSent */) { }
80     virtual void responseReceived(Resource*, const ResourceResponse&, PassOwnPtr<WebDataConsumerHandle>) { }
81     virtual void dataReceived(Resource*, const char* /* data */, unsigned /* length */) { }
82     virtual void redirectReceived(Resource*, ResourceRequest&, const ResourceResponse&) { }
83     virtual void updateRequest(Resource*, const ResourceRequest&) { }
84     virtual void dataDownloaded(Resource*, int) { }
85 };
86
87 }
88
89 #endif // RawResource_h