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 * | 17 * |
18 * Example: | 18 * Example: |
19 * | 19 * |
20 * <neon-animated-pages> | 20 * <neon-animated-pages> |
21 * <settings-startup-urls-page prefs="{{prefs}}"> | 21 * <settings-startup-urls-page prefs="{{prefs}}"> |
22 * </settings-startup-urls-page> | 22 * </settings-startup-urls-page> |
23 * ... other pages ... | 23 * ... other pages ... |
24 * </neon-animated-pages> | 24 * </neon-animated-pages> |
25 */ | 25 */ |
26 Polymer({ | 26 Polymer({ |
27 is: 'settings-startup-urls-page', | 27 is: 'settings-startup-urls-page', |
28 | 28 |
| 29 behaviors: [WebUIListenerBehavior], |
| 30 |
29 properties: { | 31 properties: { |
30 /** | 32 /** |
31 * Preferences state. | 33 * Preferences state. |
32 */ | 34 */ |
33 prefs: { | 35 prefs: { |
34 type: Object, | 36 type: Object, |
35 notify: true, | 37 notify: true, |
36 }, | 38 }, |
37 | 39 |
| 40 /** @type {settings.StartupUrlsPageBrowserProxy} */ |
| 41 browserProxy_: Object, |
| 42 |
38 /** @private {string} */ | 43 /** @private {string} */ |
39 newUrl_: { | 44 newUrl_: { |
40 type: String, | 45 type: String, |
41 value: '', | 46 value: '', |
42 }, | 47 }, |
43 | 48 |
44 /** | 49 /** |
45 * Pages to load upon browser startup. | 50 * Pages to load upon browser startup. |
46 * @private {!Array<!StartupPageInfo>} | 51 * @private {!Array<!StartupPageInfo>} |
47 */ | 52 */ |
48 startupPages_: Array, | 53 startupPages_: Array, |
49 }, | 54 }, |
50 | 55 |
51 attached: function() { | 56 created: function() { |
52 var self = this; | 57 this.browserProxy_ = settings.StartupUrlsPageBrowserProxyImpl.getInstance(); |
53 cr.define('Settings', function() { | |
54 return { | |
55 updateStartupPages: function() { | |
56 return self.updateStartupPages_.apply(self, arguments); | |
57 }, | |
58 }; | |
59 }); | |
60 chrome.send('onStartupPrefsPageLoad'); | |
61 }, | 58 }, |
62 | 59 |
| 60 attached: function() { |
| 61 this.addWebUIListener('update-startup-pages', |
| 62 this.updateStartupPages_.bind(this)); |
| 63 this.browserProxy_.loadStartupPages(); |
| 64 }, |
| 65 |
| 66 /** |
| 67 * @param {string} url Location of an image to get a set of icons fors. |
| 68 * @return {string} A set of icon URLs. |
| 69 * @private |
| 70 */ |
63 getIconSet_: function(url) { | 71 getIconSet_: function(url) { |
64 return getFaviconImageSet(url); | 72 return getFaviconImageSet(url); |
65 }, | 73 }, |
66 | 74 |
67 /** @private */ | 75 /** @private */ |
68 updateStartupPages_: function(startupPages) { | 76 updateStartupPages_: function(startupPages) { |
69 this.startupPages_ = startupPages; | 77 this.startupPages_ = startupPages; |
70 }, | 78 }, |
71 | 79 |
72 /** @private */ | 80 /** @private */ |
73 onAddPageTap_: function() { | 81 onAddPageTap_: function() { |
74 this.newUrl_ = ''; | 82 this.newUrl_ = ''; |
75 this.$.addUrlDialog.open(); | 83 this.$.addUrlDialog.open(); |
76 }, | 84 }, |
77 | 85 |
78 /** @private */ | 86 /** @private */ |
79 onUseCurrentPagesTap_: function() { | 87 onUseCurrentPagesTap_: function() { |
80 chrome.send('setStartupPagesToCurrentPages'); | 88 this.browserProxy_.useCurrentPages(); |
81 }, | 89 }, |
82 | 90 |
83 /** @private */ | 91 /** @private */ |
84 onCancelTap_: function() { | 92 onCancelTap_: function() { |
85 this.$.addUrlDialog.close(); | 93 this.$.addUrlDialog.close(); |
86 }, | 94 }, |
87 | 95 |
88 /** | 96 /** |
89 * @return {boolean} Whether tapping the Add button should be allowed. | 97 * @return {boolean} Whether tapping the Add button should be allowed. |
90 * @private | 98 * @private |
91 */ | 99 */ |
92 isAddEnabled_: function() { | 100 isAddEnabled_: function() { |
93 return this.newUrl_.trim().length > 0; | 101 return this.browserProxy_.canAddPage(this.newUrl_); |
94 }, | 102 }, |
95 | 103 |
96 /** @private */ | 104 /** @private */ |
97 onAddTap_: function() { | 105 onAddTap_: function() { |
98 assert(this.isAddEnabled_()); | 106 assert(this.isAddEnabled_()); |
99 chrome.send('addStartupPage', [this.newUrl_.trim()]); | 107 this.browserProxy_.addStartupPage(this.newUrl_); |
100 this.$.addUrlDialog.close(); | 108 this.$.addUrlDialog.close(); |
101 }, | 109 }, |
102 | 110 |
103 /** | 111 /** |
104 * @param {!{model: !{index: number}}} e | 112 * @param {!{model: !{index: number}}} e |
105 * @private | 113 * @private |
106 */ | 114 */ |
107 onRemoveUrlTap_: function(e) { | 115 onRemoveUrlTap_: function(e) { |
108 chrome.send('removeStartupPage', [e.model.index]); | 116 this.browserProxy_.removeStartupPage(e.model.index); |
109 }, | 117 }, |
110 }); | 118 }); |
OLD | NEW |