OLD | NEW |
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_MALWARE_DETAILS_H_ | 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_H_ |
6 #define CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_H_ | 6 #define CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 // A class that encapsulates the detailed malware reports sent when | 9 // A class that encapsulates the detailed malware reports sent when |
10 // users opt-in to do so from the malware warning page. | 10 // users opt-in to do so from the malware warning page. |
11 | 11 |
12 // An instance of this class is generated when a malware warning page | 12 // An instance of this class is generated when a malware warning page |
13 // is shown (SafeBrowsingBlockingPage). | 13 // is shown (SafeBrowsingBlockingPage). |
14 | 14 |
15 #include <string> | 15 #include <string> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
18 #include "base/hash_tables.h" | 18 #include "base/hash_tables.h" |
19 #include "base/memory/linked_ptr.h" | 19 #include "base/memory/linked_ptr.h" |
20 #include "base/memory/ref_counted.h" | 20 #include "base/memory/ref_counted.h" |
21 #include "base/memory/scoped_ptr.h" | 21 #include "base/memory/scoped_ptr.h" |
22 #include "chrome/browser/safe_browsing/report.pb.h" | 22 #include "chrome/browser/safe_browsing/report.pb.h" |
23 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 23 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 24 #include "content/browser/browser_thread.h" |
24 #include "content/browser/tab_contents/tab_contents_observer.h" | 25 #include "content/browser/tab_contents/tab_contents_observer.h" |
25 #include "net/base/completion_callback.h" | 26 #include "net/base/completion_callback.h" |
26 | 27 |
27 class TabContents; | 28 class TabContents; |
28 struct SafeBrowsingHostMsg_MalwareDOMDetails_Node; | 29 struct SafeBrowsingHostMsg_MalwareDOMDetails_Node; |
29 | 30 |
30 class MalwareDetailsCacheCollector; | 31 class MalwareDetailsCacheCollector; |
| 32 class MalwareDetailsRedirectsCollector; |
31 class MalwareDetailsFactory; | 33 class MalwareDetailsFactory; |
32 | 34 |
33 namespace safe_browsing { | 35 namespace safe_browsing { |
34 // Maps a URL to its Resource. | 36 // Maps a URL to its Resource. |
35 typedef base::hash_map< | 37 typedef base::hash_map< |
36 std::string, | 38 std::string, |
37 linked_ptr<safe_browsing::ClientMalwareReportRequest::Resource> > ResourceMap; | 39 linked_ptr<safe_browsing::ClientMalwareReportRequest::Resource> > ResourceMap; |
38 } | 40 } |
39 | 41 |
40 class MalwareDetails : public base::RefCountedThreadSafe<MalwareDetails>, | 42 class MalwareDetails : public base::RefCountedThreadSafe<MalwareDetails>, |
41 public TabContentsObserver { | 43 public TabContentsObserver { |
42 public: | 44 public: |
43 // Constructs a new MalwareDetails instance, using the factory. | 45 // Constructs a new MalwareDetails instance, using the factory. |
44 static MalwareDetails* NewMalwareDetails( | 46 static MalwareDetails* NewMalwareDetails( |
45 SafeBrowsingService* sb_service, | 47 SafeBrowsingService* sb_service, |
46 TabContents* tab_contents, | 48 TabContents* tab_contents, |
47 const SafeBrowsingService::UnsafeResource& resource); | 49 const SafeBrowsingService::UnsafeResource& resource); |
48 | 50 |
49 // Makes the passed |factory| the factory used to instanciate | 51 // Makes the passed |factory| the factory used to instanciate |
50 // SafeBrowsingBlockingPage objects. Useful for tests. | 52 // SafeBrowsingBlockingPage objects. Useful for tests. |
51 static void RegisterFactory(MalwareDetailsFactory* factory) { | 53 static void RegisterFactory(MalwareDetailsFactory* factory) { |
52 factory_ = factory; | 54 factory_ = factory; |
53 } | 55 } |
54 | 56 |
55 // The SafeBrowsingBlockingPage calls this from the IO thread when | 57 // The SafeBrowsingBlockingPage calls this from the IO thread when |
56 // the user is leaving the blocking page and has opted-in to sending | 58 // the user is leaving the blocking page and has opted-in to sending |
57 // the report. We start the cache collection, and when we are done, | 59 // the report. We start the redirection urls collection from history service |
58 // we send the report. | 60 // in UI thread; then do cache collection back in IO thread. |
| 61 // When we are done, we send the report. |
59 void FinishCollection(); | 62 void FinishCollection(); |
60 | 63 |
61 void OnCacheCollectionReady(); | 64 void OnCacheCollectionReady(); |
62 | 65 |
| 66 void OnRedirectionCollectionReady(); |
| 67 |
63 // TabContentsObserver implementation. | 68 // TabContentsObserver implementation. |
64 virtual bool OnMessageReceived(const IPC::Message& message); | 69 virtual bool OnMessageReceived(const IPC::Message& message); |
65 | 70 |
66 protected: | 71 protected: |
67 friend class MalwareDetailsFactoryImpl; | 72 friend class MalwareDetailsFactoryImpl; |
68 | 73 |
69 MalwareDetails(SafeBrowsingService* sb_service, | 74 MalwareDetails(SafeBrowsingService* sb_service, |
70 TabContents* tab_contents, | 75 TabContents* tab_contents, |
71 const SafeBrowsingService::UnsafeResource& resource); | 76 const SafeBrowsingService::UnsafeResource& resource); |
72 | 77 |
(...skipping 28 matching lines...) Expand all Loading... |
101 // relationship. |parent| and |tagname| can be empty, |children| can be NULL. | 106 // relationship. |parent| and |tagname| can be empty, |children| can be NULL. |
102 void AddUrl(const GURL& url, | 107 void AddUrl(const GURL& url, |
103 const GURL& parent, | 108 const GURL& parent, |
104 const std::string& tagname, | 109 const std::string& tagname, |
105 const std::vector<GURL>* children); | 110 const std::vector<GURL>* children); |
106 | 111 |
107 // Message handler. | 112 // Message handler. |
108 void OnReceivedMalwareDOMDetails( | 113 void OnReceivedMalwareDOMDetails( |
109 const std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node>& params); | 114 const std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node>& params); |
110 | 115 |
| 116 void AddRedirectUrlList(const std::vector<GURL>& urls); |
| 117 |
111 scoped_refptr<SafeBrowsingService> sb_service_; | 118 scoped_refptr<SafeBrowsingService> sb_service_; |
112 | 119 |
113 const SafeBrowsingService::UnsafeResource resource_; | 120 const SafeBrowsingService::UnsafeResource resource_; |
114 | 121 |
115 // For every Url we collect we create a Resource message. We keep | 122 // For every Url we collect we create a Resource message. We keep |
116 // them in a map so we can avoid duplicates. | 123 // them in a map so we can avoid duplicates. |
117 safe_browsing::ResourceMap resources_; | 124 safe_browsing::ResourceMap resources_; |
118 | 125 |
119 // Result from the cache extractor. | 126 // Result from the cache extractor. |
120 bool cache_result_; | 127 bool cache_result_; |
121 | 128 |
122 // The factory used to instanciate SafeBrowsingBlockingPage objects. | 129 // The factory used to instanciate SafeBrowsingBlockingPage objects. |
123 // Usefull for tests, so they can provide their own implementation of | 130 // Usefull for tests, so they can provide their own implementation of |
124 // SafeBrowsingBlockingPage. | 131 // SafeBrowsingBlockingPage. |
125 static MalwareDetailsFactory* factory_; | 132 static MalwareDetailsFactory* factory_; |
126 | 133 |
127 // Used to collect details from the HTTP Cache. | 134 // Used to collect details from the HTTP Cache. |
128 scoped_refptr<MalwareDetailsCacheCollector> cache_collector_; | 135 scoped_refptr<MalwareDetailsCacheCollector> cache_collector_; |
129 | 136 |
| 137 // Used to collect redirect urls from the history service |
| 138 scoped_refptr<MalwareDetailsRedirectsCollector> redirects_collector_; |
| 139 |
130 FRIEND_TEST_ALL_PREFIXES(MalwareDetailsTest, MalwareDOMDetails); | 140 FRIEND_TEST_ALL_PREFIXES(MalwareDetailsTest, MalwareDOMDetails); |
131 FRIEND_TEST_ALL_PREFIXES(MalwareDetailsTest, HTTPCache); | 141 FRIEND_TEST_ALL_PREFIXES(MalwareDetailsTest, HTTPCache); |
132 FRIEND_TEST_ALL_PREFIXES(MalwareDetailsTest, HTTPCacheNoEntries); | 142 FRIEND_TEST_ALL_PREFIXES(MalwareDetailsTest, HTTPCacheNoEntries); |
| 143 FRIEND_TEST_ALL_PREFIXES(MalwareDetailsTest, HistoryServiceUrls); |
133 | 144 |
134 DISALLOW_COPY_AND_ASSIGN(MalwareDetails); | 145 DISALLOW_COPY_AND_ASSIGN(MalwareDetails); |
135 }; | 146 }; |
136 | 147 |
137 // Factory for creating MalwareDetails. Useful for tests. | 148 // Factory for creating MalwareDetails. Useful for tests. |
138 class MalwareDetailsFactory { | 149 class MalwareDetailsFactory { |
139 public: | 150 public: |
140 virtual ~MalwareDetailsFactory() { } | 151 virtual ~MalwareDetailsFactory() { } |
141 | 152 |
142 virtual MalwareDetails* CreateMalwareDetails( | 153 virtual MalwareDetails* CreateMalwareDetails( |
143 SafeBrowsingService* sb_service, | 154 SafeBrowsingService* sb_service, |
144 TabContents* tab_contents, | 155 TabContents* tab_contents, |
145 const SafeBrowsingService::UnsafeResource& unsafe_resource) = 0; | 156 const SafeBrowsingService::UnsafeResource& unsafe_resource) = 0; |
146 }; | 157 }; |
147 | 158 |
148 #endif // CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_H_ | 159 #endif // CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_H_ |
OLD | NEW |