Skip to content

Latest commit

 

History

History
264 lines (189 loc) · 9.58 KB

File metadata and controls

264 lines (189 loc) · 9.58 KB

API categories | API index

RequestHandler (interface)

Implement this interface to handle events related to browser requests.

For an example of how to implement handler see cefpython.CreateBrowser(). For a list of all handler interfaces see API > Client handlers.

The RequestHandler tests can be found in the wxpython.py script.

Table of contents:

Callbacks

OnBeforeBrowse

Parameter Type
browser Browser
frame Frame
request Request
isRedirect bool
Return void

Called on the UI thread before browser navigation. Return true to cancel the navigation or false to allow the navigation to proceed. The |request| object cannot be modified in this callback. DisplayHandler.OnLoadingStateChange will be called twice in all cases. If the navigation is allowed LoadHandler.OnLoadStart and OnLoadEnd will be called. If the navigation is canceled LoadHandler.OnLoadError will be called with an |errorCode| value of ERR_ABORTED.

OnBeforeResourceLoad

Parameter Type
browser Browser
frame Frame
request Request
Return bool

Called on the IO thread before a resource request is loaded. The |request| object may be modified. To cancel the request return true otherwise return false.

GetResourceHandler

Parameter Type
browser Browser
frame Frame
request Request
Return ResourceHandler

Called on the IO thread before a resource is loaded. To allow the resource to load normally return None. To specify a handler for the resource return a ResourceHandler object. The |request| object should not be modified in this callback.

The ResourceHandler object is a python class that implements the ResourceHandler callbacks. Remember to keep a strong reference to this object while resource is being loaded.

The GetResourceHandler example can be found in the wxpython-response.py script on Linux.

OnResourceResponse

Return void

Not yet available in CEF 3 (see CEF Issue 515), though it can be emulated, see the comment below.

You can implement this functionality by using ResourceHandler and WebRequest / WebRequestClient. For an example see the _OnResourceResponse() method in the wxpython-response.py script.

OnResourceRedirect

Parameter Type
browser Browser
frame Frame
oldUrl string
newUrlOut list&
Return void

Called on the IO thread when a resource load is redirected. The |oldUrl| parameter will contain the old URL. The newUrlOut[0] parameter will contain the new URL and can be changed if desired.

GetAuthCredentials

Parameter Type
browser Browser
frame Frame
isProxy bool
host string
port int
realm string
scheme string
callback AuthCallback
Return bool

Called on the IO thread when the browser needs credentials from the user. |isProxy| indicates whether the host is a proxy server. |host| contains the hostname and |port| contains the port number. Return true to continue the request and call AuthCallback::Continue() when the authentication information is available. Return false to cancel the request.

The AuthCallback object methods:

  • void Continue(string username, string password)
  • void Cancel()

OnQuotaRequest

Parameter Type
browser Browser
originUrl string
newSize long
callback QuotaCallback
Return bool

Called on the IO thread when javascript requests a specific storage quota size via the webkitStorageInfo.requestQuota function. |originUrl| is the origin of the page making the request. |newSize| is the requested quota size in bytes. Return true and call QuotaCallback::Continue() either in this method or at a later time to grant or deny the request. Return False to cancel the request.

The QuotaCallback object methods:

  • void Continue(bool allow)
  • void Cancel()

GetCookieManager

Parameter Type
browser None
mainUrl string
Return CookieManager

Called on the IO thread to retrieve the cookie manager. |mainUrl| is the URL of the top-level frame. Cookies managers can be unique per browser or shared across multiple browsers. The global cookie manager will be used if this method returns None.

To successfully implement separate cookie manager per browser session, you have to set ApplicationSettings.unique_request_context_per_browser to True. Otherwise the browser param passed to this callback will always be the same first browser that was created using cefpython.CreateBrowserSync.

Popup browsers created javascript's window.open share the same renderer process and request context. If you want to have separate cookie managers for popups created using window.open then you have to implement the LifespanHandler.OnBeforePopup callback. Return True in that callback to cancel popup creation and instead create the window on your own and embed browser in it. The CreateAnotherBrowser function from the wxpython example does that.

IMPORTANT: in an exceptional case the browser parameter could be None, so you should handle such case. During testing this issue did not occur, but it may happen in some yet unknown scenarios.

OnProtocolExecution

Parameter Type
browser Browser
url string
allowExecutionOut list&
Return void

Called on the UI thread to handle requests for URLs with an unknown protocol component. Set allowExecutionOut[0] to True to attempt execution via the registered OS protocol handler, if any. SECURITY WARNING: YOU SHOULD USE THIS METHOD TO ENFORCE RESTRICTIONS BASED ON SCHEME, HOST OR OTHER URL ANALYSIS BEFORE ALLOWING OS EXECUTION.

There's no default implementation for OnProtocolExecution on Linux, you have to make OS system call on your own. You probably also need to use LoadHandler::OnLoadError() when implementing this on Linux.

_OnBeforePluginLoad

Parameter Type
browser Browser
url string
policyUrl string
info WebPluginInfo
Return bool

Called on the browser process IO thread before a plugin is loaded. Return True to block loading of the plugin.

This callback will be executed during browser creation, thus you must call cefpython.SetGlobalClientCallback() to use it. The callback name was prefixed with "_" to distinguish this special behavior.

Plugins are loaded on demand, only when website requires it. This callback is called every time the page tries to load a plugin (perhaps even multiple times per plugin).

_OnCertificateError

Parameter Type
certError NetworkError
requestUrl string
callback AllowCertificateErrorCallback
Return bool

This callback is not associated with any specific browser, thus you must call cefpython.SetGlobalClientCallback() to use it. The callback name was prefixed with "_" to distinguish this special behavior.

Called on the UI thread to handle requests for URLs with an invalid SSL certificate. Return True and call AllowCertificateErrorCallback:: Continue() either in this method or at a later time to continue or cancel the request. Return False to cancel the request immediately. If |callback| is empty the error cannot be recovered from and the request will be canceled automatically. If ApplicationSettings.ignore_certificate_errors is set all invalid certificates will be accepted without calling this method.

The AllowCertificateErrorCallback object methods:

  • void Continue(bool allow)

OnRendererProcessTerminated

Parameter Type
browser Browser
status TerminationStatus
Return void

Called when the render process terminates unexpectedly. |status| indicates how the process terminated.

TerminationStatus constants:

  • cefpython.TS_ABNORMAL_TERMINATION - Non-zero exit status.
  • cefpython.TS_PROCESS_WAS_KILLED - SIGKILL or task manager kill.
  • cefpython.TS_PROCESS_CRASHED - Segmentation fault.

OnPluginCrashed

Parameter Type
browser Browser
pluginPath string
Return void

Called when a plugin has crashed. |pluginPath| is the path of the plugin that crashed.