OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/ui/certificate_dialogs.h" | 5 #include "chrome/browser/ui/certificate_dialogs.h" |
6 | 6 |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "chrome/browser/ui/chrome_select_file_policy.h" |
15 #include "chrome/common/net/x509_certificate_model.h" | 16 #include "chrome/common/net/x509_certificate_model.h" |
16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
17 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
18 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
19 | 20 |
20 using content::BrowserThread; | 21 using content::BrowserThread; |
21 using content::WebContents; | 22 using content::WebContents; |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 private: | 73 private: |
73 scoped_refptr<SelectFileDialog> select_file_dialog_; | 74 scoped_refptr<SelectFileDialog> select_file_dialog_; |
74 | 75 |
75 // The certificate hierarchy (leaf cert first). | 76 // The certificate hierarchy (leaf cert first). |
76 net::X509Certificate::OSCertHandles cert_chain_list_; | 77 net::X509Certificate::OSCertHandles cert_chain_list_; |
77 }; | 78 }; |
78 | 79 |
79 Exporter::Exporter(WebContents* web_contents, | 80 Exporter::Exporter(WebContents* web_contents, |
80 gfx::NativeWindow parent, | 81 gfx::NativeWindow parent, |
81 net::X509Certificate::OSCertHandle cert) | 82 net::X509Certificate::OSCertHandle cert) |
82 : select_file_dialog_(SelectFileDialog::Create(this)) { | 83 : select_file_dialog_(SelectFileDialog::Create( |
| 84 this, new ChromeSelectFilePolicy(web_contents))) { |
83 x509_certificate_model::GetCertChainFromCert(cert, &cert_chain_list_); | 85 x509_certificate_model::GetCertChainFromCert(cert, &cert_chain_list_); |
84 | 86 |
85 // TODO(mattm): should this default to some directory? | 87 // TODO(mattm): should this default to some directory? |
86 // Maybe SavePackage::GetSaveDirPreference? (Except that it's private.) | 88 // Maybe SavePackage::GetSaveDirPreference? (Except that it's private.) |
87 FilePath suggested_path("certificate"); | 89 FilePath suggested_path("certificate"); |
88 std::string cert_title = x509_certificate_model::GetTitle(cert); | 90 std::string cert_title = x509_certificate_model::GetTitle(cert); |
89 if (!cert_title.empty()) | 91 if (!cert_title.empty()) |
90 suggested_path = FilePath(cert_title); | 92 suggested_path = FilePath(cert_title); |
91 | 93 |
92 ShowCertSelectFileDialog(select_file_dialog_.get(), | 94 ShowCertSelectFileDialog(select_file_dialog_.get(), |
93 SelectFileDialog::SELECT_SAVEAS_FILE, | 95 SelectFileDialog::SELECT_SAVEAS_FILE, |
94 suggested_path, | 96 suggested_path, |
95 web_contents, | |
96 parent, | 97 parent, |
97 NULL); | 98 NULL); |
98 } | 99 } |
99 | 100 |
100 Exporter::~Exporter() { | 101 Exporter::~Exporter() { |
101 // There may be pending file dialogs, we need to tell them that we've gone | 102 // There may be pending file dialogs, we need to tell them that we've gone |
102 // away so they don't try and call back to us. | 103 // away so they don't try and call back to us. |
103 if (select_file_dialog_.get()) | 104 if (select_file_dialog_.get()) |
104 select_file_dialog_->ListenerDestroyed(); | 105 select_file_dialog_->ListenerDestroyed(); |
105 | 106 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 | 138 |
138 void Exporter::FileSelectionCanceled(void* params) { | 139 void Exporter::FileSelectionCanceled(void* params) { |
139 delete this; | 140 delete this; |
140 } | 141 } |
141 | 142 |
142 } // namespace | 143 } // namespace |
143 | 144 |
144 void ShowCertSelectFileDialog(SelectFileDialog* select_file_dialog, | 145 void ShowCertSelectFileDialog(SelectFileDialog* select_file_dialog, |
145 SelectFileDialog::Type type, | 146 SelectFileDialog::Type type, |
146 const FilePath& suggested_path, | 147 const FilePath& suggested_path, |
147 WebContents* web_contents, | |
148 gfx::NativeWindow parent, | 148 gfx::NativeWindow parent, |
149 void* params) { | 149 void* params) { |
150 SelectFileDialog::FileTypeInfo file_type_info; | 150 SelectFileDialog::FileTypeInfo file_type_info; |
151 file_type_info.extensions.resize(5); | 151 file_type_info.extensions.resize(5); |
152 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("pem")); | 152 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("pem")); |
153 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("crt")); | 153 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("crt")); |
154 file_type_info.extension_description_overrides.push_back( | 154 file_type_info.extension_description_overrides.push_back( |
155 l10n_util::GetStringUTF16(IDS_CERT_EXPORT_TYPE_BASE64)); | 155 l10n_util::GetStringUTF16(IDS_CERT_EXPORT_TYPE_BASE64)); |
156 file_type_info.extensions[1].push_back(FILE_PATH_LITERAL("pem")); | 156 file_type_info.extensions[1].push_back(FILE_PATH_LITERAL("pem")); |
157 file_type_info.extensions[1].push_back(FILE_PATH_LITERAL("crt")); | 157 file_type_info.extensions[1].push_back(FILE_PATH_LITERAL("crt")); |
158 file_type_info.extension_description_overrides.push_back( | 158 file_type_info.extension_description_overrides.push_back( |
159 l10n_util::GetStringUTF16(IDS_CERT_EXPORT_TYPE_BASE64_CHAIN)); | 159 l10n_util::GetStringUTF16(IDS_CERT_EXPORT_TYPE_BASE64_CHAIN)); |
160 file_type_info.extensions[2].push_back(FILE_PATH_LITERAL("der")); | 160 file_type_info.extensions[2].push_back(FILE_PATH_LITERAL("der")); |
161 file_type_info.extension_description_overrides.push_back( | 161 file_type_info.extension_description_overrides.push_back( |
162 l10n_util::GetStringUTF16(IDS_CERT_EXPORT_TYPE_DER)); | 162 l10n_util::GetStringUTF16(IDS_CERT_EXPORT_TYPE_DER)); |
163 file_type_info.extensions[3].push_back(FILE_PATH_LITERAL("p7c")); | 163 file_type_info.extensions[3].push_back(FILE_PATH_LITERAL("p7c")); |
164 file_type_info.extension_description_overrides.push_back( | 164 file_type_info.extension_description_overrides.push_back( |
165 l10n_util::GetStringUTF16(IDS_CERT_EXPORT_TYPE_PKCS7)); | 165 l10n_util::GetStringUTF16(IDS_CERT_EXPORT_TYPE_PKCS7)); |
166 file_type_info.extensions[4].push_back(FILE_PATH_LITERAL("p7c")); | 166 file_type_info.extensions[4].push_back(FILE_PATH_LITERAL("p7c")); |
167 file_type_info.extension_description_overrides.push_back( | 167 file_type_info.extension_description_overrides.push_back( |
168 l10n_util::GetStringUTF16(IDS_CERT_EXPORT_TYPE_PKCS7_CHAIN)); | 168 l10n_util::GetStringUTF16(IDS_CERT_EXPORT_TYPE_PKCS7_CHAIN)); |
169 file_type_info.include_all_files = true; | 169 file_type_info.include_all_files = true; |
170 select_file_dialog->SelectFile( | 170 select_file_dialog->SelectFile( |
171 type, string16(), | 171 type, string16(), |
172 suggested_path, &file_type_info, 1, | 172 suggested_path, &file_type_info, 1, |
173 FILE_PATH_LITERAL("crt"), web_contents, | 173 FILE_PATH_LITERAL("crt"), |
174 parent, params); | 174 parent, params); |
175 } | 175 } |
176 | 176 |
177 void ShowCertExportDialog(WebContents* web_contents, | 177 void ShowCertExportDialog(WebContents* web_contents, |
178 gfx::NativeWindow parent, | 178 gfx::NativeWindow parent, |
179 net::X509Certificate::OSCertHandle cert) { | 179 net::X509Certificate::OSCertHandle cert) { |
180 new Exporter(web_contents, parent, cert); | 180 new Exporter(web_contents, parent, cert); |
181 } | 181 } |
OLD | NEW |