2012-04-03 03:34:16 +02:00
|
|
|
// Copyright (c) 2008-2009 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.
|
|
|
|
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/common/request_impl.h"
|
|
|
|
|
2017-11-17 17:33:50 +01:00
|
|
|
#include <algorithm>
|
2016-01-06 20:20:54 +01:00
|
|
|
#include <limits>
|
2024-01-20 23:48:57 +01:00
|
|
|
#include <memory>
|
2012-04-03 03:34:16 +02:00
|
|
|
#include <string>
|
2016-01-06 20:20:54 +01:00
|
|
|
#include <utility>
|
2012-04-03 03:34:16 +02:00
|
|
|
#include <vector>
|
|
|
|
|
2015-12-01 19:22:28 +01:00
|
|
|
#include "base/command_line.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "base/logging.h"
|
2021-05-14 18:58:55 +02:00
|
|
|
#include "base/strings/string_split.h"
|
2015-12-01 19:22:28 +01:00
|
|
|
#include "base/strings/string_util.h"
|
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/common/net/http_header_utils.h"
|
|
|
|
#include "cef/libcef/common/net_service/net_service_util.h"
|
2015-12-01 19:22:28 +01:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
2022-03-26 02:12:30 +01:00
|
|
|
#include "content/public/browser/navigation_handle.h"
|
2015-12-01 19:22:28 +01:00
|
|
|
#include "content/public/common/content_switches.h"
|
2014-11-12 20:25:15 +01:00
|
|
|
#include "net/base/elements_upload_data_stream.h"
|
2015-12-01 19:22:28 +01:00
|
|
|
#include "net/base/load_flags.h"
|
2017-05-17 11:29:28 +02:00
|
|
|
#include "net/base/upload_bytes_element_reader.h"
|
2012-11-30 20:08:20 +01:00
|
|
|
#include "net/base/upload_data_stream.h"
|
|
|
|
#include "net/base/upload_element_reader.h"
|
|
|
|
#include "net/base/upload_file_element_reader.h"
|
|
|
|
#include "net/http/http_request_headers.h"
|
2015-12-01 19:22:28 +01:00
|
|
|
#include "net/http/http_util.h"
|
2019-04-24 04:50:25 +02:00
|
|
|
#include "net/url_request/redirect_info.h"
|
2020-08-29 00:39:23 +02:00
|
|
|
#include "net/url_request/referrer_policy.h"
|
2019-04-24 04:50:25 +02:00
|
|
|
#include "services/network/public/cpp/data_element.h"
|
2018-02-15 01:12:09 +01:00
|
|
|
#include "services/network/public/cpp/network_switches.h"
|
2019-04-24 04:50:25 +02:00
|
|
|
#include "services/network/public/cpp/resource_request.h"
|
|
|
|
#include "services/network/public/cpp/resource_request_body.h"
|
2019-11-12 17:11:44 +01:00
|
|
|
#include "third_party/blink/public/mojom/fetch/fetch_api_request.mojom-shared.h"
|
2020-03-30 22:13:42 +02:00
|
|
|
#include "third_party/blink/public/platform/web_http_body.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_request.h"
|
2021-05-14 18:58:55 +02:00
|
|
|
#include "third_party/blink/public/platform/web_url_request_util.h"
|
2018-04-19 17:44:42 +02:00
|
|
|
#include "third_party/blink/public/web/web_security_policy.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-01-14 20:21:17 +01:00
|
|
|
namespace {
|
|
|
|
|
2022-06-17 15:28:55 +02:00
|
|
|
const char kCacheControlDirectiveNoCache[] = "no-cache";
|
|
|
|
const char kCacheControlDirectiveNoStore[] = "no-store";
|
|
|
|
const char kCacheControlDirectiveOnlyIfCached[] = "only-if-cached";
|
2015-12-01 19:22:28 +01:00
|
|
|
|
2017-11-17 17:33:50 +01:00
|
|
|
// Mask of values that configure the cache policy.
|
2019-03-07 23:05:36 +01:00
|
|
|
const int kURCachePolicyMask =
|
|
|
|
(UR_FLAG_SKIP_CACHE | UR_FLAG_ONLY_FROM_CACHE | UR_FLAG_DISABLE_CACHE);
|
2017-11-17 17:33:50 +01:00
|
|
|
|
|
|
|
// Returns the cef_urlrequest_flags_t policy specified by the Cache-Control
|
|
|
|
// request header directives, if any. The directives are case-insensitive and
|
|
|
|
// some have an optional argument. Multiple directives are comma-separated.
|
|
|
|
// See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
|
|
|
|
// for details.
|
|
|
|
int GetCacheControlHeaderPolicy(CefRequest::HeaderMap headerMap) {
|
|
|
|
std::string line;
|
|
|
|
|
|
|
|
// Extract the Cache-Control header line.
|
|
|
|
{
|
|
|
|
CefRequest::HeaderMap::const_iterator it = headerMap.begin();
|
|
|
|
for (; it != headerMap.end(); ++it) {
|
2022-06-17 15:28:55 +02:00
|
|
|
if (base::EqualsCaseInsensitiveASCII(
|
|
|
|
it->first.ToString(), net::HttpRequestHeaders::kCacheControl)) {
|
2017-11-17 17:33:50 +01:00
|
|
|
line = it->second;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int flags = 0;
|
|
|
|
|
|
|
|
if (!line.empty()) {
|
2019-10-14 13:32:38 +02:00
|
|
|
HttpHeaderUtils::MakeASCIILower(&line);
|
2017-11-17 17:33:50 +01:00
|
|
|
|
2024-04-23 22:06:00 +02:00
|
|
|
std::vector<std::string_view> pieces = base::SplitStringPiece(
|
2017-11-17 17:33:50 +01:00
|
|
|
line, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
|
|
|
|
for (const auto& piece : pieces) {
|
2022-06-17 15:28:55 +02:00
|
|
|
if (base::EqualsCaseInsensitiveASCII(piece,
|
|
|
|
kCacheControlDirectiveNoCache)) {
|
2017-11-17 17:33:50 +01:00
|
|
|
flags |= UR_FLAG_SKIP_CACHE;
|
2022-06-17 15:28:55 +02:00
|
|
|
} else if (base::EqualsCaseInsensitiveASCII(
|
|
|
|
piece, kCacheControlDirectiveOnlyIfCached)) {
|
2017-11-17 17:33:50 +01:00
|
|
|
flags |= UR_FLAG_ONLY_FROM_CACHE;
|
2022-06-17 15:28:55 +02:00
|
|
|
} else if (base::EqualsCaseInsensitiveASCII(
|
|
|
|
piece, kCacheControlDirectiveNoStore)) {
|
2019-03-07 23:05:36 +01:00
|
|
|
flags |= UR_FLAG_DISABLE_CACHE;
|
2017-11-17 17:33:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert cef_urlrequest_flags_t to blink::WebCachePolicy.
|
2017-12-07 22:44:24 +01:00
|
|
|
blink::mojom::FetchCacheMode GetFetchCacheMode(int ur_flags) {
|
2021-07-23 18:40:13 +02:00
|
|
|
const bool skip_cache{!!(ur_flags & UR_FLAG_SKIP_CACHE)};
|
|
|
|
const bool only_from_cache{!!(ur_flags & UR_FLAG_ONLY_FROM_CACHE)};
|
|
|
|
const bool disable_cache{!!(ur_flags & UR_FLAG_DISABLE_CACHE)};
|
2019-03-07 23:05:36 +01:00
|
|
|
if (only_from_cache && (skip_cache || disable_cache)) {
|
2019-05-21 16:51:39 +02:00
|
|
|
// The request will always fail because only_from_cache and
|
|
|
|
// skip_cache/disable_cache are mutually exclusive.
|
2017-12-07 22:44:24 +01:00
|
|
|
return blink::mojom::FetchCacheMode::kUnspecifiedForceCacheMiss;
|
2019-05-21 16:51:39 +02:00
|
|
|
} else if (disable_cache) {
|
|
|
|
// This additionally implies the skip_cache behavior.
|
|
|
|
return blink::mojom::FetchCacheMode::kNoStore;
|
2019-03-07 23:05:36 +01:00
|
|
|
} else if (skip_cache) {
|
2017-12-07 22:44:24 +01:00
|
|
|
return blink::mojom::FetchCacheMode::kBypassCache;
|
2019-03-07 23:05:36 +01:00
|
|
|
} else if (only_from_cache) {
|
2017-12-07 22:44:24 +01:00
|
|
|
return blink::mojom::FetchCacheMode::kOnlyIfCached;
|
2017-11-17 17:33:50 +01:00
|
|
|
}
|
2017-12-07 22:44:24 +01:00
|
|
|
return blink::mojom::FetchCacheMode::kDefault;
|
2017-11-17 17:33:50 +01:00
|
|
|
}
|
|
|
|
|
2015-12-01 19:22:28 +01:00
|
|
|
// Read |headers| into |map|.
|
|
|
|
void GetHeaderMap(const net::HttpRequestHeaders& headers,
|
|
|
|
CefRequest::HeaderMap& map) {
|
2016-03-02 00:59:53 +01:00
|
|
|
map.clear();
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (headers.IsEmpty()) {
|
2015-12-01 19:22:28 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-12-01 19:22:28 +01:00
|
|
|
|
|
|
|
net::HttpRequestHeaders::Iterator it(headers);
|
2016-03-02 00:59:53 +01:00
|
|
|
while (it.GetNext()) {
|
2015-12-01 19:22:28 +01:00
|
|
|
const std::string& name = it.name();
|
|
|
|
|
|
|
|
// Do not include Referer in the header map.
|
2022-06-17 15:28:55 +02:00
|
|
|
if (!base::EqualsCaseInsensitiveASCII(name,
|
2022-07-29 18:14:16 +02:00
|
|
|
net::HttpRequestHeaders::kReferer)) {
|
2015-12-01 19:22:28 +01:00
|
|
|
map.insert(std::make_pair(name, it.value()));
|
2022-07-29 18:14:16 +02:00
|
|
|
}
|
2016-03-02 00:59:53 +01:00
|
|
|
};
|
2015-12-01 19:22:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Read |source| into |map|.
|
|
|
|
void GetHeaderMap(const CefRequest::HeaderMap& source,
|
|
|
|
CefRequest::HeaderMap& map) {
|
2016-03-02 00:59:53 +01:00
|
|
|
map.clear();
|
|
|
|
|
2015-12-01 19:22:28 +01:00
|
|
|
CefRequest::HeaderMap::const_iterator it = source.begin();
|
|
|
|
for (; it != source.end(); ++it) {
|
|
|
|
const CefString& name = it->first;
|
|
|
|
|
|
|
|
// Do not include Referer in the header map.
|
2022-06-17 15:28:55 +02:00
|
|
|
if (!base::EqualsCaseInsensitiveASCII(name.ToString(),
|
|
|
|
net::HttpRequestHeaders::kReferer)) {
|
2015-12-01 19:22:28 +01:00
|
|
|
map.insert(std::make_pair(name, it->second));
|
2022-06-17 15:28:55 +02:00
|
|
|
}
|
2015-12-01 19:22:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-14 20:21:17 +01:00
|
|
|
} // namespace
|
|
|
|
|
2023-05-08 17:07:57 +02:00
|
|
|
#define CHECK_READONLY_RETURN(val) \
|
|
|
|
if (read_only_) { \
|
|
|
|
DCHECK(false) << "object is read only"; \
|
|
|
|
return val; \
|
2012-06-19 18:29:49 +02:00
|
|
|
}
|
|
|
|
|
2023-05-08 17:07:57 +02:00
|
|
|
#define CHECK_READONLY_RETURN_VOID() \
|
|
|
|
if (read_only_) { \
|
|
|
|
DCHECK(false) << "object is read only"; \
|
|
|
|
return; \
|
2012-06-19 18:29:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// CefRequest -----------------------------------------------------------------
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefRequest> CefRequest::Create() {
|
2012-04-03 03:34:16 +02:00
|
|
|
CefRefPtr<CefRequest> request(new CefRequestImpl());
|
|
|
|
return request;
|
|
|
|
}
|
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
// CefRequestImpl -------------------------------------------------------------
|
|
|
|
|
2019-04-24 04:50:25 +02:00
|
|
|
CefRequestImpl::CefRequestImpl() {
|
2017-07-27 01:19:27 +02:00
|
|
|
// Verify that our enum matches Chromium's values.
|
2017-11-17 17:33:50 +01:00
|
|
|
static_assert(static_cast<int>(REFERRER_POLICY_LAST_VALUE) ==
|
2020-08-29 00:39:23 +02:00
|
|
|
static_cast<int>(net::ReferrerPolicy::MAX),
|
2017-11-17 17:33:50 +01:00
|
|
|
"enum mismatch");
|
2017-07-27 01:19:27 +02:00
|
|
|
|
2015-10-09 17:23:12 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
Reset();
|
2012-06-19 18:29:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefRequestImpl::IsReadOnly() {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-06-19 18:29:49 +02:00
|
|
|
return read_only_;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefRequestImpl::GetURL() {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2016-10-28 20:15:26 +02:00
|
|
|
return url_.spec();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestImpl::SetURL(const CefString& url) {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-06-19 18:29:49 +02:00
|
|
|
CHECK_READONLY_RETURN_VOID();
|
2016-10-28 20:15:26 +02:00
|
|
|
const GURL& new_url = GURL(url.ToString());
|
|
|
|
if (url_ != new_url) {
|
2015-11-16 23:20:34 +01:00
|
|
|
Changed(kChangedUrl);
|
2019-04-24 04:50:25 +02:00
|
|
|
url_ = new_url;
|
2015-11-16 23:20:34 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefRequestImpl::GetMethod() {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-04-03 03:34:16 +02:00
|
|
|
return method_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestImpl::SetMethod(const CefString& method) {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-06-19 18:29:49 +02:00
|
|
|
CHECK_READONLY_RETURN_VOID();
|
2016-10-28 20:15:26 +02:00
|
|
|
const std::string& new_method = method;
|
|
|
|
if (method_ != new_method) {
|
2015-11-16 23:20:34 +01:00
|
|
|
Changed(kChangedMethod);
|
2019-04-24 04:50:25 +02:00
|
|
|
method_ = new_method;
|
2015-11-16 23:20:34 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2015-12-01 19:22:28 +01:00
|
|
|
void CefRequestImpl::SetReferrer(const CefString& referrer_url,
|
|
|
|
ReferrerPolicy policy) {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
CHECK_READONLY_RETURN_VOID();
|
|
|
|
|
2020-03-04 01:29:39 +01:00
|
|
|
const auto& sanitized_referrer = content::Referrer::SanitizeForRequest(
|
|
|
|
url_, content::Referrer(GURL(referrer_url.ToString()),
|
|
|
|
NetReferrerPolicyToBlinkReferrerPolicy(policy)));
|
|
|
|
const auto sanitized_policy =
|
|
|
|
BlinkReferrerPolicyToNetReferrerPolicy(sanitized_referrer.policy);
|
|
|
|
|
|
|
|
if (referrer_url_ != sanitized_referrer.url ||
|
|
|
|
referrer_policy_ != sanitized_policy) {
|
2019-04-24 04:50:25 +02:00
|
|
|
Changed(kChangedReferrer);
|
2020-03-04 01:29:39 +01:00
|
|
|
referrer_url_ = sanitized_referrer.url;
|
|
|
|
referrer_policy_ = sanitized_policy;
|
2015-12-01 19:22:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefRequestImpl::GetReferrerURL() {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
2016-10-28 20:15:26 +02:00
|
|
|
return referrer_url_.spec();
|
2015-12-01 19:22:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRequestImpl::ReferrerPolicy CefRequestImpl::GetReferrerPolicy() {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
return referrer_policy_;
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
CefRefPtr<CefPostData> CefRequestImpl::GetPostData() {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-04-03 03:34:16 +02:00
|
|
|
return postdata_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestImpl::SetPostData(CefRefPtr<CefPostData> postData) {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-06-19 18:29:49 +02:00
|
|
|
CHECK_READONLY_RETURN_VOID();
|
2015-11-16 23:20:34 +01:00
|
|
|
Changed(kChangedPostData);
|
2019-04-24 04:50:25 +02:00
|
|
|
postdata_ = postData;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestImpl::GetHeaderMap(HeaderMap& headerMap) {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-04-03 03:34:16 +02:00
|
|
|
headerMap = headermap_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestImpl::SetHeaderMap(const HeaderMap& headerMap) {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-06-19 18:29:49 +02:00
|
|
|
CHECK_READONLY_RETURN_VOID();
|
2019-04-24 04:50:25 +02:00
|
|
|
Changed(kChangedHeaderMap);
|
2015-12-01 19:22:28 +01:00
|
|
|
::GetHeaderMap(headerMap, headermap_);
|
2019-04-24 04:50:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefRequestImpl::GetHeaderByName(const CefString& name) {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
|
|
|
|
std::string nameLower = name;
|
2019-10-14 13:32:38 +02:00
|
|
|
HttpHeaderUtils::MakeASCIILower(&nameLower);
|
2019-04-24 04:50:25 +02:00
|
|
|
|
2019-10-14 13:32:38 +02:00
|
|
|
auto it = HttpHeaderUtils::FindHeaderInMap(nameLower, headermap_);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (it != headermap_.end()) {
|
2019-04-24 04:50:25 +02:00
|
|
|
return it->second;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-04-24 04:50:25 +02:00
|
|
|
|
|
|
|
return CefString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestImpl::SetHeaderByName(const CefString& name,
|
|
|
|
const CefString& value,
|
|
|
|
bool overwrite) {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
CHECK_READONLY_RETURN_VOID();
|
|
|
|
|
2022-06-17 15:28:55 +02:00
|
|
|
const std::string& nameStr = name;
|
2019-04-24 04:50:25 +02:00
|
|
|
|
|
|
|
// Do not include Referer in the header map.
|
2022-06-17 15:28:55 +02:00
|
|
|
if (base::EqualsCaseInsensitiveASCII(nameStr,
|
|
|
|
net::HttpRequestHeaders::kReferer)) {
|
2019-04-24 04:50:25 +02:00
|
|
|
return;
|
2022-06-17 15:28:55 +02:00
|
|
|
}
|
2019-04-24 04:50:25 +02:00
|
|
|
|
2015-11-16 23:20:34 +01:00
|
|
|
Changed(kChangedHeaderMap);
|
2019-04-24 04:50:25 +02:00
|
|
|
|
|
|
|
// There may be multiple values, so remove any first.
|
|
|
|
for (auto it = headermap_.begin(); it != headermap_.end();) {
|
2022-06-17 15:28:55 +02:00
|
|
|
if (base::EqualsCaseInsensitiveASCII(it->first.ToString(), nameStr)) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!overwrite) {
|
2019-04-24 04:50:25 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-04-24 04:50:25 +02:00
|
|
|
it = headermap_.erase(it);
|
|
|
|
} else {
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
headermap_.insert(std::make_pair(name, value));
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestImpl::Set(const CefString& url,
|
|
|
|
const CefString& method,
|
|
|
|
CefRefPtr<CefPostData> postData,
|
|
|
|
const HeaderMap& headerMap) {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-06-19 18:29:49 +02:00
|
|
|
CHECK_READONLY_RETURN_VOID();
|
2016-10-28 20:15:26 +02:00
|
|
|
const GURL& new_url = GURL(url.ToString());
|
|
|
|
if (url_ != new_url) {
|
2015-11-16 23:20:34 +01:00
|
|
|
Changed(kChangedUrl);
|
2019-04-24 04:50:25 +02:00
|
|
|
url_ = new_url;
|
2015-11-16 23:20:34 +01:00
|
|
|
}
|
2016-10-28 20:15:26 +02:00
|
|
|
const std::string& new_method = method;
|
|
|
|
if (method_ != new_method) {
|
2015-11-16 23:20:34 +01:00
|
|
|
Changed(kChangedMethod);
|
2019-04-24 04:50:25 +02:00
|
|
|
method_ = new_method;
|
2015-11-16 23:20:34 +01:00
|
|
|
}
|
2019-04-24 04:50:25 +02:00
|
|
|
if (postdata_ != postData) {
|
|
|
|
Changed(kChangedPostData);
|
|
|
|
postdata_ = postData;
|
|
|
|
}
|
|
|
|
Changed(kChangedHeaderMap);
|
2015-12-01 19:22:28 +01:00
|
|
|
::GetHeaderMap(headerMap, headermap_);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
int CefRequestImpl::GetFlags() {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-04-03 03:34:16 +02:00
|
|
|
return flags_;
|
|
|
|
}
|
2015-11-16 23:20:34 +01:00
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
void CefRequestImpl::SetFlags(int flags) {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-06-19 18:29:49 +02:00
|
|
|
CHECK_READONLY_RETURN_VOID();
|
2015-11-16 23:20:34 +01:00
|
|
|
if (flags_ != flags) {
|
|
|
|
Changed(kChangedFlags);
|
2019-04-24 04:50:25 +02:00
|
|
|
flags_ = flags;
|
2015-11-16 23:20:34 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefRequestImpl::GetFirstPartyForCookies() {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2020-03-04 01:29:39 +01:00
|
|
|
return site_for_cookies_.RepresentativeUrl().spec();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2015-11-16 23:20:34 +01:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
void CefRequestImpl::SetFirstPartyForCookies(const CefString& url) {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-06-19 18:29:49 +02:00
|
|
|
CHECK_READONLY_RETURN_VOID();
|
2020-03-04 01:29:39 +01:00
|
|
|
auto new_site = net::SiteForCookies::FromUrl(GURL(url.ToString()));
|
|
|
|
if (!new_site.IsEquivalent(site_for_cookies_)) {
|
|
|
|
Changed(kChangedSiteForCookies);
|
|
|
|
site_for_cookies_ = new_site;
|
2015-11-16 23:20:34 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2013-09-10 21:42:53 +02:00
|
|
|
CefRequestImpl::ResourceType CefRequestImpl::GetResourceType() {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2013-09-10 21:42:53 +02:00
|
|
|
return resource_type_;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRequestImpl::TransitionType CefRequestImpl::GetTransitionType() {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2013-09-10 21:42:53 +02:00
|
|
|
return transition_type_;
|
|
|
|
}
|
|
|
|
|
2023-06-01 16:06:15 +02:00
|
|
|
uint64_t CefRequestImpl::GetIdentifier() {
|
2015-03-11 19:44:11 +01:00
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
return identifier_;
|
|
|
|
}
|
|
|
|
|
2019-04-24 04:50:25 +02:00
|
|
|
void CefRequestImpl::Set(const network::ResourceRequest* request,
|
2023-06-01 16:06:15 +02:00
|
|
|
uint64_t identifier) {
|
2019-04-24 04:50:25 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
CHECK_READONLY_RETURN_VOID();
|
|
|
|
|
|
|
|
Reset();
|
|
|
|
|
|
|
|
url_ = request->url;
|
|
|
|
method_ = request->method;
|
|
|
|
identifier_ = identifier;
|
|
|
|
|
|
|
|
if (request->referrer.is_valid()) {
|
2020-03-04 01:29:39 +01:00
|
|
|
const auto& sanitized_referrer = content::Referrer::SanitizeForRequest(
|
|
|
|
request->url,
|
|
|
|
content::Referrer(
|
|
|
|
request->referrer,
|
|
|
|
NetReferrerPolicyToBlinkReferrerPolicy(
|
|
|
|
static_cast<cef_referrer_policy_t>(request->referrer_policy))));
|
|
|
|
referrer_url_ = sanitized_referrer.url;
|
2019-04-24 04:50:25 +02:00
|
|
|
referrer_policy_ =
|
2020-03-04 01:29:39 +01:00
|
|
|
BlinkReferrerPolicyToNetReferrerPolicy(sanitized_referrer.policy);
|
2019-04-24 04:50:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Transfer request headers.
|
|
|
|
::GetHeaderMap(request->headers, headermap_);
|
|
|
|
|
|
|
|
// Transfer post data, if any.
|
|
|
|
if (request->request_body) {
|
|
|
|
postdata_ = CefPostData::Create();
|
|
|
|
static_cast<CefPostDataImpl*>(postdata_.get())->Set(*request->request_body);
|
|
|
|
}
|
|
|
|
|
2020-03-04 01:29:39 +01:00
|
|
|
site_for_cookies_ = request->site_for_cookies;
|
2019-04-24 04:50:25 +02:00
|
|
|
|
|
|
|
resource_type_ = static_cast<cef_resource_type_t>(request->resource_type);
|
|
|
|
transition_type_ =
|
|
|
|
static_cast<cef_transition_type_t>(request->transition_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestImpl::Get(network::ResourceRequest* request,
|
|
|
|
bool changed_only) const {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (ShouldSet(kChangedUrl, changed_only)) {
|
2019-04-24 04:50:25 +02:00
|
|
|
request->url = url_;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-04-24 04:50:25 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (ShouldSet(kChangedMethod, changed_only)) {
|
2019-04-24 04:50:25 +02:00
|
|
|
request->method = method_;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-04-24 04:50:25 +02:00
|
|
|
|
|
|
|
if (ShouldSet(kChangedReferrer, changed_only)) {
|
|
|
|
request->referrer = referrer_url_;
|
|
|
|
request->referrer_policy =
|
2020-08-29 00:39:23 +02:00
|
|
|
static_cast<net::ReferrerPolicy>(referrer_policy_);
|
2019-04-24 04:50:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ShouldSet(kChangedHeaderMap, changed_only)) {
|
|
|
|
net::HttpRequestHeaders headers;
|
|
|
|
headers.AddHeadersFromString(HttpHeaderUtils::GenerateHeaders(headermap_));
|
|
|
|
request->headers.Swap(&headers);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ShouldSet(kChangedPostData, changed_only)) {
|
|
|
|
if (postdata_.get()) {
|
|
|
|
request->request_body =
|
|
|
|
static_cast<CefPostDataImpl*>(postdata_.get())->GetBody();
|
|
|
|
} else if (request->request_body) {
|
|
|
|
request->request_body = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-04 01:29:39 +01:00
|
|
|
if (!site_for_cookies_.IsNull() &&
|
|
|
|
ShouldSet(kChangedSiteForCookies, changed_only)) {
|
|
|
|
request->site_for_cookies = site_for_cookies_;
|
2019-04-24 04:50:25 +02:00
|
|
|
}
|
2019-05-11 00:14:48 +02:00
|
|
|
|
|
|
|
if (ShouldSet(kChangedFlags, changed_only)) {
|
|
|
|
int flags = flags_;
|
|
|
|
if (!(flags & kURCachePolicyMask)) {
|
|
|
|
// Only consider the Cache-Control directives when a cache policy is not
|
|
|
|
// explicitly set on the request.
|
|
|
|
flags |= GetCacheControlHeaderPolicy(headermap_);
|
|
|
|
}
|
|
|
|
|
|
|
|
int net_flags = 0;
|
|
|
|
|
|
|
|
if (flags & UR_FLAG_SKIP_CACHE) {
|
|
|
|
net_flags |= net::LOAD_BYPASS_CACHE;
|
|
|
|
}
|
|
|
|
if (flags & UR_FLAG_ONLY_FROM_CACHE) {
|
|
|
|
net_flags |= net::LOAD_ONLY_FROM_CACHE | net::LOAD_SKIP_CACHE_VALIDATION;
|
|
|
|
}
|
|
|
|
if (flags & UR_FLAG_DISABLE_CACHE) {
|
|
|
|
net_flags |= net::LOAD_DISABLE_CACHE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(flags & UR_FLAG_ALLOW_STORED_CREDENTIALS)) {
|
2020-10-08 21:54:42 +02:00
|
|
|
// This will disable all credentials including cookies, auth tokens, etc.
|
|
|
|
request->credentials_mode = network::mojom::CredentialsMode::kOmit;
|
2019-05-11 00:14:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
request->load_flags = net_flags;
|
|
|
|
}
|
2019-04-24 04:50:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestImpl::Set(const net::RedirectInfo& redirect_info) {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
CHECK_READONLY_RETURN_VOID();
|
|
|
|
|
|
|
|
url_ = redirect_info.new_url;
|
|
|
|
method_ = redirect_info.new_method;
|
2020-03-04 01:29:39 +01:00
|
|
|
site_for_cookies_ = redirect_info.new_site_for_cookies;
|
|
|
|
|
|
|
|
const auto& sanitized_referrer = content::Referrer::SanitizeForRequest(
|
|
|
|
redirect_info.new_url,
|
|
|
|
content::Referrer(GURL(redirect_info.new_referrer),
|
|
|
|
NetReferrerPolicyToBlinkReferrerPolicy(
|
|
|
|
static_cast<cef_referrer_policy_t>(
|
|
|
|
redirect_info.new_referrer_policy))));
|
|
|
|
referrer_url_ = sanitized_referrer.url;
|
2019-04-24 04:50:25 +02:00
|
|
|
referrer_policy_ =
|
2020-03-04 01:29:39 +01:00
|
|
|
BlinkReferrerPolicyToNetReferrerPolicy(sanitized_referrer.policy);
|
2019-04-24 04:50:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestImpl::Set(const net::HttpRequestHeaders& headers) {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
CHECK_READONLY_RETURN_VOID();
|
|
|
|
|
|
|
|
::GetHeaderMap(headers, headermap_);
|
|
|
|
}
|
|
|
|
|
2022-03-26 02:12:30 +01:00
|
|
|
void CefRequestImpl::Set(content::NavigationHandle* navigation_handle) {
|
2015-10-09 17:23:12 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
CHECK_READONLY_RETURN_VOID();
|
|
|
|
|
|
|
|
Reset();
|
|
|
|
|
2022-03-26 02:12:30 +01:00
|
|
|
url_ = navigation_handle->GetURL();
|
|
|
|
method_ = navigation_handle->IsPost() ? "POST" : "GET";
|
2015-10-09 17:23:12 +02:00
|
|
|
|
2022-03-26 02:12:30 +01:00
|
|
|
const auto& sanitized_referrer = content::Referrer::SanitizeForRequest(
|
|
|
|
navigation_handle->GetURL(), navigation_handle->GetReferrer());
|
|
|
|
referrer_url_ = sanitized_referrer->url;
|
2015-12-01 19:22:28 +01:00
|
|
|
referrer_policy_ =
|
2022-03-26 02:12:30 +01:00
|
|
|
BlinkReferrerPolicyToNetReferrerPolicy(sanitized_referrer->policy);
|
2015-10-09 17:23:12 +02:00
|
|
|
|
2022-03-26 02:12:30 +01:00
|
|
|
resource_type_ =
|
|
|
|
navigation_handle->IsInMainFrame() ? RT_MAIN_FRAME : RT_SUB_FRAME;
|
|
|
|
transition_type_ = static_cast<cef_transition_type_t>(
|
|
|
|
navigation_handle->GetPageTransition());
|
2015-10-09 17:23:12 +02:00
|
|
|
}
|
|
|
|
|
2015-12-01 19:22:28 +01:00
|
|
|
// static
|
2021-05-14 18:58:55 +02:00
|
|
|
void CefRequestImpl::Get(const cef::mojom::RequestParamsPtr& params,
|
2015-12-01 19:22:28 +01:00
|
|
|
blink::WebURLRequest& request) {
|
2021-05-14 18:58:55 +02:00
|
|
|
request.SetUrl(params->url);
|
|
|
|
request.SetRequestorOrigin(blink::WebSecurityOrigin::Create(params->url));
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!params->method.empty()) {
|
2021-05-14 18:58:55 +02:00
|
|
|
request.SetHttpMethod(blink::WebString::FromASCII(params->method));
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-12-01 19:22:28 +01:00
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
if (params->referrer && params->referrer->url.is_valid()) {
|
2015-12-01 19:22:28 +01:00
|
|
|
const blink::WebString& referrer =
|
2017-04-20 21:28:17 +02:00
|
|
|
blink::WebSecurityPolicy::GenerateReferrerHeader(
|
2021-05-14 18:58:55 +02:00
|
|
|
params->referrer->policy, params->url,
|
|
|
|
blink::WebString::FromUTF8(params->referrer->url.spec()));
|
2017-04-20 21:28:17 +02:00
|
|
|
if (!referrer.IsEmpty()) {
|
2020-03-04 01:29:39 +01:00
|
|
|
request.SetReferrerString(referrer);
|
2021-05-14 18:58:55 +02:00
|
|
|
request.SetReferrerPolicy(params->referrer->policy);
|
2015-12-01 19:22:28 +01:00
|
|
|
}
|
2015-11-16 23:20:34 +01:00
|
|
|
}
|
2012-06-19 18:29:49 +02:00
|
|
|
|
2017-11-17 17:33:50 +01:00
|
|
|
CefRequest::HeaderMap headerMap;
|
2021-05-14 18:58:55 +02:00
|
|
|
if (!params->headers.empty()) {
|
|
|
|
for (net::HttpUtil::HeadersIterator i(params->headers.begin(),
|
|
|
|
params->headers.end(), "\n\r");
|
2017-05-17 11:29:28 +02:00
|
|
|
i.GetNext();) {
|
2019-04-16 16:38:48 +02:00
|
|
|
request.AddHttpHeaderField(blink::WebString::FromUTF8(i.name()),
|
2017-04-20 21:28:17 +02:00
|
|
|
blink::WebString::FromUTF8(i.values()));
|
2017-11-17 17:33:50 +01:00
|
|
|
headerMap.insert(std::make_pair(i.name(), i.values()));
|
2015-12-01 19:22:28 +01:00
|
|
|
}
|
2015-11-16 23:20:34 +01:00
|
|
|
}
|
2012-06-19 18:29:49 +02:00
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
if (params->upload_data) {
|
2021-04-21 00:52:34 +02:00
|
|
|
const std::u16string& method = request.HttpMethod().Utf16();
|
|
|
|
if (method == u"GET" || method == u"HEAD") {
|
2019-06-05 16:15:45 +02:00
|
|
|
request.SetHttpMethod(blink::WebString::FromASCII("POST"));
|
2015-12-01 19:22:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// The comparison performed by httpHeaderField() is case insensitive.
|
2017-05-17 11:29:28 +02:00
|
|
|
if (request
|
|
|
|
.HttpHeaderField(blink::WebString::FromASCII(
|
|
|
|
net::HttpRequestHeaders::kContentType))
|
|
|
|
.length() == 0) {
|
2019-04-16 16:38:48 +02:00
|
|
|
request.SetHttpHeaderField(
|
2017-04-20 21:28:17 +02:00
|
|
|
blink::WebString::FromASCII(net::HttpRequestHeaders::kContentType),
|
2019-05-11 00:14:48 +02:00
|
|
|
blink::WebString::FromASCII(
|
|
|
|
net_service::kContentTypeApplicationFormURLEncoded));
|
2015-12-01 19:22:28 +01:00
|
|
|
}
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
request.SetHttpBody(
|
|
|
|
blink::GetWebHTTPBodyForRequestBody(*params->upload_data));
|
2012-06-19 18:29:49 +02:00
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!params->site_for_cookies.IsNull()) {
|
2021-05-14 18:58:55 +02:00
|
|
|
request.SetSiteForCookies(params->site_for_cookies);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-12-01 19:22:28 +01:00
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
int flags = params->load_flags;
|
2017-11-17 17:33:50 +01:00
|
|
|
if (!(flags & kURCachePolicyMask)) {
|
|
|
|
// Only consider the Cache-Control directives when a cache policy is not
|
|
|
|
// explicitly set on the request.
|
|
|
|
flags |= GetCacheControlHeaderPolicy(headerMap);
|
|
|
|
}
|
2017-12-07 22:44:24 +01:00
|
|
|
request.SetCacheMode(GetFetchCacheMode(flags));
|
2015-12-01 19:22:28 +01:00
|
|
|
|
2023-10-19 20:08:48 +02:00
|
|
|
request.SetCredentialsMode(
|
|
|
|
(params->load_flags & UR_FLAG_ALLOW_STORED_CREDENTIALS)
|
|
|
|
? network::mojom::CredentialsMode::kInclude
|
|
|
|
: network::mojom::CredentialsMode::kOmit);
|
|
|
|
request.SetReportUploadProgress(params->load_flags &
|
|
|
|
UR_FLAG_REPORT_UPLOAD_PROGRESS);
|
2015-12-01 19:22:28 +01:00
|
|
|
}
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
void CefRequestImpl::Get(cef::mojom::RequestParamsPtr& params) const {
|
2015-12-01 19:22:28 +01:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-06-19 18:29:49 +02:00
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
params->url = url_;
|
|
|
|
params->method = method_;
|
2012-06-19 18:29:49 +02:00
|
|
|
|
2015-12-01 19:22:28 +01:00
|
|
|
// Referrer policy will be applied later in the request pipeline.
|
2021-05-14 18:58:55 +02:00
|
|
|
params->referrer = blink::mojom::Referrer::New(
|
|
|
|
referrer_url_, NetReferrerPolicyToBlinkReferrerPolicy(referrer_policy_));
|
2012-06-19 18:29:49 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!headermap_.empty()) {
|
2021-05-14 18:58:55 +02:00
|
|
|
params->headers = HttpHeaderUtils::GenerateHeaders(headermap_);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-12-01 19:22:28 +01:00
|
|
|
|
|
|
|
if (postdata_) {
|
|
|
|
CefPostDataImpl* impl = static_cast<CefPostDataImpl*>(postdata_.get());
|
2021-05-14 18:58:55 +02:00
|
|
|
params->upload_data = impl->GetBody();
|
2015-11-16 23:20:34 +01:00
|
|
|
}
|
2012-06-19 18:29:49 +02:00
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
params->site_for_cookies = site_for_cookies_;
|
|
|
|
params->load_flags = flags_;
|
2015-12-01 19:22:28 +01:00
|
|
|
}
|
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
void CefRequestImpl::SetReadOnly(bool read_only) {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (read_only_ == read_only) {
|
2012-06-19 18:29:49 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-06-19 18:29:49 +02:00
|
|
|
|
|
|
|
read_only_ = read_only;
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (postdata_.get()) {
|
2012-06-19 18:29:49 +02:00
|
|
|
static_cast<CefPostDataImpl*>(postdata_.get())->SetReadOnly(read_only);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-06-19 18:29:49 +02:00
|
|
|
}
|
|
|
|
|
2019-04-24 04:50:25 +02:00
|
|
|
void CefRequestImpl::SetTrackChanges(bool track_changes,
|
|
|
|
bool backup_on_change) {
|
2015-11-16 23:20:34 +01:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (track_changes_ == track_changes) {
|
2015-11-16 23:20:34 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-11-16 23:20:34 +01:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!track_changes && backup_on_change_) {
|
2019-04-24 04:50:25 +02:00
|
|
|
backup_.reset();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-04-24 04:50:25 +02:00
|
|
|
|
2015-11-16 23:20:34 +01:00
|
|
|
track_changes_ = track_changes;
|
2019-04-24 04:50:25 +02:00
|
|
|
backup_on_change_ = track_changes ? backup_on_change : false;
|
2015-11-16 23:20:34 +01:00
|
|
|
changes_ = kChangedNone;
|
|
|
|
|
|
|
|
if (postdata_.get()) {
|
2017-05-17 11:29:28 +02:00
|
|
|
static_cast<CefPostDataImpl*>(postdata_.get())
|
|
|
|
->SetTrackChanges(track_changes);
|
2015-11-16 23:20:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-24 04:50:25 +02:00
|
|
|
void CefRequestImpl::RevertChanges() {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
DCHECK(!read_only_);
|
|
|
|
DCHECK(track_changes_);
|
|
|
|
DCHECK(backup_on_change_);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!backup_) {
|
2019-04-24 04:50:25 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-04-24 04:50:25 +02:00
|
|
|
|
|
|
|
// Restore the original values if a backup exists.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (backup_->backups_ & kChangedUrl) {
|
2019-04-24 04:50:25 +02:00
|
|
|
url_ = backup_->url_;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (backup_->backups_ & kChangedMethod) {
|
2019-04-24 04:50:25 +02:00
|
|
|
method_ = backup_->method_;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-04-24 04:50:25 +02:00
|
|
|
if (backup_->backups_ & kChangedReferrer) {
|
|
|
|
referrer_url_ = backup_->referrer_url_;
|
|
|
|
referrer_policy_ = backup_->referrer_policy_;
|
|
|
|
}
|
2023-01-02 23:59:03 +01:00
|
|
|
if (backup_->backups_ & kChangedPostData) {
|
2019-04-24 04:50:25 +02:00
|
|
|
postdata_ = backup_->postdata_;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-04-24 04:50:25 +02:00
|
|
|
if (backup_->backups_ & kChangedHeaderMap) {
|
|
|
|
DCHECK(backup_->headermap_);
|
|
|
|
headermap_.swap(*backup_->headermap_);
|
|
|
|
}
|
2023-01-02 23:59:03 +01:00
|
|
|
if (backup_->backups_ & kChangedFlags) {
|
2019-04-24 04:50:25 +02:00
|
|
|
flags_ = backup_->flags_;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (backup_->backups_ & kChangedSiteForCookies) {
|
2020-03-04 01:29:39 +01:00
|
|
|
site_for_cookies_ = backup_->site_for_cookies_;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-04-24 04:50:25 +02:00
|
|
|
|
|
|
|
backup_.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestImpl::DiscardChanges() {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
DCHECK(track_changes_);
|
|
|
|
DCHECK(backup_on_change_);
|
|
|
|
backup_.reset();
|
|
|
|
}
|
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
uint8_t CefRequestImpl::GetChanges() const {
|
2015-11-16 23:20:34 +01:00
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
uint8_t changes = changes_;
|
2015-11-16 23:20:34 +01:00
|
|
|
if (postdata_.get() &&
|
|
|
|
static_cast<CefPostDataImpl*>(postdata_.get())->HasChanges()) {
|
|
|
|
changes |= kChangedPostData;
|
|
|
|
}
|
|
|
|
return changes;
|
|
|
|
}
|
|
|
|
|
2017-07-27 01:19:27 +02:00
|
|
|
// From content/child/web_url_loader_impl.cc
|
|
|
|
// static
|
2018-11-03 02:15:09 +01:00
|
|
|
network::mojom::ReferrerPolicy
|
|
|
|
CefRequestImpl::NetReferrerPolicyToBlinkReferrerPolicy(
|
2017-07-27 01:19:27 +02:00
|
|
|
cef_referrer_policy_t net_policy) {
|
|
|
|
switch (net_policy) {
|
|
|
|
case REFERRER_POLICY_CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE:
|
2018-11-03 02:15:09 +01:00
|
|
|
return network::mojom::ReferrerPolicy::kNoReferrerWhenDowngrade;
|
2017-07-27 01:19:27 +02:00
|
|
|
case REFERRER_POLICY_REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN:
|
2020-03-30 22:13:42 +02:00
|
|
|
return network::mojom::ReferrerPolicy::kStrictOriginWhenCrossOrigin;
|
2017-07-27 01:19:27 +02:00
|
|
|
case REFERRER_POLICY_ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN:
|
2018-11-03 02:15:09 +01:00
|
|
|
return network::mojom::ReferrerPolicy::kOriginWhenCrossOrigin;
|
2017-07-27 01:19:27 +02:00
|
|
|
case REFERRER_POLICY_NEVER_CLEAR_REFERRER:
|
2018-11-03 02:15:09 +01:00
|
|
|
return network::mojom::ReferrerPolicy::kAlways;
|
2017-07-27 01:19:27 +02:00
|
|
|
case REFERRER_POLICY_ORIGIN:
|
2018-11-03 02:15:09 +01:00
|
|
|
return network::mojom::ReferrerPolicy::kOrigin;
|
2017-07-27 01:19:27 +02:00
|
|
|
case REFERRER_POLICY_CLEAR_REFERRER_ON_TRANSITION_CROSS_ORIGIN:
|
2018-11-03 02:15:09 +01:00
|
|
|
return network::mojom::ReferrerPolicy::kSameOrigin;
|
2017-07-27 01:19:27 +02:00
|
|
|
case REFERRER_POLICY_ORIGIN_CLEAR_ON_TRANSITION_FROM_SECURE_TO_INSECURE:
|
2018-11-03 02:15:09 +01:00
|
|
|
return network::mojom::ReferrerPolicy::kStrictOrigin;
|
2017-07-27 01:19:27 +02:00
|
|
|
case REFERRER_POLICY_NO_REFERRER:
|
2018-11-03 02:15:09 +01:00
|
|
|
return network::mojom::ReferrerPolicy::kNever;
|
2017-07-27 01:19:27 +02:00
|
|
|
}
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false);
|
2018-11-03 02:15:09 +01:00
|
|
|
return network::mojom::ReferrerPolicy::kDefault;
|
2017-07-27 01:19:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
cef_referrer_policy_t CefRequestImpl::BlinkReferrerPolicyToNetReferrerPolicy(
|
2018-11-03 02:15:09 +01:00
|
|
|
network::mojom::ReferrerPolicy blink_policy) {
|
2017-07-27 01:19:27 +02:00
|
|
|
switch (blink_policy) {
|
2018-11-03 02:15:09 +01:00
|
|
|
case network::mojom::ReferrerPolicy::kNoReferrerWhenDowngrade:
|
2017-07-27 01:19:27 +02:00
|
|
|
return REFERRER_POLICY_CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE;
|
2020-03-30 22:13:42 +02:00
|
|
|
case network::mojom::ReferrerPolicy::kStrictOriginWhenCrossOrigin:
|
2017-07-27 01:19:27 +02:00
|
|
|
return REFERRER_POLICY_REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN;
|
2018-11-03 02:15:09 +01:00
|
|
|
case network::mojom::ReferrerPolicy::kOriginWhenCrossOrigin:
|
2017-07-27 01:19:27 +02:00
|
|
|
return REFERRER_POLICY_ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN;
|
2018-11-03 02:15:09 +01:00
|
|
|
case network::mojom::ReferrerPolicy::kAlways:
|
2017-07-27 01:19:27 +02:00
|
|
|
return REFERRER_POLICY_NEVER_CLEAR_REFERRER;
|
2018-11-03 02:15:09 +01:00
|
|
|
case network::mojom::ReferrerPolicy::kOrigin:
|
2017-07-27 01:19:27 +02:00
|
|
|
return REFERRER_POLICY_ORIGIN;
|
2018-11-03 02:15:09 +01:00
|
|
|
case network::mojom::ReferrerPolicy::kSameOrigin:
|
2017-07-27 01:19:27 +02:00
|
|
|
return REFERRER_POLICY_CLEAR_REFERRER_ON_TRANSITION_CROSS_ORIGIN;
|
2018-11-03 02:15:09 +01:00
|
|
|
case network::mojom::ReferrerPolicy::kStrictOrigin:
|
2017-07-27 01:19:27 +02:00
|
|
|
return REFERRER_POLICY_ORIGIN_CLEAR_ON_TRANSITION_FROM_SECURE_TO_INSECURE;
|
2018-11-03 02:15:09 +01:00
|
|
|
case network::mojom::ReferrerPolicy::kNever:
|
2017-07-27 01:19:27 +02:00
|
|
|
return REFERRER_POLICY_NO_REFERRER;
|
2018-11-03 02:15:09 +01:00
|
|
|
case network::mojom::ReferrerPolicy::kDefault:
|
2017-07-27 01:19:27 +02:00
|
|
|
return REFERRER_POLICY_DEFAULT;
|
|
|
|
}
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false);
|
2017-07-27 01:19:27 +02:00
|
|
|
return REFERRER_POLICY_DEFAULT;
|
|
|
|
}
|
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
void CefRequestImpl::Changed(uint8_t changes) {
|
2015-11-16 23:20:34 +01:00
|
|
|
lock_.AssertAcquired();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!track_changes_) {
|
2019-04-24 04:50:25 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-04-24 04:50:25 +02:00
|
|
|
|
|
|
|
if (backup_on_change_) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!backup_) {
|
2024-01-20 23:48:57 +01:00
|
|
|
backup_ = std::make_unique<Backup>();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-04-24 04:50:25 +02:00
|
|
|
|
|
|
|
// Set the backup values if not already set.
|
|
|
|
if ((changes & kChangedUrl) && !(backup_->backups_ & kChangedUrl)) {
|
|
|
|
backup_->url_ = url_;
|
|
|
|
backup_->backups_ |= kChangedUrl;
|
|
|
|
}
|
|
|
|
if ((changes & kChangedMethod) && !(backup_->backups_ & kChangedMethod)) {
|
|
|
|
backup_->method_ = method_;
|
|
|
|
backup_->backups_ |= kChangedMethod;
|
|
|
|
}
|
|
|
|
if ((changes & kChangedReferrer) &&
|
|
|
|
!(backup_->backups_ & kChangedReferrer)) {
|
|
|
|
backup_->referrer_url_ = referrer_url_;
|
|
|
|
backup_->referrer_policy_ = referrer_policy_;
|
|
|
|
backup_->backups_ |= kChangedReferrer;
|
|
|
|
}
|
|
|
|
if ((changes & kChangedPostData) &&
|
|
|
|
!(backup_->backups_ & kChangedPostData)) {
|
|
|
|
backup_->postdata_ = postdata_;
|
|
|
|
backup_->backups_ |= kChangedPostData;
|
|
|
|
}
|
|
|
|
if ((changes & kChangedHeaderMap) &&
|
|
|
|
!(backup_->backups_ & kChangedHeaderMap)) {
|
2024-01-20 23:48:57 +01:00
|
|
|
backup_->headermap_ = std::make_unique<HeaderMap>();
|
2019-06-25 22:47:34 +02:00
|
|
|
if (!headermap_.empty()) {
|
|
|
|
backup_->headermap_->insert(headermap_.begin(), headermap_.end());
|
|
|
|
}
|
2019-04-24 04:50:25 +02:00
|
|
|
backup_->backups_ |= kChangedHeaderMap;
|
|
|
|
}
|
|
|
|
if ((changes & kChangedFlags) && !(backup_->backups_ & kChangedFlags)) {
|
|
|
|
backup_->flags_ = flags_;
|
|
|
|
backup_->backups_ |= kChangedFlags;
|
|
|
|
}
|
2020-03-04 01:29:39 +01:00
|
|
|
if ((changes & kChangedSiteForCookies) &&
|
|
|
|
!(backup_->backups_ & kChangedSiteForCookies)) {
|
|
|
|
backup_->site_for_cookies_ = site_for_cookies_;
|
|
|
|
backup_->backups_ |= kChangedSiteForCookies;
|
2019-04-24 04:50:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
changes_ |= changes;
|
2015-11-16 23:20:34 +01:00
|
|
|
}
|
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
bool CefRequestImpl::ShouldSet(uint8_t changes, bool changed_only) const {
|
2015-11-16 23:20:34 +01:00
|
|
|
lock_.AssertAcquired();
|
|
|
|
|
|
|
|
// Always change if changes are not being tracked.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!track_changes_) {
|
2015-11-16 23:20:34 +01:00
|
|
|
return true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-11-16 23:20:34 +01:00
|
|
|
|
|
|
|
// Always change if changed-only was not requested.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!changed_only) {
|
2015-11-16 23:20:34 +01:00
|
|
|
return true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-11-16 23:20:34 +01:00
|
|
|
|
|
|
|
// Change if the |changes| bit flag has been set.
|
2023-01-02 23:59:03 +01:00
|
|
|
if ((changes_ & changes) == changes) {
|
2015-11-16 23:20:34 +01:00
|
|
|
return true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-11-16 23:20:34 +01:00
|
|
|
|
|
|
|
if ((changes & kChangedPostData) == kChangedPostData) {
|
|
|
|
// Change if the post data object was modified directly.
|
|
|
|
if (postdata_.get() &&
|
|
|
|
static_cast<CefPostDataImpl*>(postdata_.get())->HasChanges()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-09 17:23:12 +02:00
|
|
|
void CefRequestImpl::Reset() {
|
|
|
|
lock_.AssertAcquired();
|
|
|
|
DCHECK(!read_only_);
|
|
|
|
|
2016-10-28 20:15:26 +02:00
|
|
|
url_ = GURL();
|
2015-10-09 17:23:12 +02:00
|
|
|
method_ = "GET";
|
2016-10-28 20:15:26 +02:00
|
|
|
referrer_url_ = GURL();
|
2015-12-01 19:22:28 +01:00
|
|
|
referrer_policy_ = REFERRER_POLICY_DEFAULT;
|
2020-01-15 14:36:24 +01:00
|
|
|
postdata_ = nullptr;
|
2015-10-09 17:23:12 +02:00
|
|
|
headermap_.clear();
|
|
|
|
resource_type_ = RT_SUB_RESOURCE;
|
|
|
|
transition_type_ = TT_EXPLICIT;
|
|
|
|
identifier_ = 0U;
|
|
|
|
flags_ = UR_FLAG_NONE;
|
2020-03-04 01:29:39 +01:00
|
|
|
site_for_cookies_ = net::SiteForCookies();
|
2015-11-16 23:20:34 +01:00
|
|
|
|
|
|
|
changes_ = kChangedNone;
|
2015-10-09 17:23:12 +02:00
|
|
|
}
|
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
// CefPostData ----------------------------------------------------------------
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefPostData> CefPostData::Create() {
|
2012-04-03 03:34:16 +02:00
|
|
|
CefRefPtr<CefPostData> postdata(new CefPostDataImpl());
|
|
|
|
return postdata;
|
|
|
|
}
|
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
// CefPostDataImpl ------------------------------------------------------------
|
|
|
|
|
2024-01-20 23:48:57 +01:00
|
|
|
CefPostDataImpl::CefPostDataImpl() = default;
|
2012-06-19 18:29:49 +02:00
|
|
|
|
|
|
|
bool CefPostDataImpl::IsReadOnly() {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-06-19 18:29:49 +02:00
|
|
|
return read_only_;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2015-12-01 19:22:28 +01:00
|
|
|
bool CefPostDataImpl::HasExcludedElements() {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
return has_excluded_elements_;
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
size_t CefPostDataImpl::GetElementCount() {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-04-03 03:34:16 +02:00
|
|
|
return elements_.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefPostDataImpl::GetElements(ElementVector& elements) {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-04-03 03:34:16 +02:00
|
|
|
elements = elements_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefPostDataImpl::RemoveElement(CefRefPtr<CefPostDataElement> element) {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-06-19 18:29:49 +02:00
|
|
|
CHECK_READONLY_RETURN(false);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
ElementVector::iterator it = elements_.begin();
|
|
|
|
for (; it != elements_.end(); ++it) {
|
|
|
|
if (it->get() == element.get()) {
|
|
|
|
elements_.erase(it);
|
2015-11-16 23:20:34 +01:00
|
|
|
Changed();
|
2012-04-03 03:34:16 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefPostDataImpl::AddElement(CefRefPtr<CefPostDataElement> element) {
|
|
|
|
bool found = false;
|
|
|
|
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-06-19 18:29:49 +02:00
|
|
|
CHECK_READONLY_RETURN(false);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// check that the element isn't already in the list before adding
|
|
|
|
ElementVector::const_iterator it = elements_.begin();
|
|
|
|
for (; it != elements_.end(); ++it) {
|
|
|
|
if (it->get() == element.get()) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-16 23:20:34 +01:00
|
|
|
if (!found) {
|
2012-04-03 03:34:16 +02:00
|
|
|
elements_.push_back(element);
|
2015-11-16 23:20:34 +01:00
|
|
|
Changed();
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return !found;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefPostDataImpl::RemoveElements() {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-06-19 18:29:49 +02:00
|
|
|
CHECK_READONLY_RETURN_VOID();
|
2012-04-03 03:34:16 +02:00
|
|
|
elements_.clear();
|
2015-11-16 23:20:34 +01:00
|
|
|
Changed();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2019-04-24 04:50:25 +02:00
|
|
|
void CefPostDataImpl::Set(const network::ResourceRequestBody& body) {
|
|
|
|
{
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
CHECK_READONLY_RETURN_VOID();
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefPostDataElement> postelem;
|
|
|
|
|
|
|
|
for (const auto& element : *body.elements()) {
|
|
|
|
postelem = CefPostDataElement::Create();
|
|
|
|
static_cast<CefPostDataElementImpl*>(postelem.get())->Set(element);
|
|
|
|
AddElement(postelem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
scoped_refptr<network::ResourceRequestBody> CefPostDataImpl::GetBody() const {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
|
|
|
|
scoped_refptr<network::ResourceRequestBody> body =
|
|
|
|
new network::ResourceRequestBody();
|
|
|
|
for (const auto& element : elements_) {
|
|
|
|
static_cast<CefPostDataElementImpl*>(element.get())->Get(*body);
|
|
|
|
}
|
|
|
|
return body;
|
|
|
|
}
|
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
void CefPostDataImpl::SetReadOnly(bool read_only) {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (read_only_ == read_only) {
|
2012-06-19 18:29:49 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-06-19 18:29:49 +02:00
|
|
|
|
|
|
|
read_only_ = read_only;
|
|
|
|
|
|
|
|
ElementVector::const_iterator it = elements_.begin();
|
|
|
|
for (; it != elements_.end(); ++it) {
|
|
|
|
static_cast<CefPostDataElementImpl*>(it->get())->SetReadOnly(read_only);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-16 23:20:34 +01:00
|
|
|
void CefPostDataImpl::SetTrackChanges(bool track_changes) {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (track_changes_ == track_changes) {
|
2015-11-16 23:20:34 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-11-16 23:20:34 +01:00
|
|
|
|
|
|
|
track_changes_ = track_changes;
|
|
|
|
has_changes_ = false;
|
|
|
|
|
|
|
|
ElementVector::const_iterator it = elements_.begin();
|
|
|
|
for (; it != elements_.end(); ++it) {
|
2017-05-17 11:29:28 +02:00
|
|
|
static_cast<CefPostDataElementImpl*>(it->get())->SetTrackChanges(
|
|
|
|
track_changes);
|
2015-11-16 23:20:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefPostDataImpl::HasChanges() const {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (has_changes_) {
|
2015-11-16 23:20:34 +01:00
|
|
|
return true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-11-16 23:20:34 +01:00
|
|
|
|
|
|
|
ElementVector::const_iterator it = elements_.begin();
|
|
|
|
for (; it != elements_.end(); ++it) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (static_cast<CefPostDataElementImpl*>(it->get())->HasChanges()) {
|
2015-11-16 23:20:34 +01:00
|
|
|
return true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-11-16 23:20:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefPostDataImpl::Changed() {
|
|
|
|
lock_.AssertAcquired();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (track_changes_ && !has_changes_) {
|
2015-11-16 23:20:34 +01:00
|
|
|
has_changes_ = true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-11-16 23:20:34 +01:00
|
|
|
}
|
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
// CefPostDataElement ---------------------------------------------------------
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefPostDataElement> CefPostDataElement::Create() {
|
2012-04-03 03:34:16 +02:00
|
|
|
CefRefPtr<CefPostDataElement> element(new CefPostDataElementImpl());
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
// CefPostDataElementImpl -----------------------------------------------------
|
|
|
|
|
2024-01-20 23:48:57 +01:00
|
|
|
CefPostDataElementImpl::CefPostDataElementImpl() {
|
2012-04-03 03:34:16 +02:00
|
|
|
memset(&data_, 0, sizeof(data_));
|
|
|
|
}
|
|
|
|
|
|
|
|
CefPostDataElementImpl::~CefPostDataElementImpl() {
|
2012-06-19 18:29:49 +02:00
|
|
|
Cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefPostDataElementImpl::IsReadOnly() {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-06-19 18:29:49 +02:00
|
|
|
return read_only_;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefPostDataElementImpl::SetToEmpty() {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-06-19 18:29:49 +02:00
|
|
|
CHECK_READONLY_RETURN_VOID();
|
|
|
|
|
|
|
|
Cleanup();
|
2015-11-16 23:20:34 +01:00
|
|
|
Changed();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefPostDataElementImpl::SetToFile(const CefString& fileName) {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-06-19 18:29:49 +02:00
|
|
|
CHECK_READONLY_RETURN_VOID();
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Clear any data currently in the element
|
2014-07-15 00:18:51 +02:00
|
|
|
Cleanup();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Assign the new data
|
|
|
|
type_ = PDE_TYPE_FILE;
|
|
|
|
cef_string_copy(fileName.c_str(), fileName.length(), &data_.filename);
|
2015-11-16 23:20:34 +01:00
|
|
|
|
|
|
|
Changed();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefPostDataElementImpl::SetToBytes(size_t size, const void* bytes) {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-06-19 18:29:49 +02:00
|
|
|
CHECK_READONLY_RETURN_VOID();
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Clear any data currently in the element
|
2014-07-15 00:18:51 +02:00
|
|
|
Cleanup();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Assign the new data
|
|
|
|
void* data = malloc(size);
|
2020-01-15 14:36:24 +01:00
|
|
|
DCHECK(data != nullptr);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (data == nullptr) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
memcpy(data, bytes, size);
|
|
|
|
|
|
|
|
type_ = PDE_TYPE_BYTES;
|
|
|
|
data_.bytes.bytes = data;
|
|
|
|
data_.bytes.size = size;
|
2015-11-16 23:20:34 +01:00
|
|
|
|
|
|
|
Changed();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefPostDataElement::Type CefPostDataElementImpl::GetType() {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-04-03 03:34:16 +02:00
|
|
|
return type_;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefPostDataElementImpl::GetFile() {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-04-03 03:34:16 +02:00
|
|
|
DCHECK(type_ == PDE_TYPE_FILE);
|
|
|
|
CefString filename;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (type_ == PDE_TYPE_FILE) {
|
2012-04-03 03:34:16 +02:00
|
|
|
filename.FromString(data_.filename.str, data_.filename.length, false);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t CefPostDataElementImpl::GetBytesCount() {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-04-03 03:34:16 +02:00
|
|
|
DCHECK(type_ == PDE_TYPE_BYTES);
|
|
|
|
size_t size = 0;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (type_ == PDE_TYPE_BYTES) {
|
2012-04-03 03:34:16 +02:00
|
|
|
size = data_.bytes.size;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t CefPostDataElementImpl::GetBytes(size_t size, void* bytes) {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-04-03 03:34:16 +02:00
|
|
|
DCHECK(type_ == PDE_TYPE_BYTES);
|
|
|
|
size_t rv = 0;
|
|
|
|
if (type_ == PDE_TYPE_BYTES) {
|
|
|
|
rv = (size < data_.bytes.size ? size : data_.bytes.size);
|
|
|
|
memcpy(bytes, data_.bytes.bytes, rv);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2019-04-24 04:50:25 +02:00
|
|
|
void CefPostDataElementImpl::Set(const network::DataElement& element) {
|
|
|
|
{
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
CHECK_READONLY_RETURN_VOID();
|
|
|
|
}
|
|
|
|
|
2021-01-28 00:13:12 +01:00
|
|
|
if (element.type() == network::DataElement::Tag::kBytes) {
|
|
|
|
const auto& bytes_element = element.As<network::DataElementBytes>();
|
|
|
|
const auto& bytes = bytes_element.bytes();
|
|
|
|
SetToBytes(bytes.size(), bytes.data());
|
|
|
|
} else if (element.type() == network::DataElement::Tag::kFile) {
|
|
|
|
const auto& file_element = element.As<network::DataElementFile>();
|
|
|
|
SetToFile(file_element.path().value());
|
2019-04-24 04:50:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefPostDataElementImpl::Get(network::ResourceRequestBody& body) const {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
|
|
|
|
if (type_ == PDE_TYPE_BYTES) {
|
|
|
|
body.AppendBytes(static_cast<char*>(data_.bytes.bytes), data_.bytes.size);
|
|
|
|
} else if (type_ == PDE_TYPE_FILE) {
|
|
|
|
base::FilePath path = base::FilePath(CefString(&data_.filename));
|
|
|
|
body.AppendFileRange(path, 0, std::numeric_limits<uint64_t>::max(),
|
|
|
|
base::Time());
|
|
|
|
} else {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false);
|
2019-04-24 04:50:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
void CefPostDataElementImpl::SetReadOnly(bool read_only) {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (read_only_ == read_only) {
|
2012-06-19 18:29:49 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-06-19 18:29:49 +02:00
|
|
|
|
|
|
|
read_only_ = read_only;
|
|
|
|
}
|
|
|
|
|
2015-11-16 23:20:34 +01:00
|
|
|
void CefPostDataElementImpl::SetTrackChanges(bool track_changes) {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (track_changes_ == track_changes) {
|
2015-11-16 23:20:34 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-11-16 23:20:34 +01:00
|
|
|
|
|
|
|
track_changes_ = track_changes;
|
|
|
|
has_changes_ = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefPostDataElementImpl::HasChanges() const {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
return has_changes_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefPostDataElementImpl::Changed() {
|
|
|
|
lock_.AssertAcquired();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (track_changes_ && !has_changes_) {
|
2015-11-16 23:20:34 +01:00
|
|
|
has_changes_ = true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-11-16 23:20:34 +01:00
|
|
|
}
|
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
void CefPostDataElementImpl::Cleanup() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (type_ == PDE_TYPE_EMPTY) {
|
2012-06-19 18:29:49 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-06-19 18:29:49 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (type_ == PDE_TYPE_BYTES) {
|
2012-06-19 18:29:49 +02:00
|
|
|
free(data_.bytes.bytes);
|
2023-01-02 23:59:03 +01:00
|
|
|
} else if (type_ == PDE_TYPE_FILE) {
|
2012-06-19 18:29:49 +02:00
|
|
|
cef_string_clear(&data_.filename);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-06-19 18:29:49 +02:00
|
|
|
type_ = PDE_TYPE_EMPTY;
|
|
|
|
memset(&data_, 0, sizeof(data_));
|
|
|
|
}
|