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.
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "libcef/common/http_header_utils.h"
|
|
|
|
#include "libcef/common/request_impl.h"
|
2013-01-15 20:12:28 +01:00
|
|
|
#include "libcef/common/task_runner_impl.h"
|
2014-02-05 21:35:45 +01:00
|
|
|
#include "libcef/common/upload_data.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
#include "base/logging.h"
|
2013-09-10 21:42:53 +02:00
|
|
|
#include "content/public/browser/resource_request_info.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"
|
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"
|
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"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-01-14 20:21:17 +01:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// A subclass of net::UploadBytesElementReader that keeps the associated
|
|
|
|
// UploadElement alive until the request completes.
|
|
|
|
class BytesElementReader : public net::UploadBytesElementReader {
|
|
|
|
public:
|
|
|
|
explicit BytesElementReader(scoped_ptr<net::UploadElement> element)
|
|
|
|
: net::UploadBytesElementReader(element->bytes(),
|
|
|
|
element->bytes_length()),
|
|
|
|
element_(element.Pass()) {
|
|
|
|
DCHECK_EQ(net::UploadElement::TYPE_BYTES, element_->type());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
scoped_ptr<net::UploadElement> element_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(BytesElementReader);
|
|
|
|
};
|
|
|
|
|
2013-01-15 20:12:28 +01:00
|
|
|
base::TaskRunner* GetFileTaskRunner() {
|
|
|
|
scoped_refptr<base::SequencedTaskRunner> task_runner =
|
|
|
|
CefTaskRunnerImpl::GetTaskRunner(TID_FILE);
|
2014-09-27 01:48:19 +02:00
|
|
|
DCHECK(task_runner.get());
|
|
|
|
return task_runner.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:
|
|
|
|
explicit FileElementReader(scoped_ptr<net::UploadElement> element)
|
|
|
|
: 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()),
|
|
|
|
element_(element.Pass()) {
|
|
|
|
DCHECK_EQ(net::UploadElement::TYPE_FILE, element_->type());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
scoped_ptr<net::UploadElement> element_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(FileElementReader);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // 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; \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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()
|
|
|
|
: method_("GET"),
|
2013-09-10 21:42:53 +02:00
|
|
|
resource_type_(RT_SUB_RESOURCE),
|
|
|
|
transition_type_(TT_EXPLICIT),
|
2015-03-11 19:44:11 +01:00
|
|
|
identifier_(0U),
|
2012-06-19 18:29:49 +02:00
|
|
|
flags_(UR_FLAG_NONE),
|
|
|
|
read_only_(false) {
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2012-04-03 03:34:16 +02:00
|
|
|
url_ = url;
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2012-04-03 03:34:16 +02:00
|
|
|
method_ = method;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2012-04-03 03:34:16 +02:00
|
|
|
headermap_ = headerMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2012-04-03 03:34:16 +02:00
|
|
|
url_ = url;
|
|
|
|
method_ = method;
|
|
|
|
postdata_ = postData;
|
|
|
|
headermap_ = headerMap;
|
|
|
|
}
|
|
|
|
|
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_;
|
|
|
|
}
|
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();
|
2012-04-03 03:34:16 +02:00
|
|
|
flags_ = flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
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_;
|
|
|
|
}
|
|
|
|
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();
|
2012-04-03 03:34:16 +02:00
|
|
|
first_party_for_cookies_ = url;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
url_ = request->url().spec();
|
|
|
|
method_ = request->method();
|
|
|
|
first_party_for_cookies_ = request->first_party_for_cookies().spec();
|
2015-03-11 19:44:11 +01:00
|
|
|
identifier_ = request->identifier();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
net::HttpRequestHeaders headers = request->extra_request_headers();
|
|
|
|
|
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
|
|
|
|
|
|
|
// Strip Referer from request_info_.extra_headers to prevent, e.g., plugins
|
|
|
|
// from overriding headers that are controlled using other means. Otherwise a
|
|
|
|
// plugin could set a referrer although sending the referrer is inhibited.
|
|
|
|
headers.RemoveHeader(net::HttpRequestHeaders::kReferer);
|
|
|
|
|
|
|
|
// Our consumer should have made sure that this is a safe referrer. See for
|
|
|
|
// instance WebCore::FrameLoader::HideReferrer.
|
|
|
|
if (referrer.is_valid())
|
|
|
|
headers.SetHeader(net::HttpRequestHeaders::kReferer, referrer.spec());
|
|
|
|
|
|
|
|
// Transfer request headers
|
|
|
|
GetHeaderMap(headers, headermap_);
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
} else if (postdata_.get()) {
|
|
|
|
postdata_ = NULL;
|
|
|
|
}
|
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());
|
|
|
|
} else {
|
|
|
|
resource_type_ = RT_SUB_RESOURCE;
|
|
|
|
transition_type_ = TT_EXPLICIT;
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestImpl::Get(net::URLRequest* request) {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
request->set_method(method_);
|
|
|
|
if (!first_party_for_cookies_.empty()) {
|
|
|
|
request->set_first_party_for_cookies(
|
|
|
|
GURL(std::string(first_party_for_cookies_)));
|
|
|
|
}
|
|
|
|
|
|
|
|
CefString referrerStr;
|
2012-06-01 19:41:30 +02:00
|
|
|
referrerStr.FromASCII(net::HttpRequestHeaders::kReferer);
|
2012-04-03 03:34:16 +02:00
|
|
|
HeaderMap headerMap = headermap_;
|
|
|
|
HeaderMap::iterator it = headerMap.find(referrerStr);
|
|
|
|
if (it == headerMap.end()) {
|
2013-04-16 00:16:01 +02:00
|
|
|
request->SetReferrer("");
|
2012-04-03 03:34:16 +02:00
|
|
|
} else {
|
2013-04-16 00:16:01 +02:00
|
|
|
request->SetReferrer(it->second);
|
2012-04-03 03:34:16 +02:00
|
|
|
headerMap.erase(it);
|
|
|
|
}
|
|
|
|
net::HttpRequestHeaders headers;
|
|
|
|
headers.AddHeadersFromString(HttpHeaderUtils::GenerateHeaders(headerMap));
|
|
|
|
request->SetExtraRequestHeaders(headers);
|
|
|
|
|
|
|
|
if (postdata_.get()) {
|
2013-01-14 20:21:17 +01:00
|
|
|
request->set_upload(
|
|
|
|
make_scoped_ptr(static_cast<CefPostDataImpl*>(postdata_.get())->Get()));
|
2012-04-03 03:34:16 +02:00
|
|
|
} else if (request->get_upload()) {
|
2013-01-14 20:21:17 +01:00
|
|
|
request->set_upload(scoped_ptr<net::UploadDataStream>());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
url_ = request.url().spec().utf16();
|
|
|
|
method_ = request.httpMethod();
|
|
|
|
|
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);
|
|
|
|
} else if (postdata_.get()) {
|
|
|
|
postdata_ = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
headermap_.clear();
|
|
|
|
GetHeaderMap(request, headermap_);
|
|
|
|
|
|
|
|
flags_ = UR_FLAG_NONE;
|
2013-11-08 22:28:56 +01:00
|
|
|
if (request.cachePolicy() == blink::WebURLRequest::ReloadIgnoringCacheData)
|
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;
|
|
|
|
if (request.reportRawHeaders())
|
|
|
|
flags_ |= UR_FLAG_REPORT_RAW_HEADERS;
|
|
|
|
|
|
|
|
first_party_for_cookies_ = request.firstPartyForCookies().spec().utf16();
|
|
|
|
}
|
|
|
|
|
2013-11-08 22:28:56 +01:00
|
|
|
void CefRequestImpl::Get(blink::WebURLRequest& request) {
|
2012-06-19 18:29:49 +02:00
|
|
|
request.initialize();
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-06-19 18:29:49 +02:00
|
|
|
|
|
|
|
GURL gurl = GURL(url_.ToString());
|
2013-11-08 22:28:56 +01:00
|
|
|
request.setURL(blink::WebURL(gurl));
|
2012-06-19 18:29:49 +02:00
|
|
|
|
|
|
|
std::string method(method_);
|
2013-11-08 22:28:56 +01:00
|
|
|
request.setHTTPMethod(blink::WebString::fromUTF8(method.c_str()));
|
2012-06-19 18:29:49 +02:00
|
|
|
|
2013-11-08 22:28:56 +01:00
|
|
|
blink::WebHTTPBody body;
|
2012-06-19 18:29:49 +02:00
|
|
|
if (postdata_.get()) {
|
|
|
|
body.initialize();
|
|
|
|
static_cast<CefPostDataImpl*>(postdata_.get())->Get(body);
|
|
|
|
request.setHTTPBody(body);
|
|
|
|
}
|
|
|
|
|
|
|
|
SetHeaderMap(headermap_, request);
|
|
|
|
|
|
|
|
request.setCachePolicy((flags_ & UR_FLAG_SKIP_CACHE) ?
|
2013-11-08 22:28:56 +01:00
|
|
|
blink::WebURLRequest::ReloadIgnoringCacheData :
|
|
|
|
blink::WebURLRequest::UseProtocolCachePolicy);
|
2012-06-19 18:29:49 +02:00
|
|
|
|
|
|
|
#define SETBOOLFLAG(obj, flags, method, FLAG) \
|
|
|
|
obj.method((flags & (FLAG)) == (FLAG))
|
|
|
|
|
|
|
|
SETBOOLFLAG(request, flags_, setAllowStoredCredentials,
|
|
|
|
UR_FLAG_ALLOW_CACHED_CREDENTIALS);
|
|
|
|
SETBOOLFLAG(request, flags_, setReportUploadProgress,
|
|
|
|
UR_FLAG_REPORT_UPLOAD_PROGRESS);
|
|
|
|
SETBOOLFLAG(request, flags_, setReportRawHeaders,
|
|
|
|
UR_FLAG_REPORT_RAW_HEADERS);
|
|
|
|
|
|
|
|
if (!first_party_for_cookies_.empty()) {
|
|
|
|
GURL gurl = GURL(first_party_for_cookies_.ToString());
|
2013-11-08 22:28:56 +01:00
|
|
|
request.setFirstPartyForCookies(blink::WebURL(gurl));
|
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);
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// static
|
|
|
|
void CefRequestImpl::GetHeaderMap(const net::HttpRequestHeaders& headers,
|
|
|
|
HeaderMap& map) {
|
2012-05-18 17:04:56 +02:00
|
|
|
if (headers.IsEmpty())
|
|
|
|
return;
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
net::HttpRequestHeaders::Iterator it(headers);
|
|
|
|
do {
|
|
|
|
map.insert(std::make_pair(it.name(), it.value()));
|
|
|
|
} while (it.GetNext());
|
|
|
|
}
|
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
|
|
|
|
// static
|
2013-11-08 22:28:56 +01:00
|
|
|
void CefRequestImpl::GetHeaderMap(const blink::WebURLRequest& request,
|
2012-06-19 18:29:49 +02:00
|
|
|
HeaderMap& map) {
|
2013-11-08 22:28:56 +01:00
|
|
|
class HeaderVisitor : public blink::WebHTTPHeaderVisitor {
|
2012-06-19 18:29:49 +02:00
|
|
|
public:
|
|
|
|
explicit HeaderVisitor(HeaderMap* map) : map_(map) {}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void visitHeader(const blink::WebString& name,
|
|
|
|
const blink::WebString& value) override {
|
2013-12-17 23:04:35 +01:00
|
|
|
map_->insert(std::make_pair(base::string16(name),
|
|
|
|
base::string16(value)));
|
2012-06-19 18:29:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
HeaderMap* map_;
|
|
|
|
};
|
|
|
|
|
|
|
|
HeaderVisitor visitor(&map);
|
|
|
|
request.visitHTTPHeaderFields(&visitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void CefRequestImpl::SetHeaderMap(const HeaderMap& map,
|
2013-11-08 22:28:56 +01:00
|
|
|
blink::WebURLRequest& request) {
|
2012-06-19 18:29:49 +02:00
|
|
|
HeaderMap::const_iterator it = map.begin();
|
|
|
|
for (; it != map.end(); ++it)
|
2013-12-17 23:04:35 +01:00
|
|
|
request.setHTTPHeaderField(base::string16(it->first),
|
|
|
|
base::string16(it->second));
|
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()
|
|
|
|
: read_only_(false) {
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
elements_.push_back(element);
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
const ScopedVector<net::UploadElementReader>* elements =
|
|
|
|
data_stream.GetElementReaders();
|
|
|
|
if (elements) {
|
|
|
|
ScopedVector<net::UploadElementReader>::const_iterator it =
|
|
|
|
elements->begin();
|
|
|
|
for (; it != elements->end(); ++it) {
|
|
|
|
postelem = CefPostDataElement::Create();
|
|
|
|
static_cast<CefPostDataElementImpl*>(postelem.get())->Set(**it);
|
|
|
|
AddElement(postelem);
|
|
|
|
}
|
2012-11-30 20:08:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
void CefPostDataImpl::Get(net::UploadData& data) {
|
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
|
|
|
}
|
|
|
|
|
2013-01-14 20:21:17 +01:00
|
|
|
net::UploadDataStream* CefPostDataImpl::Get() {
|
2014-07-15 00:18:51 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2013-01-14 20:21:17 +01:00
|
|
|
|
|
|
|
ScopedVector<net::UploadElementReader> element_readers;
|
|
|
|
ElementVector::const_iterator it = elements_.begin();
|
|
|
|
for (; it != elements_.end(); ++it) {
|
|
|
|
element_readers.push_back(
|
|
|
|
static_cast<CefPostDataElementImpl*>(it->get())->Get());
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
return new net::ElementsUploadDataStream(element_readers.Pass(), 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-08 22:28:56 +01:00
|
|
|
void CefPostDataImpl::Get(blink::WebHTTPBody& data) {
|
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;
|
2012-06-19 18:29:49 +02:00
|
|
|
ElementVector::iterator it = elements_.begin();
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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),
|
|
|
|
read_only_(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();
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
NOTREACHED();
|
|
|
|
}
|
|
|
|
|
2012-08-29 00:26:35 +02:00
|
|
|
void CefPostDataElementImpl::Get(net::UploadElement& element) {
|
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
|
|
|
|
2013-01-14 20:21:17 +01:00
|
|
|
net::UploadElementReader* CefPostDataElementImpl::Get() {
|
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);
|
|
|
|
return new BytesElementReader(make_scoped_ptr(element));
|
|
|
|
} 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);
|
|
|
|
return new FileElementReader(make_scoped_ptr(element));
|
|
|
|
} 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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-08 22:28:56 +01:00
|
|
|
void CefPostDataElementImpl::Get(blink::WebHTTPBody::Element& element) {
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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_));
|
|
|
|
}
|