Move LoadRequest execution to the browser process and use data: URLs for LoadString (issue #579).

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1765 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2014-07-10 18:22:09 +00:00
parent 49fa439594
commit b9781aa000
12 changed files with 280 additions and 354 deletions

View File

@ -26,3 +26,4 @@ Corey Lucier <clucier@adobe.com>
Mihai Tica <mitica@adobe.com>
Czarek Tomczak <czarek.tomczak@gmail.com>
Felix Bruns <felixbruns@spotify.com>
Gonzo Berman <gberman@factset.com>

View File

@ -932,8 +932,6 @@
'libcef/browser/menu_creator.h',
'libcef/browser/menu_model_impl.cc',
'libcef/browser/menu_model_impl.h',
'libcef/browser/navigate_params.cc',
'libcef/browser/navigate_params.h',
'libcef/browser/origin_whitelist_impl.cc',
'libcef/browser/origin_whitelist_impl.h',
'libcef/browser/path_util_impl.cc',

View File

@ -17,7 +17,6 @@
#include "libcef/browser/devtools_delegate.h"
#include "libcef/browser/devtools_frontend.h"
#include "libcef/browser/media_capture_devices_dispatcher.h"
#include "libcef/browser/navigate_params.h"
#include "libcef/browser/printing/print_view_manager.h"
#include "libcef/browser/render_widget_host_view_osr.h"
#include "libcef/browser/request_context_impl.h"
@ -32,6 +31,7 @@
#include "libcef/common/process_message_impl.h"
#include "libcef/common/request_impl.h"
#include "base/base64.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/command_line.h"
@ -263,6 +263,143 @@ class CefRunFileDialogCallbackWrapper
CefRefPtr<CefRunFileDialogCallback> callback_;
};
class NavigationHelper {
public:
static content::NavigationController::LoadURLParams GetParams(
int64 frame_id,
const std::string& url) {
content::NavigationController::LoadURLParams params(
GetGURL(url));
params.frame_tree_node_id = frame_id;
params.transition_type = content::PAGE_TRANSITION_TYPED;
return params;
}
static content::NavigationController::LoadURLParams GetParams(
int64 frame_id,
CefRefPtr<CefRequest> request) {
content::NavigationController::LoadURLParams params(
GetGURL(request->GetURL()));
params.frame_tree_node_id = frame_id;
params.transition_type =
static_cast<content::PageTransition>(request->GetTransitionType());
params.extra_headers = GetHeaders(request);
if (request->GetMethod() == "POST") {
params.load_type =
content::NavigationController::LOAD_TYPE_BROWSER_INITIATED_HTTP_POST;
params.browser_initiated_post_data = GetPostData(request->GetPostData());
}
return params;
}
static content::NavigationController::LoadURLParams GetParams(
int64 frame_id,
const std::string& data,
const std::string& url) {
content::NavigationController::LoadURLParams params(GetDataURL(data));
params.frame_tree_node_id = frame_id;
params.load_type = content::NavigationController::LOAD_TYPE_DATA;
params.virtual_url_for_data_url = GURL(url);
params.base_url_for_data_url = GURL(url);
return params;
}
static content::NavigationController::LoadURLParams GetParams(
const content::OpenURLParams& content_params) {
GURL gurl = GetGURL(content_params.url.spec());
content::NavigationController::LoadURLParams params(gurl);
params.frame_tree_node_id = CefFrameHostImpl::kMainFrameId;
params.referrer = content_params.referrer;
params.transition_type = content_params.transition;
params.extra_headers = content_params.extra_headers;
return params;
}
static content::NavigationController::LoadURLParams GetParams(
const CefHostMsg_LoadRequest_Params& request_params) {
content::NavigationController::LoadURLParams params(request_params.url);
params.referrer.url = request_params.referrer;
params.referrer.policy =
static_cast<blink::WebReferrerPolicy>(request_params.referrer_policy);
params.frame_tree_node_id = request_params.frame_id;
params.extra_headers = request_params.headers;
if (request_params.method == "POST") {
params.load_type =
content::NavigationController::LOAD_TYPE_BROWSER_INITIATED_HTTP_POST;
params.browser_initiated_post_data =
GetPostData(request_params.upload_data);
}
return params;
}
private:
static GURL GetDataURL(const std::string& data) {
std::string encoded_data;
base::Base64Encode(data, &encoded_data);
GURL gurl("data:text/html;charset=UTF-8;base64," + encoded_data);
return gurl;
}
static GURL GetGURL(const std::string& url) {
GURL gurl(url);
if (!gurl.is_valid() && !gurl.has_scheme()) {
// Try to add "http://" at the beginning
std::string new_url = std::string("http://") + url;
gurl = GURL(new_url);
}
return gurl;
}
static std::string GetHeaders(CefRefPtr<CefRequest> request) {
CefRequest::HeaderMap headerMap;
request->GetHeaderMap(headerMap);
if (!headerMap.empty()) {
return HttpHeaderUtils::GenerateHeaders(headerMap);
}
return std::string();
}
static base::RefCountedBytes* GetPostData(
CefRefPtr<CefPostData> postData) {
if (postData.get()) {
CefPostDataImpl* impl = static_cast<CefPostDataImpl*>(postData.get());
scoped_refptr<net::UploadData> upload_data = new net::UploadData();
impl->Get(*upload_data);
return GetPostData(upload_data);
}
return NULL;
}
static base::RefCountedBytes* GetPostData(
scoped_refptr<net::UploadData> upload_data) {
if (upload_data.get()) {
std::vector<unsigned char> body;
if (!upload_data->elements().empty()) {
const net::UploadElement* elem = upload_data->elements().front();
if (elem) {
body.insert(body.end(), elem->bytes(),
elem->bytes() + elem->bytes_length());
}
}
return base::RefCountedBytes::TakeVector(&body);
}
return NULL;
}
};
} // namespace
@ -373,8 +510,7 @@ CefRefPtr<CefBrowserHostImpl> CefBrowserHostImpl::Create(
CefBrowserHostImpl::CreateInternal(windowInfo, settings, client, NULL,
info, opener, request_context);
if (browser && !url.empty()) {
browser->LoadURL(CefFrameHostImpl::kMainFrameId, url, content::Referrer(),
content::PAGE_TRANSITION_TYPED, std::string());
browser->LoadURL(CefFrameHostImpl::kMainFrameId, url);
}
return browser.get();
}
@ -1440,122 +1576,18 @@ CefRefPtr<CefFrame> CefBrowserHostImpl::GetFrameForRequest(
GURL());
}
void CefBrowserHostImpl::Navigate(const CefNavigateParams& params) {
// Only known frame ids and kMainFrameId are supported.
DCHECK(params.frame_id >= CefFrameHostImpl::kMainFrameId);
CefMsg_LoadRequest_Params request;
request.url = params.url;
if (!request.url.is_valid()) {
LOG(ERROR) << "Invalid URL passed to CefBrowserHostImpl::Navigate: " <<
params.url;
return;
}
request.method = params.method;
request.referrer = params.referrer.url;
request.referrer_policy = params.referrer.policy;
request.frame_id = params.frame_id;
request.first_party_for_cookies = params.first_party_for_cookies;
request.headers = params.headers;
request.load_flags = params.load_flags;
request.upload_data = params.upload_data;
Send(new CefMsg_LoadRequest(routing_id(), request));
OnSetFocus(FOCUS_SOURCE_NAVIGATION);
}
void CefBrowserHostImpl::LoadRequest(int64 frame_id,
CefRefPtr<CefRequest> request) {
CefNavigateParams params(GURL(std::string(request->GetURL())),
content::PAGE_TRANSITION_TYPED);
params.method = request->GetMethod();
params.frame_id = frame_id;
params.first_party_for_cookies =
GURL(std::string(request->GetFirstPartyForCookies()));
CefRequest::HeaderMap headerMap;
request->GetHeaderMap(headerMap);
if (!headerMap.empty())
params.headers = HttpHeaderUtils::GenerateHeaders(headerMap);
CefRefPtr<CefPostData> postData = request->GetPostData();
if (postData.get()) {
CefPostDataImpl* impl = static_cast<CefPostDataImpl*>(postData.get());
params.upload_data = new net::UploadData();
impl->Get(*params.upload_data.get());
}
params.load_flags = request->GetFlags();
Navigate(params);
Navigate(NavigationHelper::GetParams(frame_id, request));
}
void CefBrowserHostImpl::LoadURL(
int64 frame_id,
const std::string& url,
const content::Referrer& referrer,
content::PageTransition transition,
const std::string& extra_headers) {
if (frame_id == CefFrameHostImpl::kMainFrameId) {
// Go through the navigation controller.
if (CEF_CURRENTLY_ON_UIT()) {
if (web_contents_.get()) {
GURL gurl = GURL(url);
if (!gurl.is_valid() && !gurl.has_scheme()) {
// Try to add "http://" at the beginning
std::string new_url = std::string("http://") + url;
gurl = GURL(new_url);
}
if (!gurl.is_valid()) {
LOG(ERROR) <<
"Invalid URL passed to CefBrowserHostImpl::LoadURL: " << url;
return;
}
// Update the loading URL.
OnLoadingURLChange(gurl);
web_contents_->GetController().LoadURL(
gurl,
referrer,
transition,
extra_headers);
OnSetFocus(FOCUS_SOURCE_NAVIGATION);
}
} else {
CEF_POST_TASK(CEF_UIT,
base::Bind(&CefBrowserHostImpl::LoadURL, this, frame_id, url,
referrer, transition, extra_headers));
}
} else {
CefNavigateParams params(GURL(url), transition);
params.frame_id = frame_id;
params.referrer = referrer;
params.headers = extra_headers;
Navigate(params);
}
void CefBrowserHostImpl::LoadURL(int64 frame_id, const std::string& url) {
Navigate(NavigationHelper::GetParams(frame_id, url));
}
void CefBrowserHostImpl::LoadString(int64 frame_id, const std::string& string,
const std::string& url) {
// Only known frame ids or kMainFrameId are supported.
DCHECK(frame_id >= CefFrameHostImpl::kMainFrameId);
Cef_Request_Params params;
params.name = "load-string";
params.frame_id = frame_id;
params.user_initiated = false;
params.request_id = -1;
params.expect_response = false;
params.arguments.Append(base::Value::CreateStringValue(string));
params.arguments.Append(base::Value::CreateStringValue(url));
Send(new CefMsg_Request(routing_id(), params));
Navigate(NavigationHelper::GetParams(frame_id, string, url));
}
void CefBrowserHostImpl::SendCommand(
@ -1922,6 +1954,34 @@ void CefBrowserHostImpl::DragSourceEndedAt(
}
void CefBrowserHostImpl::Navigate(
const content::NavigationController::LoadURLParams& params) {
// Only known frame ids and kMainFrameId are supported.
DCHECK(params.frame_tree_node_id >= CefFrameHostImpl::kMainFrameId);
// Go through the navigation controller.
if (CEF_CURRENTLY_ON_UIT()) {
if (web_contents_.get()) {
if (!params.url.is_valid()) {
LOG(ERROR)
<< "Invalid URL passed to CefBrowserHostImpl::LoadURLWithParams: "
<< params.url.spec();
return;
}
// Update the loading URL.
OnLoadingURLChange(params.url);
web_contents_->GetController().LoadURLWithParams(params);
OnSetFocus(FOCUS_SOURCE_NAVIGATION);
}
} else {
CEF_POST_TASK(CEF_UIT,
base::Bind(&CefBrowserHostImpl::Navigate, this, params));
}
}
// content::WebContentsDelegate methods.
// -----------------------------------------------------------------------------
@ -1930,8 +1990,7 @@ content::WebContents* CefBrowserHostImpl::OpenURLFromTab(
const content::OpenURLParams& params) {
// Start a navigation that will result in the creation of a new render
// process.
LoadURL(CefFrameHostImpl::kMainFrameId, params.url.spec(), params.referrer,
params.transition, params.extra_headers);
Navigate(NavigationHelper::GetParams(params));
return source;
}
@ -2432,6 +2491,7 @@ bool CefBrowserHostImpl::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(CefHostMsg_Request, OnRequest)
IPC_MESSAGE_HANDLER(CefHostMsg_Response, OnResponse)
IPC_MESSAGE_HANDLER(CefHostMsg_ResponseAck, OnResponseAck)
IPC_MESSAGE_HANDLER(CefHostMsg_LoadRequest, OnLoadRequest)
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PDFHasUnsupportedFeature,
OnPDFHasUnsupportedFeature)
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PDFSaveURLAs, OnPDFSaveURLAs)
@ -2534,6 +2594,11 @@ void CefBrowserHostImpl::OnResponseAck(int request_id) {
response_manager_->RunAckHandler(request_id);
}
void CefBrowserHostImpl::OnLoadRequest(
const CefHostMsg_LoadRequest_Params& request_params) {
Navigate(NavigationHelper::GetParams(request_params));
}
void CefBrowserHostImpl::OnPDFHasUnsupportedFeature() {
// TODO(cef): Use Adobe PDF plugin instead. See PDFHasUnsupportedFeature in
// chrome/browser/ui/pdf/pdf_unsupported_feature.cc.

View File

@ -64,11 +64,11 @@ class Widget;
class CefWindowX11;
#endif
struct CefHostMsg_LoadRequest_Params;
struct Cef_Request_Params;
struct Cef_Response_Params;
class CefBrowserInfo;
class CefDevToolsFrontend;
struct CefNavigateParams;
class SiteInstance;
// Implementation of CefBrowser.
@ -237,17 +237,13 @@ class CefBrowserHostImpl : public CefBrowserHost,
CefRefPtr<CefFrame> GetFrameForRequest(net::URLRequest* request);
// Navigate as specified by the |params| argument.
void Navigate(const CefNavigateParams& params);
void Navigate(const content::NavigationController::LoadURLParams& params);
// Load the specified request.
void LoadRequest(int64 frame_id, CefRefPtr<CefRequest> request);
// Load the specified URL.
void LoadURL(int64 frame_id,
const std::string& url,
const content::Referrer& referrer,
content::PageTransition transition,
const std::string& extra_headers);
void LoadURL(int64 frame_id, const std::string& url);
// Load the specified string.
void LoadString(int64 frame_id, const std::string& string,
@ -456,6 +452,7 @@ class CefBrowserHostImpl : public CefBrowserHost,
void OnRequest(const Cef_Request_Params& params);
void OnResponse(const Cef_Response_Params& params);
void OnResponseAck(int request_id);
void OnLoadRequest(const CefHostMsg_LoadRequest_Params& params);
void OnPDFHasUnsupportedFeature();
void OnPDFSaveURLAs(const GURL& url,
const content::Referrer& referrer);

View File

@ -136,8 +136,7 @@ void CefFrameHostImpl::LoadURL(const CefString& url) {
}
if (browser) {
browser->LoadURL(frame_id, url, content::Referrer(),
content::PAGE_TRANSITION_TYPED, std::string());
browser->LoadURL(frame_id, url);
}
}

View File

@ -1,20 +0,0 @@
// Copyright (c) 2012 The Chromium Embedded Framework Authors.
// Portions copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "libcef/browser/navigate_params.h"
CefNavigateParams::CefNavigateParams(
const GURL& a_url,
content::PageTransition a_transition)
: url(a_url),
frame_id(-1),
disposition(CURRENT_TAB),
transition(a_transition),
is_renderer_initiated(false),
user_gesture(true) {
}
CefNavigateParams::~CefNavigateParams() {
}

View File

@ -1,85 +0,0 @@
// Copyright (c) 2012 The Chromium Embedded Framework Authors.
// Portions copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CEF_LIBCEF_BROWSER_NAVIGATE_PARAMS_H_
#define CEF_LIBCEF_BROWSER_NAVIGATE_PARAMS_H_
#pragma once
#include <string>
#include "libcef/common/upload_data.h"
#include "content/public/browser/global_request_id.h"
#include "content/public/common/page_transition_types.h"
#include "content/public/common/referrer.h"
#include "ui/base/window_open_disposition.h"
#include "url/gurl.h"
// Parameters that tell CefBrowserHostImpl::Navigate() what to do.
struct CefNavigateParams {
CefNavigateParams(const GURL& a_url,
content::PageTransition a_transition);
~CefNavigateParams();
// The following parameters are sent to the renderer via CefMsg_LoadRequest.
// ---------------------------------------------------------------------------
// Request method.
std::string method;
// The URL/referrer to be loaded.
GURL url;
content::Referrer referrer;
// The frame that the request should be loaded in or -1 to use the main frame.
int64 frame_id;
// Usually the URL of the document in the top-level window, which may be
// checked by the third-party cookie blocking policy. Leaving it empty may
// lead to undesired cookie blocking. Third-party cookie blocking can be
// bypassed by setting first_party_for_cookies = url, but this should ideally
// only be done if there really is no way to determine the correct value.
GURL first_party_for_cookies;
// Additional HTTP request headers.
std::string headers;
// net::URLRequest load flags (0 by default).
int load_flags;
// Upload data (may be NULL).
scoped_refptr<net::UploadData> upload_data;
// The following parameters are used to define browser behavior when servicing
// the navigation request.
// ---------------------------------------------------------------------------
// The disposition requested by the navigation source. Default is CURRENT_TAB.
WindowOpenDisposition disposition;
// The transition type of the navigation.
content::PageTransition transition;
// Whether this navigation was initiated by the renderer process.
bool is_renderer_initiated;
// If non-empty, the new tab contents encoding is overriden by this value.
std::string override_encoding;
// If false then the navigation was not initiated by a user gesture. Default
// is true.
bool user_gesture;
// Refers to a navigation that was parked in the browser in order to be
// transferred to another RVH. Only used in case of a redirection of a request
// to a different site that created a new RVH.
content::GlobalRequestID transferred_global_request_id;
private:
CefNavigateParams();
};
#endif // CEF_LIBCEF_BROWSER_NAVIGATE_PARAMS_H_

View File

@ -70,45 +70,6 @@ IPC_STRUCT_END()
// Messages sent from the browser to the renderer.
// Parameters for a resource request.
IPC_STRUCT_BEGIN(CefMsg_LoadRequest_Params)
// The request method: GET, POST, etc.
IPC_STRUCT_MEMBER(std::string, method)
// The requested URL.
IPC_STRUCT_MEMBER(GURL, url)
// The URL to send in the "Referer" header field. Can be empty if there is
// no referrer.
IPC_STRUCT_MEMBER(GURL, referrer)
// One of the blink::WebReferrerPolicy values.
IPC_STRUCT_MEMBER(int, referrer_policy)
// Identifies the frame within the RenderView that sent the request.
// -1 if unknown / invalid.
IPC_STRUCT_MEMBER(int64, frame_id)
// Usually the URL of the document in the top-level window, which may be
// checked by the third-party cookie blocking policy. Leaving it empty may
// lead to undesired cookie blocking. Third-party cookie blocking can be
// bypassed by setting first_party_for_cookies = url, but this should ideally
// only be done if there really is no way to determine the correct value.
IPC_STRUCT_MEMBER(GURL, first_party_for_cookies)
// Additional HTTP request headers.
IPC_STRUCT_MEMBER(std::string, headers)
// net::URLRequest load flags (0 by default).
IPC_STRUCT_MEMBER(int, load_flags)
// Optional upload data (may be null).
IPC_STRUCT_MEMBER(scoped_refptr<net::UploadData>, upload_data)
IPC_STRUCT_END()
// Tell the renderer to load a request.
IPC_MESSAGE_ROUTED1(CefMsg_LoadRequest,
CefMsg_LoadRequest_Params)
// Sent when the browser has a request for the renderer. The renderer may
// respond with a CefHostMsg_Response.
IPC_MESSAGE_ROUTED1(CefMsg_Request,
@ -201,6 +162,35 @@ IPC_MESSAGE_ROUTED1(CefHostMsg_Response,
IPC_MESSAGE_ROUTED1(CefHostMsg_ResponseAck,
int /* request_id */)
// Parameters for a resource request.
IPC_STRUCT_BEGIN(CefHostMsg_LoadRequest_Params)
// The request method: GET, POST, etc.
IPC_STRUCT_MEMBER(std::string, method)
// The requested URL.
IPC_STRUCT_MEMBER(GURL, url)
// The URL to send in the "Referer" header field. Can be empty if there is
// no referrer.
IPC_STRUCT_MEMBER(GURL, referrer)
// One of the blink::WebReferrerPolicy values.
IPC_STRUCT_MEMBER(int, referrer_policy)
// Identifies the frame within the RenderView that sent the request.
// -1 if unknown / invalid.
IPC_STRUCT_MEMBER(int64, frame_id)
// Additional HTTP request headers.
IPC_STRUCT_MEMBER(std::string, headers)
// Optional upload data (may be null).
IPC_STRUCT_MEMBER(scoped_refptr<net::UploadData>, upload_data)
IPC_STRUCT_END()
// Tell the browser to load a request.
IPC_MESSAGE_ROUTED1(CefHostMsg_LoadRequest,
CefHostMsg_LoadRequest_Params)
// Pepper PDF plugin messages excerpted from chrome/common/render_messages.h.
// Including all of render_messages.h would bring in a number of chrome

View File

@ -281,80 +281,8 @@ CefBrowserImpl::CefBrowserImpl(content::RenderView* render_view,
CefBrowserImpl::~CefBrowserImpl() {
}
void CefBrowserImpl::LoadRequest(const CefMsg_LoadRequest_Params& params) {
CefRefPtr<CefFrameImpl> framePtr = GetWebFrameImpl(params.frame_id);
if (!framePtr.get())
return;
WebFrame* web_frame = framePtr->web_frame();
blink::WebURLRequest request(params.url);
// DidCreateDataSource checks for this value.
request.setRequestorID(-1);
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);
}
web_frame->loadRequest(request);
void CefBrowserImpl::LoadRequest(const CefHostMsg_LoadRequest_Params& params) {
Send(new CefHostMsg_LoadRequest(routing_id(), params));
}
bool CefBrowserImpl::SendProcessMessage(CefProcessId target_process,
@ -616,7 +544,6 @@ bool CefBrowserImpl::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(CefMsg_Request, OnRequest)
IPC_MESSAGE_HANDLER(CefMsg_Response, OnResponse)
IPC_MESSAGE_HANDLER(CefMsg_ResponseAck, OnResponseAck)
IPC_MESSAGE_HANDLER(CefMsg_LoadRequest, LoadRequest)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;

View File

@ -20,7 +20,7 @@
#include "content/public/renderer/render_view_observer.h"
class GURL;
struct CefMsg_LoadRequest_Params;
struct CefHostMsg_LoadRequest_Params;
struct Cef_Request_Params;
struct Cef_Response_Params;
class CefContentRendererClient;
@ -79,7 +79,7 @@ class CefBrowserImpl : public CefBrowser,
bool is_windowless);
virtual ~CefBrowserImpl();
void LoadRequest(const CefMsg_LoadRequest_Params& params);
void LoadRequest(const CefHostMsg_LoadRequest_Params& params);
// Avoids unnecessary string type conversions.
bool SendProcessMessage(CefProcessId target_process,

View File

@ -110,12 +110,10 @@ void CefFrameImpl::LoadRequest(CefRefPtr<CefRequest> request) {
if (!browser_)
return;
CefMsg_LoadRequest_Params params;
CefHostMsg_LoadRequest_Params params;
params.url = GURL(std::string(request->GetURL()));
params.method = request->GetMethod();
params.frame_id = frame_id_;
params.first_party_for_cookies =
GURL(std::string(request->GetFirstPartyForCookies()));
CefRequest::HeaderMap headerMap;
request->GetHeaderMap(headerMap);
@ -129,8 +127,6 @@ void CefFrameImpl::LoadRequest(CefRefPtr<CefRequest> request) {
impl->Get(*params.upload_data.get());
}
params.load_flags = request->GetFlags();
browser_->LoadRequest(params);
}
@ -140,7 +136,7 @@ void CefFrameImpl::LoadURL(const CefString& url) {
if (!browser_)
return;
CefMsg_LoadRequest_Params params;
CefHostMsg_LoadRequest_Params params;
params.url = GURL(url.ToString());
params.method = "GET";
params.frame_id = frame_id_;

View File

@ -141,7 +141,7 @@ class RequestSendRecvTestHandler : public TestHandler {
CreateRequest(request_);
// Create the browser
CreateBrowser("about:blank");
CreateBrowser("");
}
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE {
@ -157,7 +157,7 @@ class RequestSendRecvTestHandler : public TestHandler {
// Verify that the request is the same
TestRequestEqual(request_, request, true);
EXPECT_EQ(RT_MAIN_FRAME, request->GetResourceType());
EXPECT_EQ(TT_LINK, request->GetTransitionType());
EXPECT_EQ(request_->GetTransitionType(), request->GetTransitionType());
got_before_resource_load_.yes();
@ -171,7 +171,7 @@ class RequestSendRecvTestHandler : public TestHandler {
// Verify that the request is the same
TestRequestEqual(request_, request, true);
EXPECT_EQ(RT_MAIN_FRAME, request->GetResourceType());
EXPECT_EQ(TT_LINK, request->GetTransitionType());
EXPECT_EQ(request_->GetTransitionType(), request->GetTransitionType());
got_resource_handler_.yes();
@ -201,6 +201,64 @@ TEST(RequestTest, SendRecv) {
namespace {
class LoadStringTestHandler : public TestHandler,
public CefStringVisitor {
public:
LoadStringTestHandler() {
source_ = "<html><head></head><body>Test</body></html>";
url_ = "http://tests/run.html";
}
virtual void RunTest() OVERRIDE {
CreateBrowser("");
}
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE {
TestHandler::OnAfterCreated(browser);
browser->GetMainFrame()->LoadString(source_, url_);
}
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int httpStatusCode) OVERRIDE {
EXPECT_EQ(url_, frame->GetURL().ToString());
CefRefPtr<CefStringVisitor> visitor(this);
frame->GetSource(visitor);
got_on_load_end_.yes();
}
virtual void Visit(const CefString& source) OVERRIDE {
EXPECT_EQ(source_, source.ToString());
got_source_.yes();
DestroyTest();
}
std::string source_;
std::string url_;
TrackCallback got_on_load_end_;
TrackCallback got_source_;
private:
IMPLEMENT_REFCOUNTING(LoadStringTestHandler);
};
} // namespace
TEST(RequestTest, LoadStringTest) {
CefRefPtr<LoadStringTestHandler> handler =
new LoadStringTestHandler();
handler->ExecuteTest();
ASSERT_TRUE(handler->got_on_load_end_);
ASSERT_TRUE(handler->got_source_);
}
namespace {
const char kTypeTestCompleteMsg[] = "RequestTest.Type";
const char kTypeTestOrigin[] = "http://tests-requesttt.com/";