OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/chromeos/cros/cros_library.h" |
10 #include "chrome/browser/chromeos/options/network_config_view.h" | 11 #include "chrome/browser/chromeos/options/network_config_view.h" |
11 #include "grit/chromium_strings.h" | 12 #include "grit/chromium_strings.h" |
12 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
13 #include "grit/locale_settings.h" | 14 #include "grit/locale_settings.h" |
14 #include "grit/theme_resources.h" | 15 #include "grit/theme_resources.h" |
15 #include "views/controls/button/image_button.h" | 16 #include "views/controls/button/image_button.h" |
| 17 #include "views/controls/button/native_button.h" |
16 #include "views/controls/label.h" | 18 #include "views/controls/label.h" |
17 #include "views/grid_layout.h" | 19 #include "views/grid_layout.h" |
18 #include "views/standard_layout.h" | 20 #include "views/standard_layout.h" |
19 #include "views/window/window.h" | 21 #include "views/window/window.h" |
20 | 22 |
21 namespace chromeos { | 23 namespace chromeos { |
22 | 24 |
23 WifiConfigView::WifiConfigView(NetworkConfigView* parent, WifiNetwork wifi) | 25 WifiConfigView::WifiConfigView(NetworkConfigView* parent, WifiNetwork wifi) |
24 : parent_(parent), | 26 : parent_(parent), |
25 other_network_(false), | 27 other_network_(false), |
26 can_login_(false), | 28 can_login_(false), |
27 wifi_(wifi), | 29 wifi_(wifi), |
28 ssid_textfield_(NULL), | 30 ssid_textfield_(NULL), |
29 passphrase_textfield_(NULL) { | 31 identity_textfield_(NULL), |
| 32 certificate_browse_button_(NULL), |
| 33 certificate_path_(), |
| 34 passphrase_textfield_(NULL), |
| 35 passphrase_visible_button_(NULL) { |
30 Init(); | 36 Init(); |
31 } | 37 } |
32 | 38 |
33 WifiConfigView::WifiConfigView(NetworkConfigView* parent) | 39 WifiConfigView::WifiConfigView(NetworkConfigView* parent) |
34 : parent_(parent), | 40 : parent_(parent), |
35 other_network_(true), | 41 other_network_(true), |
36 can_login_(false), | 42 can_login_(false), |
37 ssid_textfield_(NULL), | 43 ssid_textfield_(NULL), |
38 passphrase_textfield_(NULL) { | 44 identity_textfield_(NULL), |
| 45 certificate_browse_button_(NULL), |
| 46 certificate_path_(), |
| 47 passphrase_textfield_(NULL), |
| 48 passphrase_visible_button_(NULL) { |
39 Init(); | 49 Init(); |
40 } | 50 } |
41 | 51 |
42 void WifiConfigView::ContentsChanged(views::Textfield* sender, | 52 void WifiConfigView::UpdateCanLogin(void) { |
43 const string16& new_contents) { | |
44 bool can_login = true; | 53 bool can_login = true; |
45 if (other_network_) { | 54 if (other_network_) { |
46 // Since the user can try to connect to a non-encrypted hidden network, | 55 // Since the user can try to connect to a non-encrypted hidden network, |
47 // only enforce ssid is non-empty. | 56 // only enforce ssid is non-empty. |
48 can_login = !ssid_textfield_->text().empty(); | 57 can_login = !ssid_textfield_->text().empty(); |
49 } else { | 58 } else { |
50 // Connecting to an encrypted network, so make sure passphrase is non-empty. | 59 // Connecting to an encrypted network, so make sure passphrase is non-empty. |
51 can_login = !passphrase_textfield_->text().empty(); | 60 can_login = !passphrase_textfield_->text().empty(); |
| 61 if (identity_textfield_ != NULL) |
| 62 can_login = !identity_textfield_->text().empty() && |
| 63 !certificate_path_.empty(); |
52 } | 64 } |
53 | 65 |
54 // Update the login button enable/disable state if can_login_ changes. | 66 // Update the login button enable/disable state if can_login_ changes. |
55 if (can_login != can_login_) { | 67 if (can_login != can_login_) { |
56 can_login_ = can_login; | 68 can_login_ = can_login; |
57 parent_->GetDialogClientView()->UpdateDialogButtons(); | 69 parent_->GetDialogClientView()->UpdateDialogButtons(); |
58 } | 70 } |
59 } | 71 } |
60 | 72 |
| 73 void WifiConfigView::ContentsChanged(views::Textfield* sender, |
| 74 const string16& new_contents) { |
| 75 UpdateCanLogin(); |
| 76 } |
| 77 |
61 void WifiConfigView::ButtonPressed(views::Button* sender, | 78 void WifiConfigView::ButtonPressed(views::Button* sender, |
62 const views::Event& event) { | 79 const views::Event& event) { |
63 // We only have one button to toggle password visible. | 80 if (sender == passphrase_visible_button_) { |
64 if (passphrase_textfield_) | 81 if (passphrase_textfield_) |
65 passphrase_textfield_->SetPassword(!passphrase_textfield_->IsPassword()); | 82 passphrase_textfield_->SetPassword(!passphrase_textfield_->IsPassword()); |
| 83 } else if (sender == certificate_browse_button_) { |
| 84 select_file_dialog_ = SelectFileDialog::Create(this); |
| 85 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE, |
| 86 string16(), FilePath(), NULL, 0, |
| 87 std::string(), NULL, NULL); |
| 88 } else { |
| 89 NOTREACHED(); |
| 90 } |
| 91 } |
| 92 |
| 93 void WifiConfigView::FileSelected(const FilePath& path, |
| 94 int index, void* params) { |
| 95 certificate_path_ = path; |
| 96 certificate_browse_button_->SetLabel(path.BaseName().ToWStringHack()); |
| 97 UpdateCanLogin(); // TODO(njw) Check if the passphrase decrypts the key. |
| 98 } |
| 99 |
| 100 bool WifiConfigView::Accept() { |
| 101 string16 identity_string, certificate_path_string; |
| 102 |
| 103 if (identity_textfield_ != NULL) { |
| 104 identity_string = identity_textfield_->text(); |
| 105 certificate_path_string = WideToUTF16(certificate_path_.ToWStringHack()); |
| 106 } |
| 107 if (other_network_) { |
| 108 CrosLibrary::Get()->GetNetworkLibrary()->ConnectToWifiNetwork( |
| 109 ssid_textfield_->text(), passphrase_textfield_->text(), |
| 110 identity_string, certificate_path_string); |
| 111 } else { |
| 112 CrosLibrary::Get()->GetNetworkLibrary()->ConnectToWifiNetwork( |
| 113 wifi_, passphrase_textfield_->text(), |
| 114 identity_string, certificate_path_string); |
| 115 } |
| 116 return true; |
66 } | 117 } |
67 | 118 |
68 const string16& WifiConfigView::GetSSID() const { | 119 const string16& WifiConfigView::GetSSID() const { |
69 return ssid_textfield_->text(); | 120 return ssid_textfield_->text(); |
70 } | 121 } |
71 | 122 |
72 const string16& WifiConfigView::GetPassphrase() const { | 123 const string16& WifiConfigView::GetPassphrase() const { |
73 return passphrase_textfield_->text(); | 124 return passphrase_textfield_->text(); |
74 } | 125 } |
75 | 126 |
76 void WifiConfigView::FocusFirstField() { | 127 void WifiConfigView::FocusFirstField() { |
77 if (ssid_textfield_) | 128 if (ssid_textfield_) |
78 ssid_textfield_->RequestFocus(); | 129 ssid_textfield_->RequestFocus(); |
| 130 else if (identity_textfield_) |
| 131 identity_textfield_->RequestFocus(); |
79 else if (passphrase_textfield_) | 132 else if (passphrase_textfield_) |
80 passphrase_textfield_->RequestFocus(); | 133 passphrase_textfield_->RequestFocus(); |
81 } | 134 } |
82 | 135 |
83 void WifiConfigView::Init() { | 136 void WifiConfigView::Init() { |
84 views::GridLayout* layout = CreatePanelGridLayout(this); | 137 views::GridLayout* layout = CreatePanelGridLayout(this); |
85 SetLayoutManager(layout); | 138 SetLayoutManager(layout); |
86 | 139 |
87 int column_view_set_id = 0; | 140 int column_view_set_id = 0; |
88 views::ColumnSet* column_set = layout->AddColumnSet(column_view_set_id); | 141 views::ColumnSet* column_set = layout->AddColumnSet(column_view_set_id); |
(...skipping 14 matching lines...) Expand all Loading... |
103 ssid_textfield_ = new views::Textfield(views::Textfield::STYLE_DEFAULT); | 156 ssid_textfield_ = new views::Textfield(views::Textfield::STYLE_DEFAULT); |
104 ssid_textfield_->SetController(this); | 157 ssid_textfield_->SetController(this); |
105 layout->AddView(ssid_textfield_); | 158 layout->AddView(ssid_textfield_); |
106 } else { | 159 } else { |
107 views::Label* label = new views::Label(ASCIIToWide(wifi_.ssid)); | 160 views::Label* label = new views::Label(ASCIIToWide(wifi_.ssid)); |
108 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 161 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
109 layout->AddView(label); | 162 layout->AddView(label); |
110 } | 163 } |
111 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 164 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
112 | 165 |
| 166 // Add ID and cert password if we're using 802.1x |
| 167 // XXX we're cheating and assuming 802.1x means EAP-TLS - not true |
| 168 // in general, but very common. WPA Supplicant doesn't report the |
| 169 // EAP type because it's unknown until the process begins, and we'd |
| 170 // need some kind of callback. |
| 171 if (wifi_.encrypted && wifi_.encryption == SECURITY_8021X) { |
| 172 layout->StartRow(0, column_view_set_id); |
| 173 layout->AddView(new views::Label(l10n_util::GetString( |
| 174 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_IDENTITY))); |
| 175 identity_textfield_ = new views::Textfield( |
| 176 views::Textfield::STYLE_DEFAULT); |
| 177 identity_textfield_->SetController(this); |
| 178 layout->AddView(identity_textfield_); |
| 179 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
| 180 layout->StartRow(0, column_view_set_id); |
| 181 layout->AddView(new views::Label(l10n_util::GetString( |
| 182 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT))); |
| 183 certificate_browse_button_ = new views::NativeButton(this, |
| 184 l10n_util::GetString( |
| 185 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_BUTTON)); |
| 186 layout->AddView(certificate_browse_button_); |
| 187 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
| 188 } |
| 189 |
113 // Add passphrase if other_network or wifi is encrypted. | 190 // Add passphrase if other_network or wifi is encrypted. |
114 if (other_network_ || wifi_.encrypted) { | 191 if (other_network_ || wifi_.encrypted) { |
115 layout->StartRow(0, column_view_set_id); | 192 layout->StartRow(0, column_view_set_id); |
116 layout->AddView(new views::Label(l10n_util::GetString( | 193 int label_text_id; |
117 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSPHRASE))); | 194 if (wifi_.encryption == SECURITY_8021X) |
| 195 label_text_id = IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT; |
| 196 else |
| 197 label_text_id = IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSPHRASE; |
| 198 layout->AddView(new views::Label(l10n_util::GetString(label_text_id))); |
118 passphrase_textfield_ = new views::Textfield( | 199 passphrase_textfield_ = new views::Textfield( |
119 views::Textfield::STYLE_PASSWORD); | 200 views::Textfield::STYLE_PASSWORD); |
120 passphrase_textfield_->SetController(this); | 201 passphrase_textfield_->SetController(this); |
121 if (!wifi_.passphrase.empty()) | 202 if (!wifi_.passphrase.empty()) |
122 passphrase_textfield_->SetText(UTF8ToUTF16(wifi_.passphrase)); | 203 passphrase_textfield_->SetText(UTF8ToUTF16(wifi_.passphrase)); |
123 layout->AddView(passphrase_textfield_); | 204 layout->AddView(passphrase_textfield_); |
124 // Password visible button. | 205 // Password visible button. |
125 views::ImageButton* button = new views::ImageButton(this); | 206 passphrase_visible_button_ = new views::ImageButton(this); |
126 button->SetImage(views::ImageButton::BS_NORMAL, | 207 passphrase_visible_button_->SetImage(views::ImageButton::BS_NORMAL, |
127 ResourceBundle::GetSharedInstance().GetBitmapNamed( | 208 ResourceBundle::GetSharedInstance(). |
128 IDR_STATUSBAR_NETWORK_SECURE)); | 209 GetBitmapNamed(IDR_STATUSBAR_NETWORK_SECURE)); |
129 button->SetImageAlignment(views::ImageButton::ALIGN_CENTER, | 210 passphrase_visible_button_->SetImageAlignment( |
130 views::ImageButton::ALIGN_MIDDLE); | 211 views::ImageButton::ALIGN_CENTER, views::ImageButton::ALIGN_MIDDLE); |
131 layout->AddView(button); | 212 layout->AddView(passphrase_visible_button_); |
132 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 213 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
133 } | 214 } |
134 } | 215 } |
135 | 216 |
136 } // namespace chromeos | 217 } // namespace chromeos |
OLD | NEW |