mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
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:
@ -45,23 +45,79 @@
|
||||
#include "include/cef_request.h"
|
||||
#include "include/cef_response.h"
|
||||
|
||||
///
|
||||
// Callback for asynchronous continuation of CefResourceHandler::Skip().
|
||||
///
|
||||
/*--cef(source=library)--*/
|
||||
class CefResourceSkipCallback : public virtual CefBaseRefCounted {
|
||||
public:
|
||||
///
|
||||
// Callback for asynchronous continuation of Skip(). If |bytes_skipped| > 0
|
||||
// then either Skip() will be called again until the requested number of
|
||||
// bytes have been skipped or the request will proceed. If |bytes_skipped|
|
||||
// <= 0 the request will fail with ERR_REQUEST_RANGE_NOT_SATISFIABLE.
|
||||
///
|
||||
/*--cef(capi_name=cont)--*/
|
||||
virtual void Continue(int64 bytes_skipped) = 0;
|
||||
};
|
||||
|
||||
///
|
||||
// Callback for asynchronous continuation of CefResourceHandler::Read().
|
||||
///
|
||||
/*--cef(source=library)--*/
|
||||
class CefResourceReadCallback : public virtual CefBaseRefCounted {
|
||||
public:
|
||||
///
|
||||
// Callback for asynchronous continuation of Read(). If |bytes_read| == 0
|
||||
// the response will be considered complete. If |bytes_read| > 0 then Read()
|
||||
// will be called again until the request is complete (based on either the
|
||||
// result or the expected content length). If |bytes_read| < 0 then the
|
||||
// request will fail and the |bytes_read| value will be treated as the error
|
||||
// code.
|
||||
///
|
||||
/*--cef(capi_name=cont)--*/
|
||||
virtual void Continue(int bytes_read) = 0;
|
||||
};
|
||||
|
||||
///
|
||||
// Class used to implement a custom request handler interface. The methods of
|
||||
// this class will always be called on the IO thread.
|
||||
// this class will be called on the IO thread unless otherwise indicated.
|
||||
///
|
||||
/*--cef(source=client)--*/
|
||||
class CefResourceHandler : public virtual CefBaseRefCounted {
|
||||
public:
|
||||
///
|
||||
// Open the response stream. To handle the request immediately set
|
||||
// |handle_request| to true and return true. To decide at a later time set
|
||||
// |handle_request| to false, return true, and execute |callback| to continue
|
||||
// or cancel the request. To cancel the request immediately set
|
||||
// |handle_request| to true and return false. This method will be called in
|
||||
// sequence but not from a dedicated thread. For backwards compatibility set
|
||||
// |handle_request| to false and return false and the ProcessRequest method
|
||||
// will be called.
|
||||
///
|
||||
/*--cef()--*/
|
||||
virtual bool Open(CefRefPtr<CefRequest> request,
|
||||
bool& handle_request,
|
||||
CefRefPtr<CefCallback> callback) {
|
||||
handle_request = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
///
|
||||
// Begin processing the request. To handle the request return true and call
|
||||
// CefCallback::Continue() once the response header information is available
|
||||
// (CefCallback::Continue() can also be called from inside this method if
|
||||
// header information is available immediately). To cancel the request return
|
||||
// false.
|
||||
//
|
||||
// WARNING: This method is deprecated. Use Open instead.
|
||||
///
|
||||
/*--cef()--*/
|
||||
virtual bool ProcessRequest(CefRefPtr<CefRequest> request,
|
||||
CefRefPtr<CefCallback> callback) = 0;
|
||||
CefRefPtr<CefCallback> callback) {
|
||||
return false;
|
||||
}
|
||||
|
||||
///
|
||||
// Retrieve response header information. If the response length is not known
|
||||
@ -83,33 +139,62 @@ class CefResourceHandler : public virtual CefBaseRefCounted {
|
||||
int64& response_length,
|
||||
CefString& redirectUrl) = 0;
|
||||
|
||||
///
|
||||
// Skip response data when requested by a Range header. Skip over and discard
|
||||
// |bytes_to_skip| bytes of response data. If data is available immediately
|
||||
// set |bytes_skipped| to the number of of bytes skipped and return true. To
|
||||
// read the data at a later time set |bytes_skipped| to 0, return true and
|
||||
// execute |callback| when the data is available. To indicate failure set
|
||||
// |bytes_skipped| to < 0 (e.g. -2 for ERR_FAILED) and return false. This
|
||||
// method will be called in sequence but not from a dedicated thread.
|
||||
///
|
||||
/*--cef()--*/
|
||||
virtual bool Skip(int64 bytes_to_skip,
|
||||
int64& bytes_skipped,
|
||||
CefRefPtr<CefResourceSkipCallback> callback) {
|
||||
bytes_skipped = -2;
|
||||
return false;
|
||||
}
|
||||
|
||||
///
|
||||
// Read response data. If data is available immediately copy up to
|
||||
// |bytes_to_read| bytes into |data_out|, set |bytes_read| to the number of
|
||||
// bytes copied, and return true. To read the data at a later time keep a
|
||||
// pointer to |data_out|, set |bytes_read| to 0, return true and execute
|
||||
// |callback| when the data is available (|data_out| will remain valid until
|
||||
// the callback is executed). To indicate response completion set |bytes_read|
|
||||
// to 0 and return false. To indicate failure set |bytes_read| to < 0 (e.g. -2
|
||||
// for ERR_FAILED) and return false. This method will be called in sequence
|
||||
// but not from a dedicated thread. For backwards compatibility set
|
||||
// |bytes_read| to -1 and return false and the ReadResponse method will be
|
||||
// called.
|
||||
///
|
||||
/*--cef()--*/
|
||||
virtual bool Read(void* data_out,
|
||||
int bytes_to_read,
|
||||
int& bytes_read,
|
||||
CefRefPtr<CefResourceReadCallback> callback) {
|
||||
bytes_read = -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
///
|
||||
// Read response data. If data is available immediately copy up to
|
||||
// |bytes_to_read| bytes into |data_out|, set |bytes_read| to the number of
|
||||
// bytes copied, and return true. To read the data at a later time set
|
||||
// |bytes_read| to 0, return true and call CefCallback::Continue() when the
|
||||
// data is available. To indicate response completion return false.
|
||||
//
|
||||
// WARNING: This method is deprecated. Use Skip and Read instead.
|
||||
///
|
||||
/*--cef()--*/
|
||||
virtual bool ReadResponse(void* data_out,
|
||||
int bytes_to_read,
|
||||
int& bytes_read,
|
||||
CefRefPtr<CefCallback> callback) = 0;
|
||||
|
||||
///
|
||||
// Return true if the specified cookie can be sent with the request or false
|
||||
// otherwise. If false is returned for any cookie then no cookies will be sent
|
||||
// with the request.
|
||||
///
|
||||
/*--cef()--*/
|
||||
virtual bool CanGetCookie(const CefCookie& cookie) { return true; }
|
||||
|
||||
///
|
||||
// Return true if the specified cookie returned with the response can be set
|
||||
// or false otherwise.
|
||||
///
|
||||
/*--cef()--*/
|
||||
virtual bool CanSetCookie(const CefCookie& cookie) { return true; }
|
||||
CefRefPtr<CefCallback> callback) {
|
||||
bytes_read = -2;
|
||||
return false;
|
||||
}
|
||||
|
||||
///
|
||||
// Request processing has been canceled.
|
||||
|
Reference in New Issue
Block a user