From 1b8f76dd69386ac710832bc84fe97374c16ddc96 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Mon, 29 Feb 2016 15:23:44 -0500 Subject: [PATCH] Fix thread safety issue with CefBrowserHostImpl::IsWindowless --- libcef/browser/browser_host_impl.cc | 63 +++++++++++++++-------------- libcef/browser/browser_host_impl.h | 1 + 2 files changed, 33 insertions(+), 31 deletions(-) diff --git a/libcef/browser/browser_host_impl.cc b/libcef/browser/browser_host_impl.cc index 573eeeb43..1178a1c30 100644 --- a/libcef/browser/browser_host_impl.cc +++ b/libcef/browser/browser_host_impl.cc @@ -1259,7 +1259,7 @@ bool CefBrowserHostImpl::SendProcessMessage( // ----------------------------------------------------------------------------- bool CefBrowserHostImpl::IsWindowless() const { - return platform_delegate_->IsWindowless(); + return is_windowless_; } void CefBrowserHostImpl::WindowDestroyed() { @@ -1725,6 +1725,11 @@ void CefBrowserHostImpl::HandleKeyEventAfterTextInputClient( void CefBrowserHostImpl::DragTargetDragEnter(CefRefPtr drag_data, const CefMouseEvent& event, CefBrowserHost::DragOperationsMask allowed_ops) { + if (!IsWindowless()) { + NOTREACHED() << "Window rendering is not disabled"; + return; + } + if (!CEF_CURRENTLY_ON_UIT()) { CEF_POST_TASK(CEF_UIT, base::Bind(&CefBrowserHostImpl::DragTargetDragEnter, this, drag_data, @@ -1737,11 +1742,6 @@ void CefBrowserHostImpl::DragTargetDragEnter(CefRefPtr drag_data, return; } - if (!IsWindowless()) { - NOTREACHED() << "Window rendering is not disabled"; - return; - } - if (!web_contents()) return; @@ -1750,6 +1750,11 @@ void CefBrowserHostImpl::DragTargetDragEnter(CefRefPtr drag_data, void CefBrowserHostImpl::DragTargetDragOver(const CefMouseEvent& event, CefBrowserHost::DragOperationsMask allowed_ops) { + if (!IsWindowless()) { + NOTREACHED() << "Window rendering is not disabled"; + return; + } + if (!CEF_CURRENTLY_ON_UIT()) { CEF_POST_TASK(CEF_UIT, base::Bind(&CefBrowserHostImpl::DragTargetDragOver, this, event, @@ -1757,11 +1762,6 @@ void CefBrowserHostImpl::DragTargetDragOver(const CefMouseEvent& event, return; } - if (!IsWindowless()) { - NOTREACHED() << "Window rendering is not disabled"; - return; - } - if (!web_contents()) return; @@ -1769,14 +1769,14 @@ void CefBrowserHostImpl::DragTargetDragOver(const CefMouseEvent& event, } void CefBrowserHostImpl::DragTargetDragLeave() { - if (!CEF_CURRENTLY_ON_UIT()) { - CEF_POST_TASK(CEF_UIT, - base::Bind(&CefBrowserHostImpl::DragTargetDragLeave, this)); + if (!IsWindowless()) { + NOTREACHED() << "Window rendering is not disabled"; return; } - if (!IsWindowless()) { - NOTREACHED() << "Window rendering is not disabled"; + if (!CEF_CURRENTLY_ON_UIT()) { + CEF_POST_TASK(CEF_UIT, + base::Bind(&CefBrowserHostImpl::DragTargetDragLeave, this)); return; } @@ -1787,14 +1787,14 @@ void CefBrowserHostImpl::DragTargetDragLeave() { } void CefBrowserHostImpl::DragTargetDrop(const CefMouseEvent& event) { - if (!CEF_CURRENTLY_ON_UIT()) { - CEF_POST_TASK(CEF_UIT, - base::Bind(&CefBrowserHostImpl::DragTargetDrop, this, event)); + if (!IsWindowless()) { + NOTREACHED() << "Window rendering is not disabled"; return; } - if (!IsWindowless()) { - NOTREACHED() << "Window rendering is not disabled"; + if (!CEF_CURRENTLY_ON_UIT()) { + CEF_POST_TASK(CEF_UIT, + base::Bind(&CefBrowserHostImpl::DragTargetDrop, this, event)); return; } @@ -1805,14 +1805,14 @@ void CefBrowserHostImpl::DragTargetDrop(const CefMouseEvent& event) { } void CefBrowserHostImpl::DragSourceSystemDragEnded() { - if (!CEF_CURRENTLY_ON_UIT()) { - CEF_POST_TASK(CEF_UIT, - base::Bind(&CefBrowserHostImpl::DragSourceSystemDragEnded, this)); + if (!IsWindowless()) { + NOTREACHED() << "Window rendering is not disabled"; return; } - if (!IsWindowless()) { - NOTREACHED() << "Window rendering is not disabled"; + if (!CEF_CURRENTLY_ON_UIT()) { + CEF_POST_TASK(CEF_UIT, + base::Bind(&CefBrowserHostImpl::DragSourceSystemDragEnded, this)); return; } @@ -1821,14 +1821,14 @@ void CefBrowserHostImpl::DragSourceSystemDragEnded() { void CefBrowserHostImpl::DragSourceEndedAt( int x, int y, CefBrowserHost::DragOperationsMask op) { - if (!CEF_CURRENTLY_ON_UIT()) { - CEF_POST_TASK(CEF_UIT, - base::Bind(&CefBrowserHostImpl::DragSourceEndedAt, this, x, y, op)); + if (!IsWindowless()) { + NOTREACHED() << "Window rendering is not disabled"; return; } - if (!IsWindowless()) { - NOTREACHED() << "Window rendering is not disabled"; + if (!CEF_CURRENTLY_ON_UIT()) { + CEF_POST_TASK(CEF_UIT, + base::Bind(&CefBrowserHostImpl::DragSourceEndedAt, this, x, y, op)); return; } @@ -2638,6 +2638,7 @@ CefBrowserHostImpl::CefBrowserHostImpl( opener_(kNullWindowHandle), request_context_(request_context), platform_delegate_(std::move(platform_delegate)), + is_windowless_(platform_delegate_->IsWindowless()), is_loading_(false), can_go_back_(false), can_go_forward_(false), diff --git a/libcef/browser/browser_host_impl.h b/libcef/browser/browser_host_impl.h index f15a5a8af..45dddb144 100644 --- a/libcef/browser/browser_host_impl.h +++ b/libcef/browser/browser_host_impl.h @@ -520,6 +520,7 @@ class CefBrowserHostImpl : public CefBrowserHost, CefWindowHandle opener_; CefRefPtr request_context_; scoped_ptr platform_delegate_; + const bool is_windowless_; // Volatile state information. All access must be protected by the state lock. base::Lock state_lock_;