summaryrefslogtreecommitdiffstats
path: root/src/core/net
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-06-03 16:01:24 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-09-09 15:19:07 +0200
commitcd61343ceb4a3de8ce16082917a2f197b2481d08 (patch)
treeae88767edf6b3dc07b8dcf54c97a779eb2812768 /src/core/net
parentfc3893ea80296bd17e1797d5caf4479e0be4afd1 (diff)
Chromium 81-based adaptations
Change-Id: Ie422b327025da084bc8038c7a0aadee2db801f29 Reviewed-by: Jüri Valdmann <juri.valdmann@qt.io>
Diffstat (limited to 'src/core/net')
-rw-r--r--src/core/net/custom_url_loader_factory.cpp64
-rw-r--r--src/core/net/proxying_restricted_cookie_manager_qt.cpp17
-rw-r--r--src/core/net/proxying_restricted_cookie_manager_qt.h14
-rw-r--r--src/core/net/proxying_url_loader_factory_qt.cpp16
-rw-r--r--src/core/net/proxying_url_loader_factory_qt.h1
-rw-r--r--src/core/net/ssl_host_state_delegate_qt.cpp6
-rw-r--r--src/core/net/ssl_host_state_delegate_qt.h6
-rw-r--r--src/core/net/url_request_custom_job_proxy.h6
8 files changed, 77 insertions, 53 deletions
diff --git a/src/core/net/custom_url_loader_factory.cpp b/src/core/net/custom_url_loader_factory.cpp
index e5f580536..709e4451b 100644
--- a/src/core/net/custom_url_loader_factory.cpp
+++ b/src/core/net/custom_url_loader_factory.cpp
@@ -51,9 +51,10 @@
#include "net/base/net_errors.h"
#include "net/http/http_status_code.h"
#include "net/http/http_util.h"
-#include "services/network/public/cpp/resource_response.h"
+#include "services/network/public/cpp/cors/cors.h"
#include "services/network/public/mojom/url_loader.mojom.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
+#include "services/network/public/mojom/url_response_head.mojom.h"
#include "api/qwebengineurlscheme.h"
#include "net/url_request_custom_job_proxy.h"
@@ -140,7 +141,19 @@ private:
void Start()
{
DCHECK(m_taskRunner->RunsTasksInCurrentSequence());
- m_head.request_start = base::TimeTicks::Now();
+
+ if (network::cors::IsCorsEnabledRequestMode(m_request.mode)) {
+ // CORS mode requires a valid request_initiator.
+ if (!m_request.request_initiator)
+ return CompleteWithFailure(net::ERR_INVALID_ARGUMENT);
+
+ // Custom schemes are not covered by CorsURLLoader, so we need to reject CORS requests manually.
+ if (!m_corsEnabled && !m_request.request_initiator->IsSameOriginWith(url::Origin::Create(m_request.url)))
+ return CompleteWithFailure(network::CorsErrorStatus(network::mojom::CorsError::kCorsDisabledScheme));
+ }
+
+ m_head = network::mojom::URLResponseHead::New();
+ m_head->request_start = base::TimeTicks::Now();
if (!m_pipe.consumer_handle.is_valid())
return CompleteWithFailure(net::ERR_FAILED);
@@ -162,6 +175,13 @@ private:
m_request.url, m_request.method, m_request.request_initiator, std::move(headers)));
}
+ void CompleteWithFailure(network::CorsErrorStatus cors_error)
+ {
+ DCHECK(m_taskRunner->RunsTasksInCurrentSequence());
+ m_client->OnComplete(network::URLLoaderCompletionStatus(cors_error));
+ ClearProxyAndClient(false);
+ }
+
void CompleteWithFailure(net::Error net_error)
{
DCHECK(m_taskRunner->RunsTasksInCurrentSequence());
@@ -184,7 +204,7 @@ private:
DCHECK(m_taskRunner->RunsTasksInCurrentSequence());
if (result == MOJO_RESULT_OK) {
network::URLLoaderCompletionStatus status(net::OK);
- status.encoded_data_length = m_totalBytesRead + m_head.headers->raw_headers().length();
+ status.encoded_data_length = m_totalBytesRead + m_headerBytesRead;
status.encoded_body_length = m_totalBytesRead;
status.decoded_body_length = m_totalBytesRead;
m_client->OnComplete(status);
@@ -219,17 +239,17 @@ private:
CompleteWithFailure(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE);
} else {
m_maxBytesToRead = m_byteRange.last_byte_position() - m_byteRange.first_byte_position() + 1;
- m_head.content_length = m_maxBytesToRead;
+ m_head->content_length = m_maxBytesToRead;
}
} else {
- m_head.content_length = size;
+ m_head->content_length = size;
}
}
void notifyHeadersComplete() override
{
DCHECK(m_taskRunner->RunsTasksInCurrentSequence());
DCHECK(!m_error);
- m_head.response_start = base::TimeTicks::Now();
+ m_head->response_start = base::TimeTicks::Now();
std::string headers;
if (!m_redirect.is_empty()) {
@@ -262,11 +282,11 @@ private:
headers += "Access-Control-Allow-Credentials: true\n";
}
}
- m_head.headers = base::MakeRefCounted<net::HttpResponseHeaders>(net::HttpUtil::AssembleRawHeaders(headers));
- m_head.encoded_data_length = m_head.headers->raw_headers().length();
+ m_head->headers = base::MakeRefCounted<net::HttpResponseHeaders>(net::HttpUtil::AssembleRawHeaders(headers));
+ m_head->encoded_data_length = m_head->headers->raw_headers().length();
if (!m_redirect.is_empty()) {
- m_head.content_length = m_head.encoded_body_length = -1;
+ m_head->content_length = m_head->encoded_body_length = -1;
net::URLRequest::FirstPartyURLPolicy first_party_url_policy =
m_request.update_first_party_url_on_redirect ? net::URLRequest::UPDATE_FIRST_PARTY_URL_ON_REDIRECT
: net::URLRequest::NEVER_CHANGE_FIRST_PARTY_URL;
@@ -276,15 +296,18 @@ private:
first_party_url_policy, m_request.referrer_policy,
m_request.referrer.spec(), net::HTTP_SEE_OTHER,
m_redirect, base::nullopt, false /*insecure_scheme_was_upgraded*/);
- m_client->OnReceiveRedirect(redirectInfo, m_head);
+ m_client->OnReceiveRedirect(redirectInfo, std::move(m_head));
+ m_head = nullptr;
// ### should m_request be updated with RedirectInfo? (see FollowRedirect)
return;
}
DCHECK(m_device);
- m_head.mime_type = m_mimeType;
- m_head.charset = m_charset;
- m_client->OnReceiveResponse(m_head);
+ m_head->mime_type = m_mimeType;
+ m_head->charset = m_charset;
+ m_headerBytesRead = m_head->headers->raw_headers().length();
+ m_client->OnReceiveResponse(std::move(m_head));
m_client->OnStartLoadingResponseBody(std::move(m_pipe.consumer_handle));
+ m_head = nullptr;
if (readAvailableData()) // May delete this
return;
@@ -309,7 +332,7 @@ private:
void notifyStartFailure(int error) override
{
DCHECK(m_taskRunner->RunsTasksInCurrentSequence());
- m_head.response_start = base::TimeTicks::Now();
+ m_head->response_start = base::TimeTicks::Now();
std::string headers;
switch (error) {
case net::ERR_INVALID_URL:
@@ -331,10 +354,10 @@ private:
headers = "HTTP/1.1 500 Internal Error\n";
break;
}
- m_head.headers = base::MakeRefCounted<net::HttpResponseHeaders>(net::HttpUtil::AssembleRawHeaders(headers));
- m_head.encoded_data_length = m_head.headers->raw_headers().length();
- m_head.content_length = m_head.encoded_body_length = -1;
- m_client->OnReceiveResponse(m_head);
+ m_head->headers = base::MakeRefCounted<net::HttpResponseHeaders>(net::HttpUtil::AssembleRawHeaders(headers));
+ m_head->encoded_data_length = m_head->headers->raw_headers().length();
+ m_head->content_length = m_head->encoded_body_length = -1;
+ m_client->OnReceiveResponse(std::move(m_head));
CompleteWithFailure(net::Error(error));
}
void notifyReadyRead() override
@@ -404,7 +427,7 @@ private:
}
return false;
}
- base::TaskRunner *taskRunner() override
+ base::SequencedTaskRunner *taskRunner() override
{
DCHECK(m_taskRunner->RunsTasksInCurrentSequence());
return m_taskRunner.get();
@@ -422,7 +445,8 @@ private:
int64_t m_totalSize = 0;
int64_t m_maxBytesToRead = -1;
network::ResourceRequest m_request;
- network::ResourceResponseHead m_head;
+ network::mojom::URLResponseHeadPtr m_head;
+ qint64 m_headerBytesRead = 0;
qint64 m_totalBytesRead = 0;
bool m_corsEnabled;
diff --git a/src/core/net/proxying_restricted_cookie_manager_qt.cpp b/src/core/net/proxying_restricted_cookie_manager_qt.cpp
index 331b55e62..b0b46c817 100644
--- a/src/core/net/proxying_restricted_cookie_manager_qt.cpp
+++ b/src/core/net/proxying_restricted_cookie_manager_qt.cpp
@@ -116,7 +116,7 @@ ProxyingRestrictedCookieManagerQt::~ProxyingRestrictedCookieManagerQt()
}
void ProxyingRestrictedCookieManagerQt::GetAllForUrl(const GURL &url,
- const GURL &site_for_cookies,
+ const net::SiteForCookies &site_for_cookies,
const url::Origin &top_frame_origin,
network::mojom::CookieManagerGetOptionsPtr options,
GetAllForUrlCallback callback)
@@ -132,7 +132,8 @@ void ProxyingRestrictedCookieManagerQt::GetAllForUrl(const GURL &url,
void ProxyingRestrictedCookieManagerQt::SetCanonicalCookie(const net::CanonicalCookie &cookie,
const GURL &url,
- const GURL &site_for_cookies, const url::Origin &top_frame_origin,
+ const net::SiteForCookies &site_for_cookies,
+ const url::Origin &top_frame_origin,
SetCanonicalCookieCallback callback)
{
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
@@ -145,7 +146,7 @@ void ProxyingRestrictedCookieManagerQt::SetCanonicalCookie(const net::CanonicalC
}
void ProxyingRestrictedCookieManagerQt::AddChangeListener(const GURL &url,
- const GURL &site_for_cookies,
+ const net::SiteForCookies &site_for_cookies,
const url::Origin &top_frame_origin,
mojo::PendingRemote<network::mojom::CookieChangeListener> listener,
AddChangeListenerCallback callback)
@@ -155,7 +156,7 @@ void ProxyingRestrictedCookieManagerQt::AddChangeListener(const GURL &url,
}
void ProxyingRestrictedCookieManagerQt::SetCookieFromString(const GURL &url,
- const GURL &site_for_cookies,
+ const net::SiteForCookies &site_for_cookies,
const url::Origin &top_frame_origin,
const std::string &cookie,
SetCookieFromStringCallback callback)
@@ -170,7 +171,7 @@ void ProxyingRestrictedCookieManagerQt::SetCookieFromString(const GURL &url,
}
void ProxyingRestrictedCookieManagerQt::GetCookiesString(const GURL &url,
- const GURL &site_for_cookies,
+ const net::SiteForCookies &site_for_cookies,
const url::Origin &top_frame_origin,
GetCookiesStringCallback callback)
{
@@ -184,7 +185,7 @@ void ProxyingRestrictedCookieManagerQt::GetCookiesString(const GURL &url,
}
void ProxyingRestrictedCookieManagerQt::CookiesEnabledFor(const GURL &url,
- const GURL &site_for_cookies,
+ const net::SiteForCookies &site_for_cookies,
const url::Origin & /*top_frame_origin*/,
CookiesEnabledForCallback callback)
{
@@ -192,11 +193,11 @@ void ProxyingRestrictedCookieManagerQt::CookiesEnabledFor(const GURL &url,
std::move(callback).Run(allowCookies(url, site_for_cookies));
}
-bool ProxyingRestrictedCookieManagerQt::allowCookies(const GURL &url, const GURL &site_for_cookies) const
+bool ProxyingRestrictedCookieManagerQt::allowCookies(const GURL &url, const net::SiteForCookies &site_for_cookies) const
{
if (!m_profileIoData)
return false;
- return m_profileIoData->canGetCookies(toQt(site_for_cookies), toQt(url));
+ return m_profileIoData->canGetCookies(toQt(site_for_cookies.RepresentativeUrl()), toQt(url));
}
} // namespace QtWebEngineCore
diff --git a/src/core/net/proxying_restricted_cookie_manager_qt.h b/src/core/net/proxying_restricted_cookie_manager_qt.h
index b682075ed..3d4765b3b 100644
--- a/src/core/net/proxying_restricted_cookie_manager_qt.h
+++ b/src/core/net/proxying_restricted_cookie_manager_qt.h
@@ -65,36 +65,36 @@ public:
// network::mojom::RestrictedCookieManager interface:
void GetAllForUrl(const GURL &url,
- const GURL &site_for_cookies,
+ const net::SiteForCookies &site_for_cookies,
const url::Origin &top_frame_origin,
network::mojom::CookieManagerGetOptionsPtr options,
GetAllForUrlCallback callback) override;
void SetCanonicalCookie(const net::CanonicalCookie& cookie,
const GURL &url,
- const GURL &site_for_cookies,
+ const net::SiteForCookies &site_for_cookies,
const url::Origin &top_frame_origin,
SetCanonicalCookieCallback callback) override;
void AddChangeListener(const GURL &url,
- const GURL &site_for_cookies,
+ const net::SiteForCookies &site_for_cookies,
const url::Origin &top_frame_origin,
mojo::PendingRemote<network::mojom::CookieChangeListener> listener,
AddChangeListenerCallback callback) override;
void SetCookieFromString(const GURL &url,
- const GURL &site_for_cookies,
+ const net::SiteForCookies &site_for_cookies,
const url::Origin &top_frame_origin,
const std::string &cookie,
SetCookieFromStringCallback callback) override;
void GetCookiesString(const GURL &url,
- const GURL &site_for_cookies,
+ const net::SiteForCookies &site_for_cookies,
const url::Origin &top_frame_origin,
GetCookiesStringCallback callback) override;
void CookiesEnabledFor(const GURL &url,
- const GURL &site_for_cookies,
+ const net::SiteForCookies &site_for_cookies,
const url::Origin &top_frame_origin,
CookiesEnabledForCallback callback) override;
// Internal:
- bool allowCookies(const GURL &url, const GURL &site_for_cookies) const;
+ bool allowCookies(const GURL &url, const net::SiteForCookies &site_for_cookies) const;
private:
ProxyingRestrictedCookieManagerQt(base::WeakPtr<ProfileIODataQt> profileIoData,
diff --git a/src/core/net/proxying_url_loader_factory_qt.cpp b/src/core/net/proxying_url_loader_factory_qt.cpp
index 8e084a40b..cf0b0fb7e 100644
--- a/src/core/net/proxying_url_loader_factory_qt.cpp
+++ b/src/core/net/proxying_url_loader_factory_qt.cpp
@@ -45,7 +45,6 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/task/post_task.h"
-#include "components/safe_browsing/common/safebrowsing_constants.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
@@ -151,7 +150,7 @@ private:
// error didn't occur.
int error_status_ = net::OK;
network::ResourceRequest request_;
- network::ResourceResponseHead current_response_;
+ network::mojom::URLResponseHeadPtr current_response_;
const net::MutableNetworkTrafficAnnotationTag traffic_annotation_;
@@ -189,6 +188,7 @@ InterceptedRequest::InterceptedRequest(int process_id, uint64_t request_id, int3
, target_factory_(std::move(target_factory))
, weak_factory_(this)
{
+ current_response_ = network::mojom::URLResponseHead::New();
// If there is a client error, clean up the request.
target_client_.set_disconnect_handler(
base::BindOnce(&InterceptedRequest::OnURLLoaderClientError, weak_factory_.GetWeakPtr()));
@@ -219,12 +219,12 @@ void InterceptedRequest::Restart()
webContents = content::WebContents::FromFrameTreeNodeId(request_.render_frame_id);
}
- GURL top_document_url = webContents ? webContents->GetLastCommittedURL() : GURL();
+ GURL top_document_url = webContents ? webContents->GetVisibleURL() : GURL();
QUrl firstPartyUrl;
if (!top_document_url.is_empty())
firstPartyUrl = toQt(top_document_url);
else
- firstPartyUrl = toQt(request_.site_for_cookies); // m_topDocumentUrl can be empty for the main-frame.
+ firstPartyUrl = toQt(request_.site_for_cookies.RepresentativeUrl()); // m_topDocumentUrl can be empty for the main-frame.
QWebEngineUrlRequestInfoPrivate *infoPrivate =
new QWebEngineUrlRequestInfoPrivate(toQt(resourceType), toQt(navigationType), originalUrl, firstPartyUrl,
@@ -283,7 +283,7 @@ void InterceptedRequest::ContinueAfterIntercept()
false /*insecure_scheme_was_upgraded*/);
// FIXME: Should probably create a new header.
- current_response_.encoded_data_length = 0;
+ current_response_->encoded_data_length = 0;
request_.method = redirectInfo.new_method;
request_.url = redirectInfo.new_url;
request_.site_for_cookies = redirectInfo.new_site_for_cookies;
@@ -291,7 +291,7 @@ void InterceptedRequest::ContinueAfterIntercept()
request_.referrer_policy = redirectInfo.new_referrer_policy;
if (request_.method == net::HttpRequestHeaders::kGetMethod)
request_.request_body = nullptr;
- target_client_->OnReceiveRedirect(redirectInfo, current_response_);
+ target_client_->OnReceiveRedirect(redirectInfo, std::move(current_response_));
return;
}
@@ -319,7 +319,7 @@ void InterceptedRequest::ContinueAfterIntercept()
void InterceptedRequest::OnReceiveResponse(network::mojom::URLResponseHeadPtr head)
{
- current_response_ = head;
+ current_response_ = head.Clone();
target_client_->OnReceiveResponse(std::move(head));
}
@@ -328,7 +328,7 @@ void InterceptedRequest::OnReceiveRedirect(const net::RedirectInfo &redirect_inf
{
// TODO(timvolodine): handle redirect override.
request_was_redirected_ = true;
- current_response_ = head;
+ current_response_ = head.Clone();
target_client_->OnReceiveRedirect(redirect_info, std::move(head));
request_.url = redirect_info.new_url;
request_.method = redirect_info.new_method;
diff --git a/src/core/net/proxying_url_loader_factory_qt.h b/src/core/net/proxying_url_loader_factory_qt.h
index 3d77856cc..e1bcc276c 100644
--- a/src/core/net/proxying_url_loader_factory_qt.h
+++ b/src/core/net/proxying_url_loader_factory_qt.h
@@ -49,7 +49,6 @@
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/cpp/resource_request.h"
-#include "services/network/public/cpp/resource_response.h"
#include "services/network/public/mojom/url_loader.mojom.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "url/gurl.h"
diff --git a/src/core/net/ssl_host_state_delegate_qt.cpp b/src/core/net/ssl_host_state_delegate_qt.cpp
index 3f3f95c83..3390c092a 100644
--- a/src/core/net/ssl_host_state_delegate_qt.cpp
+++ b/src/core/net/ssl_host_state_delegate_qt.cpp
@@ -77,7 +77,7 @@ SSLHostStateDelegateQt::SSLHostStateDelegateQt() {}
SSLHostStateDelegateQt::~SSLHostStateDelegateQt() {}
-void SSLHostStateDelegateQt::AllowCert(const std::string &host, const net::X509Certificate &cert, int error)
+void SSLHostStateDelegateQt::AllowCert(const std::string &host, const net::X509Certificate &cert, int error, content::WebContents *)
{
m_certPolicyforHost[host].Allow(cert, error);
}
@@ -105,7 +105,7 @@ void SSLHostStateDelegateQt::Clear(base::RepeatingCallback<bool(const std::strin
// prior to this query, otherwise false.
content::SSLHostStateDelegate::CertJudgment SSLHostStateDelegateQt::QueryPolicy(const std::string &host,
const net::X509Certificate &cert,
- int error)
+ int error, content::WebContents *)
{
return m_certPolicyforHost[host].Check(cert, error) ? SSLHostStateDelegate::ALLOWED : SSLHostStateDelegate::DENIED;
}
@@ -132,7 +132,7 @@ void SSLHostStateDelegateQt::RevokeUserAllowExceptions(const std::string &host)
// |host|. This does not mean that *all* certificate errors are allowed, just
// that there exists an exception. To see if a particular certificate and
// error combination exception is allowed, use QueryPolicy().
-bool SSLHostStateDelegateQt::HasAllowException(const std::string &host)
+bool SSLHostStateDelegateQt::HasAllowException(const std::string &host, content::WebContents *)
{
auto policy_iterator = m_certPolicyforHost.find(host);
return policy_iterator != m_certPolicyforHost.end() &&
diff --git a/src/core/net/ssl_host_state_delegate_qt.h b/src/core/net/ssl_host_state_delegate_qt.h
index 26e503eb5..6b407353a 100644
--- a/src/core/net/ssl_host_state_delegate_qt.h
+++ b/src/core/net/ssl_host_state_delegate_qt.h
@@ -66,13 +66,13 @@ public:
~SSLHostStateDelegateQt();
// content::SSLHostStateDelegate implementation:
- void AllowCert(const std::string &, const net::X509Certificate &cert, int error) override;
+ void AllowCert(const std::string &, const net::X509Certificate &cert, int error, content::WebContents *web_contents) override;
void Clear(base::RepeatingCallback<bool(const std::string&)> host_filter) override;
- CertJudgment QueryPolicy(const std::string &host, const net::X509Certificate &cert, int error) override;
+ CertJudgment QueryPolicy(const std::string &host, const net::X509Certificate &cert, int error, content::WebContents *web_contents) override;
void HostRanInsecureContent(const std::string &host, int child_id, InsecureContentType content_type) override;
bool DidHostRunInsecureContent(const std::string &host, int child_id, InsecureContentType content_type) override;
void RevokeUserAllowExceptions(const std::string &host) override;
- bool HasAllowException(const std::string &host) override;
+ bool HasAllowException(const std::string &host, content::WebContents *web_contents) override;
private:
std::map<std::string, CertPolicy> m_certPolicyforHost;
diff --git a/src/core/net/url_request_custom_job_proxy.h b/src/core/net/url_request_custom_job_proxy.h
index db38083dd..b14322f91 100644
--- a/src/core/net/url_request_custom_job_proxy.h
+++ b/src/core/net/url_request_custom_job_proxy.h
@@ -42,7 +42,7 @@
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
-#include "base/task_runner.h"
+#include "base/sequenced_task_runner.h"
#include "url/gurl.h"
#include "url/origin.h"
#include <QtCore/QPointer>
@@ -75,7 +75,7 @@ public:
virtual void notifyAborted() = 0;
virtual void notifyStartFailure(int) = 0;
virtual void notifyReadyRead() = 0;
- virtual base::TaskRunner *taskRunner() = 0;
+ virtual base::SequencedTaskRunner *taskRunner() = 0;
};
URLRequestCustomJobProxy(Client *client,
@@ -101,7 +101,7 @@ public:
std::string m_scheme;
URLRequestCustomJobDelegate *m_delegate;
QPointer<ProfileAdapter> m_profileAdapter;
- scoped_refptr<base::TaskRunner> m_ioTaskRunner;
+ scoped_refptr<base::SequencedTaskRunner> m_ioTaskRunner;
};
} // namespace QtWebEngineCore