mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-02-16 12:10:41 +01:00
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:
parent
f9b042c375
commit
ba0e1b5719
8
BUILD.gn
8
BUILD.gn
@ -278,8 +278,6 @@ static_library("libcef_static") {
|
||||
"libcef/browser/browser_platform_delegate.cc",
|
||||
"libcef/browser/browser_platform_delegate.h",
|
||||
"libcef/browser/browser_platform_delegate_create.cc",
|
||||
"libcef/browser/browser_urlrequest_impl.cc",
|
||||
"libcef/browser/browser_urlrequest_impl.h",
|
||||
"libcef/browser/browser_util.cc",
|
||||
"libcef/browser/browser_util.h",
|
||||
"libcef/browser/chrome_browser_process_stub.cc",
|
||||
@ -372,6 +370,8 @@ static_library("libcef_static") {
|
||||
"libcef/browser/navigate_params.h",
|
||||
"libcef/browser/navigation_entry_impl.cc",
|
||||
"libcef/browser/navigation_entry_impl.h",
|
||||
"libcef/browser/net/browser_urlrequest_old_impl.cc",
|
||||
"libcef/browser/net/browser_urlrequest_old_impl.h",
|
||||
"libcef/browser/net/chrome_scheme_handler.cc",
|
||||
"libcef/browser/net/chrome_scheme_handler.h",
|
||||
"libcef/browser/net/cookie_manager_old_impl.cc",
|
||||
@ -401,6 +401,8 @@ static_library("libcef_static") {
|
||||
"libcef/browser/net/url_request_manager.h",
|
||||
"libcef/browser/net/url_request_user_data.cc",
|
||||
"libcef/browser/net/url_request_user_data.h",
|
||||
"libcef/browser/net_service/browser_urlrequest_impl.cc",
|
||||
"libcef/browser/net_service/browser_urlrequest_impl.h",
|
||||
"libcef/browser/net_service/cookie_helper.cc",
|
||||
"libcef/browser/net_service/cookie_helper.h",
|
||||
"libcef/browser/net_service/cookie_manager_impl.cc",
|
||||
@ -413,6 +415,8 @@ static_library("libcef_static") {
|
||||
"libcef/browser/net_service/resource_request_handler_wrapper.h",
|
||||
"libcef/browser/net_service/stream_reader_url_loader.cc",
|
||||
"libcef/browser/net_service/stream_reader_url_loader.h",
|
||||
"libcef/browser/net_service/url_loader_factory_getter.cc",
|
||||
"libcef/browser/net_service/url_loader_factory_getter.h",
|
||||
"libcef/browser/origin_whitelist_impl.cc",
|
||||
"libcef/browser/origin_whitelist_impl.h",
|
||||
"libcef/browser/osr/browser_platform_delegate_osr.cc",
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -34,7 +34,7 @@
|
||||
// implementations. See the translator.README.txt file in the tools directory
|
||||
// for more information.
|
||||
//
|
||||
// $hash=dc61bafdca990fc0b1da9ba902dccefb8c8cf38f$
|
||||
// $hash=2fc75812c34a605fb4e67a5942f6597c6dd3be78$
|
||||
//
|
||||
|
||||
#ifndef CEF_INCLUDE_API_HASH_H_
|
||||
@ -47,13 +47,13 @@
|
||||
// way that may cause binary incompatibility with other builds. The universal
|
||||
// hash value will change if any platform is affected whereas the platform hash
|
||||
// values will change only if that particular platform is affected.
|
||||
#define CEF_API_HASH_UNIVERSAL "45812b72803c3a0e84eccfe798fb40c945c85135"
|
||||
#define CEF_API_HASH_UNIVERSAL "f9715e9bc13434498505eecee052706483eb7892"
|
||||
#if defined(OS_WIN)
|
||||
#define CEF_API_HASH_PLATFORM "968d2733802c68469af053b20c4e7e5abd425ee3"
|
||||
#define CEF_API_HASH_PLATFORM "7bd952f75673366dc4834de5e5995798d3db91f0"
|
||||
#elif defined(OS_MACOSX)
|
||||
#define CEF_API_HASH_PLATFORM "244b441b45d676649052f6da646aa0e76e227eb3"
|
||||
#define CEF_API_HASH_PLATFORM "daa91396f67341e7bde65747f69487ecde4e3cf5"
|
||||
#elif defined(OS_LINUX)
|
||||
#define CEF_API_HASH_PLATFORM "3aa82a71e8a2e40c7cf96eee3539b4787d18b7fd"
|
||||
#define CEF_API_HASH_PLATFORM "be8ed9d9ba0b53e18c5c0adae09ff841b1fa7063"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -45,6 +45,8 @@
|
||||
#include "include/cef_string_visitor.h"
|
||||
|
||||
class CefBrowser;
|
||||
class CefURLRequest;
|
||||
class CefURLRequestClient;
|
||||
class CefV8Context;
|
||||
|
||||
///
|
||||
@ -220,6 +222,32 @@ class CefFrame : public virtual CefBaseRefCounted {
|
||||
///
|
||||
/*--cef()--*/
|
||||
virtual void VisitDOM(CefRefPtr<CefDOMVisitor> visitor) = 0;
|
||||
|
||||
///
|
||||
// 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 CefResourceRequestHandler or CefSchemeHandlerFactory. Use
|
||||
// CefURLRequest::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 method). 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 method.
|
||||
///
|
||||
/*--cef()--*/
|
||||
virtual CefRefPtr<CefURLRequest> CreateURLRequest(
|
||||
CefRefPtr<CefRequest> request,
|
||||
CefRefPtr<CefURLRequestClient> client) = 0;
|
||||
};
|
||||
|
||||
#endif // CEF_INCLUDE_CEF_FRAME_H_
|
||||
|
@ -94,12 +94,12 @@ class CefRequestContextHandler : public virtual CefBaseRefCounted {
|
||||
///
|
||||
// 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 if the resource request is a
|
||||
// navigation. |is_download| will be true 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 to
|
||||
// request, and may be NULL for requests originating from service workers or
|
||||
// CefURLRequest. |request| represents the request contents and cannot be
|
||||
// modified in this callback. |is_navigation| will be true if the resource
|
||||
// request is a navigation. |is_download| will be true 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 to
|
||||
// disable default handling of the request, in which case it will need to be
|
||||
// handled via CefResourceRequestHandler::GetResourceHandler or it will be
|
||||
// canceled. To allow the resource load to proceed with default handling
|
||||
|
@ -64,9 +64,9 @@ class CefResourceRequestHandler : public virtual CefBaseRefCounted {
|
||||
///
|
||||
// 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 CefCookieAccessFilter object. The |request| object
|
||||
// cannot not be modified in this callback.
|
||||
// requests originating from service workers or CefURLRequest. To optionally
|
||||
// filter cookies for the request return a CefCookieAccessFilter object. The
|
||||
// |request| object cannot not be modified in this callback.
|
||||
///
|
||||
/*--cef(optional_param=browser,optional_param=frame)--*/
|
||||
virtual CefRefPtr<CefCookieAccessFilter> GetCookieAccessFilter(
|
||||
@ -79,12 +79,12 @@ class CefResourceRequestHandler : public virtual CefBaseRefCounted {
|
||||
///
|
||||
// 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 CefRequestCallback::
|
||||
// Continue() 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 CefURLRequest. 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
|
||||
// CefRequestCallback:: Continue() at a later time to continue or cancel the
|
||||
// request asynchronously. Return RV_CANCEL to cancel the request immediately.
|
||||
//
|
||||
///
|
||||
/*--cef(optional_param=browser,optional_param=frame,
|
||||
@ -100,10 +100,10 @@ class CefResourceRequestHandler : public virtual CefBaseRefCounted {
|
||||
///
|
||||
// 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 CefResourceHandler object. The |request| object cannot
|
||||
// not be modified in this callback.
|
||||
// requests originating from service workers or CefURLRequest. To allow the
|
||||
// resource to load using the default network loader return NULL. To specify a
|
||||
// handler for the resource return a CefResourceHandler object. The |request|
|
||||
// object cannot not be modified in this callback.
|
||||
///
|
||||
/*--cef(optional_param=browser,optional_param=frame)--*/
|
||||
virtual CefRefPtr<CefResourceHandler> GetResourceHandler(
|
||||
@ -116,11 +116,12 @@ class CefResourceRequestHandler : public virtual CefBaseRefCounted {
|
||||
///
|
||||
// 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 CefURLRequest. 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.
|
||||
///
|
||||
/*--cef(optional_param=browser,optional_param=frame)--*/
|
||||
virtual void OnResourceRedirect(CefRefPtr<CefBrowser> browser,
|
||||
@ -132,12 +133,12 @@ class CefResourceRequestHandler : public virtual CefBaseRefCounted {
|
||||
///
|
||||
// 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. To redirect or retry the
|
||||
// resource load optionally modify |request| and return true. 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 CefURLRequest. To allow the
|
||||
// resource load to proceed without modification return false. To redirect or
|
||||
// retry the resource load optionally modify |request| and return true.
|
||||
// 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 method is deprecated. Use
|
||||
// OnBeforeResourceLoad or GetResourceHandler to perform redirects.
|
||||
@ -153,9 +154,9 @@ class CefResourceRequestHandler : public virtual CefBaseRefCounted {
|
||||
///
|
||||
// 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 CefURLRequest.
|
||||
// |request| and |response| represent the request and response respectively
|
||||
// and cannot be modified in this callback.
|
||||
///
|
||||
/*--cef(optional_param=browser,optional_param=frame)--*/
|
||||
virtual CefRefPtr<CefResponseFilter> GetResourceResponseFilter(
|
||||
@ -169,9 +170,9 @@ class CefResourceRequestHandler : public virtual CefBaseRefCounted {
|
||||
///
|
||||
// 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.
|
||||
// requests originating from service workers or CefURLRequest. |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.
|
||||
///
|
||||
/*--cef(optional_param=browser,optional_param=frame)--*/
|
||||
@ -186,8 +187,8 @@ class CefResourceRequestHandler : public virtual CefBaseRefCounted {
|
||||
// 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 to attempt execution via the registered OS
|
||||
// workers or CefURLRequest. |request| cannot be modified in this callback.
|
||||
// Set |allow_os_execution| 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.
|
||||
@ -210,9 +211,9 @@ class CefCookieAccessFilter : public virtual CefBaseRefCounted {
|
||||
///
|
||||
// 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 if the specified cookie can be sent with the
|
||||
// request or false otherwise.
|
||||
// requests originating from service workers or CefURLRequest. |request|
|
||||
// cannot be modified in this callback. Return true if the specified cookie
|
||||
// can be sent with the request or false otherwise.
|
||||
///
|
||||
/*--cef(optional_param=browser,optional_param=frame)--*/
|
||||
virtual bool CanSendCookie(CefRefPtr<CefBrowser> browser,
|
||||
@ -225,9 +226,9 @@ class CefCookieAccessFilter : public virtual CefBaseRefCounted {
|
||||
///
|
||||
// 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 if the specified cookie returned
|
||||
// with the response can be saved or false otherwise.
|
||||
// be NULL for requests originating from service workers or CefURLRequest.
|
||||
// |request| cannot be modified in this callback. Return true if the specified
|
||||
// cookie returned with the response can be saved or false otherwise.
|
||||
///
|
||||
/*--cef(optional_param=browser,optional_param=frame)--*/
|
||||
virtual bool CanSaveCookie(CefRefPtr<CefBrowser> browser,
|
||||
|
@ -60,19 +60,25 @@ class CefURLRequest : public virtual CefBaseRefCounted {
|
||||
typedef cef_errorcode_t ErrorCode;
|
||||
|
||||
///
|
||||
// Create a new URL request. Only GET, POST, HEAD, DELETE and PUT request
|
||||
// methods 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 method. In the browser process if
|
||||
// |request_context| is empty the global request context will be used. In the
|
||||
// render process |request_context| must be empty 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 CefFrame::CreateURLRequest instead if you want the request to
|
||||
// have this association, in which case it may be handled differently (see
|
||||
// documentation on that method). 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 method.
|
||||
///
|
||||
/*--cef(optional_param=request_context)--*/
|
||||
static CefRefPtr<CefURLRequest> Create(
|
||||
|
@ -1868,35 +1868,6 @@ void CefBrowserHostImpl::SendCode(
|
||||
}
|
||||
}
|
||||
|
||||
void CefBrowserHostImpl::ExecuteJavaScriptWithUserGestureForTests(
|
||||
int64 frame_id,
|
||||
const CefString& javascript) {
|
||||
DCHECK(frame_id >= CefFrameHostImpl::kMainFrameId);
|
||||
|
||||
if (!CEF_CURRENTLY_ON_UIT()) {
|
||||
CEF_POST_TASK(
|
||||
CEF_UIT,
|
||||
base::BindOnce(
|
||||
&CefBrowserHostImpl::ExecuteJavaScriptWithUserGestureForTests, this,
|
||||
frame_id, javascript));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!web_contents())
|
||||
return;
|
||||
|
||||
content::RenderFrameHost* rfh;
|
||||
if (frame_id == CefFrameHostImpl::kMainFrameId) {
|
||||
rfh = web_contents()->GetMainFrame();
|
||||
} else {
|
||||
rfh = content::RenderFrameHost::FromID(
|
||||
web_contents()->GetRenderViewHost()->GetProcess()->GetID(), frame_id);
|
||||
}
|
||||
|
||||
if (rfh)
|
||||
rfh->ExecuteJavaScriptWithUserGestureForTests(javascript);
|
||||
}
|
||||
|
||||
void CefBrowserHostImpl::ViewText(const std::string& text) {
|
||||
if (!CEF_CURRENTLY_ON_UIT()) {
|
||||
CEF_POST_TASK(CEF_UIT,
|
||||
|
@ -351,9 +351,6 @@ class CefBrowserHostImpl : public CefBrowserHost,
|
||||
int script_start_line,
|
||||
CefRefPtr<CefResponseManager::Handler> responseHandler);
|
||||
|
||||
void ExecuteJavaScriptWithUserGestureForTests(int64 frame_id,
|
||||
const CefString& javascript);
|
||||
|
||||
// Open the specified text in the default text editor.
|
||||
void ViewText(const std::string& text);
|
||||
|
||||
|
@ -3,12 +3,20 @@
|
||||
// be found in the LICENSE file.
|
||||
|
||||
#include "libcef/browser/frame_host_impl.h"
|
||||
|
||||
#include "include/cef_request.h"
|
||||
#include "include/cef_stream.h"
|
||||
#include "include/cef_v8.h"
|
||||
#include "include/test/cef_test_helpers.h"
|
||||
#include "libcef/browser/browser_host_impl.h"
|
||||
#include "libcef/browser/net/browser_urlrequest_old_impl.h"
|
||||
#include "libcef/browser/net_service/browser_urlrequest_impl.h"
|
||||
#include "libcef/common/cef_messages.h"
|
||||
#include "libcef/common/net_service/util.h"
|
||||
#include "libcef/common/task_runner_impl.h"
|
||||
|
||||
#include "content/public/browser/render_process_host.h"
|
||||
#include "content/public/browser/render_view_host.h"
|
||||
|
||||
namespace {
|
||||
|
||||
@ -235,6 +243,42 @@ void CefFrameHostImpl::VisitDOM(CefRefPtr<CefDOMVisitor> visitor) {
|
||||
NOTREACHED() << "VisitDOM cannot be called from the browser process";
|
||||
}
|
||||
|
||||
CefRefPtr<CefURLRequest> CefFrameHostImpl::CreateURLRequest(
|
||||
CefRefPtr<CefRequest> request,
|
||||
CefRefPtr<CefURLRequestClient> client) {
|
||||
if (!request || !client)
|
||||
return NULL;
|
||||
|
||||
if (!CefTaskRunnerImpl::GetCurrentTaskRunner()) {
|
||||
NOTREACHED() << "called on invalid thread";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CefRefPtr<CefBrowserHostImpl> browser;
|
||||
{
|
||||
base::AutoLock lock_scope(state_lock_);
|
||||
browser = browser_;
|
||||
}
|
||||
|
||||
if (!browser)
|
||||
return NULL;
|
||||
|
||||
auto request_context = browser->request_context();
|
||||
|
||||
if (net_service::IsEnabled()) {
|
||||
CefRefPtr<CefBrowserURLRequest> impl =
|
||||
new CefBrowserURLRequest(this, request, client, request_context);
|
||||
if (impl->Start())
|
||||
return impl.get();
|
||||
} else {
|
||||
CefRefPtr<CefBrowserURLRequestOld> impl =
|
||||
new CefBrowserURLRequestOld(request, client, request_context);
|
||||
if (impl->Start())
|
||||
return impl.get();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CefFrameHostImpl::SendJavaScript(const std::string& jsCode,
|
||||
const std::string& scriptUrl,
|
||||
int startLine) {
|
||||
@ -262,6 +306,23 @@ void CefFrameHostImpl::SendJavaScript(const std::string& jsCode,
|
||||
|
||||
void CefFrameHostImpl::ExecuteJavaScriptWithUserGestureForTests(
|
||||
const CefString& javascript) {
|
||||
if (!CEF_CURRENTLY_ON_UIT()) {
|
||||
CEF_POST_TASK(
|
||||
CEF_UIT,
|
||||
base::BindOnce(
|
||||
&CefFrameHostImpl::ExecuteJavaScriptWithUserGestureForTests, this,
|
||||
javascript));
|
||||
return;
|
||||
}
|
||||
|
||||
content::RenderFrameHost* rfh = GetRenderFrameHost();
|
||||
if (rfh)
|
||||
rfh->ExecuteJavaScriptWithUserGestureForTests(javascript);
|
||||
}
|
||||
|
||||
content::RenderFrameHost* CefFrameHostImpl::GetRenderFrameHost() {
|
||||
CEF_REQUIRE_UIT();
|
||||
|
||||
CefRefPtr<CefBrowserHostImpl> browser;
|
||||
int64 frame_id;
|
||||
|
||||
@ -271,8 +332,18 @@ void CefFrameHostImpl::ExecuteJavaScriptWithUserGestureForTests(
|
||||
frame_id = (is_main_frame_ ? kMainFrameId : frame_id_);
|
||||
}
|
||||
|
||||
if (browser.get() && frame_id != kInvalidFrameId)
|
||||
browser->ExecuteJavaScriptWithUserGestureForTests(frame_id, javascript);
|
||||
if (!browser || frame_id == kInvalidFrameId)
|
||||
return nullptr;
|
||||
|
||||
auto web_contents = browser->web_contents();
|
||||
if (!web_contents)
|
||||
return nullptr;
|
||||
|
||||
if (frame_id == kMainFrameId)
|
||||
return web_contents->GetMainFrame();
|
||||
|
||||
return content::RenderFrameHost::FromID(
|
||||
web_contents->GetRenderViewHost()->GetProcess()->GetID(), frame_id);
|
||||
}
|
||||
|
||||
void CefFrameHostImpl::Detach() {
|
||||
@ -300,5 +371,6 @@ void CefFrameHostImpl::SendCommand(
|
||||
void CefExecuteJavaScriptWithUserGestureForTests(CefRefPtr<CefFrame> frame,
|
||||
const CefString& javascript) {
|
||||
CefFrameHostImpl* impl = static_cast<CefFrameHostImpl*>(frame.get());
|
||||
impl->ExecuteJavaScriptWithUserGestureForTests(javascript);
|
||||
if (impl)
|
||||
impl->ExecuteJavaScriptWithUserGestureForTests(javascript);
|
||||
}
|
||||
|
@ -13,6 +13,10 @@
|
||||
|
||||
#include "base/synchronization/lock.h"
|
||||
|
||||
namespace content {
|
||||
class RenderFrameHost;
|
||||
}
|
||||
|
||||
class CefBrowserHostImpl;
|
||||
|
||||
// Implementation of CefFrame. CefFrameHostImpl objects are owned by the
|
||||
@ -55,6 +59,9 @@ class CefFrameHostImpl : public CefFrame {
|
||||
CefRefPtr<CefBrowser> GetBrowser() override;
|
||||
CefRefPtr<CefV8Context> GetV8Context() override;
|
||||
void VisitDOM(CefRefPtr<CefDOMVisitor> visitor) override;
|
||||
CefRefPtr<CefURLRequest> CreateURLRequest(
|
||||
CefRefPtr<CefRequest> request,
|
||||
CefRefPtr<CefURLRequestClient> client) override;
|
||||
|
||||
void SetFocused(bool focused);
|
||||
void SetAttributes(bool is_main_frame,
|
||||
@ -69,6 +76,10 @@ class CefFrameHostImpl : public CefFrame {
|
||||
|
||||
void ExecuteJavaScriptWithUserGestureForTests(const CefString& javascript);
|
||||
|
||||
// Returns the RFH associated with this frame. Must be called on the UI
|
||||
// thread.
|
||||
content::RenderFrameHost* GetRenderFrameHost();
|
||||
|
||||
// Detach the frame from the browser.
|
||||
void Detach();
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that can
|
||||
// be found in the LICENSE file.
|
||||
|
||||
#include "libcef/browser/browser_urlrequest_impl.h"
|
||||
#include "libcef/browser/net/browser_urlrequest_old_impl.h"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
@ -36,7 +36,7 @@ namespace {
|
||||
|
||||
class CefURLFetcherDelegate : public net::URLFetcherDelegate {
|
||||
public:
|
||||
CefURLFetcherDelegate(CefBrowserURLRequest::Context* context,
|
||||
CefURLFetcherDelegate(CefBrowserURLRequestOld::Context* context,
|
||||
int request_flags);
|
||||
~CefURLFetcherDelegate() override;
|
||||
|
||||
@ -52,14 +52,14 @@ class CefURLFetcherDelegate : public net::URLFetcherDelegate {
|
||||
|
||||
private:
|
||||
// The context_ pointer will outlive this object.
|
||||
CefBrowserURLRequest::Context* context_;
|
||||
CefBrowserURLRequestOld::Context* context_;
|
||||
int request_flags_;
|
||||
};
|
||||
|
||||
class CefURLFetcherResponseWriter : public net::URLFetcherResponseWriter {
|
||||
public:
|
||||
CefURLFetcherResponseWriter(
|
||||
CefRefPtr<CefBrowserURLRequest> url_request,
|
||||
CefRefPtr<CefBrowserURLRequestOld> url_request,
|
||||
scoped_refptr<base::SequencedTaskRunner> task_runner)
|
||||
: url_request_(url_request), task_runner_(task_runner) {}
|
||||
|
||||
@ -91,7 +91,7 @@ class CefURLFetcherResponseWriter : public net::URLFetcherResponseWriter {
|
||||
|
||||
private:
|
||||
static void WriteOnClientThread(
|
||||
CefRefPtr<CefBrowserURLRequest> url_request,
|
||||
CefRefPtr<CefBrowserURLRequestOld> url_request,
|
||||
scoped_refptr<net::IOBuffer> buffer,
|
||||
int num_bytes,
|
||||
net::CompletionOnceCallback callback,
|
||||
@ -111,7 +111,7 @@ class CefURLFetcherResponseWriter : public net::URLFetcherResponseWriter {
|
||||
std::move(callback).Run(num_bytes);
|
||||
}
|
||||
|
||||
CefRefPtr<CefBrowserURLRequest> url_request_;
|
||||
CefRefPtr<CefBrowserURLRequestOld> url_request_;
|
||||
scoped_refptr<base::SequencedTaskRunner> task_runner_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CefURLFetcherResponseWriter);
|
||||
@ -124,12 +124,13 @@ std::unique_ptr<base::SupportsUserData::Data> CreateURLRequestUserData(
|
||||
|
||||
} // namespace
|
||||
|
||||
// CefBrowserURLRequest::Context ----------------------------------------------
|
||||
// CefBrowserURLRequestOld::Context
|
||||
// ----------------------------------------------
|
||||
|
||||
class CefBrowserURLRequest::Context
|
||||
: public base::RefCountedThreadSafe<CefBrowserURLRequest::Context> {
|
||||
class CefBrowserURLRequestOld::Context
|
||||
: public base::RefCountedThreadSafe<CefBrowserURLRequestOld::Context> {
|
||||
public:
|
||||
Context(CefRefPtr<CefBrowserURLRequest> url_request,
|
||||
Context(CefRefPtr<CefBrowserURLRequestOld> url_request,
|
||||
CefRefPtr<CefRequest> request,
|
||||
CefRefPtr<CefURLRequestClient> client,
|
||||
CefRefPtr<CefRequestContext> request_context)
|
||||
@ -177,10 +178,12 @@ class CefBrowserURLRequest::Context
|
||||
|
||||
base::PostTaskWithTraitsAndReply(
|
||||
FROM_HERE, {BrowserThread::UI},
|
||||
base::Bind(&CefBrowserURLRequest::Context::GetRequestContextOnUIThread,
|
||||
this),
|
||||
base::Bind(&CefBrowserURLRequest::Context::ContinueOnOriginatingThread,
|
||||
this, url, request_type));
|
||||
base::Bind(
|
||||
&CefBrowserURLRequestOld::Context::GetRequestContextOnUIThread,
|
||||
this),
|
||||
base::Bind(
|
||||
&CefBrowserURLRequestOld::Context::ContinueOnOriginatingThread,
|
||||
this, url, request_type));
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -330,7 +333,7 @@ class CefBrowserURLRequest::Context
|
||||
bool response_was_cached() const { return response_was_cached_; }
|
||||
|
||||
private:
|
||||
friend class base::RefCountedThreadSafe<CefBrowserURLRequest::Context>;
|
||||
friend class base::RefCountedThreadSafe<CefBrowserURLRequestOld::Context>;
|
||||
|
||||
~Context() {
|
||||
if (fetcher_.get()) {
|
||||
@ -369,7 +372,7 @@ class CefBrowserURLRequest::Context
|
||||
}
|
||||
|
||||
// Members only accessed on the initialization thread.
|
||||
CefRefPtr<CefBrowserURLRequest> url_request_;
|
||||
CefRefPtr<CefBrowserURLRequestOld> url_request_;
|
||||
CefRefPtr<CefRequest> request_;
|
||||
CefRefPtr<CefURLRequestClient> client_;
|
||||
CefRefPtr<CefRequestContext> request_context_;
|
||||
@ -391,7 +394,7 @@ class CefBrowserURLRequest::Context
|
||||
namespace {
|
||||
|
||||
CefURLFetcherDelegate::CefURLFetcherDelegate(
|
||||
CefBrowserURLRequest::Context* context,
|
||||
CefBrowserURLRequestOld::Context* context,
|
||||
int request_flags)
|
||||
: context_(context), request_flags_(request_flags) {}
|
||||
|
||||
@ -402,7 +405,7 @@ void CefURLFetcherDelegate::OnURLFetchComplete(const net::URLFetcher* source) {
|
||||
// in the call stack.
|
||||
CefTaskRunnerImpl::GetCurrentTaskRunner()->PostTask(
|
||||
FROM_HERE,
|
||||
base::Bind(&CefBrowserURLRequest::Context::OnComplete, context_));
|
||||
base::Bind(&CefBrowserURLRequestOld::Context::OnComplete, context_));
|
||||
}
|
||||
|
||||
void CefURLFetcherDelegate::OnURLFetchDownloadProgress(
|
||||
@ -423,66 +426,67 @@ void CefURLFetcherDelegate::OnURLFetchUploadProgress(
|
||||
|
||||
} // namespace
|
||||
|
||||
// CefBrowserURLRequest -------------------------------------------------------
|
||||
// CefBrowserURLRequestOld
|
||||
// -------------------------------------------------------
|
||||
|
||||
CefBrowserURLRequest::CefBrowserURLRequest(
|
||||
CefBrowserURLRequestOld::CefBrowserURLRequestOld(
|
||||
CefRefPtr<CefRequest> request,
|
||||
CefRefPtr<CefURLRequestClient> client,
|
||||
CefRefPtr<CefRequestContext> request_context) {
|
||||
context_ = new Context(this, request, client, request_context);
|
||||
}
|
||||
|
||||
CefBrowserURLRequest::~CefBrowserURLRequest() {}
|
||||
CefBrowserURLRequestOld::~CefBrowserURLRequestOld() {}
|
||||
|
||||
bool CefBrowserURLRequest::Start() {
|
||||
bool CefBrowserURLRequestOld::Start() {
|
||||
if (!VerifyContext())
|
||||
return false;
|
||||
return context_->Start();
|
||||
}
|
||||
|
||||
CefRefPtr<CefRequest> CefBrowserURLRequest::GetRequest() {
|
||||
CefRefPtr<CefRequest> CefBrowserURLRequestOld::GetRequest() {
|
||||
if (!VerifyContext())
|
||||
return NULL;
|
||||
return context_->request();
|
||||
}
|
||||
|
||||
CefRefPtr<CefURLRequestClient> CefBrowserURLRequest::GetClient() {
|
||||
CefRefPtr<CefURLRequestClient> CefBrowserURLRequestOld::GetClient() {
|
||||
if (!VerifyContext())
|
||||
return NULL;
|
||||
return context_->client();
|
||||
}
|
||||
|
||||
CefURLRequest::Status CefBrowserURLRequest::GetRequestStatus() {
|
||||
CefURLRequest::Status CefBrowserURLRequestOld::GetRequestStatus() {
|
||||
if (!VerifyContext())
|
||||
return UR_UNKNOWN;
|
||||
return context_->status();
|
||||
}
|
||||
|
||||
CefURLRequest::ErrorCode CefBrowserURLRequest::GetRequestError() {
|
||||
CefURLRequest::ErrorCode CefBrowserURLRequestOld::GetRequestError() {
|
||||
if (!VerifyContext())
|
||||
return ERR_NONE;
|
||||
return context_->error_code();
|
||||
}
|
||||
|
||||
CefRefPtr<CefResponse> CefBrowserURLRequest::GetResponse() {
|
||||
CefRefPtr<CefResponse> CefBrowserURLRequestOld::GetResponse() {
|
||||
if (!VerifyContext())
|
||||
return NULL;
|
||||
return context_->response();
|
||||
}
|
||||
|
||||
bool CefBrowserURLRequest::ResponseWasCached() {
|
||||
bool CefBrowserURLRequestOld::ResponseWasCached() {
|
||||
if (!VerifyContext())
|
||||
return false;
|
||||
return context_->response_was_cached();
|
||||
}
|
||||
|
||||
void CefBrowserURLRequest::Cancel() {
|
||||
void CefBrowserURLRequestOld::Cancel() {
|
||||
if (!VerifyContext())
|
||||
return;
|
||||
return context_->Cancel();
|
||||
}
|
||||
|
||||
bool CefBrowserURLRequest::VerifyContext() {
|
||||
bool CefBrowserURLRequestOld::VerifyContext() {
|
||||
DCHECK(context_.get());
|
||||
if (!context_->CalledOnValidThread()) {
|
||||
NOTREACHED() << "called on invalid thread";
|
40
libcef/browser/net/browser_urlrequest_old_impl.h
Normal file
40
libcef/browser/net/browser_urlrequest_old_impl.h
Normal file
@ -0,0 +1,40 @@
|
||||
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
|
||||
// reserved. Use of this source code is governed by a BSD-style license that can
|
||||
// be found in the LICENSE file.
|
||||
|
||||
#ifndef CEF_LIBCEF_BROWSER_NET_BROWSER_URLREQUEST_OLD_IMPL_H_
|
||||
#define CEF_LIBCEF_BROWSER_NET_BROWSER_URLREQUEST_OLD_IMPL_H_
|
||||
|
||||
#include "include/cef_urlrequest.h"
|
||||
|
||||
#include "base/memory/ref_counted.h"
|
||||
|
||||
class CefBrowserURLRequestOld : public CefURLRequest {
|
||||
public:
|
||||
class Context;
|
||||
|
||||
CefBrowserURLRequestOld(CefRefPtr<CefRequest> request,
|
||||
CefRefPtr<CefURLRequestClient> client,
|
||||
CefRefPtr<CefRequestContext> request_context);
|
||||
~CefBrowserURLRequestOld() override;
|
||||
|
||||
bool Start();
|
||||
|
||||
// CefURLRequest methods.
|
||||
CefRefPtr<CefRequest> GetRequest() override;
|
||||
CefRefPtr<CefURLRequestClient> GetClient() override;
|
||||
Status GetRequestStatus() override;
|
||||
ErrorCode GetRequestError() override;
|
||||
CefRefPtr<CefResponse> GetResponse() override;
|
||||
bool ResponseWasCached() override;
|
||||
void Cancel() override;
|
||||
|
||||
private:
|
||||
bool VerifyContext();
|
||||
|
||||
scoped_refptr<Context> context_;
|
||||
|
||||
IMPLEMENT_REFCOUNTING(CefBrowserURLRequestOld);
|
||||
};
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_NET_BROWSER_URLREQUEST_OLD_IMPL_H_
|
510
libcef/browser/net_service/browser_urlrequest_impl.cc
Normal file
510
libcef/browser/net_service/browser_urlrequest_impl.cc
Normal file
@ -0,0 +1,510 @@
|
||||
// Copyright (c) 2019 The Chromium Embedded Framework Authors. Portions
|
||||
// Copyright (c) 2018 The Chromium Authors. All rights reserved. Use of this
|
||||
// source code is governed by a BSD-style license that can be found in the
|
||||
// LICENSE file.
|
||||
|
||||
#include "libcef/browser/net_service/browser_urlrequest_impl.h"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "libcef/browser/browser_context.h"
|
||||
#include "libcef/browser/frame_host_impl.h"
|
||||
#include "libcef/browser/net_service/url_loader_factory_getter.h"
|
||||
#include "libcef/browser/request_context_impl.h"
|
||||
#include "libcef/browser/thread_util.h"
|
||||
#include "libcef/common/net_service/net_service_util.h"
|
||||
#include "libcef/common/request_impl.h"
|
||||
#include "libcef/common/response_impl.h"
|
||||
#include "libcef/common/task_runner_impl.h"
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/message_loop/message_loop.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "net/base/net_errors.h"
|
||||
#include "net/http/http_response_headers.h"
|
||||
#include "services/network/public/cpp/shared_url_loader_factory.h"
|
||||
#include "services/network/public/cpp/simple_url_loader.h"
|
||||
#include "services/network/public/cpp/simple_url_loader_stream_consumer.h"
|
||||
|
||||
// CefBrowserURLRequest::Context ----------------------------------------------
|
||||
|
||||
class CefBrowserURLRequest::Context
|
||||
: public network::SimpleURLLoaderStreamConsumer {
|
||||
public:
|
||||
Context(CefRefPtr<CefBrowserURLRequest> url_request,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
CefRefPtr<CefURLRequestClient> client,
|
||||
CefRefPtr<CefRequestContext> request_context)
|
||||
: url_request_(url_request),
|
||||
frame_(frame),
|
||||
request_(static_cast<CefRequestImpl*>(request.get())),
|
||||
client_(client),
|
||||
request_context_(request_context),
|
||||
task_runner_(CefTaskRunnerImpl::GetCurrentTaskRunner()),
|
||||
response_(new CefResponseImpl()),
|
||||
weak_ptr_factory_(this) {
|
||||
// Mark the request/response objects as read-only.
|
||||
request_->SetReadOnly(true);
|
||||
response_->SetReadOnly(true);
|
||||
}
|
||||
~Context() override = default;
|
||||
|
||||
bool Start() {
|
||||
DCHECK(CalledOnValidThread());
|
||||
|
||||
const GURL& url = GURL(request_->GetURL().ToString());
|
||||
if (!url.is_valid())
|
||||
return false;
|
||||
|
||||
CEF_POST_TASK(
|
||||
CEF_UIT,
|
||||
base::BindOnce(
|
||||
&CefBrowserURLRequest::Context::GetURLLoaderFactoryGetterOnUIThread,
|
||||
frame_, request_context_, weak_ptr_factory_.GetWeakPtr(),
|
||||
task_runner_));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Cancel() {
|
||||
DCHECK(CalledOnValidThread());
|
||||
|
||||
// The request may already be complete or canceled.
|
||||
if (!url_request_)
|
||||
return;
|
||||
|
||||
DCHECK_EQ(status_, UR_IO_PENDING);
|
||||
status_ = UR_CANCELED;
|
||||
|
||||
response_->SetReadOnly(false);
|
||||
response_->SetError(ERR_ABORTED);
|
||||
response_->SetReadOnly(true);
|
||||
|
||||
cleanup_immediately_ = true;
|
||||
OnComplete(false);
|
||||
}
|
||||
|
||||
CefRefPtr<CefRequest> request() const { return request_.get(); }
|
||||
CefRefPtr<CefURLRequestClient> client() const { return client_; }
|
||||
CefURLRequest::Status status() const { return status_; }
|
||||
CefRefPtr<CefResponse> response() const { return response_.get(); }
|
||||
bool response_was_cached() const { return response_was_cached_; }
|
||||
|
||||
inline bool CalledOnValidThread() {
|
||||
return task_runner_->RunsTasksInCurrentSequence();
|
||||
}
|
||||
|
||||
private:
|
||||
static void GetURLLoaderFactoryGetterOnUIThread(
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequestContext> request_context,
|
||||
base::WeakPtr<CefBrowserURLRequest::Context> self,
|
||||
scoped_refptr<base::SequencedTaskRunner> task_runner) {
|
||||
CEF_REQUIRE_UIT();
|
||||
|
||||
// Get or create the request context and browser context.
|
||||
CefRefPtr<CefRequestContextImpl> request_context_impl =
|
||||
CefRequestContextImpl::GetOrCreateForRequestContext(request_context);
|
||||
DCHECK(request_context_impl);
|
||||
CefBrowserContext* browser_context =
|
||||
request_context_impl->GetBrowserContext();
|
||||
DCHECK(browser_context);
|
||||
|
||||
content::RenderFrameHost* rfh = nullptr;
|
||||
if (frame) {
|
||||
// The request will be associated with this frame/browser.
|
||||
rfh = static_cast<CefFrameHostImpl*>(frame.get())->GetRenderFrameHost();
|
||||
}
|
||||
|
||||
auto loader_factory_getter =
|
||||
net_service::URLLoaderFactoryGetter::Create(rfh, browser_context);
|
||||
|
||||
task_runner->PostTask(
|
||||
FROM_HERE,
|
||||
base::BindOnce(
|
||||
&CefBrowserURLRequest::Context::ContinueOnOriginatingThread, self,
|
||||
loader_factory_getter));
|
||||
}
|
||||
|
||||
void ContinueOnOriginatingThread(
|
||||
scoped_refptr<net_service::URLLoaderFactoryGetter>
|
||||
loader_factory_getter) {
|
||||
DCHECK(CalledOnValidThread());
|
||||
|
||||
// The request may have been canceled.
|
||||
if (!url_request_)
|
||||
return;
|
||||
|
||||
DCHECK_EQ(status_, UR_IO_PENDING);
|
||||
|
||||
loader_factory_getter_ = loader_factory_getter;
|
||||
|
||||
const int request_flags = request_->GetFlags();
|
||||
|
||||
// Create the URLLoaderFactory and bind to this thread.
|
||||
auto loader_factory = loader_factory_getter_->GetURLLoaderFactory();
|
||||
|
||||
auto resource_request = std::make_unique<network::ResourceRequest>();
|
||||
static_cast<CefRequestImpl*>(request_.get())
|
||||
->Get(resource_request.get(), false);
|
||||
|
||||
// SimpleURLLoader is picky about the body contents. Try to populate them
|
||||
// correctly below.
|
||||
auto request_body = resource_request->request_body;
|
||||
resource_request->request_body = nullptr;
|
||||
|
||||
std::string content_type;
|
||||
std::string method = resource_request->method;
|
||||
if (request_body) {
|
||||
if (method == "GET" || method == "HEAD") {
|
||||
// Fix the method value to allow a request body.
|
||||
method = "POST";
|
||||
resource_request->method = method;
|
||||
|
||||
request_->SetReadOnly(false);
|
||||
request_->SetMethod(method);
|
||||
request_->SetReadOnly(true);
|
||||
}
|
||||
resource_request->headers.GetHeader(net::HttpRequestHeaders::kContentType,
|
||||
&content_type);
|
||||
}
|
||||
|
||||
loader_ = network::SimpleURLLoader::Create(std::move(resource_request),
|
||||
NO_TRAFFIC_ANNOTATION_YET);
|
||||
|
||||
if (request_body) {
|
||||
if (request_body->elements()->size() == 1) {
|
||||
const auto& element = (*request_body->elements())[0];
|
||||
if (element.type() == network::mojom::DataElementType::kFile) {
|
||||
if (content_type.empty()) {
|
||||
const auto& extension = element.path().Extension();
|
||||
if (!extension.empty()) {
|
||||
// Requests should not block on the disk! On POSIX this goes to
|
||||
// disk. http://code.google.com/p/chromium/issues/detail?id=59849
|
||||
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
||||
// Also remove the leading period.
|
||||
net::GetMimeTypeFromExtension(extension.substr(1), &content_type);
|
||||
}
|
||||
}
|
||||
loader_->AttachFileForUpload(element.path(), content_type);
|
||||
} else if (element.type() == network::mojom::DataElementType::kBytes) {
|
||||
if (content_type.empty()) {
|
||||
content_type = net_service::kContentTypeApplicationFormURLEncoded;
|
||||
}
|
||||
loader_->AttachStringForUpload(
|
||||
std::string(element.bytes() + element.offset(),
|
||||
element.length() - element.offset()),
|
||||
content_type);
|
||||
|
||||
if (request_flags & UR_FLAG_REPORT_UPLOAD_PROGRESS) {
|
||||
// Report the expected upload data size.
|
||||
upload_data_size_ = element.length() - element.offset();
|
||||
}
|
||||
} else {
|
||||
NOTIMPLEMENTED() << "Unsupported element type: " << element.type();
|
||||
}
|
||||
} else if (request_body->elements()->size() > 1) {
|
||||
NOTIMPLEMENTED() << "Multi-part form data is not supported";
|
||||
}
|
||||
}
|
||||
|
||||
if (request_flags & UR_FLAG_NO_RETRY_ON_5XX) {
|
||||
// No retries is the default setting, so we don't need to configure that.
|
||||
// Allow delivery of non-2xx response bodies.
|
||||
loader_->SetAllowHttpErrorResults(true);
|
||||
} else {
|
||||
// Allow 2 retries on 5xx response or network change.
|
||||
// TODO(network): Consider exposing configuration of max retries and/or
|
||||
// RETRY_ON_NETWORK_CHANGE as a separate flag.
|
||||
loader_->SetRetryOptions(
|
||||
2, network::SimpleURLLoader::RETRY_ON_5XX |
|
||||
network::SimpleURLLoader::RETRY_ON_NETWORK_CHANGE);
|
||||
}
|
||||
|
||||
if (request_flags & UR_FLAG_STOP_ON_REDIRECT) {
|
||||
// The request will be canceled in OnRedirect.
|
||||
loader_->SetOnRedirectCallback(
|
||||
base::Bind(&CefBrowserURLRequest::Context::OnRedirect,
|
||||
weak_ptr_factory_.GetWeakPtr()));
|
||||
}
|
||||
|
||||
if (request_flags & UR_FLAG_REPORT_UPLOAD_PROGRESS) {
|
||||
loader_->SetOnUploadProgressCallback(
|
||||
base::Bind(&CefBrowserURLRequest::Context::OnUploadProgress,
|
||||
weak_ptr_factory_.GetWeakPtr()));
|
||||
}
|
||||
|
||||
if ((request_flags & UR_FLAG_NO_DOWNLOAD_DATA) || method == "HEAD") {
|
||||
loader_->DownloadHeadersOnly(
|
||||
loader_factory.get(),
|
||||
base::BindOnce(&CefBrowserURLRequest::Context::OnHeadersOnly,
|
||||
weak_ptr_factory_.GetWeakPtr()));
|
||||
} else {
|
||||
loader_->SetOnResponseStartedCallback(
|
||||
base::BindOnce(&CefBrowserURLRequest::Context::OnResponseStarted,
|
||||
weak_ptr_factory_.GetWeakPtr()));
|
||||
loader_->SetOnDownloadProgressCallback(
|
||||
base::Bind(&CefBrowserURLRequest::Context::OnDownloadProgress,
|
||||
weak_ptr_factory_.GetWeakPtr()));
|
||||
|
||||
loader_->DownloadAsStream(loader_factory.get(), this);
|
||||
}
|
||||
}
|
||||
|
||||
void OnHeadersOnly(scoped_refptr<net::HttpResponseHeaders> headers) {
|
||||
DCHECK(CalledOnValidThread());
|
||||
DCHECK_EQ(status_, UR_IO_PENDING);
|
||||
|
||||
response_->SetReadOnly(false);
|
||||
response_->SetResponseHeaders(*headers);
|
||||
response_->SetReadOnly(true);
|
||||
|
||||
// Match the previous behavior of sending download progress notifications
|
||||
// for UR_FLAG_NO_DOWNLOAD_DATA requests but not HEAD requests.
|
||||
if (request_->GetMethod().ToString() != "HEAD") {
|
||||
download_data_size_ = headers->GetContentLength();
|
||||
OnDownloadProgress(0);
|
||||
}
|
||||
|
||||
cleanup_immediately_ = true;
|
||||
OnComplete(true);
|
||||
}
|
||||
|
||||
void OnRedirect(const net::RedirectInfo& redirect_info,
|
||||
const network::ResourceResponseHead& response_head,
|
||||
std::vector<std::string>* removed_headers) {
|
||||
DCHECK(CalledOnValidThread());
|
||||
DCHECK_EQ(status_, UR_IO_PENDING);
|
||||
|
||||
// This method is only called if we intend to stop on redirects.
|
||||
DCHECK(request_->GetFlags() | UR_FLAG_STOP_ON_REDIRECT);
|
||||
|
||||
response_->SetReadOnly(false);
|
||||
response_->SetResponseHeaders(*response_head.headers);
|
||||
response_->SetReadOnly(true);
|
||||
|
||||
Cancel();
|
||||
}
|
||||
|
||||
void OnResponseStarted(const GURL& final_url,
|
||||
const network::ResourceResponseHead& response_head) {
|
||||
DCHECK(CalledOnValidThread());
|
||||
DCHECK_EQ(status_, UR_IO_PENDING);
|
||||
|
||||
response_->SetReadOnly(false);
|
||||
response_->SetURL(final_url.spec());
|
||||
response_->SetResponseHeaders(*response_head.headers);
|
||||
response_->SetReadOnly(true);
|
||||
|
||||
download_data_size_ = response_head.content_length;
|
||||
}
|
||||
|
||||
void OnUploadProgress(uint64_t position, uint64_t total) {
|
||||
DCHECK(CalledOnValidThread());
|
||||
DCHECK_EQ(status_, UR_IO_PENDING);
|
||||
|
||||
upload_data_size_ = total;
|
||||
if (position == total)
|
||||
got_upload_progress_complete_ = true;
|
||||
|
||||
client_->OnUploadProgress(url_request_.get(), position, total);
|
||||
}
|
||||
|
||||
void OnDownloadProgress(uint64_t current) {
|
||||
DCHECK(CalledOnValidThread());
|
||||
DCHECK_EQ(status_, UR_IO_PENDING);
|
||||
|
||||
if (response_->GetStatus() == 0) {
|
||||
// With failed requests this callback may arrive without a proceeding
|
||||
// OnHeadersOnly or OnResponseStarted.
|
||||
return;
|
||||
}
|
||||
|
||||
NotifyUploadProgressIfNecessary();
|
||||
|
||||
client_->OnDownloadProgress(url_request_.get(), current,
|
||||
download_data_size_);
|
||||
}
|
||||
|
||||
void NotifyUploadProgressIfNecessary() {
|
||||
if (!got_upload_progress_complete_ && upload_data_size_ > 0) {
|
||||
// URLLoader sends upload notifications using a timer and will not send
|
||||
// a notification if the request completes too quickly. We therefore
|
||||
// send the notification here if necessary.
|
||||
client_->OnUploadProgress(url_request_.get(), upload_data_size_,
|
||||
upload_data_size_);
|
||||
got_upload_progress_complete_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
// SimpleURLLoaderStreamConsumer methods:
|
||||
void OnDataReceived(base::StringPiece string_piece,
|
||||
base::OnceClosure resume) override {
|
||||
DCHECK(CalledOnValidThread());
|
||||
DCHECK_EQ(status_, UR_IO_PENDING);
|
||||
|
||||
client_->OnDownloadData(url_request_.get(), string_piece.data(),
|
||||
string_piece.length());
|
||||
std::move(resume).Run();
|
||||
}
|
||||
|
||||
void OnComplete(bool success) override {
|
||||
DCHECK(CalledOnValidThread());
|
||||
|
||||
// The request may already be complete or canceled.
|
||||
if (!url_request_)
|
||||
return;
|
||||
|
||||
// Status will be UR_IO_PENDING if we're called when the request is complete
|
||||
// (via SimpleURLLoaderStreamConsumer or OnHeadersOnly). We can only call
|
||||
// these SimpleURLLoader methods if the request is complete.
|
||||
if (status_ == UR_IO_PENDING) {
|
||||
status_ = success ? UR_SUCCESS : UR_FAILED;
|
||||
|
||||
response_->SetReadOnly(false);
|
||||
response_->SetURL(loader_->GetFinalURL().spec());
|
||||
response_->SetError(static_cast<cef_errorcode_t>(loader_->NetError()));
|
||||
response_->SetReadOnly(true);
|
||||
|
||||
response_was_cached_ = loader_->LoadedFromCache();
|
||||
}
|
||||
|
||||
if (success)
|
||||
NotifyUploadProgressIfNecessary();
|
||||
|
||||
client_->OnRequestComplete(url_request_.get());
|
||||
|
||||
// When called via SimpleURLLoaderStreamConsumer we need to cleanup
|
||||
// asynchronously. If the load is still pending this will also cancel it.
|
||||
Cleanup();
|
||||
}
|
||||
|
||||
void OnRetry(base::OnceClosure start_retry) override {
|
||||
DCHECK(CalledOnValidThread());
|
||||
DCHECK_EQ(status_, UR_IO_PENDING);
|
||||
std::move(start_retry).Run();
|
||||
}
|
||||
|
||||
void Cleanup() {
|
||||
DCHECK(CalledOnValidThread());
|
||||
DCHECK(url_request_);
|
||||
|
||||
client_ = nullptr;
|
||||
request_context_ = nullptr;
|
||||
|
||||
// We may be canceled before the loader is created.
|
||||
if (loader_) {
|
||||
// Must delete the loader before the factory.
|
||||
if (cleanup_immediately_) {
|
||||
// Most SimpleURLLoader callbacks let us delete the URLLoader objects
|
||||
// immediately.
|
||||
loader_.reset();
|
||||
loader_factory_getter_ = nullptr;
|
||||
} else {
|
||||
// Delete the URLLoader objects asynchronously on the correct thread.
|
||||
task_runner_->DeleteSoon(FROM_HERE, std::move(loader_));
|
||||
task_runner_->ReleaseSoon(FROM_HERE, std::move(loader_factory_getter_));
|
||||
}
|
||||
}
|
||||
|
||||
// We may be holding the last reference to |url_request_|, destruction of
|
||||
// which will delete |this|. Use a local variable to keep |url_request_|
|
||||
// alive until this method returns.
|
||||
auto url_request = url_request_;
|
||||
url_request_ = nullptr;
|
||||
}
|
||||
|
||||
// Members only accessed on the initialization thread.
|
||||
CefRefPtr<CefBrowserURLRequest> url_request_;
|
||||
CefRefPtr<CefFrame> frame_;
|
||||
CefRefPtr<CefRequestImpl> request_;
|
||||
CefRefPtr<CefURLRequestClient> client_;
|
||||
CefRefPtr<CefRequestContext> request_context_;
|
||||
scoped_refptr<base::SequencedTaskRunner> task_runner_;
|
||||
|
||||
scoped_refptr<net_service::URLLoaderFactoryGetter> loader_factory_getter_;
|
||||
std::unique_ptr<network::SimpleURLLoader> loader_;
|
||||
|
||||
CefURLRequest::Status status_ = UR_IO_PENDING;
|
||||
CefRefPtr<CefResponseImpl> response_;
|
||||
bool response_was_cached_ = false;
|
||||
int64 upload_data_size_ = 0;
|
||||
int64 download_data_size_ = -1;
|
||||
bool got_upload_progress_complete_ = false;
|
||||
bool cleanup_immediately_ = false;
|
||||
|
||||
// Must be the last member.
|
||||
base::WeakPtrFactory<CefBrowserURLRequest::Context> weak_ptr_factory_;
|
||||
};
|
||||
|
||||
// CefBrowserURLRequest -------------------------------------------------------
|
||||
|
||||
CefBrowserURLRequest::CefBrowserURLRequest(
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
CefRefPtr<CefURLRequestClient> client,
|
||||
CefRefPtr<CefRequestContext> request_context) {
|
||||
context_.reset(new Context(this, frame, request, client, request_context));
|
||||
}
|
||||
|
||||
CefBrowserURLRequest::~CefBrowserURLRequest() {}
|
||||
|
||||
bool CefBrowserURLRequest::Start() {
|
||||
if (!VerifyContext())
|
||||
return false;
|
||||
return context_->Start();
|
||||
}
|
||||
|
||||
CefRefPtr<CefRequest> CefBrowserURLRequest::GetRequest() {
|
||||
if (!VerifyContext())
|
||||
return NULL;
|
||||
return context_->request();
|
||||
}
|
||||
|
||||
CefRefPtr<CefURLRequestClient> CefBrowserURLRequest::GetClient() {
|
||||
if (!VerifyContext())
|
||||
return NULL;
|
||||
return context_->client();
|
||||
}
|
||||
|
||||
CefURLRequest::Status CefBrowserURLRequest::GetRequestStatus() {
|
||||
if (!VerifyContext())
|
||||
return UR_UNKNOWN;
|
||||
return context_->status();
|
||||
}
|
||||
|
||||
CefURLRequest::ErrorCode CefBrowserURLRequest::GetRequestError() {
|
||||
if (!VerifyContext())
|
||||
return ERR_NONE;
|
||||
return context_->response()->GetError();
|
||||
}
|
||||
|
||||
CefRefPtr<CefResponse> CefBrowserURLRequest::GetResponse() {
|
||||
if (!VerifyContext())
|
||||
return NULL;
|
||||
return context_->response();
|
||||
}
|
||||
|
||||
bool CefBrowserURLRequest::ResponseWasCached() {
|
||||
if (!VerifyContext())
|
||||
return false;
|
||||
return context_->response_was_cached();
|
||||
}
|
||||
|
||||
void CefBrowserURLRequest::Cancel() {
|
||||
if (!VerifyContext())
|
||||
return;
|
||||
return context_->Cancel();
|
||||
}
|
||||
|
||||
bool CefBrowserURLRequest::VerifyContext() {
|
||||
if (!context_->CalledOnValidThread()) {
|
||||
NOTREACHED() << "called on invalid thread";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
@ -2,18 +2,21 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that can
|
||||
// be found in the LICENSE file.
|
||||
|
||||
#ifndef CEF_LIBCEF_BROWSER_BROWSER_URLREQUEST_IMPL_H_
|
||||
#define CEF_LIBCEF_BROWSER_BROWSER_URLREQUEST_IMPL_H_
|
||||
#ifndef CEF_LIBCEF_BROWSER_NET_SERVICE_BROWSER_URLREQUEST_IMPL_H_
|
||||
#define CEF_LIBCEF_BROWSER_NET_SERVICE_BROWSER_URLREQUEST_IMPL_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "include/cef_urlrequest.h"
|
||||
|
||||
#include "base/memory/ref_counted.h"
|
||||
|
||||
class CefBrowserURLRequest : public CefURLRequest {
|
||||
public:
|
||||
class Context;
|
||||
|
||||
CefBrowserURLRequest(CefRefPtr<CefRequest> request,
|
||||
// If |frame| is nullptr requests can still be intercepted but no
|
||||
// browser/frame will be associated with them.
|
||||
CefBrowserURLRequest(CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
CefRefPtr<CefURLRequestClient> client,
|
||||
CefRefPtr<CefRequestContext> request_context);
|
||||
~CefBrowserURLRequest() override;
|
||||
@ -32,9 +35,9 @@ class CefBrowserURLRequest : public CefURLRequest {
|
||||
private:
|
||||
bool VerifyContext();
|
||||
|
||||
scoped_refptr<Context> context_;
|
||||
std::unique_ptr<Context> context_;
|
||||
|
||||
IMPLEMENT_REFCOUNTING(CefBrowserURLRequest);
|
||||
};
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_BROWSER_URLREQUEST_IMPL_H_
|
||||
#endif // CEF_LIBCEF_BROWSER_NET_SERVICE_BROWSER_URLREQUEST_IMPL_H_
|
@ -204,6 +204,8 @@ class InterceptedRequest : public network::mojom::URLLoader,
|
||||
|
||||
void SendErrorCallback(int error_code, bool safebrowsing_hit);
|
||||
|
||||
void OnUploadProgressACK();
|
||||
|
||||
ProxyURLLoaderFactory* const factory_;
|
||||
const RequestId id_;
|
||||
const uint32_t options_;
|
||||
@ -223,6 +225,9 @@ class InterceptedRequest : public network::mojom::URLLoader,
|
||||
network::URLLoaderCompletionStatus status_;
|
||||
bool got_loader_error_ = false;
|
||||
|
||||
// Used for rate limiting OnUploadProgress callbacks.
|
||||
bool waiting_for_upload_progress_ack_ = false;
|
||||
|
||||
network::ResourceRequest request_;
|
||||
network::ResourceResponseHead current_response_;
|
||||
scoped_refptr<net::HttpResponseHeaders> override_headers_;
|
||||
@ -486,8 +491,25 @@ void InterceptedRequest::OnReceiveRedirect(
|
||||
void InterceptedRequest::OnUploadProgress(int64_t current_position,
|
||||
int64_t total_size,
|
||||
OnUploadProgressCallback callback) {
|
||||
target_client_->OnUploadProgress(current_position, total_size,
|
||||
std::move(callback));
|
||||
// Implement our own rate limiting for OnUploadProgress calls.
|
||||
if (!waiting_for_upload_progress_ack_) {
|
||||
waiting_for_upload_progress_ack_ = true;
|
||||
target_client_->OnUploadProgress(
|
||||
current_position, total_size,
|
||||
base::BindOnce(&InterceptedRequest::OnUploadProgressACK,
|
||||
weak_factory_.GetWeakPtr()));
|
||||
}
|
||||
|
||||
// Always execute the callback immediately to avoid a race between
|
||||
// URLLoaderClient_OnUploadProgress_ProxyToResponder::Run() (which would
|
||||
// otherwise be blocked on the target client executing the callback) and
|
||||
// CallOnComplete(). If CallOnComplete() is executed first the interface pipe
|
||||
// will be closed and the callback destructor will generate an assertion like:
|
||||
// "URLLoaderClient::OnUploadProgressCallback was destroyed without first
|
||||
// either being run or its corresponding binding being closed. It is an error
|
||||
// to drop response callbacks which still correspond to an open interface
|
||||
// pipe."
|
||||
std::move(callback).Run();
|
||||
}
|
||||
|
||||
void InterceptedRequest::OnReceiveCachedMetadata(
|
||||
@ -524,16 +546,15 @@ void InterceptedRequest::FollowRedirect(
|
||||
OnProcessRequestHeaders(new_url.value_or(GURL()), &modified_headers,
|
||||
&removed_headers);
|
||||
|
||||
if (target_loader_) {
|
||||
target_loader_->FollowRedirect(removed_headers, modified_headers, new_url);
|
||||
}
|
||||
|
||||
// If |OnURLLoaderClientError| was called then we're just waiting for the
|
||||
// connection error handler of |proxied_loader_binding_|. Don't restart the
|
||||
// job since that'll create another URLLoader.
|
||||
if (!target_client_)
|
||||
return;
|
||||
|
||||
// Normally we would call FollowRedirect on the target loader and it would
|
||||
// begin loading the redirected request. However, the client might want to
|
||||
// intercept that request so restart the job instead.
|
||||
Restart();
|
||||
}
|
||||
|
||||
@ -937,6 +958,11 @@ void InterceptedRequest::SendErrorCallback(int error_code,
|
||||
safebrowsing_hit);
|
||||
}
|
||||
|
||||
void InterceptedRequest::OnUploadProgressACK() {
|
||||
DCHECK(waiting_for_upload_progress_ack_);
|
||||
waiting_for_upload_progress_ack_ = false;
|
||||
}
|
||||
|
||||
//==============================
|
||||
// InterceptedRequestHandler
|
||||
//==============================
|
||||
|
@ -18,6 +18,9 @@
|
||||
#include "libcef/common/request_impl.h"
|
||||
#include "libcef/common/response_impl.h"
|
||||
|
||||
#include "chrome/common/chrome_features.h"
|
||||
#include "components/language/core/browser/pref_names.h"
|
||||
#include "components/prefs/pref_service.h"
|
||||
#include "content/public/browser/browser_context.h"
|
||||
#include "content/public/browser/render_frame_host.h"
|
||||
#include "content/public/browser/render_process_host.h"
|
||||
@ -77,12 +80,20 @@ std::string GetAcceptLanguageList(content::BrowserContext* browser_context,
|
||||
return CefString(&browser_settings.accept_language_list);
|
||||
}
|
||||
}
|
||||
const CefRequestContextSettings& context_settings =
|
||||
static_cast<CefBrowserContext*>(browser_context)->GetSettings();
|
||||
if (context_settings.accept_language_list.length > 0) {
|
||||
return CefString(&context_settings.accept_language_list);
|
||||
}
|
||||
return "en-US,en";
|
||||
|
||||
// This defaults to the value from CefRequestContextSettings via
|
||||
// browser_prefs::CreatePrefService().
|
||||
auto prefs = Profile::FromBrowserContext(browser_context)->GetPrefs();
|
||||
return prefs->GetString(language::prefs::kAcceptLanguages);
|
||||
}
|
||||
|
||||
// Match the logic in chrome/browser/net/profile_network_context_service.cc.
|
||||
std::string ComputeAcceptLanguageFromPref(const std::string& language_pref) {
|
||||
std::string accept_languages_str =
|
||||
base::FeatureList::IsEnabled(features::kUseNewAcceptLanguageHeader)
|
||||
? net::HttpUtil::ExpandLanguageList(language_pref)
|
||||
: language_pref;
|
||||
return net::HttpUtil::GenerateAcceptLanguageHeader(accept_languages_str);
|
||||
}
|
||||
|
||||
class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
|
||||
@ -167,9 +178,11 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
|
||||
is_external_ = is_external;
|
||||
|
||||
// Default values for standard headers.
|
||||
accept_language_ = net::HttpUtil::GenerateAcceptLanguageHeader(
|
||||
accept_language_ = ComputeAcceptLanguageFromPref(
|
||||
GetAcceptLanguageList(browser_context, browser));
|
||||
DCHECK(!accept_language_.empty());
|
||||
user_agent_ = CefContentClient::Get()->browser()->GetUserAgent();
|
||||
DCHECK(!user_agent_.empty());
|
||||
|
||||
CEF_POST_TASK(
|
||||
CEF_IOT,
|
||||
|
127
libcef/browser/net_service/url_loader_factory_getter.cc
Normal file
127
libcef/browser/net_service/url_loader_factory_getter.cc
Normal file
@ -0,0 +1,127 @@
|
||||
// Copyright (c) 2019 The Chromium Embedded Framework Authors. Portions
|
||||
// Copyright (c) 2018 The Chromium Authors. All rights reserved. Use of this
|
||||
// source code is governed by a BSD-style license that can be found in the
|
||||
// LICENSE file.
|
||||
|
||||
#include "libcef/browser/net_service/url_loader_factory_getter.h"
|
||||
|
||||
#include "libcef/browser/content_browser_client.h"
|
||||
#include "libcef/browser/thread_util.h"
|
||||
|
||||
#include "base/threading/thread_task_runner_handle.h"
|
||||
#include "content/browser/devtools/devtools_instrumentation.h"
|
||||
#include "content/browser/frame_host/render_frame_host_impl.h"
|
||||
#include "content/public/browser/storage_partition.h"
|
||||
#include "content/public/common/content_client.h"
|
||||
#include "services/network/public/cpp/shared_url_loader_factory.h"
|
||||
#include "services/network/public/cpp/wrapper_shared_url_loader_factory.h"
|
||||
|
||||
namespace net_service {
|
||||
|
||||
// Based on CreateDownloadURLLoaderFactoryGetter from
|
||||
// content/browser/download/download_manager_impl.cc.
|
||||
// static
|
||||
scoped_refptr<URLLoaderFactoryGetter> URLLoaderFactoryGetter::Create(
|
||||
content::RenderFrameHost* render_frame_host,
|
||||
content::BrowserContext* browser_context) {
|
||||
CEF_REQUIRE_UIT();
|
||||
DCHECK(browser_context);
|
||||
|
||||
// Call this early because newly created BrowserContexts may need to
|
||||
// initialize additional state, and that should be done on the UI thread
|
||||
// instead of potentially racing with the WillCreateURLLoaderFactory
|
||||
// implementation.
|
||||
auto loader_factory =
|
||||
content::BrowserContext::GetDefaultStoragePartition(browser_context)
|
||||
->GetURLLoaderFactoryForBrowserProcess();
|
||||
|
||||
network::mojom::URLLoaderFactoryPtrInfo proxy_factory_ptr_info;
|
||||
network::mojom::URLLoaderFactoryRequest proxy_factory_request;
|
||||
|
||||
// Create an intermediate pipe that can be used to proxy the request's
|
||||
// URLLoaderFactory.
|
||||
network::mojom::URLLoaderFactoryPtrInfo maybe_proxy_factory_ptr_info;
|
||||
network::mojom::URLLoaderFactoryRequest maybe_proxy_factory_request =
|
||||
MakeRequest(&maybe_proxy_factory_ptr_info);
|
||||
|
||||
bool should_proxy = false;
|
||||
int render_process_id = -1;
|
||||
|
||||
if (render_frame_host) {
|
||||
render_process_id = render_frame_host->GetProcess()->GetID();
|
||||
|
||||
// Allow DevTools to potentially inject itself into the proxy pipe.
|
||||
should_proxy =
|
||||
content::devtools_instrumentation::WillCreateURLLoaderFactory(
|
||||
static_cast<content::RenderFrameHostImpl*>(render_frame_host),
|
||||
false /* is_navigation */, false /* is_download */,
|
||||
&maybe_proxy_factory_request);
|
||||
}
|
||||
|
||||
// Allow the Content embedder to inject itself if it wants to.
|
||||
should_proxy |= CefContentBrowserClient::Get()->WillCreateURLLoaderFactory(
|
||||
browser_context, render_frame_host, render_process_id,
|
||||
false /* is_navigation */, false /* is_download */, url::Origin(),
|
||||
&maybe_proxy_factory_request, nullptr /* header_client */,
|
||||
nullptr /* bypass_redirect_checks */);
|
||||
|
||||
// If anyone above indicated that they care about proxying, pass the
|
||||
// intermediate pipe along to the URLLoaderFactoryGetter.
|
||||
if (should_proxy) {
|
||||
proxy_factory_ptr_info = std::move(maybe_proxy_factory_ptr_info);
|
||||
proxy_factory_request = std::move(maybe_proxy_factory_request);
|
||||
}
|
||||
|
||||
return base::WrapRefCounted(new URLLoaderFactoryGetter(
|
||||
loader_factory->Clone(), std::move(proxy_factory_ptr_info),
|
||||
std::move(proxy_factory_request)));
|
||||
}
|
||||
|
||||
// Based on NetworkDownloadURLLoaderFactoryGetter from
|
||||
// content/browser/download/network_download_url_loader_factory_getter.cc.
|
||||
scoped_refptr<network::SharedURLLoaderFactory>
|
||||
URLLoaderFactoryGetter::GetURLLoaderFactory() {
|
||||
// On first call we associate with the current thread.
|
||||
if (!task_runner_) {
|
||||
task_runner_ = base::ThreadTaskRunnerHandle::Get();
|
||||
} else {
|
||||
DCHECK(task_runner_->RunsTasksInCurrentSequence());
|
||||
}
|
||||
|
||||
if (lazy_factory_)
|
||||
return lazy_factory_;
|
||||
|
||||
// Bind on the current thread.
|
||||
auto loader_factory =
|
||||
network::SharedURLLoaderFactory::Create(std::move(loader_factory_info_));
|
||||
|
||||
if (proxy_factory_request_.is_pending()) {
|
||||
loader_factory->Clone(std::move(proxy_factory_request_));
|
||||
lazy_factory_ =
|
||||
base::MakeRefCounted<network::WrapperSharedURLLoaderFactory>(
|
||||
std::move(proxy_factory_ptr_info_));
|
||||
} else {
|
||||
lazy_factory_ = loader_factory;
|
||||
}
|
||||
return lazy_factory_;
|
||||
}
|
||||
|
||||
URLLoaderFactoryGetter::URLLoaderFactoryGetter(
|
||||
std::unique_ptr<network::SharedURLLoaderFactoryInfo> loader_factory_info,
|
||||
network::mojom::URLLoaderFactoryPtrInfo proxy_factory_ptr_info,
|
||||
network::mojom::URLLoaderFactoryRequest proxy_factory_request)
|
||||
: loader_factory_info_(std::move(loader_factory_info)),
|
||||
proxy_factory_ptr_info_(std::move(proxy_factory_ptr_info)),
|
||||
proxy_factory_request_(std::move(proxy_factory_request)) {}
|
||||
|
||||
URLLoaderFactoryGetter::~URLLoaderFactoryGetter() = default;
|
||||
|
||||
void URLLoaderFactoryGetter::DeleteOnCorrectThread() const {
|
||||
if (task_runner_ && !task_runner_->RunsTasksInCurrentSequence()) {
|
||||
task_runner_->DeleteSoon(FROM_HERE, this);
|
||||
return;
|
||||
}
|
||||
delete this;
|
||||
}
|
||||
|
||||
} // namespace net_service
|
76
libcef/browser/net_service/url_loader_factory_getter.h
Normal file
76
libcef/browser/net_service/url_loader_factory_getter.h
Normal file
@ -0,0 +1,76 @@
|
||||
// Copyright (c) 2019 The Chromium Embedded Framework Authors. Portions
|
||||
// Copyright (c) 2018 The Chromium Authors. All rights reserved. Use of this
|
||||
// source code is governed by a BSD-style license that can be found in the
|
||||
// LICENSE file.
|
||||
|
||||
#ifndef CEF_LIBCEF_BROWSER_NET_SERVICE_URL_LOADER_FACTORY_GETTER_H_
|
||||
#define CEF_LIBCEF_BROWSER_NET_SERVICE_URL_LOADER_FACTORY_GETTER_H_
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/sequenced_task_runner.h"
|
||||
#include "base/sequenced_task_runner_helpers.h"
|
||||
#include "services/network/public/mojom/url_loader_factory.mojom.h"
|
||||
|
||||
namespace content {
|
||||
class BrowserContext;
|
||||
class RenderFrameHost;
|
||||
} // namespace content
|
||||
|
||||
namespace network {
|
||||
class SharedURLLoaderFactory;
|
||||
class SharedURLLoaderFactoryInfo;
|
||||
} // namespace network
|
||||
|
||||
namespace net_service {
|
||||
|
||||
struct URLLoaderFactoryGetterDeleter;
|
||||
|
||||
// Helper class for retrieving a URLLoaderFactory that can be bound on any
|
||||
// thread, and that correctly handles proxied requests.
|
||||
class URLLoaderFactoryGetter
|
||||
: public base::RefCountedThreadSafe<URLLoaderFactoryGetter,
|
||||
URLLoaderFactoryGetterDeleter> {
|
||||
public:
|
||||
// Create a URLLoaderFactoryGetter on the UI thread.
|
||||
// |render_frame_host| may be nullptr.
|
||||
static scoped_refptr<URLLoaderFactoryGetter> Create(
|
||||
content::RenderFrameHost* render_frame_host,
|
||||
content::BrowserContext* browser_context);
|
||||
|
||||
// Create a SharedURLLoaderFactory on the current thread. All future calls
|
||||
// to this method must be on the same thread.
|
||||
scoped_refptr<network::SharedURLLoaderFactory> GetURLLoaderFactory();
|
||||
|
||||
private:
|
||||
friend class base::DeleteHelper<URLLoaderFactoryGetter>;
|
||||
friend class base::RefCountedThreadSafe<URLLoaderFactoryGetter,
|
||||
URLLoaderFactoryGetterDeleter>;
|
||||
friend struct URLLoaderFactoryGetterDeleter;
|
||||
|
||||
URLLoaderFactoryGetter(
|
||||
std::unique_ptr<network::SharedURLLoaderFactoryInfo> loader_factory_info,
|
||||
network::mojom::URLLoaderFactoryPtrInfo proxy_factory_ptr_info,
|
||||
network::mojom::URLLoaderFactoryRequest proxy_factory_request);
|
||||
~URLLoaderFactoryGetter();
|
||||
|
||||
void DeleteOnCorrectThread() const;
|
||||
|
||||
std::unique_ptr<network::SharedURLLoaderFactoryInfo> loader_factory_info_;
|
||||
scoped_refptr<network::SharedURLLoaderFactory> lazy_factory_;
|
||||
network::mojom::URLLoaderFactoryPtrInfo proxy_factory_ptr_info_;
|
||||
network::mojom::URLLoaderFactoryRequest proxy_factory_request_;
|
||||
scoped_refptr<base::SequencedTaskRunner> task_runner_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(URLLoaderFactoryGetter);
|
||||
};
|
||||
|
||||
struct URLLoaderFactoryGetterDeleter {
|
||||
static void Destruct(const URLLoaderFactoryGetter* factory_getter) {
|
||||
factory_getter->DeleteOnCorrectThread();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace net_service
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_NET_SERVICE_URL_LOADER_FACTORY_GETTER_H_
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "libcef/browser/prefs/browser_prefs.h"
|
||||
|
||||
#include "libcef/browser/browser_context.h"
|
||||
#include "libcef/browser/media_capture_devices_dispatcher.h"
|
||||
#include "libcef/browser/net/url_request_context_getter.h"
|
||||
#include "libcef/browser/prefs/pref_store.h"
|
||||
@ -36,6 +37,7 @@
|
||||
#include "components/google/core/browser/google_url_tracker.h"
|
||||
#include "components/keyed_service/content/browser_context_dependency_manager.h"
|
||||
#include "components/language/core/browser/language_prefs.h"
|
||||
#include "components/language/core/browser/pref_names.h"
|
||||
#include "components/pref_registry/pref_registry_syncable.h"
|
||||
#include "components/prefs/json_pref_store.h"
|
||||
#include "components/prefs/pref_filter.h"
|
||||
@ -58,6 +60,19 @@
|
||||
|
||||
namespace browser_prefs {
|
||||
|
||||
namespace {
|
||||
|
||||
std::string GetAcceptLanguageList(Profile* profile) {
|
||||
const CefRequestContextSettings& context_settings =
|
||||
static_cast<CefBrowserContext*>(profile)->GetSettings();
|
||||
if (context_settings.accept_language_list.length > 0) {
|
||||
return CefString(&context_settings.accept_language_list);
|
||||
}
|
||||
return std::string();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
const char kUserPrefsFileName[] = "UserPrefs.json";
|
||||
|
||||
std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
|
||||
@ -230,6 +245,14 @@ std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
|
||||
// Based on DevToolsWindow::RegisterProfilePrefs.
|
||||
registry->RegisterDictionaryPref(prefs::kDevToolsPreferences);
|
||||
registry->RegisterDictionaryPref(prefs::kDevToolsEditedFiles);
|
||||
|
||||
// Language preferences. Used by ProfileNetworkContextService and
|
||||
// InterceptedRequestHandlerWrapper.
|
||||
const std::string& accept_language_list = GetAcceptLanguageList(profile);
|
||||
if (!accept_language_list.empty()) {
|
||||
registry->SetDefaultPrefValue(language::prefs::kAcceptLanguages,
|
||||
base::Value(accept_language_list));
|
||||
}
|
||||
}
|
||||
|
||||
// Build the PrefService that manages the PrefRegistry and PrefStores.
|
||||
|
@ -44,6 +44,9 @@ bool GetCookieDomain(const GURL& url,
|
||||
const char kHTTPLocationHeaderName[] = "Location";
|
||||
const char kHTTPSetCookieHeaderName[] = "Set-Cookie";
|
||||
|
||||
const char kContentTypeApplicationFormURLEncoded[] =
|
||||
"application/x-www-form-urlencoded";
|
||||
|
||||
const char kHTTPHeaderSep[] = ": ";
|
||||
|
||||
std::string MakeHeader(const std::string& name, const std::string& value) {
|
||||
|
@ -29,6 +29,9 @@ namespace net_service {
|
||||
extern const char kHTTPLocationHeaderName[];
|
||||
extern const char kHTTPSetCookieHeaderName[];
|
||||
|
||||
// HTTP header values.
|
||||
extern const char kContentTypeApplicationFormURLEncoded[];
|
||||
|
||||
// Make a header name/value pair.
|
||||
std::string MakeHeader(const std::string& name, const std::string& value);
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "libcef/common/cef_messages.h"
|
||||
#include "libcef/common/net/http_header_utils.h"
|
||||
#include "libcef/common/net/upload_data.h"
|
||||
#include "libcef/common/net_service/net_service_util.h"
|
||||
#include "libcef/common/request_impl.h"
|
||||
|
||||
#include "base/command_line.h"
|
||||
@ -54,7 +55,6 @@ const char kCacheControlLowerCase[] = "cache-control";
|
||||
const char kCacheControlDirectiveNoCacheLowerCase[] = "no-cache";
|
||||
const char kCacheControlDirectiveNoStoreLowerCase[] = "no-store";
|
||||
const char kCacheControlDirectiveOnlyIfCachedLowerCase[] = "only-if-cached";
|
||||
const char kApplicationFormURLEncoded[] = "application/x-www-form-urlencoded";
|
||||
|
||||
// Mask of values that configure the cache policy.
|
||||
const int kURCachePolicyMask =
|
||||
@ -549,6 +549,35 @@ void CefRequestImpl::Get(network::ResourceRequest* request,
|
||||
ShouldSet(kChangedFirstPartyForCookies, changed_only)) {
|
||||
request->site_for_cookies = first_party_for_cookies_;
|
||||
}
|
||||
|
||||
if (ShouldSet(kChangedFlags, changed_only)) {
|
||||
int flags = flags_;
|
||||
if (!(flags & kURCachePolicyMask)) {
|
||||
// Only consider the Cache-Control directives when a cache policy is not
|
||||
// explicitly set on the request.
|
||||
flags |= GetCacheControlHeaderPolicy(headermap_);
|
||||
}
|
||||
|
||||
int net_flags = 0;
|
||||
|
||||
if (flags & UR_FLAG_SKIP_CACHE) {
|
||||
net_flags |= net::LOAD_BYPASS_CACHE;
|
||||
}
|
||||
if (flags & UR_FLAG_ONLY_FROM_CACHE) {
|
||||
net_flags |= net::LOAD_ONLY_FROM_CACHE | net::LOAD_SKIP_CACHE_VALIDATION;
|
||||
}
|
||||
if (flags & UR_FLAG_DISABLE_CACHE) {
|
||||
net_flags |= net::LOAD_DISABLE_CACHE;
|
||||
}
|
||||
|
||||
if (!(flags & UR_FLAG_ALLOW_STORED_CREDENTIALS)) {
|
||||
net_flags |= net::LOAD_DO_NOT_SEND_AUTH_DATA |
|
||||
net::LOAD_DO_NOT_SEND_COOKIES |
|
||||
net::LOAD_DO_NOT_SAVE_COOKIES;
|
||||
}
|
||||
|
||||
request->load_flags = net_flags;
|
||||
}
|
||||
}
|
||||
|
||||
void CefRequestImpl::Set(const net::RedirectInfo& redirect_info) {
|
||||
@ -771,7 +800,8 @@ void CefRequestImpl::Get(const CefMsg_LoadRequest_Params& params,
|
||||
.length() == 0) {
|
||||
request.SetHttpHeaderField(
|
||||
blink::WebString::FromASCII(net::HttpRequestHeaders::kContentType),
|
||||
blink::WebString::FromASCII(kApplicationFormURLEncoded));
|
||||
blink::WebString::FromASCII(
|
||||
net_service::kContentTypeApplicationFormURLEncoded));
|
||||
}
|
||||
|
||||
blink::WebHTTPBody body;
|
||||
@ -869,7 +899,7 @@ void CefRequestImpl::Get(net::URLFetcher& fetcher,
|
||||
if (elements.size() == 1) {
|
||||
// Default to URL encoding if not specified.
|
||||
if (content_type.empty())
|
||||
content_type = kApplicationFormURLEncoded;
|
||||
content_type = net_service::kContentTypeApplicationFormURLEncoded;
|
||||
|
||||
CefPostDataElementImpl* impl =
|
||||
static_cast<CefPostDataElementImpl*>(elements[0].get());
|
||||
|
@ -93,7 +93,7 @@ class CefRequestImpl : public CefRequest {
|
||||
// Populate this object from the ResourceRequest object.
|
||||
void Set(const network::ResourceRequest* request, uint64 identifier);
|
||||
|
||||
// Populate the URLRequest object from this object.
|
||||
// Populate the ResourceRequest object from this object.
|
||||
// If |changed_only| is true then only the changed fields will be updated.
|
||||
void Get(network::ResourceRequest* request, bool changed_only) const;
|
||||
|
||||
@ -131,7 +131,8 @@ class CefRequestImpl : public CefRequest {
|
||||
void Get(CefNavigateParams& params) const;
|
||||
|
||||
// Populate the URLFetcher object from this object.
|
||||
// Called from CefBrowserURLRequest::Context::ContinueOnOriginatingThread().
|
||||
// Called from
|
||||
// CefBrowserURLRequestOld::Context::ContinueOnOriginatingThread().
|
||||
void Get(net::URLFetcher& fetcher, int64& upload_data_size) const;
|
||||
|
||||
void SetReadOnly(bool read_only);
|
||||
|
@ -162,10 +162,16 @@ void CefResponseImpl::SetResponseHeaders(
|
||||
status_code_ = headers.response_code();
|
||||
status_text_ = headers.GetStatusText();
|
||||
|
||||
std::string mime_type, charset;
|
||||
headers.GetMimeTypeAndCharset(&mime_type, &charset);
|
||||
mime_type_ = mime_type;
|
||||
charset_ = charset;
|
||||
if (headers.IsRedirect(nullptr)) {
|
||||
// Don't report Content-Type header values for redirects.
|
||||
mime_type_.clear();
|
||||
charset_.clear();
|
||||
} else {
|
||||
std::string mime_type, charset;
|
||||
headers.GetMimeTypeAndCharset(&mime_type, &charset);
|
||||
mime_type_ = mime_type;
|
||||
charset_ = charset;
|
||||
}
|
||||
}
|
||||
|
||||
void CefResponseImpl::Set(const blink::WebURLResponse& response) {
|
||||
|
@ -3,8 +3,10 @@
|
||||
// be found in the LICENSE file.
|
||||
|
||||
#include "include/cef_urlrequest.h"
|
||||
#include "libcef/browser/browser_urlrequest_impl.h"
|
||||
#include "libcef/browser/net/browser_urlrequest_old_impl.h"
|
||||
#include "libcef/browser/net_service/browser_urlrequest_impl.h"
|
||||
#include "libcef/common/content_client.h"
|
||||
#include "libcef/common/net_service/util.h"
|
||||
#include "libcef/common/task_runner_impl.h"
|
||||
#include "libcef/renderer/render_urlrequest_impl.h"
|
||||
|
||||
@ -29,15 +31,22 @@ CefRefPtr<CefURLRequest> CefURLRequest::Create(
|
||||
|
||||
if (CefContentClient::Get()->browser()) {
|
||||
// In the browser process.
|
||||
CefRefPtr<CefBrowserURLRequest> impl =
|
||||
new CefBrowserURLRequest(request, client, request_context);
|
||||
if (impl->Start())
|
||||
return impl.get();
|
||||
if (net_service::IsEnabled()) {
|
||||
CefRefPtr<CefBrowserURLRequest> impl =
|
||||
new CefBrowserURLRequest(nullptr, request, client, request_context);
|
||||
if (impl->Start())
|
||||
return impl.get();
|
||||
} else {
|
||||
CefRefPtr<CefBrowserURLRequestOld> impl =
|
||||
new CefBrowserURLRequestOld(request, client, request_context);
|
||||
if (impl->Start())
|
||||
return impl.get();
|
||||
}
|
||||
return NULL;
|
||||
} else if (CefContentClient::Get()->renderer()) {
|
||||
// In the render process.
|
||||
CefRefPtr<CefRenderURLRequest> impl =
|
||||
new CefRenderURLRequest(request, client);
|
||||
new CefRenderURLRequest(nullptr, request, client);
|
||||
if (impl->Start())
|
||||
return impl.get();
|
||||
return NULL;
|
||||
|
@ -243,6 +243,15 @@ void CefContentRendererClient::OnGuestViewDestroyed(CefGuestView* guest_view) {
|
||||
NOTREACHED();
|
||||
}
|
||||
|
||||
blink::WebURLLoaderFactory*
|
||||
CefContentRendererClient::GetDefaultURLLoaderFactory() {
|
||||
if (!default_url_loader_factory_) {
|
||||
default_url_loader_factory_ =
|
||||
blink::Platform::Current()->CreateDefaultURLLoaderFactory();
|
||||
}
|
||||
return default_url_loader_factory_.get();
|
||||
}
|
||||
|
||||
void CefContentRendererClient::WebKitInitialized() {
|
||||
const base::CommandLine* command_line =
|
||||
base::CommandLine::ForCurrentProcess();
|
||||
@ -302,9 +311,6 @@ void CefContentRendererClient::WebKitInitialized() {
|
||||
}
|
||||
}
|
||||
|
||||
url_loader_factory_ =
|
||||
blink::Platform::Current()->CreateDefaultURLLoaderFactory();
|
||||
|
||||
// Notify the render process handler.
|
||||
CefRefPtr<CefApp> application = CefContentClient::Get()->application();
|
||||
if (application.get()) {
|
||||
|
@ -87,10 +87,9 @@ class CefContentRendererClient
|
||||
return uncaught_exception_stack_size_;
|
||||
}
|
||||
|
||||
// Used by CefRenderURLRequest to create WebURLLoaders.
|
||||
blink::WebURLLoaderFactory* url_loader_factory() const {
|
||||
return url_loader_factory_.get();
|
||||
}
|
||||
// Returns a factory that only supports unintercepted http(s) and blob
|
||||
// requests. Used by CefRenderURLRequest.
|
||||
blink::WebURLLoaderFactory* GetDefaultURLLoaderFactory();
|
||||
|
||||
void WebKitInitialized();
|
||||
|
||||
@ -169,7 +168,8 @@ class CefContentRendererClient
|
||||
std::unique_ptr<CefRenderThreadObserver> observer_;
|
||||
std::unique_ptr<web_cache::WebCacheImpl> web_cache_impl_;
|
||||
std::unique_ptr<SpellCheck> spellcheck_;
|
||||
std::unique_ptr<blink::WebURLLoaderFactory> url_loader_factory_;
|
||||
|
||||
std::unique_ptr<blink::WebURLLoaderFactory> default_url_loader_factory_;
|
||||
|
||||
// Map of RenderView pointers to CefBrowserImpl references.
|
||||
typedef std::map<content::RenderView*, CefRefPtr<CefBrowserImpl>> BrowserMap;
|
||||
|
@ -24,10 +24,11 @@
|
||||
#include "libcef/renderer/browser_impl.h"
|
||||
#include "libcef/renderer/dom_document_impl.h"
|
||||
#include "libcef/renderer/render_frame_util.h"
|
||||
#include "libcef/renderer/render_urlrequest_impl.h"
|
||||
#include "libcef/renderer/thread_util.h"
|
||||
#include "libcef/renderer/v8_impl.h"
|
||||
|
||||
#include "content/public/renderer/render_frame.h"
|
||||
#include "content/renderer/render_frame_impl.h"
|
||||
#include "third_party/blink/public/platform/web_data.h"
|
||||
#include "third_party/blink/public/platform/web_string.h"
|
||||
#include "third_party/blink/public/platform/web_url.h"
|
||||
@ -275,9 +276,36 @@ void CefFrameImpl::VisitDOM(CefRefPtr<CefDOMVisitor> visitor) {
|
||||
documentImpl->Detach();
|
||||
}
|
||||
|
||||
CefRefPtr<CefURLRequest> CefFrameImpl::CreateURLRequest(
|
||||
CefRefPtr<CefRequest> request,
|
||||
CefRefPtr<CefURLRequestClient> client) {
|
||||
CEF_REQUIRE_RT_RETURN(NULL);
|
||||
|
||||
if (!request || !client || !frame_)
|
||||
return NULL;
|
||||
|
||||
CefRefPtr<CefRenderURLRequest> impl =
|
||||
new CefRenderURLRequest(this, request, client);
|
||||
if (impl->Start())
|
||||
return impl.get();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
blink::WebURLLoaderFactory* CefFrameImpl::GetURLLoaderFactory() {
|
||||
CEF_REQUIRE_RT();
|
||||
if (!url_loader_factory_ && frame_) {
|
||||
auto render_frame = content::RenderFrameImpl::FromWebFrame(frame_);
|
||||
if (render_frame) {
|
||||
url_loader_factory_ = render_frame->CreateURLLoaderFactory();
|
||||
}
|
||||
}
|
||||
return url_loader_factory_.get();
|
||||
}
|
||||
|
||||
void CefFrameImpl::Detach() {
|
||||
browser_ = NULL;
|
||||
frame_ = NULL;
|
||||
url_loader_factory_.reset();
|
||||
}
|
||||
|
||||
void CefFrameImpl::ExecuteCommand(const std::string& command) {
|
||||
|
@ -14,7 +14,8 @@ class CefBrowserImpl;
|
||||
|
||||
namespace blink {
|
||||
class WebLocalFrame;
|
||||
}
|
||||
class WebURLLoaderFactory;
|
||||
} // namespace blink
|
||||
|
||||
// Implementation of CefFrame. CefFrameImpl objects are owned by the
|
||||
// CefBrowerImpl and will be detached when the browser is notified that the
|
||||
@ -53,6 +54,12 @@ class CefFrameImpl : public CefFrame {
|
||||
CefRefPtr<CefBrowser> GetBrowser() override;
|
||||
CefRefPtr<CefV8Context> GetV8Context() override;
|
||||
void VisitDOM(CefRefPtr<CefDOMVisitor> visitor) override;
|
||||
CefRefPtr<CefURLRequest> CreateURLRequest(
|
||||
CefRefPtr<CefRequest> request,
|
||||
CefRefPtr<CefURLRequestClient> client) override;
|
||||
|
||||
// Used by CefRenderURLRequest.
|
||||
blink::WebURLLoaderFactory* GetURLLoaderFactory();
|
||||
|
||||
void Detach();
|
||||
|
||||
@ -65,6 +72,8 @@ class CefFrameImpl : public CefFrame {
|
||||
blink::WebLocalFrame* frame_;
|
||||
int64 frame_id_;
|
||||
|
||||
std::unique_ptr<blink::WebURLLoaderFactory> url_loader_factory_;
|
||||
|
||||
IMPLEMENT_REFCOUNTING(CefFrameImpl);
|
||||
DISALLOW_COPY_AND_ASSIGN(CefFrameImpl);
|
||||
};
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include "libcef/common/cef_messages.h"
|
||||
#include "libcef/common/content_client.h"
|
||||
#include "libcef/renderer/blink_glue.h"
|
||||
#include "libcef/renderer/content_renderer_client.h"
|
||||
#include "libcef/renderer/browser_impl.h"
|
||||
#include "libcef/renderer/v8_impl.h"
|
||||
|
||||
#include "content/public/renderer/render_frame.h"
|
||||
|
@ -81,9 +81,11 @@ class CefRenderURLRequest::Context
|
||||
: public base::RefCountedThreadSafe<CefRenderURLRequest::Context> {
|
||||
public:
|
||||
Context(CefRefPtr<CefRenderURLRequest> url_request,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
CefRefPtr<CefURLRequestClient> client)
|
||||
: url_request_(url_request),
|
||||
frame_(frame),
|
||||
request_(request),
|
||||
client_(client),
|
||||
task_runner_(CefTaskRunnerImpl::GetCurrentTaskRunner()),
|
||||
@ -121,10 +123,19 @@ class CefRenderURLRequest::Context
|
||||
urlRequest.SetRequestorOrigin(
|
||||
blink::WebSecurityOrigin::Create(urlRequest.Url()));
|
||||
|
||||
loader_ =
|
||||
CefContentRendererClient::Get()->url_loader_factory()->CreateURLLoader(
|
||||
urlRequest, blink::scheduler::WebResourceLoadingTaskRunnerHandle::
|
||||
CreateUnprioritized(task_runner_.get()));
|
||||
blink::WebURLLoaderFactory* factory = nullptr;
|
||||
if (frame_) {
|
||||
// This factory supports all requests.
|
||||
factory = static_cast<CefFrameImpl*>(frame_.get())->GetURLLoaderFactory();
|
||||
}
|
||||
if (!factory) {
|
||||
// This factory only supports unintercepted http(s) and blob requests.
|
||||
factory = CefContentRendererClient::Get()->GetDefaultURLLoaderFactory();
|
||||
}
|
||||
|
||||
loader_ = factory->CreateURLLoader(
|
||||
urlRequest, blink::scheduler::WebResourceLoadingTaskRunnerHandle::
|
||||
CreateUnprioritized(task_runner_.get()));
|
||||
loader_->LoadAsynchronously(urlRequest, url_client_.get());
|
||||
return true;
|
||||
}
|
||||
@ -316,6 +327,7 @@ class CefRenderURLRequest::Context
|
||||
|
||||
// Members only accessed on the initialization thread.
|
||||
CefRefPtr<CefRenderURLRequest> url_request_;
|
||||
CefRefPtr<CefFrame> frame_;
|
||||
CefRefPtr<CefRequest> request_;
|
||||
CefRefPtr<CefURLRequestClient> client_;
|
||||
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
|
||||
@ -404,9 +416,10 @@ bool CefWebURLLoaderClient::WillFollowRedirect(
|
||||
// CefRenderURLRequest --------------------------------------------------------
|
||||
|
||||
CefRenderURLRequest::CefRenderURLRequest(
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
CefRefPtr<CefURLRequestClient> client) {
|
||||
context_ = new Context(this, request, client);
|
||||
context_ = new Context(this, frame, request, client);
|
||||
}
|
||||
|
||||
CefRenderURLRequest::~CefRenderURLRequest() {}
|
||||
|
@ -5,6 +5,7 @@
|
||||
#ifndef CEF_LIBCEF_RENDERER_RENDER_URLREQUEST_IMPL_H_
|
||||
#define CEF_LIBCEF_RENDERER_RENDER_URLREQUEST_IMPL_H_
|
||||
|
||||
#include "include/cef_frame.h"
|
||||
#include "include/cef_urlrequest.h"
|
||||
|
||||
#include "base/memory/ref_counted.h"
|
||||
@ -13,7 +14,11 @@ class CefRenderURLRequest : public CefURLRequest {
|
||||
public:
|
||||
class Context;
|
||||
|
||||
CefRenderURLRequest(CefRefPtr<CefRequest> request,
|
||||
// If |frame| is nullptr the default URLLoaderFactory will be used. That
|
||||
// factory only supports http(s) and blob requests that cannot be
|
||||
// intercepted in the browser process.
|
||||
CefRenderURLRequest(CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
CefRefPtr<CefURLRequestClient> client);
|
||||
~CefRenderURLRequest() override;
|
||||
|
||||
|
@ -9,15 +9,17 @@
|
||||
// implementations. See the translator.README.txt file in the tools directory
|
||||
// for more information.
|
||||
//
|
||||
// $hash=a30b10a968d268b0fb84c189d78c37e599361c05$
|
||||
// $hash=eaff0c45fa3549df59bb9e64d5ac189205136ed3$
|
||||
//
|
||||
|
||||
#include "libcef_dll/cpptoc/frame_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/browser_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/request_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/urlrequest_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/v8context_cpptoc.h"
|
||||
#include "libcef_dll/ctocpp/domvisitor_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/string_visitor_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/urlrequest_client_ctocpp.h"
|
||||
#include "libcef_dll/shutdown_checker.h"
|
||||
|
||||
namespace {
|
||||
@ -408,6 +410,36 @@ void CEF_CALLBACK frame_visit_dom(struct _cef_frame_t* self,
|
||||
CefFrameCppToC::Get(self)->VisitDOM(CefDOMVisitorCToCpp::Wrap(visitor));
|
||||
}
|
||||
|
||||
struct _cef_urlrequest_t* CEF_CALLBACK
|
||||
frame_create_urlrequest(struct _cef_frame_t* self,
|
||||
struct _cef_request_t* request,
|
||||
struct _cef_urlrequest_client_t* client) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
DCHECK(self);
|
||||
if (!self)
|
||||
return NULL;
|
||||
// Verify param: request; type: refptr_same
|
||||
DCHECK(request);
|
||||
if (!request)
|
||||
return NULL;
|
||||
// Verify param: client; type: refptr_diff
|
||||
DCHECK(client);
|
||||
if (!client)
|
||||
return NULL;
|
||||
|
||||
// Execute
|
||||
CefRefPtr<CefURLRequest> _retval =
|
||||
CefFrameCppToC::Get(self)->CreateURLRequest(
|
||||
CefRequestCppToC::Unwrap(request),
|
||||
CefURLRequestClientCToCpp::Wrap(client));
|
||||
|
||||
// Return type: refptr_same
|
||||
return CefURLRequestCppToC::Wrap(_retval);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// CONSTRUCTOR - Do not edit by hand.
|
||||
@ -437,6 +469,7 @@ CefFrameCppToC::CefFrameCppToC() {
|
||||
GetStruct()->get_browser = frame_get_browser;
|
||||
GetStruct()->get_v8context = frame_get_v8context;
|
||||
GetStruct()->visit_dom = frame_visit_dom;
|
||||
GetStruct()->create_urlrequest = frame_create_urlrequest;
|
||||
}
|
||||
|
||||
// DESTRUCTOR - Do not edit by hand.
|
||||
|
@ -9,7 +9,7 @@
|
||||
// implementations. See the translator.README.txt file in the tools directory
|
||||
// for more information.
|
||||
//
|
||||
// $hash=44a73e5a0632c0d3d3c4b1e5f3f929cf4834f054$
|
||||
// $hash=f85b5cfb8484052d8c0bc014dbdb27eb0f498dd9$
|
||||
//
|
||||
|
||||
#ifndef CEF_LIBCEF_DLL_CPPTOC_FRAME_CPPTOC_H_
|
||||
@ -22,9 +22,11 @@
|
||||
|
||||
#include "include/capi/cef_browser_capi.h"
|
||||
#include "include/capi/cef_frame_capi.h"
|
||||
#include "include/capi/cef_urlrequest_capi.h"
|
||||
#include "include/capi/cef_v8_capi.h"
|
||||
#include "include/cef_browser.h"
|
||||
#include "include/cef_frame.h"
|
||||
#include "include/cef_urlrequest.h"
|
||||
#include "include/cef_v8.h"
|
||||
#include "libcef_dll/cpptoc/cpptoc_ref_counted.h"
|
||||
|
||||
|
@ -9,14 +9,16 @@
|
||||
// implementations. See the translator.README.txt file in the tools directory
|
||||
// for more information.
|
||||
//
|
||||
// $hash=e1e8b50b87dbf2cb7fa8b4d53fa5ff635c51bde3$
|
||||
// $hash=301b9573f13ede3bc9cb210caaae109fdf909130$
|
||||
//
|
||||
|
||||
#include "libcef_dll/ctocpp/frame_ctocpp.h"
|
||||
#include "libcef_dll/cpptoc/domvisitor_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/string_visitor_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/urlrequest_client_cpptoc.h"
|
||||
#include "libcef_dll/ctocpp/browser_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/request_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/urlrequest_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/v8context_ctocpp.h"
|
||||
#include "libcef_dll/shutdown_checker.h"
|
||||
|
||||
@ -416,6 +418,36 @@ void CefFrameCToCpp::VisitDOM(CefRefPtr<CefDOMVisitor> visitor) {
|
||||
_struct->visit_dom(_struct, CefDOMVisitorCppToC::Wrap(visitor));
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi-icall")
|
||||
CefRefPtr<CefURLRequest> CefFrameCToCpp::CreateURLRequest(
|
||||
CefRefPtr<CefRequest> request,
|
||||
CefRefPtr<CefURLRequestClient> client) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
cef_frame_t* _struct = GetStruct();
|
||||
if (CEF_MEMBER_MISSING(_struct, create_urlrequest))
|
||||
return NULL;
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
// Verify param: request; type: refptr_same
|
||||
DCHECK(request.get());
|
||||
if (!request.get())
|
||||
return NULL;
|
||||
// Verify param: client; type: refptr_diff
|
||||
DCHECK(client.get());
|
||||
if (!client.get())
|
||||
return NULL;
|
||||
|
||||
// Execute
|
||||
cef_urlrequest_t* _retval =
|
||||
_struct->create_urlrequest(_struct, CefRequestCToCpp::Unwrap(request),
|
||||
CefURLRequestClientCppToC::Wrap(client));
|
||||
|
||||
// Return type: refptr_same
|
||||
return CefURLRequestCToCpp::Wrap(_retval);
|
||||
}
|
||||
|
||||
// CONSTRUCTOR - Do not edit by hand.
|
||||
|
||||
CefFrameCToCpp::CefFrameCToCpp() {}
|
||||
|
@ -9,7 +9,7 @@
|
||||
// implementations. See the translator.README.txt file in the tools directory
|
||||
// for more information.
|
||||
//
|
||||
// $hash=756629986a078c1403693255503cc6307215126b$
|
||||
// $hash=7479de0c460d69b7846c0c13df0ea50f3b9aeae1$
|
||||
//
|
||||
|
||||
#ifndef CEF_LIBCEF_DLL_CTOCPP_FRAME_CTOCPP_H_
|
||||
@ -22,9 +22,11 @@
|
||||
|
||||
#include "include/capi/cef_browser_capi.h"
|
||||
#include "include/capi/cef_frame_capi.h"
|
||||
#include "include/capi/cef_urlrequest_capi.h"
|
||||
#include "include/capi/cef_v8_capi.h"
|
||||
#include "include/cef_browser.h"
|
||||
#include "include/cef_frame.h"
|
||||
#include "include/cef_urlrequest.h"
|
||||
#include "include/cef_v8.h"
|
||||
#include "libcef_dll/ctocpp/ctocpp_ref_counted.h"
|
||||
|
||||
@ -63,6 +65,9 @@ class CefFrameCToCpp
|
||||
CefRefPtr<CefBrowser> GetBrowser() OVERRIDE;
|
||||
CefRefPtr<CefV8Context> GetV8Context() OVERRIDE;
|
||||
void VisitDOM(CefRefPtr<CefDOMVisitor> visitor) OVERRIDE;
|
||||
CefRefPtr<CefURLRequest> CreateURLRequest(
|
||||
CefRefPtr<CefRequest> request,
|
||||
CefRefPtr<CefURLRequestClient> client) OVERRIDE;
|
||||
};
|
||||
|
||||
#endif // CEF_LIBCEF_DLL_CTOCPP_FRAME_CTOCPP_H_
|
||||
|
@ -12,6 +12,27 @@ index 864f2a5a315a..78b71d523e86 100644
|
||||
public:
|
||||
explicit ContentServiceManagerMainDelegate(const ContentMainParams& params);
|
||||
~ContentServiceManagerMainDelegate() override;
|
||||
diff --git content/browser/devtools/devtools_instrumentation.h content/browser/devtools/devtools_instrumentation.h
|
||||
index 605e388043ac..4566dd95f0b8 100644
|
||||
--- content/browser/devtools/devtools_instrumentation.h
|
||||
+++ content/browser/devtools/devtools_instrumentation.h
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "base/optional.h"
|
||||
+#include "content/common/content_export.h"
|
||||
#include "content/common/navigation_params.mojom.h"
|
||||
#include "content/public/browser/certificate_request_result_type.h"
|
||||
#include "services/network/public/mojom/url_loader_factory.mojom.h"
|
||||
@@ -49,7 +50,7 @@ void ApplyNetworkRequestOverrides(FrameTreeNode* frame_tree_node,
|
||||
mojom::BeginNavigationParams* begin_params,
|
||||
bool* report_raw_headers);
|
||||
|
||||
-bool WillCreateURLLoaderFactory(
|
||||
+CONTENT_EXPORT bool WillCreateURLLoaderFactory(
|
||||
RenderFrameHostImpl* rfh,
|
||||
bool is_navigation,
|
||||
bool is_download,
|
||||
diff --git content/browser/renderer_host/input/synthetic_gesture_target_base.h content/browser/renderer_host/input/synthetic_gesture_target_base.h
|
||||
index 33a2d55e47ac..1700b3df2468 100644
|
||||
--- content/browser/renderer_host/input/synthetic_gesture_target_base.h
|
||||
|
@ -217,9 +217,11 @@ class ClientSchemeHandler : public CefResourceHandler {
|
||||
EXPECT_STREQ(test_results_->accept_language.data(),
|
||||
accept_language.data());
|
||||
} else {
|
||||
// Value from CefSettings.accept_language set in
|
||||
// CefTestSuite::GetSettings().
|
||||
EXPECT_STREQ(CEF_SETTINGS_ACCEPT_LANGUAGE, accept_language.data());
|
||||
// CEF_SETTINGS_ACCEPT_LANGUAGE value from
|
||||
// CefSettings.accept_language_list set in CefTestSuite::GetSettings()
|
||||
// and expanded internally by ComputeAcceptLanguageFromPref.
|
||||
EXPECT_STREQ(IsNetworkServiceEnabled() ? "en-GB,en;q=0.9" : "en-GB",
|
||||
accept_language.data());
|
||||
}
|
||||
|
||||
if (handled) {
|
||||
|
@ -417,9 +417,10 @@ void VerifyNormalRequest(const RequestRunSettings* settings,
|
||||
// Check if the default headers were sent.
|
||||
EXPECT_FALSE(GetHeaderValue(headerMap, "user-agent").empty());
|
||||
|
||||
// Verify that we get the value that was set via
|
||||
// CefSettings.accept_language_list in CefTestSuite::GetSettings().
|
||||
EXPECT_STREQ(CEF_SETTINGS_ACCEPT_LANGUAGE,
|
||||
// CEF_SETTINGS_ACCEPT_LANGUAGE value from CefSettings.accept_language_list
|
||||
// set in CefTestSuite::GetSettings() and expanded internally by
|
||||
// ComputeAcceptLanguageFromPref.
|
||||
EXPECT_STREQ(IsNetworkServiceEnabled() ? "en-GB,en;q=0.9" : "en-GB",
|
||||
GetHeaderValue(headerMap, "accept-language").c_str());
|
||||
|
||||
if (server_backend) {
|
||||
@ -1022,8 +1023,8 @@ class RequestClient : public CefURLRequestClient {
|
||||
int download_progress_ct_;
|
||||
int download_data_ct_;
|
||||
|
||||
uint64 upload_total_;
|
||||
uint64 download_total_;
|
||||
int64 upload_total_;
|
||||
int64 download_total_;
|
||||
std::string download_data_;
|
||||
CefRefPtr<CefRequest> request_;
|
||||
CefURLRequest::Status status_;
|
||||
@ -1044,9 +1045,11 @@ class RequestTestRunner : public base::RefCountedThreadSafe<RequestTestRunner> {
|
||||
|
||||
RequestTestRunner(bool is_browser_process,
|
||||
bool is_server_backend,
|
||||
bool use_frame_method,
|
||||
bool run_in_browser_process)
|
||||
: is_browser_process_(is_browser_process),
|
||||
is_server_backend_(is_server_backend),
|
||||
use_frame_method_(use_frame_method),
|
||||
run_in_browser_process_(run_in_browser_process) {
|
||||
owner_task_runner_ = CefTaskRunner::GetForCurrentThread();
|
||||
EXPECT_TRUE(owner_task_runner_.get());
|
||||
@ -1130,9 +1133,12 @@ class RequestTestRunner : public base::RefCountedThreadSafe<RequestTestRunner> {
|
||||
|
||||
// Called in either the browser or render process to run the test.
|
||||
void RunTest(RequestTestMode test_mode,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
const base::Closure& complete_callback) {
|
||||
EXPECT_TRUE(owner_task_runner_->BelongsToCurrentThread());
|
||||
|
||||
frame_ = frame;
|
||||
|
||||
const base::Closure& safe_complete_callback = base::Bind(
|
||||
&RequestTestRunner::CompleteOnCorrectThread, this, complete_callback);
|
||||
|
||||
@ -1266,6 +1272,9 @@ class RequestTestRunner : public base::RefCountedThreadSafe<RequestTestRunner> {
|
||||
// on stop redirects.
|
||||
settings_.response = CefResponse::Create();
|
||||
settings_.response->SetStatus(302);
|
||||
if (IsNetworkServiceEnabled()) {
|
||||
settings_.response->SetStatusText("Found");
|
||||
}
|
||||
|
||||
// Add a redirect request.
|
||||
settings_.redirect_request = CefRequest::Create();
|
||||
@ -1766,7 +1775,12 @@ class RequestTestRunner : public base::RefCountedThreadSafe<RequestTestRunner> {
|
||||
EXPECT_TRUE(request.get());
|
||||
|
||||
CefRefPtr<RequestClient> client = new RequestClient(complete_callback);
|
||||
CefURLRequest::Create(request, client.get(), request_context_);
|
||||
if (use_frame_method_) {
|
||||
EXPECT_TRUE(frame_);
|
||||
frame_->CreateURLRequest(request, client.get());
|
||||
} else {
|
||||
CefURLRequest::Create(request, client.get(), request_context_);
|
||||
}
|
||||
}
|
||||
|
||||
// Verify a response.
|
||||
@ -1807,7 +1821,7 @@ class RequestTestRunner : public base::RefCountedThreadSafe<RequestTestRunner> {
|
||||
EXPECT_EQ(upload_data.size(), client->upload_total_);
|
||||
} else {
|
||||
EXPECT_EQ(0, client->upload_progress_ct_);
|
||||
EXPECT_EQ((uint64)0, client->upload_total_);
|
||||
EXPECT_EQ(0, client->upload_total_);
|
||||
}
|
||||
|
||||
if (settings_.expect_download_progress) {
|
||||
@ -1815,7 +1829,7 @@ class RequestTestRunner : public base::RefCountedThreadSafe<RequestTestRunner> {
|
||||
EXPECT_EQ(settings_.response_data.size(), client->download_total_);
|
||||
} else {
|
||||
EXPECT_EQ(0, client->download_progress_ct_);
|
||||
EXPECT_EQ((uint64)0, client->download_total_);
|
||||
EXPECT_EQ(0, client->download_total_);
|
||||
}
|
||||
|
||||
if (settings_.expect_download_data) {
|
||||
@ -1999,9 +2013,10 @@ class RequestTestRunner : public base::RefCountedThreadSafe<RequestTestRunner> {
|
||||
scheme_factory_ = nullptr;
|
||||
}
|
||||
|
||||
bool is_browser_process_;
|
||||
bool is_server_backend_;
|
||||
bool run_in_browser_process_;
|
||||
const bool is_browser_process_;
|
||||
const bool is_server_backend_;
|
||||
const bool use_frame_method_;
|
||||
const bool run_in_browser_process_;
|
||||
|
||||
// Primary thread runner for the object that owns us. In the browser process
|
||||
// this will be the UI thread and in the renderer process this will be the
|
||||
@ -2010,6 +2025,9 @@ class RequestTestRunner : public base::RefCountedThreadSafe<RequestTestRunner> {
|
||||
|
||||
CefRefPtr<CefRequestContext> request_context_;
|
||||
|
||||
// Frame that originates the request. May be nullptr.
|
||||
CefRefPtr<CefFrame> frame_;
|
||||
|
||||
struct TestEntry {
|
||||
TestCallback setup;
|
||||
TestCallback run;
|
||||
@ -2045,10 +2063,17 @@ class RequestRendererTest : public ClientAppRenderer::Delegate {
|
||||
|
||||
app_ = app;
|
||||
browser_ = browser;
|
||||
frame_ = nullptr;
|
||||
|
||||
CefRefPtr<CefListValue> args = message->GetArgumentList();
|
||||
|
||||
const bool use_frame_method = args->GetBool(2);
|
||||
if (use_frame_method)
|
||||
frame_ = browser->GetMainFrame();
|
||||
|
||||
test_mode_ = static_cast<RequestTestMode>(args->GetInt(0));
|
||||
test_runner_ = new RequestTestRunner(false, args->GetBool(1), false);
|
||||
test_runner_ = new RequestTestRunner(false, args->GetBool(1),
|
||||
use_frame_method, false);
|
||||
|
||||
// Setup the test. This will create the objects that we test against but
|
||||
// not register any backend (because we're in the render process).
|
||||
@ -2068,7 +2093,8 @@ class RequestRendererTest : public ClientAppRenderer::Delegate {
|
||||
|
||||
// Run the test.
|
||||
test_runner_->RunTest(
|
||||
test_mode_, base::Bind(&RequestRendererTest::OnRunComplete, this));
|
||||
test_mode_, frame_,
|
||||
base::Bind(&RequestRendererTest::OnRunComplete, this));
|
||||
}
|
||||
|
||||
void OnRunComplete() {
|
||||
@ -2097,6 +2123,7 @@ class RequestRendererTest : public ClientAppRenderer::Delegate {
|
||||
|
||||
CefRefPtr<ClientAppRenderer> app_;
|
||||
CefRefPtr<CefBrowser> browser_;
|
||||
CefRefPtr<CefFrame> frame_;
|
||||
RequestTestMode test_mode_;
|
||||
|
||||
scoped_refptr<RequestTestRunner> test_runner_;
|
||||
@ -2112,11 +2139,13 @@ class RequestTestHandler : public TestHandler {
|
||||
ContextTestMode context_mode,
|
||||
bool test_in_browser,
|
||||
bool test_server_backend,
|
||||
bool test_frame_method,
|
||||
const char* test_url)
|
||||
: test_mode_(test_mode),
|
||||
context_mode_(context_mode),
|
||||
test_in_browser_(test_in_browser),
|
||||
test_server_backend_(test_server_backend),
|
||||
test_frame_method_(test_frame_method),
|
||||
test_url_(test_url) {}
|
||||
|
||||
void RunTest() override {
|
||||
@ -2148,8 +2177,8 @@ class RequestTestHandler : public TestHandler {
|
||||
void PreSetupContinue() {
|
||||
EXPECT_TRUE(CefCurrentlyOn(TID_UI));
|
||||
|
||||
test_runner_ =
|
||||
new RequestTestRunner(true, test_server_backend_, test_in_browser_);
|
||||
test_runner_ = new RequestTestRunner(true, test_server_backend_,
|
||||
test_frame_method_, test_in_browser_);
|
||||
|
||||
// Get or create the request context.
|
||||
if (context_mode_ == CONTEXT_GLOBAL) {
|
||||
@ -2222,9 +2251,20 @@ class RequestTestHandler : public TestHandler {
|
||||
}
|
||||
|
||||
if (test_in_browser_) {
|
||||
// Run the test now.
|
||||
test_runner_->RunTest(
|
||||
test_mode_, base::Bind(&RequestTestHandler::OnRunComplete, this));
|
||||
if (test_frame_method_) {
|
||||
EXPECT_TRUE(test_url_ != NULL);
|
||||
AddResource(test_url_, "<html><body>TEST</body></html>", "text/html");
|
||||
|
||||
// Create the browser who's main frame will be the initiator for the
|
||||
// request.
|
||||
CreateBrowser(test_url_, test_runner_->GetRequestContext());
|
||||
} else {
|
||||
// Run the test now.
|
||||
test_running_ = true;
|
||||
test_runner_->RunTest(
|
||||
test_mode_, nullptr /* frame */,
|
||||
base::Bind(&RequestTestHandler::OnRunComplete, this));
|
||||
}
|
||||
} else {
|
||||
EXPECT_TRUE(test_url_ != NULL);
|
||||
AddResource(test_url_, "<html><body>TEST</body></html>", "text/html");
|
||||
@ -2234,9 +2274,33 @@ class RequestTestHandler : public TestHandler {
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue OnBeforeResourceLoad(
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
CefRefPtr<CefRequestCallback> callback) override {
|
||||
if (test_running_ && test_frame_method_) {
|
||||
EXPECT_TRUE(frame);
|
||||
EXPECT_EQ(test_frame_->GetIdentifier(), frame->GetIdentifier());
|
||||
test_frame_resource_load_ct_++;
|
||||
}
|
||||
|
||||
return TestHandler::OnBeforeResourceLoad(browser, frame, request, callback);
|
||||
}
|
||||
|
||||
void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
int httpStatusCode) override {
|
||||
if (test_in_browser_ && test_frame_method_) {
|
||||
// Run the test now.
|
||||
test_frame_ = frame;
|
||||
test_running_ = true;
|
||||
test_runner_->RunTest(
|
||||
test_mode_, frame,
|
||||
base::Bind(&RequestTestHandler::OnRunComplete, this));
|
||||
return;
|
||||
}
|
||||
|
||||
EXPECT_FALSE(test_in_browser_);
|
||||
if (frame->IsMain()) {
|
||||
CefRefPtr<CefProcessMessage> test_message =
|
||||
@ -2244,6 +2308,11 @@ class RequestTestHandler : public TestHandler {
|
||||
CefRefPtr<CefListValue> args = test_message->GetArgumentList();
|
||||
EXPECT_TRUE(args->SetInt(0, test_mode_));
|
||||
EXPECT_TRUE(args->SetBool(1, test_server_backend_));
|
||||
EXPECT_TRUE(args->SetBool(2, test_frame_method_));
|
||||
|
||||
if (test_frame_method_)
|
||||
test_frame_ = frame;
|
||||
test_running_ = true;
|
||||
|
||||
// Send a message to the renderer process to run the test.
|
||||
EXPECT_TRUE(browser->SendProcessMessage(PID_RENDERER, test_message));
|
||||
@ -2296,14 +2365,22 @@ class RequestTestHandler : public TestHandler {
|
||||
EXPECT_TRUE(got_success_);
|
||||
}
|
||||
|
||||
if (IsNetworkServiceEnabled()) {
|
||||
if (test_frame_method_) {
|
||||
// Expect at least 1 call to OnBeforeResourceLoad for every test.
|
||||
// Redirect tests may get multiple calls.
|
||||
EXPECT_LE(1, test_frame_resource_load_ct_);
|
||||
}
|
||||
}
|
||||
|
||||
TestHandler::DestroyTest();
|
||||
|
||||
// Need to call TestComplete() explicitly if testing in the browser and
|
||||
// using the global context. Otherwise, TestComplete() will be called when
|
||||
// the browser is destroyed (for render test + global context) or when the
|
||||
// temporary context is destroyed.
|
||||
const bool call_test_complete =
|
||||
(test_in_browser_ && context_mode_ == CONTEXT_GLOBAL);
|
||||
const bool call_test_complete = (test_in_browser_ && !test_frame_method_ &&
|
||||
context_mode_ == CONTEXT_GLOBAL);
|
||||
|
||||
// Release our reference to the context. Do not access any object members
|
||||
// after this call because |this| might be deleted.
|
||||
@ -2376,14 +2453,20 @@ class RequestTestHandler : public TestHandler {
|
||||
IMPLEMENT_REFCOUNTING(SupportedSchemesCompletionCallback);
|
||||
};
|
||||
|
||||
RequestTestMode test_mode_;
|
||||
ContextTestMode context_mode_;
|
||||
bool test_in_browser_;
|
||||
bool test_server_backend_;
|
||||
const char* test_url_;
|
||||
const RequestTestMode test_mode_;
|
||||
const ContextTestMode context_mode_;
|
||||
const bool test_in_browser_;
|
||||
const bool test_server_backend_;
|
||||
const bool test_frame_method_;
|
||||
const char* const test_url_;
|
||||
|
||||
scoped_refptr<RequestTestRunner> test_runner_;
|
||||
|
||||
bool test_running_ = false;
|
||||
|
||||
CefRefPtr<CefFrame> test_frame_;
|
||||
int test_frame_resource_load_ct_ = 0;
|
||||
|
||||
CefScopedTempDir context_tmpdir_;
|
||||
CefString context_tmpdir_path_;
|
||||
|
||||
@ -2395,6 +2478,21 @@ class RequestTestHandler : public TestHandler {
|
||||
IMPLEMENT_REFCOUNTING(RequestTestHandler);
|
||||
};
|
||||
|
||||
bool IsTestSupported(RequestTestMode test_mode,
|
||||
ContextTestMode context_mode,
|
||||
bool test_in_browser,
|
||||
bool test_server_backend,
|
||||
bool test_frame_method) {
|
||||
if (IsNetworkServiceEnabled() && !test_in_browser && !test_server_backend &&
|
||||
!test_frame_method) {
|
||||
// When NetworkService is enabled requests from the render process can only
|
||||
// reach non-server backends when using the CefFrame::CreateURLRequest
|
||||
// method.
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// Entry point for creating URLRequest renderer test objects.
|
||||
@ -2415,119 +2513,152 @@ void RegisterURLRequestCustomSchemes(
|
||||
}
|
||||
|
||||
// Helpers for defining URLRequest tests.
|
||||
#define REQ_TEST_EX(name, test_mode, context_mode, test_in_browser, \
|
||||
test_server_backend, test_url) \
|
||||
TEST(URLRequestTest, name) { \
|
||||
CefRefPtr<RequestTestHandler> handler = \
|
||||
new RequestTestHandler(test_mode, context_mode, test_in_browser, \
|
||||
test_server_backend, test_url); \
|
||||
handler->ExecuteTest(); \
|
||||
ReleaseAndWaitForDestructor(handler); \
|
||||
#define REQ_TEST_EX(name, test_mode, context_mode, test_in_browser, \
|
||||
test_server_backend, test_frame_method, test_url) \
|
||||
TEST(URLRequestTest, name) { \
|
||||
if (!IsTestSupported(test_mode, context_mode, test_in_browser, \
|
||||
test_server_backend, test_frame_method)) { \
|
||||
return; \
|
||||
} \
|
||||
CefRefPtr<RequestTestHandler> handler = new RequestTestHandler( \
|
||||
test_mode, context_mode, test_in_browser, test_server_backend, \
|
||||
test_frame_method, test_url); \
|
||||
handler->ExecuteTest(); \
|
||||
ReleaseAndWaitForDestructor(handler); \
|
||||
}
|
||||
|
||||
#define REQ_TEST(name, test_mode, context_mode, test_in_browser, \
|
||||
test_server_backend) \
|
||||
test_server_backend, test_frame_method) \
|
||||
REQ_TEST_EX(name, test_mode, context_mode, test_in_browser, \
|
||||
test_server_backend, kRequestTestUrl)
|
||||
test_server_backend, test_frame_method, kRequestTestUrl)
|
||||
|
||||
// Define the tests.
|
||||
#define REQ_TEST_SET(suffix, context_mode, test_server_backend) \
|
||||
#define REQ_TEST_SET_EX(suffix, context_mode, test_server_backend, \
|
||||
test_frame_method) \
|
||||
REQ_TEST(BrowserGET##suffix, REQTEST_GET, context_mode, true, \
|
||||
test_server_backend) \
|
||||
test_server_backend, test_frame_method) \
|
||||
REQ_TEST(BrowserGETNoData##suffix, REQTEST_GET_NODATA, context_mode, true, \
|
||||
test_server_backend) \
|
||||
test_server_backend, test_frame_method) \
|
||||
REQ_TEST(BrowserGETAllowCookies##suffix, REQTEST_GET_ALLOWCOOKIES, \
|
||||
context_mode, true, test_server_backend) \
|
||||
context_mode, true, test_server_backend, test_frame_method) \
|
||||
REQ_TEST(BrowserGETRedirect##suffix, REQTEST_GET_REDIRECT, context_mode, \
|
||||
true, test_server_backend) \
|
||||
true, test_server_backend, test_frame_method) \
|
||||
REQ_TEST(BrowserGETRedirectStop##suffix, REQTEST_GET_REDIRECT_STOP, \
|
||||
context_mode, true, test_server_backend) \
|
||||
context_mode, true, test_server_backend, test_frame_method) \
|
||||
REQ_TEST(BrowserGETRedirectLocation##suffix, REQTEST_GET_REDIRECT_LOCATION, \
|
||||
context_mode, true, test_server_backend) \
|
||||
context_mode, true, test_server_backend, test_frame_method) \
|
||||
REQ_TEST(BrowserGETReferrer##suffix, REQTEST_GET_REFERRER, context_mode, \
|
||||
true, test_server_backend) \
|
||||
true, test_server_backend, test_frame_method) \
|
||||
REQ_TEST(BrowserPOST##suffix, REQTEST_POST, context_mode, true, \
|
||||
test_server_backend) \
|
||||
test_server_backend, test_frame_method) \
|
||||
REQ_TEST(BrowserPOSTFile##suffix, REQTEST_POST_FILE, context_mode, true, \
|
||||
test_server_backend) \
|
||||
test_server_backend, test_frame_method) \
|
||||
REQ_TEST(BrowserPOSTWithProgress##suffix, REQTEST_POST_WITHPROGRESS, \
|
||||
context_mode, true, test_server_backend) \
|
||||
context_mode, true, test_server_backend, test_frame_method) \
|
||||
REQ_TEST(BrowserHEAD##suffix, REQTEST_HEAD, context_mode, true, \
|
||||
test_server_backend) \
|
||||
test_server_backend, test_frame_method) \
|
||||
REQ_TEST(RendererGET##suffix, REQTEST_GET, context_mode, false, \
|
||||
test_server_backend) \
|
||||
test_server_backend, test_frame_method) \
|
||||
REQ_TEST(RendererGETNoData##suffix, REQTEST_GET_NODATA, context_mode, false, \
|
||||
test_server_backend) \
|
||||
test_server_backend, test_frame_method) \
|
||||
REQ_TEST(RendererGETAllowCookies##suffix, REQTEST_GET_ALLOWCOOKIES, \
|
||||
context_mode, false, test_server_backend) \
|
||||
context_mode, false, test_server_backend, test_frame_method) \
|
||||
REQ_TEST(RendererGETRedirect##suffix, REQTEST_GET_REDIRECT, context_mode, \
|
||||
false, test_server_backend) \
|
||||
false, test_server_backend, test_frame_method) \
|
||||
REQ_TEST(RendererGETRedirectStop##suffix, REQTEST_GET_REDIRECT_STOP, \
|
||||
context_mode, false, test_server_backend) \
|
||||
context_mode, false, test_server_backend, test_frame_method) \
|
||||
REQ_TEST(RendererGETRedirectLocation##suffix, REQTEST_GET_REDIRECT_LOCATION, \
|
||||
context_mode, false, test_server_backend) \
|
||||
context_mode, false, test_server_backend, test_frame_method) \
|
||||
REQ_TEST(RendererGETReferrer##suffix, REQTEST_GET_REFERRER, context_mode, \
|
||||
false, test_server_backend) \
|
||||
false, test_server_backend, test_frame_method) \
|
||||
REQ_TEST(RendererPOST##suffix, REQTEST_POST, context_mode, false, \
|
||||
test_server_backend) \
|
||||
test_server_backend, test_frame_method) \
|
||||
REQ_TEST(RendererPOSTWithProgress##suffix, REQTEST_POST_WITHPROGRESS, \
|
||||
context_mode, false, test_server_backend) \
|
||||
context_mode, false, test_server_backend, test_frame_method) \
|
||||
REQ_TEST(RendererHEAD##suffix, REQTEST_HEAD, context_mode, false, \
|
||||
test_server_backend)
|
||||
test_server_backend, test_frame_method)
|
||||
|
||||
REQ_TEST_SET(ContextGlobalCustom, CONTEXT_GLOBAL, false)
|
||||
REQ_TEST_SET(ContextInMemoryCustom, CONTEXT_INMEMORY, false)
|
||||
REQ_TEST_SET(ContextOnDiskCustom, CONTEXT_ONDISK, false)
|
||||
REQ_TEST_SET(ContextGlobalServer, CONTEXT_GLOBAL, true)
|
||||
REQ_TEST_SET(ContextInMemoryServer, CONTEXT_INMEMORY, true)
|
||||
REQ_TEST_SET(ContextOnDiskServer, CONTEXT_ONDISK, true)
|
||||
#define REQ_TEST_SET(suffix, test_frame_method) \
|
||||
REQ_TEST_SET_EX(ContextGlobalCustom##suffix, CONTEXT_GLOBAL, false, \
|
||||
test_frame_method) \
|
||||
REQ_TEST_SET_EX(ContextInMemoryCustom##suffix, CONTEXT_INMEMORY, false, \
|
||||
test_frame_method) \
|
||||
REQ_TEST_SET_EX(ContextOnDiskCustom##suffix, CONTEXT_ONDISK, false, \
|
||||
test_frame_method) \
|
||||
REQ_TEST_SET_EX(ContextGlobalServer##suffix, CONTEXT_GLOBAL, true, \
|
||||
test_frame_method) \
|
||||
REQ_TEST_SET_EX(ContextInMemoryServer##suffix, CONTEXT_INMEMORY, true, \
|
||||
test_frame_method) \
|
||||
REQ_TEST_SET_EX(ContextOnDiskServer##suffix, CONTEXT_ONDISK, true, \
|
||||
test_frame_method)
|
||||
|
||||
REQ_TEST_SET(WithoutFrame, false)
|
||||
REQ_TEST_SET(WithFrame, true)
|
||||
|
||||
// Cache tests can only be run with the server backend.
|
||||
#define REQ_TEST_CACHE_SET(suffix, context_mode) \
|
||||
#define REQ_TEST_CACHE_SET_EX(suffix, context_mode, test_frame_method) \
|
||||
REQ_TEST(BrowserGETCacheWithControl##suffix, REQTEST_CACHE_WITH_CONTROL, \
|
||||
context_mode, true, true) \
|
||||
context_mode, true, true, test_frame_method) \
|
||||
REQ_TEST(BrowserGETCacheWithoutControl##suffix, \
|
||||
REQTEST_CACHE_WITHOUT_CONTROL, context_mode, true, true) \
|
||||
REQTEST_CACHE_WITHOUT_CONTROL, context_mode, true, true, \
|
||||
test_frame_method) \
|
||||
REQ_TEST(BrowserGETCacheSkipFlag##suffix, REQTEST_CACHE_SKIP_FLAG, \
|
||||
context_mode, true, true) \
|
||||
context_mode, true, true, test_frame_method) \
|
||||
REQ_TEST(BrowserGETCacheSkipHeader##suffix, REQTEST_CACHE_SKIP_HEADER, \
|
||||
context_mode, true, true) \
|
||||
context_mode, true, true, test_frame_method) \
|
||||
REQ_TEST(BrowserGETCacheOnlyFailureFlag##suffix, \
|
||||
REQTEST_CACHE_ONLY_FAILURE_FLAG, context_mode, true, true) \
|
||||
REQTEST_CACHE_ONLY_FAILURE_FLAG, context_mode, true, true, \
|
||||
test_frame_method) \
|
||||
REQ_TEST(BrowserGETCacheOnlyFailureHeader##suffix, \
|
||||
REQTEST_CACHE_ONLY_FAILURE_HEADER, context_mode, true, true) \
|
||||
REQTEST_CACHE_ONLY_FAILURE_HEADER, context_mode, true, true, \
|
||||
test_frame_method) \
|
||||
REQ_TEST(BrowserGETCacheOnlySuccessFlag##suffix, \
|
||||
REQTEST_CACHE_ONLY_SUCCESS_FLAG, context_mode, true, true) \
|
||||
REQTEST_CACHE_ONLY_SUCCESS_FLAG, context_mode, true, true, \
|
||||
test_frame_method) \
|
||||
REQ_TEST(BrowserGETCacheOnlySuccessHeader##suffix, \
|
||||
REQTEST_CACHE_ONLY_SUCCESS_HEADER, context_mode, true, true) \
|
||||
REQTEST_CACHE_ONLY_SUCCESS_HEADER, context_mode, true, true, \
|
||||
test_frame_method) \
|
||||
REQ_TEST(BrowserGETCacheDisableFlag##suffix, REQTEST_CACHE_DISABLE_FLAG, \
|
||||
context_mode, true, true) \
|
||||
context_mode, true, true, test_frame_method) \
|
||||
REQ_TEST(BrowserGETCacheDisableHeader##suffix, REQTEST_CACHE_DISABLE_HEADER, \
|
||||
context_mode, true, true) \
|
||||
context_mode, true, true, test_frame_method) \
|
||||
REQ_TEST(RendererGETCacheWithControl##suffix, REQTEST_CACHE_WITH_CONTROL, \
|
||||
context_mode, false, true) \
|
||||
context_mode, false, true, test_frame_method) \
|
||||
REQ_TEST(RendererGETCacheWithoutControl##suffix, \
|
||||
REQTEST_CACHE_WITHOUT_CONTROL, context_mode, false, true) \
|
||||
REQTEST_CACHE_WITHOUT_CONTROL, context_mode, false, true, \
|
||||
test_frame_method) \
|
||||
REQ_TEST(RendererGETCacheSkipFlag##suffix, REQTEST_CACHE_SKIP_FLAG, \
|
||||
context_mode, false, true) \
|
||||
context_mode, false, true, test_frame_method) \
|
||||
REQ_TEST(RendererGETCacheSkipHeader##suffix, REQTEST_CACHE_SKIP_HEADER, \
|
||||
context_mode, false, true) \
|
||||
context_mode, false, true, test_frame_method) \
|
||||
REQ_TEST(RendererGETCacheOnlyFailureFlag##suffix, \
|
||||
REQTEST_CACHE_ONLY_FAILURE_FLAG, context_mode, false, true) \
|
||||
REQTEST_CACHE_ONLY_FAILURE_FLAG, context_mode, false, true, \
|
||||
test_frame_method) \
|
||||
REQ_TEST(RendererGETCacheOnlyFailureHeader##suffix, \
|
||||
REQTEST_CACHE_ONLY_FAILURE_HEADER, context_mode, false, true) \
|
||||
REQTEST_CACHE_ONLY_FAILURE_HEADER, context_mode, false, true, \
|
||||
test_frame_method) \
|
||||
REQ_TEST(RendererGETCacheOnlySuccessFlag##suffix, \
|
||||
REQTEST_CACHE_ONLY_SUCCESS_FLAG, context_mode, false, true) \
|
||||
REQTEST_CACHE_ONLY_SUCCESS_FLAG, context_mode, false, true, \
|
||||
test_frame_method) \
|
||||
REQ_TEST(RendererGETCacheOnlySuccessHeader##suffix, \
|
||||
REQTEST_CACHE_ONLY_SUCCESS_HEADER, context_mode, false, true) \
|
||||
REQTEST_CACHE_ONLY_SUCCESS_HEADER, context_mode, false, true, \
|
||||
test_frame_method) \
|
||||
REQ_TEST(RendererGETCacheDisableFlag##suffix, REQTEST_CACHE_DISABLE_FLAG, \
|
||||
context_mode, false, true) \
|
||||
context_mode, false, true, test_frame_method) \
|
||||
REQ_TEST(RendererGETCacheDisableHeader##suffix, \
|
||||
REQTEST_CACHE_DISABLE_HEADER, context_mode, false, true)
|
||||
REQTEST_CACHE_DISABLE_HEADER, context_mode, false, true, \
|
||||
test_frame_method)
|
||||
|
||||
REQ_TEST_CACHE_SET(ContextGlobalServer, CONTEXT_GLOBAL)
|
||||
REQ_TEST_CACHE_SET(ContextInMemoryServer, CONTEXT_INMEMORY)
|
||||
REQ_TEST_CACHE_SET(ContextOnDiskServer, CONTEXT_ONDISK)
|
||||
#define REQ_TEST_CACHE_SET(suffix, test_frame_method) \
|
||||
REQ_TEST_CACHE_SET_EX(ContextGlobalServer##suffix, CONTEXT_GLOBAL, \
|
||||
test_frame_method) \
|
||||
REQ_TEST_CACHE_SET_EX(ContextInMemoryServer##suffix, CONTEXT_INMEMORY, \
|
||||
test_frame_method) \
|
||||
REQ_TEST_CACHE_SET_EX(ContextOnDiskServer##suffix, CONTEXT_ONDISK, \
|
||||
test_frame_method)
|
||||
|
||||
REQ_TEST_CACHE_SET(WithoutFrame, false)
|
||||
REQ_TEST_CACHE_SET(WithFrame, true)
|
||||
|
||||
namespace {
|
||||
|
||||
@ -2546,6 +2677,9 @@ class InvalidURLTestClient : public CefURLRequestClient {
|
||||
|
||||
void OnRequestComplete(CefRefPtr<CefURLRequest> client) override {
|
||||
EXPECT_EQ(UR_FAILED, client->GetRequestStatus());
|
||||
if (IsNetworkServiceEnabled()) {
|
||||
EXPECT_EQ(ERR_UNKNOWN_URL_SCHEME, client->GetRequestError());
|
||||
}
|
||||
|
||||
// Let the call stack unwind before signaling completion.
|
||||
CefPostTask(TID_UI,
|
||||
|
Loading…
x
Reference in New Issue
Block a user