| 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 // BrowserFeatureExtractor computes various browser features for client-side | 5 // BrowserFeatureExtractor computes various browser features for client-side |
| 6 // phishing detection. For now it does a bunch of lookups in the history | 6 // phishing detection. For now it does a bunch of lookups in the history |
| 7 // service to see whether a particular URL has been visited before by the | 7 // service to see whether a particular URL has been visited before by the |
| 8 // user. | 8 // user. |
| 9 | 9 |
| 10 #ifndef CHROME_BROWSER_SAFE_BROWSING_BROWSER_FEATURE_EXTRACTOR_H_ | 10 #ifndef CHROME_BROWSER_SAFE_BROWSING_BROWSER_FEATURE_EXTRACTOR_H_ |
| 11 #define CHROME_BROWSER_SAFE_BROWSING_BROWSER_FEATURE_EXTRACTOR_H_ | 11 #define CHROME_BROWSER_SAFE_BROWSING_BROWSER_FEATURE_EXTRACTOR_H_ |
| 12 | 12 |
| 13 #include <map> | 13 #include <map> |
| 14 #include <memory> |
| 14 #include <set> | 15 #include <set> |
| 15 #include <string> | 16 #include <string> |
| 16 #include <utility> | 17 #include <utility> |
| 17 #include <vector> | 18 #include <vector> |
| 18 | 19 |
| 19 #include "base/callback.h" | 20 #include "base/callback.h" |
| 20 #include "base/containers/hash_tables.h" | 21 #include "base/containers/hash_tables.h" |
| 21 #include "base/macros.h" | 22 #include "base/macros.h" |
| 22 #include "base/memory/scoped_ptr.h" | |
| 23 #include "base/task/cancelable_task_tracker.h" | 23 #include "base/task/cancelable_task_tracker.h" |
| 24 #include "base/time/time.h" | 24 #include "base/time/time.h" |
| 25 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 25 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 26 #include "chrome/browser/safe_browsing/ui_manager.h" | 26 #include "chrome/browser/safe_browsing/ui_manager.h" |
| 27 #include "components/history/core/browser/history_types.h" | 27 #include "components/history/core/browser/history_types.h" |
| 28 #include "content/public/common/resource_type.h" | 28 #include "content/public/common/resource_type.h" |
| 29 #include "url/gurl.h" | 29 #include "url/gurl.h" |
| 30 | 30 |
| 31 | 31 |
| 32 namespace content { | 32 namespace content { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 62 struct BrowseInfo { | 62 struct BrowseInfo { |
| 63 // The URL we're currently browsing. | 63 // The URL we're currently browsing. |
| 64 GURL url; | 64 GURL url; |
| 65 | 65 |
| 66 // List of IPv4 and IPv6 addresses from which content was requested | 66 // List of IPv4 and IPv6 addresses from which content was requested |
| 67 // together with the hosts on it, while browsing to the |url|. | 67 // together with the hosts on it, while browsing to the |url|. |
| 68 IPUrlMap ips; | 68 IPUrlMap ips; |
| 69 | 69 |
| 70 // If a SafeBrowsing interstitial was shown for the current URL | 70 // If a SafeBrowsing interstitial was shown for the current URL |
| 71 // this will contain the UnsafeResource struct for that URL. | 71 // this will contain the UnsafeResource struct for that URL. |
| 72 scoped_ptr<SafeBrowsingUIManager::UnsafeResource> unsafe_resource; | 72 std::unique_ptr<SafeBrowsingUIManager::UnsafeResource> unsafe_resource; |
| 73 | 73 |
| 74 // List of redirects that lead to the first page on the current host and | 74 // List of redirects that lead to the first page on the current host and |
| 75 // the current url respectively. These may be the same if the current url | 75 // the current url respectively. These may be the same if the current url |
| 76 // is the first page on its host. | 76 // is the first page on its host. |
| 77 std::vector<GURL> host_redirects; | 77 std::vector<GURL> host_redirects; |
| 78 std::vector<GURL> url_redirects; | 78 std::vector<GURL> url_redirects; |
| 79 | 79 |
| 80 // URL of the referrer of this URL load. | 80 // URL of the referrer of this URL load. |
| 81 GURL referrer; | 81 GURL referrer; |
| 82 | 82 |
| 83 // The HTTP status code from this navigation. | 83 // The HTTP status code from this navigation. |
| 84 int http_status_code; | 84 int http_status_code; |
| 85 | 85 |
| 86 BrowseInfo(); | 86 BrowseInfo(); |
| 87 ~BrowseInfo(); | 87 ~BrowseInfo(); |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 // All methods of this class must be called on the UI thread (including | 90 // All methods of this class must be called on the UI thread (including |
| 91 // the constructor). | 91 // the constructor). |
| 92 class BrowserFeatureExtractor { | 92 class BrowserFeatureExtractor { |
| 93 public: | 93 public: |
| 94 // Called when feature extraction is done. The first argument will be | 94 // Called when feature extraction is done. The first argument will be |
| 95 // true iff feature extraction succeeded. The second argument is the | 95 // true iff feature extraction succeeded. The second argument is the |
| 96 // phishing request which was modified by the feature extractor. The | 96 // phishing request which was modified by the feature extractor. The |
| 97 // DoneCallback takes ownership of the request object. | 97 // DoneCallback takes ownership of the request object. |
| 98 typedef base::Callback<void(bool, scoped_ptr<ClientPhishingRequest>)> | 98 typedef base::Callback<void(bool, std::unique_ptr<ClientPhishingRequest>)> |
| 99 DoneCallback; | 99 DoneCallback; |
| 100 typedef base::Callback<void(bool, scoped_ptr<ClientMalwareRequest>)> | 100 typedef base::Callback<void(bool, std::unique_ptr<ClientMalwareRequest>)> |
| 101 MalwareDoneCallback; | 101 MalwareDoneCallback; |
| 102 | 102 |
| 103 // The caller keeps ownership of the tab and host objects and is | 103 // The caller keeps ownership of the tab and host objects and is |
| 104 // responsible for ensuring that they stay valid for the entire | 104 // responsible for ensuring that they stay valid for the entire |
| 105 // lifetime of this object. | 105 // lifetime of this object. |
| 106 BrowserFeatureExtractor(content::WebContents* tab, | 106 BrowserFeatureExtractor(content::WebContents* tab, |
| 107 ClientSideDetectionHost* host); | 107 ClientSideDetectionHost* host); |
| 108 | 108 |
| 109 // The destructor will cancel any pending requests. | 109 // The destructor will cancel any pending requests. |
| 110 virtual ~BrowserFeatureExtractor(); | 110 virtual ~BrowserFeatureExtractor(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 127 virtual void ExtractMalwareFeatures(BrowseInfo* info, | 127 virtual void ExtractMalwareFeatures(BrowseInfo* info, |
| 128 ClientMalwareRequest* request, | 128 ClientMalwareRequest* request, |
| 129 const MalwareDoneCallback& callback); | 129 const MalwareDoneCallback& callback); |
| 130 | 130 |
| 131 private: | 131 private: |
| 132 // Synchronous browser feature extraction. | 132 // Synchronous browser feature extraction. |
| 133 void ExtractBrowseInfoFeatures(const BrowseInfo& info, | 133 void ExtractBrowseInfoFeatures(const BrowseInfo& info, |
| 134 ClientPhishingRequest* request); | 134 ClientPhishingRequest* request); |
| 135 | 135 |
| 136 // Actually starts feature extraction (does the real work). | 136 // Actually starts feature extraction (does the real work). |
| 137 void StartExtractFeatures(scoped_ptr<ClientPhishingRequest> request, | 137 void StartExtractFeatures(std::unique_ptr<ClientPhishingRequest> request, |
| 138 const DoneCallback& callback); | 138 const DoneCallback& callback); |
| 139 | 139 |
| 140 // HistoryService callback which is called when we're done querying URL visits | 140 // HistoryService callback which is called when we're done querying URL visits |
| 141 // in the history. | 141 // in the history. |
| 142 void QueryUrlHistoryDone(scoped_ptr<ClientPhishingRequest> request, | 142 void QueryUrlHistoryDone(std::unique_ptr<ClientPhishingRequest> request, |
| 143 const DoneCallback& callback, | 143 const DoneCallback& callback, |
| 144 bool success, | 144 bool success, |
| 145 const history::URLRow& row, | 145 const history::URLRow& row, |
| 146 const history::VisitVector& visits); | 146 const history::VisitVector& visits); |
| 147 | 147 |
| 148 // HistoryService callback which is called when we're done querying HTTP host | 148 // HistoryService callback which is called when we're done querying HTTP host |
| 149 // visits in the history. | 149 // visits in the history. |
| 150 void QueryHttpHostVisitsDone(scoped_ptr<ClientPhishingRequest> request, | 150 void QueryHttpHostVisitsDone(std::unique_ptr<ClientPhishingRequest> request, |
| 151 const DoneCallback& callback, | 151 const DoneCallback& callback, |
| 152 bool success, | 152 bool success, |
| 153 int num_visits, | 153 int num_visits, |
| 154 base::Time first_visit); | 154 base::Time first_visit); |
| 155 | 155 |
| 156 // HistoryService callback which is called when we're done querying HTTPS host | 156 // HistoryService callback which is called when we're done querying HTTPS host |
| 157 // visits in the history. | 157 // visits in the history. |
| 158 void QueryHttpsHostVisitsDone(scoped_ptr<ClientPhishingRequest> request, | 158 void QueryHttpsHostVisitsDone(std::unique_ptr<ClientPhishingRequest> request, |
| 159 const DoneCallback& callback, | 159 const DoneCallback& callback, |
| 160 bool success, | 160 bool success, |
| 161 int num_visits, | 161 int num_visits, |
| 162 base::Time first_visit); | 162 base::Time first_visit); |
| 163 | 163 |
| 164 // Helper function which sets the host history features given the | 164 // Helper function which sets the host history features given the |
| 165 // number of host visits and the time of the fist host visit. Set | 165 // number of host visits and the time of the fist host visit. Set |
| 166 // |is_http_query| to true if the URL scheme is HTTP and to false if | 166 // |is_http_query| to true if the URL scheme is HTTP and to false if |
| 167 // the scheme is HTTPS. | 167 // the scheme is HTTPS. |
| 168 void SetHostVisitsFeatures(int num_visits, | 168 void SetHostVisitsFeatures(int num_visits, |
| 169 base::Time first_visit, | 169 base::Time first_visit, |
| 170 bool is_http_query, | 170 bool is_http_query, |
| 171 ClientPhishingRequest* request); | 171 ClientPhishingRequest* request); |
| 172 | 172 |
| 173 // Helper function which gets the history server if possible. If the pointer | 173 // Helper function which gets the history server if possible. If the pointer |
| 174 // is set it will return true and false otherwise. | 174 // is set it will return true and false otherwise. |
| 175 bool GetHistoryService(history::HistoryService** history); | 175 bool GetHistoryService(history::HistoryService** history); |
| 176 | 176 |
| 177 // Helper function which is called when we're done filtering out benign IPs | 177 // Helper function which is called when we're done filtering out benign IPs |
| 178 // on the IO thread. This function is called on the UI thread. | 178 // on the IO thread. This function is called on the UI thread. |
| 179 void FinishExtractMalwareFeatures(scoped_ptr<IPUrlMap> bad_ips, | 179 void FinishExtractMalwareFeatures( |
| 180 MalwareDoneCallback callback, | 180 std::unique_ptr<IPUrlMap> bad_ips, |
| 181 scoped_ptr<ClientMalwareRequest> request); | 181 MalwareDoneCallback callback, |
| 182 std::unique_ptr<ClientMalwareRequest> request); |
| 182 | 183 |
| 183 content::WebContents* tab_; | 184 content::WebContents* tab_; |
| 184 ClientSideDetectionHost* host_; | 185 ClientSideDetectionHost* host_; |
| 185 base::CancelableTaskTracker cancelable_task_tracker_; | 186 base::CancelableTaskTracker cancelable_task_tracker_; |
| 186 base::WeakPtrFactory<BrowserFeatureExtractor> weak_factory_; | 187 base::WeakPtrFactory<BrowserFeatureExtractor> weak_factory_; |
| 187 | 188 |
| 188 DISALLOW_COPY_AND_ASSIGN(BrowserFeatureExtractor); | 189 DISALLOW_COPY_AND_ASSIGN(BrowserFeatureExtractor); |
| 189 }; | 190 }; |
| 190 | 191 |
| 191 } // namespace safe_browsing | 192 } // namespace safe_browsing |
| 192 #endif // CHROME_BROWSER_SAFE_BROWSING_BROWSER_FEATURE_EXTRACTOR_H_ | 193 #endif // CHROME_BROWSER_SAFE_BROWSING_BROWSER_FEATURE_EXTRACTOR_H_ |
| OLD | NEW |