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