chromiumembedded / cef

Chromium Embedded Framework (CEF). A simple framework for embedding Chromium-based browsers in other applications.
https://bitbucket.org/chromiumembedded/cef/
Other
3.09k stars 450 forks source link

chrome: Unintended Window Unminimization on Navigation in Minimized State #3618

Closed nik-sp closed 6 months ago

nik-sp commented 6 months ago

Description

The issue appears when attempting to redirect the user to a webpage using the following code snippet:

browser_->GetMainFrame()->LoadURL(web_page_url);

To Reproduce

Steps to reproduce the behavior:

  1. In tests/cefclient/cefclient_win.cc:106, add a flag to open the window in a minimized state:
    window_config->show_state = cef_show_state_t::CEF_SHOW_STATE_MINIMIZED;
    window_config->bounds = {200, 200, 800, 600};
  2. In tests/cefclient/browser/root_window_manager.cc:433, after the browser is created, add a call to load any URL:
    active_browser_->GetMainFrame()->LoadURL("https://example.com/");
  3. Build the cefclient
  4. Launch the cefclient with the following flags: --use-views --enable-chrome-runtime
  5. Observe the window being unminimized after start.

Without --enable-chrome-runtime flag, the window stays minimized.

Expected behavior

The application window should remain in a minimized state when using LoadURL to load a URL.

Versions (please complete the following information):

Additional context

If params.user_gesture = false is added to CefFrameHostImpl::LoadURLWithExtras it fixes the issue:

if (frame_id == CefFrameHostImpl::kMainFrameId) {
    // Load via the browser using NavigationController.
    auto browser = GetBrowserHostBase();
    if (browser) {
      content::OpenURLParams params(
          gurl, referrer, WindowOpenDisposition::CURRENT_TAB, transition,
          /*is_renderer_initiated=*/false);
      params.extra_headers = extra_headers;      
+    params.user_gesture = false; // <-- adding this line fixes the issue

https://github.com/chromiumembedded/cef/blob/2f0b00f8f59b1a9114fcd855fd7fef37c6ee24ea/libcef/browser/frame_host_impl.cc#L378

This user_gesture flag is then used in bool ChromeBrowserHostImpl::Navigate(const content::OpenURLParams& params) to set proper window_action https://github.com/chromiumembedded/cef/blob/2f0b00f8f59b1a9114fcd855fd7fef37c6ee24ea/libcef/browser/chrome/chrome_browser_host_impl.cc#L447-L449

And this window_action is used to determine whether to show window or not

~ScopedBrowserShower() {
    BrowserWindow* window = params_->browser->window();
    if (params_->window_action == NavigateParams::SHOW_WINDOW_INACTIVE) {
      // TODO(crbug.com/1490267): investigate if SHOW_WINDOW_INACTIVE needs to
      // be supported for tab modal popups.
      CHECK_EQ(params_->is_tab_modal_popup, false);
      window->ShowInactive();
    } else if (params_->window_action == NavigateParams::SHOW_WINDOW) {
      if (params_->is_tab_modal_popup) {
        CHECK_EQ(params_->disposition, WindowOpenDisposition::NEW_POPUP);
        CHECK_NE(source_contents_, nullptr);
        constrained_window::ShowModalDialog(window->GetNativeWindow(),
                                            source_contents_);
      } else {
        window->Show();
      }

https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ui/browser_navigator.cc;l=506;drc=bc07189b068b3088cd70f03e50b85064d8d04805

magreenblatt commented 6 months ago
  • params.user_gesture = false; // <-- adding this line fixes the issue

We should try this and see if it has any impact on unit tests.