Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / certificate_manager_handler.h
blob948c3bbaa9bdd26173ec0e5350967ce055dcf4d9
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.
5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_CERTIFICATE_MANAGER_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_CERTIFICATE_MANAGER_HANDLER_H_
8 #include <string>
10 #include "base/compiler_specific.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/task/cancelable_task_tracker.h"
14 #include "chrome/browser/certificate_manager_model.h"
15 #include "chrome/browser/ui/webui/options/options_ui.h"
16 #include "net/cert/nss_cert_database.h"
17 #include "ui/gfx/native_widget_types.h"
18 #include "ui/shell_dialogs/select_file_dialog.h"
20 namespace options {
22 class CertIdMap;
23 class FileAccessProvider;
25 class CertificateManagerHandler
26 : public OptionsPageUIHandler,
27 public CertificateManagerModel::Observer,
28 public ui::SelectFileDialog::Listener {
29 public:
30 explicit CertificateManagerHandler(bool show_certs_in_modal_dialog);
31 ~CertificateManagerHandler() override;
33 // OptionsPageUIHandler implementation.
34 void GetLocalizedValues(base::DictionaryValue* localized_strings) override;
35 void RegisterMessages() override;
37 // CertificateManagerModel::Observer implementation.
38 void CertificatesRefreshed() override;
40 // SelectFileDialog::Listener implementation.
41 void FileSelected(const base::FilePath& path,
42 int index,
43 void* params) override;
44 void FileSelectionCanceled(void* params) override;
46 private:
47 // View certificate.
48 void View(const base::ListValue* args);
50 // Edit server certificate trust values.
51 void EditServer(const base::ListValue* args);
53 // Edit certificate authority trust values. The sequence goes like:
54 // 1. user clicks edit button -> CertificateEditCaTrustOverlay.show ->
55 // GetCATrust -> CertificateEditCaTrustOverlay.populateTrust
56 // 2. user clicks ok -> EditCATrust -> CertificateEditCaTrustOverlay.dismiss
57 void GetCATrust(const base::ListValue* args);
58 void EditCATrust(const base::ListValue* args);
60 // Cleanup state stored during import or export process.
61 void CancelImportExportProcess(const base::ListValue* args);
62 void ImportExportCleanup();
64 // Export to PKCS #12 file. The sequence goes like:
65 // 1a. user click on export button -> ExportPersonal -> launches file
66 // selector
67 // 1b. user click on export all button -> ExportAllPersonal -> launches file
68 // selector
69 // 2. user selects file -> ExportPersonalFileSelected -> launches password
70 // dialog
71 // 3. user enters password -> ExportPersonalPasswordSelected -> unlock slots
72 // 4. slots unlocked -> ExportPersonalSlotsUnlocked -> exports to memory
73 // buffer -> starts async write operation
74 // 5. write finishes (or fails) -> ExportPersonalFileWritten
75 void ExportPersonal(const base::ListValue* args);
76 void ExportAllPersonal(const base::ListValue* args);
77 void ExportPersonalFileSelected(const base::FilePath& path);
78 void ExportPersonalPasswordSelected(const base::ListValue* args);
79 void ExportPersonalSlotsUnlocked();
80 void ExportPersonalFileWritten(const int* write_errno,
81 const int* bytes_written);
83 // Import from PKCS #12 file. The sequence goes like:
84 // 1. user click on import button -> StartImportPersonal -> launches file
85 // selector
86 // 2. user selects file -> ImportPersonalFileSelected -> launches password
87 // dialog
88 // 3. user enters password -> ImportPersonalPasswordSelected -> starts async
89 // read operation
90 // 4. read operation completes -> ImportPersonalFileRead -> unlock slot
91 // 5. slot unlocked -> ImportPersonalSlotUnlocked attempts to
92 // import with previously entered password
93 // 6a. if import succeeds -> ImportExportCleanup
94 // 6b. if import fails -> show error, ImportExportCleanup
95 // TODO(mattm): allow retrying with different password
96 void StartImportPersonal(const base::ListValue* args);
97 void ImportPersonalFileSelected(const base::FilePath& path);
98 void ImportPersonalPasswordSelected(const base::ListValue* args);
99 void ImportPersonalFileRead(const int* read_errno, const std::string* data);
100 void ImportPersonalSlotUnlocked();
102 // Import Server certificates from file. Sequence goes like:
103 // 1. user clicks on import button -> ImportServer -> launches file selector
104 // 2. user selects file -> ImportServerFileSelected -> starts async read
105 // 3. read completes -> ImportServerFileRead -> parse certs -> attempt import
106 // 4a. if import succeeds -> ImportExportCleanup
107 // 4b. if import fails -> show error, ImportExportCleanup
108 void ImportServer(const base::ListValue* args);
109 void ImportServerFileSelected(const base::FilePath& path);
110 void ImportServerFileRead(const int* read_errno, const std::string* data);
112 // Import Certificate Authorities from file. Sequence goes like:
113 // 1. user clicks on import button -> ImportCA -> launches file selector
114 // 2. user selects file -> ImportCAFileSelected -> starts async read
115 // 3. read completes -> ImportCAFileRead -> parse certs ->
116 // CertificateEditCaTrustOverlay.showImport
117 // 4. user clicks ok -> ImportCATrustSelected -> attempt import
118 // 5a. if import succeeds -> ImportExportCleanup
119 // 5b. if import fails -> show error, ImportExportCleanup
120 void ImportCA(const base::ListValue* args);
121 void ImportCAFileSelected(const base::FilePath& path);
122 void ImportCAFileRead(const int* read_errno, const std::string* data);
123 void ImportCATrustSelected(const base::ListValue* args);
125 // Export a certificate.
126 void Export(const base::ListValue* args);
128 // Delete certificate and private key (if any).
129 void Delete(const base::ListValue* args);
131 // Model initialization methods.
132 void OnCertificateManagerModelCreated(
133 scoped_ptr<CertificateManagerModel> model);
134 void CertificateManagerModelReady();
136 // Populate the trees in all the tabs.
137 void Populate(const base::ListValue* args);
139 // Populate the given tab's tree.
140 void PopulateTree(const std::string& tab_name,
141 net::CertType type,
142 const net::CertificateList& web_trust_certs);
144 // Populate the tree after retrieving the list of policy-installed
145 // web-trusted certificates.
146 void OnPolicyWebTrustCertsRetrieved(
147 const net::CertificateList& web_trust_certs);
149 // Display a WebUI error message box.
150 void ShowError(const std::string& title, const std::string& error) const;
152 // Display a WebUI error message box for import failures.
153 // Depends on |selected_cert_list_| being set to the imports that we
154 // attempted to import.
155 void ShowImportErrors(
156 const std::string& title,
157 const net::NSSCertDatabase::ImportCertFailureList& not_imported) const;
159 gfx::NativeWindow GetParentWindow() const;
161 // True if certificate viewer should be shown in modal instead of constrianed
162 // dialog.
163 bool show_certs_in_modal_dialog_;
164 // The Certificates Manager model
165 bool requested_certificate_manager_model_;
166 scoped_ptr<CertificateManagerModel> certificate_manager_model_;
168 // For multi-step import or export processes, we need to store the path,
169 // password, etc the user chose while we wait for them to enter a password,
170 // wait for file to be read, etc.
171 base::FilePath file_path_;
172 base::string16 password_;
173 bool use_hardware_backed_;
174 std::string file_data_;
175 net::CertificateList selected_cert_list_;
176 scoped_refptr<ui::SelectFileDialog> select_file_dialog_;
177 scoped_refptr<net::CryptoModule> module_;
179 // Used in reading and writing certificate files.
180 base::CancelableTaskTracker tracker_;
181 scoped_refptr<FileAccessProvider> file_access_provider_;
183 scoped_ptr<CertIdMap> cert_id_map_;
185 base::WeakPtrFactory<CertificateManagerHandler> weak_ptr_factory_;
187 DISALLOW_COPY_AND_ASSIGN(CertificateManagerHandler);
190 } // namespace options
192 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CERTIFICATE_MANAGER_HANDLER_H_