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