| 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 * 'cr-settings-search-page' is the settings page containing search settings. | 7 * 'cr-settings-search-page' is the settings page containing search settings. |
| 8 * | 8 * |
| 9 * Example: | 9 * Example: |
| 10 * | 10 * |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 defaultEngineGuid: '', | 81 defaultEngineGuid: '', |
| 82 }, | 82 }, |
| 83 | 83 |
| 84 /** @override */ | 84 /** @override */ |
| 85 created: function() { | 85 created: function() { |
| 86 this.searchEngines = []; | 86 this.searchEngines = []; |
| 87 }, | 87 }, |
| 88 | 88 |
| 89 /** @override */ | 89 /** @override */ |
| 90 domReady: function() { | 90 domReady: function() { |
| 91 chrome.searchEnginesPrivate.onDefaultSearchEnginesChanged.addListener( | 91 chrome.searchEnginesPrivate.onSearchEnginesChanged.addListener( |
| 92 this.updateSearchEngines_.bind(this)); | 92 this.updateSearchEngines_.bind(this)); |
| 93 chrome.searchEnginesPrivate.getDefaultSearchEngines( | 93 chrome.searchEnginesPrivate.getSearchEngines( |
| 94 this.updateSearchEngines_.bind(this)); | 94 this.updateSearchEngines_.bind(this)); |
| 95 }, | 95 }, |
| 96 | 96 |
| 97 /** | 97 /** |
| 98 * Persists the new default search engine back to Chrome. Called when the | 98 * Persists the new default search engine back to Chrome. Called when the |
| 99 * user selects a new default in the search engines dropdown. | 99 * user selects a new default in the search engines dropdown. |
| 100 */ | 100 */ |
| 101 defaultEngineGuidChanged: function() { | 101 defaultEngineGuidChanged: function() { |
| 102 chrome.searchEnginesPrivate.setSelectedSearchEngine(this.defaultEngineGuid); | 102 chrome.searchEnginesPrivate.setSelectedSearchEngine(this.defaultEngineGuid); |
| 103 }, | 103 }, |
| 104 | 104 |
| 105 | 105 |
| 106 /** | 106 /** |
| 107 * Updates the list of search engines with the given |engines|. | 107 * Updates the list of default search engines based on the given |engines|. |
| 108 * @param {!Array<!SearchEngine>} engines | 108 * @param {!Array<!SearchEngine>} engines All the search engines. |
| 109 * @private | 109 * @private |
| 110 */ | 110 */ |
| 111 updateSearchEngines_: function(engines) { | 111 updateSearchEngines_: function(engines) { |
| 112 this.searchEngines = engines; | 112 var defaultEngines = []; |
| 113 for (var i = 0; i < engines.length; i++) { | 113 |
| 114 if (engines[i].isSelected) { | 114 engines.forEach(function(engine) { |
| 115 this.defaultEngineGuid = engines[i].guid; | 115 if (engine.type == |
| 116 chrome.searchEnginesPrivate.SearchEngineType.DEFAULT) { |
| 117 defaultEngines.push(engine); |
| 118 if (engine.isSelected) { |
| 119 this.defaultEngineGuid = engine.guid; |
| 120 } |
| 116 } | 121 } |
| 117 } | 122 }, this); |
| 123 |
| 124 this.searchEngines = defaultEngines; |
| 118 } | 125 } |
| 119 }); | 126 }); |
| OLD | NEW |