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

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

Issue 240193003: Move Infobars core files to the Infobars component (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix nib name on mac Created 6 years, 8 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
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"
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/confirm_infobar_delegate.h"
19 #include "chrome/browser/infobars/infobar.h"
20 #include "chrome/browser/infobars/infobar_service.h" 19 #include "chrome/browser/infobars/infobar_service.h"
21 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/ssl/ssl_add_cert_handler.h" 21 #include "chrome/browser/ssl/ssl_add_cert_handler.h"
23 #include "chrome/browser/ssl/ssl_client_certificate_selector.h" 22 #include "chrome/browser/ssl/ssl_client_certificate_selector.h"
24 #include "chrome/browser/ui/browser_finder.h" 23 #include "chrome/browser/ui/browser_finder.h"
25 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
25 #include "components/infobars/core/infobar.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 ConfirmInfoBarDelegate {
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 infobars::InfoBar* Create(InfoBarService* infobar_service,
50 InfoBar* previous_infobar, 50 infobars::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(const base::string16& message,
56 net::X509Certificate* cert); 56 net::X509Certificate* cert);
57 virtual ~SSLCertResultInfoBarDelegate(); 57 virtual ~SSLCertResultInfoBarDelegate();
58 58
59 // ConfirmInfoBarDelegate: 59 // ConfirmInfoBarDelegate:
60 virtual int GetIconID() const OVERRIDE; 60 virtual int GetIconID() const OVERRIDE;
61 virtual Type GetInfoBarType() const OVERRIDE; 61 virtual Type GetInfoBarType() const OVERRIDE;
62 virtual base::string16 GetMessageText() const OVERRIDE; 62 virtual base::string16 GetMessageText() const OVERRIDE;
63 virtual int GetButtons() const OVERRIDE; 63 virtual int GetButtons() const OVERRIDE;
64 virtual base::string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; 64 virtual base::string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
65 virtual bool Accept() OVERRIDE; 65 virtual bool Accept() OVERRIDE;
66 66
67 base::string16 message_; 67 base::string16 message_;
68 scoped_refptr<net::X509Certificate> cert_; // The cert we added, if any. 68 scoped_refptr<net::X509Certificate> cert_; // The cert we added, if any.
69 69
70 DISALLOW_COPY_AND_ASSIGN(SSLCertResultInfoBarDelegate); 70 DISALLOW_COPY_AND_ASSIGN(SSLCertResultInfoBarDelegate);
71 }; 71 };
72 72
73 // static 73 // static
74 InfoBar* SSLCertResultInfoBarDelegate::Create(InfoBarService* infobar_service, 74 infobars::InfoBar* SSLCertResultInfoBarDelegate::Create(
75 InfoBar* previous_infobar, 75 InfoBarService* infobar_service,
76 const base::string16& message, 76 infobars::InfoBar* previous_infobar,
77 net::X509Certificate* cert) { 77 const base::string16& message,
78 scoped_ptr<InfoBar> infobar(ConfirmInfoBarDelegate::CreateInfoBar( 78 net::X509Certificate* cert) {
79 scoped_ptr<ConfirmInfoBarDelegate>( 79 scoped_ptr<infobars::InfoBar> infobar(
80 ConfirmInfoBarDelegate::CreateInfoBar(scoped_ptr<ConfirmInfoBarDelegate>(
80 new SSLCertResultInfoBarDelegate(message, cert)))); 81 new SSLCertResultInfoBarDelegate(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(
87 const base::string16& message, 88 const base::string16& message,
88 net::X509Certificate* cert) 89 net::X509Certificate* cert)
89 : ConfirmInfoBarDelegate(), 90 : ConfirmInfoBarDelegate(),
90 message_(message), 91 message_(message),
91 cert_(cert) { 92 cert_(cert) {
92 } 93 }
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 infobars::InfoBarDelegate::Type SSLCertResultInfoBarDelegate::GetInfoBarType()
104 const {
103 return cert_.get() ? PAGE_ACTION_TYPE : WARNING_TYPE; 105 return cert_.get() ? PAGE_ACTION_TYPE : WARNING_TYPE;
104 } 106 }
105 107
106 base::string16 SSLCertResultInfoBarDelegate::GetMessageText() const { 108 base::string16 SSLCertResultInfoBarDelegate::GetMessageText() const {
107 return message_; 109 return message_;
108 } 110 }
109 111
110 int SSLCertResultInfoBarDelegate::GetButtons() const { 112 int SSLCertResultInfoBarDelegate::GetButtons() const {
111 return cert_.get() ? BUTTON_OK : BUTTON_NONE; 113 return cert_.get() ? BUTTON_OK : BUTTON_NONE;
112 } 114 }
(...skipping 27 matching lines...) Expand all
140 // Displays an infobar, replacing |infobar_| if it exists. 142 // Displays an infobar, replacing |infobar_| if it exists.
141 void ShowInfoBar(const base::string16& message, net::X509Certificate* cert); 143 void ShowInfoBar(const base::string16& message, net::X509Certificate* cert);
142 144
143 private: 145 private:
144 // content::NotificationObserver: 146 // content::NotificationObserver:
145 virtual void Observe(int type, 147 virtual void Observe(int type,
146 const content::NotificationSource& source, 148 const content::NotificationSource& source,
147 const content::NotificationDetails& details) OVERRIDE; 149 const content::NotificationDetails& details) OVERRIDE;
148 150
149 InfoBarService* infobar_service_; 151 InfoBarService* infobar_service_;
150 InfoBar* infobar_; 152 infobars::InfoBar* infobar_;
151 content::NotificationRegistrar registrar_; 153 content::NotificationRegistrar registrar_;
152 154
153 DISALLOW_COPY_AND_ASSIGN(SSLAddCertData); 155 DISALLOW_COPY_AND_ASSIGN(SSLAddCertData);
154 }; 156 };
155 157
156 SSLTabHelper::SSLAddCertData::SSLAddCertData(InfoBarService* infobar_service) 158 SSLTabHelper::SSLAddCertData::SSLAddCertData(InfoBarService* infobar_service)
157 : infobar_service_(infobar_service), 159 : infobar_service_(infobar_service),
158 infobar_(NULL) { 160 infobar_(NULL) {
159 content::Source<InfoBarService> source(infobar_service_); 161 content::Source<InfoBarService> source(infobar_service_);
160 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, 162 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
(...skipping 12 matching lines...) Expand all
173 } 175 }
174 176
175 void SSLTabHelper::SSLAddCertData::Observe( 177 void SSLTabHelper::SSLAddCertData::Observe(
176 int type, 178 int type,
177 const content::NotificationSource& source, 179 const content::NotificationSource& source,
178 const content::NotificationDetails& details) { 180 const content::NotificationDetails& details) {
179 DCHECK(type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED || 181 DCHECK(type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED ||
180 type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED); 182 type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED);
181 if (infobar_ == 183 if (infobar_ ==
182 ((type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED) ? 184 ((type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED) ?
183 content::Details<InfoBar::RemovedDetails>(details)->first : 185 content::Details<infobars::InfoBar::RemovedDetails>(
184 content::Details<InfoBar::ReplacedDetails>(details)->first)) 186 details)->first :
187 content::Details<infobars::InfoBar::ReplacedDetails>(
188 details)->first)) {
185 infobar_ = NULL; 189 infobar_ = NULL;
190 }
186 } 191 }
187 192
188 193
189 // SSLTabHelper ---------------------------------------------------------------- 194 // SSLTabHelper ----------------------------------------------------------------
190 195
191 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SSLTabHelper); 196 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SSLTabHelper);
192 197
193 SSLTabHelper::SSLTabHelper(content::WebContents* contents) 198 SSLTabHelper::SSLTabHelper(content::WebContents* contents)
194 : WebContentsObserver(contents), 199 : WebContentsObserver(contents),
195 web_contents_(contents) { 200 web_contents_(contents) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 // Find/create the slot. 270 // Find/create the slot.
266 linked_ptr<SSLAddCertData>& ptr_ref = 271 linked_ptr<SSLAddCertData>& ptr_ref =
267 request_id_to_add_cert_data_[handler->network_request_id()]; 272 request_id_to_add_cert_data_[handler->network_request_id()];
268 // Fill it if necessary. 273 // Fill it if necessary.
269 if (!ptr_ref.get()) { 274 if (!ptr_ref.get()) {
270 ptr_ref.reset( 275 ptr_ref.reset(
271 new SSLAddCertData(InfoBarService::FromWebContents(web_contents_))); 276 new SSLAddCertData(InfoBarService::FromWebContents(web_contents_)));
272 } 277 }
273 return ptr_ref.get(); 278 return ptr_ref.get();
274 } 279 }
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