How to close one CefBrowserView without closing CefWindow?

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.

Re: How to close one CefBrowserView without closing CefWindo

Postby paveldvlip » Sat Aug 20, 2022 8:20 am

Code: Select all
bool CHWindow::OnDoClose(CefRefPtr<CefBrowser> browser)
{
   CEF_REQUIRE_UI_THREAD();

   if (m_active_tab.m_browser_view && m_active_tab.m_browser_view->GetBrowser()->IsSame(browser))
      m_active_tab = CHTab();

   for (auto it = m_tabs.begin(); it != m_tabs.end(); ++it) {
      auto& tab = *it;
      if (tab.m_browser_view->GetBrowser()->IsSame(browser)) {
         tab.m_panel->RemoveAllChildViews();
         m_bottom_panel->RemoveChildView(tab.m_panel);
         m_browser_panel->RemoveChildView(tab.m_browser_view);
         m_tabs.erase(it);

         auto browser_view = CefBrowserView::GetForBrowser(browser);

         break;
      }
   }

   if (!TSTERMINATE && !m_active_tab.m_browser_view && !m_tabs.empty())
      SetActiveTab(*m_tabs.rbegin());

   return true;
}

When I remove the last reference to the CefBrowserView in the m_tabs.erase(it) line, I see in the destructor that there is one more active reference to the CefBrowserView somewhere else. Because of this, the view object is not deleted. The browser itself stores it and returns it correctly in the next line of code.
Calling CloseBrowser(false) has no effect because the window_destroyed_ flag is false and the function does nothing. This is a bug.
paveldvlip
Techie
 
Posts: 22
Joined: Thu Mar 30, 2017 7:53 am

Re: How to close one CefBrowserView without closing CefWindo

Postby magreenblatt » Sat Aug 20, 2022 9:41 am

Likely WindowDestroyed needs to be called in response to CloseBrowser if DoClose returns true and the CefBrowserView is not part of the Views hierarchy. A PR to fix including unit test coverage in ceftests is welcome.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: How to close one CefBrowserView without closing CefWindo

Postby paveldvlip » Sat Aug 20, 2022 5:47 pm

This solution breaks the logic of the DoClose function, which is supposed to close the "browser window" itself, but there is no mechanism to tell the browser that the "window" is closed if a view is used instead of a window or the window has non-standard closing behavior. The same problem occurs when using cef with MFC dialog boxes: the browser does not close correctly after the window is closed. The solution to this problem is to make the WindowDestroyed function available to call directly.
paveldvlip
Techie
 
Posts: 22
Joined: Thu Mar 30, 2017 7:53 am

Re: How to close one CefBrowserView without closing CefWindo

Postby magreenblatt » Sat Aug 20, 2022 9:50 pm

The solution to this problem is to make the WindowDestroyed function available to call directly.

I disagree. If the CefBrowserView does not have a window then there is no window to notify, and we can proceed with browser destruction similar to the existing logic for windowless rendering (in that case when DoClose returns false). DoClose will not be called if the CefBrowserView has already been destroyed via Views hierarch tear-down. This is consistent with the DoClose documentation. https://github.com/chromiumembedded/cef ... ler.h#L121
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: How to close one CefBrowserView without closing CefWindo

Postby magreenblatt » Sat Aug 20, 2022 10:07 pm

The same problem occurs when using cef with MFC dialog boxes: the browser does not close correctly after the window is closed.

Are you talking about non-Views windowed rendering? If so, and the browser HWND is parented to the MFC dialog, then the browser will be destroyed when the dialog is destroyed. Otherwise, you call ::DestroyWindow(browser->GetHost()->GetWindowHandle()) from DoClose and return true.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: How to close one CefBrowserView without closing CefWindo

Postby paveldvlip » Sun Aug 21, 2022 2:38 am

Can you make such a change to the code to solve this problem? I am not familiar with chromium and cef source code and it will take me a very long time to get it done. If you make a fix, then I can confirm if it works in my solution or not.
paveldvlip
Techie
 
Posts: 22
Joined: Thu Mar 30, 2017 7:53 am

Re: How to close one CefBrowserView without closing CefWindo

Postby paveldvlip » Sun Aug 21, 2022 2:45 am

It is possible that the CloseBrowser function with the force_close = true argument is implemented incorrectly. Calling CloseBrowser(true) implies that the browser is guaranteed to be closed anyway, but it turns out that's not the case.
paveldvlip
Techie
 
Posts: 22
Joined: Thu Mar 30, 2017 7:53 am

Re: How to close one CefBrowserView without closing CefWindo

Postby magreenblatt » Sun Aug 21, 2022 8:32 am

Please add a bug to the issue tracker that describes the issue and links this thread. I don’t know how soon it will be fixed.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm


Re: How to close one CefBrowserView without closing CefWindo

Postby liulun » Wed Sep 07, 2022 10:20 pm

@paveldvlip
Have you get some tricks to pass by this issue.

@magreenblatt
Is this a recent issue?
Dose Old CEF version has this issue?

----
BrowserView which added by AddOverlayView can not be released,too.

Add a BrowserView to a window by AddOverlayView
Code: Select all
overlayView = CefBrowserView::CreateBrowserView(pageHandler, url, settings, nullptr, nullptr, nullptr);
overlayController = window->AddOverlayView(overlayView, CEF_DOCKING_MODE_CUSTOM);


Close the BrowserView:
Code: Select all
overlayView->GetBrowser()->GetHost()->CloseBrowser(true)


The overlayView is not visible now.
But the overlayView's browser process is not exited.
The CefLifeSpanHandler::OnBeforeClose() method was not called,too.

OS:Windows 10
CEF Version:104.4.19
liulun
Techie
 
Posts: 12
Joined: Tue Sep 07, 2021 1:01 am

PreviousNext

Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 60 guests