Fix thread safety issue with CefBrowserHostImpl::IsWindowless

This commit is contained in:
Marshall Greenblatt 2016-02-29 15:23:44 -05:00
parent b4cf5bdb9c
commit 1b8f76dd69
2 changed files with 33 additions and 31 deletions

View File

@ -1259,7 +1259,7 @@ bool CefBrowserHostImpl::SendProcessMessage(
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
bool CefBrowserHostImpl::IsWindowless() const { bool CefBrowserHostImpl::IsWindowless() const {
return platform_delegate_->IsWindowless(); return is_windowless_;
} }
void CefBrowserHostImpl::WindowDestroyed() { void CefBrowserHostImpl::WindowDestroyed() {
@ -1725,6 +1725,11 @@ void CefBrowserHostImpl::HandleKeyEventAfterTextInputClient(
void CefBrowserHostImpl::DragTargetDragEnter(CefRefPtr<CefDragData> drag_data, void CefBrowserHostImpl::DragTargetDragEnter(CefRefPtr<CefDragData> drag_data,
const CefMouseEvent& event, const CefMouseEvent& event,
CefBrowserHost::DragOperationsMask allowed_ops) { CefBrowserHost::DragOperationsMask allowed_ops) {
if (!IsWindowless()) {
NOTREACHED() << "Window rendering is not disabled";
return;
}
if (!CEF_CURRENTLY_ON_UIT()) { if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(CEF_UIT, CEF_POST_TASK(CEF_UIT,
base::Bind(&CefBrowserHostImpl::DragTargetDragEnter, this, drag_data, base::Bind(&CefBrowserHostImpl::DragTargetDragEnter, this, drag_data,
@ -1737,11 +1742,6 @@ void CefBrowserHostImpl::DragTargetDragEnter(CefRefPtr<CefDragData> drag_data,
return; return;
} }
if (!IsWindowless()) {
NOTREACHED() << "Window rendering is not disabled";
return;
}
if (!web_contents()) if (!web_contents())
return; return;
@ -1750,6 +1750,11 @@ void CefBrowserHostImpl::DragTargetDragEnter(CefRefPtr<CefDragData> drag_data,
void CefBrowserHostImpl::DragTargetDragOver(const CefMouseEvent& event, void CefBrowserHostImpl::DragTargetDragOver(const CefMouseEvent& event,
CefBrowserHost::DragOperationsMask allowed_ops) { CefBrowserHost::DragOperationsMask allowed_ops) {
if (!IsWindowless()) {
NOTREACHED() << "Window rendering is not disabled";
return;
}
if (!CEF_CURRENTLY_ON_UIT()) { if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(CEF_UIT, CEF_POST_TASK(CEF_UIT,
base::Bind(&CefBrowserHostImpl::DragTargetDragOver, this, event, base::Bind(&CefBrowserHostImpl::DragTargetDragOver, this, event,
@ -1757,11 +1762,6 @@ void CefBrowserHostImpl::DragTargetDragOver(const CefMouseEvent& event,
return; return;
} }
if (!IsWindowless()) {
NOTREACHED() << "Window rendering is not disabled";
return;
}
if (!web_contents()) if (!web_contents())
return; return;
@ -1769,14 +1769,14 @@ void CefBrowserHostImpl::DragTargetDragOver(const CefMouseEvent& event,
} }
void CefBrowserHostImpl::DragTargetDragLeave() { void CefBrowserHostImpl::DragTargetDragLeave() {
if (!CEF_CURRENTLY_ON_UIT()) { if (!IsWindowless()) {
CEF_POST_TASK(CEF_UIT, NOTREACHED() << "Window rendering is not disabled";
base::Bind(&CefBrowserHostImpl::DragTargetDragLeave, this));
return; return;
} }
if (!IsWindowless()) { if (!CEF_CURRENTLY_ON_UIT()) {
NOTREACHED() << "Window rendering is not disabled"; CEF_POST_TASK(CEF_UIT,
base::Bind(&CefBrowserHostImpl::DragTargetDragLeave, this));
return; return;
} }
@ -1787,14 +1787,14 @@ void CefBrowserHostImpl::DragTargetDragLeave() {
} }
void CefBrowserHostImpl::DragTargetDrop(const CefMouseEvent& event) { void CefBrowserHostImpl::DragTargetDrop(const CefMouseEvent& event) {
if (!CEF_CURRENTLY_ON_UIT()) { if (!IsWindowless()) {
CEF_POST_TASK(CEF_UIT, NOTREACHED() << "Window rendering is not disabled";
base::Bind(&CefBrowserHostImpl::DragTargetDrop, this, event));
return; return;
} }
if (!IsWindowless()) { if (!CEF_CURRENTLY_ON_UIT()) {
NOTREACHED() << "Window rendering is not disabled"; CEF_POST_TASK(CEF_UIT,
base::Bind(&CefBrowserHostImpl::DragTargetDrop, this, event));
return; return;
} }
@ -1805,14 +1805,14 @@ void CefBrowserHostImpl::DragTargetDrop(const CefMouseEvent& event) {
} }
void CefBrowserHostImpl::DragSourceSystemDragEnded() { void CefBrowserHostImpl::DragSourceSystemDragEnded() {
if (!CEF_CURRENTLY_ON_UIT()) { if (!IsWindowless()) {
CEF_POST_TASK(CEF_UIT, NOTREACHED() << "Window rendering is not disabled";
base::Bind(&CefBrowserHostImpl::DragSourceSystemDragEnded, this));
return; return;
} }
if (!IsWindowless()) { if (!CEF_CURRENTLY_ON_UIT()) {
NOTREACHED() << "Window rendering is not disabled"; CEF_POST_TASK(CEF_UIT,
base::Bind(&CefBrowserHostImpl::DragSourceSystemDragEnded, this));
return; return;
} }
@ -1821,14 +1821,14 @@ void CefBrowserHostImpl::DragSourceSystemDragEnded() {
void CefBrowserHostImpl::DragSourceEndedAt( void CefBrowserHostImpl::DragSourceEndedAt(
int x, int y, CefBrowserHost::DragOperationsMask op) { int x, int y, CefBrowserHost::DragOperationsMask op) {
if (!CEF_CURRENTLY_ON_UIT()) { if (!IsWindowless()) {
CEF_POST_TASK(CEF_UIT, NOTREACHED() << "Window rendering is not disabled";
base::Bind(&CefBrowserHostImpl::DragSourceEndedAt, this, x, y, op));
return; return;
} }
if (!IsWindowless()) { if (!CEF_CURRENTLY_ON_UIT()) {
NOTREACHED() << "Window rendering is not disabled"; CEF_POST_TASK(CEF_UIT,
base::Bind(&CefBrowserHostImpl::DragSourceEndedAt, this, x, y, op));
return; return;
} }
@ -2638,6 +2638,7 @@ CefBrowserHostImpl::CefBrowserHostImpl(
opener_(kNullWindowHandle), opener_(kNullWindowHandle),
request_context_(request_context), request_context_(request_context),
platform_delegate_(std::move(platform_delegate)), platform_delegate_(std::move(platform_delegate)),
is_windowless_(platform_delegate_->IsWindowless()),
is_loading_(false), is_loading_(false),
can_go_back_(false), can_go_back_(false),
can_go_forward_(false), can_go_forward_(false),

View File

@ -520,6 +520,7 @@ class CefBrowserHostImpl : public CefBrowserHost,
CefWindowHandle opener_; CefWindowHandle opener_;
CefRefPtr<CefRequestContext> request_context_; CefRefPtr<CefRequestContext> request_context_;
scoped_ptr<CefBrowserPlatformDelegate> platform_delegate_; scoped_ptr<CefBrowserPlatformDelegate> platform_delegate_;
const bool is_windowless_;
// Volatile state information. All access must be protected by the state lock. // Volatile state information. All access must be protected by the state lock.
base::Lock state_lock_; base::Lock state_lock_;