OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/webui/certificate_viewer_webui.h" | 5 #include "chrome/browser/ui/webui/certificate_viewer_webui.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/i18n/time_formatting.h" | 9 #include "base/i18n/time_formatting.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 24 matching lines...) Expand all Loading... | |
35 dialog->Show(web_contents, parent); | 35 dialog->Show(web_contents, parent); |
36 } | 36 } |
37 | 37 |
38 //////////////////////////////////////////////////////////////////////////////// | 38 //////////////////////////////////////////////////////////////////////////////// |
39 // CertificateViewerDialog | 39 // CertificateViewerDialog |
40 | 40 |
41 CertificateViewerModalDialog::CertificateViewerModalDialog( | 41 CertificateViewerModalDialog::CertificateViewerModalDialog( |
42 net::X509Certificate* cert) | 42 net::X509Certificate* cert) |
43 : cert_(cert), webui_(NULL), window_(NULL) { | 43 : cert_(cert), webui_(NULL), window_(NULL) { |
44 // Construct the dialog title from the certificate. | 44 // Construct the dialog title from the certificate. |
45 net::X509Certificate::OSCertHandles cert_chain; | 45 title_ = l10n_util::GetStringFUTF16( |
46 x509_certificate_model::GetCertChainFromCert(cert_->os_cert_handle(), | 46 IDS_CERT_INFO_DIALOG_TITLE, |
47 &cert_chain); | 47 base::UTF8ToUTF16( |
48 title_ = l10n_util::GetStringFUTF16(IDS_CERT_INFO_DIALOG_TITLE, | 48 x509_certificate_model::GetTitle(cert_->os_cert_handle()))); |
49 base::UTF8ToUTF16(x509_certificate_model::GetTitle(cert_chain.front()))); | |
50 } | 49 } |
51 | 50 |
52 CertificateViewerModalDialog::~CertificateViewerModalDialog() { | 51 CertificateViewerModalDialog::~CertificateViewerModalDialog() { |
53 } | 52 } |
54 | 53 |
55 void CertificateViewerModalDialog::Show(content::WebContents* web_contents, | 54 void CertificateViewerModalDialog::Show(content::WebContents* web_contents, |
56 gfx::NativeWindow parent) { | 55 gfx::NativeWindow parent) { |
57 window_ = chrome::ShowWebDialog(parent, | 56 window_ = chrome::ShowWebDialog(parent, |
58 web_contents->GetBrowserContext(), | 57 web_contents->GetBrowserContext(), |
59 this); | 58 this); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 std::string CertificateViewerModalDialog::GetDialogArgs() const { | 95 std::string CertificateViewerModalDialog::GetDialogArgs() const { |
97 std::string data; | 96 std::string data; |
98 | 97 |
99 // Certificate information. The keys in this dictionary's general key | 98 // Certificate information. The keys in this dictionary's general key |
100 // correspond to the IDs in the Html page. | 99 // correspond to the IDs in the Html page. |
101 base::DictionaryValue cert_info; | 100 base::DictionaryValue cert_info; |
102 net::X509Certificate::OSCertHandle cert_hnd = cert_->os_cert_handle(); | 101 net::X509Certificate::OSCertHandle cert_hnd = cert_->os_cert_handle(); |
103 | 102 |
104 // Get the certificate chain. | 103 // Get the certificate chain. |
105 net::X509Certificate::OSCertHandles cert_chain; | 104 net::X509Certificate::OSCertHandles cert_chain; |
106 x509_certificate_model::GetCertChainFromCert(cert_hnd, &cert_chain); | 105 x509_certificate_model::GetCertChainFromCert(cert_, &cert_chain); |
107 | 106 |
108 // Certificate usage. | 107 // Certificate usage. |
109 std::vector<std::string> usages; | 108 std::vector<std::string> usages; |
110 x509_certificate_model::GetUsageStrings(cert_hnd, &usages); | 109 x509_certificate_model::GetUsageStrings(cert_hnd, &usages); |
111 std::string usagestr; | 110 std::string usagestr; |
112 for (std::vector<std::string>::iterator it = usages.begin(); | 111 for (std::vector<std::string>::iterator it = usages.begin(); |
113 it != usages.end(); ++it) { | 112 it != usages.end(); ++it) { |
114 if (usagestr.length() > 0) { | 113 if (usagestr.length() > 0) { |
115 usagestr += "\n"; | 114 usagestr += "\n"; |
116 } | 115 } |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 ui::ModalType CertificateViewerDialog::GetDialogModalType() const { | 244 ui::ModalType CertificateViewerDialog::GetDialogModalType() const { |
246 return ui::MODAL_TYPE_NONE; | 245 return ui::MODAL_TYPE_NONE; |
247 } | 246 } |
248 | 247 |
249 //////////////////////////////////////////////////////////////////////////////// | 248 //////////////////////////////////////////////////////////////////////////////// |
250 // CertificateViewerDialogHandler | 249 // CertificateViewerDialogHandler |
251 | 250 |
252 CertificateViewerDialogHandler::CertificateViewerDialogHandler( | 251 CertificateViewerDialogHandler::CertificateViewerDialogHandler( |
253 CertificateViewerModalDialog* dialog, | 252 CertificateViewerModalDialog* dialog, |
254 net::X509Certificate* cert) : cert_(cert), dialog_(dialog) { | 253 net::X509Certificate* cert) : cert_(cert), dialog_(dialog) { |
255 x509_certificate_model::GetCertChainFromCert(cert_->os_cert_handle(), | 254 x509_certificate_model::GetCertChainFromCert(cert_, &cert_chain_); |
Ryan Sleevi
2014/07/10 02:50:18
Do we really need this method any more? (the x509_
mattm
2014/07/10 22:57:59
Done.
| |
256 &cert_chain_); | |
257 } | 255 } |
258 | 256 |
259 CertificateViewerDialogHandler::~CertificateViewerDialogHandler() { | 257 CertificateViewerDialogHandler::~CertificateViewerDialogHandler() { |
260 } | 258 } |
261 | 259 |
262 void CertificateViewerDialogHandler::RegisterMessages() { | 260 void CertificateViewerDialogHandler::RegisterMessages() { |
263 web_ui()->RegisterMessageCallback("exportCertificate", | 261 web_ui()->RegisterMessageCallback("exportCertificate", |
264 base::Bind(&CertificateViewerDialogHandler::ExportCertificate, | 262 base::Bind(&CertificateViewerDialogHandler::ExportCertificate, |
265 base::Unretained(this))); | 263 base::Unretained(this))); |
266 web_ui()->RegisterMessageCallback("requestCertificateFields", | 264 web_ui()->RegisterMessageCallback("requestCertificateFields", |
267 base::Bind(&CertificateViewerDialogHandler::RequestCertificateFields, | 265 base::Bind(&CertificateViewerDialogHandler::RequestCertificateFields, |
268 base::Unretained(this))); | 266 base::Unretained(this))); |
269 } | 267 } |
270 | 268 |
271 void CertificateViewerDialogHandler::ExportCertificate( | 269 void CertificateViewerDialogHandler::ExportCertificate( |
272 const base::ListValue* args) { | 270 const base::ListValue* args) { |
273 int cert_index = GetCertificateIndex(args); | 271 int cert_index = GetCertificateIndex(args); |
274 if (cert_index < 0) | 272 if (cert_index < 0) |
275 return; | 273 return; |
276 | 274 |
277 NativeWebContentsModalDialog window = | 275 NativeWebContentsModalDialog window = |
278 platform_util::GetTopLevel(dialog_->GetNativeWebContentsModalDialog()); | 276 platform_util::GetTopLevel(dialog_->GetNativeWebContentsModalDialog()); |
279 ShowCertExportDialog(web_ui()->GetWebContents(), | 277 ShowCertExportDialog(web_ui()->GetWebContents(), |
280 window, | 278 window, |
281 cert_chain_[cert_index]); | 279 cert_chain_.begin() + cert_index, |
280 cert_chain_.end()); | |
282 } | 281 } |
283 | 282 |
284 void CertificateViewerDialogHandler::RequestCertificateFields( | 283 void CertificateViewerDialogHandler::RequestCertificateFields( |
285 const base::ListValue* args) { | 284 const base::ListValue* args) { |
286 int cert_index = GetCertificateIndex(args); | 285 int cert_index = GetCertificateIndex(args); |
287 if (cert_index < 0) | 286 if (cert_index < 0) |
288 return; | 287 return; |
289 | 288 |
290 net::X509Certificate::OSCertHandle cert = cert_chain_[cert_index]; | 289 net::X509Certificate::OSCertHandle cert = cert_chain_[cert_index]; |
291 | 290 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
440 const base::ListValue* args) const { | 439 const base::ListValue* args) const { |
441 int cert_index; | 440 int cert_index; |
442 double val; | 441 double val; |
443 if (!(args->GetDouble(0, &val))) | 442 if (!(args->GetDouble(0, &val))) |
444 return -1; | 443 return -1; |
445 cert_index = static_cast<int>(val); | 444 cert_index = static_cast<int>(val); |
446 if (cert_index < 0 || cert_index >= static_cast<int>(cert_chain_.size())) | 445 if (cert_index < 0 || cert_index >= static_cast<int>(cert_chain_.size())) |
447 return -1; | 446 return -1; |
448 return cert_index; | 447 return cert_index; |
449 } | 448 } |
OLD | NEW |