How to close child popup window with parent

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.

How to close child popup window with parent

Postby tiplip » Fri Sep 03, 2021 2:37 am

Hi,

I find close cefclient, its devtools window will be closed automatically, how to make popup window behave the same?

that is, closing parent can close popup window as well,

Code: Select all
bool ClientHandler::CreatePopupWindow(CefRefPtr<CefBrowser> browser,
                                      bool is_devtools,
                                      const CefPopupFeatures& popupFeatures,
                                      CefWindowInfo& windowInfo,
                                      CefRefPtr<CefClient>& client,
                                      CefBrowserSettings& settings) {


I notice this function will be called for devtools and popup, but I dont know what arguments make difference, thanks
Last edited by tiplip on Sat Sep 04, 2021 7:47 pm, edited 1 time in total.
tiplip
Mentor
 
Posts: 76
Joined: Thu Mar 26, 2015 3:09 am

Re: How to close child popup window with parent

Postby magreenblatt » Fri Sep 03, 2021 10:15 am

Keep a list in OnAfterCreated of popup windows created. When OnBeforeClose is called for the main window, call CloseBrowser on the popups.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: How to close child popup window with parent

Postby tiplip » Sat Sep 04, 2021 7:16 am

thanks for your point.

I can understand the logic, but where the browser list should be put in cefclient? I tried put the browser list in ClientHandler but find main window and pop window has its own ClientHandler obj.

so I declare it as static in ClientHandler class, it works, but not sure if it is right way.
tiplip
Mentor
 
Posts: 76
Joined: Thu Mar 26, 2015 3:09 am

Re: How to close child popup window with parent

Postby magreenblatt » Sat Sep 04, 2021 8:29 am

In cefclient you could use RootWindowManager.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: How to close child popup window with parent

Postby tiplip » Sat Sep 04, 2021 8:26 pm

magreenblatt wrote:In cefclient you could use RootWindowManager.


thanks.

I implemented as below, and verified it is working as expected for the time being.

Code: Select all
void ClientHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
#ifdef APP_EXT
  MainContext::Get()->GetRootWindowManager()->CloseBrowser(browser);
#endif
}

void RootWindowManager::OnBrowserCreated(RootWindow* root_window,
                                         CefRefPtr<CefBrowser> browser) {
#ifdef APP_EXT
  // Add to the list of existing browsers.
  if (browser->IsPopup())
    browser_list_.push_back(browser);
#endif

}

#ifdef APP_EXT
void RootWindowManager::CloseBrowser(CefRefPtr<CefBrowser> browser) {
  // if it is main window
  if (!browser->IsPopup()) {
    // Remove from the list of existing browsers.
    BrowserList::iterator bit = browser_list_.begin();
    for (; bit != browser_list_.end(); ++bit) {
      (*bit)->GetHost()->CloseBrowser(false);
      browser_list_.erase(bit);
    }
    return;
  }

  // if it is pop window
  BrowserList::iterator bit = browser_list_.begin();
  for (; bit != browser_list_.end(); ++bit) {
    if ((*bit)->IsSame(browser)) {
      browser_list_.erase(bit);
      break;
    }
  }
}
#endif


I use !browser->IsPopup() to judge if it is main window or popup window, that is, there are two kinds of window in total for cef3, right?
if not, what's the right way to detect main window, pop up window, or etc?

thanks
tiplip
Mentor
 
Posts: 76
Joined: Thu Mar 26, 2015 3:09 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 38 guests

cron