Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: chrome/browser/safe_browsing/malware_details.cc

Issue 4822002: Send malware reports when a user opts-in from the safe browsing interstitial ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4 //
5 // Implementation of the MalwareDetails class.
6
7 #include "chrome/browser/safe_browsing/malware_details.h"
8
9 #include "chrome/browser/browser_thread.h"
10 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
11 #include "chrome/browser/tab_contents/navigation_entry.h"
12 #include "chrome/browser/tab_contents/tab_contents.h"
13 #include "chrome/browser/safe_browsing/report.pb.h"
14
15 // Create a MalwareDetails for the given tab. Runs in the UI thread.
16 MalwareDetails::MalwareDetails(
17 TabContents* tab_contents,
18 const SafeBrowsingService::UnsafeResource resource)
19 : tab_contents_(tab_contents),
20 resource_(resource) {
21 StartCollection();
22 }
23
24 MalwareDetails::~MalwareDetails() {}
25
26 bool MalwareDetails::IsPublicUrl(const GURL& url) const {
27 return url.SchemeIs("http"); // TODO(panayiotis): also skip internal urls.
28 }
29
30 void MalwareDetails::AddNode(const std::string& url,
31 const std::string& parent) {
32 if (!IsPublicUrl(GURL(url)))
33 return;
34 linked_ptr<safe_browsing::ClientMalwareReportRequest::Resource> resource(
35 new safe_browsing::ClientMalwareReportRequest::Resource());
36 resource->set_url(url);
37 if (!parent.empty() && IsPublicUrl(GURL(parent)))
38 resource->set_parent(parent);
39 urls_[url] = resource;
40 }
41
42 void MalwareDetails::StartCollection() {
43 DVLOG(1) << "Starting to compute malware details.";
44 report_.reset(new safe_browsing::ClientMalwareReportRequest());
45
46 if (IsPublicUrl(resource_.url)) {
47 report_->set_malware_url(resource_.url.spec());
48 }
49
50 GURL page_url = tab_contents_->GetURL();
51 if (IsPublicUrl(page_url)) {
52 report_->set_page_url(page_url.spec());
53 }
54
55 GURL referrer_url;
56 NavigationEntry* nav_entry = tab_contents_->controller().GetActiveEntry();
57 if (nav_entry) {
58 referrer_url = nav_entry->referrer();
59 if (IsPublicUrl(referrer_url)) {
60 report_->set_referrer_url(referrer_url.spec());
61 }
62 }
63
64 // Add the nodes, starting from the page url.
65 AddNode(page_url.spec(), "");
66
67 // Add the resource_url and its original url, if non-empty and different.
68 if (!resource_.original_url.spec().empty() &&
69 resource_.url != resource_.original_url) {
70 // Add original_url, as the parent of resource_url.
71 AddNode(resource_.original_url.spec(), "");
72 AddNode(resource_.url.spec(), resource_.original_url.spec());
73 } else {
74 AddNode(resource_.url.spec(), "");
75 }
76
77 // Add the referrer url.
78 if (nav_entry && !referrer_url.spec().empty()) {
79 AddNode(referrer_url.spec(), "");
80 }
81
82 // Add all the urls in our |urls_| map to the |report_| protobuf.
83 for (ResourceMap::const_iterator it = urls_.begin();
84 it != urls_.end(); it++) {
85 safe_browsing::ClientMalwareReportRequest::Resource* pb_resource =
86 report_->add_nodes();
87 pb_resource->CopyFrom(*(it->second));
88 }
89 }
90
91 // Called from the SB Service on the IO thread.
92 const std::string* MalwareDetails::GetSerializedReport() {
93 scoped_ptr<std::string> request_data(new std::string());
94 if (!report_->SerializeToString(request_data.get())) {
95 DLOG(ERROR) << "Unable to serialize the malware report.";
96 }
97
98 return request_data.release();
99 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/malware_details.h ('k') | chrome/browser/safe_browsing/malware_details_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698