diff options
Diffstat (limited to 'chrome/browser/chromeos/options/wifi_config_view.cc')
| -rw-r--r-- | chrome/browser/chromeos/options/wifi_config_view.cc | 145 |
1 files changed, 113 insertions, 32 deletions
diff --git a/chrome/browser/chromeos/options/wifi_config_view.cc b/chrome/browser/chromeos/options/wifi_config_view.cc index 72cb512..7cdad5b 100644 --- a/chrome/browser/chromeos/options/wifi_config_view.cc +++ b/chrome/browser/chromeos/options/wifi_config_view.cc @@ -27,15 +27,46 @@ namespace chromeos { // The width of the password field. const int kPasswordWidth = 150; -WifiConfigView::WifiConfigView(NetworkConfigView* parent, WifiNetwork wifi) +enum SecurityComboboxIndex { + INDEX_NONE = 0, + INDEX_WEP = 1, + INDEX_WPA = 2, + INDEX_RSN = 3, + INDEX_COUNT = 4 +}; + +int WifiConfigView::SecurityComboboxModel::GetItemCount() { + return INDEX_COUNT; +} + +string16 WifiConfigView::SecurityComboboxModel::GetItemAt(int index) { + if (index == INDEX_NONE) + return l10n_util::GetStringUTF16( + IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SECURITY_NONE); + else if (index == INDEX_WEP) + return l10n_util::GetStringUTF16( + IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SECURITY_WEP); + else if (index == INDEX_WPA) + return l10n_util::GetStringUTF16( + IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SECURITY_WPA); + else if (index == INDEX_RSN) + return l10n_util::GetStringUTF16( + IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SECURITY_RSN); + NOTREACHED(); + return string16(); +} + +WifiConfigView::WifiConfigView(NetworkConfigView* parent, + const WifiNetwork* wifi) : parent_(parent), other_network_(false), can_login_(false), - wifi_(wifi), + wifi_(new WifiNetwork(*wifi)), ssid_textfield_(NULL), identity_textfield_(NULL), certificate_browse_button_(NULL), certificate_path_(), + security_combobox_(NULL), passphrase_textfield_(NULL), passphrase_visible_button_(NULL), autoconnect_checkbox_(NULL) { @@ -50,18 +81,24 @@ WifiConfigView::WifiConfigView(NetworkConfigView* parent) identity_textfield_(NULL), certificate_browse_button_(NULL), certificate_path_(), + security_combobox_(NULL), passphrase_textfield_(NULL), passphrase_visible_button_(NULL), autoconnect_checkbox_(NULL) { Init(); } +WifiConfigView::~WifiConfigView() { +} + void WifiConfigView::UpdateCanLogin(void) { bool can_login = true; if (other_network_) { - // Since the user can try to connect to a non-encrypted hidden network, - // only enforce ssid is non-empty. - can_login = !ssid_textfield_->text().empty(); + // Enforce ssid is non empty. + // If security is not none, also enforce passphrase is non empty. + can_login = !ssid_textfield_->text().empty() && + (security_combobox_->selected_item() == INDEX_NONE || + !passphrase_textfield_->text().empty()); } else { // Connecting to an encrypted network if (passphrase_textfield_ != NULL) { @@ -128,6 +165,19 @@ void WifiConfigView::ButtonPressed(views::Button* sender, } } +void WifiConfigView::ItemChanged(views::Combobox* combo_box, + int prev_index, int new_index) { + // If changed to no security, then disable combobox and clear it. + // Otherwise, enable it. Also, update can login. + if (new_index == INDEX_NONE) { + passphrase_textfield_->SetEnabled(false); + passphrase_textfield_->SetText(string16()); + } else { + passphrase_textfield_->SetEnabled(true); + } + UpdateCanLogin(); +} + void WifiConfigView::FileSelected(const FilePath& path, int index, void* params) { certificate_path_ = path.value(); @@ -141,18 +191,29 @@ bool WifiConfigView::Login() { if (identity_textfield_ != NULL) { identity_string = UTF16ToUTF8(identity_textfield_->text()); } + bool connected = false; if (other_network_) { - CrosLibrary::Get()->GetNetworkLibrary()->ConnectToWifiNetwork( - GetSSID(), GetPassphrase(), + ConnectionSecurity sec = SECURITY_UNKNOWN; + int index = security_combobox_->selected_item(); + if (index == INDEX_NONE) + sec = SECURITY_NONE; + else if (index == INDEX_WEP) + sec = SECURITY_WEP; + else if (index == INDEX_WPA) + sec = SECURITY_WPA; + else if (index == INDEX_RSN) + sec = SECURITY_RSN; + connected = CrosLibrary::Get()->GetNetworkLibrary()->ConnectToWifiNetwork( + sec, GetSSID(), GetPassphrase(), identity_string, certificate_path_, autoconnect_checkbox_ ? autoconnect_checkbox_->checked() : true); } else { Save(); - CrosLibrary::Get()->GetNetworkLibrary()->ConnectToWifiNetwork( - wifi_, GetPassphrase(), + connected = CrosLibrary::Get()->GetNetworkLibrary()->ConnectToWifiNetwork( + wifi_.get(), GetPassphrase(), identity_string, certificate_path_); } - return true; + return connected; } bool WifiConfigView::Save() { @@ -162,8 +223,8 @@ bool WifiConfigView::Save() { if (autoconnect_checkbox_) { bool auto_connect = autoconnect_checkbox_->checked(); - if (auto_connect != wifi_.auto_connect()) { - wifi_.set_auto_connect(auto_connect); + if (auto_connect != wifi_->auto_connect()) { + wifi_->set_auto_connect(auto_connect); changed = true; } } @@ -171,14 +232,14 @@ bool WifiConfigView::Save() { if (passphrase_textfield_) { const std::string& passphrase = UTF16ToUTF8(passphrase_textfield_->text()); - if (passphrase != wifi_.passphrase()) { - wifi_.set_passphrase(passphrase); + if (passphrase != wifi_->passphrase()) { + wifi_->set_passphrase(passphrase); changed = true; } } if (changed) - CrosLibrary::Get()->GetNetworkLibrary()->SaveWifiNetwork(wifi_); + CrosLibrary::Get()->GetNetworkLibrary()->SaveWifiNetwork(wifi_.get()); } return true; } @@ -222,6 +283,7 @@ void WifiConfigView::Init() { column_set->AddColumn(views::GridLayout::CENTER, views::GridLayout::FILL, 1, views::GridLayout::USE_PREF, 0, 0); + // SSID input layout->StartRow(0, column_view_set_id); layout->AddView(new views::Label(l10n_util::GetString( IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NETWORK_ID))); @@ -230,12 +292,13 @@ void WifiConfigView::Init() { ssid_textfield_->SetController(this); layout->AddView(ssid_textfield_); } else { - views::Label* label = new views::Label(ASCIIToWide(wifi_.name())); + views::Label* label = new views::Label(ASCIIToWide(wifi_->name())); label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); layout->AddView(label); } layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + // Certificate input // Loaded certificates (i.e. stored in a pkcs11 device) do not require // a passphrase. bool certificate_loaded = false; @@ -245,23 +308,24 @@ void WifiConfigView::Init() { // in general, but very common. WPA Supplicant doesn't report the // EAP type because it's unknown until the process begins, and we'd // need some kind of callback. - if (wifi_.encrypted() && wifi_.encryption() == SECURITY_8021X) { + if (wifi_.get() && wifi_->encrypted() && + wifi_->encryption() == SECURITY_8021X) { layout->StartRow(0, column_view_set_id); layout->AddView(new views::Label(l10n_util::GetString( IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_IDENTITY))); identity_textfield_ = new views::Textfield( views::Textfield::STYLE_DEFAULT); identity_textfield_->SetController(this); - if (!wifi_.identity().empty()) - identity_textfield_->SetText(UTF8ToUTF16(wifi_.identity())); + if (!wifi_->identity().empty()) + identity_textfield_->SetText(UTF8ToUTF16(wifi_->identity())); layout->AddView(identity_textfield_); layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); layout->StartRow(0, column_view_set_id); layout->AddView(new views::Label(l10n_util::GetString( IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT))); - if (!wifi_.cert_path().empty()) { - certificate_path_ = wifi_.cert_path(); - certificate_loaded = wifi_.IsCertificateLoaded(); + if (!wifi_->cert_path().empty()) { + certificate_path_ = wifi_->cert_path(); + certificate_loaded = wifi_->IsCertificateLoaded(); } if (certificate_loaded) { std::wstring label = l10n_util::GetString( @@ -282,11 +346,24 @@ void WifiConfigView::Init() { layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); } + // Security select + if (other_network_) { + layout->StartRow(0, column_view_set_id); + layout->AddView(new views::Label(l10n_util::GetString( + IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SECURITY))); + security_combobox_ = new views::Combobox(new SecurityComboboxModel()); + security_combobox_->set_listener(this); + layout->AddView(security_combobox_); + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + } + + // Passphrase input // Add passphrase if other_network or wifi is encrypted. - if (other_network_ || (wifi_.encrypted() && !certificate_loaded)) { + if (other_network_ || (wifi_.get() && wifi_->encrypted() && + !certificate_loaded)) { layout->StartRow(0, column_view_set_id); int label_text_id; - if (wifi_.encryption() == SECURITY_8021X) + if (wifi_.get() && wifi_->encryption() == SECURITY_8021X) label_text_id = IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PRIVATE_KEY_PASSWORD; else @@ -295,8 +372,11 @@ void WifiConfigView::Init() { passphrase_textfield_ = new views::Textfield( views::Textfield::STYLE_PASSWORD); passphrase_textfield_->SetController(this); - if (!wifi_.passphrase().empty()) - passphrase_textfield_->SetText(UTF8ToUTF16(wifi_.passphrase())); + if (wifi_.get() && !wifi_->passphrase().empty()) + passphrase_textfield_->SetText(UTF8ToUTF16(wifi_->passphrase())); + // Disable passphrase input initially for other network. + if (other_network_) + passphrase_textfield_->SetEnabled(false); layout->AddView(passphrase_textfield_); // Password visible button. passphrase_visible_button_ = new views::ImageButton(this); @@ -306,7 +386,7 @@ void WifiConfigView::Init() { passphrase_visible_button_->SetImageAlignment( views::ImageButton::ALIGN_CENTER, views::ImageButton::ALIGN_MIDDLE); // Disable viewing password by unauthenticated user. - if (!wifi_.passphrase().empty() && + if (wifi_.get() && !wifi_->passphrase().empty() && chromeos::UserManager::Get()->logged_in_user().email().empty()) { passphrase_visible_button_->SetVisible(false); } @@ -314,14 +394,15 @@ void WifiConfigView::Init() { layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); } + // Error label // If there's an error, add an error message label. // Right now, only displaying bad_passphrase and bad_wepkey errors. - if (wifi_.error() == ERROR_BAD_PASSPHRASE || - wifi_.error() == ERROR_BAD_WEPKEY) { + if (wifi_.get() && (wifi_->error() == ERROR_BAD_PASSPHRASE || + wifi_->error() == ERROR_BAD_WEPKEY)) { layout->StartRow(0, column_view_set_id); layout->SkipColumns(1); int id = IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_BAD_PASSPHRASE; - if (wifi_.error() == ERROR_BAD_WEPKEY) + if (wifi_->error() == ERROR_BAD_WEPKEY) id = IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_BAD_WEPKEY; views::Label* label_error = new views::Label(l10n_util::GetString(id)); label_error->SetHorizontalAlignment(views::Label::ALIGN_LEFT); @@ -332,11 +413,11 @@ void WifiConfigView::Init() { // Autoconnect checkbox // Only show if this network is already remembered (a favorite). - if (wifi_.favorite()) { + if (wifi_.get() && wifi_->favorite()) { autoconnect_checkbox_ = new views::Checkbox(l10n_util::GetString( IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_AUTO_CONNECT)); // For other network, default to autoconnect. - bool autoconnect = other_network_ || wifi_.auto_connect(); + bool autoconnect = other_network_ || wifi_->auto_connect(); autoconnect_checkbox_->SetChecked(autoconnect); layout->StartRow(0, column_view_set_id); layout->AddView(autoconnect_checkbox_, 3, 1); |
