Commit c3a9d8e8 authored by Jiaqi Han's avatar Jiaqi Han Committed by Commit Bot

[Chromecast] Disable supports_multiple_windows to Webviews

This change disables supports_multiple_windows by default to
Webview controller, in order to open new window navigations
in the current view.

Bug: b/170218696
Test: Sample website on Chromecast navigates on the current view.
Change-Id: I44cb7d7e9c8ffa42789f7019779fc9c87935ba92
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2533679Reviewed-by: default avatarSean Topping <seantopping@chromium.org>
Reviewed-by: default avatarDaniel Nicoara <dnicoara@chromium.org>
Commit-Queue: Jiaqi Han <jiaqih@google.com>
Cr-Commit-Position: refs/heads/master@{#827432}
parent 88b7ca99
......@@ -694,6 +694,22 @@ bool CastContentBrowserClient::CanCreateWindow(
bool opener_suppressed,
bool* no_javascript_access) {
*no_javascript_access = true;
// To show new page in the existing view for WebView new window navigations,
// when supports_multiple_windows is disabled, return true so
// RenderFrameHostImpl::CreateNewWindow returns with kReuse.
// Otherwise, return false.
content::WebContents* web_contents =
content::WebContents::FromRenderFrameHost(opener);
if (web_contents) {
CastWebPreferences* cast_prefs =
static_cast<CastWebPreferences*>(web_contents->GetUserData(
CastWebPreferences::kCastWebPreferencesDataKey));
return (cast_prefs &&
!cast_prefs->preferences()->supports_multiple_windows.value());
}
return false;
}
......
......@@ -22,6 +22,10 @@ void CastWebPreferences::Update(blink::web_pref::WebPreferences* prefs) {
if (preferences_.javascript_enabled)
prefs->javascript_enabled = preferences_.javascript_enabled.value();
if (preferences_.supports_multiple_windows) {
prefs->supports_multiple_windows = preferences_.supports_multiple_windows.value();
}
}
} // namespace chromecast
......@@ -21,6 +21,7 @@ class CastWebPreferences : public base::SupportsUserData::Data {
base::Optional<blink::mojom::AutoplayPolicy> autoplay_policy;
base::Optional<bool> hide_scrollbars;
base::Optional<bool> javascript_enabled;
base::Optional<bool> supports_multiple_windows;
};
// Unique key used to identify CastWebPreferences in WebContents' user data.
......
......@@ -69,10 +69,15 @@ WebviewController::WebviewController(content::BrowserContext* browser_context,
contents_->SetUserData(CastWebPreferences::kCastWebPreferencesDataKey,
std::make_unique<CastWebPreferences>());
CastWebPreferences* cast_prefs = GetCastPreferencesFor(contents_.get());
// Allow Webviews to show scrollbars. These are globally disabled since Cast
// Apps are not expected to be scrollable.
GetCastPreferencesFor(contents_.get())->preferences()->hide_scrollbars =
false;
cast_prefs->preferences()->hide_scrollbars = false;
// Disallow Webviews to use multiple windows to show the new page in the
// existing view.
cast_prefs->preferences()->supports_multiple_windows = false;
CastWebContents::InitParams cast_contents_init;
cast_contents_init.is_root_window = true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment