| 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 cert_chain.push_back(cert_->os_cert_handle()); |
| 106 const net::X509Certificate::OSCertHandles& certs = |
| 107 cert_->GetIntermediateCertificates(); |
| 108 cert_chain.insert(cert_chain.end(), certs.begin(), certs.end()); |
| 107 | 109 |
| 108 // Certificate usage. | 110 // Certificate usage. |
| 109 std::vector<std::string> usages; | 111 std::vector<std::string> usages; |
| 110 x509_certificate_model::GetUsageStrings(cert_hnd, &usages); | 112 x509_certificate_model::GetUsageStrings(cert_hnd, &usages); |
| 111 std::string usagestr; | 113 std::string usagestr; |
| 112 for (std::vector<std::string>::iterator it = usages.begin(); | 114 for (std::vector<std::string>::iterator it = usages.begin(); |
| 113 it != usages.end(); ++it) { | 115 it != usages.end(); ++it) { |
| 114 if (usagestr.length() > 0) { | 116 if (usagestr.length() > 0) { |
| 115 usagestr += "\n"; | 117 usagestr += "\n"; |
| 116 } | 118 } |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 | 246 |
| 245 ui::ModalType CertificateViewerDialog::GetDialogModalType() const { | 247 ui::ModalType CertificateViewerDialog::GetDialogModalType() const { |
| 246 return ui::MODAL_TYPE_NONE; | 248 return ui::MODAL_TYPE_NONE; |
| 247 } | 249 } |
| 248 | 250 |
| 249 //////////////////////////////////////////////////////////////////////////////// | 251 //////////////////////////////////////////////////////////////////////////////// |
| 250 // CertificateViewerDialogHandler | 252 // CertificateViewerDialogHandler |
| 251 | 253 |
| 252 CertificateViewerDialogHandler::CertificateViewerDialogHandler( | 254 CertificateViewerDialogHandler::CertificateViewerDialogHandler( |
| 253 CertificateViewerModalDialog* dialog, | 255 CertificateViewerModalDialog* dialog, |
| 254 net::X509Certificate* cert) : cert_(cert), dialog_(dialog) { | 256 net::X509Certificate* cert) |
| 255 x509_certificate_model::GetCertChainFromCert(cert_->os_cert_handle(), | 257 : cert_(cert), dialog_(dialog) { |
| 256 &cert_chain_); | 258 cert_chain_.push_back(cert_->os_cert_handle()); |
| 259 const net::X509Certificate::OSCertHandles& certs = |
| 260 cert_->GetIntermediateCertificates(); |
| 261 cert_chain_.insert(cert_chain_.end(), certs.begin(), certs.end()); |
| 257 } | 262 } |
| 258 | 263 |
| 259 CertificateViewerDialogHandler::~CertificateViewerDialogHandler() { | 264 CertificateViewerDialogHandler::~CertificateViewerDialogHandler() { |
| 260 } | 265 } |
| 261 | 266 |
| 262 void CertificateViewerDialogHandler::RegisterMessages() { | 267 void CertificateViewerDialogHandler::RegisterMessages() { |
| 263 web_ui()->RegisterMessageCallback("exportCertificate", | 268 web_ui()->RegisterMessageCallback("exportCertificate", |
| 264 base::Bind(&CertificateViewerDialogHandler::ExportCertificate, | 269 base::Bind(&CertificateViewerDialogHandler::ExportCertificate, |
| 265 base::Unretained(this))); | 270 base::Unretained(this))); |
| 266 web_ui()->RegisterMessageCallback("requestCertificateFields", | 271 web_ui()->RegisterMessageCallback("requestCertificateFields", |
| 267 base::Bind(&CertificateViewerDialogHandler::RequestCertificateFields, | 272 base::Bind(&CertificateViewerDialogHandler::RequestCertificateFields, |
| 268 base::Unretained(this))); | 273 base::Unretained(this))); |
| 269 } | 274 } |
| 270 | 275 |
| 271 void CertificateViewerDialogHandler::ExportCertificate( | 276 void CertificateViewerDialogHandler::ExportCertificate( |
| 272 const base::ListValue* args) { | 277 const base::ListValue* args) { |
| 273 int cert_index = GetCertificateIndex(args); | 278 int cert_index = GetCertificateIndex(args); |
| 274 if (cert_index < 0) | 279 if (cert_index < 0) |
| 275 return; | 280 return; |
| 276 | 281 |
| 277 NativeWebContentsModalDialog window = | 282 NativeWebContentsModalDialog window = |
| 278 platform_util::GetTopLevel(dialog_->GetNativeWebContentsModalDialog()); | 283 platform_util::GetTopLevel(dialog_->GetNativeWebContentsModalDialog()); |
| 279 ShowCertExportDialog(web_ui()->GetWebContents(), | 284 ShowCertExportDialog(web_ui()->GetWebContents(), |
| 280 window, | 285 window, |
| 281 cert_chain_[cert_index]); | 286 cert_chain_.begin() + cert_index, |
| 287 cert_chain_.end()); |
| 282 } | 288 } |
| 283 | 289 |
| 284 void CertificateViewerDialogHandler::RequestCertificateFields( | 290 void CertificateViewerDialogHandler::RequestCertificateFields( |
| 285 const base::ListValue* args) { | 291 const base::ListValue* args) { |
| 286 int cert_index = GetCertificateIndex(args); | 292 int cert_index = GetCertificateIndex(args); |
| 287 if (cert_index < 0) | 293 if (cert_index < 0) |
| 288 return; | 294 return; |
| 289 | 295 |
| 290 net::X509Certificate::OSCertHandle cert = cert_chain_[cert_index]; | 296 net::X509Certificate::OSCertHandle cert = cert_chain_[cert_index]; |
| 291 | 297 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 const base::ListValue* args) const { | 446 const base::ListValue* args) const { |
| 441 int cert_index; | 447 int cert_index; |
| 442 double val; | 448 double val; |
| 443 if (!(args->GetDouble(0, &val))) | 449 if (!(args->GetDouble(0, &val))) |
| 444 return -1; | 450 return -1; |
| 445 cert_index = static_cast<int>(val); | 451 cert_index = static_cast<int>(val); |
| 446 if (cert_index < 0 || cert_index >= static_cast<int>(cert_chain_.size())) | 452 if (cert_index < 0 || cert_index >= static_cast<int>(cert_chain_.size())) |
| 447 return -1; | 453 return -1; |
| 448 return cert_index; | 454 return cert_index; |
| 449 } | 455 } |
| OLD | NEW |