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_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, |
77 UNUSED_BLOCKING_PAGE_EVENT, | 84 UNDERSTAND, |
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( |
87 bool proceed, | 95 bool proceed, |
(...skipping 49 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 std::string kCondition15Control = "Condition15SSLControl"; | |
agl
2013/05/01 18:54:12
static const char kFoo[] = "...";
felt
2013/05/01 19:39:45
Done.
| |
157 static const std::string kCondition16Firefox = "Condition16SSLFirefox"; | |
158 static const std::string kCondition17FancyFirefox = | |
159 "Condition17SSLFancyFirefox"; | |
160 static const std::string kCondition18NoImages = "Condition18SSLNoImages"; | |
161 static const std::string kCondition19Policeman = "Condition19SSLPoliceman"; | |
162 static const std::string kCondition20Stoplight = "Condition20SSLStoplight"; | |
163 static const std::string kCondition21BadGuy = "Condition21SSLBadGuy"; | |
164 | |
147 } // namespace | 165 } // namespace |
148 | 166 |
149 // Note that we always create a navigation entry with SSL errors. | 167 // Note that we always create a navigation entry with SSL errors. |
150 // No error happening loading a sub-resource triggers an interstitial so far. | 168 // No error happening loading a sub-resource triggers an interstitial so far. |
151 SSLBlockingPage::SSLBlockingPage( | 169 SSLBlockingPage::SSLBlockingPage( |
152 content::WebContents* web_contents, | 170 content::WebContents* web_contents, |
153 int cert_error, | 171 int cert_error, |
154 const net::SSLInfo& ssl_info, | 172 const net::SSLInfo& ssl_info, |
155 const GURL& request_url, | 173 const GURL& request_url, |
156 bool overridable, | 174 bool overridable, |
157 bool strict_enforcement, | 175 bool strict_enforcement, |
158 const base::Callback<void(bool)>& callback) | 176 const base::Callback<void(bool)>& callback) |
159 : callback_(callback), | 177 : callback_(callback), |
160 web_contents_(web_contents), | 178 web_contents_(web_contents), |
161 cert_error_(cert_error), | 179 cert_error_(cert_error), |
162 ssl_info_(ssl_info), | 180 ssl_info_(ssl_info), |
163 request_url_(request_url), | 181 request_url_(request_url), |
164 overridable_(overridable), | 182 overridable_(overridable), |
165 strict_enforcement_(strict_enforcement) { | 183 strict_enforcement_(strict_enforcement) { |
184 | |
185 // Only assign to a group if the warning can be clicked through. | |
186 trial_ = ""; | |
agl
2013/05/01 18:54:12
doesn't need to be initially cleared.
felt
2013/05/01 19:39:45
Done.
| |
187 if (overridable_ && !strict_enforcement_) | |
188 trial_ = base::FieldTrialList::FindFullName("InterstitialSSL"); | |
189 | |
166 RecordSSLBlockingPageEventStats(SHOW_ALL); | 190 RecordSSLBlockingPageEventStats(SHOW_ALL); |
167 if (overridable_ && !strict_enforcement_) | 191 if (overridable_ && !strict_enforcement_) |
168 RecordSSLBlockingPageEventStats(SHOW_OVERRIDABLE); | 192 RecordSSLBlockingPageEventStats(SHOW_OVERRIDABLE); |
169 | 193 |
170 interstitial_page_ = InterstitialPage::Create( | 194 interstitial_page_ = InterstitialPage::Create( |
171 web_contents_, true, request_url, this); | 195 web_contents_, true, request_url, this); |
172 display_start_time_ = TimeTicks(); | 196 display_start_time_ = TimeTicks(); |
173 interstitial_page_->Show(); | 197 interstitial_page_->Show(); |
174 } | 198 } |
175 | 199 |
176 SSLBlockingPage::~SSLBlockingPage() { | 200 SSLBlockingPage::~SSLBlockingPage() { |
177 if (!callback_.is_null()) { | 201 if (!callback_.is_null()) { |
202 RecordSSLBlockingPageTimeStats(false, cert_error_, | |
203 overridable_ && !strict_enforcement_, display_start_time_, | |
204 base::TimeTicks::Now()); | |
178 // The page is closed without the user having chosen what to do, default to | 205 // The page is closed without the user having chosen what to do, default to |
179 // deny. | 206 // deny. |
180 NotifyDenyCertificate(); | 207 NotifyDenyCertificate(); |
181 } | 208 } |
182 } | 209 } |
183 | 210 |
184 std::string SSLBlockingPage::GetHTMLContents() { | 211 std::string SSLBlockingPage::GetHTMLContents() { |
185 // Let's build the html error page. | 212 // Let's build the html error page. |
186 DictionaryValue strings; | 213 DictionaryValue strings; |
187 SSLErrorInfo error_info = SSLErrorInfo::CreateError( | 214 SSLErrorInfo error_info = SSLErrorInfo::CreateError( |
188 SSLErrorInfo::NetErrorToErrorType(cert_error_), ssl_info_.cert, | 215 SSLErrorInfo::NetErrorToErrorType(cert_error_), ssl_info_.cert, |
189 request_url_); | 216 request_url_); |
190 | 217 |
218 int resource_id = IDR_SSL_ROAD_BLOCK_HTML; | |
191 strings.SetString("headLine", error_info.title()); | 219 strings.SetString("headLine", error_info.title()); |
192 strings.SetString("description", error_info.details()); | 220 strings.SetString("description", error_info.details()); |
193 strings.SetString("moreInfoTitle", | 221 strings.SetString("moreInfoTitle", |
194 l10n_util::GetStringUTF16(IDS_CERT_ERROR_EXTRA_INFO_TITLE)); | 222 l10n_util::GetStringUTF16(IDS_CERT_ERROR_EXTRA_INFO_TITLE)); |
195 SetExtraInfo(&strings, error_info.extra_information()); | 223 SetExtraInfo(&strings, error_info.extra_information()); |
196 | 224 |
197 strings.SetString("exit", | 225 strings.SetString("exit", |
198 l10n_util::GetStringUTF16(IDS_SSL_BLOCKING_PAGE_EXIT)); | 226 l10n_util::GetStringUTF16(IDS_SSL_BLOCKING_PAGE_EXIT)); |
199 | 227 |
200 int resource_id = IDR_SSL_ROAD_BLOCK_HTML; | |
201 if (overridable_ && !strict_enforcement_) { | 228 if (overridable_ && !strict_enforcement_) { |
202 strings.SetString("title", | 229 strings.SetString("title", |
203 l10n_util::GetStringUTF16(IDS_SSL_BLOCKING_PAGE_TITLE)); | 230 l10n_util::GetStringUTF16(IDS_SSL_BLOCKING_PAGE_TITLE)); |
204 strings.SetString("proceed", | 231 strings.SetString("proceed", |
205 l10n_util::GetStringUTF16(IDS_SSL_BLOCKING_PAGE_PROCEED)); | 232 l10n_util::GetStringUTF16(IDS_SSL_BLOCKING_PAGE_PROCEED)); |
206 strings.SetString("reasonForNotProceeding", | 233 strings.SetString("reasonForNotProceeding", |
207 l10n_util::GetStringUTF16( | 234 l10n_util::GetStringUTF16( |
208 IDS_SSL_BLOCKING_PAGE_SHOULD_NOT_PROCEED)); | 235 IDS_SSL_BLOCKING_PAGE_SHOULD_NOT_PROCEED)); |
209 // The value of errorType doesn't matter; we actually just check if it's | 236 // The value of errorType doesn't matter; we actually just check if it's |
210 // empty or not in ssl_roadblock. | 237 // empty or not in ssl_roadblock. |
211 strings.SetString("errorType", | 238 strings.SetString("errorType", |
212 l10n_util::GetStringUTF16(IDS_SSL_BLOCKING_PAGE_TITLE)); | 239 l10n_util::GetStringUTF16(IDS_SSL_BLOCKING_PAGE_TITLE)); |
213 } else { | 240 } else { |
214 strings.SetString("title", | 241 strings.SetString("title", |
215 l10n_util::GetStringUTF16(IDS_SSL_ERROR_PAGE_TITLE)); | 242 l10n_util::GetStringUTF16(IDS_SSL_ERROR_PAGE_TITLE)); |
216 if (strict_enforcement_) { | 243 if (strict_enforcement_) { |
217 strings.SetString("reasonForNotProceeding", | 244 strings.SetString("reasonForNotProceeding", |
218 l10n_util::GetStringUTF16( | 245 l10n_util::GetStringUTF16( |
219 IDS_SSL_ERROR_PAGE_CANNOT_PROCEED)); | 246 IDS_SSL_ERROR_PAGE_CANNOT_PROCEED)); |
220 } else { | 247 } else { |
221 strings.SetString("reasonForNotProceeding", std::string()); | 248 strings.SetString("reasonForNotProceeding", std::string()); |
222 } | 249 } |
223 strings.SetString("errorType", std::string()); | 250 strings.SetString("errorType", std::string()); |
224 } | 251 } |
225 | 252 |
226 strings.SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); | 253 strings.SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); |
227 | 254 |
255 // Set up the Finch trial layouts. | |
256 strings.SetString("trialType", trial_); | |
257 if (trial_ == kCondition16Firefox || trial_ == kCondition17FancyFirefox) { | |
258 strings.SetString("domain", request_url_.host()); | |
259 std::string font_family = l10n_util::GetStringUTF8(IDS_WEB_FONT_FAMILY); | |
260 #if defined(OS_WIN) | |
261 if (base::win::GetVersion() < base::win::VERSION_VISTA) | |
262 font_family = l10n_util::GetStringUTF8(IDS_WEB_FONT_FAMILY_XP); | |
263 #endif | |
264 #if defined(TOOLKIT_GTK) | |
265 font_family = ui::ResourceBundle::GetSharedInstance().GetFont( | |
266 ui::ResourceBundle::BaseFont).GetFontName() + ", " + font_family; | |
267 #endif | |
268 strings.SetString("fontfamily", font_family); | |
269 if (trial_ == kCondition16Firefox) | |
agl
2013/05/01 18:54:12
braces needed I think.
felt
2013/05/01 19:39:45
Done.
felt
2013/05/01 19:39:45
Done.
| |
270 resource_id = IDR_SSL_FIREFOX_HTML; | |
271 else if (trial_ == kCondition17FancyFirefox) | |
272 resource_id = IDR_SSL_FANCY_FIREFOX_HTML; | |
273 } | |
274 | |
228 base::StringPiece html( | 275 base::StringPiece html( |
229 ResourceBundle::GetSharedInstance().GetRawDataResource( | 276 ResourceBundle::GetSharedInstance().GetRawDataResource( |
230 resource_id)); | 277 resource_id)); |
231 | 278 |
232 return webui::GetI18nTemplateHtml(html, &strings); | 279 return webui::GetI18nTemplateHtml(html, &strings); |
233 } | 280 } |
234 | 281 |
235 void SSLBlockingPage::OverrideEntry(NavigationEntry* entry) { | 282 void SSLBlockingPage::OverrideEntry(NavigationEntry* entry) { |
236 int cert_id = content::CertStore::GetInstance()->StoreCert( | 283 int cert_id = content::CertStore::GetInstance()->StoreCert( |
237 ssl_info_.cert, web_contents_->GetRenderProcessHost()->GetID()); | 284 ssl_info_.cert, web_contents_->GetRenderProcessHost()->GetID()); |
(...skipping 15 matching lines...) Expand all Loading... | |
253 int cmd = atoi(command.c_str()); | 300 int cmd = atoi(command.c_str()); |
254 if (cmd == CMD_DONT_PROCEED) { | 301 if (cmd == CMD_DONT_PROCEED) { |
255 interstitial_page_->DontProceed(); | 302 interstitial_page_->DontProceed(); |
256 } else if (cmd == CMD_PROCEED) { | 303 } else if (cmd == CMD_PROCEED) { |
257 interstitial_page_->Proceed(); | 304 interstitial_page_->Proceed(); |
258 } else if (cmd == CMD_FOCUS) { | 305 } else if (cmd == CMD_FOCUS) { |
259 // Start recording the time when the page is first in focus | 306 // Start recording the time when the page is first in focus |
260 display_start_time_ = base::TimeTicks::Now(); | 307 display_start_time_ = base::TimeTicks::Now(); |
261 } else if (cmd == CMD_MORE) { | 308 } else if (cmd == CMD_MORE) { |
262 RecordSSLBlockingPageEventStats(MORE); | 309 RecordSSLBlockingPageEventStats(MORE); |
310 } else if (cmd == CMD_UNDERSTAND) { | |
311 // Used in the Finch experiment. | |
312 RecordSSLBlockingPageEventStats(UNDERSTAND); | |
263 } | 313 } |
264 } | 314 } |
265 | 315 |
266 void SSLBlockingPage::OverrideRendererPrefs( | 316 void SSLBlockingPage::OverrideRendererPrefs( |
267 content::RendererPreferences* prefs) { | 317 content::RendererPreferences* prefs) { |
268 Profile* profile = Profile::FromBrowserContext( | 318 Profile* profile = Profile::FromBrowserContext( |
269 web_contents_->GetBrowserContext()); | 319 web_contents_->GetBrowserContext()); |
270 renderer_preferences_util::UpdateFromSystemSettings(prefs, profile); | 320 renderer_preferences_util::UpdateFromSystemSettings(prefs, profile); |
271 } | 321 } |
272 | 322 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 "moreInfo1", "moreInfo2", "moreInfo3", "moreInfo4", "moreInfo5" | 364 "moreInfo1", "moreInfo2", "moreInfo3", "moreInfo4", "moreInfo5" |
315 }; | 365 }; |
316 int i; | 366 int i; |
317 for (i = 0; i < static_cast<int>(extra_info.size()); i++) { | 367 for (i = 0; i < static_cast<int>(extra_info.size()); i++) { |
318 strings->SetString(keys[i], extra_info[i]); | 368 strings->SetString(keys[i], extra_info[i]); |
319 } | 369 } |
320 for (; i < 5; i++) { | 370 for (; i < 5; i++) { |
321 strings->SetString(keys[i], std::string()); | 371 strings->SetString(keys[i], std::string()); |
322 } | 372 } |
323 } | 373 } |
OLD | NEW |