| OLD | NEW |
| 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 /** | 15 /** |
| 14 * List of default search engines available. | 16 * List of default search engines available. |
| 15 * @private {!Array<!SearchEngine>} | 17 * @private {!Array<!SearchEngine>} |
| 16 */ | 18 */ |
| 17 searchEngines_: { | 19 searchEngines_: { |
| 18 type: Array, | 20 type: Array, |
| 19 value: function() { return []; } | 21 value: function() { |
| 22 return []; |
| 23 } |
| 20 }, | 24 }, |
| 21 | 25 |
| 26 /** @private {!SearchPageHotwordInfo|undefined} */ |
| 27 hotwordInfo_: Object, |
| 28 |
| 29 /** |
| 30 * This is a local PrefObject used to reflect the enabled state of hotword |
| 31 * search. It is not tied directly to a pref. (There are two prefs |
| 32 * associated with state and they do not map directly to whether or not |
| 33 * hotword search is actually enabled). |
| 34 * @private {!chrome.settingsPrivate.PrefObject|undefined} |
| 35 */ |
| 36 hotwordSearchEnablePref_: Object, |
| 37 |
| 22 /** @private {!settings.SearchEnginesBrowserProxy} */ | 38 /** @private {!settings.SearchEnginesBrowserProxy} */ |
| 23 browserProxy_: Object, | 39 browserProxy_: Object, |
| 24 }, | 40 }, |
| 25 | 41 |
| 26 /** @override */ | 42 /** @override */ |
| 27 created: function() { | 43 created: function() { |
| 28 this.browserProxy_ = settings.SearchEnginesBrowserProxyImpl.getInstance(); | 44 this.browserProxy_ = settings.SearchEnginesBrowserProxyImpl.getInstance(); |
| 29 }, | 45 }, |
| 30 | 46 |
| 31 /** @override */ | 47 /** @override */ |
| 32 ready: function() { | 48 ready: function() { |
| 49 // Omnibox search engine |
| 33 var updateSearchEngines = function(searchEngines) { | 50 var updateSearchEngines = function(searchEngines) { |
| 34 this.set('searchEngines_', searchEngines.defaults); | 51 this.set('searchEngines_', searchEngines.defaults); |
| 35 }.bind(this); | 52 }.bind(this); |
| 36 this.browserProxy_.getSearchEnginesList().then(updateSearchEngines); | 53 this.browserProxy_.getSearchEnginesList().then(updateSearchEngines); |
| 37 cr.addWebUIListener('search-engines-changed', updateSearchEngines); | 54 cr.addWebUIListener('search-engines-changed', updateSearchEngines); |
| 55 |
| 56 // Hotword (OK Google) |
| 57 cr.addWebUIListener( |
| 58 'hotword-info-update', this.hotwordInfoUpdate_.bind(this)); |
| 59 this.browserProxy_.getHotwordInfo().then(function(hotwordInfo) { |
| 60 this.hotwordInfoUpdate_(hotwordInfo); |
| 61 }.bind(this)); |
| 38 }, | 62 }, |
| 39 | 63 |
| 40 /** @private */ | 64 /** @private */ |
| 41 onManageSearchEnginesTap_: function() { | 65 onManageSearchEnginesTap_: function() { |
| 42 settings.navigateTo(settings.Route.SEARCH_ENGINES); | 66 settings.navigateTo(settings.Route.SEARCH_ENGINES); |
| 43 }, | 67 }, |
| 44 | 68 |
| 45 /** @private */ | 69 /** @private */ |
| 46 onChange_: function(e) { | 70 onChange_: function(e) { |
| 47 var select = /** @type {!HTMLSelectElement} */ (this.$$('select')); | 71 var select = /** @type {!HTMLSelectElement} */ (this.$$('select')); |
| 48 var searchEngine = this.searchEngines_[select.selectedIndex]; | 72 var searchEngine = this.searchEngines_[select.selectedIndex]; |
| 49 this.browserProxy_.setDefaultSearchEngine(searchEngine.modelIndex); | 73 this.browserProxy_.setDefaultSearchEngine(searchEngine.modelIndex); |
| 50 }, | 74 }, |
| 75 |
| 76 /** |
| 77 * @param {Event} event |
| 78 * @private |
| 79 */ |
| 80 onHotwordSearchEnableChange_: function(event) { |
| 81 // Do not set the pref directly, allow Chrome to run the setup app instead. |
| 82 this.browserProxy_.setHotwordSearchEnabled( |
| 83 !!this.hotwordSearchEnablePref_.value); |
| 84 }, |
| 85 |
| 86 /** |
| 87 * @param {!SearchPageHotwordInfo} hotwordInfo |
| 88 * @private |
| 89 */ |
| 90 hotwordInfoUpdate_: function(hotwordInfo) { |
| 91 this.hotwordInfo_ = hotwordInfo; |
| 92 this.hotwordSearchEnablePref_ = { |
| 93 key: 'unused', // required for PrefObject |
| 94 type: chrome.settingsPrivate.PrefType.BOOLEAN, |
| 95 value: this.hotwordInfo_.enabled, |
| 96 }; |
| 97 }, |
| 98 |
| 99 /** |
| 100 * @return {string} |
| 101 * @private |
| 102 */ |
| 103 getHotwordSearchEnableSubLabel_: function() { |
| 104 return this.i18n( |
| 105 this.hotwordInfo_.alwaysOn ? 'searchOkGoogleSubtextAlwaysOn' : |
| 106 'searchOkGoogleSubtextNoDsp'); |
| 107 }, |
| 108 |
| 109 /** |
| 110 * @return {boolean} |
| 111 * @private |
| 112 */ |
| 113 getShowHotwordSearchRetrain_: function() { |
| 114 return this.hotwordInfo_.enabled && this.hotwordInfo_.alwaysOn; |
| 115 }, |
| 116 |
| 117 /** |
| 118 * @return {boolean} True if the pref is enabled but hotword is not. |
| 119 * @private |
| 120 */ |
| 121 getShowHotwordError_: function() { |
| 122 return this.hotwordInfo_.enabled && !!this.hotwordInfo_.errorMessage; |
| 123 }, |
| 124 |
| 125 /** @private */ |
| 126 onRetrainTap_: function() { |
| 127 // Re-enable hotword search enable; this will trigger the retrain UI. |
| 128 this.browserProxy_.setHotwordSearchEnabled(this.hotwordInfo_.enabled); |
| 129 }, |
| 130 |
| 131 /** @private */ |
| 132 onManageAudioHistoryTap_: function() { |
| 133 window.open(loadTimeData.getString('manageAudioHistoryUrl')); |
| 134 }, |
| 135 |
| 136 /** |
| 137 * @param {Event} event |
| 138 * @private |
| 139 */ |
| 140 doNothing_: function(event) { |
| 141 event.stopPropagation(); |
| 142 } |
| 51 }); | 143 }); |
| OLD | NEW |