Implement NetworkService request interception/handling (see issue #2622).

Implementation notes:
- Chromium change: CookieMonster::SetCookieableSchemes needs to be called
  immediately after the CookieMonster is created in NetworkContext::
  ApplyContextParamsToBuilder. Add a Profile::GetCookieableSchemes method and
  NetworkContextParams.cookieable_schemes member (set from
  ProfileNetworkContextService::CreateNetworkContextParams) to support that.
- Chromium change: Add a ContentBrowserClient::HandleExternalProtocol variant
  that exposes additional NetworkService request information.
- GetResourceResponseFilter is not yet implemented.

API changes:
- Resource-related callbacks have been moved from CefRequestHandler to a new
  CefResourceRequestHandler interface which is returned via the
  GetResourceRequestHandler method. If the CefRequestHandler declines to handle
  a resource it can optionally be handled by the CefRequestContextHandler, if
  any, associated with the loading context.
- The OnProtocolExecution callback has been moved from CefRequestHandler to
  CefResourceRequestHandler and will be called if a custom scheme request is
  unhandled.
- Cookie send/save permission callbacks have been moved from CefRequestHandler
  and CefResourceHandler to CefResourceRequestHandler.
- New methods added to CefResourceHandler that better match NetworkService
  execution sequence expectations. The old methods are now deprecated.
- New methods added to CefRequest and CefResponse.

Known behavior changes with the NetworkService implementation:
- Modifying the |new_url| parameter in OnResourceRedirect will no longer result
  in the method being called an additional time (likely a bug in the old
  implementation).
- Modifying the request URL in OnResourceResponse would previously cause a
  redirect. This behavior is now deprecated because the NetworkService does not
  support this functionality when using default network loaders. Temporary
  support has been added in combination with CefResourceHandler usage only.
- Other changes to the request object in OnResourceResponse will now cause the
  request to be restarted. This means that OnBeforeResourceLoad, etc, will be
  called an additional time with the new request information.
- CefResponse::GetMimeType will now be empty for non-200 responses.
- Requests using custom schemes can now be handled via CefResourceRequestHandler
  with the same callback behavior as builtin schemes.
- Redirects of custom scheme requests will now be followed as expected.
- Default handling of builtin schemes can now be disabled by setting
  |disable_default_handling| to true in GetResourceRequestHandler.
- Unhandled requests (custom scheme or builtin scheme with default handling
  disabled) will fail with an CefResponse::GetError value of
  ERR_UNKNOWN_URL_SCHEME.
- The CefSchemeHandlerFactory::Create callback will now include cookie headers.

To test:
- Run `cefclient --enable-network-service`. All resources should load
  successfully (this tests the transparent proxy capability).
- All tests pass with NetworkService disabled.
- The following tests pass with NetworkService enabled:
  - CookieTest.*
  - FrameTest.* (excluding .*Nav)
  - NavigationTest.* (excluding .Redirect*)
  - RequestHandlerTest.*
  - RequestContextTest.Basic*
  - RequestContextTest.Popup*
  - RequestTest.*
  - ResourceManagerTest.*
  - ResourceRequestHandlerTest.* (excluding .Filter*)
  - SchemeHandlerTest.*
  - StreamResourceHandlerTest.*
This commit is contained in:
Marshall Greenblatt
2019-04-24 02:50:25 +00:00
parent 019611c764
commit 8f240861e3
141 changed files with 12733 additions and 3927 deletions

View File

@ -9,18 +9,16 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=9353ea1707598e400907e00b1338270ee90c97b0$
// $hash=370a54c21bec2aff5cf62b5897f5d43401e1ec31$
//
#include "libcef_dll/cpptoc/request_handler_cpptoc.h"
#include "libcef_dll/cpptoc/resource_handler_cpptoc.h"
#include "libcef_dll/cpptoc/response_filter_cpptoc.h"
#include "libcef_dll/cpptoc/resource_request_handler_cpptoc.h"
#include "libcef_dll/ctocpp/auth_callback_ctocpp.h"
#include "libcef_dll/ctocpp/browser_ctocpp.h"
#include "libcef_dll/ctocpp/frame_ctocpp.h"
#include "libcef_dll/ctocpp/request_callback_ctocpp.h"
#include "libcef_dll/ctocpp/request_ctocpp.h"
#include "libcef_dll/ctocpp/response_ctocpp.h"
#include "libcef_dll/ctocpp/select_client_certificate_callback_ctocpp.h"
#include "libcef_dll/ctocpp/sslinfo_ctocpp.h"
#include "libcef_dll/ctocpp/x509certificate_ctocpp.h"
@ -103,173 +101,16 @@ int CEF_CALLBACK request_handler_on_open_urlfrom_tab(
return _retval;
}
cef_return_value_t CEF_CALLBACK
request_handler_on_before_resource_load(struct _cef_request_handler_t* self,
cef_browser_t* browser,
cef_frame_t* frame,
cef_request_t* request,
cef_request_callback_t* callback) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return RV_CONTINUE;
// Verify param: browser; type: refptr_diff
DCHECK(browser);
if (!browser)
return RV_CONTINUE;
// Verify param: frame; type: refptr_diff
DCHECK(frame);
if (!frame)
return RV_CONTINUE;
// Verify param: request; type: refptr_diff
DCHECK(request);
if (!request)
return RV_CONTINUE;
// Verify param: callback; type: refptr_diff
DCHECK(callback);
if (!callback)
return RV_CONTINUE;
// Execute
cef_return_value_t _retval =
CefRequestHandlerCppToC::Get(self)->OnBeforeResourceLoad(
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame),
CefRequestCToCpp::Wrap(request),
CefRequestCallbackCToCpp::Wrap(callback));
// Return type: simple
return _retval;
}
struct _cef_resource_handler_t* CEF_CALLBACK
request_handler_get_resource_handler(struct _cef_request_handler_t* self,
cef_browser_t* browser,
cef_frame_t* frame,
cef_request_t* request) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return NULL;
// Verify param: browser; type: refptr_diff
DCHECK(browser);
if (!browser)
return NULL;
// Verify param: frame; type: refptr_diff
DCHECK(frame);
if (!frame)
return NULL;
// Verify param: request; type: refptr_diff
DCHECK(request);
if (!request)
return NULL;
// Execute
CefRefPtr<CefResourceHandler> _retval =
CefRequestHandlerCppToC::Get(self)->GetResourceHandler(
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame),
CefRequestCToCpp::Wrap(request));
// Return type: refptr_same
return CefResourceHandlerCppToC::Wrap(_retval);
}
void CEF_CALLBACK
request_handler_on_resource_redirect(struct _cef_request_handler_t* self,
cef_browser_t* browser,
cef_frame_t* frame,
cef_request_t* request,
struct _cef_response_t* response,
cef_string_t* new_url) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return;
// Verify param: browser; type: refptr_diff
DCHECK(browser);
if (!browser)
return;
// Verify param: frame; type: refptr_diff
DCHECK(frame);
if (!frame)
return;
// Verify param: request; type: refptr_diff
DCHECK(request);
if (!request)
return;
// Verify param: response; type: refptr_diff
DCHECK(response);
if (!response)
return;
// Verify param: new_url; type: string_byref
DCHECK(new_url);
if (!new_url)
return;
// Translate param: new_url; type: string_byref
CefString new_urlStr(new_url);
// Execute
CefRequestHandlerCppToC::Get(self)->OnResourceRedirect(
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame),
CefRequestCToCpp::Wrap(request), CefResponseCToCpp::Wrap(response),
new_urlStr);
}
int CEF_CALLBACK
request_handler_on_resource_response(struct _cef_request_handler_t* self,
cef_browser_t* browser,
cef_frame_t* frame,
cef_request_t* request,
struct _cef_response_t* response) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Verify param: browser; type: refptr_diff
DCHECK(browser);
if (!browser)
return 0;
// Verify param: frame; type: refptr_diff
DCHECK(frame);
if (!frame)
return 0;
// Verify param: request; type: refptr_diff
DCHECK(request);
if (!request)
return 0;
// Verify param: response; type: refptr_diff
DCHECK(response);
if (!response)
return 0;
// Execute
bool _retval = CefRequestHandlerCppToC::Get(self)->OnResourceResponse(
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame),
CefRequestCToCpp::Wrap(request), CefResponseCToCpp::Wrap(response));
// Return type: bool
return _retval;
}
struct _cef_response_filter_t* CEF_CALLBACK
request_handler_get_resource_response_filter(
struct _cef_resource_request_handler_t* CEF_CALLBACK
request_handler_get_resource_request_handler(
struct _cef_request_handler_t* self,
cef_browser_t* browser,
cef_frame_t* frame,
cef_request_t* request,
struct _cef_response_t* response) {
int is_navigation,
int is_download,
const cef_string_t* request_initiator,
int* disable_default_handling) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
@ -289,58 +130,30 @@ request_handler_get_resource_response_filter(
DCHECK(request);
if (!request)
return NULL;
// Verify param: response; type: refptr_diff
DCHECK(response);
if (!response)
// Verify param: disable_default_handling; type: bool_byref
DCHECK(disable_default_handling);
if (!disable_default_handling)
return NULL;
// Unverified params: request_initiator
// Translate param: disable_default_handling; type: bool_byref
bool disable_default_handlingBool =
(disable_default_handling && *disable_default_handling) ? true : false;
// Execute
CefRefPtr<CefResponseFilter> _retval =
CefRequestHandlerCppToC::Get(self)->GetResourceResponseFilter(
CefRefPtr<CefResourceRequestHandler> _retval =
CefRequestHandlerCppToC::Get(self)->GetResourceRequestHandler(
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame),
CefRequestCToCpp::Wrap(request), CefResponseCToCpp::Wrap(response));
CefRequestCToCpp::Wrap(request), is_navigation ? true : false,
is_download ? true : false, CefString(request_initiator),
disable_default_handlingBool);
// Restore param: disable_default_handling; type: bool_byref
if (disable_default_handling)
*disable_default_handling = disable_default_handlingBool ? true : false;
// Return type: refptr_same
return CefResponseFilterCppToC::Wrap(_retval);
}
void CEF_CALLBACK
request_handler_on_resource_load_complete(struct _cef_request_handler_t* self,
cef_browser_t* browser,
cef_frame_t* frame,
cef_request_t* request,
struct _cef_response_t* response,
cef_urlrequest_status_t status,
int64 received_content_length) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return;
// Verify param: browser; type: refptr_diff
DCHECK(browser);
if (!browser)
return;
// Verify param: frame; type: refptr_diff
DCHECK(frame);
if (!frame)
return;
// Verify param: request; type: refptr_diff
DCHECK(request);
if (!request)
return;
// Verify param: response; type: refptr_diff
DCHECK(response);
if (!response)
return;
// Execute
CefRequestHandlerCppToC::Get(self)->OnResourceLoadComplete(
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame),
CefRequestCToCpp::Wrap(request), CefResponseCToCpp::Wrap(response),
status, received_content_length);
return CefResourceRequestHandlerCppToC::Wrap(_retval);
}
int CEF_CALLBACK
@ -388,84 +201,6 @@ request_handler_get_auth_credentials(struct _cef_request_handler_t* self,
return _retval;
}
int CEF_CALLBACK
request_handler_can_get_cookies(struct _cef_request_handler_t* self,
cef_browser_t* browser,
cef_frame_t* frame,
cef_request_t* request) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Verify param: browser; type: refptr_diff
DCHECK(browser);
if (!browser)
return 0;
// Verify param: frame; type: refptr_diff
DCHECK(frame);
if (!frame)
return 0;
// Verify param: request; type: refptr_diff
DCHECK(request);
if (!request)
return 0;
// Execute
bool _retval = CefRequestHandlerCppToC::Get(self)->CanGetCookies(
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame),
CefRequestCToCpp::Wrap(request));
// Return type: bool
return _retval;
}
int CEF_CALLBACK
request_handler_can_set_cookie(struct _cef_request_handler_t* self,
cef_browser_t* browser,
cef_frame_t* frame,
cef_request_t* request,
const struct _cef_cookie_t* cookie) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Verify param: browser; type: refptr_diff
DCHECK(browser);
if (!browser)
return 0;
// Verify param: frame; type: refptr_diff
DCHECK(frame);
if (!frame)
return 0;
// Verify param: request; type: refptr_diff
DCHECK(request);
if (!request)
return 0;
// Verify param: cookie; type: struct_byref_const
DCHECK(cookie);
if (!cookie)
return 0;
// Translate param: cookie; type: struct_byref_const
CefCookie cookieObj;
if (cookie)
cookieObj.Set(*cookie, false);
// Execute
bool _retval = CefRequestHandlerCppToC::Get(self)->CanSetCookie(
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame),
CefRequestCToCpp::Wrap(request), cookieObj);
// Return type: bool
return _retval;
}
int CEF_CALLBACK
request_handler_on_quota_request(struct _cef_request_handler_t* self,
cef_browser_t* browser,
@ -501,44 +236,6 @@ request_handler_on_quota_request(struct _cef_request_handler_t* self,
return _retval;
}
void CEF_CALLBACK
request_handler_on_protocol_execution(struct _cef_request_handler_t* self,
cef_browser_t* browser,
const cef_string_t* url,
int* allow_os_execution) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return;
// Verify param: browser; type: refptr_diff
DCHECK(browser);
if (!browser)
return;
// Verify param: url; type: string_byref_const
DCHECK(url);
if (!url)
return;
// Verify param: allow_os_execution; type: bool_byref
DCHECK(allow_os_execution);
if (!allow_os_execution)
return;
// Translate param: allow_os_execution; type: bool_byref
bool allow_os_executionBool =
(allow_os_execution && *allow_os_execution) ? true : false;
// Execute
CefRequestHandlerCppToC::Get(self)->OnProtocolExecution(
CefBrowserCToCpp::Wrap(browser), CefString(url), allow_os_executionBool);
// Restore param: allow_os_execution; type: bool_byref
if (allow_os_execution)
*allow_os_execution = allow_os_executionBool ? true : false;
}
int CEF_CALLBACK
request_handler_on_certificate_error(struct _cef_request_handler_t* self,
cef_browser_t* browser,
@ -706,20 +403,10 @@ void CEF_CALLBACK request_handler_on_render_process_terminated(
CefRequestHandlerCppToC::CefRequestHandlerCppToC() {
GetStruct()->on_before_browse = request_handler_on_before_browse;
GetStruct()->on_open_urlfrom_tab = request_handler_on_open_urlfrom_tab;
GetStruct()->on_before_resource_load =
request_handler_on_before_resource_load;
GetStruct()->get_resource_handler = request_handler_get_resource_handler;
GetStruct()->on_resource_redirect = request_handler_on_resource_redirect;
GetStruct()->on_resource_response = request_handler_on_resource_response;
GetStruct()->get_resource_response_filter =
request_handler_get_resource_response_filter;
GetStruct()->on_resource_load_complete =
request_handler_on_resource_load_complete;
GetStruct()->get_resource_request_handler =
request_handler_get_resource_request_handler;
GetStruct()->get_auth_credentials = request_handler_get_auth_credentials;
GetStruct()->can_get_cookies = request_handler_can_get_cookies;
GetStruct()->can_set_cookie = request_handler_can_set_cookie;
GetStruct()->on_quota_request = request_handler_on_quota_request;
GetStruct()->on_protocol_execution = request_handler_on_protocol_execution;
GetStruct()->on_certificate_error = request_handler_on_certificate_error;
GetStruct()->on_select_client_certificate =
request_handler_on_select_client_certificate;