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.
|
|
|
|
|
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>
|
|
|
|
|
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 "libcef/browser/navigate_params.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
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/sys_string_conversions.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"
|
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_bytes_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"
|
2016-04-27 22:38:52 +02:00
|
|
|
#include "third_party/WebKit/public/platform/WebCachePolicy.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"
|
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";
|
|
|
|
const char kApplicationFormURLEncoded[] = "application/x-www-form-urlencoded";
|
|
|
|
|
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(
|
2015-12-01 19:22:28 +01: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);
|
|
|
|
};
|
|
|
|
|
2015-12-01 19:22:28 +01:00
|
|
|
// GetURLRequestReferrerPolicy() and GetURLRequestReferrer() are based on
|
|
|
|
// SetReferrerForRequest() from
|
|
|
|
// content/browser/loader/resource_dispatcher_host_impl.cc
|
|
|
|
|
|
|
|
net::URLRequest::ReferrerPolicy GetURLRequestReferrerPolicy(
|
|
|
|
cef_referrer_policy_t policy) {
|
|
|
|
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
|
|
|
net::URLRequest::ReferrerPolicy net_referrer_policy =
|
|
|
|
net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE;
|
|
|
|
switch (static_cast<blink::WebReferrerPolicy>(policy)) {
|
|
|
|
case blink::WebReferrerPolicyAlways:
|
|
|
|
case blink::WebReferrerPolicyNever:
|
|
|
|
case blink::WebReferrerPolicyOrigin:
|
|
|
|
net_referrer_policy = net::URLRequest::NEVER_CLEAR_REFERRER;
|
|
|
|
break;
|
|
|
|
case blink::WebReferrerPolicyNoReferrerWhenDowngrade:
|
|
|
|
net_referrer_policy =
|
|
|
|
net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE;
|
|
|
|
break;
|
|
|
|
case blink::WebReferrerPolicyOriginWhenCrossOrigin:
|
|
|
|
net_referrer_policy =
|
|
|
|
net::URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN;
|
|
|
|
break;
|
|
|
|
case blink::WebReferrerPolicyDefault:
|
|
|
|
default:
|
|
|
|
net_referrer_policy =
|
|
|
|
command_line->HasSwitch(switches::kReducedReferrerGranularity)
|
|
|
|
? net::URLRequest::
|
|
|
|
REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN
|
|
|
|
: net::URLRequest::
|
|
|
|
CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return net_referrer_policy;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string GetURLRequestReferrer(const CefString& referrer_url) {
|
|
|
|
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
|
|
|
if (!GURL(referrer_url.ToString()).is_valid() ||
|
|
|
|
command_line->HasSwitch(switches::kNoReferrers)) {
|
|
|
|
return std::string();
|
|
|
|
}
|
|
|
|
|
|
|
|
return referrer_url;
|
|
|
|
}
|
|
|
|
|
|
|
|
blink::WebString FilePathStringToWebString(
|
|
|
|
const base::FilePath::StringType& str) {
|
|
|
|
#if defined(OS_POSIX)
|
|
|
|
return base::WideToUTF16(base::SysNativeMBToWide(str));
|
|
|
|
#elif defined(OS_WIN)
|
|
|
|
return base::WideToUTF16(str);
|
|
|
|
#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,
|
|
|
|
CefString& 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:
|
|
|
|
HeaderVisitor(CefRequest::HeaderMap* map, CefString* referrer)
|
|
|
|
: map_(map),
|
|
|
|
referrer_(referrer) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void visitHeader(const blink::WebString& name,
|
|
|
|
const blink::WebString& value) override {
|
|
|
|
const base::string16& nameStr = name;
|
|
|
|
const base::string16& valueStr = value;
|
|
|
|
if (base::LowerCaseEqualsASCII(nameStr, kReferrerLowerCase))
|
|
|
|
*referrer_ = valueStr;
|
|
|
|
else
|
|
|
|
map_->insert(std::make_pair(nameStr, valueStr));
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
CefRequest::HeaderMap* map_;
|
|
|
|
CefString* referrer_;
|
|
|
|
};
|
|
|
|
|
|
|
|
HeaderVisitor visitor(&map, &referrer);
|
|
|
|
request.visitHTTPHeaderFields(&visitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
request.setHTTPHeaderField(base::string16(it->first),
|
|
|
|
base::string16(it->second));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-09 17:10:16 +01:00
|
|
|
// Type used in UploadDataStream.
|
2016-04-27 22:38:52 +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
|
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
|
|
|
|
#define CHECK_READONLY_RETURN(val) \
|
|
|
|
if (read_only_) { \
|
|
|
|
NOTREACHED() << "object is read only"; \
|
|
|
|
return val; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CHECK_READONLY_RETURN_VOID() \
|
|
|
|
if (read_only_) { \
|
|
|
|
NOTREACHED() << "object is read only"; \
|
|
|
|
return; \
|
|
|
|
}
|
|
|
|
|
2015-12-01 19:22:28 +01:00
|
|
|
#define SETBOOLFLAG(obj, flags, method, FLAG) \
|
|
|
|
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 -------------------------------------------------------------
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
CefRequestImpl::CefRequestImpl()
|
2015-11-16 23:20:34 +01:00
|
|
|
: read_only_(false),
|
|
|
|
track_changes_(false) {
|
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_);
|
2012-04-03 03:34:16 +02:00
|
|
|
return url_;
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2015-11-16 23:20:34 +01:00
|
|
|
if (url_ != url) {
|
|
|
|
url_ = url;
|
|
|
|
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();
|
2015-11-16 23:20:34 +01:00
|
|
|
if (method_ != method) {
|
|
|
|
method_ = method;
|
|
|
|
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().
|
|
|
|
const GURL& gurl = GURL(referrer_url.ToString()).GetAsReferrer();
|
|
|
|
if (referrer_url_ != gurl.spec() || referrer_policy_ != policy) {
|
|
|
|
referrer_url_ = gurl.spec();
|
|
|
|
referrer_policy_ = policy;
|
|
|
|
Changed(kChangedReferrer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefRequestImpl::GetReferrerURL() {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
return referrer_url_;
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2015-11-16 23:20:34 +01:00
|
|
|
if (url_ != url) {
|
|
|
|
url_ = url;
|
|
|
|
Changed(kChangedUrl);
|
|
|
|
}
|
|
|
|
if (method_ != method) {
|
|
|
|
method_ = method;
|
|
|
|
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_);
|
2012-04-03 03:34:16 +02:00
|
|
|
return first_party_for_cookies_;
|
|
|
|
}
|
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();
|
2015-11-16 23:20:34 +01:00
|
|
|
if (first_party_for_cookies_ != url) {
|
|
|
|
first_party_for_cookies_ = url;
|
|
|
|
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_;
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
void CefRequestImpl::Set(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();
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
url_ = request->url().spec();
|
|
|
|
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()) {
|
|
|
|
referrer_url_ = referrer.spec();
|
|
|
|
switch (request->referrer_policy()) {
|
|
|
|
case net::URLRequest::
|
|
|
|
CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE:
|
|
|
|
referrer_policy_ = REFERRER_POLICY_NO_REFERRER_WHEN_DOWNGRADE;
|
|
|
|
break;
|
|
|
|
case net::URLRequest::
|
|
|
|
REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN:
|
|
|
|
referrer_policy_ = REFERRER_POLICY_ORIGIN_WHEN_CROSS_ORIGIN;
|
|
|
|
break;
|
|
|
|
case net::URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN:
|
|
|
|
referrer_policy_ = REFERRER_POLICY_ORIGIN_WHEN_CROSS_ORIGIN;
|
|
|
|
break;
|
|
|
|
case net::URLRequest::NEVER_CLEAR_REFERRER:
|
|
|
|
referrer_policy_ = REFERRER_POLICY_ALWAYS;
|
|
|
|
break;
|
2016-07-06 21:34:09 +02:00
|
|
|
case net::URLRequest::ORIGIN:
|
|
|
|
referrer_policy_ = REFERRER_POLICY_ORIGIN;
|
|
|
|
break;
|
|
|
|
case net::URLRequest::NO_REFERRER:
|
|
|
|
referrer_policy_ = REFERRER_POLICY_NEVER;
|
|
|
|
break;
|
|
|
|
case net::URLRequest::MAX_REFERRER_POLICY:
|
|
|
|
break;
|
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
|
|
|
|
2015-12-01 19:22:28 +01:00
|
|
|
first_party_for_cookies_ = request->first_party_for_cookies().spec();
|
|
|
|
|
2013-09-10 21:42:53 +02:00
|
|
|
const content::ResourceRequestInfo* info =
|
|
|
|
content::ResourceRequestInfo::ForRequest(request);
|
|
|
|
if (info) {
|
|
|
|
resource_type_ =
|
|
|
|
static_cast<cef_resource_type_t>(info->GetResourceType());
|
|
|
|
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_));
|
|
|
|
request->set_referrer_policy(GetURLRequestReferrerPolicy(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()) {
|
2016-05-25 01:35:43 +02:00
|
|
|
request->set_upload(base::WrapUnique(
|
2015-11-16 23:20:34 +01:00
|
|
|
static_cast<CefPostDataImpl*>(postdata_.get())->Get()));
|
|
|
|
} 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
|
|
|
|
|
|
|
if (!first_party_for_cookies_.empty() &&
|
|
|
|
ShouldSet(kChangedFirstPartyForCookies, changed_only)) {
|
|
|
|
request->set_first_party_for_cookies(
|
|
|
|
GURL(std::string(first_party_for_cookies_)));
|
|
|
|
}
|
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();
|
|
|
|
|
|
|
|
url_ = params.url().spec();
|
|
|
|
method_ = params.is_post() ? "POST" : "GET";
|
|
|
|
|
|
|
|
const content::Referrer& sanitized_referrer =
|
|
|
|
content::Referrer::SanitizeForRequest(params.url(), params.referrer());
|
2015-12-01 19:22:28 +01:00
|
|
|
referrer_url_ = sanitized_referrer.url.spec();
|
|
|
|
referrer_policy_ =
|
|
|
|
static_cast<cef_referrer_policy_t>(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) {
|
2012-06-19 18:29:49 +02:00
|
|
|
DCHECK(!request.isNull());
|
|
|
|
|
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();
|
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
url_ = request.url().string();
|
2012-06-19 18:29:49 +02:00
|
|
|
method_ = request.httpMethod();
|
|
|
|
|
2015-12-01 19:22:28 +01:00
|
|
|
::GetHeaderMap(request, headermap_, referrer_url_);
|
|
|
|
referrer_policy_ =
|
|
|
|
static_cast<cef_referrer_policy_t>(request.referrerPolicy());
|
|
|
|
|
2013-11-08 22:28:56 +01:00
|
|
|
const blink::WebHTTPBody& body = request.httpBody();
|
2012-06-19 18:29:49 +02:00
|
|
|
if (!body.isNull()) {
|
|
|
|
postdata_ = new CefPostDataImpl();
|
|
|
|
static_cast<CefPostDataImpl*>(postdata_.get())->Set(body);
|
|
|
|
}
|
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
first_party_for_cookies_ = request.firstPartyForCookies().string();
|
2012-06-19 18:29:49 +02:00
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
if (request.getCachePolicy() == blink::WebCachePolicy::BypassingCache)
|
2012-06-19 18:29:49 +02:00
|
|
|
flags_ |= UR_FLAG_SKIP_CACHE;
|
|
|
|
if (request.allowStoredCredentials())
|
|
|
|
flags_ |= UR_FLAG_ALLOW_CACHED_CREDENTIALS;
|
|
|
|
if (request.reportUploadProgress())
|
|
|
|
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
|
|
|
|
2015-12-01 19:22:28 +01:00
|
|
|
request.setURL(GURL(url_.ToString()));
|
|
|
|
request.setHTTPMethod(blink::WebString::fromUTF8(method_.ToString()));
|
|
|
|
|
|
|
|
if (!referrer_url_.empty()) {
|
|
|
|
const blink::WebString& referrer =
|
|
|
|
blink::WebSecurityPolicy::generateReferrerHeader(
|
|
|
|
static_cast<blink::WebReferrerPolicy>(referrer_policy_),
|
|
|
|
GURL(url_.ToString()),
|
|
|
|
blink::WebString::fromUTF8(referrer_url_));
|
|
|
|
if (!referrer.isEmpty()) {
|
|
|
|
request.setHTTPReferrer(
|
|
|
|
referrer,
|
|
|
|
static_cast<blink::WebReferrerPolicy>(referrer_policy_));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (postdata_.get()) {
|
|
|
|
blink::WebHTTPBody body;
|
|
|
|
body.initialize();
|
|
|
|
static_cast<CefPostDataImpl*>(postdata_.get())->Get(body);
|
|
|
|
request.setHTTPBody(body);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (!first_party_for_cookies_.empty())
|
|
|
|
request.setFirstPartyForCookies(GURL(first_party_for_cookies_.ToString()));
|
|
|
|
|
|
|
|
request.setCachePolicy((flags_ & UR_FLAG_SKIP_CACHE) ?
|
2016-04-27 22:38:52 +02:00
|
|
|
blink::WebCachePolicy::BypassingCache :
|
|
|
|
blink::WebCachePolicy::UseProtocolCachePolicy);
|
2015-12-01 19:22:28 +01:00
|
|
|
|
|
|
|
SETBOOLFLAG(request, flags_, setAllowStoredCredentials,
|
|
|
|
UR_FLAG_ALLOW_CACHED_CREDENTIALS);
|
|
|
|
SETBOOLFLAG(request, flags_, setReportUploadProgress,
|
|
|
|
UR_FLAG_REPORT_UPLOAD_PROGRESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void CefRequestImpl::Get(const CefMsg_LoadRequest_Params& params,
|
|
|
|
blink::WebURLRequest& request) {
|
|
|
|
request.setURL(params.url);
|
|
|
|
if (!params.method.empty())
|
|
|
|
request.setHTTPMethod(base::ASCIIToUTF16(params.method));
|
|
|
|
|
|
|
|
if (params.referrer.is_valid()) {
|
|
|
|
const blink::WebString& referrer =
|
|
|
|
blink::WebSecurityPolicy::generateReferrerHeader(
|
|
|
|
static_cast<blink::WebReferrerPolicy>(params.referrer_policy),
|
|
|
|
params.url,
|
|
|
|
blink::WebString::fromUTF8(params.referrer.spec()));
|
|
|
|
if (!referrer.isEmpty()) {
|
|
|
|
request.setHTTPReferrer(
|
|
|
|
referrer,
|
|
|
|
static_cast<blink::WebReferrerPolicy>(params.referrer_policy));
|
|
|
|
}
|
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.headers.empty()) {
|
|
|
|
for (net::HttpUtil::HeadersIterator i(params.headers.begin(),
|
|
|
|
params.headers.end(), "\n");
|
|
|
|
i.GetNext(); ) {
|
|
|
|
request.addHTTPHeaderField(blink::WebString::fromUTF8(i.name()),
|
|
|
|
blink::WebString::fromUTF8(i.values()));
|
|
|
|
}
|
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()) {
|
|
|
|
const base::string16& method = request.httpMethod();
|
|
|
|
if (method == base::ASCIIToUTF16("GET") ||
|
|
|
|
method == base::ASCIIToUTF16("HEAD")) {
|
|
|
|
request.setHTTPMethod(base::ASCIIToUTF16("POST"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// The comparison performed by httpHeaderField() is case insensitive.
|
|
|
|
if (request.httpHeaderField(base::ASCIIToUTF16(
|
|
|
|
net::HttpRequestHeaders::kContentType)).length()== 0) {
|
|
|
|
request.setHTTPHeaderField(
|
|
|
|
base::ASCIIToUTF16(net::HttpRequestHeaders::kContentType),
|
|
|
|
base::ASCIIToUTF16(kApplicationFormURLEncoded));
|
|
|
|
}
|
|
|
|
|
2015-11-16 23:20:34 +01:00
|
|
|
blink::WebHTTPBody body;
|
2015-12-01 19:22:28 +01:00
|
|
|
body.initialize();
|
|
|
|
|
|
|
|
const ScopedVector<net::UploadElement>& elements =
|
|
|
|
params.upload_data->elements();
|
|
|
|
ScopedVector<net::UploadElement>::const_iterator it =
|
|
|
|
elements.begin();
|
|
|
|
for (; it != elements.end(); ++it) {
|
|
|
|
const net::UploadElement& element = **it;
|
|
|
|
if (element.type() == net::UploadElement::TYPE_BYTES) {
|
|
|
|
blink::WebData data;
|
|
|
|
data.assign(element.bytes(), element.bytes_length());
|
|
|
|
body.appendData(data);
|
|
|
|
} else if (element.type() == net::UploadElement::TYPE_FILE) {
|
|
|
|
body.appendFile(FilePathStringToWebString(element.file_path().value()));
|
|
|
|
} else {
|
|
|
|
NOTREACHED();
|
|
|
|
}
|
2015-11-16 23:20:34 +01:00
|
|
|
}
|
2015-12-01 19:22:28 +01:00
|
|
|
|
|
|
|
request.setHTTPBody(body);
|
2012-06-19 18:29:49 +02:00
|
|
|
}
|
|
|
|
|
2015-12-01 19:22:28 +01:00
|
|
|
if (params.first_party_for_cookies.is_valid())
|
|
|
|
request.setFirstPartyForCookies(params.first_party_for_cookies);
|
|
|
|
|
|
|
|
request.setCachePolicy((params.load_flags & UR_FLAG_SKIP_CACHE) ?
|
2016-04-27 22:38:52 +02:00
|
|
|
blink::WebCachePolicy::BypassingCache :
|
|
|
|
blink::WebCachePolicy::UseProtocolCachePolicy);
|
2015-12-01 19:22:28 +01:00
|
|
|
|
|
|
|
SETBOOLFLAG(request, params.load_flags, setAllowStoredCredentials,
|
|
|
|
UR_FLAG_ALLOW_CACHED_CREDENTIALS);
|
|
|
|
SETBOOLFLAG(request, params.load_flags, setReportUploadProgress,
|
|
|
|
UR_FLAG_REPORT_UPLOAD_PROGRESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestImpl::Get(CefNavigateParams& params) const {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-06-19 18:29:49 +02:00
|
|
|
|
2015-12-01 19:22:28 +01:00
|
|
|
params.url = GURL(url_.ToString());
|
|
|
|
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.
|
|
|
|
params.referrer.url = GURL(referrer_url_.ToString());
|
|
|
|
params.referrer.policy =
|
|
|
|
static_cast<blink::WebReferrerPolicy>(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
|
|
|
|
2015-12-01 19:22:28 +01:00
|
|
|
params.first_party_for_cookies = GURL(first_party_for_cookies_.ToString());
|
|
|
|
params.load_flags = flags_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestImpl::Get(net::URLFetcher& fetcher,
|
|
|
|
int64& upload_data_size) const {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
|
|
|
|
if (!referrer_url_.empty()) {
|
|
|
|
fetcher.SetReferrer(GetURLRequestReferrer(referrer_url_));
|
|
|
|
fetcher.SetReferrerPolicy(GetURLRequestReferrerPolicy(referrer_policy_));
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fetcher.SetExtraRequestHeaders(
|
|
|
|
HttpHeaderUtils::GenerateHeaders(headerMap));
|
|
|
|
|
|
|
|
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(
|
|
|
|
content_type,
|
|
|
|
base::FilePath(impl->GetFile()),
|
2016-01-06 20:20:54 +01:00
|
|
|
0, std::numeric_limits<uint64_t>::max(),
|
2015-12-01 19:22:28 +01:00
|
|
|
GetFileTaskRunner());
|
|
|
|
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
|
|
|
|
2016-02-02 22:32:44 +01:00
|
|
|
if (!first_party_for_cookies_.empty())
|
|
|
|
fetcher.SetInitiatorURL(GURL(first_party_for_cookies_.ToString()));
|
2015-12-01 19:22:28 +01:00
|
|
|
|
|
|
|
if (flags_ & UR_FLAG_NO_RETRY_ON_5XX)
|
|
|
|
fetcher.SetAutomaticallyRetryOn5xx(false);
|
|
|
|
|
|
|
|
int load_flags = 0;
|
|
|
|
|
|
|
|
if (flags_ & UR_FLAG_SKIP_CACHE)
|
|
|
|
load_flags |= net::LOAD_BYPASS_CACHE;
|
|
|
|
|
|
|
|
if (!(flags_ & UR_FLAG_ALLOW_CACHED_CREDENTIALS)) {
|
|
|
|
load_flags |= net::LOAD_DO_NOT_SEND_AUTH_DATA;
|
|
|
|
load_flags |= net::LOAD_DO_NOT_SEND_COOKIES;
|
|
|
|
load_flags |= net::LOAD_DO_NOT_SAVE_COOKIES;
|
|
|
|
}
|
|
|
|
|
|
|
|
fetcher.SetLoadFlags(load_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()) {
|
|
|
|
static_cast<CefPostDataImpl*>(postdata_.get())->
|
|
|
|
SetTrackChanges(track_changes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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_);
|
|
|
|
|
|
|
|
url_.clear();
|
|
|
|
method_ = "GET";
|
2015-12-01 19:22:28 +01:00
|
|
|
referrer_url_.clear();
|
|
|
|
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;
|
|
|
|
first_party_for_cookies_.clear();
|
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()
|
2015-11-16 23:20:34 +01:00
|
|
|
: read_only_(false),
|
2015-12-01 19:22:28 +01:00
|
|
|
has_excluded_elements_(false),
|
2015-11-16 23:20:34 +01:00
|
|
|
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;
|
|
|
|
|
2012-11-16 03:58:25 +01:00
|
|
|
const ScopedVector<net::UploadElement>& elements = data.elements();
|
|
|
|
ScopedVector<net::UploadElement>::const_iterator it = elements.begin();
|
|
|
|
for (; it != elements.end(); ++it) {
|
2012-06-19 18:29:49 +02:00
|
|
|
postelem = CefPostDataElement::Create();
|
2012-11-16 03:58:25 +01:00
|
|
|
static_cast<CefPostDataElementImpl*>(postelem.get())->Set(**it);
|
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
|
|
|
|
2012-11-16 03:58:25 +01:00
|
|
|
ScopedVector<net::UploadElement> data_elements;
|
2012-06-19 18:29:49 +02:00
|
|
|
ElementVector::const_iterator it = elements_.begin();
|
2012-04-03 03:34:16 +02:00
|
|
|
for (; it != elements_.end(); ++it) {
|
2012-11-16 03:58:25 +01:00
|
|
|
net::UploadElement* element = new net::UploadElement();
|
|
|
|
static_cast<CefPostDataElementImpl*>(it->get())->Get(*element);
|
2012-04-03 03:34:16 +02:00
|
|
|
data_elements.push_back(element);
|
|
|
|
}
|
2012-11-16 03:58:25 +01:00
|
|
|
data.swap_elements(&data_elements);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2015-11-16 23:20:34 +01:00
|
|
|
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;
|
2013-01-14 20:21:17 +01:00
|
|
|
ElementVector::const_iterator it = elements_.begin();
|
|
|
|
for (; it != elements_.end(); ++it) {
|
2016-05-25 01:35:43 +02:00
|
|
|
element_readers.push_back(base::WrapUnique(
|
2015-12-09 17:10:16 +01:00
|
|
|
static_cast<CefPostDataElementImpl*>(it->get())->Get()));
|
2013-01-14 20:21:17 +01:00
|
|
|
}
|
|
|
|
|
2015-12-09 17:10:16 +01:00
|
|
|
return new 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;
|
2012-06-19 18:29:49 +02:00
|
|
|
size_t size = data.elementCount();
|
|
|
|
for (size_t i = 0; i < size; ++i) {
|
|
|
|
if (data.elementAt(i, element)) {
|
|
|
|
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);
|
2013-11-08 22:28:56 +01:00
|
|
|
if (element.type == blink::WebHTTPBody::Element::TypeData) {
|
2012-06-19 18:29:49 +02:00
|
|
|
data.appendData(element.data);
|
2013-11-08 22:28:56 +01:00
|
|
|
} else if (element.type == blink::WebHTTPBody::Element::TypeFile) {
|
2012-06-19 18:29:49 +02:00
|
|
|
data.appendFile(element.filePath);
|
|
|
|
} 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) {
|
|
|
|
static_cast<CefPostDataElementImpl*>(it->get())->
|
|
|
|
SetTrackChanges(track_changes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
: type_(PDE_TYPE_EMPTY),
|
2015-11-16 23:20:34 +01:00
|
|
|
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
|
|
|
|
2015-11-16 23:20:34 +01:00
|
|
|
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);
|
2016-05-25 01:35:43 +02:00
|
|
|
return new 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);
|
2016-05-25 01:35:43 +02:00
|
|
|
return new FileElementReader(base::WrapUnique(element));
|
2013-01-14 20:21:17 +01:00
|
|
|
} else {
|
|
|
|
NOTREACHED();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2013-11-08 22:28:56 +01:00
|
|
|
if (element.type == blink::WebHTTPBody::Element::TypeData) {
|
2012-06-19 18:29:49 +02:00
|
|
|
SetToBytes(element.data.size(),
|
|
|
|
static_cast<const void*>(element.data.data()));
|
2013-11-08 22:28:56 +01:00
|
|
|
} else if (element.type == blink::WebHTTPBody::Element::TypeFile) {
|
2013-12-17 23:04:35 +01:00
|
|
|
SetToFile(base::string16(element.filePath));
|
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) {
|
2013-11-08 22:28:56 +01:00
|
|
|
element.type = blink::WebHTTPBody::Element::TypeData;
|
2012-06-19 18:29:49 +02:00
|
|
|
element.data.assign(
|
|
|
|
static_cast<char*>(data_.bytes.bytes), data_.bytes.size);
|
|
|
|
} else if (type_ == PDE_TYPE_FILE) {
|
2013-11-08 22:28:56 +01:00
|
|
|
element.type = blink::WebHTTPBody::Element::TypeFile;
|
2013-12-17 23:04:35 +01:00
|
|
|
element.filePath.assign(base::string16(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_));
|
|
|
|
}
|