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

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

Issue 10916348: Switch SSLTabHelper to use WebContentsUserData. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ssl/ssl_tab_helper.h ('k') | chrome/browser/ssl_client_certificate_selector.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/tab_contents/tab_contents_ssl_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/string_number_conversions.h" 12 #include "base/string_number_conversions.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" 15 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h"
16 #include "chrome/browser/api/infobars/simple_alert_infobar_delegate.h" 16 #include "chrome/browser/api/infobars/simple_alert_infobar_delegate.h"
17 #include "chrome/browser/certificate_viewer.h" 17 #include "chrome/browser/certificate_viewer.h"
18 #include "chrome/browser/content_settings/host_content_settings_map.h" 18 #include "chrome/browser/content_settings/host_content_settings_map.h"
19 #include "chrome/browser/infobars/infobar.h" 19 #include "chrome/browser/infobars/infobar.h"
20 #include "chrome/browser/infobars/infobar_tab_helper.h" 20 #include "chrome/browser/infobars/infobar_tab_helper.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_client_certificate_selector.h" 23 #include "chrome/browser/ssl/ssl_client_certificate_selector.h"
24 #include "chrome/browser/ui/tab_contents/tab_contents.h" 24 #include "chrome/browser/ui/tab_contents/tab_contents.h"
25 #include "chrome/common/chrome_notification_types.h" 25 #include "chrome/common/chrome_notification_types.h"
26 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
27 #include "content/public/browser/notification_details.h" 27 #include "content/public/browser/notification_details.h"
28 #include "content/public/browser/notification_source.h" 28 #include "content/public/browser/notification_source.h"
29 #include "content/public/browser/web_contents.h" 29 #include "content/public/browser/web_contents.h"
30 #include "content/public/browser/web_contents_view.h" 30 #include "content/public/browser/web_contents_view.h"
31 #include "grit/generated_resources.h" 31 #include "grit/generated_resources.h"
32 #include "grit/theme_resources.h" 32 #include "grit/theme_resources.h"
33 #include "net/base/net_errors.h" 33 #include "net/base/net_errors.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 ShowCertificateViewer( 102 ShowCertificateViewer(
103 owner()->GetWebContents(), 103 owner()->GetWebContents(),
104 owner()->GetWebContents()->GetView()->GetTopLevelNativeWindow(), 104 owner()->GetWebContents()->GetView()->GetTopLevelNativeWindow(),
105 cert_); 105 cert_);
106 return false; // Hiding the infobar just as the dialog opens looks weird. 106 return false; // Hiding the infobar just as the dialog opens looks weird.
107 } 107 }
108 108
109 } // namespace 109 } // namespace
110 110
111 111
112 // TabContentsSSLHelper::SSLAddCertData --------------------------------------- 112 // SSLTabHelper::SSLAddCertData ------------------------------------------------
113 113
114 class TabContentsSSLHelper::SSLAddCertData 114 class SSLTabHelper::SSLAddCertData
115 : public content::NotificationObserver { 115 : public content::NotificationObserver {
116 public: 116 public:
117 explicit SSLAddCertData(TabContents* tab_contents); 117 explicit SSLAddCertData(content::WebContents* contents);
118 virtual ~SSLAddCertData(); 118 virtual ~SSLAddCertData();
119 119
120 // Displays |delegate| as an infobar in |tab_|, replacing our current one if 120 // Displays |delegate| as an infobar in |tab_|, replacing our current one if
121 // still active. 121 // still active.
122 void ShowInfoBar(InfoBarDelegate* delegate); 122 void ShowInfoBar(InfoBarDelegate* delegate);
123 123
124 // Same as above, for the common case of wanting to show a simple alert 124 // Same as above, for the common case of wanting to show a simple alert
125 // message. 125 // message.
126 void ShowErrorInfoBar(const string16& message); 126 void ShowErrorInfoBar(const string16& message);
127 127
128 private: 128 private:
129 // content::NotificationObserver: 129 // content::NotificationObserver:
130 virtual void Observe(int type, 130 virtual void Observe(int type,
131 const content::NotificationSource& source, 131 const content::NotificationSource& source,
132 const content::NotificationDetails& details); 132 const content::NotificationDetails& details);
133 133
134 TabContents* tab_contents_; 134 InfoBarTabHelper* infobar_helper_;
135 InfoBarDelegate* infobar_delegate_; 135 InfoBarDelegate* infobar_delegate_;
136 content::NotificationRegistrar registrar_; 136 content::NotificationRegistrar registrar_;
137 137
138 DISALLOW_COPY_AND_ASSIGN(SSLAddCertData); 138 DISALLOW_COPY_AND_ASSIGN(SSLAddCertData);
139 }; 139 };
140 140
141 TabContentsSSLHelper::SSLAddCertData::SSLAddCertData( 141 SSLTabHelper::SSLAddCertData::SSLAddCertData(content::WebContents* contents)
142 TabContents* tab_contents) 142 : infobar_helper_(
143 : tab_contents_(tab_contents), 143 TabContents::FromWebContents(contents)->infobar_tab_helper()),
144 infobar_delegate_(NULL) { 144 infobar_delegate_(NULL) {
145 content::Source<InfoBarTabHelper> source(tab_contents_->infobar_tab_helper()); 145 content::Source<InfoBarTabHelper> source(infobar_helper_);
146 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, 146 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
147 source); 147 source);
148 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED, 148 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED,
149 source); 149 source);
150 } 150 }
151 151
152 TabContentsSSLHelper::SSLAddCertData::~SSLAddCertData() { 152 SSLTabHelper::SSLAddCertData::~SSLAddCertData() {
153 } 153 }
154 154
155 void TabContentsSSLHelper::SSLAddCertData::ShowInfoBar( 155 void SSLTabHelper::SSLAddCertData::ShowInfoBar(InfoBarDelegate* delegate) {
156 InfoBarDelegate* delegate) {
157 if (infobar_delegate_) 156 if (infobar_delegate_)
158 tab_contents_->infobar_tab_helper()->ReplaceInfoBar(infobar_delegate_, 157 infobar_helper_->ReplaceInfoBar(infobar_delegate_, delegate);
159 delegate);
160 else 158 else
161 tab_contents_->infobar_tab_helper()->AddInfoBar(delegate); 159 infobar_helper_->AddInfoBar(delegate);
162 infobar_delegate_ = delegate; 160 infobar_delegate_ = delegate;
163 } 161 }
164 162
165 void TabContentsSSLHelper::SSLAddCertData::ShowErrorInfoBar( 163 void SSLTabHelper::SSLAddCertData::ShowErrorInfoBar(const string16& message) {
166 const string16& message) {
167 ShowInfoBar(new SimpleAlertInfoBarDelegate( 164 ShowInfoBar(new SimpleAlertInfoBarDelegate(
168 tab_contents_->infobar_tab_helper(), GetCertIcon(), message, true)); 165 infobar_helper_, GetCertIcon(), message, true));
169 } 166 }
170 167
171 void TabContentsSSLHelper::SSLAddCertData::Observe( 168 void SSLTabHelper::SSLAddCertData::Observe(
172 int type, 169 int type,
173 const content::NotificationSource& source, 170 const content::NotificationSource& source,
174 const content::NotificationDetails& details) { 171 const content::NotificationDetails& details) {
175 DCHECK(type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED || 172 DCHECK(type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED ||
176 type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED); 173 type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED);
177 if (infobar_delegate_ == 174 if (infobar_delegate_ ==
178 ((type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED) ? 175 ((type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED) ?
179 content::Details<InfoBarRemovedDetails>(details)->first : 176 content::Details<InfoBarRemovedDetails>(details)->first :
180 content::Details<InfoBarReplacedDetails>(details)->first)) 177 content::Details<InfoBarReplacedDetails>(details)->first))
181 infobar_delegate_ = NULL; 178 infobar_delegate_ = NULL;
182 } 179 }
183 180
184 181
185 // TabContentsSSLHelper ------------------------------------------------------- 182 // SSLTabHelper ----------------------------------------------------------------
186 183
187 TabContentsSSLHelper::TabContentsSSLHelper(TabContents* tab_contents) 184 int SSLTabHelper::kUserDataKey;
188 : tab_contents_(tab_contents) { 185
186 SSLTabHelper::SSLTabHelper(content::WebContents* contents)
187 : web_contents_(contents) {
189 } 188 }
190 189
191 TabContentsSSLHelper::~TabContentsSSLHelper() { 190 SSLTabHelper::~SSLTabHelper() {
192 } 191 }
193 192
194 void TabContentsSSLHelper::ShowClientCertificateRequestDialog( 193 void SSLTabHelper::ShowClientCertificateRequestDialog(
195 const net::HttpNetworkSession* network_session, 194 const net::HttpNetworkSession* network_session,
196 net::SSLCertRequestInfo* cert_request_info, 195 net::SSLCertRequestInfo* cert_request_info,
197 const base::Callback<void(net::X509Certificate*)>& callback) { 196 const base::Callback<void(net::X509Certificate*)>& callback) {
198 chrome::ShowSSLClientCertificateSelector( 197 chrome::ShowSSLClientCertificateSelector(
199 tab_contents_, network_session, cert_request_info, callback); 198 web_contents_, network_session, cert_request_info, callback);
200 } 199 }
201 200
202 void TabContentsSSLHelper::OnVerifyClientCertificateError( 201 void SSLTabHelper::OnVerifyClientCertificateError(
203 scoped_refptr<SSLAddCertHandler> handler, int error_code) { 202 scoped_refptr<SSLAddCertHandler> handler, int error_code) {
204 SSLAddCertData* add_cert_data = GetAddCertData(handler); 203 SSLAddCertData* add_cert_data = GetAddCertData(handler);
205 // Display an infobar with the error message. 204 // Display an infobar with the error message.
206 // TODO(davidben): Display a more user-friendly error string. 205 // TODO(davidben): Display a more user-friendly error string.
207 add_cert_data->ShowErrorInfoBar( 206 add_cert_data->ShowErrorInfoBar(
208 l10n_util::GetStringFUTF16(IDS_ADD_CERT_ERR_INVALID_CERT, 207 l10n_util::GetStringFUTF16(IDS_ADD_CERT_ERR_INVALID_CERT,
209 base::IntToString16(-error_code), 208 base::IntToString16(-error_code),
210 ASCIIToUTF16(net::ErrorToString(error_code)))); 209 ASCIIToUTF16(net::ErrorToString(error_code))));
211 } 210 }
212 211
213 void TabContentsSSLHelper::AskToAddClientCertificate( 212 void SSLTabHelper::AskToAddClientCertificate(
214 scoped_refptr<SSLAddCertHandler> handler) { 213 scoped_refptr<SSLAddCertHandler> handler) {
215 NOTREACHED(); // Not implemented yet. 214 NOTREACHED(); // Not implemented yet.
216 } 215 }
217 216
218 void TabContentsSSLHelper::OnAddClientCertificateSuccess( 217 void SSLTabHelper::OnAddClientCertificateSuccess(
219 scoped_refptr<SSLAddCertHandler> handler) { 218 scoped_refptr<SSLAddCertHandler> handler) {
220 SSLAddCertData* add_cert_data = GetAddCertData(handler); 219 SSLAddCertData* add_cert_data = GetAddCertData(handler);
221 // Display an infobar to inform the user. 220 // Display an infobar to inform the user.
221 TabContents* tab_contents = TabContents::FromWebContents(web_contents_);
222 add_cert_data->ShowInfoBar(new SSLCertAddedInfoBarDelegate( 222 add_cert_data->ShowInfoBar(new SSLCertAddedInfoBarDelegate(
223 tab_contents_->infobar_tab_helper(), handler->cert())); 223 tab_contents->infobar_tab_helper(), handler->cert()));
224 } 224 }
225 225
226 void TabContentsSSLHelper::OnAddClientCertificateError( 226 void SSLTabHelper::OnAddClientCertificateError(
227 scoped_refptr<SSLAddCertHandler> handler, int error_code) { 227 scoped_refptr<SSLAddCertHandler> handler, int error_code) {
228 SSLAddCertData* add_cert_data = GetAddCertData(handler); 228 SSLAddCertData* add_cert_data = GetAddCertData(handler);
229 // Display an infobar with the error message. 229 // Display an infobar with the error message.
230 // TODO(davidben): Display a more user-friendly error string. 230 // TODO(davidben): Display a more user-friendly error string.
231 add_cert_data->ShowErrorInfoBar( 231 add_cert_data->ShowErrorInfoBar(
232 l10n_util::GetStringFUTF16(IDS_ADD_CERT_ERR_FAILED, 232 l10n_util::GetStringFUTF16(IDS_ADD_CERT_ERR_FAILED,
233 base::IntToString16(-error_code), 233 base::IntToString16(-error_code),
234 ASCIIToUTF16(net::ErrorToString(error_code)))); 234 ASCIIToUTF16(net::ErrorToString(error_code))));
235 } 235 }
236 236
237 void TabContentsSSLHelper::OnAddClientCertificateFinished( 237 void SSLTabHelper::OnAddClientCertificateFinished(
238 scoped_refptr<SSLAddCertHandler> handler) { 238 scoped_refptr<SSLAddCertHandler> handler) {
239 // Clean up. 239 // Clean up.
240 request_id_to_add_cert_data_.erase(handler->network_request_id()); 240 request_id_to_add_cert_data_.erase(handler->network_request_id());
241 } 241 }
242 242
243 TabContentsSSLHelper::SSLAddCertData* TabContentsSSLHelper::GetAddCertData( 243 SSLTabHelper::SSLAddCertData*
244 SSLAddCertHandler* handler) { 244 SSLTabHelper::GetAddCertData(SSLAddCertHandler* handler) {
245 // Find/create the slot. 245 // Find/create the slot.
246 linked_ptr<SSLAddCertData>& ptr_ref = 246 linked_ptr<SSLAddCertData>& ptr_ref =
247 request_id_to_add_cert_data_[handler->network_request_id()]; 247 request_id_to_add_cert_data_[handler->network_request_id()];
248 // Fill it if necessary. 248 // Fill it if necessary.
249 if (!ptr_ref.get()) 249 if (!ptr_ref.get())
250 ptr_ref.reset(new SSLAddCertData(tab_contents_)); 250 ptr_ref.reset(new SSLAddCertData(web_contents_));
251 return ptr_ref.get(); 251 return ptr_ref.get();
252 } 252 }
OLDNEW
« no previous file with comments | « chrome/browser/ssl/ssl_tab_helper.h ('k') | chrome/browser/ssl_client_certificate_selector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698