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_REQUEST_HANDLER_H_ 38 #define CEF_INCLUDE_CEF_REQUEST_HANDLER_H_ 39 #pragma once 40 41 #include <vector> 42 43 #include "include/cef_auth_callback.h" 44 #include "include/cef_base.h" 45 #include "include/cef_browser.h" 46 #include "include/cef_callback.h" 47 #include "include/cef_frame.h" 48 #include "include/cef_request.h" 49 #include "include/cef_resource_request_handler.h" 50 #include "include/cef_ssl_info.h" 51 #include "include/cef_x509_certificate.h" 52 53 /// 54 // Callback interface used to select a client certificate for authentication. 55 /// 56 /*--cef(source=library)--*/ 57 class CefSelectClientCertificateCallback : public virtual CefBaseRefCounted { 58 public: 59 /// 60 // Chooses the specified certificate for client certificate authentication. 61 // NULL value means that no client certificate should be used. 62 /// 63 /*--cef(optional_param=cert)--*/ 64 virtual void Select(CefRefPtr<CefX509Certificate> cert) = 0; 65 }; 66 67 /// 68 // Implement this interface to handle events related to browser requests. The 69 // methods of this class will be called on the thread indicated. 70 /// 71 /*--cef(source=client)--*/ 72 class CefRequestHandler : public virtual CefBaseRefCounted { 73 public: 74 typedef cef_termination_status_t TerminationStatus; 75 typedef cef_window_open_disposition_t WindowOpenDisposition; 76 typedef std::vector<CefRefPtr<CefX509Certificate>> X509CertificateList; 77 78 /// 79 // Called on the UI thread before browser navigation. Return true to cancel 80 // the navigation or false to allow the navigation to proceed. The |request| 81 // object cannot be modified in this callback. 82 // CefLoadHandler::OnLoadingStateChange will be called twice in all cases. 83 // If the navigation is allowed CefLoadHandler::OnLoadStart and 84 // CefLoadHandler::OnLoadEnd will be called. If the navigation is canceled 85 // CefLoadHandler::OnLoadError will be called with an |errorCode| value of 86 // ERR_ABORTED. The |user_gesture| value will be true if the browser 87 // navigated via explicit user gesture (e.g. clicking a link) or false if it 88 // navigated automatically (e.g. via the DomContentLoaded event). 89 /// 90 /*--cef()--*/ OnBeforeBrowse(CefRefPtr<CefBrowser> browser,CefRefPtr<CefFrame> frame,CefRefPtr<CefRequest> request,bool user_gesture,bool is_redirect)91 virtual bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser, 92 CefRefPtr<CefFrame> frame, 93 CefRefPtr<CefRequest> request, 94 bool user_gesture, 95 bool is_redirect) { 96 return false; 97 } 98 99 /// 100 // Called on the UI thread before OnBeforeBrowse in certain limited cases 101 // where navigating a new or different browser might be desirable. This 102 // includes user-initiated navigation that might open in a special way (e.g. 103 // links clicked via middle-click or ctrl + left-click) and certain types of 104 // cross-origin navigation initiated from the renderer process (e.g. 105 // navigating the top-level frame to/from a file URL). The |browser| and 106 // |frame| values represent the source of the navigation. The 107 // |target_disposition| value indicates where the user intended to navigate 108 // the browser based on standard Chromium behaviors (e.g. current tab, 109 // new tab, etc). The |user_gesture| value will be true if the browser 110 // navigated via explicit user gesture (e.g. clicking a link) or false if it 111 // navigated automatically (e.g. via the DomContentLoaded event). Return true 112 // to cancel the navigation or false to allow the navigation to proceed in the 113 // source browser's top-level frame. 114 /// 115 /*--cef()--*/ OnOpenURLFromTab(CefRefPtr<CefBrowser> browser,CefRefPtr<CefFrame> frame,const CefString & target_url,WindowOpenDisposition target_disposition,bool user_gesture)116 virtual bool OnOpenURLFromTab(CefRefPtr<CefBrowser> browser, 117 CefRefPtr<CefFrame> frame, 118 const CefString& target_url, 119 WindowOpenDisposition target_disposition, 120 bool user_gesture) { 121 return false; 122 } 123 124 /// 125 // Called on the browser process IO thread before a resource request is 126 // initiated. The |browser| and |frame| values represent the source of the 127 // request. |request| represents the request contents and cannot be modified 128 // in this callback. |is_navigation| will be true if the resource request is a 129 // navigation. |is_download| will be true if the resource request is a 130 // download. |request_initiator| is the origin (scheme + domain) of the page 131 // that initiated the request. Set |disable_default_handling| to true to 132 // disable default handling of the request, in which case it will need to be 133 // handled via CefResourceRequestHandler::GetResourceHandler or it will be 134 // canceled. To allow the resource load to proceed with default handling 135 // return NULL. To specify a handler for the resource return a 136 // CefResourceRequestHandler object. If this callback returns NULL the same 137 // method will be called on the associated CefRequestContextHandler, if any. 138 /// 139 /*--cef(optional_param=request_initiator)--*/ GetResourceRequestHandler(CefRefPtr<CefBrowser> browser,CefRefPtr<CefFrame> frame,CefRefPtr<CefRequest> request,bool is_navigation,bool is_download,const CefString & request_initiator,bool & disable_default_handling)140 virtual CefRefPtr<CefResourceRequestHandler> GetResourceRequestHandler( 141 CefRefPtr<CefBrowser> browser, 142 CefRefPtr<CefFrame> frame, 143 CefRefPtr<CefRequest> request, 144 bool is_navigation, 145 bool is_download, 146 const CefString& request_initiator, 147 bool& disable_default_handling) { 148 return nullptr; 149 } 150 151 /// 152 // Called on the IO thread when the browser needs credentials from the user. 153 // |origin_url| is the origin making this authentication request. |isProxy| 154 // indicates whether the host is a proxy server. |host| contains the hostname 155 // and |port| contains the port number. |realm| is the realm of the challenge 156 // and may be empty. |scheme| is the authentication scheme used, such as 157 // "basic" or "digest", and will be empty if the source of the request is an 158 // FTP server. Return true to continue the request and call 159 // CefAuthCallback::Continue() either in this method or at a later time when 160 // the authentication information is available. Return false to cancel the 161 // request immediately. 162 /// 163 /*--cef(optional_param=realm,optional_param=scheme)--*/ GetAuthCredentials(CefRefPtr<CefBrowser> browser,const CefString & origin_url,bool isProxy,const CefString & host,int port,const CefString & realm,const CefString & scheme,CefRefPtr<CefAuthCallback> callback)164 virtual bool GetAuthCredentials(CefRefPtr<CefBrowser> browser, 165 const CefString& origin_url, 166 bool isProxy, 167 const CefString& host, 168 int port, 169 const CefString& realm, 170 const CefString& scheme, 171 CefRefPtr<CefAuthCallback> callback) { 172 return false; 173 } 174 175 /// 176 // Called on the IO thread when JavaScript requests a specific storage quota 177 // size via the webkitStorageInfo.requestQuota function. |origin_url| is the 178 // origin of the page making the request. |new_size| is the requested quota 179 // size in bytes. Return true to continue the request and call CefCallback 180 // methods either in this method or at a later time to grant or deny the 181 // request. Return false to cancel the request immediately. 182 /// 183 /*--cef()--*/ OnQuotaRequest(CefRefPtr<CefBrowser> browser,const CefString & origin_url,int64 new_size,CefRefPtr<CefCallback> callback)184 virtual bool OnQuotaRequest(CefRefPtr<CefBrowser> browser, 185 const CefString& origin_url, 186 int64 new_size, 187 CefRefPtr<CefCallback> callback) { 188 return false; 189 } 190 191 /// 192 // Called on the UI thread to handle requests for URLs with an invalid 193 // SSL certificate. Return true and call CefCallback methods either in this 194 // method or at a later time to continue or cancel the request. Return false 195 // to cancel the request immediately. If CefSettings.ignore_certificate_errors 196 // is set all invalid certificates will be accepted without calling this 197 // method. 198 /// 199 /*--cef()--*/ OnCertificateError(CefRefPtr<CefBrowser> browser,cef_errorcode_t cert_error,const CefString & request_url,CefRefPtr<CefSSLInfo> ssl_info,CefRefPtr<CefCallback> callback)200 virtual bool OnCertificateError(CefRefPtr<CefBrowser> browser, 201 cef_errorcode_t cert_error, 202 const CefString& request_url, 203 CefRefPtr<CefSSLInfo> ssl_info, 204 CefRefPtr<CefCallback> callback) { 205 return false; 206 } 207 208 /// 209 // Called on the UI thread when a client certificate is being requested for 210 // authentication. Return false to use the default behavior and automatically 211 // select the first certificate available. Return true and call 212 // CefSelectClientCertificateCallback::Select either in this method or at a 213 // later time to select a certificate. Do not call Select or call it with NULL 214 // to continue without using any certificate. |isProxy| indicates whether the 215 // host is an HTTPS proxy or the origin server. |host| and |port| contains the 216 // hostname and port of the SSL server. |certificates| is the list of 217 // certificates to choose from; this list has already been pruned by Chromium 218 // so that it only contains certificates from issuers that the server trusts. 219 /// 220 /*--cef()--*/ OnSelectClientCertificate(CefRefPtr<CefBrowser> browser,bool isProxy,const CefString & host,int port,const X509CertificateList & certificates,CefRefPtr<CefSelectClientCertificateCallback> callback)221 virtual bool OnSelectClientCertificate( 222 CefRefPtr<CefBrowser> browser, 223 bool isProxy, 224 const CefString& host, 225 int port, 226 const X509CertificateList& certificates, 227 CefRefPtr<CefSelectClientCertificateCallback> callback) { 228 return false; 229 } 230 231 /// 232 // Called on the browser process UI thread when a plugin has crashed. 233 // |plugin_path| is the path of the plugin that crashed. 234 /// 235 /*--cef()--*/ OnPluginCrashed(CefRefPtr<CefBrowser> browser,const CefString & plugin_path)236 virtual void OnPluginCrashed(CefRefPtr<CefBrowser> browser, 237 const CefString& plugin_path) {} 238 239 /// 240 // Called on the browser process UI thread when the render view associated 241 // with |browser| is ready to receive/handle IPC messages in the render 242 // process. 243 /// 244 /*--cef()--*/ OnRenderViewReady(CefRefPtr<CefBrowser> browser)245 virtual void OnRenderViewReady(CefRefPtr<CefBrowser> browser) {} 246 247 /// 248 // Called on the browser process UI thread when the render process 249 // terminates unexpectedly. |status| indicates how the process 250 // terminated. 251 /// 252 /*--cef()--*/ OnRenderProcessTerminated(CefRefPtr<CefBrowser> browser,TerminationStatus status)253 virtual void OnRenderProcessTerminated(CefRefPtr<CefBrowser> browser, 254 TerminationStatus status) {} 255 256 /// 257 // Called on the browser process UI thread when the window.document object of 258 // the main frame has been created. 259 /// 260 /*--cef()--*/ OnDocumentAvailableInMainFrame(CefRefPtr<CefBrowser> browser)261 virtual void OnDocumentAvailableInMainFrame(CefRefPtr<CefBrowser> browser) {} 262 }; 263 264 #endif // CEF_INCLUDE_CEF_REQUEST_HANDLER_H_ 265