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

Side by Side Diff: chrome/browser/safe_browsing/threat_details.h

Issue 1414343007: Collect threat details for phishing and UwS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit Created 5 years, 1 month 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_H_ 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_H_
6 #define CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_H_ 6 #define CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_H_
7 7
8 // A class that encapsulates the detailed threat reports sent when 8 // A class that encapsulates the detailed threat reports sent when
9 // users opt-in to do so from the safe browsing warning page. 9 // users opt-in to do so from the safe browsing warning page.
10 10
11 // An instance of this class is generated when a safe browsing warning page 11 // An instance of this class is generated when a safe browsing warning page
12 // is shown (SafeBrowsingBlockingPage). 12 // is shown (SafeBrowsingBlockingPage).
13 13
14 #include <string> 14 #include <string>
15 #include <vector> 15 #include <vector>
16 16
17 #include "base/containers/hash_tables.h" 17 #include "base/containers/hash_tables.h"
18 #include "base/gtest_prod_util.h" 18 #include "base/gtest_prod_util.h"
19 #include "base/macros.h" 19 #include "base/macros.h"
20 #include "base/memory/linked_ptr.h" 20 #include "base/memory/linked_ptr.h"
21 #include "base/memory/ref_counted.h" 21 #include "base/memory/ref_counted.h"
22 #include "base/memory/scoped_ptr.h" 22 #include "base/memory/scoped_ptr.h"
23 #include "chrome/browser/safe_browsing/report.pb.h"
24 #include "chrome/browser/safe_browsing/ui_manager.h" 23 #include "chrome/browser/safe_browsing/ui_manager.h"
24 #include "chrome/common/safe_browsing/csd.pb.h"
25 #include "content/public/browser/web_contents_observer.h" 25 #include "content/public/browser/web_contents_observer.h"
26 #include "net/base/completion_callback.h" 26 #include "net/base/completion_callback.h"
27 27
28 namespace net { 28 namespace net {
29 class URLRequestContextGetter; 29 class URLRequestContextGetter;
30 } 30 }
31 31
32 class ThreatDetailsCacheCollector; 32 class ThreatDetailsCacheCollector;
33 class ThreatDetailsRedirectsCollector; 33 class ThreatDetailsRedirectsCollector;
34 class ThreatDetailsFactory; 34 class ThreatDetailsFactory;
35 class Profile; 35 class Profile;
36 struct SafeBrowsingHostMsg_MalwareDOMDetails_Node; 36 struct SafeBrowsingHostMsg_ThreatDOMDetails_Node;
37 37
38 namespace safe_browsing { 38 namespace safe_browsing {
39 // Maps a URL to its Resource. 39 // Maps a URL to its Resource.
40 typedef base::hash_map< 40 typedef base::hash_map<
41 std::string, 41 std::string,
42 linked_ptr<safe_browsing::ClientMalwareReportRequest::Resource>> 42 linked_ptr<safe_browsing::ClientSafeBrowsingReportRequest::Resource>>
43 ResourceMap; 43 ResourceMap;
44 } 44 }
45 45
46 class ThreatDetails : public base::RefCountedThreadSafe<ThreatDetails>, 46 class ThreatDetails : public base::RefCountedThreadSafe<ThreatDetails>,
47 public content::WebContentsObserver { 47 public content::WebContentsObserver {
48 public: 48 public:
49 typedef SafeBrowsingUIManager::UnsafeResource UnsafeResource; 49 typedef SafeBrowsingUIManager::UnsafeResource UnsafeResource;
50 50
51 // Constructs a new ThreatDetails instance, using the factory. 51 // Constructs a new ThreatDetails instance, using the factory.
52 static ThreatDetails* NewThreatDetails(SafeBrowsingUIManager* ui_manager, 52 static ThreatDetails* NewThreatDetails(SafeBrowsingUIManager* ui_manager,
(...skipping 25 matching lines...) Expand all
78 friend class ThreatDetailsFactoryImpl; 78 friend class ThreatDetailsFactoryImpl;
79 79
80 ThreatDetails(SafeBrowsingUIManager* ui_manager, 80 ThreatDetails(SafeBrowsingUIManager* ui_manager,
81 content::WebContents* web_contents, 81 content::WebContents* web_contents,
82 const UnsafeResource& resource); 82 const UnsafeResource& resource);
83 83
84 ~ThreatDetails() override; 84 ~ThreatDetails() override;
85 85
86 // Called on the IO thread with the DOM details. 86 // Called on the IO thread with the DOM details.
87 virtual void AddDOMDetails( 87 virtual void AddDOMDetails(
88 const std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node>& params); 88 const std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node>& params);
89 89
90 Profile* profile_; 90 Profile* profile_;
91 91
92 // The report protocol buffer. 92 // The report protocol buffer.
93 scoped_ptr<safe_browsing::ClientMalwareReportRequest> report_; 93 scoped_ptr<safe_browsing::ClientSafeBrowsingReportRequest> report_;
94 94
95 // Used to get a pointer to the HTTP cache. 95 // Used to get a pointer to the HTTP cache.
96 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; 96 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
97 97
98 private: 98 private:
99 friend class base::RefCountedThreadSafe<ThreatDetails>; 99 friend class base::RefCountedThreadSafe<ThreatDetails>;
100 100
101 // Starts the collection of the report. 101 // Starts the collection of the report.
102 void StartCollection(); 102 void StartCollection();
103 103
104 // Whether the url is "public" so we can add it to the report. 104 // Whether the url is "public" so we can add it to the report.
105 bool IsReportableUrl(const GURL& url) const; 105 bool IsReportableUrl(const GURL& url) const;
106 106
107 // Finds an existing Resource for the given url, or creates a new 107 // Finds an existing Resource for the given url, or creates a new
108 // one if not found, and adds it to |resources_|. Returns the 108 // one if not found, and adds it to |resources_|. Returns the
109 // found/created resource. 109 // found/created resource.
110 safe_browsing::ClientMalwareReportRequest::Resource* FindOrCreateResource( 110 safe_browsing::ClientSafeBrowsingReportRequest::Resource*
111 const GURL& url); 111 FindOrCreateResource(const GURL& url);
112 112
113 // Adds a Resource to resources_ with the given parent-child 113 // Adds a Resource to resources_ with the given parent-child
114 // relationship. |parent| and |tagname| can be empty, |children| can be NULL. 114 // relationship. |parent| and |tagname| can be empty, |children| can be NULL.
115 void AddUrl(const GURL& url, 115 void AddUrl(const GURL& url,
116 const GURL& parent, 116 const GURL& parent,
117 const std::string& tagname, 117 const std::string& tagname,
118 const std::vector<GURL>* children); 118 const std::vector<GURL>* children);
119 119
120 // Message handler. 120 // Message handler.
121 void OnReceivedThreatDOMDetails( 121 void OnReceivedThreatDOMDetails(
122 const std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node>& params); 122 const std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node>& params);
123 123
124 void AddRedirectUrlList(const std::vector<GURL>& urls); 124 void AddRedirectUrlList(const std::vector<GURL>& urls);
125 125
126 scoped_refptr<SafeBrowsingUIManager> ui_manager_; 126 scoped_refptr<SafeBrowsingUIManager> ui_manager_;
127 127
128 const UnsafeResource resource_; 128 const UnsafeResource resource_;
129 129
130 // For every Url we collect we create a Resource message. We keep 130 // For every Url we collect we create a Resource message. We keep
131 // them in a map so we can avoid duplicates. 131 // them in a map so we can avoid duplicates.
132 safe_browsing::ResourceMap resources_; 132 safe_browsing::ResourceMap resources_;
(...skipping 12 matching lines...) Expand all
145 // Usefull for tests, so they can provide their own implementation of 145 // Usefull for tests, so they can provide their own implementation of
146 // SafeBrowsingBlockingPage. 146 // SafeBrowsingBlockingPage.
147 static ThreatDetailsFactory* factory_; 147 static ThreatDetailsFactory* factory_;
148 148
149 // Used to collect details from the HTTP Cache. 149 // Used to collect details from the HTTP Cache.
150 scoped_refptr<ThreatDetailsCacheCollector> cache_collector_; 150 scoped_refptr<ThreatDetailsCacheCollector> cache_collector_;
151 151
152 // Used to collect redirect urls from the history service 152 // Used to collect redirect urls from the history service
153 scoped_refptr<ThreatDetailsRedirectsCollector> redirects_collector_; 153 scoped_refptr<ThreatDetailsRedirectsCollector> redirects_collector_;
154 154
155 FRIEND_TEST_ALL_PREFIXES(ThreatDetailsTest, MalwareDOMDetails); 155 FRIEND_TEST_ALL_PREFIXES(ThreatDetailsTest, ThreatDOMDetails);
156 FRIEND_TEST_ALL_PREFIXES(ThreatDetailsTest, HTTPCache); 156 FRIEND_TEST_ALL_PREFIXES(ThreatDetailsTest, HTTPCache);
157 FRIEND_TEST_ALL_PREFIXES(ThreatDetailsTest, HTTPCacheNoEntries); 157 FRIEND_TEST_ALL_PREFIXES(ThreatDetailsTest, HTTPCacheNoEntries);
158 FRIEND_TEST_ALL_PREFIXES(ThreatDetailsTest, HistoryServiceUrls); 158 FRIEND_TEST_ALL_PREFIXES(ThreatDetailsTest, HistoryServiceUrls);
159 159
160 DISALLOW_COPY_AND_ASSIGN(ThreatDetails); 160 DISALLOW_COPY_AND_ASSIGN(ThreatDetails);
161 }; 161 };
162 162
163 // Factory for creating ThreatDetails. Useful for tests. 163 // Factory for creating ThreatDetails. Useful for tests.
164 class ThreatDetailsFactory { 164 class ThreatDetailsFactory {
165 public: 165 public:
166 virtual ~ThreatDetailsFactory() {} 166 virtual ~ThreatDetailsFactory() {}
167 167
168 virtual ThreatDetails* CreateThreatDetails( 168 virtual ThreatDetails* CreateThreatDetails(
169 SafeBrowsingUIManager* ui_manager, 169 SafeBrowsingUIManager* ui_manager,
170 content::WebContents* web_contents, 170 content::WebContents* web_contents,
171 const SafeBrowsingUIManager::UnsafeResource& unsafe_resource) = 0; 171 const SafeBrowsingUIManager::UnsafeResource& unsafe_resource) = 0;
172 }; 172 };
173 173
174 #endif // CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_H_ 174 #endif // CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698