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 MalwareDetails class. | 5 // Implementation of the MalwareDetails class. |
6 | 6 |
7 #include "chrome/browser/safe_browsing/threat_details.h" | 7 #include "chrome/browser/safe_browsing/threat_details.h" |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/safe_browsing/report.pb.h" | 12 #include "chrome/browser/safe_browsing/report.pb.h" |
13 #include "chrome/browser/safe_browsing/threat_details_cache.h" | 13 #include "chrome/browser/safe_browsing/threat_details_cache.h" |
14 #include "chrome/browser/safe_browsing/threat_details_history.h" | 14 #include "chrome/browser/safe_browsing/threat_details_history.h" |
15 #include "chrome/common/safe_browsing/safebrowsing_messages.h" | 15 #include "chrome/common/safe_browsing/safebrowsing_messages.h" |
16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/browser/navigation_controller.h" | 17 #include "content/public/browser/navigation_controller.h" |
18 #include "content/public/browser/navigation_entry.h" | 18 #include "content/public/browser/navigation_entry.h" |
19 #include "content/public/browser/render_view_host.h" | 19 #include "content/public/browser/render_view_host.h" |
20 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
21 #include "net/url_request/url_request_context_getter.h" | 21 #include "net/url_request/url_request_context_getter.h" |
22 | 22 |
23 using content::BrowserThread; | 23 using content::BrowserThread; |
24 using content::NavigationEntry; | 24 using content::NavigationEntry; |
25 using content::WebContents; | 25 using content::WebContents; |
26 using safe_browsing::ClientMalwareReportRequest; | 26 |
27 namespace safe_browsing { | |
28 | |
29 class ClientMalwareReportRequest; | |
Nathan Parker
2015/11/05 22:00:53
Should be able to remove this, since it must have
vakh (old account. dont use)
2015/11/07 01:22:57
Done.
| |
27 | 30 |
28 // Keep in sync with KMaxNodes in renderer/safe_browsing/malware_dom_details | 31 // Keep in sync with KMaxNodes in renderer/safe_browsing/malware_dom_details |
29 static const uint32 kMaxDomNodes = 500; | 32 static const uint32 kMaxDomNodes = 500; |
30 | 33 |
31 // static | 34 // static |
32 ThreatDetailsFactory* ThreatDetails::factory_ = NULL; | 35 ThreatDetailsFactory* ThreatDetails::factory_ = NULL; |
33 | 36 |
34 // The default ThreatDetailsFactory. Global, made a singleton so we | 37 // The default ThreatDetailsFactory. Global, made a singleton so we |
35 // don't leak it. | 38 // don't leak it. |
36 class ThreatDetailsFactoryImpl : public ThreatDetailsFactory { | 39 class ThreatDetailsFactoryImpl : public ThreatDetailsFactory { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 // TODO(panayiotis): also skip internal urls. | 100 // TODO(panayiotis): also skip internal urls. |
98 return url.SchemeIs("http") || url.SchemeIs("https"); | 101 return url.SchemeIs("http") || url.SchemeIs("https"); |
99 } | 102 } |
100 | 103 |
101 // Looks for a Resource for the given url in resources_. If found, it | 104 // Looks for a Resource for the given url in resources_. If found, it |
102 // updates |resource|. Otherwise, it creates a new message, adds it to | 105 // updates |resource|. Otherwise, it creates a new message, adds it to |
103 // resources_ and updates |resource| to point to it. | 106 // resources_ and updates |resource| to point to it. |
104 // | 107 // |
105 ClientMalwareReportRequest::Resource* ThreatDetails::FindOrCreateResource( | 108 ClientMalwareReportRequest::Resource* ThreatDetails::FindOrCreateResource( |
106 const GURL& url) { | 109 const GURL& url) { |
107 safe_browsing::ResourceMap::iterator it = resources_.find(url.spec()); | 110 ResourceMap::iterator it = resources_.find(url.spec()); |
108 if (it != resources_.end()) | 111 if (it != resources_.end()) |
109 return it->second.get(); | 112 return it->second.get(); |
110 | 113 |
111 // Create the resource for |url|. | 114 // Create the resource for |url|. |
112 int id = resources_.size(); | 115 int id = resources_.size(); |
113 linked_ptr<ClientMalwareReportRequest::Resource> new_resource( | 116 linked_ptr<ClientMalwareReportRequest::Resource> new_resource( |
114 new ClientMalwareReportRequest::Resource()); | 117 new ClientMalwareReportRequest::Resource()); |
115 new_resource->set_url(url.spec()); | 118 new_resource->set_url(url.spec()); |
116 new_resource->set_id(id); | 119 new_resource->set_id(id); |
117 resources_[url.spec()] = new_resource; | 120 resources_[url.spec()] = new_resource; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 // closed the tab, or clicked proceed or goback. Since the user needs | 246 // closed the tab, or clicked proceed or goback. Since the user needs |
244 // to take an action, we expect this to be called after | 247 // to take an action, we expect this to be called after |
245 // OnReceivedThreatDOMDetails in most cases. If not, we don't include | 248 // OnReceivedThreatDOMDetails in most cases. If not, we don't include |
246 // the DOM data in our report. | 249 // the DOM data in our report. |
247 void ThreatDetails::FinishCollection(bool did_proceed, int num_visit) { | 250 void ThreatDetails::FinishCollection(bool did_proceed, int num_visit) { |
248 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 251 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
249 | 252 |
250 did_proceed_ = did_proceed; | 253 did_proceed_ = did_proceed; |
251 num_visits_ = num_visit; | 254 num_visits_ = num_visit; |
252 std::vector<GURL> urls; | 255 std::vector<GURL> urls; |
253 for (safe_browsing::ResourceMap::const_iterator it = resources_.begin(); | 256 for (ResourceMap::const_iterator it = resources_.begin(); |
254 it != resources_.end(); ++it) { | 257 it != resources_.end(); ++it) { |
255 urls.push_back(GURL(it->first)); | 258 urls.push_back(GURL(it->first)); |
256 } | 259 } |
257 redirects_collector_->StartHistoryCollection( | 260 redirects_collector_->StartHistoryCollection( |
258 urls, base::Bind(&ThreatDetails::OnRedirectionCollectionReady, this)); | 261 urls, base::Bind(&ThreatDetails::OnRedirectionCollectionReady, this)); |
259 } | 262 } |
260 | 263 |
261 void ThreatDetails::OnRedirectionCollectionReady() { | 264 void ThreatDetails::OnRedirectionCollectionReady() { |
262 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 265 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
263 const std::vector<safe_browsing::RedirectChain>& redirects = | 266 const std::vector<RedirectChain>& redirects = |
264 redirects_collector_->GetCollectedUrls(); | 267 redirects_collector_->GetCollectedUrls(); |
265 | 268 |
266 for (size_t i = 0; i < redirects.size(); ++i) | 269 for (size_t i = 0; i < redirects.size(); ++i) |
267 AddRedirectUrlList(redirects[i]); | 270 AddRedirectUrlList(redirects[i]); |
268 | 271 |
269 // Call the cache collector | 272 // Call the cache collector |
270 cache_collector_->StartCacheCollection( | 273 cache_collector_->StartCacheCollection( |
271 request_context_getter_.get(), &resources_, &cache_result_, | 274 request_context_getter_.get(), &resources_, &cache_result_, |
272 base::Bind(&ThreatDetails::OnCacheCollectionReady, this)); | 275 base::Bind(&ThreatDetails::OnCacheCollectionReady, this)); |
273 } | 276 } |
274 | 277 |
275 void ThreatDetails::AddRedirectUrlList(const std::vector<GURL>& urls) { | 278 void ThreatDetails::AddRedirectUrlList(const std::vector<GURL>& urls) { |
276 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 279 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
277 for (size_t i = 0; i < urls.size() - 1; ++i) { | 280 for (size_t i = 0; i < urls.size() - 1; ++i) { |
278 AddUrl(urls[i], urls[i + 1], std::string(), NULL); | 281 AddUrl(urls[i], urls[i + 1], std::string(), NULL); |
279 } | 282 } |
280 } | 283 } |
281 | 284 |
282 void ThreatDetails::OnCacheCollectionReady() { | 285 void ThreatDetails::OnCacheCollectionReady() { |
283 DVLOG(1) << "OnCacheCollectionReady."; | 286 DVLOG(1) << "OnCacheCollectionReady."; |
284 // Add all the urls in our |resources_| maps to the |report_| protocol buffer. | 287 // Add all the urls in our |resources_| maps to the |report_| protocol buffer. |
285 for (safe_browsing::ResourceMap::const_iterator it = resources_.begin(); | 288 for (ResourceMap::const_iterator it = resources_.begin(); |
286 it != resources_.end(); ++it) { | 289 it != resources_.end(); ++it) { |
287 ClientMalwareReportRequest::Resource* pb_resource = | 290 ClientMalwareReportRequest::Resource* pb_resource = |
288 report_->add_resources(); | 291 report_->add_resources(); |
289 pb_resource->CopyFrom(*(it->second)); | 292 pb_resource->CopyFrom(*(it->second)); |
290 const GURL url(pb_resource->url()); | 293 const GURL url(pb_resource->url()); |
291 if (url.SchemeIs("https")) { | 294 if (url.SchemeIs("https")) { |
292 // Don't report headers of HTTPS requests since they may contain private | 295 // Don't report headers of HTTPS requests since they may contain private |
293 // cookies. We still retain the full URL. | 296 // cookies. We still retain the full URL. |
294 DVLOG(1) << "Clearing out HTTPS resource: " << pb_resource->url(); | 297 DVLOG(1) << "Clearing out HTTPS resource: " << pb_resource->url(); |
295 pb_resource->clear_request(); | 298 pb_resource->clear_request(); |
(...skipping 10 matching lines...) Expand all Loading... | |
306 | 309 |
307 // Send the report, using the SafeBrowsingService. | 310 // Send the report, using the SafeBrowsingService. |
308 std::string serialized; | 311 std::string serialized; |
309 if (!report_->SerializeToString(&serialized)) { | 312 if (!report_->SerializeToString(&serialized)) { |
310 DLOG(ERROR) << "Unable to serialize the malware report."; | 313 DLOG(ERROR) << "Unable to serialize the malware report."; |
311 return; | 314 return; |
312 } | 315 } |
313 | 316 |
314 ui_manager_->SendSerializedThreatDetails(serialized); | 317 ui_manager_->SendSerializedThreatDetails(serialized); |
315 } | 318 } |
319 | |
320 } // namespace safe_browsing | |
OLD | NEW |