Commit 3109d3ea authored by dbeam's avatar dbeam Committed by Commit bot

Add mac-only "Set Up Automatic Updates..." button to the new about page.

A mac-only "Set Up Automatic Updates for All Users" button existed in
the old crome://help page, but was not ported over to the
chrome://md-settings/help page. This CL aims to port that button over.

By Scott Chen <scottchen@chromium.org> (http://crrev.com/2538013002)

BUG=649187
TBR=dpapad@chromium.org (LG'd on other CL)
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:closure_compilation

Review-Url: https://codereview.chromium.org/2583743002
Cr-Commit-Position: refs/heads/master@{#439368}
parent 1b4d4c75
......@@ -109,6 +109,14 @@
<message name="IDS_SETTINGS_ABOUT_UPGRADE_CHECK_STARTED" desc="Status label: About to start checking for updates">
Checking for updates
</message>
<if expr="is_macosx">
<message name="IDS_ABOUT_CHROME_AUTOUPDATE_ALL" desc="The 'Automatically update Chrome for all users.' button in the About window. Mac-only.">
Automatically update Chrome for all users.
</message>
<message name="IDS_ABOUT_CHROME_AUTOUPDATE_ALL_IS_ON" desc="The text in About Page to indicate automatic update is turned on. Mac-only.">
Automatic updates are turned on.
</message>
</if>
<!-- Accessibility Page -->
<message name="IDS_SETTINGS_ACCESSIBILITY" desc="Name of the settings page which displays accessibility preferences.">
......
......@@ -166,6 +166,10 @@ enum BrandFileType {
- (BOOL)needsPromotion;
- (BOOL)wantsPromotion;
// -isAutoupdateEnabledForAllUsers indicates whether or not autoupdate is
// turned on for all users.
- (BOOL)isAutoupdateEnabledForAllUsers;
// Promotes the Keystone ticket into the system store. System Keystone will
// be installed if necessary. If synchronous is NO, the promotion may occur
// in the background. synchronous should be YES for promotion during
......
......@@ -837,6 +837,10 @@ NSString* const kVersionKey = @"KSVersion";
return (statfsBuf.f_flags & MNT_RDONLY) != 0;
}
- (BOOL)isAutoupdateEnabledForAllUsers {
return [self isSystemKeystone] && ![self isUserTicket];
}
- (BOOL)needsPromotion {
// Don't promote when on a read-only filesystem.
if ([self isOnReadOnlyFilesystem]) {
......
......@@ -22,6 +22,10 @@
<link rel="import" href="/settings_page/settings_subpage.html">
</if>
<if expr="_google_chrome and is_macosx">
<link rel="import" href="chrome://resources/polymer/v1_0/paper-icon-button/paper-icon-button-light.html">
</if>
<dom-module id="settings-about-page">
<template>
<style include="settings-shared settings-page-styles">
......@@ -69,6 +73,12 @@
#regulatoryInfo img {
width: 330px;
}
<if expr="_google_chrome and is_macosx">
#promoteUpdater[disabled] {
@apply(--settings-secondary);
}
</if>
</style>
<div>
<settings-section page-title="$i18n{aboutPageTitle}" section="about">
......@@ -128,6 +138,27 @@
</if>
</span>
</div>
<if expr="_google_chrome and is_macosx">
<template is="dom-if" if="[[!promoteUpdaterStatus_.hidden]]">
<div id="promoteUpdater" class="settings-box"
disabled$="[[promoteUpdaterStatus_.disabled]]"
actionable$="[[promoteUpdaterStatus_.actionable]]"
on-tap="onPromoteUpdaterTap_">
<div class="start">
[[promoteUpdaterStatus_.text]]
<a href="https://support.google.com/chrome/answer/95414"
target="_blank" id="updaterLearnMore"
on-tap="onLearnMoreTap_">
$i18n{learnMore}
</a>
</div>
<button class="subpage-arrow" is="paper-icon-button-light"
disabled="[[promoteUpdaterStatus_.disabled]]"
hidden="[[!promoteUpdaterStatus_.actionable]]">
</button>
</div>
</template>
</if>
<div id="help" class="settings-box" on-tap="onHelpTap_" actionable>
<div class="start">$i18n{aboutGetHelpUsingChrome}</div>
<button class="icon-external" is="paper-icon-button-light">
......
......@@ -35,6 +35,11 @@ Polymer({
regulatoryInfo_: Object,
</if>
<if expr="_google_chrome and is_macosx">
/** @private {!PromoteUpdaterStatus} */
promoteUpdaterStatus_: Object,
</if>
/** @private {!{obsolete: boolean, endOfLine: boolean}} */
obsoleteSystemInfo_: {
type: Object,
......@@ -130,6 +135,11 @@ Polymer({
this.addWebUIListener(
'update-status-changed',
this.onUpdateStatusChanged_.bind(this));
<if expr="_google_chrome and is_macosx">
this.addWebUIListener(
'promotion-state-changed',
this.onPromoteUpdaterStatusChanged_.bind(this));
</if>
this.aboutBrowserProxy_.refreshUpdateStatus();
},
......@@ -145,6 +155,38 @@ Polymer({
this.currentUpdateStatusEvent_ = event;
},
<if expr="_google_chrome and is_macosx">
/**
* @param {!PromoteUpdaterStatus} status
* @private
*/
onPromoteUpdaterStatusChanged_: function(status) {
this.promoteUpdaterStatus_ = status;
},
/**
* If #promoteUpdater isn't disabled, trigger update promotion.
* @private
*/
onPromoteUpdaterTap_: function() {
// This is necessary because #promoteUpdater is not a button, so by default
// disable doesn't do anything.
if (this.promoteUpdaterStatus_.disabled)
return;
this.aboutBrowserProxy_.promoteUpdater();
},
/**
* @param {!Event} event
* @private
*/
onLearnMoreTap_: function(event) {
// Stop the propagation of events, so that clicking on links inside
// actionable items won't trigger action.
event.stopPropagation();
},
</if>
/** @private */
onHelpTap_: function() {
this.aboutBrowserProxy_.openHelpPage();
......
......@@ -60,6 +60,18 @@ var UpdateStatus = {
DISABLED_BY_ADMIN: 'disabled_by_admin',
};
<if expr="_google_chrome and is_macosx">
/**
* @typedef {{
* hidden: boolean,
* disabled: boolean,
* actionable: boolean,
* text: (string|undefined)
* }}
*/
var PromoteUpdaterStatus;
</if>
/**
* @typedef {{
* status: !UpdateStatus,
......@@ -148,6 +160,13 @@ cr.define('settings', function() {
/** @return {!Promise<?RegulatoryInfo>} */
getRegulatoryInfo: function() {},
</if>
<if expr="_google_chrome and is_macosx">
/**
* Triggers setting up auto-updates for all users.
*/
promoteUpdater: function() {},
</if>
};
/**
......@@ -168,6 +187,13 @@ cr.define('settings', function() {
chrome.send('refreshUpdateStatus');
},
<if expr="_google_chrome and is_macosx">
/** @override */
promoteUpdater: function() {
chrome.send('promoteUpdater');
},
</if>
/** @override */
openHelpPage: function() {
chrome.send('openHelpPage');
......
......@@ -690,6 +690,7 @@ void HelpHandler::SetPromotionState(VersionUpdater::PromotionState state) {
std::string state_str;
switch (state) {
case VersionUpdater::PROMOTE_HIDDEN:
case VersionUpdater::PROMOTED:
state_str = "hidden";
break;
case VersionUpdater::PROMOTE_ENABLED:
......
......@@ -39,7 +39,8 @@ class VersionUpdater {
enum PromotionState {
PROMOTE_HIDDEN,
PROMOTE_ENABLED,
PROMOTE_DISABLED
PROMOTE_DISABLED,
PROMOTED,
};
// TODO(jhawkins): Use a delegate interface instead of multiple callback
......
......@@ -237,11 +237,20 @@ void VersionUpdaterMac::UpdateStatus(NSDictionary* dictionary) {
if (!status_callback_.is_null())
status_callback_.Run(status, 0, message);
PromotionState promotion_state;
if (!promote_callback_.is_null()) {
PromotionState promotion_state = PROMOTE_HIDDEN;
if (show_promote_button_)
promotion_state = enable_promote_button ? PROMOTE_ENABLED
: PROMOTE_DISABLED;
KeystoneGlue* keystone_glue = [KeystoneGlue defaultKeystoneGlue];
if (keystone_glue && [keystone_glue isAutoupdateEnabledForAllUsers]) {
promotion_state = PROMOTED;
} else {
promotion_state = PROMOTE_HIDDEN;
if (show_promote_button_) {
promotion_state = enable_promote_button ? PROMOTE_ENABLED
: PROMOTE_DISABLED;
}
}
promote_callback_.Run(promotion_state);
}
}
......
......@@ -592,22 +592,31 @@ void AboutHandler::SetUpdateStatus(VersionUpdater::Status status,
#if defined(OS_MACOSX)
void AboutHandler::SetPromotionState(VersionUpdater::PromotionState state) {
std::string state_str;
switch (state) {
case VersionUpdater::PROMOTE_HIDDEN:
state_str = "hidden";
break;
case VersionUpdater::PROMOTE_ENABLED:
state_str = "enabled";
break;
case VersionUpdater::PROMOTE_DISABLED:
state_str = "disabled";
break;
}
// Worth noting: PROMOTE_DISABLED indicates that promotion is possible,
// there's just something else going on right now (e.g. checking for update).
bool hidden = state == VersionUpdater::PROMOTE_HIDDEN;
bool disabled = state == VersionUpdater::PROMOTE_HIDDEN ||
state == VersionUpdater::PROMOTE_DISABLED ||
state == VersionUpdater::PROMOTED;
bool actionable = state == VersionUpdater::PROMOTE_DISABLED ||
state == VersionUpdater::PROMOTE_ENABLED;
base::string16 text = base::string16();
if (actionable)
text = l10n_util::GetStringUTF16(IDS_ABOUT_CHROME_AUTOUPDATE_ALL);
else if (state == VersionUpdater::PROMOTED)
text = l10n_util::GetStringUTF16(IDS_ABOUT_CHROME_AUTOUPDATE_ALL_IS_ON);
base::DictionaryValue promo_state;
promo_state.SetBoolean("hidden", hidden);
promo_state.SetBoolean("disabled", disabled);
promo_state.SetBoolean("actionable", actionable);
if (!text.empty())
promo_state.SetString("text", text);
CallJavascriptFunction("cr.webUIListenerCallback",
base::StringValue("promotion-state-changed"),
base::StringValue(state_str));
promo_state);
}
#endif // defined(OS_MACOSX)
......@@ -645,7 +654,6 @@ void AboutHandler::OnRegulatoryLabelTextRead(
ResolveJavascriptCallback(base::StringValue(callback_id), *regulatory_info);
}
#endif // defined(OS_CHROMEOS)
} // namespace settings
......@@ -24,6 +24,9 @@ cr.define('settings_about_page', function() {
'setChannel');
}
if (cr.isMac)
methodNames.push('promoteUpdater');
settings.TestBrowserProxy.call(this, methodNames);
/** @private {!UpdateStatus} */
......@@ -82,6 +85,13 @@ cr.define('settings_about_page', function() {
},
};
if (cr.isMac) {
/** @override */
TestAboutPageBrowserProxy.prototype.promoteUpdater = function() {
this.methodCalled('promoteUpdater');
};
}
if (cr.isChromeOS) {
/** @param {!VersionInfo} */
TestAboutPageBrowserProxy.prototype.setVersionInfo = function(versionInfo) {
......@@ -557,6 +567,107 @@ cr.define('settings_about_page', function() {
MockInteractions.tap(page.$.reportIssue);
return browserProxy.whenCalled('openFeedbackDialog');
});
if (cr.isMac) {
/**
* A list of possible scenarios for the promoteUpdater.
* @enum {!PromoteUpdaterStatus}
*/
var PromoStatusScenarios = {
CANT_PROMOTE: {
hidden: true,
disabled: true,
actionable: false,
},
CAN_PROMOTE: {
hidden: false,
disabled: false,
actionable: true,
},
IN_BETWEEN: {
hidden: false,
disabled: true,
actionable: true,
},
PROMOTED: {
hidden: false,
disabled: true,
actionable: false,
},
};
/**
* @param {!PromoteUpdaterStatus} status
*/
function firePromoteUpdaterStatusChanged(status) {
cr.webUIListenerCallback('promotion-state-changed', status);
}
/**
* Tests that the button's states are wired up to the status correctly.
*/
test('PromoteUpdaterButtonCorrectStates', function() {
var item = page.$$('#promoteUpdater');
var arrow = page.$$('#promoteUpdater button');
assertFalse(!!item);
assertFalse(!!arrow);
firePromoteUpdaterStatusChanged(PromoStatusScenarios.CANT_PROMOTE);
Polymer.dom.flush();
item = page.$$('#promoteUpdater');
arrow = page.$$('#promoteUpdater button');
assertFalse(!!item);
assertFalse(!!arrow);
firePromoteUpdaterStatusChanged(PromoStatusScenarios.CAN_PROMOTE);
Polymer.dom.flush();
item = page.$$('#promoteUpdater');
assertTrue(!!item);
assertFalse(item.hasAttribute('disabled'));
assertTrue(item.hasAttribute('actionable'));
arrow = page.$$('#promoteUpdater button');
assertTrue(!!arrow);
assertFalse(arrow.hidden);
assertFalse(arrow.hasAttribute('disabled'));
firePromoteUpdaterStatusChanged(PromoStatusScenarios.IN_BETWEEN);
Polymer.dom.flush();
item = page.$$('#promoteUpdater');
assertTrue(!!item);
assertTrue(item.hasAttribute('disabled'));
assertTrue(item.hasAttribute('actionable'));
arrow = page.$$('#promoteUpdater button');
assertTrue(!!arrow);
assertFalse(arrow.hidden);
assertTrue(arrow.hasAttribute('disabled'));
firePromoteUpdaterStatusChanged(PromoStatusScenarios.PROMOTED);
Polymer.dom.flush();
item = page.$$('#promoteUpdater');
assertTrue(!!item);
assertTrue(item.hasAttribute('disabled'));
assertFalse(item.hasAttribute('actionable'));
arrow = page.$$('#promoteUpdater button');
assertTrue(!!arrow);
assertTrue(arrow.hidden);
assertTrue(arrow.hasAttribute('disabled'));
});
test('PromoteUpdaterButtonWorksWhenEnabled', function() {
firePromoteUpdaterStatusChanged(PromoStatusScenarios.CAN_PROMOTE);
Polymer.dom.flush();
var item = page.$$('#promoteUpdater');
assertTrue(!!item);
MockInteractions.tap(item);
return browserProxy.whenCalled('promoteUpdater');
});
}
});
}
......
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