2012-06-19 18:29:49 +02:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
#include "libcef/renderer/render_urlrequest_impl.h"
|
2016-01-06 20:20:54 +01:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
#include "libcef/common/request_impl.h"
|
|
|
|
#include "libcef/common/response_impl.h"
|
2018-04-19 17:44:42 +02:00
|
|
|
#include "libcef/renderer/blink_glue.h"
|
2020-06-28 23:05:36 +02:00
|
|
|
#include "libcef/renderer/frame_impl.h"
|
2020-12-02 23:31:49 +01:00
|
|
|
#include "libcef/renderer/thread_util.h"
|
2012-06-19 18:29:49 +02:00
|
|
|
|
|
|
|
#include "base/logging.h"
|
2020-03-30 22:13:42 +02:00
|
|
|
#include "net/base/request_priority.h"
|
|
|
|
#include "third_party/blink/public/mojom/fetch/fetch_api_request.mojom.h"
|
2020-06-28 23:05:36 +02:00
|
|
|
#include "third_party/blink/public/mojom/loader/resource_load_info.mojom.h"
|
2020-12-02 23:31:49 +01:00
|
|
|
#include "third_party/blink/public/platform/resource_load_info_notifier_wrapper.h"
|
2018-07-06 19:11:55 +02:00
|
|
|
#include "third_party/blink/public/platform/web_security_origin.h"
|
2018-04-19 17:44:42 +02:00
|
|
|
#include "third_party/blink/public/platform/web_string.h"
|
|
|
|
#include "third_party/blink/public/platform/web_url.h"
|
|
|
|
#include "third_party/blink/public/platform/web_url_error.h"
|
|
|
|
#include "third_party/blink/public/platform/web_url_loader.h"
|
|
|
|
#include "third_party/blink/public/platform/web_url_loader_client.h"
|
|
|
|
#include "third_party/blink/public/platform/web_url_request.h"
|
2020-12-02 23:31:49 +01:00
|
|
|
#include "third_party/blink/public/platform/web_url_request_extra_data.h"
|
2018-04-19 17:44:42 +02:00
|
|
|
#include "third_party/blink/public/platform/web_url_response.h"
|
2012-06-19 18:29:49 +02:00
|
|
|
|
2013-11-08 22:28:56 +01:00
|
|
|
using blink::WebString;
|
|
|
|
using blink::WebURL;
|
|
|
|
using blink::WebURLError;
|
|
|
|
using blink::WebURLLoader;
|
|
|
|
using blink::WebURLRequest;
|
|
|
|
using blink::WebURLResponse;
|
2012-06-19 18:29:49 +02:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2013-11-08 22:28:56 +01:00
|
|
|
class CefWebURLLoaderClient : public blink::WebURLLoaderClient {
|
2012-06-19 18:29:49 +02:00
|
|
|
public:
|
|
|
|
CefWebURLLoaderClient(CefRenderURLRequest::Context* context,
|
|
|
|
int request_flags);
|
2014-11-12 20:25:15 +01:00
|
|
|
~CefWebURLLoaderClient() override;
|
2012-06-19 18:29:49 +02:00
|
|
|
|
2013-11-08 22:28:56 +01:00
|
|
|
// blink::WebURLLoaderClient methods.
|
2019-03-13 22:27:37 +01:00
|
|
|
void DidSendData(uint64_t bytes_sent,
|
|
|
|
uint64_t total_bytes_to_be_sent) override;
|
2017-05-17 11:29:28 +02:00
|
|
|
void DidReceiveResponse(const WebURLResponse& response) override;
|
|
|
|
void DidReceiveData(const char* data, int dataLength) override;
|
2019-10-01 15:55:16 +02:00
|
|
|
void DidFinishLoading(base::TimeTicks finish_time,
|
|
|
|
int64_t total_encoded_data_length,
|
|
|
|
int64_t total_encoded_body_length,
|
|
|
|
int64_t total_decoded_body_length,
|
|
|
|
bool should_report_corb_blocking) override;
|
2017-05-31 17:33:30 +02:00
|
|
|
void DidFail(const WebURLError&,
|
2021-01-28 00:13:12 +01:00
|
|
|
base::TimeTicks finish_time,
|
2017-05-31 17:33:30 +02:00
|
|
|
int64_t total_encoded_data_length,
|
|
|
|
int64_t total_encoded_body_length,
|
|
|
|
int64_t total_decoded_body_length) override;
|
2019-04-16 16:38:48 +02:00
|
|
|
void DidStartLoadingResponseBody(
|
|
|
|
mojo::ScopedDataPipeConsumerHandle response_body) override;
|
2019-11-12 17:11:44 +01:00
|
|
|
bool WillFollowRedirect(const WebURL& new_url,
|
2020-03-04 01:29:39 +01:00
|
|
|
const net::SiteForCookies& new_site_for_cookies,
|
2019-11-12 17:11:44 +01:00
|
|
|
const WebString& new_referrer,
|
|
|
|
network::mojom::ReferrerPolicy new_referrer_policy,
|
|
|
|
const WebString& new_method,
|
|
|
|
const WebURLResponse& passed_redirect_response,
|
2020-06-09 19:48:00 +02:00
|
|
|
bool& report_raw_headers,
|
2021-10-19 00:17:16 +02:00
|
|
|
std::vector<std::string>* removed_headers,
|
|
|
|
bool insecure_scheme_was_upgraded) override;
|
2012-06-19 18:29:49 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// The context_ pointer will outlive this object.
|
|
|
|
CefRenderURLRequest::Context* context_;
|
|
|
|
int request_flags_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// CefRenderURLRequest::Context -----------------------------------------------
|
|
|
|
|
|
|
|
class CefRenderURLRequest::Context
|
|
|
|
: public base::RefCountedThreadSafe<CefRenderURLRequest::Context> {
|
|
|
|
public:
|
|
|
|
Context(CefRefPtr<CefRenderURLRequest> url_request,
|
2019-05-11 00:14:48 +02:00
|
|
|
CefRefPtr<CefFrame> frame,
|
2012-06-19 18:29:49 +02:00
|
|
|
CefRefPtr<CefRequest> request,
|
|
|
|
CefRefPtr<CefURLRequestClient> client)
|
2017-05-17 11:29:28 +02:00
|
|
|
: url_request_(url_request),
|
2019-05-11 00:14:48 +02:00
|
|
|
frame_(frame),
|
2017-05-17 11:29:28 +02:00
|
|
|
request_(request),
|
|
|
|
client_(client),
|
|
|
|
status_(UR_IO_PENDING),
|
|
|
|
error_code_(ERR_NONE),
|
2019-04-16 16:38:48 +02:00
|
|
|
body_watcher_(FROM_HERE, mojo::SimpleWatcher::ArmingPolicy::MANUAL),
|
2018-01-03 22:14:29 +01:00
|
|
|
response_was_cached_(false),
|
2017-05-17 11:29:28 +02:00
|
|
|
upload_data_size_(0),
|
|
|
|
got_upload_progress_complete_(false),
|
|
|
|
download_data_received_(0),
|
|
|
|
download_data_total_(-1) {
|
2012-06-19 18:29:49 +02:00
|
|
|
// Mark the request as read-only.
|
|
|
|
static_cast<CefRequestImpl*>(request_.get())->SetReadOnly(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Start() {
|
|
|
|
GURL url = GURL(request_->GetURL().ToString());
|
|
|
|
if (!url.is_valid())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
url_client_.reset(new CefWebURLLoaderClient(this, request_->GetFlags()));
|
|
|
|
|
2020-03-30 22:13:42 +02:00
|
|
|
std::unique_ptr<network::ResourceRequest> resource_request =
|
|
|
|
std::make_unique<network::ResourceRequest>();
|
2017-05-17 11:29:28 +02:00
|
|
|
static_cast<CefRequestImpl*>(request_.get())
|
2020-03-30 22:13:42 +02:00
|
|
|
->Get(resource_request.get(), false);
|
|
|
|
resource_request->priority = net::MEDIUM;
|
|
|
|
|
|
|
|
// Behave the same as a subresource load.
|
|
|
|
resource_request->resource_type =
|
|
|
|
static_cast<int>(blink::mojom::ResourceType::kSubResource);
|
|
|
|
|
|
|
|
// Need load timing info for WebURLLoaderImpl::PopulateURLResponse to
|
|
|
|
// properly set cached status.
|
|
|
|
resource_request->enable_load_timing = true;
|
2012-06-19 18:29:49 +02:00
|
|
|
|
2017-07-27 01:19:27 +02:00
|
|
|
// Set the origin to match the request. The requirement for an origin is
|
|
|
|
// DCHECK'd in ResourceDispatcherHostImpl::ContinuePendingBeginRequest.
|
2020-03-30 22:13:42 +02:00
|
|
|
resource_request->request_initiator = url::Origin::Create(url);
|
|
|
|
|
2020-04-24 23:48:16 +02:00
|
|
|
if (request_->GetFlags() & UR_FLAG_ALLOW_STORED_CREDENTIALS) {
|
|
|
|
// Include SameSite cookies.
|
|
|
|
resource_request->site_for_cookies =
|
|
|
|
net::SiteForCookies::FromOrigin(*resource_request->request_initiator);
|
|
|
|
}
|
|
|
|
|
2020-03-30 22:13:42 +02:00
|
|
|
if (resource_request->request_body) {
|
|
|
|
const auto& elements = *resource_request->request_body->elements();
|
|
|
|
if (elements.size() > 0) {
|
|
|
|
const auto& element = elements[0];
|
2021-01-28 00:13:12 +01:00
|
|
|
if (element.type() == network::DataElement::Tag::kBytes) {
|
|
|
|
const auto& bytes_element = element.As<network::DataElementBytes>();
|
|
|
|
upload_data_size_ = bytes_element.bytes().size();
|
2020-03-30 22:13:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-27 01:19:27 +02:00
|
|
|
|
2020-12-02 23:31:49 +01:00
|
|
|
auto frame_impl = static_cast<CefFrameImpl*>(frame_.get());
|
|
|
|
loader_ = frame_impl->CreateURLLoader();
|
2020-03-30 22:13:42 +02:00
|
|
|
loader_->LoadAsynchronously(
|
2020-12-02 23:31:49 +01:00
|
|
|
std::move(resource_request), /*extra_data=*/nullptr,
|
|
|
|
/*no_mime_sniffing=*/false,
|
|
|
|
frame_impl->CreateResourceLoadInfoNotifierWrapper(), url_client_.get());
|
2012-06-19 18:29:49 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Cancel() {
|
|
|
|
// The request may already be complete.
|
|
|
|
if (!loader_.get() || status_ != UR_IO_PENDING)
|
|
|
|
return;
|
|
|
|
|
|
|
|
status_ = UR_CANCELED;
|
|
|
|
error_code_ = ERR_ABORTED;
|
|
|
|
|
|
|
|
// Will result in a call to OnError().
|
2017-04-20 21:28:17 +02:00
|
|
|
loader_->Cancel();
|
2012-06-19 18:29:49 +02:00
|
|
|
}
|
|
|
|
|
2018-04-10 19:04:57 +02:00
|
|
|
void OnStopRedirect(const WebURL& redirect_url,
|
|
|
|
const WebURLResponse& response) {
|
2018-04-19 17:44:42 +02:00
|
|
|
response_was_cached_ = blink_glue::ResponseWasCached(response);
|
2018-04-10 19:04:57 +02:00
|
|
|
response_ = CefResponse::Create();
|
|
|
|
CefResponseImpl* responseImpl =
|
|
|
|
static_cast<CefResponseImpl*>(response_.get());
|
|
|
|
|
|
|
|
// In case of StopOnRedirect we only set these fields. Everything else is
|
|
|
|
// left blank. This also replicates the behaviour of the browser urlrequest
|
|
|
|
// fetcher.
|
|
|
|
responseImpl->SetStatus(response.HttpStatusCode());
|
|
|
|
responseImpl->SetURL(redirect_url.GetString().Utf16());
|
|
|
|
responseImpl->SetReadOnly(true);
|
|
|
|
|
|
|
|
status_ = UR_CANCELED;
|
|
|
|
error_code_ = ERR_ABORTED;
|
|
|
|
|
|
|
|
OnComplete();
|
|
|
|
}
|
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
void OnResponse(const WebURLResponse& response) {
|
2018-04-19 17:44:42 +02:00
|
|
|
response_was_cached_ = blink_glue::ResponseWasCached(response);
|
2012-06-19 18:29:49 +02:00
|
|
|
response_ = CefResponse::Create();
|
|
|
|
CefResponseImpl* responseImpl =
|
|
|
|
static_cast<CefResponseImpl*>(response_.get());
|
|
|
|
responseImpl->Set(response);
|
|
|
|
responseImpl->SetReadOnly(true);
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
download_data_total_ = response.ExpectedContentLength();
|
2012-06-19 18:29:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void OnError(const WebURLError& error) {
|
|
|
|
if (status_ == UR_IO_PENDING) {
|
|
|
|
status_ = UR_FAILED;
|
2017-12-07 22:44:24 +01:00
|
|
|
error_code_ = static_cast<cef_errorcode_t>(error.reason());
|
2012-06-19 18:29:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
OnComplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnComplete() {
|
2019-04-16 16:38:48 +02:00
|
|
|
if (body_handle_.is_valid()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
if (status_ == UR_IO_PENDING) {
|
|
|
|
status_ = UR_SUCCESS;
|
|
|
|
NotifyUploadProgressIfNecessary();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (loader_.get())
|
2020-01-15 14:36:24 +01:00
|
|
|
loader_.reset(nullptr);
|
2012-06-19 18:29:49 +02:00
|
|
|
|
|
|
|
DCHECK(url_request_.get());
|
|
|
|
client_->OnRequestComplete(url_request_.get());
|
|
|
|
|
|
|
|
// This may result in the Context object being deleted.
|
2020-01-15 14:36:24 +01:00
|
|
|
url_request_ = nullptr;
|
2012-06-19 18:29:49 +02:00
|
|
|
}
|
|
|
|
|
2019-04-16 16:38:48 +02:00
|
|
|
void OnBodyReadable(MojoResult, const mojo::HandleSignalsState&) {
|
|
|
|
const void* buffer = nullptr;
|
|
|
|
uint32_t read_bytes = 0;
|
|
|
|
MojoResult result = body_handle_->BeginReadData(&buffer, &read_bytes,
|
|
|
|
MOJO_READ_DATA_FLAG_NONE);
|
|
|
|
if (result == MOJO_RESULT_SHOULD_WAIT) {
|
|
|
|
body_watcher_.ArmOrNotify();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result == MOJO_RESULT_FAILED_PRECONDITION) {
|
|
|
|
// Whole body has been read.
|
|
|
|
body_handle_.reset();
|
|
|
|
body_watcher_.Cancel();
|
|
|
|
OnComplete();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result != MOJO_RESULT_OK) {
|
|
|
|
// Something went wrong.
|
|
|
|
body_handle_.reset();
|
|
|
|
body_watcher_.Cancel();
|
|
|
|
OnComplete();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
download_data_received_ += read_bytes;
|
|
|
|
|
|
|
|
client_->OnDownloadProgress(url_request_.get(), download_data_received_,
|
|
|
|
download_data_total_);
|
|
|
|
|
|
|
|
if (!(request_->GetFlags() & UR_FLAG_NO_DOWNLOAD_DATA)) {
|
|
|
|
client_->OnDownloadData(url_request_.get(), buffer, read_bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
body_handle_->EndReadData(read_bytes);
|
|
|
|
body_watcher_.ArmOrNotify();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnStartLoadingResponseBody(
|
|
|
|
mojo::ScopedDataPipeConsumerHandle response_body) {
|
|
|
|
DCHECK(response_body);
|
|
|
|
DCHECK(!body_handle_);
|
|
|
|
body_handle_ = std::move(response_body);
|
|
|
|
|
|
|
|
body_watcher_.Watch(
|
|
|
|
body_handle_.get(),
|
|
|
|
MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED,
|
|
|
|
MOJO_TRIGGER_CONDITION_SIGNALS_SATISFIED,
|
|
|
|
base::BindRepeating(&CefRenderURLRequest::Context::OnBodyReadable,
|
|
|
|
base::Unretained(this)));
|
|
|
|
body_watcher_.ArmOrNotify();
|
|
|
|
}
|
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
void OnDownloadProgress(int64_t current) {
|
2012-06-19 18:29:49 +02:00
|
|
|
DCHECK(url_request_.get());
|
|
|
|
|
|
|
|
NotifyUploadProgressIfNecessary();
|
|
|
|
|
|
|
|
download_data_received_ += current;
|
|
|
|
client_->OnDownloadProgress(url_request_.get(), download_data_received_,
|
2017-05-17 11:29:28 +02:00
|
|
|
download_data_total_);
|
2012-06-19 18:29:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void OnDownloadData(const char* data, int dataLength) {
|
|
|
|
DCHECK(url_request_.get());
|
|
|
|
client_->OnDownloadData(url_request_.get(), data, dataLength);
|
|
|
|
}
|
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
void OnUploadProgress(int64_t current, int64_t total) {
|
2012-06-19 18:29:49 +02:00
|
|
|
DCHECK(url_request_.get());
|
|
|
|
if (current == total)
|
|
|
|
got_upload_progress_complete_ = true;
|
|
|
|
client_->OnUploadProgress(url_request_.get(), current, total);
|
|
|
|
}
|
|
|
|
|
2018-01-03 22:14:29 +01:00
|
|
|
CefRefPtr<CefRequest> request() const { return request_; }
|
|
|
|
CefRefPtr<CefURLRequestClient> client() const { return client_; }
|
|
|
|
CefURLRequest::Status status() const { return status_; }
|
|
|
|
CefURLRequest::ErrorCode error_code() const { return error_code_; }
|
|
|
|
CefRefPtr<CefResponse> response() const { return response_; }
|
|
|
|
bool response_was_cached() const { return response_was_cached_; }
|
2012-06-19 18:29:49 +02:00
|
|
|
|
|
|
|
private:
|
2014-11-12 20:25:15 +01:00
|
|
|
friend class base::RefCountedThreadSafe<CefRenderURLRequest::Context>;
|
|
|
|
|
|
|
|
virtual ~Context() {}
|
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
void NotifyUploadProgressIfNecessary() {
|
|
|
|
if (!got_upload_progress_complete_ && upload_data_size_ > 0) {
|
2019-07-29 23:27:12 +02:00
|
|
|
// Upload notifications are sent using a timer and may not occur if the
|
|
|
|
// request completes too quickly. We therefore send the notification here
|
|
|
|
// if necessary.
|
2020-03-30 22:13:42 +02:00
|
|
|
url_client_->DidSendData(upload_data_size_, upload_data_size_);
|
2012-06-19 18:29:49 +02:00
|
|
|
got_upload_progress_complete_ = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Members only accessed on the initialization thread.
|
|
|
|
CefRefPtr<CefRenderURLRequest> url_request_;
|
2019-05-11 00:14:48 +02:00
|
|
|
CefRefPtr<CefFrame> frame_;
|
2012-06-19 18:29:49 +02:00
|
|
|
CefRefPtr<CefRequest> request_;
|
|
|
|
CefRefPtr<CefURLRequestClient> client_;
|
|
|
|
CefURLRequest::Status status_;
|
|
|
|
CefURLRequest::ErrorCode error_code_;
|
|
|
|
CefRefPtr<CefResponse> response_;
|
2019-04-16 16:38:48 +02:00
|
|
|
mojo::ScopedDataPipeConsumerHandle body_handle_;
|
|
|
|
mojo::SimpleWatcher body_watcher_;
|
2018-01-03 22:14:29 +01:00
|
|
|
bool response_was_cached_;
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<blink::WebURLLoader> loader_;
|
|
|
|
std::unique_ptr<CefWebURLLoaderClient> url_client_;
|
2016-01-06 20:20:54 +01:00
|
|
|
int64_t upload_data_size_;
|
2012-06-19 18:29:49 +02:00
|
|
|
bool got_upload_progress_complete_;
|
2016-01-06 20:20:54 +01:00
|
|
|
int64_t download_data_received_;
|
|
|
|
int64_t download_data_total_;
|
2012-06-19 18:29:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// CefWebURLLoaderClient --------------------------------------------------
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
CefWebURLLoaderClient::CefWebURLLoaderClient(
|
|
|
|
CefRenderURLRequest::Context* context,
|
|
|
|
int request_flags)
|
2017-05-17 11:29:28 +02:00
|
|
|
: context_(context), request_flags_(request_flags) {}
|
2012-06-19 18:29:49 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefWebURLLoaderClient::~CefWebURLLoaderClient() {}
|
2012-06-19 18:29:49 +02:00
|
|
|
|
2019-03-13 22:27:37 +01:00
|
|
|
void CefWebURLLoaderClient::DidSendData(uint64_t bytes_sent,
|
|
|
|
uint64_t total_bytes_to_be_sent) {
|
2012-06-19 18:29:49 +02:00
|
|
|
if (request_flags_ & UR_FLAG_REPORT_UPLOAD_PROGRESS)
|
2019-03-13 22:27:37 +01:00
|
|
|
context_->OnUploadProgress(bytes_sent, total_bytes_to_be_sent);
|
2012-06-19 18:29:49 +02:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefWebURLLoaderClient::DidReceiveResponse(const WebURLResponse& response) {
|
2012-06-19 18:29:49 +02:00
|
|
|
context_->OnResponse(response);
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefWebURLLoaderClient::DidReceiveData(const char* data, int dataLength) {
|
2012-06-19 18:29:49 +02:00
|
|
|
context_->OnDownloadProgress(dataLength);
|
|
|
|
|
|
|
|
if (!(request_flags_ & UR_FLAG_NO_DOWNLOAD_DATA))
|
|
|
|
context_->OnDownloadData(data, dataLength);
|
|
|
|
}
|
|
|
|
|
2019-10-01 15:55:16 +02:00
|
|
|
void CefWebURLLoaderClient::DidFinishLoading(base::TimeTicks finish_time,
|
|
|
|
int64_t total_encoded_data_length,
|
|
|
|
int64_t total_encoded_body_length,
|
|
|
|
int64_t total_decoded_body_length,
|
|
|
|
bool should_report_corb_blocking) {
|
2012-06-19 18:29:49 +02:00
|
|
|
context_->OnComplete();
|
|
|
|
}
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
void CefWebURLLoaderClient::DidFail(const WebURLError& error,
|
2021-01-28 00:13:12 +01:00
|
|
|
base::TimeTicks finish_time,
|
2017-05-31 17:33:30 +02:00
|
|
|
int64_t total_encoded_data_length,
|
|
|
|
int64_t total_encoded_body_length,
|
|
|
|
int64_t total_decoded_body_length) {
|
2012-06-19 18:29:49 +02:00
|
|
|
context_->OnError(error);
|
|
|
|
}
|
|
|
|
|
2019-04-16 16:38:48 +02:00
|
|
|
void CefWebURLLoaderClient::DidStartLoadingResponseBody(
|
|
|
|
mojo::ScopedDataPipeConsumerHandle response_body) {
|
|
|
|
context_->OnStartLoadingResponseBody(std::move(response_body));
|
|
|
|
}
|
|
|
|
|
2018-04-10 19:04:57 +02:00
|
|
|
bool CefWebURLLoaderClient::WillFollowRedirect(
|
|
|
|
const WebURL& new_url,
|
2020-03-04 01:29:39 +01:00
|
|
|
const net::SiteForCookies& new_site_for_cookies,
|
2018-04-10 19:04:57 +02:00
|
|
|
const WebString& new_referrer,
|
2018-11-03 02:15:09 +01:00
|
|
|
network::mojom::ReferrerPolicy new_referrer_policy,
|
2018-04-10 19:04:57 +02:00
|
|
|
const WebString& new_method,
|
|
|
|
const WebURLResponse& passed_redirect_response,
|
2020-06-09 19:48:00 +02:00
|
|
|
bool& report_raw_headers,
|
2021-10-19 00:17:16 +02:00
|
|
|
std::vector<std::string>* removed_headers,
|
|
|
|
bool insecure_scheme_was_upgraded) {
|
2018-04-10 19:04:57 +02:00
|
|
|
if (request_flags_ & UR_FLAG_STOP_ON_REDIRECT) {
|
|
|
|
context_->OnStopRedirect(new_url, passed_redirect_response);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// CefRenderURLRequest --------------------------------------------------------
|
|
|
|
|
|
|
|
CefRenderURLRequest::CefRenderURLRequest(
|
2019-05-11 00:14:48 +02:00
|
|
|
CefRefPtr<CefFrame> frame,
|
2012-06-19 18:29:49 +02:00
|
|
|
CefRefPtr<CefRequest> request,
|
|
|
|
CefRefPtr<CefURLRequestClient> client) {
|
2020-08-29 00:39:23 +02:00
|
|
|
DCHECK(frame);
|
|
|
|
DCHECK(request);
|
|
|
|
DCHECK(client);
|
2019-05-11 00:14:48 +02:00
|
|
|
context_ = new Context(this, frame, request, client);
|
2012-06-19 18:29:49 +02:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRenderURLRequest::~CefRenderURLRequest() {}
|
2012-06-19 18:29:49 +02:00
|
|
|
|
|
|
|
bool CefRenderURLRequest::Start() {
|
|
|
|
if (!VerifyContext())
|
|
|
|
return false;
|
|
|
|
return context_->Start();
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefRequest> CefRenderURLRequest::GetRequest() {
|
|
|
|
if (!VerifyContext())
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2012-06-19 18:29:49 +02:00
|
|
|
return context_->request();
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefURLRequestClient> CefRenderURLRequest::GetClient() {
|
|
|
|
if (!VerifyContext())
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2012-06-19 18:29:49 +02:00
|
|
|
return context_->client();
|
|
|
|
}
|
|
|
|
|
|
|
|
CefURLRequest::Status CefRenderURLRequest::GetRequestStatus() {
|
|
|
|
if (!VerifyContext())
|
|
|
|
return UR_UNKNOWN;
|
|
|
|
return context_->status();
|
|
|
|
}
|
|
|
|
|
|
|
|
CefURLRequest::ErrorCode CefRenderURLRequest::GetRequestError() {
|
|
|
|
if (!VerifyContext())
|
|
|
|
return ERR_NONE;
|
|
|
|
return context_->error_code();
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefResponse> CefRenderURLRequest::GetResponse() {
|
|
|
|
if (!VerifyContext())
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2012-06-19 18:29:49 +02:00
|
|
|
return context_->response();
|
|
|
|
}
|
|
|
|
|
2018-01-03 22:14:29 +01:00
|
|
|
bool CefRenderURLRequest::ResponseWasCached() {
|
|
|
|
if (!VerifyContext())
|
|
|
|
return false;
|
|
|
|
return context_->response_was_cached();
|
|
|
|
}
|
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
void CefRenderURLRequest::Cancel() {
|
|
|
|
if (!VerifyContext())
|
|
|
|
return;
|
|
|
|
return context_->Cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefRenderURLRequest::VerifyContext() {
|
|
|
|
DCHECK(context_.get());
|
2020-12-02 23:31:49 +01:00
|
|
|
if (!CEF_CURRENTLY_ON_RT()) {
|
2012-06-19 18:29:49 +02:00
|
|
|
NOTREACHED() << "called on invalid thread";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|