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

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

Issue 9323071: Use InterstitialPage through a delegate interface instead of deriving from it. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix tests Created 8 years, 10 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_blocking_page.h" 5 #include "chrome/browser/ssl/ssl_blocking_page.h"
6 6
7 #include "base/i18n/rtl.h" 7 #include "base/i18n/rtl.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/string_piece.h" 9 #include "base/string_piece.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/renderer_preferences_util.h"
12 #include "chrome/browser/ssl/ssl_error_info.h" 14 #include "chrome/browser/ssl/ssl_error_info.h"
13 #include "chrome/browser/tab_contents/tab_util.h" 15 #include "chrome/browser/tab_contents/tab_util.h"
14 #include "chrome/common/jstemplate_builder.h" 16 #include "chrome/common/jstemplate_builder.h"
15 #include "content/browser/cert_store.h" 17 #include "content/browser/cert_store.h"
16 #include "content/browser/renderer_host/render_view_host.h" 18 #include "content/browser/renderer_host/render_view_host.h"
17 #include "content/browser/ssl/ssl_cert_error_handler.h" 19 #include "content/browser/ssl/ssl_cert_error_handler.h"
20 #include "content/browser/tab_contents/interstitial_page.h"
18 #include "content/public/browser/navigation_controller.h" 21 #include "content/public/browser/navigation_controller.h"
19 #include "content/public/browser/navigation_entry.h" 22 #include "content/public/browser/navigation_entry.h"
20 #include "content/public/browser/notification_service.h" 23 #include "content/public/browser/notification_service.h"
21 #include "content/public/browser/notification_types.h" 24 #include "content/public/browser/notification_types.h"
22 #include "content/public/browser/render_process_host.h" 25 #include "content/public/browser/render_process_host.h"
23 #include "content/public/browser/ssl_status.h" 26 #include "content/public/browser/ssl_status.h"
24 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
25 #include "grit/browser_resources.h" 28 #include "grit/browser_resources.h"
26 #include "grit/generated_resources.h" 29 #include "grit/generated_resources.h"
27 #include "ui/base/l10n/l10n_util.h" 30 #include "ui/base/l10n/l10n_util.h"
(...skipping 16 matching lines...) Expand all
44 } 47 }
45 48
46 } // namespace 49 } // namespace
47 50
48 // Note that we always create a navigation entry with SSL errors. 51 // Note that we always create a navigation entry with SSL errors.
49 // No error happening loading a sub-resource triggers an interstitial so far. 52 // No error happening loading a sub-resource triggers an interstitial so far.
50 SSLBlockingPage::SSLBlockingPage( 53 SSLBlockingPage::SSLBlockingPage(
51 SSLCertErrorHandler* handler, 54 SSLCertErrorHandler* handler,
52 bool overridable, 55 bool overridable,
53 const base::Callback<void(SSLCertErrorHandler*, bool)>& callback) 56 const base::Callback<void(SSLCertErrorHandler*, bool)>& callback)
54 : ChromeInterstitialPage( 57 : handler_(handler),
55 tab_util::GetWebContentsByID(
56 handler->render_process_host_id(), handler->tab_contents_id()),
57 true,
58 handler->request_url()),
59 handler_(handler),
60 callback_(callback), 58 callback_(callback),
61 overridable_(overridable) { 59 overridable_(overridable) {
62 RecordSSLBlockingPageStats(SHOW); 60 RecordSSLBlockingPageStats(SHOW);
61 web_contents_ = tab_util::GetWebContentsByID(
62 handler->render_process_host_id(), handler->tab_contents_id());
63 interstitial_page_ = InterstitialPage::Create(
64 web_contents_, true, handler->request_url(), this);
65 interstitial_page_->Show();
63 } 66 }
64 67
65 SSLBlockingPage::~SSLBlockingPage() { 68 SSLBlockingPage::~SSLBlockingPage() {
66 if (!callback_.is_null()) { 69 if (!callback_.is_null()) {
67 // The page is closed without the user having chosen what to do, default to 70 // The page is closed without the user having chosen what to do, default to
68 // deny. 71 // deny.
69 NotifyDenyCertificate(); 72 NotifyDenyCertificate();
70 } 73 }
71 } 74 }
72 75
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 } 111 }
109 112
110 strings.SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); 113 strings.SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr");
111 114
112 base::StringPiece html( 115 base::StringPiece html(
113 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); 116 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id));
114 117
115 return jstemplate_builder::GetI18nTemplateHtml(html, &strings); 118 return jstemplate_builder::GetI18nTemplateHtml(html, &strings);
116 } 119 }
117 120
118 void SSLBlockingPage::UpdateEntry(NavigationEntry* entry) { 121 void SSLBlockingPage::OverrideEntry(NavigationEntry* entry) {
119 const net::SSLInfo& ssl_info = handler_->ssl_info(); 122 const net::SSLInfo& ssl_info = handler_->ssl_info();
120 int cert_id = CertStore::GetInstance()->StoreCert( 123 int cert_id = CertStore::GetInstance()->StoreCert(
121 ssl_info.cert, tab()->GetRenderProcessHost()->GetID()); 124 ssl_info.cert, web_contents_->GetRenderProcessHost()->GetID());
122 125
123 entry->GetSSL().security_style = 126 entry->GetSSL().security_style =
124 content::SECURITY_STYLE_AUTHENTICATION_BROKEN; 127 content::SECURITY_STYLE_AUTHENTICATION_BROKEN;
125 entry->GetSSL().cert_id = cert_id; 128 entry->GetSSL().cert_id = cert_id;
126 entry->GetSSL().cert_status = ssl_info.cert_status; 129 entry->GetSSL().cert_status = ssl_info.cert_status;
127 entry->GetSSL().security_bits = ssl_info.security_bits; 130 entry->GetSSL().security_bits = ssl_info.security_bits;
128 content::NotificationService::current()->Notify( 131 content::NotificationService::current()->Notify(
129 content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED, 132 content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED,
130 content::Source<NavigationController>(&tab()->GetController()), 133 content::Source<NavigationController>(&web_contents_->GetController()),
131 content::NotificationService::NoDetails()); 134 content::NotificationService::NoDetails());
132 } 135 }
133 136
134 void SSLBlockingPage::CommandReceived(const std::string& command) { 137 void SSLBlockingPage::CommandReceived(const std::string& command) {
135 if (command == "1") { 138 if (command == "1") {
136 Proceed(); 139 interstitial_page_->Proceed();
137 } else { 140 } else {
138 DontProceed(); 141 interstitial_page_->DontProceed();
139 } 142 }
140 } 143 }
141 144
142 void SSLBlockingPage::Proceed() { 145 void SSLBlockingPage::OverrideRendererPrefs(
146 content::RendererPreferences* prefs) {
147 Profile* profile = Profile::FromBrowserContext(
148 web_contents_->GetBrowserContext());
149 renderer_preferences_util::UpdateFromSystemSettings(prefs, profile);
150 }
151
152 void SSLBlockingPage::OnProceed() {
143 RecordSSLBlockingPageStats(PROCEED); 153 RecordSSLBlockingPageStats(PROCEED);
144 154
145 // Accepting the certificate resumes the loading of the page. 155 // Accepting the certificate resumes the loading of the page.
146 NotifyAllowCertificate(); 156 NotifyAllowCertificate();
147
148 // This call hides and deletes the interstitial.
149 InterstitialPage::Proceed();
150 } 157 }
151 158
152 void SSLBlockingPage::DontProceed() { 159 void SSLBlockingPage::OnDontProceed() {
153 RecordSSLBlockingPageStats(DONT_PROCEED); 160 RecordSSLBlockingPageStats(DONT_PROCEED);
154 161
155 NotifyDenyCertificate(); 162 NotifyDenyCertificate();
156 InterstitialPage::DontProceed();
157 } 163 }
158 164
159 void SSLBlockingPage::NotifyDenyCertificate() { 165 void SSLBlockingPage::NotifyDenyCertificate() {
160 // It's possible that callback_ may not exist if the user clicks "Proceed" 166 // It's possible that callback_ may not exist if the user clicks "Proceed"
161 // followed by pressing the back button before the interstitial is hidden. 167 // followed by pressing the back button before the interstitial is hidden.
162 // In that case the certificate will still be treated as allowed. 168 // In that case the certificate will still be treated as allowed.
163 if (callback_.is_null()) 169 if (callback_.is_null())
164 return; 170 return;
165 171
166 callback_.Run(handler_, false); 172 callback_.Run(handler_, false);
(...skipping 16 matching lines...) Expand all
183 "moreInfo1", "moreInfo2", "moreInfo3", "moreInfo4", "moreInfo5" 189 "moreInfo1", "moreInfo2", "moreInfo3", "moreInfo4", "moreInfo5"
184 }; 190 };
185 int i; 191 int i;
186 for (i = 0; i < static_cast<int>(extra_info.size()); i++) { 192 for (i = 0; i < static_cast<int>(extra_info.size()); i++) {
187 strings->SetString(keys[i], extra_info[i]); 193 strings->SetString(keys[i], extra_info[i]);
188 } 194 }
189 for (; i < 5; i++) { 195 for (; i < 5; i++) {
190 strings->SetString(keys[i], ""); 196 strings->SetString(keys[i], "");
191 } 197 }
192 } 198 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698