libcef:
- Parse request headers and pass to the scheme handler. - Fix memory leak in scheme handler implementation. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@38 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
parent
087319efdb
commit
b821811c08
|
@ -229,28 +229,17 @@ class RequestProxy : public URLRequest::Delegate,
|
|||
requestimpl->SetURL(UTF8ToWide(params->url.spec()));
|
||||
requestimpl->SetMethod(UTF8ToWide(params->method));
|
||||
|
||||
// Transfer request headers
|
||||
CefRequest::HeaderMap headerMap;
|
||||
|
||||
// Parse the request header values
|
||||
std::string headerStr = "HTTP/1.1 200 OK\n";
|
||||
headerStr += params->headers;
|
||||
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))
|
||||
headerMap.insert(std::make_pair(UTF8ToWide(name), UTF8ToWide(value)));
|
||||
|
||||
CefRequestImpl::GetHeaderMap(params->headers, headerMap);
|
||||
headerMap.insert(
|
||||
std::make_pair(L"Referrer", UTF8ToWide(params->referrer.spec())));
|
||||
|
||||
requestimpl->SetHeaderMap(headerMap);
|
||||
|
||||
// Transfer post data, if any
|
||||
scoped_refptr<net::UploadData> upload = params->upload;
|
||||
CefRefPtr<CefPostData> postdata;
|
||||
if(upload.get()) {
|
||||
postdata = new CefPostDataImpl();
|
||||
CefRefPtr<CefPostData> postdata(new CefPostDataImpl());
|
||||
static_cast<CefPostDataImpl*>(postdata.get())->Set(*upload.get());
|
||||
requestimpl->SetPostData(postdata);
|
||||
}
|
||||
|
|
|
@ -7,9 +7,14 @@
|
|||
|
||||
#include "base/logging.h"
|
||||
#include "base/string_util.h"
|
||||
#include "net/http/http_response_headers.h"
|
||||
#include "net/http/http_util.h"
|
||||
#include "net/url_request/url_request.h"
|
||||
#include "webkit/api/public/WebHTTPHeaderVisitor.h"
|
||||
#include "webkit/glue/glue_util.h"
|
||||
|
||||
using net::HttpResponseHeaders;
|
||||
|
||||
|
||||
CefRefPtr<CefRequest> CefRequest::CreateRequest()
|
||||
{
|
||||
|
@ -93,6 +98,27 @@ void CefRequestImpl::Set(const std::wstring& url,
|
|||
Unlock();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void CefRequestImpl::GetHeaderMap(const WebKit::WebURLRequest& request,
|
||||
HeaderMap& map)
|
||||
{
|
||||
|
@ -127,6 +153,20 @@ void CefRequestImpl::SetHeaderMap(const HeaderMap& map,
|
|||
}
|
||||
}
|
||||
|
||||
void CefRequestImpl::GetHeaderMap(const std::string& header_str, HeaderMap& map)
|
||||
{
|
||||
// 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)));
|
||||
}
|
||||
|
||||
CefRefPtr<CefPostData> CefPostData::CreatePostData()
|
||||
{
|
||||
CefRefPtr<CefPostData> postdata(new CefPostDataImpl());
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "webkit/api/public/WebHTTPBody.h"
|
||||
#include "webkit/api/public/WebURLRequest.h"
|
||||
|
||||
class URLRequest;
|
||||
|
||||
// Implementation of CefRequest
|
||||
class CefRequestImpl : public CefThreadSafeBase<CefRequest>
|
||||
|
@ -31,11 +32,15 @@ public:
|
|||
CefRefPtr<CefPostData> postData,
|
||||
const HeaderMap& headerMap);
|
||||
|
||||
void Set(URLRequest* request);
|
||||
|
||||
static void GetHeaderMap(const WebKit::WebURLRequest& request,
|
||||
HeaderMap& map);
|
||||
static void SetHeaderMap(const HeaderMap& map,
|
||||
WebKit::WebURLRequest& request);
|
||||
|
||||
static void GetHeaderMap(const std::string& header_str, HeaderMap& map);
|
||||
|
||||
protected:
|
||||
std::wstring url_;
|
||||
std::wstring method_;
|
||||
|
|
|
@ -183,16 +183,10 @@ private:
|
|||
//////////////////////////////////////////////////////////////////////////
|
||||
// safe to perform long operation here
|
||||
CefRefPtr<CefRequest> req(CefRequest::CreateRequest());
|
||||
req->SetURL(UTF8ToWide(url.spec()));
|
||||
req->SetMethod(UTF8ToWide(owner_->request()->method()));
|
||||
|
||||
// check to see if we have post data
|
||||
net::UploadData* data = owner_->request()->get_upload();
|
||||
if (data) {
|
||||
CefRefPtr<CefPostData> postdata(CefPostData::CreatePostData());
|
||||
static_cast<CefPostDataImpl*>(postdata.get())->Set(*data);
|
||||
req->SetPostData(postdata);
|
||||
}
|
||||
// populate the request data
|
||||
static_cast<CefRequestImpl*>(req.get())->Set(owner_->request());
|
||||
|
||||
owner_->handler_->Cancel();
|
||||
std::wstring mime_type;
|
||||
int response_length = 0;
|
||||
|
@ -386,7 +380,7 @@ public:
|
|||
}
|
||||
|
||||
void AddRef() {}
|
||||
void Release() {}
|
||||
void Release() { delete this; }
|
||||
|
||||
private:
|
||||
CefSchemeHandlerFactory* factory_;
|
||||
|
|
Loading…
Reference in New Issue