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