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

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

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

Powered by Google App Engine
This is Rietveld 408576698