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 '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 * @private {!Array<!WebUIListener>} | |
| 44 */ | |
| 45 webUIListeners_: [], | |
|
Dan Beam
2016/02/13 02:03:02
probably makes sense to make a behavior to do stuf
dpapad
2016/02/16 18:48:05
Agreed, this functionality can be re-used by putti
dpapad
2016/02/17 01:12:20
FYI, extracting this as a behavior in follow-up CL
| |
| 46 | |
| 43 /** @override */ | 47 /** @override */ |
| 44 ready: function() { | 48 ready: function() { |
| 45 chrome.searchEnginesPrivate.onSearchEnginesChanged.addListener( | 49 settings.SearchEnginesBrowserProxy.getInstance(). |
| 46 this.enginesChanged_.bind(this)); | 50 getSearchEnginesList().then(this.enginesChanged_.bind(this)); |
| 47 this.enginesChanged_(); | 51 this.webUIListeners_.push( |
| 52 cr.addWebUIListener( | |
| 53 'search-engines-changed', | |
| 54 this.enginesChanged_.bind(this))); | |
| 55 }, | |
| 56 | |
| 57 /** @override */ | |
| 58 detached: function() { | |
| 59 this.webUIListeners_.forEach(function(listener) { | |
| 60 cr.removeWebUIListener(listener); | |
| 61 }); | |
| 48 }, | 62 }, |
| 49 | 63 |
| 50 /** @private */ | 64 /** @private */ |
| 51 enginesChanged_: function() { | 65 enginesChanged_: function(searchEnginesInfo) { |
| 52 chrome.searchEnginesPrivate.getSearchEngines(function(engines) { | 66 this.defaultEngines = searchEnginesInfo['defaults']; |
| 53 this.defaultEngines = engines.filter(function(engine) { | 67 this.otherEngines = searchEnginesInfo['others']; |
| 54 return engine.type == | 68 // TODO(dpapad): Use searchEnginesInfo['extensions'] once UI mocks are |
| 55 chrome.searchEnginesPrivate.SearchEngineType.DEFAULT; | 69 // provided. |
| 56 }, this); | |
| 57 | |
| 58 this.otherEngines = engines.filter(function(engine) { | |
| 59 return engine.type == | |
| 60 chrome.searchEnginesPrivate.SearchEngineType.OTHER; | |
| 61 }, this); | |
| 62 }.bind(this)); | |
| 63 }, | 70 }, |
| 64 | 71 |
| 65 /** @private */ | 72 /** @private */ |
| 66 onAddSearchEngineTap_: function() { | 73 onAddSearchEngineTap_: function() { |
| 67 this.showAddSearchEngineDialog_ = true; | 74 this.showAddSearchEngineDialog_ = true; |
| 68 this.async(function() { | 75 this.async(function() { |
| 69 var dialog = this.$$('settings-add-search-engine-dialog'); | 76 var dialog = this.$$('settings-search-engine-dialog'); |
| 70 // Register listener to detect when the dialog is closed. Flip the boolean | 77 // 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 | 78 // once closed to force a restamp next time it is shown such that the |
| 72 // previous dialog's contents are cleared. | 79 // previous dialog's contents are cleared. |
| 73 dialog.addEventListener('iron-overlay-closed', function() { | 80 dialog.addEventListener('iron-overlay-closed', function() { |
| 74 this.showAddSearchEngineDialog_ = false; | 81 this.showAddSearchEngineDialog_ = false; |
| 75 }.bind(this)); | 82 }.bind(this)); |
| 76 dialog.open(); | |
| 77 }.bind(this)); | 83 }.bind(this)); |
| 78 }, | 84 }, |
| 79 }); | 85 }); |
| OLD | NEW |