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

Side by Side Diff: chrome/browser/chromeos/options/wifi_config_view.cc

Issue 4237001: Add support for different type of encyrption when adding a network.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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 | Annotate | Revision Log
OLDNEW
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/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/chromeos/cros/cros_library.h" 11 #include "chrome/browser/chromeos/cros/cros_library.h"
12 #include "chrome/browser/chromeos/login/user_manager.h" 12 #include "chrome/browser/chromeos/login/user_manager.h"
13 #include "chrome/browser/chromeos/options/network_config_view.h" 13 #include "chrome/browser/chromeos/options/network_config_view.h"
14 #include "grit/chromium_strings.h" 14 #include "grit/chromium_strings.h"
15 #include "grit/generated_resources.h" 15 #include "grit/generated_resources.h"
16 #include "grit/locale_settings.h" 16 #include "grit/locale_settings.h"
17 #include "grit/theme_resources.h" 17 #include "grit/theme_resources.h"
18 #include "views/controls/button/image_button.h" 18 #include "views/controls/button/image_button.h"
19 #include "views/controls/button/native_button.h" 19 #include "views/controls/button/native_button.h"
20 #include "views/controls/label.h" 20 #include "views/controls/label.h"
21 #include "views/grid_layout.h" 21 #include "views/grid_layout.h"
22 #include "views/standard_layout.h" 22 #include "views/standard_layout.h"
23 #include "views/window/window.h" 23 #include "views/window/window.h"
24 24
25 namespace chromeos { 25 namespace chromeos {
26 26
27 // The width of the password field. 27 // The width of the password field.
28 const int kPasswordWidth = 150; 28 const int kPasswordWidth = 150;
29 29
30 enum SecurityComboboxIndex {
31 INDEX_NONE = 0,
32 INDEX_WEP = 1,
33 INDEX_WPA = 2,
34 INDEX_RSN = 3,
35 INDEX_COUNT = 4
36 };
37
38 int WifiConfigView::SecurityComboboxModel::GetItemCount() {
39 return INDEX_COUNT;
40 }
41
42 string16 WifiConfigView::SecurityComboboxModel::GetItemAt(int index) {
43 if (index == INDEX_NONE)
44 return l10n_util::GetStringUTF16(
45 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SECURITY_NONE);
46 else if (index == INDEX_WEP)
47 return l10n_util::GetStringUTF16(
48 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SECURITY_WEP);
49 else if (index == INDEX_WPA)
50 return l10n_util::GetStringUTF16(
51 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SECURITY_WPA);
52 else if (index == INDEX_RSN)
53 return l10n_util::GetStringUTF16(
54 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SECURITY_RSN);
55 NOTREACHED();
56 return string16();
57 }
58
30 WifiConfigView::WifiConfigView(NetworkConfigView* parent, 59 WifiConfigView::WifiConfigView(NetworkConfigView* parent,
31 const WifiNetwork* wifi) 60 const WifiNetwork* wifi)
32 : parent_(parent), 61 : parent_(parent),
33 other_network_(false), 62 other_network_(false),
34 can_login_(false), 63 can_login_(false),
35 wifi_(new WifiNetwork(*wifi)), 64 wifi_(new WifiNetwork(*wifi)),
36 ssid_textfield_(NULL), 65 ssid_textfield_(NULL),
37 identity_textfield_(NULL), 66 identity_textfield_(NULL),
38 certificate_browse_button_(NULL), 67 certificate_browse_button_(NULL),
39 certificate_path_(), 68 certificate_path_(),
69 security_combobox_(NULL),
40 passphrase_textfield_(NULL), 70 passphrase_textfield_(NULL),
41 passphrase_visible_button_(NULL), 71 passphrase_visible_button_(NULL),
42 autoconnect_checkbox_(NULL) { 72 autoconnect_checkbox_(NULL) {
43 Init(); 73 Init();
44 } 74 }
45 75
46 WifiConfigView::WifiConfigView(NetworkConfigView* parent) 76 WifiConfigView::WifiConfigView(NetworkConfigView* parent)
47 : parent_(parent), 77 : parent_(parent),
48 other_network_(true), 78 other_network_(true),
49 can_login_(false), 79 can_login_(false),
50 ssid_textfield_(NULL), 80 ssid_textfield_(NULL),
51 identity_textfield_(NULL), 81 identity_textfield_(NULL),
52 certificate_browse_button_(NULL), 82 certificate_browse_button_(NULL),
53 certificate_path_(), 83 certificate_path_(),
84 security_combobox_(NULL),
54 passphrase_textfield_(NULL), 85 passphrase_textfield_(NULL),
55 passphrase_visible_button_(NULL), 86 passphrase_visible_button_(NULL),
56 autoconnect_checkbox_(NULL) { 87 autoconnect_checkbox_(NULL) {
57 Init(); 88 Init();
58 } 89 }
59 90
60 WifiConfigView::~WifiConfigView() { 91 WifiConfigView::~WifiConfigView() {
61 } 92 }
62 93
63 void WifiConfigView::UpdateCanLogin(void) { 94 void WifiConfigView::UpdateCanLogin(void) {
64 bool can_login = true; 95 bool can_login = true;
65 if (other_network_) { 96 if (other_network_) {
66 // Since the user can try to connect to a non-encrypted hidden network, 97 // Enforce ssid is non empty.
67 // only enforce ssid is non-empty. 98 // If security is not none, also enforce passphrase is non empty.
68 can_login = !ssid_textfield_->text().empty(); 99 can_login = !ssid_textfield_->text().empty() &&
100 (security_combobox_->selected_item() == INDEX_NONE ||
101 !passphrase_textfield_->text().empty());
69 } else { 102 } else {
70 // Connecting to an encrypted network 103 // Connecting to an encrypted network
71 if (passphrase_textfield_ != NULL) { 104 if (passphrase_textfield_ != NULL) {
72 // if the network requires a passphrase, make sure it is non empty. 105 // if the network requires a passphrase, make sure it is non empty.
73 can_login &= !passphrase_textfield_->text().empty(); 106 can_login &= !passphrase_textfield_->text().empty();
74 } 107 }
75 if (identity_textfield_ != NULL) { 108 if (identity_textfield_ != NULL) {
76 // If we have an identity field, we can login if we have a non empty 109 // If we have an identity field, we can login if we have a non empty
77 // identity and a certificate path 110 // identity and a certificate path
78 can_login &= !identity_textfield_->text().empty() && 111 can_login &= !identity_textfield_->text().empty() &&
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 std::string(), 158 std::string(),
126 parent_->is_browser_mode() ? 159 parent_->is_browser_mode() ?
127 NULL : 160 NULL :
128 parent_->GetNativeWindow(), 161 parent_->GetNativeWindow(),
129 NULL); 162 NULL);
130 } else { 163 } else {
131 NOTREACHED(); 164 NOTREACHED();
132 } 165 }
133 } 166 }
134 167
168 void WifiConfigView::ItemChanged(views::Combobox* combo_box,
169 int prev_index, int new_index) {
170 // If changed to no security, then disable combobox and clear it.
171 // Otherwise, enable it. Also, update can login.
172 if (new_index == INDEX_NONE) {
173 passphrase_textfield_->SetEnabled(false);
174 passphrase_textfield_->SetText(string16());
175 } else {
176 passphrase_textfield_->SetEnabled(true);
177 }
178 UpdateCanLogin();
179 }
180
135 void WifiConfigView::FileSelected(const FilePath& path, 181 void WifiConfigView::FileSelected(const FilePath& path,
136 int index, void* params) { 182 int index, void* params) {
137 certificate_path_ = path.value(); 183 certificate_path_ = path.value();
138 if (certificate_browse_button_) 184 if (certificate_browse_button_)
139 certificate_browse_button_->SetLabel(path.BaseName().ToWStringHack()); 185 certificate_browse_button_->SetLabel(path.BaseName().ToWStringHack());
140 UpdateCanLogin(); // TODO(njw) Check if the passphrase decrypts the key. 186 UpdateCanLogin(); // TODO(njw) Check if the passphrase decrypts the key.
141 } 187 }
142 188
143 bool WifiConfigView::Login() { 189 bool WifiConfigView::Login() {
144 std::string identity_string; 190 std::string identity_string;
145 if (identity_textfield_ != NULL) { 191 if (identity_textfield_ != NULL) {
146 identity_string = UTF16ToUTF8(identity_textfield_->text()); 192 identity_string = UTF16ToUTF8(identity_textfield_->text());
147 } 193 }
148 if (other_network_) { 194 if (other_network_) {
195 ConnectionSecurity sec = SECURITY_UNKNOWN;
196 int index = security_combobox_->selected_item();
197 if (index == INDEX_NONE)
198 sec = SECURITY_NONE;
199 else if (index == INDEX_WEP)
200 sec = SECURITY_WEP;
201 else if (index == INDEX_WPA)
202 sec = SECURITY_WPA;
203 else if (index == INDEX_RSN)
204 sec = SECURITY_RSN;
149 CrosLibrary::Get()->GetNetworkLibrary()->ConnectToWifiNetwork( 205 CrosLibrary::Get()->GetNetworkLibrary()->ConnectToWifiNetwork(
150 GetSSID(), GetPassphrase(), 206 sec, GetSSID(), GetPassphrase(),
151 identity_string, certificate_path_, 207 identity_string, certificate_path_,
152 autoconnect_checkbox_ ? autoconnect_checkbox_->checked() : true); 208 autoconnect_checkbox_ ? autoconnect_checkbox_->checked() : true);
153 } else { 209 } else {
154 Save(); 210 Save();
155 CrosLibrary::Get()->GetNetworkLibrary()->ConnectToWifiNetwork( 211 CrosLibrary::Get()->GetNetworkLibrary()->ConnectToWifiNetwork(
156 wifi_.get(), GetPassphrase(), 212 wifi_.get(), GetPassphrase(),
157 identity_string, certificate_path_); 213 identity_string, certificate_path_);
158 } 214 }
159 return true; 215 return true;
160 } 216 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 // Label 275 // Label
220 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, 276 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1,
221 views::GridLayout::USE_PREF, 0, 0); 277 views::GridLayout::USE_PREF, 0, 0);
222 // Textfield 278 // Textfield
223 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, 279 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
224 views::GridLayout::USE_PREF, 0, kPasswordWidth); 280 views::GridLayout::USE_PREF, 0, kPasswordWidth);
225 // Password visible button 281 // Password visible button
226 column_set->AddColumn(views::GridLayout::CENTER, views::GridLayout::FILL, 1, 282 column_set->AddColumn(views::GridLayout::CENTER, views::GridLayout::FILL, 1,
227 views::GridLayout::USE_PREF, 0, 0); 283 views::GridLayout::USE_PREF, 0, 0);
228 284
285 // SSID input
229 layout->StartRow(0, column_view_set_id); 286 layout->StartRow(0, column_view_set_id);
230 layout->AddView(new views::Label(l10n_util::GetString( 287 layout->AddView(new views::Label(l10n_util::GetString(
231 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NETWORK_ID))); 288 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NETWORK_ID)));
232 if (other_network_) { 289 if (other_network_) {
233 ssid_textfield_ = new views::Textfield(views::Textfield::STYLE_DEFAULT); 290 ssid_textfield_ = new views::Textfield(views::Textfield::STYLE_DEFAULT);
234 ssid_textfield_->SetController(this); 291 ssid_textfield_->SetController(this);
235 layout->AddView(ssid_textfield_); 292 layout->AddView(ssid_textfield_);
236 } else { 293 } else {
237 views::Label* label = new views::Label(ASCIIToWide(wifi_->name())); 294 views::Label* label = new views::Label(ASCIIToWide(wifi_->name()));
238 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 295 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
239 layout->AddView(label); 296 layout->AddView(label);
240 } 297 }
241 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); 298 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
242 299
300 // Certificate input
243 // Loaded certificates (i.e. stored in a pkcs11 device) do not require 301 // Loaded certificates (i.e. stored in a pkcs11 device) do not require
244 // a passphrase. 302 // a passphrase.
245 bool certificate_loaded = false; 303 bool certificate_loaded = false;
246 304
247 // Add ID and cert password if we're using 802.1x 305 // Add ID and cert password if we're using 802.1x
248 // XXX we're cheating and assuming 802.1x means EAP-TLS - not true 306 // XXX we're cheating and assuming 802.1x means EAP-TLS - not true
249 // in general, but very common. WPA Supplicant doesn't report the 307 // in general, but very common. WPA Supplicant doesn't report the
250 // EAP type because it's unknown until the process begins, and we'd 308 // EAP type because it's unknown until the process begins, and we'd
251 // need some kind of callback. 309 // need some kind of callback.
252 if (wifi_.get() && wifi_->encrypted() && 310 if (wifi_.get() && wifi_->encrypted() &&
(...skipping 27 matching lines...) Expand all
280 label = UTF8ToWide(certificate_path_); 338 label = UTF8ToWide(certificate_path_);
281 else 339 else
282 label = l10n_util::GetString( 340 label = l10n_util::GetString(
283 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_BUTTON); 341 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_BUTTON);
284 certificate_browse_button_ = new views::NativeButton(this, label); 342 certificate_browse_button_ = new views::NativeButton(this, label);
285 layout->AddView(certificate_browse_button_); 343 layout->AddView(certificate_browse_button_);
286 } 344 }
287 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); 345 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
288 } 346 }
289 347
348 // Security select
349 if (other_network_) {
350 layout->StartRow(0, column_view_set_id);
351 layout->AddView(new views::Label(l10n_util::GetString(
352 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SECURITY)));
353 security_combobox_ = new views::Combobox(new SecurityComboboxModel());
354 security_combobox_->set_listener(this);
355 layout->AddView(security_combobox_);
356 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
357 }
358
359 // Passphrase input
290 // Add passphrase if other_network or wifi is encrypted. 360 // Add passphrase if other_network or wifi is encrypted.
291 if (other_network_ || (wifi_.get() && wifi_->encrypted() && 361 if (other_network_ || (wifi_.get() && wifi_->encrypted() &&
292 !certificate_loaded)) { 362 !certificate_loaded)) {
293 layout->StartRow(0, column_view_set_id); 363 layout->StartRow(0, column_view_set_id);
294 int label_text_id; 364 int label_text_id;
295 if (wifi_.get() && wifi_->encryption() == SECURITY_8021X) 365 if (wifi_.get() && wifi_->encryption() == SECURITY_8021X)
296 label_text_id = 366 label_text_id =
297 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PRIVATE_KEY_PASSWORD; 367 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PRIVATE_KEY_PASSWORD;
298 else 368 else
299 label_text_id = IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSPHRASE; 369 label_text_id = IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSPHRASE;
300 layout->AddView(new views::Label(l10n_util::GetString(label_text_id))); 370 layout->AddView(new views::Label(l10n_util::GetString(label_text_id)));
301 passphrase_textfield_ = new views::Textfield( 371 passphrase_textfield_ = new views::Textfield(
302 views::Textfield::STYLE_PASSWORD); 372 views::Textfield::STYLE_PASSWORD);
303 passphrase_textfield_->SetController(this); 373 passphrase_textfield_->SetController(this);
304 if (wifi_.get() && !wifi_->passphrase().empty()) 374 if (wifi_.get() && !wifi_->passphrase().empty())
305 passphrase_textfield_->SetText(UTF8ToUTF16(wifi_->passphrase())); 375 passphrase_textfield_->SetText(UTF8ToUTF16(wifi_->passphrase()));
376 // Disable passphrase input initially for other network.
377 if (other_network_)
378 passphrase_textfield_->SetEnabled(false);
306 layout->AddView(passphrase_textfield_); 379 layout->AddView(passphrase_textfield_);
307 // Password visible button. 380 // Password visible button.
308 passphrase_visible_button_ = new views::ImageButton(this); 381 passphrase_visible_button_ = new views::ImageButton(this);
309 passphrase_visible_button_->SetImage(views::ImageButton::BS_NORMAL, 382 passphrase_visible_button_->SetImage(views::ImageButton::BS_NORMAL,
310 ResourceBundle::GetSharedInstance(). 383 ResourceBundle::GetSharedInstance().
311 GetBitmapNamed(IDR_STATUSBAR_NETWORK_SECURE)); 384 GetBitmapNamed(IDR_STATUSBAR_NETWORK_SECURE));
312 passphrase_visible_button_->SetImageAlignment( 385 passphrase_visible_button_->SetImageAlignment(
313 views::ImageButton::ALIGN_CENTER, views::ImageButton::ALIGN_MIDDLE); 386 views::ImageButton::ALIGN_CENTER, views::ImageButton::ALIGN_MIDDLE);
314 // Disable viewing password by unauthenticated user. 387 // Disable viewing password by unauthenticated user.
315 if (wifi_.get() && !wifi_->passphrase().empty() && 388 if (wifi_.get() && !wifi_->passphrase().empty() &&
316 chromeos::UserManager::Get()->logged_in_user().email().empty()) { 389 chromeos::UserManager::Get()->logged_in_user().email().empty()) {
317 passphrase_visible_button_->SetVisible(false); 390 passphrase_visible_button_->SetVisible(false);
318 } 391 }
319 layout->AddView(passphrase_visible_button_); 392 layout->AddView(passphrase_visible_button_);
320 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); 393 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
321 } 394 }
322 395
396 // Error label
323 // If there's an error, add an error message label. 397 // If there's an error, add an error message label.
324 // Right now, only displaying bad_passphrase and bad_wepkey errors. 398 // Right now, only displaying bad_passphrase and bad_wepkey errors.
325 if (wifi_.get() && (wifi_->error() == ERROR_BAD_PASSPHRASE || 399 if (wifi_.get() && (wifi_->error() == ERROR_BAD_PASSPHRASE ||
326 wifi_->error() == ERROR_BAD_WEPKEY)) { 400 wifi_->error() == ERROR_BAD_WEPKEY)) {
327 layout->StartRow(0, column_view_set_id); 401 layout->StartRow(0, column_view_set_id);
328 layout->SkipColumns(1); 402 layout->SkipColumns(1);
329 int id = IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_BAD_PASSPHRASE; 403 int id = IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_BAD_PASSPHRASE;
330 if (wifi_->error() == ERROR_BAD_WEPKEY) 404 if (wifi_->error() == ERROR_BAD_WEPKEY)
331 id = IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_BAD_WEPKEY; 405 id = IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_BAD_WEPKEY;
332 views::Label* label_error = new views::Label(l10n_util::GetString(id)); 406 views::Label* label_error = new views::Label(l10n_util::GetString(id));
(...skipping 11 matching lines...) Expand all
344 // For other network, default to autoconnect. 418 // For other network, default to autoconnect.
345 bool autoconnect = other_network_ || wifi_->auto_connect(); 419 bool autoconnect = other_network_ || wifi_->auto_connect();
346 autoconnect_checkbox_->SetChecked(autoconnect); 420 autoconnect_checkbox_->SetChecked(autoconnect);
347 layout->StartRow(0, column_view_set_id); 421 layout->StartRow(0, column_view_set_id);
348 layout->AddView(autoconnect_checkbox_, 3, 1); 422 layout->AddView(autoconnect_checkbox_, 3, 1);
349 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); 423 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
350 } 424 }
351 } 425 }
352 426
353 } // namespace chromeos 427 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/options/wifi_config_view.h ('k') | chrome/browser/chromeos/status/network_menu.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698