Add NetworkService support for CefURLRequest (see issue #2622).

Requests created using CefURLRequest::Create are not associated with a
browser/frame. When originating from the render process these requests cannot be
intercepted and consequently only http(s) and blob requests are supported. To
work around this limitation a new CefFrame::CreateURLRequest method has been
added that allows the request to be associated with that browser/frame for
interception purposes.

This change also fixes an issue with the NetworkService implementation where
redirected requests could result in two parallel requests being sent to the
target server.

To test: URLRequestTest.* tests pass with NetworkService enabled.
This commit is contained in:
Marshall Greenblatt
2019-05-10 18:14:48 -04:00
parent f9b042c375
commit ba0e1b5719
43 changed files with 1637 additions and 344 deletions

View File

@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=d3fcf9a928adb588443a52d82a48c188a67d3231$
// $hash=4e8384d7f289708b09f08be98c5477f2be3fde97$
//
#ifndef CEF_INCLUDE_CAPI_CEF_FRAME_CAPI_H_
@ -51,6 +51,8 @@ extern "C" {
#endif
struct _cef_browser_t;
struct _cef_urlrequest_client_t;
struct _cef_urlrequest_t;
struct _cef_v8context_t;
///
@ -215,6 +217,33 @@ typedef struct _cef_frame_t {
///
void(CEF_CALLBACK* visit_dom)(struct _cef_frame_t* self,
struct _cef_domvisitor_t* visitor);
///
// Create a new URL request that will be treated as originating from this
// frame and the associated browser. This request may be intercepted by the
// client via cef_resource_request_handler_t or cef_scheme_handler_factory_t.
// Use cef_urlrequest_t::Create instead if you do not want the request to have
// this association, in which case it may be handled differently (see
// documentation on that function). Requests may originate from both the
// browser process and the render process.
//
// For requests originating from the browser process:
// - POST data may only contain a single element of type PDE_TYPE_FILE or
// PDE_TYPE_BYTES.
// For requests originating from the render process:
// - POST data may only contain a single element of type PDE_TYPE_BYTES.
// - If the response contains Content-Disposition or Mime-Type header values
// that would not normally be rendered then the response may receive
// special handling inside the browser (for example, via the file download
// code path instead of the URL request code path).
//
// The |request| object will be marked as read-only after calling this
// function.
///
struct _cef_urlrequest_t*(CEF_CALLBACK* create_urlrequest)(
struct _cef_frame_t* self,
struct _cef_request_t* request,
struct _cef_urlrequest_client_t* client);
} cef_frame_t;
#ifdef __cplusplus

View File

@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=240893b4019b0bf8c69ffc1682ddabcacabcb3e4$
// $hash=d3a339e3f85077d971e5814eb5a164a87c647810$
//
#ifndef CEF_INCLUDE_CAPI_CEF_REQUEST_CONTEXT_HANDLER_CAPI_H_
@ -101,16 +101,16 @@ typedef struct _cef_request_context_handler_t {
///
// Called on the browser process IO thread before a resource request is
// initiated. The |browser| and |frame| values represent the source of the
// request, and may be NULL for requests originating from service workers.
// |request| represents the request contents and cannot be modified in this
// callback. |is_navigation| will be true (1) if the resource request is a
// navigation. |is_download| will be true (1) if the resource request is a
// download. |request_initiator| is the origin (scheme + domain) of the page
// that initiated the request. Set |disable_default_handling| to true (1) to
// disable default handling of the request, in which case it will need to be
// handled via cef_resource_request_handler_t::GetResourceHandler or it will
// be canceled. To allow the resource load to proceed with default handling
// return NULL. To specify a handler for the resource return a
// request, and may be NULL for requests originating from service workers or
// cef_urlrequest_t. |request| represents the request contents and cannot be
// modified in this callback. |is_navigation| will be true (1) if the resource
// request is a navigation. |is_download| will be true (1) if the resource
// request is a download. |request_initiator| is the origin (scheme + domain)
// of the page that initiated the request. Set |disable_default_handling| to
// true (1) to disable default handling of the request, in which case it will
// need to be handled via cef_resource_request_handler_t::GetResourceHandler
// or it will be canceled. To allow the resource load to proceed with default
// handling return NULL. To specify a handler for the resource return a
// cef_resource_request_handler_t object. This function will not be called if
// the client associated with |browser| returns a non-NULL value from
// cef_request_tHandler::GetResourceRequestHandler for the same request

View File

@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=07e185ca89ea4b4db129a5d3650a55311e582fc4$
// $hash=8d92ad3e0836dffa44a4b35a6b277e963af8144c$
//
#ifndef CEF_INCLUDE_CAPI_CEF_RESOURCE_REQUEST_HANDLER_CAPI_H_
@ -70,9 +70,10 @@ typedef struct _cef_resource_request_handler_t {
///
// Called on the IO thread before a resource request is loaded. The |browser|
// and |frame| values represent the source of the request, and may be NULL for
// requests originating from service workers. To optionally filter cookies for
// the request return a cef_cookie_access_filter_t object. The |request|
// object cannot not be modified in this callback.
// requests originating from service workers or cef_urlrequest_t. To
// optionally filter cookies for the request return a
// cef_cookie_access_filter_t object. The |request| object cannot not be
// modified in this callback.
///
struct _cef_cookie_access_filter_t*(CEF_CALLBACK* get_cookie_access_filter)(
struct _cef_resource_request_handler_t* self,
@ -83,12 +84,12 @@ typedef struct _cef_resource_request_handler_t {
///
// Called on the IO thread before a resource request is loaded. The |browser|
// and |frame| values represent the source of the request, and may be NULL for
// requests originating from service workers. To redirect or change the
// resource load optionally modify |request|. Modification of the request URL
// will be treated as a redirect. Return RV_CONTINUE to continue the request
// immediately. Return RV_CONTINUE_ASYNC and call cef_request_tCallback::
// cont() at a later time to continue or cancel the request asynchronously.
// Return RV_CANCEL to cancel the request immediately.
// requests originating from service workers or cef_urlrequest_t. To redirect
// or change the resource load optionally modify |request|. Modification of
// the request URL will be treated as a redirect. Return RV_CONTINUE to
// continue the request immediately. Return RV_CONTINUE_ASYNC and call
// cef_request_tCallback:: cont() at a later time to continue or cancel the
// request asynchronously. Return RV_CANCEL to cancel the request immediately.
//
///
cef_return_value_t(CEF_CALLBACK* on_before_resource_load)(
@ -101,10 +102,10 @@ typedef struct _cef_resource_request_handler_t {
///
// Called on the IO thread before a resource is loaded. The |browser| and
// |frame| values represent the source of the request, and may be NULL for
// requests originating from service workers. To allow the resource to load
// using the default network loader return NULL. To specify a handler for the
// resource return a cef_resource_handler_t object. The |request| object
// cannot not be modified in this callback.
// requests originating from service workers or cef_urlrequest_t. To allow the
// resource to load using the default network loader return NULL. To specify a
// handler for the resource return a cef_resource_handler_t object. The
// |request| object cannot not be modified in this callback.
///
struct _cef_resource_handler_t*(CEF_CALLBACK* get_resource_handler)(
struct _cef_resource_request_handler_t* self,
@ -115,11 +116,12 @@ typedef struct _cef_resource_request_handler_t {
///
// Called on the IO thread when a resource load is redirected. The |browser|
// and |frame| values represent the source of the request, and may be NULL for
// requests originating from service workers. The |request| parameter will
// contain the old URL and other request-related information. The |response|
// parameter will contain the response that resulted in the redirect. The
// |new_url| parameter will contain the new URL and can be changed if desired.
// The |request| and |response| objects cannot be modified in this callback.
// requests originating from service workers or cef_urlrequest_t. The
// |request| parameter will contain the old URL and other request-related
// information. The |response| parameter will contain the response that
// resulted in the redirect. The |new_url| parameter will contain the new URL
// and can be changed if desired. The |request| and |response| objects cannot
// be modified in this callback.
///
void(CEF_CALLBACK* on_resource_redirect)(
struct _cef_resource_request_handler_t* self,
@ -132,12 +134,12 @@ typedef struct _cef_resource_request_handler_t {
///
// Called on the IO thread when a resource response is received. The |browser|
// and |frame| values represent the source of the request, and may be NULL for
// requests originating from service workers. To allow the resource load to
// proceed without modification return false (0). To redirect or retry the
// resource load optionally modify |request| and return true (1). Modification
// of the request URL will be treated as a redirect. Requests handled using
// the default network loader cannot be redirected in this callback. The
// |response| object cannot be modified in this callback.
// requests originating from service workers or cef_urlrequest_t. To allow the
// resource load to proceed without modification return false (0). To redirect
// or retry the resource load optionally modify |request| and return true (1).
// Modification of the request URL will be treated as a redirect. Requests
// handled using the default network loader cannot be redirected in this
// callback. The |response| object cannot be modified in this callback.
//
// WARNING: Redirecting using this function is deprecated. Use
// OnBeforeResourceLoad or GetResourceHandler to perform redirects.
@ -152,9 +154,9 @@ typedef struct _cef_resource_request_handler_t {
///
// Called on the IO thread to optionally filter resource response content. The
// |browser| and |frame| values represent the source of the request, and may
// be NULL for requests originating from service workers. |request| and
// |response| represent the request and response respectively and cannot be
// modified in this callback.
// be NULL for requests originating from service workers or cef_urlrequest_t.
// |request| and |response| represent the request and response respectively
// and cannot be modified in this callback.
///
struct _cef_response_filter_t*(CEF_CALLBACK* get_resource_response_filter)(
struct _cef_resource_request_handler_t* self,
@ -166,10 +168,11 @@ typedef struct _cef_resource_request_handler_t {
///
// Called on the IO thread when a resource load has completed. The |browser|
// and |frame| values represent the source of the request, and may be NULL for
// requests originating from service workers. |request| and |response|
// represent the request and response respectively and cannot be modified in
// this callback. |status| indicates the load completion status.
// |received_content_length| is the number of response bytes actually read.
// requests originating from service workers or cef_urlrequest_t. |request|
// and |response| represent the request and response respectively and cannot
// be modified in this callback. |status| indicates the load completion
// status. |received_content_length| is the number of response bytes actually
// read.
///
void(CEF_CALLBACK* on_resource_load_complete)(
struct _cef_resource_request_handler_t* self,
@ -184,11 +187,11 @@ typedef struct _cef_resource_request_handler_t {
// Called on the IO thread to handle requests for URLs with an unknown
// protocol component. The |browser| and |frame| values represent the source
// of the request, and may be NULL for requests originating from service
// workers. |request| cannot be modified in this callback. Set
// |allow_os_execution| to true (1) 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.
// workers or cef_urlrequest_t. |request| cannot be modified in this callback.
// Set |allow_os_execution| to true (1) 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.
///
void(CEF_CALLBACK* on_protocol_execution)(
struct _cef_resource_request_handler_t* self,
@ -212,9 +215,9 @@ typedef struct _cef_cookie_access_filter_t {
///
// Called on the IO thread before a resource request is sent. The |browser|
// and |frame| values represent the source of the request, and may be NULL for
// requests originating from service workers. |request| cannot be modified in
// this callback. Return true (1) if the specified cookie can be sent with the
// request or false (0) otherwise.
// requests originating from service workers or cef_urlrequest_t. |request|
// cannot be modified in this callback. Return true (1) if the specified
// cookie can be sent with the request or false (0) otherwise.
///
int(CEF_CALLBACK* can_send_cookie)(struct _cef_cookie_access_filter_t* self,
struct _cef_browser_t* browser,
@ -225,9 +228,10 @@ typedef struct _cef_cookie_access_filter_t {
///
// Called on the IO thread after a resource response is received. The
// |browser| and |frame| values represent the source of the request, and may
// be NULL for requests originating from service workers. |request| cannot be
// modified in this callback. Return true (1) if the specified cookie returned
// with the response can be saved or false (0) otherwise.
// be NULL for requests originating from service workers or cef_urlrequest_t.
// |request| cannot be modified in this callback. Return true (1) if the
// specified cookie returned with the response can be saved or false (0)
// otherwise.
///
int(CEF_CALLBACK* can_save_cookie)(struct _cef_cookie_access_filter_t* self,
struct _cef_browser_t* browser,

View File

@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=fa6b1185c566277ff593e7e537dff2b8085d1f3a$
// $hash=3d31b2d1bad50deeb68a5e6318344024c2f3f5be$
//
#ifndef CEF_INCLUDE_CAPI_CEF_URLREQUEST_CAPI_H_
@ -112,19 +112,25 @@ typedef struct _cef_urlrequest_t {
} cef_urlrequest_t;
///
// Create a new URL request. Only GET, POST, HEAD, DELETE and PUT request
// functions are supported. Multiple post data elements are not supported and
// elements of type PDE_TYPE_FILE are only supported for requests originating
// from the browser process. Requests originating from the render process will
// receive the same handling as requests originating from Web content -- if the
// response contains Content-Disposition or Mime-Type header values that would
// not normally be rendered then the response may receive special handling
// inside the browser (for example, via the file download code path instead of
// the URL request code path). The |request| object will be marked as read-only
// after calling this function. In the browser process if |request_context| is
// NULL the global request context will be used. In the render process
// |request_context| must be NULL and the context associated with the current
// renderer process' browser will be used.
// Create a new URL request that is not associated with a specific browser or
// frame. Use cef_frame_t::CreateURLRequest instead if you want the request to
// have this association, in which case it may be handled differently (see
// documentation on that function). Requests may originate from the both browser
// process and the render process.
//
// For requests originating from the browser process:
// - It may be intercepted by the client via CefResourceRequestHandler or
// CefSchemeHandlerFactory.
// - POST data may only contain only a single element of type PDE_TYPE_FILE
// or PDE_TYPE_BYTES.
// - If |request_context| is empty the global request context will be used.
// For requests originating from the render process:
// - It cannot be intercepted by the client so only http(s) and blob schemes
// are supported.
// - POST data may only contain a single element of type PDE_TYPE_BYTES.
// - The |request_context| parameter must be NULL.
//
// The |request| object will be marked as read-only after calling this function.
///
CEF_EXPORT cef_urlrequest_t* cef_urlrequest_create(
struct _cef_request_t* request,