diff --git a/libcef/browser/browser_host_impl.cc b/libcef/browser/browser_host_impl.cc index 2e28353b5..6eb6f0755 100644 --- a/libcef/browser/browser_host_impl.cc +++ b/libcef/browser/browser_host_impl.cc @@ -312,12 +312,7 @@ void CefBrowserHostImpl::SetFocus(bool enable) { if (!enable) return; - if (CEF_CURRENTLY_ON_UIT()) { - OnSetFocus(FOCUS_SOURCE_SYSTEM); - } else { - CEF_POST_TASK(CEF_UIT, - base::Bind(&CefBrowserHostImpl::SetFocus, this, enable)); - } + OnSetFocus(FOCUS_SOURCE_SYSTEM); } CefWindowHandle CefBrowserHostImpl::GetWindowHandle() { @@ -838,26 +833,29 @@ GURL CefBrowserHostImpl::GetLoadingURL() { } void CefBrowserHostImpl::OnSetFocus(cef_focus_source_t source) { - CEF_REQUIRE_UIT(); + if (CEF_CURRENTLY_ON_UIT()) { + // SetFocus() might be called while inside the OnSetFocus() callback. If so, + // don't re-enter the callback. + if (!is_in_onsetfocus_) { + if (client_.get()) { + CefRefPtr handler = client_->GetFocusHandler(); + if (handler.get()) { + is_in_onsetfocus_ = true; + bool handled = handler->OnSetFocus(this, source); + is_in_onsetfocus_ = false; - // SetFocus() might be called while inside the OnSetFocus() callback. If so, - // don't re-enter the callback. - if (!is_in_onsetfocus_) { - if (client_.get()) { - CefRefPtr handler = client_->GetFocusHandler(); - if (handler.get()) { - is_in_onsetfocus_ = true; - bool handled = handler->OnSetFocus(this, source); - is_in_onsetfocus_ = false; - - if (handled) - return; + if (handled) + return; + } } } - } - if (web_contents_.get()) - web_contents_->Focus(); + if (web_contents_.get()) + web_contents_->Focus(); + } else { + CEF_POST_TASK(CEF_UIT, + base::Bind(&CefBrowserHostImpl::OnSetFocus, this, source)); + } }