2009-07-24 21:11:01 +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.
|
|
|
|
|
2008-12-02 16:48:14 +01:00
|
|
|
#include "request_impl.h"
|
2010-02-11 19:33:33 +01:00
|
|
|
#include "browser_webkit_glue.h"
|
2008-12-02 16:48:14 +01:00
|
|
|
|
|
|
|
#include "base/logging.h"
|
2010-03-29 19:53:26 +02:00
|
|
|
#include "base/utf_string_conversions.h"
|
2009-08-21 16:21:15 +02:00
|
|
|
#include "net/http/http_response_headers.h"
|
|
|
|
#include "net/http/http_util.h"
|
|
|
|
#include "net/url_request/url_request.h"
|
2010-01-12 02:37:00 +01:00
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebHTTPHeaderVisitor.h"
|
2008-12-02 16:48:14 +01:00
|
|
|
|
2009-08-21 16:21:15 +02:00
|
|
|
using net::HttpResponseHeaders;
|
|
|
|
|
2008-12-02 16:48:14 +01:00
|
|
|
|
|
|
|
CefRefPtr<CefRequest> CefRequest::CreateRequest()
|
|
|
|
{
|
|
|
|
CefRefPtr<CefRequest> request(new CefRequestImpl());
|
|
|
|
return request;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRequestImpl::CefRequestImpl()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::wstring CefRequestImpl::GetURL()
|
|
|
|
{
|
|
|
|
Lock();
|
|
|
|
std::wstring url = url_;
|
|
|
|
Unlock();
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestImpl::SetURL(const std::wstring& url)
|
|
|
|
{
|
|
|
|
Lock();
|
|
|
|
url_ = url;
|
|
|
|
Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::wstring CefRequestImpl::GetMethod()
|
|
|
|
{
|
|
|
|
Lock();
|
|
|
|
std::wstring method = method_;
|
|
|
|
Unlock();
|
|
|
|
return method;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestImpl::SetMethod(const std::wstring& method)
|
|
|
|
{
|
|
|
|
Lock();
|
|
|
|
method_ = method;
|
|
|
|
Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefPostData> CefRequestImpl::GetPostData()
|
|
|
|
{
|
|
|
|
Lock();
|
|
|
|
CefRefPtr<CefPostData> postData = postdata_;
|
|
|
|
Unlock();
|
|
|
|
return postData;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestImpl::SetPostData(CefRefPtr<CefPostData> postData)
|
|
|
|
{
|
|
|
|
Lock();
|
|
|
|
postdata_ = postData;
|
|
|
|
Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestImpl::GetHeaderMap(HeaderMap& headerMap)
|
|
|
|
{
|
|
|
|
Lock();
|
|
|
|
headerMap = headermap_;
|
|
|
|
Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestImpl::SetHeaderMap(const HeaderMap& headerMap)
|
|
|
|
{
|
|
|
|
Lock();
|
|
|
|
headermap_ = headerMap;
|
|
|
|
Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestImpl::Set(const std::wstring& url,
|
2009-05-28 02:31:21 +02:00
|
|
|
const std::wstring& method,
|
|
|
|
CefRefPtr<CefPostData> postData,
|
|
|
|
const HeaderMap& headerMap)
|
2008-12-02 16:48:14 +01:00
|
|
|
{
|
|
|
|
Lock();
|
|
|
|
url_ = url;
|
|
|
|
method_ = method;
|
|
|
|
postdata_ = postData;
|
|
|
|
headermap_ = headerMap;
|
|
|
|
Unlock();
|
|
|
|
}
|
|
|
|
|
2009-08-21 16:21:15 +02:00
|
|
|
void CefRequestImpl::Set(URLRequest* request)
|
|
|
|
{
|
|
|
|
SetURL(UTF8ToWide(request->url().spec()));
|
|
|
|
SetMethod(UTF8ToWide(request->method()));
|
|
|
|
|
|
|
|
// Transfer request headers
|
|
|
|
HeaderMap headerMap;
|
|
|
|
GetHeaderMap(request->extra_request_headers(), headerMap);
|
|
|
|
headerMap.insert(
|
|
|
|
std::make_pair(L"Referrer", UTF8ToWide(request->referrer())));
|
|
|
|
SetHeaderMap(headerMap);
|
|
|
|
|
|
|
|
// Transfer post data, if any
|
|
|
|
net::UploadData* data = request->get_upload();
|
|
|
|
if (data) {
|
|
|
|
CefRefPtr<CefPostData> postdata(CefPostData::CreatePostData());
|
|
|
|
static_cast<CefPostDataImpl*>(postdata.get())->Set(*data);
|
|
|
|
SetPostData(postdata);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-21 20:02:39 +02:00
|
|
|
|
|
|
|
void CefRequestImpl::GetHeaderMap(const net::HttpRequestHeaders& headers, HeaderMap& map)
|
|
|
|
{
|
|
|
|
net::HttpRequestHeaders::Iterator it(headers);
|
|
|
|
do {
|
|
|
|
map[UTF8ToWide(it.name())] = UTF8ToWide(it.value());
|
|
|
|
} while (it.GetNext());
|
|
|
|
}
|
|
|
|
|
2009-07-24 20:37:00 +02:00
|
|
|
void CefRequestImpl::GetHeaderMap(const WebKit::WebURLRequest& request,
|
|
|
|
HeaderMap& map)
|
2008-12-02 16:48:14 +01:00
|
|
|
{
|
2009-07-24 20:37:00 +02:00
|
|
|
class CefHTTPHeaderVisitor : public WebKit::WebHTTPHeaderVisitor {
|
|
|
|
public:
|
|
|
|
CefHTTPHeaderVisitor(HeaderMap* map) : map_(map) {}
|
|
|
|
|
|
|
|
virtual void visitHeader(const WebKit::WebString& name,
|
|
|
|
const WebKit::WebString& value) {
|
|
|
|
map_->insert(
|
|
|
|
std::make_pair(
|
|
|
|
UTF8ToWide(webkit_glue::WebStringToStdString(name)),
|
|
|
|
UTF8ToWide(webkit_glue::WebStringToStdString(value))));
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
HeaderMap* map_;
|
|
|
|
};
|
|
|
|
|
|
|
|
CefHTTPHeaderVisitor visitor(&map);
|
|
|
|
request.visitHTTPHeaderFields(&visitor);
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
|
|
|
|
2009-07-24 20:37:00 +02:00
|
|
|
void CefRequestImpl::SetHeaderMap(const HeaderMap& map,
|
|
|
|
WebKit::WebURLRequest& request)
|
2008-12-02 16:48:14 +01:00
|
|
|
{
|
2009-07-24 20:37:00 +02:00
|
|
|
HeaderMap::const_iterator it = map.begin();
|
|
|
|
for(; it != map.end(); ++it) {
|
|
|
|
request.setHTTPHeaderField(
|
|
|
|
webkit_glue::StdStringToWebString(WideToUTF8(it->first.c_str())),
|
|
|
|
webkit_glue::StdStringToWebString(WideToUTF8(it->second.c_str())));
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-30 22:26:13 +02:00
|
|
|
std::string CefRequestImpl::GenerateHeaders(const HeaderMap& map)
|
|
|
|
{
|
|
|
|
std::string headers;
|
|
|
|
|
|
|
|
for(HeaderMap::const_iterator header = map.begin();
|
|
|
|
header != map.end();
|
|
|
|
++header) {
|
|
|
|
const std::wstring& key = header->first;
|
|
|
|
const std::wstring& value = header->second;
|
|
|
|
|
|
|
|
if(!key.empty()) {
|
|
|
|
// Delimit with "\r\n".
|
|
|
|
if(!headers.empty())
|
|
|
|
headers += "\r\n";
|
|
|
|
|
|
|
|
headers += WideToUTF8(key) + ": " + WideToUTF8(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return headers;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestImpl::ParseHeaders(const std::string& header_str, HeaderMap& map)
|
2009-08-21 16:21:15 +02:00
|
|
|
{
|
|
|
|
// Parse the request header values
|
|
|
|
std::string headerStr = "HTTP/1.1 200 OK\n";
|
|
|
|
headerStr += header_str;
|
|
|
|
scoped_refptr<net::HttpResponseHeaders> headers =
|
|
|
|
new HttpResponseHeaders(net::HttpUtil::AssembleRawHeaders(
|
|
|
|
headerStr.c_str(), headerStr.length()));
|
|
|
|
void* iter = NULL;
|
|
|
|
std::string name, value;
|
|
|
|
while(headers->EnumerateHeaderLines(&iter, &name, &value))
|
|
|
|
map.insert(std::make_pair(UTF8ToWide(name), UTF8ToWide(value)));
|
|
|
|
}
|
|
|
|
|
2008-12-02 16:48:14 +01:00
|
|
|
CefRefPtr<CefPostData> CefPostData::CreatePostData()
|
|
|
|
{
|
|
|
|
CefRefPtr<CefPostData> postdata(new CefPostDataImpl());
|
|
|
|
return postdata;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefPostDataImpl::CefPostDataImpl()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t CefPostDataImpl::GetElementCount()
|
|
|
|
{
|
|
|
|
Lock();
|
|
|
|
size_t ct = elements_.size();
|
|
|
|
Unlock();
|
|
|
|
return ct;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefPostDataImpl::GetElements(ElementVector& elements)
|
|
|
|
{
|
|
|
|
Lock();
|
|
|
|
elements = elements_;
|
|
|
|
Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefPostDataImpl::RemoveElement(CefRefPtr<CefPostDataElement> element)
|
|
|
|
{
|
2009-07-24 21:11:01 +02:00
|
|
|
bool deleted = false;
|
|
|
|
|
|
|
|
Lock();
|
|
|
|
|
|
|
|
ElementVector::iterator it = elements_.begin();
|
|
|
|
for(; it != elements_.end(); ++it) {
|
|
|
|
if(it->get() == element.get()) {
|
|
|
|
elements_.erase(it);
|
|
|
|
deleted = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Unlock();
|
|
|
|
|
2008-12-02 16:48:14 +01:00
|
|
|
return deleted;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefPostDataImpl::AddElement(CefRefPtr<CefPostDataElement> element)
|
|
|
|
{
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
Lock();
|
|
|
|
|
|
|
|
// check that the element isn't already in the list before adding
|
2009-07-24 21:11:01 +02:00
|
|
|
ElementVector::const_iterator it = elements_.begin();
|
|
|
|
for(; it != elements_.end(); ++it) {
|
|
|
|
if(it->get() == element.get()) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!found)
|
|
|
|
elements_.push_back(element);
|
|
|
|
|
|
|
|
Unlock();
|
|
|
|
return !found;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefPostDataImpl::RemoveElements()
|
|
|
|
{
|
|
|
|
Lock();
|
|
|
|
elements_.clear();
|
|
|
|
Unlock();
|
|
|
|
}
|
|
|
|
|
2010-06-21 20:02:39 +02:00
|
|
|
void CefPostDataImpl::Set(net::UploadData& data)
|
2008-12-02 16:48:14 +01:00
|
|
|
{
|
|
|
|
Lock();
|
|
|
|
|
|
|
|
CefRefPtr<CefPostDataElement> postelem;
|
2010-06-21 20:02:39 +02:00
|
|
|
|
|
|
|
std::vector<net::UploadData::Element>* elements = data.elements();
|
|
|
|
std::vector<net::UploadData::Element>::const_iterator it = elements->begin();
|
|
|
|
for (; it != elements->end(); ++it) {
|
2009-07-24 21:11:01 +02:00
|
|
|
postelem = CefPostDataElement::CreatePostDataElement();
|
|
|
|
static_cast<CefPostDataElementImpl*>(postelem.get())->Set(*it);
|
|
|
|
AddElement(postelem);
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefPostDataImpl::Get(net::UploadData& data)
|
|
|
|
{
|
|
|
|
Lock();
|
|
|
|
|
2009-07-24 20:37:00 +02:00
|
|
|
net::UploadData::Element element;
|
|
|
|
std::vector<net::UploadData::Element> data_elements;
|
2009-07-24 21:11:01 +02:00
|
|
|
ElementVector::iterator it = elements_.begin();
|
|
|
|
for(; it != elements_.end(); ++it) {
|
|
|
|
static_cast<CefPostDataElementImpl*>(it->get())->Get(element);
|
|
|
|
data_elements.push_back(element);
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
2010-09-13 03:59:43 +02:00
|
|
|
data.SetElements(data_elements);
|
2008-12-02 16:48:14 +01:00
|
|
|
|
|
|
|
Unlock();
|
|
|
|
}
|
|
|
|
|
2009-07-24 20:37:00 +02:00
|
|
|
void CefPostDataImpl::Set(const WebKit::WebHTTPBody& data)
|
|
|
|
{
|
|
|
|
Lock();
|
|
|
|
|
|
|
|
CefRefPtr<CefPostDataElement> postelem;
|
|
|
|
WebKit::WebHTTPBody::Element element;
|
|
|
|
size_t size = data.elementCount();
|
2009-07-24 21:11:01 +02:00
|
|
|
for (size_t i = 0; i < size; ++i) {
|
|
|
|
if (data.elementAt(i, element)) {
|
|
|
|
postelem = CefPostDataElement::CreatePostDataElement();
|
|
|
|
static_cast<CefPostDataElementImpl*>(postelem.get())->Set(element);
|
|
|
|
AddElement(postelem);
|
|
|
|
}
|
2009-07-24 20:37:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefPostDataImpl::Get(WebKit::WebHTTPBody& data)
|
|
|
|
{
|
|
|
|
Lock();
|
|
|
|
|
|
|
|
WebKit::WebHTTPBody::Element element;
|
2009-07-24 21:11:01 +02:00
|
|
|
ElementVector::iterator it = elements_.begin();
|
|
|
|
for(; it != elements_.end(); ++it) {
|
|
|
|
static_cast<CefPostDataElementImpl*>(it->get())->Get(element);
|
|
|
|
if(element.type == WebKit::WebHTTPBody::Element::TypeData) {
|
|
|
|
data.appendData(element.data);
|
|
|
|
} else if(element.type == WebKit::WebHTTPBody::Element::TypeFile) {
|
|
|
|
data.appendFile(element.filePath);
|
|
|
|
} else {
|
|
|
|
NOTREACHED();
|
|
|
|
}
|
2009-07-24 20:37:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Unlock();
|
|
|
|
}
|
2008-12-02 16:48:14 +01:00
|
|
|
|
|
|
|
CefRefPtr<CefPostDataElement> CefPostDataElement::CreatePostDataElement()
|
|
|
|
{
|
|
|
|
CefRefPtr<CefPostDataElement> element(new CefPostDataElementImpl());
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefPostDataElementImpl::CefPostDataElementImpl()
|
|
|
|
{
|
2009-07-24 21:11:01 +02:00
|
|
|
type_ = PDE_TYPE_EMPTY;
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CefPostDataElementImpl::~CefPostDataElementImpl()
|
|
|
|
{
|
|
|
|
SetToEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefPostDataElementImpl::SetToEmpty()
|
|
|
|
{
|
|
|
|
Lock();
|
2009-07-24 21:11:01 +02:00
|
|
|
if(type_ == PDE_TYPE_BYTES)
|
2008-12-02 16:48:14 +01:00
|
|
|
free(data_.bytes.bytes);
|
2009-07-24 21:11:01 +02:00
|
|
|
else if(type_ == PDE_TYPE_FILE)
|
2008-12-02 16:48:14 +01:00
|
|
|
free(data_.filename);
|
2009-07-24 21:11:01 +02:00
|
|
|
type_ = PDE_TYPE_EMPTY;
|
2008-12-02 16:48:14 +01:00
|
|
|
Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefPostDataElementImpl::SetToFile(const std::wstring& fileName)
|
|
|
|
{
|
|
|
|
Lock();
|
|
|
|
// Clear any data currently in the element
|
|
|
|
SetToEmpty();
|
|
|
|
|
|
|
|
// Assign the new file name
|
|
|
|
size_t size = fileName.size();
|
|
|
|
wchar_t* data = static_cast<wchar_t*>(malloc((size + 1) * sizeof(wchar_t)));
|
|
|
|
DCHECK(data != NULL);
|
|
|
|
if(data == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
memcpy(static_cast<void*>(data), static_cast<const void*>(fileName.c_str()),
|
|
|
|
size * sizeof(wchar_t));
|
|
|
|
data[size] = 0;
|
|
|
|
|
|
|
|
// Assign the new data
|
2009-07-24 21:11:01 +02:00
|
|
|
type_ = PDE_TYPE_FILE;
|
2008-12-02 16:48:14 +01:00
|
|
|
data_.filename = data;
|
|
|
|
Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefPostDataElementImpl::SetToBytes(size_t size, const void* bytes)
|
|
|
|
{
|
|
|
|
Lock();
|
|
|
|
// Clear any data currently in the element
|
|
|
|
SetToEmpty();
|
|
|
|
|
|
|
|
// Assign the new data
|
|
|
|
void* data = malloc(size);
|
|
|
|
DCHECK(data != NULL);
|
|
|
|
if(data == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
memcpy(data, bytes, size);
|
|
|
|
|
2009-07-24 21:11:01 +02:00
|
|
|
type_ = PDE_TYPE_BYTES;
|
2008-12-02 16:48:14 +01:00
|
|
|
data_.bytes.bytes = data;
|
|
|
|
data_.bytes.size = size;
|
|
|
|
Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
CefPostDataElement::Type CefPostDataElementImpl::GetType()
|
|
|
|
{
|
|
|
|
Lock();
|
|
|
|
CefPostDataElement::Type type = type_;
|
|
|
|
Unlock();
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::wstring CefPostDataElementImpl::GetFile()
|
|
|
|
{
|
|
|
|
Lock();
|
2009-07-24 21:11:01 +02:00
|
|
|
DCHECK(type_ == PDE_TYPE_FILE);
|
2008-12-02 16:48:14 +01:00
|
|
|
std::wstring filename;
|
2009-07-24 21:11:01 +02:00
|
|
|
if(type_ == PDE_TYPE_FILE)
|
2008-12-02 16:48:14 +01:00
|
|
|
filename = data_.filename;
|
|
|
|
Unlock();
|
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t CefPostDataElementImpl::GetBytesCount()
|
|
|
|
{
|
|
|
|
Lock();
|
2009-07-24 21:11:01 +02:00
|
|
|
DCHECK(type_ == PDE_TYPE_BYTES);
|
2008-12-02 16:48:14 +01:00
|
|
|
size_t size = 0;
|
2009-07-24 21:11:01 +02:00
|
|
|
if(type_ == PDE_TYPE_BYTES)
|
2008-12-02 16:48:14 +01:00
|
|
|
size = data_.bytes.size;
|
|
|
|
Unlock();
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2009-06-25 17:59:48 +02:00
|
|
|
size_t CefPostDataElementImpl::GetBytes(size_t size, void* bytes)
|
2008-12-02 16:48:14 +01:00
|
|
|
{
|
|
|
|
Lock();
|
2009-07-24 21:11:01 +02:00
|
|
|
DCHECK(type_ == PDE_TYPE_BYTES);
|
2008-12-02 16:48:14 +01:00
|
|
|
size_t rv = 0;
|
2009-07-24 21:11:01 +02:00
|
|
|
if(type_ == PDE_TYPE_BYTES) {
|
2008-12-02 16:48:14 +01:00
|
|
|
rv = (size < data_.bytes.size ? size : data_.bytes.size);
|
|
|
|
memcpy(bytes, data_.bytes.bytes, rv);
|
|
|
|
}
|
|
|
|
Unlock();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefPostDataElementImpl::Set(const net::UploadData::Element& element)
|
|
|
|
{
|
|
|
|
Lock();
|
|
|
|
|
2009-07-24 21:11:01 +02:00
|
|
|
if (element.type() == net::UploadData::TYPE_BYTES) {
|
|
|
|
SetToBytes(element.bytes().size(),
|
|
|
|
static_cast<const void*>(
|
|
|
|
std::string(element.bytes().begin(),
|
|
|
|
element.bytes().end()).c_str()));
|
|
|
|
} else if (element.type() == net::UploadData::TYPE_FILE) {
|
|
|
|
SetToFile(element.file_path().value());
|
|
|
|
} else {
|
|
|
|
NOTREACHED();
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefPostDataElementImpl::Get(net::UploadData::Element& element)
|
|
|
|
{
|
|
|
|
Lock();
|
|
|
|
|
2009-07-24 21:11:01 +02:00
|
|
|
if(type_ == PDE_TYPE_BYTES) {
|
2008-12-02 16:48:14 +01:00
|
|
|
element.SetToBytes(static_cast<char*>(data_.bytes.bytes), data_.bytes.size);
|
2009-07-24 21:11:01 +02:00
|
|
|
} else if(type_ == PDE_TYPE_FILE) {
|
2009-04-28 02:29:14 +02:00
|
|
|
element.SetToFilePath(FilePath(data_.filename));
|
2009-07-24 21:11:01 +02:00
|
|
|
} else {
|
|
|
|
NOTREACHED();
|
2008-12-02 16:48:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Unlock();
|
|
|
|
}
|
|
|
|
|
2009-07-24 20:37:00 +02:00
|
|
|
void CefPostDataElementImpl::Set(const WebKit::WebHTTPBody::Element& element)
|
|
|
|
{
|
|
|
|
Lock();
|
|
|
|
|
|
|
|
if(element.type == WebKit::WebHTTPBody::Element::TypeData) {
|
|
|
|
SetToBytes(element.data.size(),
|
|
|
|
static_cast<const void*>(element.data.data()));
|
|
|
|
} else if(element.type == WebKit::WebHTTPBody::Element::TypeFile) {
|
|
|
|
SetToFile(UTF8ToWide(webkit_glue::WebStringToStdString(element.filePath)));
|
2009-07-24 21:11:01 +02:00
|
|
|
} else {
|
|
|
|
NOTREACHED();
|
2009-07-24 20:37:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefPostDataElementImpl::Get(WebKit::WebHTTPBody::Element& element)
|
|
|
|
{
|
|
|
|
Lock();
|
|
|
|
|
2009-07-24 21:11:01 +02:00
|
|
|
if(type_ == PDE_TYPE_BYTES) {
|
2009-07-24 20:37:00 +02:00
|
|
|
element.type = WebKit::WebHTTPBody::Element::TypeData;
|
|
|
|
element.data.assign(
|
|
|
|
static_cast<char*>(data_.bytes.bytes), data_.bytes.size);
|
2009-07-24 21:11:01 +02:00
|
|
|
} else if(type_ == PDE_TYPE_FILE) {
|
2009-07-24 20:37:00 +02:00
|
|
|
element.type = WebKit::WebHTTPBody::Element::TypeFile;
|
|
|
|
element.filePath.assign(
|
|
|
|
webkit_glue::StdStringToWebString(WideToUTF8(data_.filename)));
|
2009-07-24 21:11:01 +02:00
|
|
|
} else {
|
|
|
|
NOTREACHED();
|
2009-07-24 20:37:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Unlock();
|
|
|
|
}
|