• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 //    * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 //    * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 //    * Neither the name of Google Inc. nor the name Chromium Embedded
14 // Framework nor the names of its contributors may be used to endorse
15 // or promote products derived from this software without specific prior
16 // written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // ---------------------------------------------------------------------------
31 //
32 // The contents of this file must follow a specific format in order to
33 // support the CEF translator tool. See the translator.README.txt file in the
34 // tools directory for more information.
35 //
36 
37 #ifndef CEF_INCLUDE_CEF_REQUEST_H_
38 #define CEF_INCLUDE_CEF_REQUEST_H_
39 #pragma once
40 
41 #include <map>
42 #include <vector>
43 #include "include/cef_base.h"
44 
45 class CefPostData;
46 class CefPostDataElement;
47 
48 ///
49 // Class used to represent a web request. The methods of this class may be
50 // called on any thread.
51 ///
52 /*--cef(source=library,no_debugct_check)--*/
53 class CefRequest : public virtual CefBaseRefCounted {
54  public:
55   typedef std::multimap<CefString, CefString> HeaderMap;
56   typedef cef_referrer_policy_t ReferrerPolicy;
57   typedef cef_resource_type_t ResourceType;
58   typedef cef_transition_type_t TransitionType;
59 
60   ///
61   // Create a new CefRequest object.
62   ///
63   /*--cef()--*/
64   static CefRefPtr<CefRequest> Create();
65 
66   ///
67   // Returns true if this object is read-only.
68   ///
69   /*--cef()--*/
70   virtual bool IsReadOnly() = 0;
71 
72   ///
73   // Get the fully qualified URL.
74   ///
75   /*--cef()--*/
76   virtual CefString GetURL() = 0;
77 
78   ///
79   // Set the fully qualified URL.
80   ///
81   /*--cef()--*/
82   virtual void SetURL(const CefString& url) = 0;
83 
84   ///
85   // Get the request method type. The value will default to POST if post data
86   // is provided and GET otherwise.
87   ///
88   /*--cef()--*/
89   virtual CefString GetMethod() = 0;
90 
91   ///
92   // Set the request method type.
93   ///
94   /*--cef()--*/
95   virtual void SetMethod(const CefString& method) = 0;
96 
97   ///
98   // Set the referrer URL and policy. If non-empty the referrer URL must be
99   // fully qualified with an HTTP or HTTPS scheme component. Any username,
100   // password or ref component will be removed.
101   ///
102   /*--cef(optional_param=referrer_url)--*/
103   virtual void SetReferrer(const CefString& referrer_url,
104                            ReferrerPolicy policy) = 0;
105 
106   ///
107   // Get the referrer URL.
108   ///
109   /*--cef()--*/
110   virtual CefString GetReferrerURL() = 0;
111 
112   ///
113   // Get the referrer policy.
114   ///
115   /*--cef(default_retval=REFERRER_POLICY_DEFAULT)--*/
116   virtual ReferrerPolicy GetReferrerPolicy() = 0;
117 
118   ///
119   // Get the post data.
120   ///
121   /*--cef()--*/
122   virtual CefRefPtr<CefPostData> GetPostData() = 0;
123 
124   ///
125   // Set the post data.
126   ///
127   /*--cef()--*/
128   virtual void SetPostData(CefRefPtr<CefPostData> postData) = 0;
129 
130   ///
131   // Get the header values. Will not include the Referer value if any.
132   ///
133   /*--cef()--*/
134   virtual void GetHeaderMap(HeaderMap& headerMap) = 0;
135 
136   ///
137   // Set the header values. If a Referer value exists in the header map it will
138   // be removed and ignored.
139   ///
140   /*--cef()--*/
141   virtual void SetHeaderMap(const HeaderMap& headerMap) = 0;
142 
143   ///
144   // Returns the first header value for |name| or an empty string if not found.
145   // Will not return the Referer value if any. Use GetHeaderMap instead if
146   // |name| might have multiple values.
147   ///
148   /*--cef()--*/
149   virtual CefString GetHeaderByName(const CefString& name) = 0;
150 
151   ///
152   // Set the header |name| to |value|. If |overwrite| is true any existing
153   // values will be replaced with the new value. If |overwrite| is false any
154   // existing values will not be overwritten. The Referer value cannot be set
155   // using this method.
156   ///
157   /*--cef(optional_param=value)--*/
158   virtual void SetHeaderByName(const CefString& name,
159                                const CefString& value,
160                                bool overwrite) = 0;
161 
162   ///
163   // Set all values at one time.
164   ///
165   /*--cef(optional_param=postData)--*/
166   virtual void Set(const CefString& url,
167                    const CefString& method,
168                    CefRefPtr<CefPostData> postData,
169                    const HeaderMap& headerMap) = 0;
170 
171   ///
172   // Get the flags used in combination with CefURLRequest. See
173   // cef_urlrequest_flags_t for supported values.
174   ///
175   /*--cef(default_retval=UR_FLAG_NONE)--*/
176   virtual int GetFlags() = 0;
177 
178   ///
179   // Set the flags used in combination with CefURLRequest.  See
180   // cef_urlrequest_flags_t for supported values.
181   ///
182   /*--cef()--*/
183   virtual void SetFlags(int flags) = 0;
184 
185   ///
186   // Get the URL to the first party for cookies used in combination with
187   // CefURLRequest.
188   ///
189   /*--cef()--*/
190   virtual CefString GetFirstPartyForCookies() = 0;
191 
192   ///
193   // Set the URL to the first party for cookies used in combination with
194   // CefURLRequest.
195   ///
196   /*--cef(optional_param=url)--*/
197   virtual void SetFirstPartyForCookies(const CefString& url) = 0;
198 
199   ///
200   // Get the resource type for this request. Only available in the browser
201   // process.
202   ///
203   /*--cef(default_retval=RT_SUB_RESOURCE)--*/
204   virtual ResourceType GetResourceType() = 0;
205 
206   ///
207   // Get the transition type for this request. Only available in the browser
208   // process and only applies to requests that represent a main frame or
209   // sub-frame navigation.
210   ///
211   /*--cef(default_retval=TT_EXPLICIT)--*/
212   virtual TransitionType GetTransitionType() = 0;
213 
214   ///
215   // Returns the globally unique identifier for this request or 0 if not
216   // specified. Can be used by CefResourceRequestHandler implementations in the
217   // browser process to track a single request across multiple callbacks.
218   ///
219   /*--cef()--*/
220   virtual uint64 GetIdentifier() = 0;
221 };
222 
223 ///
224 // Class used to represent post data for a web request. The methods of this
225 // class may be called on any thread.
226 ///
227 /*--cef(source=library,no_debugct_check)--*/
228 class CefPostData : public virtual CefBaseRefCounted {
229  public:
230   typedef std::vector<CefRefPtr<CefPostDataElement>> ElementVector;
231 
232   ///
233   // Create a new CefPostData object.
234   ///
235   /*--cef()--*/
236   static CefRefPtr<CefPostData> Create();
237 
238   ///
239   // Returns true if this object is read-only.
240   ///
241   /*--cef()--*/
242   virtual bool IsReadOnly() = 0;
243 
244   ///
245   // Returns true if the underlying POST data includes elements that are not
246   // represented by this CefPostData object (for example, multi-part file upload
247   // data). Modifying CefPostData objects with excluded elements may result in
248   // the request failing.
249   ///
250   /*--cef()--*/
251   virtual bool HasExcludedElements() = 0;
252 
253   ///
254   // Returns the number of existing post data elements.
255   ///
256   /*--cef()--*/
257   virtual size_t GetElementCount() = 0;
258 
259   ///
260   // Retrieve the post data elements.
261   ///
262   /*--cef(count_func=elements:GetElementCount)--*/
263   virtual void GetElements(ElementVector& elements) = 0;
264 
265   ///
266   // Remove the specified post data element.  Returns true if the removal
267   // succeeds.
268   ///
269   /*--cef()--*/
270   virtual bool RemoveElement(CefRefPtr<CefPostDataElement> element) = 0;
271 
272   ///
273   // Add the specified post data element.  Returns true if the add succeeds.
274   ///
275   /*--cef()--*/
276   virtual bool AddElement(CefRefPtr<CefPostDataElement> element) = 0;
277 
278   ///
279   // Remove all existing post data elements.
280   ///
281   /*--cef()--*/
282   virtual void RemoveElements() = 0;
283 };
284 
285 ///
286 // Class used to represent a single element in the request post data. The
287 // methods of this class may be called on any thread.
288 ///
289 /*--cef(source=library,no_debugct_check)--*/
290 class CefPostDataElement : public virtual CefBaseRefCounted {
291  public:
292   ///
293   // Post data elements may represent either bytes or files.
294   ///
295   typedef cef_postdataelement_type_t Type;
296 
297   ///
298   // Create a new CefPostDataElement object.
299   ///
300   /*--cef()--*/
301   static CefRefPtr<CefPostDataElement> Create();
302 
303   ///
304   // Returns true if this object is read-only.
305   ///
306   /*--cef()--*/
307   virtual bool IsReadOnly() = 0;
308 
309   ///
310   // Remove all contents from the post data element.
311   ///
312   /*--cef()--*/
313   virtual void SetToEmpty() = 0;
314 
315   ///
316   // The post data element will represent a file.
317   ///
318   /*--cef()--*/
319   virtual void SetToFile(const CefString& fileName) = 0;
320 
321   ///
322   // The post data element will represent bytes.  The bytes passed
323   // in will be copied.
324   ///
325   /*--cef()--*/
326   virtual void SetToBytes(size_t size, const void* bytes) = 0;
327 
328   ///
329   // Return the type of this post data element.
330   ///
331   /*--cef(default_retval=PDE_TYPE_EMPTY)--*/
332   virtual Type GetType() = 0;
333 
334   ///
335   // Return the file name.
336   ///
337   /*--cef()--*/
338   virtual CefString GetFile() = 0;
339 
340   ///
341   // Return the number of bytes.
342   ///
343   /*--cef()--*/
344   virtual size_t GetBytesCount() = 0;
345 
346   ///
347   // Read up to |size| bytes into |bytes| and return the number of bytes
348   // actually read.
349   ///
350   /*--cef()--*/
351   virtual size_t GetBytes(size_t size, void* bytes) = 0;
352 };
353 
354 #endif  // CEF_INCLUDE_CEF_REQUEST_H_
355