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

Side by Side Diff: chrome/browser/ssl/ssl_tab_helper.cc

Issue 22694006: Infobar system refactor. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
(...skipping 24 matching lines...) Expand all
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 ConfirmInfoBarDelegate {
44 public: 44 public:
45 // Creates an SSL cert result infobar 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 InfoBarDelegate* Create(InfoBarService* infobar_service, 49 static InfoBar* Create(InfoBarService* infobar_service,
50 InfoBarDelegate* previous_infobar, 50 InfoBar* previous_infobar,
51 const string16& message, 51 const string16& message,
52 net::X509Certificate* cert); 52 net::X509Certificate* cert);
53 53
54 private: 54 private:
55 SSLCertResultInfoBarDelegate(InfoBarService* infobar_service, 55 SSLCertResultInfoBarDelegate(const string16& message,
56 const string16& message,
57 net::X509Certificate* cert); 56 net::X509Certificate* cert);
58 virtual ~SSLCertResultInfoBarDelegate(); 57 virtual ~SSLCertResultInfoBarDelegate();
59 58
60 // ConfirmInfoBarDelegate: 59 // ConfirmInfoBarDelegate:
61 virtual int GetIconID() const OVERRIDE; 60 virtual int GetIconID() const OVERRIDE;
62 virtual Type GetInfoBarType() const OVERRIDE; 61 virtual Type GetInfoBarType() const OVERRIDE;
63 virtual string16 GetMessageText() const OVERRIDE; 62 virtual string16 GetMessageText() const OVERRIDE;
64 virtual int GetButtons() const OVERRIDE; 63 virtual int GetButtons() const OVERRIDE;
65 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; 64 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
66 virtual bool Accept() OVERRIDE; 65 virtual bool Accept() OVERRIDE;
67 66
68 string16 message_; 67 string16 message_;
69 scoped_refptr<net::X509Certificate> cert_; // The cert we added, if any. 68 scoped_refptr<net::X509Certificate> cert_; // The cert we added, if any.
70 69
71 DISALLOW_COPY_AND_ASSIGN(SSLCertResultInfoBarDelegate); 70 DISALLOW_COPY_AND_ASSIGN(SSLCertResultInfoBarDelegate);
72 }; 71 };
73 72
74 // static 73 // static
75 InfoBarDelegate* SSLCertResultInfoBarDelegate::Create( 74 InfoBar* SSLCertResultInfoBarDelegate::Create(InfoBarService* infobar_service,
76 InfoBarService* infobar_service, 75 InfoBar* previous_infobar,
77 InfoBarDelegate* previous_infobar, 76 const string16& message,
78 const string16& message, 77 net::X509Certificate* cert) {
79 net::X509Certificate* cert) { 78 scoped_ptr<InfoBar> infobar(ConfirmInfoBarDelegate::CreateInfoBar(
80 scoped_ptr<InfoBarDelegate> infobar( 79 scoped_ptr<ConfirmInfoBarDelegate>(
81 new SSLCertResultInfoBarDelegate(infobar_service, message, cert)); 80 new SSLCertResultInfoBarDelegate(message, cert))));
82 return previous_infobar ? 81 return previous_infobar ?
83 infobar_service->ReplaceInfoBar(previous_infobar, infobar.Pass()) : 82 infobar_service->ReplaceInfoBar(previous_infobar, infobar.Pass()) :
84 infobar_service->AddInfoBar(infobar.Pass()); 83 infobar_service->AddInfoBar(infobar.Pass());
85 } 84 }
86 85
87 SSLCertResultInfoBarDelegate::SSLCertResultInfoBarDelegate( 86 SSLCertResultInfoBarDelegate::SSLCertResultInfoBarDelegate(
88 InfoBarService* infobar_service,
89 const string16& message, 87 const string16& message,
90 net::X509Certificate* cert) 88 net::X509Certificate* cert)
91 : ConfirmInfoBarDelegate(infobar_service), 89 : ConfirmInfoBarDelegate(),
92 message_(message), 90 message_(message),
93 cert_(cert) { 91 cert_(cert) {
94 } 92 }
95 93
96 SSLCertResultInfoBarDelegate::~SSLCertResultInfoBarDelegate() { 94 SSLCertResultInfoBarDelegate::~SSLCertResultInfoBarDelegate() {
97 } 95 }
98 96
99 int SSLCertResultInfoBarDelegate::GetIconID() const { 97 int SSLCertResultInfoBarDelegate::GetIconID() const {
100 // TODO(davidben): use a more appropriate icon. 98 // TODO(davidben): use a more appropriate icon.
101 return IDR_INFOBAR_SAVE_PASSWORD; 99 return IDR_INFOBAR_SAVE_PASSWORD;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 // Displays an infobar, replacing |infobar_| if it exists. 138 // Displays an infobar, replacing |infobar_| if it exists.
141 void ShowInfoBar(const string16& message, net::X509Certificate* cert); 139 void ShowInfoBar(const string16& message, net::X509Certificate* cert);
142 140
143 private: 141 private:
144 // content::NotificationObserver: 142 // content::NotificationObserver:
145 virtual void Observe(int type, 143 virtual void Observe(int type,
146 const content::NotificationSource& source, 144 const content::NotificationSource& source,
147 const content::NotificationDetails& details) OVERRIDE; 145 const content::NotificationDetails& details) OVERRIDE;
148 146
149 InfoBarService* infobar_service_; 147 InfoBarService* infobar_service_;
150 InfoBarDelegate* infobar_; 148 InfoBar* infobar_;
151 content::NotificationRegistrar registrar_; 149 content::NotificationRegistrar registrar_;
152 150
153 DISALLOW_COPY_AND_ASSIGN(SSLAddCertData); 151 DISALLOW_COPY_AND_ASSIGN(SSLAddCertData);
154 }; 152 };
155 153
156 SSLTabHelper::SSLAddCertData::SSLAddCertData(InfoBarService* infobar_service) 154 SSLTabHelper::SSLAddCertData::SSLAddCertData(InfoBarService* infobar_service)
157 : infobar_service_(infobar_service), 155 : infobar_service_(infobar_service),
158 infobar_(NULL) { 156 infobar_(NULL) {
159 content::Source<InfoBarService> source(infobar_service_); 157 content::Source<InfoBarService> source(infobar_service_);
160 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, 158 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 // Find/create the slot. 260 // Find/create the slot.
263 linked_ptr<SSLAddCertData>& ptr_ref = 261 linked_ptr<SSLAddCertData>& ptr_ref =
264 request_id_to_add_cert_data_[handler->network_request_id()]; 262 request_id_to_add_cert_data_[handler->network_request_id()];
265 // Fill it if necessary. 263 // Fill it if necessary.
266 if (!ptr_ref.get()) { 264 if (!ptr_ref.get()) {
267 ptr_ref.reset( 265 ptr_ref.reset(
268 new SSLAddCertData(InfoBarService::FromWebContents(web_contents_))); 266 new SSLAddCertData(InfoBarService::FromWebContents(web_contents_)));
269 } 267 }
270 return ptr_ref.get(); 268 return ptr_ref.get();
271 } 269 }
OLDNEW
« no previous file with comments | « chrome/browser/policy/policy_browsertest.cc ('k') | chrome/browser/task_manager/task_manager_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698