summaryrefslogtreecommitdiffstats
path: root/chrome/browser/tab_contents/tab_contents_ssl_helper.cc
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-21 19:01:19 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-21 19:01:19 +0000
commitf4f50efb4d3ee42470c8057345e902ac42e76801 (patch)
tree5b4d0c57cd94d8169db9dc441f424d6443e4f490 /chrome/browser/tab_contents/tab_contents_ssl_helper.cc
parent0bd22cab9c919ff8d9b35153f6799dc031fe2770 (diff)
downloadchromium_src-f4f50efb4d3ee42470c8057345e902ac42e76801.zip
chromium_src-f4f50efb4d3ee42470c8057345e902ac42e76801.tar.gz
chromium_src-f4f50efb4d3ee42470c8057345e902ac42e76801.tar.bz2
Cleanup: de-inline a bunch of classes, rename and move "PluginInstaller" to "PluginInstallerInfoBarDelegate" for clarity, lots of other misc. stuff
BUG=none TEST=none Review URL: http://codereview.chromium.org/6249010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72166 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents/tab_contents_ssl_helper.cc')
-rw-r--r--chrome/browser/tab_contents/tab_contents_ssl_helper.cc222
1 files changed, 120 insertions, 102 deletions
diff --git a/chrome/browser/tab_contents/tab_contents_ssl_helper.cc b/chrome/browser/tab_contents/tab_contents_ssl_helper.cc
index be8e567..06048ac 100644
--- a/chrome/browser/tab_contents/tab_contents_ssl_helper.cc
+++ b/chrome/browser/tab_contents/tab_contents_ssl_helper.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -29,134 +29,152 @@ SkBitmap* GetCertIcon() {
IDR_INFOBAR_SAVE_PASSWORD);
}
+
+// SSLCertAddedInfoBarDelegate ------------------------------------------------
+
class SSLCertAddedInfoBarDelegate : public ConfirmInfoBarDelegate {
public:
SSLCertAddedInfoBarDelegate(TabContents* tab_contents,
- net::X509Certificate* cert)
- : ConfirmInfoBarDelegate(tab_contents),
- tab_contents_(tab_contents),
- cert_(cert) {
- }
-
- virtual ~SSLCertAddedInfoBarDelegate() {
- }
-
- // Overridden from ConfirmInfoBarDelegate:
- virtual string16 GetMessageText() const {
- // TODO(evanm): GetDisplayName should return UTF-16.
- return l10n_util::GetStringFUTF16(
- IDS_ADD_CERT_SUCCESS_INFOBAR_LABEL,
- UTF8ToUTF16(cert_->issuer().GetDisplayName()));
- }
-
- virtual SkBitmap* GetIcon() const {
- return GetCertIcon();
- }
-
- virtual int GetButtons() const {
- return BUTTON_OK;
- }
-
- virtual string16 GetButtonLabel(InfoBarButton button) const {
- switch (button) {
- case BUTTON_OK:
- return l10n_util::GetStringUTF16(IDS_ADD_CERT_SUCCESS_INFOBAR_BUTTON);
- default:
- return string16();
- }
- }
-
- virtual Type GetInfoBarType() {
- return PAGE_ACTION_TYPE;
- }
-
- virtual bool Accept() {
- ShowCertificateViewer(tab_contents_->GetMessageBoxRootWindow(), cert_);
- return false; // Hiding the infobar just as the dialog opens looks weird.
- }
-
- virtual void InfoBarClosed() {
- // ConfirmInfoBarDelegate doesn't delete itself.
- delete this;
- }
+ net::X509Certificate* cert);
private:
+ virtual ~SSLCertAddedInfoBarDelegate();
+
+ // ConfirmInfoBarDelegate:
+ virtual void InfoBarClosed();
+ virtual SkBitmap* GetIcon() const;
+ virtual Type GetInfoBarType() const;
+ virtual string16 GetMessageText() const;
+ virtual int GetButtons() const;
+ virtual string16 GetButtonLabel(InfoBarButton button) const;
+ virtual bool Accept();
+
// The TabContents we are attached to
TabContents* tab_contents_;
// The cert we added.
scoped_refptr<net::X509Certificate> cert_;
};
+SSLCertAddedInfoBarDelegate::SSLCertAddedInfoBarDelegate(
+ TabContents* tab_contents,
+ net::X509Certificate* cert)
+ : ConfirmInfoBarDelegate(tab_contents),
+ tab_contents_(tab_contents),
+ cert_(cert) {
+}
+
+SSLCertAddedInfoBarDelegate::~SSLCertAddedInfoBarDelegate() {
+}
+
+void SSLCertAddedInfoBarDelegate::InfoBarClosed() {
+ // ConfirmInfoBarDelegate doesn't delete itself.
+ delete this;
+}
+
+SkBitmap* SSLCertAddedInfoBarDelegate::GetIcon() const {
+ return GetCertIcon();
+}
+
+InfoBarDelegate::Type SSLCertAddedInfoBarDelegate::GetInfoBarType() const {
+ return PAGE_ACTION_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()));
+}
+
+int SSLCertAddedInfoBarDelegate::GetButtons() const {
+ return BUTTON_OK;
+}
+
+string16 SSLCertAddedInfoBarDelegate::GetButtonLabel(
+ InfoBarButton button) const {
+ DCHECK_EQ(BUTTON_OK, button);
+ return l10n_util::GetStringUTF16(IDS_ADD_CERT_SUCCESS_INFOBAR_BUTTON);
+}
+
+bool SSLCertAddedInfoBarDelegate::Accept() {
+ ShowCertificateViewer(tab_contents_->GetMessageBoxRootWindow(), cert_);
+ return false; // Hiding the infobar just as the dialog opens looks weird.
+}
+
} // namespace
+
+// TabContentsSSLHelper::SSLAddCertData ---------------------------------------
+
class TabContentsSSLHelper::SSLAddCertData : public NotificationObserver {
public:
- SSLAddCertData(TabContents* tab, SSLAddCertHandler* handler)
- : tab_(tab),
- handler_(handler),
- infobar_delegate_(NULL) {
- // Listen for disappearing InfoBars.
- Source<TabContents> tc_source(tab_);
- registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
- tc_source);
- registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
- tc_source);
- }
- ~SSLAddCertData() {}
+ SSLAddCertData(TabContents* tab, SSLAddCertHandler* handler);
+ virtual ~SSLAddCertData();
// Displays |delegate| as an infobar in |tab_|, replacing our current one if
// still active.
- void ShowInfoBar(InfoBarDelegate* delegate) {
- if (infobar_delegate_) {
- tab_->ReplaceInfoBar(infobar_delegate_, delegate);
- } else {
- tab_->AddInfoBar(delegate);
- }
- infobar_delegate_ = delegate;
- }
-
- void ShowErrorInfoBar(const string16& message) {
- ShowInfoBar(
- new SimpleAlertInfoBarDelegate(tab_, message, GetCertIcon(), true));
- }
-
- // NotificationObserver implementation.
+ void ShowInfoBar(InfoBarDelegate* delegate);
+
+ // Same as above, for the common case of wanting to show a simple alert
+ // message.
+ void ShowErrorInfoBar(const string16& message);
+
+ private:
+ // NotificationObserver:
virtual void Observe(NotificationType type,
const NotificationSource& source,
- const NotificationDetails& details) {
- switch (type.value) {
- case NotificationType::TAB_CONTENTS_INFOBAR_REMOVED:
- InfoBarClosed(Details<InfoBarDelegate>(details).ptr());
- break;
- case NotificationType::TAB_CONTENTS_INFOBAR_REPLACED:
- typedef std::pair<InfoBarDelegate*, InfoBarDelegate*>
- InfoBarDelegatePair;
- InfoBarClosed(Details<InfoBarDelegatePair>(details).ptr()->first);
- break;
- default:
- NOTREACHED();
- break;
- }
- }
+ const NotificationDetails& details);
- private:
- void InfoBarClosed(InfoBarDelegate* delegate) {
- if (infobar_delegate_ == delegate)
- infobar_delegate_ = NULL;
- }
-
- // The TabContents we are attached to.
- TabContents* tab_;
- // The handler we call back to.
- scoped_refptr<SSLAddCertHandler> handler_;
- // The current InfoBarDelegate we're displaying.
+ TabContents* tab_contents_;
+ scoped_refptr<SSLAddCertHandler> handler_; // The handler we call back to.
InfoBarDelegate* infobar_delegate_;
-
NotificationRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(SSLAddCertData);
};
+TabContentsSSLHelper::SSLAddCertData::SSLAddCertData(TabContents* tab_contents,
+ SSLAddCertHandler* handler)
+ : tab_contents_(tab_contents),
+ handler_(handler),
+ infobar_delegate_(NULL) {
+ Source<TabContents> source(tab_contents_);
+ registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, source);
+ registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REPLACED, source);
+}
+
+TabContentsSSLHelper::SSLAddCertData::~SSLAddCertData() {
+}
+
+void TabContentsSSLHelper::SSLAddCertData::ShowInfoBar(
+ InfoBarDelegate* delegate) {
+ if (infobar_delegate_)
+ tab_contents_->ReplaceInfoBar(infobar_delegate_, delegate);
+ else
+ tab_contents_->AddInfoBar(delegate);
+ infobar_delegate_ = delegate;
+}
+
+void TabContentsSSLHelper::SSLAddCertData::ShowErrorInfoBar(
+ const string16& message) {
+ ShowInfoBar(new SimpleAlertInfoBarDelegate(tab_contents_, GetCertIcon(),
+ message, true));
+}
+
+void TabContentsSSLHelper::SSLAddCertData::Observe(
+ NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ typedef std::pair<InfoBarDelegate*, InfoBarDelegate*> InfoBarDelegatePair;
+ if (infobar_delegate_ ==
+ ((type.value == NotificationType::TAB_CONTENTS_INFOBAR_REMOVED) ?
+ Details<InfoBarDelegate>(details).ptr() :
+ Details<InfoBarDelegatePair>(details).ptr()->first))
+ infobar_delegate_ = NULL;
+}
+
+
+// TabContentsSSLHelper -------------------------------------------------------
+
TabContentsSSLHelper::TabContentsSSLHelper(TabContents* tab_contents)
: tab_contents_(tab_contents) {
}