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 attached: function() { |
52 var self = this; | 57 this.addWebUIListener('update-startup-pages', |
53 cr.define('Settings', function() { | 58 this.updateStartupPages_.bind(this)); |
54 return { | 59 this.browserProxy_ = settings.StartupUrlsPageBrowserProxyImpl.getInstance(); |
55 updateStartupPages: function() { | 60 this.browserProxy_.loadStartupPages(); |
56 return self.updateStartupPages_.apply(self, arguments); | |
57 }, | |
58 }; | |
59 }); | |
60 chrome.send('onStartupPrefsPageLoad'); | |
61 }, | 61 }, |
62 | 62 |
63 /** | |
dschuyler
2016/03/30 23:14:40
Should there be an @param for the url
Dan Beam
2016/03/31 00:06:28
Done.
| |
64 * @return {string} A set of icon URLs. | |
65 * @private | |
66 */ | |
63 getIconSet_: function(url) { | 67 getIconSet_: function(url) { |
64 return getFaviconImageSet(url); | 68 return getFaviconImageSet(url); |
65 }, | 69 }, |
66 | 70 |
67 /** @private */ | 71 /** @private */ |
68 updateStartupPages_: function(startupPages) { | 72 updateStartupPages_: function(startupPages) { |
69 this.startupPages_ = startupPages; | 73 this.startupPages_ = startupPages; |
70 }, | 74 }, |
71 | 75 |
72 /** @private */ | 76 /** @private */ |
73 onAddPageTap_: function() { | 77 onAddPageTap_: function() { |
74 this.newUrl_ = ''; | 78 this.newUrl_ = ''; |
75 this.$.addUrlDialog.open(); | 79 this.$.addUrlDialog.open(); |
76 }, | 80 }, |
77 | 81 |
78 /** @private */ | 82 /** @private */ |
79 onUseCurrentPagesTap_: function() { | 83 onUseCurrentPagesTap_: function() { |
80 chrome.send('setStartupPagesToCurrentPages'); | 84 this.browserProxy_.useCurrentPages(); |
81 }, | 85 }, |
82 | 86 |
83 /** @private */ | 87 /** @private */ |
84 onCancelTap_: function() { | 88 onCancelTap_: function() { |
85 this.$.addUrlDialog.close(); | 89 this.$.addUrlDialog.close(); |
86 }, | 90 }, |
87 | 91 |
88 /** | 92 /** |
89 * @return {boolean} Whether tapping the Add button should be allowed. | 93 * @return {boolean} Whether tapping the Add button should be allowed. |
90 * @private | 94 * @private |
91 */ | 95 */ |
92 isAddEnabled_: function() { | 96 isAddEnabled_: function() { |
93 return this.newUrl_.trim().length > 0; | 97 return this.browserProxy_ && this.browserProxy_.canAddPage(this.newUrl_); |
Dan Beam
2016/03/30 02:30:23
i don't currently know whether the "this.browserPr
dschuyler
2016/03/30 23:14:40
I asked Demetrios about it. He suggested changing
Dan Beam
2016/03/31 00:06:28
Done. (had to initialize browserProxy_ in created)
| |
94 }, | 98 }, |
95 | 99 |
96 /** @private */ | 100 /** @private */ |
97 onAddTap_: function() { | 101 onAddTap_: function() { |
98 assert(this.isAddEnabled_()); | 102 assert(this.isAddEnabled_()); |
99 chrome.send('addStartupPage', [this.newUrl_.trim()]); | 103 this.browserProxy_.addStartupPage(this.newUrl_); |
100 this.$.addUrlDialog.close(); | 104 this.$.addUrlDialog.close(); |
101 }, | 105 }, |
102 | 106 |
103 /** | 107 /** |
104 * @param {!{model: !{index: number}}} e | 108 * @param {!{model: !{index: number}}} e |
105 * @private | 109 * @private |
106 */ | 110 */ |
107 onRemoveUrlTap_: function(e) { | 111 onRemoveUrlTap_: function(e) { |
108 chrome.send('removeStartupPage', [e.model.index]); | 112 this.browserProxy_.removeStartupPage(e.model.index); |
109 }, | 113 }, |
110 }); | 114 }); |
OLD | NEW |