| OLD | NEW |
| 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 #ifndef CHROME_BROWSER_CHROMEOS_OPTIONS_VPN_CONFIG_VIEW_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_OPTIONS_VPN_CONFIG_VIEW_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_OPTIONS_VPN_CONFIG_VIEW_H_ | 6 #define CHROME_BROWSER_CHROMEOS_OPTIONS_VPN_CONFIG_VIEW_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 12 #include "chrome/browser/chromeos/cros/cert_library.h" | 12 #include "chrome/browser/chromeos/cros/cert_library.h" |
| 13 #include "chrome/browser/chromeos/cros/network_property_ui_data.h" | 13 #include "chrome/browser/chromeos/cros/network_property_ui_data.h" |
| 14 #include "chrome/browser/chromeos/options/network_config_view.h" | 14 #include "chrome/browser/chromeos/options/network_config_view.h" |
| 15 #include "chrome/browser/chromeos/options/passphrase_textfield.h" | 15 #include "chrome/browser/chromeos/options/passphrase_textfield.h" |
| 16 #include "ui/views/controls/button/button.h" | 16 #include "ui/views/controls/button/button.h" |
| 17 #include "ui/views/controls/combobox/combobox_listener.h" | 17 #include "ui/views/controls/combobox/combobox_listener.h" |
| 18 #include "ui/views/controls/textfield/textfield_controller.h" | 18 #include "ui/views/controls/textfield/textfield_controller.h" |
| 19 #include "ui/views/view.h" | 19 #include "ui/views/view.h" |
| 20 | 20 |
| 21 namespace base { |
| 22 class DictionaryValue; |
| 23 } |
| 24 |
| 21 namespace views { | 25 namespace views { |
| 22 class Checkbox; | 26 class Checkbox; |
| 27 class GridLayout; |
| 23 class Label; | 28 class Label; |
| 24 } | 29 } |
| 25 | 30 |
| 26 namespace chromeos { | 31 namespace chromeos { |
| 27 | 32 |
| 33 class NetworkState; |
| 34 |
| 28 namespace internal { | 35 namespace internal { |
| 29 class ProviderTypeComboboxModel; | 36 class ProviderTypeComboboxModel; |
| 30 class VpnServerCACertComboboxModel; | 37 class VpnServerCACertComboboxModel; |
| 31 class VpnUserCertComboboxModel; | 38 class VpnUserCertComboboxModel; |
| 32 } | 39 } |
| 33 | 40 |
| 34 // A dialog box to allow configuration of VPN connection. | 41 // A dialog box to allow configuration of VPN connection. |
| 35 class VPNConfigView : public ChildNetworkConfigView, | 42 class VPNConfigView : public ChildNetworkConfigView, |
| 36 public views::TextfieldController, | 43 public views::TextfieldController, |
| 37 public views::ButtonListener, | 44 public views::ButtonListener, |
| 38 public views::ComboboxListener, | 45 public views::ComboboxListener, |
| 39 public CertLibrary::Observer { | 46 public CertLibrary::Observer, |
| 47 public base::SupportsWeakPtr<VPNConfigView> { |
| 40 public: | 48 public: |
| 41 VPNConfigView(NetworkConfigView* parent, VirtualNetwork* vpn); | 49 VPNConfigView(NetworkConfigView* parent, const std::string& service_path); |
| 42 explicit VPNConfigView(NetworkConfigView* parent); | |
| 43 virtual ~VPNConfigView(); | 50 virtual ~VPNConfigView(); |
| 44 | 51 |
| 45 // views::TextfieldController: | 52 // views::TextfieldController: |
| 46 virtual void ContentsChanged(views::Textfield* sender, | 53 virtual void ContentsChanged(views::Textfield* sender, |
| 47 const string16& new_contents) OVERRIDE; | 54 const string16& new_contents) OVERRIDE; |
| 48 virtual bool HandleKeyEvent(views::Textfield* sender, | 55 virtual bool HandleKeyEvent(views::Textfield* sender, |
| 49 const ui::KeyEvent& key_event) OVERRIDE; | 56 const ui::KeyEvent& key_event) OVERRIDE; |
| 50 | 57 |
| 51 // views::ButtonListener: | 58 // views::ButtonListener: |
| 52 virtual void ButtonPressed(views::Button* sender, | 59 virtual void ButtonPressed(views::Button* sender, |
| 53 const ui::Event& event) OVERRIDE; | 60 const ui::Event& event) OVERRIDE; |
| 54 | 61 |
| 55 // views::ComboboxListener: | 62 // views::ComboboxListener: |
| 56 virtual void OnSelectedIndexChanged(views::Combobox* combobox) OVERRIDE; | 63 virtual void OnSelectedIndexChanged(views::Combobox* combobox) OVERRIDE; |
| 57 | 64 |
| 58 // CertLibrary::Observer: | 65 // CertLibrary::Observer: |
| 59 virtual void OnCertificatesLoaded(bool initial_load) OVERRIDE; | 66 virtual void OnCertificatesLoaded(bool initial_load) OVERRIDE; |
| 60 | 67 |
| 61 // ChildNetworkConfigView: | 68 // ChildNetworkConfigView: |
| 62 virtual string16 GetTitle() const OVERRIDE; | 69 virtual string16 GetTitle() const OVERRIDE; |
| 63 virtual views::View* GetInitiallyFocusedView() OVERRIDE; | 70 virtual views::View* GetInitiallyFocusedView() OVERRIDE; |
| 64 virtual bool CanLogin() OVERRIDE; | 71 virtual bool CanLogin() OVERRIDE; |
| 65 virtual bool Login() OVERRIDE; | 72 virtual bool Login() OVERRIDE; |
| 66 virtual void Cancel() OVERRIDE; | 73 virtual void Cancel() OVERRIDE; |
| 67 virtual void InitFocus() OVERRIDE; | 74 virtual void InitFocus() OVERRIDE; |
| 68 | 75 |
| 69 private: | 76 private: |
| 70 // Initializes data members and create UI controls. | 77 // Initializes data members and create UI controls. |
| 71 void Init(VirtualNetwork* vpn); | 78 void Init(); |
| 79 void InitControls(); |
| 80 |
| 81 // Callback to initialize fields from uncached network properties. |
| 82 void InitFromProperties(const std::string& service_path, |
| 83 const base::DictionaryValue& dictionary); |
| 84 void GetPropertiesError(const std::string& error_name, |
| 85 scoped_ptr<base::DictionaryValue> error_data); |
| 86 |
| 87 // Helper function to set credential properties. |
| 88 void SetCredentials(base::DictionaryValue* properties); |
| 72 | 89 |
| 73 // Set and update all control values. | 90 // Set and update all control values. |
| 74 void Refresh(); | 91 void Refresh(); |
| 75 | 92 |
| 76 // Update various controls. | 93 // Update various controls. |
| 77 void UpdateControlsToEnable(); | 94 void UpdateControlsToEnable(); |
| 78 void UpdateControls(); | 95 void UpdateControls(); |
| 79 void UpdateErrorLabel(); | 96 void UpdateErrorLabel(); |
| 80 | 97 |
| 81 // Update state of the Login button. | 98 // Update state of the Login button. |
| 82 void UpdateCanLogin(); | 99 void UpdateCanLogin(); |
| 83 | 100 |
| 84 // Returns true if the provider type requires a user certificate. | |
| 85 bool UserCertRequired() const; | |
| 86 | |
| 87 // Returns true if there is at least one user certificate installed. | 101 // Returns true if there is at least one user certificate installed. |
| 88 bool HaveUserCerts() const; | 102 bool HaveUserCerts() const; |
| 89 | 103 |
| 90 // Returns true if there is a selected user certificate and it is valid. | 104 // Returns true if there is a selected user certificate and it is valid. |
| 91 bool IsUserCertValid() const; | 105 bool IsUserCertValid() const; |
| 92 | 106 |
| 93 // Get text from input field. | 107 // Get text from input field. |
| 94 const std::string GetTextFromField(views::Textfield* textfield, | 108 const std::string GetTextFromField(views::Textfield* textfield, |
| 95 bool trim_whitespace) const; | 109 bool trim_whitespace) const; |
| 96 | 110 |
| 97 // Get passphrase from input field. | 111 // Get passphrase from input field. |
| 98 const std::string GetPassphraseFromField( | 112 const std::string GetPassphraseFromField( |
| 99 PassphraseTextfield* textfield) const; | 113 PassphraseTextfield* textfield) const; |
| 100 | 114 |
| 101 // Convenience methods to get text from input field or cached VirtualNetwork. | 115 // Convenience methods to get text from input field or cached VirtualNetwork. |
| 102 const std::string GetService() const; | 116 const std::string GetService() const; |
| 103 const std::string GetServer() const; | 117 const std::string GetServer() const; |
| 104 const std::string GetPSKPassphrase() const; | 118 const std::string GetPSKPassphrase() const; |
| 105 const std::string GetUsername() const; | 119 const std::string GetUsername() const; |
| 106 const std::string GetUserPassphrase() const; | 120 const std::string GetUserPassphrase() const; |
| 107 const std::string GetOTP() const; | 121 const std::string GetOTP() const; |
| 108 const std::string GetGroupName() const; | 122 const std::string GetGroupName() const; |
| 109 const std::string GetServerCACertPEM() const; | 123 const std::string GetServerCACertPEM() const; |
| 110 const std::string GetUserCertID() const; | 124 const std::string GetUserCertID() const; |
| 111 bool GetSaveCredentials() const; | 125 bool GetSaveCredentials() const; |
| 126 int GetProviderTypeIndex() const; |
| 127 std::string GetProviderTypeString() const; |
| 112 | 128 |
| 113 // Parses a VPN UI |property| from the given |network|. |key| is the property | 129 // Parses a VPN UI |property| from the given |network|. |key| is the property |
| 114 // name within the type-specific VPN subdictionary named |dict_key|. | 130 // name within the type-specific VPN subdictionary named |dict_key|. |
| 115 void ParseVPNUIProperty(NetworkPropertyUIData* property_ui_data, | 131 void ParseVPNUIProperty(NetworkPropertyUIData* property_ui_data, |
| 116 Network* network, | 132 const NetworkState* network, |
| 117 const std::string& dict_key, | 133 const std::string& dict_key, |
| 118 const std::string& key); | 134 const std::string& key); |
| 119 | 135 |
| 120 std::string server_hostname_; | |
| 121 string16 service_name_from_server_; | 136 string16 service_name_from_server_; |
| 122 bool service_text_modified_; | 137 bool service_text_modified_; |
| 123 | 138 |
| 124 // Initialized in Init(): | 139 // Initialized in Init(): |
| 125 | 140 |
| 126 ProviderType provider_type_; | 141 std::string provider_type_; |
| 127 | 142 |
| 128 bool enable_psk_passphrase_; | 143 bool enable_psk_passphrase_; |
| 129 bool enable_user_cert_; | 144 bool enable_user_cert_; |
| 130 bool enable_server_ca_cert_; | 145 bool enable_server_ca_cert_; |
| 131 bool enable_otp_; | 146 bool enable_otp_; |
| 132 bool enable_group_name_; | 147 bool enable_group_name_; |
| 133 | 148 |
| 134 NetworkPropertyUIData ca_cert_ui_data_; | 149 NetworkPropertyUIData ca_cert_ui_data_; |
| 135 NetworkPropertyUIData psk_passphrase_ui_data_; | 150 NetworkPropertyUIData psk_passphrase_ui_data_; |
| 136 NetworkPropertyUIData user_cert_ui_data_; | 151 NetworkPropertyUIData user_cert_ui_data_; |
| 137 NetworkPropertyUIData username_ui_data_; | 152 NetworkPropertyUIData username_ui_data_; |
| 138 NetworkPropertyUIData user_passphrase_ui_data_; | 153 NetworkPropertyUIData user_passphrase_ui_data_; |
| 139 NetworkPropertyUIData group_name_ui_data_; | 154 NetworkPropertyUIData group_name_ui_data_; |
| 140 NetworkPropertyUIData save_credentials_ui_data_; | 155 NetworkPropertyUIData save_credentials_ui_data_; |
| 141 | 156 |
| 142 int title_; | 157 int title_; |
| 143 | 158 |
| 159 views::GridLayout* layout_; |
| 144 views::Textfield* server_textfield_; | 160 views::Textfield* server_textfield_; |
| 145 views::Label* service_text_; | 161 views::Label* service_text_; |
| 146 views::Textfield* service_textfield_; | 162 views::Textfield* service_textfield_; |
| 147 scoped_ptr<internal::ProviderTypeComboboxModel> provider_type_combobox_model_; | 163 scoped_ptr<internal::ProviderTypeComboboxModel> provider_type_combobox_model_; |
| 148 views::Combobox* provider_type_combobox_; | 164 views::Combobox* provider_type_combobox_; |
| 149 views::Label* provider_type_text_label_; | 165 views::Label* provider_type_text_label_; |
| 150 views::Label* psk_passphrase_label_; | 166 views::Label* psk_passphrase_label_; |
| 151 PassphraseTextfield* psk_passphrase_textfield_; | 167 PassphraseTextfield* psk_passphrase_textfield_; |
| 152 views::Label* user_cert_label_; | 168 views::Label* user_cert_label_; |
| 153 scoped_ptr<internal::VpnUserCertComboboxModel> user_cert_combobox_model_; | 169 scoped_ptr<internal::VpnUserCertComboboxModel> user_cert_combobox_model_; |
| 154 views::Combobox* user_cert_combobox_; | 170 views::Combobox* user_cert_combobox_; |
| 155 views::Label* server_ca_cert_label_; | 171 views::Label* server_ca_cert_label_; |
| 156 scoped_ptr<internal::VpnServerCACertComboboxModel> | 172 scoped_ptr<internal::VpnServerCACertComboboxModel> |
| 157 server_ca_cert_combobox_model_; | 173 server_ca_cert_combobox_model_; |
| 158 views::Combobox* server_ca_cert_combobox_; | 174 views::Combobox* server_ca_cert_combobox_; |
| 159 views::Textfield* username_textfield_; | 175 views::Textfield* username_textfield_; |
| 160 PassphraseTextfield* user_passphrase_textfield_; | 176 PassphraseTextfield* user_passphrase_textfield_; |
| 161 views::Label* otp_label_; | 177 views::Label* otp_label_; |
| 162 views::Textfield* otp_textfield_; | 178 views::Textfield* otp_textfield_; |
| 163 views::Label* group_name_label_; | 179 views::Label* group_name_label_; |
| 164 views::Textfield* group_name_textfield_; | 180 views::Textfield* group_name_textfield_; |
| 165 views::Checkbox* save_credentials_checkbox_; | 181 views::Checkbox* save_credentials_checkbox_; |
| 166 views::Label* error_label_; | 182 views::Label* error_label_; |
| 167 | 183 |
| 184 // Cached VPN properties |
| 185 std::string ca_cert_pem_; |
| 186 std::string client_cert_id_; |
| 187 |
| 168 DISALLOW_COPY_AND_ASSIGN(VPNConfigView); | 188 DISALLOW_COPY_AND_ASSIGN(VPNConfigView); |
| 169 }; | 189 }; |
| 170 | 190 |
| 171 } // namespace chromeos | 191 } // namespace chromeos |
| 172 | 192 |
| 173 #endif // CHROME_BROWSER_CHROMEOS_OPTIONS_VPN_CONFIG_VIEW_H_ | 193 #endif // CHROME_BROWSER_CHROMEOS_OPTIONS_VPN_CONFIG_VIEW_H_ |
| OLD | NEW |