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/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 WifiConfigView::WifiConfigView(NetworkConfigView* parent, WifiNetwork wifi) | 30 WifiConfigView::WifiConfigView(NetworkConfigView* parent, |
| 31 const WifiNetwork* wifi) |
31 : parent_(parent), | 32 : parent_(parent), |
32 other_network_(false), | 33 other_network_(false), |
33 can_login_(false), | 34 can_login_(false), |
34 wifi_(wifi), | 35 wifi_(new WifiNetwork(*wifi)), |
35 ssid_textfield_(NULL), | 36 ssid_textfield_(NULL), |
36 identity_textfield_(NULL), | 37 identity_textfield_(NULL), |
37 certificate_browse_button_(NULL), | 38 certificate_browse_button_(NULL), |
38 certificate_path_(), | 39 certificate_path_(), |
39 passphrase_textfield_(NULL), | 40 passphrase_textfield_(NULL), |
40 passphrase_visible_button_(NULL), | 41 passphrase_visible_button_(NULL), |
41 autoconnect_checkbox_(NULL) { | 42 autoconnect_checkbox_(NULL) { |
42 Init(); | 43 Init(); |
43 } | 44 } |
44 | 45 |
45 WifiConfigView::WifiConfigView(NetworkConfigView* parent) | 46 WifiConfigView::WifiConfigView(NetworkConfigView* parent) |
46 : parent_(parent), | 47 : parent_(parent), |
47 other_network_(true), | 48 other_network_(true), |
48 can_login_(false), | 49 can_login_(false), |
| 50 wifi_(NULL), |
49 ssid_textfield_(NULL), | 51 ssid_textfield_(NULL), |
50 identity_textfield_(NULL), | 52 identity_textfield_(NULL), |
51 certificate_browse_button_(NULL), | 53 certificate_browse_button_(NULL), |
52 certificate_path_(), | 54 certificate_path_(), |
53 passphrase_textfield_(NULL), | 55 passphrase_textfield_(NULL), |
54 passphrase_visible_button_(NULL), | 56 passphrase_visible_button_(NULL), |
55 autoconnect_checkbox_(NULL) { | 57 autoconnect_checkbox_(NULL) { |
56 Init(); | 58 Init(); |
57 } | 59 } |
58 | 60 |
| 61 WifiConfigView::~WifiConfigView() { |
| 62 } |
| 63 |
59 void WifiConfigView::UpdateCanLogin(void) { | 64 void WifiConfigView::UpdateCanLogin(void) { |
60 bool can_login = true; | 65 bool can_login = true; |
61 if (other_network_) { | 66 if (other_network_) { |
62 // Since the user can try to connect to a non-encrypted hidden network, | 67 // Since the user can try to connect to a non-encrypted hidden network, |
63 // only enforce ssid is non-empty. | 68 // only enforce ssid is non-empty. |
64 can_login = !ssid_textfield_->text().empty(); | 69 can_login = !ssid_textfield_->text().empty(); |
65 } else { | 70 } else { |
66 // Connecting to an encrypted network | 71 // Connecting to an encrypted network |
67 if (passphrase_textfield_ != NULL) { | 72 if (passphrase_textfield_ != NULL) { |
68 // if the network requires a passphrase, make sure it is non empty. | 73 // if the network requires a passphrase, make sure it is non empty. |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 identity_string = UTF16ToUTF8(identity_textfield_->text()); | 147 identity_string = UTF16ToUTF8(identity_textfield_->text()); |
143 } | 148 } |
144 if (other_network_) { | 149 if (other_network_) { |
145 CrosLibrary::Get()->GetNetworkLibrary()->ConnectToWifiNetwork( | 150 CrosLibrary::Get()->GetNetworkLibrary()->ConnectToWifiNetwork( |
146 GetSSID(), GetPassphrase(), | 151 GetSSID(), GetPassphrase(), |
147 identity_string, certificate_path_, | 152 identity_string, certificate_path_, |
148 autoconnect_checkbox_ ? autoconnect_checkbox_->checked() : true); | 153 autoconnect_checkbox_ ? autoconnect_checkbox_->checked() : true); |
149 } else { | 154 } else { |
150 Save(); | 155 Save(); |
151 CrosLibrary::Get()->GetNetworkLibrary()->ConnectToWifiNetwork( | 156 CrosLibrary::Get()->GetNetworkLibrary()->ConnectToWifiNetwork( |
152 wifi_, GetPassphrase(), | 157 wifi_.get(), GetPassphrase(), |
153 identity_string, certificate_path_); | 158 identity_string, certificate_path_); |
154 } | 159 } |
155 return true; | 160 return true; |
156 } | 161 } |
157 | 162 |
158 bool WifiConfigView::Save() { | 163 bool WifiConfigView::Save() { |
159 // Save password and auto-connect here. | 164 // Save password and auto-connect here. |
160 if (!other_network_) { | 165 if (!other_network_) { |
161 bool changed = false; | 166 bool changed = false; |
162 | 167 |
163 if (autoconnect_checkbox_) { | 168 if (autoconnect_checkbox_) { |
164 bool auto_connect = autoconnect_checkbox_->checked(); | 169 bool auto_connect = autoconnect_checkbox_->checked(); |
165 if (auto_connect != wifi_.auto_connect()) { | 170 if (auto_connect != wifi_->auto_connect()) { |
166 wifi_.set_auto_connect(auto_connect); | 171 wifi_->set_auto_connect(auto_connect); |
167 changed = true; | 172 changed = true; |
168 } | 173 } |
169 } | 174 } |
170 | 175 |
171 if (passphrase_textfield_) { | 176 if (passphrase_textfield_) { |
172 const std::string& passphrase = | 177 const std::string& passphrase = |
173 UTF16ToUTF8(passphrase_textfield_->text()); | 178 UTF16ToUTF8(passphrase_textfield_->text()); |
174 if (passphrase != wifi_.passphrase()) { | 179 if (passphrase != wifi_->passphrase()) { |
175 wifi_.set_passphrase(passphrase); | 180 wifi_->set_passphrase(passphrase); |
176 changed = true; | 181 changed = true; |
177 } | 182 } |
178 } | 183 } |
179 | 184 |
180 if (changed) | 185 if (changed) |
181 CrosLibrary::Get()->GetNetworkLibrary()->SaveWifiNetwork(wifi_); | 186 CrosLibrary::Get()->GetNetworkLibrary()->SaveWifiNetwork(wifi_.get()); |
182 } | 187 } |
183 return true; | 188 return true; |
184 } | 189 } |
185 | 190 |
186 const std::string WifiConfigView::GetSSID() const { | 191 const std::string WifiConfigView::GetSSID() const { |
187 std::string result; | 192 std::string result; |
188 if (ssid_textfield_ != NULL) | 193 if (ssid_textfield_ != NULL) |
189 result = UTF16ToUTF8(ssid_textfield_->text()); | 194 result = UTF16ToUTF8(ssid_textfield_->text()); |
190 return result; | 195 return result; |
191 } | 196 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 views::GridLayout::USE_PREF, 0, 0); | 228 views::GridLayout::USE_PREF, 0, 0); |
224 | 229 |
225 layout->StartRow(0, column_view_set_id); | 230 layout->StartRow(0, column_view_set_id); |
226 layout->AddView(new views::Label(l10n_util::GetString( | 231 layout->AddView(new views::Label(l10n_util::GetString( |
227 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NETWORK_ID))); | 232 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NETWORK_ID))); |
228 if (other_network_) { | 233 if (other_network_) { |
229 ssid_textfield_ = new views::Textfield(views::Textfield::STYLE_DEFAULT); | 234 ssid_textfield_ = new views::Textfield(views::Textfield::STYLE_DEFAULT); |
230 ssid_textfield_->SetController(this); | 235 ssid_textfield_->SetController(this); |
231 layout->AddView(ssid_textfield_); | 236 layout->AddView(ssid_textfield_); |
232 } else { | 237 } else { |
233 views::Label* label = new views::Label(ASCIIToWide(wifi_.name())); | 238 views::Label* label = new views::Label(ASCIIToWide(wifi_->name())); |
234 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 239 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
235 layout->AddView(label); | 240 layout->AddView(label); |
236 } | 241 } |
237 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 242 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
238 | 243 |
239 // Loaded certificates (i.e. stored in a pkcs11 device) do not require | 244 // Loaded certificates (i.e. stored in a pkcs11 device) do not require |
240 // a passphrase. | 245 // a passphrase. |
241 bool certificate_loaded = false; | 246 bool certificate_loaded = false; |
242 | 247 |
243 // Add ID and cert password if we're using 802.1x | 248 // Add ID and cert password if we're using 802.1x |
244 // XXX we're cheating and assuming 802.1x means EAP-TLS - not true | 249 // XXX we're cheating and assuming 802.1x means EAP-TLS - not true |
245 // in general, but very common. WPA Supplicant doesn't report the | 250 // in general, but very common. WPA Supplicant doesn't report the |
246 // EAP type because it's unknown until the process begins, and we'd | 251 // EAP type because it's unknown until the process begins, and we'd |
247 // need some kind of callback. | 252 // need some kind of callback. |
248 if (wifi_.encrypted() && wifi_.encryption() == SECURITY_8021X) { | 253 if (wifi_->encrypted() && wifi_->encryption() == SECURITY_8021X) { |
249 layout->StartRow(0, column_view_set_id); | 254 layout->StartRow(0, column_view_set_id); |
250 layout->AddView(new views::Label(l10n_util::GetString( | 255 layout->AddView(new views::Label(l10n_util::GetString( |
251 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_IDENTITY))); | 256 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_IDENTITY))); |
252 identity_textfield_ = new views::Textfield( | 257 identity_textfield_ = new views::Textfield( |
253 views::Textfield::STYLE_DEFAULT); | 258 views::Textfield::STYLE_DEFAULT); |
254 identity_textfield_->SetController(this); | 259 identity_textfield_->SetController(this); |
255 if (!wifi_.identity().empty()) | 260 if (!wifi_->identity().empty()) |
256 identity_textfield_->SetText(UTF8ToUTF16(wifi_.identity())); | 261 identity_textfield_->SetText(UTF8ToUTF16(wifi_->identity())); |
257 layout->AddView(identity_textfield_); | 262 layout->AddView(identity_textfield_); |
258 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 263 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
259 layout->StartRow(0, column_view_set_id); | 264 layout->StartRow(0, column_view_set_id); |
260 layout->AddView(new views::Label(l10n_util::GetString( | 265 layout->AddView(new views::Label(l10n_util::GetString( |
261 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT))); | 266 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT))); |
262 if (!wifi_.cert_path().empty()) { | 267 if (!wifi_->cert_path().empty()) { |
263 certificate_path_ = wifi_.cert_path(); | 268 certificate_path_ = wifi_->cert_path(); |
264 certificate_loaded = wifi_.IsCertificateLoaded(); | 269 certificate_loaded = wifi_->IsCertificateLoaded(); |
265 } | 270 } |
266 if (certificate_loaded) { | 271 if (certificate_loaded) { |
267 std::wstring label = l10n_util::GetString( | 272 std::wstring label = l10n_util::GetString( |
268 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_INSTALLED); | 273 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_INSTALLED); |
269 views::Label* cert_text = new views::Label(label); | 274 views::Label* cert_text = new views::Label(label); |
270 cert_text->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 275 cert_text->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
271 layout->AddView(cert_text); | 276 layout->AddView(cert_text); |
272 } else { | 277 } else { |
273 std::wstring label; | 278 std::wstring label; |
274 if (!certificate_path_.empty()) | 279 if (!certificate_path_.empty()) |
275 label = UTF8ToWide(certificate_path_); | 280 label = UTF8ToWide(certificate_path_); |
276 else | 281 else |
277 label = l10n_util::GetString( | 282 label = l10n_util::GetString( |
278 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_BUTTON); | 283 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_BUTTON); |
279 certificate_browse_button_ = new views::NativeButton(this, label); | 284 certificate_browse_button_ = new views::NativeButton(this, label); |
280 layout->AddView(certificate_browse_button_); | 285 layout->AddView(certificate_browse_button_); |
281 } | 286 } |
282 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 287 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
283 } | 288 } |
284 | 289 |
285 // Add passphrase if other_network or wifi is encrypted. | 290 // Add passphrase if other_network or wifi is encrypted. |
286 if (other_network_ || (wifi_.encrypted() && !certificate_loaded)) { | 291 if (other_network_ || (wifi_->encrypted() && !certificate_loaded)) { |
287 layout->StartRow(0, column_view_set_id); | 292 layout->StartRow(0, column_view_set_id); |
288 int label_text_id; | 293 int label_text_id; |
289 if (wifi_.encryption() == SECURITY_8021X) | 294 if (wifi_->encryption() == SECURITY_8021X) |
290 label_text_id = | 295 label_text_id = |
291 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PRIVATE_KEY_PASSWORD; | 296 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PRIVATE_KEY_PASSWORD; |
292 else | 297 else |
293 label_text_id = IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSPHRASE; | 298 label_text_id = IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSPHRASE; |
294 layout->AddView(new views::Label(l10n_util::GetString(label_text_id))); | 299 layout->AddView(new views::Label(l10n_util::GetString(label_text_id))); |
295 passphrase_textfield_ = new views::Textfield( | 300 passphrase_textfield_ = new views::Textfield( |
296 views::Textfield::STYLE_PASSWORD); | 301 views::Textfield::STYLE_PASSWORD); |
297 passphrase_textfield_->SetController(this); | 302 passphrase_textfield_->SetController(this); |
298 if (!wifi_.passphrase().empty()) | 303 if (!wifi_->passphrase().empty()) |
299 passphrase_textfield_->SetText(UTF8ToUTF16(wifi_.passphrase())); | 304 passphrase_textfield_->SetText(UTF8ToUTF16(wifi_->passphrase())); |
300 layout->AddView(passphrase_textfield_); | 305 layout->AddView(passphrase_textfield_); |
301 // Password visible button. | 306 // Password visible button. |
302 passphrase_visible_button_ = new views::ImageButton(this); | 307 passphrase_visible_button_ = new views::ImageButton(this); |
303 passphrase_visible_button_->SetImage(views::ImageButton::BS_NORMAL, | 308 passphrase_visible_button_->SetImage(views::ImageButton::BS_NORMAL, |
304 ResourceBundle::GetSharedInstance(). | 309 ResourceBundle::GetSharedInstance(). |
305 GetBitmapNamed(IDR_STATUSBAR_NETWORK_SECURE)); | 310 GetBitmapNamed(IDR_STATUSBAR_NETWORK_SECURE)); |
306 passphrase_visible_button_->SetImageAlignment( | 311 passphrase_visible_button_->SetImageAlignment( |
307 views::ImageButton::ALIGN_CENTER, views::ImageButton::ALIGN_MIDDLE); | 312 views::ImageButton::ALIGN_CENTER, views::ImageButton::ALIGN_MIDDLE); |
308 // Disable viewing password by unauthenticated user. | 313 // Disable viewing password by unauthenticated user. |
309 if (!wifi_.passphrase().empty() && | 314 if (!wifi_->passphrase().empty() && |
310 chromeos::UserManager::Get()->logged_in_user().email().empty()) { | 315 chromeos::UserManager::Get()->logged_in_user().email().empty()) { |
311 passphrase_visible_button_->SetVisible(false); | 316 passphrase_visible_button_->SetVisible(false); |
312 } | 317 } |
313 layout->AddView(passphrase_visible_button_); | 318 layout->AddView(passphrase_visible_button_); |
314 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 319 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
315 } | 320 } |
316 | 321 |
317 // If there's an error, add an error message label. | 322 // If there's an error, add an error message label. |
318 // Right now, only displaying bad_passphrase and bad_wepkey errors. | 323 // Right now, only displaying bad_passphrase and bad_wepkey errors. |
319 if (wifi_.error() == ERROR_BAD_PASSPHRASE || | 324 if (wifi_->error() == ERROR_BAD_PASSPHRASE || |
320 wifi_.error() == ERROR_BAD_WEPKEY) { | 325 wifi_->error() == ERROR_BAD_WEPKEY) { |
321 layout->StartRow(0, column_view_set_id); | 326 layout->StartRow(0, column_view_set_id); |
322 layout->SkipColumns(1); | 327 layout->SkipColumns(1); |
323 int id = IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_BAD_PASSPHRASE; | 328 int id = IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_BAD_PASSPHRASE; |
324 if (wifi_.error() == ERROR_BAD_WEPKEY) | 329 if (wifi_->error() == ERROR_BAD_WEPKEY) |
325 id = IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_BAD_WEPKEY; | 330 id = IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_BAD_WEPKEY; |
326 views::Label* label_error = new views::Label(l10n_util::GetString(id)); | 331 views::Label* label_error = new views::Label(l10n_util::GetString(id)); |
327 label_error->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 332 label_error->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
328 label_error->SetColor(SK_ColorRED); | 333 label_error->SetColor(SK_ColorRED); |
329 layout->AddView(label_error); | 334 layout->AddView(label_error); |
330 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 335 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
331 } | 336 } |
332 | 337 |
333 // Autoconnect checkbox | 338 // Autoconnect checkbox |
334 // Only show if this network is already remembered (a favorite). | 339 // Only show if this network is already remembered (a favorite). |
335 if (wifi_.favorite()) { | 340 if (wifi_->favorite()) { |
336 autoconnect_checkbox_ = new views::Checkbox(l10n_util::GetString( | 341 autoconnect_checkbox_ = new views::Checkbox(l10n_util::GetString( |
337 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_AUTO_CONNECT)); | 342 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_AUTO_CONNECT)); |
338 // For other network, default to autoconnect. | 343 // For other network, default to autoconnect. |
339 bool autoconnect = other_network_ || wifi_.auto_connect(); | 344 bool autoconnect = other_network_ || wifi_->auto_connect(); |
340 autoconnect_checkbox_->SetChecked(autoconnect); | 345 autoconnect_checkbox_->SetChecked(autoconnect); |
341 layout->StartRow(0, column_view_set_id); | 346 layout->StartRow(0, column_view_set_id); |
342 layout->AddView(autoconnect_checkbox_, 3, 1); | 347 layout->AddView(autoconnect_checkbox_, 3, 1); |
343 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 348 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
344 } | 349 } |
345 } | 350 } |
346 | 351 |
347 } // namespace chromeos | 352 } // namespace chromeos |
OLD | NEW |