mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
- Add CefURLRequest support (issue #517).
- Add CefBrowserProcessHandler interface (issue #650). - Internally re-register supported schemes with CefCookieManager after changing the storage path (issue #651). - Add CefResourceHandler callbacks for blocking cookie loading and saving (issue #652). - Allow custom scheme handlers for requests that do not originate from browser content (issue #653). - Use 'int' instead of 'RequestFlags' for CefRequest::GetFlags and SetFlags (issue #654). - Rename cef_request.h CreateObject methods to Create (issue #655). - Add #ifdef guards to cef_tuple.h to allow the use of both cef_runnable.h and base/bind.h in the same unit test source file. - Retrieve cookieable schemes as part of ClientApp::RegisterCustomSchemes and register with the global cookie manager. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@697 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
@ -10,15 +10,46 @@
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "net/url_request/url_request.h"
|
||||
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebHTTPHeaderVisitor.h"
|
||||
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
|
||||
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
|
||||
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRequest.h"
|
||||
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.h"
|
||||
|
||||
CefRefPtr<CefRequest> CefRequest::CreateRequest() {
|
||||
|
||||
#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() {
|
||||
CefRefPtr<CefRequest> request(new CefRequestImpl());
|
||||
return request;
|
||||
}
|
||||
|
||||
|
||||
// CefRequestImpl -------------------------------------------------------------
|
||||
|
||||
CefRequestImpl::CefRequestImpl()
|
||||
: method_("GET"),
|
||||
flags_(WUR_FLAG_NONE) {
|
||||
flags_(UR_FLAG_NONE),
|
||||
read_only_(false) {
|
||||
}
|
||||
|
||||
bool CefRequestImpl::IsReadOnly() {
|
||||
AutoLock lock_scope(this);
|
||||
return read_only_;
|
||||
}
|
||||
|
||||
CefString CefRequestImpl::GetURL() {
|
||||
@ -28,6 +59,7 @@ CefString CefRequestImpl::GetURL() {
|
||||
|
||||
void CefRequestImpl::SetURL(const CefString& url) {
|
||||
AutoLock lock_scope(this);
|
||||
CHECK_READONLY_RETURN_VOID();
|
||||
url_ = url;
|
||||
}
|
||||
|
||||
@ -38,6 +70,7 @@ CefString CefRequestImpl::GetMethod() {
|
||||
|
||||
void CefRequestImpl::SetMethod(const CefString& method) {
|
||||
AutoLock lock_scope(this);
|
||||
CHECK_READONLY_RETURN_VOID();
|
||||
method_ = method;
|
||||
}
|
||||
|
||||
@ -48,6 +81,7 @@ CefRefPtr<CefPostData> CefRequestImpl::GetPostData() {
|
||||
|
||||
void CefRequestImpl::SetPostData(CefRefPtr<CefPostData> postData) {
|
||||
AutoLock lock_scope(this);
|
||||
CHECK_READONLY_RETURN_VOID();
|
||||
postdata_ = postData;
|
||||
}
|
||||
|
||||
@ -58,6 +92,7 @@ void CefRequestImpl::GetHeaderMap(HeaderMap& headerMap) {
|
||||
|
||||
void CefRequestImpl::SetHeaderMap(const HeaderMap& headerMap) {
|
||||
AutoLock lock_scope(this);
|
||||
CHECK_READONLY_RETURN_VOID();
|
||||
headermap_ = headerMap;
|
||||
}
|
||||
|
||||
@ -66,21 +101,20 @@ void CefRequestImpl::Set(const CefString& url,
|
||||
CefRefPtr<CefPostData> postData,
|
||||
const HeaderMap& headerMap) {
|
||||
AutoLock lock_scope(this);
|
||||
CHECK_READONLY_RETURN_VOID();
|
||||
url_ = url;
|
||||
method_ = method;
|
||||
postdata_ = postData;
|
||||
headermap_ = headerMap;
|
||||
}
|
||||
|
||||
#define SETBOOLFLAG(obj, flags, method, FLAG) \
|
||||
obj.method((flags & (FLAG)) == (FLAG))
|
||||
|
||||
CefRequest::RequestFlags CefRequestImpl::GetFlags() {
|
||||
int CefRequestImpl::GetFlags() {
|
||||
AutoLock lock_scope(this);
|
||||
return flags_;
|
||||
}
|
||||
void CefRequestImpl::SetFlags(RequestFlags flags) {
|
||||
void CefRequestImpl::SetFlags(int flags) {
|
||||
AutoLock lock_scope(this);
|
||||
CHECK_READONLY_RETURN_VOID();
|
||||
flags_ = flags;
|
||||
}
|
||||
|
||||
@ -90,11 +124,13 @@ CefString CefRequestImpl::GetFirstPartyForCookies() {
|
||||
}
|
||||
void CefRequestImpl::SetFirstPartyForCookies(const CefString& url) {
|
||||
AutoLock lock_scope(this);
|
||||
CHECK_READONLY_RETURN_VOID();
|
||||
first_party_for_cookies_ = url;
|
||||
}
|
||||
|
||||
void CefRequestImpl::Set(net::URLRequest* request) {
|
||||
AutoLock lock_scope(this);
|
||||
CHECK_READONLY_RETURN_VOID();
|
||||
|
||||
url_ = request->url().spec();
|
||||
method_ = request->method();
|
||||
@ -121,7 +157,7 @@ void CefRequestImpl::Set(net::URLRequest* request) {
|
||||
// Transfer post data, if any
|
||||
net::UploadData* data = request->get_upload();
|
||||
if (data) {
|
||||
postdata_ = CefPostData::CreatePostData();
|
||||
postdata_ = CefPostData::Create();
|
||||
static_cast<CefPostDataImpl*>(postdata_.get())->Set(*data);
|
||||
} else if (postdata_.get()) {
|
||||
postdata_ = NULL;
|
||||
@ -160,6 +196,98 @@ void CefRequestImpl::Get(net::URLRequest* request) {
|
||||
}
|
||||
}
|
||||
|
||||
void CefRequestImpl::Set(const WebKit::WebURLRequest& request) {
|
||||
DCHECK(!request.isNull());
|
||||
|
||||
AutoLock lock_scope(this);
|
||||
CHECK_READONLY_RETURN_VOID();
|
||||
|
||||
url_ = request.url().spec().utf16();
|
||||
method_ = request.httpMethod();
|
||||
|
||||
const WebKit::WebHTTPBody& body = request.httpBody();
|
||||
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;
|
||||
if (request.cachePolicy() == WebKit::WebURLRequest::ReloadIgnoringCacheData)
|
||||
flags_ |= UR_FLAG_SKIP_CACHE;
|
||||
if (request.allowStoredCredentials())
|
||||
flags_ |= UR_FLAG_ALLOW_CACHED_CREDENTIALS;
|
||||
if (request.allowCookies())
|
||||
flags_ |= UR_FLAG_ALLOW_COOKIES;
|
||||
if (request.reportUploadProgress())
|
||||
flags_ |= UR_FLAG_REPORT_UPLOAD_PROGRESS;
|
||||
if (request.reportLoadTiming())
|
||||
flags_ |= UR_FLAG_REPORT_LOAD_TIMING;
|
||||
if (request.reportRawHeaders())
|
||||
flags_ |= UR_FLAG_REPORT_RAW_HEADERS;
|
||||
|
||||
first_party_for_cookies_ = request.firstPartyForCookies().spec().utf16();
|
||||
}
|
||||
|
||||
void CefRequestImpl::Get(WebKit::WebURLRequest& request) {
|
||||
request.initialize();
|
||||
AutoLock lock_scope(this);
|
||||
|
||||
GURL gurl = GURL(url_.ToString());
|
||||
request.setURL(WebKit::WebURL(gurl));
|
||||
|
||||
std::string method(method_);
|
||||
request.setHTTPMethod(WebKit::WebString::fromUTF8(method.c_str()));
|
||||
request.setTargetType(WebKit::WebURLRequest::TargetIsMainFrame);
|
||||
|
||||
WebKit::WebHTTPBody body;
|
||||
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) ?
|
||||
WebKit::WebURLRequest::ReloadIgnoringCacheData :
|
||||
WebKit::WebURLRequest::UseProtocolCachePolicy);
|
||||
|
||||
#define SETBOOLFLAG(obj, flags, method, FLAG) \
|
||||
obj.method((flags & (FLAG)) == (FLAG))
|
||||
|
||||
SETBOOLFLAG(request, flags_, setAllowStoredCredentials,
|
||||
UR_FLAG_ALLOW_CACHED_CREDENTIALS);
|
||||
SETBOOLFLAG(request, flags_, setAllowCookies,
|
||||
UR_FLAG_ALLOW_COOKIES);
|
||||
SETBOOLFLAG(request, flags_, setReportUploadProgress,
|
||||
UR_FLAG_REPORT_UPLOAD_PROGRESS);
|
||||
SETBOOLFLAG(request, flags_, setReportLoadTiming,
|
||||
UR_FLAG_REPORT_LOAD_TIMING);
|
||||
SETBOOLFLAG(request, flags_, setReportRawHeaders,
|
||||
UR_FLAG_REPORT_RAW_HEADERS);
|
||||
|
||||
if (!first_party_for_cookies_.empty()) {
|
||||
GURL gurl = GURL(first_party_for_cookies_.ToString());
|
||||
request.setFirstPartyForCookies(WebKit::WebURL(gurl));
|
||||
}
|
||||
}
|
||||
|
||||
void CefRequestImpl::SetReadOnly(bool read_only) {
|
||||
AutoLock lock_scope(this);
|
||||
if (read_only_ == read_only)
|
||||
return;
|
||||
|
||||
read_only_ = read_only;
|
||||
|
||||
if (postdata_.get())
|
||||
static_cast<CefPostDataImpl*>(postdata_.get())->SetReadOnly(read_only);
|
||||
}
|
||||
|
||||
// static
|
||||
void CefRequestImpl::GetHeaderMap(const net::HttpRequestHeaders& headers,
|
||||
HeaderMap& map) {
|
||||
@ -172,12 +300,53 @@ void CefRequestImpl::GetHeaderMap(const net::HttpRequestHeaders& headers,
|
||||
} while (it.GetNext());
|
||||
}
|
||||
|
||||
CefRefPtr<CefPostData> CefPostData::CreatePostData() {
|
||||
|
||||
// static
|
||||
void CefRequestImpl::GetHeaderMap(const WebKit::WebURLRequest& request,
|
||||
HeaderMap& map) {
|
||||
class HeaderVisitor : public WebKit::WebHTTPHeaderVisitor {
|
||||
public:
|
||||
explicit HeaderVisitor(HeaderMap* map) : map_(map) {}
|
||||
|
||||
virtual void visitHeader(const WebKit::WebString& name,
|
||||
const WebKit::WebString& value) {
|
||||
map_->insert(std::make_pair(string16(name), string16(value)));
|
||||
}
|
||||
|
||||
private:
|
||||
HeaderMap* map_;
|
||||
};
|
||||
|
||||
HeaderVisitor visitor(&map);
|
||||
request.visitHTTPHeaderFields(&visitor);
|
||||
}
|
||||
|
||||
// static
|
||||
void CefRequestImpl::SetHeaderMap(const HeaderMap& map,
|
||||
WebKit::WebURLRequest& request) {
|
||||
HeaderMap::const_iterator it = map.begin();
|
||||
for (; it != map.end(); ++it)
|
||||
request.setHTTPHeaderField(string16(it->first), string16(it->second));
|
||||
}
|
||||
|
||||
// CefPostData ----------------------------------------------------------------
|
||||
|
||||
// static
|
||||
CefRefPtr<CefPostData> CefPostData::Create() {
|
||||
CefRefPtr<CefPostData> postdata(new CefPostDataImpl());
|
||||
return postdata;
|
||||
}
|
||||
|
||||
CefPostDataImpl::CefPostDataImpl() {
|
||||
|
||||
// CefPostDataImpl ------------------------------------------------------------
|
||||
|
||||
CefPostDataImpl::CefPostDataImpl()
|
||||
: read_only_(false) {
|
||||
}
|
||||
|
||||
bool CefPostDataImpl::IsReadOnly() {
|
||||
AutoLock lock_scope(this);
|
||||
return read_only_;
|
||||
}
|
||||
|
||||
size_t CefPostDataImpl::GetElementCount() {
|
||||
@ -192,6 +361,7 @@ void CefPostDataImpl::GetElements(ElementVector& elements) {
|
||||
|
||||
bool CefPostDataImpl::RemoveElement(CefRefPtr<CefPostDataElement> element) {
|
||||
AutoLock lock_scope(this);
|
||||
CHECK_READONLY_RETURN(false);
|
||||
|
||||
ElementVector::iterator it = elements_.begin();
|
||||
for (; it != elements_.end(); ++it) {
|
||||
@ -208,6 +378,7 @@ bool CefPostDataImpl::AddElement(CefRefPtr<CefPostDataElement> element) {
|
||||
bool found = false;
|
||||
|
||||
AutoLock lock_scope(this);
|
||||
CHECK_READONLY_RETURN(false);
|
||||
|
||||
// check that the element isn't already in the list before adding
|
||||
ElementVector::const_iterator it = elements_.begin();
|
||||
@ -226,18 +397,20 @@ bool CefPostDataImpl::AddElement(CefRefPtr<CefPostDataElement> element) {
|
||||
|
||||
void CefPostDataImpl::RemoveElements() {
|
||||
AutoLock lock_scope(this);
|
||||
CHECK_READONLY_RETURN_VOID();
|
||||
elements_.clear();
|
||||
}
|
||||
|
||||
void CefPostDataImpl::Set(net::UploadData& data) {
|
||||
AutoLock lock_scope(this);
|
||||
CHECK_READONLY_RETURN_VOID();
|
||||
|
||||
CefRefPtr<CefPostDataElement> postelem;
|
||||
|
||||
std::vector<net::UploadData::Element>* elements = data.elements();
|
||||
std::vector<net::UploadData::Element>::const_iterator it = elements->begin();
|
||||
for (; it != elements->end(); ++it) {
|
||||
postelem = CefPostDataElement::CreatePostDataElement();
|
||||
postelem = CefPostDataElement::Create();
|
||||
static_cast<CefPostDataElementImpl*>(postelem.get())->Set(*it);
|
||||
AddElement(postelem);
|
||||
}
|
||||
@ -248,7 +421,7 @@ void CefPostDataImpl::Get(net::UploadData& data) {
|
||||
|
||||
net::UploadData::Element element;
|
||||
std::vector<net::UploadData::Element> data_elements;
|
||||
ElementVector::iterator it = elements_.begin();
|
||||
ElementVector::const_iterator it = elements_.begin();
|
||||
for (; it != elements_.end(); ++it) {
|
||||
static_cast<CefPostDataElementImpl*>(it->get())->Get(element);
|
||||
data_elements.push_back(element);
|
||||
@ -256,32 +429,89 @@ void CefPostDataImpl::Get(net::UploadData& data) {
|
||||
data.SetElements(data_elements);
|
||||
}
|
||||
|
||||
CefRefPtr<CefPostDataElement> CefPostDataElement::CreatePostDataElement() {
|
||||
void CefPostDataImpl::Set(const WebKit::WebHTTPBody& data) {
|
||||
AutoLock lock_scope(this);
|
||||
CHECK_READONLY_RETURN_VOID();
|
||||
|
||||
CefRefPtr<CefPostDataElement> postelem;
|
||||
WebKit::WebHTTPBody::Element element;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CefPostDataImpl::Get(WebKit::WebHTTPBody& data) {
|
||||
AutoLock lock_scope(this);
|
||||
|
||||
WebKit::WebHTTPBody::Element element;
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CefPostDataImpl::SetReadOnly(bool read_only) {
|
||||
AutoLock lock_scope(this);
|
||||
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() {
|
||||
CefRefPtr<CefPostDataElement> element(new CefPostDataElementImpl());
|
||||
return element;
|
||||
}
|
||||
|
||||
CefPostDataElementImpl::CefPostDataElementImpl() {
|
||||
type_ = PDE_TYPE_EMPTY;
|
||||
|
||||
// CefPostDataElementImpl -----------------------------------------------------
|
||||
|
||||
CefPostDataElementImpl::CefPostDataElementImpl()
|
||||
: type_(PDE_TYPE_EMPTY),
|
||||
read_only_(false) {
|
||||
memset(&data_, 0, sizeof(data_));
|
||||
}
|
||||
|
||||
CefPostDataElementImpl::~CefPostDataElementImpl() {
|
||||
SetToEmpty();
|
||||
Cleanup();
|
||||
}
|
||||
|
||||
bool CefPostDataElementImpl::IsReadOnly() {
|
||||
AutoLock lock_scope(this);
|
||||
return read_only_;
|
||||
}
|
||||
|
||||
void CefPostDataElementImpl::SetToEmpty() {
|
||||
AutoLock lock_scope(this);
|
||||
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_));
|
||||
CHECK_READONLY_RETURN_VOID();
|
||||
|
||||
Cleanup();
|
||||
}
|
||||
|
||||
void CefPostDataElementImpl::SetToFile(const CefString& fileName) {
|
||||
AutoLock lock_scope(this);
|
||||
CHECK_READONLY_RETURN_VOID();
|
||||
|
||||
// Clear any data currently in the element
|
||||
SetToEmpty();
|
||||
|
||||
@ -292,6 +522,8 @@ void CefPostDataElementImpl::SetToFile(const CefString& fileName) {
|
||||
|
||||
void CefPostDataElementImpl::SetToBytes(size_t size, const void* bytes) {
|
||||
AutoLock lock_scope(this);
|
||||
CHECK_READONLY_RETURN_VOID();
|
||||
|
||||
// Clear any data currently in the element
|
||||
SetToEmpty();
|
||||
|
||||
@ -344,6 +576,7 @@ size_t CefPostDataElementImpl::GetBytes(size_t size, void* bytes) {
|
||||
|
||||
void CefPostDataElementImpl::Set(const net::UploadData::Element& element) {
|
||||
AutoLock lock_scope(this);
|
||||
CHECK_READONLY_RETURN_VOID();
|
||||
|
||||
if (element.type() == net::UploadData::TYPE_BYTES) {
|
||||
SetToBytes(element.bytes().size(),
|
||||
@ -369,3 +602,52 @@ void CefPostDataElementImpl::Get(net::UploadData::Element& element) {
|
||||
NOTREACHED();
|
||||
}
|
||||
}
|
||||
|
||||
void CefPostDataElementImpl::Set(const WebKit::WebHTTPBody::Element& element) {
|
||||
AutoLock lock_scope(this);
|
||||
CHECK_READONLY_RETURN_VOID();
|
||||
|
||||
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(string16(element.filePath));
|
||||
} else {
|
||||
NOTREACHED();
|
||||
}
|
||||
}
|
||||
|
||||
void CefPostDataElementImpl::Get(WebKit::WebHTTPBody::Element& element) {
|
||||
AutoLock lock_scope(this);
|
||||
|
||||
if (type_ == PDE_TYPE_BYTES) {
|
||||
element.type = WebKit::WebHTTPBody::Element::TypeData;
|
||||
element.data.assign(
|
||||
static_cast<char*>(data_.bytes.bytes), data_.bytes.size);
|
||||
} else if (type_ == PDE_TYPE_FILE) {
|
||||
element.type = WebKit::WebHTTPBody::Element::TypeFile;
|
||||
element.filePath.assign(string16(CefString(&data_.filename)));
|
||||
} else {
|
||||
NOTREACHED();
|
||||
}
|
||||
}
|
||||
|
||||
void CefPostDataElementImpl::SetReadOnly(bool read_only) {
|
||||
AutoLock lock_scope(this);
|
||||
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_));
|
||||
}
|
||||
|
Reference in New Issue
Block a user