mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02: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:
@@ -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
|
||||
//==============================
|
||||
|
Reference in New Issue
Block a user