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 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" | 5 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 const char kFirstHttpsHostVisitMoreThan24hAgo[] = | 36 const char kFirstHttpsHostVisitMoreThan24hAgo[] = |
37 "FirstHttpsHostVisitMoreThan24hAgo"; | 37 "FirstHttpsHostVisitMoreThan24hAgo"; |
38 | 38 |
39 const char kHostPrefix[] = "Host"; | 39 const char kHostPrefix[] = "Host"; |
40 const char kRedirectPrefix[] = "Redirect"; | 40 const char kRedirectPrefix[] = "Redirect"; |
41 const char kReferrer[] = "Referrer"; | 41 const char kReferrer[] = "Referrer"; |
42 const char kHasSSLReferrer[] = "HasSSLReferrer"; | 42 const char kHasSSLReferrer[] = "HasSSLReferrer"; |
43 const char kPageTransitionType[] = "PageTransitionType"; | 43 const char kPageTransitionType[] = "PageTransitionType"; |
44 const char kIsFirstNavigation[] = "IsFirstNavigation"; | 44 const char kIsFirstNavigation[] = "IsFirstNavigation"; |
45 const char kBadIpFetch[] = "BadIpFetch="; | 45 const char kBadIpFetch[] = "BadIpFetch="; |
| 46 const char kSafeBrowsingMaliciousUrl[] = "SafeBrowsingMaliciousUrl="; |
| 47 const char kSafeBrowsingOriginalUrl[] = "SafeBrowsingOriginalUrl="; |
| 48 const char kSafeBrowsingIsSubresource[] = "SafeBrowsingIsSubresource"; |
| 49 const char kSafeBrowsingThreatType[] = "SafeBrowsingThreatType"; |
46 } // namespace features | 50 } // namespace features |
47 | 51 |
48 BrowseInfo::BrowseInfo() {} | 52 BrowseInfo::BrowseInfo() {} |
49 | 53 |
50 BrowseInfo::~BrowseInfo() {} | 54 BrowseInfo::~BrowseInfo() {} |
51 | 55 |
52 static void AddFeature(const std::string& feature_name, | 56 static void AddFeature(const std::string& feature_name, |
53 double feature_value, | 57 double feature_value, |
54 ClientPhishingRequest* request) { | 58 ClientPhishingRequest* request) { |
55 DCHECK(request); | 59 DCHECK(request); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 const BrowseInfo& info, | 223 const BrowseInfo& info, |
220 ClientPhishingRequest* request) { | 224 ClientPhishingRequest* request) { |
221 if (service_) { | 225 if (service_) { |
222 for (std::set<std::string>::const_iterator it = info.ips.begin(); | 226 for (std::set<std::string>::const_iterator it = info.ips.begin(); |
223 it != info.ips.end(); ++it) { | 227 it != info.ips.end(); ++it) { |
224 if (service_->IsBadIpAddress(*it)) { | 228 if (service_->IsBadIpAddress(*it)) { |
225 AddFeature(features::kBadIpFetch + *it, 1.0, request); | 229 AddFeature(features::kBadIpFetch + *it, 1.0, request); |
226 } | 230 } |
227 } | 231 } |
228 } | 232 } |
| 233 if (info.unsafe_resource.get()) { |
| 234 // A SafeBrowsing interstitial was shown for the current URL. |
| 235 AddFeature(features::kSafeBrowsingMaliciousUrl + |
| 236 info.unsafe_resource->url.spec(), |
| 237 1.0, |
| 238 request); |
| 239 AddFeature(features::kSafeBrowsingOriginalUrl + |
| 240 info.unsafe_resource->original_url.spec(), |
| 241 1.0, |
| 242 request); |
| 243 AddFeature(features::kSafeBrowsingIsSubresource, |
| 244 info.unsafe_resource->is_subresource ? 1.0 : 0.0, |
| 245 request); |
| 246 AddFeature(features::kSafeBrowsingThreatType, |
| 247 static_cast<double>(info.unsafe_resource->threat_type), |
| 248 request); |
| 249 } |
| 250 |
229 } | 251 } |
230 | 252 |
231 void BrowserFeatureExtractor::StartExtractFeatures( | 253 void BrowserFeatureExtractor::StartExtractFeatures( |
232 ClientPhishingRequest* request, | 254 ClientPhishingRequest* request, |
233 DoneCallback* callback) { | 255 DoneCallback* callback) { |
234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 256 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
235 ExtractionData extraction = std::make_pair(request, callback); | 257 ExtractionData extraction = std::make_pair(request, callback); |
236 size_t removed = pending_extractions_.erase(extraction); | 258 size_t removed = pending_extractions_.erase(extraction); |
237 DCHECK_EQ(1U, removed); | 259 DCHECK_EQ(1U, removed); |
238 HistoryService* history; | 260 HistoryService* history; |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 *history = profile->GetHistoryService(Profile::EXPLICIT_ACCESS); | 457 *history = profile->GetHistoryService(Profile::EXPLICIT_ACCESS); |
436 if (*history) { | 458 if (*history) { |
437 return true; | 459 return true; |
438 } | 460 } |
439 } | 461 } |
440 VLOG(2) << "Unable to query history. No history service available."; | 462 VLOG(2) << "Unable to query history. No history service available."; |
441 return false; | 463 return false; |
442 } | 464 } |
443 | 465 |
444 }; // namespace safe_browsing | 466 }; // namespace safe_browsing |
OLD | NEW |