1 // Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved.
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
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
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.
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.
30 // ---------------------------------------------------------------------------
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.
37 #ifndef CEF_INCLUDE_CEF_URLREQUEST_H_
38 #define CEF_INCLUDE_CEF_URLREQUEST_H_
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"
47 class CefURLRequestClient;
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.
56 /*--cef(source=library)--*/
57 class CefURLRequest : public virtual CefBase {
59 typedef cef_urlrequest_status_t Status;
60 typedef cef_errorcode_t ErrorCode;
63 // Create a new URL request. Only GET, POST, HEAD, DELETE and PUT request
64 // methods are supported. Multiple post data elements are not supported and
65 // elements of type PDE_TYPE_FILE are only supported for requests originating
66 // from the browser process. Requests originating from the render process will
67 // receive the same handling as requests originating from Web content -- if
68 // the response contains Content-Disposition or Mime-Type header values that
69 // would not normally be rendered then the response may receive special
70 // handling inside the browser (for example, via the file download code path
71 // instead of the URL request code path). The |request| object will be marked
72 // as read-only after calling this method. In the browser process if
73 // |request_context| is empty the global request context will be used. In the
74 // render process |request_context| must be empty and the context associated
75 // with the current renderer process' browser will be used.
77 /*--cef(optional_param=request_context)--*/
78 static CefRefPtr<CefURLRequest> Create(
79 CefRefPtr<CefRequest> request,
80 CefRefPtr<CefURLRequestClient> client,
81 CefRefPtr<CefRequestContext> request_context);
84 // Returns the request object used to create this URL request. The returned
85 // object is read-only and should not be modified.
88 virtual CefRefPtr<CefRequest> GetRequest() =0;
91 // Returns the client.
94 virtual CefRefPtr<CefURLRequestClient> GetClient() =0;
97 // Returns the request status.
99 /*--cef(default_retval=UR_UNKNOWN)--*/
100 virtual Status GetRequestStatus() =0;
103 // Returns the request error if status is UR_CANCELED or UR_FAILED, or 0
106 /*--cef(default_retval=ERR_NONE)--*/
107 virtual ErrorCode GetRequestError() =0;
110 // Returns the response, or NULL if no response information is available.
111 // Response information will only be available after the upload has completed.
112 // The returned object is read-only and should not be modified.
115 virtual CefRefPtr<CefResponse> GetResponse() =0;
118 // Cancel the request.
121 virtual void Cancel() =0;
125 // Interface that should be implemented by the CefURLRequest client. The
126 // methods of this class will be called on the same thread that created the
127 // request unless otherwise documented.
129 /*--cef(source=client)--*/
130 class CefURLRequestClient : public virtual CefBase {
133 // Notifies the client that the request has completed. Use the
134 // CefURLRequest::GetRequestStatus method to determine if the request was
135 // successful or not.
138 virtual void OnRequestComplete(CefRefPtr<CefURLRequest> request) =0;
141 // Notifies the client of upload progress. |current| denotes the number of
142 // bytes sent so far and |total| is the total size of uploading data (or -1 if
143 // chunked upload is enabled). This method will only be called if the
144 // UR_FLAG_REPORT_UPLOAD_PROGRESS flag is set on the request.
147 virtual void OnUploadProgress(CefRefPtr<CefURLRequest> request,
152 // Notifies the client of download progress. |current| denotes the number of
153 // bytes received up to the call and |total| is the expected total size of the
154 // response (or -1 if not determined).
157 virtual void OnDownloadProgress(CefRefPtr<CefURLRequest> request,
162 // Called when some part of the response is read. |data| contains the current
163 // bytes received since the last call. This method will not be called if the
164 // UR_FLAG_NO_DOWNLOAD_DATA flag is set on the request.
167 virtual void OnDownloadData(CefRefPtr<CefURLRequest> request,
169 size_t data_length) =0;
172 // Called on the IO thread when the browser needs credentials from the user.
173 // |isProxy| indicates whether the host is a proxy server. |host| contains the
174 // hostname and |port| contains the port number. Return true to continue the
175 // request and call CefAuthCallback::Continue() when the authentication
176 // information is available. Return false to cancel the request. This method
177 // will only be called for requests initiated from the browser process.
179 /*--cef(optional_param=realm)--*/
180 virtual bool GetAuthCredentials(bool isProxy,
181 const CefString& host,
183 const CefString& realm,
184 const CefString& scheme,
185 CefRefPtr<CefAuthCallback> callback) =0;
188 #endif // CEF_INCLUDE_CEF_URLREQUEST_H_