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,12 +9,14 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=9d3f948866d05cacdb33a2335422ff0f94825389$
// $hash=e95db24c85f1c1880048b6319660133038f8b213$
//
#include "libcef_dll/cpptoc/resource_handler_cpptoc.h"
#include "libcef_dll/ctocpp/callback_ctocpp.h"
#include "libcef_dll/ctocpp/request_ctocpp.h"
#include "libcef_dll/ctocpp/resource_read_callback_ctocpp.h"
#include "libcef_dll/ctocpp/resource_skip_callback_ctocpp.h"
#include "libcef_dll/ctocpp/response_ctocpp.h"
#include "libcef_dll/shutdown_checker.h"
@ -22,6 +24,46 @@ namespace {
// MEMBER FUNCTIONS - Body may be edited by hand.
int CEF_CALLBACK resource_handler_open(struct _cef_resource_handler_t* self,
cef_request_t* request,
int* handle_request,
cef_callback_t* callback) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Verify param: request; type: refptr_diff
DCHECK(request);
if (!request)
return 0;
// Verify param: handle_request; type: bool_byref
DCHECK(handle_request);
if (!handle_request)
return 0;
// Verify param: callback; type: refptr_diff
DCHECK(callback);
if (!callback)
return 0;
// Translate param: handle_request; type: bool_byref
bool handle_requestBool = (handle_request && *handle_request) ? true : false;
// Execute
bool _retval = CefResourceHandlerCppToC::Get(self)->Open(
CefRequestCToCpp::Wrap(request), handle_requestBool,
CefCallbackCToCpp::Wrap(callback));
// Restore param: handle_request; type: bool_byref
if (handle_request)
*handle_request = handle_requestBool ? true : false;
// Return type: bool
return _retval;
}
int CEF_CALLBACK
resource_handler_process_request(struct _cef_resource_handler_t* self,
cef_request_t* request,
@ -89,6 +131,83 @@ resource_handler_get_response_headers(struct _cef_resource_handler_t* self,
*response_length = response_lengthVal;
}
int CEF_CALLBACK resource_handler_skip(struct _cef_resource_handler_t* self,
int64 bytes_to_skip,
int64* bytes_skipped,
cef_resource_skip_callback_t* callback) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Verify param: bytes_skipped; type: simple_byref
DCHECK(bytes_skipped);
if (!bytes_skipped)
return 0;
// Verify param: callback; type: refptr_diff
DCHECK(callback);
if (!callback)
return 0;
// Translate param: bytes_skipped; type: simple_byref
int64 bytes_skippedVal = bytes_skipped ? *bytes_skipped : 0;
// Execute
bool _retval = CefResourceHandlerCppToC::Get(self)->Skip(
bytes_to_skip, bytes_skippedVal,
CefResourceSkipCallbackCToCpp::Wrap(callback));
// Restore param: bytes_skipped; type: simple_byref
if (bytes_skipped)
*bytes_skipped = bytes_skippedVal;
// Return type: bool
return _retval;
}
int CEF_CALLBACK resource_handler_read(struct _cef_resource_handler_t* self,
void* data_out,
int bytes_to_read,
int* bytes_read,
cef_resource_read_callback_t* callback) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Verify param: data_out; type: simple_byaddr
DCHECK(data_out);
if (!data_out)
return 0;
// Verify param: bytes_read; type: simple_byref
DCHECK(bytes_read);
if (!bytes_read)
return 0;
// Verify param: callback; type: refptr_diff
DCHECK(callback);
if (!callback)
return 0;
// Translate param: bytes_read; type: simple_byref
int bytes_readVal = bytes_read ? *bytes_read : 0;
// Execute
bool _retval = CefResourceHandlerCppToC::Get(self)->Read(
data_out, bytes_to_read, bytes_readVal,
CefResourceReadCallbackCToCpp::Wrap(callback));
// Restore param: bytes_read; type: simple_byref
if (bytes_read)
*bytes_read = bytes_readVal;
// Return type: bool
return _retval;
}
int CEF_CALLBACK
resource_handler_read_response(struct _cef_resource_handler_t* self,
void* data_out,
@ -131,60 +250,6 @@ resource_handler_read_response(struct _cef_resource_handler_t* self,
return _retval;
}
int CEF_CALLBACK
resource_handler_can_get_cookie(struct _cef_resource_handler_t* self,
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: 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 = CefResourceHandlerCppToC::Get(self)->CanGetCookie(cookieObj);
// Return type: bool
return _retval;
}
int CEF_CALLBACK
resource_handler_can_set_cookie(struct _cef_resource_handler_t* self,
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: 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 = CefResourceHandlerCppToC::Get(self)->CanSetCookie(cookieObj);
// Return type: bool
return _retval;
}
void CEF_CALLBACK
resource_handler_cancel(struct _cef_resource_handler_t* self) {
shutdown_checker::AssertNotShutdown();
@ -204,11 +269,12 @@ resource_handler_cancel(struct _cef_resource_handler_t* self) {
// CONSTRUCTOR - Do not edit by hand.
CefResourceHandlerCppToC::CefResourceHandlerCppToC() {
GetStruct()->open = resource_handler_open;
GetStruct()->process_request = resource_handler_process_request;
GetStruct()->get_response_headers = resource_handler_get_response_headers;
GetStruct()->skip = resource_handler_skip;
GetStruct()->read = resource_handler_read;
GetStruct()->read_response = resource_handler_read_response;
GetStruct()->can_get_cookie = resource_handler_can_get_cookie;
GetStruct()->can_set_cookie = resource_handler_can_set_cookie;
GetStruct()->cancel = resource_handler_cancel;
}