Chromium Code Reviews| 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/01 23:21:45
static is unnecessary (and should not be used) in
| |
| 157 static const char kCondition16Firefox[] = "Condition16SSLFirefox"; | |
| 158 static const char kCondition17FancyFirefox[] = "Condition17SSLFancyFirefox"; | |
| 159 static const char kCondition18NoImages[] = "Condition18SSLNoImages"; | |
| 160 static const char kCondition19Policeman[] = "Condition19SSLPoliceman"; | |
| 161 static const char kCondition20Stoplight[] = "Condition20SSLStoplight"; | |
| 162 static const char kCondition21BadGuy[] = "Condition21SSLBadGuy"; | |
| 163 | |
| 147 } // namespace | 164 } // namespace |
| 148 | 165 |
| 149 // Note that we always create a navigation entry with SSL errors. | 166 // Note that we always create a navigation entry with SSL errors. |
| 150 // No error happening loading a sub-resource triggers an interstitial so far. | 167 // No error happening loading a sub-resource triggers an interstitial so far. |
| 151 SSLBlockingPage::SSLBlockingPage( | 168 SSLBlockingPage::SSLBlockingPage( |
| 152 content::WebContents* web_contents, | 169 content::WebContents* web_contents, |
| 153 int cert_error, | 170 int cert_error, |
| 154 const net::SSLInfo& ssl_info, | 171 const net::SSLInfo& ssl_info, |
| 155 const GURL& request_url, | 172 const GURL& request_url, |
| 156 bool overridable, | 173 bool overridable, |
| 157 bool strict_enforcement, | 174 bool strict_enforcement, |
| 158 const base::Callback<void(bool)>& callback) | 175 const base::Callback<void(bool)>& callback) |
| 159 : callback_(callback), | 176 : callback_(callback), |
| 160 web_contents_(web_contents), | 177 web_contents_(web_contents), |
| 161 cert_error_(cert_error), | 178 cert_error_(cert_error), |
| 162 ssl_info_(ssl_info), | 179 ssl_info_(ssl_info), |
| 163 request_url_(request_url), | 180 request_url_(request_url), |
| 164 overridable_(overridable), | 181 overridable_(overridable), |
| 165 strict_enforcement_(strict_enforcement) { | 182 strict_enforcement_(strict_enforcement) { |
| 183 | |
| 184 // Only assign to a group if the warning can be clicked through. | |
| 185 if (overridable_ && !strict_enforcement_) | |
| 186 trial_ = base::FieldTrialList::FindFullName("InterstitialSSL"); | |
| 187 | |
| 166 RecordSSLBlockingPageEventStats(SHOW_ALL); | 188 RecordSSLBlockingPageEventStats(SHOW_ALL); |
| 167 if (overridable_ && !strict_enforcement_) | 189 if (overridable_ && !strict_enforcement_) |
| 168 RecordSSLBlockingPageEventStats(SHOW_OVERRIDABLE); | 190 RecordSSLBlockingPageEventStats(SHOW_OVERRIDABLE); |
| 169 | 191 |
| 170 interstitial_page_ = InterstitialPage::Create( | 192 interstitial_page_ = InterstitialPage::Create( |
| 171 web_contents_, true, request_url, this); | 193 web_contents_, true, request_url, this); |
| 172 display_start_time_ = TimeTicks(); | 194 display_start_time_ = TimeTicks(); |
| 173 interstitial_page_->Show(); | 195 interstitial_page_->Show(); |
| 174 } | 196 } |
| 175 | 197 |
| 176 SSLBlockingPage::~SSLBlockingPage() { | 198 SSLBlockingPage::~SSLBlockingPage() { |
| 177 if (!callback_.is_null()) { | 199 if (!callback_.is_null()) { |
| 200 RecordSSLBlockingPageTimeStats(false, cert_error_, | |
| 201 overridable_ && !strict_enforcement_, display_start_time_, | |
| 202 base::TimeTicks::Now()); | |
| 178 // The page is closed without the user having chosen what to do, default to | 203 // The page is closed without the user having chosen what to do, default to |
| 179 // deny. | 204 // deny. |
| 180 NotifyDenyCertificate(); | 205 NotifyDenyCertificate(); |
| 181 } | 206 } |
| 182 } | 207 } |
| 183 | 208 |
| 184 std::string SSLBlockingPage::GetHTMLContents() { | 209 std::string SSLBlockingPage::GetHTMLContents() { |
| 185 // Let's build the html error page. | 210 // Let's build the html error page. |
| 186 DictionaryValue strings; | 211 DictionaryValue strings; |
| 187 SSLErrorInfo error_info = SSLErrorInfo::CreateError( | 212 SSLErrorInfo error_info = SSLErrorInfo::CreateError( |
| 188 SSLErrorInfo::NetErrorToErrorType(cert_error_), ssl_info_.cert, | 213 SSLErrorInfo::NetErrorToErrorType(cert_error_), ssl_info_.cert, |
| 189 request_url_); | 214 request_url_); |
| 190 | 215 |
| 216 int resource_id = IDR_SSL_ROAD_BLOCK_HTML; | |
|
James Hawkins
2013/05/01 23:21:45
static const int
felt
2013/05/02 16:07:12
I assign to this int later.
| |
| 191 strings.SetString("headLine", error_info.title()); | 217 strings.SetString("headLine", error_info.title()); |
| 192 strings.SetString("description", error_info.details()); | 218 strings.SetString("description", error_info.details()); |
| 193 strings.SetString("moreInfoTitle", | 219 strings.SetString("moreInfoTitle", |
| 194 l10n_util::GetStringUTF16(IDS_CERT_ERROR_EXTRA_INFO_TITLE)); | 220 l10n_util::GetStringUTF16(IDS_CERT_ERROR_EXTRA_INFO_TITLE)); |
| 195 SetExtraInfo(&strings, error_info.extra_information()); | 221 SetExtraInfo(&strings, error_info.extra_information()); |
| 196 | 222 |
| 197 strings.SetString("exit", | 223 strings.SetString("exit", |
| 198 l10n_util::GetStringUTF16(IDS_SSL_BLOCKING_PAGE_EXIT)); | 224 l10n_util::GetStringUTF16(IDS_SSL_BLOCKING_PAGE_EXIT)); |
| 199 | 225 |
| 200 int resource_id = IDR_SSL_ROAD_BLOCK_HTML; | |
| 201 if (overridable_ && !strict_enforcement_) { | 226 if (overridable_ && !strict_enforcement_) { |
| 202 strings.SetString("title", | 227 strings.SetString("title", |
| 203 l10n_util::GetStringUTF16(IDS_SSL_BLOCKING_PAGE_TITLE)); | 228 l10n_util::GetStringUTF16(IDS_SSL_BLOCKING_PAGE_TITLE)); |
| 204 strings.SetString("proceed", | 229 strings.SetString("proceed", |
| 205 l10n_util::GetStringUTF16(IDS_SSL_BLOCKING_PAGE_PROCEED)); | 230 l10n_util::GetStringUTF16(IDS_SSL_BLOCKING_PAGE_PROCEED)); |
| 206 strings.SetString("reasonForNotProceeding", | 231 strings.SetString("reasonForNotProceeding", |
| 207 l10n_util::GetStringUTF16( | 232 l10n_util::GetStringUTF16( |
| 208 IDS_SSL_BLOCKING_PAGE_SHOULD_NOT_PROCEED)); | 233 IDS_SSL_BLOCKING_PAGE_SHOULD_NOT_PROCEED)); |
| 209 // The value of errorType doesn't matter; we actually just check if it's | 234 // The value of errorType doesn't matter; we actually just check if it's |
| 210 // empty or not in ssl_roadblock. | 235 // empty or not in ssl_roadblock. |
| 211 strings.SetString("errorType", | 236 strings.SetString("errorType", |
| 212 l10n_util::GetStringUTF16(IDS_SSL_BLOCKING_PAGE_TITLE)); | 237 l10n_util::GetStringUTF16(IDS_SSL_BLOCKING_PAGE_TITLE)); |
| 213 } else { | 238 } else { |
| 214 strings.SetString("title", | 239 strings.SetString("title", |
| 215 l10n_util::GetStringUTF16(IDS_SSL_ERROR_PAGE_TITLE)); | 240 l10n_util::GetStringUTF16(IDS_SSL_ERROR_PAGE_TITLE)); |
| 216 if (strict_enforcement_) { | 241 if (strict_enforcement_) { |
| 217 strings.SetString("reasonForNotProceeding", | 242 strings.SetString("reasonForNotProceeding", |
| 218 l10n_util::GetStringUTF16( | 243 l10n_util::GetStringUTF16( |
| 219 IDS_SSL_ERROR_PAGE_CANNOT_PROCEED)); | 244 IDS_SSL_ERROR_PAGE_CANNOT_PROCEED)); |
| 220 } else { | 245 } else { |
| 221 strings.SetString("reasonForNotProceeding", std::string()); | 246 strings.SetString("reasonForNotProceeding", std::string()); |
| 222 } | 247 } |
| 223 strings.SetString("errorType", std::string()); | 248 strings.SetString("errorType", std::string()); |
| 224 } | 249 } |
| 225 | 250 |
| 226 strings.SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); | 251 strings.SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); |
| 227 | 252 |
| 253 // Set up the Finch trial layouts. | |
| 254 strings.SetString("trialType", trial_); | |
| 255 if (trial_ == kCondition16Firefox || trial_ == kCondition17FancyFirefox) { | |
| 256 strings.SetString("domain", request_url_.host()); | |
| 257 std::string font_family = l10n_util::GetStringUTF8(IDS_WEB_FONT_FAMILY); | |
| 258 #if defined(OS_WIN) | |
| 259 if (base::win::GetVersion() < base::win::VERSION_VISTA) { | |
| 260 font_family = l10n_util::GetStringUTF8(IDS_WEB_FONT_FAMILY_XP); | |
| 261 } | |
| 262 #endif | |
| 263 #if defined(TOOLKIT_GTK) | |
| 264 font_family = ui::ResourceBundle::GetSharedInstance().GetFont( | |
| 265 ui::ResourceBundle::BaseFont).GetFontName() + ", " + font_family; | |
| 266 #endif | |
| 267 strings.SetString("fontfamily", font_family); | |
| 268 if (trial_ == kCondition16Firefox) { | |
| 269 resource_id = IDR_SSL_FIREFOX_HTML; | |
| 270 } else if (trial_ == kCondition17FancyFirefox) { | |
| 271 resource_id = IDR_SSL_FANCY_FIREFOX_HTML; | |
| 272 } | |
| 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_SHOW_UNDERSTAND) { | |
| 311 // Used in the Finch experiment. | |
| 312 RecordSSLBlockingPageEventStats(SHOW_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 |