| OLD | NEW |
| 1 // Copyright (c) 2012 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" | |
| 16 #include "chrome/common/net/x509_certificate_model.h" | 15 #include "chrome/common/net/x509_certificate_model.h" |
| 17 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 18 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
| 20 | 19 |
| 21 using content::BrowserThread; | 20 using content::BrowserThread; |
| 22 using content::WebContents; | 21 using content::WebContents; |
| 23 | 22 |
| 24 namespace { | 23 namespace { |
| 25 | 24 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 private: | 72 private: |
| 74 scoped_refptr<SelectFileDialog> select_file_dialog_; | 73 scoped_refptr<SelectFileDialog> select_file_dialog_; |
| 75 | 74 |
| 76 // The certificate hierarchy (leaf cert first). | 75 // The certificate hierarchy (leaf cert first). |
| 77 net::X509Certificate::OSCertHandles cert_chain_list_; | 76 net::X509Certificate::OSCertHandles cert_chain_list_; |
| 78 }; | 77 }; |
| 79 | 78 |
| 80 Exporter::Exporter(WebContents* web_contents, | 79 Exporter::Exporter(WebContents* web_contents, |
| 81 gfx::NativeWindow parent, | 80 gfx::NativeWindow parent, |
| 82 net::X509Certificate::OSCertHandle cert) | 81 net::X509Certificate::OSCertHandle cert) |
| 83 : select_file_dialog_(SelectFileDialog::Create( | 82 : select_file_dialog_(SelectFileDialog::Create(this)) { |
| 84 this, new ChromeSelectFilePolicy(web_contents))) { | |
| 85 x509_certificate_model::GetCertChainFromCert(cert, &cert_chain_list_); | 83 x509_certificate_model::GetCertChainFromCert(cert, &cert_chain_list_); |
| 86 | 84 |
| 87 // TODO(mattm): should this default to some directory? | 85 // TODO(mattm): should this default to some directory? |
| 88 // Maybe SavePackage::GetSaveDirPreference? (Except that it's private.) | 86 // Maybe SavePackage::GetSaveDirPreference? (Except that it's private.) |
| 89 FilePath suggested_path("certificate"); | 87 FilePath suggested_path("certificate"); |
| 90 std::string cert_title = x509_certificate_model::GetTitle(cert); | 88 std::string cert_title = x509_certificate_model::GetTitle(cert); |
| 91 if (!cert_title.empty()) | 89 if (!cert_title.empty()) |
| 92 suggested_path = FilePath(cert_title); | 90 suggested_path = FilePath(cert_title); |
| 93 | 91 |
| 94 ShowCertSelectFileDialog(select_file_dialog_.get(), | 92 ShowCertSelectFileDialog(select_file_dialog_.get(), |
| 95 SelectFileDialog::SELECT_SAVEAS_FILE, | 93 SelectFileDialog::SELECT_SAVEAS_FILE, |
| 96 suggested_path, | 94 suggested_path, |
| 95 web_contents, |
| 97 parent, | 96 parent, |
| 98 NULL); | 97 NULL); |
| 99 } | 98 } |
| 100 | 99 |
| 101 Exporter::~Exporter() { | 100 Exporter::~Exporter() { |
| 102 // There may be pending file dialogs, we need to tell them that we've gone | 101 // There may be pending file dialogs, we need to tell them that we've gone |
| 103 // away so they don't try and call back to us. | 102 // away so they don't try and call back to us. |
| 104 if (select_file_dialog_.get()) | 103 if (select_file_dialog_.get()) |
| 105 select_file_dialog_->ListenerDestroyed(); | 104 select_file_dialog_->ListenerDestroyed(); |
| 106 | 105 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 | 137 |
| 139 void Exporter::FileSelectionCanceled(void* params) { | 138 void Exporter::FileSelectionCanceled(void* params) { |
| 140 delete this; | 139 delete this; |
| 141 } | 140 } |
| 142 | 141 |
| 143 } // namespace | 142 } // namespace |
| 144 | 143 |
| 145 void ShowCertSelectFileDialog(SelectFileDialog* select_file_dialog, | 144 void ShowCertSelectFileDialog(SelectFileDialog* select_file_dialog, |
| 146 SelectFileDialog::Type type, | 145 SelectFileDialog::Type type, |
| 147 const FilePath& suggested_path, | 146 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"), | 173 FILE_PATH_LITERAL("crt"), web_contents, |
| 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 |