Commit 05deba43 authored by Tibor Goldschwendt's avatar Tibor Goldschwendt Committed by Commit Bot

[ntp][doodle] Hide share button if not sent in doodle response

The share button is not sent for doodles that should not be shared.

Fixed: 1113160
Bug: 162949376
Change-Id: I833d6c536cc46fa9fa1db04149a45077a08809d2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2339759
Auto-Submit: Tibor Goldschwendt <tiborg@chromium.org>
Commit-Queue: Alex Gough <ajgo@chromium.org>
Reviewed-by: default avatarEsmael Elmoslimany <aee@chromium.org>
Reviewed-by: default avatarAlex Gough <ajgo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795204}
parent e2005576
...@@ -115,7 +115,8 @@ ...@@ -115,7 +115,8 @@
hidden="[[!showAnimation_]]"> hidden="[[!showAnimation_]]">
</ntp-iframe> </ntp-iframe>
<cr-button id="shareButton" title="$i18n{shareDoodle}" <cr-button id="shareButton" title="$i18n{shareDoodle}"
on-click="onShareButtonClick_"> on-click="onShareButtonClick_"
hidden="[[!imageDoodle_.shareButton]]">
<img id="shareButtonImage" <img id="shareButtonImage"
src="[[imageDoodle_.shareButton.iconUrl.url]]"> src="[[imageDoodle_.shareButton.iconUrl.url]]">
</img> </img>
......
...@@ -204,8 +204,8 @@ class LogoElement extends PolymerElement { ...@@ -204,8 +204,8 @@ class LogoElement extends PolymerElement {
/** @private */ /** @private */
onImageDoodleChange_() { onImageDoodleChange_() {
if (this.imageDoodle_) { const shareButton = this.imageDoodle_ && this.imageDoodle_.shareButton;
const shareButton = this.imageDoodle_.shareButton; if (shareButton) {
const height = this.imageDoodle_.height; const height = this.imageDoodle_.height;
const width = this.imageDoodle_.width; const width = this.imageDoodle_.width;
this.updateStyles({ this.updateStyles({
...@@ -217,8 +217,6 @@ class LogoElement extends PolymerElement { ...@@ -217,8 +217,6 @@ class LogoElement extends PolymerElement {
`${SHARE_BUTTON_SIZE_PX / width * 100}%`, `${SHARE_BUTTON_SIZE_PX / width * 100}%`,
'--ntp-logo-share-button-x': `${shareButton.x / width * 100}%`, '--ntp-logo-share-button-x': `${shareButton.x / width * 100}%`,
'--ntp-logo-share-button-y': `${shareButton.y / height * 100}%`, '--ntp-logo-share-button-y': `${shareButton.y / height * 100}%`,
'--ntp-logo-box-color':
skColorToRgba(this.imageDoodle_.backgroundColor),
}); });
} else { } else {
this.updateStyles({ this.updateStyles({
...@@ -227,6 +225,15 @@ class LogoElement extends PolymerElement { ...@@ -227,6 +225,15 @@ class LogoElement extends PolymerElement {
'--ntp-logo-share-button-width': null, '--ntp-logo-share-button-width': null,
'--ntp-logo-share-button-x': null, '--ntp-logo-share-button-x': null,
'--ntp-logo-share-button-y': null, '--ntp-logo-share-button-y': null,
});
}
if (this.imageDoodle_) {
this.updateStyles({
'--ntp-logo-box-color':
skColorToRgba(this.imageDoodle_.backgroundColor),
});
} else {
this.updateStyles({
'--ntp-logo-box-color': null, '--ntp-logo-box-color': null,
}); });
} }
......
...@@ -207,7 +207,7 @@ struct ImageDoodle { ...@@ -207,7 +207,7 @@ struct ImageDoodle {
// differs from that color we show the doodle in a box of that color. // differs from that color we show the doodle in a box of that color.
skia.mojom.SkColor background_color; skia.mojom.SkColor background_color;
// Specification of the share button. // Specification of the share button.
DoodleShareButton share_button; DoodleShareButton? share_button;
// URLs to be pinged when an image has been shown. // URLs to be pinged when an image has been shown.
url.mojom.Url image_impression_log_url; url.mojom.Url image_impression_log_url;
url.mojom.Url? animation_impression_log_url; url.mojom.Url? animation_impression_log_url;
......
...@@ -268,12 +268,14 @@ new_tab_page::mojom::ImageDoodlePtr MakeImageDoodle( ...@@ -268,12 +268,14 @@ new_tab_page::mojom::ImageDoodlePtr MakeImageDoodle(
doodle->width = width_px; doodle->width = width_px;
doodle->height = height_px; doodle->height = height_px;
doodle->background_color = ParseHexColor(background_color); doodle->background_color = ParseHexColor(background_color);
doodle->share_button = new_tab_page::mojom::DoodleShareButton::New(); if (!share_button_icon.empty()) {
doodle->share_button->x = share_button_x; doodle->share_button = new_tab_page::mojom::DoodleShareButton::New();
doodle->share_button->y = share_button_y; doodle->share_button->x = share_button_x;
doodle->share_button->icon_url = GURL(base::StringPrintf( doodle->share_button->y = share_button_y;
"data:image/png;base64,%s", share_button_icon.c_str())); doodle->share_button->icon_url = GURL(base::StringPrintf(
doodle->share_button->background_color = ParseHexColor(share_button_bg); "data:image/png;base64,%s", share_button_icon.c_str()));
doodle->share_button->background_color = ParseHexColor(share_button_bg);
}
if (type == search_provider_logos::LogoType::ANIMATED) { if (type == search_provider_logos::LogoType::ANIMATED) {
doodle->image_impression_log_url = cta_log_url; doodle->image_impression_log_url = cta_log_url;
doodle->animation_impression_log_url = log_url; doodle->animation_impression_log_url = log_url;
......
...@@ -149,6 +149,22 @@ function createSuite(themeModeDoodlesEnabled) { ...@@ -149,6 +149,22 @@ function createSuite(themeModeDoodlesEnabled) {
}); });
}); });
[true, false].forEach(dark => {
test(`hide share button in ${dark ? 'dark' : 'light'} mode`, async () => {
// Arrange.
const doodle = createImageDoodle();
const imageDoodle = dark ? doodle.image.dark : doodle.image.light;
delete imageDoodle.shareButton;
// Act.
const logo = await createLogo(doodle);
logo.dark = dark;
// Assert.
assertStyle($$(logo, '#shareButton'), 'display', 'none');
});
});
[null, '#ff0000'].forEach(color => { [null, '#ff0000'].forEach(color => {
test(`${color || 'no'} background color shows box`, async () => { test(`${color || 'no'} background color shows box`, async () => {
// Arrange. // Arrange.
......
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