Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: chrome/browser/resources/settings/search_page/search_page.js

Issue 2507363002: MD Settings: Add Hotword (OK Google) section to search_page (Closed)
Patch Set: Nit Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * 'settings-search-page' is the settings page containing search settings. 7 * 'settings-search-page' is the settings page containing search settings.
8 */ 8 */
9 Polymer({ 9 Polymer({
10 is: 'settings-search-page', 10 is: 'settings-search-page',
11 11
12 behaviors: [I18nBehavior],
13
12 properties: { 14 properties: {
13 prefs: Object, 15 prefs: Object,
14 16
15 /** 17 /**
16 * List of default search engines available. 18 * List of default search engines available.
17 * @private {!Array<!SearchEngine>} 19 * @private {!Array<!SearchEngine>}
18 */ 20 */
19 searchEngines_: { 21 searchEngines_: {
20 type: Array, 22 type: Array,
21 value: function() { return []; } 23 value: function() {
24 return [];
25 }
22 }, 26 },
27
28 /** @private {!SearchPageHotwordInfo|undefined} */
29 hotwordInfo_: Object,
30
31 /**
32 * This is a local PrefObject used to reflect the enabled state of hotword
33 * search. It is not tied directly to a pref. (There are two prefs
34 * associated with state and they do not map directly to whether or not
35 * hotword search is actually enabled).
36 * @private {!chrome.settingsPrivate.PrefObject|undefined}
37 */
38 hotwordSearchEnablePref_: Object,
23 }, 39 },
24 40
25 /** @private {?settings.SearchEnginesBrowserProxy} */ 41 /** @private {?settings.SearchEnginesBrowserProxy} */
26 browserProxy_: null, 42 browserProxy_: null,
27 43
28 /** @override */ 44 /** @override */
29 created: function() { 45 created: function() {
30 this.browserProxy_ = settings.SearchEnginesBrowserProxyImpl.getInstance(); 46 this.browserProxy_ = settings.SearchEnginesBrowserProxyImpl.getInstance();
31 }, 47 },
32 48
33 /** @override */ 49 /** @override */
34 ready: function() { 50 ready: function() {
51 // Omnibox search engine
35 var updateSearchEngines = function(searchEngines) { 52 var updateSearchEngines = function(searchEngines) {
36 this.set('searchEngines_', searchEngines.defaults); 53 this.set('searchEngines_', searchEngines.defaults);
37 }.bind(this); 54 }.bind(this);
38 this.browserProxy_.getSearchEnginesList().then(updateSearchEngines); 55 this.browserProxy_.getSearchEnginesList().then(updateSearchEngines);
39 cr.addWebUIListener('search-engines-changed', updateSearchEngines); 56 cr.addWebUIListener('search-engines-changed', updateSearchEngines);
57
58 // Hotword (OK Google)
59 cr.addWebUIListener(
60 'hotword-info-update', this.hotwordInfoUpdate_.bind(this));
61 this.browserProxy_.getHotwordInfo().then(function(hotwordInfo) {
62 this.hotwordInfoUpdate_(hotwordInfo);
63 }.bind(this));
40 }, 64 },
41 65
42 /** @private */ 66 /** @private */
43 onChange_: function() { 67 onChange_: function() {
44 var select = /** @type {!HTMLSelectElement} */ (this.$$('select')); 68 var select = /** @type {!HTMLSelectElement} */ (this.$$('select'));
45 var searchEngine = this.searchEngines_[select.selectedIndex]; 69 var searchEngine = this.searchEngines_[select.selectedIndex];
46 this.browserProxy_.setDefaultSearchEngine(searchEngine.modelIndex); 70 this.browserProxy_.setDefaultSearchEngine(searchEngine.modelIndex);
47 }, 71 },
48 72
49 /** @private */ 73 /** @private */
50 onDisableExtension_: function() { 74 onDisableExtension_: function() {
51 this.fire('refresh-pref', 'default_search_provider.enabled'); 75 this.fire('refresh-pref', 'default_search_provider.enabled');
52 }, 76 },
53 77
54 /** @private */ 78 /** @private */
55 onManageSearchEnginesTap_: function() { 79 onManageSearchEnginesTap_: function() {
56 settings.navigateTo(settings.Route.SEARCH_ENGINES); 80 settings.navigateTo(settings.Route.SEARCH_ENGINES);
57 }, 81 },
82
83 /**
84 * @param {Event} event
85 * @private
86 */
87 onHotwordSearchEnableChange_: function(event) {
88 // Do not set the pref directly, allow Chrome to run the setup app instead.
89 this.browserProxy_.setHotwordSearchEnabled(
90 !!this.hotwordSearchEnablePref_.value);
91 },
92
93 /**
94 * @param {!SearchPageHotwordInfo} hotwordInfo
95 * @private
96 */
97 hotwordInfoUpdate_: function(hotwordInfo) {
98 this.hotwordInfo_ = hotwordInfo;
99 this.hotwordSearchEnablePref_ = {
100 key: 'unused', // required for PrefObject
101 type: chrome.settingsPrivate.PrefType.BOOLEAN,
102 value: this.hotwordInfo_.enabled,
103 };
104 },
105
106 /**
107 * @return {string}
108 * @private
109 */
110 getHotwordSearchEnableSubLabel_: function() {
111 return this.i18n(
112 this.hotwordInfo_.alwaysOn ? 'searchOkGoogleSubtextAlwaysOn' :
113 'searchOkGoogleSubtextNoHardware');
114 },
115
116 /**
117 * @return {boolean}
118 * @private
119 */
120 getShowHotwordSearchRetrain_: function() {
121 return this.hotwordInfo_.enabled && this.hotwordInfo_.alwaysOn;
122 },
123
124 /**
125 * @return {boolean} True if the pref is enabled but hotword is not.
126 * @private
127 */
128 getShowHotwordError_: function() {
129 return this.hotwordInfo_.enabled && !!this.hotwordInfo_.errorMessage;
130 },
131
132 /** @private */
133 onRetrainTap_: function() {
134 // Re-enable hotword search enable; this will trigger the retrain UI.
135 this.browserProxy_.setHotwordSearchEnabled(this.hotwordInfo_.enabled);
136 },
137
138 /** @private */
139 onManageAudioHistoryTap_: function() {
140 window.open(loadTimeData.getString('manageAudioHistoryUrl'));
141 },
142
143 /**
144 * @param {Event} event
145 * @private
146 */
147 doNothing_: function(event) {
148 event.stopPropagation();
149 }
58 }); 150 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698