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 "base/i18n/time_formatting.h" | 5 #include "base/i18n/time_formatting.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
8 #include "chrome/browser/ui/webui/certificate_viewer.h" | 8 #include "chrome/browser/certificate_viewer.h" |
9 #include "chrome/common/url_constants.h" | |
10 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_dialogs.h" |
11 #include "chrome/browser/ui/browser_list.h" | 11 #include "chrome/browser/ui/browser_list.h" |
12 #include "chrome/browser/ui/gtk/certificate_dialogs.h" | 12 #include "chrome/browser/ui/gtk/certificate_dialogs.h" |
13 #include "chrome/browser/ui/browser_dialogs.h" | 13 #include "chrome/browser/ui/webui/certificate_viewer.h" |
| 14 #include "chrome/browser/ui/webui/chrome_web_ui.h" |
14 #include "chrome/common/net/x509_certificate_model.h" | 15 #include "chrome/common/net/x509_certificate_model.h" |
| 16 #include "chrome/common/url_constants.h" |
15 #include "content/browser/tab_contents/tab_contents.h" | 17 #include "content/browser/tab_contents/tab_contents.h" |
16 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
17 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
18 | 20 |
19 namespace { | 21 namespace { |
20 | 22 |
21 // Default width/height of the dialog. | 23 // Default width/height of the dialog. |
22 const int kDefaultWidth = 450; | 24 const int kDefaultWidth = 450; |
23 const int kDefaultHeight = 450; | 25 const int kDefaultHeight = 450; |
24 | 26 |
25 } // namespace | 27 } // namespace |
26 | 28 |
27 // Shows a certificate using the WebUI certificate viewer. | 29 // Shows a certificate using the native or WebUI certificate viewer. |
28 void ShowCertificateViewer(gfx::NativeWindow parent, | 30 void ShowCertificateViewer(gfx::NativeWindow parent, |
29 net::X509Certificate* cert) { | 31 net::X509Certificate* cert) { |
30 CertificateViewerDialog::ShowDialog(parent, cert); | 32 if (ChromeWebUI::IsMoreWebUI()) { |
| 33 CertificateViewerDialog::ShowDialog(parent, cert); |
| 34 } else { |
| 35 ShowNativeCertificateViewer(parent, cert); |
| 36 } |
31 } | 37 } |
32 | 38 |
33 //////////////////////////////////////////////////////////////////////////////// | 39 //////////////////////////////////////////////////////////////////////////////// |
34 // CertificateViewerDialog | 40 // CertificateViewerDialog |
35 | 41 |
36 void CertificateViewerDialog::ShowDialog(gfx::NativeWindow parent, | 42 void CertificateViewerDialog::ShowDialog(gfx::NativeWindow parent, |
37 net::X509Certificate* cert) { | 43 net::X509Certificate* cert) { |
38 Browser* browser = BrowserList::GetLastActive(); | 44 Browser* browser = BrowserList::GetLastActive(); |
39 DCHECK(browser); | 45 DCHECK(browser); |
40 browser->BrowserShowHtmlDialog(new CertificateViewerDialog(parent, cert), | 46 browser->BrowserShowHtmlDialog(new CertificateViewerDialog(parent, cert), |
41 parent); | 47 parent); |
42 } | 48 } |
43 | 49 |
44 CertificateViewerDialog::CertificateViewerDialog(gfx::NativeWindow parent, | 50 CertificateViewerDialog::CertificateViewerDialog(gfx::NativeWindow parent, |
45 net::X509Certificate* cert) | 51 net::X509Certificate* cert) |
46 : cert_(cert), parent_(parent) { | 52 : cert_(cert), parent_(parent) { |
47 // Construct the dialog title from the certificate. | 53 // Construct the dialog title from the certificate. |
48 net::X509Certificate::OSCertHandles cert_chain; | 54 net::X509Certificate::OSCertHandles cert_chain; |
49 x509_certificate_model::GetCertChainFromCert(cert_->os_cert_handle(), | 55 x509_certificate_model::GetCertChainFromCert(cert_->os_cert_handle(), |
50 &cert_chain); | 56 &cert_chain); |
51 title_ = l10n_util::GetStringFUTF16(IDS_CERT_INFO_DIALOG_TITLE, | 57 title_ = l10n_util::GetStringFUTF16(IDS_CERT_INFO_DIALOG_TITLE, |
52 UTF8ToUTF16(x509_certificate_model::GetTitle(cert_chain.front()))); | 58 UTF8ToUTF16(x509_certificate_model::GetTitle(cert_chain.front()))); |
53 } | 59 } |
54 | 60 |
| 61 CertificateViewerDialog::~CertificateViewerDialog() { |
| 62 } |
| 63 |
55 bool CertificateViewerDialog::IsDialogModal() const { | 64 bool CertificateViewerDialog::IsDialogModal() const { |
56 return true; | 65 return true; |
57 } | 66 } |
58 | 67 |
59 string16 CertificateViewerDialog::GetDialogTitle() const { | 68 string16 CertificateViewerDialog::GetDialogTitle() const { |
60 return title_; | 69 return title_; |
61 } | 70 } |
62 | 71 |
63 GURL CertificateViewerDialog::GetDialogContentURL() const { | 72 GURL CertificateViewerDialog::GetDialogContentURL() const { |
64 return GURL(chrome::kChromeUICertificateViewerURL); | 73 return GURL(chrome::kChromeUICertificateViewerURL); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 //////////////////////////////////////////////////////////////////////////////// | 108 //////////////////////////////////////////////////////////////////////////////// |
100 // CertificateViewerDialogHandler | 109 // CertificateViewerDialogHandler |
101 | 110 |
102 CertificateViewerDialogHandler::CertificateViewerDialogHandler( | 111 CertificateViewerDialogHandler::CertificateViewerDialogHandler( |
103 gfx::NativeWindow parent, | 112 gfx::NativeWindow parent, |
104 net::X509Certificate* cert) : cert_(cert), parent_(parent) { | 113 net::X509Certificate* cert) : cert_(cert), parent_(parent) { |
105 x509_certificate_model::GetCertChainFromCert(cert_->os_cert_handle(), | 114 x509_certificate_model::GetCertChainFromCert(cert_->os_cert_handle(), |
106 &cert_chain_); | 115 &cert_chain_); |
107 } | 116 } |
108 | 117 |
| 118 CertificateViewerDialogHandler::~CertificateViewerDialogHandler() { |
| 119 } |
| 120 |
109 void CertificateViewerDialogHandler::RegisterMessages() { | 121 void CertificateViewerDialogHandler::RegisterMessages() { |
110 web_ui_->RegisterMessageCallback("exportCertificate", | 122 web_ui_->RegisterMessageCallback("exportCertificate", |
111 NewCallback(this, | 123 NewCallback(this, |
112 &CertificateViewerDialogHandler::ExportCertificate)); | 124 &CertificateViewerDialogHandler::ExportCertificate)); |
113 web_ui_->RegisterMessageCallback("requestCertificateInfo", | 125 web_ui_->RegisterMessageCallback("requestCertificateInfo", |
114 NewCallback(this, | 126 NewCallback(this, |
115 &CertificateViewerDialogHandler::RequestCertificateInfo)); | 127 &CertificateViewerDialogHandler::RequestCertificateInfo)); |
116 web_ui_->RegisterMessageCallback("requestCertificateFields", | 128 web_ui_->RegisterMessageCallback("requestCertificateFields", |
117 NewCallback(this, | 129 NewCallback(this, |
118 &CertificateViewerDialogHandler::RequestCertificateFields)); | 130 &CertificateViewerDialogHandler::RequestCertificateFields)); |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 cert_sub_fields->Append(node_details = new DictionaryValue()); | 389 cert_sub_fields->Append(node_details = new DictionaryValue()); |
378 node_details->SetString("label", | 390 node_details->SetString("label", |
379 l10n_util::GetStringUTF8(IDS_CERT_INFO_SHA1_FINGERPRINT_LABEL)); | 391 l10n_util::GetStringUTF8(IDS_CERT_INFO_SHA1_FINGERPRINT_LABEL)); |
380 node_details->SetString("payload.val", | 392 node_details->SetString("payload.val", |
381 x509_certificate_model::HashCertSHA1(cert)); | 393 x509_certificate_model::HashCertSHA1(cert)); |
382 | 394 |
383 // Send certificate information to javascript. | 395 // Send certificate information to javascript. |
384 web_ui_->CallJavascriptFunction("cert_viewer.getCertificateFields", | 396 web_ui_->CallJavascriptFunction("cert_viewer.getCertificateFields", |
385 root_list); | 397 root_list); |
386 } | 398 } |
OLD | NEW |