~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/platform/network/ResourceRequestBase.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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) 2009, 2012 Google Inc. All rights reserved.
 
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 ResourceRequestBase_h
 
29
#define ResourceRequestBase_h
 
30
 
 
31
#include "FormData.h"
 
32
#include "HTTPHeaderMap.h"
 
33
#include "KURL.h"
 
34
#include "ResourceLoadPriority.h"
 
35
 
 
36
#include <wtf/OwnPtr.h>
 
37
 
 
38
namespace WebCore {
 
39
 
 
40
    enum ResourceRequestCachePolicy {
 
41
        UseProtocolCachePolicy, // normal load
 
42
        ReloadIgnoringCacheData, // reload
 
43
        ReturnCacheDataElseLoad, // back/forward or encoding change - allow stale data
 
44
        ReturnCacheDataDontLoad  // results of a post - allow stale data and only use cache
 
45
    };
 
46
 
 
47
    class ResourceRequest;
 
48
    struct CrossThreadResourceRequestData;
 
49
 
 
50
    // Do not use this type directly.  Use ResourceRequest instead.
 
51
    class ResourceRequestBase {
 
52
        WTF_MAKE_FAST_ALLOCATED;
 
53
    public:
 
54
        static PassOwnPtr<ResourceRequest> adopt(PassOwnPtr<CrossThreadResourceRequestData>);
 
55
 
 
56
        // Gets a copy of the data suitable for passing to another thread.
 
57
        PassOwnPtr<CrossThreadResourceRequestData> copyData() const;
 
58
 
 
59
        bool isNull() const;
 
60
        bool isEmpty() const;
 
61
 
 
62
        const KURL& url() const;
 
63
        void setURL(const KURL& url);
 
64
 
 
65
        void removeCredentials();
 
66
 
 
67
        ResourceRequestCachePolicy cachePolicy() const;
 
68
        void setCachePolicy(ResourceRequestCachePolicy cachePolicy);
 
69
        
 
70
        double timeoutInterval() const; // May return 0 when using platform default.
 
71
        void setTimeoutInterval(double timeoutInterval);
 
72
        
 
73
        const KURL& firstPartyForCookies() const;
 
74
        void setFirstPartyForCookies(const KURL& firstPartyForCookies);
 
75
        
 
76
        const String& httpMethod() const;
 
77
        void setHTTPMethod(const String& httpMethod);
 
78
        
 
79
        const HTTPHeaderMap& httpHeaderFields() const;
 
80
        String httpHeaderField(const AtomicString& name) const;
 
81
        String httpHeaderField(const char* name) const;
 
82
        void setHTTPHeaderField(const AtomicString& name, const String& value);
 
83
        void setHTTPHeaderField(const char* name, const String& value);
 
84
        void addHTTPHeaderField(const AtomicString& name, const String& value);
 
85
        void addHTTPHeaderFields(const HTTPHeaderMap& headerFields);
 
86
        
 
87
        void clearHTTPAuthorization();
 
88
 
 
89
        String httpContentType() const { return httpHeaderField("Content-Type");  }
 
90
        void setHTTPContentType(const String& httpContentType) { setHTTPHeaderField("Content-Type", httpContentType); }
 
91
        void clearHTTPContentType();
 
92
 
 
93
        String httpReferrer() const { return httpHeaderField("Referer"); }
 
94
        void setHTTPReferrer(const String& httpReferrer) { setHTTPHeaderField("Referer", httpReferrer); }
 
95
        void clearHTTPReferrer();
 
96
        
 
97
        String httpOrigin() const { return httpHeaderField("Origin"); }
 
98
        void setHTTPOrigin(const String& httpOrigin) { setHTTPHeaderField("Origin", httpOrigin); }
 
99
        void clearHTTPOrigin();
 
100
 
 
101
        String httpUserAgent() const { return httpHeaderField("User-Agent"); }
 
102
        void setHTTPUserAgent(const String& httpUserAgent) { setHTTPHeaderField("User-Agent", httpUserAgent); }
 
103
        void clearHTTPUserAgent();
 
104
 
 
105
        String httpAccept() const { return httpHeaderField("Accept"); }
 
106
        void setHTTPAccept(const String& httpAccept) { setHTTPHeaderField("Accept", httpAccept); }
 
107
        void clearHTTPAccept();
 
108
 
 
109
        void setResponseContentDispositionEncodingFallbackArray(const String& encoding1, const String& encoding2 = String(), const String& encoding3 = String());
 
110
 
 
111
        FormData* httpBody() const;
 
112
        void setHTTPBody(PassRefPtr<FormData> httpBody);
 
113
        
 
114
        bool allowCookies() const;
 
115
        void setAllowCookies(bool allowCookies);
 
116
 
 
117
        ResourceLoadPriority priority() const;
 
118
        void setPriority(ResourceLoadPriority);
 
119
 
 
120
        bool isConditional() const;
 
121
 
 
122
        // Whether the associated ResourceHandleClient needs to be notified of
 
123
        // upload progress made for that resource.
 
124
        bool reportUploadProgress() const { return m_reportUploadProgress; }
 
125
        void setReportUploadProgress(bool reportUploadProgress) { m_reportUploadProgress = reportUploadProgress; }
 
126
 
 
127
        // Whether the timing information should be collected for the request.
 
128
        bool reportLoadTiming() const { return m_reportLoadTiming; }
 
129
        void setReportLoadTiming(bool reportLoadTiming) { m_reportLoadTiming = reportLoadTiming; }
 
130
 
 
131
        // Whether actual headers being sent/received should be collected and reported for the request.
 
132
        bool reportRawHeaders() const { return m_reportRawHeaders; }
 
133
        void setReportRawHeaders(bool reportRawHeaders) { m_reportRawHeaders = reportRawHeaders; }
 
134
 
 
135
        static double defaultTimeoutInterval(); // May return 0 when using platform default.
 
136
        static void setDefaultTimeoutInterval(double);
 
137
 
 
138
        static bool compare(const ResourceRequest&, const ResourceRequest&);
 
139
 
 
140
    protected:
 
141
        // Used when ResourceRequest is initialized from a platform representation of the request
 
142
        ResourceRequestBase()
 
143
            : m_resourceRequestUpdated(false)
 
144
            , m_platformRequestUpdated(true)
 
145
            , m_reportUploadProgress(false)
 
146
            , m_reportLoadTiming(false)
 
147
            , m_reportRawHeaders(false)
 
148
            , m_priority(ResourceLoadPriorityLow)
 
149
        {
 
150
        }
 
151
 
 
152
        ResourceRequestBase(const KURL& url, ResourceRequestCachePolicy policy)
 
153
            : m_url(url)
 
154
            , m_cachePolicy(policy)
 
155
            , m_timeoutInterval(s_defaultTimeoutInterval)
 
156
            , m_httpMethod("GET")
 
157
            , m_allowCookies(true)
 
158
            , m_resourceRequestUpdated(true)
 
159
            , m_platformRequestUpdated(false)
 
160
            , m_reportUploadProgress(false)
 
161
            , m_reportLoadTiming(false)
 
162
            , m_reportRawHeaders(false)
 
163
            , m_priority(ResourceLoadPriorityLow)
 
164
        {
 
165
        }
 
166
 
 
167
        void updatePlatformRequest() const; 
 
168
        void updateResourceRequest() const; 
 
169
 
 
170
        void reportMemoryUsageBase(MemoryObjectInfo*) const;
 
171
 
 
172
        // The ResourceRequest subclass may "shadow" this method to compare platform specific fields
 
173
        static bool platformCompare(const ResourceRequest&, const ResourceRequest&) { return true; }
 
174
 
 
175
        KURL m_url;
 
176
 
 
177
        ResourceRequestCachePolicy m_cachePolicy;
 
178
        double m_timeoutInterval; // 0 is a magic value for platform default on platforms that have one.
 
179
        KURL m_firstPartyForCookies;
 
180
        String m_httpMethod;
 
181
        HTTPHeaderMap m_httpHeaderFields;
 
182
        Vector<String> m_responseContentDispositionEncodingFallbackArray;
 
183
        RefPtr<FormData> m_httpBody;
 
184
        bool m_allowCookies : 1;
 
185
        mutable bool m_resourceRequestUpdated : 1;
 
186
        mutable bool m_platformRequestUpdated : 1;
 
187
        bool m_reportUploadProgress : 1;
 
188
        bool m_reportLoadTiming : 1;
 
189
        bool m_reportRawHeaders : 1;
 
190
        ResourceLoadPriority m_priority;
 
191
 
 
192
    private:
 
193
        const ResourceRequest& asResourceRequest() const;
 
194
 
 
195
        static double s_defaultTimeoutInterval;
 
196
    };
 
197
 
 
198
    bool equalIgnoringHeaderFields(const ResourceRequestBase&, const ResourceRequestBase&);
 
199
 
 
200
    inline bool operator==(const ResourceRequest& a, const ResourceRequest& b) { return ResourceRequestBase::compare(a, b); }
 
201
    inline bool operator!=(ResourceRequest& a, const ResourceRequest& b) { return !(a == b); }
 
202
 
 
203
    struct CrossThreadResourceRequestDataBase {
 
204
        WTF_MAKE_NONCOPYABLE(CrossThreadResourceRequestDataBase); WTF_MAKE_FAST_ALLOCATED;
 
205
    public:
 
206
        CrossThreadResourceRequestDataBase() { }
 
207
        KURL m_url;
 
208
 
 
209
        ResourceRequestCachePolicy m_cachePolicy;
 
210
        double m_timeoutInterval;
 
211
        KURL m_firstPartyForCookies;
 
212
 
 
213
        String m_httpMethod;
 
214
        OwnPtr<CrossThreadHTTPHeaderMapData> m_httpHeaders;
 
215
        Vector<String> m_responseContentDispositionEncodingFallbackArray;
 
216
        RefPtr<FormData> m_httpBody;
 
217
        bool m_allowCookies;
 
218
        ResourceLoadPriority m_priority;
 
219
    };
 
220
    
 
221
    unsigned initializeMaximumHTTPConnectionCountPerHost();
 
222
 
 
223
} // namespace WebCore
 
224
 
 
225
#endif // ResourceRequestBase_h