0

Changing GetCanResizeFromWebAPI to GetWebApiWindowResizable

The function name CanResizeFromWebAPI reflects the fact that
the returned value comes for WebApi window.setResizable(bool) API.
Tha name however is confusing, as even if the function returns false,
`window.resizeTo(x,y)` called from WebApi still works and changes the
size of the window. The ambiguity arises as 'from' has two meanings:
 * (CanResize)FromWebAPI from reflects the origin of value of
 'CanResize' - the current name comes from that meaning.
 * Can(ResizeFromWebAPI) about the origin for resize request what is
 unaligned with the semantic of the function
 It is impossible to know how to interpret the name without the context.

 Therefore in this CL I propose the less ambiguous name reflecting
 origin of value: GetWebApiWindowResizable.


Fixed: 380246006
Change-Id: I6b89e4330fd9069a7e757f01a263f8297b66aa4e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6269297
Commit-Queue: Robert Ferens <rferens@google.com>
Reviewed-by: Taylor Bergquist <tbergquist@chromium.org>
Reviewed-by: Avi Drissman <avi@chromium.org>
Reviewed-by: Andrew Rayskiy <greengrape@google.com>
Cr-Commit-Position: refs/heads/main@{#1420970}
This commit is contained in:
Robert Ferens
2025-02-17 01:52:32 -08:00
committed by Chromium LUCI CQ
parent 35972cd639
commit 9610d728c1
12 changed files with 36 additions and 32 deletions

@ -2364,8 +2364,8 @@ bool Browser::CanUseWindowingControls(
return true;
}
void Browser::OnCanResizeFromWebAPIChanged() {
window_->OnCanResizeFromWebAPIChanged();
void Browser::OnWebApiWindowResizableChanged() {
window_->OnWebApiWindowResizableChanged();
}
bool Browser::GetCanResize() {

@ -1012,7 +1012,7 @@ class Browser : public TabStripModelObserver,
const base::FilePath& path) override;
bool CanUseWindowingControls(
content::RenderFrameHost* requesting_frame) override;
void OnCanResizeFromWebAPIChanged() override;
void OnWebApiWindowResizableChanged() override;
bool GetCanResize() override;
void MinimizeFromWebAPI() override;
void MaximizeFromWebAPI() override;

@ -612,9 +612,9 @@ class BrowserWindow : public ui::BaseWindow,
// of a full titlebar. This is only supported for desktop web apps.
virtual bool IsBorderlessModeEnabled() const = 0;
// Notifies `BrowserView` about the resizable boolean having been set vith
// Notifies `BrowserView` about the resizable boolean having been set with
// `window.setResizable(bool)` API.
virtual void OnCanResizeFromWebAPIChanged() = 0;
virtual void OnWebApiWindowResizableChanged() = 0;
// Returns the overall resizability of the `BrowserView` when considering
// both the value set by the `window.setResizable(bool)` API and browser's

@ -1865,7 +1865,7 @@ void BrowserView::OnActiveTabChanged(content::WebContents* old_contents,
// TODO(laurila, crbug.com/1493617): Support multi-tab apps.
// window.setResizable API should never be called from multi-tab browser.
CHECK(!GetCanResizeFromWebAPI());
CHECK(!GetWebApiWindowResizable());
// If |contents_container_| already has the correct WebContents, we can save
// some work. This also prevents extra events from being reported by the
@ -2884,7 +2884,7 @@ void BrowserView::OnWidgetVisibilityChanged(views::Widget* widget,
UpdateLoadingAnimations(visible);
}
std::optional<bool> BrowserView::GetCanResizeFromWebAPI() const {
std::optional<bool> BrowserView::GetWebApiWindowResizable() const {
// TODO(laurila, crbug.com/1493617): Support multi-tab apps.
if (browser()->tab_strip_model()->count() > 1) {
return std::nullopt;
@ -2920,7 +2920,7 @@ ui::mojom::WindowShowState BrowserView::GetWindowShowState() const {
}
}
void BrowserView::OnCanResizeFromWebAPIChanged() {
void BrowserView::OnWebApiWindowResizableChanged() {
// TODO(laurila, crbug.com/1493617): Support multi-tab apps.
// The value can only be set in web apps, where there currently can only be 1
// WebContents, the return value can be determined only by looking at the
@ -3000,7 +3000,7 @@ void BrowserView::OnWidgetWindowModalVisibilityChanged(views::Widget* widget,
}
void BrowserView::DidFirstVisuallyNonEmptyPaint() {
auto can_resize = GetCanResizeFromWebAPI();
auto can_resize = GetWebApiWindowResizable();
if (cached_can_resize_from_web_api_ == can_resize) {
return;
}
@ -3727,17 +3727,18 @@ bool BrowserView::GetAcceleratorForCommandId(
// BrowserView, views::WidgetDelegate implementation:
bool BrowserView::CanResize() const {
return WidgetDelegate::CanResize() && GetCanResizeFromWebAPI().value_or(true);
return WidgetDelegate::CanResize() &&
GetWebApiWindowResizable().value_or(true);
}
bool BrowserView::CanFullscreen() const {
return WidgetDelegate::CanFullscreen() &&
GetCanResizeFromWebAPI().value_or(true);
GetWebApiWindowResizable().value_or(true);
}
bool BrowserView::CanMaximize() const {
return WidgetDelegate::CanMaximize() &&
GetCanResizeFromWebAPI().value_or(true);
GetWebApiWindowResizable().value_or(true);
}
bool BrowserView::CanActivate() const {

@ -466,7 +466,7 @@ class BrowserView : public BrowserWindow,
void UpdateWebAppStatusIconsVisiblity();
// Getter for the `window.setResizable(bool)` state.
std::optional<bool> GetCanResizeFromWebAPI() const;
std::optional<bool> GetWebApiWindowResizable() const;
// Return the tab strip index of the single tab (if any) that is inactive but
// part of a split view. Assumes there is max one split view in the tab
@ -531,7 +531,7 @@ class BrowserView : public BrowserWindow,
void Maximize() override;
void Minimize() override;
void Restore() override;
void OnCanResizeFromWebAPIChanged() override;
void OnWebApiWindowResizableChanged() override;
bool GetCanResize() override;
ui::mojom::WindowShowState GetWindowShowState() const override;
void EnterFullscreen(const GURL& url,

@ -1972,7 +1972,7 @@ class WebAppFrameToolbarBrowserTest_AdditionalWindowingControls
std::optional<bool> web_api_can_resize_expected) {
EXPECT_EQ(helper()->browser_view()->CanResize(),
browser_view_can_resize_expected);
EXPECT_EQ(helper()->browser_view()->GetCanResizeFromWebAPI(),
EXPECT_EQ(helper()->browser_view()->GetWebApiWindowResizable(),
web_api_can_resize_expected);
#if defined(USE_AURA)
@ -2061,13 +2061,13 @@ IN_PROC_BROWSER_TEST_F(
auto* web_contents = helper()->browser_view()->GetActiveWebContents();
content::WaitForLoadStop(web_contents);
EXPECT_EQ(helper()->browser_view()->GetCanResizeFromWebAPI(), std::nullopt);
EXPECT_EQ(helper()->browser_view()->GetWebApiWindowResizable(), std::nullopt);
// Navigates to the second page of the app.
ASSERT_TRUE(
ui_test_utils::NavigateToURL(helper()->app_browser(), second_page_url()));
content::WaitForLoadStop(web_contents);
EXPECT_EQ(helper()->browser_view()->GetCanResizeFromWebAPI(), std::nullopt);
EXPECT_EQ(helper()->browser_view()->GetWebApiWindowResizable(), std::nullopt);
}
IN_PROC_BROWSER_TEST_F(
@ -2085,7 +2085,7 @@ IN_PROC_BROWSER_TEST_F(
ASSERT_TRUE(
ui_test_utils::NavigateToURL(helper()->app_browser(), second_page_url()));
content::WaitForLoadStop(web_contents);
EXPECT_EQ(helper()->browser_view()->GetCanResizeFromWebAPI(), std::nullopt);
EXPECT_EQ(helper()->browser_view()->GetWebApiWindowResizable(), std::nullopt);
// Sets the resizability true for the second page.
SetResizableAndWait(web_contents, /*resizable=*/true, /*expected=*/true);
@ -2096,9 +2096,10 @@ IN_PROC_BROWSER_TEST_F(
content::WaitForLoadStop(web_contents);
// Reads the resizability from the BFCache if it's enabled. Otherwise null.
if (content::BackForwardCache::IsBackForwardCacheFeatureEnabled()) {
EXPECT_FALSE(helper()->browser_view()->GetCanResizeFromWebAPI().value());
EXPECT_FALSE(helper()->browser_view()->GetWebApiWindowResizable().value());
} else {
EXPECT_EQ(helper()->browser_view()->GetCanResizeFromWebAPI(), std::nullopt);
EXPECT_EQ(helper()->browser_view()->GetWebApiWindowResizable(),
std::nullopt);
}
// Navigates forward to the already visited second page.
@ -2106,9 +2107,10 @@ IN_PROC_BROWSER_TEST_F(
content::WaitForLoadStop(web_contents);
// Reads the resizability from the BFCache if it's enabled. Otherwise null.
if (content::BackForwardCache::IsBackForwardCacheFeatureEnabled()) {
EXPECT_TRUE(helper()->browser_view()->GetCanResizeFromWebAPI().value());
EXPECT_TRUE(helper()->browser_view()->GetWebApiWindowResizable().value());
} else {
EXPECT_EQ(helper()->browser_view()->GetCanResizeFromWebAPI(), std::nullopt);
EXPECT_EQ(helper()->browser_view()->GetWebApiWindowResizable(),
std::nullopt);
}
}
@ -2129,16 +2131,17 @@ IN_PROC_BROWSER_TEST_F(
ASSERT_TRUE(ui_test_utils::NavigateToURL(helper()->app_browser(),
GURL("http://www.google.com/")));
content::WaitForLoadStop(web_contents);
EXPECT_EQ(helper()->browser_view()->GetCanResizeFromWebAPI(), std::nullopt);
EXPECT_EQ(helper()->browser_view()->GetWebApiWindowResizable(), std::nullopt);
// Returning to the original URL then reads the resizability from the BFCache
// if it's enabled.
web_contents->GetController().GoBack();
content::WaitForLoadStop(web_contents);
if (content::BackForwardCache::IsBackForwardCacheFeatureEnabled()) {
EXPECT_TRUE(helper()->browser_view()->GetCanResizeFromWebAPI().value());
EXPECT_TRUE(helper()->browser_view()->GetWebApiWindowResizable().value());
} else {
EXPECT_EQ(helper()->browser_view()->GetCanResizeFromWebAPI(), std::nullopt);
EXPECT_EQ(helper()->browser_view()->GetWebApiWindowResizable(),
std::nullopt);
}
}

@ -112,7 +112,7 @@ class TestBrowserWindow : public BrowserWindow {
void Maximize() override {}
void Minimize() override {}
void Restore() override {}
void OnCanResizeFromWebAPIChanged() override {}
void OnWebApiWindowResizableChanged() override {}
bool GetCanResize() override;
ui::mojom::WindowShowState GetWindowShowState() const override;
bool ShouldHideUIForFullscreen() const override;

@ -38,7 +38,7 @@ class PageDelegate {
// Notifies `BrowserView` about the resizable boolean having been set vith
// `window.setResizable(bool)` API.
virtual void OnCanResizeFromWebAPIChanged() = 0;
virtual void OnWebApiWindowResizableChanged() = 0;
// Notify the page uses a forbidden powerful API and cannot be shown in
// preview mode.

@ -112,7 +112,7 @@ void PageImpl::SetResizableForTesting(std::optional<bool> resizable) {
void PageImpl::SetResizable(std::optional<bool> resizable) {
resizable_ = resizable;
delegate_->OnCanResizeFromWebAPIChanged();
delegate_->OnWebApiWindowResizableChanged();
}
std::optional<bool> PageImpl::GetResizable() {

@ -11418,8 +11418,8 @@ void WebContentsImpl::CancelPreviewByMojoBinderPolicy(
}
}
void WebContentsImpl::OnCanResizeFromWebAPIChanged() {
delegate_->OnCanResizeFromWebAPIChanged();
void WebContentsImpl::OnWebApiWindowResizableChanged() {
delegate_->OnWebApiWindowResizableChanged();
}
FrameTreeNodeId WebContentsImpl::GetOuterDelegateFrameTreeNodeId() {

@ -1217,7 +1217,7 @@ class CONTENT_EXPORT WebContentsImpl
bool IsPageInPreviewMode() const override;
void CancelPreviewByMojoBinderPolicy(
const std::string& interface_name) override;
void OnCanResizeFromWebAPIChanged() override;
void OnWebApiWindowResizableChanged() override;
// blink::mojom::ColorChooserFactory ---------------------------------------
void OnColorChooserFactoryReceiver(

@ -469,7 +469,7 @@ class CONTENT_EXPORT WebContentsDelegate {
// Notifies `BrowserView` about the resizable boolean having been set vith
// `window.setResizable(bool)` API.
virtual void OnCanResizeFromWebAPIChanged() {}
virtual void OnWebApiWindowResizableChanged() {}
// Returns the overall resizability of the `BrowserView` when considering
// both the value set by the AWC API and browser's "native" resizability.
virtual bool GetCanResize();