1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/options/wimax_config_view.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chromeos/cros/network_library.h"
#include "chrome/browser/chromeos/enrollment_dialog_view.h"
#include "chrome/browser/chromeos/login/startup_utils.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chromeos/login/login_state.h"
#include "chromeos/network/onc/onc_constants.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "grit/locale_settings.h"
#include "grit/theme_resources.h"
#include "ui/base/events/event.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/views/controls/button/checkbox.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/layout/grid_layout.h"
#include "ui/views/layout/layout_constants.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/dialog_client_view.h"
namespace chromeos {
WimaxConfigView::WimaxConfigView(NetworkConfigView* parent, WimaxNetwork* wimax)
: ChildNetworkConfigView(parent, wimax),
identity_label_(NULL),
identity_textfield_(NULL),
save_credentials_checkbox_(NULL),
share_network_checkbox_(NULL),
shared_network_label_(NULL),
passphrase_label_(NULL),
passphrase_textfield_(NULL),
passphrase_visible_button_(NULL),
error_label_(NULL) {
Init(wimax);
}
WimaxConfigView::~WimaxConfigView() {
}
string16 WimaxConfigView::GetTitle() const {
return l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_JOIN_WIMAX_NETWORKS);
}
views::View* WimaxConfigView::GetInitiallyFocusedView() {
if (identity_textfield_ && identity_textfield_->enabled())
return identity_textfield_;
if (passphrase_textfield_ && passphrase_textfield_->enabled())
return passphrase_textfield_;
return NULL;
}
bool WimaxConfigView::CanLogin() {
// In OOBE it may be valid to log in with no credentials (crbug.com/137776).
if (!chromeos::StartupUtils::IsOobeCompleted())
return true;
// TODO(benchan): Update this with the correct minimum length (don't just
// check if empty).
// If the network requires a passphrase, make sure it is the right length.
return passphrase_textfield_ && !passphrase_textfield_->text().empty();
}
void WimaxConfigView::UpdateDialogButtons() {
parent_->GetDialogClientView()->UpdateDialogButtons();
}
void WimaxConfigView::UpdateErrorLabel() {
std::string error_msg;
if (!service_path_.empty()) {
NetworkLibrary* cros = NetworkLibrary::Get();
const WimaxNetwork* wimax = cros->FindWimaxNetworkByPath(service_path_);
if (wimax && wimax->failed()) {
bool passphrase_empty = wimax->eap_passphrase().empty();
switch (wimax->error()) {
case ERROR_BAD_PASSPHRASE:
if (!passphrase_empty) {
error_msg = l10n_util::GetStringUTF8(
IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_BAD_PASSPHRASE);
}
break;
case ERROR_BAD_WEPKEY:
if (!passphrase_empty) {
error_msg = l10n_util::GetStringUTF8(
IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_BAD_WEPKEY);
}
break;
default:
error_msg = wimax->GetErrorString();
break;
}
}
}
if (!error_msg.empty()) {
error_label_->SetText(UTF8ToUTF16(error_msg));
error_label_->SetVisible(true);
} else {
error_label_->SetVisible(false);
}
}
void WimaxConfigView::ContentsChanged(views::Textfield* sender,
const string16& new_contents) {
UpdateDialogButtons();
}
bool WimaxConfigView::HandleKeyEvent(views::Textfield* sender,
const ui::KeyEvent& key_event) {
if (sender == passphrase_textfield_ &&
key_event.key_code() == ui::VKEY_RETURN) {
parent_->GetDialogClientView()->AcceptWindow();
}
return false;
}
void WimaxConfigView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
if (sender == passphrase_visible_button_) {
if (passphrase_textfield_) {
passphrase_textfield_->SetObscured(!passphrase_textfield_->IsObscured());
passphrase_visible_button_->SetToggled(
!passphrase_textfield_->IsObscured());
}
} else {
NOTREACHED();
}
}
bool WimaxConfigView::Login() {
NetworkLibrary* cros = NetworkLibrary::Get();
WimaxNetwork* wimax = cros->FindWimaxNetworkByPath(service_path_);
if (!wimax) {
// Shill no longer knows about this wimax network (edge case).
// TODO(stevenjb): Add a notification (chromium-os13225).
LOG(WARNING) << "Wimax network: " << service_path_ << " no longer exists.";
return true;
}
wimax->SetEAPIdentity(GetEapIdentity());
wimax->SetEAPPassphrase(GetEapPassphrase());
wimax->SetSaveCredentials(GetSaveCredentials());
bool share_default = (wimax->profile_type() != PROFILE_USER);
bool share = GetShareNetwork(share_default);
wimax->SetEnrollmentDelegate(
CreateEnrollmentDelegate(GetWidget()->GetNativeWindow(),
wimax->name(),
ProfileManager::GetLastUsedProfile()));
cros->ConnectToWimaxNetwork(wimax, share);
// Connection failures are responsible for updating the UI, including
// reopening dialogs.
return true; // dialog will be closed
}
std::string WimaxConfigView::GetEapIdentity() const {
DCHECK(identity_textfield_);
return UTF16ToUTF8(identity_textfield_->text());
}
std::string WimaxConfigView::GetEapPassphrase() const {
return passphrase_textfield_ ? UTF16ToUTF8(passphrase_textfield_->text()) :
std::string();
}
bool WimaxConfigView::GetSaveCredentials() const {
return save_credentials_checkbox_ ? save_credentials_checkbox_->checked() :
false;
}
bool WimaxConfigView::GetShareNetwork(bool share_default) const {
return share_network_checkbox_ ? share_network_checkbox_->checked() :
share_default;
}
void WimaxConfigView::Cancel() {
}
void WimaxConfigView::Init(WimaxNetwork* wimax) {
DCHECK(wimax);
WifiConfigView::ParseWiFiEAPUIProperty(
&save_credentials_ui_data_, wimax, onc::eap::kSaveCredentials);
WifiConfigView::ParseWiFiEAPUIProperty(
&identity_ui_data_, wimax, onc::eap::kIdentity);
WifiConfigView::ParseWiFiUIProperty(
&passphrase_ui_data_, wimax, onc::wifi::kPassphrase);
views::GridLayout* layout = views::GridLayout::CreatePanel(this);
SetLayoutManager(layout);
const int column_view_set_id = 0;
views::ColumnSet* column_set = layout->AddColumnSet(column_view_set_id);
const int kPasswordVisibleWidth = 20;
// Label
column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1,
views::GridLayout::USE_PREF, 0, 0);
column_set->AddPaddingColumn(0, views::kRelatedControlSmallHorizontalSpacing);
// Textfield, combobox.
column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
views::GridLayout::USE_PREF, 0,
ChildNetworkConfigView::kInputFieldMinWidth);
column_set->AddPaddingColumn(0, views::kRelatedControlSmallHorizontalSpacing);
// Password visible button / policy indicator.
column_set->AddColumn(views::GridLayout::CENTER, views::GridLayout::FILL, 1,
views::GridLayout::USE_PREF, 0, kPasswordVisibleWidth);
// Network name
layout->StartRow(0, column_view_set_id);
layout->AddView(new views::Label(l10n_util::GetStringUTF16(
IDS_OPTIONS_SETTINGS_INTERNET_TAB_NETWORK)));
views::Label* label = new views::Label(UTF8ToUTF16(wimax->name()));
label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
layout->AddView(label);
layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
// Identity
layout->StartRow(0, column_view_set_id);
string16 identity_label_text = l10n_util::GetStringUTF16(
IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_IDENTITY);
identity_label_ = new views::Label(identity_label_text);
layout->AddView(identity_label_);
identity_textfield_ = new views::Textfield(
views::Textfield::STYLE_DEFAULT);
identity_textfield_->SetAccessibleName(identity_label_text);
identity_textfield_->SetController(this);
const std::string& eap_identity = wimax->eap_identity();
identity_textfield_->SetText(UTF8ToUTF16(eap_identity));
identity_textfield_->SetEnabled(identity_ui_data_.IsEditable());
layout->AddView(identity_textfield_);
layout->AddView(new ControlledSettingIndicatorView(identity_ui_data_));
layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
// Passphrase input
layout->StartRow(0, column_view_set_id);
string16 passphrase_label_text = l10n_util::GetStringUTF16(
IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSPHRASE);
passphrase_label_ = new views::Label(passphrase_label_text);
layout->AddView(passphrase_label_);
passphrase_textfield_ = new views::Textfield(
views::Textfield::STYLE_OBSCURED);
passphrase_textfield_->SetController(this);
passphrase_label_->SetEnabled(true);
passphrase_textfield_->SetEnabled(passphrase_ui_data_.IsEditable());
passphrase_textfield_->SetAccessibleName(passphrase_label_text);
layout->AddView(passphrase_textfield_);
if (passphrase_ui_data_.IsManaged()) {
layout->AddView(new ControlledSettingIndicatorView(passphrase_ui_data_));
} else {
// Password visible button.
passphrase_visible_button_ = new views::ToggleImageButton(this);
passphrase_visible_button_->set_focusable(true);
passphrase_visible_button_->SetTooltipText(
l10n_util::GetStringUTF16(
IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSPHRASE_SHOW));
passphrase_visible_button_->SetToggledTooltipText(
l10n_util::GetStringUTF16(
IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSPHRASE_HIDE));
passphrase_visible_button_->SetImage(
views::ImageButton::STATE_NORMAL,
ResourceBundle::GetSharedInstance().
GetImageSkiaNamed(IDR_NETWORK_SHOW_PASSWORD));
passphrase_visible_button_->SetImage(
views::ImageButton::STATE_HOVERED,
ResourceBundle::GetSharedInstance().
GetImageSkiaNamed(IDR_NETWORK_SHOW_PASSWORD_HOVER));
passphrase_visible_button_->SetToggledImage(
views::ImageButton::STATE_NORMAL,
ResourceBundle::GetSharedInstance().
GetImageSkiaNamed(IDR_NETWORK_HIDE_PASSWORD));
passphrase_visible_button_->SetToggledImage(
views::ImageButton::STATE_HOVERED,
ResourceBundle::GetSharedInstance().
GetImageSkiaNamed(IDR_NETWORK_HIDE_PASSWORD_HOVER));
passphrase_visible_button_->SetImageAlignment(
views::ImageButton::ALIGN_CENTER, views::ImageButton::ALIGN_MIDDLE);
layout->AddView(passphrase_visible_button_);
}
layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
// Checkboxes.
if (LoginState::Get()->IsUserLoggedIn()) {
// Save credentials
layout->StartRow(0, column_view_set_id);
save_credentials_checkbox_ = new views::Checkbox(
l10n_util::GetStringUTF16(
IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SAVE_CREDENTIALS));
save_credentials_checkbox_->SetEnabled(
save_credentials_ui_data_.IsEditable());
save_credentials_checkbox_->SetChecked(wimax->save_credentials());
layout->SkipColumns(1);
layout->AddView(save_credentials_checkbox_);
layout->AddView(
new ControlledSettingIndicatorView(save_credentials_ui_data_));
// Share network
if (wimax->profile_type() == PROFILE_NONE && wimax->passphrase_required()) {
layout->StartRow(0, column_view_set_id);
share_network_checkbox_ = new views::Checkbox(
l10n_util::GetStringUTF16(
IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SHARE_NETWORK));
share_network_checkbox_->SetEnabled(true);
share_network_checkbox_->SetChecked(false); // Default to unshared.
layout->SkipColumns(1);
layout->AddView(share_network_checkbox_);
}
}
layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
// Create an error label.
layout->StartRow(0, column_view_set_id);
layout->SkipColumns(1);
error_label_ = new views::Label();
error_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
error_label_->SetEnabledColor(SK_ColorRED);
layout->AddView(error_label_);
UpdateErrorLabel();
}
void WimaxConfigView::InitFocus() {
views::View* view_to_focus = GetInitiallyFocusedView();
if (view_to_focus)
view_to_focus->RequestFocus();
}
} // namespace chromeos
|