Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(469)

Side by Side Diff: chrome/browser/safe_browsing/browser_feature_extractor.cc

Issue 8983010: Convert WebContents to return a content::NavigationController instead of the implementation. Upda... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix mac Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/format_macros.h" 12 #include "base/format_macros.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/stringprintf.h" 14 #include "base/stringprintf.h"
15 #include "base/task.h" 15 #include "base/task.h"
16 #include "base/time.h" 16 #include "base/time.h"
17 #include "chrome/browser/cancelable_request.h" 17 #include "chrome/browser/cancelable_request.h"
18 #include "chrome/browser/history/history.h" 18 #include "chrome/browser/history/history.h"
19 #include "chrome/browser/history/history_types.h" 19 #include "chrome/browser/history/history_types.h"
20 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
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/browser/tab_contents/navigation_controller.h"
25 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.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::NavigationEntry; 32 using content::NavigationEntry;
33 using content::WebContents; 33 using content::WebContents;
34 34
35 namespace safe_browsing { 35 namespace safe_browsing {
36 36
37 BrowseInfo::BrowseInfo() : http_status_code(0) {} 37 BrowseInfo::BrowseInfo() : http_status_code(0) {}
38 38
39 BrowseInfo::~BrowseInfo() {} 39 BrowseInfo::~BrowseInfo() {}
40 40
41 static void AddFeature(const std::string& feature_name, 41 static void AddFeature(const std::string& feature_name,
42 double feature_value, 42 double feature_value,
43 ClientPhishingRequest* request) { 43 ClientPhishingRequest* request) {
44 DCHECK(request); 44 DCHECK(request);
45 ClientPhishingRequest::Feature* feature = 45 ClientPhishingRequest::Feature* feature =
46 request->add_non_model_feature_map(); 46 request->add_non_model_feature_map();
47 feature->set_name(feature_name); 47 feature->set_name(feature_name);
48 feature->set_value(feature_value); 48 feature->set_value(feature_value);
49 VLOG(2) << "Browser feature: " << feature->name() << " " << feature->value(); 49 VLOG(2) << "Browser feature: " << feature->name() << " " << feature->value();
50 } 50 }
51 51
52 static void AddNavigationFeatures(const std::string& feature_prefix, 52 static void AddNavigationFeatures(
53 const NavigationController& controller, 53 const std::string& feature_prefix,
54 int index, 54 const content::NavigationController& controller,
55 const std::vector<GURL>& redirect_chain, 55 int index,
56 ClientPhishingRequest* request) { 56 const std::vector<GURL>& redirect_chain,
57 ClientPhishingRequest* request) {
57 NavigationEntry* entry = controller.GetEntryAtIndex(index); 58 NavigationEntry* entry = controller.GetEntryAtIndex(index);
58 bool is_secure_referrer = entry->GetReferrer().url.SchemeIsSecure(); 59 bool is_secure_referrer = entry->GetReferrer().url.SchemeIsSecure();
59 if (!is_secure_referrer) { 60 if (!is_secure_referrer) {
60 AddFeature(StringPrintf("%s%s=%s", 61 AddFeature(StringPrintf("%s%s=%s",
61 feature_prefix.c_str(), 62 feature_prefix.c_str(),
62 features::kReferrer, 63 features::kReferrer,
63 entry->GetReferrer().url.spec().c_str()), 64 entry->GetReferrer().url.spec().c_str()),
64 1.0, 65 1.0,
65 request); 66 request);
66 } 67 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 DCHECK(request); 149 DCHECK(request);
149 DCHECK(info); 150 DCHECK(info);
150 DCHECK_EQ(0U, request->url().find("http:")); 151 DCHECK_EQ(0U, request->url().find("http:"));
151 DCHECK(!callback.is_null()); 152 DCHECK(!callback.is_null());
152 if (callback.is_null()) { 153 if (callback.is_null()) {
153 DLOG(ERROR) << "ExtractFeatures called without a callback object"; 154 DLOG(ERROR) << "ExtractFeatures called without a callback object";
154 return; 155 return;
155 } 156 }
156 157
157 // Extract features pertaining to this navigation. 158 // Extract features pertaining to this navigation.
158 const NavigationController& controller = tab_->GetController(); 159 const content::NavigationController& controller = tab_->GetController();
159 int url_index = -1; 160 int url_index = -1;
160 int first_host_index = -1; 161 int first_host_index = -1;
161 162
162 GURL request_url(request->url()); 163 GURL request_url(request->url());
163 int index = controller.GetCurrentEntryIndex(); 164 int index = controller.GetCurrentEntryIndex();
164 // The url that we are extracting features for should already be commited. 165 // The url that we are extracting features for should already be commited.
165 DCHECK_NE(index, -1); 166 DCHECK_NE(index, -1);
166 for (; index >= 0; index--) { 167 for (; index >= 0; index--) {
167 NavigationEntry* entry = controller.GetEntryAtIndex(index); 168 NavigationEntry* entry = controller.GetEntryAtIndex(index);
168 if (url_index == -1 && entry->GetURL() == request_url) { 169 if (url_index == -1 && entry->GetURL() == request_url) {
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 *history = profile->GetHistoryService(Profile::EXPLICIT_ACCESS); 443 *history = profile->GetHistoryService(Profile::EXPLICIT_ACCESS);
443 if (*history) { 444 if (*history) {
444 return true; 445 return true;
445 } 446 }
446 } 447 }
447 VLOG(2) << "Unable to query history. No history service available."; 448 VLOG(2) << "Unable to query history. No history service available.";
448 return false; 449 return false;
449 } 450 }
450 451
451 } // namespace safe_browsing 452 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698