OLD | NEW |
---|---|
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/field_trial.h" | |
8 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
9 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
10 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
11 #include "base/values.h" | 12 #include "base/values.h" |
12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/renderer_preferences_util.h" | 14 #include "chrome/browser/renderer_preferences_util.h" |
14 #include "chrome/browser/ssl/ssl_error_info.h" | 15 #include "chrome/browser/ssl/ssl_error_info.h" |
15 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/browser_finder.h" | 17 #include "chrome/browser/ui/browser_finder.h" |
17 #include "content/public/browser/cert_store.h" | 18 #include "content/public/browser/cert_store.h" |
18 #include "content/public/browser/interstitial_page.h" | 19 #include "content/public/browser/interstitial_page.h" |
19 #include "content/public/browser/navigation_controller.h" | 20 #include "content/public/browser/navigation_controller.h" |
20 #include "content/public/browser/navigation_entry.h" | 21 #include "content/public/browser/navigation_entry.h" |
21 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
22 #include "content/public/browser/notification_types.h" | 23 #include "content/public/browser/notification_types.h" |
23 #include "content/public/browser/render_process_host.h" | 24 #include "content/public/browser/render_process_host.h" |
24 #include "content/public/browser/render_view_host.h" | 25 #include "content/public/browser/render_view_host.h" |
25 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
26 #include "content/public/common/ssl_status.h" | 27 #include "content/public/common/ssl_status.h" |
28 #include "grit/app_locale_settings.h" | |
27 #include "grit/browser_resources.h" | 29 #include "grit/browser_resources.h" |
28 #include "grit/generated_resources.h" | 30 #include "grit/generated_resources.h" |
29 #include "net/base/net_errors.h" | 31 #include "net/base/net_errors.h" |
30 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
31 #include "ui/base/resource/resource_bundle.h" | 33 #include "ui/base/resource/resource_bundle.h" |
32 #include "ui/webui/jstemplate_builder.h" | 34 #include "ui/webui/jstemplate_builder.h" |
33 | 35 |
36 #if defined(OS_WIN) | |
37 #include "base/win/windows_version.h" | |
38 #endif | |
39 | |
34 using base::TimeDelta; | 40 using base::TimeDelta; |
35 using base::TimeTicks; | 41 using base::TimeTicks; |
36 using content::InterstitialPage; | 42 using content::InterstitialPage; |
37 using content::NavigationController; | 43 using content::NavigationController; |
38 using content::NavigationEntry; | 44 using content::NavigationEntry; |
39 | 45 |
40 #define HISTOGRAM_INTERSTITIAL_SMALL_TIME(name, sample) \ | 46 #define HISTOGRAM_INTERSTITIAL_SMALL_TIME(name, sample) \ |
41 UMA_HISTOGRAM_CUSTOM_TIMES( \ | 47 UMA_HISTOGRAM_CUSTOM_TIMES( \ |
42 name, \ | 48 name, \ |
43 sample, \ | 49 sample, \ |
44 base::TimeDelta::FromMilliseconds(400), \ | 50 base::TimeDelta::FromMilliseconds(400), \ |
45 base::TimeDelta::FromMinutes(15), 75); | 51 base::TimeDelta::FromMinutes(15), 75); |
46 | 52 |
47 #define HISTOGRAM_INTERSTITIAL_LARGE_TIME(name, sample) \ | 53 #define HISTOGRAM_INTERSTITIAL_LARGE_TIME(name, sample) \ |
48 UMA_HISTOGRAM_CUSTOM_TIMES( \ | 54 UMA_HISTOGRAM_CUSTOM_TIMES( \ |
49 name, \ | 55 name, \ |
50 sample, \ | 56 sample, \ |
51 base::TimeDelta::FromMilliseconds(400), \ | 57 base::TimeDelta::FromMilliseconds(400), \ |
52 base::TimeDelta::FromMinutes(20), 50); | 58 base::TimeDelta::FromMinutes(20), 50); |
53 | 59 |
54 namespace { | 60 namespace { |
55 | 61 |
56 // These represent the commands sent by ssl_roadblock.html. | 62 // These represent the commands sent by ssl_roadblock.html. |
57 enum SSLBlockingPageCommands { | 63 enum SSLBlockingPageCommands { |
58 CMD_DONT_PROCEED, | 64 CMD_DONT_PROCEED, |
59 CMD_PROCEED, | 65 CMD_PROCEED, |
60 CMD_FOCUS, | 66 CMD_FOCUS, |
61 CMD_MORE, | 67 CMD_MORE, |
68 CMD_SHOW_UNDERSTAND, // Used by the Finch trial. | |
62 }; | 69 }; |
63 | 70 |
64 // Events for UMA. | 71 // Events for UMA. |
65 enum SSLBlockingPageEvent { | 72 enum SSLBlockingPageEvent { |
66 SHOW_ALL, | 73 SHOW_ALL, |
67 SHOW_OVERRIDABLE, | 74 SHOW_OVERRIDABLE, |
68 PROCEED_OVERRIDABLE, | 75 PROCEED_OVERRIDABLE, |
69 PROCEED_NAME, | 76 PROCEED_NAME, |
70 PROCEED_DATE, | 77 PROCEED_DATE, |
71 PROCEED_AUTHORITY, | 78 PROCEED_AUTHORITY, |
72 DONT_PROCEED_OVERRIDABLE, | 79 DONT_PROCEED_OVERRIDABLE, |
73 DONT_PROCEED_NAME, | 80 DONT_PROCEED_NAME, |
74 DONT_PROCEED_DATE, | 81 DONT_PROCEED_DATE, |
75 DONT_PROCEED_AUTHORITY, | 82 DONT_PROCEED_AUTHORITY, |
76 MORE, | 83 MORE, |
84 SHOW_UNDERSTAND, | |
77 UNUSED_BLOCKING_PAGE_EVENT, | 85 UNUSED_BLOCKING_PAGE_EVENT, |
78 }; | 86 }; |
79 | 87 |
80 void RecordSSLBlockingPageEventStats(SSLBlockingPageEvent event) { | 88 void RecordSSLBlockingPageEventStats(SSLBlockingPageEvent event) { |
81 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl", | 89 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl", |
82 event, | 90 event, |
83 UNUSED_BLOCKING_PAGE_EVENT); | 91 UNUSED_BLOCKING_PAGE_EVENT); |
84 } | 92 } |
85 | 93 |
86 void RecordSSLBlockingPageTimeStats( | 94 void RecordSSLBlockingPageTimeStats( |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 else | 145 else |
138 RecordSSLBlockingPageEventStats(DONT_PROCEED_AUTHORITY); | 146 RecordSSLBlockingPageEventStats(DONT_PROCEED_AUTHORITY); |
139 break; | 147 break; |
140 } | 148 } |
141 default: { | 149 default: { |
142 break; | 150 break; |
143 } | 151 } |
144 } | 152 } |
145 } | 153 } |
146 | 154 |
155 // These are the conditions for the Finch experiment. | |
156 static const char kCondition15Control[] = "Condition15SSLControl"; | |
James Hawkins
2013/05/03 18:31:55
Remove 'static' in unnamed namespace.
felt
2013/05/03 18:43:25
Done.
| |
157 static const char kCondition16Firefox[] = "Condition16SSLFirefox"; | |
158 static const char kCondition17FancyFirefox[] = "Condition17SSLFancyFirefox"; | |
159 static const char kCondition18NoImages[] = "Condition18SSLNoImages"; | |
160 | |
147 } // namespace | 161 } // namespace |
148 | 162 |
149 // Note that we always create a navigation entry with SSL errors. | 163 // Note that we always create a navigation entry with SSL errors. |
150 // No error happening loading a sub-resource triggers an interstitial so far. | 164 // No error happening loading a sub-resource triggers an interstitial so far. |
151 SSLBlockingPage::SSLBlockingPage( | 165 SSLBlockingPage::SSLBlockingPage( |
152 content::WebContents* web_contents, | 166 content::WebContents* web_contents, |
153 int cert_error, | 167 int cert_error, |
154 const net::SSLInfo& ssl_info, | 168 const net::SSLInfo& ssl_info, |
155 const GURL& request_url, | 169 const GURL& request_url, |
156 bool overridable, | 170 bool overridable, |
157 bool strict_enforcement, | 171 bool strict_enforcement, |
158 const base::Callback<void(bool)>& callback) | 172 const base::Callback<void(bool)>& callback) |
159 : callback_(callback), | 173 : callback_(callback), |
160 web_contents_(web_contents), | 174 web_contents_(web_contents), |
161 cert_error_(cert_error), | 175 cert_error_(cert_error), |
162 ssl_info_(ssl_info), | 176 ssl_info_(ssl_info), |
163 request_url_(request_url), | 177 request_url_(request_url), |
164 overridable_(overridable), | 178 overridable_(overridable), |
165 strict_enforcement_(strict_enforcement) { | 179 strict_enforcement_(strict_enforcement) { |
180 | |
James Hawkins
2013/05/03 18:31:55
nit: Remove blank line.
felt
2013/05/03 18:43:25
Done.
| |
181 trialCondition_ = base::FieldTrialList::FindFullName("InterstitialSSL517"); | |
James Hawkins
2013/05/03 18:31:55
Shouldn't this string be in a const var?
felt
2013/05/03 18:43:25
Done. Also did the same for safe browsing file.
| |
182 | |
166 RecordSSLBlockingPageEventStats(SHOW_ALL); | 183 RecordSSLBlockingPageEventStats(SHOW_ALL); |
167 if (overridable_ && !strict_enforcement_) | 184 if (overridable_ && !strict_enforcement_) |
168 RecordSSLBlockingPageEventStats(SHOW_OVERRIDABLE); | 185 RecordSSLBlockingPageEventStats(SHOW_OVERRIDABLE); |
169 | 186 |
170 interstitial_page_ = InterstitialPage::Create( | 187 interstitial_page_ = InterstitialPage::Create( |
171 web_contents_, true, request_url, this); | 188 web_contents_, true, request_url, this); |
172 display_start_time_ = TimeTicks(); | 189 display_start_time_ = TimeTicks(); |
173 interstitial_page_->Show(); | 190 interstitial_page_->Show(); |
174 } | 191 } |
175 | 192 |
176 SSLBlockingPage::~SSLBlockingPage() { | 193 SSLBlockingPage::~SSLBlockingPage() { |
177 if (!callback_.is_null()) { | 194 if (!callback_.is_null()) { |
195 RecordSSLBlockingPageTimeStats(false, cert_error_, | |
James Hawkins
2013/05/03 18:31:55
nit: Start of parameter rows must align on the sam
felt
2013/05/03 18:43:25
Done.
| |
196 overridable_ && !strict_enforcement_, display_start_time_, | |
197 base::TimeTicks::Now()); | |
178 // The page is closed without the user having chosen what to do, default to | 198 // The page is closed without the user having chosen what to do, default to |
179 // deny. | 199 // deny. |
180 NotifyDenyCertificate(); | 200 NotifyDenyCertificate(); |
181 } | 201 } |
182 } | 202 } |
183 | 203 |
184 std::string SSLBlockingPage::GetHTMLContents() { | 204 std::string SSLBlockingPage::GetHTMLContents() { |
185 // Let's build the html error page. | 205 // Let's build the html error page. |
186 DictionaryValue strings; | 206 DictionaryValue strings; |
187 SSLErrorInfo error_info = SSLErrorInfo::CreateError( | 207 SSLErrorInfo error_info = SSLErrorInfo::CreateError( |
188 SSLErrorInfo::NetErrorToErrorType(cert_error_), ssl_info_.cert, | 208 SSLErrorInfo::NetErrorToErrorType(cert_error_), ssl_info_.cert, |
189 request_url_); | 209 request_url_); |
190 | 210 |
211 int resource_id = IDR_SSL_ROAD_BLOCK_HTML; | |
191 strings.SetString("headLine", error_info.title()); | 212 strings.SetString("headLine", error_info.title()); |
192 strings.SetString("description", error_info.details()); | 213 strings.SetString("description", error_info.details()); |
193 strings.SetString("moreInfoTitle", | 214 strings.SetString("moreInfoTitle", |
194 l10n_util::GetStringUTF16(IDS_CERT_ERROR_EXTRA_INFO_TITLE)); | 215 l10n_util::GetStringUTF16(IDS_CERT_ERROR_EXTRA_INFO_TITLE)); |
195 SetExtraInfo(&strings, error_info.extra_information()); | 216 SetExtraInfo(&strings, error_info.extra_information()); |
196 | 217 |
197 strings.SetString("exit", | 218 strings.SetString("exit", |
198 l10n_util::GetStringUTF16(IDS_SSL_BLOCKING_PAGE_EXIT)); | 219 l10n_util::GetStringUTF16(IDS_SSL_BLOCKING_PAGE_EXIT)); |
199 | 220 |
200 int resource_id = IDR_SSL_ROAD_BLOCK_HTML; | |
201 if (overridable_ && !strict_enforcement_) { | 221 if (overridable_ && !strict_enforcement_) { |
202 strings.SetString("title", | 222 strings.SetString("title", |
203 l10n_util::GetStringUTF16(IDS_SSL_BLOCKING_PAGE_TITLE)); | 223 l10n_util::GetStringUTF16(IDS_SSL_BLOCKING_PAGE_TITLE)); |
204 strings.SetString("proceed", | 224 strings.SetString("proceed", |
205 l10n_util::GetStringUTF16(IDS_SSL_BLOCKING_PAGE_PROCEED)); | 225 l10n_util::GetStringUTF16(IDS_SSL_BLOCKING_PAGE_PROCEED)); |
206 strings.SetString("reasonForNotProceeding", | 226 strings.SetString("reasonForNotProceeding", |
207 l10n_util::GetStringUTF16( | 227 l10n_util::GetStringUTF16( |
208 IDS_SSL_BLOCKING_PAGE_SHOULD_NOT_PROCEED)); | 228 IDS_SSL_BLOCKING_PAGE_SHOULD_NOT_PROCEED)); |
209 // The value of errorType doesn't matter; we actually just check if it's | 229 strings.SetString("errorType", "overridable")); |
210 // empty or not in ssl_roadblock. | |
211 strings.SetString("errorType", | |
212 l10n_util::GetStringUTF16(IDS_SSL_BLOCKING_PAGE_TITLE)); | |
213 } else { | 230 } else { |
214 strings.SetString("title", | 231 strings.SetString("title", |
215 l10n_util::GetStringUTF16(IDS_SSL_ERROR_PAGE_TITLE)); | 232 l10n_util::GetStringUTF16(IDS_SSL_ERROR_PAGE_TITLE)); |
216 if (strict_enforcement_) { | 233 if (strict_enforcement_) { |
217 strings.SetString("reasonForNotProceeding", | 234 strings.SetString("reasonForNotProceeding", |
218 l10n_util::GetStringUTF16( | 235 l10n_util::GetStringUTF16( |
219 IDS_SSL_ERROR_PAGE_CANNOT_PROCEED)); | 236 IDS_SSL_ERROR_PAGE_CANNOT_PROCEED)); |
220 } else { | 237 } else { |
221 strings.SetString("reasonForNotProceeding", std::string()); | 238 strings.SetString("reasonForNotProceeding", std::string()); |
222 } | 239 } |
223 strings.SetString("errorType", std::string()); | 240 strings.SetString("errorType", "notoverridable")); |
224 } | 241 } |
225 | 242 |
226 strings.SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); | 243 strings.SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); |
227 | 244 |
245 // Set up the Finch trial layouts. | |
246 strings.SetString("trialType", trialCondition_); | |
247 if (trialCondition_ == kCondition16Firefox || | |
248 trialCondition_ == kCondition17FancyFirefox || | |
249 trialCondition_ = kCondition18NoImages) { | |
250 strings.SetString("domain", request_url_.host()); | |
251 std::string font_family = l10n_util::GetStringUTF8(IDS_WEB_FONT_FAMILY); | |
252 #if defined(OS_WIN) | |
253 if (base::win::GetVersion() < base::win::VERSION_VISTA) { | |
254 font_family = l10n_util::GetStringUTF8(IDS_WEB_FONT_FAMILY_XP); | |
255 } | |
256 #endif | |
257 #if defined(TOOLKIT_GTK) | |
258 font_family = ui::ResourceBundle::GetSharedInstance().GetFont( | |
259 ui::ResourceBundle::BaseFont).GetFontName() + ", " + font_family; | |
260 #endif | |
261 strings.SetString("fontfamily", font_family); | |
262 if (trialCondition_ == kCondition16Firefox || | |
263 trialCondition_ = kCondition18NoImages) { | |
264 resource_id = IDR_SSL_FIREFOX_HTML; | |
265 } else if (trialCondition_ == kCondition17FancyFirefox) { | |
266 resource_id = IDR_SSL_FANCY_FIREFOX_HTML; | |
267 } | |
268 } | |
269 | |
228 base::StringPiece html( | 270 base::StringPiece html( |
229 ResourceBundle::GetSharedInstance().GetRawDataResource( | 271 ResourceBundle::GetSharedInstance().GetRawDataResource( |
230 resource_id)); | 272 resource_id)); |
231 | 273 |
232 return webui::GetI18nTemplateHtml(html, &strings); | 274 return webui::GetI18nTemplateHtml(html, &strings); |
233 } | 275 } |
234 | 276 |
235 void SSLBlockingPage::OverrideEntry(NavigationEntry* entry) { | 277 void SSLBlockingPage::OverrideEntry(NavigationEntry* entry) { |
236 int cert_id = content::CertStore::GetInstance()->StoreCert( | 278 int cert_id = content::CertStore::GetInstance()->StoreCert( |
237 ssl_info_.cert, web_contents_->GetRenderProcessHost()->GetID()); | 279 ssl_info_.cert, web_contents_->GetRenderProcessHost()->GetID()); |
(...skipping 15 matching lines...) Expand all Loading... | |
253 int cmd = atoi(command.c_str()); | 295 int cmd = atoi(command.c_str()); |
254 if (cmd == CMD_DONT_PROCEED) { | 296 if (cmd == CMD_DONT_PROCEED) { |
255 interstitial_page_->DontProceed(); | 297 interstitial_page_->DontProceed(); |
256 } else if (cmd == CMD_PROCEED) { | 298 } else if (cmd == CMD_PROCEED) { |
257 interstitial_page_->Proceed(); | 299 interstitial_page_->Proceed(); |
258 } else if (cmd == CMD_FOCUS) { | 300 } else if (cmd == CMD_FOCUS) { |
259 // Start recording the time when the page is first in focus | 301 // Start recording the time when the page is first in focus |
260 display_start_time_ = base::TimeTicks::Now(); | 302 display_start_time_ = base::TimeTicks::Now(); |
261 } else if (cmd == CMD_MORE) { | 303 } else if (cmd == CMD_MORE) { |
262 RecordSSLBlockingPageEventStats(MORE); | 304 RecordSSLBlockingPageEventStats(MORE); |
305 } else if (cmd == CMD_SHOW_UNDERSTAND) { | |
306 // Used in the Finch experiment. | |
307 RecordSSLBlockingPageEventStats(SHOW_UNDERSTAND); | |
263 } | 308 } |
264 } | 309 } |
265 | 310 |
266 void SSLBlockingPage::OverrideRendererPrefs( | 311 void SSLBlockingPage::OverrideRendererPrefs( |
267 content::RendererPreferences* prefs) { | 312 content::RendererPreferences* prefs) { |
268 Profile* profile = Profile::FromBrowserContext( | 313 Profile* profile = Profile::FromBrowserContext( |
269 web_contents_->GetBrowserContext()); | 314 web_contents_->GetBrowserContext()); |
270 renderer_preferences_util::UpdateFromSystemSettings(prefs, profile); | 315 renderer_preferences_util::UpdateFromSystemSettings(prefs, profile); |
271 } | 316 } |
272 | 317 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 "moreInfo1", "moreInfo2", "moreInfo3", "moreInfo4", "moreInfo5" | 359 "moreInfo1", "moreInfo2", "moreInfo3", "moreInfo4", "moreInfo5" |
315 }; | 360 }; |
316 int i; | 361 int i; |
317 for (i = 0; i < static_cast<int>(extra_info.size()); i++) { | 362 for (i = 0; i < static_cast<int>(extra_info.size()); i++) { |
318 strings->SetString(keys[i], extra_info[i]); | 363 strings->SetString(keys[i], extra_info[i]); |
319 } | 364 } |
320 for (; i < 5; i++) { | 365 for (; i < 5; i++) { |
321 strings->SetString(keys[i], std::string()); | 366 strings->SetString(keys[i], std::string()); |
322 } | 367 } |
323 } | 368 } |
OLD | NEW |