- 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:
parent
8a504d3d25
commit
1e871cc2c8
|
@ -72,12 +72,26 @@ typedef struct _cef_browser_process_handler_t {
|
|||
struct _cef_browser_process_handler_t* self);
|
||||
|
||||
///
|
||||
// Called on the browser process IO thread before a child process is launched.
|
||||
// Provides an opportunity to modify the child process command line.
|
||||
// Called before a child process is launched. Will be called on the browser
|
||||
// process UI thread when launching a render process and on the browser
|
||||
// process IO thread when launching a GPU or plugin process. Provides an
|
||||
// opportunity to modify the child process command line. Do not keep a
|
||||
// reference to |command_line| outside of this function.
|
||||
///
|
||||
void (CEF_CALLBACK *on_before_child_process_launch)(
|
||||
struct _cef_browser_process_handler_t* self,
|
||||
struct _cef_command_line_t* command_line);
|
||||
|
||||
///
|
||||
// Called on the browser process IO thread after the main thread has been
|
||||
// created for a new render process. Provides an opportunity to specify extra
|
||||
// information that will be passed to
|
||||
// cef_render_process_handler_t::on_render_thread_created() in the render
|
||||
// process. Do not keep a reference to |extra_info| outside of this function.
|
||||
///
|
||||
void (CEF_CALLBACK *on_render_process_thread_created)(
|
||||
struct _cef_browser_process_handler_t* self,
|
||||
struct _cef_list_value_t* extra_info);
|
||||
} cef_browser_process_handler_t;
|
||||
|
||||
|
||||
|
|
|
@ -56,10 +56,14 @@ typedef struct _cef_render_process_handler_t {
|
|||
cef_base_t base;
|
||||
|
||||
///
|
||||
// Called after the render process main thread has been created.
|
||||
// Called after the render process main thread has been created. |extra_info|
|
||||
// is a read-only value originating from
|
||||
// cef_browser_process_handler_t::on_render_process_thread_created(). Do not
|
||||
// keep a reference to |extra_info| outside of this function.
|
||||
///
|
||||
void (CEF_CALLBACK *on_render_thread_created)(
|
||||
struct _cef_render_process_handler_t* self);
|
||||
struct _cef_render_process_handler_t* self,
|
||||
struct _cef_list_value_t* extra_info);
|
||||
|
||||
///
|
||||
// Called after WebKit has been initialized.
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include "include/cef_base.h"
|
||||
#include "include/cef_command_line.h"
|
||||
#include "include/cef_proxy_handler.h"
|
||||
#include "include/cef_values.h"
|
||||
|
||||
///
|
||||
// Class used to implement browser process callbacks. The methods of this class
|
||||
|
@ -67,13 +68,26 @@ class CefBrowserProcessHandler : public virtual CefBase {
|
|||
virtual void OnContextInitialized() {}
|
||||
|
||||
///
|
||||
// Called on the browser process IO thread before a child process is launched.
|
||||
// Provides an opportunity to modify the child process command line.
|
||||
// Called before a child process is launched. Will be called on the browser
|
||||
// process UI thread when launching a render process and on the browser
|
||||
// process IO thread when launching a GPU or plugin process. Provides an
|
||||
// opportunity to modify the child process command line. Do not keep a
|
||||
// reference to |command_line| outside of this method.
|
||||
///
|
||||
/*--cef()--*/
|
||||
virtual void OnBeforeChildProcessLaunch(
|
||||
CefRefPtr<CefCommandLine> command_line) {
|
||||
}
|
||||
CefRefPtr<CefCommandLine> command_line) {}
|
||||
|
||||
///
|
||||
// Called on the browser process IO thread after the main thread has been
|
||||
// created for a new render process. Provides an opportunity to specify extra
|
||||
// information that will be passed to
|
||||
// CefRenderProcessHandler::OnRenderThreadCreated() in the render process. Do
|
||||
// not keep a reference to |extra_info| outside of this method.
|
||||
///
|
||||
/*--cef()--*/
|
||||
virtual void OnRenderProcessThreadCreated(
|
||||
CefRefPtr<CefListValue> extra_info) {}
|
||||
};
|
||||
|
||||
#endif // CEF_INCLUDE_CEF_BROWSER_PROCESS_HANDLER_H_
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
#include "include/cef_frame.h"
|
||||
#include "include/cef_process_message.h"
|
||||
#include "include/cef_v8.h"
|
||||
#include "include/cef_values.h"
|
||||
|
||||
///
|
||||
// Class used to implement render process callbacks. The methods of this class
|
||||
|
@ -55,10 +56,13 @@ class CefRenderProcessHandler : public virtual CefBase {
|
|||
typedef cef_navigation_type_t NavigationType;
|
||||
|
||||
///
|
||||
// Called after the render process main thread has been created.
|
||||
// Called after the render process main thread has been created. |extra_info|
|
||||
// is a read-only value originating from
|
||||
// CefBrowserProcessHandler::OnRenderProcessThreadCreated(). Do not keep a
|
||||
// reference to |extra_info| outside of this method.
|
||||
///
|
||||
/*--cef()--*/
|
||||
virtual void OnRenderThreadCreated() {}
|
||||
virtual void OnRenderThreadCreated(CefRefPtr<CefListValue> extra_info) {}
|
||||
|
||||
///
|
||||
// Called after WebKit has been initialized.
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include "libcef/browser/browser_context.h"
|
||||
#include "libcef/browser/chrome_scheme_handler.h"
|
||||
#include "libcef/browser/content_browser_client.h"
|
||||
#include "libcef/browser/context.h"
|
||||
#include "libcef/browser/devtools_delegate.h"
|
||||
#include "libcef/browser/navigate_params.h"
|
||||
|
@ -251,8 +252,10 @@ CefRefPtr<CefBrowser> CefBrowserHost::CreateBrowserSync(
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int browser_id = _Context->GetNextBrowserID();
|
||||
CefRefPtr<CefBrowserHostImpl> browser =
|
||||
CefBrowserHostImpl::Create(windowInfo, settings, client, NULL, NULL);
|
||||
CefBrowserHostImpl::Create(windowInfo, settings, client, NULL, browser_id,
|
||||
NULL);
|
||||
if (!url.empty())
|
||||
browser->LoadURL(CefFrameHostImpl::kMainFrameId, url);
|
||||
return browser.get();
|
||||
|
@ -268,6 +271,7 @@ CefRefPtr<CefBrowserHostImpl> CefBrowserHostImpl::Create(
|
|||
const CefBrowserSettings& settings,
|
||||
CefRefPtr<CefClient> client,
|
||||
content::WebContents* web_contents,
|
||||
int browser_id,
|
||||
CefWindowHandle opener) {
|
||||
CEF_REQUIRE_UIT();
|
||||
|
||||
|
@ -281,7 +285,7 @@ CefRefPtr<CefBrowserHostImpl> CefBrowserHostImpl::Create(
|
|||
|
||||
CefRefPtr<CefBrowserHostImpl> browser =
|
||||
new CefBrowserHostImpl(window_info, settings, client, web_contents,
|
||||
opener);
|
||||
browser_id, opener);
|
||||
if (!browser->PlatformCreateWindow())
|
||||
return NULL;
|
||||
|
||||
|
@ -561,7 +565,7 @@ void CefBrowserHostImpl::StopLoad() {
|
|||
}
|
||||
|
||||
int CefBrowserHostImpl::GetIdentifier() {
|
||||
return unique_id();
|
||||
return browser_id();
|
||||
}
|
||||
|
||||
bool CefBrowserHostImpl::IsPopup() {
|
||||
|
@ -669,12 +673,6 @@ bool CefBrowserHostImpl::SendProcessMessage(
|
|||
// CefBrowserHostImpl public methods.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void CefBrowserHostImpl::SetUniqueId(int unique_id) {
|
||||
CEF_REQUIRE_UIT();
|
||||
unique_id_ = unique_id;
|
||||
Send(new CefMsg_UpdateBrowserWindowId(routing_id(), unique_id, IsPopup()));
|
||||
}
|
||||
|
||||
void CefBrowserHostImpl::DestroyBrowser() {
|
||||
CEF_REQUIRE_UIT();
|
||||
|
||||
|
@ -1218,9 +1216,16 @@ void CefBrowserHostImpl::WebContentsCreated(
|
|||
if (source_contents)
|
||||
opener = GetBrowserForContents(source_contents)->GetWindowHandle();
|
||||
|
||||
CefContentBrowserClient::NewPopupBrowserInfo info;
|
||||
CefContentBrowserClient::Get()->GetNewPopupBrowserInfo(
|
||||
new_contents->GetRenderProcessHost()->GetID(),
|
||||
new_contents->GetRoutingID(),
|
||||
&info);
|
||||
DCHECK_GT(info.browser_id, 0);
|
||||
|
||||
CefRefPtr<CefBrowserHostImpl> browser = CefBrowserHostImpl::Create(
|
||||
pending_window_info_, pending_settings_, pending_client_, new_contents,
|
||||
opener);
|
||||
info.browser_id, opener);
|
||||
|
||||
pending_client_ = NULL;
|
||||
}
|
||||
|
@ -1288,6 +1293,12 @@ void CefBrowserHostImpl::RenderViewDeleted(
|
|||
}
|
||||
|
||||
void CefBrowserHostImpl::RenderViewReady() {
|
||||
if (IsPopup()) {
|
||||
CefContentBrowserClient::Get()->ClearNewPopupBrowserInfo(
|
||||
web_contents()->GetRenderProcessHost()->GetID(),
|
||||
web_contents()->GetRoutingID());
|
||||
}
|
||||
|
||||
// Send the queued messages.
|
||||
queue_messages_ = false;
|
||||
while (!queued_messages_.empty()) {
|
||||
|
@ -1511,15 +1522,16 @@ CefBrowserHostImpl::CefBrowserHostImpl(const CefWindowInfo& window_info,
|
|||
const CefBrowserSettings& settings,
|
||||
CefRefPtr<CefClient> client,
|
||||
content::WebContents* web_contents,
|
||||
int browser_id,
|
||||
CefWindowHandle opener)
|
||||
: content::WebContentsObserver(web_contents),
|
||||
window_info_(window_info),
|
||||
settings_(settings),
|
||||
client_(client),
|
||||
browser_id_(browser_id),
|
||||
opener_(opener),
|
||||
render_process_id_(0),
|
||||
render_view_id_(0),
|
||||
unique_id_(0),
|
||||
render_process_id_(MSG_ROUTING_NONE),
|
||||
render_view_id_(MSG_ROUTING_NONE),
|
||||
is_loading_(false),
|
||||
can_go_back_(false),
|
||||
can_go_forward_(false),
|
||||
|
|
|
@ -78,6 +78,7 @@ class CefBrowserHostImpl : public CefBrowserHost,
|
|||
const CefBrowserSettings& settings,
|
||||
CefRefPtr<CefClient> client,
|
||||
content::WebContents* web_contents,
|
||||
int browser_id,
|
||||
CefWindowHandle opener);
|
||||
|
||||
// Returns the browser associated with the specified RenderViewHost.
|
||||
|
@ -138,9 +139,6 @@ class CefBrowserHostImpl : public CefBrowserHost,
|
|||
CefProcessId target_process,
|
||||
CefRefPtr<CefProcessMessage> message) OVERRIDE;
|
||||
|
||||
// Set the unique identifier for this browser.
|
||||
void SetUniqueId(int unique_id);
|
||||
|
||||
// Destroy the browser members. This method should only be called after the
|
||||
// native browser window is not longer processing messages.
|
||||
void DestroyBrowser();
|
||||
|
@ -198,7 +196,7 @@ class CefBrowserHostImpl : public CefBrowserHost,
|
|||
// Thread safe accessors.
|
||||
const CefBrowserSettings& settings() const { return settings_; }
|
||||
CefRefPtr<CefClient> client() const { return client_; }
|
||||
int unique_id() const { return unique_id_; }
|
||||
int browser_id() const { return browser_id_; }
|
||||
|
||||
// Returns the URL that is currently loading (or loaded) in the main frame.
|
||||
GURL GetLoadingURL();
|
||||
|
@ -323,6 +321,7 @@ class CefBrowserHostImpl : public CefBrowserHost,
|
|||
const CefBrowserSettings& settings,
|
||||
CefRefPtr<CefClient> client,
|
||||
content::WebContents* web_contents,
|
||||
int browser_id,
|
||||
CefWindowHandle opener);
|
||||
|
||||
// Initialize settings based on the specified RenderViewHost.
|
||||
|
@ -398,6 +397,7 @@ class CefBrowserHostImpl : public CefBrowserHost,
|
|||
CefBrowserSettings settings_;
|
||||
CefRefPtr<CefClient> client_;
|
||||
scoped_ptr<content::WebContents> web_contents_;
|
||||
int browser_id_;
|
||||
CefWindowHandle opener_;
|
||||
|
||||
// Unique ids used for routing communication to/from the renderer. We keep a
|
||||
|
@ -406,9 +406,6 @@ class CefBrowserHostImpl : public CefBrowserHost,
|
|||
int render_process_id_;
|
||||
int render_view_id_;
|
||||
|
||||
// Unique id for the browser.
|
||||
int unique_id_;
|
||||
|
||||
// Used when creating a new popup window.
|
||||
CefWindowInfo pending_window_info_;
|
||||
CefBrowserSettings pending_settings_;
|
||||
|
|
|
@ -5,12 +5,17 @@
|
|||
|
||||
#include "libcef/browser/browser_message_filter.h"
|
||||
|
||||
#include "libcef/browser/browser_host_impl.h"
|
||||
#include "libcef/browser/content_browser_client.h"
|
||||
#include "libcef/browser/context.h"
|
||||
#include "libcef/browser/origin_whitelist_impl.h"
|
||||
#include "libcef/browser/thread_util.h"
|
||||
#include "libcef/common/cef_messages.h"
|
||||
#include "libcef/common/values_impl.h"
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "base/bind.h"
|
||||
#include "content/public/browser/render_process_host.h"
|
||||
|
||||
CefBrowserMessageFilter::CefBrowserMessageFilter(
|
||||
content::RenderProcessHost* host)
|
||||
|
@ -31,22 +36,50 @@ void CefBrowserMessageFilter::OnFilterRemoved() {
|
|||
bool CefBrowserMessageFilter::OnMessageReceived(const IPC::Message& message) {
|
||||
bool handled = true;
|
||||
IPC_BEGIN_MESSAGE_MAP(CefBrowserMessageFilter, message)
|
||||
IPC_MESSAGE_HANDLER(CefProcessHostMsg_RenderThreadStarted,
|
||||
OnRenderThreadStarted)
|
||||
IPC_MESSAGE_HANDLER(CefProcessHostMsg_GetNewRenderThreadInfo,
|
||||
OnGetNewRenderThreadInfo)
|
||||
IPC_MESSAGE_HANDLER(CefProcessHostMsg_GetNewBrowserInfo,
|
||||
OnGetNewBrowserInfo)
|
||||
IPC_MESSAGE_UNHANDLED(handled = false)
|
||||
IPC_END_MESSAGE_MAP()
|
||||
return handled;
|
||||
}
|
||||
|
||||
void CefBrowserMessageFilter::OnRenderThreadStarted() {
|
||||
// Execute registration on the UI thread.
|
||||
CEF_POST_TASK(CEF_UIT,
|
||||
base::Bind(&CefBrowserMessageFilter::RegisterOnUIThread, this));
|
||||
bool CefBrowserMessageFilter::Send(IPC::Message* message) {
|
||||
return host_->Send(message);
|
||||
}
|
||||
|
||||
void CefBrowserMessageFilter::RegisterOnUIThread() {
|
||||
CEF_REQUIRE_UIT();
|
||||
|
||||
// Send existing registrations to the new render process.
|
||||
RegisterCrossOriginWhitelistEntriesWithHost(host_);
|
||||
void CefBrowserMessageFilter::OnGetNewRenderThreadInfo(
|
||||
CefProcessHostMsg_GetNewRenderThreadInfo_Params* params) {
|
||||
GetCrossOriginWhitelistEntries(¶ms->cross_origin_whitelist_entries);
|
||||
|
||||
CefRefPtr<CefApp> app = _Context->application();
|
||||
if (app.get()) {
|
||||
CefRefPtr<CefBrowserProcessHandler> handler =
|
||||
app->GetBrowserProcessHandler();
|
||||
if (handler.get()) {
|
||||
CefRefPtr<CefListValueImpl> listValuePtr(
|
||||
new CefListValueImpl(¶ms->extra_info, false, false));
|
||||
handler->OnRenderProcessThreadCreated(listValuePtr.get());
|
||||
listValuePtr->Detach(NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CefBrowserMessageFilter::OnGetNewBrowserInfo(
|
||||
int routing_id, CefProcessHostMsg_GetNewBrowserInfo_Params* params) {
|
||||
CefRefPtr<CefBrowserHostImpl> browser =
|
||||
CefBrowserHostImpl::GetBrowserByRoutingID(host_->GetID(), routing_id);
|
||||
if (browser.get()) {
|
||||
params->browser_id = browser->GetIdentifier();
|
||||
params->is_popup = browser->IsPopup();
|
||||
} else {
|
||||
CefContentBrowserClient::NewPopupBrowserInfo info;
|
||||
CefContentBrowserClient::Get()->GetNewPopupBrowserInfo(host_->GetID(),
|
||||
routing_id,
|
||||
&info);
|
||||
DCHECK_GT(info.browser_id, 0);
|
||||
params->browser_id = info.browser_id;
|
||||
params->is_popup = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,9 @@ namespace content {
|
|||
class RenderProcessHost;
|
||||
}
|
||||
|
||||
struct CefProcessHostMsg_GetNewBrowserInfo_Params;
|
||||
struct CefProcessHostMsg_GetNewRenderThreadInfo_Params;
|
||||
|
||||
// This class sends and receives control messages on the browser process.
|
||||
class CefBrowserMessageFilter : public IPC::ChannelProxy::MessageFilter {
|
||||
public:
|
||||
|
@ -24,11 +27,14 @@ class CefBrowserMessageFilter : public IPC::ChannelProxy::MessageFilter {
|
|||
virtual void OnFilterRemoved() OVERRIDE;
|
||||
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
|
||||
|
||||
bool Send(IPC::Message* message);
|
||||
|
||||
private:
|
||||
// Message handlers.
|
||||
void OnRenderThreadStarted();
|
||||
|
||||
void RegisterOnUIThread();
|
||||
void OnGetNewRenderThreadInfo(
|
||||
CefProcessHostMsg_GetNewRenderThreadInfo_Params* params);
|
||||
void OnGetNewBrowserInfo(int routing_id,
|
||||
CefProcessHostMsg_GetNewBrowserInfo_Params* params);
|
||||
|
||||
content::RenderProcessHost* host_;
|
||||
IPC::Channel* channel_;
|
||||
|
|
|
@ -247,6 +247,44 @@ CefContentBrowserClient::CefContentBrowserClient()
|
|||
CefContentBrowserClient::~CefContentBrowserClient() {
|
||||
}
|
||||
|
||||
// static
|
||||
CefContentBrowserClient* CefContentBrowserClient::Get() {
|
||||
return static_cast<CefContentBrowserClient*>(
|
||||
content::GetContentClient()->browser());
|
||||
}
|
||||
|
||||
void CefContentBrowserClient::GetNewPopupBrowserInfo(
|
||||
int render_process_id, int render_view_id, NewPopupBrowserInfo* info) {
|
||||
base::AutoLock lock_scope(new_popup_browser_lock_);
|
||||
|
||||
NewPopupBrowserInfoMap::const_iterator it =
|
||||
new_popup_browser_info_map_.find(
|
||||
std::make_pair(render_process_id, render_view_id));
|
||||
if (it != new_popup_browser_info_map_.end()) {
|
||||
*info = it->second;
|
||||
return;
|
||||
}
|
||||
|
||||
// Create the info now.
|
||||
NewPopupBrowserInfo new_info;
|
||||
new_info.browser_id = _Context->GetNextBrowserID();
|
||||
new_popup_browser_info_map_.insert(
|
||||
std::make_pair(
|
||||
std::make_pair(render_process_id, render_view_id), new_info));
|
||||
*info = new_info;
|
||||
}
|
||||
|
||||
void CefContentBrowserClient::ClearNewPopupBrowserInfo(int render_process_id,
|
||||
int render_view_id) {
|
||||
base::AutoLock lock_scope(new_popup_browser_lock_);
|
||||
|
||||
NewPopupBrowserInfoMap::iterator it =
|
||||
new_popup_browser_info_map_.find(
|
||||
std::make_pair(render_process_id, render_view_id));
|
||||
if (it != new_popup_browser_info_map_.end())
|
||||
new_popup_browser_info_map_.erase(it);
|
||||
}
|
||||
|
||||
content::BrowserMainParts* CefContentBrowserClient::CreateBrowserMainParts(
|
||||
const content::MainFunctionParams& parameters) {
|
||||
browser_main_parts_ = new CefBrowserMainParts(parameters);
|
||||
|
|
|
@ -6,12 +6,14 @@
|
|||
#define CEF_LIBCEF_BROWSER_CONTENT_BROWSER_CLIENT_H_
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/synchronization/lock.h"
|
||||
#include "content/public/browser/content_browser_client.h"
|
||||
|
||||
class CefBrowserMainParts;
|
||||
|
@ -28,10 +30,29 @@ class CefContentBrowserClient : public content::ContentBrowserClient {
|
|||
CefContentBrowserClient();
|
||||
virtual ~CefContentBrowserClient();
|
||||
|
||||
// Returns the singleton CefContentBrowserClient instance.
|
||||
static CefContentBrowserClient* Get();
|
||||
|
||||
CefBrowserMainParts* browser_main_parts() const {
|
||||
return browser_main_parts_;
|
||||
}
|
||||
|
||||
// During popup window creation there is a race between the call to
|
||||
// CefBrowserMessageFilter::OnGetNewBrowserInfo on the IO thread and the call
|
||||
// to CefBrowserHostImpl::WebContentsCreated on the UI thread. To resolve this
|
||||
// race we create the info when requested for the first time.
|
||||
class NewPopupBrowserInfo {
|
||||
public:
|
||||
NewPopupBrowserInfo()
|
||||
: browser_id(0) {}
|
||||
int browser_id;
|
||||
};
|
||||
void GetNewPopupBrowserInfo(int render_process_id,
|
||||
int render_view_id,
|
||||
NewPopupBrowserInfo* info);
|
||||
void ClearNewPopupBrowserInfo(int render_process_id,
|
||||
int render_view_id);
|
||||
|
||||
virtual content::BrowserMainParts* CreateBrowserMainParts(
|
||||
const content::MainFunctionParams& parameters) OVERRIDE;
|
||||
virtual void RenderProcessHostCreated(
|
||||
|
@ -60,6 +81,14 @@ class CefContentBrowserClient : public content::ContentBrowserClient {
|
|||
scoped_ptr<content::PluginServiceFilter> plugin_service_filter_;
|
||||
scoped_ptr<CefResourceDispatcherHostDelegate>
|
||||
resource_dispatcher_host_delegate_;
|
||||
|
||||
base::Lock new_popup_browser_lock_;
|
||||
|
||||
// Map of (render_process_id, render_view_id) to info. Access must be
|
||||
// protected by |new_popup_browser_lock_|.
|
||||
typedef std::map<std::pair<int, int>, NewPopupBrowserInfo>
|
||||
NewPopupBrowserInfoMap;
|
||||
NewPopupBrowserInfoMap new_popup_browser_info_map_;
|
||||
};
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_CONTENT_BROWSER_CLIENT_H_
|
||||
|
|
|
@ -167,8 +167,7 @@ void CefQuitMessageLoop() {
|
|||
CefContext::CefContext()
|
||||
: initialized_(false),
|
||||
shutting_down_(false),
|
||||
init_thread_id_(0),
|
||||
next_browser_id_(kNextBrowserIdReset) {
|
||||
init_thread_id_(0) {
|
||||
}
|
||||
|
||||
CefContext::~CefContext() {
|
||||
|
@ -271,48 +270,26 @@ bool CefContext::OnInitThread() {
|
|||
return (base::PlatformThread::CurrentId() == init_thread_id_);
|
||||
}
|
||||
|
||||
bool CefContext::AddBrowser(CefRefPtr<CefBrowserHostImpl> browser) {
|
||||
bool found = false;
|
||||
int CefContext::GetNextBrowserID() {
|
||||
return next_browser_id_.GetNext() + 1;
|
||||
}
|
||||
|
||||
void CefContext::AddBrowser(CefRefPtr<CefBrowserHostImpl> browser) {
|
||||
AutoLock lock_scope(this);
|
||||
|
||||
// check that the browser isn't already in the list before adding
|
||||
BrowserList::const_iterator it = browserlist_.begin();
|
||||
browserlist_.push_back(browser);
|
||||
}
|
||||
|
||||
void CefContext::RemoveBrowser(CefRefPtr<CefBrowserHostImpl> browser) {
|
||||
AutoLock lock_scope(this);
|
||||
|
||||
BrowserList::iterator it = browserlist_.begin();
|
||||
for (; it != browserlist_.end(); ++it) {
|
||||
if (it->get() == browser.get()) {
|
||||
found = true;
|
||||
browserlist_.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
browser->SetUniqueId(next_browser_id_++);
|
||||
browserlist_.push_back(browser);
|
||||
}
|
||||
|
||||
return !found;
|
||||
}
|
||||
|
||||
bool CefContext::RemoveBrowser(CefRefPtr<CefBrowserHostImpl> browser) {
|
||||
bool deleted = false;
|
||||
|
||||
{
|
||||
AutoLock lock_scope(this);
|
||||
|
||||
BrowserList::iterator it = browserlist_.begin();
|
||||
for (; it != browserlist_.end(); ++it) {
|
||||
if (it->get() == browser.get()) {
|
||||
browserlist_.erase(it);
|
||||
deleted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (browserlist_.empty())
|
||||
next_browser_id_ = kNextBrowserIdReset;
|
||||
}
|
||||
|
||||
return deleted;
|
||||
}
|
||||
|
||||
CefRefPtr<CefBrowserHostImpl> CefContext::GetBrowserByID(int id) {
|
||||
|
@ -320,7 +297,7 @@ CefRefPtr<CefBrowserHostImpl> CefContext::GetBrowserByID(int id) {
|
|||
|
||||
BrowserList::const_iterator it = browserlist_.begin();
|
||||
for (; it != browserlist_.end(); ++it) {
|
||||
if (it->get()->unique_id() == id)
|
||||
if (it->get()->browser_id() == id)
|
||||
return it->get();
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "include/cef_app.h"
|
||||
#include "include/cef_base.h"
|
||||
|
||||
#include "base/atomic_sequence_num.h"
|
||||
#include "base/file_path.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/scoped_temp_dir.h"
|
||||
|
@ -54,8 +55,9 @@ class CefContext : public CefBase {
|
|||
// Returns true if the context is shutting down.
|
||||
bool shutting_down() { return shutting_down_; }
|
||||
|
||||
bool AddBrowser(CefRefPtr<CefBrowserHostImpl> browser);
|
||||
bool RemoveBrowser(CefRefPtr<CefBrowserHostImpl> browser);
|
||||
int GetNextBrowserID();
|
||||
void AddBrowser(CefRefPtr<CefBrowserHostImpl> browser);
|
||||
void RemoveBrowser(CefRefPtr<CefBrowserHostImpl> browser);
|
||||
CefRefPtr<CefBrowserHostImpl> GetBrowserByID(int id);
|
||||
CefRefPtr<CefBrowserHostImpl> GetBrowserByRoutingID(int render_process_id,
|
||||
int render_view_id);
|
||||
|
@ -97,7 +99,7 @@ class CefContext : public CefBase {
|
|||
BrowserList browserlist_;
|
||||
|
||||
// Used for assigning unique IDs to browser instances.
|
||||
int next_browser_id_;
|
||||
base::AtomicSequenceNumber next_browser_id_;
|
||||
|
||||
scoped_ptr<CefMainDelegate> main_delegate_;
|
||||
scoped_ptr<content::ContentMainRunner> main_runner_;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "libcef/browser/origin_whitelist_impl.h"
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
#include "include/cef_origin_whitelist.h"
|
||||
#include "libcef/browser/context.h"
|
||||
|
@ -14,6 +14,7 @@
|
|||
|
||||
#include "base/bind.h"
|
||||
#include "base/lazy_instance.h"
|
||||
#include "base/synchronization/lock.h"
|
||||
#include "content/public/browser/render_process_host.h"
|
||||
#include "googleurl/src/gurl.h"
|
||||
|
||||
|
@ -31,25 +32,26 @@ class CefOriginWhitelistManager {
|
|||
const std::string& target_protocol,
|
||||
const std::string& target_domain,
|
||||
bool allow_target_subdomains) {
|
||||
CEF_REQUIRE_UIT();
|
||||
|
||||
OriginInfo info;
|
||||
Cef_CrossOriginWhiteListEntry_Params info;
|
||||
info.source_origin = source_origin;
|
||||
info.target_protocol = target_protocol;
|
||||
info.target_domain = target_domain;
|
||||
info.allow_target_subdomains = allow_target_subdomains;
|
||||
|
||||
// Verify that the origin entry doesn't already exist.
|
||||
OriginList::const_iterator it = origin_list_.begin();
|
||||
for (; it != origin_list_.end(); ++it) {
|
||||
if (it->Equals(info))
|
||||
return false;
|
||||
{
|
||||
base::AutoLock lock_scope(lock_);
|
||||
|
||||
// Verify that the origin entry doesn't already exist.
|
||||
OriginList::const_iterator it = origin_list_.begin();
|
||||
for (; it != origin_list_.end(); ++it) {
|
||||
if (IsEqual(*it, info))
|
||||
return false;
|
||||
}
|
||||
|
||||
origin_list_.push_back(info);
|
||||
}
|
||||
|
||||
origin_list_.push_back(info);
|
||||
|
||||
SendModifyCrossOriginWhitelistEntry(true, source_origin, target_protocol,
|
||||
target_domain, allow_target_subdomains);
|
||||
SendModifyCrossOriginWhitelistEntry(true, info);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -57,9 +59,7 @@ class CefOriginWhitelistManager {
|
|||
const std::string& target_protocol,
|
||||
const std::string& target_domain,
|
||||
bool allow_target_subdomains) {
|
||||
CEF_REQUIRE_UIT();
|
||||
|
||||
OriginInfo info;
|
||||
Cef_CrossOriginWhiteListEntry_Params info;
|
||||
info.source_origin = source_origin;
|
||||
info.target_protocol = target_protocol;
|
||||
info.target_domain = target_domain;
|
||||
|
@ -67,70 +67,63 @@ class CefOriginWhitelistManager {
|
|||
|
||||
bool found = false;
|
||||
|
||||
OriginList::iterator it = origin_list_.begin();
|
||||
for (; it != origin_list_.end(); ++it) {
|
||||
if (it->Equals(info)) {
|
||||
origin_list_.erase(it);
|
||||
found = true;
|
||||
break;
|
||||
{
|
||||
base::AutoLock lock_scope(lock_);
|
||||
|
||||
OriginList::iterator it = origin_list_.begin();
|
||||
for (; it != origin_list_.end(); ++it) {
|
||||
if (IsEqual(*it, info)) {
|
||||
origin_list_.erase(it);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
return false;
|
||||
|
||||
SendModifyCrossOriginWhitelistEntry(false, source_origin, target_protocol,
|
||||
target_domain, allow_target_subdomains);
|
||||
SendModifyCrossOriginWhitelistEntry(false, info);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ClearOrigins() {
|
||||
CEF_REQUIRE_UIT();
|
||||
|
||||
origin_list_.clear();
|
||||
{
|
||||
base::AutoLock lock_scope(lock_);
|
||||
origin_list_.clear();
|
||||
}
|
||||
|
||||
SendClearCrossOriginWhitelist();
|
||||
}
|
||||
|
||||
// Send all existing cross-origin registrations to the specified host.
|
||||
void RegisterOriginsWithHost(content::RenderProcessHost* host) {
|
||||
CEF_REQUIRE_UIT();
|
||||
void GetCrossOriginWhitelistEntries(
|
||||
std::vector<Cef_CrossOriginWhiteListEntry_Params>* entries) {
|
||||
base::AutoLock lock_scope(lock_);
|
||||
|
||||
if (origin_list_.empty())
|
||||
return;
|
||||
|
||||
OriginList::const_iterator it = origin_list_.begin();
|
||||
for (; it != origin_list_.end(); ++it) {
|
||||
host->Send(
|
||||
new CefProcessMsg_ModifyCrossOriginWhitelistEntry(
|
||||
true, it->source_origin, it->target_protocol, it->target_domain,
|
||||
it->allow_target_subdomains));
|
||||
}
|
||||
entries->insert(entries->end(), origin_list_.begin(), origin_list_.end());
|
||||
}
|
||||
|
||||
private:
|
||||
// Send the modify cross-origin whitelist entry message to all currently
|
||||
// existing hosts.
|
||||
void SendModifyCrossOriginWhitelistEntry(bool add,
|
||||
const std::string& source_origin,
|
||||
const std::string& target_protocol,
|
||||
const std::string& target_domain,
|
||||
bool allow_target_subdomains) {
|
||||
static void SendModifyCrossOriginWhitelistEntry(
|
||||
bool add,
|
||||
Cef_CrossOriginWhiteListEntry_Params& params) {
|
||||
CEF_REQUIRE_UIT();
|
||||
|
||||
content::RenderProcessHost::iterator i(
|
||||
content::RenderProcessHost::AllHostsIterator());
|
||||
for (; !i.IsAtEnd(); i.Advance()) {
|
||||
i.GetCurrentValue()->Send(
|
||||
new CefProcessMsg_ModifyCrossOriginWhitelistEntry(
|
||||
add, source_origin, target_protocol, target_domain,
|
||||
allow_target_subdomains));
|
||||
new CefProcessMsg_ModifyCrossOriginWhitelistEntry(add, params));
|
||||
}
|
||||
}
|
||||
|
||||
// Send the clear cross-origin whitelists message to all currently existing
|
||||
// hosts.
|
||||
void SendClearCrossOriginWhitelist() {
|
||||
static void SendClearCrossOriginWhitelist() {
|
||||
CEF_REQUIRE_UIT();
|
||||
|
||||
content::RenderProcessHost::iterator i(
|
||||
|
@ -140,22 +133,18 @@ class CefOriginWhitelistManager {
|
|||
}
|
||||
}
|
||||
|
||||
struct OriginInfo {
|
||||
std::string source_origin;
|
||||
std::string target_protocol;
|
||||
std::string target_domain;
|
||||
bool allow_target_subdomains;
|
||||
static bool IsEqual(const Cef_CrossOriginWhiteListEntry_Params& param1,
|
||||
const Cef_CrossOriginWhiteListEntry_Params& param2) {
|
||||
return (param1.source_origin == param2.source_origin &&
|
||||
param1.target_protocol == param2.target_protocol &&
|
||||
param1.target_domain == param2.target_domain &&
|
||||
param1.allow_target_subdomains == param2.allow_target_subdomains);
|
||||
}
|
||||
|
||||
bool Equals(const OriginInfo& info) const {
|
||||
return (source_origin == info.source_origin &&
|
||||
target_protocol == info.target_protocol &&
|
||||
target_domain == info.target_domain &&
|
||||
allow_target_subdomains == info.allow_target_subdomains);
|
||||
}
|
||||
};
|
||||
base::Lock lock_;
|
||||
|
||||
// List of registered origins.
|
||||
typedef std::list<OriginInfo> OriginList;
|
||||
// List of registered origins. Access must be protected by |lock_|.
|
||||
typedef std::vector<Cef_CrossOriginWhiteListEntry_Params> OriginList;
|
||||
OriginList origin_list_;
|
||||
|
||||
DISALLOW_EVIL_CONSTRUCTORS(CefOriginWhitelistManager);
|
||||
|
@ -247,8 +236,8 @@ bool CefClearCrossOriginWhitelist() {
|
|||
return true;
|
||||
}
|
||||
|
||||
void RegisterCrossOriginWhitelistEntriesWithHost(
|
||||
content::RenderProcessHost* host) {
|
||||
CEF_REQUIRE_UIT();
|
||||
CefOriginWhitelistManager::GetInstance()->RegisterOriginsWithHost(host);
|
||||
void GetCrossOriginWhitelistEntries(
|
||||
std::vector<Cef_CrossOriginWhiteListEntry_Params>* entries) {
|
||||
CefOriginWhitelistManager::GetInstance()->GetCrossOriginWhitelistEntries(
|
||||
entries);
|
||||
}
|
||||
|
|
|
@ -5,13 +5,17 @@
|
|||
#ifndef CEF_LIBCEF_BROWSER_ORIGIN_WHITELIST_IMPL_H_
|
||||
#define CEF_LIBCEF_BROWSER_ORIGIN_WHITELIST_IMPL_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace content {
|
||||
class RenderProcessHost;
|
||||
}
|
||||
|
||||
// Called when a new RenderProcessHost is created to send existing cross-origin
|
||||
// whitelist entry information.
|
||||
void RegisterCrossOriginWhitelistEntriesWithHost(
|
||||
content::RenderProcessHost* host);
|
||||
struct Cef_CrossOriginWhiteListEntry_Params;
|
||||
|
||||
// Called to retrieve the current list of cross-origin white list entries. This
|
||||
// method is thread safe.
|
||||
void GetCrossOriginWhitelistEntries(
|
||||
std::vector<Cef_CrossOriginWhiteListEntry_Params>* entries);
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_ORIGIN_WHITELIST_IMPL_H_
|
||||
|
|
|
@ -58,15 +58,17 @@ IPC_STRUCT_BEGIN(Cef_Response_Params)
|
|||
IPC_STRUCT_MEMBER(std::string, response)
|
||||
IPC_STRUCT_END()
|
||||
|
||||
// Parameters structure for a cross-origin white list entry.
|
||||
IPC_STRUCT_BEGIN(Cef_CrossOriginWhiteListEntry_Params)
|
||||
IPC_STRUCT_MEMBER(std::string, source_origin)
|
||||
IPC_STRUCT_MEMBER(std::string, target_protocol)
|
||||
IPC_STRUCT_MEMBER(std::string, target_domain)
|
||||
IPC_STRUCT_MEMBER(bool, allow_target_subdomains)
|
||||
IPC_STRUCT_END()
|
||||
|
||||
|
||||
// Messages sent from the browser to the renderer.
|
||||
|
||||
// Tell the renderer which browser window it's being attached to.
|
||||
IPC_MESSAGE_ROUTED2(CefMsg_UpdateBrowserWindowId,
|
||||
int /* browser_id */,
|
||||
bool /* is_popup */)
|
||||
|
||||
// Parameters for a resource request.
|
||||
IPC_STRUCT_BEGIN(CefMsg_LoadRequest_Params)
|
||||
// The request method: GET, POST, etc.
|
||||
|
@ -121,12 +123,9 @@ IPC_MESSAGE_ROUTED1(CefMsg_ResponseAck,
|
|||
int /* request_id */)
|
||||
|
||||
// Sent to child processes to add or remove a cross-origin whitelist entry.
|
||||
IPC_MESSAGE_CONTROL5(CefProcessMsg_ModifyCrossOriginWhitelistEntry,
|
||||
IPC_MESSAGE_CONTROL2(CefProcessMsg_ModifyCrossOriginWhitelistEntry,
|
||||
bool /* add */,
|
||||
std::string /* source_origin */,
|
||||
std::string /* target_protocol */,
|
||||
std::string /* target_domain */,
|
||||
bool /* allow_target_subdomains */)
|
||||
Cef_CrossOriginWhiteListEntry_Params /* params */)
|
||||
|
||||
// Sent to child processes to clear the cross-origin whitelist.
|
||||
IPC_MESSAGE_CONTROL0(CefProcessMsg_ClearCrossOriginWhitelist)
|
||||
|
@ -134,8 +133,30 @@ IPC_MESSAGE_CONTROL0(CefProcessMsg_ClearCrossOriginWhitelist)
|
|||
|
||||
// Messages sent from the renderer to the browser.
|
||||
|
||||
// Sent when the render thread has started and all filters are attached.
|
||||
IPC_MESSAGE_CONTROL0(CefProcessHostMsg_RenderThreadStarted)
|
||||
// Parameters for a newly created render thread.
|
||||
IPC_STRUCT_BEGIN(CefProcessHostMsg_GetNewRenderThreadInfo_Params)
|
||||
IPC_STRUCT_MEMBER(std::vector<Cef_CrossOriginWhiteListEntry_Params>,
|
||||
cross_origin_whitelist_entries)
|
||||
|
||||
IPC_STRUCT_MEMBER(ListValue, extra_info)
|
||||
IPC_STRUCT_END()
|
||||
|
||||
// Retrieve information about a newly created render thread.
|
||||
IPC_SYNC_MESSAGE_CONTROL0_1(
|
||||
CefProcessHostMsg_GetNewRenderThreadInfo,
|
||||
CefProcessHostMsg_GetNewRenderThreadInfo_Params /* params*/)
|
||||
|
||||
// Parameters for a newly created browser window.
|
||||
IPC_STRUCT_BEGIN(CefProcessHostMsg_GetNewBrowserInfo_Params)
|
||||
IPC_STRUCT_MEMBER(int, browser_id)
|
||||
IPC_STRUCT_MEMBER(bool, is_popup)
|
||||
IPC_STRUCT_END()
|
||||
|
||||
// Retrieve information about a newly created browser window.
|
||||
IPC_SYNC_MESSAGE_CONTROL1_1(
|
||||
CefProcessHostMsg_GetNewBrowserInfo,
|
||||
int /* routing_id */,
|
||||
CefProcessHostMsg_GetNewBrowserInfo_Params /* params*/)
|
||||
|
||||
// Sent when a frame is identified for the first time.
|
||||
IPC_MESSAGE_ROUTED3(CefHostMsg_FrameIdentified,
|
||||
|
|
|
@ -38,6 +38,14 @@ CefRefPtr<CefBinaryValue> CefBinaryValueImpl::GetOrCreateRef(
|
|||
CefBinaryValueImpl::kReference, controller);
|
||||
}
|
||||
|
||||
CefBinaryValueImpl::CefBinaryValueImpl(base::BinaryValue* value,
|
||||
bool will_delete,
|
||||
bool read_only)
|
||||
: CefValueBase<CefBinaryValue, base::BinaryValue>(
|
||||
value, NULL, will_delete ? kOwnerWillDelete : kOwnerNoDelete,
|
||||
read_only, NULL) {
|
||||
}
|
||||
|
||||
base::BinaryValue* CefBinaryValueImpl::CopyValue() {
|
||||
CEF_VALUE_VERIFY_RETURN(false, NULL);
|
||||
return const_value().DeepCopy();
|
||||
|
@ -139,6 +147,14 @@ CefRefPtr<CefDictionaryValue> CefDictionaryValueImpl::GetOrCreateRef(
|
|||
CefDictionaryValueImpl::kReference, read_only, controller);
|
||||
}
|
||||
|
||||
CefDictionaryValueImpl::CefDictionaryValueImpl(base::DictionaryValue* value,
|
||||
bool will_delete,
|
||||
bool read_only)
|
||||
: CefValueBase<CefDictionaryValue, base::DictionaryValue>(
|
||||
value, NULL, will_delete ? kOwnerWillDelete : kOwnerNoDelete,
|
||||
read_only, NULL) {
|
||||
}
|
||||
|
||||
base::DictionaryValue* CefDictionaryValueImpl::CopyValue() {
|
||||
CEF_VALUE_VERIFY_RETURN(false, NULL);
|
||||
return const_value().DeepCopy();
|
||||
|
@ -487,6 +503,14 @@ CefRefPtr<CefListValue> CefListValueImpl::GetOrCreateRef(
|
|||
CefListValueImpl::kReference, read_only, controller);
|
||||
}
|
||||
|
||||
CefListValueImpl::CefListValueImpl(base::ListValue* value,
|
||||
bool will_delete,
|
||||
bool read_only)
|
||||
: CefValueBase<CefListValue, base::ListValue>(
|
||||
value, NULL, will_delete ? kOwnerWillDelete : kOwnerNoDelete,
|
||||
read_only, NULL) {
|
||||
}
|
||||
|
||||
base::ListValue* CefListValueImpl::CopyValue() {
|
||||
CEF_VALUE_VERIFY_RETURN(false, NULL);
|
||||
return const_value().DeepCopy();
|
||||
|
|
|
@ -25,6 +25,11 @@ class CefBinaryValueImpl
|
|||
void* parent_value,
|
||||
CefValueController* controller);
|
||||
|
||||
// Simple constructor for referencing existing value objects.
|
||||
CefBinaryValueImpl(base::BinaryValue* value,
|
||||
bool will_delete,
|
||||
bool read_only);
|
||||
|
||||
// Return a copy of the value.
|
||||
base::BinaryValue* CopyValue();
|
||||
|
||||
|
@ -72,6 +77,11 @@ class CefDictionaryValueImpl
|
|||
bool read_only,
|
||||
CefValueController* controller);
|
||||
|
||||
// Simple constructor for referencing existing value objects.
|
||||
CefDictionaryValueImpl(base::DictionaryValue* value,
|
||||
bool will_delete,
|
||||
bool read_only);
|
||||
|
||||
// Return a copy of the value.
|
||||
base::DictionaryValue* CopyValue();
|
||||
|
||||
|
@ -140,6 +150,11 @@ class CefListValueImpl
|
|||
bool read_only,
|
||||
CefValueController* controller);
|
||||
|
||||
// Simple constructor for referencing existing value objects.
|
||||
CefListValueImpl(base::ListValue* value,
|
||||
bool will_delete,
|
||||
bool read_only);
|
||||
|
||||
// Return a copy of the value.
|
||||
base::ListValue* CopyValue();
|
||||
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "libcef_dll/cpptoc/browser_process_handler_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/proxy_handler_cpptoc.h"
|
||||
#include "libcef_dll/ctocpp/command_line_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/list_value_ctocpp.h"
|
||||
|
||||
|
||||
// MEMBER FUNCTIONS - Body may be edited by hand.
|
||||
|
@ -63,6 +64,24 @@ void CEF_CALLBACK browser_process_handler_on_before_child_process_launch(
|
|||
CefCommandLineCToCpp::Wrap(command_line));
|
||||
}
|
||||
|
||||
void CEF_CALLBACK browser_process_handler_on_render_process_thread_created(
|
||||
struct _cef_browser_process_handler_t* self,
|
||||
struct _cef_list_value_t* extra_info) {
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
DCHECK(self);
|
||||
if (!self)
|
||||
return;
|
||||
// Verify param: extra_info; type: refptr_diff
|
||||
DCHECK(extra_info);
|
||||
if (!extra_info)
|
||||
return;
|
||||
|
||||
// Execute
|
||||
CefBrowserProcessHandlerCppToC::Get(self)->OnRenderProcessThreadCreated(
|
||||
CefListValueCToCpp::Wrap(extra_info));
|
||||
}
|
||||
|
||||
|
||||
// CONSTRUCTOR - Do not edit by hand.
|
||||
|
||||
|
@ -75,6 +94,8 @@ CefBrowserProcessHandlerCppToC::CefBrowserProcessHandlerCppToC(
|
|||
browser_process_handler_on_context_initialized;
|
||||
struct_.struct_.on_before_child_process_launch =
|
||||
browser_process_handler_on_before_child_process_launch;
|
||||
struct_.struct_.on_render_process_thread_created =
|
||||
browser_process_handler_on_render_process_thread_created;
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "libcef_dll/ctocpp/browser_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/domnode_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/frame_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/list_value_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/process_message_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/request_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/v8context_ctocpp.h"
|
||||
|
@ -24,15 +25,21 @@
|
|||
// MEMBER FUNCTIONS - Body may be edited by hand.
|
||||
|
||||
void CEF_CALLBACK render_process_handler_on_render_thread_created(
|
||||
struct _cef_render_process_handler_t* self) {
|
||||
struct _cef_render_process_handler_t* self,
|
||||
struct _cef_list_value_t* extra_info) {
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
DCHECK(self);
|
||||
if (!self)
|
||||
return;
|
||||
// Verify param: extra_info; type: refptr_diff
|
||||
DCHECK(extra_info);
|
||||
if (!extra_info)
|
||||
return;
|
||||
|
||||
// Execute
|
||||
CefRenderProcessHandlerCppToC::Get(self)->OnRenderThreadCreated();
|
||||
CefRenderProcessHandlerCppToC::Get(self)->OnRenderThreadCreated(
|
||||
CefListValueCToCpp::Wrap(extra_info));
|
||||
}
|
||||
|
||||
void CEF_CALLBACK render_process_handler_on_web_kit_initialized(
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
//
|
||||
|
||||
#include "libcef_dll/cpptoc/command_line_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/list_value_cpptoc.h"
|
||||
#include "libcef_dll/ctocpp/browser_process_handler_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/proxy_handler_ctocpp.h"
|
||||
|
||||
|
@ -57,6 +58,23 @@ void CefBrowserProcessHandlerCToCpp::OnBeforeChildProcessLaunch(
|
|||
CefCommandLineCppToC::Wrap(command_line));
|
||||
}
|
||||
|
||||
void CefBrowserProcessHandlerCToCpp::OnRenderProcessThreadCreated(
|
||||
CefRefPtr<CefListValue> extra_info) {
|
||||
if (CEF_MEMBER_MISSING(struct_, on_render_process_thread_created))
|
||||
return;
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
// Verify param: extra_info; type: refptr_diff
|
||||
DCHECK(extra_info.get());
|
||||
if (!extra_info.get())
|
||||
return;
|
||||
|
||||
// Execute
|
||||
struct_->on_render_process_thread_created(struct_,
|
||||
CefListValueCppToC::Wrap(extra_info));
|
||||
}
|
||||
|
||||
|
||||
#ifndef NDEBUG
|
||||
template<> long CefCToCpp<CefBrowserProcessHandlerCToCpp,
|
||||
|
|
|
@ -38,6 +38,8 @@ class CefBrowserProcessHandlerCToCpp
|
|||
virtual void OnContextInitialized() OVERRIDE;
|
||||
virtual void OnBeforeChildProcessLaunch(
|
||||
CefRefPtr<CefCommandLine> command_line) OVERRIDE;
|
||||
virtual void OnRenderProcessThreadCreated(
|
||||
CefRefPtr<CefListValue> extra_info) OVERRIDE;
|
||||
};
|
||||
|
||||
#endif // BUILDING_CEF_SHARED
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "libcef_dll/cpptoc/browser_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/domnode_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/frame_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/list_value_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/process_message_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/request_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/v8context_cpptoc.h"
|
||||
|
@ -23,14 +24,21 @@
|
|||
|
||||
// VIRTUAL METHODS - Body may be edited by hand.
|
||||
|
||||
void CefRenderProcessHandlerCToCpp::OnRenderThreadCreated() {
|
||||
void CefRenderProcessHandlerCToCpp::OnRenderThreadCreated(
|
||||
CefRefPtr<CefListValue> extra_info) {
|
||||
if (CEF_MEMBER_MISSING(struct_, on_render_thread_created))
|
||||
return;
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
// Verify param: extra_info; type: refptr_diff
|
||||
DCHECK(extra_info.get());
|
||||
if (!extra_info.get())
|
||||
return;
|
||||
|
||||
// Execute
|
||||
struct_->on_render_thread_created(struct_);
|
||||
struct_->on_render_thread_created(struct_,
|
||||
CefListValueCppToC::Wrap(extra_info));
|
||||
}
|
||||
|
||||
void CefRenderProcessHandlerCToCpp::OnWebKitInitialized() {
|
||||
|
|
|
@ -34,7 +34,8 @@ class CefRenderProcessHandlerCToCpp
|
|||
virtual ~CefRenderProcessHandlerCToCpp() {}
|
||||
|
||||
// CefRenderProcessHandler methods
|
||||
virtual void OnRenderThreadCreated() OVERRIDE;
|
||||
virtual void OnRenderThreadCreated(
|
||||
CefRefPtr<CefListValue> extra_info) OVERRIDE;
|
||||
virtual void OnWebKitInitialized() OVERRIDE;
|
||||
virtual void OnBrowserCreated(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
||||
virtual void OnBrowserDestroyed(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
||||
|
|
|
@ -229,6 +229,14 @@ void ClientApp::OnBeforeChildProcessLaunch(
|
|||
(*it)->OnBeforeChildProcessLaunch(this, command_line);
|
||||
}
|
||||
|
||||
void ClientApp::OnRenderProcessThreadCreated(
|
||||
CefRefPtr<CefListValue> extra_info) {
|
||||
// Execute delegate callbacks.
|
||||
BrowserDelegateSet::iterator it = browser_delegates_.begin();
|
||||
for (; it != browser_delegates_.end(); ++it)
|
||||
(*it)->OnRenderProcessThreadCreated(this, extra_info);
|
||||
}
|
||||
|
||||
void ClientApp::GetProxyForUrl(const CefString& url,
|
||||
CefProxyInfo& proxy_info) {
|
||||
proxy_info.proxyType = proxy_type_;
|
||||
|
@ -236,11 +244,11 @@ void ClientApp::GetProxyForUrl(const CefString& url,
|
|||
CefString(&proxy_info.proxyList) = proxy_config_;
|
||||
}
|
||||
|
||||
void ClientApp::OnRenderThreadCreated() {
|
||||
void ClientApp::OnRenderThreadCreated(CefRefPtr<CefListValue> extra_info) {
|
||||
// Execute delegate callbacks.
|
||||
RenderDelegateSet::iterator it = render_delegates_.begin();
|
||||
for (; it != render_delegates_.end(); ++it)
|
||||
(*it)->OnRenderThreadCreated(this);
|
||||
(*it)->OnRenderThreadCreated(this, extra_info);
|
||||
}
|
||||
|
||||
void ClientApp::OnWebKitInitialized() {
|
||||
|
|
|
@ -29,12 +29,22 @@ class ClientApp : public CefApp,
|
|||
}
|
||||
|
||||
// Called on the browser process IO thread before a child process is
|
||||
// launched Provides an opportunity to modify the child process command
|
||||
// line.
|
||||
// launched. Provides an opportunity to modify the child process command
|
||||
// line. Do not keep a reference to |command_line| outside of this method.
|
||||
virtual void OnBeforeChildProcessLaunch(
|
||||
CefRefPtr<ClientApp> app,
|
||||
CefRefPtr<CefCommandLine> command_line) {
|
||||
}
|
||||
|
||||
// Called on the browser process IO thread after the main thread has been
|
||||
// created for a new render process. Provides an opportunity to specify
|
||||
// extra information that will be passed to
|
||||
// CefRenderProcessHandler::OnRenderThreadCreated() in the render process.
|
||||
// Do not keep a reference to |extra_info| outside of this method.
|
||||
virtual void OnRenderProcessThreadCreated(
|
||||
CefRefPtr<ClientApp> app,
|
||||
CefRefPtr<CefListValue> extra_info) {
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::set<CefRefPtr<BrowserDelegate> > BrowserDelegateSet;
|
||||
|
@ -45,7 +55,8 @@ class ClientApp : public CefApp,
|
|||
class RenderDelegate : public virtual CefBase {
|
||||
public:
|
||||
// Called after the render process main thread has been created.
|
||||
virtual void OnRenderThreadCreated(CefRefPtr<ClientApp> app) {
|
||||
virtual void OnRenderThreadCreated(CefRefPtr<ClientApp> app,
|
||||
CefRefPtr<CefListValue> extra_info) {
|
||||
}
|
||||
|
||||
// Called when WebKit is initialized. Used to register V8 extensions.
|
||||
|
@ -177,13 +188,16 @@ class ClientApp : public CefApp,
|
|||
virtual void OnContextInitialized() OVERRIDE;
|
||||
virtual void OnBeforeChildProcessLaunch(
|
||||
CefRefPtr<CefCommandLine> command_line) OVERRIDE;
|
||||
virtual void OnRenderProcessThreadCreated(CefRefPtr<CefListValue> extra_info)
|
||||
OVERRIDE;
|
||||
|
||||
// CefProxyHandler methods.
|
||||
virtual void GetProxyForUrl(const CefString& url,
|
||||
CefProxyInfo& proxy_info) OVERRIDE;
|
||||
|
||||
// CefRenderProcessHandler methods.
|
||||
virtual void OnRenderThreadCreated() OVERRIDE;
|
||||
virtual void OnRenderThreadCreated(CefRefPtr<CefListValue> extra_info)
|
||||
OVERRIDE;
|
||||
virtual void OnWebKitInitialized() OVERRIDE;
|
||||
virtual void OnBrowserCreated(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
||||
virtual void OnBrowserDestroyed(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
||||
|
|
|
@ -9,6 +9,10 @@ void ClientApp::CreateBrowserDelegates(BrowserDelegateSet& delegates) {
|
|||
// Bring in the V8 tests.
|
||||
extern void CreateV8BrowserTests(BrowserDelegateSet& delegates);
|
||||
CreateV8BrowserTests(delegates);
|
||||
|
||||
// Bring in the Navigation tests.
|
||||
extern void CreateNavigationBrowserTests(BrowserDelegateSet& delegates);
|
||||
CreateNavigationBrowserTests(delegates);
|
||||
}
|
||||
|
||||
// static
|
||||
|
|
|
@ -6,17 +6,16 @@
|
|||
#include "include/cef_scheme.h"
|
||||
#include "tests/cefclient/client_app.h"
|
||||
#include "tests/unittests/test_handler.h"
|
||||
#include "tests/unittests/test_util.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
namespace {
|
||||
|
||||
const char kHNavDomain[] = "http://tests-hnav/";
|
||||
const char kHNav1[] = "http://tests-hnav/nav1.html";
|
||||
const char kHNav2[] = "http://tests-hnav/nav2.html";
|
||||
const char kHNav3[] = "http://tests-hnav/nav3.html";
|
||||
const char kHistoryNavMsg[] = "NavigationTest.HistoryNav";
|
||||
|
||||
|
||||
enum NavAction {
|
||||
NA_LOAD = 1,
|
||||
NA_BACK,
|
||||
|
@ -46,11 +45,46 @@ static NavListItem kHNavList[] = {
|
|||
|
||||
#define NAV_LIST_SIZE() (sizeof(kHNavList) / sizeof(NavListItem))
|
||||
|
||||
bool g_history_nav_test = false;
|
||||
|
||||
// Browser side.
|
||||
class HistoryNavBrowserTest : public ClientApp::BrowserDelegate {
|
||||
public:
|
||||
HistoryNavBrowserTest() {}
|
||||
|
||||
virtual void OnBeforeChildProcessLaunch(
|
||||
CefRefPtr<ClientApp> app,
|
||||
CefRefPtr<CefCommandLine> command_line) OVERRIDE {
|
||||
if (!g_history_nav_test)
|
||||
return;
|
||||
|
||||
// Indicate to the render process that the test should be run.
|
||||
command_line->AppendSwitchWithValue("test", kHistoryNavMsg);
|
||||
}
|
||||
|
||||
protected:
|
||||
IMPLEMENT_REFCOUNTING(HistoryNavBrowserTest);
|
||||
};
|
||||
|
||||
// Renderer side.
|
||||
class HistoryNavRendererTest : public ClientApp::RenderDelegate {
|
||||
public:
|
||||
HistoryNavRendererTest()
|
||||
: nav_(0) {}
|
||||
: run_test_(false),
|
||||
nav_(0) {}
|
||||
|
||||
virtual void OnRenderThreadCreated(
|
||||
CefRefPtr<ClientApp> app,
|
||||
CefRefPtr<CefListValue> extra_info) OVERRIDE {
|
||||
// Check that the test should be run.
|
||||
CefRefPtr<CefCommandLine> command_line =
|
||||
CefCommandLine::GetGlobalCommandLine();
|
||||
const std::string& test = command_line->GetSwitchValue("test");
|
||||
if (test != kHistoryNavMsg)
|
||||
return;
|
||||
|
||||
run_test_ = true;
|
||||
}
|
||||
|
||||
virtual bool OnBeforeNavigation(CefRefPtr<ClientApp> app,
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
|
@ -58,13 +92,12 @@ class HistoryNavRendererTest : public ClientApp::RenderDelegate {
|
|||
CefRefPtr<CefRequest> request,
|
||||
cef_navigation_type_t navigation_type,
|
||||
bool is_redirect) OVERRIDE {
|
||||
std::string url = request->GetURL();
|
||||
// Don't leak into other tests.
|
||||
if (url.find(kHNavDomain) != 0)
|
||||
if (!run_test_)
|
||||
return false;
|
||||
|
||||
const NavListItem& item = kHNavList[nav_];
|
||||
|
||||
std::string url = request->GetURL();
|
||||
EXPECT_STREQ(item.target, url.c_str());
|
||||
|
||||
if (item.action == NA_LOAD)
|
||||
|
@ -103,6 +136,7 @@ class HistoryNavRendererTest : public ClientApp::RenderDelegate {
|
|||
EXPECT_TRUE(browser->SendProcessMessage(PID_BROWSER, return_msg));
|
||||
}
|
||||
|
||||
bool run_test_;
|
||||
int nav_;
|
||||
|
||||
IMPLEMENT_REFCOUNTING(HistoryNavRendererTest);
|
||||
|
@ -284,9 +318,11 @@ class HistoryNavTestHandler : public TestHandler {
|
|||
|
||||
// Verify history navigation.
|
||||
TEST(NavigationTest, History) {
|
||||
g_history_nav_test = true;
|
||||
CefRefPtr<HistoryNavTestHandler> handler =
|
||||
new HistoryNavTestHandler();
|
||||
handler->ExecuteTest();
|
||||
g_history_nav_test = false;
|
||||
|
||||
for (size_t i = 0; i < NAV_LIST_SIZE(); ++i) {
|
||||
if (kHNavList[i].action != NA_CLEAR) {
|
||||
|
@ -718,9 +754,394 @@ TEST(NavigationTest, Redirect) {
|
|||
}
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
const char KONav1[] = "http://tests-onav/nav1.html";
|
||||
const char KONav2[] = "http://tests-onav/nav2.html";
|
||||
const char kOrderNavMsg[] = "NavigationTest.OrderNav";
|
||||
const char kOrderNavClosedMsg[] = "NavigationTest.OrderNavClosed";
|
||||
|
||||
void SetOrderNavExtraInfo(CefRefPtr<CefListValue> extra_info) {
|
||||
// Arbitrary data for testing.
|
||||
extra_info->SetBool(0, true);
|
||||
CefRefPtr<CefDictionaryValue> dict = CefDictionaryValue::Create();
|
||||
dict->SetInt("key1", 5);
|
||||
dict->SetString("key2", "test string");
|
||||
extra_info->SetDictionary(1, dict);
|
||||
extra_info->SetDouble(2, 5.43322);
|
||||
extra_info->SetString(3, "some string");
|
||||
}
|
||||
|
||||
bool g_order_nav_test = false;
|
||||
|
||||
// Browser side.
|
||||
class OrderNavBrowserTest : public ClientApp::BrowserDelegate {
|
||||
public:
|
||||
OrderNavBrowserTest() {}
|
||||
|
||||
virtual void OnBeforeChildProcessLaunch(
|
||||
CefRefPtr<ClientApp> app,
|
||||
CefRefPtr<CefCommandLine> command_line) OVERRIDE {
|
||||
if (!g_order_nav_test)
|
||||
return;
|
||||
|
||||
// Indicate to the render process that the test should be run.
|
||||
command_line->AppendSwitchWithValue("test", kOrderNavMsg);
|
||||
}
|
||||
|
||||
virtual void OnRenderProcessThreadCreated(
|
||||
CefRefPtr<ClientApp> app,
|
||||
CefRefPtr<CefListValue> extra_info) OVERRIDE {
|
||||
if (!g_order_nav_test)
|
||||
return;
|
||||
|
||||
// Some data that we'll check for.
|
||||
SetOrderNavExtraInfo(extra_info);
|
||||
}
|
||||
|
||||
protected:
|
||||
IMPLEMENT_REFCOUNTING(OrderNavBrowserTest);
|
||||
};
|
||||
|
||||
// Renderer side.
|
||||
class OrderNavRendererTest : public ClientApp::RenderDelegate {
|
||||
public:
|
||||
OrderNavRendererTest()
|
||||
: run_test_(false),
|
||||
browser_id_main_(0),
|
||||
browser_id_popup_(0) {}
|
||||
|
||||
virtual void OnRenderThreadCreated(
|
||||
CefRefPtr<ClientApp> app,
|
||||
CefRefPtr<CefListValue> extra_info) OVERRIDE {
|
||||
// Check that the test should be run.
|
||||
CefRefPtr<CefCommandLine> command_line =
|
||||
CefCommandLine::GetGlobalCommandLine();
|
||||
const std::string& test = command_line->GetSwitchValue("test");
|
||||
if (test != kOrderNavMsg)
|
||||
return;
|
||||
|
||||
run_test_ = true;
|
||||
|
||||
EXPECT_FALSE(got_webkit_initialized_);
|
||||
|
||||
got_render_thread_created_.yes();
|
||||
|
||||
// Verify that |extra_info| transferred successfully.
|
||||
CefRefPtr<CefListValue> expected = CefListValue::Create();
|
||||
SetOrderNavExtraInfo(expected);
|
||||
TestListEqual(expected, extra_info);
|
||||
}
|
||||
|
||||
virtual void OnWebKitInitialized(CefRefPtr<ClientApp> app) OVERRIDE {
|
||||
if (!run_test_)
|
||||
return;
|
||||
|
||||
EXPECT_TRUE(got_render_thread_created_);
|
||||
|
||||
got_webkit_initialized_.yes();
|
||||
}
|
||||
|
||||
virtual void OnBrowserCreated(CefRefPtr<ClientApp> app,
|
||||
CefRefPtr<CefBrowser> browser) OVERRIDE {
|
||||
if (!run_test_)
|
||||
return;
|
||||
|
||||
EXPECT_TRUE(got_render_thread_created_);
|
||||
EXPECT_TRUE(got_webkit_initialized_);
|
||||
|
||||
if (browser->IsPopup()) {
|
||||
EXPECT_FALSE(got_browser_created_popup_);
|
||||
EXPECT_FALSE(got_before_navigation_popup_);
|
||||
EXPECT_FALSE(got_browser_destroyed_popup_);
|
||||
|
||||
got_browser_created_popup_.yes();
|
||||
browser_id_popup_ = browser->GetIdentifier();
|
||||
EXPECT_GT(browser->GetIdentifier(), 0);
|
||||
} else {
|
||||
EXPECT_FALSE(got_browser_created_main_);
|
||||
EXPECT_FALSE(got_before_navigation_main_);
|
||||
EXPECT_FALSE(got_browser_destroyed_main_);
|
||||
|
||||
got_browser_created_main_.yes();
|
||||
browser_id_main_ = browser->GetIdentifier();
|
||||
EXPECT_GT(browser->GetIdentifier(), 0);
|
||||
|
||||
browser_main_ = browser;
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnBrowserDestroyed(CefRefPtr<ClientApp> app,
|
||||
CefRefPtr<CefBrowser> browser) OVERRIDE {
|
||||
if (!run_test_)
|
||||
return;
|
||||
|
||||
EXPECT_TRUE(got_render_thread_created_);
|
||||
EXPECT_TRUE(got_webkit_initialized_);
|
||||
|
||||
if (browser->IsPopup()) {
|
||||
EXPECT_TRUE(got_browser_created_popup_);
|
||||
EXPECT_TRUE(got_before_navigation_popup_);
|
||||
EXPECT_FALSE(got_browser_destroyed_popup_);
|
||||
|
||||
got_browser_destroyed_popup_.yes();
|
||||
EXPECT_EQ(browser_id_popup_, browser->GetIdentifier());
|
||||
EXPECT_GT(browser->GetIdentifier(), 0);
|
||||
|
||||
// Use |browser_main_| to send the message otherwise it will fail.
|
||||
SendTestResults(browser_main_, kOrderNavClosedMsg);
|
||||
} else {
|
||||
EXPECT_TRUE(got_browser_created_main_);
|
||||
EXPECT_TRUE(got_before_navigation_main_);
|
||||
EXPECT_FALSE(got_browser_destroyed_main_);
|
||||
|
||||
got_browser_destroyed_main_.yes();
|
||||
EXPECT_EQ(browser_id_main_, browser->GetIdentifier());
|
||||
EXPECT_GT(browser->GetIdentifier(), 0);
|
||||
|
||||
browser_main_ = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool OnBeforeNavigation(CefRefPtr<ClientApp> app,
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
cef_navigation_type_t navigation_type,
|
||||
bool is_redirect) OVERRIDE {
|
||||
if (!run_test_)
|
||||
return false;
|
||||
|
||||
EXPECT_TRUE(got_render_thread_created_);
|
||||
EXPECT_TRUE(got_webkit_initialized_);
|
||||
|
||||
if (browser->IsPopup()) {
|
||||
EXPECT_TRUE(got_browser_created_popup_);
|
||||
EXPECT_FALSE(got_before_navigation_popup_);
|
||||
EXPECT_FALSE(got_browser_destroyed_popup_);
|
||||
|
||||
got_before_navigation_popup_.yes();
|
||||
EXPECT_EQ(browser_id_popup_, browser->GetIdentifier());
|
||||
EXPECT_GT(browser->GetIdentifier(), 0);
|
||||
} else {
|
||||
EXPECT_TRUE(got_browser_created_main_);
|
||||
EXPECT_FALSE(got_before_navigation_main_);
|
||||
EXPECT_FALSE(got_browser_destroyed_main_);
|
||||
|
||||
got_before_navigation_main_.yes();
|
||||
EXPECT_EQ(browser_id_main_, browser->GetIdentifier());
|
||||
EXPECT_GT(browser->GetIdentifier(), 0);
|
||||
}
|
||||
|
||||
std::string url = request->GetURL();
|
||||
if (url == KONav1)
|
||||
EXPECT_FALSE(browser->IsPopup());
|
||||
else if (url == KONav2)
|
||||
EXPECT_TRUE(browser->IsPopup());
|
||||
else
|
||||
EXPECT_TRUE(false); // not reached
|
||||
|
||||
SendTestResults(browser, kOrderNavMsg);
|
||||
return false;
|
||||
}
|
||||
|
||||
protected:
|
||||
// Send the test results.
|
||||
void SendTestResults(CefRefPtr<CefBrowser> browser, const char* msg_name) {
|
||||
// Check if the test has failed.
|
||||
bool result = !TestFailed();
|
||||
|
||||
// Return the result to the browser process.
|
||||
CefRefPtr<CefProcessMessage> return_msg =
|
||||
CefProcessMessage::Create(msg_name);
|
||||
CefRefPtr<CefListValue> args = return_msg->GetArgumentList();
|
||||
EXPECT_TRUE(args.get());
|
||||
EXPECT_TRUE(args->SetBool(0, result));
|
||||
if (browser->IsPopup())
|
||||
EXPECT_TRUE(args->SetInt(1, browser_id_popup_));
|
||||
else
|
||||
EXPECT_TRUE(args->SetInt(1, browser_id_main_));
|
||||
EXPECT_TRUE(browser->SendProcessMessage(PID_BROWSER, return_msg));
|
||||
}
|
||||
|
||||
bool run_test_;
|
||||
|
||||
int browser_id_main_;
|
||||
int browser_id_popup_;
|
||||
CefRefPtr<CefBrowser> browser_main_;
|
||||
TrackCallback got_render_thread_created_;
|
||||
TrackCallback got_webkit_initialized_;
|
||||
TrackCallback got_browser_created_main_;
|
||||
TrackCallback got_browser_destroyed_main_;
|
||||
TrackCallback got_before_navigation_main_;
|
||||
TrackCallback got_browser_created_popup_;
|
||||
TrackCallback got_browser_destroyed_popup_;
|
||||
TrackCallback got_before_navigation_popup_;
|
||||
|
||||
IMPLEMENT_REFCOUNTING(OrderNavRendererTest);
|
||||
};
|
||||
|
||||
// Browser side.
|
||||
class OrderNavTestHandler : public TestHandler {
|
||||
public:
|
||||
OrderNavTestHandler()
|
||||
: browser_id_main_(0),
|
||||
browser_id_popup_(0),
|
||||
got_message_(false),
|
||||
got_load_end_(false) {}
|
||||
|
||||
virtual void RunTest() OVERRIDE {
|
||||
// Add the resources that we will navigate to/from.
|
||||
AddResource(KONav1, "<html>Nav1</html>", "text/html");
|
||||
AddResource(KONav2, "<html>Nav2</html>", "text/html");
|
||||
|
||||
// Create the browser.
|
||||
CreateBrowser(KONav1);
|
||||
}
|
||||
|
||||
void ContinueIfReady(CefRefPtr<CefBrowser> browser) {
|
||||
if (!got_message_ || !got_load_end_)
|
||||
return;
|
||||
|
||||
got_message_ = false;
|
||||
got_load_end_ = false;
|
||||
|
||||
if (!browser->IsPopup()) {
|
||||
// Create the popup window.
|
||||
browser->GetMainFrame()->ExecuteJavaScript(
|
||||
"window.open('" + std::string(KONav2) + "');", CefString(), 0);
|
||||
} else {
|
||||
// Close the popup window.
|
||||
browser_popup_->GetHost()->CloseBrowser();
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE {
|
||||
TestHandler::OnAfterCreated(browser);
|
||||
|
||||
if (browser->IsPopup()) {
|
||||
browser_id_popup_ = browser->GetIdentifier();
|
||||
EXPECT_GT(browser_id_popup_, 0);
|
||||
browser_popup_ = browser;
|
||||
} else {
|
||||
browser_id_main_ = browser->GetIdentifier();
|
||||
EXPECT_GT(browser_id_main_, 0);
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request) OVERRIDE {
|
||||
if (browser->IsPopup()) {
|
||||
EXPECT_GT(browser->GetIdentifier(), 0);
|
||||
EXPECT_EQ(browser_id_popup_, browser->GetIdentifier());
|
||||
} else {
|
||||
EXPECT_GT(browser->GetIdentifier(), 0);
|
||||
EXPECT_EQ(browser_id_main_, browser->GetIdentifier());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void OnLoadStart(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame) OVERRIDE {
|
||||
if (browser->IsPopup()) {
|
||||
EXPECT_GT(browser->GetIdentifier(), 0);
|
||||
EXPECT_EQ(browser_id_popup_, browser->GetIdentifier());
|
||||
} else {
|
||||
EXPECT_GT(browser->GetIdentifier(), 0);
|
||||
EXPECT_EQ(browser_id_main_, browser->GetIdentifier());
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
int httpStatusCode) OVERRIDE {
|
||||
if (browser->IsPopup()) {
|
||||
EXPECT_GT(browser->GetIdentifier(), 0);
|
||||
EXPECT_EQ(browser_id_popup_, browser->GetIdentifier());
|
||||
} else {
|
||||
EXPECT_GT(browser->GetIdentifier(), 0);
|
||||
EXPECT_EQ(browser_id_main_, browser->GetIdentifier());
|
||||
}
|
||||
|
||||
got_load_end_ = true;
|
||||
ContinueIfReady(browser);
|
||||
}
|
||||
|
||||
virtual bool OnProcessMessageReceived(
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
CefProcessId source_process,
|
||||
CefRefPtr<CefProcessMessage> message) OVERRIDE {
|
||||
if (browser->IsPopup()) {
|
||||
EXPECT_GT(browser->GetIdentifier(), 0);
|
||||
EXPECT_EQ(browser_id_popup_, browser->GetIdentifier());
|
||||
} else {
|
||||
EXPECT_GT(browser->GetIdentifier(), 0);
|
||||
EXPECT_EQ(browser_id_main_, browser->GetIdentifier());
|
||||
}
|
||||
|
||||
const std::string& msg_name = message->GetName();
|
||||
if (msg_name == kOrderNavMsg || msg_name == kOrderNavClosedMsg) {
|
||||
// Test that the renderer side succeeded.
|
||||
CefRefPtr<CefListValue> args = message->GetArgumentList();
|
||||
EXPECT_TRUE(args.get());
|
||||
EXPECT_TRUE(args->GetBool(0));
|
||||
|
||||
if (browser->IsPopup()) {
|
||||
EXPECT_EQ(browser_id_popup_, args->GetInt(1));
|
||||
} else {
|
||||
EXPECT_EQ(browser_id_main_, args->GetInt(1));
|
||||
}
|
||||
|
||||
if (msg_name == kOrderNavMsg) {
|
||||
// Continue with the test.
|
||||
got_message_ = true;
|
||||
ContinueIfReady(browser);
|
||||
} else {
|
||||
// Popup was closed. End the test.
|
||||
browser_popup_ = NULL;
|
||||
DestroyTest();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Message not handled.
|
||||
return false;
|
||||
}
|
||||
|
||||
protected:
|
||||
int browser_id_main_;
|
||||
int browser_id_popup_;
|
||||
CefRefPtr<CefBrowser> browser_popup_;
|
||||
|
||||
bool got_message_;
|
||||
bool got_load_end_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
// Verify the order of navigation-related callbacks.
|
||||
TEST(NavigationTest, Order) {
|
||||
g_order_nav_test = true;
|
||||
CefRefPtr<OrderNavTestHandler> handler =
|
||||
new OrderNavTestHandler();
|
||||
handler->ExecuteTest();
|
||||
g_order_nav_test = false;
|
||||
}
|
||||
|
||||
|
||||
// Entry point for creating navigation browser test objects.
|
||||
// Called from client_app_delegates.cc.
|
||||
void CreateNavigationBrowserTests(ClientApp::BrowserDelegateSet& delegates) {
|
||||
delegates.insert(new HistoryNavBrowserTest);
|
||||
delegates.insert(new OrderNavBrowserTest);
|
||||
}
|
||||
|
||||
// Entry point for creating navigation renderer test objects.
|
||||
// Called from client_app_delegates.cc.
|
||||
void CreateNavigationRendererTests(
|
||||
ClientApp::RenderDelegateSet& delegates) {
|
||||
void CreateNavigationRendererTests(ClientApp::RenderDelegateSet& delegates) {
|
||||
delegates.insert(new HistoryNavRendererTest);
|
||||
delegates.insert(new OrderNavRendererTest);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue