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 /** |
|
Dan Beam
2016/02/17 02:21:35
can you keep these 2 comments joined like they wer
Dan Beam
2016/02/18 03:08:18
ping
dpapad
2016/02/18 19:34:51
Done.
| |
| 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))); | |
| 57 }, | |
| 58 | |
| 59 /** @override */ | |
| 60 detached: function() { | |
| 61 this.webUIListeners_.forEach(function(listener) { | |
| 62 cr.removeWebUIListener(listener); | |
| 63 }); | |
| 48 }, | 64 }, |
| 49 | 65 |
| 50 /** @private */ | 66 /** @private */ |
|
Dan Beam
2016/02/17 02:21:35
can you document |searchEnginesInfo| and its @type
dpapad
2016/02/17 03:22:36
Done. The typedef is already defined (see search_e
| |
| 51 enginesChanged_: function() { | 67 enginesChanged_: function(searchEnginesInfo) { |
| 52 chrome.searchEnginesPrivate.getSearchEngines(function(engines) { | 68 this.defaultEngines = searchEnginesInfo['defaults']; |
| 53 this.defaultEngines = engines.filter(function(engine) { | 69 this.otherEngines = searchEnginesInfo['others']; |
| 54 return engine.type == | 70 // TODO(dpapad): Use searchEnginesInfo['extensions'] once UI mocks are |
| 55 chrome.searchEnginesPrivate.SearchEngineType.DEFAULT; | 71 // 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 }, | 72 }, |
| 64 | 73 |
| 65 /** @private */ | 74 /** @private */ |
| 66 onAddSearchEngineTap_: function() { | 75 onAddSearchEngineTap_: function() { |
| 67 this.showAddSearchEngineDialog_ = true; | 76 this.showAddSearchEngineDialog_ = true; |
| 68 this.async(function() { | 77 this.async(function() { |
| 69 var dialog = this.$$('settings-add-search-engine-dialog'); | 78 var dialog = this.$$('settings-search-engine-dialog'); |
| 70 // Register listener to detect when the dialog is closed. Flip the boolean | 79 // 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 | 80 // once closed to force a restamp next time it is shown such that the |
| 72 // previous dialog's contents are cleared. | 81 // previous dialog's contents are cleared. |
| 73 dialog.addEventListener('iron-overlay-closed', function() { | 82 dialog.addEventListener('iron-overlay-closed', function() { |
| 74 this.showAddSearchEngineDialog_ = false; | 83 this.showAddSearchEngineDialog_ = false; |
| 75 }.bind(this)); | 84 }.bind(this)); |
| 76 dialog.open(); | |
| 77 }.bind(this)); | 85 }.bind(this)); |
| 78 }, | 86 }, |
| 79 }); | 87 }); |
| OLD | NEW |