• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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_RESOURCE_REQUEST_HANDLER_H_
38 #define CEF_INCLUDE_CEF_RESOURCE_REQUEST_HANDLER_H_
39 #pragma once
40 
41 #include "include/cef_base.h"
42 #include "include/cef_browser.h"
43 #include "include/cef_frame.h"
44 #include "include/cef_request.h"
45 #include "include/cef_request_callback.h"
46 #include "include/cef_resource_handler.h"
47 #include "include/cef_response.h"
48 #include "include/cef_response_filter.h"
49 
50 class CefCookieAccessFilter;
51 
52 ///
53 // Implement this interface to handle events related to browser requests. The
54 // methods of this class will be called on the IO thread unless otherwise
55 // indicated.
56 ///
57 /*--cef(source=client,no_debugct_check)--*/
58 class CefResourceRequestHandler : public virtual CefBaseRefCounted {
59  public:
60   typedef cef_return_value_t ReturnValue;
61   typedef cef_urlrequest_status_t URLRequestStatus;
62 
63   ///
64   // Called on the IO thread before a resource request is loaded. The |browser|
65   // and |frame| values represent the source of the request, and may be NULL for
66   // requests originating from service workers or CefURLRequest. To optionally
67   // filter cookies for the request return a CefCookieAccessFilter object. The
68   // |request| object cannot not be modified in this callback.
69   ///
70   /*--cef(optional_param=browser,optional_param=frame)--*/
GetCookieAccessFilter(CefRefPtr<CefBrowser> browser,CefRefPtr<CefFrame> frame,CefRefPtr<CefRequest> request)71   virtual CefRefPtr<CefCookieAccessFilter> GetCookieAccessFilter(
72       CefRefPtr<CefBrowser> browser,
73       CefRefPtr<CefFrame> frame,
74       CefRefPtr<CefRequest> request) {
75     return nullptr;
76   }
77 
78   ///
79   // Called on the IO thread before a resource request is loaded. The |browser|
80   // and |frame| values represent the source of the request, and may be NULL for
81   // requests originating from service workers or CefURLRequest. To redirect or
82   // change the resource load optionally modify |request|. Modification of the
83   // request URL will be treated as a redirect. Return RV_CONTINUE to continue
84   // the request immediately. Return RV_CONTINUE_ASYNC and call
85   // CefRequestCallback:: Continue() at a later time to continue or cancel the
86   // request asynchronously. Return RV_CANCEL to cancel the request immediately.
87   //
88   ///
89   /*--cef(optional_param=browser,optional_param=frame,
90           default_retval=RV_CONTINUE)--*/
OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,CefRefPtr<CefFrame> frame,CefRefPtr<CefRequest> request,CefRefPtr<CefRequestCallback> callback)91   virtual ReturnValue OnBeforeResourceLoad(
92       CefRefPtr<CefBrowser> browser,
93       CefRefPtr<CefFrame> frame,
94       CefRefPtr<CefRequest> request,
95       CefRefPtr<CefRequestCallback> callback) {
96     return RV_CONTINUE;
97   }
98 
99   ///
100   // Called on the IO thread before a resource is loaded. The |browser| and
101   // |frame| values represent the source of the request, and may be NULL for
102   // requests originating from service workers or CefURLRequest. To allow the
103   // resource to load using the default network loader return NULL. To specify a
104   // handler for the resource return a CefResourceHandler object. The |request|
105   // object cannot not be modified in this callback.
106   ///
107   /*--cef(optional_param=browser,optional_param=frame)--*/
GetResourceHandler(CefRefPtr<CefBrowser> browser,CefRefPtr<CefFrame> frame,CefRefPtr<CefRequest> request)108   virtual CefRefPtr<CefResourceHandler> GetResourceHandler(
109       CefRefPtr<CefBrowser> browser,
110       CefRefPtr<CefFrame> frame,
111       CefRefPtr<CefRequest> request) {
112     return nullptr;
113   }
114 
115   ///
116   // Called on the IO thread when a resource load is redirected. The |browser|
117   // and |frame| values represent the source of the request, and may be NULL for
118   // requests originating from service workers or CefURLRequest. The |request|
119   // parameter will contain the old URL and other request-related information.
120   // The |response| parameter will contain the response that resulted in the
121   // redirect. The |new_url| parameter will contain the new URL and can be
122   // changed if desired. The |request| and |response| objects cannot be modified
123   // in this callback.
124   ///
125   /*--cef(optional_param=browser,optional_param=frame)--*/
OnResourceRedirect(CefRefPtr<CefBrowser> browser,CefRefPtr<CefFrame> frame,CefRefPtr<CefRequest> request,CefRefPtr<CefResponse> response,CefString & new_url)126   virtual void OnResourceRedirect(CefRefPtr<CefBrowser> browser,
127                                   CefRefPtr<CefFrame> frame,
128                                   CefRefPtr<CefRequest> request,
129                                   CefRefPtr<CefResponse> response,
130                                   CefString& new_url) {}
131 
132   ///
133   // Called on the IO thread when a resource response is received. The |browser|
134   // and |frame| values represent the source of the request, and may be NULL for
135   // requests originating from service workers or CefURLRequest. To allow the
136   // resource load to proceed without modification return false. To redirect or
137   // retry the resource load optionally modify |request| and return true.
138   // Modification of the request URL will be treated as a redirect. Requests
139   // handled using the default network loader cannot be redirected in this
140   // callback. The |response| object cannot be modified in this callback.
141   //
142   // WARNING: Redirecting using this method is deprecated. Use
143   // OnBeforeResourceLoad or GetResourceHandler to perform redirects.
144   ///
145   /*--cef(optional_param=browser,optional_param=frame)--*/
OnResourceResponse(CefRefPtr<CefBrowser> browser,CefRefPtr<CefFrame> frame,CefRefPtr<CefRequest> request,CefRefPtr<CefResponse> response)146   virtual bool OnResourceResponse(CefRefPtr<CefBrowser> browser,
147                                   CefRefPtr<CefFrame> frame,
148                                   CefRefPtr<CefRequest> request,
149                                   CefRefPtr<CefResponse> response) {
150     return false;
151   }
152 
153   ///
154   // Called on the IO thread to optionally filter resource response content. The
155   // |browser| and |frame| values represent the source of the request, and may
156   // be NULL for requests originating from service workers or CefURLRequest.
157   // |request| and |response| represent the request and response respectively
158   // and cannot be modified in this callback.
159   ///
160   /*--cef(optional_param=browser,optional_param=frame)--*/
GetResourceResponseFilter(CefRefPtr<CefBrowser> browser,CefRefPtr<CefFrame> frame,CefRefPtr<CefRequest> request,CefRefPtr<CefResponse> response)161   virtual CefRefPtr<CefResponseFilter> GetResourceResponseFilter(
162       CefRefPtr<CefBrowser> browser,
163       CefRefPtr<CefFrame> frame,
164       CefRefPtr<CefRequest> request,
165       CefRefPtr<CefResponse> response) {
166     return nullptr;
167   }
168 
169   ///
170   // Called on the IO thread when a resource load has completed. The |browser|
171   // and |frame| values represent the source of the request, and may be NULL for
172   // requests originating from service workers or CefURLRequest. |request| and
173   // |response| represent the request and response respectively and cannot be
174   // modified in this callback. |status| indicates the load completion status.
175   // |received_content_length| is the number of response bytes actually read.
176   // This method will be called for all requests, including requests that are
177   // aborted due to CEF shutdown or destruction of the associated browser. In
178   // cases where the associated browser is destroyed this callback may arrive
179   // after the CefLifeSpanHandler::OnBeforeClose callback for that browser. The
180   // CefFrame::IsValid method can be used to test for this situation, and care
181   // should be taken not to call |browser| or |frame| methods that modify state
182   // (like LoadURL, SendProcessMessage, etc.) if the frame is invalid.
183   ///
184   /*--cef(optional_param=browser,optional_param=frame)--*/
OnResourceLoadComplete(CefRefPtr<CefBrowser> browser,CefRefPtr<CefFrame> frame,CefRefPtr<CefRequest> request,CefRefPtr<CefResponse> response,URLRequestStatus status,int64 received_content_length)185   virtual void OnResourceLoadComplete(CefRefPtr<CefBrowser> browser,
186                                       CefRefPtr<CefFrame> frame,
187                                       CefRefPtr<CefRequest> request,
188                                       CefRefPtr<CefResponse> response,
189                                       URLRequestStatus status,
190                                       int64 received_content_length) {}
191 
192   ///
193   // Called on the IO thread to handle requests for URLs with an unknown
194   // protocol component. The |browser| and |frame| values represent the source
195   // of the request, and may be NULL for requests originating from service
196   // workers or CefURLRequest. |request| cannot be modified in this callback.
197   // Set |allow_os_execution| to true to attempt execution via the registered OS
198   // protocol handler, if any.
199   // SECURITY WARNING: YOU SHOULD USE THIS METHOD TO ENFORCE RESTRICTIONS BASED
200   // ON SCHEME, HOST OR OTHER URL ANALYSIS BEFORE ALLOWING OS EXECUTION.
201   ///
202   /*--cef(optional_param=browser,optional_param=frame)--*/
OnProtocolExecution(CefRefPtr<CefBrowser> browser,CefRefPtr<CefFrame> frame,CefRefPtr<CefRequest> request,bool & allow_os_execution)203   virtual void OnProtocolExecution(CefRefPtr<CefBrowser> browser,
204                                    CefRefPtr<CefFrame> frame,
205                                    CefRefPtr<CefRequest> request,
206                                    bool& allow_os_execution) {}
207 };
208 
209 ///
210 // Implement this interface to filter cookies that may be sent or received from
211 // resource requests. The methods of this class will be called on the IO thread
212 // unless otherwise indicated.
213 ///
214 /*--cef(source=client,no_debugct_check)--*/
215 class CefCookieAccessFilter : public virtual CefBaseRefCounted {
216  public:
217   ///
218   // Called on the IO thread before a resource request is sent. The |browser|
219   // and |frame| values represent the source of the request, and may be NULL for
220   // requests originating from service workers or CefURLRequest. |request|
221   // cannot be modified in this callback. Return true if the specified cookie
222   // can be sent with the request or false otherwise.
223   ///
224   /*--cef(optional_param=browser,optional_param=frame)--*/
CanSendCookie(CefRefPtr<CefBrowser> browser,CefRefPtr<CefFrame> frame,CefRefPtr<CefRequest> request,const CefCookie & cookie)225   virtual bool CanSendCookie(CefRefPtr<CefBrowser> browser,
226                              CefRefPtr<CefFrame> frame,
227                              CefRefPtr<CefRequest> request,
228                              const CefCookie& cookie) {
229     return true;
230   }
231 
232   ///
233   // Called on the IO thread after a resource response is received. The
234   // |browser| and |frame| values represent the source of the request, and may
235   // be NULL for requests originating from service workers or CefURLRequest.
236   // |request| cannot be modified in this callback. Return true if the specified
237   // cookie returned with the response can be saved or false otherwise.
238   ///
239   /*--cef(optional_param=browser,optional_param=frame)--*/
CanSaveCookie(CefRefPtr<CefBrowser> browser,CefRefPtr<CefFrame> frame,CefRefPtr<CefRequest> request,CefRefPtr<CefResponse> response,const CefCookie & cookie)240   virtual bool CanSaveCookie(CefRefPtr<CefBrowser> browser,
241                              CefRefPtr<CefFrame> frame,
242                              CefRefPtr<CefRequest> request,
243                              CefRefPtr<CefResponse> response,
244                              const CefCookie& cookie) {
245     return true;
246   }
247 };
248 
249 #endif  // CEF_INCLUDE_CEF_RESOURCE_REQUEST_HANDLER_H_
250