| 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 /** | 5 /** | 
| 6  * This partially describes the network list entries passed to | 6  * This partially describes the network list entries passed to | 
| 7  * refreshNetworkData. The contents of those lists actually match | 7  * refreshNetworkData. The contents of those lists actually match | 
| 8  * CrOnc.NetworkConfigType with the addition of the policyManaged property. | 8  * CrOnc.NetworkConfigType with the addition of the policyManaged property. | 
| 9  * TODO(stevenjb): Use networkingPrivate.getNetworks. | 9  * TODO(stevenjb): Use networkingPrivate.getNetworks. | 
| 10  * @typedef {{ | 10  * @typedef {{ | 
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 368         Menu.decorate(menu); | 368         Menu.decorate(menu); | 
| 369         for (var i = 0; i < this.data.menu.length; i++) { | 369         for (var i = 0; i < this.data.menu.length; i++) { | 
| 370           var entry = this.data.menu[i]; | 370           var entry = this.data.menu[i]; | 
| 371           createCallback_(menu, null, entry.label, entry.command); | 371           createCallback_(menu, null, entry.label, entry.command); | 
| 372         } | 372         } | 
| 373         return menu; | 373         return menu; | 
| 374       } | 374       } | 
| 375       return null; | 375       return null; | 
| 376     }, | 376     }, | 
| 377 | 377 | 
|  | 378     /** | 
|  | 379      * Determines if a menu can be updated on the fly. Menus that cannot be | 
|  | 380      * updated are fully regenerated using createMenu. The advantage of | 
|  | 381      * updating a menu is that it can preserve ordering of networks avoiding | 
|  | 382      * entries from jumping around after an update. | 
|  | 383      * @return {boolean} Whether the menu can be updated on the fly. | 
|  | 384      */ | 
| 378     canUpdateMenu: function() { | 385     canUpdateMenu: function() { | 
| 379       return false; | 386       return false; | 
| 380     }, | 387     }, | 
| 381 | 388 | 
| 382     /** | 389     /** | 
|  | 390      * Removes the current menu contents, causing it to be regenerated when the | 
|  | 391      * menu is shown the next time. If the menu is showing right now, its | 
|  | 392      * contents are regenerated immediately and the menu remains visible. | 
|  | 393      */ | 
|  | 394     refreshMenu: function() { | 
|  | 395       this.menu_ = null; | 
|  | 396       if (activeMenu_ == this.getMenuName()) | 
|  | 397         this.showMenu(); | 
|  | 398     }, | 
|  | 399 | 
|  | 400     /** | 
| 383      * Displays a popup menu. | 401      * Displays a popup menu. | 
| 384      */ | 402      */ | 
| 385     showMenu: function() { | 403     showMenu: function() { | 
| 386       var rebuild = false; | 404       var rebuild = false; | 
| 387       // Force a rescan if opening the menu for WiFi networks to ensure the | 405       // Force a rescan if opening the menu for WiFi networks to ensure the | 
| 388       // list is up to date. Networks are periodically rescanned, but depending | 406       // list is up to date. Networks are periodically rescanned, but depending | 
| 389       // on timing, there could be an excessive delay before the first rescan | 407       // on timing, there could be an excessive delay before the first rescan | 
| 390       // unless forced. | 408       // unless forced. | 
| 391       var rescan = !activeMenu_ && this.data_.key == 'WiFi'; | 409       var rescan = !activeMenu_ && this.data_.key == 'WiFi'; | 
| 392       if (!this.menu_) { | 410       if (!this.menu_) { | 
| 393         rebuild = true; | 411         rebuild = true; | 
| 394         var existing = $(this.getMenuName()); | 412         var existing = $(this.getMenuName()); | 
| 395         if (existing) { | 413         if (existing) { | 
| 396           if (this.updateMenu()) | 414           if (this.canUpdateMenu() && this.updateMenu()) | 
| 397             return; | 415             return; | 
| 398           closeMenu_(); | 416           closeMenu_(); | 
| 399         } | 417         } | 
| 400         this.menu_ = this.createMenu(); | 418         this.menu_ = this.createMenu(); | 
| 401         this.menu_.addEventListener('mousedown', function(e) { | 419         this.menu_.addEventListener('mousedown', function(e) { | 
| 402           // Prevent blurring of list, which would close the menu. | 420           // Prevent blurring of list, which would close the menu. | 
| 403           e.preventDefault(); | 421           e.preventDefault(); | 
| 404         }); | 422         }); | 
| 405         var parent = $('network-menus'); | 423         var parent = $('network-menus'); | 
| 406         if (existing) | 424         if (existing) | 
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 490     createMenu: function() { | 508     createMenu: function() { | 
| 491       var menu = this.ownerDocument.createElement('div'); | 509       var menu = this.ownerDocument.createElement('div'); | 
| 492       menu.id = this.getMenuName(); | 510       menu.id = this.getMenuName(); | 
| 493       menu.className = 'network-menu'; | 511       menu.className = 'network-menu'; | 
| 494       menu.hidden = true; | 512       menu.hidden = true; | 
| 495       Menu.decorate(menu); | 513       Menu.decorate(menu); | 
| 496       var addendum = []; | 514       var addendum = []; | 
| 497       if (this.data_.key == 'WiFi') { | 515       if (this.data_.key == 'WiFi') { | 
| 498         addendum.push({ | 516         addendum.push({ | 
| 499           label: loadTimeData.getString('joinOtherNetwork'), | 517           label: loadTimeData.getString('joinOtherNetwork'), | 
| 500           command: createAddConnectionCallback_('WiFi'), | 518           command: createAddNonVPNConnectionCallback_('WiFi'), | 
| 501           data: {} | 519           data: {} | 
| 502         }); | 520         }); | 
| 503       } else if (this.data_.key == 'Cellular') { | 521       } else if (this.data_.key == 'Cellular') { | 
| 504         if (cellularEnabled_ && cellularSupportsScan_) { | 522         if (cellularEnabled_ && cellularSupportsScan_) { | 
| 505           addendum.push({ | 523           addendum.push({ | 
| 506             label: loadTimeData.getString('otherCellularNetworks'), | 524             label: loadTimeData.getString('otherCellularNetworks'), | 
| 507             command: createAddConnectionCallback_('Cellular'), | 525             command: createAddNonVPNConnectionCallback_('Cellular'), | 
| 508             addClass: ['other-cellulars'], | 526             addClass: ['other-cellulars'], | 
| 509             data: {} | 527             data: {} | 
| 510           }); | 528           }); | 
| 511         } | 529         } | 
| 512 | 530 | 
| 513         var label = enableDataRoaming_ ? 'disableDataRoaming' : | 531         var label = enableDataRoaming_ ? 'disableDataRoaming' : | 
| 514             'enableDataRoaming'; | 532             'enableDataRoaming'; | 
| 515         var disabled = !loadTimeData.getValue('loggedInAsOwner'); | 533         var disabled = !loadTimeData.getValue('loggedInAsOwner'); | 
| 516         var entry = {label: loadTimeData.getString(label), | 534         var entry = {label: loadTimeData.getString(label), | 
| 517                      data: {}}; | 535                      data: {}}; | 
| 518         if (disabled) { | 536         if (disabled) { | 
| 519           entry.command = null; | 537           entry.command = null; | 
| 520           entry.tooltip = | 538           entry.tooltip = | 
| 521               loadTimeData.getString('dataRoamingDisableToggleTooltip'); | 539               loadTimeData.getString('dataRoamingDisableToggleTooltip'); | 
| 522         } else { | 540         } else { | 
| 523           var self = this; | 541           var self = this; | 
| 524           entry.command = function() { | 542           entry.command = function() { | 
| 525             options.Preferences.setBooleanPref( | 543             options.Preferences.setBooleanPref( | 
| 526                 'cros.signed.data_roaming_enabled', | 544                 'cros.signed.data_roaming_enabled', | 
| 527                 !enableDataRoaming_, true); | 545                 !enableDataRoaming_, true); | 
| 528             // Force revalidation of the menu the next time it is displayed. | 546             // Force revalidation of the menu the next time it is displayed. | 
| 529             self.menu_ = null; | 547             self.menu_ = null; | 
| 530           }; | 548           }; | 
| 531         } | 549         } | 
| 532         addendum.push(entry); | 550         addendum.push(entry); | 
| 533       } else if (this.data_.key == 'VPN') { | 551       } else if (this.data_.key == 'VPN') { | 
| 534         addendum.push({ | 552         addendum = addendum.concat(createAddVPNConnectionEntries_()); | 
| 535           label: loadTimeData.getString('joinOtherNetwork'), |  | 
| 536           command: createAddConnectionCallback_('VPN'), |  | 
| 537           data: {} |  | 
| 538         }); |  | 
| 539       } | 553       } | 
| 540 | 554 | 
| 541       var list = this.data.rememberedNetworks; | 555       var list = this.data.rememberedNetworks; | 
| 542       if (list && list.length > 0) { | 556       if (list && list.length > 0) { | 
| 543         var callback = function(list) { | 557         var callback = function(list) { | 
| 544           $('remembered-network-list').clear(); | 558           $('remembered-network-list').clear(); | 
| 545           var dialog = options.PreferredNetworks.getInstance(); | 559           var dialog = options.PreferredNetworks.getInstance(); | 
| 546           PageManager.showPageByName('preferredNetworksPage', false); | 560           PageManager.showPageByName('preferredNetworksPage', false); | 
| 547           dialog.update(list); | 561           dialog.update(list); | 
| 548           sendChromeMetricsAction('Options_NetworkShowPreferred'); | 562           sendChromeMetricsAction('Options_NetworkShowPreferred'); | 
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 627             separator = false; | 641             separator = false; | 
| 628           } else if (!separator) { | 642           } else if (!separator) { | 
| 629             menu.appendChild(MenuItem.createSeparator()); | 643             menu.appendChild(MenuItem.createSeparator()); | 
| 630             separator = true; | 644             separator = true; | 
| 631           } | 645           } | 
| 632         } | 646         } | 
| 633       } | 647       } | 
| 634       return menu; | 648       return menu; | 
| 635     }, | 649     }, | 
| 636 | 650 | 
| 637     /** | 651     /** @override */ | 
| 638      * Determines if a menu can be updated on the fly. Menus that cannot be |  | 
| 639      * updated are fully regenerated using createMenu. The advantage of |  | 
| 640      * updating a menu is that it can preserve ordering of networks avoiding |  | 
| 641      * entries from jumping around after an update. |  | 
| 642      */ |  | 
| 643     canUpdateMenu: function() { | 652     canUpdateMenu: function() { | 
| 644       return this.data_.key == 'WiFi' && activeMenu_ == this.getMenuName(); | 653       return this.data_.key == 'WiFi' && activeMenu_ == this.getMenuName(); | 
| 645     }, | 654     }, | 
| 646 | 655 | 
| 647     /** | 656     /** | 
| 648      * Updates an existing menu.  Updated menus preserve ordering of prior | 657      * Updates an existing menu.  Updated menus preserve ordering of prior | 
| 649      * entries.  During the update process, the ordering may differ from the | 658      * entries.  During the update process, the ordering may differ from the | 
| 650      * preferred ordering as determined by the network library.  If the | 659      * preferred ordering as determined by the network library.  If the | 
| 651      * ordering becomes potentially out of sync, then the updated menu is | 660      * ordering becomes potentially out of sync, then the updated menu is | 
| 652      * marked for disposal on close.  Reopening the menu will force a | 661      * marked for disposal on close.  Reopening the menu will force a | 
| 653      * regeneration, which will in turn fix the ordering. | 662      * regeneration, which will in turn fix the ordering. This method must only | 
|  | 663      * be called if canUpdateMenu() returned |true|. | 
| 654      * @return {boolean} True if successfully updated. | 664      * @return {boolean} True if successfully updated. | 
| 655      */ | 665      */ | 
| 656     updateMenu: function() { | 666     updateMenu: function() { | 
| 657       if (!this.canUpdateMenu()) |  | 
| 658         return false; |  | 
| 659       var oldMenu = $(this.getMenuName()); | 667       var oldMenu = $(this.getMenuName()); | 
| 660       var group = oldMenu.getElementsByClassName('network-menu-group')[0]; | 668       var group = oldMenu.getElementsByClassName('network-menu-group')[0]; | 
| 661       if (!group) | 669       if (!group) | 
| 662         return false; | 670         return false; | 
| 663       var newMenu = this.createMenu(); | 671       var newMenu = this.createMenu(); | 
| 664       var discardOnClose = false; | 672       var discardOnClose = false; | 
| 665       var oldNetworkButtons = this.extractNetworkConnectButtons_(oldMenu); | 673       var oldNetworkButtons = this.extractNetworkConnectButtons_(oldMenu); | 
| 666       var newNetworkButtons = this.extractNetworkConnectButtons_(newMenu); | 674       var newNetworkButtons = this.extractNetworkConnectButtons_(newMenu); | 
| 667       for (var key in oldNetworkButtons) { | 675       for (var key in oldNetworkButtons) { | 
| 668         if (newNetworkButtons[key]) { | 676         if (newNetworkButtons[key]) { | 
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 835       this.autoExpands = true; | 843       this.autoExpands = true; | 
| 836       this.dataModel = new ArrayDataModel([]); | 844       this.dataModel = new ArrayDataModel([]); | 
| 837       this.selectionModel = new ListSingleSelectionModel(); | 845       this.selectionModel = new ListSingleSelectionModel(); | 
| 838       this.addEventListener('blur', this.onBlur_.bind(this)); | 846       this.addEventListener('blur', this.onBlur_.bind(this)); | 
| 839       this.selectionModel.addEventListener('change', | 847       this.selectionModel.addEventListener('change', | 
| 840                                            this.onSelectionChange_.bind(this)); | 848                                            this.onSelectionChange_.bind(this)); | 
| 841 | 849 | 
| 842       // Wi-Fi control is always visible. | 850       // Wi-Fi control is always visible. | 
| 843       this.update({key: 'WiFi', networkList: []}); | 851       this.update({key: 'WiFi', networkList: []}); | 
| 844 | 852 | 
| 845       var entryAddWifi = { | 853       this.updateAddConnectionMenuEntries_(); | 
| 846         label: loadTimeData.getString('addConnectionWifi'), |  | 
| 847         command: createAddConnectionCallback_('WiFi') |  | 
| 848       }; |  | 
| 849       var entryAddVPN = { |  | 
| 850         label: loadTimeData.getString('addConnectionVPN'), |  | 
| 851         command: createAddConnectionCallback_('VPN') |  | 
| 852       }; |  | 
| 853       this.update({key: 'addConnection', |  | 
| 854                    iconType: 'add-connection', |  | 
| 855                    menu: [entryAddWifi, entryAddVPN] |  | 
| 856                   }); |  | 
| 857 | 854 | 
| 858       var prefs = options.Preferences.getInstance(); | 855       var prefs = options.Preferences.getInstance(); | 
| 859       prefs.addEventListener('cros.signed.data_roaming_enabled', | 856       prefs.addEventListener('cros.signed.data_roaming_enabled', | 
| 860           function(event) { | 857           function(event) { | 
| 861             enableDataRoaming_ = event.value.value; | 858             enableDataRoaming_ = event.value.value; | 
| 862           }); | 859           }); | 
| 863       this.endBatchUpdates(); | 860       this.endBatchUpdates(); | 
|  | 861 | 
|  | 862       options.VPNProviders.addObserver(this.onVPNProvidersChanged_.bind(this)); | 
| 864     }, | 863     }, | 
| 865 | 864 | 
| 866     /** | 865     /** | 
|  | 866      * Called when the list of VPN providers changes. Refreshes the contents of | 
|  | 867      * menus that list VPN providers. | 
|  | 868      * @private | 
|  | 869      */ | 
|  | 870     onVPNProvidersChanged_: function() { | 
|  | 871       // Refresh the contents of the VPN menu. | 
|  | 872       var index = this.indexOf('VPN'); | 
|  | 873       if (index != undefined) | 
|  | 874         this.getListItemByIndex(index).refreshMenu(); | 
|  | 875 | 
|  | 876       // Refresh the contents of the "add connection" menu. | 
|  | 877       this.updateAddConnectionMenuEntries_(); | 
|  | 878       index = this.indexOf('addConnection'); | 
|  | 879       if (index != undefined) | 
|  | 880         this.getListItemByIndex(index).refreshMenu(); | 
|  | 881     }, | 
|  | 882 | 
|  | 883     /** | 
|  | 884      * Updates the entries in the "add connection" menu, based on the VPN | 
|  | 885      * providers currently enabled in the primary user's profile. | 
|  | 886      * @private | 
|  | 887      */ | 
|  | 888     updateAddConnectionMenuEntries_: function() { | 
|  | 889       var entries = [{ | 
|  | 890         label: loadTimeData.getString('addConnectionWifi'), | 
|  | 891         command: createAddNonVPNConnectionCallback_('WiFi') | 
|  | 892       }]; | 
|  | 893       entries = entries.concat(createAddVPNConnectionEntries_()); | 
|  | 894       this.update({key: 'addConnection', | 
|  | 895                    iconType: 'add-connection', | 
|  | 896                    menu: entries | 
|  | 897                   }); | 
|  | 898     }, | 
|  | 899 | 
|  | 900     /** | 
| 867      * When the list loses focus, unselect all items in the list and close the | 901      * When the list loses focus, unselect all items in the list and close the | 
| 868      * active menu. | 902      * active menu. | 
| 869      * @private | 903      * @private | 
| 870      */ | 904      */ | 
| 871     onBlur_: function() { | 905     onBlur_: function() { | 
| 872       this.selectionModel.unselectAll(); | 906       this.selectionModel.unselectAll(); | 
| 873       closeMenu_(); | 907       closeMenu_(); | 
| 874     }, | 908     }, | 
| 875 | 909 | 
| 876     /** | 910     /** | 
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1211     for (var i = 0; i < networkList.length; i++) { | 1245     for (var i = 0; i < networkList.length; i++) { | 
| 1212       var entry = networkList[i]; | 1246       var entry = networkList[i]; | 
| 1213       if (entry.ConnectionState == 'Connected' || | 1247       if (entry.ConnectionState == 'Connected' || | 
| 1214           entry.ConnectionState == 'Connecting') | 1248           entry.ConnectionState == 'Connecting') | 
| 1215         return entry; | 1249         return entry; | 
| 1216     } | 1250     } | 
| 1217     return null; | 1251     return null; | 
| 1218   } | 1252   } | 
| 1219 | 1253 | 
| 1220   /** | 1254   /** | 
| 1221    * Create a callback function that adds a new connection of the given type. | 1255    * Creates a callback function that adds a new connection of the given type. | 
|  | 1256    * This method may be used for all network types except VPN. | 
| 1222    * @param {string} type An ONC network type | 1257    * @param {string} type An ONC network type | 
| 1223    * @return {function()} The created callback. | 1258    * @return {function()} The created callback. | 
| 1224    * @private | 1259    * @private | 
| 1225    */ | 1260    */ | 
| 1226   function createAddConnectionCallback_(type) { | 1261   function createAddNonVPNConnectionCallback_(type) { | 
| 1227     return function() { | 1262     return function() { | 
| 1228       if (type == 'WiFi') | 1263       if (type == 'WiFi') | 
| 1229         sendChromeMetricsAction('Options_NetworkJoinOtherWifi'); | 1264         sendChromeMetricsAction('Options_NetworkJoinOtherWifi'); | 
| 1230       else if (type == 'VPN') | 1265       chrome.send('addNonVPNConnection', [type]); | 
| 1231         sendChromeMetricsAction('Options_NetworkJoinOtherVPN'); |  | 
| 1232       chrome.send('addConnection', [type]); |  | 
| 1233     }; | 1266     }; | 
| 1234   } | 1267   } | 
| 1235 | 1268 | 
| 1236   /** | 1269   /** | 
|  | 1270    * Creates a callback function that shows the "add network" dialog for a VPN | 
|  | 1271    * provider. If |opt_extensionID| is omitted, the dialog for the built-in | 
|  | 1272    * OpenVPN/L2TP provider is shown. Otherwise, |opt_extensionID| identifies the | 
|  | 1273    * third-party provider for which the dialog should be shown. | 
|  | 1274    * @param {string=} opt_extensionID Extension ID identifying the third-party | 
|  | 1275    *     VPN provider for which the dialog should be shown. | 
|  | 1276    * @return {function()} The created callback. | 
|  | 1277    * @private | 
|  | 1278    */ | 
|  | 1279   function createVPNConnectionCallback_(opt_extensionID) { | 
|  | 1280     return function() { | 
|  | 1281       sendChromeMetricsAction(opt_extensionID ? | 
|  | 1282           'Options_NetworkAddVPNThirdParty' : | 
|  | 1283           'Options_NetworkAddVPNBuiltIn'); | 
|  | 1284       chrome.send('addVPNConnection', | 
|  | 1285                   opt_extensionID ? [opt_extensionID] : undefined); | 
|  | 1286     }; | 
|  | 1287   } | 
|  | 1288 | 
|  | 1289   /** | 
|  | 1290    * Generates an "add network" entry for each VPN provider currently enabled in | 
|  | 1291    * the primary user's profile. | 
|  | 1292    * @return {!Array<{label: string, command: function(), data: !Object}>} The | 
|  | 1293    *     list of entries. | 
|  | 1294    * @private | 
|  | 1295    */ | 
|  | 1296   function createAddVPNConnectionEntries_() { | 
|  | 1297     var entries = []; | 
|  | 1298     var providers = options.VPNProviders.getProviders(); | 
|  | 1299     for (var i = 0; i < providers.length; ++i) { | 
|  | 1300       entries.push({ | 
|  | 1301         label: loadTimeData.getStringF('addConnectionVPNTemplate', | 
|  | 1302                                        providers[i].name), | 
|  | 1303         command: createVPNConnectionCallback_(providers[i].extensionID), | 
|  | 1304         data: {} | 
|  | 1305       }); | 
|  | 1306     } | 
|  | 1307     return entries; | 
|  | 1308   } | 
|  | 1309 | 
|  | 1310   /** | 
| 1237    * Whether the Network list is disabled. Only used for display purpose. | 1311    * Whether the Network list is disabled. Only used for display purpose. | 
| 1238    */ | 1312    */ | 
| 1239   cr.defineProperty(NetworkList, 'disabled', cr.PropertyKind.BOOL_ATTR); | 1313   cr.defineProperty(NetworkList, 'disabled', cr.PropertyKind.BOOL_ATTR); | 
| 1240 | 1314 | 
| 1241   // Export | 1315   // Export | 
| 1242   return { | 1316   return { | 
| 1243     NetworkList: NetworkList | 1317     NetworkList: NetworkList | 
| 1244   }; | 1318   }; | 
| 1245 }); | 1319 }); | 
| OLD | NEW | 
|---|