| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "components/safe_browsing/base_blocking_page.h" | 5 #include "components/safe_browsing/base_blocking_page.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "components/safe_browsing_db/safe_browsing_prefs.h" | 12 #include "components/safe_browsing_db/safe_browsing_prefs.h" |
| 13 #include "components/security_interstitials/content/security_interstitial_contro
ller_client.h" | 13 #include "components/security_interstitials/content/security_interstitial_contro
ller_client.h" |
| 14 #include "components/security_interstitials/core/metrics_helper.h" | 14 #include "components/security_interstitials/core/metrics_helper.h" |
| 15 #include "content/public/browser/interstitial_page.h" | 15 #include "content/public/browser/interstitial_page.h" |
| 16 #include "content/public/browser/navigation_entry.h" | 16 #include "content/public/browser/navigation_entry.h" |
| 17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 18 | 18 |
| 19 using content::InterstitialPage; | 19 using content::InterstitialPage; |
| 20 using content::WebContents; | 20 using content::WebContents; |
| 21 using security_interstitials::SafeBrowsingErrorUI; | 21 using security_interstitials::SafeBrowsingLoudErrorUI; |
| 22 using security_interstitials::SecurityInterstitialControllerClient; | 22 using security_interstitials::SecurityInterstitialControllerClient; |
| 23 | 23 |
| 24 namespace safe_browsing { | 24 namespace safe_browsing { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 // After a safe browsing interstitial where the user opted-in to the report | 28 // After a safe browsing interstitial where the user opted-in to the report |
| 29 // but clicked "proceed anyway", we delay the call to | 29 // but clicked "proceed anyway", we delay the call to |
| 30 // ThreatDetails::FinishCollection() by this much time (in | 30 // ThreatDetails::FinishCollection() by this much time (in |
| 31 // milliseconds). | 31 // milliseconds). |
| 32 const int64_t kThreatDetailsProceedDelayMilliSeconds = 3000; | 32 const int64_t kThreatDetailsProceedDelayMilliSeconds = 3000; |
| 33 | 33 |
| 34 base::LazyInstance<BaseBlockingPage::UnsafeResourceMap>::Leaky | 34 base::LazyInstance<BaseBlockingPage::UnsafeResourceMap>::Leaky |
| 35 g_unsafe_resource_map = LAZY_INSTANCE_INITIALIZER; | 35 g_unsafe_resource_map = LAZY_INSTANCE_INITIALIZER; |
| 36 | 36 |
| 37 } // namespace | 37 } // namespace |
| 38 | 38 |
| 39 BaseBlockingPage::BaseBlockingPage( | 39 BaseBlockingPage::BaseBlockingPage( |
| 40 BaseUIManager* ui_manager, | 40 BaseUIManager* ui_manager, |
| 41 WebContents* web_contents, | 41 WebContents* web_contents, |
| 42 const GURL& main_frame_url, | 42 const GURL& main_frame_url, |
| 43 const UnsafeResourceList& unsafe_resources, | 43 const UnsafeResourceList& unsafe_resources, |
| 44 std::unique_ptr<SecurityInterstitialControllerClient> controller_client, | 44 std::unique_ptr<SecurityInterstitialControllerClient> controller_client, |
| 45 const SafeBrowsingErrorUI::SBErrorDisplayOptions& display_options) | 45 const BaseSafeBrowsingErrorUI::SBErrorDisplayOptions& display_options) |
| 46 : SecurityInterstitialPage(web_contents, | 46 : SecurityInterstitialPage(web_contents, |
| 47 unsafe_resources[0].url, | 47 unsafe_resources[0].url, |
| 48 std::move(controller_client)), | 48 std::move(controller_client)), |
| 49 ui_manager_(ui_manager), | 49 ui_manager_(ui_manager), |
| 50 main_frame_url_(main_frame_url), | 50 main_frame_url_(main_frame_url), |
| 51 navigation_entry_index_to_remove_( | 51 navigation_entry_index_to_remove_( |
| 52 IsMainPageLoadBlocked(unsafe_resources) | 52 IsMainPageLoadBlocked(unsafe_resources) |
| 53 ? -1 | 53 ? -1 |
| 54 : web_contents->GetController().GetLastCommittedEntryIndex()), | 54 : web_contents->GetController().GetLastCommittedEntryIndex()), |
| 55 unsafe_resources_(unsafe_resources), | 55 unsafe_resources_(unsafe_resources), |
| 56 sb_error_ui_(base::MakeUnique<SafeBrowsingErrorUI>( | 56 sb_error_ui_(base::MakeUnique<SafeBrowsingLoudErrorUI>( |
| 57 unsafe_resources_[0].url, | 57 unsafe_resources_[0].url, |
| 58 main_frame_url_, | 58 main_frame_url_, |
| 59 GetInterstitialReason(unsafe_resources_), | 59 GetInterstitialReason(unsafe_resources_), |
| 60 display_options, | 60 display_options, |
| 61 ui_manager->app_locale(), | 61 ui_manager->app_locale(), |
| 62 base::Time::NowFromSystemTime(), | 62 base::Time::NowFromSystemTime(), |
| 63 controller())), | 63 controller())), |
| 64 proceeded_(false), | 64 proceeded_(false), |
| 65 threat_details_proceed_delay_ms_(kThreatDetailsProceedDelayMilliSeconds) { | 65 threat_details_proceed_delay_ms_(kThreatDetailsProceedDelayMilliSeconds) { |
| 66 } | 66 } |
| 67 | 67 |
| 68 BaseBlockingPage::~BaseBlockingPage() {} | 68 BaseBlockingPage::~BaseBlockingPage() {} |
| 69 | 69 |
| 70 // static | 70 // static |
| 71 const SafeBrowsingErrorUI::SBErrorDisplayOptions | 71 const security_interstitials::BaseSafeBrowsingErrorUI::SBErrorDisplayOptions |
| 72 BaseBlockingPage::CreateDefaultDisplayOptions( | 72 BaseBlockingPage::CreateDefaultDisplayOptions( |
| 73 const UnsafeResourceList& unsafe_resources) { | 73 const UnsafeResourceList& unsafe_resources) { |
| 74 return SafeBrowsingErrorUI::SBErrorDisplayOptions( | 74 return BaseSafeBrowsingErrorUI::SBErrorDisplayOptions( |
| 75 IsMainPageLoadBlocked(unsafe_resources), | 75 IsMainPageLoadBlocked(unsafe_resources), |
| 76 false, // kSafeBrowsingExtendedReportingOptInAllowed | 76 false, // kSafeBrowsingExtendedReportingOptInAllowed |
| 77 false, // is_off_the_record | 77 false, // is_off_the_record |
| 78 false, // is_extended_reporting | 78 false, // is_extended_reporting |
| 79 false, // is_scout | 79 false, // is_scout |
| 80 false, // kSafeBrowsingProceedAnywayDisabled | 80 false, // kSafeBrowsingProceedAnywayDisabled |
| 81 true); // is_resource_cancellable | 81 true); // is_resource_cancellable |
| 82 } | 82 } |
| 83 | 83 |
| 84 // static | 84 // static |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 threat_details_proceed_delay_ms_ = delay; | 139 threat_details_proceed_delay_ms_ = delay; |
| 140 } | 140 } |
| 141 | 141 |
| 142 void BaseBlockingPage::OnDontProceed() { | 142 void BaseBlockingPage::OnDontProceed() { |
| 143 // We could have already called Proceed(), in which case we must not notify | 143 // We could have already called Proceed(), in which case we must not notify |
| 144 // the SafeBrowsingUIManager again, as the client has been deleted. | 144 // the SafeBrowsingUIManager again, as the client has been deleted. |
| 145 if (proceeded_) | 145 if (proceeded_) |
| 146 return; | 146 return; |
| 147 | 147 |
| 148 UpdateMetricsAfterSecurityInterstitial(); | 148 UpdateMetricsAfterSecurityInterstitial(); |
| 149 if (!sb_error_ui_->is_proceed_anyway_disabled()) { | 149 if (!sb_error_ui_->base_safe_browsing_error_ui.is_proceed_anyway_disabled()) { |
| 150 controller()->metrics_helper()->RecordUserDecision( | 150 controller()->metrics_helper()->RecordUserDecision( |
| 151 security_interstitials::MetricsHelper::DONT_PROCEED); | 151 security_interstitials::MetricsHelper::DONT_PROCEED); |
| 152 } | 152 } |
| 153 | 153 |
| 154 // Send the malware details, if we opted to. | 154 // Send the malware details, if we opted to. |
| 155 FinishThreatDetails(base::TimeDelta(), false /* did_proceed */, | 155 FinishThreatDetails(base::TimeDelta(), false /* did_proceed */, |
| 156 controller()->metrics_helper()->NumVisits()); // No delay | 156 controller()->metrics_helper()->NumVisits()); // No delay |
| 157 | 157 |
| 158 ui_manager_->OnBlockingPageDone(unsafe_resources_, false /* proceed */, | 158 ui_manager_->OnBlockingPageDone(unsafe_resources_, false /* proceed */, |
| 159 web_contents(), main_frame_url_); | 159 web_contents(), main_frame_url_); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 int command = 0; | 194 int command = 0; |
| 195 bool retval = base::StringToInt(page_cmd, &command); | 195 bool retval = base::StringToInt(page_cmd, &command); |
| 196 DCHECK(retval) << page_cmd; | 196 DCHECK(retval) << page_cmd; |
| 197 | 197 |
| 198 sb_error_ui_->HandleCommand( | 198 sb_error_ui_->HandleCommand( |
| 199 static_cast<security_interstitials::SecurityInterstitialCommands>( | 199 static_cast<security_interstitials::SecurityInterstitialCommands>( |
| 200 command)); | 200 command)); |
| 201 } | 201 } |
| 202 | 202 |
| 203 bool BaseBlockingPage::ShouldCreateNewNavigation() const { | 203 bool BaseBlockingPage::ShouldCreateNewNavigation() const { |
| 204 return sb_error_ui_->is_main_frame_load_blocked(); | 204 return sb_error_ui_->base_safe_browsing_error_ui.is_main_frame_load_blocked(); |
| 205 } | 205 } |
| 206 | 206 |
| 207 void BaseBlockingPage::PopulateInterstitialStrings( | 207 void BaseBlockingPage::PopulateInterstitialStrings( |
| 208 base::DictionaryValue* load_time_data) { | 208 base::DictionaryValue* load_time_data) { |
| 209 sb_error_ui_->PopulateStringsForHTML(load_time_data); | 209 sb_error_ui_->PopulateStringsForHTML(load_time_data); |
| 210 } | 210 } |
| 211 | 211 |
| 212 void BaseBlockingPage::FinishThreatDetails(const base::TimeDelta& delay, | 212 void BaseBlockingPage::FinishThreatDetails(const base::TimeDelta& delay, |
| 213 bool did_proceed, | 213 bool did_proceed, |
| 214 int num_visits) {} | 214 int num_visits) {} |
| 215 | 215 |
| 216 // static | 216 // static |
| 217 BaseBlockingPage::UnsafeResourceMap* | 217 BaseBlockingPage::UnsafeResourceMap* |
| 218 BaseBlockingPage::GetUnsafeResourcesMap() { | 218 BaseBlockingPage::GetUnsafeResourcesMap() { |
| 219 return g_unsafe_resource_map.Pointer(); | 219 return g_unsafe_resource_map.Pointer(); |
| 220 } | 220 } |
| 221 | 221 |
| 222 // static | 222 // static |
| 223 std::string BaseBlockingPage::GetMetricPrefix( | 223 std::string BaseBlockingPage::GetMetricPrefix( |
| 224 const UnsafeResourceList& unsafe_resources, | 224 const UnsafeResourceList& unsafe_resources, |
| 225 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason) { | 225 BaseSafeBrowsingErrorUI::SBInterstitialReason interstitial_reason) { |
| 226 bool primary_subresource = unsafe_resources[0].is_subresource; | 226 bool primary_subresource = unsafe_resources[0].is_subresource; |
| 227 switch (interstitial_reason) { | 227 switch (interstitial_reason) { |
| 228 case SafeBrowsingErrorUI::SB_REASON_MALWARE: | 228 case BaseSafeBrowsingErrorUI::SB_REASON_MALWARE: |
| 229 return primary_subresource ? "malware_subresource" : "malware"; | 229 return primary_subresource ? "malware_subresource" : "malware"; |
| 230 case SafeBrowsingErrorUI::SB_REASON_HARMFUL: | 230 case BaseSafeBrowsingErrorUI::SB_REASON_HARMFUL: |
| 231 return primary_subresource ? "harmful_subresource" : "harmful"; | 231 return primary_subresource ? "harmful_subresource" : "harmful"; |
| 232 case SafeBrowsingErrorUI::SB_REASON_PHISHING: | 232 case BaseSafeBrowsingErrorUI::SB_REASON_PHISHING: |
| 233 ThreatPatternType threat_pattern_type = | 233 ThreatPatternType threat_pattern_type = |
| 234 unsafe_resources[0].threat_metadata.threat_pattern_type; | 234 unsafe_resources[0].threat_metadata.threat_pattern_type; |
| 235 if (threat_pattern_type == ThreatPatternType::PHISHING || | 235 if (threat_pattern_type == ThreatPatternType::PHISHING || |
| 236 threat_pattern_type == ThreatPatternType::NONE) | 236 threat_pattern_type == ThreatPatternType::NONE) |
| 237 return primary_subresource ? "phishing_subresource" : "phishing"; | 237 return primary_subresource ? "phishing_subresource" : "phishing"; |
| 238 else if (threat_pattern_type == ThreatPatternType::SOCIAL_ENGINEERING_ADS) | 238 else if (threat_pattern_type == ThreatPatternType::SOCIAL_ENGINEERING_ADS) |
| 239 return primary_subresource ? "social_engineering_ads_subresource" | 239 return primary_subresource ? "social_engineering_ads_subresource" |
| 240 : "social_engineering_ads"; | 240 : "social_engineering_ads"; |
| 241 else if (threat_pattern_type == | 241 else if (threat_pattern_type == |
| 242 ThreatPatternType::SOCIAL_ENGINEERING_LANDING) | 242 ThreatPatternType::SOCIAL_ENGINEERING_LANDING) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 264 case safe_browsing::ThreatSource::CLIENT_SIDE_DETECTION: | 264 case safe_browsing::ThreatSource::CLIENT_SIDE_DETECTION: |
| 265 return "from_client_side_detection"; | 265 return "from_client_side_detection"; |
| 266 case safe_browsing::ThreatSource::UNKNOWN: | 266 case safe_browsing::ThreatSource::UNKNOWN: |
| 267 break; | 267 break; |
| 268 } | 268 } |
| 269 NOTREACHED(); | 269 NOTREACHED(); |
| 270 return std::string(); | 270 return std::string(); |
| 271 } | 271 } |
| 272 | 272 |
| 273 // static | 273 // static |
| 274 SafeBrowsingErrorUI::SBInterstitialReason | 274 security_interstitials::BaseSafeBrowsingErrorUI::SBInterstitialReason |
| 275 BaseBlockingPage::GetInterstitialReason( | 275 BaseBlockingPage::GetInterstitialReason( |
| 276 const UnsafeResourceList& unsafe_resources) { | 276 const UnsafeResourceList& unsafe_resources) { |
| 277 bool harmful = false; | 277 bool harmful = false; |
| 278 for (UnsafeResourceList::const_iterator iter = unsafe_resources.begin(); | 278 for (UnsafeResourceList::const_iterator iter = unsafe_resources.begin(); |
| 279 iter != unsafe_resources.end(); ++iter) { | 279 iter != unsafe_resources.end(); ++iter) { |
| 280 const BaseUIManager::UnsafeResource& resource = *iter; | 280 const BaseUIManager::UnsafeResource& resource = *iter; |
| 281 safe_browsing::SBThreatType threat_type = resource.threat_type; | 281 safe_browsing::SBThreatType threat_type = resource.threat_type; |
| 282 if (threat_type == SB_THREAT_TYPE_URL_MALWARE || | 282 if (threat_type == SB_THREAT_TYPE_URL_MALWARE || |
| 283 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL) { | 283 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL) { |
| 284 return SafeBrowsingErrorUI::SB_REASON_MALWARE; | 284 return BaseSafeBrowsingErrorUI::SB_REASON_MALWARE; |
| 285 } else if (threat_type == SB_THREAT_TYPE_URL_UNWANTED) { | 285 } else if (threat_type == SB_THREAT_TYPE_URL_UNWANTED) { |
| 286 harmful = true; | 286 harmful = true; |
| 287 } else { | 287 } else { |
| 288 DCHECK(threat_type == SB_THREAT_TYPE_URL_PHISHING || | 288 DCHECK(threat_type == SB_THREAT_TYPE_URL_PHISHING || |
| 289 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL); | 289 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL); |
| 290 } | 290 } |
| 291 } | 291 } |
| 292 | 292 |
| 293 if (harmful) | 293 if (harmful) |
| 294 return SafeBrowsingErrorUI::SB_REASON_HARMFUL; | 294 return BaseSafeBrowsingErrorUI::SB_REASON_HARMFUL; |
| 295 return SafeBrowsingErrorUI::SB_REASON_PHISHING; | 295 return BaseSafeBrowsingErrorUI::SB_REASON_PHISHING; |
| 296 } | 296 } |
| 297 | 297 |
| 298 BaseUIManager* BaseBlockingPage::ui_manager() const { | 298 BaseUIManager* BaseBlockingPage::ui_manager() const { |
| 299 return ui_manager_; | 299 return ui_manager_; |
| 300 } | 300 } |
| 301 | 301 |
| 302 const GURL BaseBlockingPage::main_frame_url() const { | 302 const GURL BaseBlockingPage::main_frame_url() const { |
| 303 return main_frame_url_; | 303 return main_frame_url_; |
| 304 } | 304 } |
| 305 | 305 |
| 306 BaseBlockingPage::UnsafeResourceList | 306 BaseBlockingPage::UnsafeResourceList |
| 307 BaseBlockingPage::unsafe_resources() const { | 307 BaseBlockingPage::unsafe_resources() const { |
| 308 return unsafe_resources_; | 308 return unsafe_resources_; |
| 309 } | 309 } |
| 310 | 310 |
| 311 SafeBrowsingErrorUI* BaseBlockingPage::sb_error_ui() const { | 311 SafeBrowsingLoudErrorUI* BaseBlockingPage::sb_error_ui() const { |
| 312 return sb_error_ui_.get(); | 312 return sb_error_ui_.get(); |
| 313 } | 313 } |
| 314 | 314 |
| 315 void BaseBlockingPage::set_proceeded(bool proceeded) { | 315 void BaseBlockingPage::set_proceeded(bool proceeded) { |
| 316 proceeded_ = proceeded; | 316 proceeded_ = proceeded; |
| 317 } | 317 } |
| 318 | 318 |
| 319 // static | 319 // static |
| 320 security_interstitials::MetricsHelper::ReportDetails | 320 security_interstitials::MetricsHelper::ReportDetails |
| 321 BaseBlockingPage::GetReportingInfo(const UnsafeResourceList& unsafe_resources) { | 321 BaseBlockingPage::GetReportingInfo(const UnsafeResourceList& unsafe_resources) { |
| 322 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason = | 322 BaseSafeBrowsingErrorUI::SBInterstitialReason interstitial_reason = |
| 323 GetInterstitialReason(unsafe_resources); | 323 GetInterstitialReason(unsafe_resources); |
| 324 | 324 |
| 325 security_interstitials::MetricsHelper::ReportDetails reporting_info; | 325 security_interstitials::MetricsHelper::ReportDetails reporting_info; |
| 326 reporting_info.metric_prefix = | 326 reporting_info.metric_prefix = |
| 327 GetMetricPrefix(unsafe_resources, interstitial_reason); | 327 GetMetricPrefix(unsafe_resources, interstitial_reason); |
| 328 reporting_info.extra_suffix = GetExtraMetricsSuffix(unsafe_resources); | 328 reporting_info.extra_suffix = GetExtraMetricsSuffix(unsafe_resources); |
| 329 return reporting_info; | 329 return reporting_info; |
| 330 } | 330 } |
| 331 | 331 |
| 332 // static | 332 // static |
| 333 std::unique_ptr<SecurityInterstitialControllerClient> | 333 std::unique_ptr<SecurityInterstitialControllerClient> |
| 334 BaseBlockingPage::CreateControllerClient( | 334 BaseBlockingPage::CreateControllerClient( |
| 335 content::WebContents* web_contents, | 335 content::WebContents* web_contents, |
| 336 const UnsafeResourceList& unsafe_resources, | 336 const UnsafeResourceList& unsafe_resources, |
| 337 BaseUIManager* ui_manager) { | 337 BaseUIManager* ui_manager) { |
| 338 history::HistoryService* history_service = | 338 history::HistoryService* history_service = |
| 339 ui_manager->history_service(web_contents); | 339 ui_manager->history_service(web_contents); |
| 340 | 340 |
| 341 std::unique_ptr<security_interstitials::MetricsHelper> metrics_helper = | 341 std::unique_ptr<security_interstitials::MetricsHelper> metrics_helper = |
| 342 base::MakeUnique<security_interstitials::MetricsHelper>( | 342 base::MakeUnique<security_interstitials::MetricsHelper>( |
| 343 unsafe_resources[0].url, GetReportingInfo(unsafe_resources), | 343 unsafe_resources[0].url, GetReportingInfo(unsafe_resources), |
| 344 history_service); | 344 history_service); |
| 345 | 345 |
| 346 return base::MakeUnique<SecurityInterstitialControllerClient>( | 346 return base::MakeUnique<SecurityInterstitialControllerClient>( |
| 347 web_contents, std::move(metrics_helper), nullptr, /* prefs */ | 347 web_contents, std::move(metrics_helper), nullptr, /* prefs */ |
| 348 ui_manager->app_locale(), ui_manager->default_safe_page()); | 348 ui_manager->app_locale(), ui_manager->default_safe_page()); |
| 349 } | 349 } |
| 350 | 350 |
| 351 } // namespace safe_browsing | 351 } // namespace safe_browsing |
| OLD | NEW |