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/safe_browsing/client_side_detection_host.h" | 5 #include "chrome/browser/safe_browsing/client_side_detection_host.h" |
6 | 6 |
| 7 #include <memory> |
7 #include <vector> | 8 #include <vector> |
8 | 9 |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
11 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/sequenced_task_runner_helpers.h" | 14 #include "base/sequenced_task_runner_helpers.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" | 18 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" |
19 #include "chrome/browser/safe_browsing/client_side_detection_service.h" | 19 #include "chrome/browser/safe_browsing/client_side_detection_service.h" |
20 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 20 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
21 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
22 #include "chrome/common/safe_browsing/csd.pb.h" | 22 #include "chrome/common/safe_browsing/csd.pb.h" |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 DVLOG(2) << "Page finished loading."; | 480 DVLOG(2) << "Page finished loading."; |
481 pageload_complete_ = true; | 481 pageload_complete_ = true; |
482 MaybeStartMalwareFeatureExtraction(); | 482 MaybeStartMalwareFeatureExtraction(); |
483 } | 483 } |
484 | 484 |
485 void ClientSideDetectionHost::MaybeStartMalwareFeatureExtraction() { | 485 void ClientSideDetectionHost::MaybeStartMalwareFeatureExtraction() { |
486 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 486 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
487 if (csd_service_ && browse_info_.get() && | 487 if (csd_service_ && browse_info_.get() && |
488 should_classify_for_malware_ && | 488 should_classify_for_malware_ && |
489 pageload_complete_) { | 489 pageload_complete_) { |
490 scoped_ptr<ClientMalwareRequest> malware_request( | 490 std::unique_ptr<ClientMalwareRequest> malware_request( |
491 new ClientMalwareRequest); | 491 new ClientMalwareRequest); |
492 // Start browser-side malware feature extraction. Once we're done it will | 492 // Start browser-side malware feature extraction. Once we're done it will |
493 // send the malware client verdict request. | 493 // send the malware client verdict request. |
494 malware_request->set_url(browse_info_->url.spec()); | 494 malware_request->set_url(browse_info_->url.spec()); |
495 const GURL& referrer = browse_info_->referrer; | 495 const GURL& referrer = browse_info_->referrer; |
496 if (referrer.SchemeIs("http")) { // Only send http urls. | 496 if (referrer.SchemeIs("http")) { // Only send http urls. |
497 malware_request->set_referrer_url(referrer.spec()); | 497 malware_request->set_referrer_url(referrer.spec()); |
498 } | 498 } |
499 // This function doesn't expect browse_info_ to stay around after this | 499 // This function doesn't expect browse_info_ to stay around after this |
500 // function returns. | 500 // function returns. |
(...skipping 10 matching lines...) Expand all Loading... |
511 const std::string& verdict_str) { | 511 const std::string& verdict_str) { |
512 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 512 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
513 // There is something seriously wrong if there is no service class but | 513 // There is something seriously wrong if there is no service class but |
514 // this method is called. The renderer should not start phishing detection | 514 // this method is called. The renderer should not start phishing detection |
515 // if there isn't any service class in the browser. | 515 // if there isn't any service class in the browser. |
516 DCHECK(csd_service_); | 516 DCHECK(csd_service_); |
517 DCHECK(browse_info_.get()); | 517 DCHECK(browse_info_.get()); |
518 | 518 |
519 // We parse the protocol buffer here. If we're unable to parse it we won't | 519 // We parse the protocol buffer here. If we're unable to parse it we won't |
520 // send the verdict further. | 520 // send the verdict further. |
521 scoped_ptr<ClientPhishingRequest> verdict(new ClientPhishingRequest); | 521 std::unique_ptr<ClientPhishingRequest> verdict(new ClientPhishingRequest); |
522 if (csd_service_ && | 522 if (csd_service_ && |
523 browse_info_.get() && | 523 browse_info_.get() && |
524 verdict->ParseFromString(verdict_str) && | 524 verdict->ParseFromString(verdict_str) && |
525 verdict->IsInitialized()) { | 525 verdict->IsInitialized()) { |
526 UMA_HISTOGRAM_BOOLEAN( | 526 UMA_HISTOGRAM_BOOLEAN( |
527 "SBClientPhishing.ClientDeterminesPhishing", | 527 "SBClientPhishing.ClientDeterminesPhishing", |
528 verdict->is_phishing()); | 528 verdict->is_phishing()); |
529 // We only send phishing verdict to the server if the verdict is phishing or | 529 // We only send phishing verdict to the server if the verdict is phishing or |
530 // if a SafeBrowsing interstitial was already shown for this site. E.g., a | 530 // if a SafeBrowsing interstitial was already shown for this site. E.g., a |
531 // malware or phishing interstitial was shown but the user clicked | 531 // malware or phishing interstitial was shown but the user clicked |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 ui_manager_->DisplayBlockingPage(resource); | 610 ui_manager_->DisplayBlockingPage(resource); |
611 } | 611 } |
612 // If there is true malware verdict, invalidate weakptr so that no longer | 612 // If there is true malware verdict, invalidate weakptr so that no longer |
613 // consider the phishing vedict. | 613 // consider the phishing vedict. |
614 weak_factory_.InvalidateWeakPtrs(); | 614 weak_factory_.InvalidateWeakPtrs(); |
615 } | 615 } |
616 } | 616 } |
617 | 617 |
618 void ClientSideDetectionHost::FeatureExtractionDone( | 618 void ClientSideDetectionHost::FeatureExtractionDone( |
619 bool success, | 619 bool success, |
620 scoped_ptr<ClientPhishingRequest> request) { | 620 std::unique_ptr<ClientPhishingRequest> request) { |
621 DCHECK(request); | 621 DCHECK(request); |
622 DVLOG(2) << "Feature extraction done (success:" << success << ") for URL: " | 622 DVLOG(2) << "Feature extraction done (success:" << success << ") for URL: " |
623 << request->url() << ". Start sending client phishing request."; | 623 << request->url() << ". Start sending client phishing request."; |
624 ClientSideDetectionService::ClientReportPhishingRequestCallback callback; | 624 ClientSideDetectionService::ClientReportPhishingRequestCallback callback; |
625 // If the client-side verdict isn't phishing we don't care about the server | 625 // If the client-side verdict isn't phishing we don't care about the server |
626 // response because we aren't going to display a warning. | 626 // response because we aren't going to display a warning. |
627 if (request->is_phishing()) { | 627 if (request->is_phishing()) { |
628 callback = base::Bind(&ClientSideDetectionHost::MaybeShowPhishingWarning, | 628 callback = base::Bind(&ClientSideDetectionHost::MaybeShowPhishingWarning, |
629 weak_factory_.GetWeakPtr()); | 629 weak_factory_.GetWeakPtr()); |
630 } | 630 } |
631 Profile* profile = | 631 Profile* profile = |
632 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 632 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
633 // Send ping even if the browser feature extraction failed. | 633 // Send ping even if the browser feature extraction failed. |
634 csd_service_->SendClientReportPhishingRequest( | 634 csd_service_->SendClientReportPhishingRequest( |
635 request.release(), // The service takes ownership of the request object. | 635 request.release(), // The service takes ownership of the request object. |
636 profile->GetPrefs()->GetBoolean( | 636 profile->GetPrefs()->GetBoolean( |
637 prefs::kSafeBrowsingExtendedReportingEnabled), | 637 prefs::kSafeBrowsingExtendedReportingEnabled), |
638 callback); | 638 callback); |
639 } | 639 } |
640 | 640 |
641 void ClientSideDetectionHost::MalwareFeatureExtractionDone( | 641 void ClientSideDetectionHost::MalwareFeatureExtractionDone( |
642 bool feature_extraction_success, | 642 bool feature_extraction_success, |
643 scoped_ptr<ClientMalwareRequest> request) { | 643 std::unique_ptr<ClientMalwareRequest> request) { |
644 DCHECK(request.get()); | 644 DCHECK(request.get()); |
645 DVLOG(2) << "Malware Feature extraction done for URL: " << request->url() | 645 DVLOG(2) << "Malware Feature extraction done for URL: " << request->url() |
646 << ", with badip url count:" << request->bad_ip_url_info_size(); | 646 << ", with badip url count:" << request->bad_ip_url_info_size(); |
647 UMA_HISTOGRAM_BOOLEAN( | 647 UMA_HISTOGRAM_BOOLEAN( |
648 "SBClientMalware.ResourceUrlMatchesBadIp", | 648 "SBClientMalware.ResourceUrlMatchesBadIp", |
649 request->bad_ip_url_info_size() > 0); | 649 request->bad_ip_url_info_size() > 0); |
650 // Send ping if there is matching features. | 650 // Send ping if there is matching features. |
651 if (feature_extraction_success && request->bad_ip_url_info_size() > 0) { | 651 if (feature_extraction_success && request->bad_ip_url_info_size() > 0) { |
652 DVLOG(1) << "Start sending client malware request."; | 652 DVLOG(1) << "Start sending client malware request."; |
653 ClientSideDetectionService::ClientReportMalwareRequestCallback callback; | 653 ClientSideDetectionService::ClientReportMalwareRequestCallback callback; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 ui_manager_->RemoveObserver(this); | 716 ui_manager_->RemoveObserver(this); |
717 | 717 |
718 ui_manager_ = ui_manager; | 718 ui_manager_ = ui_manager; |
719 if (ui_manager) | 719 if (ui_manager) |
720 ui_manager_->AddObserver(this); | 720 ui_manager_->AddObserver(this); |
721 | 721 |
722 database_manager_ = database_manager; | 722 database_manager_ = database_manager; |
723 } | 723 } |
724 | 724 |
725 } // namespace safe_browsing | 725 } // namespace safe_browsing |
OLD | NEW |