Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "chrome/browser/chromeos/options/wifi_config_view.h" | 5 #include "chrome/browser/chromeos/options/wifi_config_view.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "base/string_util.h" | |
| 9 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/chromeos/cros/cros_library.h" | 11 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 11 #include "chrome/browser/chromeos/options/network_config_view.h" | 12 #include "chrome/browser/chromeos/options/network_config_view.h" |
| 12 #include "grit/chromium_strings.h" | 13 #include "grit/chromium_strings.h" |
| 13 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
| 14 #include "grit/locale_settings.h" | 15 #include "grit/locale_settings.h" |
| 15 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
| 16 #include "views/controls/button/image_button.h" | 17 #include "views/controls/button/image_button.h" |
| 17 #include "views/controls/button/native_button.h" | 18 #include "views/controls/button/native_button.h" |
| 18 #include "views/controls/label.h" | 19 #include "views/controls/label.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 Init(); | 55 Init(); |
| 55 } | 56 } |
| 56 | 57 |
| 57 void WifiConfigView::UpdateCanLogin(void) { | 58 void WifiConfigView::UpdateCanLogin(void) { |
| 58 bool can_login = true; | 59 bool can_login = true; |
| 59 if (other_network_) { | 60 if (other_network_) { |
| 60 // Since the user can try to connect to a non-encrypted hidden network, | 61 // Since the user can try to connect to a non-encrypted hidden network, |
| 61 // only enforce ssid is non-empty. | 62 // only enforce ssid is non-empty. |
| 62 can_login = !ssid_textfield_->text().empty(); | 63 can_login = !ssid_textfield_->text().empty(); |
| 63 } else { | 64 } else { |
| 64 // Connecting to an encrypted network, so make sure passphrase is non-empty. | 65 // Connecting to an encrypted network |
| 65 can_login = !passphrase_textfield_->text().empty(); | 66 if (passphrase_textfield_ != NULL) { |
| 66 if (identity_textfield_ != NULL) | 67 // if the network requires a passphrase, make sure it is non empty. |
| 67 can_login = !identity_textfield_->text().empty() && | 68 can_login &= !passphrase_textfield_->text().empty(); |
| 69 } | |
| 70 if (identity_textfield_ != NULL) { | |
| 71 // If we have an identity field, we can login if we have a non empty | |
| 72 // identity and a certificate path | |
| 73 can_login &= !identity_textfield_->text().empty() && | |
| 68 !certificate_path_.empty(); | 74 !certificate_path_.empty(); |
| 75 } | |
| 69 } | 76 } |
| 70 | 77 |
| 71 // Update the login button enable/disable state if can_login_ changes. | 78 // Update the login button enable/disable state if can_login_ changes. |
| 72 if (can_login != can_login_) { | 79 if (can_login != can_login_) { |
| 73 can_login_ = can_login; | 80 can_login_ = can_login; |
| 74 parent_->GetDialogClientView()->UpdateDialogButtons(); | 81 parent_->GetDialogClientView()->UpdateDialogButtons(); |
| 75 } | 82 } |
| 76 } | 83 } |
| 77 | 84 |
| 78 void WifiConfigView::ContentsChanged(views::Textfield* sender, | 85 void WifiConfigView::ContentsChanged(views::Textfield* sender, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 95 NULL : | 102 NULL : |
| 96 parent_->GetNativeWindow(), | 103 parent_->GetNativeWindow(), |
| 97 NULL); | 104 NULL); |
| 98 } else { | 105 } else { |
| 99 NOTREACHED(); | 106 NOTREACHED(); |
| 100 } | 107 } |
| 101 } | 108 } |
| 102 | 109 |
| 103 void WifiConfigView::FileSelected(const FilePath& path, | 110 void WifiConfigView::FileSelected(const FilePath& path, |
| 104 int index, void* params) { | 111 int index, void* params) { |
| 105 certificate_path_ = path; | 112 certificate_path_ = path.value(); |
| 106 certificate_browse_button_->SetLabel(path.BaseName().ToWStringHack()); | 113 if (certificate_browse_button_) |
| 114 certificate_browse_button_->SetLabel(path.BaseName().ToWStringHack()); | |
| 107 UpdateCanLogin(); // TODO(njw) Check if the passphrase decrypts the key. | 115 UpdateCanLogin(); // TODO(njw) Check if the passphrase decrypts the key. |
| 108 } | 116 } |
| 109 | 117 |
| 110 bool WifiConfigView::Login() { | 118 bool WifiConfigView::Login() { |
| 111 string16 identity_string, certificate_path_string; | 119 std::string identity_string; |
| 112 | |
| 113 if (identity_textfield_ != NULL) { | 120 if (identity_textfield_ != NULL) { |
| 114 identity_string = identity_textfield_->text(); | 121 identity_string = UTF16ToUTF8(identity_textfield_->text()); |
| 115 certificate_path_string = WideToUTF16(certificate_path_.ToWStringHack()); | |
| 116 } | 122 } |
| 117 if (other_network_) { | 123 if (other_network_) { |
| 118 CrosLibrary::Get()->GetNetworkLibrary()->ConnectToWifiNetwork( | 124 CrosLibrary::Get()->GetNetworkLibrary()->ConnectToWifiNetwork( |
| 119 ssid_textfield_->text(), passphrase_textfield_->text(), | 125 GetSSID(), GetPassphrase(), |
| 120 identity_string, certificate_path_string, | 126 identity_string, certificate_path_, |
| 121 autoconnect_checkbox_->checked()); | 127 autoconnect_checkbox_->checked()); |
| 122 } else { | 128 } else { |
| 123 Save(); | 129 Save(); |
| 124 CrosLibrary::Get()->GetNetworkLibrary()->ConnectToWifiNetwork( | 130 CrosLibrary::Get()->GetNetworkLibrary()->ConnectToWifiNetwork( |
| 125 wifi_, passphrase_textfield_->text(), | 131 wifi_, GetPassphrase(), |
| 126 identity_string, certificate_path_string); | 132 identity_string, certificate_path_); |
| 127 } | 133 } |
| 128 return true; | 134 return true; |
| 129 } | 135 } |
| 130 | 136 |
| 131 bool WifiConfigView::Save() { | 137 bool WifiConfigView::Save() { |
| 132 // Save password and auto-connect here. | 138 // Save password and auto-connect here. |
| 133 if (!other_network_) { | 139 if (!other_network_) { |
| 134 bool changed = false; | 140 bool changed = false; |
| 135 | 141 |
| 136 bool auto_connect = autoconnect_checkbox_->checked(); | 142 bool auto_connect = autoconnect_checkbox_->checked(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 147 changed = true; | 153 changed = true; |
| 148 } | 154 } |
| 149 } | 155 } |
| 150 | 156 |
| 151 if (changed) | 157 if (changed) |
| 152 CrosLibrary::Get()->GetNetworkLibrary()->SaveWifiNetwork(wifi_); | 158 CrosLibrary::Get()->GetNetworkLibrary()->SaveWifiNetwork(wifi_); |
| 153 } | 159 } |
| 154 return true; | 160 return true; |
| 155 } | 161 } |
| 156 | 162 |
| 157 const string16& WifiConfigView::GetSSID() const { | 163 const std::string WifiConfigView::GetSSID() const { |
| 158 return ssid_textfield_->text(); | 164 std::string result; |
| 165 if (ssid_textfield_ != NULL) | |
| 166 result = UTF16ToUTF8(ssid_textfield_->text()); | |
| 167 return result; | |
| 159 } | 168 } |
| 160 | 169 |
| 161 const string16& WifiConfigView::GetPassphrase() const { | 170 const std::string WifiConfigView::GetPassphrase() const { |
| 162 return passphrase_textfield_->text(); | 171 std::string result; |
| 172 if (passphrase_textfield_ != NULL) | |
| 173 result = UTF16ToUTF8(passphrase_textfield_->text()); | |
| 174 return result; | |
| 163 } | 175 } |
| 164 | 176 |
| 165 void WifiConfigView::FocusFirstField() { | 177 void WifiConfigView::FocusFirstField() { |
| 166 if (ssid_textfield_) | 178 if (ssid_textfield_) |
| 167 ssid_textfield_->RequestFocus(); | 179 ssid_textfield_->RequestFocus(); |
| 168 else if (identity_textfield_) | 180 else if (identity_textfield_) |
| 169 identity_textfield_->RequestFocus(); | 181 identity_textfield_->RequestFocus(); |
| 170 else if (passphrase_textfield_) | 182 else if (passphrase_textfield_) |
| 171 passphrase_textfield_->RequestFocus(); | 183 passphrase_textfield_->RequestFocus(); |
| 172 } | 184 } |
| 173 | 185 |
| 186 // Parse 'path' to determine if the certificate is stored in a pkcs#11 device. | |
| 187 // flimflam recognizes the string "SETTINGS:" to specify authentication | |
| 188 // parameters. 'key_id=' indicates that the certificate is stored in a pkcs#11 | |
| 189 // device. See src/third_party/flimflam/files/doc/service-api.txt. | |
| 190 static bool is_certificate_in_pkcs11(const std::string& path) { | |
| 191 static const std::string settings_string("SETTINGS:"); | |
| 192 static const std::string pkcs11_key("key_id"); | |
| 193 if (path.find(settings_string) == 0) { | |
| 194 std::string::size_type idx = path.find(pkcs11_key); | |
|
Charlie Lee
2010/06/24 22:43:15
The code you have works, but can it be simpler?
w
stevenjb
2010/06/24 22:57:48
I've had enough bad experiences with soft parsing
| |
| 195 if (idx != std::string::npos) | |
| 196 idx = path.find_first_not_of(kWhitespaceASCII, idx + pkcs11_key.length()); | |
| 197 if (idx != std::string::npos && path[idx] == '=') | |
| 198 return true; | |
| 199 } | |
| 200 return false; | |
| 201 } | |
| 202 | |
| 174 void WifiConfigView::Init() { | 203 void WifiConfigView::Init() { |
| 175 views::GridLayout* layout = CreatePanelGridLayout(this); | 204 views::GridLayout* layout = CreatePanelGridLayout(this); |
| 176 SetLayoutManager(layout); | 205 SetLayoutManager(layout); |
| 177 | 206 |
| 178 int column_view_set_id = 0; | 207 int column_view_set_id = 0; |
| 179 views::ColumnSet* column_set = layout->AddColumnSet(column_view_set_id); | 208 views::ColumnSet* column_set = layout->AddColumnSet(column_view_set_id); |
| 180 // Label | 209 // Label |
| 181 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, | 210 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, |
| 182 views::GridLayout::USE_PREF, 0, 0); | 211 views::GridLayout::USE_PREF, 0, 0); |
| 183 // Textfield | 212 // Textfield |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 194 ssid_textfield_ = new views::Textfield(views::Textfield::STYLE_DEFAULT); | 223 ssid_textfield_ = new views::Textfield(views::Textfield::STYLE_DEFAULT); |
| 195 ssid_textfield_->SetController(this); | 224 ssid_textfield_->SetController(this); |
| 196 layout->AddView(ssid_textfield_); | 225 layout->AddView(ssid_textfield_); |
| 197 } else { | 226 } else { |
| 198 views::Label* label = new views::Label(ASCIIToWide(wifi_.name())); | 227 views::Label* label = new views::Label(ASCIIToWide(wifi_.name())); |
| 199 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 228 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 200 layout->AddView(label); | 229 layout->AddView(label); |
| 201 } | 230 } |
| 202 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 231 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
| 203 | 232 |
| 233 // Certificates stored in a pkcs11 device can not be browsed | |
| 234 // and do not require a passphrase. | |
| 235 bool certificate_in_pkcs11 = false; | |
| 236 | |
| 204 // Add ID and cert password if we're using 802.1x | 237 // Add ID and cert password if we're using 802.1x |
| 205 // XXX we're cheating and assuming 802.1x means EAP-TLS - not true | 238 // XXX we're cheating and assuming 802.1x means EAP-TLS - not true |
| 206 // in general, but very common. WPA Supplicant doesn't report the | 239 // in general, but very common. WPA Supplicant doesn't report the |
| 207 // EAP type because it's unknown until the process begins, and we'd | 240 // EAP type because it's unknown until the process begins, and we'd |
| 208 // need some kind of callback. | 241 // need some kind of callback. |
| 209 if (wifi_.encrypted() && wifi_.encryption() == SECURITY_8021X) { | 242 if (wifi_.encrypted() && wifi_.encryption() == SECURITY_8021X) { |
| 210 layout->StartRow(0, column_view_set_id); | 243 layout->StartRow(0, column_view_set_id); |
| 211 layout->AddView(new views::Label(l10n_util::GetString( | 244 layout->AddView(new views::Label(l10n_util::GetString( |
| 212 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_IDENTITY))); | 245 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_IDENTITY))); |
| 213 identity_textfield_ = new views::Textfield( | 246 identity_textfield_ = new views::Textfield( |
| 214 views::Textfield::STYLE_DEFAULT); | 247 views::Textfield::STYLE_DEFAULT); |
| 215 identity_textfield_->SetController(this); | 248 identity_textfield_->SetController(this); |
| 216 if (!wifi_.identity().empty()) | 249 if (!wifi_.identity().empty()) |
| 217 identity_textfield_->SetText(UTF8ToUTF16(wifi_.identity())); | 250 identity_textfield_->SetText(UTF8ToUTF16(wifi_.identity())); |
| 218 layout->AddView(identity_textfield_); | 251 layout->AddView(identity_textfield_); |
| 219 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 252 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
| 220 layout->StartRow(0, column_view_set_id); | 253 layout->StartRow(0, column_view_set_id); |
| 221 layout->AddView(new views::Label(l10n_util::GetString( | 254 layout->AddView(new views::Label(l10n_util::GetString( |
| 222 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT))); | 255 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT))); |
| 223 if (!wifi_.cert_path().empty()) { | 256 if (!wifi_.cert_path().empty()) { |
| 224 certificate_path_ = FilePath(wifi_.cert_path()); | 257 certificate_path_ = wifi_.cert_path(); |
| 225 certificate_browse_button_ = new views::NativeButton( | 258 certificate_in_pkcs11 = is_certificate_in_pkcs11(certificate_path_); |
| 226 this, UTF8ToWide(wifi_.cert_path())); | 259 } |
| 260 if (certificate_in_pkcs11) { | |
|
Charlie Lee
2010/06/24 22:43:15
it might be simpler to call is_certificate_in_pkcs
stevenjb
2010/06/24 22:57:48
We also use certificate_in_pkcs11 below to check w
| |
| 261 std::wstring label = l10n_util::GetString( | |
| 262 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_INSTALLED); | |
| 263 views::Label* cert_text = new views::Label(label); | |
| 264 cert_text->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | |
| 265 layout->AddView(cert_text); | |
| 227 } else { | 266 } else { |
| 228 certificate_browse_button_ = new views::NativeButton( | 267 std::wstring label; |
| 229 this, | 268 if (!certificate_path_.empty()) |
| 230 l10n_util::GetString( | 269 label = UTF8ToWide(certificate_path_); |
| 231 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_BUTTON)); | 270 else |
| 271 label = IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_BUTTON; | |
| 272 certificate_browse_button_ = new views::NativeButton(this, label); | |
| 273 layout->AddView(certificate_browse_button_); | |
| 232 } | 274 } |
| 233 layout->AddView(certificate_browse_button_); | |
| 234 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 275 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
| 235 } | 276 } |
| 236 | 277 |
| 237 // Add passphrase if other_network or wifi is encrypted. | 278 // Add passphrase if other_network or wifi is encrypted. |
| 238 if (other_network_ || wifi_.encrypted()) { | 279 if (other_network_ || (wifi_.encrypted() && !certificate_in_pkcs11)) { |
| 239 layout->StartRow(0, column_view_set_id); | 280 layout->StartRow(0, column_view_set_id); |
| 240 int label_text_id; | 281 int label_text_id; |
| 241 if (wifi_.encryption() == SECURITY_8021X) | 282 if (wifi_.encryption() == SECURITY_8021X) |
| 242 label_text_id = | 283 label_text_id = |
| 243 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PRIVATE_KEY_PASSWORD; | 284 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PRIVATE_KEY_PASSWORD; |
| 244 else | 285 else |
| 245 label_text_id = IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSPHRASE; | 286 label_text_id = IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSPHRASE; |
| 246 layout->AddView(new views::Label(l10n_util::GetString(label_text_id))); | 287 layout->AddView(new views::Label(l10n_util::GetString(label_text_id))); |
| 247 passphrase_textfield_ = new views::Textfield( | 288 passphrase_textfield_ = new views::Textfield( |
| 248 views::Textfield::STYLE_PASSWORD); | 289 views::Textfield::STYLE_PASSWORD); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 266 l10n_util::GetString(IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_AUTO_CONNECT)); | 307 l10n_util::GetString(IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_AUTO_CONNECT)); |
| 267 // For other network, default to autoconnect. | 308 // For other network, default to autoconnect. |
| 268 bool autoconnect = other_network_ || wifi_.auto_connect(); | 309 bool autoconnect = other_network_ || wifi_.auto_connect(); |
| 269 autoconnect_checkbox_->SetChecked(autoconnect); | 310 autoconnect_checkbox_->SetChecked(autoconnect); |
| 270 layout->StartRow(0, column_view_set_id); | 311 layout->StartRow(0, column_view_set_id); |
| 271 layout->AddView(autoconnect_checkbox_, 3, 1); | 312 layout->AddView(autoconnect_checkbox_, 3, 1); |
| 272 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 313 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
| 273 } | 314 } |
| 274 | 315 |
| 275 } // namespace chromeos | 316 } // namespace chromeos |
| OLD | NEW |