mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
- Add CefPostData::HasExcludedElements which returns true if the underlying
POST data includes elements that are not represented (issue #1761). - Add CefRequest::SetReferrer and CefRequest::GetReferrer[URL|Policy]. The Referer value will no longer be stored in the header map. - Move request-related conversion logic to CefRequestImpl and standardize the implementation.
This commit is contained in:
@ -11,6 +11,7 @@
|
||||
#include "libcef/common/cef_messages.h"
|
||||
#include "libcef/common/content_client.h"
|
||||
#include "libcef/common/process_message_impl.h"
|
||||
#include "libcef/common/request_impl.h"
|
||||
#include "libcef/common/response_manager.h"
|
||||
#include "libcef/renderer/content_renderer_client.h"
|
||||
#include "libcef/renderer/dom_document_impl.h"
|
||||
@ -19,14 +20,12 @@
|
||||
|
||||
#include "base/strings/string16.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "content/public/renderer/document_state.h"
|
||||
#include "content/public/renderer/navigation_state.h"
|
||||
#include "content/public/renderer/render_view.h"
|
||||
#include "content/renderer/navigation_state_impl.h"
|
||||
#include "content/renderer/render_view_impl.h"
|
||||
#include "net/http/http_util.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"
|
||||
@ -46,19 +45,6 @@ using blink::WebString;
|
||||
using blink::WebURL;
|
||||
using blink::WebView;
|
||||
|
||||
namespace {
|
||||
|
||||
blink::WebString FilePathStringToWebString(
|
||||
const base::FilePath::StringType& str) {
|
||||
#if defined(OS_POSIX)
|
||||
return base::WideToUTF16(base::SysNativeMBToWide(str));
|
||||
#elif defined(OS_WIN)
|
||||
return base::WideToUTF16(str);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
// CefBrowserImpl static methods.
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -305,68 +291,8 @@ void CefBrowserImpl::LoadRequest(const CefMsg_LoadRequest_Params& params) {
|
||||
|
||||
WebFrame* web_frame = framePtr->web_frame();
|
||||
|
||||
blink::WebURLRequest request(params.url);
|
||||
|
||||
if (!params.method.empty())
|
||||
request.setHTTPMethod(base::ASCIIToUTF16(params.method));
|
||||
|
||||
if (params.referrer.is_valid()) {
|
||||
WebString referrer = blink::WebSecurityPolicy::generateReferrerHeader(
|
||||
static_cast<blink::WebReferrerPolicy>(params.referrer_policy),
|
||||
params.url,
|
||||
WebString::fromUTF8(params.referrer.spec()));
|
||||
if (!referrer.isEmpty())
|
||||
request.setHTTPHeaderField(WebString::fromUTF8("Referer"), referrer);
|
||||
}
|
||||
|
||||
if (params.first_party_for_cookies.is_valid())
|
||||
request.setFirstPartyForCookies(params.first_party_for_cookies);
|
||||
|
||||
if (!params.headers.empty()) {
|
||||
for (net::HttpUtil::HeadersIterator i(params.headers.begin(),
|
||||
params.headers.end(), "\n");
|
||||
i.GetNext(); ) {
|
||||
request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
|
||||
WebString::fromUTF8(i.values()));
|
||||
}
|
||||
}
|
||||
|
||||
if (params.upload_data.get()) {
|
||||
base::string16 method = request.httpMethod();
|
||||
if (method == base::ASCIIToUTF16("GET") ||
|
||||
method == base::ASCIIToUTF16("HEAD")) {
|
||||
request.setHTTPMethod(base::ASCIIToUTF16("POST"));
|
||||
}
|
||||
|
||||
if (request.httpHeaderField(
|
||||
base::ASCIIToUTF16("Content-Type")).length() == 0) {
|
||||
request.setHTTPHeaderField(
|
||||
base::ASCIIToUTF16("Content-Type"),
|
||||
base::ASCIIToUTF16("application/x-www-form-urlencoded"));
|
||||
}
|
||||
|
||||
blink::WebHTTPBody body;
|
||||
body.initialize();
|
||||
|
||||
const ScopedVector<net::UploadElement>& elements =
|
||||
params.upload_data->elements();
|
||||
ScopedVector<net::UploadElement>::const_iterator it =
|
||||
elements.begin();
|
||||
for (; it != elements.end(); ++it) {
|
||||
const net::UploadElement& element = **it;
|
||||
if (element.type() == net::UploadElement::TYPE_BYTES) {
|
||||
blink::WebData data;
|
||||
data.assign(element.bytes(), element.bytes_length());
|
||||
body.appendData(data);
|
||||
} else if (element.type() == net::UploadElement::TYPE_FILE) {
|
||||
body.appendFile(FilePathStringToWebString(element.file_path().value()));
|
||||
} else {
|
||||
NOTREACHED();
|
||||
}
|
||||
}
|
||||
|
||||
request.setHTTPBody(body);
|
||||
}
|
||||
blink::WebURLRequest request;
|
||||
CefRequestImpl::Get(params, request);
|
||||
|
||||
web_frame->loadRequest(request);
|
||||
}
|
||||
|
Reference in New Issue
Block a user