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-startup-urls-page' is the settings page | 6 * @fileoverview 'cr-settings-startup-urls-page' is the settings page |
7 * containing the urls that will be opened when chrome is started. | 7 * containing the urls that will be opened when chrome is started. |
8 * | 8 * |
9 * Example: | 9 * Example: |
10 * | 10 * |
(...skipping 18 matching lines...) Expand all Loading... | |
29 notify: true, | 29 notify: true, |
30 }, | 30 }, |
31 | 31 |
32 newUrl: { | 32 newUrl: { |
33 type: String, | 33 type: String, |
34 }, | 34 }, |
35 | 35 |
36 /** @type {!Array<string>} */ | 36 /** @type {!Array<string>} */ |
37 savedUrlList: { | 37 savedUrlList: { |
38 type: Array, | 38 type: Array, |
39 value: function() { return []; } | |
40 }, | 39 }, |
41 }, | 40 }, |
42 | 41 |
42 observers: [ | |
43 'prefsChanged_(prefs.session.startup_urls.value.*)', | |
44 ], | |
45 | |
46 attached: function() { | |
47 var caller = this; | |
michaelpg
2015/09/14 19:13:49
use .bind instead of caching this
dschuyler
2015/09/14 23:20:00
Done.
| |
48 cr.define('Settings', function() { | |
michaelpg
2015/09/14 19:13:48
What is this for?
dschuyler
2015/09/14 23:20:00
This is routing the 'Settings.updateStartupPages'
| |
49 return { | |
50 updateStartupPages: function(data) { | |
51 caller.updateStartupPages_(data); | |
52 }, | |
53 }; | |
54 }); | |
55 }, | |
56 | |
57 prefsChanged_: function(change) { | |
58 if (this.savedUrlList === undefined && | |
michaelpg
2015/09/14 19:13:48
use double equals (the property shouldn't be null,
dschuyler
2015/09/14 23:20:00
Actually, I'm expecting it to be undefined. I don
michaelpg
2015/09/17 21:18:13
We rarely use strict equality (===) which is the m
| |
59 this.get('prefs.session.startup_urls')) { | |
60 this.savedUrlList = this.prefs.session.startup_urls.value.slice(); | |
61 } | |
62 }, | |
63 | |
64 /** @private */ | |
65 updateStartupPages_: function(data) { | |
66 var urlArray = []; | |
67 for (var i = 0; i < data.length; ++i) { | |
michaelpg
2015/09/14 19:13:48
no braces around single line
dschuyler
2015/09/14 23:20:00
Done.
| |
68 urlArray.push(data[i].url); | |
michaelpg
2015/09/14 19:13:49
or:
var urlArray = data.map(function(datum) { retu
dschuyler
2015/09/14 23:20:00
heh, was this an fyi and I can use either one - or
michaelpg
2015/09/17 21:18:13
"or" meant "optional" :-) I personally prefer this
| |
69 } | |
70 this.set('prefs.session.startup_urls.value', urlArray); | |
71 }, | |
72 | |
43 /** @private */ | 73 /** @private */ |
44 onUseCurrentPagesTap_: function() { | 74 onUseCurrentPagesTap_: function() { |
45 // TODO(dschuyler): I'll be making a chrome.send call here. | 75 chrome.send('setStartupPagesToCurrentPages'); |
46 }, | 76 }, |
47 | 77 |
48 /** @private */ | 78 /** @private */ |
49 onCancelTap_: function() { | 79 onCancelTap_: function() { |
50 this.set('prefs.session.startup_urls.value', this.savedUrlList.slice()); | 80 if (this.savedUrlList !== undefined) { |
81 this.set('prefs.session.startup_urls.value', this.savedUrlList.slice()); | |
82 } | |
51 }, | 83 }, |
52 | 84 |
53 /** @private */ | 85 /** @private */ |
54 onOkTap_: function() { | 86 onOkTap_: function() { |
55 var value = this.newUrl && this.newUrl.trim(); | 87 var value = this.newUrl && this.newUrl.trim(); |
56 if (!value) | 88 if (!value) |
57 return; | 89 return; |
58 this.push('prefs.session.startup_urls.value', value); | 90 this.push('prefs.session.startup_urls.value', value); |
59 this.newUrl = undefined; | 91 this.newUrl = undefined; |
60 }, | 92 }, |
61 | 93 |
62 /** @private */ | 94 /** @private */ |
63 onRemoveUrlTap_: function(e) { | 95 onRemoveUrlTap_: function(e) { |
64 this.splice('prefs.session.startup_urls.value', e.model.index, 1); | 96 this.splice('prefs.session.startup_urls.value', e.model.index, 1); |
65 }, | 97 }, |
66 }); | 98 }); |
OLD | NEW |