Commit adfdef98 authored by proberge's avatar proberge Committed by Commit Bot

Chrome Cleanup WebUI: add conditional "Powered by" element

Chrome Cleanup's functionality can be powered by an external company.
When this is the case, we want to show attribution in the WebUI. This is
done through the text "Powered by" followed by the company's logo inlined
in the text, then the registered trademark symbol.

Also fixes a line-split issue for the file paths to be removed and makes
some static chrome_cleaner_controller methods into class methods.

Bug: 690020
Change-Id: I87acfeb4a6ee95cbdd197318b3596f93f819c520
Reviewed-on: https://chromium-review.googlesource.com/568399
Commit-Queue: proberge <proberge@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarChris Sharp <csharp@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487246}
parent 5fc9993f
......@@ -18,6 +18,11 @@
<include name="IDR_PRODUCT_LOGO_64" file="google_chrome/product_logo_64.png" type="BINDATA" />
<include name="IDR_PRODUCT_LOGO_128" file="google_chrome/product_logo_128.png" type="BINDATA" />
<include name="IDR_PRODUCT_LOGO_256" file="google_chrome/product_logo_256.png" type="BINDATA" />
<if expr="is_win">
<!-- External company logo, displayed in the Chrome Cleanup WebUI if
cleanup functionality is powered by an external company. -->
<include name="IDR_CHROME_CLEANUP_PARTNER" file="google_chrome/win/chrome_cleanup_powered_by_company.svg" type="BINDATA" />
</if>
<!-- NOTE: product_logo_*.* files beyond what's listed above are
referenced by installer code; don't remove them unless you know
what you're doing! -->
......
......@@ -14,10 +14,31 @@
<dom-module id="settings-chrome-cleanup-page">
<template>
<style include="settings-shared">
#files-to-remove-container {
/* Use the full available width for file paths to avoid inconsistent
* line breaks when zooming in or out */
width: calc(var(--settings-card-max-width) -
2 * var(--settings-box-row-padding));
}
#files-to-remove-list {
word-break: break-all;
}
#powered-by-container {
align-items: center;
display: flex;
width: 100%;
}
/* Used by |chromeCleanupPoweredByHTML| */
#powered-by-logo {
-webkit-padding-end: 2px;
-webkit-padding-start: 5px;
content: url(chrome://settings/partner-logo.svg);
height: 13px;
}
#show-files-button {
--paper-button-ink-color: white;
/* Left-align the text of the button with the rest of the card's text */
......@@ -85,12 +106,12 @@
</settings-toggle-button>
</div>
<div class="settings-box" hidden="[[!showDetails_]]">
<div class="show-files-container start" hidden="[[showFilesToRemove_]]">
<div class="start" hidden="[[showFilesToRemove_]]">
<paper-button id="show-files-button" on-tap="showFiles_">
$i18n{chromeCleanupLinkShowFiles}
</paper-button>
</div>
<div hidden="[[!showFilesToRemove_]]">
<div id="files-to-remove-container" hidden="[[!showFilesToRemove_]]">
<ul id="files-to-remove-list" class="secondary">
<template is="dom-repeat" items="[[filesToRemove_]]" as="fileName">
<li>[[fileName]]</li>
......@@ -98,6 +119,12 @@
</ul>
</div>
</div>
<div class="settings-box"
hidden="[[!showPoweredBy_(showFilesToRemove_, isPartnerPowered_)]]">
<div id="powered-by-container" class="secondary">
$i18nRaw{chromeCleanupPoweredByHtml}
</div>
</div>
</template>
<script src="chrome_cleanup_page.js"></script>
</dom-module>
......@@ -102,6 +102,15 @@ Polymer({
return /** @type {chrome.settingsPrivate.PrefObject} */ ({});
},
},
/** @private */
isPartnerPowered_: {
type: Boolean,
value: function() {
return loadTimeData.valueExists('cleanupPoweredByPartner') &&
loadTimeData.getBoolean('cleanupPoweredByPartner');
},
},
},
/** @private {?settings.ChromeCleanupProxy} */
......@@ -155,6 +164,14 @@ Polymer({
this.showFilesToRemove_ = true;
},
/**
* @return {boolean}
* @private
*/
showPoweredBy_: function() {
return this.showFilesToRemove_ && this.isPartnerPowered_;
},
/**
* Listener of event 'chrome-cleanup-on-idle'.
* @param {number} idleReason
......
......@@ -186,19 +186,29 @@ ChromeCleanerController* ChromeCleanerController::GetInstance() {
return g_controller;
}
// static
bool ChromeCleanerController::ShouldShowCleanupInSettingsUI() {
// Short-circuit if the instance doesn't exist to avoid creating it during
// navigation to chrome://settings.
if (!g_controller)
return false;
State state = GetInstance()->state();
IdleReason reason = GetInstance()->idle_reason();
return state == State::kInfected || state == State::kCleaning ||
state == State::kRebootRequired ||
(state == State::kIdle && (reason == IdleReason::kCleaningFailed ||
reason == IdleReason::kConnectionLost));
return state_ == State::kInfected || state_ == State::kCleaning ||
state_ == State::kRebootRequired ||
(state_ == State::kIdle &&
(idle_reason_ == IdleReason::kCleaningFailed ||
idle_reason_ == IdleReason::kConnectionLost));
}
bool ChromeCleanerController::IsPoweredByPartner() {
// |reporter_invocation_| is not expected to hold a value for the entire
// lifecycle of the ChromeCleanerController instance. To be consistent, use
// a cached return value if the |reporter_invocation_| has been cleaned up.
if (!reporter_invocation_) {
return powered_by_partner_;
}
const std::string& reporter_engine =
reporter_invocation_->command_line.GetSwitchValueASCII(
chrome_cleaner::kEngineSwitch);
// Currently, only engine=2 corresponds to a partner-powered engine. This
// condition should be updated if other partner-powered engines are added.
powered_by_partner_ = !reporter_engine.empty() && reporter_engine == "2";
return powered_by_partner_;
}
void ChromeCleanerController::SetLogsEnabled(bool logs_enabled) {
......
......@@ -132,8 +132,10 @@ class ChromeCleanerController {
static ChromeCleanerController* GetInstance();
// Returns whether the Cleanup card in settings should be displayed.
// Static to prevent instantiation of the global controller object.
static bool ShouldShowCleanupInSettingsUI();
bool ShouldShowCleanupInSettingsUI();
// Returns whether Cleanup is powered by a partner company.
bool IsPoweredByPartner();
State state() const { return state_; }
IdleReason idle_reason() const { return idle_reason_; }
......@@ -244,6 +246,8 @@ class ChromeCleanerController {
// The logs permission checkboxes in the Chrome Cleaner dialog and webui page
// are opt out.
bool logs_enabled_ = true;
// Whether Cleanup is powered by an external partner.
bool powered_by_partner_ = false;
IdleReason idle_reason_ = IdleReason::kInitial;
std::unique_ptr<SwReporterInvocation> reporter_invocation_;
std::unique_ptr<std::set<base::FilePath>> files_to_delete_;
......
......@@ -808,6 +808,11 @@ void AddChromeCleanupStrings(content::WebUIDataSource* html_source) {
g_browser_process->GetApplicationLocale())
.spec();
html_source->AddString("chromeCleanupLearnMoreUrl", cleanup_learn_more_url);
base::string16 powered_by_html = l10n_util::GetStringFUTF16(
IDS_CHROME_CLEANUP_WEBUI_FOOTER_POWERED_BY,
L"<span id='powered-by-logo'></span><span>®</span>");
html_source->AddString("chromeCleanupPoweredByHtml", powered_by_html);
}
#endif // defined(OS_WIN)
......
......@@ -50,6 +50,9 @@
#include "chrome/browser/safe_browsing/chrome_cleaner/chrome_cleaner_controller_win.h"
#include "chrome/browser/safe_browsing/chrome_cleaner/srt_field_trial_win.h"
#include "chrome/browser/ui/webui/settings/chrome_cleanup_handler.h"
#if defined(GOOGLE_CHROME_BUILD)
#include "chrome/grit/chrome_unscaled_resources.h"
#endif
#endif // defined(OS_WIN)
#if defined(OS_WIN) || defined(OS_CHROMEOS)
......@@ -110,6 +113,10 @@ void MdSettingsUI::RegisterProfilePrefs(
MdSettingsUI::MdSettingsUI(content::WebUI* web_ui, const GURL& url)
: content::WebUIController(web_ui),
WebContentsObserver(web_ui->GetWebContents()) {
#if BUILDFLAG(USE_VULCANIZE)
std::unordered_set<std::string> exclude_from_gzip;
#endif
Profile* profile = Profile::FromWebUI(web_ui);
AddSettingsPageUIHandler(base::MakeUnique<AppearanceHandler>(web_ui));
......@@ -185,8 +192,21 @@ MdSettingsUI::MdSettingsUI(content::WebUI* web_ui, const GURL& url)
if (base::FeatureList::IsEnabled(safe_browsing::kInBrowserCleanerUIFeature)) {
AddSettingsPageUIHandler(base::MakeUnique<ChromeCleanupHandler>(profile));
if (safe_browsing::ChromeCleanerController::ShouldShowCleanupInSettingsUI())
safe_browsing::ChromeCleanerController* cleaner_controller =
safe_browsing::ChromeCleanerController::GetInstance();
if (cleaner_controller->ShouldShowCleanupInSettingsUI())
html_source->AddBoolean("chromeCleanupEnabled", true);
#if defined(GOOGLE_CHROME_BUILD)
if (cleaner_controller->IsPoweredByPartner())
html_source->AddBoolean("cleanupPoweredByPartner", true);
html_source->AddResourcePath("partner-logo.svg",
IDR_CHROME_CLEANUP_PARTNER);
#if BUILDFLAG(USE_VULCANIZE)
exclude_from_gzip.insert("partner-logo.svg");
#endif
#endif // defined(GOOGLE_CHROME_BUILD)
}
#endif // defined(OS_WIN)
......@@ -244,7 +264,7 @@ MdSettingsUI::MdSettingsUI(content::WebUI* web_ui, const GURL& url)
html_source->AddResourcePath("lazy_load.html",
IDR_MD_SETTINGS_LAZY_LOAD_VULCANIZED_HTML);
html_source->SetDefaultResource(IDR_MD_SETTINGS_VULCANIZED_HTML);
html_source->UseGzip(std::unordered_set<std::string>());
html_source->UseGzip(exclude_from_gzip);
#else
// Add all settings resources.
for (size_t i = 0; i < kSettingsResourcesSize; ++i) {
......
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