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 11 matching lines...) Expand all Loading... |
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_controller.h" | 25 #include "content/public/browser/navigation_controller.h" |
26 #include "content/public/browser/navigation_entry.h" | 26 #include "content/public/browser/navigation_entry.h" |
27 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
28 #include "content/public/common/page_transition_types.h" | 28 #include "content/public/common/page_transition_types.h" |
29 #include "googleurl/src/gurl.h" | 29 #include "googleurl/src/gurl.h" |
30 | 30 |
31 using content::BrowserThread; | 31 using content::BrowserThread; |
| 32 using content::NavigationController; |
32 using content::NavigationEntry; | 33 using content::NavigationEntry; |
33 using content::WebContents; | 34 using content::WebContents; |
34 | 35 |
35 namespace safe_browsing { | 36 namespace safe_browsing { |
36 | 37 |
37 BrowseInfo::BrowseInfo() : http_status_code(0) {} | 38 BrowseInfo::BrowseInfo() : http_status_code(0) {} |
38 | 39 |
39 BrowseInfo::~BrowseInfo() {} | 40 BrowseInfo::~BrowseInfo() {} |
40 | 41 |
41 static void AddFeature(const std::string& feature_name, | 42 static void AddFeature(const std::string& feature_name, |
42 double feature_value, | 43 double feature_value, |
43 ClientPhishingRequest* request) { | 44 ClientPhishingRequest* request) { |
44 DCHECK(request); | 45 DCHECK(request); |
45 ClientPhishingRequest::Feature* feature = | 46 ClientPhishingRequest::Feature* feature = |
46 request->add_non_model_feature_map(); | 47 request->add_non_model_feature_map(); |
47 feature->set_name(feature_name); | 48 feature->set_name(feature_name); |
48 feature->set_value(feature_value); | 49 feature->set_value(feature_value); |
49 VLOG(2) << "Browser feature: " << feature->name() << " " << feature->value(); | 50 VLOG(2) << "Browser feature: " << feature->name() << " " << feature->value(); |
50 } | 51 } |
51 | 52 |
52 static void AddNavigationFeatures( | 53 static void AddNavigationFeatures( |
53 const std::string& feature_prefix, | 54 const std::string& feature_prefix, |
54 const content::NavigationController& controller, | 55 const NavigationController& controller, |
55 int index, | 56 int index, |
56 const std::vector<GURL>& redirect_chain, | 57 const std::vector<GURL>& redirect_chain, |
57 ClientPhishingRequest* request) { | 58 ClientPhishingRequest* request) { |
58 NavigationEntry* entry = controller.GetEntryAtIndex(index); | 59 NavigationEntry* entry = controller.GetEntryAtIndex(index); |
59 bool is_secure_referrer = entry->GetReferrer().url.SchemeIsSecure(); | 60 bool is_secure_referrer = entry->GetReferrer().url.SchemeIsSecure(); |
60 if (!is_secure_referrer) { | 61 if (!is_secure_referrer) { |
61 AddFeature(StringPrintf("%s%s=%s", | 62 AddFeature(StringPrintf("%s%s=%s", |
62 feature_prefix.c_str(), | 63 feature_prefix.c_str(), |
63 features::kReferrer, | 64 features::kReferrer, |
64 entry->GetReferrer().url.spec().c_str()), | 65 entry->GetReferrer().url.spec().c_str()), |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 DCHECK(request); | 150 DCHECK(request); |
150 DCHECK(info); | 151 DCHECK(info); |
151 DCHECK_EQ(0U, request->url().find("http:")); | 152 DCHECK_EQ(0U, request->url().find("http:")); |
152 DCHECK(!callback.is_null()); | 153 DCHECK(!callback.is_null()); |
153 if (callback.is_null()) { | 154 if (callback.is_null()) { |
154 DLOG(ERROR) << "ExtractFeatures called without a callback object"; | 155 DLOG(ERROR) << "ExtractFeatures called without a callback object"; |
155 return; | 156 return; |
156 } | 157 } |
157 | 158 |
158 // Extract features pertaining to this navigation. | 159 // Extract features pertaining to this navigation. |
159 const content::NavigationController& controller = tab_->GetController(); | 160 const NavigationController& controller = tab_->GetController(); |
160 int url_index = -1; | 161 int url_index = -1; |
161 int first_host_index = -1; | 162 int first_host_index = -1; |
162 | 163 |
163 GURL request_url(request->url()); | 164 GURL request_url(request->url()); |
164 int index = controller.GetCurrentEntryIndex(); | 165 int index = controller.GetCurrentEntryIndex(); |
165 // The url that we are extracting features for should already be commited. | 166 // The url that we are extracting features for should already be commited. |
166 DCHECK_NE(index, -1); | 167 DCHECK_NE(index, -1); |
167 for (; index >= 0; index--) { | 168 for (; index >= 0; index--) { |
168 NavigationEntry* entry = controller.GetEntryAtIndex(index); | 169 NavigationEntry* entry = controller.GetEntryAtIndex(index); |
169 if (url_index == -1 && entry->GetURL() == request_url) { | 170 if (url_index == -1 && entry->GetURL() == request_url) { |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 *history = profile->GetHistoryService(Profile::EXPLICIT_ACCESS); | 444 *history = profile->GetHistoryService(Profile::EXPLICIT_ACCESS); |
444 if (*history) { | 445 if (*history) { |
445 return true; | 446 return true; |
446 } | 447 } |
447 } | 448 } |
448 VLOG(2) << "Unable to query history. No history service available."; | 449 VLOG(2) << "Unable to query history. No history service available."; |
449 return false; | 450 return false; |
450 } | 451 } |
451 | 452 |
452 } // namespace safe_browsing | 453 } // namespace safe_browsing |
OLD | NEW |