Repository: electron/electron
File: shell/browser/native_window_views.cc (C++)

Code before:
    // thickFrame also works for normal window.
    if (!thick_frame_)
      FlipWindowStyle(GetAcceleratedWidget(), false, WS_THICKFRAME);
#endif
  }

  // Default content view.
  SetContentView(new views::View());

  options.Get(options::kUseContentSize, &use_content_size_);

  // NOTE(@mlaurencin) Spec requirements can be found here:
  // https://developer.mozilla.org/en-US/docs/Web/API/Window/open#width
  constexpr int kMinSizeReqdBySpec = 100;
  const int inner_width = options.ValueOrDefault(options::kinnerWidth, 0);
  const int inner_height = options.ValueOrDefault(options::kinnerHeight, 0);
  if (inner_width || inner_height) {
    use_content_size_ = true;
    if (inner_width)
      bounds.set_width(std::max(kMinSizeReqdBySpec, inner_width));
    if (inner_height)
      bounds.set_height(std::max(kMinSizeReqdBySpec, inner_height));
  }

  gfx::Size size = bounds.size();
  if ((has_frame() || has_client_frame()) && use_content_size_)
    size = ContentBoundsToWindowBounds(gfx::Rect(size)).size();

  widget()->CenterWindow(size);

#if BUILDFLAG(IS_WIN)
  // Save initial window state.
  if (fullscreen)
    last_window_state_ = ui::mojom::WindowShowState::kFullscreen;
  else
    last_window_state_ = ui::mojom::WindowShowState::kNormal;
#endif

  // Listen to mouse events.
  aura::Window* window = GetNativeWindow();
  if (window)
    window->AddPreTargetHandler(this);

  WindowBoundsToContentBounds(gfx::Rect(size));

#if BUILDFLAG(IS_LINUX)
  // We need to set bounds again after widget init for two reasons:
  // 1. For CSD windows, user-specified bounds need  to be inflated by frame
  //    insets, but the frame view isn't available at first.
  // 2. The widget clamps bounds to fit the screen, but we want to allow
  //    windows larger than the display.

Review comment (suggestion):
The lack of the check for `has_client_frame()` was preventing `useContentSize` and `setContentSize` from working on Linux CSD windows, which are frameless but create simulated frames + titlebars.

Code after:
    widget()->set_frame_type(views::Widget::FrameType::kForceNative);
    widget()->FrameTypeChanged();
#if BUILDFLAG(IS_WIN)
    // thickFrame also works for normal window.
    if (!thick_frame_)
      FlipWindowStyle(GetAcceleratedWidget(), false, WS_THICKFRAME);
#endif
  }

  // Default content view.
  SetContentView(new views::View());

  options.Get(options::kUseContentSize, &use_content_size_);

  // NOTE(@mlaurencin) Spec requirements can be found here:
  // https://developer.mozilla.org/en-US/docs/Web/API/Window/open#width
  constexpr int kMinSizeReqdBySpec = 100;
  const int inner_width = options.ValueOrDefault(options::kinnerWidth, 0);
  const int inner_height = options.ValueOrDefault(options::kinnerHeight, 0);
  if (inner_width || inner_height) {
    use_content_size_ = true;
    if (inner_width)
      bounds.set_width(std::max(kMinSizeReqdBySpec, inner_width));
    if (inner_height)
      bounds.set_height(std::max(kMinSizeReqdBySpec, inner_height));
  }

  gfx::Size size = bounds.size();
  if (has_frame() && use_content_size_)
    size = ContentBoundsToWindowBounds(gfx::Rect(size)).size();

  widget()->CenterWindow(size);

#if BUILDFLAG(IS_WIN)
  // Save initial window state.
  if (fullscreen)
    last_window_state_ = ui::mojom::WindowShowState::kFullscreen;
  else
    last_window_state_ = ui::mojom::WindowShowState::kNormal;
#endif

  // Listen to mouse events.
  aura::Window* window = GetNativeWindow();
  if (window)
    window->AddPreTargetHandler(this);

#if BUILDFLAG(IS_LINUX)
  // We need to set bounds again after widget init for two reasons:
  // 1. For CSD windows, user-specified bounds need  to be inflated by frame
  //    insets, but the frame view isn't available at first.
  // 2. The widget clamps bounds to fit the screen, but we want to allow