Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4244)

Unified Diff: chrome/browser/ssl/ssl_tab_helper.cc

Issue 11644059: Change infobar creation to use a public static Create() method on the infobar delegate classes. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/plugins/plugin_observer.cc ('k') | chrome/browser/three_d_api_observer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ssl/ssl_tab_helper.cc
===================================================================
--- chrome/browser/ssl/ssl_tab_helper.cc (revision 175396)
+++ chrome/browser/ssl/ssl_tab_helper.cc (working copy)
@@ -14,7 +14,6 @@
#include "base/values.h"
#include "chrome/browser/api/infobars/confirm_infobar_delegate.h"
#include "chrome/browser/api/infobars/infobar_service.h"
-#include "chrome/browser/api/infobars/simple_alert_infobar_delegate.h"
#include "chrome/browser/certificate_viewer.h"
#include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/infobars/infobar.h"
@@ -36,23 +35,27 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
-namespace {
-gfx::Image* GetCertIcon() {
- // TODO(davidben): use a more appropriate icon.
- return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(
- IDR_INFOBAR_SAVE_PASSWORD);
-}
+// SSLCertResultInfoBarDelegate -----------------------------------------------
-// SSLCertAddedInfoBarDelegate ------------------------------------------------
+namespace {
-class SSLCertAddedInfoBarDelegate : public ConfirmInfoBarDelegate {
+class SSLCertResultInfoBarDelegate : public ConfirmInfoBarDelegate {
public:
- SSLCertAddedInfoBarDelegate(InfoBarService* infobar_service,
- net::X509Certificate* cert);
+ // Creates an SSL cert result delegate. If |previous_infobar| is
+ // NULL, adds the infobar to |infobar_service|; otherwise, replaces
+ // |previous_infobar|. Returns the new delegate if it was successfully added.
+ // |cert| is valid iff cert addition was successful.
+ static InfoBarDelegate* Create(InfoBarService* infobar_service,
+ InfoBarDelegate* previous_infobar,
+ const string16& message,
+ net::X509Certificate* cert);
private:
- virtual ~SSLCertAddedInfoBarDelegate();
+ SSLCertResultInfoBarDelegate(InfoBarService* infobar_service,
+ const string16& message,
+ net::X509Certificate* cert);
+ virtual ~SSLCertResultInfoBarDelegate();
// ConfirmInfoBarDelegate:
virtual gfx::Image* GetIcon() const OVERRIDE;
@@ -62,44 +65,60 @@
virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
virtual bool Accept() OVERRIDE;
- scoped_refptr<net::X509Certificate> cert_; // The cert we added.
+ string16 message_;
+ scoped_refptr<net::X509Certificate> cert_; // The cert we added, if any.
};
-SSLCertAddedInfoBarDelegate::SSLCertAddedInfoBarDelegate(
+// static
+InfoBarDelegate* SSLCertResultInfoBarDelegate::Create(
InfoBarService* infobar_service,
+ InfoBarDelegate* previous_infobar,
+ const string16& message,
+ net::X509Certificate* cert) {
+ scoped_ptr<InfoBarDelegate> infobar(
+ new SSLCertResultInfoBarDelegate(infobar_service, message, cert));
+ return previous_infobar ?
+ infobar_service->ReplaceInfoBar(previous_infobar, infobar.Pass()) :
+ infobar_service->AddInfoBar(infobar.Pass());
+}
+
+SSLCertResultInfoBarDelegate::SSLCertResultInfoBarDelegate(
+ InfoBarService* infobar_service,
+ const string16& message,
net::X509Certificate* cert)
: ConfirmInfoBarDelegate(infobar_service),
+ message_(message),
cert_(cert) {
}
-SSLCertAddedInfoBarDelegate::~SSLCertAddedInfoBarDelegate() {
+SSLCertResultInfoBarDelegate::~SSLCertResultInfoBarDelegate() {
}
-gfx::Image* SSLCertAddedInfoBarDelegate::GetIcon() const {
- return GetCertIcon();
+gfx::Image* SSLCertResultInfoBarDelegate::GetIcon() const {
+ // TODO(davidben): use a more appropriate icon.
+ return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(
+ IDR_INFOBAR_SAVE_PASSWORD);
}
-InfoBarDelegate::Type SSLCertAddedInfoBarDelegate::GetInfoBarType() const {
- return PAGE_ACTION_TYPE;
+InfoBarDelegate::Type SSLCertResultInfoBarDelegate::GetInfoBarType() const {
+ return cert_.get() ? PAGE_ACTION_TYPE : WARNING_TYPE;
}
-string16 SSLCertAddedInfoBarDelegate::GetMessageText() const {
- // TODO(evanm): GetDisplayName should return UTF-16.
- return l10n_util::GetStringFUTF16(IDS_ADD_CERT_SUCCESS_INFOBAR_LABEL,
- UTF8ToUTF16(cert_->issuer().GetDisplayName()));
+string16 SSLCertResultInfoBarDelegate::GetMessageText() const {
+ return message_;
}
-int SSLCertAddedInfoBarDelegate::GetButtons() const {
- return BUTTON_OK;
+int SSLCertResultInfoBarDelegate::GetButtons() const {
+ return cert_.get() ? BUTTON_OK : BUTTON_NONE;
}
-string16 SSLCertAddedInfoBarDelegate::GetButtonLabel(
+string16 SSLCertResultInfoBarDelegate::GetButtonLabel(
InfoBarButton button) const {
DCHECK_EQ(BUTTON_OK, button);
return l10n_util::GetStringUTF16(IDS_ADD_CERT_SUCCESS_INFOBAR_BUTTON);
}
-bool SSLCertAddedInfoBarDelegate::Accept() {
+bool SSLCertResultInfoBarDelegate::Accept() {
ShowCertificateViewer(
owner()->GetWebContents(),
owner()->GetWebContents()->GetView()->GetTopLevelNativeWindow(),
@@ -118,14 +137,9 @@
explicit SSLAddCertData(content::WebContents* contents);
virtual ~SSLAddCertData();
- // Displays |delegate| as an infobar in |tab_|, replacing our current one if
- // still active.
- void ShowInfoBar(InfoBarDelegate* delegate);
+ // Displays an infobar, replacing |infobar_delegate_| if it exists.
+ void ShowInfoBar(const string16& message, net::X509Certificate* cert);
- // Same as above, for the common case of wanting to show a simple alert
- // message.
- void ShowErrorInfoBar(const string16& message);
-
private:
// content::NotificationObserver:
virtual void Observe(int type,
@@ -152,19 +166,12 @@
SSLTabHelper::SSLAddCertData::~SSLAddCertData() {
}
-void SSLTabHelper::SSLAddCertData::ShowInfoBar(InfoBarDelegate* delegate) {
- if (infobar_delegate_)
- infobar_service_->ReplaceInfoBar(infobar_delegate_, delegate);
- else
- infobar_service_->AddInfoBar(delegate);
- infobar_delegate_ = delegate;
+void SSLTabHelper::SSLAddCertData::ShowInfoBar(const string16& message,
+ net::X509Certificate* cert) {
+ infobar_delegate_ = SSLCertResultInfoBarDelegate::Create(
+ infobar_service_, infobar_delegate_, message, cert);
}
-void SSLTabHelper::SSLAddCertData::ShowErrorInfoBar(const string16& message) {
- ShowInfoBar(new SimpleAlertInfoBarDelegate(
- infobar_service_, GetCertIcon(), message, true));
-}
-
void SSLTabHelper::SSLAddCertData::Observe(
int type,
const content::NotificationSource& source,
@@ -203,10 +210,11 @@
SSLAddCertData* add_cert_data = GetAddCertData(handler);
// Display an infobar with the error message.
// TODO(davidben): Display a more user-friendly error string.
- add_cert_data->ShowErrorInfoBar(
+ add_cert_data->ShowInfoBar(
l10n_util::GetStringFUTF16(IDS_ADD_CERT_ERR_INVALID_CERT,
base::IntToString16(-error_code),
- ASCIIToUTF16(net::ErrorToString(error_code))));
+ ASCIIToUTF16(net::ErrorToString(error_code))),
+ NULL);
}
void SSLTabHelper::AskToAddClientCertificate(
@@ -218,10 +226,12 @@
scoped_refptr<SSLAddCertHandler> handler) {
SSLAddCertData* add_cert_data = GetAddCertData(handler);
// Display an infobar to inform the user.
- InfoBarService* infobar_service =
- InfoBarService::FromWebContents(web_contents_);
- add_cert_data->ShowInfoBar(new SSLCertAddedInfoBarDelegate(
- infobar_service, handler->cert()));
+ net::X509Certificate* cert = handler->cert();
+ // TODO(evanm): GetDisplayName should return UTF-16.
+ add_cert_data->ShowInfoBar(
+ l10n_util::GetStringFUTF16(IDS_ADD_CERT_SUCCESS_INFOBAR_LABEL,
+ UTF8ToUTF16(cert->issuer().GetDisplayName())),
+ cert);
}
void SSLTabHelper::OnAddClientCertificateError(
@@ -229,10 +239,11 @@
SSLAddCertData* add_cert_data = GetAddCertData(handler);
// Display an infobar with the error message.
// TODO(davidben): Display a more user-friendly error string.
- add_cert_data->ShowErrorInfoBar(
+ add_cert_data->ShowInfoBar(
l10n_util::GetStringFUTF16(IDS_ADD_CERT_ERR_FAILED,
base::IntToString16(-error_code),
- ASCIIToUTF16(net::ErrorToString(error_code))));
+ ASCIIToUTF16(net::ErrorToString(error_code))),
+ NULL);
}
void SSLTabHelper::OnAddClientCertificateFinished(
« no previous file with comments | « chrome/browser/plugins/plugin_observer.cc ('k') | chrome/browser/three_d_api_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698