tizen beta release
[profile/ivi/webkit-efl.git] / Source / WebCore / platform / network / chromium / ResourceRequest.h
1 /*
2  * Copyright (C) 2003, 2006 Apple Computer, Inc.  All rights reserved.
3  * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
4  * Copyright (C) 2008 Google, Inc.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
26  */
27
28 #ifndef ResourceRequest_h
29 #define ResourceRequest_h
30
31 #include "ResourceRequestBase.h"
32
33 #include <wtf/PassRefPtr.h>
34 #include <wtf/RefCounted.h>
35
36 namespace WebCore {
37
38     class Frame;
39
40     class ResourceRequest : public ResourceRequestBase {
41     public:
42         // The type of this ResourceRequest, based on how the resource will be used.
43         enum TargetType {
44             TargetIsMainFrame,
45             TargetIsSubframe,
46             TargetIsSubresource, // Resource is a generic subresource. (Generally a specific type should be specified)
47             TargetIsStyleSheet,
48             TargetIsScript,
49             TargetIsFontResource,
50             TargetIsImage,
51             TargetIsObject,
52             TargetIsMedia,
53             TargetIsWorker,
54             TargetIsSharedWorker,
55             TargetIsPrefetch,
56             TargetIsPrerender,
57             TargetIsFavicon,
58             TargetIsXHR,
59             TargetIsTextTrack,
60             TargetIsUnspecified,
61         };
62
63         class ExtraData : public RefCounted<ExtraData> {
64         public:
65             virtual ~ExtraData() { }
66         };
67
68         ResourceRequest(const String& url) 
69             : ResourceRequestBase(KURL(ParsedURLString, url), UseProtocolCachePolicy)
70             , m_requestorID(0)
71             , m_requestorProcessID(0)
72             , m_appCacheHostID(0)
73             , m_hasUserGesture(false)
74             , m_downloadToFile(false)
75             , m_targetType(TargetIsUnspecified)
76         {
77         }
78
79         ResourceRequest(const KURL& url) 
80             : ResourceRequestBase(url, UseProtocolCachePolicy)
81             , m_requestorID(0)
82             , m_requestorProcessID(0)
83             , m_appCacheHostID(0)
84             , m_hasUserGesture(false)
85             , m_downloadToFile(false)
86             , m_targetType(TargetIsUnspecified)
87         {
88         }
89
90         ResourceRequest(const KURL& url, const String& referrer, ResourceRequestCachePolicy policy = UseProtocolCachePolicy) 
91             : ResourceRequestBase(url, policy)
92             , m_requestorID(0)
93             , m_requestorProcessID(0)
94             , m_appCacheHostID(0)
95             , m_hasUserGesture(false)
96             , m_downloadToFile(false)
97             , m_targetType(TargetIsUnspecified)
98         {
99             setHTTPReferrer(referrer);
100         }
101         
102         ResourceRequest()
103             : ResourceRequestBase(KURL(), UseProtocolCachePolicy)
104             , m_requestorID(0)
105             , m_requestorProcessID(0)
106             , m_appCacheHostID(0)
107             , m_hasUserGesture(false)
108             , m_downloadToFile(false)
109             , m_targetType(TargetIsUnspecified)
110         {
111         }
112
113         // Allows the request to be matched up with its requestor.
114         int requestorID() const { return m_requestorID; }
115         void setRequestorID(int requestorID) { m_requestorID = requestorID; }
116
117         // The process id of the process from which this request originated. In
118         // the case of out-of-process plugins, this allows to link back the
119         // request to the plugin process (as it is processed through a render
120         // view process).
121         int requestorProcessID() const { return m_requestorProcessID; }
122         void setRequestorProcessID(int requestorProcessID) { m_requestorProcessID = requestorProcessID; }
123
124         // Allows the request to be matched up with its app cache host.
125         int appCacheHostID() const { return m_appCacheHostID; }
126         void setAppCacheHostID(int id) { m_appCacheHostID = id; }
127
128         // True if request was user initiated.
129         bool hasUserGesture() const { return m_hasUserGesture; }
130         void setHasUserGesture(bool hasUserGesture) { m_hasUserGesture = hasUserGesture; }
131
132         // True if request should be downloaded to file.
133         bool downloadToFile() const { return m_downloadToFile; }
134         void setDownloadToFile(bool downloadToFile) { m_downloadToFile = downloadToFile; }
135
136         // Extra data associated with this request.
137         ExtraData* extraData() const { return m_extraData.get(); }
138         void setExtraData(PassRefPtr<ExtraData> extraData) { m_extraData = extraData; }
139
140         // What this request is for.
141         TargetType targetType() const { return m_targetType; }
142         void setTargetType(TargetType type) { m_targetType = type; }
143
144     private:
145         friend class ResourceRequestBase;
146
147         void doUpdatePlatformRequest() {}
148         void doUpdateResourceRequest() {}
149
150         PassOwnPtr<CrossThreadResourceRequestData> doPlatformCopyData(PassOwnPtr<CrossThreadResourceRequestData>) const;
151         void doPlatformAdopt(PassOwnPtr<CrossThreadResourceRequestData>);
152
153         int m_requestorID;
154         int m_requestorProcessID;
155         int m_appCacheHostID;
156         bool m_hasUserGesture;
157         bool m_downloadToFile;
158         RefPtr<ExtraData> m_extraData;
159         TargetType m_targetType;
160     };
161
162     struct CrossThreadResourceRequestData : public CrossThreadResourceRequestDataBase {
163         int m_requestorID;
164         int m_requestorProcessID;
165         int m_appCacheHostID;
166         bool m_hasUserGesture;
167         bool m_downloadToFile;
168         ResourceRequest::TargetType m_targetType;
169     };
170
171 } // namespace WebCore
172
173 #endif