CefBrowser::GetMainFrame() fails in NotificationStateLock

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

CefBrowser::GetMainFrame() fails in NotificationStateLock

Postby BobM » Tue Aug 10, 2021 1:26 am

Hi, I've just updated to 4577 from 4280. I've implemented all the recent changes and CEF runs, but occasionally the CHECK that is is in NotificationStateLock (browser_info.cc) is failing during call to CefBrowser::GetMainFrame().

In the Main Thread, my code sends messages to the renderer as below to get "can copy" states for the UI etc, but the m_cefBrowser->GetMainFrame() call fails in the CHECK before SendProcessMessage is called...

Call stack at CHECK failure...
    >libcef.dll!CefBrowserInfo::NotificationStateLock::NotificationStateLock(CefBrowserInfo * browser_info=0x51825010) Line 568 C++ Symbols loaded.
    libcef.dll!CefBrowserInfo::GetMainFrame() Line 230 C++ Symbols loaded.
    libcef.dll!CefBrowserHostBase::GetFrame(__int64 identifier=-1) Line 637 C++ Symbols loaded.
    libcef.dll!CefBrowserHostBase::GetMainFrame() Line 626 C++ Symbols loaded.
    libcef.dll!`anonymous namespace'::browser_get_main_frame(_cef_browser_t * self=0x51822f00) Line 253 C++ Symbols loaded.
    nbW.exe!CefBrowserCToCpp::GetMainFrame() Line 249 C++ Symbols loaded.
    nbW.exe!MyWebBrowserWindow::CanEditCopy() Line 9430 C++ Symbols loaded.
    nbW.exe!TMyWebBrowserWindow::CeEnableCommand(CCmdUI * pCmdUI=0x003bf3e4) Line 9845 C++ Symbols loaded.

The CrBrowserMain thread has this call stack at the CHECK failure (this time at lease - it has been different, but always seems to be doing some lock acquisition)...
    ntdll.dll!_NtWaitForAlertByThreadId@8() Unknown Non-user code. Symbols loaded.
    ntdll.dll!RtlAcquireSRWLockExclusive() Unknown Non-user code. Symbols loaded.
    > libcef.dll!base::internal::LockImpl::LockInternalWithTracking() Line 21 C++ Symbols loaded.
    [Inline Frame] libcef.dll!base::internal::LockImpl::Lock() Line 94 C++ Symbols loaded.
    [Inline Frame] libcef.dll!base::Lock::Acquire() Line 47 C++ Symbols loaded.
    [Inline Frame] libcef.dll!base::internal::BasicAutoLock<base::Lock>::BasicAutoLock(base::Lock & lock={...}) Line 129 C++ Symbols loaded.
    libcef.dll!CefBrowserInfo::NotificationStateLock::~NotificationStateLock() Line 583 C++ Symbols loaded.
    libcef.dll!CefBrowserInfo::MaybeCreateFrame(content::RenderFrameHost * host=0x3ae04e10, bool is_guest_view) Line 154 C++ Symbols loaded.
    libcef.dll!CefBrowserContentsDelegate::RenderFrameCreated(content::RenderFrameHost * render_frame_host=0x3ae04e10) Line 237 C++ Symbols loaded.
    libcef.dll!CefBrowserContentsDelegate::RenderFrameHostChanged(content::RenderFrameHost * old_host, content::RenderFrameHost * new_host=0x3ae04e10) Line 244 C++ Symbols loaded.
    libcef.dll!content::WebContentsImpl::WebContentsObserverList::NotifyObservers<void (content::WebContentsObserver::*)(content::RenderFrameHost *, content::RenderFrameHost *) __attribute__((thiscall)),content::RenderFrameHostImpl *&,content::RenderFrameHostImpl *&>(void(content::WebContentsObserver::*)(content::RenderFrameHost *, content::RenderFrameHost *) func, content::RenderFrameHostImpl * & args=0x00000000, content::RenderFrameHostImpl * & args=0x3ae04e10) Line 1478 C++ Symbols loaded.
    libcef.dll!content::WebContentsImpl::NotifyFrameSwapped(content::RenderFrameHostImpl * old_frame=0x00000000, content::RenderFrameHostImpl * new_frame=0x3ae04e10, bool is_main_frame) Line 6439 C++ Symbols loaded.
    libcef.dll!content::WebContentsImpl::NotifySwappedFromRenderManager(content::RenderFrameHostImpl * old_frame=0x00000000, content::RenderFrameHostImpl * new_frame=0x3ae04e10, bool is_main_frame) Line 7738 C++ Symbols loaded.
    libcef.dll!content::FrameTree::AddFrame(content::RenderFrameHostImpl * parent=0x3a42aa10, int process_id=5, int new_routing_id=24, mojo::PendingAssociatedRemote<content::mojom::Frame> frame_remote={...}, mojo::PendingReceiver<blink::mojom::BrowserInterfaceBroker> browser_interface_broker_receiver={...}, mojo::StructPtr<blink::mojom::PolicyContainerBindParams> policy_container_bind_params={...}, blink::mojom::TreeScopeType scope=kDocument, const std::__1::basic_string<char,std::__1::char_traits<char>,std::__1::allocator<char>> & frame_name={...}, const std::__1::basic_string<char,std::__1::char_traits<char>,std::__1::allocator<char>> & frame_unique_name={...}, bool is_created_by_script=true, const base::TokenType<blink::LocalFrameTokenTypeMarker> & frame_token={...}, const base::UnguessableToken & devtools_frame_token={...}, const blink::FramePolicy & frame_policy={...}, const blink::mojom::FrameOwnerProperties & frame_owner_properties={...}, bool was_discarded=false, blink::mojom::FrameOwnerElementType owner_type=kIframe) Line 373 C++ Symbols loaded.
    libcef.dll!content::RenderFrameHostImpl::OnCreateChildFrame(int new_routing_id=24, mojo::PendingAssociatedRemote<content::mojom::Frame> frame_remote={...}, mojo::PendingReceiver<blink::mojom::BrowserInterfaceBroker> browser_interface_broker_receiver={...}, mojo::StructPtr<blink::mojom::PolicyContainerBindParams> policy_container_bind_params={...}, blink::mojom::TreeScopeType scope=kDocument, const std::__1::basic_string<char,std::__1::char_traits<char>,std::__1::allocator<char>> & frame_name={...}, const std::__1::basic_string<char,std::__1::char_traits<char>,std::__1::allocator<char>> & frame_unique_name={...}, bool is_created_by_script=true, const base::TokenType<blink::LocalFrameTokenTypeMarker> & frame_token={...}, const base::UnguessableToken & devtools_frame_token={...}, const blink::FramePolicy & frame_policy={...}, const blink::mojom::FrameOwnerProperties & frame_owner_properties={...}, blink::mojom::FrameOwnerElementType owner_type=kIframe) Line 3429 C++ Symbols loaded.
    libcef.dll!content::RenderFrameHostImpl::CreateChildFrame(int new_routing_id=24, mojo::PendingAssociatedRemote<content::mojom::Frame> frame_remote={...}, mojo::PendingReceiver<blink::mojom::BrowserInterfaceBroker> browser_interface_broker_receiver={...}, mojo::StructPtr<blink::mojom::PolicyContainerBindParams> policy_container_bind_params={...}, blink::mojom::TreeScopeType scope=kDocument, const std::__1::basic_string<char,std::__1::char_traits<char>,std::__1::allocator<char>> & frame_name={...}, const std::__1::basic_string<char,std::__1::char_traits<char>,std::__1::allocator<char>> & frame_unique_name={...}, bool is_created_by_script=true, const blink::FramePolicy & frame_policy={...}, mojo::StructPtr<blink::mojom::FrameOwnerProperties> frame_owner_properties={...}, blink::mojom::FrameOwnerElementType owner_type=kIframe) Line 3463 C++ Symbols loaded.
    libcef.dll!content::mojom::FrameHostStubDispatch::Accept(content::mojom::FrameHost * impl=0x3a42aa38, mojo::Message * message=0x08dbf6f8) Line 4988 C++ Symbols loaded.
    libcef.dll!content::mojom::FrameHostStub<mojo::RawPtrImplRefTraits<content::mojom::FrameHost>>::Accept(mojo::Message * message=0x08dbf6f8) Line 647 C++ Symbols loaded.
    libcef.dll!mojo::InterfaceEndpointClient::HandleValidatedMessage(mojo::Message * message=0x08dbf6f8) Line 901 C++ Symbols loaded.
    libcef.dll!mojo::MessageDispatcher::Accept(mojo::Message * message=0x08dbf6f8) Line 48 C++ Symbols loaded.
    libcef.dll!mojo::InterfaceEndpointClient::HandleIncomingMessage(mojo::Message * message=0x08dbf6f8) Line 655 C++ Symbols loaded.
    libcef.dll!IPC::`anonymous namespace'::ChannelAssociatedGroupController::AcceptOnEndpointThread(mojo::Message message={...}) Line 981 C++ Symbols loaded.
    libcef.dll!base::internal::FunctorTraits<void (mojo::(anonymous namespace)::ThreadSafeInterfaceEndpointClientProxy::*)(mojo::Message) __attribute__((thiscall)),void>::Invoke<void (mojo::(anonymous namespace)::ThreadSafeInterfaceEndpointClientProxy::*)(mojo::Message) __attribute__((thiscall)),scoped_refptr<mojo::(anonymous namespace)::ThreadSafeInterfaceEndpointClientProxy>,mojo::Message>(void(mojo::`anonymous namespace'::ThreadSafeInterfaceEndpointClientProxy::*)(mojo::Message) method, scoped_refptr<mojo::(anonymous namespace)::ThreadSafeInterfaceEndpointClientProxy> && receiver_ptr, mojo::Message && args={...}) Line 509 C++ Symbols loaded.
    [Inline Frame] libcef.dll!base::internal::InvokeHelper<0,void>::MakeItSo(void(mojo::`anonymous namespace'::ThreadSafeInterfaceEndpointClientProxy::*)(mojo::Message) && functor, scoped_refptr<mojo::(anonymous namespace)::ThreadSafeInterfaceEndpointClientProxy> && args, mojo::Message && args) Line 648 C++ Symbols loaded.
    [Inline Frame] libcef.dll!base::internal::Invoker<base::internal::BindState<void (mojo::(anonymous namespace)::ThreadSafeInterfaceEndpointClientProxy::*)(mojo::Message) __attribute__((thiscall)),scoped_refptr<mojo::(anonymous namespace)::ThreadSafeInterfaceEndpointClientProxy>,mojo::Message>,void ()>::RunImpl(void(mojo::`anonymous namespace'::ThreadSafeInterfaceEndpointClientProxy::*)(mojo::Message) && functor, std::__1::tuple<scoped_refptr<mojo::(anonymous namespace)::ThreadSafeInterfaceEndpointClientProxy>,mojo::Message> && bound, std::__1::integer_sequence<unsigned int,0,1>) Line 721 C++ Symbols loaded.
    libcef.dll!base::internal::Invoker<base::internal::BindState<void (mojo::(anonymous namespace)::ThreadSafeInterfaceEndpointClientProxy::*)(mojo::Message) __attribute__((thiscall)),scoped_refptr<mojo::(anonymous namespace)::ThreadSafeInterfaceEndpointClientProxy>,mojo::Message>,void ()>::RunOnce(base::internal::BindStateBase * base=0x3adb2610) Line 690 C++ Symbols loaded.
    [Inline Frame] libcef.dll!base::OnceCallback<void ()>::Run() Line 98 C++ Symbols loaded.
    libcef.dll!base::TaskAnnotator::RunTask(const char * trace_event_name=0x1925bf7e, base::PendingTask * pending_task=0x3a34a010) Line 178 C++ Symbols loaded.
    libcef.dll!base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl(base::sequence_manager::LazyNow * continuation_lazy_now=0x08dbf890) Line 361 C++ Symbols loaded.
    libcef.dll!base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork() Line 266 C++ Symbols loaded.
    libcef.dll!base::MessagePumpForUI::DoRunLoop() Line 222 C++ Symbols loaded.
    libcef.dll!base::MessagePumpWin::Run(base::MessagePump::Delegate * delegate=0x3a2ddc94) Line 80 C++ Symbols loaded.
    libcef.dll!base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::Run(bool application_tasks_allowed, base::TimeDelta timeout={...}) Line 470 C++ Symbols loaded.
    libcef.dll!base::RunLoop::Run(const base::Location & location={...}) Line 136 C++ Symbols loaded.
    libcef.dll!CefMainRunner::RunMessageLoop() Line 288 C++ Symbols loaded.
    libcef.dll!CefUIThread::ThreadMain() Line 184 C++ Symbols loaded.
    libcef.dll!base::`anonymous namespace'::ThreadFunc(void * params=0x3a288850) Line 113 C++ Symbols loaded.


My calling code...
Code: Select all
bool TMyWebBrowserWindow::CanEditCopy()
{
  if (m_cefBrowser.get())
    m_cefBrowser->GetMainFrame()->SendProcessMessage(PID_RENDERER, CefProcessMessage::Create("CanCopy"));
  if (m_cefClientHandler.get())
    return m_cefClientHandler->m_canCopy;
  return false;
}


CHECK failure...
Code: Select all
CefBrowserInfo::NotificationStateLock::NotificationStateLock(
    CefBrowserInfo* browser_info)
    : browser_info_(browser_info) {
  // Take the navigation state lock.
  {
    base::AutoLock lock_scope_(browser_info_->notification_lock_);
    CHECK(!browser_info_->notification_state_lock_);          // <<<<<<<<<<<<<<<< This CHECK is failing occasionally
    browser_info_->notification_state_lock_ = this;
    // We may need this on destruction, and the original might be cleared.
    frame_handler_ = browser_info_->frame_handler_;
  }

  // Take the browser info state lock.
  browser_info_lock_scope_.reset(new base::AutoLock(browser_info_->lock_));
}
BobM
Mentor
 
Posts: 72
Joined: Wed May 11, 2016 4:28 pm

Re: CefBrowser::GetMainFrame() fails in NotificationStateLoc

Postby magreenblatt » Tue Aug 10, 2021 9:34 am

What is the thread and call stack for tmywebbrowserwindow::CeEnableCommand?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: CefBrowser::GetMainFrame() fails in NotificationStateLoc

Postby BobM » Tue Aug 10, 2021 5:03 pm

magreenblatt wrote:What is the thread and call stack for tmywebbrowserwindow::CeEnableCommand?


That is Main Thread - the stack is the first one shown above. The call to CeEnableCommand comes from normal MFC idle processing to enable toolbar buttons as appropriate. Here it is again in full (different toolbar button but same deal) ...

    > libcef.dll!CefBrowserInfo::NotificationStateLock::NotificationStateLock(CefBrowserInfo * browser_info=0x470237b0) Line 568 C++ Symbols loaded.
    libcef.dll!CefBrowserInfo::GetMainFrame() Line 230 C++ Symbols loaded.
    libcef.dll!CefBrowserHostBase::GetFrame(__int64 identifier=-1) Line 637 C++ Symbols loaded.
    libcef.dll!CefBrowserHostBase::GetMainFrame() Line 626 C++ Symbols loaded.
    libcef.dll!`anonymous namespace'::browser_get_main_frame(_cef_browser_t * self=0x4702e080) Line 253 C++ Symbols loaded.
    nbW.exe!CefBrowserCToCpp::GetMainFrame() Line 249 C++ Symbols loaded.
    nbW.exe!TMyWebBrowserWindow::CanCopyItem() Line 9447 C++ Symbols loaded.
    nbW.exe!TMyWebBrowserWindow::CeEnableCommand(CCmdUI * pCmdUI=0x01fdf05c) Line 9862 C++ Symbols loaded.
    nbW.exe!_AfxDispatchCmdMsg(CCmdTarget * pTarget=0x1e546410, unsigned int nID=28706, int nCode=-1, void(CCmdTarget::*)() pfn=0x0085a210, void * pExtra=0x01fdf05c, unsigned int nSig=66, AFX_CMDHANDLERINFO * pHandlerInfo=0x00000000) Line 150 C++ Symbols loaded.
    nbW.exe!CCmdTarget::OnCmdMsg(unsigned int nID=28706, int nCode=-1, void * pExtra=0x01fdf05c, AFX_CMDHANDLERINFO * pHandlerInfo=0x00000000) Line 372 C++ Symbols loaded.
    nbW.exe!TBrowserItemWindow::OnCmdMsg(unsigned int nID=28706, int nCode=-1, void * pExtra=0x01fdf05c, AFX_CMDHANDLERINFO * pHandlerInfo=0x00000000) Line 11900 C++ Symbols loaded.
    nbW.exe!TMultiEditorWindow::OnCmdMsg(unsigned int nID=28706, int nCode=-1, void * pExtra=0x01fdf05c, AFX_CMDHANDLERINFO * pHandlerInfo=0x00000000) Line 2937 C++ Symbols loaded.
    nbW.exe!TMyMDIItemChild::OnCmdMsg(unsigned int nID=28706, int nCode=-1, void * pExtra=0x01fdf05c, AFX_CMDHANDLERINFO * pHandlerInfo=0x00000000) Line 455 C++ Symbols loaded.
    nbW.exe!CMDIFrameWnd::OnCmdMsg(unsigned int nID=28706, int nCode=-1, void * pExtra=0x01fdf05c, AFX_CMDHANDLERINFO * pHandlerInfo=0x00000000) Line 72 C++ Symbols loaded.
    nbW.exe!CCmdUI::DoUpdate(CCmdTarget * pTarget=0x068677a8, int bDisableIfNoHndler=1) Line 756 C++ Symbols loaded.
    nbW.exe!CToolBar::OnUpdateCmdUI(CFrameWnd * pTarget=0x068677a8, int bDisableIfNoHndler=1) Line 1535 C++ Symbols loaded.
    nbW.exe!CControlBar::OnIdleUpdateCmdUI(unsigned int wParam=1, long __formal=0) Line 742 C++ Symbols loaded.
    nbW.exe!CWnd::OnWndMsg(unsigned int message=867, unsigned int wParam=1, long lParam=0, long * pResult=0x01fdf5d0) Line 2441 C++ Symbols loaded.
    nbW.exe!CWnd::WindowProc(unsigned int message=867, unsigned int wParam=1, long lParam=0) Line 2099 C++ Symbols loaded.
    nbW.exe!CControlBar::WindowProc(unsigned int nMsg=867, unsigned int wParam=1, long lParam=0) Line 501 C++ Symbols loaded.
    nbW.exe!AfxCallWndProc(CWnd * pWnd=0x06868050, HWND__ * hWnd=0x00640fc6, unsigned int nMsg=867, unsigned int wParam=1, long lParam=0) Line 265 C++ Symbols loaded.
    nbW.exe!CWnd::SendMessageToDescendants(HWND__ * hWnd=0x004910a2, unsigned int message=867, unsigned int wParam=1, long lParam=0, int bDeep=1, int bOnlyPerm=1) Line 3024 C++ Symbols loaded.
    nbW.exe!CWnd::SendMessageToDescendants(HWND__ * hWnd=0x00d813fe, unsigned int message=867, unsigned int wParam=1, long lParam=0, int bDeep=1, int bOnlyPerm=1) Line 3036 C++ Symbols loaded.
    nbW.exe!CWnd::SendMessageToDescendants(unsigned int message=867, unsigned int wParam=1, long lParam=0, int bDeep=1, int bOnlyPerm=1) Line 130 C++ Symbols loaded.
    nbW.exe!CWinThread::OnIdle(long lCount=0) Line 680 C++ Symbols loaded.
    nbW.exe!CWinApp::OnIdle(long lCount=0) Line 1050 C++ Symbols loaded.
    nbW.exe!TMyApp::OnIdle(long lCount=0) Line 849 C++ Symbols loaded.
    nbW.exe!client::MainMessageLoopMultithreadedWin::Run() Line 103 C++ Symbols loaded.
    nbW.exe!TMyApp::Run() Line 411 C++ Symbols loaded.
    nbW.exe!AfxWinMain(HINSTANCE__ * hInstance=0x00540000, HINSTANCE__ * hPrevInstance=0x00000000, wchar_t * lpCmdLine=0x023930a0, int nCmdShow=10) Line 47 C++ Symbols loaded.
    nbW.exe!wWinMain(HINSTANCE__ * hInstance=0x00540000, HINSTANCE__ * hPrevInstance=0x00000000, wchar_t * lpCmdLine=0x023930a0, int nCmdShow=10) Line 26 C++ Symbols loaded.


And this is the CrBrowserMain thread when the above Main Thread failed the CHECK....

    ntdll.dll!_NtWaitForAlertByThreadId@8() Unknown Non-user code. Symbols loaded.
    ntdll.dll!RtlAcquireSRWLockExclusive() Unknown Non-user code. Symbols loaded.
    > libcef.dll!base::internal::LockImpl::LockInternalWithTracking() Line 21 C++ Symbols loaded.
    [Inline Frame] libcef.dll!base::internal::LockImpl::Lock() Line 94 C++ Symbols loaded.
    [Inline Frame] libcef.dll!base::Lock::Acquire() Line 47 C++ Symbols loaded.
    [Inline Frame] libcef.dll!base::internal::BasicAutoLock<base::Lock>::BasicAutoLock(base::Lock & lock={...}) Line 129 C++ Symbols loaded.
    libcef.dll!CefBrowserInfo::NotificationStateLock::~NotificationStateLock() Line 583 C++ Symbols loaded.
    libcef.dll!CefBrowserInfo::MaybeCreateFrame(content::RenderFrameHost * host=0x27394010, bool is_guest_view) Line 154 C++ Symbols loaded.
    libcef.dll!CefBrowserContentsDelegate::RenderFrameCreated(content::RenderFrameHost * render_frame_host=0x27394010) Line 237 C++ Symbols loaded.
    libcef.dll!content::WebContentsImpl::WebContentsObserverList::NotifyObservers<void (content::WebContentsObserver::*)(content::Visibility) __attribute__((thiscall)),content::Visibility &>(void(content::WebContentsObserver::*)(content::Visibility) func, content::Visibility & args=658063376) Line 1478 C++ Symbols loaded.
    libcef.dll!content::WebContentsImpl::RenderFrameCreated(content::RenderFrameHostImpl * render_frame_host=0x27394010) Line 6536 C++ Symbols loaded.
    libcef.dll!content::RenderFrameHostImpl::RenderFrameCreated() Line 3201 C++ Symbols loaded.
    libcef.dll!content::RenderFrameHostImpl::CreateRenderFrame(int previous_routing_id=16, const absl::optional<blink::MultiToken<base::TokenType<blink::LocalFrameTokenTypeMarker>,base::TokenType<blink::RemoteFrameTokenTypeMarker>>> & opener_frame_token={...}, int parent_routing_id=3, int previous_sibling_routing_id=15) Line 3076 C++ Symbols loaded.
    libcef.dll!content::RenderFrameHostManager::InitRenderFrame(content::RenderFrameHostImpl * render_frame_host=0x27394010) Line 3083 C++ Symbols loaded.
    libcef.dll!content::RenderFrameHostManager::CreateSpeculativeRenderFrame(content::SiteInstance * instance=0x4a00e510, bool recovering_without_early_commit) Line 2782 C++ Symbols loaded.
    libcef.dll!content::RenderFrameHostManager::CreateSpeculativeRenderFrameHost(content::SiteInstance * old_instance=0x47019390, content::SiteInstance * new_instance=0x4a00e510, bool recovering_without_early_commit) Line 2696 C++ Symbols loaded.
    libcef.dll!content::RenderFrameHostManager::GetFrameHostForNavigation(content::NavigationRequest * request=0x47102010, std::__1::basic_string<char,std::__1::char_traits<char>,std::__1::allocator<char>> * reason=0x00000000) Line 1042 C++ Symbols loaded.
    libcef.dll!content::RenderFrameHostManager::DidCreateNavigationRequest(content::NavigationRequest * request=0x47102010) Line 868 C++ Symbols loaded.
    libcef.dll!content::FrameTreeNode::CreatedNavigationRequest(std::__1::unique_ptr<content::NavigationRequest,std::__1::default_delete<content::NavigationRequest>> navigation_request={...}) Line 538 C++ Symbols loaded.
    libcef.dll!content::Navigator::OnBeginNavigation(content::FrameTreeNode * frame_tree_node=0x48552110, mojo::StructPtr<blink::mojom::CommonNavigationParams> common_params={...}, mojo::StructPtr<blink::mojom::BeginNavigationParams> begin_params={...}, scoped_refptr<network::SharedURLLoaderFactory> blob_url_loader_factory={...}, mojo::PendingAssociatedRemote<content::mojom::NavigationClient> navigation_client={...}, scoped_refptr<content::PrefetchedSignedExchangeCache> prefetched_signed_exchange_cache={...}, std::__1::unique_ptr<content::WebBundleHandleTracker,std::__1::default_delete<content::WebBundleHandleTracker>> web_bundle_handle_tracker={...}) Line 888 C++ Symbols loaded.
    libcef.dll!content::RenderFrameHostImpl::BeginNavigation(mojo::StructPtr<blink::mojom::CommonNavigationParams> common_params={...}, mojo::StructPtr<blink::mojom::BeginNavigationParams> begin_params={...}, mojo::PendingRemote<blink::mojom::BlobURLToken> blob_url_token={...}, mojo::PendingAssociatedRemote<content::mojom::NavigationClient> navigation_client={...}, mojo::PendingRemote<blink::mojom::PolicyContainerHostKeepAliveHandle> initiator_policy_container_host_keep_alive_handle={...}) Line 6702 C++ Symbols loaded.
    libcef.dll!content::mojom::FrameHostStubDispatch::Accept(content::mojom::FrameHost * impl=0x4850c638, mojo::Message * message=0x0eddfb58) Line 5164 C++ Symbols loaded.
    libcef.dll!content::mojom::FrameHostStub<mojo::RawPtrImplRefTraits<content::mojom::FrameHost>>::Accept(mojo::Message * message=0x0eddfb58) Line 647 C++ Symbols loaded.
    libcef.dll!mojo::InterfaceEndpointClient::HandleValidatedMessage(mojo::Message * message=0x0eddfb58) Line 901 C++ Symbols loaded.
    libcef.dll!mojo::MessageDispatcher::Accept(mojo::Message * message=0x0eddfb58) Line 48 C++ Symbols loaded.
    libcef.dll!mojo::InterfaceEndpointClient::HandleIncomingMessage(mojo::Message * message=0x0eddfb58) Line 655 C++ Symbols loaded.
    libcef.dll!IPC::`anonymous namespace'::ChannelAssociatedGroupController::AcceptOnEndpointThread(mojo::Message message={...}) Line 981 C++ Symbols loaded.
    libcef.dll!base::internal::FunctorTraits<void (mojo::(anonymous namespace)::ThreadSafeInterfaceEndpointClientProxy::*)(mojo::Message) __attribute__((thiscall)),void>::Invoke<void (mojo::(anonymous namespace)::ThreadSafeInterfaceEndpointClientProxy::*)(mojo::Message) __attribute__((thiscall)),scoped_refptr<mojo::(anonymous namespace)::ThreadSafeInterfaceEndpointClientProxy>,mojo::Message>(void(mojo::`anonymous namespace'::ThreadSafeInterfaceEndpointClientProxy::*)(mojo::Message) method, scoped_refptr<mojo::(anonymous namespace)::ThreadSafeInterfaceEndpointClientProxy> && receiver_ptr, mojo::Message && args={...}) Line 509 C++ Symbols loaded.
    [Inline Frame] libcef.dll!base::internal::InvokeHelper<0,void>::MakeItSo(void(mojo::`anonymous namespace'::ThreadSafeInterfaceEndpointClientProxy::*)(mojo::Message) && functor, scoped_refptr<mojo::(anonymous namespace)::ThreadSafeInterfaceEndpointClientProxy> && args, mojo::Message && args) Line 648 C++ Symbols loaded.
    [Inline Frame] libcef.dll!base::internal::Invoker<base::internal::BindState<void (mojo::(anonymous namespace)::ThreadSafeInterfaceEndpointClientProxy::*)(mojo::Message) __attribute__((thiscall)),scoped_refptr<mojo::(anonymous namespace)::ThreadSafeInterfaceEndpointClientProxy>,mojo::Message>,void ()>::RunImpl(void(mojo::`anonymous namespace'::ThreadSafeInterfaceEndpointClientProxy::*)(mojo::Message) && functor, std::__1::tuple<scoped_refptr<mojo::(anonymous namespace)::ThreadSafeInterfaceEndpointClientProxy>,mojo::Message> && bound, std::__1::integer_sequence<unsigned int,0,1>) Line 721 C++ Symbols loaded.
    libcef.dll!base::internal::Invoker<base::internal::BindState<void (mojo::(anonymous namespace)::ThreadSafeInterfaceEndpointClientProxy::*)(mojo::Message) __attribute__((thiscall)),scoped_refptr<mojo::(anonymous namespace)::ThreadSafeInterfaceEndpointClientProxy>,mojo::Message>,void ()>::RunOnce(base::internal::BindStateBase * base=0x481dbf90) Line 690 C++ Symbols loaded.
    [Inline Frame] libcef.dll!base::OnceCallback<void ()>::Run() Line 98 C++ Symbols loaded.
    libcef.dll!base::TaskAnnotator::RunTask(const char * trace_event_name=0x1925bf7e, base::PendingTask * pending_task=0x4714a010) Line 178 C++ Symbols loaded.
    libcef.dll!base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl(base::sequence_manager::LazyNow * continuation_lazy_now=0x0eddfcf0) Line 361 C++ Symbols loaded.
    libcef.dll!base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork() Line 266 C++ Symbols loaded.
    libcef.dll!base::MessagePumpForUI::DoRunLoop() Line 222 C++ Symbols loaded.
    libcef.dll!base::MessagePumpWin::Run(base::MessagePump::Delegate * delegate=0x470ddc94) Line 80 C++ Symbols loaded.
    libcef.dll!base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::Run(bool application_tasks_allowed, base::TimeDelta timeout={...}) Line 470 C++ Symbols loaded.
    libcef.dll!base::RunLoop::Run(const base::Location & location={...}) Line 136 C++ Symbols loaded.
    libcef.dll!CefMainRunner::RunMessageLoop() Line 288 C++ Symbols loaded.
    libcef.dll!CefUIThread::ThreadMain() Line 184 C++ Symbols loaded.
    libcef.dll!base::`anonymous namespace'::ThreadFunc(void * params=0x47088850) Line 113 C++ Symbols loaded.


And this is the Chrome_IOThread at above CHECK fail...

    libcef.dll!base::Lock::CheckHeldAndUnmark() Line 26 C++ Symbols loaded.
    [Inline Frame] libcef.dll!base::Lock::Release() Line 51 C++ Symbols loaded.
    > [Inline Frame] libcef.dll!base::internal::BasicAutoLock<base::Lock>::~BasicAutoLock() Line 140 C++ Symbols loaded.
    libcef.dll!base::ThreadCheckerImpl::CalledOnValidThread(std::__1::unique_ptr<base::debug::StackTrace,std::__1::default_delete<base::debug::StackTrace>> * out_bound_at=0x0f41f830) Line 115 C++ Symbols loaded.
    libcef.dll!base::ScopedValidateThreadChecker::ScopedValidateThreadChecker(const base::ThreadChecker & checker={...}) Line 148 C++ Symbols loaded.
    [Inline Frame] libcef.dll!base::sequence_manager::internal::TaskQueueImpl::main_thread_only() Line 530 C++ Symbols loaded.
    libcef.dll!base::sequence_manager::internal::TaskQueueImpl::NotifyDidProcessTask(const base::sequence_manager::Task & task={...}) Line 751 C++ Symbols loaded.
    libcef.dll!base::sequence_manager::internal::SequenceManagerImpl::NotifyDidProcessTask(base::sequence_manager::internal::SequenceManagerImpl::ExecutingTask * executing_task=0x4700e010, base::sequence_manager::LazyNow * time_after_task=0x0f41f980) Line 886 C++ Symbols loaded.
    libcef.dll!base::sequence_manager::internal::SequenceManagerImpl::DidRunTask() Line 681 C++ Symbols loaded.
    libcef.dll!base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl(base::sequence_manager::LazyNow * continuation_lazy_now=0x0f41fa80) Line 369 C++ Symbols loaded.
    libcef.dll!base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork() Line 266 C++ Symbols loaded.
    libcef.dll!base::MessagePumpForIO::DoRunLoop() Line 731 C++ Symbols loaded.
    libcef.dll!base::MessagePumpWin::Run(base::MessagePump::Delegate * delegate=0x470dc914) Line 80 C++ Symbols loaded.
    libcef.dll!base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::Run(bool application_tasks_allowed, base::TimeDelta timeout={...}) Line 470 C++ Symbols loaded.
    libcef.dll!base::RunLoop::Run(const base::Location & location={...}) Line 136 C++ Symbols loaded.
    libcef.dll!base::Thread::Run(base::RunLoop * run_loop=0x0f41fc80) Line 341 C++ Symbols loaded.
    libcef.dll!content::BrowserProcessIOThread::IOThreadRun(base::RunLoop * run_loop=0x0f41fc80) Line 128 C++ Symbols loaded.
    libcef.dll!content::BrowserProcessIOThread::Run(base::RunLoop * run_loop=0x0f41fc80) Line 92 C++ Symbols loaded.
    libcef.dll!base::Thread::ThreadMain() Line 415 C++ Symbols loaded.
    libcef.dll!base::`anonymous namespace'::ThreadFunc(void * params=0x47089e10) Line 113 C++ Symbols loaded.
Last edited by BobM on Tue Aug 10, 2021 5:26 pm, edited 2 times in total.
BobM
Mentor
 
Posts: 72
Joined: Wed May 11, 2016 4:28 pm

Re: CefBrowser::GetMainFrame() fails in NotificationStateLoc

Postby magreenblatt » Tue Aug 10, 2021 5:13 pm

Ok, thanks. It looks like you’re calling GetMainFrame() from a different thread during navigation. I suggest disabling your commands until navigation completes (OnLoadingStateChange called with isLoading=false).
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: CefBrowser::GetMainFrame() fails in NotificationStateLoc

Postby BobM » Tue Aug 10, 2021 5:31 pm

magreenblatt wrote:Ok, thanks. It looks like you’re calling GetMainFrame() from a different thread during navigation. I suggest disabling your commands until navigation completes (OnLoadingStateChange called with isLoading=false).


Yes, that was the conclusion I came to yesterday, so I tried adding IsValid() and !IsLoading() before calling SenProcessMessage() ...

Code: Select all
bool
TNewsBossWebBrowserWindow::CanCopyItem()
{
  BOOL ret = FALSE;
  if (m_cefBrowser.get() && m_cefBrowser->IsValid() && !m_cefBrowser->IsLoading())
    m_cefBrowser->GetMainFrame()->SendProcessMessage(PID_RENDERER, CefProcessMessage::Create("CanCopy"));
  if (m_cefClientHandler.get())
    ret = m_cefClientHandler->m_canCopy;
  return ret ? true : false;
}


The Main Thread stack in my previous message is from this code with IsLoading check. The checks did stop to greatly, but I left it running overnight with a web page open and this morning the CHECK had failed with the stack traces in previous message.
BobM
Mentor
 
Posts: 72
Joined: Wed May 11, 2016 4:28 pm

Re: CefBrowser::GetMainFrame() fails in NotificationStateLoc

Postby magreenblatt » Tue Aug 10, 2021 5:35 pm

Code: Select all
 m_cefBrowser->GetMainFrame()->SendProcessMessage(PID_RENDERER, CefProcessMessage::Create("CanCopy"));

What is the purpose of this code (what do you do with the message in the renderer process?) You could avoid calling GetMainFrame() from your main thread and instead execute the call (using CefPostTask) on the CEF UI thread.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: CefBrowser::GetMainFrame() fails in NotificationStateLoc

Postby BobM » Tue Aug 10, 2021 5:47 pm

magreenblatt wrote:
Code: Select all
 m_cefBrowser->GetMainFrame()->SendProcessMessage(PID_RENDERER, CefProcessMessage::Create("CanCopy"));

What is the purpose of this code (what do you do with the message in the renderer process?) You could avoid calling GetMainFrame() from your main thread and instead execute the call (using CefPostTask) on the CEF UI thread.


The message is sent to my render process and V8 is used to set flag...

Code: Select all
  bool ClientAppRenderer::OnProcessMessageReceived(
    CefRefPtr<CefBrowser> browser,
    CefRefPtr<CefFrame> frame,
    CefProcessId source_process,
    CefRefPtr<CefProcessMessage> message)
  {
    DCHECK_EQ(source_process, PID_BROWSER);

    DelegateSet::iterator it = delegates_.begin();
    for (; it != delegates_.end(); ++it)
    {
      if ((*it)->OnProcessMessageReceived(this, browser, frame, source_process, message))
        return true;
    }
.
.
.
    if (message->GetName() == CefString("CanCopy"))
    {
      DoQueryCommandEnabled("Copy", frame);
      return true;
    }
.
 .   
.
   return false;
}


void DoQueryCommandEnabled(const char* command, CefRefPtr<CefFrame> frame)
  {
    if (frame)
    {
      CefRefPtr<CefV8Context> context = frame->GetV8Context();
      if (context)
      {
        CefRefPtr<CefV8Value> val;
        CefRefPtr<CefV8Exception> exception;
        string cmd = "document.queryCommandEnabled(\"";
        cmd += command;
        cmd += "\");";
        if (context->Eval(cmd.c_str(), CefString(), 0, val, exception))
        {
          //ATLTRACE("Command enable: %s - %d\n", cmd.c_str(), val->GetBoolValue() ? 1 : 0);
          string resName = "Can";
          resName += command;
          resName += "_Result";
          CefRefPtr<CefProcessMessage> message = CefProcessMessage::Create(resName.c_str());
          message->GetArgumentList()->SetBool(0, val->GetBoolValue());
          frame->SendProcessMessage(PID_BROWSER, message);
        }
      }
    }
  }

BobM
Mentor
 
Posts: 72
Joined: Wed May 11, 2016 4:28 pm

Re: CefBrowser::GetMainFrame() fails in NotificationStateLoc

Postby magreenblatt » Tue Aug 10, 2021 5:58 pm

Is it necessary to explicitly query this state from the native code? Seems like you could instead poll queryCommandEnabled using a timer in JS and only deliver the results via IPC to the browser process if they change. Then store that state somewhere your browser main thread can access it.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: CefBrowser::GetMainFrame() fails in NotificationStateLoc

Postby BobM » Tue Aug 10, 2021 6:05 pm

magreenblatt wrote:Is it necessary to explicitly query this state from the native code? Seems like you could instead poll queryCommandEnabled using a timer in JS and only deliver the results via IPC to the browser process if they change. Then store that state somewhere your browser main thread can access it.


You are probably right about that. Can you point me to how to run a JS polling loop to call QueryCommandEnable, like where/how do I run it? Sorry probably basic stuff. Thanks

Nevermind - found the info... https://bitbucket.org/chromiumembedded/ ... t-bindings

Thanks Marshall! Cheers.
BobM
Mentor
 
Posts: 72
Joined: Wed May 11, 2016 4:28 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 215 guests