- 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.