| 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 'settings-search-engines-page' is the settings page | 6 * @fileoverview 'settings-search-engines-page' is the settings page |
| 7 * containing search engines settings. | 7 * containing search engines settings. |
| 8 * | 8 * |
| 9 * Example: | |
| 10 * | |
| 11 * <core-animated-pages> | |
| 12 * <settings-search-engines-page prefs="{{prefs}}"> | |
| 13 * </settings-search-engines-page> | |
| 14 * ... other pages ... | |
| 15 * </core-animated-pages> | |
| 16 * | |
| 17 * @group Chrome Settings Elements | 9 * @group Chrome Settings Elements |
| 18 * @element settings-search-engines-page | 10 * @element settings-search-engines-page |
| 19 */ | 11 */ |
| 20 Polymer({ | 12 Polymer({ |
| 21 is: 'settings-search-engines-page', | 13 is: 'settings-search-engines-page', |
| 22 | 14 |
| 23 properties: { | 15 properties: { |
| 24 /** @type {!Array<!SearchEngine>} */ | 16 /** @type {!Array<!SearchEngine>} */ |
| 25 defaultEngines: { | 17 defaultEngines: { |
| 26 type: Array, | 18 type: Array, |
| 27 value: function() { return []; } | 19 value: function() { return []; } |
| 28 }, | 20 }, |
| 29 | 21 |
| 30 /** @type {!Array<!SearchEngine>} */ | 22 /** @type {!Array<!SearchEngine>} */ |
| 31 otherEngines: { | 23 otherEngines: { |
| 32 type: Array, | 24 type: Array, |
| 33 value: function() { return []; } | 25 value: function() { return []; } |
| 34 }, | 26 }, |
| 35 | 27 |
| 36 /** @type {boolean} */ | 28 /** @private {boolean} */ |
| 37 showAddSearchEngineDialog_: { | 29 showAddSearchEngineDialog_: Boolean, |
| 30 |
| 31 /** @private {boolean} */ |
| 32 otherSearchEnginesExpanded_: { |
| 38 type: Boolean, | 33 type: Boolean, |
| 39 value: false, | 34 value: true, |
| 40 }, | 35 }, |
| 41 }, | 36 }, |
| 42 | 37 |
| 38 /** |
| 39 * Holds WebUI listeners that need to be removed when this element is |
| 40 * destroyed. |
| 41 * TODO(dpapad): Move listener tracking logic to a Polymer behavior class, |
| 42 * such that it can be re-used. |
| 43 * @private {!Array<!WebUIListener>} |
| 44 */ |
| 45 webUIListeners_: [], |
| 46 |
| 43 /** @override */ | 47 /** @override */ |
| 44 ready: function() { | 48 ready: function() { |
| 45 chrome.searchEnginesPrivate.onSearchEnginesChanged.addListener( | 49 settings.SearchEnginesBrowserProxyImpl.getInstance(). |
| 46 this.enginesChanged_.bind(this)); | 50 getSearchEnginesList().then(this.enginesChanged_.bind(this)); |
| 47 this.enginesChanged_(); | 51 this.webUIListeners_.push(cr.addWebUIListener( |
| 52 'search-engines-changed', this.enginesChanged_.bind(this))); |
| 48 }, | 53 }, |
| 49 | 54 |
| 50 /** @private */ | 55 /** @override */ |
| 51 enginesChanged_: function() { | 56 detached: function() { |
| 52 chrome.searchEnginesPrivate.getSearchEngines(function(engines) { | 57 this.webUIListeners_.forEach(function(listener) { |
| 53 this.defaultEngines = engines.filter(function(engine) { | 58 cr.removeWebUIListener(listener); |
| 54 return engine.type == | 59 }); |
| 55 chrome.searchEnginesPrivate.SearchEngineType.DEFAULT; | 60 }, |
| 56 }, this); | |
| 57 | 61 |
| 58 this.otherEngines = engines.filter(function(engine) { | 62 /** |
| 59 return engine.type == | 63 * @param {!SearchEnginesInfo} searchEnginesInfo |
| 60 chrome.searchEnginesPrivate.SearchEngineType.OTHER; | 64 * @private |
| 61 }, this); | 65 */ |
| 62 }.bind(this)); | 66 enginesChanged_: function(searchEnginesInfo) { |
| 67 this.defaultEngines = searchEnginesInfo['defaults']; |
| 68 this.otherEngines = searchEnginesInfo['others']; |
| 69 // TODO(dpapad): Use searchEnginesInfo['extensions'] once UI mocks are |
| 70 // provided. |
| 63 }, | 71 }, |
| 64 | 72 |
| 65 /** @private */ | 73 /** @private */ |
| 66 onAddSearchEngineTap_: function() { | 74 onAddSearchEngineTap_: function() { |
| 67 this.showAddSearchEngineDialog_ = true; | 75 this.showAddSearchEngineDialog_ = true; |
| 68 this.async(function() { | 76 this.async(function() { |
| 69 var dialog = this.$$('settings-add-search-engine-dialog'); | 77 var dialog = this.$$('settings-search-engine-dialog'); |
| 70 // Register listener to detect when the dialog is closed. Flip the boolean | 78 // Register listener to detect when the dialog is closed. Flip the boolean |
| 71 // once closed to force a restamp next time it is shown such that the | 79 // once closed to force a restamp next time it is shown such that the |
| 72 // previous dialog's contents are cleared. | 80 // previous dialog's contents are cleared. |
| 73 dialog.addEventListener('iron-overlay-closed', function() { | 81 dialog.addEventListener('iron-overlay-closed', function() { |
| 74 this.showAddSearchEngineDialog_ = false; | 82 this.showAddSearchEngineDialog_ = false; |
| 75 }.bind(this)); | 83 }.bind(this)); |
| 76 dialog.open(); | |
| 77 }.bind(this)); | 84 }.bind(this)); |
| 78 }, | 85 }, |
| 79 }); | 86 }); |
| OLD | NEW |