Commit 3f5bfc1e authored by fsamuel's avatar fsamuel Committed by Commit bot

<webview>: Don't reset allowtransparency and allowscaling between createGuest and attachGuest

https://codereview.chromium.org/1033373003/ introduced lazily issuing updated GuestView attributes
between create and attach. The AllowTransparency and AllowScaling attributes were defaulting to false
if not available in the attach params and so they were getting reset on attach. This CL fixes the issue
by only updating the attributes if they are passed along on attach.

BUG=471997

Review URL: https://codereview.chromium.org/1065413002

Cr-Commit-Position: refs/heads/master@{#324327}
parent fa14fd7f
...@@ -2737,3 +2737,15 @@ IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_WebViewInBackgroundPage) { ...@@ -2737,3 +2737,15 @@ IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_WebViewInBackgroundPage) {
ASSERT_TRUE(RunExtensionTest("platform_apps/web_view/background")) ASSERT_TRUE(RunExtensionTest("platform_apps/web_view/background"))
<< message_; << message_;
} }
// This test verifies that the allowtransparency attribute properly propagates
IN_PROC_BROWSER_TEST_F(WebViewTest, AllowTransparencyAndAllowScalingPropagate) {
LoadAppWithGuest("web_view/simple");
ASSERT_TRUE(!!GetGuestWebContents());
extensions::WebViewGuest* guest =
extensions::WebViewGuest::FromWebContents(GetGuestWebContents());
ASSERT_TRUE(guest->allow_transparency());
ASSERT_TRUE(guest->allow_scaling());
}
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
function CreateWebViewAndGuest(callback) { function CreateWebViewAndGuest(callback) {
var webview = document.createElement('webview'); var webview = document.createElement('webview');
webview.allowtransparency = true;
webview.allowscaling = true;
var onLoadStop = function(e) { var onLoadStop = function(e) {
chrome.test.sendMessage('WebViewTest.LAUNCHED'); chrome.test.sendMessage('WebViewTest.LAUNCHED');
webview.removeEventListener('loadstop', onLoadStop); webview.removeEventListener('loadstop', onLoadStop);
......
...@@ -422,14 +422,14 @@ void WebViewGuest::GuestReady() { ...@@ -422,14 +422,14 @@ void WebViewGuest::GuestReady() {
// WebContents::GetRenderWidgetHostView will return the RWHV of an // WebContents::GetRenderWidgetHostView will return the RWHV of an
// interstitial page if one is showing at this time. We only want opacity // interstitial page if one is showing at this time. We only want opacity
// to apply to web pages. // to apply to web pages.
if (guest_opaque_) { if (allow_transparency_) {
web_contents()->GetRenderViewHost()->GetView()->SetBackgroundColor(
SK_ColorTRANSPARENT);
} else {
web_contents() web_contents()
->GetRenderViewHost() ->GetRenderViewHost()
->GetView() ->GetView()
->SetBackgroundColorToDefault(); ->SetBackgroundColorToDefault();
} else {
web_contents()->GetRenderViewHost()->GetView()->SetBackgroundColor(
SK_ColorTRANSPARENT);
} }
} }
...@@ -721,7 +721,7 @@ WebViewGuest::WebViewGuest(content::WebContents* owner_web_contents) ...@@ -721,7 +721,7 @@ WebViewGuest::WebViewGuest(content::WebContents* owner_web_contents)
rules_registry_id_(RulesRegistryService::kInvalidRulesRegistryID), rules_registry_id_(RulesRegistryService::kInvalidRulesRegistryID),
find_helper_(this), find_helper_(this),
is_overriding_user_agent_(false), is_overriding_user_agent_(false),
guest_opaque_(true), allow_transparency_(false),
javascript_dialog_helper_(this), javascript_dialog_helper_(this),
allow_scaling_(false), allow_scaling_(false),
is_guest_fullscreen_(false), is_guest_fullscreen_(false),
...@@ -1018,14 +1018,16 @@ void WebViewGuest::ApplyAttributes(const base::DictionaryValue& params) { ...@@ -1018,14 +1018,16 @@ void WebViewGuest::ApplyAttributes(const base::DictionaryValue& params) {
SetUserAgentOverride(user_agent_override); SetUserAgentOverride(user_agent_override);
bool allow_transparency = false; bool allow_transparency = false;
params.GetBoolean(webview::kAttributeAllowTransparency, &allow_transparency); if (params.GetBoolean(webview::kAttributeAllowTransparency,
// We need to set the background opaque flag after navigation to ensure that &allow_transparency)) {
// there is a RenderWidgetHostView available. // We need to set the background opaque flag after navigation to ensure that
SetAllowTransparency(allow_transparency); // there is a RenderWidgetHostView available.
SetAllowTransparency(allow_transparency);
}
bool allow_scaling = false; bool allow_scaling = false;
params.GetBoolean(webview::kAttributeAllowScaling, &allow_scaling); if (params.GetBoolean(webview::kAttributeAllowScaling, &allow_scaling))
SetAllowScaling(allow_scaling); SetAllowScaling(allow_scaling);
bool is_pending_new_window = false; bool is_pending_new_window = false;
if (GetOpener()) { if (GetOpener()) {
...@@ -1082,21 +1084,21 @@ void WebViewGuest::SetZoomMode(ZoomController::ZoomMode zoom_mode) { ...@@ -1082,21 +1084,21 @@ void WebViewGuest::SetZoomMode(ZoomController::ZoomMode zoom_mode) {
} }
void WebViewGuest::SetAllowTransparency(bool allow) { void WebViewGuest::SetAllowTransparency(bool allow) {
if (guest_opaque_ != allow) if (allow_transparency_ == allow)
return; return;
guest_opaque_ = !allow; allow_transparency_ = allow;
if (!web_contents()->GetRenderViewHost()->GetView()) if (!web_contents()->GetRenderViewHost()->GetView())
return; return;
if (guest_opaque_) { if (allow_transparency_) {
web_contents()->GetRenderViewHost()->GetView()->SetBackgroundColor(
SK_ColorTRANSPARENT);
} else {
web_contents() web_contents()
->GetRenderViewHost() ->GetRenderViewHost()
->GetView() ->GetView()
->SetBackgroundColorToDefault(); ->SetBackgroundColorToDefault();
} else {
web_contents()->GetRenderViewHost()->GetView()->SetBackgroundColor(
SK_ColorTRANSPARENT);
} }
} }
......
...@@ -89,9 +89,11 @@ class WebViewGuest : public GuestView<WebViewGuest>, ...@@ -89,9 +89,11 @@ class WebViewGuest : public GuestView<WebViewGuest>,
void SetZoomMode(ui_zoom::ZoomController::ZoomMode zoom_mode); void SetZoomMode(ui_zoom::ZoomController::ZoomMode zoom_mode);
void SetAllowScaling(bool allow); void SetAllowScaling(bool allow);
bool allow_scaling() const { return allow_scaling_; }
// Sets the transparency of the guest. // Sets the transparency of the guest.
void SetAllowTransparency(bool allow); void SetAllowTransparency(bool allow);
bool allow_transparency() const { return allow_transparency_; }
// Loads a data URL with a specified base URL and virtual URL. // Loads a data URL with a specified base URL and virtual URL.
bool LoadDataWithBaseURL(const std::string& data_url, bool LoadDataWithBaseURL(const std::string& data_url,
...@@ -364,7 +366,7 @@ class WebViewGuest : public GuestView<WebViewGuest>, ...@@ -364,7 +366,7 @@ class WebViewGuest : public GuestView<WebViewGuest>,
std::string name_; std::string name_;
// Stores whether the contents of the guest can be transparent. // Stores whether the contents of the guest can be transparent.
bool guest_opaque_; bool allow_transparency_;
// Stores the src URL of the WebView. // Stores the src URL of the WebView.
GURL src_; GURL src_;
......
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