Commit 96d45c70 authored by kcarattini's avatar kcarattini Committed by Commit bot

Add error indicators to always-on andno-dsp hotword checkboxes.

Also shows the indicator regardless of pref status.
(For always-on, the opt-in process requires that there
are no errors, so if something goes wrong it is better that the user know why.)

Screenshot in attached bug.

BUG=390086

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

Cr-Commit-Position: refs/heads/master@{#302710}
parent c687507f
...@@ -168,6 +168,8 @@ ...@@ -168,6 +168,8 @@
i18n-content="learnMore" i18n-content="learnMore"
i18n-values="href:hotwordLearnMoreURL"> i18n-values="href:hotwordLearnMoreURL">
</a> </a>
<span id="hotword-always-on-search-setting-indicator"
pref="hotword.always_on_search_enabled" dialog-pref></span>
<div> <div>
<span class="hotword-description" <span class="hotword-description"
i18n-content="hotwordAlwaysOnDesc"> i18n-content="hotwordAlwaysOnDesc">
...@@ -186,6 +188,8 @@ ...@@ -186,6 +188,8 @@
i18n-content="learnMore" i18n-content="learnMore"
i18n-values="href:hotwordLearnMoreURL"> i18n-values="href:hotwordLearnMoreURL">
</a> </a>
<span id="hotword-no-dsp-search-setting-indicator"
pref="hotword.search_enabled_2" dialog-pref></span>
<div> <div>
<span class="hotword-description" <span class="hotword-description"
i18n-content="hotwordNoDSPDesc"> i18n-content="hotwordNoDSPDesc">
......
...@@ -224,8 +224,12 @@ cr.define('options', function() { ...@@ -224,8 +224,12 @@ cr.define('options', function() {
['Options_Homepage_ShowSettings']); ['Options_Homepage_ShowSettings']);
}; };
var hotwordIndicator = $('hotword-search-setting-indicator'); HotwordSearchSettingIndicator.decorate(
HotwordSearchSettingIndicator.decorate(hotwordIndicator); $('hotword-search-setting-indicator'));
HotwordSearchSettingIndicator.decorate(
$('hotword-no-dsp-search-setting-indicator'));
HotwordSearchSettingIndicator.decorate(
$('hotword-always-on-search-setting-indicator'));
chrome.send('requestHotwordAvailable'); chrome.send('requestHotwordAvailable');
if ($('set-wallpaper')) { if ($('set-wallpaper')) {
...@@ -1127,34 +1131,56 @@ cr.define('options', function() { ...@@ -1127,34 +1131,56 @@ cr.define('options', function() {
/** /**
* Activates the Hotword section from the System settings page. * Activates the Hotword section from the System settings page.
* @param {boolean} opt_enabled Current preference state for hotwording. * @param {string} sectionId The id of the section to display.
* @param {string} opt_error The error message to display. * @param {string} indicatorId The id of the indicator to display.
* @param {string=} opt_error The error message to display.
* @private * @private
*/ */
showHotwordSection_: function(opt_enabled, opt_error) { showHotwordCheckboxAndIndicator_: function(sectionId, indicatorId,
$('hotword-search').hidden = false; opt_error) {
$('hotword-search-setting-indicator').setError(opt_error); $(sectionId).hidden = false;
if (opt_enabled && opt_error) $(indicatorId).setError(opt_error);
$('hotword-search-setting-indicator').updateBasedOnError(); if (opt_error)
$(indicatorId).updateBasedOnError();
},
/**
* Activates the Hotword section from the System settings page.
* @param {string=} opt_error The error message to display.
* @private
*/
showHotwordSection_: function(opt_error) {
this.showHotwordCheckboxAndIndicator_(
'hotword-search',
'hotword-search-setting-indicator',
opt_error);
}, },
/** /**
* Activates the Audio History and Always-On Hotword sections from the * Activates the Audio History and Always-On Hotword sections from the
* System settings page. * System settings page.
* @param {string=} opt_error The error message to display.
* @private * @private
*/ */
showHotwordAlwaysOnSection_: function() { showHotwordAlwaysOnSection_: function(opt_error) {
$('hotword-always-on-search').hidden = false; this.showHotwordCheckboxAndIndicator_(
'hotword-always-on-search',
'hotword-always-on-search-setting-indicator',
opt_error);
$('audio-logging').hidden = false; $('audio-logging').hidden = false;
}, },
/** /**
* Activates the Hotword section on devices with no DSP * Activates the Hotword section on devices with no DSP
* from the System settings page. * from the System settings page.
* @param {string=} opt_error The error message to display.
* @private * @private
*/ */
showHotwordNoDSPSection_: function() { showHotwordNoDspSection_: function(opt_error) {
$('hotword-no-dsp-search').hidden = false; this.showHotwordCheckboxAndIndicator_(
'hotword-no-dsp-search',
'hotword-no-dsp-search-setting-indicator',
opt_error);
}, },
/** /**
...@@ -2054,7 +2080,7 @@ cr.define('options', function() { ...@@ -2054,7 +2080,7 @@ cr.define('options', function() {
'showCreateProfileSuccess', 'showCreateProfileSuccess',
'showCreateProfileWarning', 'showCreateProfileWarning',
'showHotwordAlwaysOnSection', 'showHotwordAlwaysOnSection',
'showHotwordNoDSPSection', 'showHotwordNoDspSection',
'showHotwordSection', 'showHotwordSection',
'showMouseControls', 'showMouseControls',
'showSupervisedUserImportError', 'showSupervisedUserImportError',
......
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
/* Hotword extension-specific controlled setting indicator and bubble. */ /* Hotword extension-specific controlled setting indicator and bubble. */
#hotword-search-setting-indicator > div { #hotword-search-setting-indicator > div,
background: url('chrome://theme/IDR_WARNING') left top no-repeat; #hotword-always-on-search-setting-indicator > div,
#hotword-no-dsp-search-setting-indicator > div {
background: url(chrome://theme/IDR_WARNING) left top no-repeat;
background-size: 18px; background-size: 18px;
} }
...@@ -1621,25 +1621,26 @@ void BrowserOptionsHandler::HandleRequestHotwordAvailable( ...@@ -1621,25 +1621,26 @@ void BrowserOptionsHandler::HandleRequestHotwordAvailable(
const base::ListValue* args) { const base::ListValue* args) {
Profile* profile = Profile::FromWebUI(web_ui()); Profile* profile = Profile::FromWebUI(web_ui());
std::string group = base::FieldTrialList::FindFullName("VoiceTrigger"); std::string group = base::FieldTrialList::FindFullName("VoiceTrigger");
base::FundamentalValue enabled(
profile->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled));
if (group != "" && group != "Disabled" && if (group != "" && group != "Disabled" &&
HotwordServiceFactory::IsHotwordAllowed(profile)) { HotwordServiceFactory::IsHotwordAllowed(profile)) {
// Update the current error value. // Update the current error value.
HotwordServiceFactory::IsServiceAvailable(profile); HotwordServiceFactory::IsServiceAvailable(profile);
int error = HotwordServiceFactory::GetCurrentError(profile); int error = HotwordServiceFactory::GetCurrentError(profile);
std::string function_name;
if (CommandLine::ForCurrentProcess()->HasSwitch( if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableExperimentalHotwording)) { switches::kEnableExperimentalHotwording)) {
if (HotwordServiceFactory::IsHotwordHardwareAvailable()) { if (HotwordServiceFactory::IsHotwordHardwareAvailable()) {
web_ui()->CallJavascriptFunction( function_name = "BrowserOptions.showHotwordAlwaysOnSection";
"BrowserOptions.showHotwordAlwaysOnSection");
} else { } else {
web_ui()->CallJavascriptFunction( function_name = "BrowserOptions.showHotwordNoDspSection";
"BrowserOptions.showHotwordNoDSPSection");
} }
} else if (!error) { } else {
web_ui()->CallJavascriptFunction("BrowserOptions.showHotwordSection", function_name = "BrowserOptions.showHotwordSection";
enabled); }
if (!error) {
web_ui()->CallJavascriptFunction(function_name);
} else { } else {
base::string16 hotword_help_url = base::string16 hotword_help_url =
base::ASCIIToUTF16(chrome::kHotwordLearnMoreURL); base::ASCIIToUTF16(chrome::kHotwordLearnMoreURL);
...@@ -1648,8 +1649,7 @@ void BrowserOptionsHandler::HandleRequestHotwordAvailable( ...@@ -1648,8 +1649,7 @@ void BrowserOptionsHandler::HandleRequestHotwordAvailable(
error_message = base::StringValue( error_message = base::StringValue(
l10n_util::GetStringFUTF16(error, hotword_help_url)); l10n_util::GetStringFUTF16(error, hotword_help_url));
} }
web_ui()->CallJavascriptFunction("BrowserOptions.showHotwordSection", web_ui()->CallJavascriptFunction(function_name, error_message);
enabled, error_message);
} }
} }
} }
......
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