mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
- Pass information to the renderer process synchronously on render thread creation and new browser creation to avoid race conditions (issue #744).
- Add the ability to pass extra information to child processes using a new CefBrowserProcessHandler::OnRenderProcessThreadCreated callback (issue #744). - Fix OnBeforeChildProcessLaunch documentation (issue #754). git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@910 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
@@ -250,10 +250,12 @@ bool CefBrowserImpl::SendProcessMessage(CefProcessId target_process,
|
||||
// CefBrowserImpl public methods.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
CefBrowserImpl::CefBrowserImpl(content::RenderView* render_view)
|
||||
CefBrowserImpl::CefBrowserImpl(content::RenderView* render_view,
|
||||
int browser_id,
|
||||
bool is_popup)
|
||||
: content::RenderViewObserver(render_view),
|
||||
browser_window_id_(kInvalidBrowserId),
|
||||
is_popup_(false),
|
||||
browser_window_id_(browser_id),
|
||||
is_popup_(is_popup),
|
||||
last_focused_frame_id_(kInvalidFrameId) {
|
||||
response_manager_.reset(new CefResponseManager);
|
||||
}
|
||||
@@ -547,8 +549,6 @@ void CefBrowserImpl::DidCreateDataSource(WebKit::WebFrame* frame,
|
||||
bool CefBrowserImpl::OnMessageReceived(const IPC::Message& message) {
|
||||
bool handled = true;
|
||||
IPC_BEGIN_MESSAGE_MAP(CefBrowserImpl, message)
|
||||
IPC_MESSAGE_HANDLER(CefMsg_UpdateBrowserWindowId,
|
||||
OnUpdateBrowserWindowId)
|
||||
IPC_MESSAGE_HANDLER(CefMsg_Request, OnRequest)
|
||||
IPC_MESSAGE_HANDLER(CefMsg_Response, OnResponse)
|
||||
IPC_MESSAGE_HANDLER(CefMsg_ResponseAck, OnResponseAck)
|
||||
@@ -562,23 +562,6 @@ bool CefBrowserImpl::OnMessageReceived(const IPC::Message& message) {
|
||||
// RenderViewObserver::OnMessageReceived message handlers.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void CefBrowserImpl::OnUpdateBrowserWindowId(int window_id, bool is_popup) {
|
||||
// This message should only be sent one time.
|
||||
DCHECK(browser_window_id_ == kInvalidBrowserId);
|
||||
|
||||
browser_window_id_ = window_id;
|
||||
is_popup_ = is_popup;
|
||||
|
||||
// Notify that the browser window has been created.
|
||||
CefRefPtr<CefApp> app = CefContentClient::Get()->application();
|
||||
if (app.get()) {
|
||||
CefRefPtr<CefRenderProcessHandler> handler =
|
||||
app->GetRenderProcessHandler();
|
||||
if (handler.get())
|
||||
handler->OnBrowserCreated(this);
|
||||
}
|
||||
}
|
||||
|
||||
void CefBrowserImpl::OnRequest(const Cef_Request_Params& params) {
|
||||
bool success = false;
|
||||
std::string response;
|
||||
|
@@ -76,7 +76,9 @@ class CefBrowserImpl : public CefBrowser,
|
||||
CefProcessId target_process,
|
||||
CefRefPtr<CefProcessMessage> message) OVERRIDE;
|
||||
|
||||
explicit CefBrowserImpl(content::RenderView* render_view);
|
||||
CefBrowserImpl(content::RenderView* render_view,
|
||||
int browser_id,
|
||||
bool is_popup);
|
||||
virtual ~CefBrowserImpl();
|
||||
|
||||
void LoadRequest(const CefMsg_LoadRequest_Params& params);
|
||||
@@ -110,7 +112,6 @@ class CefBrowserImpl : public CefBrowser,
|
||||
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
|
||||
|
||||
// RenderViewObserver::OnMessageReceived message handlers.
|
||||
void OnUpdateBrowserWindowId(int window_id, bool is_popup);
|
||||
void OnRequest(const Cef_Request_Params& params);
|
||||
void OnResponse(const Cef_Response_Params& params);
|
||||
void OnResponseAck(int request_id);
|
||||
|
@@ -16,6 +16,7 @@ MSVC_POP_WARNING();
|
||||
#include "libcef/common/cef_messages.h"
|
||||
#include "libcef/common/content_client.h"
|
||||
#include "libcef/common/request_impl.h"
|
||||
#include "libcef/common/values_impl.h"
|
||||
#include "libcef/renderer/browser_impl.h"
|
||||
#include "libcef/renderer/chrome_bindings.h"
|
||||
#include "libcef/renderer/render_message_filter.h"
|
||||
@@ -182,7 +183,44 @@ void CefContentRendererClient::RenderThreadStarted() {
|
||||
|
||||
WebKit::WebPrerenderingSupport::initialize(new CefPrerenderingSupport());
|
||||
|
||||
thread->Send(new CefProcessHostMsg_RenderThreadStarted);
|
||||
// Retrieve the new render thread information synchronously.
|
||||
CefProcessHostMsg_GetNewRenderThreadInfo_Params params;
|
||||
thread->Send(new CefProcessHostMsg_GetNewRenderThreadInfo(¶ms));
|
||||
|
||||
if (params.cross_origin_whitelist_entries.size() > 0) {
|
||||
// Cross-origin entries need to be added after WebKit is initialized.
|
||||
observer_->set_pending_cross_origin_whitelist_entries(
|
||||
params.cross_origin_whitelist_entries);
|
||||
}
|
||||
|
||||
// Notify the render process handler.
|
||||
CefRefPtr<CefApp> application = CefContentClient::Get()->application();
|
||||
if (application.get()) {
|
||||
CefRefPtr<CefRenderProcessHandler> handler =
|
||||
application->GetRenderProcessHandler();
|
||||
if (handler.get()) {
|
||||
CefRefPtr<CefListValueImpl> listValuePtr(
|
||||
new CefListValueImpl(¶ms.extra_info, false, true));
|
||||
handler->OnRenderThreadCreated(listValuePtr.get());
|
||||
listValuePtr->Detach(NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CefContentRendererClient::RenderViewCreated(
|
||||
content::RenderView* render_view) {
|
||||
// Retrieve the new browser information synchronously.
|
||||
CefProcessHostMsg_GetNewBrowserInfo_Params params;
|
||||
content::RenderThread::Get()->Send(
|
||||
new CefProcessHostMsg_GetNewBrowserInfo(render_view->GetRoutingID(),
|
||||
¶ms));
|
||||
DCHECK_GT(params.browser_id, 0);
|
||||
|
||||
CefRefPtr<CefBrowserImpl> browser =
|
||||
new CefBrowserImpl(render_view, params.browser_id, params.is_popup);
|
||||
browsers_.insert(std::make_pair(render_view, browser));
|
||||
|
||||
new CefPrerendererClient(render_view);
|
||||
|
||||
// Notify the render process handler.
|
||||
CefRefPtr<CefApp> application = CefContentClient::Get()->application();
|
||||
@@ -190,18 +228,10 @@ void CefContentRendererClient::RenderThreadStarted() {
|
||||
CefRefPtr<CefRenderProcessHandler> handler =
|
||||
application->GetRenderProcessHandler();
|
||||
if (handler.get())
|
||||
handler->OnRenderThreadCreated();
|
||||
handler->OnBrowserCreated(browser.get());
|
||||
}
|
||||
}
|
||||
|
||||
void CefContentRendererClient::RenderViewCreated(
|
||||
content::RenderView* render_view) {
|
||||
CefRefPtr<CefBrowserImpl> browser = new CefBrowserImpl(render_view);
|
||||
browsers_.insert(std::make_pair(render_view, browser));
|
||||
|
||||
new CefPrerendererClient(render_view);
|
||||
}
|
||||
|
||||
bool CefContentRendererClient::HandleNavigation(
|
||||
WebKit::WebFrame* frame,
|
||||
const WebKit::WebURLRequest& request,
|
||||
|
@@ -57,6 +57,22 @@ void CefRenderProcessObserver::WebKitInitialized() {
|
||||
// Register any custom schemes with WebKit.
|
||||
CefContentRendererClient::Get()->RegisterCustomSchemes();
|
||||
|
||||
if (pending_cross_origin_whitelist_entries_.size() > 0) {
|
||||
// Add pending cross-origin white list entries.
|
||||
for (size_t i = 0;
|
||||
i < pending_cross_origin_whitelist_entries_.size(); ++i) {
|
||||
const Cef_CrossOriginWhiteListEntry_Params& entry =
|
||||
pending_cross_origin_whitelist_entries_[i];
|
||||
GURL gurl = GURL(entry.source_origin);
|
||||
WebKit::WebSecurityPolicy::addOriginAccessWhitelistEntry(
|
||||
gurl,
|
||||
WebKit::WebString::fromUTF8(entry.target_protocol),
|
||||
WebKit::WebString::fromUTF8(entry.target_domain),
|
||||
entry.allow_target_subdomains);
|
||||
}
|
||||
pending_cross_origin_whitelist_entries_.clear();
|
||||
}
|
||||
|
||||
// The number of stack trace frames to capture for uncaught exceptions.
|
||||
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
|
||||
if (command_line.HasSwitch(switches::kUncaughtExceptionStackSize)) {
|
||||
@@ -86,23 +102,20 @@ void CefRenderProcessObserver::WebKitInitialized() {
|
||||
|
||||
void CefRenderProcessObserver::OnModifyCrossOriginWhitelistEntry(
|
||||
bool add,
|
||||
const std::string& source_origin,
|
||||
const std::string& target_protocol,
|
||||
const std::string& target_domain,
|
||||
bool allow_target_subdomains) {
|
||||
GURL gurl = GURL(source_origin);
|
||||
const Cef_CrossOriginWhiteListEntry_Params& params) {
|
||||
GURL gurl = GURL(params.source_origin);
|
||||
if (add) {
|
||||
WebKit::WebSecurityPolicy::addOriginAccessWhitelistEntry(
|
||||
gurl,
|
||||
WebKit::WebString::fromUTF8(target_protocol),
|
||||
WebKit::WebString::fromUTF8(target_domain),
|
||||
allow_target_subdomains);
|
||||
WebKit::WebString::fromUTF8(params.target_protocol),
|
||||
WebKit::WebString::fromUTF8(params.target_domain),
|
||||
params.allow_target_subdomains);
|
||||
} else {
|
||||
WebKit::WebSecurityPolicy::removeOriginAccessWhitelistEntry(
|
||||
gurl,
|
||||
WebKit::WebString::fromUTF8(target_protocol),
|
||||
WebKit::WebString::fromUTF8(target_domain),
|
||||
allow_target_subdomains);
|
||||
WebKit::WebString::fromUTF8(params.target_protocol),
|
||||
WebKit::WebString::fromUTF8(params.target_domain),
|
||||
params.allow_target_subdomains);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -7,28 +7,37 @@
|
||||
#define CEF_LIBCEF_RENDERER_RENDER_PROCESS_OBSERVER_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "content/public/renderer/render_process_observer.h"
|
||||
|
||||
struct Cef_CrossOriginWhiteListEntry_Params;
|
||||
|
||||
// This class sends and receives control messages on the renderer process.
|
||||
class CefRenderProcessObserver : public content::RenderProcessObserver {
|
||||
public:
|
||||
CefRenderProcessObserver();
|
||||
virtual ~CefRenderProcessObserver();
|
||||
|
||||
void set_pending_cross_origin_whitelist_entries(
|
||||
const std::vector<Cef_CrossOriginWhiteListEntry_Params>& entries) {
|
||||
pending_cross_origin_whitelist_entries_ = entries;
|
||||
}
|
||||
|
||||
// RenderProcessObserver implementation.
|
||||
virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE;
|
||||
virtual void WebKitInitialized() OVERRIDE;
|
||||
|
||||
private:
|
||||
// Message handlers called on the render thread.
|
||||
void OnModifyCrossOriginWhitelistEntry(bool add,
|
||||
const std::string& source_origin,
|
||||
const std::string& target_protocol,
|
||||
const std::string& target_domain,
|
||||
bool allow_target_subdomains);
|
||||
void OnModifyCrossOriginWhitelistEntry(
|
||||
bool add,
|
||||
const Cef_CrossOriginWhiteListEntry_Params& params);
|
||||
void OnClearCrossOriginWhitelist();
|
||||
|
||||
typedef std::vector<Cef_CrossOriginWhiteListEntry_Params> CrossOriginList;
|
||||
CrossOriginList pending_cross_origin_whitelist_entries_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CefRenderProcessObserver);
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user