OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/wimax_config_view.h" | 5 #include "chrome/browser/chromeos/options/wimax_config_view.h" |
6 | 6 |
7 #include "ash/system/chromeos/network/network_connect.h" | |
7 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
8 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/chromeos/cros/network_library.h" | |
11 #include "chrome/browser/chromeos/enrollment_dialog_view.h" | 11 #include "chrome/browser/chromeos/enrollment_dialog_view.h" |
12 #include "chrome/browser/chromeos/login/startup_utils.h" | 12 #include "chrome/browser/chromeos/login/startup_utils.h" |
13 #include "chrome/browser/chromeos/options/network_connect.h" | |
13 #include "chrome/browser/profiles/profile_manager.h" | 14 #include "chrome/browser/profiles/profile_manager.h" |
14 #include "chromeos/login/login_state.h" | 15 #include "chromeos/login/login_state.h" |
16 #include "chromeos/network/network_configuration_handler.h" | |
17 #include "chromeos/network/network_event_log.h" | |
18 #include "chromeos/network/network_profile.h" | |
19 #include "chromeos/network/network_profile_handler.h" | |
20 #include "chromeos/network/network_state.h" | |
21 #include "chromeos/network/network_state_handler.h" | |
15 #include "chromeos/network/onc/onc_constants.h" | 22 #include "chromeos/network/onc/onc_constants.h" |
16 #include "grit/chromium_strings.h" | 23 #include "grit/chromium_strings.h" |
17 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
18 #include "grit/locale_settings.h" | 25 #include "grit/locale_settings.h" |
19 #include "grit/theme_resources.h" | 26 #include "grit/theme_resources.h" |
27 #include "third_party/cros_system_api/dbus/service_constants.h" | |
20 #include "ui/base/events/event.h" | 28 #include "ui/base/events/event.h" |
21 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
22 #include "ui/base/resource/resource_bundle.h" | 30 #include "ui/base/resource/resource_bundle.h" |
23 #include "ui/views/controls/button/checkbox.h" | 31 #include "ui/views/controls/button/checkbox.h" |
24 #include "ui/views/controls/button/image_button.h" | 32 #include "ui/views/controls/button/image_button.h" |
25 #include "ui/views/controls/label.h" | 33 #include "ui/views/controls/label.h" |
26 #include "ui/views/controls/textfield/textfield.h" | 34 #include "ui/views/controls/textfield/textfield.h" |
27 #include "ui/views/layout/grid_layout.h" | 35 #include "ui/views/layout/grid_layout.h" |
28 #include "ui/views/layout/layout_constants.h" | 36 #include "ui/views/layout/layout_constants.h" |
29 #include "ui/views/widget/widget.h" | 37 #include "ui/views/widget/widget.h" |
30 #include "ui/views/window/dialog_client_view.h" | 38 #include "ui/views/window/dialog_client_view.h" |
31 | 39 |
32 namespace chromeos { | 40 namespace chromeos { |
33 | 41 |
34 WimaxConfigView::WimaxConfigView(NetworkConfigView* parent, WimaxNetwork* wimax) | 42 namespace { |
35 : ChildNetworkConfigView(parent, wimax), | 43 |
44 void ShillError(const std::string& function, | |
45 const std::string& error_name, | |
46 scoped_ptr<base::DictionaryValue> error_data) { | |
47 NET_LOG_ERROR("Shill Error from WimaxConfigView: " + error_name, function); | |
48 } | |
49 | |
50 } // namespace | |
51 | |
52 WimaxConfigView::WimaxConfigView(NetworkConfigView* parent, | |
53 const std::string& service_path) | |
54 : ChildNetworkConfigView(parent, service_path), | |
36 identity_label_(NULL), | 55 identity_label_(NULL), |
37 identity_textfield_(NULL), | 56 identity_textfield_(NULL), |
38 save_credentials_checkbox_(NULL), | 57 save_credentials_checkbox_(NULL), |
39 share_network_checkbox_(NULL), | 58 share_network_checkbox_(NULL), |
40 shared_network_label_(NULL), | 59 shared_network_label_(NULL), |
41 passphrase_label_(NULL), | 60 passphrase_label_(NULL), |
42 passphrase_textfield_(NULL), | 61 passphrase_textfield_(NULL), |
43 passphrase_visible_button_(NULL), | 62 passphrase_visible_button_(NULL), |
44 error_label_(NULL) { | 63 error_label_(NULL) { |
45 Init(wimax); | 64 Init(service_path); |
46 } | 65 } |
47 | 66 |
48 WimaxConfigView::~WimaxConfigView() { | 67 WimaxConfigView::~WimaxConfigView() { |
49 } | 68 } |
50 | 69 |
51 string16 WimaxConfigView::GetTitle() const { | 70 string16 WimaxConfigView::GetTitle() const { |
52 return l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_JOIN_WIMAX_NETWORKS); | 71 return l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_JOIN_WIMAX_NETWORKS); |
53 } | 72 } |
54 | 73 |
55 views::View* WimaxConfigView::GetInitiallyFocusedView() { | 74 views::View* WimaxConfigView::GetInitiallyFocusedView() { |
(...skipping 13 matching lines...) Expand all Loading... | |
69 // check if empty). | 88 // check if empty). |
70 // If the network requires a passphrase, make sure it is the right length. | 89 // If the network requires a passphrase, make sure it is the right length. |
71 return passphrase_textfield_ && !passphrase_textfield_->text().empty(); | 90 return passphrase_textfield_ && !passphrase_textfield_->text().empty(); |
72 } | 91 } |
73 | 92 |
74 void WimaxConfigView::UpdateDialogButtons() { | 93 void WimaxConfigView::UpdateDialogButtons() { |
75 parent_->GetDialogClientView()->UpdateDialogButtons(); | 94 parent_->GetDialogClientView()->UpdateDialogButtons(); |
76 } | 95 } |
77 | 96 |
78 void WimaxConfigView::UpdateErrorLabel() { | 97 void WimaxConfigView::UpdateErrorLabel() { |
79 std::string error_msg; | 98 base::string16 error_msg; |
80 if (!service_path_.empty()) { | 99 if (!service_path_.empty()) { |
81 NetworkLibrary* cros = NetworkLibrary::Get(); | 100 const NetworkState* wimax = NetworkHandler::Get()->network_state_handler()-> |
82 const WimaxNetwork* wimax = cros->FindWimaxNetworkByPath(service_path_); | 101 GetNetworkState(service_path_); |
gauravsh
2013/08/03 01:15:54
Add DCHECK to verity this is a kTypeWimax network.
stevenjb
2013/08/06 00:32:48
Added a DCHECK in Init()
| |
83 if (wimax && wimax->failed()) { | 102 if (wimax && wimax->connection_state() == flimflam::kStateFailure) |
84 bool passphrase_empty = wimax->eap_passphrase().empty(); | 103 error_msg = ash::network_connect::ErrorString(wimax->error()); |
85 switch (wimax->error()) { | |
86 case ERROR_BAD_PASSPHRASE: | |
87 if (!passphrase_empty) { | |
88 error_msg = l10n_util::GetStringUTF8( | |
89 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_BAD_PASSPHRASE); | |
90 } | |
91 break; | |
92 case ERROR_BAD_WEPKEY: | |
93 if (!passphrase_empty) { | |
94 error_msg = l10n_util::GetStringUTF8( | |
95 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_BAD_WEPKEY); | |
96 } | |
97 break; | |
98 default: | |
99 error_msg = wimax->GetErrorString(); | |
100 break; | |
101 } | |
102 } | |
103 } | 104 } |
104 if (!error_msg.empty()) { | 105 if (!error_msg.empty()) { |
105 error_label_->SetText(UTF8ToUTF16(error_msg)); | 106 error_label_->SetText(error_msg); |
106 error_label_->SetVisible(true); | 107 error_label_->SetVisible(true); |
107 } else { | 108 } else { |
108 error_label_->SetVisible(false); | 109 error_label_->SetVisible(false); |
109 } | 110 } |
110 } | 111 } |
111 | 112 |
112 void WimaxConfigView::ContentsChanged(views::Textfield* sender, | 113 void WimaxConfigView::ContentsChanged(views::Textfield* sender, |
113 const string16& new_contents) { | 114 const string16& new_contents) { |
114 UpdateDialogButtons(); | 115 UpdateDialogButtons(); |
115 } | 116 } |
(...skipping 14 matching lines...) Expand all Loading... | |
130 passphrase_textfield_->SetObscured(!passphrase_textfield_->IsObscured()); | 131 passphrase_textfield_->SetObscured(!passphrase_textfield_->IsObscured()); |
131 passphrase_visible_button_->SetToggled( | 132 passphrase_visible_button_->SetToggled( |
132 !passphrase_textfield_->IsObscured()); | 133 !passphrase_textfield_->IsObscured()); |
133 } | 134 } |
134 } else { | 135 } else { |
135 NOTREACHED(); | 136 NOTREACHED(); |
136 } | 137 } |
137 } | 138 } |
138 | 139 |
139 bool WimaxConfigView::Login() { | 140 bool WimaxConfigView::Login() { |
140 NetworkLibrary* cros = NetworkLibrary::Get(); | 141 const NetworkState* wimax = NetworkHandler::Get()->network_state_handler()-> |
141 WimaxNetwork* wimax = cros->FindWimaxNetworkByPath(service_path_); | 142 GetNetworkState(service_path_); |
142 if (!wimax) { | 143 if (!wimax) { |
143 // Shill no longer knows about this wimax network (edge case). | 144 // Shill no longer knows about this network (edge case). |
144 // TODO(stevenjb): Add a notification (chromium-os13225). | 145 // TODO(stevenjb): Add notification for this. |
145 LOG(WARNING) << "Wimax network: " << service_path_ << " no longer exists."; | 146 NET_LOG_ERROR("Network not found", service_path_); |
146 return true; | 147 return true; // Close dialog |
147 } | 148 } |
148 wimax->SetEAPIdentity(GetEapIdentity()); | 149 base::DictionaryValue properties; |
149 wimax->SetEAPPassphrase(GetEapPassphrase()); | 150 properties.SetStringWithoutPathExpansion( |
150 wimax->SetSaveCredentials(GetSaveCredentials()); | 151 flimflam::kEapIdentityProperty, GetEapIdentity()); |
151 bool share_default = (wimax->profile_type() != PROFILE_USER); | 152 properties.SetStringWithoutPathExpansion( |
152 bool share = GetShareNetwork(share_default); | 153 flimflam::kEapPasswordProperty, GetEapPassphrase()); |
153 wimax->SetEnrollmentDelegate( | 154 properties.SetBooleanWithoutPathExpansion( |
154 CreateEnrollmentDelegate(GetWidget()->GetNativeWindow(), | 155 flimflam::kSaveCredentialsProperty, GetSaveCredentials()); |
155 wimax->name(), | 156 bool wimax_shared = !wimax->IsPrivate(); |
gauravsh
2013/08/03 01:15:54
What are lines l156 - l175 doing? (add a comment t
stevenjb
2013/08/06 00:32:48
Comment Added.
| |
156 ProfileManager::GetLastUsedProfile())); | 157 bool share_network = GetShareNetwork(wimax_shared); |
157 cros->ConnectToWimaxNetwork(wimax, share); | 158 if (share_network != wimax_shared) { |
158 // Connection failures are responsible for updating the UI, including | 159 std::string profile_path; |
159 // reopening dialogs. | 160 if (share_network) { |
161 profile_path = NetworkProfileHandler::kSharedProfilePath; | |
162 } else { | |
163 const NetworkProfile* profile = | |
164 NetworkHandler::Get()->network_profile_handler()-> | |
165 GetDefaultUserProfile(); | |
166 if (profile) | |
167 profile_path = profile->path; | |
168 else | |
169 NET_LOG_ERROR("Unable to set user profile", service_path_); | |
170 } | |
171 if (!profile_path.empty()) { | |
172 properties.SetStringWithoutPathExpansion( | |
173 flimflam::kProfileProperty, profile_path); | |
174 } | |
175 } | |
176 ash::network_connect::ConfigureNetworkAndConnect(service_path_, properties); | |
160 return true; // dialog will be closed | 177 return true; // dialog will be closed |
161 } | 178 } |
162 | 179 |
163 std::string WimaxConfigView::GetEapIdentity() const { | 180 std::string WimaxConfigView::GetEapIdentity() const { |
164 DCHECK(identity_textfield_); | 181 DCHECK(identity_textfield_); |
165 return UTF16ToUTF8(identity_textfield_->text()); | 182 return UTF16ToUTF8(identity_textfield_->text()); |
166 } | 183 } |
167 | 184 |
168 std::string WimaxConfigView::GetEapPassphrase() const { | 185 std::string WimaxConfigView::GetEapPassphrase() const { |
169 return passphrase_textfield_ ? UTF16ToUTF8(passphrase_textfield_->text()) : | 186 return passphrase_textfield_ ? UTF16ToUTF8(passphrase_textfield_->text()) : |
170 std::string(); | 187 std::string(); |
171 } | 188 } |
172 | 189 |
173 bool WimaxConfigView::GetSaveCredentials() const { | 190 bool WimaxConfigView::GetSaveCredentials() const { |
174 return save_credentials_checkbox_ ? save_credentials_checkbox_->checked() : | 191 return save_credentials_checkbox_ ? save_credentials_checkbox_->checked() : |
175 false; | 192 false; |
176 } | 193 } |
177 | 194 |
178 bool WimaxConfigView::GetShareNetwork(bool share_default) const { | 195 bool WimaxConfigView::GetShareNetwork(bool share_default) const { |
179 return share_network_checkbox_ ? share_network_checkbox_->checked() : | 196 return share_network_checkbox_ ? share_network_checkbox_->checked() : |
180 share_default; | 197 share_default; |
181 } | 198 } |
182 | 199 |
183 void WimaxConfigView::Cancel() { | 200 void WimaxConfigView::Cancel() { |
184 } | 201 } |
185 | 202 |
186 void WimaxConfigView::Init(WimaxNetwork* wimax) { | 203 void WimaxConfigView::Init(const std::string& service_path) { |
204 const NetworkState* wimax = NetworkHandler::Get()->network_state_handler()-> | |
205 GetNetworkState(service_path); | |
187 DCHECK(wimax); | 206 DCHECK(wimax); |
188 WifiConfigView::ParseWiFiEAPUIProperty( | 207 WifiConfigView::ParseWiFiEAPUIProperty( |
189 &save_credentials_ui_data_, wimax, onc::eap::kSaveCredentials); | 208 &save_credentials_ui_data_, wimax, onc::eap::kSaveCredentials); |
190 WifiConfigView::ParseWiFiEAPUIProperty( | 209 WifiConfigView::ParseWiFiEAPUIProperty( |
191 &identity_ui_data_, wimax, onc::eap::kIdentity); | 210 &identity_ui_data_, wimax, onc::eap::kIdentity); |
192 WifiConfigView::ParseWiFiUIProperty( | 211 WifiConfigView::ParseWiFiUIProperty( |
193 &passphrase_ui_data_, wimax, onc::wifi::kPassphrase); | 212 &passphrase_ui_data_, wimax, onc::wifi::kPassphrase); |
194 | 213 |
195 views::GridLayout* layout = views::GridLayout::CreatePanel(this); | 214 views::GridLayout* layout = views::GridLayout::CreatePanel(this); |
196 SetLayoutManager(layout); | 215 SetLayoutManager(layout); |
(...skipping 26 matching lines...) Expand all Loading... | |
223 // Identity | 242 // Identity |
224 layout->StartRow(0, column_view_set_id); | 243 layout->StartRow(0, column_view_set_id); |
225 string16 identity_label_text = l10n_util::GetStringUTF16( | 244 string16 identity_label_text = l10n_util::GetStringUTF16( |
226 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_IDENTITY); | 245 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_IDENTITY); |
227 identity_label_ = new views::Label(identity_label_text); | 246 identity_label_ = new views::Label(identity_label_text); |
228 layout->AddView(identity_label_); | 247 layout->AddView(identity_label_); |
229 identity_textfield_ = new views::Textfield( | 248 identity_textfield_ = new views::Textfield( |
230 views::Textfield::STYLE_DEFAULT); | 249 views::Textfield::STYLE_DEFAULT); |
231 identity_textfield_->SetAccessibleName(identity_label_text); | 250 identity_textfield_->SetAccessibleName(identity_label_text); |
232 identity_textfield_->SetController(this); | 251 identity_textfield_->SetController(this); |
233 const std::string& eap_identity = wimax->eap_identity(); | |
234 identity_textfield_->SetText(UTF8ToUTF16(eap_identity)); | |
235 identity_textfield_->SetEnabled(identity_ui_data_.IsEditable()); | 252 identity_textfield_->SetEnabled(identity_ui_data_.IsEditable()); |
236 layout->AddView(identity_textfield_); | 253 layout->AddView(identity_textfield_); |
237 layout->AddView(new ControlledSettingIndicatorView(identity_ui_data_)); | 254 layout->AddView(new ControlledSettingIndicatorView(identity_ui_data_)); |
238 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 255 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
239 | 256 |
240 // Passphrase input | 257 // Passphrase input |
241 layout->StartRow(0, column_view_set_id); | 258 layout->StartRow(0, column_view_set_id); |
242 string16 passphrase_label_text = l10n_util::GetStringUTF16( | 259 string16 passphrase_label_text = l10n_util::GetStringUTF16( |
243 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSPHRASE); | 260 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSPHRASE); |
244 passphrase_label_ = new views::Label(passphrase_label_text); | 261 passphrase_label_ = new views::Label(passphrase_label_text); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
289 // Checkboxes. | 306 // Checkboxes. |
290 | 307 |
291 if (LoginState::Get()->IsUserLoggedIn()) { | 308 if (LoginState::Get()->IsUserLoggedIn()) { |
292 // Save credentials | 309 // Save credentials |
293 layout->StartRow(0, column_view_set_id); | 310 layout->StartRow(0, column_view_set_id); |
294 save_credentials_checkbox_ = new views::Checkbox( | 311 save_credentials_checkbox_ = new views::Checkbox( |
295 l10n_util::GetStringUTF16( | 312 l10n_util::GetStringUTF16( |
296 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SAVE_CREDENTIALS)); | 313 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SAVE_CREDENTIALS)); |
297 save_credentials_checkbox_->SetEnabled( | 314 save_credentials_checkbox_->SetEnabled( |
298 save_credentials_ui_data_.IsEditable()); | 315 save_credentials_ui_data_.IsEditable()); |
299 save_credentials_checkbox_->SetChecked(wimax->save_credentials()); | |
300 layout->SkipColumns(1); | 316 layout->SkipColumns(1); |
301 layout->AddView(save_credentials_checkbox_); | 317 layout->AddView(save_credentials_checkbox_); |
302 layout->AddView( | 318 layout->AddView( |
303 new ControlledSettingIndicatorView(save_credentials_ui_data_)); | 319 new ControlledSettingIndicatorView(save_credentials_ui_data_)); |
304 | 320 |
305 // Share network | 321 // Share network |
306 if (wimax->profile_type() == PROFILE_NONE && wimax->passphrase_required()) { | 322 if (!wimax->IsPrivate()) { |
307 layout->StartRow(0, column_view_set_id); | 323 layout->StartRow(0, column_view_set_id); |
308 share_network_checkbox_ = new views::Checkbox( | 324 share_network_checkbox_ = new views::Checkbox( |
309 l10n_util::GetStringUTF16( | 325 l10n_util::GetStringUTF16( |
310 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SHARE_NETWORK)); | 326 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SHARE_NETWORK)); |
311 share_network_checkbox_->SetEnabled(true); | 327 share_network_checkbox_->SetEnabled(true); |
312 share_network_checkbox_->SetChecked(false); // Default to unshared. | 328 share_network_checkbox_->SetChecked(true); |
313 layout->SkipColumns(1); | 329 layout->SkipColumns(1); |
314 layout->AddView(share_network_checkbox_); | 330 layout->AddView(share_network_checkbox_); |
315 } | 331 } |
316 } | 332 } |
317 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 333 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
318 | 334 |
319 // Create an error label. | 335 // Create an error label. |
320 layout->StartRow(0, column_view_set_id); | 336 layout->StartRow(0, column_view_set_id); |
321 layout->SkipColumns(1); | 337 layout->SkipColumns(1); |
322 error_label_ = new views::Label(); | 338 error_label_ = new views::Label(); |
323 error_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 339 error_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
324 error_label_->SetEnabledColor(SK_ColorRED); | 340 error_label_->SetEnabledColor(SK_ColorRED); |
325 layout->AddView(error_label_); | 341 layout->AddView(error_label_); |
326 | 342 |
327 UpdateErrorLabel(); | 343 UpdateErrorLabel(); |
344 | |
345 if (wimax) { | |
346 NetworkHandler::Get()->network_configuration_handler()->GetProperties( | |
347 service_path, | |
348 base::Bind(&WimaxConfigView::InitFromProperties, AsWeakPtr()), | |
349 base::Bind(&ShillError, "GetProperties")); | |
350 } | |
351 } | |
352 | |
353 void WimaxConfigView::InitFromProperties( | |
354 const std::string& service_path, | |
355 const base::DictionaryValue& properties) { | |
356 // EapIdentity | |
357 std::string eap_identity; | |
358 properties.GetStringWithoutPathExpansion( | |
359 flimflam::kEapIdentityProperty, &eap_identity); | |
360 identity_textfield_->SetText(UTF8ToUTF16(eap_identity)); | |
361 | |
362 // Save credentials | |
363 if (save_credentials_checkbox_) { | |
364 bool save_credentials = false; | |
365 properties.GetBooleanWithoutPathExpansion( | |
366 flimflam::kSaveCredentialsProperty, &save_credentials); | |
367 save_credentials_checkbox_->SetChecked(save_credentials); | |
368 } | |
328 } | 369 } |
329 | 370 |
330 void WimaxConfigView::InitFocus() { | 371 void WimaxConfigView::InitFocus() { |
331 views::View* view_to_focus = GetInitiallyFocusedView(); | 372 views::View* view_to_focus = GetInitiallyFocusedView(); |
332 if (view_to_focus) | 373 if (view_to_focus) |
333 view_to_focus->RequestFocus(); | 374 view_to_focus->RequestFocus(); |
334 } | 375 } |
335 | 376 |
336 } // namespace chromeos | 377 } // namespace chromeos |
OLD | NEW |