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