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/bind.h" | 10 #include "base/bind.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "chrome/browser/safe_browsing/browser_features.h" | 21 #include "chrome/browser/safe_browsing/browser_features.h" |
22 #include "chrome/browser/safe_browsing/client_side_detection_service.h" | 22 #include "chrome/browser/safe_browsing/client_side_detection_service.h" |
23 #include "chrome/common/safe_browsing/csd.pb.h" | 23 #include "chrome/common/safe_browsing/csd.pb.h" |
24 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
25 #include "content/public/browser/navigation_entry.h" | 25 #include "content/public/browser/navigation_entry.h" |
26 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
27 #include "content/public/common/page_transition_types.h" | 27 #include "content/public/common/page_transition_types.h" |
28 #include "googleurl/src/gurl.h" | 28 #include "googleurl/src/gurl.h" |
29 | 29 |
30 using content::BrowserThread; | 30 using content::BrowserThread; |
| 31 using content::NavigationEntry; |
31 using content::WebContents; | 32 using content::WebContents; |
32 | 33 |
33 namespace safe_browsing { | 34 namespace safe_browsing { |
34 | 35 |
35 BrowseInfo::BrowseInfo() : http_status_code(0) {} | 36 BrowseInfo::BrowseInfo() : http_status_code(0) {} |
36 | 37 |
37 BrowseInfo::~BrowseInfo() {} | 38 BrowseInfo::~BrowseInfo() {} |
38 | 39 |
39 static void AddFeature(const std::string& feature_name, | 40 static void AddFeature(const std::string& feature_name, |
40 double feature_value, | 41 double feature_value, |
41 ClientPhishingRequest* request) { | 42 ClientPhishingRequest* request) { |
42 DCHECK(request); | 43 DCHECK(request); |
43 ClientPhishingRequest::Feature* feature = | 44 ClientPhishingRequest::Feature* feature = |
44 request->add_non_model_feature_map(); | 45 request->add_non_model_feature_map(); |
45 feature->set_name(feature_name); | 46 feature->set_name(feature_name); |
46 feature->set_value(feature_value); | 47 feature->set_value(feature_value); |
47 VLOG(2) << "Browser feature: " << feature->name() << " " << feature->value(); | 48 VLOG(2) << "Browser feature: " << feature->name() << " " << feature->value(); |
48 } | 49 } |
49 | 50 |
50 static void AddNavigationFeatures(const std::string& feature_prefix, | 51 static void AddNavigationFeatures(const std::string& feature_prefix, |
51 const NavigationController& controller, | 52 const NavigationController& controller, |
52 int index, | 53 int index, |
53 const std::vector<GURL>& redirect_chain, | 54 const std::vector<GURL>& redirect_chain, |
54 ClientPhishingRequest* request) { | 55 ClientPhishingRequest* request) { |
55 content::NavigationEntry* entry = controller.GetEntryAtIndex(index); | 56 NavigationEntry* entry = controller.GetEntryAtIndex(index); |
56 bool is_secure_referrer = entry->GetReferrer().url.SchemeIsSecure(); | 57 bool is_secure_referrer = entry->GetReferrer().url.SchemeIsSecure(); |
57 if (!is_secure_referrer) { | 58 if (!is_secure_referrer) { |
58 AddFeature(StringPrintf("%s%s=%s", | 59 AddFeature(StringPrintf("%s%s=%s", |
59 feature_prefix.c_str(), | 60 feature_prefix.c_str(), |
60 features::kReferrer, | 61 features::kReferrer, |
61 entry->GetReferrer().url.spec().c_str()), | 62 entry->GetReferrer().url.spec().c_str()), |
62 1.0, | 63 1.0, |
63 request); | 64 request); |
64 } | 65 } |
65 AddFeature(feature_prefix + features::kHasSSLReferrer, | 66 AddFeature(feature_prefix + features::kHasSSLReferrer, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 // Extract features pertaining to this navigation. | 156 // Extract features pertaining to this navigation. |
156 const NavigationController& controller = tab_->GetController(); | 157 const NavigationController& controller = tab_->GetController(); |
157 int url_index = -1; | 158 int url_index = -1; |
158 int first_host_index = -1; | 159 int first_host_index = -1; |
159 | 160 |
160 GURL request_url(request->url()); | 161 GURL request_url(request->url()); |
161 int index = controller.GetCurrentEntryIndex(); | 162 int index = controller.GetCurrentEntryIndex(); |
162 // The url that we are extracting features for should already be commited. | 163 // The url that we are extracting features for should already be commited. |
163 DCHECK_NE(index, -1); | 164 DCHECK_NE(index, -1); |
164 for (; index >= 0; index--) { | 165 for (; index >= 0; index--) { |
165 content::NavigationEntry* entry = controller.GetEntryAtIndex(index); | 166 NavigationEntry* entry = controller.GetEntryAtIndex(index); |
166 if (url_index == -1 && entry->GetURL() == request_url) { | 167 if (url_index == -1 && entry->GetURL() == request_url) { |
167 // It's possible that we've been on the on the possibly phishy url before | 168 // It's possible that we've been on the on the possibly phishy url before |
168 // in this tab, so make sure that we use the latest navigation for | 169 // in this tab, so make sure that we use the latest navigation for |
169 // features. | 170 // features. |
170 // Note that it's possible that the url_index should always be the | 171 // Note that it's possible that the url_index should always be the |
171 // latest entry, but I'm worried about possible races during a navigation | 172 // latest entry, but I'm worried about possible races during a navigation |
172 // and transient entries (i.e. interstiatials) so for now we will just | 173 // and transient entries (i.e. interstiatials) so for now we will just |
173 // be cautious. | 174 // be cautious. |
174 url_index = index; | 175 url_index = index; |
175 } else if (index < url_index) { | 176 } else if (index < url_index) { |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 *history = profile->GetHistoryService(Profile::EXPLICIT_ACCESS); | 441 *history = profile->GetHistoryService(Profile::EXPLICIT_ACCESS); |
441 if (*history) { | 442 if (*history) { |
442 return true; | 443 return true; |
443 } | 444 } |
444 } | 445 } |
445 VLOG(2) << "Unable to query history. No history service available."; | 446 VLOG(2) << "Unable to query history. No history service available."; |
446 return false; | 447 return false; |
447 } | 448 } |
448 | 449 |
449 } // namespace safe_browsing | 450 } // namespace safe_browsing |
OLD | NEW |