OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 cr.define('options.internet', function() { | 5 cr.define('options.internet', function() { |
6 var OptionsPage = options.OptionsPage; | 6 var OptionsPage = options.OptionsPage; |
7 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; | 7 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; |
8 | 8 |
9 /** | |
10 * Minimum delay in milliseconds before updating controls. Used to | |
11 * consolidate update requests resulting from preference update | |
12 * notifications. | |
13 * @type {Number} | |
14 */ | |
15 var minimumUpdateContentsDelay_ = 50; | |
csilv
2012/04/24 22:00:53
/** @const */
kevers
2012/04/24 22:20:10
Done.
| |
16 | |
17 /** | |
18 * Time of the last request to update controls in milliseconds. | |
19 * @type {Number} | |
20 */ | |
21 var lastContentsUpdateRequest_ = 0; | |
22 | |
23 /** | |
24 * Time of the last update to the controls in milliseconds. | |
25 * @type {Number} | |
26 */ | |
27 var lastContentsUpdate_ = 0; | |
28 | |
9 /* | 29 /* |
10 * Helper function to set hidden attribute for elements matching a selector. | 30 * Helper function to set hidden attribute for elements matching a selector. |
11 * @param {string} selector CSS selector for extracting a list of elements. | 31 * @param {string} selector CSS selector for extracting a list of elements. |
12 * @param {bool} hidden New hidden value. | 32 * @param {bool} hidden New hidden value. |
13 */ | 33 */ |
14 function updateHidden(selector, hidden) { | 34 function updateHidden(selector, hidden) { |
15 var elements = cr.doc.querySelectorAll(selector); | 35 var elements = cr.doc.querySelectorAll(selector); |
16 for (var i = 0, el; el = elements[i]; i++) { | 36 for (var i = 0, el; el = elements[i]; i++) { |
17 el.hidden = hidden; | 37 el.hidden = hidden; |
18 } | 38 } |
19 } | 39 } |
20 | 40 |
21 /** | 41 /** |
22 * Monitor pref change of given element. | 42 * Monitor pref change of given element. |
23 * @param {Element} el Target element. | 43 * @param {Element} el Target element. |
24 */ | 44 */ |
25 function observePrefsUI(el) { | 45 function observePrefsUI(el) { |
26 Preferences.getInstance().addEventListener(el.pref, handlePrefUpdate); | 46 Preferences.getInstance().addEventListener(el.pref, handlePrefUpdate); |
27 } | 47 } |
28 | 48 |
29 /** | 49 /** |
30 * UI pref change handler. | 50 * UI pref change handler. |
31 * @param {Event} e The update event. | 51 * @param {Event} e The update event. |
32 */ | 52 */ |
33 function handlePrefUpdate(e) { | 53 function handlePrefUpdate(e) { |
34 DetailsInternetPage.getInstance().updateControls(); | 54 var now = new Date(); |
55 requestUpdateControls(now.getTime()); | |
56 } | |
57 | |
58 /** | |
59 * Throttles the frequency of updating controls to accelerate loading of the | |
60 * page. | |
61 * @param {Number} when Timestamp for the update request. | |
62 */ | |
63 function requestUpdateControls(when) { | |
64 if (when < lastContentsUpdate_) | |
65 return; | |
66 var now = new Date(); | |
67 var time = now.getTime(); | |
68 if (!lastContentsUpdateRequest_) | |
69 lastContentsUpdateRequest_ = time; | |
70 var elapsed = time - lastContentsUpdateRequest_; | |
71 if (elapsed > minimumUpdateContentsDelay_) { | |
72 DetailsInternetPage.getInstance().updateControls(); | |
73 } else { | |
74 setTimeout(function() { | |
75 requestUpdateControls(when); | |
76 }, minimumUpdateContentsDelay_); | |
77 } | |
78 lastContentsUpdateRequest_ = time; | |
35 } | 79 } |
36 | 80 |
37 ///////////////////////////////////////////////////////////////////////////// | 81 ///////////////////////////////////////////////////////////////////////////// |
38 // DetailsInternetPage class: | 82 // DetailsInternetPage class: |
39 | 83 |
40 /** | 84 /** |
41 * Encapsulated handling of ChromeOS internet details overlay page. | 85 * Encapsulated handling of ChromeOS internet details overlay page. |
42 * @constructor | 86 * @constructor |
43 */ | 87 */ |
44 function DetailsInternetPage() { | 88 function DetailsInternetPage() { |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 for (var x = 0; x < selectedItems.length; x++) { | 311 for (var x = 0; x < selectedItems.length; x++) { |
268 $('ignored-host-list').removeException(selectedItems[x]); | 312 $('ignored-host-list').removeException(selectedItems[x]); |
269 } | 313 } |
270 }, | 314 }, |
271 | 315 |
272 /** | 316 /** |
273 * Update details page controls. | 317 * Update details page controls. |
274 * @private | 318 * @private |
275 */ | 319 */ |
276 updateControls: function() { | 320 updateControls: function() { |
321 // Record time of the update to throttle future updates. | |
322 var now = new Date(); | |
323 lastContentsUpdate_ = now.getTime(); | |
324 | |
277 // Only show ipconfig section if network is connected OR if nothing on | 325 // Only show ipconfig section if network is connected OR if nothing on |
278 // this device is connected. This is so that you can fix the ip configs | 326 // this device is connected. This is so that you can fix the ip configs |
279 // if you can't connect to any network. | 327 // if you can't connect to any network. |
280 // TODO(chocobo): Once ipconfig is moved to flimflam service objects, | 328 // TODO(chocobo): Once ipconfig is moved to flimflam service objects, |
281 // we need to redo this logic to allow configuration of all networks. | 329 // we need to redo this logic to allow configuration of all networks. |
282 $('ipconfig-section').hidden = !this.connected && this.deviceConnected; | 330 $('ipconfig-section').hidden = !this.connected && this.deviceConnected; |
283 | 331 |
284 // Network type related. | 332 // Network type related. |
285 updateHidden('#details-internet-page .cellular-details', !this.cellular); | 333 updateHidden('#details-internet-page .cellular-details', !this.cellular); |
286 updateHidden('#details-internet-page .wifi-details', !this.wireless); | 334 updateHidden('#details-internet-page .wifi-details', !this.wireless); |
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
834 | 882 |
835 // Don't show page name in address bar and in history to prevent people | 883 // Don't show page name in address bar and in history to prevent people |
836 // navigate here by hand and solve issue with page session restore. | 884 // navigate here by hand and solve issue with page session restore. |
837 OptionsPage.showPageByName('detailsInternetPage', false); | 885 OptionsPage.showPageByName('detailsInternetPage', false); |
838 }; | 886 }; |
839 | 887 |
840 return { | 888 return { |
841 DetailsInternetPage: DetailsInternetPage | 889 DetailsInternetPage: DetailsInternetPage |
842 }; | 890 }; |
843 }); | 891 }); |
OLD | NEW |