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" |
11 #include "chrome/browser/infobars/infobar_service.h" | 11 #include "chrome/browser/infobars/infobar_service.h" |
12 #include "chrome/grit/generated_resources.h" | 12 #include "chrome/grit/generated_resources.h" |
13 #include "components/infobars/core/confirm_infobar_delegate.h" | 13 #include "components/infobars/core/confirm_infobar_delegate.h" |
14 #include "components/infobars/core/infobar.h" | 14 #include "components/infobars/core/infobar.h" |
15 #include "components/infobars/core/simple_alert_infobar_delegate.h" | 15 #include "components/infobars/core/simple_alert_infobar_delegate.h" |
16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/browser/render_frame_host.h" | 17 #include "content/public/browser/render_frame_host.h" |
18 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
19 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
20 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
21 #include "net/cert/cert_database.h" | 21 #include "net/cert/cert_database.h" |
22 #include "net/cert/x509_certificate.h" | 22 #include "net/cert/x509_certificate.h" |
23 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 24 #include "ui/gfx/vector_icons_public.h" |
24 | 25 |
25 using content::BrowserThread; | 26 using content::BrowserThread; |
26 using content::RenderFrameHost; | 27 using content::RenderFrameHost; |
27 using content::WebContents; | 28 using content::WebContents; |
28 | 29 |
29 namespace chrome { | 30 namespace chrome { |
30 | 31 |
31 namespace { | 32 namespace { |
32 | 33 |
33 class SSLAddCertificateInfoBarDelegate : public ConfirmInfoBarDelegate { | 34 class SSLAddCertificateInfoBarDelegate : public ConfirmInfoBarDelegate { |
34 public: | 35 public: |
35 // Creates an SSL certificate enrollment result infobar and delegate and adds | 36 // Creates an SSL certificate enrollment result infobar and delegate and adds |
36 // the infobar to |infobar_service|. | 37 // the infobar to |infobar_service|. |
37 static void Create(InfoBarService* infobar_service, | 38 static void Create(InfoBarService* infobar_service, |
38 net::X509Certificate* cert); | 39 net::X509Certificate* cert); |
39 | 40 |
40 private: | 41 private: |
41 explicit SSLAddCertificateInfoBarDelegate(net::X509Certificate* cert); | 42 explicit SSLAddCertificateInfoBarDelegate(net::X509Certificate* cert); |
42 ~SSLAddCertificateInfoBarDelegate() override; | 43 ~SSLAddCertificateInfoBarDelegate() override; |
43 | 44 |
44 // ConfirmInfoBarDelegate: | 45 // ConfirmInfoBarDelegate: |
45 Type GetInfoBarType() const override; | 46 Type GetInfoBarType() const override; |
46 int GetIconId() const override; | 47 int GetIconId() const override; |
| 48 gfx::VectorIconId GetVectorIconId() const override; |
47 base::string16 GetMessageText() const override; | 49 base::string16 GetMessageText() const override; |
48 int GetButtons() const override; | 50 int GetButtons() const override; |
49 base::string16 GetButtonLabel(InfoBarButton button) const override; | 51 base::string16 GetButtonLabel(InfoBarButton button) const override; |
50 bool Accept() override; | 52 bool Accept() override; |
51 | 53 |
52 // The certificate that was added. | 54 // The certificate that was added. |
53 scoped_refptr<net::X509Certificate> cert_; | 55 scoped_refptr<net::X509Certificate> cert_; |
54 | 56 |
55 DISALLOW_COPY_AND_ASSIGN(SSLAddCertificateInfoBarDelegate); | 57 DISALLOW_COPY_AND_ASSIGN(SSLAddCertificateInfoBarDelegate); |
56 }; | 58 }; |
(...skipping 17 matching lines...) Expand all Loading... |
74 infobars::InfoBarDelegate::Type | 76 infobars::InfoBarDelegate::Type |
75 SSLAddCertificateInfoBarDelegate::GetInfoBarType() const { | 77 SSLAddCertificateInfoBarDelegate::GetInfoBarType() const { |
76 return PAGE_ACTION_TYPE; | 78 return PAGE_ACTION_TYPE; |
77 } | 79 } |
78 | 80 |
79 int SSLAddCertificateInfoBarDelegate::GetIconId() const { | 81 int SSLAddCertificateInfoBarDelegate::GetIconId() const { |
80 // TODO(davidben): Use a more appropriate icon. | 82 // TODO(davidben): Use a more appropriate icon. |
81 return IDR_INFOBAR_SAVE_PASSWORD; | 83 return IDR_INFOBAR_SAVE_PASSWORD; |
82 } | 84 } |
83 | 85 |
| 86 gfx::VectorIconId SSLAddCertificateInfoBarDelegate::GetVectorIconId() const { |
| 87 #if !defined(OS_MACOSX) |
| 88 return gfx::VectorIconId::AUTOLOGIN; |
| 89 #else |
| 90 return gfx::VectorIconId::VECTOR_ICON_NONE; |
| 91 #endif |
| 92 } |
| 93 |
84 base::string16 SSLAddCertificateInfoBarDelegate::GetMessageText() const { | 94 base::string16 SSLAddCertificateInfoBarDelegate::GetMessageText() const { |
85 // TODO(evanm): GetDisplayName should return UTF-16. | 95 // TODO(evanm): GetDisplayName should return UTF-16. |
86 return l10n_util::GetStringFUTF16(IDS_ADD_CERT_SUCCESS_INFOBAR_LABEL, | 96 return l10n_util::GetStringFUTF16(IDS_ADD_CERT_SUCCESS_INFOBAR_LABEL, |
87 base::UTF8ToUTF16( | 97 base::UTF8ToUTF16( |
88 cert_->issuer().GetDisplayName())); | 98 cert_->issuer().GetDisplayName())); |
89 } | 99 } |
90 | 100 |
91 int SSLAddCertificateInfoBarDelegate::GetButtons() const { | 101 int SSLAddCertificateInfoBarDelegate::GetButtons() const { |
92 return BUTTON_OK; | 102 return BUTTON_OK; |
93 } | 103 } |
(...skipping 19 matching lines...) Expand all Loading... |
113 int render_frame_id, | 123 int render_frame_id, |
114 int cert_error) { | 124 int cert_error) { |
115 WebContents* web_contents = WebContents::FromRenderFrameHost( | 125 WebContents* web_contents = WebContents::FromRenderFrameHost( |
116 RenderFrameHost::FromID(render_process_id, render_frame_id)); | 126 RenderFrameHost::FromID(render_process_id, render_frame_id)); |
117 if (!web_contents) | 127 if (!web_contents) |
118 return; | 128 return; |
119 | 129 |
120 // TODO(davidben): Use a more appropriate icon. | 130 // TODO(davidben): Use a more appropriate icon. |
121 // TODO(davidben): Display a more user-friendly error string. | 131 // TODO(davidben): Display a more user-friendly error string. |
122 SimpleAlertInfoBarDelegate::Create( | 132 SimpleAlertInfoBarDelegate::Create( |
123 InfoBarService::FromWebContents(web_contents), | 133 InfoBarService::FromWebContents(web_contents), IDR_INFOBAR_SAVE_PASSWORD, |
124 IDR_INFOBAR_SAVE_PASSWORD, | 134 #if !defined(OS_MACOSX) |
125 l10n_util::GetStringFUTF16(IDS_ADD_CERT_ERR_INVALID_CERT, | 135 gfx::VectorIconId::AUTOLOGIN, |
126 base::IntToString16(-cert_error), | 136 #else |
127 base::ASCIIToUTF16( | 137 gfx::VectorIconId::VECTOR_ICON_NONE, |
128 net::ErrorToString(cert_error))), | 138 #endif |
| 139 l10n_util::GetStringFUTF16( |
| 140 IDS_ADD_CERT_ERR_INVALID_CERT, base::IntToString16(-cert_error), |
| 141 base::ASCIIToUTF16(net::ErrorToString(cert_error))), |
129 true); | 142 true); |
130 } | 143 } |
131 | 144 |
132 void ShowSuccessInfoBar(int render_process_id, | 145 void ShowSuccessInfoBar(int render_process_id, |
133 int render_frame_id, | 146 int render_frame_id, |
134 net::X509Certificate* cert) { | 147 net::X509Certificate* cert) { |
135 WebContents* web_contents = WebContents::FromRenderFrameHost( | 148 WebContents* web_contents = WebContents::FromRenderFrameHost( |
136 RenderFrameHost::FromID(render_process_id, render_frame_id)); | 149 RenderFrameHost::FromID(render_process_id, render_frame_id)); |
137 if (!web_contents) | 150 if (!web_contents) |
138 return; | 151 return; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 render_process_id, render_frame_id, cert_error)); | 201 render_process_id, render_frame_id, cert_error)); |
189 } else { | 202 } else { |
190 BrowserThread::PostTask( | 203 BrowserThread::PostTask( |
191 BrowserThread::UI, FROM_HERE, | 204 BrowserThread::UI, FROM_HERE, |
192 base::Bind(&ShowSuccessInfoBar, | 205 base::Bind(&ShowSuccessInfoBar, |
193 render_process_id, render_frame_id, cert)); | 206 render_process_id, render_frame_id, cert)); |
194 } | 207 } |
195 } | 208 } |
196 | 209 |
197 } // namespace chrome | 210 } // namespace chrome |
OLD | NEW |