| 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 'cr-settings-search-engines-page' is the settings page | 6 * @fileoverview 'cr-settings-search-engines-page' is the settings page |
| 7 * containing search engines settings. | 7 * containing search engines settings. |
| 8 * | 8 * |
| 9 * Example: | 9 * Example: |
| 10 * | 10 * |
| 11 * <core-animated-pages> | 11 * <core-animated-pages> |
| 12 * <cr-settings-search-engines-page prefs="{{prefs}}"> | 12 * <cr-settings-search-engines-page prefs="{{prefs}}"> |
| 13 * </cr-settings-search-engines-page> | 13 * </cr-settings-search-engines-page> |
| 14 * ... other pages ... | 14 * ... other pages ... |
| 15 * </core-animated-pages> | 15 * </core-animated-pages> |
| 16 * | 16 * |
| 17 * @group Chrome Settings Elements | 17 * @group Chrome Settings Elements |
| 18 * @element cr-settings-search-engines-page | 18 * @element cr-settings-search-engines-page |
| 19 */ | 19 */ |
| 20 Polymer('cr-settings-search-engines-page', { | 20 Polymer({ |
| 21 publish: { | 21 is: 'cr-settings-search-engines-page', |
| 22 |
| 23 properties: { |
| 22 /** | 24 /** |
| 23 * Preferences state. | 25 * Preferences state. |
| 24 * | 26 * @type {?CrSettingsPrefsElement} |
| 25 * @attribute prefs | |
| 26 * @type {CrSettingsPrefsElement} | |
| 27 * @default null | |
| 28 */ | 27 */ |
| 29 prefs: null, | 28 prefs: { |
| 29 type: Object, |
| 30 notify: true |
| 31 }, |
| 30 | 32 |
| 31 /** | 33 /** |
| 32 * Route for the page. | 34 * Route for the page. |
| 33 * | |
| 34 * @attribute route | |
| 35 * @type {string} | |
| 36 * @default '' | |
| 37 */ | 35 */ |
| 38 route: '', | 36 route: { |
| 37 type: String, |
| 38 value: '' |
| 39 }, |
| 39 | 40 |
| 40 /** | 41 /** |
| 41 * Whether the page is a subpage. | 42 * Whether the page is a subpage. |
| 42 * | |
| 43 * @attribute subpage | |
| 44 * @type {boolean} | |
| 45 * @default true | |
| 46 */ | 43 */ |
| 47 subpage: true, | 44 subpage: { |
| 45 type: Boolean, |
| 46 value: true, |
| 47 readOnly: true |
| 48 }, |
| 48 | 49 |
| 49 /** | 50 /** |
| 50 * ID of the page. | 51 * ID of the page. |
| 51 * | |
| 52 * @attribute PAGE_ID | |
| 53 * @const {string} | |
| 54 * @default 'search' | |
| 55 */ | 52 */ |
| 56 PAGE_ID: 'search_engines', | 53 PAGE_ID: { |
| 54 type: String, |
| 55 value: 'search_engines', |
| 56 readOnly: true |
| 57 }, |
| 57 | 58 |
| 58 /** | 59 /** |
| 59 * Title for the page header and navigation menu. | 60 * Title for the page header and navigation menu. |
| 60 * | |
| 61 * @attribute pageTitle | |
| 62 * @type {string} | |
| 63 */ | 61 */ |
| 64 pageTitle: loadTimeData.getString('searchEnginesPageTitle'), | 62 pageTitle: { |
| 63 type: String, |
| 64 value: loadTimeData.getString('searchEnginesPageTitle'), |
| 65 readOnly: true |
| 66 }, |
| 65 | 67 |
| 66 /** | 68 /** |
| 67 * Name of the 'core-icon' to be shown in the settings-page-header. | 69 * Name of the 'core-icon' to be shown in the settings-page-header. |
| 68 * | |
| 69 * @attribute icon | |
| 70 * @type {string} | |
| 71 * @default 'search' | |
| 72 */ | 70 */ |
| 73 icon: 'search', | 71 icon: { |
| 74 | 72 type: String, |
| 75 /** | 73 value: 'search', |
| 76 * List of default search engines available. | 74 readOnly: true |
| 77 * | 75 }, |
| 78 * @attribute defaultSearchEngines | |
| 79 * @type {Array<!SearchEngine>} | |
| 80 * @default null | |
| 81 */ | |
| 82 defaultSearchEngines: null, | |
| 83 | |
| 84 /** | |
| 85 * List of other search engines available. | |
| 86 * | |
| 87 * @attribute otherSearchEngines | |
| 88 * @type {Array<!SearchEngine>} | |
| 89 * @default null | |
| 90 */ | |
| 91 otherSearchEngines: null, | |
| 92 | |
| 93 /** | |
| 94 * GUID of the currently selected default search engine. | |
| 95 * | |
| 96 * @attribute defaultEngineGuid | |
| 97 * @type {string} | |
| 98 * @default '' | |
| 99 */ | |
| 100 defaultEngineGuid: '', | |
| 101 }, | |
| 102 | |
| 103 /** @override */ | |
| 104 created: function() { | |
| 105 this.searchEngines = []; | |
| 106 }, | |
| 107 | |
| 108 /** @override */ | |
| 109 domReady: function() { | |
| 110 chrome.searchEnginesPrivate.onSearchEnginesChanged.addListener( | |
| 111 this.updateSearchEngines_.bind(this)); | |
| 112 chrome.searchEnginesPrivate.getSearchEngines( | |
| 113 this.updateSearchEngines_.bind(this)); | |
| 114 }, | |
| 115 | |
| 116 /** | |
| 117 * Persists the new default search engine back to Chrome. Called when the | |
| 118 * user selects a new default in the search engines dropdown. | |
| 119 */ | |
| 120 defaultEngineGuidChanged: function() { | |
| 121 chrome.searchEnginesPrivate.setSelectedSearchEngine(this.defaultEngineGuid); | |
| 122 }, | |
| 123 | |
| 124 | |
| 125 /** | |
| 126 * Updates the lists of search engines based on the given |engines|. | |
| 127 * @param {!Array<!SearchEngine>} engines All the search engines. | |
| 128 * @private | |
| 129 */ | |
| 130 updateSearchEngines_: function(engines) { | |
| 131 var defaultEngines = []; | |
| 132 var otherEngines = []; | |
| 133 | |
| 134 engines.forEach(function(engine) { | |
| 135 if (engine.type == | |
| 136 chrome.searchEnginesPrivate.SearchEngineType.DEFAULT) { | |
| 137 defaultEngines.push(engine); | |
| 138 if (engine.isSelected) { | |
| 139 this.defaultEngineGuid = engine.guid; | |
| 140 } | |
| 141 } else if (engine.type == | |
| 142 chrome.searchEnginesPrivate.SearchEngineType.OTHER) { | |
| 143 otherEngines.push(engine); | |
| 144 } | |
| 145 }, this); | |
| 146 | |
| 147 this.defaultSearchEngines = defaultEngines; | |
| 148 this.otherSearchEngines = otherEngines; | |
| 149 } | |
| 150 }); | 76 }); |
| OLD | NEW |