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/ssl/ssl_add_certificate.h" | 5 #include "chrome/browser/ssl/ssl_add_certificate.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/certificate_viewer.h" | 10 #include "chrome/browser/certificate_viewer.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 using content::BrowserThread; | 25 using content::BrowserThread; |
26 using content::RenderFrameHost; | 26 using content::RenderFrameHost; |
27 using content::WebContents; | 27 using content::WebContents; |
28 | 28 |
29 namespace chrome { | 29 namespace chrome { |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
33 class SSLAddCertificateInfoBarDelegate : public ConfirmInfoBarDelegate { | 33 class SSLAddCertificateInfoBarDelegate : public ConfirmInfoBarDelegate { |
34 public: | 34 public: |
35 // Creates an SSL certificate enrollment result infobar and delegate. | 35 // Creates an SSL certificate enrollment result infobar and delegate and adds |
| 36 // the infobar to |infobar_service|. |
36 static void Create(InfoBarService* infobar_service, | 37 static void Create(InfoBarService* infobar_service, |
37 net::X509Certificate* cert) { | 38 net::X509Certificate* cert); |
38 infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( | |
39 scoped_ptr<ConfirmInfoBarDelegate>( | |
40 new SSLAddCertificateInfoBarDelegate(cert)))); | |
41 } | |
42 | 39 |
43 private: | 40 private: |
44 explicit SSLAddCertificateInfoBarDelegate(net::X509Certificate* cert) | 41 explicit SSLAddCertificateInfoBarDelegate(net::X509Certificate* cert); |
45 : cert_(cert) {} | 42 ~SSLAddCertificateInfoBarDelegate() override; |
46 ~SSLAddCertificateInfoBarDelegate() override {} | |
47 | 43 |
48 // ConfirmInfoBarDelegate implementation: | 44 // ConfirmInfoBarDelegate: |
49 int GetIconID() const override { | 45 Type GetInfoBarType() const override; |
50 // TODO(davidben): Use a more appropriate icon. | 46 int GetIconID() const override; |
51 return IDR_INFOBAR_SAVE_PASSWORD; | 47 base::string16 GetMessageText() const override; |
52 } | 48 int GetButtons() const override; |
53 | 49 base::string16 GetButtonLabel(InfoBarButton button) const override; |
54 Type GetInfoBarType() const override { return PAGE_ACTION_TYPE; } | 50 bool Accept() override; |
55 | |
56 base::string16 GetMessageText() const override { | |
57 // TODO(evanm): GetDisplayName should return UTF-16. | |
58 return l10n_util::GetStringFUTF16(IDS_ADD_CERT_SUCCESS_INFOBAR_LABEL, | |
59 base::UTF8ToUTF16( | |
60 cert_->issuer().GetDisplayName())); | |
61 } | |
62 | |
63 int GetButtons() const override { return BUTTON_OK; } | |
64 | |
65 base::string16 GetButtonLabel(InfoBarButton button) const override { | |
66 DCHECK_EQ(BUTTON_OK, button); | |
67 return l10n_util::GetStringUTF16(IDS_ADD_CERT_SUCCESS_INFOBAR_BUTTON); | |
68 } | |
69 | |
70 bool Accept() override { | |
71 WebContents* web_contents = | |
72 InfoBarService::WebContentsFromInfoBar(infobar()); | |
73 ShowCertificateViewer(web_contents, | |
74 web_contents->GetTopLevelNativeWindow(), | |
75 cert_.get()); | |
76 // It looks weird to hide the infobar just as the dialog opens. | |
77 return false; | |
78 } | |
79 | 51 |
80 // The certificate that was added. | 52 // The certificate that was added. |
81 scoped_refptr<net::X509Certificate> cert_; | 53 scoped_refptr<net::X509Certificate> cert_; |
82 | 54 |
83 DISALLOW_COPY_AND_ASSIGN(SSLAddCertificateInfoBarDelegate); | 55 DISALLOW_COPY_AND_ASSIGN(SSLAddCertificateInfoBarDelegate); |
84 }; | 56 }; |
85 | 57 |
| 58 // static |
| 59 void SSLAddCertificateInfoBarDelegate::Create(InfoBarService* infobar_service, |
| 60 net::X509Certificate* cert) { |
| 61 infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( |
| 62 scoped_ptr<ConfirmInfoBarDelegate>( |
| 63 new SSLAddCertificateInfoBarDelegate(cert)))); |
| 64 } |
| 65 |
| 66 SSLAddCertificateInfoBarDelegate::SSLAddCertificateInfoBarDelegate( |
| 67 net::X509Certificate* cert) |
| 68 : cert_(cert) { |
| 69 } |
| 70 |
| 71 SSLAddCertificateInfoBarDelegate::~SSLAddCertificateInfoBarDelegate() { |
| 72 } |
| 73 |
| 74 infobars::InfoBarDelegate::Type |
| 75 SSLAddCertificateInfoBarDelegate::GetInfoBarType() const { |
| 76 return PAGE_ACTION_TYPE; |
| 77 } |
| 78 |
| 79 int SSLAddCertificateInfoBarDelegate::GetIconID() const { |
| 80 // TODO(davidben): Use a more appropriate icon. |
| 81 return IDR_INFOBAR_SAVE_PASSWORD; |
| 82 } |
| 83 |
| 84 base::string16 SSLAddCertificateInfoBarDelegate::GetMessageText() const { |
| 85 // TODO(evanm): GetDisplayName should return UTF-16. |
| 86 return l10n_util::GetStringFUTF16(IDS_ADD_CERT_SUCCESS_INFOBAR_LABEL, |
| 87 base::UTF8ToUTF16( |
| 88 cert_->issuer().GetDisplayName())); |
| 89 } |
| 90 |
| 91 int SSLAddCertificateInfoBarDelegate::GetButtons() const { |
| 92 return BUTTON_OK; |
| 93 } |
| 94 |
| 95 base::string16 SSLAddCertificateInfoBarDelegate::GetButtonLabel( |
| 96 InfoBarButton button) const { |
| 97 DCHECK_EQ(BUTTON_OK, button); |
| 98 return l10n_util::GetStringUTF16(IDS_ADD_CERT_SUCCESS_INFOBAR_BUTTON); |
| 99 } |
| 100 |
| 101 bool SSLAddCertificateInfoBarDelegate::Accept() { |
| 102 WebContents* web_contents = |
| 103 InfoBarService::WebContentsFromInfoBar(infobar()); |
| 104 ShowCertificateViewer(web_contents, |
| 105 web_contents->GetTopLevelNativeWindow(), |
| 106 cert_.get()); |
| 107 // It looks weird to hide the infobar just as the dialog opens. |
| 108 return false; |
| 109 } |
| 110 |
86 void ShowErrorInfoBar(int message_id, | 111 void ShowErrorInfoBar(int message_id, |
87 int render_process_id, | 112 int render_process_id, |
88 int render_frame_id, | 113 int render_frame_id, |
89 int cert_error) { | 114 int cert_error) { |
90 WebContents* web_contents = WebContents::FromRenderFrameHost( | 115 WebContents* web_contents = WebContents::FromRenderFrameHost( |
91 RenderFrameHost::FromID(render_process_id, render_frame_id)); | 116 RenderFrameHost::FromID(render_process_id, render_frame_id)); |
92 if (!web_contents) | 117 if (!web_contents) |
93 return; | 118 return; |
94 | 119 |
95 // TODO(davidben): Use a more appropriate icon. | 120 // TODO(davidben): Use a more appropriate icon. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 render_process_id, render_frame_id, cert_error)); | 188 render_process_id, render_frame_id, cert_error)); |
164 } else { | 189 } else { |
165 BrowserThread::PostTask( | 190 BrowserThread::PostTask( |
166 BrowserThread::UI, FROM_HERE, | 191 BrowserThread::UI, FROM_HERE, |
167 base::Bind(&ShowSuccessInfoBar, | 192 base::Bind(&ShowSuccessInfoBar, |
168 render_process_id, render_frame_id, cert)); | 193 render_process_id, render_frame_id, cert)); |
169 } | 194 } |
170 } | 195 } |
171 | 196 |
172 } // namespace chrome | 197 } // namespace chrome |
OLD | NEW |