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