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.
|
|
|
|
|
2017-11-17 17:33:50 +01:00
|
|
|
#include <algorithm>
|
2016-01-06 20:20:54 +01:00
|
|
|
#include <limits>
|
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>
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
#include "libcef/browser/navigate_params.h"
|
2015-12-01 19:22:28 +01:00
|
|
|
#include "libcef/common/cef_messages.h"
|
2015-11-26 03:53:12 +01:00
|
|
|
#include "libcef/common/net/http_header_utils.h"
|
|
|
|
#include "libcef/common/net/upload_data.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/common/request_impl.h"
|
|
|
|
|
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"
|
2015-12-01 19:22:28 +01:00
|
|
|
#include "base/strings/string_util.h"
|
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2015-10-09 17:23:12 +02:00
|
|
|
#include "components/navigation_interception/navigation_params.h"
|
2015-12-01 19:22:28 +01:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
2013-09-10 21:42:53 +02:00
|
|
|
#include "content/public/browser/resource_request_info.h"
|
2015-12-01 19:22:28 +01:00
|
|
|
#include "content/public/common/content_switches.h"
|
2014-09-04 19:53:40 +02:00
|
|
|
#include "content/public/common/resource_type.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"
|
|
|
|
#include "net/url_request/url_fetcher.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "net/url_request/url_request.h"
|
2013-06-22 04:06:32 +02:00
|
|
|
#include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h"
|
|
|
|
#include "third_party/WebKit/public/platform/WebString.h"
|
|
|
|
#include "third_party/WebKit/public/platform/WebURL.h"
|
|
|
|
#include "third_party/WebKit/public/platform/WebURLError.h"
|
|
|
|
#include "third_party/WebKit/public/platform/WebURLRequest.h"
|
2017-12-07 22:44:24 +01:00
|
|
|
#include "third_party/WebKit/public/platform/modules/fetch/fetch_api_request.mojom-shared.h"
|
2015-12-01 19:22:28 +01:00
|
|
|
#include "third_party/WebKit/public/web/WebSecurityPolicy.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-01-14 20:21:17 +01:00
|
|
|
namespace {
|
|
|
|
|
2015-12-01 19:22:28 +01:00
|
|
|
const char kReferrerLowerCase[] = "referer";
|
|
|
|
const char kContentTypeLowerCase[] = "content-type";
|
2017-11-17 17:33:50 +01:00
|
|
|
const char kCacheControlLowerCase[] = "cache-control";
|
|
|
|
const char kCacheControlDirectiveNoCacheLowerCase[] = "no-cache";
|
|
|
|
const char kCacheControlDirectiveOnlyIfCachedLowerCase[] = "only-if-cached";
|
2015-12-01 19:22:28 +01:00
|
|
|
const char kApplicationFormURLEncoded[] = "application/x-www-form-urlencoded";
|
|
|
|
|
2017-11-17 17:33:50 +01:00
|
|
|
// Mask of values that configure the cache policy.
|
|
|
|
const int kURCachePolicyMask = (UR_FLAG_SKIP_CACHE | UR_FLAG_ONLY_FROM_CACHE);
|
|
|
|
|
2013-01-14 20:21:17 +01:00
|
|
|
// A subclass of net::UploadBytesElementReader that keeps the associated
|
|
|
|
// UploadElement alive until the request completes.
|
|
|
|
class BytesElementReader : public net::UploadBytesElementReader {
|
|
|
|
public:
|
2016-04-27 22:38:52 +02:00
|
|
|
explicit BytesElementReader(std::unique_ptr<net::UploadElement> element)
|
2013-01-14 20:21:17 +01:00
|
|
|
: net::UploadBytesElementReader(element->bytes(),
|
|
|
|
element->bytes_length()),
|
2016-01-06 20:20:54 +01:00
|
|
|
element_(std::move(element)) {
|
2013-01-14 20:21:17 +01:00
|
|
|
DCHECK_EQ(net::UploadElement::TYPE_BYTES, element_->type());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<net::UploadElement> element_;
|
2013-01-14 20:21:17 +01:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(BytesElementReader);
|
|
|
|
};
|
|
|
|
|
2013-01-15 20:12:28 +01:00
|
|
|
base::TaskRunner* GetFileTaskRunner() {
|
2016-07-21 23:21:32 +02:00
|
|
|
return content::BrowserThread::GetTaskRunnerForThread(
|
2017-05-17 11:29:28 +02:00
|
|
|
content::BrowserThread::FILE)
|
|
|
|
.get();
|
2013-01-15 20:12:28 +01:00
|
|
|
}
|
|
|
|
|
2013-01-14 20:21:17 +01:00
|
|
|
// A subclass of net::UploadFileElementReader that keeps the associated
|
|
|
|
// UploadElement alive until the request completes.
|
|
|
|
class FileElementReader : public net::UploadFileElementReader {
|
|
|
|
public:
|
2016-04-27 22:38:52 +02:00
|
|
|
explicit FileElementReader(std::unique_ptr<net::UploadElement> element)
|
2013-01-14 20:21:17 +01:00
|
|
|
: net::UploadFileElementReader(
|
2013-01-15 20:12:28 +01:00
|
|
|
GetFileTaskRunner(),
|
2013-01-14 20:21:17 +01:00
|
|
|
element->file_path(),
|
|
|
|
element->file_range_offset(),
|
|
|
|
element->file_range_length(),
|
|
|
|
element->expected_file_modification_time()),
|
2016-01-06 20:20:54 +01:00
|
|
|
element_(std::move(element)) {
|
2013-01-14 20:21:17 +01:00
|
|
|
DCHECK_EQ(net::UploadElement::TYPE_FILE, element_->type());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<net::UploadElement> element_;
|
2013-01-14 20:21:17 +01:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(FileElementReader);
|
|
|
|
};
|
|
|
|
|
2016-10-28 20:15:26 +02:00
|
|
|
std::string GetURLRequestReferrer(const GURL& referrer_url) {
|
2015-12-01 19:22:28 +01:00
|
|
|
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
2016-10-28 20:15:26 +02:00
|
|
|
if (!referrer_url.is_valid() ||
|
2015-12-01 19:22:28 +01:00
|
|
|
command_line->HasSwitch(switches::kNoReferrers)) {
|
|
|
|
return std::string();
|
|
|
|
}
|
|
|
|
|
2016-10-28 20:15:26 +02:00
|
|
|
return referrer_url.spec();
|
2015-12-01 19:22:28 +01:00
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
if (base::LowerCaseEqualsASCII(it->first.ToString(),
|
|
|
|
kCacheControlLowerCase)) {
|
|
|
|
line = it->second;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int flags = 0;
|
|
|
|
|
|
|
|
if (!line.empty()) {
|
|
|
|
std::transform(line.begin(), line.end(), line.begin(), ::tolower);
|
|
|
|
|
|
|
|
std::vector<base::StringPiece> pieces = base::SplitStringPiece(
|
|
|
|
line, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
|
|
|
|
for (const auto& piece : pieces) {
|
|
|
|
if (base::LowerCaseEqualsASCII(piece,
|
|
|
|
kCacheControlDirectiveNoCacheLowerCase)) {
|
|
|
|
flags |= UR_FLAG_SKIP_CACHE;
|
|
|
|
} else if (base::LowerCaseEqualsASCII(
|
|
|
|
piece, kCacheControlDirectiveOnlyIfCachedLowerCase)) {
|
|
|
|
flags |= UR_FLAG_ONLY_FROM_CACHE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2017-11-17 17:33:50 +01:00
|
|
|
if ((ur_flags & kURCachePolicyMask) == kURCachePolicyMask) {
|
2017-12-07 22:44:24 +01:00
|
|
|
return blink::mojom::FetchCacheMode::kUnspecifiedForceCacheMiss;
|
2017-11-17 17:33:50 +01:00
|
|
|
} else if (ur_flags & UR_FLAG_SKIP_CACHE) {
|
2017-12-07 22:44:24 +01:00
|
|
|
return blink::mojom::FetchCacheMode::kBypassCache;
|
2017-11-17 17:33:50 +01:00
|
|
|
} else if (ur_flags & UR_FLAG_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
|
|
|
}
|
|
|
|
|
|
|
|
// Convert blink::WebCachePolicy to cef_urlrequest_flags_t.
|
2017-12-07 22:44:24 +01:00
|
|
|
int GetURCachePolicy(blink::mojom::FetchCacheMode cache_mode) {
|
|
|
|
if (cache_mode == blink::mojom::FetchCacheMode::kUnspecifiedForceCacheMiss) {
|
2017-11-17 17:33:50 +01:00
|
|
|
return kURCachePolicyMask;
|
2017-12-07 22:44:24 +01:00
|
|
|
} else if (cache_mode == blink::mojom::FetchCacheMode::kBypassCache) {
|
2017-11-17 17:33:50 +01:00
|
|
|
return UR_FLAG_SKIP_CACHE;
|
2017-12-07 22:44:24 +01:00
|
|
|
} else if (cache_mode == blink::mojom::FetchCacheMode::kOnlyIfCached) {
|
2017-11-17 17:33:50 +01:00
|
|
|
return UR_FLAG_ONLY_FROM_CACHE;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-12-01 19:22:28 +01:00
|
|
|
blink::WebString FilePathStringToWebString(
|
|
|
|
const base::FilePath::StringType& str) {
|
|
|
|
#if defined(OS_POSIX)
|
2017-04-20 21:28:17 +02:00
|
|
|
return blink::WebString::FromUTF8(str);
|
2015-12-01 19:22:28 +01:00
|
|
|
#elif defined(OS_WIN)
|
2017-04-20 21:28:17 +02:00
|
|
|
return blink::WebString::FromUTF16(str);
|
2015-12-01 19:22:28 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read |headers| into |map|.
|
|
|
|
void GetHeaderMap(const net::HttpRequestHeaders& headers,
|
|
|
|
CefRequest::HeaderMap& map) {
|
2016-03-02 00:59:53 +01:00
|
|
|
map.clear();
|
|
|
|
|
2015-12-01 19:22:28 +01:00
|
|
|
if (headers.IsEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
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.
|
|
|
|
if (!base::LowerCaseEqualsASCII(name, kReferrerLowerCase))
|
|
|
|
map.insert(std::make_pair(name, it.value()));
|
2016-03-02 00:59:53 +01:00
|
|
|
};
|
2015-12-01 19:22:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Read |request| into |map|. If a Referer value is specified populate
|
|
|
|
// |referrer|.
|
|
|
|
void GetHeaderMap(const blink::WebURLRequest& request,
|
|
|
|
CefRequest::HeaderMap& map,
|
2016-10-28 20:15:26 +02:00
|
|
|
GURL& referrer) {
|
2016-03-02 00:59:53 +01:00
|
|
|
map.clear();
|
|
|
|
|
2015-12-01 19:22:28 +01:00
|
|
|
class HeaderVisitor : public blink::WebHTTPHeaderVisitor {
|
|
|
|
public:
|
2016-10-28 20:15:26 +02:00
|
|
|
HeaderVisitor(CefRequest::HeaderMap* map, GURL* referrer)
|
2017-05-17 11:29:28 +02:00
|
|
|
: map_(map), referrer_(referrer) {}
|
2015-12-01 19:22:28 +01:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
void VisitHeader(const blink::WebString& name,
|
2015-12-01 19:22:28 +01:00
|
|
|
const blink::WebString& value) override {
|
2017-04-20 21:28:17 +02:00
|
|
|
const base::string16& nameStr = name.Utf16();
|
|
|
|
const base::string16& valueStr = value.Utf16();
|
2015-12-01 19:22:28 +01:00
|
|
|
if (base::LowerCaseEqualsASCII(nameStr, kReferrerLowerCase))
|
2016-10-28 20:15:26 +02:00
|
|
|
*referrer_ = GURL(valueStr);
|
2015-12-01 19:22:28 +01:00
|
|
|
else
|
|
|
|
map_->insert(std::make_pair(nameStr, valueStr));
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
CefRequest::HeaderMap* map_;
|
2016-10-28 20:15:26 +02:00
|
|
|
GURL* referrer_;
|
2015-12-01 19:22:28 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
HeaderVisitor visitor(&map, &referrer);
|
2017-04-20 21:28:17 +02:00
|
|
|
request.VisitHTTPHeaderFields(&visitor);
|
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.
|
|
|
|
if (!base::LowerCaseEqualsASCII(name.ToString(), kReferrerLowerCase))
|
|
|
|
map.insert(std::make_pair(name, it->second));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read |map| into |request|.
|
|
|
|
void SetHeaderMap(const CefRequest::HeaderMap& map,
|
|
|
|
blink::WebURLRequest& request) {
|
|
|
|
CefRequest::HeaderMap::const_iterator it = map.begin();
|
|
|
|
for (; it != map.end(); ++it) {
|
2017-04-20 21:28:17 +02:00
|
|
|
request.SetHTTPHeaderField(blink::WebString::FromUTF16(it->first),
|
|
|
|
blink::WebString::FromUTF16(it->second));
|
2015-12-01 19:22:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-09 17:10:16 +01:00
|
|
|
// Type used in UploadDataStream.
|
2017-05-17 11:29:28 +02:00
|
|
|
typedef std::vector<std::unique_ptr<net::UploadElementReader>>
|
|
|
|
UploadElementReaders;
|
2015-12-09 17:10:16 +01:00
|
|
|
|
2013-01-14 20:21:17 +01:00
|
|
|
} // namespace
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
#define CHECK_READONLY_RETURN(val) \
|
|
|
|
if (read_only_) { \
|
2012-06-19 18:29:49 +02:00
|
|
|
NOTREACHED() << "object is read only"; \
|
2017-05-17 11:29:28 +02:00
|
|
|
return val; \
|
2012-06-19 18:29:49 +02:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
#define CHECK_READONLY_RETURN_VOID() \
|
|
|
|
if (read_only_) { \
|
2012-06-19 18:29:49 +02:00
|
|
|
NOTREACHED() << "object is read only"; \
|
2017-05-17 11:29:28 +02:00
|
|
|
return; \
|
2012-06-19 18:29:49 +02:00
|
|
|
}
|
|
|
|
|
2015-12-01 19:22:28 +01:00
|
|
|
#define SETBOOLFLAG(obj, flags, method, FLAG) \
|
2017-05-17 11:29:28 +02:00
|
|
|
obj.method((flags & (FLAG)) == (FLAG))
|
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 -------------------------------------------------------------
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRequestImpl::CefRequestImpl() : read_only_(false), track_changes_(false) {
|
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) ==
|
|
|
|
static_cast<int>(net::URLRequest::MAX_REFERRER_POLICY),
|
|
|
|
"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) {
|
|
|
|
url_ = new_url;
|
2015-11-16 23:20:34 +01:00
|
|
|
Changed(kChangedUrl);
|
|
|
|
}
|
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) {
|
|
|
|
method_ = new_method;
|
2015-11-16 23:20:34 +01:00
|
|
|
Changed(kChangedMethod);
|
|
|
|
}
|
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();
|
|
|
|
|
|
|
|
// Call GetAsReferrer here for consistency since the same logic will later be
|
|
|
|
// applied by URLRequest::SetReferrer().
|
2016-10-28 20:15:26 +02:00
|
|
|
const GURL& new_referrer_url = GURL(referrer_url.ToString()).GetAsReferrer();
|
|
|
|
if (referrer_url_ != new_referrer_url || referrer_policy_ != policy) {
|
|
|
|
referrer_url_ = new_referrer_url;
|
2015-12-01 19:22:28 +01:00
|
|
|
referrer_policy_ = policy;
|
|
|
|
Changed(kChangedReferrer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2012-04-03 03:34:16 +02:00
|
|
|
postdata_ = postData;
|
2015-11-16 23:20:34 +01:00
|
|
|
Changed(kChangedPostData);
|
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();
|
2015-12-01 19:22:28 +01:00
|
|
|
::GetHeaderMap(headerMap, headermap_);
|
2015-11-16 23:20:34 +01:00
|
|
|
Changed(kChangedHeaderMap);
|
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) {
|
|
|
|
url_ = new_url;
|
2015-11-16 23:20:34 +01:00
|
|
|
Changed(kChangedUrl);
|
|
|
|
}
|
2016-10-28 20:15:26 +02:00
|
|
|
const std::string& new_method = method;
|
|
|
|
if (method_ != new_method) {
|
|
|
|
method_ = new_method;
|
2015-11-16 23:20:34 +01:00
|
|
|
Changed(kChangedMethod);
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
postdata_ = postData;
|
2015-12-01 19:22:28 +01:00
|
|
|
::GetHeaderMap(headerMap, headermap_);
|
2015-11-16 23:20:34 +01:00
|
|
|
Changed(kChangedPostData | kChangedHeaderMap);
|
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) {
|
|
|
|
flags_ = flags;
|
|
|
|
Changed(kChangedFlags);
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefRequestImpl::GetFirstPartyForCookies() {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2017-09-06 23:40:58 +02:00
|
|
|
return site_for_cookies_.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();
|
2016-10-28 20:15:26 +02:00
|
|
|
const GURL& new_url = GURL(url.ToString());
|
2017-09-06 23:40:58 +02:00
|
|
|
if (site_for_cookies_ != new_url) {
|
|
|
|
site_for_cookies_ = new_url;
|
2015-11-16 23:20:34 +01:00
|
|
|
Changed(kChangedFirstPartyForCookies);
|
|
|
|
}
|
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_;
|
|
|
|
}
|
|
|
|
|
2015-03-11 19:44:11 +01:00
|
|
|
uint64 CefRequestImpl::GetIdentifier() {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
return identifier_;
|
|
|
|
}
|
|
|
|
|
2018-02-06 01:21:14 +01:00
|
|
|
void CefRequestImpl::Set(const net::URLRequest* request) {
|
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
|
|
|
|
2015-10-09 17:23:12 +02:00
|
|
|
Reset();
|
|
|
|
|
2016-10-28 20:15:26 +02:00
|
|
|
url_ = request->url();
|
2012-04-03 03:34:16 +02:00
|
|
|
method_ = request->method();
|
2015-03-11 19:44:11 +01:00
|
|
|
identifier_ = request->identifier();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-04-16 00:16:01 +02:00
|
|
|
// URLRequest::SetReferrer ensures that we do not send username and password
|
|
|
|
// fields in the referrer.
|
|
|
|
GURL referrer(request->referrer());
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-12-01 19:22:28 +01:00
|
|
|
// Our consumer should have made sure that this is a safe referrer. See for
|
2012-04-03 03:34:16 +02:00
|
|
|
// instance WebCore::FrameLoader::HideReferrer.
|
2015-12-01 19:22:28 +01:00
|
|
|
if (referrer.is_valid()) {
|
2016-10-28 20:15:26 +02:00
|
|
|
referrer_url_ = referrer;
|
2017-07-27 01:19:27 +02:00
|
|
|
referrer_policy_ =
|
|
|
|
static_cast<cef_referrer_policy_t>(request->referrer_policy());
|
2015-12-01 19:22:28 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-12-01 19:22:28 +01:00
|
|
|
// Transfer request headers.
|
|
|
|
::GetHeaderMap(request->extra_request_headers(), headermap_);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-12-01 19:22:28 +01:00
|
|
|
// Transfer post data, if any.
|
2012-11-30 20:08:20 +01:00
|
|
|
const net::UploadDataStream* data = request->get_upload();
|
2012-04-03 03:34:16 +02:00
|
|
|
if (data) {
|
2012-06-19 18:29:49 +02:00
|
|
|
postdata_ = CefPostData::Create();
|
2012-04-03 03:34:16 +02:00
|
|
|
static_cast<CefPostDataImpl*>(postdata_.get())->Set(*data);
|
|
|
|
}
|
2013-09-10 21:42:53 +02:00
|
|
|
|
2017-09-06 23:40:58 +02:00
|
|
|
site_for_cookies_ = request->site_for_cookies();
|
2015-12-01 19:22:28 +01:00
|
|
|
|
2013-09-10 21:42:53 +02:00
|
|
|
const content::ResourceRequestInfo* info =
|
|
|
|
content::ResourceRequestInfo::ForRequest(request);
|
|
|
|
if (info) {
|
2017-05-17 11:29:28 +02:00
|
|
|
resource_type_ = static_cast<cef_resource_type_t>(info->GetResourceType());
|
2013-09-10 21:42:53 +02:00
|
|
|
transition_type_ =
|
|
|
|
static_cast<cef_transition_type_t>(info->GetPageTransition());
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2015-11-16 23:20:34 +01:00
|
|
|
void CefRequestImpl::Get(net::URLRequest* request, bool changed_only) const {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-11-16 23:20:34 +01:00
|
|
|
if (ShouldSet(kChangedMethod, changed_only))
|
|
|
|
request->set_method(method_);
|
|
|
|
|
2015-12-01 19:22:28 +01:00
|
|
|
if (ShouldSet(kChangedReferrer, changed_only)) {
|
|
|
|
request->SetReferrer(GetURLRequestReferrer(referrer_url_));
|
2017-07-27 01:19:27 +02:00
|
|
|
request->set_referrer_policy(
|
|
|
|
static_cast<net::URLRequest::ReferrerPolicy>(referrer_policy_));
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2015-11-16 23:20:34 +01:00
|
|
|
if (ShouldSet(kChangedHeaderMap, changed_only)) {
|
|
|
|
net::HttpRequestHeaders headers;
|
2015-12-01 19:22:28 +01:00
|
|
|
headers.AddHeadersFromString(HttpHeaderUtils::GenerateHeaders(headermap_));
|
2015-11-16 23:20:34 +01:00
|
|
|
request->SetExtraRequestHeaders(headers);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2015-11-16 23:20:34 +01:00
|
|
|
if (ShouldSet(kChangedPostData, changed_only)) {
|
|
|
|
if (postdata_.get()) {
|
2017-04-20 21:28:17 +02:00
|
|
|
request->set_upload(
|
|
|
|
static_cast<CefPostDataImpl*>(postdata_.get())->Get());
|
2015-11-16 23:20:34 +01:00
|
|
|
} else if (request->get_upload()) {
|
2016-04-27 22:38:52 +02:00
|
|
|
request->set_upload(std::unique_ptr<net::UploadDataStream>());
|
2015-11-16 23:20:34 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2015-12-01 19:22:28 +01:00
|
|
|
|
2017-09-06 23:40:58 +02:00
|
|
|
if (!site_for_cookies_.is_empty() &&
|
2015-12-01 19:22:28 +01:00
|
|
|
ShouldSet(kChangedFirstPartyForCookies, changed_only)) {
|
2017-09-06 23:40:58 +02:00
|
|
|
request->set_site_for_cookies(site_for_cookies_);
|
2015-12-01 19:22:28 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2015-10-09 17:23:12 +02:00
|
|
|
void CefRequestImpl::Set(
|
|
|
|
const navigation_interception::NavigationParams& params,
|
|
|
|
bool is_main_frame) {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
CHECK_READONLY_RETURN_VOID();
|
|
|
|
|
|
|
|
Reset();
|
|
|
|
|
2016-10-28 20:15:26 +02:00
|
|
|
url_ = params.url();
|
2015-10-09 17:23:12 +02:00
|
|
|
method_ = params.is_post() ? "POST" : "GET";
|
|
|
|
|
|
|
|
const content::Referrer& sanitized_referrer =
|
|
|
|
content::Referrer::SanitizeForRequest(params.url(), params.referrer());
|
2016-10-28 20:15:26 +02:00
|
|
|
referrer_url_ = sanitized_referrer.url;
|
2015-12-01 19:22:28 +01:00
|
|
|
referrer_policy_ =
|
2017-07-27 01:19:27 +02:00
|
|
|
BlinkReferrerPolicyToNetReferrerPolicy(sanitized_referrer.policy);
|
2015-10-09 17:23:12 +02:00
|
|
|
|
|
|
|
resource_type_ = is_main_frame ? RT_MAIN_FRAME : RT_SUB_FRAME;
|
|
|
|
transition_type_ =
|
|
|
|
static_cast<cef_transition_type_t>(params.transition_type());
|
|
|
|
}
|
|
|
|
|
2013-11-08 22:28:56 +01:00
|
|
|
void CefRequestImpl::Set(const blink::WebURLRequest& request) {
|
2017-04-20 21:28:17 +02:00
|
|
|
DCHECK(!request.IsNull());
|
2012-06-19 18:29:49 +02:00
|
|
|
|
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-10-09 17:23:12 +02:00
|
|
|
Reset();
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
url_ = request.Url();
|
|
|
|
method_ = request.HttpMethod().Utf8();
|
2012-06-19 18:29:49 +02:00
|
|
|
|
2015-12-01 19:22:28 +01:00
|
|
|
::GetHeaderMap(request, headermap_, referrer_url_);
|
|
|
|
referrer_policy_ =
|
2017-07-27 01:19:27 +02:00
|
|
|
BlinkReferrerPolicyToNetReferrerPolicy(request.GetReferrerPolicy());
|
2015-12-01 19:22:28 +01:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
const blink::WebHTTPBody& body = request.HttpBody();
|
|
|
|
if (!body.IsNull()) {
|
2012-06-19 18:29:49 +02:00
|
|
|
postdata_ = new CefPostDataImpl();
|
|
|
|
static_cast<CefPostDataImpl*>(postdata_.get())->Set(body);
|
|
|
|
}
|
|
|
|
|
2017-09-06 23:40:58 +02:00
|
|
|
site_for_cookies_ = request.SiteForCookies();
|
2012-06-19 18:29:49 +02:00
|
|
|
|
2017-12-07 22:44:24 +01:00
|
|
|
flags_ |= GetURCachePolicy(request.GetCacheMode());
|
2017-04-20 21:28:17 +02:00
|
|
|
if (request.AllowStoredCredentials())
|
2017-11-17 17:33:50 +01:00
|
|
|
flags_ |= UR_FLAG_ALLOW_STORED_CREDENTIALS;
|
2017-04-20 21:28:17 +02:00
|
|
|
if (request.ReportUploadProgress())
|
2012-06-19 18:29:49 +02:00
|
|
|
flags_ |= UR_FLAG_REPORT_UPLOAD_PROGRESS;
|
|
|
|
}
|
|
|
|
|
2015-11-16 23:20:34 +01:00
|
|
|
void CefRequestImpl::Get(blink::WebURLRequest& request,
|
2015-12-01 19:22:28 +01:00
|
|
|
int64& upload_data_size) const {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-06-19 18:29:49 +02:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
request.SetRequestContext(blink::WebURLRequest::kRequestContextInternal);
|
|
|
|
request.SetURL(url_);
|
|
|
|
request.SetHTTPMethod(blink::WebString::FromUTF8(method_));
|
2015-12-01 19:22:28 +01:00
|
|
|
|
2016-10-28 20:15:26 +02:00
|
|
|
if (!referrer_url_.is_empty()) {
|
2015-12-01 19:22:28 +01:00
|
|
|
const blink::WebString& referrer =
|
2017-04-20 21:28:17 +02:00
|
|
|
blink::WebSecurityPolicy::GenerateReferrerHeader(
|
2017-07-27 01:19:27 +02:00
|
|
|
NetReferrerPolicyToBlinkReferrerPolicy(referrer_policy_), url_,
|
2017-04-20 21:28:17 +02:00
|
|
|
blink::WebString::FromUTF8(referrer_url_.spec()));
|
|
|
|
if (!referrer.IsEmpty()) {
|
|
|
|
request.SetHTTPReferrer(
|
2017-07-27 01:19:27 +02:00
|
|
|
referrer, NetReferrerPolicyToBlinkReferrerPolicy(referrer_policy_));
|
2015-12-01 19:22:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (postdata_.get()) {
|
|
|
|
blink::WebHTTPBody body;
|
2017-04-20 21:28:17 +02:00
|
|
|
body.Initialize();
|
2015-12-01 19:22:28 +01:00
|
|
|
static_cast<CefPostDataImpl*>(postdata_.get())->Get(body);
|
2017-04-20 21:28:17 +02:00
|
|
|
request.SetHTTPBody(body);
|
2015-12-01 19:22:28 +01:00
|
|
|
|
|
|
|
if (flags_ & UR_FLAG_REPORT_UPLOAD_PROGRESS) {
|
|
|
|
// Attempt to determine the upload data size.
|
|
|
|
CefPostData::ElementVector elements;
|
|
|
|
postdata_->GetElements(elements);
|
|
|
|
if (elements.size() == 1 && elements[0]->GetType() == PDE_TYPE_BYTES) {
|
|
|
|
CefPostDataElementImpl* impl =
|
|
|
|
static_cast<CefPostDataElementImpl*>(elements[0].get());
|
|
|
|
upload_data_size = impl->GetBytesCount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
::SetHeaderMap(headermap_, request);
|
|
|
|
|
2017-09-06 23:40:58 +02:00
|
|
|
if (!site_for_cookies_.is_empty())
|
|
|
|
request.SetSiteForCookies(site_for_cookies_);
|
2015-12-01 19:22:28 +01:00
|
|
|
|
2017-11-17 17:33:50 +01:00
|
|
|
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_);
|
|
|
|
}
|
2017-12-07 22:44:24 +01:00
|
|
|
request.SetCacheMode(GetFetchCacheMode(flags));
|
2015-12-01 19:22:28 +01:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
SETBOOLFLAG(request, flags_, SetAllowStoredCredentials,
|
2017-11-17 17:33:50 +01:00
|
|
|
UR_FLAG_ALLOW_STORED_CREDENTIALS);
|
2017-04-20 21:28:17 +02:00
|
|
|
SETBOOLFLAG(request, flags_, SetReportUploadProgress,
|
2015-12-01 19:22:28 +01:00
|
|
|
UR_FLAG_REPORT_UPLOAD_PROGRESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void CefRequestImpl::Get(const CefMsg_LoadRequest_Params& params,
|
|
|
|
blink::WebURLRequest& request) {
|
2017-04-20 21:28:17 +02:00
|
|
|
request.SetURL(params.url);
|
2015-12-01 19:22:28 +01:00
|
|
|
if (!params.method.empty())
|
2017-04-20 21:28:17 +02:00
|
|
|
request.SetHTTPMethod(blink::WebString::FromASCII(params.method));
|
2015-12-01 19:22:28 +01:00
|
|
|
|
|
|
|
if (params.referrer.is_valid()) {
|
|
|
|
const blink::WebString& referrer =
|
2017-04-20 21:28:17 +02:00
|
|
|
blink::WebSecurityPolicy::GenerateReferrerHeader(
|
2017-07-27 01:19:27 +02:00
|
|
|
NetReferrerPolicyToBlinkReferrerPolicy(
|
|
|
|
static_cast<cef_referrer_policy_t>(params.referrer_policy)),
|
2017-05-17 11:29:28 +02:00
|
|
|
params.url, blink::WebString::FromUTF8(params.referrer.spec()));
|
2017-04-20 21:28:17 +02:00
|
|
|
if (!referrer.IsEmpty()) {
|
2017-07-27 01:19:27 +02:00
|
|
|
request.SetHTTPReferrer(
|
|
|
|
referrer,
|
|
|
|
NetReferrerPolicyToBlinkReferrerPolicy(
|
|
|
|
static_cast<cef_referrer_policy_t>(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;
|
2015-12-01 19:22:28 +01:00
|
|
|
if (!params.headers.empty()) {
|
|
|
|
for (net::HttpUtil::HeadersIterator i(params.headers.begin(),
|
|
|
|
params.headers.end(), "\n");
|
2017-05-17 11:29:28 +02:00
|
|
|
i.GetNext();) {
|
2017-04-20 21:28:17 +02:00
|
|
|
request.AddHTTPHeaderField(blink::WebString::FromUTF8(i.name()),
|
|
|
|
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
|
|
|
|
2015-12-01 19:22:28 +01:00
|
|
|
if (params.upload_data.get()) {
|
2017-04-20 21:28:17 +02:00
|
|
|
const base::string16& method = request.HttpMethod().Utf16();
|
2015-12-01 19:22:28 +01:00
|
|
|
if (method == base::ASCIIToUTF16("GET") ||
|
|
|
|
method == base::ASCIIToUTF16("HEAD")) {
|
2017-04-20 21:28:17 +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) {
|
2017-04-20 21:28:17 +02:00
|
|
|
request.SetHTTPHeaderField(
|
|
|
|
blink::WebString::FromASCII(net::HttpRequestHeaders::kContentType),
|
|
|
|
blink::WebString::FromASCII(kApplicationFormURLEncoded));
|
2015-12-01 19:22:28 +01:00
|
|
|
}
|
|
|
|
|
2015-11-16 23:20:34 +01:00
|
|
|
blink::WebHTTPBody body;
|
2017-04-20 21:28:17 +02:00
|
|
|
body.Initialize();
|
|
|
|
|
|
|
|
for (const auto& element : params.upload_data->elements()) {
|
|
|
|
if (element->type() == net::UploadElement::TYPE_BYTES) {
|
2015-12-01 19:22:28 +01:00
|
|
|
blink::WebData data;
|
2017-04-20 21:28:17 +02:00
|
|
|
data.Assign(element->bytes(), element->bytes_length());
|
|
|
|
body.AppendData(data);
|
|
|
|
} else if (element->type() == net::UploadElement::TYPE_FILE) {
|
2017-05-17 11:29:28 +02:00
|
|
|
body.AppendFile(
|
|
|
|
FilePathStringToWebString(element->file_path().value()));
|
2015-12-01 19:22:28 +01:00
|
|
|
} else {
|
|
|
|
NOTREACHED();
|
|
|
|
}
|
2015-11-16 23:20:34 +01:00
|
|
|
}
|
2015-12-01 19:22:28 +01:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
request.SetHTTPBody(body);
|
2012-06-19 18:29:49 +02:00
|
|
|
}
|
|
|
|
|
2017-09-06 23:40:58 +02:00
|
|
|
if (params.site_for_cookies.is_valid())
|
|
|
|
request.SetSiteForCookies(params.site_for_cookies);
|
2015-12-01 19:22:28 +01:00
|
|
|
|
2017-11-17 17:33:50 +01:00
|
|
|
int flags = params.load_flags;
|
|
|
|
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
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
SETBOOLFLAG(request, params.load_flags, SetAllowStoredCredentials,
|
2017-11-17 17:33:50 +01:00
|
|
|
UR_FLAG_ALLOW_STORED_CREDENTIALS);
|
2017-04-20 21:28:17 +02:00
|
|
|
SETBOOLFLAG(request, params.load_flags, SetReportUploadProgress,
|
2015-12-01 19:22:28 +01:00
|
|
|
UR_FLAG_REPORT_UPLOAD_PROGRESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestImpl::Get(CefNavigateParams& params) const {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-06-19 18:29:49 +02:00
|
|
|
|
2016-10-28 20:15:26 +02:00
|
|
|
params.url = url_;
|
2015-12-01 19:22:28 +01:00
|
|
|
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.
|
2016-10-28 20:15:26 +02:00
|
|
|
params.referrer.url = referrer_url_;
|
2015-12-01 19:22:28 +01:00
|
|
|
params.referrer.policy =
|
2017-07-27 01:19:27 +02:00
|
|
|
NetReferrerPolicyToBlinkReferrerPolicy(referrer_policy_);
|
2012-06-19 18:29:49 +02:00
|
|
|
|
2015-12-01 19:22:28 +01:00
|
|
|
if (!headermap_.empty())
|
|
|
|
params.headers = HttpHeaderUtils::GenerateHeaders(headermap_);
|
|
|
|
|
|
|
|
if (postdata_) {
|
|
|
|
CefPostDataImpl* impl = static_cast<CefPostDataImpl*>(postdata_.get());
|
|
|
|
params.upload_data = new net::UploadData();
|
|
|
|
impl->Get(*params.upload_data.get());
|
2015-11-16 23:20:34 +01:00
|
|
|
}
|
2012-06-19 18:29:49 +02:00
|
|
|
|
2017-09-06 23:40:58 +02:00
|
|
|
params.site_for_cookies = site_for_cookies_;
|
2015-12-01 19:22:28 +01:00
|
|
|
params.load_flags = flags_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestImpl::Get(net::URLFetcher& fetcher,
|
|
|
|
int64& upload_data_size) const {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
|
2016-10-28 20:15:26 +02:00
|
|
|
if (!referrer_url_.is_empty()) {
|
2015-12-01 19:22:28 +01:00
|
|
|
fetcher.SetReferrer(GetURLRequestReferrer(referrer_url_));
|
2017-07-27 01:19:27 +02:00
|
|
|
fetcher.SetReferrerPolicy(
|
|
|
|
static_cast<net::URLRequest::ReferrerPolicy>(referrer_policy_));
|
2015-12-01 19:22:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRequest::HeaderMap headerMap = headermap_;
|
|
|
|
|
|
|
|
std::string content_type;
|
|
|
|
|
|
|
|
// Extract the Content-Type header value.
|
|
|
|
{
|
|
|
|
HeaderMap::iterator it = headerMap.begin();
|
|
|
|
for (; it != headerMap.end(); ++it) {
|
|
|
|
if (base::LowerCaseEqualsASCII(it->first.ToString(),
|
|
|
|
kContentTypeLowerCase)) {
|
|
|
|
content_type = it->second;
|
|
|
|
headerMap.erase(it);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
fetcher.SetExtraRequestHeaders(HttpHeaderUtils::GenerateHeaders(headerMap));
|
2015-12-01 19:22:28 +01:00
|
|
|
|
|
|
|
if (postdata_.get()) {
|
|
|
|
CefPostData::ElementVector elements;
|
|
|
|
postdata_->GetElements(elements);
|
|
|
|
if (elements.size() == 1) {
|
|
|
|
// Default to URL encoding if not specified.
|
|
|
|
if (content_type.empty())
|
|
|
|
content_type = kApplicationFormURLEncoded;
|
|
|
|
|
|
|
|
CefPostDataElementImpl* impl =
|
|
|
|
static_cast<CefPostDataElementImpl*>(elements[0].get());
|
|
|
|
|
|
|
|
switch (elements[0]->GetType()) {
|
|
|
|
case PDE_TYPE_BYTES: {
|
|
|
|
const size_t size = impl->GetBytesCount();
|
|
|
|
if (flags_ & UR_FLAG_REPORT_UPLOAD_PROGRESS) {
|
|
|
|
// Return the upload data size.
|
|
|
|
upload_data_size = size;
|
|
|
|
}
|
|
|
|
fetcher.SetUploadData(
|
|
|
|
content_type,
|
|
|
|
std::string(static_cast<char*>(impl->GetBytes()), size));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PDE_TYPE_FILE:
|
|
|
|
fetcher.SetUploadFilePath(
|
2017-05-17 11:29:28 +02:00
|
|
|
content_type, base::FilePath(impl->GetFile()), 0,
|
|
|
|
std::numeric_limits<uint64_t>::max(), GetFileTaskRunner());
|
2015-12-01 19:22:28 +01:00
|
|
|
break;
|
|
|
|
case PDE_TYPE_EMPTY:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (elements.size() > 1) {
|
|
|
|
NOTIMPLEMENTED() << " multi-part form data is not supported";
|
|
|
|
}
|
2012-06-19 18:29:49 +02:00
|
|
|
}
|
2015-12-01 19:22:28 +01:00
|
|
|
|
2017-09-06 23:40:58 +02:00
|
|
|
if (!site_for_cookies_.is_empty())
|
2017-12-07 22:44:24 +01:00
|
|
|
fetcher.SetInitiator(url::Origin::Create(site_for_cookies_));
|
2015-12-01 19:22:28 +01:00
|
|
|
|
2017-11-17 17:33:50 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & UR_FLAG_NO_RETRY_ON_5XX)
|
2015-12-01 19:22:28 +01:00
|
|
|
fetcher.SetAutomaticallyRetryOn5xx(false);
|
|
|
|
|
2017-11-17 17:33:50 +01:00
|
|
|
int net_flags = 0;
|
2015-12-01 19:22:28 +01:00
|
|
|
|
2017-11-17 17:33:50 +01:00
|
|
|
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;
|
|
|
|
}
|
2015-12-01 19:22:28 +01:00
|
|
|
|
2017-11-17 17:33:50 +01:00
|
|
|
if (!(flags & UR_FLAG_ALLOW_STORED_CREDENTIALS)) {
|
|
|
|
net_flags |= net::LOAD_DO_NOT_SEND_AUTH_DATA |
|
|
|
|
net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES;
|
2015-12-01 19:22:28 +01:00
|
|
|
}
|
|
|
|
|
2017-11-17 17:33:50 +01:00
|
|
|
fetcher.SetLoadFlags(net_flags);
|
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_);
|
2012-06-19 18:29:49 +02:00
|
|
|
if (read_only_ == read_only)
|
|
|
|
return;
|
|
|
|
|
|
|
|
read_only_ = read_only;
|
|
|
|
|
|
|
|
if (postdata_.get())
|
|
|
|
static_cast<CefPostDataImpl*>(postdata_.get())->SetReadOnly(read_only);
|
|
|
|
}
|
|
|
|
|
2015-11-16 23:20:34 +01:00
|
|
|
void CefRequestImpl::SetTrackChanges(bool track_changes) {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
if (track_changes_ == track_changes)
|
|
|
|
return;
|
|
|
|
|
|
|
|
track_changes_ = track_changes;
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
blink::WebReferrerPolicy CefRequestImpl::NetReferrerPolicyToBlinkReferrerPolicy(
|
|
|
|
cef_referrer_policy_t net_policy) {
|
|
|
|
switch (net_policy) {
|
|
|
|
case REFERRER_POLICY_CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE:
|
|
|
|
return blink::kWebReferrerPolicyNoReferrerWhenDowngrade;
|
|
|
|
case REFERRER_POLICY_REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN:
|
|
|
|
return blink::
|
|
|
|
kWebReferrerPolicyNoReferrerWhenDowngradeOriginWhenCrossOrigin;
|
|
|
|
case REFERRER_POLICY_ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN:
|
|
|
|
return blink::kWebReferrerPolicyOriginWhenCrossOrigin;
|
|
|
|
case REFERRER_POLICY_NEVER_CLEAR_REFERRER:
|
|
|
|
return blink::kWebReferrerPolicyAlways;
|
|
|
|
case REFERRER_POLICY_ORIGIN:
|
|
|
|
return blink::kWebReferrerPolicyOrigin;
|
|
|
|
case REFERRER_POLICY_CLEAR_REFERRER_ON_TRANSITION_CROSS_ORIGIN:
|
|
|
|
return blink::kWebReferrerPolicySameOrigin;
|
|
|
|
case REFERRER_POLICY_ORIGIN_CLEAR_ON_TRANSITION_FROM_SECURE_TO_INSECURE:
|
|
|
|
return blink::kWebReferrerPolicyStrictOrigin;
|
|
|
|
case REFERRER_POLICY_NO_REFERRER:
|
|
|
|
return blink::kWebReferrerPolicyNever;
|
|
|
|
case REFERRER_POLICY_LAST_VALUE:
|
|
|
|
NOTREACHED();
|
|
|
|
return blink::kWebReferrerPolicyDefault;
|
|
|
|
}
|
|
|
|
NOTREACHED();
|
|
|
|
return blink::kWebReferrerPolicyDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
cef_referrer_policy_t CefRequestImpl::BlinkReferrerPolicyToNetReferrerPolicy(
|
|
|
|
blink::WebReferrerPolicy blink_policy) {
|
|
|
|
switch (blink_policy) {
|
|
|
|
case blink::kWebReferrerPolicyNoReferrerWhenDowngrade:
|
|
|
|
return REFERRER_POLICY_CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE;
|
|
|
|
case blink::kWebReferrerPolicyNoReferrerWhenDowngradeOriginWhenCrossOrigin:
|
|
|
|
return REFERRER_POLICY_REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN;
|
|
|
|
case blink::kWebReferrerPolicyOriginWhenCrossOrigin:
|
|
|
|
return REFERRER_POLICY_ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN;
|
|
|
|
case blink::kWebReferrerPolicyAlways:
|
|
|
|
return REFERRER_POLICY_NEVER_CLEAR_REFERRER;
|
|
|
|
case blink::kWebReferrerPolicyOrigin:
|
|
|
|
return REFERRER_POLICY_ORIGIN;
|
|
|
|
case blink::kWebReferrerPolicySameOrigin:
|
|
|
|
return REFERRER_POLICY_CLEAR_REFERRER_ON_TRANSITION_CROSS_ORIGIN;
|
|
|
|
case blink::kWebReferrerPolicyStrictOrigin:
|
|
|
|
return REFERRER_POLICY_ORIGIN_CLEAR_ON_TRANSITION_FROM_SECURE_TO_INSECURE;
|
|
|
|
case blink::kWebReferrerPolicyNever:
|
|
|
|
return REFERRER_POLICY_NO_REFERRER;
|
|
|
|
case blink::kWebReferrerPolicyDefault:
|
|
|
|
return REFERRER_POLICY_DEFAULT;
|
|
|
|
}
|
|
|
|
NOTREACHED();
|
|
|
|
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();
|
|
|
|
if (track_changes_)
|
|
|
|
changes_ |= changes;
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
if (!track_changes_)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Always change if changed-only was not requested.
|
|
|
|
if (!changed_only)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Change if the |changes| bit flag has been set.
|
|
|
|
if ((changes_ & changes) == changes)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
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;
|
2015-10-09 17:23:12 +02:00
|
|
|
postdata_ = NULL;
|
|
|
|
headermap_.clear();
|
|
|
|
resource_type_ = RT_SUB_RESOURCE;
|
|
|
|
transition_type_ = TT_EXPLICIT;
|
|
|
|
identifier_ = 0U;
|
|
|
|
flags_ = UR_FLAG_NONE;
|
2017-09-06 23:40:58 +02:00
|
|
|
site_for_cookies_ = GURL();
|
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 ------------------------------------------------------------
|
|
|
|
|
|
|
|
CefPostDataImpl::CefPostDataImpl()
|
2017-05-17 11:29:28 +02:00
|
|
|
: read_only_(false),
|
|
|
|
has_excluded_elements_(false),
|
|
|
|
track_changes_(false),
|
|
|
|
has_changes_(false) {}
|
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
|
|
|
}
|
|
|
|
|
2012-08-04 02:59:58 +02:00
|
|
|
void CefPostDataImpl::Set(const net::UploadData& data) {
|
2014-07-15 00:18:51 +02:00
|
|
|
{
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
CHECK_READONLY_RETURN_VOID();
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
CefRefPtr<CefPostDataElement> postelem;
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
for (const auto& element : data.elements()) {
|
2012-06-19 18:29:49 +02:00
|
|
|
postelem = CefPostDataElement::Create();
|
2017-04-20 21:28:17 +02:00
|
|
|
static_cast<CefPostDataElementImpl*>(postelem.get())->Set(*element);
|
2012-04-03 03:34:16 +02:00
|
|
|
AddElement(postelem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-30 20:08:20 +01:00
|
|
|
void CefPostDataImpl::Set(const net::UploadDataStream& data_stream) {
|
2014-07-15 00:18:51 +02:00
|
|
|
{
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
CHECK_READONLY_RETURN_VOID();
|
|
|
|
}
|
2012-11-30 20:08:20 +01:00
|
|
|
|
|
|
|
CefRefPtr<CefPostDataElement> postelem;
|
|
|
|
|
2015-12-09 17:10:16 +01:00
|
|
|
const UploadElementReaders* elements = data_stream.GetElementReaders();
|
2014-11-12 20:25:15 +01:00
|
|
|
if (elements) {
|
2015-12-09 17:10:16 +01:00
|
|
|
UploadElementReaders::const_iterator it = elements->begin();
|
2014-11-12 20:25:15 +01:00
|
|
|
for (; it != elements->end(); ++it) {
|
|
|
|
postelem = CefPostDataElement::Create();
|
|
|
|
static_cast<CefPostDataElementImpl*>(postelem.get())->Set(**it);
|
2015-11-16 23:20:34 +01:00
|
|
|
if (postelem->GetType() != PDE_TYPE_EMPTY)
|
|
|
|
AddElement(postelem);
|
2015-12-01 19:22:28 +01:00
|
|
|
else if (!has_excluded_elements_)
|
|
|
|
has_excluded_elements_ = true;
|
2014-11-12 20:25:15 +01:00
|
|
|
}
|
2012-11-30 20:08:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-16 23:20:34 +01:00
|
|
|
void CefPostDataImpl::Get(net::UploadData& data) const {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
net::UploadData::ElementsVector data_elements;
|
|
|
|
for (const auto& element : elements_) {
|
|
|
|
std::unique_ptr<net::UploadElement> data_element =
|
|
|
|
base::MakeUnique<net::UploadElement>();
|
2017-05-17 11:29:28 +02:00
|
|
|
static_cast<CefPostDataElementImpl*>(element.get())
|
|
|
|
->Get(*data_element.get());
|
2017-04-20 21:28:17 +02:00
|
|
|
data_elements.push_back(std::move(data_element));
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2012-11-16 03:58:25 +01:00
|
|
|
data.swap_elements(&data_elements);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
std::unique_ptr<net::UploadDataStream> CefPostDataImpl::Get() const {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2013-01-14 20:21:17 +01:00
|
|
|
|
2015-12-09 17:10:16 +01:00
|
|
|
UploadElementReaders element_readers;
|
2017-04-20 21:28:17 +02:00
|
|
|
for (const auto& element : elements_) {
|
|
|
|
element_readers.push_back(
|
|
|
|
static_cast<CefPostDataElementImpl*>(element.get())->Get());
|
2013-01-14 20:21:17 +01:00
|
|
|
}
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
return base::MakeUnique<net::ElementsUploadDataStream>(
|
|
|
|
std::move(element_readers), 0);
|
2013-01-14 20:21:17 +01:00
|
|
|
}
|
|
|
|
|
2013-11-08 22:28:56 +01:00
|
|
|
void CefPostDataImpl::Set(const blink::WebHTTPBody& data) {
|
2014-07-15 00:18:51 +02:00
|
|
|
{
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
CHECK_READONLY_RETURN_VOID();
|
|
|
|
}
|
2012-06-19 18:29:49 +02:00
|
|
|
|
|
|
|
CefRefPtr<CefPostDataElement> postelem;
|
2013-11-08 22:28:56 +01:00
|
|
|
blink::WebHTTPBody::Element element;
|
2017-04-20 21:28:17 +02:00
|
|
|
size_t size = data.ElementCount();
|
2012-06-19 18:29:49 +02:00
|
|
|
for (size_t i = 0; i < size; ++i) {
|
2017-04-20 21:28:17 +02:00
|
|
|
if (data.ElementAt(i, element)) {
|
2012-06-19 18:29:49 +02:00
|
|
|
postelem = CefPostDataElement::Create();
|
|
|
|
static_cast<CefPostDataElementImpl*>(postelem.get())->Set(element);
|
|
|
|
AddElement(postelem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-16 23:20:34 +01:00
|
|
|
void CefPostDataImpl::Get(blink::WebHTTPBody& data) const {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-06-19 18:29:49 +02:00
|
|
|
|
2013-11-08 22:28:56 +01:00
|
|
|
blink::WebHTTPBody::Element element;
|
2015-11-16 23:20:34 +01:00
|
|
|
ElementVector::const_iterator it = elements_.begin();
|
2012-06-19 18:29:49 +02:00
|
|
|
for (; it != elements_.end(); ++it) {
|
|
|
|
static_cast<CefPostDataElementImpl*>(it->get())->Get(element);
|
2017-04-20 21:28:17 +02:00
|
|
|
if (element.type == blink::WebHTTPBody::Element::kTypeData) {
|
|
|
|
data.AppendData(element.data);
|
|
|
|
} else if (element.type == blink::WebHTTPBody::Element::kTypeFile) {
|
|
|
|
data.AppendFile(element.file_path);
|
2012-06-19 18:29:49 +02:00
|
|
|
} else {
|
|
|
|
NOTREACHED();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefPostDataImpl::SetReadOnly(bool read_only) {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-06-19 18:29:49 +02:00
|
|
|
if (read_only_ == read_only)
|
|
|
|
return;
|
|
|
|
|
|
|
|
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_);
|
|
|
|
if (track_changes_ == track_changes)
|
|
|
|
return;
|
|
|
|
|
|
|
|
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_);
|
|
|
|
if (has_changes_)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
ElementVector::const_iterator it = elements_.begin();
|
|
|
|
for (; it != elements_.end(); ++it) {
|
|
|
|
if (static_cast<CefPostDataElementImpl*>(it->get())->HasChanges())
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefPostDataImpl::Changed() {
|
|
|
|
lock_.AssertAcquired();
|
|
|
|
if (track_changes_ && !has_changes_)
|
|
|
|
has_changes_ = true;
|
|
|
|
}
|
|
|
|
|
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 -----------------------------------------------------
|
|
|
|
|
|
|
|
CefPostDataElementImpl::CefPostDataElementImpl()
|
2017-05-17 11:29:28 +02:00
|
|
|
: type_(PDE_TYPE_EMPTY),
|
|
|
|
read_only_(false),
|
|
|
|
track_changes_(false),
|
|
|
|
has_changes_(false) {
|
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);
|
|
|
|
DCHECK(data != NULL);
|
|
|
|
if (data == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
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;
|
|
|
|
if (type_ == PDE_TYPE_FILE)
|
|
|
|
filename.FromString(data_.filename.str, data_.filename.length, false);
|
|
|
|
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;
|
|
|
|
if (type_ == PDE_TYPE_BYTES)
|
|
|
|
size = data_.bytes.size;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-08-29 00:26:35 +02:00
|
|
|
void CefPostDataElementImpl::Set(const net::UploadElement& element) {
|
2014-07-15 00:18:51 +02:00
|
|
|
{
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
CHECK_READONLY_RETURN_VOID();
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-08-29 00:26:35 +02:00
|
|
|
if (element.type() == net::UploadElement::TYPE_BYTES) {
|
|
|
|
SetToBytes(element.bytes_length(), element.bytes());
|
|
|
|
} else if (element.type() == net::UploadElement::TYPE_FILE) {
|
2012-04-03 03:34:16 +02:00
|
|
|
SetToFile(element.file_path().value());
|
|
|
|
} else {
|
|
|
|
NOTREACHED();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-30 20:08:20 +01:00
|
|
|
void CefPostDataElementImpl::Set(
|
|
|
|
const net::UploadElementReader& element_reader) {
|
2014-07-15 00:18:51 +02:00
|
|
|
{
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
CHECK_READONLY_RETURN_VOID();
|
|
|
|
}
|
2012-11-30 20:08:20 +01:00
|
|
|
|
|
|
|
const net::UploadBytesElementReader* bytes_reader =
|
|
|
|
element_reader.AsBytesReader();
|
|
|
|
if (bytes_reader) {
|
|
|
|
SetToBytes(bytes_reader->length(), bytes_reader->bytes());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const net::UploadFileElementReader* file_reader =
|
|
|
|
element_reader.AsFileReader();
|
|
|
|
if (file_reader) {
|
|
|
|
SetToFile(file_reader->path().value());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-16 23:20:34 +01:00
|
|
|
// Chunked uploads cannot currently be represented.
|
|
|
|
SetToEmpty();
|
2012-11-30 20:08:20 +01:00
|
|
|
}
|
|
|
|
|
2015-11-16 23:20:34 +01:00
|
|
|
void CefPostDataElementImpl::Get(net::UploadElement& element) const {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
if (type_ == PDE_TYPE_BYTES) {
|
|
|
|
element.SetToBytes(static_cast<char*>(data_.bytes.bytes), data_.bytes.size);
|
|
|
|
} else if (type_ == PDE_TYPE_FILE) {
|
2013-02-23 01:43:28 +01:00
|
|
|
base::FilePath path = base::FilePath(CefString(&data_.filename));
|
2012-04-03 03:34:16 +02:00
|
|
|
element.SetToFilePath(path);
|
|
|
|
} else {
|
|
|
|
NOTREACHED();
|
|
|
|
}
|
|
|
|
}
|
2012-06-19 18:29:49 +02:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
std::unique_ptr<net::UploadElementReader> CefPostDataElementImpl::Get() const {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2013-01-14 20:21:17 +01:00
|
|
|
|
|
|
|
if (type_ == PDE_TYPE_BYTES) {
|
|
|
|
net::UploadElement* element = new net::UploadElement();
|
|
|
|
element->SetToBytes(static_cast<char*>(data_.bytes.bytes),
|
|
|
|
data_.bytes.size);
|
2017-04-20 21:28:17 +02:00
|
|
|
return base::MakeUnique<BytesElementReader>(base::WrapUnique(element));
|
2013-01-14 20:21:17 +01:00
|
|
|
} else if (type_ == PDE_TYPE_FILE) {
|
|
|
|
net::UploadElement* element = new net::UploadElement();
|
2013-02-23 01:43:28 +01:00
|
|
|
base::FilePath path = base::FilePath(CefString(&data_.filename));
|
2013-01-14 20:21:17 +01:00
|
|
|
element->SetToFilePath(path);
|
2017-04-20 21:28:17 +02:00
|
|
|
return base::MakeUnique<FileElementReader>(base::WrapUnique(element));
|
2013-01-14 20:21:17 +01:00
|
|
|
} else {
|
|
|
|
NOTREACHED();
|
2017-04-20 21:28:17 +02:00
|
|
|
return nullptr;
|
2013-01-14 20:21:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-08 22:28:56 +01:00
|
|
|
void CefPostDataElementImpl::Set(const blink::WebHTTPBody::Element& element) {
|
2014-07-15 00:18:51 +02:00
|
|
|
{
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
CHECK_READONLY_RETURN_VOID();
|
|
|
|
}
|
2012-06-19 18:29:49 +02:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
if (element.type == blink::WebHTTPBody::Element::kTypeData) {
|
2017-09-06 23:40:58 +02:00
|
|
|
std::string file_contents;
|
|
|
|
file_contents.reserve(element.data.size());
|
|
|
|
element.data.ForEachSegment([&file_contents](const char* segment,
|
|
|
|
size_t segment_size,
|
|
|
|
size_t segment_offset) {
|
|
|
|
file_contents.append(segment, segment_size);
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
SetToBytes(file_contents.size(), file_contents.data());
|
2017-04-20 21:28:17 +02:00
|
|
|
} else if (element.type == blink::WebHTTPBody::Element::kTypeFile) {
|
|
|
|
SetToFile(element.file_path.Utf16());
|
2012-06-19 18:29:49 +02:00
|
|
|
} else {
|
|
|
|
NOTREACHED();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-16 23:20:34 +01:00
|
|
|
void CefPostDataElementImpl::Get(blink::WebHTTPBody::Element& element) const {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-06-19 18:29:49 +02:00
|
|
|
|
|
|
|
if (type_ == PDE_TYPE_BYTES) {
|
2017-04-20 21:28:17 +02:00
|
|
|
element.type = blink::WebHTTPBody::Element::kTypeData;
|
2017-05-17 11:29:28 +02:00
|
|
|
element.data.Assign(static_cast<char*>(data_.bytes.bytes),
|
|
|
|
data_.bytes.size);
|
2012-06-19 18:29:49 +02:00
|
|
|
} else if (type_ == PDE_TYPE_FILE) {
|
2017-04-20 21:28:17 +02:00
|
|
|
element.type = blink::WebHTTPBody::Element::kTypeFile;
|
2017-12-07 22:44:24 +01:00
|
|
|
element.file_path = blink::WebString::FromUTF16(CefString(&data_.filename));
|
2012-06-19 18:29:49 +02:00
|
|
|
} else {
|
|
|
|
NOTREACHED();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefPostDataElementImpl::SetReadOnly(bool read_only) {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-06-19 18:29:49 +02:00
|
|
|
if (read_only_ == read_only)
|
|
|
|
return;
|
|
|
|
|
|
|
|
read_only_ = read_only;
|
|
|
|
}
|
|
|
|
|
2015-11-16 23:20:34 +01:00
|
|
|
void CefPostDataElementImpl::SetTrackChanges(bool track_changes) {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
if (track_changes_ == track_changes)
|
|
|
|
return;
|
|
|
|
|
|
|
|
track_changes_ = track_changes;
|
|
|
|
has_changes_ = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefPostDataElementImpl::HasChanges() const {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
return has_changes_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefPostDataElementImpl::Changed() {
|
|
|
|
lock_.AssertAcquired();
|
|
|
|
if (track_changes_ && !has_changes_)
|
|
|
|
has_changes_ = true;
|
|
|
|
}
|
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
void CefPostDataElementImpl::Cleanup() {
|
|
|
|
if (type_ == PDE_TYPE_EMPTY)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (type_ == PDE_TYPE_BYTES)
|
|
|
|
free(data_.bytes.bytes);
|
|
|
|
else if (type_ == PDE_TYPE_FILE)
|
|
|
|
cef_string_clear(&data_.filename);
|
|
|
|
type_ = PDE_TYPE_EMPTY;
|
|
|
|
memset(&data_, 0, sizeof(data_));
|
|
|
|
}
|