• 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_URLREQUEST_H_
38 #define CEF_INCLUDE_CEF_URLREQUEST_H_
39 #pragma once
40 
41 #include "include/cef_auth_callback.h"
42 #include "include/cef_base.h"
43 #include "include/cef_request.h"
44 #include "include/cef_request_context.h"
45 #include "include/cef_response.h"
46 
47 class CefURLRequestClient;
48 
49 ///
50 // Class used to make a URL request. URL requests are not associated with a
51 // browser instance so no CefClient callbacks will be executed. URL requests
52 // can be created on any valid CEF thread in either the browser or render
53 // process. Once created the methods of the URL request object must be accessed
54 // on the same thread that created it.
55 ///
56 /*--cef(source=library)--*/
57 class CefURLRequest : public virtual CefBaseRefCounted {
58  public:
59   typedef cef_urlrequest_status_t Status;
60   typedef cef_errorcode_t ErrorCode;
61 
62   ///
63   // Create a new URL request that is not associated with a specific browser or
64   // frame. Use CefFrame::CreateURLRequest instead if you want the request to
65   // have this association, in which case it may be handled differently (see
66   // documentation on that method). A request created with this method may only
67   // originate from the browser process, and will behave as follows:
68   //   - It may be intercepted by the client via CefResourceRequestHandler or
69   //     CefSchemeHandlerFactory.
70   //   - POST data may only contain only a single element of type PDE_TYPE_FILE
71   //     or PDE_TYPE_BYTES.
72   //   - If |request_context| is empty the global request context will be used.
73   //
74   // The |request| object will be marked as read-only after calling this method.
75   ///
76   /*--cef(optional_param=request_context)--*/
77   static CefRefPtr<CefURLRequest> Create(
78       CefRefPtr<CefRequest> request,
79       CefRefPtr<CefURLRequestClient> client,
80       CefRefPtr<CefRequestContext> request_context);
81 
82   ///
83   // Returns the request object used to create this URL request. The returned
84   // object is read-only and should not be modified.
85   ///
86   /*--cef()--*/
87   virtual CefRefPtr<CefRequest> GetRequest() = 0;
88 
89   ///
90   // Returns the client.
91   ///
92   /*--cef()--*/
93   virtual CefRefPtr<CefURLRequestClient> GetClient() = 0;
94 
95   ///
96   // Returns the request status.
97   ///
98   /*--cef(default_retval=UR_UNKNOWN)--*/
99   virtual Status GetRequestStatus() = 0;
100 
101   ///
102   // Returns the request error if status is UR_CANCELED or UR_FAILED, or 0
103   // otherwise.
104   ///
105   /*--cef(default_retval=ERR_NONE)--*/
106   virtual ErrorCode GetRequestError() = 0;
107 
108   ///
109   // Returns the response, or NULL if no response information is available.
110   // Response information will only be available after the upload has completed.
111   // The returned object is read-only and should not be modified.
112   ///
113   /*--cef()--*/
114   virtual CefRefPtr<CefResponse> GetResponse() = 0;
115 
116   ///
117   // Returns true if the response body was served from the cache. This includes
118   // responses for which revalidation was required.
119   ///
120   /*--cef()--*/
121   virtual bool ResponseWasCached() = 0;
122 
123   ///
124   // Cancel the request.
125   ///
126   /*--cef()--*/
127   virtual void Cancel() = 0;
128 };
129 
130 ///
131 // Interface that should be implemented by the CefURLRequest client. The
132 // methods of this class will be called on the same thread that created the
133 // request unless otherwise documented.
134 ///
135 /*--cef(source=client)--*/
136 class CefURLRequestClient : public virtual CefBaseRefCounted {
137  public:
138   ///
139   // Notifies the client that the request has completed. Use the
140   // CefURLRequest::GetRequestStatus method to determine if the request was
141   // successful or not.
142   ///
143   /*--cef()--*/
144   virtual void OnRequestComplete(CefRefPtr<CefURLRequest> request) = 0;
145 
146   ///
147   // Notifies the client of upload progress. |current| denotes the number of
148   // bytes sent so far and |total| is the total size of uploading data (or -1 if
149   // chunked upload is enabled). This method will only be called if the
150   // UR_FLAG_REPORT_UPLOAD_PROGRESS flag is set on the request.
151   ///
152   /*--cef()--*/
153   virtual void OnUploadProgress(CefRefPtr<CefURLRequest> request,
154                                 int64 current,
155                                 int64 total) = 0;
156 
157   ///
158   // Notifies the client of download progress. |current| denotes the number of
159   // bytes received up to the call and |total| is the expected total size of the
160   // response (or -1 if not determined).
161   ///
162   /*--cef()--*/
163   virtual void OnDownloadProgress(CefRefPtr<CefURLRequest> request,
164                                   int64 current,
165                                   int64 total) = 0;
166 
167   ///
168   // Called when some part of the response is read. |data| contains the current
169   // bytes received since the last call. This method will not be called if the
170   // UR_FLAG_NO_DOWNLOAD_DATA flag is set on the request.
171   ///
172   /*--cef()--*/
173   virtual void OnDownloadData(CefRefPtr<CefURLRequest> request,
174                               const void* data,
175                               size_t data_length) = 0;
176 
177   ///
178   // Called on the IO thread when the browser needs credentials from the user.
179   // |isProxy| indicates whether the host is a proxy server. |host| contains the
180   // hostname and |port| contains the port number. Return true to continue the
181   // request and call CefAuthCallback::Continue() when the authentication
182   // information is available. If the request has an associated browser/frame
183   // then returning false will result in a call to GetAuthCredentials on the
184   // CefRequestHandler associated with that browser, if any. Otherwise,
185   // returning false will cancel the request immediately. This method will only
186   // be called for requests initiated from the browser process.
187   ///
188   /*--cef(optional_param=realm)--*/
189   virtual bool GetAuthCredentials(bool isProxy,
190                                   const CefString& host,
191                                   int port,
192                                   const CefString& realm,
193                                   const CefString& scheme,
194                                   CefRefPtr<CefAuthCallback> callback) = 0;
195 };
196 
197 #endif  // CEF_INCLUDE_CEF_URLREQUEST_H_
198