| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/safe_browsing_service.h" | 5 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/browser_thread.h" | 12 #include "chrome/browser/browser_thread.h" |
| 13 #include "chrome/browser/metrics/metrics_service.h" | 13 #include "chrome/browser/metrics/metrics_service.h" |
| 14 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
| 15 #include "chrome/browser/profile_manager.h" | 15 #include "chrome/browser/profile_manager.h" |
| 16 #include "chrome/browser/safe_browsing/malware_report.h" |
| 16 #include "chrome/browser/safe_browsing/protocol_manager.h" | 17 #include "chrome/browser/safe_browsing/protocol_manager.h" |
| 17 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" | 18 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" |
| 18 #include "chrome/browser/safe_browsing/safe_browsing_database.h" | 19 #include "chrome/browser/safe_browsing/safe_browsing_database.h" |
| 19 #include "chrome/browser/tab_contents/tab_util.h" | 20 #include "chrome/browser/tab_contents/tab_util.h" |
| 20 #include "chrome/browser/tab_contents/tab_contents.h" | 21 #include "chrome/browser/tab_contents/tab_contents.h" |
| 21 #include "chrome/common/chrome_constants.h" | 22 #include "chrome/common/chrome_constants.h" |
| 22 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
| 23 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
| 24 #include "chrome/common/net/url_request_context_getter.h" | 25 #include "chrome/common/net/url_request_context_getter.h" |
| 25 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
| 26 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
| 27 #include "net/base/registry_controlled_domain.h" | 28 #include "net/base/registry_controlled_domain.h" |
| 28 | 29 |
| 29 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
| 30 #include "chrome/installer/util/browser_distribution.h" | 31 #include "chrome/installer/util/browser_distribution.h" |
| 31 #endif | 32 #endif |
| 32 | 33 |
| 33 using base::Time; | 34 using base::Time; |
| 34 using base::TimeDelta; | 35 using base::TimeDelta; |
| 35 | 36 |
| 36 // The default URL prefix where browser fetches chunk updates, hashes, | 37 // The default URL prefix where browser fetches chunk updates, hashes, |
| 37 // and reports malware. | 38 // and reports safe browsing hits. |
| 38 static const char* const kSbDefaultInfoURLPrefix = | 39 static const char* const kSbDefaultInfoURLPrefix = |
| 39 "http://safebrowsing.clients.google.com/safebrowsing"; | 40 "http://safebrowsing.clients.google.com/safebrowsing"; |
| 40 | 41 |
| 41 // The default URL prefix where browser fetches MAC client key. | 42 // The default URL prefix where browser fetches MAC client key. |
| 43 // Also used for advanced malware reports. |
| 42 static const char* const kSbDefaultMacKeyURLPrefix = | 44 static const char* const kSbDefaultMacKeyURLPrefix = |
| 43 "https://sb-ssl.google.com/safebrowsing"; | 45 "https://sb-ssl.google.com/safebrowsing"; |
| 44 | 46 |
| 45 static Profile* GetDefaultProfile() { | 47 static Profile* GetDefaultProfile() { |
| 46 FilePath user_data_dir; | 48 FilePath user_data_dir; |
| 47 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 49 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 48 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 50 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 49 return profile_manager->GetDefaultProfile(user_data_dir); | 51 return profile_manager->GetDefaultProfile(user_data_dir); |
| 50 } | 52 } |
| 51 | 53 |
| (...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 if (!enabled_) | 827 if (!enabled_) |
| 826 return; | 828 return; |
| 827 | 829 |
| 828 DVLOG(1) << "ReportSafeBrowsingHit: " << malicious_url << " " << page_url | 830 DVLOG(1) << "ReportSafeBrowsingHit: " << malicious_url << " " << page_url |
| 829 << " " << referrer_url << " " << is_subresource << " " | 831 << " " << referrer_url << " " << is_subresource << " " |
| 830 << threat_type; | 832 << threat_type; |
| 831 protocol_manager_->ReportSafeBrowsingHit(malicious_url, page_url, | 833 protocol_manager_->ReportSafeBrowsingHit(malicious_url, page_url, |
| 832 referrer_url, is_subresource, | 834 referrer_url, is_subresource, |
| 833 threat_type); | 835 threat_type); |
| 834 } | 836 } |
| 837 |
| 838 // Called after the user has opted in to send the malware |report|. |
| 839 void SafeBrowsingService::SendMalwareReport( |
| 840 scoped_refptr<SafeBrowsingMalwareReport> report) { |
| 841 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 842 scoped_ptr<const std::string> serialized(report->GetSerializedReport()); |
| 843 if (!serialized->empty()) { |
| 844 DVLOG(1) << "Sending serialized report."; |
| 845 protocol_manager_->SendMalwareReport(*serialized); |
| 846 } |
| 847 } |
| OLD | NEW |