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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_CHROMEOS_OPTIONS_VPN_CONFIG_VIEW_H_ 6 #define CHROME_BROWSER_CHROMEOS_OPTIONS_VPN_CONFIG_VIEW_H_ 7 #pragma once 8 9 #include <string> 10 11 #include "base/string16.h" 12 #include "chrome/browser/chromeos/cros/network_library.h" 13 #include "chrome/browser/chromeos/options/network_config_view.h" 14 #include "chrome/browser/ui/shell_dialogs.h" 15 #include "ui/base/models/combobox_model.h" 16 #include "views/controls/button/button.h" 17 #include "views/controls/button/native_button.h" 18 #include "views/controls/combobox/combobox.h" 19 #include "views/controls/textfield/textfield_controller.h" 20 #include "views/view.h" 21 22 namespace views { 23 class Label; 24 } 25 26 namespace chromeos { 27 28 // A dialog box to allow configuration of VPN connection. 29 class VPNConfigView : public ChildNetworkConfigView, 30 public views::TextfieldController, 31 public views::ButtonListener, 32 public views::Combobox::Listener { 33 public: 34 VPNConfigView(NetworkConfigView* parent, VirtualNetwork* vpn); 35 explicit VPNConfigView(NetworkConfigView* parent); 36 virtual ~VPNConfigView(); 37 38 // views::TextfieldController methods. 39 virtual void ContentsChanged(views::Textfield* sender, 40 const string16& new_contents); 41 virtual bool HandleKeyEvent(views::Textfield* sender, 42 const views::KeyEvent& key_event); 43 44 // views::ButtonListener 45 virtual void ButtonPressed(views::Button* sender, const views::Event& event); 46 47 // views::Combobox::Listener 48 virtual void ItemChanged(views::Combobox* combo_box, 49 int prev_index, int new_index); 50 51 // ChildNetworkConfigView implementation. 52 virtual string16 GetTitle() OVERRIDE; 53 virtual bool CanLogin() OVERRIDE; 54 virtual bool Login() OVERRIDE; 55 virtual void Cancel() OVERRIDE; 56 virtual void InitFocus() OVERRIDE; 57 58 private: 59 class ProviderTypeComboboxModel : public ui::ComboboxModel { 60 public: ProviderTypeComboboxModel()61 ProviderTypeComboboxModel() {} ~ProviderTypeComboboxModel()62 virtual ~ProviderTypeComboboxModel() {} 63 virtual int GetItemCount(); 64 virtual string16 GetItemAt(int index); 65 private: 66 DISALLOW_COPY_AND_ASSIGN(ProviderTypeComboboxModel); 67 }; 68 69 class UserCertComboboxModel : public ui::ComboboxModel { 70 public: 71 UserCertComboboxModel(); ~UserCertComboboxModel()72 virtual ~UserCertComboboxModel() {} 73 virtual int GetItemCount(); 74 virtual string16 GetItemAt(int index); 75 private: 76 std::vector<std::string> user_certs_; 77 DISALLOW_COPY_AND_ASSIGN(UserCertComboboxModel); 78 }; 79 80 // Initializes data members and create UI controls. 81 void Init(VirtualNetwork* vpn); 82 83 void EnableControls(); 84 85 // Update state of the Login button. 86 void UpdateCanLogin(); 87 88 // Update the error text label. 89 void UpdateErrorLabel(); 90 91 // Get text from input field. 92 const std::string GetTextFromField(views::Textfield* textfield, 93 bool trim_whitespace) const; 94 95 // Convenience methods to get text from input field or cached VirtualNetwork. 96 const std::string GetService() const; 97 const std::string GetServer() const; 98 const std::string GetPSKPassphrase() const; 99 const std::string GetUsername() const; 100 const std::string GetUserPassphrase() const; 101 102 std::string server_hostname_; 103 string16 service_name_from_server_; 104 bool service_text_modified_; 105 VirtualNetwork::ProviderType provider_type_; 106 107 views::Label* service_text_; 108 views::Textfield* service_textfield_; 109 views::Label* server_text_; 110 views::Textfield* server_textfield_; 111 views::Combobox* provider_type_combobox_; 112 views::Label* provider_type_text_label_; 113 views::Label* psk_passphrase_label_; 114 views::Textfield* psk_passphrase_textfield_; 115 views::Label* user_cert_label_; 116 views::Combobox* user_cert_combobox_; 117 views::Textfield* username_textfield_; 118 views::Textfield* user_passphrase_textfield_; 119 views::Label* error_label_; 120 121 DISALLOW_COPY_AND_ASSIGN(VPNConfigView); 122 }; 123 124 } // namespace chromeos 125 126 #endif // CHROME_BROWSER_CHROMEOS_OPTIONS_VPN_CONFIG_VIEW_H_ 127