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" |
11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/certificate_viewer.h" | 13 #include "chrome/browser/certificate_viewer.h" |
14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/browser_dialogs.h" | 15 #include "chrome/browser/ui/browser_dialogs.h" |
16 #include "chrome/browser/ui/browser_list.h" | 16 #include "chrome/browser/ui/browser_list.h" |
17 #include "chrome/browser/ui/certificate_dialogs.h" | 17 #include "chrome/browser/ui/certificate_dialogs.h" |
18 #include "chrome/browser/ui/constrained_window.h" | 18 #include "chrome/browser/ui/constrained_window.h" |
19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
20 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" | 20 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" |
| 21 #include "chrome/browser/ui/webui/web_dialog_observer.h" |
21 #include "chrome/common/net/x509_certificate_model.h" | 22 #include "chrome/common/net/x509_certificate_model.h" |
22 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
23 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
24 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
25 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
26 | 27 |
27 using content::WebContents; | 28 using content::WebContents; |
28 using content::WebUIMessageHandler; | 29 using content::WebUIMessageHandler; |
29 | 30 |
30 namespace { | 31 namespace { |
31 | 32 |
32 // Default width/height of the dialog. | 33 // Default width/height of the dialog. |
33 const int kDefaultWidth = 580; | 34 const int kDefaultWidth = 580; |
34 const int kDefaultHeight = 600; | 35 const int kDefaultHeight = 600; |
35 | 36 |
36 } // namespace | 37 } // namespace |
37 | 38 |
38 // Shows a certificate using the WebUI certificate viewer. | 39 // Shows a certificate using the WebUI certificate viewer. |
39 void ShowCertificateViewer(gfx::NativeWindow parent, | 40 void ShowCertificateViewer(gfx::NativeWindow parent, |
40 net::X509Certificate* cert) { | 41 net::X509Certificate* cert) { |
41 CertificateViewerDialog::ShowDialog(parent, cert); | 42 CertificateViewerDialog* dialog = new CertificateViewerDialog(cert); |
| 43 dialog->Show(parent); |
42 } | 44 } |
43 | 45 |
44 //////////////////////////////////////////////////////////////////////////////// | 46 //////////////////////////////////////////////////////////////////////////////// |
45 // CertificateViewerDialog | 47 // CertificateViewerDialog |
46 | 48 |
47 void CertificateViewerDialog::ShowDialog(gfx::NativeWindow parent, | 49 void CertificateViewerDialog::AddObserver(WebDialogObserver* observer) { |
48 net::X509Certificate* cert) { | 50 observers_.AddObserver(observer); |
49 CertificateViewerDialog* dialog = new CertificateViewerDialog(cert); | 51 } |
50 dialog->Show(parent); | 52 |
| 53 void CertificateViewerDialog::RemoveObserver(WebDialogObserver* observer) { |
| 54 observers_.RemoveObserver(observer); |
51 } | 55 } |
52 | 56 |
53 CertificateViewerDialog::CertificateViewerDialog(net::X509Certificate* cert) | 57 CertificateViewerDialog::CertificateViewerDialog(net::X509Certificate* cert) |
54 : cert_(cert), window_(NULL) { | 58 : cert_(cert), window_(NULL) { |
55 // Construct the dialog title from the certificate. | 59 // Construct the dialog title from the certificate. |
56 net::X509Certificate::OSCertHandles cert_chain; | 60 net::X509Certificate::OSCertHandles cert_chain; |
57 x509_certificate_model::GetCertChainFromCert(cert_->os_cert_handle(), | 61 x509_certificate_model::GetCertChainFromCert(cert_->os_cert_handle(), |
58 &cert_chain); | 62 &cert_chain); |
59 title_ = l10n_util::GetStringFUTF16(IDS_CERT_INFO_DIALOG_TITLE, | 63 title_ = l10n_util::GetStringFUTF16(IDS_CERT_INFO_DIALOG_TITLE, |
60 UTF8ToUTF16(x509_certificate_model::GetTitle(cert_chain.front()))); | 64 UTF8ToUTF16(x509_certificate_model::GetTitle(cert_chain.front()))); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 cert_info.Set("hierarchy", children); | 196 cert_info.Set("hierarchy", children); |
193 | 197 |
194 base::JSONWriter::WriteWithOptions( | 198 base::JSONWriter::WriteWithOptions( |
195 &cert_info, | 199 &cert_info, |
196 base::JSONWriter::OPTIONS_DO_NOT_ESCAPE, | 200 base::JSONWriter::OPTIONS_DO_NOT_ESCAPE, |
197 &data); | 201 &data); |
198 | 202 |
199 return data; | 203 return data; |
200 } | 204 } |
201 | 205 |
| 206 void CertificateViewerDialog::OnDialogShown( |
| 207 content::WebUI* webui, |
| 208 content::RenderViewHost* render_view_host) { |
| 209 FOR_EACH_OBSERVER(WebDialogObserver, |
| 210 observers_, |
| 211 OnDialogShown(webui, render_view_host)); |
| 212 } |
| 213 |
202 void CertificateViewerDialog::OnDialogClosed(const std::string& json_retval) { | 214 void CertificateViewerDialog::OnDialogClosed(const std::string& json_retval) { |
203 delete this; | 215 delete this; |
204 } | 216 } |
205 | 217 |
206 void CertificateViewerDialog::OnCloseContents(WebContents* source, | 218 void CertificateViewerDialog::OnCloseContents(WebContents* source, |
207 bool* out_close_dialog) { | 219 bool* out_close_dialog) { |
208 if (out_close_dialog) | 220 if (out_close_dialog) |
209 *out_close_dialog = true; | 221 *out_close_dialog = true; |
210 } | 222 } |
211 | 223 |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 const base::ListValue* args) const { | 411 const base::ListValue* args) const { |
400 int cert_index; | 412 int cert_index; |
401 double val; | 413 double val; |
402 if (!(args->GetDouble(0, &val))) | 414 if (!(args->GetDouble(0, &val))) |
403 return -1; | 415 return -1; |
404 cert_index = static_cast<int>(val); | 416 cert_index = static_cast<int>(val); |
405 if (cert_index < 0 || cert_index >= static_cast<int>(cert_chain_.size())) | 417 if (cert_index < 0 || cert_index >= static_cast<int>(cert_chain_.size())) |
406 return -1; | 418 return -1; |
407 return cert_index; | 419 return cert_index; |
408 } | 420 } |
OLD | NEW |