| 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_tab_helper.h" | 5 #include "chrome/browser/ssl/ssl_tab_helper.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/certificate_viewer.h" | 15 #include "chrome/browser/certificate_viewer.h" |
| 16 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
| 17 #include "chrome/browser/content_settings/host_content_settings_map.h" | 17 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 18 #include "chrome/browser/infobars/confirm_infobar_delegate.h" | 18 #include "chrome/browser/infobars/content_confirm_infobar_delegate.h" |
| 19 #include "chrome/browser/infobars/infobar.h" | 19 #include "chrome/browser/infobars/infobar.h" |
| 20 #include "chrome/browser/infobars/infobar_service.h" | 20 #include "chrome/browser/infobars/infobar_service.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/ssl/ssl_add_cert_handler.h" | 22 #include "chrome/browser/ssl/ssl_add_cert_handler.h" |
| 23 #include "chrome/browser/ssl/ssl_client_certificate_selector.h" | 23 #include "chrome/browser/ssl/ssl_client_certificate_selector.h" |
| 24 #include "chrome/browser/ui/browser_finder.h" | 24 #include "chrome/browser/ui/browser_finder.h" |
| 25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 26 #include "content/public/browser/notification_details.h" | 26 #include "content/public/browser/notification_details.h" |
| 27 #include "content/public/browser/notification_observer.h" | 27 #include "content/public/browser/notification_observer.h" |
| 28 #include "content/public/browser/notification_registrar.h" | 28 #include "content/public/browser/notification_registrar.h" |
| 29 #include "content/public/browser/notification_source.h" | 29 #include "content/public/browser/notification_source.h" |
| 30 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
| 31 #include "content/public/browser/web_contents_view.h" | 31 #include "content/public/browser/web_contents_view.h" |
| 32 #include "grit/generated_resources.h" | 32 #include "grit/generated_resources.h" |
| 33 #include "grit/theme_resources.h" | 33 #include "grit/theme_resources.h" |
| 34 #include "net/base/net_errors.h" | 34 #include "net/base/net_errors.h" |
| 35 #include "net/cert/x509_certificate.h" | 35 #include "net/cert/x509_certificate.h" |
| 36 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
| 37 | 37 |
| 38 | 38 |
| 39 // SSLCertResultInfoBarDelegate ----------------------------------------------- | 39 // SSLCertResultInfoBarDelegate ----------------------------------------------- |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 class SSLCertResultInfoBarDelegate : public ConfirmInfoBarDelegate { | 43 class SSLCertResultInfoBarDelegate : public ContentConfirmInfoBarDelegate { |
| 44 public: | 44 public: |
| 45 // Creates an SSL cert result infobar and delegate. If |previous_infobar| is | 45 // Creates an SSL cert result infobar and delegate. If |previous_infobar| is |
| 46 // NULL, adds the infobar to |infobar_service|; otherwise, replaces | 46 // NULL, adds the infobar to |infobar_service|; otherwise, replaces |
| 47 // |previous_infobar|. Returns the new infobar if it was successfully added. | 47 // |previous_infobar|. Returns the new infobar if it was successfully added. |
| 48 // |cert| is valid iff cert addition was successful. | 48 // |cert| is valid iff cert addition was successful. |
| 49 static InfoBar* Create(InfoBarService* infobar_service, | 49 static InfoBar* Create(InfoBarService* infobar_service, |
| 50 InfoBar* previous_infobar, | 50 InfoBar* previous_infobar, |
| 51 const base::string16& message, | 51 const base::string16& message, |
| 52 net::X509Certificate* cert); | 52 net::X509Certificate* cert); |
| 53 | 53 |
| 54 private: | 54 private: |
| 55 SSLCertResultInfoBarDelegate(const base::string16& message, | 55 SSLCertResultInfoBarDelegate(content::WebContents* web_contents, |
| 56 const base::string16& message, |
| 56 net::X509Certificate* cert); | 57 net::X509Certificate* cert); |
| 57 virtual ~SSLCertResultInfoBarDelegate(); | 58 virtual ~SSLCertResultInfoBarDelegate(); |
| 58 | 59 |
| 59 // ConfirmInfoBarDelegate: | 60 // ConfirmInfoBarDelegate: |
| 60 virtual int GetIconID() const OVERRIDE; | 61 virtual int GetIconID() const OVERRIDE; |
| 61 virtual Type GetInfoBarType() const OVERRIDE; | 62 virtual Type GetInfoBarType() const OVERRIDE; |
| 62 virtual base::string16 GetMessageText() const OVERRIDE; | 63 virtual base::string16 GetMessageText() const OVERRIDE; |
| 63 virtual int GetButtons() const OVERRIDE; | 64 virtual int GetButtons() const OVERRIDE; |
| 64 virtual base::string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | 65 virtual base::string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
| 65 virtual bool Accept() OVERRIDE; | 66 virtual bool Accept() OVERRIDE; |
| 66 | 67 |
| 67 base::string16 message_; | 68 base::string16 message_; |
| 68 scoped_refptr<net::X509Certificate> cert_; // The cert we added, if any. | 69 scoped_refptr<net::X509Certificate> cert_; // The cert we added, if any. |
| 69 | 70 |
| 70 DISALLOW_COPY_AND_ASSIGN(SSLCertResultInfoBarDelegate); | 71 DISALLOW_COPY_AND_ASSIGN(SSLCertResultInfoBarDelegate); |
| 71 }; | 72 }; |
| 72 | 73 |
| 73 // static | 74 // static |
| 74 InfoBar* SSLCertResultInfoBarDelegate::Create(InfoBarService* infobar_service, | 75 InfoBar* SSLCertResultInfoBarDelegate::Create(InfoBarService* infobar_service, |
| 75 InfoBar* previous_infobar, | 76 InfoBar* previous_infobar, |
| 76 const base::string16& message, | 77 const base::string16& message, |
| 77 net::X509Certificate* cert) { | 78 net::X509Certificate* cert) { |
| 78 scoped_ptr<InfoBar> infobar(ConfirmInfoBarDelegate::CreateInfoBar( | 79 scoped_ptr<InfoBar> infobar(ConfirmInfoBarDelegate::CreateInfoBar( |
| 79 scoped_ptr<ConfirmInfoBarDelegate>( | 80 scoped_ptr<ConfirmInfoBarDelegate>(new SSLCertResultInfoBarDelegate( |
| 80 new SSLCertResultInfoBarDelegate(message, cert)))); | 81 infobar_service->web_contents(), message, cert)))); |
| 81 return previous_infobar ? | 82 return previous_infobar ? |
| 82 infobar_service->ReplaceInfoBar(previous_infobar, infobar.Pass()) : | 83 infobar_service->ReplaceInfoBar(previous_infobar, infobar.Pass()) : |
| 83 infobar_service->AddInfoBar(infobar.Pass()); | 84 infobar_service->AddInfoBar(infobar.Pass()); |
| 84 } | 85 } |
| 85 | 86 |
| 86 SSLCertResultInfoBarDelegate::SSLCertResultInfoBarDelegate( | 87 SSLCertResultInfoBarDelegate::SSLCertResultInfoBarDelegate( |
| 88 content::WebContents* web_contents, |
| 87 const base::string16& message, | 89 const base::string16& message, |
| 88 net::X509Certificate* cert) | 90 net::X509Certificate* cert) |
| 89 : ConfirmInfoBarDelegate(), | 91 : ContentConfirmInfoBarDelegate(web_contents), |
| 90 message_(message), | 92 message_(message), |
| 91 cert_(cert) { | 93 cert_(cert) {} |
| 92 } | |
| 93 | 94 |
| 94 SSLCertResultInfoBarDelegate::~SSLCertResultInfoBarDelegate() { | 95 SSLCertResultInfoBarDelegate::~SSLCertResultInfoBarDelegate() { |
| 95 } | 96 } |
| 96 | 97 |
| 97 int SSLCertResultInfoBarDelegate::GetIconID() const { | 98 int SSLCertResultInfoBarDelegate::GetIconID() const { |
| 98 // TODO(davidben): use a more appropriate icon. | 99 // TODO(davidben): use a more appropriate icon. |
| 99 return IDR_INFOBAR_SAVE_PASSWORD; | 100 return IDR_INFOBAR_SAVE_PASSWORD; |
| 100 } | 101 } |
| 101 | 102 |
| 102 InfoBarDelegate::Type SSLCertResultInfoBarDelegate::GetInfoBarType() const { | 103 InfoBarDelegate::Type SSLCertResultInfoBarDelegate::GetInfoBarType() const { |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 // Find/create the slot. | 264 // Find/create the slot. |
| 264 linked_ptr<SSLAddCertData>& ptr_ref = | 265 linked_ptr<SSLAddCertData>& ptr_ref = |
| 265 request_id_to_add_cert_data_[handler->network_request_id()]; | 266 request_id_to_add_cert_data_[handler->network_request_id()]; |
| 266 // Fill it if necessary. | 267 // Fill it if necessary. |
| 267 if (!ptr_ref.get()) { | 268 if (!ptr_ref.get()) { |
| 268 ptr_ref.reset( | 269 ptr_ref.reset( |
| 269 new SSLAddCertData(InfoBarService::FromWebContents(web_contents_))); | 270 new SSLAddCertData(InfoBarService::FromWebContents(web_contents_))); |
| 270 } | 271 } |
| 271 return ptr_ref.get(); | 272 return ptr_ref.get(); |
| 272 } | 273 } |
| OLD | NEW |