| 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_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 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 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 Loading... |
| 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 Loading... |
| 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_ |
| OLD | NEW |