| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/incident_reporting/resource_request_detec
tor.h" | 5 #include "chrome/browser/safe_browsing/incident_reporting/resource_request_detec
tor.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/safe_browsing/incident_reporting/incident_receiver.h" | 11 #include "chrome/browser/safe_browsing/incident_reporting/incident_receiver.h" |
| 11 #include "chrome/browser/safe_browsing/incident_reporting/resource_request_incid
ent.h" | 12 #include "chrome/browser/safe_browsing/incident_reporting/resource_request_incid
ent.h" |
| 12 #include "chrome/common/safe_browsing/csd.pb.h" | 13 #include "chrome/common/safe_browsing/csd.pb.h" |
| 13 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 14 #include "content/public/browser/render_frame_host.h" | 15 #include "content/public/browser/render_frame_host.h" |
| 15 #include "content/public/browser/render_process_host.h" | 16 #include "content/public/browser/render_process_host.h" |
| 16 #include "content/public/browser/resource_request_info.h" | 17 #include "content/public/browser/resource_request_info.h" |
| 17 #include "content/public/browser/site_instance.h" | 18 #include "content/public/browser/site_instance.h" |
| 18 #include "crypto/sha2.h" | 19 #include "crypto/sha2.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 55 |
| 55 // Implementation of SafeBrowsingDatabaseManager::Client that is used to lookup | 56 // Implementation of SafeBrowsingDatabaseManager::Client that is used to lookup |
| 56 // a resource blacklist. Can be constructed on any thread. | 57 // a resource blacklist. Can be constructed on any thread. |
| 57 class ResourceRequestDetectorClient | 58 class ResourceRequestDetectorClient |
| 58 : public SafeBrowsingDatabaseManager::Client, | 59 : public SafeBrowsingDatabaseManager::Client, |
| 59 public base::RefCountedThreadSafe<ResourceRequestDetectorClient> { | 60 public base::RefCountedThreadSafe<ResourceRequestDetectorClient> { |
| 60 public: | 61 public: |
| 61 using ResourceRequestIncidentMessage = | 62 using ResourceRequestIncidentMessage = |
| 62 ClientIncidentReport::IncidentData::ResourceRequestIncident; | 63 ClientIncidentReport::IncidentData::ResourceRequestIncident; |
| 63 | 64 |
| 64 typedef base::Callback<void(scoped_ptr<ResourceRequestIncidentMessage>)> | 65 typedef base::Callback<void(std::unique_ptr<ResourceRequestIncidentMessage>)> |
| 65 OnResultCallback; | 66 OnResultCallback; |
| 66 | 67 |
| 67 ResourceRequestDetectorClient( | 68 ResourceRequestDetectorClient( |
| 68 const GURL& resource_url, | 69 const GURL& resource_url, |
| 69 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager, | 70 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager, |
| 70 const OnResultCallback& callback) | 71 const OnResultCallback& callback) |
| 71 : database_manager_(database_manager) | 72 : database_manager_(database_manager) |
| 72 , callback_(callback) { | 73 , callback_(callback) { |
| 73 content::BrowserThread::PostTask( | 74 content::BrowserThread::PostTask( |
| 74 content::BrowserThread::IO, FROM_HERE, | 75 content::BrowserThread::IO, FROM_HERE, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 93 // client object may be destroyed immediately. | 94 // client object may be destroyed immediately. |
| 94 if (database_manager_->CheckResourceUrl(resource_url, this)) { | 95 if (database_manager_->CheckResourceUrl(resource_url, this)) { |
| 95 Release(); | 96 Release(); |
| 96 } | 97 } |
| 97 } | 98 } |
| 98 | 99 |
| 99 void OnCheckResourceUrlResult(const GURL& url, | 100 void OnCheckResourceUrlResult(const GURL& url, |
| 100 SBThreatType threat_type, | 101 SBThreatType threat_type, |
| 101 const std::string& threat_hash) override { | 102 const std::string& threat_hash) override { |
| 102 if (threat_type == SB_THREAT_TYPE_BLACKLISTED_RESOURCE) { | 103 if (threat_type == SB_THREAT_TYPE_BLACKLISTED_RESOURCE) { |
| 103 scoped_ptr<ResourceRequestIncidentMessage> incident_data( | 104 std::unique_ptr<ResourceRequestIncidentMessage> incident_data( |
| 104 new ResourceRequestIncidentMessage()); | 105 new ResourceRequestIncidentMessage()); |
| 105 incident_data->set_type(ResourceRequestIncidentMessage::TYPE_PATTERN); | 106 incident_data->set_type(ResourceRequestIncidentMessage::TYPE_PATTERN); |
| 106 incident_data->set_digest(threat_hash); | 107 incident_data->set_digest(threat_hash); |
| 107 content::BrowserThread::PostTask( | 108 content::BrowserThread::PostTask( |
| 108 content::BrowserThread::UI, FROM_HERE, | 109 content::BrowserThread::UI, FROM_HERE, |
| 109 base::Bind(callback_, base::Passed(&incident_data))); | 110 base::Bind(callback_, base::Passed(&incident_data))); |
| 110 } | 111 } |
| 111 Release(); // Balanced in StartCheck. | 112 Release(); // Balanced in StartCheck. |
| 112 } | 113 } |
| 113 | 114 |
| 114 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; | 115 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; |
| 115 OnResultCallback callback_; | 116 OnResultCallback callback_; |
| 116 | 117 |
| 117 DISALLOW_COPY_AND_ASSIGN(ResourceRequestDetectorClient); | 118 DISALLOW_COPY_AND_ASSIGN(ResourceRequestDetectorClient); |
| 118 }; | 119 }; |
| 119 | 120 |
| 120 } // namespace | 121 } // namespace |
| 121 | 122 |
| 122 ResourceRequestDetector::ResourceRequestDetector( | 123 ResourceRequestDetector::ResourceRequestDetector( |
| 123 scoped_refptr<SafeBrowsingDatabaseManager> database_manager, | 124 scoped_refptr<SafeBrowsingDatabaseManager> database_manager, |
| 124 scoped_ptr<IncidentReceiver> incident_receiver) | 125 std::unique_ptr<IncidentReceiver> incident_receiver) |
| 125 : incident_receiver_(std::move(incident_receiver)), | 126 : incident_receiver_(std::move(incident_receiver)), |
| 126 database_manager_(database_manager), | 127 database_manager_(database_manager), |
| 127 allow_null_profile_for_testing_(false), | 128 allow_null_profile_for_testing_(false), |
| 128 weak_ptr_factory_(this) { | 129 weak_ptr_factory_(this) {} |
| 129 } | |
| 130 | 130 |
| 131 ResourceRequestDetector::~ResourceRequestDetector() { | 131 ResourceRequestDetector::~ResourceRequestDetector() { |
| 132 } | 132 } |
| 133 | 133 |
| 134 void ResourceRequestDetector::OnResourceRequest( | 134 void ResourceRequestDetector::OnResourceRequest( |
| 135 const net::URLRequest* request) { | 135 const net::URLRequest* request) { |
| 136 // Only look at actual net requests (e.g., not chrome-extensions://id/foo.js). | 136 // Only look at actual net requests (e.g., not chrome-extensions://id/foo.js). |
| 137 if (!request->url().SchemeIsHTTPOrHTTPS()) | 137 if (!request->url().SchemeIsHTTPOrHTTPS()) |
| 138 return; | 138 return; |
| 139 | 139 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 156 } | 156 } |
| 157 | 157 |
| 158 void ResourceRequestDetector::set_allow_null_profile_for_testing( | 158 void ResourceRequestDetector::set_allow_null_profile_for_testing( |
| 159 bool allow_null_profile_for_testing) { | 159 bool allow_null_profile_for_testing) { |
| 160 allow_null_profile_for_testing_ = allow_null_profile_for_testing; | 160 allow_null_profile_for_testing_ = allow_null_profile_for_testing; |
| 161 } | 161 } |
| 162 | 162 |
| 163 void ResourceRequestDetector::ReportIncidentOnUIThread( | 163 void ResourceRequestDetector::ReportIncidentOnUIThread( |
| 164 int render_process_id, | 164 int render_process_id, |
| 165 int render_frame_id, | 165 int render_frame_id, |
| 166 scoped_ptr<ClientIncidentReport_IncidentData_ResourceRequestIncident> | 166 std::unique_ptr<ClientIncidentReport_IncidentData_ResourceRequestIncident> |
| 167 incident_data) { | 167 incident_data) { |
| 168 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 168 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 169 | 169 |
| 170 Profile* profile = GetProfileForRenderProcessId(render_process_id); | 170 Profile* profile = GetProfileForRenderProcessId(render_process_id); |
| 171 if (profile || allow_null_profile_for_testing_) { | 171 if (profile || allow_null_profile_for_testing_) { |
| 172 // Add the URL obtained from the RenderFrameHost, if available. | 172 // Add the URL obtained from the RenderFrameHost, if available. |
| 173 GURL host_url = GetUrlForRenderFrameId(render_process_id, render_frame_id); | 173 GURL host_url = GetUrlForRenderFrameId(render_process_id, render_frame_id); |
| 174 if (host_url.is_valid()) | 174 if (host_url.is_valid()) |
| 175 incident_data->set_origin(host_url.GetOrigin().spec()); | 175 incident_data->set_origin(host_url.GetOrigin().spec()); |
| 176 | 176 |
| 177 incident_receiver_->AddIncidentForProfile( | 177 incident_receiver_->AddIncidentForProfile( |
| 178 profile, | 178 profile, base::WrapUnique( |
| 179 make_scoped_ptr(new ResourceRequestIncident(std::move(incident_data)))); | 179 new ResourceRequestIncident(std::move(incident_data)))); |
| 180 } | 180 } |
| 181 } | 181 } |
| 182 | 182 |
| 183 } // namespace safe_browsing | 183 } // namespace safe_browsing |
| OLD | NEW |