OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/vpn_config_view.h" | 5 #include "chrome/browser/chromeos/options/vpn_config_view.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/chromeos/cros/cros_library.h" | 9 #include "chrome/browser/chromeos/cros/cros_library.h" |
10 #include "chrome/common/net/x509_certificate_model.h" | 10 #include "chrome/common/net/x509_certificate_model.h" |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
362 return std::string(); // "None installed" | 362 return std::string(); // "None installed" |
363 } else { | 363 } else { |
364 // Certificates are listed in the order they appear in the model. | 364 // Certificates are listed in the order they appear in the model. |
365 int selected = | 365 int selected = |
366 user_cert_combobox_ ? user_cert_combobox_->selected_item() : 0; | 366 user_cert_combobox_ ? user_cert_combobox_->selected_item() : 0; |
367 return cert_library_->GetUserCertificates().GetPkcs11IdAt(selected); | 367 return cert_library_->GetUserCertificates().GetPkcs11IdAt(selected); |
368 } | 368 } |
369 } | 369 } |
370 | 370 |
371 void VPNConfigView::Init(VirtualNetwork* vpn) { | 371 void VPNConfigView::Init(VirtualNetwork* vpn) { |
372 if (vpn) { | |
373 ca_cert_ui_data_.UpdateFromNetwork( | |
374 vpn, NetworkUIData::kPropertyVPNCaCertNss); | |
375 psk_passphrase_ui_data_.UpdateFromNetwork( | |
376 vpn, NetworkUIData::kPropertyVPNPskPassphrase); | |
377 user_cert_ui_data_.UpdateFromNetwork( | |
378 vpn, NetworkUIData::kPropertyVPNClientCertId); | |
379 username_ui_data_.UpdateFromNetwork( | |
380 vpn, NetworkUIData::kPropertyVPNUsername); | |
381 user_passphrase_ui_data_.UpdateFromNetwork( | |
382 vpn, NetworkUIData::kPropertyVPNUserPassphrase); | |
383 group_name_ui_data_.UpdateFromNetwork( | |
384 vpn, NetworkUIData::kPropertyVPNGroupName); | |
385 } | |
386 | |
372 views::GridLayout* layout = views::GridLayout::CreatePanel(this); | 387 views::GridLayout* layout = views::GridLayout::CreatePanel(this); |
373 SetLayoutManager(layout); | 388 SetLayoutManager(layout); |
374 | 389 |
375 // VPN may require certificates, so always set the library and observe. | 390 // VPN may require certificates, so always set the library and observe. |
376 cert_library_ = chromeos::CrosLibrary::Get()->GetCertLibrary(); | 391 cert_library_ = chromeos::CrosLibrary::Get()->GetCertLibrary(); |
377 | 392 |
378 // Setup a callback if certificates are yet to be loaded. | 393 // Setup a callback if certificates are yet to be loaded. |
379 if (!cert_library_->CertificatesLoaded()) | 394 if (!cert_library_->CertificatesLoaded()) |
380 cert_library_->AddObserver(this); | 395 cert_library_->AddObserver(this); |
381 | 396 |
382 int column_view_set_id = 0; | 397 int column_view_set_id = 0; |
383 views::ColumnSet* column_set = layout->AddColumnSet(column_view_set_id); | 398 views::ColumnSet* column_set = layout->AddColumnSet(column_view_set_id); |
384 // Label. | 399 // Label. |
385 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, | 400 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, |
386 views::GridLayout::USE_PREF, 0, 0); | 401 views::GridLayout::USE_PREF, 0, 0); |
387 column_set->AddPaddingColumn(0, views::kRelatedControlSmallHorizontalSpacing); | 402 column_set->AddPaddingColumn(0, views::kRelatedControlSmallHorizontalSpacing); |
388 // Textfield, combobox. | 403 // Textfield, combobox. |
389 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | 404 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, |
390 views::GridLayout::USE_PREF, 0, | 405 views::GridLayout::USE_PREF, 0, |
391 ChildNetworkConfigView::kInputFieldMinWidth); | 406 ChildNetworkConfigView::kInputFieldMinWidth); |
392 column_set->AddPaddingColumn(0, views::kRelatedControlSmallHorizontalSpacing); | 407 column_set->AddPaddingColumn(0, views::kRelatedControlSmallHorizontalSpacing); |
408 // Policy indicator. | |
409 column_set->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, 0, | |
410 views::GridLayout::USE_PREF, 0, 0); | |
393 | 411 |
394 // Initialize members. | 412 // Initialize members. |
395 service_text_modified_ = false; | 413 service_text_modified_ = false; |
396 if (vpn) { | 414 if (vpn) { |
397 provider_type_ = vpn->provider_type(); | 415 provider_type_ = vpn->provider_type(); |
398 // Sets enable_* based on the provider type which we use to control | 416 // Sets enable_* based on the provider type which we use to control |
399 // which controls to make visible. | 417 // which controls to make visible. |
400 UpdateControlsToEnable(); | 418 UpdateControlsToEnable(); |
401 } else { | 419 } else { |
402 // Set the default provider type. | 420 // Set the default provider type. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
464 layout->StartRow(0, column_view_set_id); | 482 layout->StartRow(0, column_view_set_id); |
465 psk_passphrase_label_ = new views::Label(l10n_util::GetStringUTF16( | 483 psk_passphrase_label_ = new views::Label(l10n_util::GetStringUTF16( |
466 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_PSK_PASSPHRASE)); | 484 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_PSK_PASSPHRASE)); |
467 layout->AddView(psk_passphrase_label_); | 485 layout->AddView(psk_passphrase_label_); |
468 psk_passphrase_textfield_ = new views::Textfield( | 486 psk_passphrase_textfield_ = new views::Textfield( |
469 views::Textfield::STYLE_PASSWORD); | 487 views::Textfield::STYLE_PASSWORD); |
470 psk_passphrase_textfield_->SetController(this); | 488 psk_passphrase_textfield_->SetController(this); |
471 if (vpn && !vpn->psk_passphrase().empty()) | 489 if (vpn && !vpn->psk_passphrase().empty()) |
472 psk_passphrase_textfield_->SetText(UTF8ToUTF16(vpn->psk_passphrase())); | 490 psk_passphrase_textfield_->SetText(UTF8ToUTF16(vpn->psk_passphrase())); |
473 layout->AddView(psk_passphrase_textfield_); | 491 layout->AddView(psk_passphrase_textfield_); |
492 layout->AddView( | |
493 new ControlledSettingIndicatorView(psk_passphrase_ui_data_)); | |
474 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 494 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
475 } else { | 495 } else { |
476 psk_passphrase_label_ = NULL; | 496 psk_passphrase_label_ = NULL; |
477 psk_passphrase_textfield_ = NULL; | 497 psk_passphrase_textfield_ = NULL; |
478 } | 498 } |
479 | 499 |
480 // Server CA certificate | 500 // Server CA certificate |
481 // Only provide Server CA when configuring a new VPN. | 501 // Only provide Server CA when configuring a new VPN. |
482 if (!vpn) { | 502 if (!vpn) { |
483 layout->StartRow(0, column_view_set_id); | 503 layout->StartRow(0, column_view_set_id); |
484 server_ca_cert_label_ = | 504 server_ca_cert_label_ = |
485 new views::Label(l10n_util::GetStringUTF16( | 505 new views::Label(l10n_util::GetStringUTF16( |
486 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_SERVER_CA)); | 506 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_SERVER_CA)); |
487 layout->AddView(server_ca_cert_label_); | 507 layout->AddView(server_ca_cert_label_); |
488 ServerCACertComboboxModel* server_ca_cert_model = | 508 ServerCACertComboboxModel* server_ca_cert_model = |
489 new ServerCACertComboboxModel(cert_library_); | 509 new ServerCACertComboboxModel(cert_library_); |
490 server_ca_cert_combobox_ = new views::Combobox(server_ca_cert_model); | 510 server_ca_cert_combobox_ = new views::Combobox(server_ca_cert_model); |
491 layout->AddView(server_ca_cert_combobox_); | 511 layout->AddView(server_ca_cert_combobox_); |
512 layout->AddView(new ControlledSettingIndicatorView(ca_cert_ui_data_)); | |
492 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 513 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
493 } else { | 514 } else { |
494 server_ca_cert_label_ = NULL; | 515 server_ca_cert_label_ = NULL; |
495 server_ca_cert_combobox_ = NULL; | 516 server_ca_cert_combobox_ = NULL; |
496 } | 517 } |
497 | 518 |
498 // User certificate label and input. | 519 // User certificate label and input. |
499 if (enable_user_cert_) { | 520 if (enable_user_cert_) { |
500 layout->StartRow(0, column_view_set_id); | 521 layout->StartRow(0, column_view_set_id); |
501 user_cert_label_ = new views::Label(l10n_util::GetStringUTF16( | 522 user_cert_label_ = new views::Label(l10n_util::GetStringUTF16( |
502 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_USER_CERT)); | 523 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_USER_CERT)); |
503 layout->AddView(user_cert_label_); | 524 layout->AddView(user_cert_label_); |
504 UserCertComboboxModel* user_cert_model = | 525 UserCertComboboxModel* user_cert_model = |
505 new UserCertComboboxModel(cert_library_); | 526 new UserCertComboboxModel(cert_library_); |
506 user_cert_combobox_ = new views::Combobox(user_cert_model); | 527 user_cert_combobox_ = new views::Combobox(user_cert_model); |
507 user_cert_combobox_->set_listener(this); | 528 user_cert_combobox_->set_listener(this); |
508 layout->AddView(user_cert_combobox_); | 529 layout->AddView(user_cert_combobox_); |
530 layout->AddView(new ControlledSettingIndicatorView(user_cert_ui_data_)); | |
509 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 531 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
510 } else { | 532 } else { |
511 user_cert_label_ = NULL; | 533 user_cert_label_ = NULL; |
512 user_cert_combobox_ = NULL; | 534 user_cert_combobox_ = NULL; |
513 } | 535 } |
514 | 536 |
515 // Username label and input. | 537 // Username label and input. |
516 layout->StartRow(0, column_view_set_id); | 538 layout->StartRow(0, column_view_set_id); |
517 layout->AddView(new views::Label(l10n_util::GetStringUTF16( | 539 layout->AddView(new views::Label(l10n_util::GetStringUTF16( |
518 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_USERNAME))); | 540 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_USERNAME))); |
519 username_textfield_ = new views::Textfield(views::Textfield::STYLE_DEFAULT); | 541 username_textfield_ = new views::Textfield(views::Textfield::STYLE_DEFAULT); |
520 username_textfield_->SetController(this); | 542 username_textfield_->SetController(this); |
543 username_textfield_->SetEnabled(username_ui_data_.editable()); | |
stevenjb
2011/11/29 17:58:28
Hmm, this looks much better than comparing the enu
Mattias Nissler (ping if slow)
2011/11/29 21:29:39
Done.
| |
521 if (vpn && !vpn->username().empty()) | 544 if (vpn && !vpn->username().empty()) |
522 username_textfield_->SetText(UTF8ToUTF16(vpn->username())); | 545 username_textfield_->SetText(UTF8ToUTF16(vpn->username())); |
523 layout->AddView(username_textfield_); | 546 layout->AddView(username_textfield_); |
547 layout->AddView(new ControlledSettingIndicatorView(username_ui_data_)); | |
524 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 548 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
525 | 549 |
526 // User passphrase label, input and visble button. | 550 // User passphrase label, input and visble button. |
527 layout->StartRow(0, column_view_set_id); | 551 layout->StartRow(0, column_view_set_id); |
528 layout->AddView(new views::Label(l10n_util::GetStringUTF16( | 552 layout->AddView(new views::Label(l10n_util::GetStringUTF16( |
529 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_USER_PASSPHRASE))); | 553 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_USER_PASSPHRASE))); |
530 user_passphrase_textfield_ = new views::Textfield( | 554 user_passphrase_textfield_ = new views::Textfield( |
531 views::Textfield::STYLE_PASSWORD); | 555 views::Textfield::STYLE_PASSWORD); |
532 user_passphrase_textfield_->SetController(this); | 556 user_passphrase_textfield_->SetController(this); |
557 user_passphrase_textfield_->SetEnabled(user_passphrase_ui_data_.editable()); | |
533 if (vpn && !vpn->user_passphrase().empty()) | 558 if (vpn && !vpn->user_passphrase().empty()) |
534 user_passphrase_textfield_->SetText(UTF8ToUTF16(vpn->user_passphrase())); | 559 user_passphrase_textfield_->SetText(UTF8ToUTF16(vpn->user_passphrase())); |
535 layout->AddView(user_passphrase_textfield_); | 560 layout->AddView(user_passphrase_textfield_); |
561 layout->AddView(new ControlledSettingIndicatorView(user_passphrase_ui_data_)); | |
536 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 562 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
537 | 563 |
538 // OTP label and input. | 564 // OTP label and input. |
539 if (enable_otp_) { | 565 if (enable_otp_) { |
540 layout->StartRow(0, column_view_set_id); | 566 layout->StartRow(0, column_view_set_id); |
541 otp_label_ = new views::Label(l10n_util::GetStringUTF16( | 567 otp_label_ = new views::Label(l10n_util::GetStringUTF16( |
542 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_OTP)); | 568 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_OTP)); |
543 layout->AddView(otp_label_); | 569 layout->AddView(otp_label_); |
544 otp_textfield_ = new views::Textfield(views::Textfield::STYLE_DEFAULT); | 570 otp_textfield_ = new views::Textfield(views::Textfield::STYLE_DEFAULT); |
545 otp_textfield_->SetController(this); | 571 otp_textfield_->SetController(this); |
(...skipping 14 matching lines...) Expand all Loading... | |
560 layout->StartRow(0, column_view_set_id); | 586 layout->StartRow(0, column_view_set_id); |
561 group_name_label_ = new views::Label(l10n_util::GetStringUTF16( | 587 group_name_label_ = new views::Label(l10n_util::GetStringUTF16( |
562 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_GROUP_NAME)); | 588 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_GROUP_NAME)); |
563 layout->AddView(group_name_label_); | 589 layout->AddView(group_name_label_); |
564 group_name_textfield_ = | 590 group_name_textfield_ = |
565 new views::Textfield(views::Textfield::STYLE_DEFAULT); | 591 new views::Textfield(views::Textfield::STYLE_DEFAULT); |
566 group_name_textfield_->SetController(this); | 592 group_name_textfield_->SetController(this); |
567 if (vpn && !vpn->group_name().empty()) | 593 if (vpn && !vpn->group_name().empty()) |
568 group_name_textfield_->SetText(UTF8ToUTF16(vpn->group_name())); | 594 group_name_textfield_->SetText(UTF8ToUTF16(vpn->group_name())); |
569 layout->AddView(group_name_textfield_); | 595 layout->AddView(group_name_textfield_); |
596 layout->AddView(new ControlledSettingIndicatorView(group_name_ui_data_)); | |
570 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 597 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
571 } else { | 598 } else { |
572 group_name_label_ = NULL; | 599 group_name_label_ = NULL; |
573 group_name_textfield_ = NULL; | 600 group_name_textfield_ = NULL; |
574 } | 601 } |
575 | 602 |
576 // Error label. | 603 // Error label. |
577 layout->StartRow(0, column_view_set_id); | 604 layout->StartRow(0, column_view_set_id); |
578 layout->SkipColumns(1); | 605 layout->SkipColumns(1); |
579 error_label_ = new views::Label(); | 606 error_label_ = new views::Label(); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
655 break; | 682 break; |
656 } | 683 } |
657 } | 684 } |
658 | 685 |
659 void VPNConfigView::UpdateControls() { | 686 void VPNConfigView::UpdateControls() { |
660 UpdateControlsToEnable(); | 687 UpdateControlsToEnable(); |
661 | 688 |
662 if (psk_passphrase_label_) | 689 if (psk_passphrase_label_) |
663 psk_passphrase_label_->SetEnabled(enable_psk_passphrase_); | 690 psk_passphrase_label_->SetEnabled(enable_psk_passphrase_); |
664 if (psk_passphrase_textfield_) | 691 if (psk_passphrase_textfield_) |
665 psk_passphrase_textfield_->SetEnabled(enable_psk_passphrase_); | 692 psk_passphrase_textfield_->SetEnabled(enable_psk_passphrase_ && |
693 psk_passphrase_ui_data_.editable()); | |
666 | 694 |
667 if (user_cert_label_) | 695 if (user_cert_label_) |
668 user_cert_label_->SetEnabled(enable_user_cert_); | 696 user_cert_label_->SetEnabled(enable_user_cert_); |
669 if (user_cert_combobox_) | 697 if (user_cert_combobox_) |
670 user_cert_combobox_->SetEnabled(enable_user_cert_); | 698 user_cert_combobox_->SetEnabled(enable_user_cert_ && |
699 user_cert_ui_data_.editable()); | |
671 | 700 |
672 if (server_ca_cert_label_) | 701 if (server_ca_cert_label_) |
673 server_ca_cert_label_->SetEnabled(enable_server_ca_cert_); | 702 server_ca_cert_label_->SetEnabled(enable_server_ca_cert_); |
674 if (server_ca_cert_combobox_) | 703 if (server_ca_cert_combobox_) |
675 server_ca_cert_combobox_->SetEnabled(enable_server_ca_cert_); | 704 server_ca_cert_combobox_->SetEnabled(enable_server_ca_cert_ && |
705 ca_cert_ui_data_.editable()); | |
676 | 706 |
677 if (otp_label_) | 707 if (otp_label_) |
678 otp_label_->SetEnabled(enable_otp_); | 708 otp_label_->SetEnabled(enable_otp_); |
679 if (otp_textfield_) | 709 if (otp_textfield_) |
680 otp_textfield_->SetEnabled(enable_otp_); | 710 otp_textfield_->SetEnabled(enable_otp_); |
681 | 711 |
682 if (group_name_label_) | 712 if (group_name_label_) |
683 group_name_label_->SetEnabled(enable_group_name_); | 713 group_name_label_->SetEnabled(enable_group_name_); |
684 if (group_name_textfield_) | 714 if (group_name_textfield_) |
685 group_name_textfield_->SetEnabled(enable_group_name_); | 715 group_name_textfield_->SetEnabled(enable_group_name_ && |
716 group_name_ui_data_.editable()); | |
686 } | 717 } |
687 | 718 |
688 void VPNConfigView::UpdateErrorLabel() { | 719 void VPNConfigView::UpdateErrorLabel() { |
689 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | 720 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
690 | 721 |
691 // Error message. | 722 // Error message. |
692 std::string error_msg; | 723 std::string error_msg; |
693 if (UserCertRequired() && cert_library_->CertificatesLoaded()) { | 724 if (UserCertRequired() && cert_library_->CertificatesLoaded()) { |
694 if (!HaveUserCerts()) { | 725 if (!HaveUserCerts()) { |
695 error_msg = l10n_util::GetStringUTF8( | 726 error_msg = l10n_util::GetStringUTF8( |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
751 return std::string(); | 782 return std::string(); |
752 std::string untrimmed = UTF16ToUTF8(textfield->text()); | 783 std::string untrimmed = UTF16ToUTF8(textfield->text()); |
753 if (!trim_whitespace) | 784 if (!trim_whitespace) |
754 return untrimmed; | 785 return untrimmed; |
755 std::string result; | 786 std::string result; |
756 TrimWhitespaceASCII(untrimmed, TRIM_ALL, &result); | 787 TrimWhitespaceASCII(untrimmed, TRIM_ALL, &result); |
757 return result; | 788 return result; |
758 } | 789 } |
759 | 790 |
760 } // namespace chromeos | 791 } // namespace chromeos |
OLD | NEW |