Multiple tabbed browsers - open in background

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.

Multiple tabbed browsers - open in background

Postby ndesktop » Thu Nov 02, 2023 1:16 pm

I have a solution managing multiple browsers in a tab. When doing a wheel-click, this should open a tab in background. For this I have modified CEF to have a new field in cef_window_info_t (int hidden, similar with what is for macOS), set this to 1. What follows is:
- open a new tab in application to host the new browser
- create browser with CefWindowInfo::hidden set to 1
- modify ChromeBrowserHostImpl::Create (cef/libcef/browser/chrome/chrome_browser_host_impl.cc) from
Code: Select all
 
  // Add a new tab. This will indirectly create a new tab WebContents and
  // call ChromeBrowserDelegate::OnWebContentsCreated to create the associated
  // ChromeBrowserHostImpl.
  chrome::AddTabAt(browser, url, /*index=*/TabStripModel::kNoTab,
                   /*foreground=*/true);

to
Code: Select all
  // Add a new tab. This will indirectly create a new tab WebContents and
  // call ChromeBrowserDelegate::OnWebContentsCreated to create the associated
  // ChromeBrowserHostImpl.
  bool foreground = true;
  if (params.window_info) {
    if (params.window_info->hidden != 0) {
      foreground = false;
    }
  }
  chrome::AddTabAt(browser, url, /*index=*/TabStripModel::kNoTab,
                   /*foreground=*/foreground);


Test is: have a 1st tab (google.com), do a search and wheel-click on the first link (acme.com).

What happens is the browser opens correctly, but visible:
- 1st tab selected, associated browser google.com visible
- 2nd tab acme.com *not* selected, but its 2nd associated browser acme.com is also visible

Clicking on a tab get the associated browser, retrieves its HWND (browser->GetHost()->GetWindowHandle()) and simply calls ShowWindow(hwnd, SW_SHOW), while calling ShowWindow(hwnd, SW_HIDE) for the previously selected browser.

Clicking on the 2nd tab and then back on the first tab fix the visibility problem, google.com becomes now visible and 2nd acme.com becomes hidden.

I have tried to suppress WS_VISIBLE from CefWindowInfo::style, call ShowWindow with SW_HIDE in client handler's OnAfterCreated for the newly (background) opened browser, but no luck.
I have also noticed that in chromium/src/chrome/browser/ui/browser_navigator.cc, in the function Navigate, there is a call
Code: Select all
  // Some dispositions need coercion to base types.
  NormalizeDisposition(params);

which changes back from NEW_BACKGROUND_TAB to NEW_FOREGROUND_TAB (also tabstrip_add_types becomes AddTabType::ADD_ACTIVE - this is merely an observation, I do not understand yet enough if this is meaningful in this case).

(Also in src/cef/libcef/browser/chrome/views/chrome_child_window.cc OnWindowCreated calls window_->Show() without any condition).

Did someone run into something similar and have a (better) solution?
I can use hardcore tricks (CBT hooks, WNDPROC subclassing etc.) to implement some kind of logic to contain this and make it behave, but if there is some regular thing I can make use of it would be much better.
ndesktop
Master
 
Posts: 756
Joined: Thu Dec 03, 2015 10:10 am

Re: Multiple tabbed browsers - open in background

Postby ndesktop » Fri Nov 03, 2023 12:42 pm

Solved using WNDPROC subclassing due tolack of time. But still, if someone can point me into a better direction, I'd be happy to hear.
ndesktop
Master
 
Posts: 756
Joined: Thu Dec 03, 2015 10:10 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 204 guests