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

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

Issue 1017443002: 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: Fixed typo; rebased. 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 */
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
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
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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 button.data = {label: label}; 823 button.data = {label: label};
816 MenuItem.decorate(button); 824 MenuItem.decorate(button);
817 menu.appendChild(button); 825 menu.appendChild(button);
818 return button; 826 return button;
819 } 827 }
820 828
821 /** 829 /**
822 * A list of controls for manipulating network connectivity. 830 * A list of controls for manipulating network connectivity.
823 * @constructor 831 * @constructor
824 * @extends {cr.ui.List} 832 * @extends {cr.ui.List}
833 * @implements {options.VPNProviders.Observer}
825 */ 834 */
826 var NetworkList = cr.ui.define('list'); 835 var NetworkList = cr.ui.define('list');
827 836
828 NetworkList.prototype = { 837 NetworkList.prototype = {
829 __proto__: List.prototype, 838 __proto__: List.prototype,
830 839
831 /** @override */ 840 /** @override */
832 decorate: function() { 841 decorate: function() {
833 List.prototype.decorate.call(this); 842 List.prototype.decorate.call(this);
834 this.startBatchUpdates(); 843 this.startBatchUpdates();
835 this.autoExpands = true; 844 this.autoExpands = true;
836 this.dataModel = new ArrayDataModel([]); 845 this.dataModel = new ArrayDataModel([]);
837 this.selectionModel = new ListSingleSelectionModel(); 846 this.selectionModel = new ListSingleSelectionModel();
838 this.addEventListener('blur', this.onBlur_.bind(this)); 847 this.addEventListener('blur', this.onBlur_.bind(this));
839 this.selectionModel.addEventListener('change', 848 this.selectionModel.addEventListener('change',
840 this.onSelectionChange_.bind(this)); 849 this.onSelectionChange_.bind(this));
841 850
842 // Wi-Fi control is always visible. 851 // Wi-Fi control is always visible.
843 this.update({key: 'WiFi', networkList: []}); 852 this.update({key: 'WiFi', networkList: []});
844 853
845 var entryAddWifi = { 854 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 855
858 var prefs = options.Preferences.getInstance(); 856 var prefs = options.Preferences.getInstance();
859 prefs.addEventListener('cros.signed.data_roaming_enabled', 857 prefs.addEventListener('cros.signed.data_roaming_enabled',
860 function(event) { 858 function(event) {
861 enableDataRoaming_ = event.value.value; 859 enableDataRoaming_ = event.value.value;
862 }); 860 });
863 this.endBatchUpdates(); 861 this.endBatchUpdates();
862
863 options.VPNProviders.addObserver(this);
864 }, 864 },
865 865
866 /** 866 /**
867 * Called when the list of VPN providers changes. Refreshes the contents of
868 * menus that list VPN providers.
869 * @override
870 */
871 onVPNProvidersChanged() {
872 // Refresh the contents of the VPN menu.
873 var index = this.indexOf('VPN');
874 if (index != undefined)
875 this.getListItemByIndex(index).refreshMenu();
876
877 // Refresh the contents of the "add connection" menu.
878 this.updateAddConnectionMenuEntries_();
879 index = this.indexOf('addConnection');
880 if (index != undefined)
881 this.getListItemByIndex(index).refreshMenu();
882 },
883
884 /**
885 * Updates the entries in the "add connection" menu, based on the VPN
886 * providers currently enabled in the primary user's profile.
887 * @private
888 */
889 updateAddConnectionMenuEntries_() {
890 var entries = [{
891 label: loadTimeData.getString('addConnectionWifi'),
892 command: createAddNonVPNConnectionCallback_('WiFi')
893 }];
894 entries = entries.concat(createAddVPNConnectionEntries_());
895 this.update({key: 'addConnection',
896 iconType: 'add-connection',
897 menu: entries
898 });
899 },
900
901 /**
867 * When the list loses focus, unselect all items in the list and close the 902 * When the list loses focus, unselect all items in the list and close the
868 * active menu. 903 * active menu.
869 * @private 904 * @private
870 */ 905 */
871 onBlur_: function() { 906 onBlur_: function() {
872 this.selectionModel.unselectAll(); 907 this.selectionModel.unselectAll();
873 closeMenu_(); 908 closeMenu_();
874 }, 909 },
875 910
876 /** 911 /**
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
1211 for (var i = 0; i < networkList.length; i++) { 1246 for (var i = 0; i < networkList.length; i++) {
1212 var entry = networkList[i]; 1247 var entry = networkList[i];
1213 if (entry.ConnectionState == 'Connected' || 1248 if (entry.ConnectionState == 'Connected' ||
1214 entry.ConnectionState == 'Connecting') 1249 entry.ConnectionState == 'Connecting')
1215 return entry; 1250 return entry;
1216 } 1251 }
1217 return null; 1252 return null;
1218 } 1253 }
1219 1254
1220 /** 1255 /**
1221 * Create a callback function that adds a new connection of the given type. 1256 * Creates a callback function that adds a new connection of the given type.
1257 * This method may be used for all network types except VPN.
1222 * @param {string} type An ONC network type 1258 * @param {string} type An ONC network type
1223 * @return {function()} The created callback. 1259 * @return {function()} The created callback.
1224 * @private 1260 * @private
1225 */ 1261 */
1226 function createAddConnectionCallback_(type) { 1262 function createAddNonVPNConnectionCallback_(type) {
1227 return function() { 1263 return function() {
1228 if (type == 'WiFi') 1264 if (type == 'WiFi')
1229 sendChromeMetricsAction('Options_NetworkJoinOtherWifi'); 1265 sendChromeMetricsAction('Options_NetworkJoinOtherWifi');
1230 else if (type == 'VPN') 1266 chrome.send('addNonVPNConnection', [type]);
1231 sendChromeMetricsAction('Options_NetworkJoinOtherVPN');
1232 chrome.send('addConnection', [type]);
1233 }; 1267 };
1234 } 1268 }
1235 1269
1236 /** 1270 /**
1271 * Creates a callback function that shows the "add network" dialog for the
1272 * built-in OpenVPN/L2TP VPN provider.
1273 * @return {function()} The created callback.
1274 * @private
1275 */
1276 function createVPNConnectionWithAddBuiltInProviderCallback_() {
1277 return function() {
1278 sendChromeMetricsAction('Options_NetworkAddVPNBuiltIn');
1279 chrome.send('addVPNConnection');
1280 };
1281 }
1282
1283 /**
1284 * Creates a callback function that asks the third-party VPN provider
1285 * identified by |extensionID| to show its "add network" dialog.
1286 * @param {string} providerID The VPN provider's extension ID.
1287 * @return {function()} The created callback.
1288 * @private
1289 */
1290 function createAddVPNConnectionWithThirdPartyProviderCallback_(extensionID) {
1291 return function() {
1292 sendChromeMetricsAction('Options_NetworkAddVPNThirdParty');
1293 chrome.send('addVPNConnection', [extensionID]);
1294 };
1295 }
1296
1297 /**
1298 * Generates an "add network" entry for each VPN provider currently enabled in
1299 * the primary user's profile.
1300 * @return {!Array<{label: string, command: function(), data: !Object}>} The
1301 * list of entries.
1302 * @private
1303 */
1304 function createAddVPNConnectionEntries_() {
1305 var entries = [];
1306 var providers = options.VPNProviders.getProviders();
1307 for (var i = 0; i < providers.length; ++i) {
1308 entries.push({
1309 label: loadTimeData.getStringF('addConnectionVPNTemplate',
1310 providers[i].name),
1311 command: providers[i].extensionID ?
1312 createAddVPNConnectionWithThirdPartyProviderCallback_(
1313 providers[i].extensionID) :
1314 createVPNConnectionWithAddBuiltInProviderCallback_(),
1315 data: {}
1316 });
1317 }
1318 return entries;
1319 }
1320
1321 /**
1237 * Whether the Network list is disabled. Only used for display purpose. 1322 * Whether the Network list is disabled. Only used for display purpose.
1238 */ 1323 */
1239 cr.defineProperty(NetworkList, 'disabled', cr.PropertyKind.BOOL_ATTR); 1324 cr.defineProperty(NetworkList, 'disabled', cr.PropertyKind.BOOL_ATTR);
1240 1325
1241 // Export 1326 // Export
1242 return { 1327 return {
1243 NetworkList: NetworkList 1328 NetworkList: NetworkList
1244 }; 1329 };
1245 }); 1330 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698