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:
@ -4,12 +4,43 @@
|
||||
|
||||
#include "libcef/common/response_impl.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/stringprintf.h"
|
||||
#include "net/http/http_request_headers.h"
|
||||
#include "net/http/http_response_headers.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/WebURLResponse.h"
|
||||
|
||||
|
||||
#define CHECK_READONLY_RETURN_VOID() \
|
||||
if (read_only_) { \
|
||||
NOTREACHED() << "object is read only"; \
|
||||
return; \
|
||||
}
|
||||
|
||||
|
||||
// CefResponse ----------------------------------------------------------------
|
||||
|
||||
// static
|
||||
CefRefPtr<CefResponse> CefResponse::Create() {
|
||||
CefRefPtr<CefResponse> response(new CefResponseImpl());
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
// CefResponseImpl ------------------------------------------------------------
|
||||
|
||||
CefResponseImpl::CefResponseImpl()
|
||||
: status_code_(0) {
|
||||
: status_code_(0),
|
||||
read_only_(false) {
|
||||
}
|
||||
|
||||
bool CefResponseImpl::IsReadOnly() {
|
||||
AutoLock lock_scope(this);
|
||||
return read_only_;
|
||||
}
|
||||
|
||||
int CefResponseImpl::GetStatus() {
|
||||
@ -19,6 +50,7 @@ int CefResponseImpl::GetStatus() {
|
||||
|
||||
void CefResponseImpl::SetStatus(int status) {
|
||||
AutoLock lock_scope(this);
|
||||
CHECK_READONLY_RETURN_VOID();
|
||||
status_code_ = status;
|
||||
}
|
||||
|
||||
@ -29,6 +61,7 @@ CefString CefResponseImpl::GetStatusText() {
|
||||
|
||||
void CefResponseImpl::SetStatusText(const CefString& statusText) {
|
||||
AutoLock lock_scope(this);
|
||||
CHECK_READONLY_RETURN_VOID();
|
||||
status_text_ = statusText;
|
||||
}
|
||||
|
||||
@ -39,6 +72,7 @@ CefString CefResponseImpl::GetMimeType() {
|
||||
|
||||
void CefResponseImpl::SetMimeType(const CefString& mimeType) {
|
||||
AutoLock lock_scope(this);
|
||||
CHECK_READONLY_RETURN_VOID();
|
||||
mime_type_ = mimeType;
|
||||
}
|
||||
|
||||
@ -61,6 +95,7 @@ void CefResponseImpl::GetHeaderMap(HeaderMap& map) {
|
||||
|
||||
void CefResponseImpl::SetHeaderMap(const HeaderMap& headerMap) {
|
||||
AutoLock lock_scope(this);
|
||||
CHECK_READONLY_RETURN_VOID();
|
||||
header_map_ = headerMap;
|
||||
}
|
||||
|
||||
@ -69,11 +104,12 @@ net::HttpResponseHeaders* CefResponseImpl::GetResponseHeaders() {
|
||||
|
||||
std::string response;
|
||||
std::string status_text;
|
||||
bool has_content_type_header = false;
|
||||
|
||||
if (status_text_.empty())
|
||||
status_text = (status_code_ == 200)?"OK":"ERROR";
|
||||
else
|
||||
if (!status_text_.empty())
|
||||
status_text = status_text_;
|
||||
else
|
||||
status_text = (status_code_ == 200)?"OK":"ERROR";
|
||||
|
||||
base::SStringPrintf(&response, "HTTP/1.1 %d %s", status_code_,
|
||||
status_text.c_str());
|
||||
@ -90,9 +126,79 @@ net::HttpResponseHeaders* CefResponseImpl::GetResponseHeaders() {
|
||||
std::string value_str(value);
|
||||
base::StringAppendF(&response, "%c%s: %s", '\0', key_str.c_str(),
|
||||
value_str.c_str());
|
||||
|
||||
if (!has_content_type_header &&
|
||||
key_str == net::HttpRequestHeaders::kContentType) {
|
||||
has_content_type_header = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!has_content_type_header) {
|
||||
std::string mime_type;
|
||||
if (!mime_type_.empty())
|
||||
mime_type = mime_type_;
|
||||
else
|
||||
mime_type = "text/html";
|
||||
|
||||
base::StringAppendF(&response, "%c%s: %s", '\0',
|
||||
net::HttpRequestHeaders::kContentType, mime_type.c_str());
|
||||
}
|
||||
|
||||
return new net::HttpResponseHeaders(response);
|
||||
}
|
||||
|
||||
void CefResponseImpl::SetResponseHeaders(
|
||||
const net::HttpResponseHeaders& headers) {
|
||||
AutoLock lock_scope(this);
|
||||
|
||||
header_map_.empty();
|
||||
|
||||
void* iter = NULL;
|
||||
std::string name, value;
|
||||
while (headers.EnumerateHeaderLines(&iter, &name, &value))
|
||||
header_map_.insert(std::make_pair(name, value));
|
||||
|
||||
status_code_ = headers.response_code();
|
||||
status_text_ = headers.GetStatusText();
|
||||
|
||||
std::string mime_type;
|
||||
if (headers.GetMimeType(&mime_type))
|
||||
mime_type_ = mime_type;
|
||||
}
|
||||
|
||||
void CefResponseImpl::Set(const WebKit::WebURLResponse& response) {
|
||||
DCHECK(!response.isNull());
|
||||
|
||||
AutoLock lock_scope(this);
|
||||
CHECK_READONLY_RETURN_VOID();
|
||||
|
||||
WebKit::WebString str;
|
||||
status_code_ = response.httpStatusCode();
|
||||
str = response.httpStatusText();
|
||||
status_text_ = CefString(str);
|
||||
str = response.mimeType();
|
||||
mime_type_ = CefString(str);
|
||||
|
||||
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(&header_map_);
|
||||
response.visitHTTPHeaderFields(&visitor);
|
||||
}
|
||||
|
||||
void CefResponseImpl::SetReadOnly(bool read_only) {
|
||||
AutoLock lock_scope(this);
|
||||
read_only_ = read_only;
|
||||
}
|
||||
|
Reference in New Issue
Block a user