| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS2_CERTIFICATE_MANAGER_HANDLER_H_ | |
| 6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS2_CERTIFICATE_MANAGER_HANDLER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/compiler_specific.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/memory/weak_ptr.h" | |
| 13 #include "chrome/browser/cancelable_request.h" | |
| 14 #include "chrome/browser/certificate_manager_model.h" | |
| 15 #include "chrome/browser/ui/webui/options2/options_ui.h" | |
| 16 #include "net/base/cert_database.h" | |
| 17 #include "ui/base/dialogs/select_file_dialog.h" | |
| 18 #include "ui/gfx/native_widget_types.h" | |
| 19 | |
| 20 #if defined(OS_CHROMEOS) | |
| 21 #include "chromeos/dbus/cryptohome_client.h" | |
| 22 #endif | |
| 23 | |
| 24 namespace options { | |
| 25 | |
| 26 class CertIdMap; | |
| 27 class FileAccessProvider; | |
| 28 | |
| 29 class CertificateManagerHandler | |
| 30 : public OptionsPageUIHandler, | |
| 31 public CertificateManagerModel::Observer, | |
| 32 public ui::SelectFileDialog::Listener { | |
| 33 public: | |
| 34 CertificateManagerHandler(); | |
| 35 virtual ~CertificateManagerHandler(); | |
| 36 | |
| 37 // OptionsPageUIHandler implementation. | |
| 38 virtual void GetLocalizedValues( | |
| 39 base::DictionaryValue* localized_strings) OVERRIDE; | |
| 40 virtual void RegisterMessages() OVERRIDE; | |
| 41 | |
| 42 // CertificateManagerModel::Observer implementation. | |
| 43 virtual void CertificatesRefreshed() OVERRIDE; | |
| 44 | |
| 45 // SelectFileDialog::Listener implementation. | |
| 46 virtual void FileSelected(const FilePath& path, | |
| 47 int index, | |
| 48 void* params) OVERRIDE; | |
| 49 virtual void FileSelectionCanceled(void* params) OVERRIDE; | |
| 50 | |
| 51 private: | |
| 52 // View certificate. | |
| 53 void View(const base::ListValue* args); | |
| 54 | |
| 55 // Edit server certificate trust values. | |
| 56 void EditServer(const base::ListValue* args); | |
| 57 | |
| 58 // Edit certificate authority trust values. The sequence goes like: | |
| 59 // 1. user clicks edit button -> CertificateEditCaTrustOverlay.show -> | |
| 60 // GetCATrust -> CertificateEditCaTrustOverlay.populateTrust | |
| 61 // 2. user clicks ok -> EditCATrust -> CertificateEditCaTrustOverlay.dismiss | |
| 62 void GetCATrust(const base::ListValue* args); | |
| 63 void EditCATrust(const base::ListValue* args); | |
| 64 | |
| 65 // Cleanup state stored during import or export process. | |
| 66 void CancelImportExportProcess(const base::ListValue* args); | |
| 67 void ImportExportCleanup(); | |
| 68 | |
| 69 // Export to PKCS #12 file. The sequence goes like: | |
| 70 // 1a. user click on export button -> ExportPersonal -> launches file | |
| 71 // selector | |
| 72 // 1b. user click on export all button -> ExportAllPersonal -> launches file | |
| 73 // selector | |
| 74 // 2. user selects file -> ExportPersonalFileSelected -> launches password | |
| 75 // dialog | |
| 76 // 3. user enters password -> ExportPersonalPasswordSelected -> unlock slots | |
| 77 // 4. slots unlocked -> ExportPersonalSlotsUnlocked -> exports to memory | |
| 78 // buffer -> starts async write operation | |
| 79 // 5. write finishes (or fails) -> ExportPersonalFileWritten | |
| 80 void ExportPersonal(const base::ListValue* args); | |
| 81 void ExportAllPersonal(const base::ListValue* args); | |
| 82 void ExportPersonalFileSelected(const FilePath& path); | |
| 83 void ExportPersonalPasswordSelected(const base::ListValue* args); | |
| 84 void ExportPersonalSlotsUnlocked(); | |
| 85 void ExportPersonalFileWritten(int write_errno, int bytes_written); | |
| 86 | |
| 87 // Import from PKCS #12 file. The sequence goes like: | |
| 88 // 1. user click on import button -> StartImportPersonal -> launches file | |
| 89 // selector | |
| 90 // 2. user selects file -> ImportPersonalFileSelected -> launches password | |
| 91 // dialog | |
| 92 // 3. user enters password -> ImportPersonalPasswordSelected -> starts async | |
| 93 // read operation | |
| 94 // 4. read operation completes -> ImportPersonalFileRead -> unlock slot | |
| 95 // 5. slot unlocked -> ImportPersonalSlotUnlocked attempts to | |
| 96 // import with previously entered password | |
| 97 // 6a. if import succeeds -> ImportExportCleanup | |
| 98 // 6b. if import fails -> show error, ImportExportCleanup | |
| 99 // TODO(mattm): allow retrying with different password | |
| 100 void StartImportPersonal(const base::ListValue* args); | |
| 101 void ImportPersonalFileSelected(const FilePath& path); | |
| 102 void ImportPersonalPasswordSelected(const base::ListValue* args); | |
| 103 void ImportPersonalFileRead(int read_errno, std::string data); | |
| 104 void ImportPersonalSlotUnlocked(); | |
| 105 | |
| 106 // Import Server certificates from file. Sequence goes like: | |
| 107 // 1. user clicks on import button -> ImportServer -> launches file selector | |
| 108 // 2. user selects file -> ImportServerFileSelected -> starts async read | |
| 109 // 3. read completes -> ImportServerFileRead -> parse certs -> attempt import | |
| 110 // 4a. if import succeeds -> ImportExportCleanup | |
| 111 // 4b. if import fails -> show error, ImportExportCleanup | |
| 112 void ImportServer(const base::ListValue* args); | |
| 113 void ImportServerFileSelected(const FilePath& path); | |
| 114 void ImportServerFileRead(int read_errno, std::string data); | |
| 115 | |
| 116 // Import Certificate Authorities from file. Sequence goes like: | |
| 117 // 1. user clicks on import button -> ImportCA -> launches file selector | |
| 118 // 2. user selects file -> ImportCAFileSelected -> starts async read | |
| 119 // 3. read completes -> ImportCAFileRead -> parse certs -> | |
| 120 // CertificateEditCaTrustOverlay.showImport | |
| 121 // 4. user clicks ok -> ImportCATrustSelected -> attempt import | |
| 122 // 5a. if import succeeds -> ImportExportCleanup | |
| 123 // 5b. if import fails -> show error, ImportExportCleanup | |
| 124 void ImportCA(const base::ListValue* args); | |
| 125 void ImportCAFileSelected(const FilePath& path); | |
| 126 void ImportCAFileRead(int read_errno, std::string data); | |
| 127 void ImportCATrustSelected(const base::ListValue* args); | |
| 128 | |
| 129 // Export a certificate. | |
| 130 void Export(const base::ListValue* args); | |
| 131 | |
| 132 // Delete certificate and private key (if any). | |
| 133 void Delete(const base::ListValue* args); | |
| 134 | |
| 135 // Populate the trees in all the tabs. | |
| 136 void Populate(const base::ListValue* args); | |
| 137 | |
| 138 // Populate the given tab's tree. | |
| 139 void PopulateTree(const std::string& tab_name, net::CertType type); | |
| 140 | |
| 141 // Display a WebUI error message box. | |
| 142 void ShowError(const std::string& title, const std::string& error) const; | |
| 143 | |
| 144 // Display a WebUI error message box for import failures. | |
| 145 // Depends on |selected_cert_list_| being set to the imports that we | |
| 146 // attempted to import. | |
| 147 void ShowImportErrors( | |
| 148 const std::string& title, | |
| 149 const net::CertDatabase::ImportCertFailureList& not_imported) const; | |
| 150 | |
| 151 #if defined(OS_CHROMEOS) | |
| 152 // Check whether Tpm token is ready and notifiy JS side. | |
| 153 void CheckTpmTokenReady(const base::ListValue* args); | |
| 154 void CheckTpmTokenReadyInternal( | |
| 155 chromeos::DBusMethodCallStatus call_status, | |
| 156 bool is_tpm_token_ready); | |
| 157 #endif | |
| 158 | |
| 159 gfx::NativeWindow GetParentWindow() const; | |
| 160 | |
| 161 // The Certificates Manager model | |
| 162 scoped_ptr<CertificateManagerModel> certificate_manager_model_; | |
| 163 | |
| 164 // For multi-step import or export processes, we need to store the path, | |
| 165 // password, etc the user chose while we wait for them to enter a password, | |
| 166 // wait for file to be read, etc. | |
| 167 FilePath file_path_; | |
| 168 string16 password_; | |
| 169 bool use_hardware_backed_; | |
| 170 std::string file_data_; | |
| 171 net::CertificateList selected_cert_list_; | |
| 172 scoped_refptr<ui::SelectFileDialog> select_file_dialog_; | |
| 173 scoped_refptr<net::CryptoModule> module_; | |
| 174 | |
| 175 // Used in reading and writing certificate files. | |
| 176 CancelableRequestConsumer consumer_; | |
| 177 scoped_refptr<FileAccessProvider> file_access_provider_; | |
| 178 | |
| 179 base::WeakPtrFactory<CertificateManagerHandler> weak_ptr_factory_; | |
| 180 | |
| 181 scoped_ptr<CertIdMap> cert_id_map_; | |
| 182 | |
| 183 DISALLOW_COPY_AND_ASSIGN(CertificateManagerHandler); | |
| 184 }; | |
| 185 | |
| 186 } // namespace options | |
| 187 | |
| 188 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS2_CERTIFICATE_MANAGER_HANDLER_H_ | |
| OLD | NEW |