| 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 // Implementation of the SafeBrowsingBlockingPage class. | 5 // Implementation of the SafeBrowsingBlockingPage class. |
| 6 | 6 |
| 7 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" | 7 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
| 14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 15 #include "base/metrics/field_trial.h" | 15 #include "base/metrics/field_trial.h" |
| 16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 17 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
| 18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/strings/string_piece.h" | 19 #include "base/strings/string_piece.h" |
| 20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 22 #include "base/time/time.h" | 22 #include "base/time/time.h" |
| 23 #include "base/values.h" | 23 #include "base/values.h" |
| 24 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
| 25 #include "chrome/browser/history/history_service_factory.h" | |
| 26 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
| 27 #include "chrome/browser/renderer_preferences_util.h" | 26 #include "chrome/browser/renderer_preferences_util.h" |
| 28 #include "chrome/browser/safe_browsing/malware_details.h" | 27 #include "chrome/browser/safe_browsing/malware_details.h" |
| 29 #include "chrome/browser/safe_browsing/ui_manager.h" | 28 #include "chrome/browser/safe_browsing/ui_manager.h" |
| 30 #include "chrome/browser/tab_contents/tab_util.h" | 29 #include "chrome/browser/tab_contents/tab_util.h" |
| 31 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
| 32 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
| 33 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
| 34 #include "chrome/grit/generated_resources.h" | 33 #include "chrome/grit/generated_resources.h" |
| 35 #include "chrome/grit/locale_settings.h" | 34 #include "chrome/grit/locale_settings.h" |
| 36 #include "components/google/core/browser/google_util.h" | 35 #include "components/google/core/browser/google_util.h" |
| 37 #include "content/public/browser/browser_thread.h" | 36 #include "content/public/browser/browser_thread.h" |
| 38 #include "content/public/browser/interstitial_page.h" | 37 #include "content/public/browser/interstitial_page.h" |
| 39 #include "content/public/browser/navigation_controller.h" | 38 #include "content/public/browser/navigation_controller.h" |
| 40 #include "content/public/browser/user_metrics.h" | 39 #include "content/public/browser/user_metrics.h" |
| 41 #include "content/public/browser/web_contents.h" | 40 #include "content/public/browser/web_contents.h" |
| 42 #include "content/public/common/renderer_preferences.h" | 41 #include "content/public/common/renderer_preferences.h" |
| 43 #include "grit/browser_resources.h" | 42 #include "grit/browser_resources.h" |
| 44 #include "net/base/escape.h" | 43 #include "net/base/escape.h" |
| 45 #include "ui/base/l10n/l10n_util.h" | 44 #include "ui/base/l10n/l10n_util.h" |
| 46 | 45 |
| 47 #if defined(ENABLE_EXTENSIONS) | |
| 48 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s
ampling.h" | |
| 49 #endif | |
| 50 | |
| 51 using base::UserMetricsAction; | 46 using base::UserMetricsAction; |
| 52 using content::BrowserThread; | 47 using content::BrowserThread; |
| 53 using content::InterstitialPage; | 48 using content::InterstitialPage; |
| 54 using content::OpenURLParams; | 49 using content::OpenURLParams; |
| 55 using content::Referrer; | 50 using content::Referrer; |
| 56 using content::WebContents; | 51 using content::WebContents; |
| 57 | 52 |
| 58 #if defined(ENABLE_EXTENSIONS) | |
| 59 using extensions::ExperienceSamplingEvent; | |
| 60 #endif | |
| 61 | |
| 62 namespace { | 53 namespace { |
| 63 | 54 |
| 64 // For malware interstitial pages, we link the problematic URL to Google's | 55 // For malware interstitial pages, we link the problematic URL to Google's |
| 65 // diagnostic page. | 56 // diagnostic page. |
| 66 #if defined(GOOGLE_CHROME_BUILD) | 57 #if defined(GOOGLE_CHROME_BUILD) |
| 67 const char kSbDiagnosticUrl[] = | 58 const char kSbDiagnosticUrl[] = |
| 68 "http://safebrowsing.clients.google.com/safebrowsing/diagnostic?site=%s&clie
nt=googlechrome"; | 59 "http://safebrowsing.clients.google.com/safebrowsing/diagnostic?site=%s&clie
nt=googlechrome"; |
| 69 #else | 60 #else |
| 70 const char kSbDiagnosticUrl[] = | 61 const char kSbDiagnosticUrl[] = |
| 71 "http://safebrowsing.clients.google.com/safebrowsing/diagnostic?site=%s&clie
nt=chromium"; | 62 "http://safebrowsing.clients.google.com/safebrowsing/diagnostic?site=%s&clie
nt=chromium"; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 95 const char kProceedCommand[] = "proceed"; | 86 const char kProceedCommand[] = "proceed"; |
| 96 const char kShowDiagnosticCommand[] = "showDiagnostic"; | 87 const char kShowDiagnosticCommand[] = "showDiagnostic"; |
| 97 const char kShowPrivacyCommand[] = "showPrivacy"; | 88 const char kShowPrivacyCommand[] = "showPrivacy"; |
| 98 const char kTakeMeBackCommand[] = "takeMeBack"; | 89 const char kTakeMeBackCommand[] = "takeMeBack"; |
| 99 | 90 |
| 100 // Other constants used to communicate with the JavaScript. | 91 // Other constants used to communicate with the JavaScript. |
| 101 const char kBoxChecked[] = "boxchecked"; | 92 const char kBoxChecked[] = "boxchecked"; |
| 102 const char kDisplayCheckBox[] = "displaycheckbox"; | 93 const char kDisplayCheckBox[] = "displaycheckbox"; |
| 103 | 94 |
| 104 // Constants for the Experience Sampling instrumentation. | 95 // Constants for the Experience Sampling instrumentation. |
| 105 #if defined(ENABLE_EXTENSIONS) | |
| 106 const char kEventNameMalware[] = "safebrowsing_interstitial_"; | 96 const char kEventNameMalware[] = "safebrowsing_interstitial_"; |
| 107 const char kEventNameHarmful[] = "harmful_interstitial_"; | 97 const char kEventNameHarmful[] = "harmful_interstitial_"; |
| 108 const char kEventNamePhishing[] = "phishing_interstitial_"; | 98 const char kEventNamePhishing[] = "phishing_interstitial_"; |
| 109 const char kEventNameOther[] = "safebrowsing_other_interstitial_"; | 99 const char kEventNameOther[] = "safebrowsing_other_interstitial_"; |
| 110 #endif | |
| 111 | 100 |
| 112 base::LazyInstance<SafeBrowsingBlockingPage::UnsafeResourceMap> | 101 base::LazyInstance<SafeBrowsingBlockingPage::UnsafeResourceMap> |
| 113 g_unsafe_resource_map = LAZY_INSTANCE_INITIALIZER; | 102 g_unsafe_resource_map = LAZY_INSTANCE_INITIALIZER; |
| 114 | 103 |
| 115 } // namespace | 104 } // namespace |
| 116 | 105 |
| 117 // static | 106 // static |
| 118 SafeBrowsingBlockingPageFactory* SafeBrowsingBlockingPage::factory_ = NULL; | 107 SafeBrowsingBlockingPageFactory* SafeBrowsingBlockingPage::factory_ = NULL; |
| 119 | 108 |
| 120 // The default SafeBrowsingBlockingPageFactory. Global, made a singleton so we | 109 // The default SafeBrowsingBlockingPageFactory. Global, made a singleton so we |
| (...skipping 30 matching lines...) Expand all Loading... |
| 151 SafeBrowsingUIManager* ui_manager, | 140 SafeBrowsingUIManager* ui_manager, |
| 152 WebContents* web_contents, | 141 WebContents* web_contents, |
| 153 const UnsafeResourceList& unsafe_resources) | 142 const UnsafeResourceList& unsafe_resources) |
| 154 : SecurityInterstitialPage(web_contents, unsafe_resources[0].url), | 143 : SecurityInterstitialPage(web_contents, unsafe_resources[0].url), |
| 155 malware_details_proceed_delay_ms_( | 144 malware_details_proceed_delay_ms_( |
| 156 kMalwareDetailsProceedDelayMilliSeconds), | 145 kMalwareDetailsProceedDelayMilliSeconds), |
| 157 ui_manager_(ui_manager), | 146 ui_manager_(ui_manager), |
| 158 report_loop_(NULL), | 147 report_loop_(NULL), |
| 159 is_main_frame_load_blocked_(IsMainPageLoadBlocked(unsafe_resources)), | 148 is_main_frame_load_blocked_(IsMainPageLoadBlocked(unsafe_resources)), |
| 160 unsafe_resources_(unsafe_resources), | 149 unsafe_resources_(unsafe_resources), |
| 161 proceeded_(false), | 150 proceeded_(false) { |
| 162 num_visits_(-1) { | |
| 163 bool malware = false; | 151 bool malware = false; |
| 164 bool harmful = false; | 152 bool harmful = false; |
| 165 bool phishing = false; | 153 bool phishing = false; |
| 166 for (UnsafeResourceList::const_iterator iter = unsafe_resources_.begin(); | 154 for (UnsafeResourceList::const_iterator iter = unsafe_resources_.begin(); |
| 167 iter != unsafe_resources_.end(); ++iter) { | 155 iter != unsafe_resources_.end(); ++iter) { |
| 168 const UnsafeResource& resource = *iter; | 156 const UnsafeResource& resource = *iter; |
| 169 SBThreatType threat_type = resource.threat_type; | 157 SBThreatType threat_type = resource.threat_type; |
| 170 if (threat_type == SB_THREAT_TYPE_URL_MALWARE || | 158 if (threat_type == SB_THREAT_TYPE_URL_MALWARE || |
| 171 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL) { | 159 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL) { |
| 172 malware = true; | 160 malware = true; |
| 173 } else if (threat_type == SB_THREAT_TYPE_URL_UNWANTED) { | 161 } else if (threat_type == SB_THREAT_TYPE_URL_UNWANTED) { |
| 174 harmful = true; | 162 harmful = true; |
| 175 } else { | 163 } else { |
| 176 DCHECK(threat_type == SB_THREAT_TYPE_URL_PHISHING || | 164 DCHECK(threat_type == SB_THREAT_TYPE_URL_PHISHING || |
| 177 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL); | 165 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL); |
| 178 phishing = true; | 166 phishing = true; |
| 179 } | 167 } |
| 180 } | 168 } |
| 181 DCHECK(phishing || malware || harmful); | 169 DCHECK(phishing || malware || harmful); |
| 182 if (malware) | 170 if (malware) |
| 183 interstitial_type_ = TYPE_MALWARE; | 171 interstitial_reason_ = SB_REASON_MALWARE; |
| 184 else if (harmful) | 172 else if (harmful) |
| 185 interstitial_type_ = TYPE_HARMFUL; | 173 interstitial_reason_ = SB_REASON_HARMFUL; |
| 186 else | 174 else |
| 187 interstitial_type_ = TYPE_PHISHING; | 175 interstitial_reason_ = SB_REASON_PHISHING; |
| 188 | 176 |
| 189 RecordUserDecision(SHOW); | 177 // This must be done after calculating |interstitial_reason_| above. |
| 190 RecordUserInteraction(TOTAL_VISITS); | 178 uma_helper_.reset(new SecurityInterstitialUmaHelper( |
| 191 if (IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) | 179 web_contents, request_url(), |
| 192 RecordUserDecision(PROCEEDING_DISABLED); | 180 GetHistogramPrefix(), GetSamplingEventName())); |
| 193 | 181 uma_helper_->RecordUserDecision(SecurityInterstitialUmaHelper::SHOW); |
| 194 HistoryService* history_service = HistoryServiceFactory::GetForProfile( | 182 uma_helper_->RecordUserInteraction( |
| 195 Profile::FromBrowserContext(web_contents->GetBrowserContext()), | 183 SecurityInterstitialUmaHelper::TOTAL_VISITS); |
| 196 ServiceAccessType::EXPLICIT_ACCESS); | 184 if (IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) { |
| 197 if (history_service) { | 185 uma_helper_->RecordUserDecision( |
| 198 history_service->GetVisibleVisitCountToHost( | 186 SecurityInterstitialUmaHelper::PROCEEDING_DISABLED); |
| 199 request_url(), | |
| 200 base::Bind(&SafeBrowsingBlockingPage::OnGotHistoryCount, | |
| 201 base::Unretained(this)), | |
| 202 &request_tracker_); | |
| 203 } | 187 } |
| 204 | 188 |
| 205 if (!is_main_frame_load_blocked_) { | 189 if (!is_main_frame_load_blocked_) { |
| 206 navigation_entry_index_to_remove_ = | 190 navigation_entry_index_to_remove_ = |
| 207 web_contents->GetController().GetLastCommittedEntryIndex(); | 191 web_contents->GetController().GetLastCommittedEntryIndex(); |
| 208 } else { | 192 } else { |
| 209 navigation_entry_index_to_remove_ = -1; | 193 navigation_entry_index_to_remove_ = -1; |
| 210 } | 194 } |
| 211 | 195 |
| 212 // Start computing malware details. They will be sent only | 196 // Start computing malware details. They will be sent only |
| 213 // if the user opts-in on the blocking page later. | 197 // if the user opts-in on the blocking page later. |
| 214 // If there's more than one malicious resources, it means the user | 198 // If there's more than one malicious resources, it means the user |
| 215 // clicked through the first warning, so we don't prepare additional | 199 // clicked through the first warning, so we don't prepare additional |
| 216 // reports. | 200 // reports. |
| 217 if (unsafe_resources.size() == 1 && | 201 if (unsafe_resources.size() == 1 && |
| 218 unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_MALWARE && | 202 unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_MALWARE && |
| 219 malware_details_.get() == NULL && CanShowMalwareDetailsOption()) { | 203 malware_details_.get() == NULL && CanShowMalwareDetailsOption()) { |
| 220 malware_details_ = MalwareDetails::NewMalwareDetails( | 204 malware_details_ = MalwareDetails::NewMalwareDetails( |
| 221 ui_manager_, web_contents, unsafe_resources[0]); | 205 ui_manager_, web_contents, unsafe_resources[0]); |
| 222 } | 206 } |
| 223 | |
| 224 #if defined(ENABLE_EXTENSIONS) | |
| 225 // ExperienceSampling: Set up new sampling event for this interstitial. | |
| 226 // This needs to handle all types of warnings this interstitial can show. | |
| 227 std::string event_name; | |
| 228 switch (interstitial_type_) { | |
| 229 case TYPE_MALWARE: | |
| 230 event_name = kEventNameMalware; | |
| 231 break; | |
| 232 case TYPE_HARMFUL: | |
| 233 event_name = kEventNameHarmful; | |
| 234 break; | |
| 235 case TYPE_PHISHING: | |
| 236 event_name = kEventNamePhishing; | |
| 237 break; | |
| 238 default: | |
| 239 event_name = kEventNameOther; | |
| 240 break; | |
| 241 } | |
| 242 sampling_event_.reset(new ExperienceSamplingEvent( | |
| 243 event_name, | |
| 244 request_url(), | |
| 245 web_contents->GetLastCommittedURL(), | |
| 246 web_contents->GetBrowserContext())); | |
| 247 #endif | |
| 248 } | 207 } |
| 249 | 208 |
| 250 bool SafeBrowsingBlockingPage::CanShowMalwareDetailsOption() { | 209 bool SafeBrowsingBlockingPage::CanShowMalwareDetailsOption() { |
| 251 return (!web_contents()->GetBrowserContext()->IsOffTheRecord() && | 210 return (!web_contents()->GetBrowserContext()->IsOffTheRecord() && |
| 252 web_contents()->GetURL().SchemeIs(url::kHttpScheme)); | 211 web_contents()->GetURL().SchemeIs(url::kHttpScheme)); |
| 253 } | 212 } |
| 254 | 213 |
| 255 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() { | 214 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() { |
| 256 } | 215 } |
| 257 | 216 |
| 258 void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) { | 217 void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) { |
| 259 std::string command(cmd); // Make a local copy so we can modify it. | 218 std::string command(cmd); // Make a local copy so we can modify it. |
| 260 // The Jasonified response has quotes, remove them. | 219 // The Jasonified response has quotes, remove them. |
| 261 if (command.length() > 1 && command[0] == '"') { | 220 if (command.length() > 1 && command[0] == '"') { |
| 262 command = command.substr(1, command.length() - 2); | 221 command = command.substr(1, command.length() - 2); |
| 263 } | 222 } |
| 264 if (command == kDoReportCommand) { | 223 if (command == kDoReportCommand) { |
| 265 SetReportingPreference(true); | 224 SetReportingPreference(true); |
| 266 return; | 225 return; |
| 267 } | 226 } |
| 268 | 227 |
| 269 if (command == kDontReportCommand) { | 228 if (command == kDontReportCommand) { |
| 270 SetReportingPreference(false); | 229 SetReportingPreference(false); |
| 271 return; | 230 return; |
| 272 } | 231 } |
| 273 | 232 |
| 274 if (command == kLearnMoreCommand) { | 233 if (command == kLearnMoreCommand) { |
| 275 // User pressed "Learn more". | 234 // User pressed "Learn more". |
| 276 RecordUserInteraction(SHOW_LEARN_MORE); | 235 uma_helper_->RecordUserInteraction( |
| 277 GURL learn_more_url(interstitial_type_ == TYPE_PHISHING ? | 236 SecurityInterstitialUmaHelper::SHOW_LEARN_MORE); |
| 278 kLearnMorePhishingUrlV2 : kLearnMoreMalwareUrlV2); | 237 GURL learn_more_url( |
| 238 interstitial_reason_ == SB_REASON_PHISHING ? |
| 239 kLearnMorePhishingUrlV2 : kLearnMoreMalwareUrlV2); |
| 279 learn_more_url = google_util::AppendGoogleLocaleParam( | 240 learn_more_url = google_util::AppendGoogleLocaleParam( |
| 280 learn_more_url, g_browser_process->GetApplicationLocale()); | 241 learn_more_url, g_browser_process->GetApplicationLocale()); |
| 281 OpenURLParams params(learn_more_url, | 242 OpenURLParams params(learn_more_url, |
| 282 Referrer(), | 243 Referrer(), |
| 283 CURRENT_TAB, | 244 CURRENT_TAB, |
| 284 ui::PAGE_TRANSITION_LINK, | 245 ui::PAGE_TRANSITION_LINK, |
| 285 false); | 246 false); |
| 286 web_contents()->OpenURL(params); | 247 web_contents()->OpenURL(params); |
| 287 return; | 248 return; |
| 288 } | 249 } |
| 289 | 250 |
| 290 if (command == kShowPrivacyCommand) { | 251 if (command == kShowPrivacyCommand) { |
| 291 // User pressed "Safe Browsing privacy policy". | 252 // User pressed "Safe Browsing privacy policy". |
| 292 RecordUserInteraction(SHOW_PRIVACY_POLICY); | 253 uma_helper_->RecordUserInteraction( |
| 254 SecurityInterstitialUmaHelper::SHOW_PRIVACY_POLICY); |
| 293 GURL privacy_url( | 255 GURL privacy_url( |
| 294 l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_PRIVACY_POLICY_URL)); | 256 l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_PRIVACY_POLICY_URL)); |
| 295 privacy_url = google_util::AppendGoogleLocaleParam( | 257 privacy_url = google_util::AppendGoogleLocaleParam( |
| 296 privacy_url, g_browser_process->GetApplicationLocale()); | 258 privacy_url, g_browser_process->GetApplicationLocale()); |
| 297 OpenURLParams params(privacy_url, | 259 OpenURLParams params(privacy_url, |
| 298 Referrer(), | 260 Referrer(), |
| 299 CURRENT_TAB, | 261 CURRENT_TAB, |
| 300 ui::PAGE_TRANSITION_LINK, | 262 ui::PAGE_TRANSITION_LINK, |
| 301 false); | 263 false); |
| 302 web_contents()->OpenURL(params); | 264 web_contents()->OpenURL(params); |
| 303 return; | 265 return; |
| 304 } | 266 } |
| 305 | 267 |
| 306 bool proceed_blocked = false; | 268 bool proceed_blocked = false; |
| 307 if (command == kProceedCommand) { | 269 if (command == kProceedCommand) { |
| 308 if (IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) { | 270 if (IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) { |
| 309 proceed_blocked = true; | 271 proceed_blocked = true; |
| 310 } else { | 272 } else { |
| 311 RecordUserDecision(PROCEED); | 273 uma_helper_->RecordUserDecision(SecurityInterstitialUmaHelper::PROCEED); |
| 312 interstitial_page()->Proceed(); | 274 interstitial_page()->Proceed(); |
| 313 // |this| has been deleted after Proceed() returns. | 275 // |this| has been deleted after Proceed() returns. |
| 314 return; | 276 return; |
| 315 } | 277 } |
| 316 } | 278 } |
| 317 | 279 |
| 318 if (command == kTakeMeBackCommand || proceed_blocked) { | 280 if (command == kTakeMeBackCommand || proceed_blocked) { |
| 319 // Don't record the user action here because there are other ways of | 281 // Don't record the user action here because there are other ways of |
| 320 // triggering DontProceed, like clicking the back button. | 282 // triggering DontProceed, like clicking the back button. |
| 321 if (is_main_frame_load_blocked_) { | 283 if (is_main_frame_load_blocked_) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 } | 319 } |
| 358 | 320 |
| 359 if (element_index >= unsafe_resources_.size()) { | 321 if (element_index >= unsafe_resources_.size()) { |
| 360 NOTREACHED(); | 322 NOTREACHED(); |
| 361 return; | 323 return; |
| 362 } | 324 } |
| 363 | 325 |
| 364 std::string bad_url_spec = unsafe_resources_[element_index].url.spec(); | 326 std::string bad_url_spec = unsafe_resources_[element_index].url.spec(); |
| 365 if (command == kShowDiagnosticCommand) { | 327 if (command == kShowDiagnosticCommand) { |
| 366 // We're going to take the user to Google's SafeBrowsing diagnostic page. | 328 // We're going to take the user to Google's SafeBrowsing diagnostic page. |
| 367 RecordUserInteraction(SHOW_DIAGNOSTIC); | 329 uma_helper_->RecordUserInteraction( |
| 330 SecurityInterstitialUmaHelper::SHOW_DIAGNOSTIC); |
| 368 std::string diagnostic = | 331 std::string diagnostic = |
| 369 base::StringPrintf(kSbDiagnosticUrl, | 332 base::StringPrintf(kSbDiagnosticUrl, |
| 370 net::EscapeQueryParamValue(bad_url_spec, true).c_str()); | 333 net::EscapeQueryParamValue(bad_url_spec, true).c_str()); |
| 371 GURL diagnostic_url(diagnostic); | 334 GURL diagnostic_url(diagnostic); |
| 372 diagnostic_url = google_util::AppendGoogleLocaleParam( | 335 diagnostic_url = google_util::AppendGoogleLocaleParam( |
| 373 diagnostic_url, g_browser_process->GetApplicationLocale()); | 336 diagnostic_url, g_browser_process->GetApplicationLocale()); |
| 374 DCHECK(unsafe_resources_[element_index].threat_type == | 337 DCHECK(unsafe_resources_[element_index].threat_type == |
| 375 SB_THREAT_TYPE_URL_MALWARE || | 338 SB_THREAT_TYPE_URL_MALWARE || |
| 376 unsafe_resources_[element_index].threat_type == | 339 unsafe_resources_[element_index].threat_type == |
| 377 SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL || | 340 SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL || |
| 378 unsafe_resources_[element_index].threat_type == | 341 unsafe_resources_[element_index].threat_type == |
| 379 SB_THREAT_TYPE_URL_UNWANTED); | 342 SB_THREAT_TYPE_URL_UNWANTED); |
| 380 OpenURLParams params( | 343 OpenURLParams params( |
| 381 diagnostic_url, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_LINK, | 344 diagnostic_url, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_LINK, |
| 382 false); | 345 false); |
| 383 web_contents()->OpenURL(params); | 346 web_contents()->OpenURL(params); |
| 384 return; | 347 return; |
| 385 } | 348 } |
| 386 | 349 |
| 387 if (command == kExpandedSeeMoreCommand) { | 350 if (command == kExpandedSeeMoreCommand) { |
| 388 RecordUserInteraction(SHOW_ADVANCED); | 351 uma_helper_->RecordUserInteraction( |
| 352 SecurityInterstitialUmaHelper::SHOW_ADVANCED); |
| 389 return; | 353 return; |
| 390 } | 354 } |
| 391 | 355 |
| 392 NOTREACHED() << "Unexpected command: " << command; | 356 NOTREACHED() << "Unexpected command: " << command; |
| 393 } | 357 } |
| 394 | 358 |
| 395 void SafeBrowsingBlockingPage::OverrideRendererPrefs( | 359 void SafeBrowsingBlockingPage::OverrideRendererPrefs( |
| 396 content::RendererPreferences* prefs) { | 360 content::RendererPreferences* prefs) { |
| 397 Profile* profile = Profile::FromBrowserContext( | 361 Profile* profile = Profile::FromBrowserContext( |
| 398 web_contents()->GetBrowserContext()); | 362 web_contents()->GetBrowserContext()); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 bool SafeBrowsingBlockingPage::ShouldCreateNewNavigation() const { | 406 bool SafeBrowsingBlockingPage::ShouldCreateNewNavigation() const { |
| 443 return is_main_frame_load_blocked_; | 407 return is_main_frame_load_blocked_; |
| 444 } | 408 } |
| 445 | 409 |
| 446 void SafeBrowsingBlockingPage::OnDontProceed() { | 410 void SafeBrowsingBlockingPage::OnDontProceed() { |
| 447 // We could have already called Proceed(), in which case we must not notify | 411 // We could have already called Proceed(), in which case we must not notify |
| 448 // the SafeBrowsingUIManager again, as the client has been deleted. | 412 // the SafeBrowsingUIManager again, as the client has been deleted. |
| 449 if (proceeded_) | 413 if (proceeded_) |
| 450 return; | 414 return; |
| 451 | 415 |
| 452 if (!IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) | 416 if (!IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) { |
| 453 RecordUserDecision(DONT_PROCEED); | 417 uma_helper_->RecordUserDecision( |
| 418 SecurityInterstitialUmaHelper::DONT_PROCEED); |
| 419 } |
| 454 | 420 |
| 455 // Send the malware details, if we opted to. | 421 // Send the malware details, if we opted to. |
| 456 FinishMalwareDetails(0); // No delay | 422 FinishMalwareDetails(0); // No delay |
| 457 | 423 |
| 458 NotifySafeBrowsingUIManager(ui_manager_, unsafe_resources_, false); | 424 NotifySafeBrowsingUIManager(ui_manager_, unsafe_resources_, false); |
| 459 | 425 |
| 460 // The user does not want to proceed, clear the queued unsafe resources | 426 // The user does not want to proceed, clear the queued unsafe resources |
| 461 // notifications we received while the interstitial was showing. | 427 // notifications we received while the interstitial was showing. |
| 462 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); | 428 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); |
| 463 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(web_contents()); | 429 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(web_contents()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 475 web_contents()->GetController().GetLastCommittedEntryIndex(); | 441 web_contents()->GetController().GetLastCommittedEntryIndex(); |
| 476 if (navigation_entry_index_to_remove_ != -1 && | 442 if (navigation_entry_index_to_remove_ != -1 && |
| 477 navigation_entry_index_to_remove_ != last_committed_index && | 443 navigation_entry_index_to_remove_ != last_committed_index && |
| 478 !web_contents()->IsBeingDestroyed()) { | 444 !web_contents()->IsBeingDestroyed()) { |
| 479 CHECK(web_contents()->GetController().RemoveEntryAtIndex( | 445 CHECK(web_contents()->GetController().RemoveEntryAtIndex( |
| 480 navigation_entry_index_to_remove_)); | 446 navigation_entry_index_to_remove_)); |
| 481 navigation_entry_index_to_remove_ = -1; | 447 navigation_entry_index_to_remove_ = -1; |
| 482 } | 448 } |
| 483 } | 449 } |
| 484 | 450 |
| 485 void SafeBrowsingBlockingPage::OnGotHistoryCount(bool success, | |
| 486 int num_visits, | |
| 487 base::Time first_visit) { | |
| 488 if (success) | |
| 489 num_visits_ = num_visits; | |
| 490 } | |
| 491 | |
| 492 void SafeBrowsingBlockingPage::RecordUserDecision(Decision decision) { | |
| 493 switch (interstitial_type_) { | |
| 494 case TYPE_MALWARE: | |
| 495 UMA_HISTOGRAM_ENUMERATION("interstitial.malware.decision", | |
| 496 decision, | |
| 497 MAX_DECISION); | |
| 498 break; | |
| 499 case TYPE_HARMFUL: | |
| 500 UMA_HISTOGRAM_ENUMERATION("interstitial.harmful.decision", | |
| 501 decision, | |
| 502 MAX_DECISION); | |
| 503 break; | |
| 504 case TYPE_PHISHING: | |
| 505 UMA_HISTOGRAM_ENUMERATION("interstitial.phishing.decision", | |
| 506 decision, | |
| 507 MAX_DECISION); | |
| 508 break; | |
| 509 } | |
| 510 | |
| 511 #if defined(ENABLE_EXTENSIONS) | |
| 512 if (sampling_event_.get()) { | |
| 513 switch (decision) { | |
| 514 case PROCEED: | |
| 515 sampling_event_->CreateUserDecisionEvent( | |
| 516 ExperienceSamplingEvent::kProceed); | |
| 517 break; | |
| 518 case DONT_PROCEED: | |
| 519 sampling_event_->CreateUserDecisionEvent( | |
| 520 ExperienceSamplingEvent::kDeny); | |
| 521 break; | |
| 522 case SHOW: | |
| 523 case PROCEEDING_DISABLED: | |
| 524 case MAX_DECISION: | |
| 525 break; | |
| 526 } | |
| 527 } | |
| 528 #endif | |
| 529 | |
| 530 // Record additional information about malware sites that users have | |
| 531 // visited before. | |
| 532 if (num_visits_ < 1 || interstitial_type_ != TYPE_MALWARE) | |
| 533 return; | |
| 534 if (decision == PROCEED || decision == DONT_PROCEED) { | |
| 535 UMA_HISTOGRAM_ENUMERATION("interstitial.malware.decision.repeat_visit", | |
| 536 SHOW, | |
| 537 MAX_DECISION); | |
| 538 UMA_HISTOGRAM_ENUMERATION("interstitial.malware.decision.repeat_visit", | |
| 539 decision, | |
| 540 MAX_DECISION); | |
| 541 } | |
| 542 } | |
| 543 | |
| 544 void SafeBrowsingBlockingPage::RecordUserInteraction(Interaction interaction) { | |
| 545 switch (interstitial_type_) { | |
| 546 case TYPE_MALWARE: | |
| 547 UMA_HISTOGRAM_ENUMERATION("interstitial.malware.interaction", | |
| 548 interaction, | |
| 549 MAX_INTERACTION); | |
| 550 break; | |
| 551 case TYPE_HARMFUL: | |
| 552 UMA_HISTOGRAM_ENUMERATION("interstitial.harmful.interaction", | |
| 553 interaction, | |
| 554 MAX_INTERACTION); | |
| 555 break; | |
| 556 case TYPE_PHISHING: | |
| 557 UMA_HISTOGRAM_ENUMERATION("interstitial.phishing.interaction", | |
| 558 interaction, | |
| 559 MAX_INTERACTION); | |
| 560 break; | |
| 561 } | |
| 562 | |
| 563 #if defined(ENABLE_EXTENSIONS) | |
| 564 if (!sampling_event_.get()) | |
| 565 return; | |
| 566 switch (interaction) { | |
| 567 case SHOW_LEARN_MORE: | |
| 568 sampling_event_->set_has_viewed_learn_more(true); | |
| 569 break; | |
| 570 case SHOW_ADVANCED: | |
| 571 sampling_event_->set_has_viewed_details(true); | |
| 572 break; | |
| 573 case SHOW_PRIVACY_POLICY: | |
| 574 case SHOW_DIAGNOSTIC: | |
| 575 case TOTAL_VISITS: | |
| 576 case MAX_INTERACTION: | |
| 577 break; | |
| 578 } | |
| 579 #endif | |
| 580 } | |
| 581 | |
| 582 void SafeBrowsingBlockingPage::FinishMalwareDetails(int64 delay_ms) { | 451 void SafeBrowsingBlockingPage::FinishMalwareDetails(int64 delay_ms) { |
| 583 if (malware_details_.get() == NULL) | 452 if (malware_details_.get() == NULL) |
| 584 return; // Not all interstitials have malware details (eg phishing). | 453 return; // Not all interstitials have malware details (eg phishing). |
| 585 DCHECK(interstitial_type_ == TYPE_MALWARE); | 454 DCHECK_EQ(interstitial_reason_, SB_REASON_MALWARE); |
| 586 | 455 |
| 587 const bool enabled = | 456 const bool enabled = |
| 588 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingEnabled); | 457 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingEnabled); |
| 589 UMA_HISTOGRAM_BOOLEAN("SB2.ExtendedReportingIsEnabled", enabled); | 458 UMA_HISTOGRAM_BOOLEAN("SB2.ExtendedReportingIsEnabled", enabled); |
| 590 if (enabled) { | 459 if (enabled) { |
| 591 // Finish the malware details collection, send it over. | 460 // Finish the malware details collection, send it over. |
| 592 BrowserThread::PostDelayedTask( | 461 BrowserThread::PostDelayedTask( |
| 593 BrowserThread::IO, FROM_HERE, | 462 BrowserThread::IO, FROM_HERE, |
| 594 base::Bind(&MalwareDetails::FinishCollection, malware_details_.get()), | 463 base::Bind(&MalwareDetails::FinishCollection, malware_details_.get()), |
| 595 base::TimeDelta::FromMilliseconds(delay_ms)); | 464 base::TimeDelta::FromMilliseconds(delay_ms)); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 // load, since they happen after the page is finished loading. | 541 // load, since they happen after the page is finished loading. |
| 673 if (unsafe_resources[0].threat_type == | 542 if (unsafe_resources[0].threat_type == |
| 674 SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL) { | 543 SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL) { |
| 675 return false; | 544 return false; |
| 676 } | 545 } |
| 677 | 546 |
| 678 // Otherwise, check the threat type. | 547 // Otherwise, check the threat type. |
| 679 return unsafe_resources.size() == 1 && !unsafe_resources[0].is_subresource; | 548 return unsafe_resources.size() == 1 && !unsafe_resources[0].is_subresource; |
| 680 } | 549 } |
| 681 | 550 |
| 551 std::string SafeBrowsingBlockingPage::GetHistogramPrefix() const { |
| 552 switch (interstitial_reason_) { |
| 553 case SB_REASON_MALWARE: |
| 554 return "malware"; |
| 555 case SB_REASON_HARMFUL: |
| 556 return "harmful"; |
| 557 case SB_REASON_PHISHING: |
| 558 return "phishing"; |
| 559 } |
| 560 NOTREACHED(); |
| 561 return std::string(); |
| 562 } |
| 563 |
| 564 std::string SafeBrowsingBlockingPage::GetSamplingEventName() const { |
| 565 switch (interstitial_reason_) { |
| 566 case SB_REASON_MALWARE: |
| 567 return kEventNameMalware; |
| 568 case SB_REASON_HARMFUL: |
| 569 return kEventNameHarmful; |
| 570 case SB_REASON_PHISHING: |
| 571 return kEventNamePhishing; |
| 572 default: |
| 573 return kEventNameOther; |
| 574 } |
| 575 } |
| 576 |
| 682 void SafeBrowsingBlockingPage::PopulateInterstitialStrings( | 577 void SafeBrowsingBlockingPage::PopulateInterstitialStrings( |
| 683 base::DictionaryValue* load_time_data) { | 578 base::DictionaryValue* load_time_data) { |
| 684 CHECK(load_time_data); | 579 CHECK(load_time_data); |
| 685 CHECK(!unsafe_resources_.empty()); | 580 CHECK(!unsafe_resources_.empty()); |
| 686 | 581 |
| 687 load_time_data->SetString("type", "SAFEBROWSING"); | 582 load_time_data->SetString("type", "SAFEBROWSING"); |
| 688 load_time_data->SetString( | 583 load_time_data->SetString( |
| 689 "tabTitle", l10n_util::GetStringUTF16(IDS_SAFEBROWSING_V3_TITLE)); | 584 "tabTitle", l10n_util::GetStringUTF16(IDS_SAFEBROWSING_V3_TITLE)); |
| 690 load_time_data->SetString( | 585 load_time_data->SetString( |
| 691 "openDetails", | 586 "openDetails", |
| 692 l10n_util::GetStringUTF16(IDS_SAFEBROWSING_V3_OPEN_DETAILS_BUTTON)); | 587 l10n_util::GetStringUTF16(IDS_SAFEBROWSING_V3_OPEN_DETAILS_BUTTON)); |
| 693 load_time_data->SetString( | 588 load_time_data->SetString( |
| 694 "closeDetails", | 589 "closeDetails", |
| 695 l10n_util::GetStringUTF16(IDS_SAFEBROWSING_V3_CLOSE_DETAILS_BUTTON)); | 590 l10n_util::GetStringUTF16(IDS_SAFEBROWSING_V3_CLOSE_DETAILS_BUTTON)); |
| 696 load_time_data->SetString( | 591 load_time_data->SetString( |
| 697 "primaryButtonText", | 592 "primaryButtonText", |
| 698 l10n_util::GetStringUTF16(IDS_SAFEBROWSING_OVERRIDABLE_SAFETY_BUTTON)); | 593 l10n_util::GetStringUTF16(IDS_SAFEBROWSING_OVERRIDABLE_SAFETY_BUTTON)); |
| 699 load_time_data->SetBoolean( | 594 load_time_data->SetBoolean( |
| 700 "overridable", | 595 "overridable", |
| 701 !IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)); | 596 !IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)); |
| 702 | 597 |
| 703 switch (interstitial_type_) { | 598 switch (interstitial_reason_) { |
| 704 case TYPE_MALWARE: | 599 case SB_REASON_MALWARE: |
| 705 PopulateMalwareLoadTimeData(load_time_data); | 600 PopulateMalwareLoadTimeData(load_time_data); |
| 706 break; | 601 break; |
| 707 case TYPE_HARMFUL: | 602 case SB_REASON_HARMFUL: |
| 708 PopulateHarmfulLoadTimeData(load_time_data); | 603 PopulateHarmfulLoadTimeData(load_time_data); |
| 709 break; | 604 break; |
| 710 case TYPE_PHISHING: | 605 case SB_REASON_PHISHING: |
| 711 PopulatePhishingLoadTimeData(load_time_data); | 606 PopulatePhishingLoadTimeData(load_time_data); |
| 712 break; | 607 break; |
| 713 } | 608 } |
| 714 } | 609 } |
| 715 | 610 |
| 716 void SafeBrowsingBlockingPage::PopulateExtendedReportingOption( | 611 void SafeBrowsingBlockingPage::PopulateExtendedReportingOption( |
| 717 base::DictionaryValue* load_time_data) { | 612 base::DictionaryValue* load_time_data) { |
| 718 // Only show checkbox if !(HTTPS || incognito-mode). | 613 // Only show checkbox if !(HTTPS || incognito-mode). |
| 719 const bool show = CanShowMalwareDetailsOption(); | 614 const bool show = CanShowMalwareDetailsOption(); |
| 720 load_time_data->SetBoolean(kDisplayCheckBox, show); | 615 load_time_data->SetBoolean(kDisplayCheckBox, show); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 797 load_time_data->SetString( | 692 load_time_data->SetString( |
| 798 "explanationParagraph", | 693 "explanationParagraph", |
| 799 l10n_util::GetStringFUTF16(IDS_PHISHING_V3_EXPLANATION_PARAGRAPH, | 694 l10n_util::GetStringFUTF16(IDS_PHISHING_V3_EXPLANATION_PARAGRAPH, |
| 800 GetFormattedHostName())); | 695 GetFormattedHostName())); |
| 801 load_time_data->SetString( | 696 load_time_data->SetString( |
| 802 "finalParagraph", | 697 "finalParagraph", |
| 803 l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH)); | 698 l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH)); |
| 804 | 699 |
| 805 PopulateExtendedReportingOption(load_time_data); | 700 PopulateExtendedReportingOption(load_time_data); |
| 806 } | 701 } |
| OLD | NEW |