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

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

Issue 21046008: Convert all connect code to use NetworkHandler instead of NetworkLibrary (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add NetworkConfigurationHandler::SetNetworkProfile Created 7 years, 4 months 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) 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 weak_ptr_factory_(this) {
65 Init();
46 } 66 }
47 67
48 WimaxConfigView::~WimaxConfigView() { 68 WimaxConfigView::~WimaxConfigView() {
49 } 69 }
50 70
51 string16 WimaxConfigView::GetTitle() const { 71 string16 WimaxConfigView::GetTitle() const {
52 return l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_JOIN_WIMAX_NETWORKS); 72 return l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_JOIN_WIMAX_NETWORKS);
53 } 73 }
54 74
55 views::View* WimaxConfigView::GetInitiallyFocusedView() { 75 views::View* WimaxConfigView::GetInitiallyFocusedView() {
(...skipping 13 matching lines...) Expand all
69 // check if empty). 89 // check if empty).
70 // If the network requires a passphrase, make sure it is the right length. 90 // If the network requires a passphrase, make sure it is the right length.
71 return passphrase_textfield_ && !passphrase_textfield_->text().empty(); 91 return passphrase_textfield_ && !passphrase_textfield_->text().empty();
72 } 92 }
73 93
74 void WimaxConfigView::UpdateDialogButtons() { 94 void WimaxConfigView::UpdateDialogButtons() {
75 parent_->GetDialogClientView()->UpdateDialogButtons(); 95 parent_->GetDialogClientView()->UpdateDialogButtons();
76 } 96 }
77 97
78 void WimaxConfigView::UpdateErrorLabel() { 98 void WimaxConfigView::UpdateErrorLabel() {
79 std::string error_msg; 99 base::string16 error_msg;
80 if (!service_path_.empty()) { 100 if (!service_path_.empty()) {
81 NetworkLibrary* cros = NetworkLibrary::Get(); 101 const NetworkState* wimax = NetworkHandler::Get()->network_state_handler()->
82 const WimaxNetwork* wimax = cros->FindWimaxNetworkByPath(service_path_); 102 GetNetworkState(service_path_);
83 if (wimax && wimax->failed()) { 103 if (wimax && wimax->connection_state() == flimflam::kStateFailure)
84 bool passphrase_empty = wimax->eap_passphrase().empty(); 104 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 } 105 }
104 if (!error_msg.empty()) { 106 if (!error_msg.empty()) {
105 error_label_->SetText(UTF8ToUTF16(error_msg)); 107 error_label_->SetText(error_msg);
106 error_label_->SetVisible(true); 108 error_label_->SetVisible(true);
107 } else { 109 } else {
108 error_label_->SetVisible(false); 110 error_label_->SetVisible(false);
109 } 111 }
110 } 112 }
111 113
112 void WimaxConfigView::ContentsChanged(views::Textfield* sender, 114 void WimaxConfigView::ContentsChanged(views::Textfield* sender,
113 const string16& new_contents) { 115 const string16& new_contents) {
114 UpdateDialogButtons(); 116 UpdateDialogButtons();
115 } 117 }
(...skipping 14 matching lines...) Expand all
130 passphrase_textfield_->SetObscured(!passphrase_textfield_->IsObscured()); 132 passphrase_textfield_->SetObscured(!passphrase_textfield_->IsObscured());
131 passphrase_visible_button_->SetToggled( 133 passphrase_visible_button_->SetToggled(
132 !passphrase_textfield_->IsObscured()); 134 !passphrase_textfield_->IsObscured());
133 } 135 }
134 } else { 136 } else {
135 NOTREACHED(); 137 NOTREACHED();
136 } 138 }
137 } 139 }
138 140
139 bool WimaxConfigView::Login() { 141 bool WimaxConfigView::Login() {
140 NetworkLibrary* cros = NetworkLibrary::Get(); 142 const NetworkState* wimax = NetworkHandler::Get()->network_state_handler()->
141 WimaxNetwork* wimax = cros->FindWimaxNetworkByPath(service_path_); 143 GetNetworkState(service_path_);
142 if (!wimax) { 144 if (!wimax) {
143 // Shill no longer knows about this wimax network (edge case). 145 // Shill no longer knows about this network (edge case).
144 // TODO(stevenjb): Add a notification (chromium-os13225). 146 // TODO(stevenjb): Add notification for this.
145 LOG(WARNING) << "Wimax network: " << service_path_ << " no longer exists."; 147 NET_LOG_ERROR("Network not found", service_path_);
146 return true; 148 return true; // Close dialog
147 } 149 }
148 wimax->SetEAPIdentity(GetEapIdentity()); 150 base::DictionaryValue properties;
149 wimax->SetEAPPassphrase(GetEapPassphrase()); 151 properties.SetStringWithoutPathExpansion(
150 wimax->SetSaveCredentials(GetSaveCredentials()); 152 flimflam::kEapIdentityProperty, GetEapIdentity());
151 bool share_default = (wimax->profile_type() != PROFILE_USER); 153 properties.SetStringWithoutPathExpansion(
152 bool share = GetShareNetwork(share_default); 154 flimflam::kEapPasswordProperty, GetEapPassphrase());
153 wimax->SetEnrollmentDelegate( 155 properties.SetBooleanWithoutPathExpansion(
154 CreateEnrollmentDelegate(GetWidget()->GetNativeWindow(), 156 flimflam::kSaveCredentialsProperty, GetSaveCredentials());
155 wimax->name(), 157
156 ProfileManager::GetLastUsedProfile())); 158 const bool share_default = true;
157 cros->ConnectToWimaxNetwork(wimax, share); 159 bool share_network = GetShareNetwork(share_default);
158 // Connection failures are responsible for updating the UI, including 160 ash::network_connect::ConfigureNetworkAndConnect(
159 // reopening dialogs. 161 service_path_, properties, share_network);
160 return true; // dialog will be closed 162 return true; // dialog will be closed
161 } 163 }
162 164
163 std::string WimaxConfigView::GetEapIdentity() const { 165 std::string WimaxConfigView::GetEapIdentity() const {
164 DCHECK(identity_textfield_); 166 DCHECK(identity_textfield_);
165 return UTF16ToUTF8(identity_textfield_->text()); 167 return UTF16ToUTF8(identity_textfield_->text());
166 } 168 }
167 169
168 std::string WimaxConfigView::GetEapPassphrase() const { 170 std::string WimaxConfigView::GetEapPassphrase() const {
169 return passphrase_textfield_ ? UTF16ToUTF8(passphrase_textfield_->text()) : 171 return passphrase_textfield_ ? UTF16ToUTF8(passphrase_textfield_->text()) :
170 std::string(); 172 std::string();
171 } 173 }
172 174
173 bool WimaxConfigView::GetSaveCredentials() const { 175 bool WimaxConfigView::GetSaveCredentials() const {
174 return save_credentials_checkbox_ ? save_credentials_checkbox_->checked() : 176 return save_credentials_checkbox_ ? save_credentials_checkbox_->checked() :
175 false; 177 false;
176 } 178 }
177 179
178 bool WimaxConfigView::GetShareNetwork(bool share_default) const { 180 bool WimaxConfigView::GetShareNetwork(bool share_default) const {
179 return share_network_checkbox_ ? share_network_checkbox_->checked() : 181 return share_network_checkbox_ ? share_network_checkbox_->checked() :
180 share_default; 182 share_default;
181 } 183 }
182 184
183 void WimaxConfigView::Cancel() { 185 void WimaxConfigView::Cancel() {
184 } 186 }
185 187
186 void WimaxConfigView::Init(WimaxNetwork* wimax) { 188 void WimaxConfigView::Init() {
187 DCHECK(wimax); 189 const NetworkState* wimax = NetworkHandler::Get()->network_state_handler()->
190 GetNetworkState(service_path_);
191 DCHECK(wimax && wimax->type() == flimflam::kTypeWimax);
192
188 WifiConfigView::ParseWiFiEAPUIProperty( 193 WifiConfigView::ParseWiFiEAPUIProperty(
189 &save_credentials_ui_data_, wimax, onc::eap::kSaveCredentials); 194 &save_credentials_ui_data_, wimax, onc::eap::kSaveCredentials);
190 WifiConfigView::ParseWiFiEAPUIProperty( 195 WifiConfigView::ParseWiFiEAPUIProperty(
191 &identity_ui_data_, wimax, onc::eap::kIdentity); 196 &identity_ui_data_, wimax, onc::eap::kIdentity);
192 WifiConfigView::ParseWiFiUIProperty( 197 WifiConfigView::ParseWiFiUIProperty(
193 &passphrase_ui_data_, wimax, onc::wifi::kPassphrase); 198 &passphrase_ui_data_, wimax, onc::wifi::kPassphrase);
194 199
195 views::GridLayout* layout = views::GridLayout::CreatePanel(this); 200 views::GridLayout* layout = views::GridLayout::CreatePanel(this);
196 SetLayoutManager(layout); 201 SetLayoutManager(layout);
197 202
(...skipping 25 matching lines...) Expand all
223 // Identity 228 // Identity
224 layout->StartRow(0, column_view_set_id); 229 layout->StartRow(0, column_view_set_id);
225 string16 identity_label_text = l10n_util::GetStringUTF16( 230 string16 identity_label_text = l10n_util::GetStringUTF16(
226 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_IDENTITY); 231 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_IDENTITY);
227 identity_label_ = new views::Label(identity_label_text); 232 identity_label_ = new views::Label(identity_label_text);
228 layout->AddView(identity_label_); 233 layout->AddView(identity_label_);
229 identity_textfield_ = new views::Textfield( 234 identity_textfield_ = new views::Textfield(
230 views::Textfield::STYLE_DEFAULT); 235 views::Textfield::STYLE_DEFAULT);
231 identity_textfield_->SetAccessibleName(identity_label_text); 236 identity_textfield_->SetAccessibleName(identity_label_text);
232 identity_textfield_->SetController(this); 237 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()); 238 identity_textfield_->SetEnabled(identity_ui_data_.IsEditable());
236 layout->AddView(identity_textfield_); 239 layout->AddView(identity_textfield_);
237 layout->AddView(new ControlledSettingIndicatorView(identity_ui_data_)); 240 layout->AddView(new ControlledSettingIndicatorView(identity_ui_data_));
238 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 241 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
239 242
240 // Passphrase input 243 // Passphrase input
241 layout->StartRow(0, column_view_set_id); 244 layout->StartRow(0, column_view_set_id);
242 string16 passphrase_label_text = l10n_util::GetStringUTF16( 245 string16 passphrase_label_text = l10n_util::GetStringUTF16(
243 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSPHRASE); 246 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSPHRASE);
244 passphrase_label_ = new views::Label(passphrase_label_text); 247 passphrase_label_ = new views::Label(passphrase_label_text);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 GetImageSkiaNamed(IDR_NETWORK_HIDE_PASSWORD_HOVER)); 284 GetImageSkiaNamed(IDR_NETWORK_HIDE_PASSWORD_HOVER));
282 passphrase_visible_button_->SetImageAlignment( 285 passphrase_visible_button_->SetImageAlignment(
283 views::ImageButton::ALIGN_CENTER, views::ImageButton::ALIGN_MIDDLE); 286 views::ImageButton::ALIGN_CENTER, views::ImageButton::ALIGN_MIDDLE);
284 layout->AddView(passphrase_visible_button_); 287 layout->AddView(passphrase_visible_button_);
285 } 288 }
286 289
287 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 290 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
288 291
289 // Checkboxes. 292 // Checkboxes.
290 293
291 if (LoginState::Get()->IsUserLoggedIn()) { 294 if (LoginState::Get()->IsUserAuthenticated()) {
292 // Save credentials 295 // Save credentials
293 layout->StartRow(0, column_view_set_id); 296 layout->StartRow(0, column_view_set_id);
294 save_credentials_checkbox_ = new views::Checkbox( 297 save_credentials_checkbox_ = new views::Checkbox(
295 l10n_util::GetStringUTF16( 298 l10n_util::GetStringUTF16(
296 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SAVE_CREDENTIALS)); 299 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SAVE_CREDENTIALS));
297 save_credentials_checkbox_->SetEnabled( 300 save_credentials_checkbox_->SetEnabled(
298 save_credentials_ui_data_.IsEditable()); 301 save_credentials_ui_data_.IsEditable());
299 save_credentials_checkbox_->SetChecked(wimax->save_credentials());
300 layout->SkipColumns(1); 302 layout->SkipColumns(1);
301 layout->AddView(save_credentials_checkbox_); 303 layout->AddView(save_credentials_checkbox_);
302 layout->AddView( 304 layout->AddView(
303 new ControlledSettingIndicatorView(save_credentials_ui_data_)); 305 new ControlledSettingIndicatorView(save_credentials_ui_data_));
306 }
304 307
305 // Share network 308 // Share network
306 if (wimax->profile_type() == PROFILE_NONE && wimax->passphrase_required()) { 309 if (wimax->profile_path().empty()) {
307 layout->StartRow(0, column_view_set_id); 310 layout->StartRow(0, column_view_set_id);
308 share_network_checkbox_ = new views::Checkbox( 311 share_network_checkbox_ = new views::Checkbox(
309 l10n_util::GetStringUTF16( 312 l10n_util::GetStringUTF16(
310 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SHARE_NETWORK)); 313 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SHARE_NETWORK));
314 if (LoginState::Get()->IsUserAuthenticated()) {
315 share_network_checkbox_->SetChecked(false); // Default to unshared
311 share_network_checkbox_->SetEnabled(true); 316 share_network_checkbox_->SetEnabled(true);
312 share_network_checkbox_->SetChecked(false); // Default to unshared. 317 } else {
313 layout->SkipColumns(1); 318 // Not logged in, must be shared
314 layout->AddView(share_network_checkbox_); 319 share_network_checkbox_->SetChecked(true);
320 share_network_checkbox_->SetEnabled(false);
315 } 321 }
322 layout->SkipColumns(1);
323 layout->AddView(share_network_checkbox_);
316 } 324 }
317 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 325 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
318 326
319 // Create an error label. 327 // Create an error label.
320 layout->StartRow(0, column_view_set_id); 328 layout->StartRow(0, column_view_set_id);
321 layout->SkipColumns(1); 329 layout->SkipColumns(1);
322 error_label_ = new views::Label(); 330 error_label_ = new views::Label();
323 error_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 331 error_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
324 error_label_->SetEnabledColor(SK_ColorRED); 332 error_label_->SetEnabledColor(SK_ColorRED);
325 layout->AddView(error_label_); 333 layout->AddView(error_label_);
326 334
327 UpdateErrorLabel(); 335 UpdateErrorLabel();
336
337 if (wimax) {
338 NetworkHandler::Get()->network_configuration_handler()->GetProperties(
339 service_path_,
340 base::Bind(&WimaxConfigView::InitFromProperties,
341 weak_ptr_factory_.GetWeakPtr()),
342 base::Bind(&ShillError, "GetProperties"));
343 }
344 }
345
346 void WimaxConfigView::InitFromProperties(
347 const std::string& service_path,
348 const base::DictionaryValue& properties) {
349 // EapIdentity
350 std::string eap_identity;
351 properties.GetStringWithoutPathExpansion(
352 flimflam::kEapIdentityProperty, &eap_identity);
353 identity_textfield_->SetText(UTF8ToUTF16(eap_identity));
354
355 // Save credentials
356 if (save_credentials_checkbox_) {
357 bool save_credentials = false;
358 properties.GetBooleanWithoutPathExpansion(
359 flimflam::kSaveCredentialsProperty, &save_credentials);
360 save_credentials_checkbox_->SetChecked(save_credentials);
361 }
328 } 362 }
329 363
330 void WimaxConfigView::InitFocus() { 364 void WimaxConfigView::InitFocus() {
331 views::View* view_to_focus = GetInitiallyFocusedView(); 365 views::View* view_to_focus = GetInitiallyFocusedView();
332 if (view_to_focus) 366 if (view_to_focus)
333 view_to_focus->RequestFocus(); 367 view_to_focus->RequestFocus();
334 } 368 }
335 369
336 } // namespace chromeos 370 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698