| 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 * @typedef {{ | 6 * @typedef {{ |
| 7 * 'title': string, | 7 * 'title': string, |
| 8 * 'tooltip': string, | 8 * 'tooltip': string, |
| 9 * 'url': string | 9 * 'url': string |
| 10 * }} | 10 * }} |
| 11 */ | 11 */ |
| 12 var StartupPageInfo; | 12 var StartupPageInfo; |
| 13 | 13 |
| 14 /** | 14 /** |
| 15 * @fileoverview 'settings-startup-urls-page' is the settings page | 15 * @fileoverview 'settings-startup-urls-page' is the settings page |
| 16 * containing the urls that will be opened when chrome is started. | 16 * containing the urls that will be opened when chrome is started. |
| 17 * | |
| 18 * Example: | |
| 19 * | |
| 20 * <neon-animated-pages> | |
| 21 * <settings-startup-urls-page prefs="{{prefs}}"> | |
| 22 * </settings-startup-urls-page> | |
| 23 * ... other pages ... | |
| 24 * </neon-animated-pages> | |
| 25 */ | 17 */ |
| 26 Polymer({ | 18 Polymer({ |
| 27 is: 'settings-startup-urls-page', | 19 is: 'settings-startup-urls-page', |
| 28 | 20 |
| 29 behaviors: [WebUIListenerBehavior], | 21 behaviors: [WebUIListenerBehavior], |
| 30 | 22 |
| 31 properties: { | 23 properties: { |
| 32 /** | |
| 33 * Preferences state. | |
| 34 */ | |
| 35 prefs: { | |
| 36 type: Object, | |
| 37 notify: true, | |
| 38 }, | |
| 39 | |
| 40 /** @type {settings.StartupUrlsPageBrowserProxy} */ | 24 /** @type {settings.StartupUrlsPageBrowserProxy} */ |
| 41 browserProxy_: Object, | 25 browserProxy_: Object, |
| 42 | 26 |
| 43 /** @private {string} */ | |
| 44 newUrl_: { | |
| 45 observer: 'newUrlChanged_', | |
| 46 type: String, | |
| 47 value: '', | |
| 48 }, | |
| 49 | |
| 50 isNewUrlValid_: { | |
| 51 type: Boolean, | |
| 52 value: false, | |
| 53 }, | |
| 54 | |
| 55 /** | 27 /** |
| 56 * Pages to load upon browser startup. | 28 * Pages to load upon browser startup. |
| 57 * @private {!Array<!StartupPageInfo>} | 29 * @private {!Array<!StartupPageInfo>} |
| 58 */ | 30 */ |
| 59 startupPages_: Array, | 31 startupPages_: Array, |
| 32 |
| 33 showStartupUrlDialog_: Boolean, |
| 60 }, | 34 }, |
| 61 | 35 |
| 62 created: function() { | 36 /** @override */ |
| 37 attached: function() { |
| 63 this.browserProxy_ = settings.StartupUrlsPageBrowserProxyImpl.getInstance(); | 38 this.browserProxy_ = settings.StartupUrlsPageBrowserProxyImpl.getInstance(); |
| 64 }, | 39 this.addWebUIListener('update-startup-pages', function(startupPages) { |
| 65 | 40 this.startupPages_ = startupPages; |
| 66 attached: function() { | 41 }.bind(this)); |
| 67 this.addWebUIListener('update-startup-pages', | |
| 68 this.updateStartupPages_.bind(this)); | |
| 69 this.browserProxy_.loadStartupPages(); | 42 this.browserProxy_.loadStartupPages(); |
| 70 }, | 43 }, |
| 71 | 44 |
| 72 /** | 45 /** |
| 73 * @param {string} url Location of an image to get a set of icons fors. | 46 * @param {string} url Location of an image to get a set of icons fors. |
| 74 * @return {string} A set of icon URLs. | 47 * @return {string} A set of icon URLs. |
| 75 * @private | 48 * @private |
| 76 */ | 49 */ |
| 77 getIconSet_: function(url) { | 50 getIconSet_: function(url) { |
| 78 return getFaviconImageSet(url); | 51 return getFaviconImageSet(url); |
| 79 }, | 52 }, |
| 80 | 53 |
| 81 /** @private */ | 54 /** |
| 82 updateStartupPages_: function(startupPages) { | 55 * Opens the dialog and registers a listener for removing the dialog from the |
| 83 this.startupPages_ = startupPages; | 56 * DOM once is closed. The listener is destroyed when the dialog is removed |
| 84 }, | 57 * (because of 'restamp'). |
| 85 | 58 * @private |
| 86 /** @private */ | 59 */ |
| 87 onAddPageTap_: function() { | 60 onAddPageTap_: function() { |
| 88 this.newUrl_ = ''; | 61 this.showStartupUrlDialog_ = true; |
| 89 this.$.addUrlDialog.open(); | 62 this.async(function() { |
| 63 var dialog = this.$$('settings-startup-url-dialog'); |
| 64 dialog.addEventListener('iron-overlay-closed', function() { |
| 65 this.showStartupUrlDialog_ = false; |
| 66 }.bind(this)); |
| 67 }.bind(this)); |
| 90 }, | 68 }, |
| 91 | 69 |
| 92 /** @private */ | 70 /** @private */ |
| 93 onUseCurrentPagesTap_: function() { | 71 onUseCurrentPagesTap_: function() { |
| 94 this.browserProxy_.useCurrentPages(); | 72 this.browserProxy_.useCurrentPages(); |
| 95 }, | 73 }, |
| 96 | 74 |
| 97 /** @private */ | |
| 98 onCancelTap_: function() { | |
| 99 this.$.addUrlDialog.close(); | |
| 100 }, | |
| 101 | |
| 102 /** | 75 /** |
| 103 * @param {string} newUrl | |
| 104 * @private | |
| 105 */ | |
| 106 newUrlChanged_: function(newUrl) { | |
| 107 if (this.validationResolver_) | |
| 108 this.validationResolver_.reject(false); | |
| 109 | |
| 110 /** @type {?PromiseResolver<boolean>} */ | |
| 111 this.validationResolver_ = this.browserProxy_.validateStartupPage(newUrl); | |
| 112 | |
| 113 this.validationResolver_.promise.then(function(isValid) { | |
| 114 this.isNewUrlValid_ = isValid; | |
| 115 this.validationResolver_ = null; | |
| 116 }.bind(this), function() { | |
| 117 // Squelchs console errors. | |
| 118 }); | |
| 119 }, | |
| 120 | |
| 121 /** @private */ | |
| 122 onAddTap_: function() { | |
| 123 assert(this.isNewUrlValid_); | |
| 124 this.browserProxy_.addStartupPage(this.newUrl_); | |
| 125 this.$.addUrlDialog.close(); | |
| 126 }, | |
| 127 | |
| 128 /** | |
| 129 * @param {!{model: !{index: number}}} e | 76 * @param {!{model: !{index: number}}} e |
| 130 * @private | 77 * @private |
| 131 */ | 78 */ |
| 132 onRemoveUrlTap_: function(e) { | 79 onRemoveUrlTap_: function(e) { |
| 133 this.browserProxy_.removeStartupPage(e.model.index); | 80 this.browserProxy_.removeStartupPage(e.model.index); |
| 134 }, | 81 }, |
| 135 }); | 82 }); |
| OLD | NEW |