Commit 0ccaf201 authored by Esmael El-Moslimany's avatar Esmael El-Moslimany Committed by Commit Bot

WebUI NTP: respect policy that disables custom backgrounds

Bug: 1082276
Change-Id: I38408bdf2fde98ae3599b5f10b6001f9fdffb1a8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2199995
Commit-Queue: Esmael Elmoslimany <aee@chromium.org>
Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#768752}
parent d620f1ff
<style> <style include="cr-hidden-style">
:host {
display: flex;
height: -webkit-fill-available;
}
#container { #container {
padding: 4px; padding: 4px;
} }
...@@ -122,6 +127,30 @@ ...@@ -122,6 +127,30 @@
width: 32px; width: 32px;
} }
#backgroundsDisabled {
align-items: center;
align-self: center;
display: flex;
flex-direction: column;
width: 100%;
}
#backgroundsDisabledIcon {
-webkit-mask-image: url(chrome://resources/images/business.svg);
-webkit-mask-repeat: no-repeat;
-webkit-mask-size: 100%;
background-color: var(--ntp-primary-text-color);
height: 48px;
margin: auto;
width: 48px;
}
#backgroundsDisabledTitle {
margin-top: 10px;
text-align: center;
width: 50%;
}
@media (prefers-color-scheme: dark) { @media (prefers-color-scheme: dark) {
.selected .image, .selected .image,
.selected #uploadFromDevice { .selected #uploadFromDevice {
...@@ -134,7 +163,11 @@ ...@@ -134,7 +163,11 @@
} }
} }
</style> </style>
<ntp-grid id="collections" columns="3" hidden="[[selectedCollection]]"> <div id="backgroundsDisabled" hidden$="[[!customBackgroundDisabledByPolicy_]]">
<div id="backgroundsDisabledIcon"></div>
<div id="backgroundsDisabledTitle">$i18n{customBackgroundDisabled}</div>
</div>
<ntp-grid id="collections" columns="3" hidden="[[!showBackgroundSelection_]]">
<div id="uploadFromDevice" class="tile" role="button" <div id="uploadFromDevice" class="tile" role="button"
on-click="onUploadFromDeviceClick_" tabindex="0"> on-click="onUploadFromDeviceClick_" tabindex="0">
<div class$="[[getCustomBackgroundClass_(theme, backgroundSelection)]]"> <div class$="[[getCustomBackgroundClass_(theme, backgroundSelection)]]">
......
...@@ -2,11 +2,14 @@ ...@@ -2,11 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'chrome://resources/cr_elements/hidden_style_css.m.js';
import './grid.js'; import './grid.js';
import './mini_page.js'; import './mini_page.js';
import './untrusted_iframe.js'; import './untrusted_iframe.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; import {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {BrowserProxy} from './browser_proxy.js'; import {BrowserProxy} from './browser_proxy.js';
import {BackgroundSelection, BackgroundSelectionType} from './customize_dialog.js'; import {BackgroundSelection, BackgroundSelectionType} from './customize_dialog.js';
...@@ -29,6 +32,19 @@ class CustomizeBackgroundsElement extends PolymerElement { ...@@ -29,6 +32,19 @@ class CustomizeBackgroundsElement extends PolymerElement {
notify: true, notify: true,
}, },
/** @private */
customBackgroundDisabledByPolicy_: {
type: Boolean,
value: () =>
loadTimeData.getBoolean('customBackgroundDisabledByPolicy'),
},
/** @private */
showBackgroundSelection_: {
type: Boolean,
computed: 'computeShowBackgroundSelection_(selectedCollection)',
},
/** @private {newTabPage.mojom.BackgroundCollection} */ /** @private {newTabPage.mojom.BackgroundCollection} */
selectedCollection: { selectedCollection: {
notify: true, notify: true,
...@@ -50,6 +66,9 @@ class CustomizeBackgroundsElement extends PolymerElement { ...@@ -50,6 +66,9 @@ class CustomizeBackgroundsElement extends PolymerElement {
constructor() { constructor() {
super(); super();
if (this.customBackgroundDisabledByPolicy_) {
return;
}
/** @private {newTabPage.mojom.PageHandlerRemote} */ /** @private {newTabPage.mojom.PageHandlerRemote} */
this.pageHandler_ = BrowserProxy.getInstance().handler; this.pageHandler_ = BrowserProxy.getInstance().handler;
this.pageHandler_.getBackgroundCollections().then(({collections}) => { this.pageHandler_.getBackgroundCollections().then(({collections}) => {
...@@ -57,6 +76,14 @@ class CustomizeBackgroundsElement extends PolymerElement { ...@@ -57,6 +76,14 @@ class CustomizeBackgroundsElement extends PolymerElement {
}); });
} }
/**
* @return {boolean}
* @private
*/
computeShowBackgroundSelection_() {
return !this.customBackgroundDisabledByPolicy_ && !this.selectedCollection;
}
/** /**
* @return {string} * @return {string}
* @private * @private
......
...@@ -436,6 +436,9 @@ void InstantService::SetCustomBackgroundInfo( ...@@ -436,6 +436,9 @@ void InstantService::SetCustomBackgroundInfo(
const GURL& action_url, const GURL& action_url,
const std::string& collection_id) { const std::string& collection_id) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (IsCustomBackgroundDisabledByPolicy()) {
return;
}
bool is_backdrop_collection = bool is_backdrop_collection =
background_service_ && background_service_ &&
background_service_->IsValidBackdropCollection(collection_id); background_service_->IsValidBackdropCollection(collection_id);
...@@ -484,6 +487,9 @@ void InstantService::SetBackgroundToLocalResource() { ...@@ -484,6 +487,9 @@ void InstantService::SetBackgroundToLocalResource() {
} }
void InstantService::SelectLocalBackgroundImage(const base::FilePath& path) { void InstantService::SelectLocalBackgroundImage(const base::FilePath& path) {
if (IsCustomBackgroundDisabledByPolicy()) {
return;
}
base::ThreadPool::PostTaskAndReply( base::ThreadPool::PostTaskAndReply(
FROM_HERE, {base::TaskPriority::USER_VISIBLE, base::MayBlock()}, FROM_HERE, {base::TaskPriority::USER_VISIBLE, base::MayBlock()},
base::BindOnce(&CopyFileToProfilePath, path, profile_->GetPath()), base::BindOnce(&CopyFileToProfilePath, path, profile_->GetPath()),
......
...@@ -106,6 +106,8 @@ content::WebUIDataSource* CreateNewTabPageUiHtmlSource(Profile* profile) { ...@@ -106,6 +106,8 @@ content::WebUIDataSource* CreateNewTabPageUiHtmlSource(Profile* profile) {
{"backgroundsMenuItem", IDS_NTP_CUSTOMIZE_MENU_BACKGROUND_LABEL}, {"backgroundsMenuItem", IDS_NTP_CUSTOMIZE_MENU_BACKGROUND_LABEL},
{"cancelButton", IDS_CANCEL}, {"cancelButton", IDS_CANCEL},
{"colorPickerLabel", IDS_NTP_CUSTOMIZE_COLOR_PICKER_LABEL}, {"colorPickerLabel", IDS_NTP_CUSTOMIZE_COLOR_PICKER_LABEL},
{"customBackgroundDisabled",
IDS_NTP_CUSTOMIZE_MENU_BACKGROUND_DISABLED_LABEL},
{"customizeButton", IDS_NTP_CUSTOMIZE_BUTTON_LABEL}, {"customizeButton", IDS_NTP_CUSTOMIZE_BUTTON_LABEL},
{"customizeThisPage", IDS_NTP_CUSTOM_BG_CUSTOMIZE_NTP_LABEL}, {"customizeThisPage", IDS_NTP_CUSTOM_BG_CUSTOMIZE_NTP_LABEL},
{"defaultThemeLabel", IDS_NTP_CUSTOMIZE_DEFAULT_LABEL}, {"defaultThemeLabel", IDS_NTP_CUSTOMIZE_DEFAULT_LABEL},
...@@ -222,8 +224,10 @@ NewTabPageUI::NewTabPageUI(content::WebUI* web_ui) ...@@ -222,8 +224,10 @@ NewTabPageUI::NewTabPageUI(content::WebUI* web_ui)
// for the unlikely case where the NewTabPageHandler is created before we // for the unlikely case where the NewTabPageHandler is created before we
// received the DidStartNavigation event. // received the DidStartNavigation event.
navigation_start_time_(base::Time::Now()) { navigation_start_time_(base::Time::Now()) {
content::WebUIDataSource::Add(profile_, auto* source = CreateNewTabPageUiHtmlSource(profile_);
CreateNewTabPageUiHtmlSource(profile_)); source->AddBoolean("customBackgroundDisabledByPolicy",
instant_service_->IsCustomBackgroundDisabledByPolicy());
content::WebUIDataSource::Add(profile_, source);
content::URLDataSource::Add( content::URLDataSource::Add(
profile_, std::make_unique<FaviconSource>( profile_, std::make_unique<FaviconSource>(
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
file="images/arrow_down.svg" type="BINDATA" compress="gzip" /> file="images/arrow_down.svg" type="BINDATA" compress="gzip" />
<include name="IDR_WEBUI_IMAGES_ARROW_RIGHT" <include name="IDR_WEBUI_IMAGES_ARROW_RIGHT"
file="images/arrow_right.svg" type="BINDATA" compress="gzip" /> file="images/arrow_right.svg" type="BINDATA" compress="gzip" />
<include name="IDR_WEBUI_IMAGES_BUSINESS" file="images/business.svg"
type="BINDATA" compress="gzip" />
<include name="IDR_WEBUI_IMAGES_DARK_ARROW_DOWN" <include name="IDR_WEBUI_IMAGES_DARK_ARROW_DOWN"
file="images/dark/arrow_down.svg" type="BINDATA" compress="gzip" /> file="images/dark/arrow_down.svg" type="BINDATA" compress="gzip" />
<include name="IDR_WEBUI_IMAGES_DARK_ICON_SEARCH" <include name="IDR_WEBUI_IMAGES_DARK_ICON_SEARCH"
......
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