Chromium Code Reviews| 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 // require: onc_data.js | 5 // require: onc_data.js |
| 6 | 6 |
| 7 // NOTE(stevenjb): This code is in the process of being converted to be | 7 // NOTE(stevenjb): This code is in the process of being converted to be |
| 8 // compatible with the networkingPrivate extension API: | 8 // compatible with the networkingPrivate extension API: |
| 9 // * The network property dictionaries are being converted to use ONC values. | 9 // * The network property dictionaries are being converted to use ONC values. |
| 10 // * chrome.send calls will be replaced with an API object that simulates the | 10 // * chrome.send calls will be replaced with an API object that simulates the |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 * Simple helper method for converting a field to a string. It is used to | 65 * Simple helper method for converting a field to a string. It is used to |
| 66 * easily assign an empty string from fields that may be unknown or undefined. | 66 * easily assign an empty string from fields that may be unknown or undefined. |
| 67 * @param {object} value that should be converted to a string. | 67 * @param {object} value that should be converted to a string. |
| 68 * @return {string} the result. | 68 * @return {string} the result. |
| 69 */ | 69 */ |
| 70 function stringFromValue(value) { | 70 function stringFromValue(value) { |
| 71 return value ? String(value) : ''; | 71 return value ? String(value) : ''; |
| 72 } | 72 } |
| 73 | 73 |
| 74 /** | 74 /** |
| 75 * @param {string} action An action to send to coreOptionsUserMetricsAction. | |
| 76 */ | |
| 77 function sendChromeMetricsAction(action) { | |
| 78 chrome.send('coreOptionsUserMetricsAction', [action]); | |
| 79 } | |
| 80 | |
| 81 /** | |
| 75 * Sends the 'checked' state of a control to chrome for a network. | 82 * Sends the 'checked' state of a control to chrome for a network. |
| 76 * @param {string} path The service path of the network. | 83 * @param {string} path The service path of the network. |
| 77 * @param {string} message The message to send to chrome. | 84 * @param {string} message The message to send to chrome. |
| 78 * @param {HTMLInputElement} checkbox The checkbox storing the value to send. | 85 * @param {HTMLInputElement} checkbox The checkbox storing the value to send. |
| 86 * @param {string=} opt_action Optional action to record. | |
| 79 */ | 87 */ |
| 80 function sendCheckedIfEnabled(path, message, checkbox) { | 88 function sendCheckedIfEnabled(path, message, checkbox, opt_action) { |
| 81 if (!checkbox.hidden && !checkbox.disabled) | 89 if (!checkbox.hidden && !checkbox.disabled) { |
| 82 chrome.send(message, [path, checkbox.checked ? 'true' : 'false']); | 90 chrome.send(message, [path, checkbox.checked ? 'true' : 'false']); |
| 91 if (opt_action) | |
| 92 sendChromeMetricsAction(opt_action); | |
| 93 } | |
| 83 } | 94 } |
| 84 | 95 |
| 85 /** | 96 /** |
| 97 * Send metrics to Chrome when the detailed page is opened. | |
| 98 * @param {string} type The ONC type of the network being shown. | |
| 99 * @param {string} state The ONC network state. | |
| 100 */ | |
| 101 function sendMetrics(type, state) { | |
|
armansito
2014/09/15 14:44:52
Should this be called "sendShowDetailsStateMetrics
stevenjb
2014/09/15 22:51:51
Done.
| |
| 102 if (type == 'WiFi') { | |
| 103 sendChromeMetricsAction('Options_NetworkShowDetailsWifi'); | |
| 104 if (state != 'NotConnected') | |
| 105 sendChromeMetricsAction('Options_NetworkShowDetailsWifiConnected'); | |
| 106 } else if (type == 'Cellular') { | |
| 107 sendChromeMetricsAction('Options_NetworkShowDetailsCellular'); | |
| 108 if (state != 'NotConnected') | |
| 109 sendChromeMetricsAction('Options_NetworkShowDetailsCellularConnected'); | |
| 110 } | |
| 111 if (type == 'VPN') { | |
|
armansito
2014/09/15 14:44:52
else if?
stevenjb
2014/09/15 22:51:51
Done.
| |
| 112 sendChromeMetricsAction('Options_NetworkShowDetailsVPN'); | |
| 113 if (state != 'NotConnected') | |
| 114 sendChromeMetricsAction('Options_NetworkShowDetailsVPNConnected'); | |
| 115 } | |
|
armansito
2014/09/15 14:44:52
Maybe you could reduce the repetitions here. Somet
stevenjb
2014/09/15 22:51:51
I prefer not to concatenate strings here for searc
| |
| 116 } | |
| 117 | |
| 118 /** | |
| 86 * Returns the netmask as a string for a given prefix length. | 119 * Returns the netmask as a string for a given prefix length. |
| 87 * @param {string} prefixLength The ONC routing prefix length. | 120 * @param {string} prefixLength The ONC routing prefix length. |
| 88 * @return {string} The corresponding netmask. | 121 * @return {string} The corresponding netmask. |
| 89 */ | 122 */ |
| 90 function prefixLengthToNetmask(prefixLength) { | 123 function prefixLengthToNetmask(prefixLength) { |
| 91 // Return the empty string for invalid inputs. | 124 // Return the empty string for invalid inputs. |
| 92 if (prefixLength < 0 || prefixLength > 32) | 125 if (prefixLength < 0 || prefixLength > 32) |
| 93 return ''; | 126 return ''; |
| 94 var netmask = ''; | 127 var netmask = ''; |
| 95 for (var i = 0; i < 4; ++i) { | 128 for (var i = 0; i < 4; ++i) { |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 520 $('ftp-proxy').disabled = true; | 553 $('ftp-proxy').disabled = true; |
| 521 $('ftp-proxy-port').disabled = true; | 554 $('ftp-proxy-port').disabled = true; |
| 522 $('socks-host').disabled = true; | 555 $('socks-host').disabled = true; |
| 523 $('socks-port').disabled = true; | 556 $('socks-port').disabled = true; |
| 524 $('proxy-use-pac-url').disabled = $('auto-proxy').disabled || | 557 $('proxy-use-pac-url').disabled = $('auto-proxy').disabled || |
| 525 !$('auto-proxy').checked; | 558 !$('auto-proxy').checked; |
| 526 $('proxy-pac-url').disabled = $('proxy-use-pac-url').disabled || | 559 $('proxy-pac-url').disabled = $('proxy-use-pac-url').disabled || |
| 527 !$('proxy-use-pac-url').checked; | 560 !$('proxy-use-pac-url').checked; |
| 528 $('auto-proxy-parms').hidden = !$('auto-proxy').checked; | 561 $('auto-proxy-parms').hidden = !$('auto-proxy').checked; |
| 529 $('manual-proxy-parms').hidden = !$('manual-proxy').checked; | 562 $('manual-proxy-parms').hidden = !$('manual-proxy').checked; |
| 530 chrome.send('coreOptionsUserMetricsAction', | 563 sendChromeMetricsAction('Options_NetworkManualProxy_Disable'); |
| 531 ['Options_NetworkManualProxy_Disable']); | |
| 532 }, | 564 }, |
| 533 | 565 |
| 534 /** | 566 /** |
| 535 * Handler for selecting a radio button that will enable the manual | 567 * Handler for selecting a radio button that will enable the manual |
| 536 * controls. | 568 * controls. |
| 537 * @private | 569 * @private |
| 538 * @param {Event} e Click event. | 570 * @param {Event} e Click event. |
| 539 */ | 571 */ |
| 540 enableManualProxy_: function(e) { | 572 enableManualProxy_: function(e) { |
| 541 $('ignored-host-list').redraw(); | 573 $('ignored-host-list').redraw(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 552 $('secure-proxy-host-name').disabled = allDisabled; | 584 $('secure-proxy-host-name').disabled = allDisabled; |
| 553 $('secure-proxy-port').disabled = allDisabled; | 585 $('secure-proxy-port').disabled = allDisabled; |
| 554 $('ftp-proxy').disabled = allDisabled; | 586 $('ftp-proxy').disabled = allDisabled; |
| 555 $('ftp-proxy-port').disabled = allDisabled; | 587 $('ftp-proxy-port').disabled = allDisabled; |
| 556 $('socks-host').disabled = allDisabled; | 588 $('socks-host').disabled = allDisabled; |
| 557 $('socks-port').disabled = allDisabled; | 589 $('socks-port').disabled = allDisabled; |
| 558 $('proxy-use-pac-url').disabled = true; | 590 $('proxy-use-pac-url').disabled = true; |
| 559 $('proxy-pac-url').disabled = true; | 591 $('proxy-pac-url').disabled = true; |
| 560 $('auto-proxy-parms').hidden = !$('auto-proxy').checked; | 592 $('auto-proxy-parms').hidden = !$('auto-proxy').checked; |
| 561 $('manual-proxy-parms').hidden = !$('manual-proxy').checked; | 593 $('manual-proxy-parms').hidden = !$('manual-proxy').checked; |
| 562 chrome.send('coreOptionsUserMetricsAction', | 594 sendChromeMetricsAction('Options_NetworkManualProxy_Enable'); |
| 563 ['Options_NetworkManualProxy_Enable']); | |
| 564 }, | 595 }, |
| 565 | 596 |
| 566 updateConnectionButtonVisibilty_: function() { | 597 updateConnectionButtonVisibilty_: function() { |
| 567 var onc = this.onc_; | 598 var onc = this.onc_; |
| 568 if (this.type_ == 'Ethernet') { | 599 if (this.type_ == 'Ethernet') { |
| 569 // Ethernet can never be connected or disconnected and can always be | 600 // Ethernet can never be connected or disconnected and can always be |
| 570 // configured (e.g. to set security). | 601 // configured (e.g. to set security). |
| 571 $('details-internet-login').hidden = true; | 602 $('details-internet-login').hidden = true; |
| 572 $('details-internet-disconnect').hidden = true; | 603 $('details-internet-disconnect').hidden = true; |
| 573 $('details-internet-configure').hidden = false; | 604 $('details-internet-configure').hidden = false; |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 884 $('network-details-header').hidden = true; | 915 $('network-details-header').hidden = true; |
| 885 $('activate-details').hidden = true; | 916 $('activate-details').hidden = true; |
| 886 $('view-account-details').hidden = true; | 917 $('view-account-details').hidden = true; |
| 887 $('web-proxy-auto-discovery').hidden = true; | 918 $('web-proxy-auto-discovery').hidden = true; |
| 888 detailsPage.showProxy_ = true; | 919 detailsPage.showProxy_ = true; |
| 889 updateHidden('#internet-tab', true); | 920 updateHidden('#internet-tab', true); |
| 890 updateHidden('#details-tab-strip', true); | 921 updateHidden('#details-tab-strip', true); |
| 891 updateHidden('#details-internet-page .action-area', true); | 922 updateHidden('#details-internet-page .action-area', true); |
| 892 detailsPage.updateControls(); | 923 detailsPage.updateControls(); |
| 893 detailsPage.visible = true; | 924 detailsPage.visible = true; |
| 894 chrome.send('coreOptionsUserMetricsAction', | 925 sendChromeMetricsAction('Options_NetworkShowProxyTab'); |
| 895 ['Options_NetworkShowProxyTab']); | |
| 896 }; | 926 }; |
| 897 | 927 |
| 898 /** | 928 /** |
| 899 * Initializes even handling for keyboard driven flow. | 929 * Initializes even handling for keyboard driven flow. |
| 900 */ | 930 */ |
| 901 DetailsInternetPage.initializeKeyboardFlow = function() { | 931 DetailsInternetPage.initializeKeyboardFlow = function() { |
| 902 keyboard.initializeKeyboardFlow(); | 932 keyboard.initializeKeyboardFlow(); |
| 903 }; | 933 }; |
| 904 | 934 |
| 905 DetailsInternetPage.updateProxySettings = function(type) { | 935 DetailsInternetPage.updateProxySettings = function(type) { |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 934 } | 964 } |
| 935 } | 965 } |
| 936 }; | 966 }; |
| 937 | 967 |
| 938 DetailsInternetPage.updateCarrier = function() { | 968 DetailsInternetPage.updateCarrier = function() { |
| 939 DetailsInternetPage.showCarrierChangeSpinner(false); | 969 DetailsInternetPage.showCarrierChangeSpinner(false); |
| 940 }; | 970 }; |
| 941 | 971 |
| 942 DetailsInternetPage.loginFromDetails = function() { | 972 DetailsInternetPage.loginFromDetails = function() { |
| 943 var detailsPage = DetailsInternetPage.getInstance(); | 973 var detailsPage = DetailsInternetPage.getInstance(); |
| 974 if (detailsPage.type_ == 'WiFi') | |
| 975 sendChromeMetricsAction('Options_NetworkConnectToWifi'); | |
| 976 else if (detailsPage.type_ == 'VPN') | |
| 977 sendChromeMetricsAction('Options_NetworkConnectToVPN'); | |
| 944 chrome.send('networkCommand', | 978 chrome.send('networkCommand', |
| 945 [detailsPage.type_, detailsPage.servicePath_, 'connect']); | 979 [detailsPage.type_, detailsPage.servicePath_, 'connect']); |
| 946 PageManager.closeOverlay(); | 980 PageManager.closeOverlay(); |
| 947 }; | 981 }; |
| 948 | 982 |
| 949 DetailsInternetPage.disconnectNetwork = function() { | 983 DetailsInternetPage.disconnectNetwork = function() { |
| 950 var detailsPage = DetailsInternetPage.getInstance(); | 984 var detailsPage = DetailsInternetPage.getInstance(); |
| 985 if (detailsPage.type_ == 'WiFi') | |
| 986 sendChromeMetricsAction('Options_NetworkDisconnectWifi'); | |
| 987 else if (detailsPage.type_ == 'VPN') | |
| 988 sendChromeMetricsAction('Options_NetworkDisconnectVPN'); | |
| 951 chrome.send('networkCommand', | 989 chrome.send('networkCommand', |
| 952 [detailsPage.type_, detailsPage.servicePath_, 'disconnect']); | 990 [detailsPage.type_, detailsPage.servicePath_, 'disconnect']); |
| 953 PageManager.closeOverlay(); | 991 PageManager.closeOverlay(); |
| 954 }; | 992 }; |
| 955 | 993 |
| 956 DetailsInternetPage.configureNetwork = function() { | 994 DetailsInternetPage.configureNetwork = function() { |
| 957 var detailsPage = DetailsInternetPage.getInstance(); | 995 var detailsPage = DetailsInternetPage.getInstance(); |
| 958 chrome.send('networkCommand', | 996 chrome.send('networkCommand', |
| 959 [detailsPage.type_, detailsPage.servicePath_, 'configure']); | 997 [detailsPage.type_, detailsPage.servicePath_, 'configure']); |
| 960 PageManager.closeOverlay(); | 998 PageManager.closeOverlay(); |
| 961 }; | 999 }; |
| 962 | 1000 |
| 963 DetailsInternetPage.activateFromDetails = function() { | 1001 DetailsInternetPage.activateFromDetails = function() { |
| 964 var detailsPage = DetailsInternetPage.getInstance(); | 1002 var detailsPage = DetailsInternetPage.getInstance(); |
| 965 if (detailsPage.type_ == 'Cellular') { | 1003 if (detailsPage.type_ == 'Cellular') { |
| 966 chrome.send('networkCommand', | 1004 chrome.send('networkCommand', |
| 967 [detailsPage.type_, detailsPage.servicePath_, 'activate']); | 1005 [detailsPage.type_, detailsPage.servicePath_, 'activate']); |
| 968 } | 1006 } |
| 969 PageManager.closeOverlay(); | 1007 PageManager.closeOverlay(); |
| 970 }; | 1008 }; |
| 971 | 1009 |
| 972 DetailsInternetPage.setDetails = function() { | 1010 DetailsInternetPage.setDetails = function() { |
| 973 var detailsPage = DetailsInternetPage.getInstance(); | 1011 var detailsPage = DetailsInternetPage.getInstance(); |
| 974 var type = detailsPage.type_; | 1012 var type = detailsPage.type_; |
| 975 var servicePath = detailsPage.servicePath_; | 1013 var servicePath = detailsPage.servicePath_; |
| 976 if (type == 'WiFi') { | 1014 if (type == 'WiFi') { |
| 977 sendCheckedIfEnabled(servicePath, 'setPreferNetwork', | 1015 sendCheckedIfEnabled(servicePath, |
| 978 $('prefer-network-wifi')); | 1016 'setPreferNetwork', |
| 979 sendCheckedIfEnabled(servicePath, 'setAutoConnect', | 1017 $('prefer-network-wifi'), |
| 980 $('auto-connect-network-wifi')); | 1018 'Options_NetworkSetPrefer'); |
| 1019 sendCheckedIfEnabled(servicePath, | |
| 1020 'setAutoConnect', | |
| 1021 $('auto-connect-network-wifi'), | |
| 1022 'Options_NetworkAutoConnect'); | |
| 981 } else if (type == 'Wimax') { | 1023 } else if (type == 'Wimax') { |
| 982 sendCheckedIfEnabled(servicePath, 'setAutoConnect', | 1024 sendCheckedIfEnabled(servicePath, |
| 983 $('auto-connect-network-wimax')); | 1025 'setAutoConnect', |
| 1026 $('auto-connect-network-wimax'), | |
| 1027 'Options_NetworkAutoConnect'); | |
| 984 } else if (type == 'Cellular') { | 1028 } else if (type == 'Cellular') { |
| 985 sendCheckedIfEnabled(servicePath, 'setAutoConnect', | 1029 sendCheckedIfEnabled(servicePath, |
| 986 $('auto-connect-network-cellular')); | 1030 'setAutoConnect', |
| 1031 $('auto-connect-network-cellular'), | |
| 1032 'Options_NetworkAutoConnect'); | |
| 987 } else if (type == 'VPN') { | 1033 } else if (type == 'VPN') { |
| 988 chrome.send('setServerHostname', | 1034 chrome.send('setServerHostname', |
| 989 [servicePath, | 1035 [servicePath, $('inet-server-hostname').value]); |
| 990 $('inet-server-hostname').value]); | 1036 sendCheckedIfEnabled(servicePath, |
| 991 sendCheckedIfEnabled(servicePath, 'setAutoConnect', | 1037 'setAutoConnect', |
| 992 $('auto-connect-network-vpn')); | 1038 $('auto-connect-network-vpn'), |
| 1039 'Options_NetworkAutoConnect'); | |
| 993 } | 1040 } |
| 994 | 1041 |
| 995 var nameServerTypes = ['automatic', 'google', 'user']; | 1042 var nameServerTypes = ['automatic', 'google', 'user']; |
| 996 var nameServerType = 'automatic'; | 1043 var nameServerType = 'automatic'; |
| 997 for (var i = 0; i < nameServerTypes.length; ++i) { | 1044 for (var i = 0; i < nameServerTypes.length; ++i) { |
| 998 if ($(nameServerTypes[i] + '-dns-radio').checked) { | 1045 if ($(nameServerTypes[i] + '-dns-radio').checked) { |
| 999 nameServerType = nameServerTypes[i]; | 1046 nameServerType = nameServerTypes[i]; |
| 1000 break; | 1047 break; |
| 1001 } | 1048 } |
| 1002 } | 1049 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1074 | 1121 |
| 1075 DetailsInternetPage.showDetailedInfo = function(data) { | 1122 DetailsInternetPage.showDetailedInfo = function(data) { |
| 1076 var onc = new OncData(data); | 1123 var onc = new OncData(data); |
| 1077 | 1124 |
| 1078 var detailsPage = DetailsInternetPage.getInstance(); | 1125 var detailsPage = DetailsInternetPage.getInstance(); |
| 1079 detailsPage.onc_ = onc; | 1126 detailsPage.onc_ = onc; |
| 1080 var type = onc.getActiveValue('Type'); | 1127 var type = onc.getActiveValue('Type'); |
| 1081 detailsPage.type_ = type; | 1128 detailsPage.type_ = type; |
| 1082 detailsPage.servicePath_ = data.servicePath; | 1129 detailsPage.servicePath_ = data.servicePath; |
| 1083 | 1130 |
| 1131 sendMetrics(type, onc.getActiveValue('ConnectionState')); | |
| 1132 | |
| 1084 detailsPage.populateHeader_(); | 1133 detailsPage.populateHeader_(); |
| 1085 detailsPage.updateConnectionButtonVisibilty_(); | 1134 detailsPage.updateConnectionButtonVisibilty_(); |
| 1086 detailsPage.updateDetails_(data); | 1135 detailsPage.updateDetails_(data); |
| 1087 | 1136 |
| 1088 // TODO(stevenjb): Some of the setup below should be moved to | 1137 // TODO(stevenjb): Some of the setup below should be moved to |
| 1089 // updateDetails_() so that updates are reflected in the UI. | 1138 // updateDetails_() so that updates are reflected in the UI. |
| 1090 | 1139 |
| 1091 // Only show proxy for remembered networks. | 1140 // Only show proxy for remembered networks. |
| 1092 var remembered = onc.getSource() != 'None'; | 1141 var remembered = onc.getSource() != 'None'; |
| 1093 if (remembered) { | 1142 if (remembered) { |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1438 | 1487 |
| 1439 // Don't show page name in address bar and in history to prevent people | 1488 // Don't show page name in address bar and in history to prevent people |
| 1440 // navigate here by hand and solve issue with page session restore. | 1489 // navigate here by hand and solve issue with page session restore. |
| 1441 PageManager.showPageByName('detailsInternetPage', false); | 1490 PageManager.showPageByName('detailsInternetPage', false); |
| 1442 }; | 1491 }; |
| 1443 | 1492 |
| 1444 return { | 1493 return { |
| 1445 DetailsInternetPage: DetailsInternetPage | 1494 DetailsInternetPage: DetailsInternetPage |
| 1446 }; | 1495 }; |
| 1447 }); | 1496 }); |
| OLD | NEW |