Chromium Code Reviews| 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 * Example: | |
| 10 * | |
| 11 * <iron-animated-pages> | |
| 12 * <settings-search-page prefs="{{prefs}}"></settings-search-page> | |
| 13 * ... other pages ... | |
| 14 * </iron-animated-pages> | |
| 15 * | |
| 16 * @group Chrome Settings Elements | 9 * @group Chrome Settings Elements |
| 17 * @element settings-search-page | 10 * @element settings-search-page |
| 18 */ | 11 */ |
| 19 Polymer({ | 12 Polymer({ |
| 20 is: 'settings-search-page', | 13 is: 'settings-search-page', |
| 21 | 14 |
| 22 properties: { | 15 properties: { |
| 23 /** | 16 /** |
| 24 * The current active route. | 17 * The current active route. |
| 25 */ | 18 */ |
| 26 currentRoute: { | 19 currentRoute: { |
| 27 type: Object, | 20 type: Object, |
| 28 notify: true, | 21 notify: true, |
| 29 }, | 22 }, |
| 30 | 23 |
| 31 /** | 24 /** @private {!Array<!SearchEngine>} */ |
| 32 * List of default search engines available. | 25 searchEngines_: { |
|
Dan Beam
2016/02/23 02:41:22
this removes "default" as a bit of documentation.
dpapad
2016/02/23 18:35:39
Restored.
| |
| 33 * @type {?Array<!SearchEngine>} | |
| 34 */ | |
| 35 searchEngines: { | |
| 36 type: Array, | 26 type: Array, |
| 37 value: function() { return []; }, | 27 value: function() { return []; } |
| 38 }, | 28 }, |
| 29 | |
| 30 /** @private {!settings.SearchEnginesBrowserProxy} */ | |
| 31 browserProxy_: Object, | |
| 39 }, | 32 }, |
| 40 | 33 |
| 41 /** @override */ | 34 /** @override */ |
| 42 created: function() { | 35 created: function() { |
| 43 chrome.searchEnginesPrivate.onSearchEnginesChanged.addListener( | 36 this.browserProxy_ = settings.SearchEnginesBrowserProxyImpl.getInstance(); |
| 44 this.updateSearchEngines_.bind(this)); | |
| 45 chrome.searchEnginesPrivate.getSearchEngines( | |
| 46 this.updateSearchEngines_.bind(this)); | |
| 47 }, | 37 }, |
| 48 | 38 |
| 49 /** | 39 /** @override */ |
| 50 * Persists the new default search engine back to Chrome. Called when the | 40 ready: function() { |
| 51 * user selects a new default in the search engines dropdown. | 41 var updateSearchEngines = function(searchEngines) { |
| 52 * @private | 42 this.set('searchEngines', searchEngines.defaults); |
| 53 */ | 43 }; |
|
Dan Beam
2016/02/23 02:41:22
bind() only once here
dpapad
2016/02/23 18:35:39
Done.
| |
| 54 defaultEngineGuidChanged_: function() { | 44 this.browserProxy_.getSearchEnginesList().then( |
| 55 chrome.searchEnginesPrivate.setSelectedSearchEngine( | 45 updateSearchEngines.bind(this)); |
| 56 this.$.searchEnginesMenu.value); | 46 cr.addWebUIListener( |
|
michaelpg
2016/02/20 04:31:16
Since the BrowserProxy handles push (setDefaultSea
dpapad
2016/02/22 18:57:53
Are you suggesting to wrap the cr.addWebUIListener
| |
| 57 }, | 47 'search-engines-changed', updateSearchEngines.bind(this)); |
| 58 | |
| 59 | |
| 60 /** | |
| 61 * Updates the list of default search engines based on the given |engines|. | |
| 62 * @param {!Array<!SearchEngine>} engines All the search engines. | |
| 63 * @private | |
| 64 */ | |
| 65 updateSearchEngines_: function(engines) { | |
| 66 var defaultEngines = []; | |
| 67 | |
| 68 engines.forEach(function(engine) { | |
| 69 if (engine.type == | |
| 70 chrome.searchEnginesPrivate.SearchEngineType.DEFAULT) { | |
| 71 defaultEngines.push(engine); | |
| 72 if (engine.isSelected) { | |
| 73 this.$.searchEnginesMenu.value = engine.guid; | |
| 74 } | |
| 75 } | |
| 76 }, this); | |
| 77 | |
| 78 this.searchEngines = defaultEngines; | |
| 79 }, | 48 }, |
| 80 | 49 |
| 81 /** @private */ | 50 /** @private */ |
| 82 onSearchEnginesTap_: function() { | 51 onManageSearchEnginesTap_: function() { |
| 83 this.$.pages.setSubpageChain(['search-engines']); | 52 this.$.pages.setSubpageChain(['search-engines']); |
| 84 }, | 53 }, |
| 54 | |
| 55 /** @private */ | |
| 56 onDefaultEngineChanged_: function() { | |
| 57 this.browserProxy_.setDefaultSearchEngine(this.$.searchEnginesMenu.value); | |
| 58 }, | |
| 85 }); | 59 }); |
| OLD | NEW |