mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
- Move browser object tracking from CefContext to CefContentBrowserClient and introduce a new CefBrowserInfo class to simplify ID management (issue #830).
- Add a new CefBrowser::IsSame method (issue #830). - Improve CefRenderProcessHandler::OnBrowserCreated documentation (issue #830). - Add a new NavigationTest.CrossOrigin test for cross-origin navigation (issue #830). - Fix existing NavigationTest tests to run in single-process mode. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@963 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
2
cef.gyp
2
cef.gyp
@ -791,6 +791,8 @@
|
|||||||
'libcef/browser/browser_context.h',
|
'libcef/browser/browser_context.h',
|
||||||
'libcef/browser/browser_host_impl.cc',
|
'libcef/browser/browser_host_impl.cc',
|
||||||
'libcef/browser/browser_host_impl.h',
|
'libcef/browser/browser_host_impl.h',
|
||||||
|
'libcef/browser/browser_info.cc',
|
||||||
|
'libcef/browser/browser_info.h',
|
||||||
'libcef/browser/browser_main.cc',
|
'libcef/browser/browser_main.cc',
|
||||||
'libcef/browser/browser_main.h',
|
'libcef/browser/browser_main.h',
|
||||||
'libcef/browser/browser_message_filter.cc',
|
'libcef/browser/browser_message_filter.cc',
|
||||||
|
@ -109,6 +109,13 @@ typedef struct _cef_browser_t {
|
|||||||
///
|
///
|
||||||
int (CEF_CALLBACK *get_identifier)(struct _cef_browser_t* self);
|
int (CEF_CALLBACK *get_identifier)(struct _cef_browser_t* self);
|
||||||
|
|
||||||
|
///
|
||||||
|
// Returns true (1) if this object is pointing to the same handle as |that|
|
||||||
|
// object.
|
||||||
|
///
|
||||||
|
int (CEF_CALLBACK *is_same)(struct _cef_browser_t* self,
|
||||||
|
struct _cef_browser_t* that);
|
||||||
|
|
||||||
///
|
///
|
||||||
// Returns true (1) if the window is a popup window.
|
// Returns true (1) if the window is a popup window.
|
||||||
///
|
///
|
||||||
|
@ -72,7 +72,9 @@ typedef struct _cef_render_process_handler_t {
|
|||||||
struct _cef_render_process_handler_t* self);
|
struct _cef_render_process_handler_t* self);
|
||||||
|
|
||||||
///
|
///
|
||||||
// Called after a browser has been created.
|
// Called after a browser has been created. When browsing cross-origin a new
|
||||||
|
// browser will be created before the old browser with the same identifier is
|
||||||
|
// destroyed.
|
||||||
///
|
///
|
||||||
void (CEF_CALLBACK *on_browser_created)(
|
void (CEF_CALLBACK *on_browser_created)(
|
||||||
struct _cef_render_process_handler_t* self,
|
struct _cef_render_process_handler_t* self,
|
||||||
|
@ -117,6 +117,13 @@ class CefBrowser : public virtual CefBase {
|
|||||||
/*--cef()--*/
|
/*--cef()--*/
|
||||||
virtual int GetIdentifier() =0;
|
virtual int GetIdentifier() =0;
|
||||||
|
|
||||||
|
///
|
||||||
|
// Returns true if this object is pointing to the same handle as |that|
|
||||||
|
// object.
|
||||||
|
///
|
||||||
|
/*--cef()--*/
|
||||||
|
virtual bool IsSame(CefRefPtr<CefBrowser> that) =0;
|
||||||
|
|
||||||
///
|
///
|
||||||
// Returns true if the window is a popup window.
|
// Returns true if the window is a popup window.
|
||||||
///
|
///
|
||||||
|
@ -71,7 +71,9 @@ class CefRenderProcessHandler : public virtual CefBase {
|
|||||||
virtual void OnWebKitInitialized() {}
|
virtual void OnWebKitInitialized() {}
|
||||||
|
|
||||||
///
|
///
|
||||||
// Called after a browser has been created.
|
// Called after a browser has been created. When browsing cross-origin a new
|
||||||
|
// browser will be created before the old browser with the same identifier is
|
||||||
|
// destroyed.
|
||||||
///
|
///
|
||||||
/*--cef()--*/
|
/*--cef()--*/
|
||||||
virtual void OnBrowserCreated(CefRefPtr<CefBrowser> browser) {}
|
virtual void OnBrowserCreated(CefRefPtr<CefBrowser> browser) {}
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "libcef/browser/browser_context.h"
|
#include "libcef/browser/browser_context.h"
|
||||||
|
#include "libcef/browser/browser_info.h"
|
||||||
#include "libcef/browser/chrome_scheme_handler.h"
|
#include "libcef/browser/chrome_scheme_handler.h"
|
||||||
#include "libcef/browser/content_browser_client.h"
|
#include "libcef/browser/content_browser_client.h"
|
||||||
#include "libcef/browser/context.h"
|
#include "libcef/browser/context.h"
|
||||||
@ -273,9 +274,11 @@ CefRefPtr<CefBrowser> CefBrowserHost::CreateBrowserSync(
|
|||||||
_Context->browser_context()->set_use_osr_next_contents_view(
|
_Context->browser_context()->set_use_osr_next_contents_view(
|
||||||
CefBrowserHostImpl::IsWindowRenderingDisabled(windowInfo));
|
CefBrowserHostImpl::IsWindowRenderingDisabled(windowInfo));
|
||||||
|
|
||||||
int browser_id = _Context->GetNextBrowserID();
|
scoped_refptr<CefBrowserInfo> info =
|
||||||
|
CefContentBrowserClient::Get()->CreateBrowserInfo();
|
||||||
|
DCHECK(!info->is_popup());
|
||||||
CefRefPtr<CefBrowserHostImpl> browser =
|
CefRefPtr<CefBrowserHostImpl> browser =
|
||||||
CefBrowserHostImpl::Create(windowInfo, settings, client, NULL, browser_id,
|
CefBrowserHostImpl::Create(windowInfo, settings, client, NULL, info,
|
||||||
NULL);
|
NULL);
|
||||||
if (!url.empty())
|
if (!url.empty())
|
||||||
browser->LoadURL(CefFrameHostImpl::kMainFrameId, url);
|
browser->LoadURL(CefFrameHostImpl::kMainFrameId, url);
|
||||||
@ -295,9 +298,13 @@ CefRefPtr<CefBrowserHostImpl> CefBrowserHostImpl::Create(
|
|||||||
const CefBrowserSettings& settings,
|
const CefBrowserSettings& settings,
|
||||||
CefRefPtr<CefClient> client,
|
CefRefPtr<CefClient> client,
|
||||||
content::WebContents* web_contents,
|
content::WebContents* web_contents,
|
||||||
int browser_id,
|
scoped_refptr<CefBrowserInfo> browser_info,
|
||||||
CefWindowHandle opener) {
|
CefWindowHandle opener) {
|
||||||
CEF_REQUIRE_UIT();
|
CEF_REQUIRE_UIT();
|
||||||
|
DCHECK(browser_info.get());
|
||||||
|
|
||||||
|
// If |opener| is non-NULL it must be a popup window.
|
||||||
|
DCHECK(opener == NULL || browser_info->is_popup());
|
||||||
|
|
||||||
if (web_contents == NULL) {
|
if (web_contents == NULL) {
|
||||||
web_contents = content::WebContents::Create(
|
web_contents = content::WebContents::Create(
|
||||||
@ -309,7 +316,7 @@ CefRefPtr<CefBrowserHostImpl> CefBrowserHostImpl::Create(
|
|||||||
|
|
||||||
CefRefPtr<CefBrowserHostImpl> browser =
|
CefRefPtr<CefBrowserHostImpl> browser =
|
||||||
new CefBrowserHostImpl(window_info, settings, client, web_contents,
|
new CefBrowserHostImpl(window_info, settings, client, web_contents,
|
||||||
browser_id, opener);
|
browser_info, opener);
|
||||||
if (!browser->IsWindowRenderingDisabled() &&
|
if (!browser->IsWindowRenderingDisabled() &&
|
||||||
!browser->PlatformCreateWindow()) {
|
!browser->PlatformCreateWindow()) {
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -327,8 +334,6 @@ CefRefPtr<CefBrowserHostImpl> CefBrowserHostImpl::Create(
|
|||||||
}
|
}
|
||||||
#endif // OS_WIN
|
#endif // OS_WIN
|
||||||
|
|
||||||
_Context->AddBrowser(browser);
|
|
||||||
|
|
||||||
if (client.get()) {
|
if (client.get()) {
|
||||||
CefRefPtr<CefLifeSpanHandler> handler = client->GetLifeSpanHandler();
|
CefRefPtr<CefLifeSpanHandler> handler = client->GetLifeSpanHandler();
|
||||||
if (handler.get())
|
if (handler.get())
|
||||||
@ -784,8 +789,13 @@ int CefBrowserHostImpl::GetIdentifier() {
|
|||||||
return browser_id();
|
return browser_id();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CefBrowserHostImpl::IsSame(CefRefPtr<CefBrowser> that) {
|
||||||
|
CefBrowserHostImpl* impl = static_cast<CefBrowserHostImpl*>(that.get());
|
||||||
|
return (impl == this);
|
||||||
|
}
|
||||||
|
|
||||||
bool CefBrowserHostImpl::IsPopup() {
|
bool CefBrowserHostImpl::IsPopup() {
|
||||||
return (opener_ != NULL);
|
return browser_info_->is_popup();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CefBrowserHostImpl::HasDocument() {
|
bool CefBrowserHostImpl::HasDocument() {
|
||||||
@ -927,8 +937,8 @@ void CefBrowserHostImpl::DestroyBrowser() {
|
|||||||
|
|
||||||
request_context_proxy_ = NULL;
|
request_context_proxy_ = NULL;
|
||||||
|
|
||||||
// Remove the browser from the list maintained by the context.
|
CefContentBrowserClient::Get()->RemoveBrowserInfo(browser_info_);
|
||||||
_Context->RemoveBrowser(this);
|
browser_info_->set_browser(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
gfx::NativeView CefBrowserHostImpl::GetContentView() const {
|
gfx::NativeView CefBrowserHostImpl::GetContentView() const {
|
||||||
@ -1189,11 +1199,8 @@ void CefBrowserHostImpl::HandleExternalProtocol(const GURL& url) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CefBrowserHostImpl::HasIDMatch(int render_process_id, int render_view_id) {
|
int CefBrowserHostImpl::browser_id() const {
|
||||||
base::AutoLock lock_scope(state_lock_);
|
return browser_info_->browser_id();
|
||||||
if (render_process_id != render_process_id_)
|
|
||||||
return false;
|
|
||||||
return (render_view_id == 0 || render_view_id == render_view_id_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GURL CefBrowserHostImpl::GetLoadingURL() {
|
GURL CefBrowserHostImpl::GetLoadingURL() {
|
||||||
@ -1451,19 +1458,25 @@ void CefBrowserHostImpl::WebContentsCreated(
|
|||||||
const GURL& target_url,
|
const GURL& target_url,
|
||||||
content::WebContents* new_contents) {
|
content::WebContents* new_contents) {
|
||||||
CefWindowHandle opener = NULL;
|
CefWindowHandle opener = NULL;
|
||||||
if (source_contents)
|
scoped_refptr<CefBrowserInfo> info;
|
||||||
|
if (source_contents) {
|
||||||
opener = GetBrowserForContents(source_contents)->GetWindowHandle();
|
opener = GetBrowserForContents(source_contents)->GetWindowHandle();
|
||||||
|
|
||||||
CefContentBrowserClient::NewPopupBrowserInfo info;
|
// Popup windows may not have info yet.
|
||||||
CefContentBrowserClient::Get()->GetNewPopupBrowserInfo(
|
info = CefContentBrowserClient::Get()->GetOrCreateBrowserInfo(
|
||||||
new_contents->GetRenderProcessHost()->GetID(),
|
new_contents->GetRenderProcessHost()->GetID(),
|
||||||
new_contents->GetRoutingID(),
|
new_contents->GetRoutingID());
|
||||||
&info);
|
DCHECK(info->is_popup());
|
||||||
DCHECK_GT(info.browser_id, 0);
|
} else {
|
||||||
|
info = CefContentBrowserClient::Get()->GetBrowserInfo(
|
||||||
|
new_contents->GetRenderProcessHost()->GetID(),
|
||||||
|
new_contents->GetRoutingID());
|
||||||
|
DCHECK(!info->is_popup());
|
||||||
|
}
|
||||||
|
|
||||||
CefRefPtr<CefBrowserHostImpl> browser = CefBrowserHostImpl::Create(
|
CefRefPtr<CefBrowserHostImpl> browser = CefBrowserHostImpl::Create(
|
||||||
pending_window_info_, pending_settings_, pending_client_, new_contents,
|
pending_window_info_, pending_settings_, pending_client_, new_contents,
|
||||||
info.browser_id, opener);
|
info, opener);
|
||||||
|
|
||||||
pending_client_ = NULL;
|
pending_client_ = NULL;
|
||||||
}
|
}
|
||||||
@ -1521,7 +1534,24 @@ void CefBrowserHostImpl::RequestMediaAccessPermission(
|
|||||||
|
|
||||||
void CefBrowserHostImpl::RenderViewCreated(
|
void CefBrowserHostImpl::RenderViewCreated(
|
||||||
content::RenderViewHost* render_view_host) {
|
content::RenderViewHost* render_view_host) {
|
||||||
SetRenderViewHost(render_view_host);
|
// When navigating cross-origin the new (pending) RenderViewHost will be
|
||||||
|
// created before the old (current) RenderViewHost is destroyed. It may be
|
||||||
|
// necessary in the future to track both current and pending render IDs.
|
||||||
|
browser_info_->set_render_ids(render_view_host->GetProcess()->GetID(),
|
||||||
|
render_view_host->GetRoutingID());
|
||||||
|
|
||||||
|
// Update the DevTools URLs, if any.
|
||||||
|
CefDevToolsDelegate* devtools_delegate = _Context->devtools_delegate();
|
||||||
|
if (devtools_delegate) {
|
||||||
|
base::AutoLock lock_scope(state_lock_);
|
||||||
|
devtools_url_http_ =
|
||||||
|
devtools_delegate->GetDevToolsURL(render_view_host, true);
|
||||||
|
devtools_url_chrome_ =
|
||||||
|
devtools_delegate->GetDevToolsURL(render_view_host, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
registrar_->Add(this, content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
|
||||||
|
content::Source<content::RenderViewHost>(render_view_host));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CefBrowserHostImpl::RenderViewDeleted(
|
void CefBrowserHostImpl::RenderViewDeleted(
|
||||||
@ -1531,12 +1561,6 @@ void CefBrowserHostImpl::RenderViewDeleted(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CefBrowserHostImpl::RenderViewReady() {
|
void CefBrowserHostImpl::RenderViewReady() {
|
||||||
if (IsPopup()) {
|
|
||||||
CefContentBrowserClient::Get()->ClearNewPopupBrowserInfo(
|
|
||||||
web_contents()->GetRenderProcessHost()->GetID(),
|
|
||||||
web_contents()->GetRoutingID());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send the queued messages.
|
// Send the queued messages.
|
||||||
queue_messages_ = false;
|
queue_messages_ = false;
|
||||||
while (!queued_messages_.empty()) {
|
while (!queued_messages_.empty()) {
|
||||||
@ -1756,20 +1780,19 @@ void CefBrowserHostImpl::Observe(int type,
|
|||||||
// CefBrowserHostImpl private methods.
|
// CefBrowserHostImpl private methods.
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
CefBrowserHostImpl::CefBrowserHostImpl(const CefWindowInfo& window_info,
|
CefBrowserHostImpl::CefBrowserHostImpl(
|
||||||
|
const CefWindowInfo& window_info,
|
||||||
const CefBrowserSettings& settings,
|
const CefBrowserSettings& settings,
|
||||||
CefRefPtr<CefClient> client,
|
CefRefPtr<CefClient> client,
|
||||||
content::WebContents* web_contents,
|
content::WebContents* web_contents,
|
||||||
int browser_id,
|
scoped_refptr<CefBrowserInfo> browser_info,
|
||||||
CefWindowHandle opener)
|
CefWindowHandle opener)
|
||||||
: content::WebContentsObserver(web_contents),
|
: content::WebContentsObserver(web_contents),
|
||||||
window_info_(window_info),
|
window_info_(window_info),
|
||||||
settings_(settings),
|
settings_(settings),
|
||||||
client_(client),
|
client_(client),
|
||||||
browser_id_(browser_id),
|
browser_info_(browser_info),
|
||||||
opener_(opener),
|
opener_(opener),
|
||||||
render_process_id_(MSG_ROUTING_NONE),
|
|
||||||
render_view_id_(MSG_ROUTING_NONE),
|
|
||||||
is_loading_(false),
|
is_loading_(false),
|
||||||
can_go_back_(false),
|
can_go_back_(false),
|
||||||
can_go_forward_(false),
|
can_go_forward_(false),
|
||||||
@ -1780,6 +1803,9 @@ CefBrowserHostImpl::CefBrowserHostImpl(const CefWindowInfo& window_info,
|
|||||||
is_in_onsetfocus_(false),
|
is_in_onsetfocus_(false),
|
||||||
focus_on_editable_field_(false),
|
focus_on_editable_field_(false),
|
||||||
file_chooser_pending_(false) {
|
file_chooser_pending_(false) {
|
||||||
|
DCHECK(!browser_info_->browser().get());
|
||||||
|
browser_info_->set_browser(this);
|
||||||
|
|
||||||
web_contents_.reset(web_contents);
|
web_contents_.reset(web_contents);
|
||||||
web_contents->SetDelegate(this);
|
web_contents->SetDelegate(this);
|
||||||
|
|
||||||
@ -1791,31 +1817,6 @@ CefBrowserHostImpl::CefBrowserHostImpl(const CefWindowInfo& window_info,
|
|||||||
|
|
||||||
placeholder_frame_ =
|
placeholder_frame_ =
|
||||||
new CefFrameHostImpl(this, CefFrameHostImpl::kInvalidFrameId, true);
|
new CefFrameHostImpl(this, CefFrameHostImpl::kInvalidFrameId, true);
|
||||||
|
|
||||||
SetRenderViewHost(web_contents->GetRenderViewHost());
|
|
||||||
}
|
|
||||||
|
|
||||||
void CefBrowserHostImpl::SetRenderViewHost(content::RenderViewHost* rvh) {
|
|
||||||
{
|
|
||||||
base::AutoLock lock_scope(state_lock_);
|
|
||||||
|
|
||||||
render_view_id_ = rvh->GetRoutingID();
|
|
||||||
render_process_id_ = rvh->GetProcess()->GetID();
|
|
||||||
|
|
||||||
// Update the DevTools URLs, if any.
|
|
||||||
CefDevToolsDelegate* devtools_delegate = _Context->devtools_delegate();
|
|
||||||
if (devtools_delegate) {
|
|
||||||
devtools_url_http_ = devtools_delegate->GetDevToolsURL(rvh, true);
|
|
||||||
devtools_url_chrome_ = devtools_delegate->GetDevToolsURL(rvh, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!registrar_->IsRegistered(
|
|
||||||
this, content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
|
|
||||||
content::Source<content::RenderViewHost>(rvh))) {
|
|
||||||
registrar_->Add(this, content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
|
|
||||||
content::Source<content::RenderViewHost>(rvh));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CefRefPtr<CefFrame> CefBrowserHostImpl::GetOrCreateFrame(
|
CefRefPtr<CefFrame> CefBrowserHostImpl::GetOrCreateFrame(
|
||||||
|
@ -45,6 +45,7 @@ class URLRequest;
|
|||||||
|
|
||||||
struct Cef_Request_Params;
|
struct Cef_Request_Params;
|
||||||
struct Cef_Response_Params;
|
struct Cef_Response_Params;
|
||||||
|
class CefBrowserInfo;
|
||||||
struct CefNavigateParams;
|
struct CefNavigateParams;
|
||||||
class SiteInstance;
|
class SiteInstance;
|
||||||
|
|
||||||
@ -83,7 +84,7 @@ class CefBrowserHostImpl : public CefBrowserHost,
|
|||||||
const CefBrowserSettings& settings,
|
const CefBrowserSettings& settings,
|
||||||
CefRefPtr<CefClient> client,
|
CefRefPtr<CefClient> client,
|
||||||
content::WebContents* web_contents,
|
content::WebContents* web_contents,
|
||||||
int browser_id,
|
scoped_refptr<CefBrowserInfo> browser_info,
|
||||||
CefWindowHandle opener);
|
CefWindowHandle opener);
|
||||||
|
|
||||||
// Returns the browser associated with the specified RenderViewHost.
|
// Returns the browser associated with the specified RenderViewHost.
|
||||||
@ -145,6 +146,7 @@ class CefBrowserHostImpl : public CefBrowserHost,
|
|||||||
virtual void ReloadIgnoreCache() OVERRIDE;
|
virtual void ReloadIgnoreCache() OVERRIDE;
|
||||||
virtual void StopLoad() OVERRIDE;
|
virtual void StopLoad() OVERRIDE;
|
||||||
virtual int GetIdentifier() OVERRIDE;
|
virtual int GetIdentifier() OVERRIDE;
|
||||||
|
virtual bool IsSame(CefRefPtr<CefBrowser> that) OVERRIDE;
|
||||||
virtual bool IsPopup() OVERRIDE;
|
virtual bool IsPopup() OVERRIDE;
|
||||||
virtual bool HasDocument() OVERRIDE;
|
virtual bool HasDocument() OVERRIDE;
|
||||||
virtual CefRefPtr<CefFrame> GetMainFrame() OVERRIDE;
|
virtual CefRefPtr<CefFrame> GetMainFrame() OVERRIDE;
|
||||||
@ -211,15 +213,10 @@ class CefBrowserHostImpl : public CefBrowserHost,
|
|||||||
// Handler for URLs involving external protocols.
|
// Handler for URLs involving external protocols.
|
||||||
void HandleExternalProtocol(const GURL& url);
|
void HandleExternalProtocol(const GURL& url);
|
||||||
|
|
||||||
// Returns true if this browser matches the specified ID values. If
|
|
||||||
// |render_view_id| is 0 any browser with the specified |render_process_id|
|
|
||||||
// will match.
|
|
||||||
bool HasIDMatch(int render_process_id, int render_view_id);
|
|
||||||
|
|
||||||
// Thread safe accessors.
|
// Thread safe accessors.
|
||||||
const CefBrowserSettings& settings() const { return settings_; }
|
const CefBrowserSettings& settings() const { return settings_; }
|
||||||
CefRefPtr<CefClient> client() const { return client_; }
|
CefRefPtr<CefClient> client() const { return client_; }
|
||||||
int browser_id() const { return browser_id_; }
|
int browser_id() const;
|
||||||
|
|
||||||
// Returns the URL that is currently loading (or loaded) in the main frame.
|
// Returns the URL that is currently loading (or loaded) in the main frame.
|
||||||
GURL GetLoadingURL();
|
GURL GetLoadingURL();
|
||||||
@ -344,12 +341,9 @@ class CefBrowserHostImpl : public CefBrowserHost,
|
|||||||
const CefBrowserSettings& settings,
|
const CefBrowserSettings& settings,
|
||||||
CefRefPtr<CefClient> client,
|
CefRefPtr<CefClient> client,
|
||||||
content::WebContents* web_contents,
|
content::WebContents* web_contents,
|
||||||
int browser_id,
|
scoped_refptr<CefBrowserInfo> browser_info,
|
||||||
CefWindowHandle opener);
|
CefWindowHandle opener);
|
||||||
|
|
||||||
// Initialize settings based on the specified RenderViewHost.
|
|
||||||
void SetRenderViewHost(content::RenderViewHost* rvh);
|
|
||||||
|
|
||||||
// Updates and returns an existing frame or creates a new frame. Pass
|
// Updates and returns an existing frame or creates a new frame. Pass
|
||||||
// CefFrameHostImpl::kUnspecifiedFrameId for |parent_frame_id| if unknown.
|
// CefFrameHostImpl::kUnspecifiedFrameId for |parent_frame_id| if unknown.
|
||||||
CefRefPtr<CefFrame> GetOrCreateFrame(int64 frame_id,
|
CefRefPtr<CefFrame> GetOrCreateFrame(int64 frame_id,
|
||||||
@ -432,15 +426,9 @@ class CefBrowserHostImpl : public CefBrowserHost,
|
|||||||
CefBrowserSettings settings_;
|
CefBrowserSettings settings_;
|
||||||
CefRefPtr<CefClient> client_;
|
CefRefPtr<CefClient> client_;
|
||||||
scoped_ptr<content::WebContents> web_contents_;
|
scoped_ptr<content::WebContents> web_contents_;
|
||||||
int browser_id_;
|
scoped_refptr<CefBrowserInfo> browser_info_;
|
||||||
CefWindowHandle opener_;
|
CefWindowHandle opener_;
|
||||||
|
|
||||||
// Unique ids used for routing communication to/from the renderer. We keep a
|
|
||||||
// copy of them as member variables so that we can locate matching browsers in
|
|
||||||
// a thread safe manner. All access must be protected by the state lock.
|
|
||||||
int render_process_id_;
|
|
||||||
int render_view_id_;
|
|
||||||
|
|
||||||
// Used when creating a new popup window.
|
// Used when creating a new popup window.
|
||||||
CefWindowInfo pending_window_info_;
|
CefWindowInfo pending_window_info_;
|
||||||
CefBrowserSettings pending_settings_;
|
CefBrowserSettings pending_settings_;
|
||||||
|
42
libcef/browser/browser_info.cc
Normal file
42
libcef/browser/browser_info.cc
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
// Copyright (c) 2012 The Chromium Embedded Framework 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/browser_info.h"
|
||||||
|
#include "ipc/ipc_message.h"
|
||||||
|
|
||||||
|
CefBrowserInfo::CefBrowserInfo(int browser_id, bool is_popup)
|
||||||
|
: browser_id_(browser_id),
|
||||||
|
is_popup_(is_popup),
|
||||||
|
render_process_id_(MSG_ROUTING_NONE),
|
||||||
|
render_view_id_(MSG_ROUTING_NONE) {
|
||||||
|
DCHECK_GT(browser_id, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
CefBrowserInfo::~CefBrowserInfo() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void CefBrowserInfo::set_render_ids(
|
||||||
|
int render_process_id, int render_view_id) {
|
||||||
|
base::AutoLock lock_scope(lock_);
|
||||||
|
render_process_id_ = render_process_id;
|
||||||
|
render_view_id_ = render_view_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CefBrowserInfo::is_render_id_match(
|
||||||
|
int render_process_id, int render_view_id) {
|
||||||
|
base::AutoLock lock_scope(lock_);
|
||||||
|
if (render_process_id != render_process_id_)
|
||||||
|
return false;
|
||||||
|
return (render_view_id == 0 || render_view_id == render_view_id_);
|
||||||
|
}
|
||||||
|
|
||||||
|
CefRefPtr<CefBrowserHostImpl> CefBrowserInfo::browser() {
|
||||||
|
base::AutoLock lock_scope(lock_);
|
||||||
|
return browser_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CefBrowserInfo::set_browser(CefRefPtr<CefBrowserHostImpl> browser) {
|
||||||
|
base::AutoLock lock_scope(lock_);
|
||||||
|
browser_ = browser;
|
||||||
|
}
|
53
libcef/browser/browser_info.h
Normal file
53
libcef/browser/browser_info.h
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
// Copyright (c) 2012 The Chromium Embedded Framework 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_BROWSER_INFO_H_
|
||||||
|
#define CEF_LIBCEF_BROWSER_BROWSER_INFO_H_
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "libcef/browser/browser_host_impl.h"
|
||||||
|
#include "base/memory/ref_counted.h"
|
||||||
|
|
||||||
|
// CefBrowserInfo is used to associate a browser ID and render view/process
|
||||||
|
// IDs with a particular CefBrowserHostImpl. Render view/process IDs may change
|
||||||
|
// during the lifetime of a single CefBrowserHostImpl.
|
||||||
|
//
|
||||||
|
// CefBrowserInfo objects are managed by CefContentBrowserClient and should not
|
||||||
|
// be created directly.
|
||||||
|
class CefBrowserInfo : public base::RefCountedThreadSafe<CefBrowserInfo> {
|
||||||
|
public:
|
||||||
|
CefBrowserInfo(int browser_id, bool is_popup);
|
||||||
|
virtual ~CefBrowserInfo();
|
||||||
|
|
||||||
|
int browser_id() const { return browser_id_; };
|
||||||
|
bool is_popup() const { return is_popup_; }
|
||||||
|
|
||||||
|
void set_render_ids(int render_process_id, int render_view_id);
|
||||||
|
|
||||||
|
// Returns true if this browser matches the specified ID values. If
|
||||||
|
// |render_view_id| is 0 any browser with the specified |render_process_id|
|
||||||
|
// will match.
|
||||||
|
bool is_render_id_match(int render_process_id, int render_view_id);
|
||||||
|
|
||||||
|
CefRefPtr<CefBrowserHostImpl> browser();
|
||||||
|
void set_browser(CefRefPtr<CefBrowserHostImpl> browser);
|
||||||
|
|
||||||
|
private:
|
||||||
|
int browser_id_;
|
||||||
|
bool is_popup_;
|
||||||
|
|
||||||
|
base::Lock lock_;
|
||||||
|
|
||||||
|
// The below members must be protected by |lock_|.
|
||||||
|
int render_process_id_;
|
||||||
|
int render_view_id_;
|
||||||
|
|
||||||
|
// May be NULL if the browser has not yet been created or if the browser has
|
||||||
|
// been destroyed.
|
||||||
|
CefRefPtr<CefBrowserHostImpl> browser_;
|
||||||
|
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(CefBrowserInfo);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CEF_LIBCEF_BROWSER_BROWSER_INFO_H_
|
@ -6,6 +6,7 @@
|
|||||||
#include "libcef/browser/browser_message_filter.h"
|
#include "libcef/browser/browser_message_filter.h"
|
||||||
|
|
||||||
#include "libcef/browser/browser_host_impl.h"
|
#include "libcef/browser/browser_host_impl.h"
|
||||||
|
#include "libcef/browser/browser_info.h"
|
||||||
#include "libcef/browser/content_browser_client.h"
|
#include "libcef/browser/content_browser_client.h"
|
||||||
#include "libcef/browser/context.h"
|
#include "libcef/browser/context.h"
|
||||||
#include "libcef/browser/origin_whitelist_impl.h"
|
#include "libcef/browser/origin_whitelist_impl.h"
|
||||||
@ -68,18 +69,10 @@ void CefBrowserMessageFilter::OnGetNewRenderThreadInfo(
|
|||||||
|
|
||||||
void CefBrowserMessageFilter::OnGetNewBrowserInfo(
|
void CefBrowserMessageFilter::OnGetNewBrowserInfo(
|
||||||
int routing_id, CefProcessHostMsg_GetNewBrowserInfo_Params* params) {
|
int routing_id, CefProcessHostMsg_GetNewBrowserInfo_Params* params) {
|
||||||
CefRefPtr<CefBrowserHostImpl> browser =
|
// Popup windows may not have info yet.
|
||||||
CefBrowserHostImpl::GetBrowserByRoutingID(host_->GetID(), routing_id);
|
scoped_refptr<CefBrowserInfo> info =
|
||||||
if (browser.get()) {
|
CefContentBrowserClient::Get()->GetOrCreateBrowserInfo(host_->GetID(),
|
||||||
params->browser_id = browser->GetIdentifier();
|
routing_id);
|
||||||
params->is_popup = browser->IsPopup();
|
params->browser_id = info->browser_id();
|
||||||
} else {
|
params->is_popup = info->is_popup();
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "libcef/browser/browser_context.h"
|
#include "libcef/browser/browser_context.h"
|
||||||
|
#include "libcef/browser/browser_info.h"
|
||||||
#include "libcef/browser/browser_host_impl.h"
|
#include "libcef/browser/browser_host_impl.h"
|
||||||
#include "libcef/browser/browser_main.h"
|
#include "libcef/browser/browser_main.h"
|
||||||
#include "libcef/browser/browser_message_filter.h"
|
#include "libcef/browser/browser_message_filter.h"
|
||||||
@ -244,9 +245,9 @@ class CefMediaObserver : public content::MediaObserver {
|
|||||||
content::MediaRequestState state) OVERRIDE {}
|
content::MediaRequestState state) OVERRIDE {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
CefContentBrowserClient::CefContentBrowserClient()
|
CefContentBrowserClient::CefContentBrowserClient()
|
||||||
: browser_main_parts_(NULL) {
|
: browser_main_parts_(NULL),
|
||||||
|
next_browser_id_(0) {
|
||||||
plugin_service_filter_.reset(new CefPluginServiceFilter);
|
plugin_service_filter_.reset(new CefPluginServiceFilter);
|
||||||
content::PluginServiceImpl::GetInstance()->SetFilter(
|
content::PluginServiceImpl::GetInstance()->SetFilter(
|
||||||
plugin_service_filter_.get());
|
plugin_service_filter_.get());
|
||||||
@ -261,36 +262,92 @@ CefContentBrowserClient* CefContentBrowserClient::Get() {
|
|||||||
content::GetContentClient()->browser());
|
content::GetContentClient()->browser());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CefContentBrowserClient::GetNewPopupBrowserInfo(
|
scoped_refptr<CefBrowserInfo> CefContentBrowserClient::CreateBrowserInfo() {
|
||||||
int render_process_id, int render_view_id, NewPopupBrowserInfo* info) {
|
base::AutoLock lock_scope(browser_info_lock_);
|
||||||
base::AutoLock lock_scope(new_popup_browser_lock_);
|
|
||||||
|
|
||||||
NewPopupBrowserInfoMap::const_iterator it =
|
scoped_refptr<CefBrowserInfo> browser_info =
|
||||||
new_popup_browser_info_map_.find(
|
new CefBrowserInfo(++next_browser_id_, false);
|
||||||
std::make_pair(render_process_id, render_view_id));
|
browser_info_list_.push_back(browser_info);
|
||||||
if (it != new_popup_browser_info_map_.end()) {
|
return browser_info;
|
||||||
*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,
|
scoped_refptr<CefBrowserInfo>
|
||||||
|
CefContentBrowserClient::GetOrCreateBrowserInfo(int render_process_id,
|
||||||
int render_view_id) {
|
int render_view_id) {
|
||||||
base::AutoLock lock_scope(new_popup_browser_lock_);
|
base::AutoLock lock_scope(browser_info_lock_);
|
||||||
|
|
||||||
NewPopupBrowserInfoMap::iterator it =
|
BrowserInfoList::const_iterator it = browser_info_list_.begin();
|
||||||
new_popup_browser_info_map_.find(
|
for (; it != browser_info_list_.end(); ++it) {
|
||||||
std::make_pair(render_process_id, render_view_id));
|
const scoped_refptr<CefBrowserInfo>& browser_info = *it;
|
||||||
if (it != new_popup_browser_info_map_.end())
|
if (browser_info->is_render_id_match(render_process_id, render_view_id))
|
||||||
new_popup_browser_info_map_.erase(it);
|
return browser_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Must be a popup if it hasn't already been created.
|
||||||
|
scoped_refptr<CefBrowserInfo> browser_info =
|
||||||
|
new CefBrowserInfo(++next_browser_id_, true);
|
||||||
|
browser_info->set_render_ids(render_process_id, render_view_id);
|
||||||
|
browser_info_list_.push_back(browser_info);
|
||||||
|
return browser_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CefContentBrowserClient::RemoveBrowserInfo(
|
||||||
|
scoped_refptr<CefBrowserInfo> browser_info) {
|
||||||
|
base::AutoLock lock_scope(browser_info_lock_);
|
||||||
|
|
||||||
|
BrowserInfoList::iterator it = browser_info_list_.begin();
|
||||||
|
for (; it != browser_info_list_.end(); ++it) {
|
||||||
|
if (*it == browser_info) {
|
||||||
|
browser_info_list_.erase(it);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NOTREACHED();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CefContentBrowserClient::DestroyAllBrowsers() {
|
||||||
|
BrowserInfoList list;
|
||||||
|
|
||||||
|
{
|
||||||
|
base::AutoLock lock_scope(browser_info_lock_);
|
||||||
|
list = browser_info_list_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destroy any remaining browser windows.
|
||||||
|
if (!list.empty()) {
|
||||||
|
BrowserInfoList::iterator it = list.begin();
|
||||||
|
for (; it != list.end(); ++it) {
|
||||||
|
CefRefPtr<CefBrowserHostImpl> browser = (*it)->browser();
|
||||||
|
if (browser.get())
|
||||||
|
browser->DestroyBrowser();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
{
|
||||||
|
// Verify that all browser windows have been destroyed.
|
||||||
|
base::AutoLock lock_scope(browser_info_lock_);
|
||||||
|
DCHECK(browser_info_list_.empty());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
scoped_refptr<CefBrowserInfo> CefContentBrowserClient::GetBrowserInfo(
|
||||||
|
int render_process_id, int render_view_id) {
|
||||||
|
base::AutoLock lock_scope(browser_info_lock_);
|
||||||
|
|
||||||
|
BrowserInfoList::const_iterator it = browser_info_list_.begin();
|
||||||
|
for (; it != browser_info_list_.end(); ++it) {
|
||||||
|
const scoped_refptr<CefBrowserInfo>& browser_info = *it;
|
||||||
|
if (browser_info->is_render_id_match(render_process_id, render_view_id))
|
||||||
|
return browser_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
DLOG(WARNING) << "No browser info matching process id " <<
|
||||||
|
render_process_id << " and view id " << render_view_id;
|
||||||
|
|
||||||
|
return scoped_refptr<CefBrowserInfo>();
|
||||||
}
|
}
|
||||||
|
|
||||||
content::BrowserMainParts* CefContentBrowserClient::CreateBrowserMainParts(
|
content::BrowserMainParts* CefContentBrowserClient::CreateBrowserMainParts(
|
||||||
|
@ -6,16 +6,18 @@
|
|||||||
#define CEF_LIBCEF_BROWSER_CONTENT_BROWSER_CLIENT_H_
|
#define CEF_LIBCEF_BROWSER_CONTENT_BROWSER_CLIENT_H_
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "base/compiler_specific.h"
|
#include "base/compiler_specific.h"
|
||||||
|
#include "base/memory/ref_counted.h"
|
||||||
#include "base/memory/scoped_ptr.h"
|
#include "base/memory/scoped_ptr.h"
|
||||||
#include "base/synchronization/lock.h"
|
#include "base/synchronization/lock.h"
|
||||||
#include "content/public/browser/content_browser_client.h"
|
#include "content/public/browser/content_browser_client.h"
|
||||||
|
|
||||||
|
class CefBrowserInfo;
|
||||||
class CefBrowserMainParts;
|
class CefBrowserMainParts;
|
||||||
class CefMediaObserver;
|
class CefMediaObserver;
|
||||||
class CefResourceDispatcherHostDelegate;
|
class CefResourceDispatcherHostDelegate;
|
||||||
@ -37,20 +39,23 @@ class CefContentBrowserClient : public content::ContentBrowserClient {
|
|||||||
return browser_main_parts_;
|
return browser_main_parts_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Methods for managing CefBrowserInfo life span. Do not add new callers of
|
||||||
|
// these methods.
|
||||||
// During popup window creation there is a race between the call to
|
// During popup window creation there is a race between the call to
|
||||||
// CefBrowserMessageFilter::OnGetNewBrowserInfo on the IO thread and the call
|
// CefBrowserMessageFilter::OnGetNewBrowserInfo on the IO thread and the call
|
||||||
// to CefBrowserHostImpl::WebContentsCreated on the UI thread. To resolve this
|
// to CefBrowserHostImpl::WebContentsCreated on the UI thread. To resolve this
|
||||||
// race we create the info when requested for the first time.
|
// race CefBrowserInfo may be created when requested for the first time and
|
||||||
class NewPopupBrowserInfo {
|
// before the associated CefBrowserHostImpl is created.
|
||||||
public:
|
scoped_refptr<CefBrowserInfo> CreateBrowserInfo();
|
||||||
NewPopupBrowserInfo()
|
scoped_refptr<CefBrowserInfo> GetOrCreateBrowserInfo(int render_process_id,
|
||||||
: browser_id(0) {}
|
int render_view_id);
|
||||||
int browser_id;
|
void RemoveBrowserInfo(scoped_refptr<CefBrowserInfo> browser_info);
|
||||||
};
|
void DestroyAllBrowsers();
|
||||||
void GetNewPopupBrowserInfo(int render_process_id,
|
|
||||||
int render_view_id,
|
// Retrieves the CefBrowserInfo matching the specified IDs or an empty
|
||||||
NewPopupBrowserInfo* info);
|
// pointer if no match is found. It is allowed to add new callers of this
|
||||||
void ClearNewPopupBrowserInfo(int render_process_id,
|
// method but consider using CefContext::GetBrowserByRoutingID() instead.
|
||||||
|
scoped_refptr<CefBrowserInfo> GetBrowserInfo(int render_process_id,
|
||||||
int render_view_id);
|
int render_view_id);
|
||||||
|
|
||||||
virtual content::BrowserMainParts* CreateBrowserMainParts(
|
virtual content::BrowserMainParts* CreateBrowserMainParts(
|
||||||
@ -86,13 +91,12 @@ class CefContentBrowserClient : public content::ContentBrowserClient {
|
|||||||
scoped_ptr<CefResourceDispatcherHostDelegate>
|
scoped_ptr<CefResourceDispatcherHostDelegate>
|
||||||
resource_dispatcher_host_delegate_;
|
resource_dispatcher_host_delegate_;
|
||||||
|
|
||||||
base::Lock new_popup_browser_lock_;
|
base::Lock browser_info_lock_;
|
||||||
|
|
||||||
// Map of (render_process_id, render_view_id) to info. Access must be
|
// Access must be protected by |browser_info_lock_|.
|
||||||
// protected by |new_popup_browser_lock_|.
|
typedef std::list<scoped_refptr<CefBrowserInfo> > BrowserInfoList;
|
||||||
typedef std::map<std::pair<int, int>, NewPopupBrowserInfo>
|
BrowserInfoList browser_info_list_;
|
||||||
NewPopupBrowserInfoMap;
|
int next_browser_id_;
|
||||||
NewPopupBrowserInfoMap new_popup_browser_info_map_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CEF_LIBCEF_BROWSER_CONTENT_BROWSER_CLIENT_H_
|
#endif // CEF_LIBCEF_BROWSER_CONTENT_BROWSER_CLIENT_H_
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include "libcef/browser/context.h"
|
#include "libcef/browser/context.h"
|
||||||
#include "libcef/browser/browser_context.h"
|
#include "libcef/browser/browser_context.h"
|
||||||
#include "libcef/browser/browser_host_impl.h"
|
#include "libcef/browser/browser_host_impl.h"
|
||||||
|
#include "libcef/browser/browser_info.h"
|
||||||
#include "libcef/browser/browser_main.h"
|
#include "libcef/browser/browser_main.h"
|
||||||
#include "libcef/browser/browser_message_loop.h"
|
#include "libcef/browser/browser_message_loop.h"
|
||||||
#include "libcef/browser/content_browser_client.h"
|
#include "libcef/browser/content_browser_client.h"
|
||||||
@ -270,53 +271,20 @@ bool CefContext::OnInitThread() {
|
|||||||
return (base::PlatformThread::CurrentId() == init_thread_id_);
|
return (base::PlatformThread::CurrentId() == init_thread_id_);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CefContext::GetNextBrowserID() {
|
|
||||||
return next_browser_id_.GetNext() + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CefContext::AddBrowser(CefRefPtr<CefBrowserHostImpl> browser) {
|
|
||||||
AutoLock lock_scope(this);
|
|
||||||
|
|
||||||
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()) {
|
|
||||||
browserlist_.erase(it);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CefRefPtr<CefBrowserHostImpl> CefContext::GetBrowserByID(int id) {
|
|
||||||
AutoLock lock_scope(this);
|
|
||||||
|
|
||||||
BrowserList::const_iterator it = browserlist_.begin();
|
|
||||||
for (; it != browserlist_.end(); ++it) {
|
|
||||||
if (it->get()->browser_id() == id)
|
|
||||||
return it->get();
|
|
||||||
}
|
|
||||||
|
|
||||||
DLOG(ERROR) << "No browser matching unique id " << id;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
CefRefPtr<CefBrowserHostImpl> CefContext::GetBrowserByRoutingID(
|
CefRefPtr<CefBrowserHostImpl> CefContext::GetBrowserByRoutingID(
|
||||||
int render_process_id, int render_view_id) {
|
int render_process_id, int render_view_id) {
|
||||||
AutoLock lock_scope(this);
|
scoped_refptr<CefBrowserInfo> info =
|
||||||
|
CefContentBrowserClient::Get()->GetBrowserInfo(render_process_id,
|
||||||
BrowserList::const_iterator it = browserlist_.begin();
|
render_view_id);
|
||||||
for (; it != browserlist_.end(); ++it) {
|
if (info.get()) {
|
||||||
if (it->get()->HasIDMatch(render_process_id, render_view_id))
|
CefRefPtr<CefBrowserHostImpl> browser = info->browser();
|
||||||
return it->get();
|
if (!browser.get()) {
|
||||||
|
DLOG(WARNING) << "Found browser id " << info->browser_id() <<
|
||||||
|
" but no browser object matching process id " <<
|
||||||
|
render_process_id << " and view id " << render_view_id;
|
||||||
|
}
|
||||||
|
return browser;
|
||||||
}
|
}
|
||||||
|
|
||||||
DLOG(ERROR) << "No browser matching process id " << render_process_id <<
|
|
||||||
" and view id " << render_view_id;
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -363,22 +331,7 @@ void CefContext::FinishShutdownOnUIThread(
|
|||||||
base::WaitableEvent* uithread_shutdown_event) {
|
base::WaitableEvent* uithread_shutdown_event) {
|
||||||
CEF_REQUIRE_UIT();
|
CEF_REQUIRE_UIT();
|
||||||
|
|
||||||
BrowserList list;
|
CefContentBrowserClient::Get()->DestroyAllBrowsers();
|
||||||
|
|
||||||
{
|
|
||||||
AutoLock lock_scope(this);
|
|
||||||
if (!browserlist_.empty()) {
|
|
||||||
list = browserlist_;
|
|
||||||
browserlist_.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Destroy any remaining browser windows.
|
|
||||||
if (!list.empty()) {
|
|
||||||
BrowserList::iterator it = list.begin();
|
|
||||||
for (; it != list.end(); ++it)
|
|
||||||
(*it)->DestroyBrowser();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (trace_subscriber_.get())
|
if (trace_subscriber_.get())
|
||||||
trace_subscriber_.reset(NULL);
|
trace_subscriber_.reset(NULL);
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
#include "include/cef_app.h"
|
#include "include/cef_app.h"
|
||||||
#include "include/cef_base.h"
|
#include "include/cef_base.h"
|
||||||
|
|
||||||
#include "base/atomic_sequence_num.h"
|
|
||||||
#include "base/file_path.h"
|
#include "base/file_path.h"
|
||||||
#include "base/files/scoped_temp_dir.h"
|
#include "base/files/scoped_temp_dir.h"
|
||||||
#include "base/memory/scoped_ptr.h"
|
#include "base/memory/scoped_ptr.h"
|
||||||
@ -55,13 +54,8 @@ class CefContext : public CefBase {
|
|||||||
// Returns true if the context is shutting down.
|
// Returns true if the context is shutting down.
|
||||||
bool shutting_down() { return shutting_down_; }
|
bool shutting_down() { return shutting_down_; }
|
||||||
|
|
||||||
int GetNextBrowserID();
|
|
||||||
void AddBrowser(CefRefPtr<CefBrowserHostImpl> browser);
|
|
||||||
void RemoveBrowser(CefRefPtr<CefBrowserHostImpl> browser);
|
|
||||||
CefRefPtr<CefBrowserHostImpl> GetBrowserByID(int id);
|
|
||||||
CefRefPtr<CefBrowserHostImpl> GetBrowserByRoutingID(int render_process_id,
|
CefRefPtr<CefBrowserHostImpl> GetBrowserByRoutingID(int render_process_id,
|
||||||
int render_view_id);
|
int render_view_id);
|
||||||
BrowserList* GetBrowserList() { return &browserlist_; }
|
|
||||||
|
|
||||||
// Retrieve the path at which cache data will be stored on disk. If empty,
|
// Retrieve the path at which cache data will be stored on disk. If empty,
|
||||||
// cache data will be stored in-memory.
|
// cache data will be stored in-memory.
|
||||||
@ -95,12 +89,6 @@ class CefContext : public CefBase {
|
|||||||
FilePath cache_path_;
|
FilePath cache_path_;
|
||||||
base::ScopedTempDir cache_temp_dir_;
|
base::ScopedTempDir cache_temp_dir_;
|
||||||
|
|
||||||
// Map of browsers that currently exist.
|
|
||||||
BrowserList browserlist_;
|
|
||||||
|
|
||||||
// Used for assigning unique IDs to browser instances.
|
|
||||||
base::AtomicSequenceNumber next_browser_id_;
|
|
||||||
|
|
||||||
scoped_ptr<CefMainDelegate> main_delegate_;
|
scoped_ptr<CefMainDelegate> main_delegate_;
|
||||||
scoped_ptr<content::ContentMainRunner> main_runner_;
|
scoped_ptr<content::ContentMainRunner> main_runner_;
|
||||||
scoped_ptr<CefTraceSubscriber> trace_subscriber_;
|
scoped_ptr<CefTraceSubscriber> trace_subscriber_;
|
||||||
|
@ -131,13 +131,20 @@ void CefBrowserImpl::StopLoad() {
|
|||||||
int CefBrowserImpl::GetIdentifier() {
|
int CefBrowserImpl::GetIdentifier() {
|
||||||
CEF_REQUIRE_RT_RETURN(0);
|
CEF_REQUIRE_RT_RETURN(0);
|
||||||
|
|
||||||
return browser_window_id();
|
return browser_id();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CefBrowserImpl::IsSame(CefRefPtr<CefBrowser> that) {
|
||||||
|
CEF_REQUIRE_RT_RETURN(false);
|
||||||
|
|
||||||
|
CefBrowserImpl* impl = static_cast<CefBrowserImpl*>(that.get());
|
||||||
|
return (impl == this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CefBrowserImpl::IsPopup() {
|
bool CefBrowserImpl::IsPopup() {
|
||||||
CEF_REQUIRE_RT_RETURN(false);
|
CEF_REQUIRE_RT_RETURN(false);
|
||||||
|
|
||||||
return is_popup_;
|
return is_popup();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CefBrowserImpl::HasDocument() {
|
bool CefBrowserImpl::HasDocument() {
|
||||||
@ -255,7 +262,7 @@ CefBrowserImpl::CefBrowserImpl(content::RenderView* render_view,
|
|||||||
int browser_id,
|
int browser_id,
|
||||||
bool is_popup)
|
bool is_popup)
|
||||||
: content::RenderViewObserver(render_view),
|
: content::RenderViewObserver(render_view),
|
||||||
browser_window_id_(browser_id),
|
browser_id_(browser_id),
|
||||||
is_popup_(is_popup),
|
is_popup_(is_popup),
|
||||||
last_focused_frame_id_(kInvalidFrameId) {
|
last_focused_frame_id_(kInvalidFrameId) {
|
||||||
response_manager_.reset(new CefResponseManager);
|
response_manager_.reset(new CefResponseManager);
|
||||||
|
@ -63,6 +63,7 @@ class CefBrowserImpl : public CefBrowser,
|
|||||||
virtual void ReloadIgnoreCache() OVERRIDE;
|
virtual void ReloadIgnoreCache() OVERRIDE;
|
||||||
virtual void StopLoad() OVERRIDE;
|
virtual void StopLoad() OVERRIDE;
|
||||||
virtual int GetIdentifier() OVERRIDE;
|
virtual int GetIdentifier() OVERRIDE;
|
||||||
|
virtual bool IsSame(CefRefPtr<CefBrowser> that) OVERRIDE;
|
||||||
virtual bool IsPopup() OVERRIDE;
|
virtual bool IsPopup() OVERRIDE;
|
||||||
virtual bool HasDocument() OVERRIDE;
|
virtual bool HasDocument() OVERRIDE;
|
||||||
virtual CefRefPtr<CefFrame> GetMainFrame() OVERRIDE;
|
virtual CefRefPtr<CefFrame> GetMainFrame() OVERRIDE;
|
||||||
@ -96,7 +97,8 @@ class CefBrowserImpl : public CefBrowser,
|
|||||||
// Frame objects will be deleted immediately before the frame is closed.
|
// Frame objects will be deleted immediately before the frame is closed.
|
||||||
void AddFrameObject(int64 frame_id, CefTrackNode* tracked_object);
|
void AddFrameObject(int64 frame_id, CefTrackNode* tracked_object);
|
||||||
|
|
||||||
int browser_window_id() const { return browser_window_id_; }
|
int browser_id() const { return browser_id_; }
|
||||||
|
bool is_popup() const { return is_popup_; }
|
||||||
content::RenderView* render_view() {
|
content::RenderView* render_view() {
|
||||||
return content::RenderViewObserver::render_view();
|
return content::RenderViewObserver::render_view();
|
||||||
}
|
}
|
||||||
@ -117,8 +119,10 @@ class CefBrowserImpl : public CefBrowser,
|
|||||||
void OnResponse(const Cef_Response_Params& params);
|
void OnResponse(const Cef_Response_Params& params);
|
||||||
void OnResponseAck(int request_id);
|
void OnResponseAck(int request_id);
|
||||||
|
|
||||||
// Id number of browser window which RenderView is attached to.
|
// ID of the browser that this RenderView is associated with. During loading
|
||||||
int browser_window_id_;
|
// of cross-origin requests multiple RenderViews may be associated with the
|
||||||
|
// same browser ID.
|
||||||
|
int browser_id_;
|
||||||
bool is_popup_;
|
bool is_popup_;
|
||||||
|
|
||||||
// Id of the last frame that had focus.
|
// Id of the last frame that had focus.
|
||||||
|
@ -145,6 +145,26 @@ int CEF_CALLBACK browser_get_identifier(struct _cef_browser_t* self) {
|
|||||||
return _retval;
|
return _retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CEF_CALLBACK browser_is_same(struct _cef_browser_t* self,
|
||||||
|
struct _cef_browser_t* that) {
|
||||||
|
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||||
|
|
||||||
|
DCHECK(self);
|
||||||
|
if (!self)
|
||||||
|
return 0;
|
||||||
|
// Verify param: that; type: refptr_same
|
||||||
|
DCHECK(that);
|
||||||
|
if (!that)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
// Execute
|
||||||
|
bool _retval = CefBrowserCppToC::Get(self)->IsSame(
|
||||||
|
CefBrowserCppToC::Unwrap(that));
|
||||||
|
|
||||||
|
// Return type: bool
|
||||||
|
return _retval;
|
||||||
|
}
|
||||||
|
|
||||||
int CEF_CALLBACK browser_is_popup(struct _cef_browser_t* self) {
|
int CEF_CALLBACK browser_is_popup(struct _cef_browser_t* self) {
|
||||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||||
|
|
||||||
@ -350,6 +370,7 @@ CefBrowserCppToC::CefBrowserCppToC(CefBrowser* cls)
|
|||||||
struct_.struct_.reload_ignore_cache = browser_reload_ignore_cache;
|
struct_.struct_.reload_ignore_cache = browser_reload_ignore_cache;
|
||||||
struct_.struct_.stop_load = browser_stop_load;
|
struct_.struct_.stop_load = browser_stop_load;
|
||||||
struct_.struct_.get_identifier = browser_get_identifier;
|
struct_.struct_.get_identifier = browser_get_identifier;
|
||||||
|
struct_.struct_.is_same = browser_is_same;
|
||||||
struct_.struct_.is_popup = browser_is_popup;
|
struct_.struct_.is_popup = browser_is_popup;
|
||||||
struct_.struct_.has_document = browser_has_document;
|
struct_.struct_.has_document = browser_has_document;
|
||||||
struct_.struct_.get_main_frame = browser_get_main_frame;
|
struct_.struct_.get_main_frame = browser_get_main_frame;
|
||||||
|
@ -134,6 +134,25 @@ int CefBrowserCToCpp::GetIdentifier() {
|
|||||||
return _retval;
|
return _retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CefBrowserCToCpp::IsSame(CefRefPtr<CefBrowser> that) {
|
||||||
|
if (CEF_MEMBER_MISSING(struct_, is_same))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||||
|
|
||||||
|
// Verify param: that; type: refptr_same
|
||||||
|
DCHECK(that.get());
|
||||||
|
if (!that.get())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Execute
|
||||||
|
int _retval = struct_->is_same(struct_,
|
||||||
|
CefBrowserCToCpp::Unwrap(that));
|
||||||
|
|
||||||
|
// Return type: bool
|
||||||
|
return _retval?true:false;
|
||||||
|
}
|
||||||
|
|
||||||
bool CefBrowserCToCpp::IsPopup() {
|
bool CefBrowserCToCpp::IsPopup() {
|
||||||
if (CEF_MEMBER_MISSING(struct_, is_popup))
|
if (CEF_MEMBER_MISSING(struct_, is_popup))
|
||||||
return false;
|
return false;
|
||||||
|
@ -45,6 +45,7 @@ class CefBrowserCToCpp
|
|||||||
virtual void ReloadIgnoreCache() OVERRIDE;
|
virtual void ReloadIgnoreCache() OVERRIDE;
|
||||||
virtual void StopLoad() OVERRIDE;
|
virtual void StopLoad() OVERRIDE;
|
||||||
virtual int GetIdentifier() OVERRIDE;
|
virtual int GetIdentifier() OVERRIDE;
|
||||||
|
virtual bool IsSame(CefRefPtr<CefBrowser> that) OVERRIDE;
|
||||||
virtual bool IsPopup() OVERRIDE;
|
virtual bool IsPopup() OVERRIDE;
|
||||||
virtual bool HasDocument() OVERRIDE;
|
virtual bool HasDocument() OVERRIDE;
|
||||||
virtual CefRefPtr<CefFrame> GetMainFrame() OVERRIDE;
|
virtual CefRefPtr<CefFrame> GetMainFrame() OVERRIDE;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
// reserved. Use of this source code is governed by a BSD-style license that
|
// reserved. Use of this source code is governed by a BSD-style license that
|
||||||
// can be found in the LICENSE file.
|
// can be found in the LICENSE file.
|
||||||
|
|
||||||
|
#include <list>
|
||||||
#include "include/cef_callback.h"
|
#include "include/cef_callback.h"
|
||||||
#include "include/cef_scheme.h"
|
#include "include/cef_scheme.h"
|
||||||
#include "tests/cefclient/client_app.h"
|
#include "tests/cefclient/client_app.h"
|
||||||
@ -76,12 +77,14 @@ class HistoryNavRendererTest : public ClientApp::RenderDelegate {
|
|||||||
virtual void OnRenderThreadCreated(
|
virtual void OnRenderThreadCreated(
|
||||||
CefRefPtr<ClientApp> app,
|
CefRefPtr<ClientApp> app,
|
||||||
CefRefPtr<CefListValue> extra_info) OVERRIDE {
|
CefRefPtr<CefListValue> extra_info) OVERRIDE {
|
||||||
|
if (!g_history_nav_test) {
|
||||||
// Check that the test should be run.
|
// Check that the test should be run.
|
||||||
CefRefPtr<CefCommandLine> command_line =
|
CefRefPtr<CefCommandLine> command_line =
|
||||||
CefCommandLine::GetGlobalCommandLine();
|
CefCommandLine::GetGlobalCommandLine();
|
||||||
const std::string& test = command_line->GetSwitchValue("test");
|
const std::string& test = command_line->GetSwitchValue("test");
|
||||||
if (test != kHistoryNavMsg)
|
if (test != kHistoryNavMsg)
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
run_test_ = true;
|
run_test_ = true;
|
||||||
}
|
}
|
||||||
@ -814,12 +817,14 @@ class OrderNavRendererTest : public ClientApp::RenderDelegate {
|
|||||||
virtual void OnRenderThreadCreated(
|
virtual void OnRenderThreadCreated(
|
||||||
CefRefPtr<ClientApp> app,
|
CefRefPtr<ClientApp> app,
|
||||||
CefRefPtr<CefListValue> extra_info) OVERRIDE {
|
CefRefPtr<CefListValue> extra_info) OVERRIDE {
|
||||||
|
if (!g_order_nav_test) {
|
||||||
// Check that the test should be run.
|
// Check that the test should be run.
|
||||||
CefRefPtr<CefCommandLine> command_line =
|
CefRefPtr<CefCommandLine> command_line =
|
||||||
CefCommandLine::GetGlobalCommandLine();
|
CefCommandLine::GetGlobalCommandLine();
|
||||||
const std::string& test = command_line->GetSwitchValue("test");
|
const std::string& test = command_line->GetSwitchValue("test");
|
||||||
if (test != kOrderNavMsg)
|
if (test != kOrderNavMsg)
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
run_test_ = true;
|
run_test_ = true;
|
||||||
|
|
||||||
@ -1132,11 +1137,315 @@ TEST(NavigationTest, Order) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
const char kCrossOriginNav1[] = "http://tests-conav1/nav1.html";
|
||||||
|
const char kCrossOriginNav2[] = "http://tests-conav2/nav2.html";
|
||||||
|
const char kCrossOriginNavMsg[] = "NavigationTest.CrossOriginNav";
|
||||||
|
|
||||||
|
bool g_cross_origin_nav_test = false;
|
||||||
|
|
||||||
|
// Browser side.
|
||||||
|
class CrossOriginNavBrowserTest : public ClientApp::BrowserDelegate {
|
||||||
|
public:
|
||||||
|
CrossOriginNavBrowserTest() {}
|
||||||
|
|
||||||
|
virtual void OnBeforeChildProcessLaunch(
|
||||||
|
CefRefPtr<ClientApp> app,
|
||||||
|
CefRefPtr<CefCommandLine> command_line) OVERRIDE {
|
||||||
|
if (!g_cross_origin_nav_test)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Indicate to the render process that the test should be run.
|
||||||
|
command_line->AppendSwitchWithValue("test", kCrossOriginNavMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
IMPLEMENT_REFCOUNTING(CrossOriginNavBrowserTest);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Renderer side.
|
||||||
|
class CrossOriginNavRendererTest : public ClientApp::RenderDelegate {
|
||||||
|
public:
|
||||||
|
CrossOriginNavRendererTest()
|
||||||
|
: run_test_(false) {}
|
||||||
|
virtual ~CrossOriginNavRendererTest() {
|
||||||
|
EXPECT_TRUE(status_list_.empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void OnRenderThreadCreated(
|
||||||
|
CefRefPtr<ClientApp> app,
|
||||||
|
CefRefPtr<CefListValue> extra_info) OVERRIDE {
|
||||||
|
if (!g_cross_origin_nav_test) {
|
||||||
|
// Check that the test should be run.
|
||||||
|
CefRefPtr<CefCommandLine> command_line =
|
||||||
|
CefCommandLine::GetGlobalCommandLine();
|
||||||
|
const std::string& test = command_line->GetSwitchValue("test");
|
||||||
|
if (test != kCrossOriginNavMsg)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
run_test_ = true;
|
||||||
|
|
||||||
|
EXPECT_FALSE(got_webkit_initialized_);
|
||||||
|
|
||||||
|
got_render_thread_created_.yes();
|
||||||
|
}
|
||||||
|
|
||||||
|
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_);
|
||||||
|
|
||||||
|
EXPECT_FALSE(GetStatus(browser));
|
||||||
|
Status* status = AddStatus(browser);
|
||||||
|
status->got_browser_created.yes();
|
||||||
|
}
|
||||||
|
|
||||||
|
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_);
|
||||||
|
|
||||||
|
Status* status = GetStatus(browser);
|
||||||
|
EXPECT_TRUE(status);
|
||||||
|
|
||||||
|
EXPECT_TRUE(status->got_browser_created);
|
||||||
|
EXPECT_TRUE(status->got_before_navigation);
|
||||||
|
|
||||||
|
EXPECT_EQ(status->browser_id, browser->GetIdentifier());
|
||||||
|
|
||||||
|
EXPECT_TRUE(RemoveStatus(browser));
|
||||||
|
}
|
||||||
|
|
||||||
|
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_);
|
||||||
|
|
||||||
|
Status* status = GetStatus(browser);
|
||||||
|
EXPECT_TRUE(status);
|
||||||
|
|
||||||
|
EXPECT_TRUE(status->got_browser_created);
|
||||||
|
EXPECT_FALSE(status->got_before_navigation);
|
||||||
|
|
||||||
|
status->got_before_navigation.yes();
|
||||||
|
|
||||||
|
EXPECT_EQ(status->browser_id, browser->GetIdentifier());
|
||||||
|
|
||||||
|
SendTestResults(browser);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Send the test results.
|
||||||
|
void SendTestResults(CefRefPtr<CefBrowser> browser) {
|
||||||
|
// Check if the test has failed.
|
||||||
|
bool result = !TestFailed();
|
||||||
|
|
||||||
|
// Return the result to the browser process.
|
||||||
|
CefRefPtr<CefProcessMessage> return_msg =
|
||||||
|
CefProcessMessage::Create(kCrossOriginNavMsg);
|
||||||
|
CefRefPtr<CefListValue> args = return_msg->GetArgumentList();
|
||||||
|
EXPECT_TRUE(args.get());
|
||||||
|
EXPECT_TRUE(args->SetBool(0, result));
|
||||||
|
EXPECT_TRUE(args->SetInt(1, browser->GetIdentifier()));
|
||||||
|
EXPECT_TRUE(browser->SendProcessMessage(PID_BROWSER, return_msg));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool run_test_;
|
||||||
|
|
||||||
|
TrackCallback got_render_thread_created_;
|
||||||
|
TrackCallback got_webkit_initialized_;
|
||||||
|
|
||||||
|
struct Status {
|
||||||
|
Status() : browser_id(0) {}
|
||||||
|
|
||||||
|
CefRefPtr<CefBrowser> browser;
|
||||||
|
int browser_id;
|
||||||
|
TrackCallback got_browser_created;
|
||||||
|
TrackCallback got_before_navigation;
|
||||||
|
};
|
||||||
|
typedef std::list<Status> StatusList;
|
||||||
|
StatusList status_list_;
|
||||||
|
|
||||||
|
Status* GetStatus(CefRefPtr<CefBrowser> browser) {
|
||||||
|
StatusList::iterator it = status_list_.begin();
|
||||||
|
for (; it != status_list_.end(); ++it) {
|
||||||
|
Status& status = (*it);
|
||||||
|
if (status.browser->IsSame(browser))
|
||||||
|
return &status;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
Status* AddStatus(CefRefPtr<CefBrowser> browser) {
|
||||||
|
Status status;
|
||||||
|
status.browser = browser;
|
||||||
|
status.browser_id = browser->GetIdentifier();
|
||||||
|
EXPECT_GT(status.browser_id, 0);
|
||||||
|
status_list_.push_back(status);
|
||||||
|
return &status_list_.back();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RemoveStatus(CefRefPtr<CefBrowser> browser) {
|
||||||
|
StatusList::iterator it = status_list_.begin();
|
||||||
|
for (; it != status_list_.end(); ++it) {
|
||||||
|
Status& status = (*it);
|
||||||
|
if (status.browser->IsSame(browser)) {
|
||||||
|
status_list_.erase(it);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
IMPLEMENT_REFCOUNTING(CrossOriginNavRendererTest);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Browser side.
|
||||||
|
class CrossOriginNavTestHandler : public TestHandler {
|
||||||
|
public:
|
||||||
|
CrossOriginNavTestHandler()
|
||||||
|
: browser_id_current_(0),
|
||||||
|
got_message_(false),
|
||||||
|
got_load_end_(false) {}
|
||||||
|
|
||||||
|
virtual void RunTest() OVERRIDE {
|
||||||
|
// Add the resources that we will navigate to/from.
|
||||||
|
AddResource(kCrossOriginNav1, "<html>Nav1</html>", "text/html");
|
||||||
|
AddResource(kCrossOriginNav2, "<html>Nav2</html>", "text/html");
|
||||||
|
|
||||||
|
// Create the browser.
|
||||||
|
CreateBrowser(kCrossOriginNav1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ContinueIfReady(CefRefPtr<CefBrowser> browser) {
|
||||||
|
if (!got_message_ || !got_load_end_)
|
||||||
|
return;
|
||||||
|
|
||||||
|
got_message_ = false;
|
||||||
|
got_load_end_ = false;
|
||||||
|
|
||||||
|
std::string url = browser->GetMainFrame()->GetURL();
|
||||||
|
if (url == kCrossOriginNav1) {
|
||||||
|
// Load the next url.
|
||||||
|
browser->GetMainFrame()->LoadURL(kCrossOriginNav2);
|
||||||
|
} else {
|
||||||
|
// Done with the test.
|
||||||
|
DestroyTest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE {
|
||||||
|
TestHandler::OnAfterCreated(browser);
|
||||||
|
|
||||||
|
EXPECT_EQ(browser_id_current_, 0);
|
||||||
|
browser_id_current_ = browser->GetIdentifier();
|
||||||
|
EXPECT_GT(browser_id_current_, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
|
||||||
|
CefRefPtr<CefFrame> frame,
|
||||||
|
CefRefPtr<CefRequest> request) OVERRIDE {
|
||||||
|
EXPECT_GT(browser_id_current_, 0);
|
||||||
|
EXPECT_EQ(browser_id_current_, browser->GetIdentifier());
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void OnLoadStart(CefRefPtr<CefBrowser> browser,
|
||||||
|
CefRefPtr<CefFrame> frame) OVERRIDE {
|
||||||
|
EXPECT_GT(browser_id_current_, 0);
|
||||||
|
EXPECT_EQ(browser_id_current_, browser->GetIdentifier());
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
||||||
|
CefRefPtr<CefFrame> frame,
|
||||||
|
int httpStatusCode) OVERRIDE {
|
||||||
|
EXPECT_GT(browser_id_current_, 0);
|
||||||
|
EXPECT_EQ(browser_id_current_, browser->GetIdentifier());
|
||||||
|
|
||||||
|
got_load_end_ = true;
|
||||||
|
ContinueIfReady(browser);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool OnProcessMessageReceived(
|
||||||
|
CefRefPtr<CefBrowser> browser,
|
||||||
|
CefProcessId source_process,
|
||||||
|
CefRefPtr<CefProcessMessage> message) OVERRIDE {
|
||||||
|
EXPECT_GT(browser_id_current_, 0);
|
||||||
|
EXPECT_EQ(browser_id_current_, browser->GetIdentifier());
|
||||||
|
|
||||||
|
const std::string& msg_name = message->GetName();
|
||||||
|
if (msg_name == kCrossOriginNavMsg) {
|
||||||
|
// Test that the renderer side succeeded.
|
||||||
|
CefRefPtr<CefListValue> args = message->GetArgumentList();
|
||||||
|
EXPECT_TRUE(args.get());
|
||||||
|
EXPECT_TRUE(args->GetBool(0));
|
||||||
|
|
||||||
|
EXPECT_EQ(browser_id_current_, args->GetInt(1));
|
||||||
|
|
||||||
|
// Continue with the test.
|
||||||
|
got_message_ = true;
|
||||||
|
ContinueIfReady(browser);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Message not handled.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int browser_id_current_;
|
||||||
|
|
||||||
|
bool got_message_;
|
||||||
|
bool got_load_end_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
// Verify navigation-related callbacks when browsing cross-origin.
|
||||||
|
TEST(NavigationTest, CrossOrigin) {
|
||||||
|
g_cross_origin_nav_test = true;
|
||||||
|
CefRefPtr<CrossOriginNavTestHandler> handler =
|
||||||
|
new CrossOriginNavTestHandler();
|
||||||
|
handler->ExecuteTest();
|
||||||
|
g_cross_origin_nav_test = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Entry point for creating navigation browser test objects.
|
// Entry point for creating navigation browser test objects.
|
||||||
// Called from client_app_delegates.cc.
|
// Called from client_app_delegates.cc.
|
||||||
void CreateNavigationBrowserTests(ClientApp::BrowserDelegateSet& delegates) {
|
void CreateNavigationBrowserTests(ClientApp::BrowserDelegateSet& delegates) {
|
||||||
delegates.insert(new HistoryNavBrowserTest);
|
delegates.insert(new HistoryNavBrowserTest);
|
||||||
delegates.insert(new OrderNavBrowserTest);
|
delegates.insert(new OrderNavBrowserTest);
|
||||||
|
delegates.insert(new CrossOriginNavBrowserTest);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Entry point for creating navigation renderer test objects.
|
// Entry point for creating navigation renderer test objects.
|
||||||
@ -1144,4 +1453,5 @@ void CreateNavigationBrowserTests(ClientApp::BrowserDelegateSet& delegates) {
|
|||||||
void CreateNavigationRendererTests(ClientApp::RenderDelegateSet& delegates) {
|
void CreateNavigationRendererTests(ClientApp::RenderDelegateSet& delegates) {
|
||||||
delegates.insert(new HistoryNavRendererTest);
|
delegates.insert(new HistoryNavRendererTest);
|
||||||
delegates.insert(new OrderNavRendererTest);
|
delegates.insert(new OrderNavRendererTest);
|
||||||
|
delegates.insert(new CrossOriginNavRendererTest);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user