Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(302)

Side by Side Diff: chrome/browser/resources/options2/chromeos/network_list.js

Issue 9584016: [uber page] Implement "use shared proxies" and "add connection". (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.network', function() { 5 cr.define('options.network', function() {
6 6
7 var ArrayDataModel = cr.ui.ArrayDataModel; 7 var ArrayDataModel = cr.ui.ArrayDataModel;
8 var List = cr.ui.List; 8 var List = cr.ui.List;
9 var ListItem = cr.ui.ListItem; 9 var ListItem = cr.ui.ListItem;
10 var Menu = cr.ui.Menu; 10 var Menu = cr.ui.Menu;
(...skipping 14 matching lines...) Expand all
25 Constants.TYPE_CELLULAR = 5; 25 Constants.TYPE_CELLULAR = 5;
26 Constants.TYPE_VPN = 6; 26 Constants.TYPE_VPN = 6;
27 27
28 /** 28 /**
29 * Order in which controls are to appear in the network list sorted by key. 29 * Order in which controls are to appear in the network list sorted by key.
30 */ 30 */
31 Constants.NETWORK_ORDER = ['ethernet', 31 Constants.NETWORK_ORDER = ['ethernet',
32 'wifi', 32 'wifi',
33 'cellular', 33 'cellular',
34 'vpn', 34 'vpn',
35 'airplaneMode']; 35 'airplaneMode',
36 'useSharedProxies',
37 'addConnection'];
36 38
37 /** 39 /**
38 * Mapping of network category titles to the network type. 40 * Mapping of network category titles to the network type.
39 */ 41 */
40 var categoryMap = { 42 var categoryMap = {
41 'cellular': Constants.TYPE_CELLULAR, 43 'cellular': Constants.TYPE_CELLULAR,
42 'ethernet': Constants.TYPE_ETHERNET, 44 'ethernet': Constants.TYPE_ETHERNET,
43 'wifi': Constants.TYPE_WIFI, 45 'wifi': Constants.TYPE_WIFI,
44 'vpn': Constants.TYPE_VPN 46 'vpn': Constants.TYPE_VPN
45 }; 47 };
46 48
47 /** 49 /**
48 * ID of the menu that is currently visible. 50 * ID of the menu that is currently visible.
49 * @type {?string} 51 * @type {?string}
50 * @private 52 * @private
51 */ 53 */
52 var activeMenu_ = null; 54 var activeMenu_ = null;
53 55
54 /** 56 /**
55 * Indicates if cellular networks are available. 57 * Indicates if cellular networks are available.
56 * @type{boolean} 58 * @type {boolean}
57 * @private 59 * @private
58 */ 60 */
59 var cellularAvailable_ = false; 61 var cellularAvailable_ = false;
60 62
61 /** 63 /**
62 * Indicates if cellular networks are enabled. 64 * Indicates if cellular networks are enabled.
63 * @type{boolean} 65 * @type {boolean}
64 * @private 66 * @private
65 */ 67 */
66 var cellularEnabled_ = false; 68 var cellularEnabled_ = false;
67 69
68 /** 70 /**
71 * Indicates if shared proxies are enabled.
72 * @type {boolean}
73 * @private
74 */
75 var useSharedProxies_ = false;
76
77 /**
69 * Create an element in the network list for controlling network 78 * Create an element in the network list for controlling network
70 * connectivity. 79 * connectivity.
71 * @param {Object} data Description of the network list or command. 80 * @param {Object} data Description of the network list or command.
72 * @constructor 81 * @constructor
73 */ 82 */
74 function NetworkListItem(data) { 83 function NetworkListItem(data) {
75 var el = cr.doc.createElement('li'); 84 var el = cr.doc.createElement('li');
76 el.data_ = {}; 85 el.data_ = {};
77 for (var key in data) 86 for (var key in data)
78 el.data_[key] = data[key]; 87 el.data_[key] = data[key];
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 */ 135 */
127 get data() { 136 get data() {
128 return this.data_; 137 return this.data_;
129 }, 138 },
130 139
131 /** 140 /**
132 * Text label for the subtitle. 141 * Text label for the subtitle.
133 * @type {string} 142 * @type {string}
134 */ 143 */
135 set subtitle(text) { 144 set subtitle(text) {
136 this.subtitle_.textContent = text; 145 if (text)
146 this.subtitle_.textContent = text;
147 this.subtitle_.hidden = !text;
137 }, 148 },
138 149
139 /** 150 /**
140 * URL for the network icon. 151 * URL for the network icon.
141 * @type {string} 152 * @type {string}
142 */ 153 */
143 set iconURL(iconURL) { 154 set iconURL(iconURL) {
144 this.icon_.style.backgroundImage = url(iconURL); 155 this.icon_.style.backgroundImage = url(iconURL);
145 }, 156 },
146 157
(...skipping 12 matching lines...) Expand all
159 set connecting(state) { 170 set connecting(state) {
160 this.connecting_ = state; 171 this.connecting_ = state;
161 if (state) 172 if (state)
162 this.icon_.classList.add('network-connecting'); 173 this.icon_.classList.add('network-connecting');
163 else 174 else
164 this.icon_.classList.remove('network-connecting'); 175 this.icon_.classList.remove('network-connecting');
165 }, 176 },
166 177
167 /** 178 /**
168 * Indicates if the network is in the process of being connected. 179 * Indicates if the network is in the process of being connected.
169 * @type{boolean} 180 * @type {boolean}
170 */ 181 */
171 get connecting() { 182 get connecting() {
172 return this.connecting_; 183 return this.connecting_;
173 }, 184 },
174 185
175 /** 186 /**
176 * Indicate that the selector arrow should be shown. 187 * Indicate that the selector arrow should be shown.
177 */ 188 */
178 showSelector: function() { 189 showSelector: function() {
179 this.subtitle_.classList.add('network-selector'); 190 this.subtitle_.classList.add('network-selector');
180 }, 191 },
181 192
182 /* @inheritDoc */ 193 /* @inheritDoc */
183 decorate: function() { 194 decorate: function() {
184 ListItem.prototype.decorate.call(this); 195 ListItem.prototype.decorate.call(this);
185 this.className = 'network-group'; 196 this.className = 'network-group';
186 this.icon_ = this.ownerDocument.createElement('div'); 197 this.icon_ = this.ownerDocument.createElement('div');
187 this.icon_.className = 'network-icon'; 198 this.icon_.className = 'network-icon';
188 this.appendChild(this.icon_); 199 this.appendChild(this.icon_);
189 var textContent = this.ownerDocument.createElement('div'); 200 var textContent = this.ownerDocument.createElement('div');
201 textContent.className = 'network-group-labels';
190 this.appendChild(textContent); 202 this.appendChild(textContent);
191 var categoryLabel = this.ownerDocument.createElement('div'); 203 var categoryLabel = this.ownerDocument.createElement('div');
192 var title = this.data_.key + 'Title'; 204 var title = this.data_.key + 'Title';
193 categoryLabel.className = 'network-title'; 205 categoryLabel.className = 'network-title';
194 categoryLabel.textContent = templateData[title]; 206 categoryLabel.textContent = templateData[title];
195 textContent.appendChild(categoryLabel); 207 textContent.appendChild(categoryLabel);
196 this.subtitle_ = this.ownerDocument.createElement('div'); 208 this.subtitle_ = this.ownerDocument.createElement('div');
197 this.subtitle_.className = 'network-subtitle'; 209 this.subtitle_.className = 'network-subtitle';
198 textContent.appendChild(this.subtitle_); 210 textContent.appendChild(this.subtitle_);
199 }, 211 },
200 }; 212 };
201 213
202 /** 214 /**
215 * Creates a control that displays a popup menu when clicked.
216 * @param {Object} data Description of the control.
217 */
218 function NetworkMenuItem(data) {
219 var el = new NetworkListItem(data);
220 el.__proto__ = NetworkMenuItem.prototype;
221 el.decorate();
222 return el;
223 }
224
225 NetworkMenuItem.prototype = {
226 __proto__: NetworkListItem.prototype,
227
228 /**
229 * Popup menu element.
230 * @type {?Element}
231 * @private
232 */
233 menu_: null,
234
235 /* @inheritDoc */
236 decorate: function() {
237 this.subtitle = null;
238 if (this.data.iconType)
239 this.iconType = this.data.iconType;
240 if (!this.connecting) {
241 this.addEventListener('click', function() {
242 this.showMenu();
243 });
244 }
245 },
246
247 /**
248 * Retrieves the ID for the menu.
249 * @private
250 */
251 getMenuName_: function() {
252 return this.data_.key + '-network-menu';
253 },
254
255 /**
256 * Creates a popup menu for the control.
257 * @return {Element} The newly created menu.
258 */
259 createMenu: function() {
260 if (this.data.menu) {
261 var menu = this.ownerDocument.createElement('div');
262 menu.id = this.getMenuName_();
263 menu.className = 'network-menu';
264 menu.hidden = true;
265 Menu.decorate(menu);
266 for (var i = 0; i < this.data.menu.length; i++) {
267 var entry = this.data.menu[i];
268 var button = this.ownerDocument.createElement('div');
269 button.className = 'network-menu-item';
270 button.textContent = entry.label;
271 button.addEventListener('click', entry.command);
272 MenuItem.decorate(button);
273 menu.appendChild(button);
274 }
275 return menu;
276 }
277 return null;
278 },
279
280 /**
281 * Displays a popup menu.
282 */
283 showMenu: function() {
284 if (!this.menu_) {
285 this.menu_ = this.createMenu();
286 var parent = $('network-menus');
287 var existing = $(this.menu_.id);
288 if (existing)
289 parent.replaceChild(this.menu_, existing);
290 else
291 parent.appendChild(this.menu_);
292 }
293 var top = this.offsetTop + this.clientHeight;
294 var menuId = this.getMenuName_();
295 if (menuId != activeMenu_) {
296 closeMenu_();
297 activeMenu_ = menuId;
298 this.menu_.style.setProperty('top', top + 'px');
299 this.menu_.hidden = false;
300 setTimeout(function() {
301 $('settings').addEventListener('click', closeMenu_);
302 }, 0);
303 }
304 },
305
306 };
307
308
309 /**
203 * Creates a control for selecting or configuring a network connection based 310 * Creates a control for selecting or configuring a network connection based
204 * on the type of connection (e.g. wifi versus vpn). 311 * on the type of connection (e.g. wifi versus vpn).
205 * @param{{key: string, 312 * @param {{key: string,
206 * networkList: Array.<Object>} data Description of the network. 313 * networkList: Array.<Object>} data Description of the network.
207 * @constructor 314 * @constructor
208 */ 315 */
209 function NetworkSelectorItem(data) { 316 function NetworkSelectorItem(data) {
210 var el = new NetworkListItem(data); 317 var el = new NetworkMenuItem(data);
211 el.__proto__ = NetworkSelectorItem.prototype; 318 el.__proto__ = NetworkSelectorItem.prototype;
212 el.decorate(); 319 el.decorate();
213 return el; 320 return el;
214 } 321 }
215 322
216 NetworkSelectorItem.prototype = { 323 NetworkSelectorItem.prototype = {
217 __proto__: NetworkListItem.prototype, 324 __proto__: NetworkMenuItem.prototype,
218 325
219 /* @inheritDoc */ 326 /* @inheritDoc */
220 decorate: function() { 327 decorate: function() {
221 this.createMenu_();
222 // TODO(kevers): Generalize method of setting default label. 328 // TODO(kevers): Generalize method of setting default label.
223 var defaultMessage = this.data_.key == 'wifi' ? 329 var defaultMessage = this.data_.key == 'wifi' ?
224 'networkOffline' : 'networkNotConnected'; 330 'networkOffline' : 'networkNotConnected';
225 this.subtitle = templateData[defaultMessage]; 331 this.subtitle = templateData[defaultMessage];
226 var list = this.data_.networkList; 332 var list = this.data_.networkList;
227 var candidateURL = null; 333 var candidateURL = null;
228 for (var i = 0; i < list.length; i++) { 334 for (var i = 0; i < list.length; i++) {
229 var networkDetails = list[i]; 335 var networkDetails = list[i];
230 if (networkDetails.connecting || networkDetails.connected) { 336 if (networkDetails.connecting || networkDetails.connected) {
231 this.subtitle = networkDetails.networkName; 337 this.subtitle = networkDetails.networkName;
232 candidateURL = networkDetails.iconURL; 338 candidateURL = networkDetails.iconURL;
233 // Only break when we see a connecting network as it is possible to 339 // Only break when we see a connecting network as it is possible to
234 // have a connected network and a connecting network at the same 340 // have a connected network and a connecting network at the same
235 // time. 341 // time.
236 if (networkDetails.connecting) { 342 if (networkDetails.connecting) {
237 this.connecting = true; 343 this.connecting = true;
238 candidateURL = null; 344 candidateURL = null;
239 break; 345 break;
240 } 346 }
241 } 347 }
242 } 348 }
243 if (candidateURL) 349 if (candidateURL)
244 this.iconURL = candidateURL; 350 this.iconURL = candidateURL;
245 else 351 else
246 this.iconType = this.data.key; 352 this.iconType = this.data.key;
247 if (!this.connecting) { 353
248 this.addEventListener('click', function() { 354 if (!this.connecting)
249 this.showMenu();
250 });
251 this.showSelector(); 355 this.showSelector();
252 } 356
253 // TODO(kevers): Add default icon for VPN when disconnected or in the 357 // TODO(kevers): Add default icon for VPN when disconnected or in the
254 // process of connecting. 358 // process of connecting.
255 }, 359 },
256 360
257 /** 361 /**
258 * Creates a menu for selecting, configuring or disconnecting from a 362 * Creates a menu for selecting, configuring or disconnecting from a
259 * network. 363 * network.
260 * @private 364 * @return {Element} The newly created menu.
261 */ 365 */
262 createMenu_: function() { 366 createMenu: function() {
263 var menu = this.ownerDocument.createElement('div'); 367 var menu = this.ownerDocument.createElement('div');
264 menu.id = this.getMenuName_(); 368 menu.id = this.getMenuName_();
265 menu.className = 'network-menu'; 369 menu.className = 'network-menu';
266 menu.hidden = true; 370 menu.hidden = true;
267 Menu.decorate(menu); 371 Menu.decorate(menu);
268 var addendum = []; 372 var addendum = [];
269 if (this.data_.key == 'wifi') { 373 if (this.data_.key == 'wifi') {
270 addendum.push({label: localStrings.getString('joinOtherNetwork'), 374 addendum.push({label: localStrings.getString('joinOtherNetwork'),
271 command: 'connect', 375 command: 'connect',
272 data: {networkType: Constants.TYPE_WIFI, 376 data: {networkType: Constants.TYPE_WIFI,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 value.data, 452 value.data,
349 value.label, 453 value.label,
350 value.command); 454 value.command);
351 separator = false; 455 separator = false;
352 } else if (!separator) { 456 } else if (!separator) {
353 menu.appendChild(MenuItem.createSeparator()); 457 menu.appendChild(MenuItem.createSeparator());
354 separator = true; 458 separator = true;
355 } 459 }
356 } 460 }
357 } 461 }
358 var parent = $('network-menus'); 462 return menu;
359 var existing = $(menu.id);
360 if (existing)
361 parent.replaceChild(menu, existing);
362 else
363 parent.appendChild(menu);
364 }, 463 },
365 464
366 /** 465 /**
367 * Adds a command to a menu for modifying network settings. 466 * Adds a command to a menu for modifying network settings.
368 * @param {!Element} menu Parent menu. 467 * @param {!Element} menu Parent menu.
369 * @param {Object} data Description of the network. 468 * @param {Object} data Description of the network.
370 * @param {string} label Display name for the menu item. 469 * @param {string} label Display name for the menu item.
371 * @param {string|function} command Callback function or name 470 * @param {string|function} command Callback function or name
372 * of the command for |buttonClickCallback|. 471 * of the command for |buttonClickCallback|.
373 * @return {!Element} The created menu item. 472 * @return {!Element} The created menu item.
(...skipping 28 matching lines...) Expand all
402 * @param {!Element} menu Parent menu. 501 * @param {!Element} menu Parent menu.
403 * @param {Object} data Description of the network. 502 * @param {Object} data Description of the network.
404 * @private 503 * @private
405 */ 504 */
406 createConnectCallback_: function(menu, data) { 505 createConnectCallback_: function(menu, data) {
407 var menuItem = this.createCallback_(menu, 506 var menuItem = this.createCallback_(menu,
408 data, 507 data,
409 data.networkName, 508 data.networkName,
410 'connect'); 509 'connect');
411 menuItem.style.backgroundImage = url(data.iconURL); 510 menuItem.style.backgroundImage = url(data.iconURL);
412 }, 511 }
413
414 /**
415 * Retrieves the ID for the menu.
416 * @private
417 */
418 getMenuName_: function() {
419 return this.data_.key + '-network-menu';
420 },
421
422 /**
423 * Displays a popup menu.
424 */
425 showMenu: function() {
426 var top = this.offsetTop + this.clientHeight;
427 var menuId = this.getMenuName_();
428 if (menuId != activeMenu_) {
429 closeMenu_();
430 activeMenu_ = menuId;
431 var menu = $(menuId);
432 menu.style.setProperty('top', top + 'px');
433 menu.hidden = false;
434 setTimeout(function() {
435 $('settings').addEventListener('click', closeMenu_);
436 }, 0);
437 }
438 },
439 }; 512 };
440 513
441
442 /** 514 /**
443 * Creates a button-like control for configurating internet connectivity. 515 * Creates a button-like control for configurating internet connectivity.
444 * @param{{key: string, 516 * @param {{key: string,
445 * subtitle: string, 517 * subtitle: string,
446 * command: function} data Description of the network control. 518 * command: function} data Description of the network control.
447 * @constructor 519 * @constructor
448 */ 520 */
449 function NetworkButtonItem(data) { 521 function NetworkButtonItem(data) {
450 var el = new NetworkListItem(data); 522 var el = new NetworkListItem(data);
451 el.__proto__ = NetworkButtonItem.prototype; 523 el.__proto__ = NetworkButtonItem.prototype;
452 el.decorate(); 524 el.decorate();
453 return el; 525 return el;
454 } 526 }
455 527
456 NetworkButtonItem.prototype = { 528 NetworkButtonItem.prototype = {
457 __proto__: NetworkListItem.prototype, 529 __proto__: NetworkListItem.prototype,
458 530
459 /** @inheritDoc */ 531 /** @inheritDoc */
460 decorate: function() { 532 decorate: function() {
461 if (this.data.subtitle) 533 if (this.data.subtitle)
462 this.subtitle = this.data.subtitle; 534 this.subtitle = this.data.subtitle;
463 if (this.data.command) 535 else
464 this.addEventListener('click', this.data.command); 536 this.subtitle = null;
465 if (this.data.iconURL) 537 if (this.data.command)
466 this.iconURL = this.data.iconURL; 538 this.addEventListener('click', this.data.command);
467 else if (this.data.iconType) 539 if (this.data.iconURL)
468 this.iconType = this.data.iconType; 540 this.iconURL = this.data.iconURL;
541 else if (this.data.iconType)
542 this.iconType = this.data.iconType;
469 }, 543 },
470 }; 544 };
471 545
472 /** 546 /**
473 * A list of controls for manipulating network connectivity. 547 * A list of controls for manipulating network connectivity.
474 * @constructor 548 * @constructor
475 */ 549 */
476 var NetworkList = cr.ui.define('list'); 550 var NetworkList = cr.ui.define('list');
477 551
478 NetworkList.prototype = { 552 NetworkList.prototype = {
479 __proto__: List.prototype, 553 __proto__: List.prototype,
480 554
481 /** @inheritDoc */ 555 /** @inheritDoc */
482 decorate: function() { 556 decorate: function() {
483 List.prototype.decorate.call(this); 557 List.prototype.decorate.call(this);
484 this.addEventListener('blur', this.onBlur_); 558 this.addEventListener('blur', this.onBlur_);
485 this.dataModel = new ArrayDataModel([]); 559 this.dataModel = new ArrayDataModel([]);
560
561 // Wi-Fi control is always visible.
486 this.update({key: 'wifi', networkList: []}); 562 this.update({key: 'wifi', networkList: []});
487 this.update({key: 'airplaneMode', 563
488 subtitle: localStrings.getString('airplaneModeLabel'), 564 if (airplaneModeAvailable_()) {
565 this.update({key: 'airplaneMode',
566 subtitle: localStrings.getString('airplaneModeLabel'),
567 command: function() {
568 chrome.send('toggleAirplaneMode');
569 }});
570 }
571 // TODO(kevers): Move to details dialog once settable on a per network
572 // basis.
573 this.update({key: 'useSharedProxies',
489 command: function() { 574 command: function() {
490 chrome.send('toggleAirplaneMode'); 575 options.Preferences.setBooleanPref(
576 'settings.use_shared_proxies',
577 !useSharedProxies_);
491 }}); 578 }});
579
580 // Add connection control.
581 var addConnection = function(type) {
582 var callback = function() {
583 console.log('fired callback to add a connection');
csilv 2012/03/03 02:21:41 delete console.log (unless you really need it to b
kevers 2012/03/05 14:33:02 Done.
584 chrome.send('buttonClickCallback',
585 [String(type), '?', 'connect']);
586 }
587 return callback;
588 }
589 this.update({key: 'addConnection',
590 iconType: 'add-connection',
591 menu: [{label: localStrings.getString('addConnectionWifi'),
592 command: addConnection(Constants.TYPE_WIFI)},
593 {label: localStrings.getString('addConnectionVPN'),
594 command: addConnection(Constants.TYPE_VPN)}]
595 });
596
597 var prefs = options.Preferences.getInstance();
598 prefs.addEventListener('settings.use_shared_proxies', function(event) {
599 useSharedProxies_ = event.value && event.value['value'] !=
600 undefined ? event.value['value'] : event.value;
601 $('network-list').updateToggleControl('useSharedProxies',
602 useSharedProxies_);
603 });
492 }, 604 },
493 605
494 /** 606 /**
495 * When the list loses focus, unselect all items in the list. 607 * When the list loses focus, unselect all items in the list.
496 * @private 608 * @private
497 */ 609 */
498 onBlur_: function() { 610 onBlur_: function() {
499 this.selectionModel.unselectAll(); 611 this.selectionModel.unselectAll();
500 }, 612 },
501 613
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 this.dataModel.splice(index, 1, data); 667 this.dataModel.splice(index, 1, data);
556 } 668 }
557 }, 669 },
558 670
559 /** @inheritDoc */ 671 /** @inheritDoc */
560 createItem: function(entry) { 672 createItem: function(entry) {
561 if (entry.networkList) 673 if (entry.networkList)
562 return new NetworkSelectorItem(entry); 674 return new NetworkSelectorItem(entry);
563 if (entry.command) 675 if (entry.command)
564 return new NetworkButtonItem(entry); 676 return new NetworkButtonItem(entry);
677 if (entry.menu)
678 return new NetworkMenuItem(entry);
565 }, 679 },
566 680
567 /** 681 /**
568 * Deletes an element from the list. 682 * Deletes an element from the list.
569 * @param{string} key Unique identifier for the element. 683 * @param {string} key Unique identifier for the element.
570 */ 684 */
571 deleteItem: function(key) { 685 deleteItem: function(key) {
572 var index = this.indexOf(key); 686 var index = this.indexOf(key);
687 if (index != undefined)
688 this.dataModel.splice(index, 1);
689 },
690
691 updateToggleControl: function(key, active) {
csilv 2012/03/03 02:21:41 comment method
kevers 2012/03/05 14:33:02 Done.
692 var index = this.indexOf(key);
573 if (index != undefined) { 693 if (index != undefined) {
574 var entry = this.dataModel.item(index); 694 var entry = this.dataModel.item(index);
575 this.dataModel.splice(index, 1); 695 entry.iconType = active ? 'control-active' :
696 'control-inactive';
697 this.update(entry);
576 } 698 }
577 } 699 }
578 }; 700 };
579 701
580 /** 702 /**
581 * Chrome callback for updating network controls. 703 * Chrome callback for updating network controls.
582 * @param {Object} data Description of available network devices and their 704 * @param {Object} data Description of available network devices and their
583 * corresponding state. 705 * corresponding state.
584 */ 706 */
585 NetworkList.refreshNetworkData = function(data) { 707 NetworkList.refreshNetworkData = function(data) {
708 var networkList = $('network-list');
586 cellularAvailable_ = data.cellularAvailable; 709 cellularAvailable_ = data.cellularAvailable;
587 cellularEnabled_ = data.cellularEnabled; 710 cellularEnabled_ = data.cellularEnabled;
588 711
589 // Only show Ethernet control if connected. 712 // Only show Ethernet control if connected.
590 var ethernetConnection = getConnection_(data.wiredList); 713 var ethernetConnection = getConnection_(data.wiredList);
591 if (ethernetConnection) { 714 if (ethernetConnection) {
592 var type = String(Constants.TYPE_ETHERNET); 715 var type = String(Constants.TYPE_ETHERNET);
593 var path = ethernetConnection.servicePath; 716 var path = ethernetConnection.servicePath;
594 var ethernetOptions = function() { 717 var ethernetOptions = function() {
595 chrome.send('buttonClickCallback', 718 chrome.send('buttonClickCallback',
596 [type, path, 'options']); 719 [type, path, 'options']);
597 }; 720 };
598 $('network-list').update({key: 'ethernet', 721 networkList.update({key: 'ethernet',
599 subtitle: localStrings.getString('networkConnected'), 722 subtitle: localStrings.getString('networkConnected'),
600 iconURL: ethernetConnection.iconURL, 723 iconURL: ethernetConnection.iconURL,
601 command: ethernetOptions}); 724 command: ethernetOptions});
602 } else { 725 } else {
603 $('network-list').deleteItem('ethernet'); 726 networkList.deleteItem('ethernet');
604 } 727 }
605 728
606 if (data.wifiEnabled) { 729 if (data.wifiEnabled) {
607 loadData_('wifi', data.wirelessList, data.rememberedList); 730 loadData_('wifi', data.wirelessList, data.rememberedList);
608 } else { 731 } else {
609 var enableWifi = function() { 732 var enableWifi = function() {
610 chrome.send('enableWifi'); 733 chrome.send('enableWifi');
611 }; 734 };
612 $('network-list').update({key: 'wifi', 735 networkList.update({key: 'wifi',
613 subtitle: localStrings.getString('networkDisabled'), 736 subtitle: localStrings.getString('networkDisabled'),
614 iconType: 'wifi', 737 iconType: 'wifi',
615 command: enableWifi}); 738 command: enableWifi});
616 } 739 }
617 740
618 // Only show cellular control if available and not in airplane mode. 741 // Only show cellular control if available and not in airplane mode.
619 if (data.cellularAvailable && !data.airplaneMode) { 742 if (data.cellularAvailable && !data.airplaneMode) {
620 if (data.cellularEnabled) { 743 if (data.cellularEnabled) {
621 loadData_('cellular', data.wirelessList, data.rememberedList); 744 loadData_('cellular', data.wirelessList, data.rememberedList);
622 } else { 745 } else {
623 var subtitle = localStrings.getString('networkDisabled'); 746 var subtitle = localStrings.getString('networkDisabled');
624 var enableCellular = function() { 747 var enableCellular = function() {
625 chrome.send('enableCellular'); 748 chrome.send('enableCellular');
626 }; 749 };
627 $('network-list').update({key: 'cellular', 750 networkList.update({key: 'cellular',
628 subtitle: subtitle, 751 subtitle: subtitle,
629 iconType: 'cellular', 752 iconType: 'cellular',
630 command: enableCellular}); 753 command: enableCellular});
631 } 754 }
632 } else { 755 } else {
633 $('network-list').deleteItem('cellular'); 756 networkList.deleteItem('cellular');
634 } 757 }
635 758
636 // Only show VPN control if there is an internet connection. 759 // Only show VPN control if there is an available network and an internet
637 if (ethernetConnection || isConnected_(data.wirelessList)) 760 // connection.
761 if (data.vpnList.length > 0 && (ethernetConnection ||
762 isConnected_(data.wirelessList)))
638 loadData_('vpn', data.vpnList, data.rememberedList); 763 loadData_('vpn', data.vpnList, data.rememberedList);
639 else 764 else
640 $('network-list').deleteItem('vpn'); 765 networkList.deleteItem('vpn');
641 766
642 $('network-list').invalidate(); 767 networkList.updateToggleControl('airplaneMode', data.airplaneMode);
643 $('network-list').redraw(); 768
769 networkList.invalidate();
770 networkList.redraw();
644 }; 771 };
645 772
646 /** 773 /**
647 * Updates the list of available networks and their status, filtered by 774 * Updates the list of available networks and their status, filtered by
648 * network type. 775 * network type.
649 * @param {string} category The type of network. 776 * @param {string} category The type of network.
650 * @param {Array} available The list of available networks and their status. 777 * @param {Array} available The list of available networks and their status.
651 * @param {Array} remembered The list of remmebered networks. 778 * @param {Array} remembered The list of remmebered networks.
652 */ 779 */
653 function loadData_(category, available, remembered) { 780 function loadData_(category, available, remembered) {
(...skipping 24 matching lines...) Expand all
678 if (activeMenu_) { 805 if (activeMenu_) {
679 $(activeMenu_).hidden = true; 806 $(activeMenu_).hidden = true;
680 activeMenu_ = null; 807 activeMenu_ = null;
681 $('settings').removeEventListener('click', closeMenu_); 808 $('settings').removeEventListener('click', closeMenu_);
682 } 809 }
683 } 810 }
684 811
685 /** 812 /**
686 * Determines if the user is connected to or in the process of connecting to 813 * Determines if the user is connected to or in the process of connecting to
687 * a wireless network. 814 * a wireless network.
688 * @param{Array.<Object>} networkList List of networks. 815 * @param {Array.<Object>} networkList List of networks.
689 * @return{boolean} True if connected or connecting to a network. 816 * @return {boolean} True if connected or connecting to a network.
690 * @private 817 * @private
691 */ 818 */
692 function isConnected_(networkList) { 819 function isConnected_(networkList) {
693 return getConnection_(networkList) != null; 820 return getConnection_(networkList) != null;
694 } 821 }
695 822
696 /** 823 /**
697 * Fetches the active connection. 824 * Fetches the active connection.
698 * @param{Array.<Object>} networkList List of networks. 825 * @param {Array.<Object>} networkList List of networks.
699 * @return{boolean} True if connected or connecting to a network. 826 * @return {boolean} True if connected or connecting to a network.
700 * @private 827 * @private
701 */ 828 */
702 function getConnection_(networkList) { 829 function getConnection_(networkList) {
703 if (!networkList) 830 if (!networkList)
704 return null; 831 return null;
705 for (var i = 0; i < networkList.length; i++) { 832 for (var i = 0; i < networkList.length; i++) {
706 var entry = networkList[i]; 833 var entry = networkList[i];
707 if (entry.connected || entry.connecting) 834 if (entry.connected || entry.connecting)
708 return entry; 835 return entry;
709 } 836 }
710 return null; 837 return null;
711 } 838 }
712 839
840 /**
841 * Queries if airplane mode is available.
842 * @return {boolean} Indicates if airplane mode is available.
843 * @private
844 */
845 function airplaneModeAvailable_() {
846 // TODO(kevers): Use library callback to determine if airplane mode is
847 // available once back-end suport is in place.
848 return false;
849 }
850
713 // Export 851 // Export
714 return { 852 return {
715 NetworkList: NetworkList 853 NetworkList: NetworkList
716 }; 854 };
717 }); 855 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698