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

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

Issue 2669013002: Convert ClientSideDetectionHost to use the new navigation callbacks. (Closed)
Patch Set: fix unittests Created 3 years, 10 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/client_side_detection_host.h" 5 #include "chrome/browser/safe_browsing/client_side_detection_host.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/metrics/histogram_macros.h" 14 #include "base/metrics/histogram_macros.h"
15 #include "base/sequenced_task_runner_helpers.h" 15 #include "base/sequenced_task_runner_helpers.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" 19 #include "chrome/browser/safe_browsing/browser_feature_extractor.h"
20 #include "chrome/browser/safe_browsing/client_side_detection_service.h" 20 #include "chrome/browser/safe_browsing/client_side_detection_service.h"
21 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 21 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
22 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
23 #include "chrome/common/safe_browsing/csd.pb.h" 23 #include "chrome/common/safe_browsing/csd.pb.h"
24 #include "components/prefs/pref_service.h" 24 #include "components/prefs/pref_service.h"
25 #include "components/safe_browsing/common/safebrowsing_messages.h" 25 #include "components/safe_browsing/common/safebrowsing_messages.h"
26 #include "components/safe_browsing_db/database_manager.h" 26 #include "components/safe_browsing_db/database_manager.h"
27 #include "components/safe_browsing_db/safe_browsing_prefs.h" 27 #include "components/safe_browsing_db/safe_browsing_prefs.h"
28 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
29 #include "content/public/browser/navigation_controller.h" 29 #include "content/public/browser/navigation_controller.h"
30 #include "content/public/browser/navigation_details.h"
31 #include "content/public/browser/navigation_entry.h" 30 #include "content/public/browser/navigation_entry.h"
31 #include "content/public/browser/navigation_handle.h"
32 #include "content/public/browser/render_frame_host.h" 32 #include "content/public/browser/render_frame_host.h"
33 #include "content/public/browser/render_process_host.h" 33 #include "content/public/browser/render_process_host.h"
34 #include "content/public/browser/resource_request_details.h" 34 #include "content/public/browser/resource_request_details.h"
35 #include "content/public/browser/web_contents.h" 35 #include "content/public/browser/web_contents.h"
36 #include "content/public/common/frame_navigate_params.h" 36 #include "content/public/common/frame_navigate_params.h"
37 #include "content/public/common/url_constants.h" 37 #include "content/public/common/url_constants.h"
38 #include "net/http/http_response_headers.h"
38 #include "url/gurl.h" 39 #include "url/gurl.h"
39 40
40 using content::BrowserThread; 41 using content::BrowserThread;
41 using content::NavigationEntry; 42 using content::NavigationEntry;
42 using content::ResourceRequestDetails; 43 using content::ResourceRequestDetails;
43 using content::ResourceType; 44 using content::ResourceType;
44 using content::WebContents; 45 using content::WebContents;
45 46
46 namespace safe_browsing { 47 namespace safe_browsing {
48 namespace {
49 bool g_ignore_mime_type_check = false;
50 }
47 51
48 const size_t ClientSideDetectionHost::kMaxUrlsPerIP = 20; 52 const size_t ClientSideDetectionHost::kMaxUrlsPerIP = 20;
49 const size_t ClientSideDetectionHost::kMaxIPsPerBrowse = 200; 53 const size_t ClientSideDetectionHost::kMaxIPsPerBrowse = 200;
50 54
51 typedef base::Callback<void(bool)> ShouldClassifyUrlCallback; 55 typedef base::Callback<void(bool)> ShouldClassifyUrlCallback;
52 56
53 // This class is instantiated each time a new toplevel URL loads, and 57 // This class is instantiated each time a new toplevel URL loads, and
54 // asynchronously checks whether the malware and phishing classifiers should run 58 // asynchronously checks whether the malware and phishing classifiers should run
55 // for this URL. If so, it notifies the host class by calling the provided 59 // for this URL. If so, it notifies the host class by calling the provided
56 // callback form the UI thread. Objects of this class are ref-counted and will 60 // callback form the UI thread. Objects of this class are ref-counted and will
57 // be destroyed once nobody uses it anymore. If |web_contents|, |csd_service| 61 // be destroyed once nobody uses it anymore. If |web_contents|, |csd_service|
58 // or |host| go away you need to call Cancel(). We keep the |database_manager| 62 // or |host| go away you need to call Cancel(). We keep the |database_manager|
59 // alive in a ref pointer for as long as it takes. 63 // alive in a ref pointer for as long as it takes.
60 class ClientSideDetectionHost::ShouldClassifyUrlRequest 64 class ClientSideDetectionHost::ShouldClassifyUrlRequest
61 : public base::RefCountedThreadSafe< 65 : public base::RefCountedThreadSafe<
62 ClientSideDetectionHost::ShouldClassifyUrlRequest> { 66 ClientSideDetectionHost::ShouldClassifyUrlRequest> {
63 public: 67 public:
64 ShouldClassifyUrlRequest( 68 ShouldClassifyUrlRequest(
65 const content::FrameNavigateParams& params, 69 content::NavigationHandle* navigation_handle,
66 const ShouldClassifyUrlCallback& start_phishing_classification, 70 const ShouldClassifyUrlCallback& start_phishing_classification,
67 const ShouldClassifyUrlCallback& start_malware_classification, 71 const ShouldClassifyUrlCallback& start_malware_classification,
68 WebContents* web_contents, 72 WebContents* web_contents,
69 ClientSideDetectionService* csd_service, 73 ClientSideDetectionService* csd_service,
70 SafeBrowsingDatabaseManager* database_manager, 74 SafeBrowsingDatabaseManager* database_manager,
71 ClientSideDetectionHost* host) 75 ClientSideDetectionHost* host)
72 : params_(params), 76 : web_contents_(web_contents),
73 web_contents_(web_contents),
74 csd_service_(csd_service), 77 csd_service_(csd_service),
75 database_manager_(database_manager), 78 database_manager_(database_manager),
76 host_(host), 79 host_(host),
77 start_phishing_classification_cb_(start_phishing_classification), 80 start_phishing_classification_cb_(start_phishing_classification),
78 start_malware_classification_cb_(start_malware_classification) { 81 start_malware_classification_cb_(start_malware_classification) {
79 DCHECK_CURRENTLY_ON(BrowserThread::UI); 82 DCHECK_CURRENTLY_ON(BrowserThread::UI);
80 DCHECK(web_contents_); 83 DCHECK(web_contents_);
81 DCHECK(csd_service_); 84 DCHECK(csd_service_);
82 DCHECK(database_manager_.get()); 85 DCHECK(database_manager_.get());
83 DCHECK(host_); 86 DCHECK(host_);
87 url_ = navigation_handle->GetURL();
88 if (navigation_handle->GetResponseHeaders())
89 navigation_handle->GetResponseHeaders()->GetMimeType(&mime_type_);
90 socket_address_ = navigation_handle->GetSocketAddress();
84 } 91 }
85 92
86 void Start() { 93 void Start() {
87 DCHECK_CURRENTLY_ON(BrowserThread::UI); 94 DCHECK_CURRENTLY_ON(BrowserThread::UI);
88 95
89 // We start by doing some simple checks that can run on the UI thread. 96 // We start by doing some simple checks that can run on the UI thread.
90 UMA_HISTOGRAM_BOOLEAN("SBClientPhishing.ClassificationStart", 1); 97 UMA_HISTOGRAM_BOOLEAN("SBClientPhishing.ClassificationStart", 1);
91 UMA_HISTOGRAM_BOOLEAN("SBClientMalware.ClassificationStart", 1); 98 UMA_HISTOGRAM_BOOLEAN("SBClientMalware.ClassificationStart", 1);
92 99
93 // Only classify [X]HTML documents. 100 // Only classify [X]HTML documents.
94 if (params_.contents_mime_type != "text/html" && 101 if (mime_type_ != "text/html" && mime_type_ != "application/xhtml+xml" &&
95 params_.contents_mime_type != "application/xhtml+xml") { 102 !g_ignore_mime_type_check) {
96 DVLOG(1) << "Skipping phishing classification for URL: " << params_.url 103 DVLOG(1) << "Skipping phishing classification for URL: " << url_
97 << " because it has an unsupported MIME type: " 104 << " because it has an unsupported MIME type: "
98 << params_.contents_mime_type; 105 << mime_type_;
99 DontClassifyForPhishing(NO_CLASSIFY_UNSUPPORTED_MIME_TYPE); 106 DontClassifyForPhishing(NO_CLASSIFY_UNSUPPORTED_MIME_TYPE);
100 } 107 }
101 108
102 if (csd_service_->IsPrivateIPAddress(params_.socket_address.host())) { 109 if (csd_service_->IsPrivateIPAddress(socket_address_.host())) {
103 DVLOG(1) << "Skipping phishing classification for URL: " << params_.url 110 DVLOG(1) << "Skipping phishing classification for URL: " << url_
104 << " because of hosting on private IP: " 111 << " because of hosting on private IP: "
105 << params_.socket_address.host(); 112 << socket_address_.host();
106 DontClassifyForPhishing(NO_CLASSIFY_PRIVATE_IP); 113 DontClassifyForPhishing(NO_CLASSIFY_PRIVATE_IP);
107 DontClassifyForMalware(NO_CLASSIFY_PRIVATE_IP); 114 DontClassifyForMalware(NO_CLASSIFY_PRIVATE_IP);
108 } 115 }
109 116
110 // For phishing we only classify HTTP pages. 117 // For phishing we only classify HTTP pages.
111 if (!params_.url.SchemeIs(url::kHttpScheme)) { 118 if (!url_.SchemeIs(url::kHttpScheme)) {
112 DVLOG(1) << "Skipping phishing classification for URL: " << params_.url 119 DVLOG(1) << "Skipping phishing classification for URL: " << url_
113 << " because it is not HTTP: " 120 << " because it is not HTTP: "
114 << params_.socket_address.host(); 121 << socket_address_.host();
115 DontClassifyForPhishing(NO_CLASSIFY_NOT_HTTP_URL); 122 DontClassifyForPhishing(NO_CLASSIFY_NOT_HTTP_URL);
116 } 123 }
117 124
118 // Don't run any classifier if the tab is incognito. 125 // Don't run any classifier if the tab is incognito.
119 if (web_contents_->GetBrowserContext()->IsOffTheRecord()) { 126 if (web_contents_->GetBrowserContext()->IsOffTheRecord()) {
120 DVLOG(1) << "Skipping phishing and malware classification for URL: " 127 DVLOG(1) << "Skipping phishing and malware classification for URL: "
121 << params_.url << " because we're browsing incognito."; 128 << url_ << " because we're browsing incognito.";
122 DontClassifyForPhishing(NO_CLASSIFY_OFF_THE_RECORD); 129 DontClassifyForPhishing(NO_CLASSIFY_OFF_THE_RECORD);
123 DontClassifyForMalware(NO_CLASSIFY_OFF_THE_RECORD); 130 DontClassifyForMalware(NO_CLASSIFY_OFF_THE_RECORD);
124 } 131 }
125 132
126 // We lookup the csd-whitelist before we lookup the cache because 133 // We lookup the csd-whitelist before we lookup the cache because
127 // a URL may have recently been whitelisted. If the URL matches 134 // a URL may have recently been whitelisted. If the URL matches
128 // the csd-whitelist we won't start phishing classification. The 135 // the csd-whitelist we won't start phishing classification. The
129 // csd-whitelist check has to be done on the IO thread because it 136 // csd-whitelist check has to be done on the IO thread because it
130 // uses the SafeBrowsing service class. 137 // uses the SafeBrowsing service class.
131 if (ShouldClassifyForPhishing() || ShouldClassifyForMalware()) { 138 if (ShouldClassifyForPhishing() || ShouldClassifyForMalware()) {
132 BrowserThread::PostTask( 139 BrowserThread::PostTask(
133 BrowserThread::IO, 140 BrowserThread::IO,
134 FROM_HERE, 141 FROM_HERE,
135 base::Bind(&ShouldClassifyUrlRequest::CheckSafeBrowsingDatabase, 142 base::Bind(&ShouldClassifyUrlRequest::CheckSafeBrowsingDatabase,
136 this, params_.url)); 143 this, url_));
137 } 144 }
138 } 145 }
139 146
140 void Cancel() { 147 void Cancel() {
141 DontClassifyForPhishing(NO_CLASSIFY_CANCEL); 148 DontClassifyForPhishing(NO_CLASSIFY_CANCEL);
142 DontClassifyForMalware(NO_CLASSIFY_CANCEL); 149 DontClassifyForMalware(NO_CLASSIFY_CANCEL);
143 // Just to make sure we don't do anything stupid we reset all these 150 // Just to make sure we don't do anything stupid we reset all these
144 // pointers except for the safebrowsing service class which may be 151 // pointers except for the safebrowsing service class which may be
145 // accessed by CheckSafeBrowsingDatabase(). 152 // accessed by CheckSafeBrowsingDatabase().
146 web_contents_ = NULL; 153 web_contents_ = NULL;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 if (phishing_reason != NO_CLASSIFY_MAX) 251 if (phishing_reason != NO_CLASSIFY_MAX)
245 DontClassifyForPhishing(phishing_reason); 252 DontClassifyForPhishing(phishing_reason);
246 if (malware_reason != NO_CLASSIFY_MAX) 253 if (malware_reason != NO_CLASSIFY_MAX)
247 DontClassifyForMalware(malware_reason); 254 DontClassifyForMalware(malware_reason);
248 if (!ShouldClassifyForMalware() && !ShouldClassifyForPhishing()) { 255 if (!ShouldClassifyForMalware() && !ShouldClassifyForPhishing()) {
249 return; // No point in doing anything else. 256 return; // No point in doing anything else.
250 } 257 }
251 // If result is cached, we don't want to run classification again. 258 // If result is cached, we don't want to run classification again.
252 // In that case we're just trying to show the warning. 259 // In that case we're just trying to show the warning.
253 bool is_phishing; 260 bool is_phishing;
254 if (csd_service_->GetValidCachedResult(params_.url, &is_phishing)) { 261 if (csd_service_->GetValidCachedResult(url_, &is_phishing)) {
255 DVLOG(1) << "Satisfying request for " << params_.url << " from cache"; 262 DVLOG(1) << "Satisfying request for " << url_ << " from cache";
256 UMA_HISTOGRAM_BOOLEAN("SBClientPhishing.RequestSatisfiedFromCache", 1); 263 UMA_HISTOGRAM_BOOLEAN("SBClientPhishing.RequestSatisfiedFromCache", 1);
257 // Since we are already on the UI thread, this is safe. 264 // Since we are already on the UI thread, this is safe.
258 host_->MaybeShowPhishingWarning(params_.url, is_phishing); 265 host_->MaybeShowPhishingWarning(url_, is_phishing);
259 DontClassifyForPhishing(NO_CLASSIFY_RESULT_FROM_CACHE); 266 DontClassifyForPhishing(NO_CLASSIFY_RESULT_FROM_CACHE);
260 } 267 }
261 268
262 // We want to limit the number of requests, though we will ignore the 269 // We want to limit the number of requests, though we will ignore the
263 // limit for urls in the cache. We don't want to start classifying 270 // limit for urls in the cache. We don't want to start classifying
264 // too many pages as phishing, but for those that we already think are 271 // too many pages as phishing, but for those that we already think are
265 // phishing we want to send a request to the server to give ourselves 272 // phishing we want to send a request to the server to give ourselves
266 // a chance to fix misclassifications. 273 // a chance to fix misclassifications.
267 if (csd_service_->IsInCache(params_.url)) { 274 if (csd_service_->IsInCache(url_)) {
268 DVLOG(1) << "Reporting limit skipped for " << params_.url 275 DVLOG(1) << "Reporting limit skipped for " << url_
269 << " as it was in the cache."; 276 << " as it was in the cache.";
270 UMA_HISTOGRAM_BOOLEAN("SBClientPhishing.ReportLimitSkipped", 1); 277 UMA_HISTOGRAM_BOOLEAN("SBClientPhishing.ReportLimitSkipped", 1);
271 } else if (csd_service_->OverPhishingReportLimit()) { 278 } else if (csd_service_->OverPhishingReportLimit()) {
272 DVLOG(1) << "Too many report phishing requests sent recently, " 279 DVLOG(1) << "Too many report phishing requests sent recently, "
273 << "not running classification for " << params_.url; 280 << "not running classification for " << url_;
274 DontClassifyForPhishing(NO_CLASSIFY_TOO_MANY_REPORTS); 281 DontClassifyForPhishing(NO_CLASSIFY_TOO_MANY_REPORTS);
275 } 282 }
276 if (csd_service_->OverMalwareReportLimit()) { 283 if (csd_service_->OverMalwareReportLimit()) {
277 DontClassifyForMalware(NO_CLASSIFY_TOO_MANY_REPORTS); 284 DontClassifyForMalware(NO_CLASSIFY_TOO_MANY_REPORTS);
278 } 285 }
279 286
280 // Everything checks out, so start classification. 287 // Everything checks out, so start classification.
281 // |web_contents_| is safe to call as we will be destructed 288 // |web_contents_| is safe to call as we will be destructed
282 // before it is. 289 // before it is.
283 if (ShouldClassifyForPhishing()) { 290 if (ShouldClassifyForPhishing()) {
284 start_phishing_classification_cb_.Run(true); 291 start_phishing_classification_cb_.Run(true);
285 // Reset the callback to make sure ShouldClassifyForPhishing() 292 // Reset the callback to make sure ShouldClassifyForPhishing()
286 // returns false. 293 // returns false.
287 start_phishing_classification_cb_.Reset(); 294 start_phishing_classification_cb_.Reset();
288 } 295 }
289 if (ShouldClassifyForMalware()) { 296 if (ShouldClassifyForMalware()) {
290 start_malware_classification_cb_.Run(true); 297 start_malware_classification_cb_.Run(true);
291 // Reset the callback to make sure ShouldClassifyForMalware() 298 // Reset the callback to make sure ShouldClassifyForMalware()
292 // returns false. 299 // returns false.
293 start_malware_classification_cb_.Reset(); 300 start_malware_classification_cb_.Reset();
294 } 301 }
295 } 302 }
296 303
297 content::FrameNavigateParams params_; 304 GURL url_;
305 std::string mime_type_;
306 net::HostPortPair socket_address_;
298 WebContents* web_contents_; 307 WebContents* web_contents_;
299 ClientSideDetectionService* csd_service_; 308 ClientSideDetectionService* csd_service_;
300 // We keep a ref pointer here just to make sure the safe browsing 309 // We keep a ref pointer here just to make sure the safe browsing
301 // database manager stays alive long enough. 310 // database manager stays alive long enough.
302 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; 311 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_;
303 ClientSideDetectionHost* host_; 312 ClientSideDetectionHost* host_;
304 313
305 ShouldClassifyUrlCallback start_phishing_classification_cb_; 314 ShouldClassifyUrlCallback start_phishing_classification_cb_;
306 ShouldClassifyUrlCallback start_malware_classification_cb_; 315 ShouldClassifyUrlCallback start_malware_classification_cb_;
307 316
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 content::RenderFrameHost* render_frame_host) { 356 content::RenderFrameHost* render_frame_host) {
348 bool handled = true; 357 bool handled = true;
349 IPC_BEGIN_MESSAGE_MAP(ClientSideDetectionHost, message) 358 IPC_BEGIN_MESSAGE_MAP(ClientSideDetectionHost, message)
350 IPC_MESSAGE_HANDLER(SafeBrowsingHostMsg_PhishingDetectionDone, 359 IPC_MESSAGE_HANDLER(SafeBrowsingHostMsg_PhishingDetectionDone,
351 OnPhishingDetectionDone) 360 OnPhishingDetectionDone)
352 IPC_MESSAGE_UNHANDLED(handled = false) 361 IPC_MESSAGE_UNHANDLED(handled = false)
353 IPC_END_MESSAGE_MAP() 362 IPC_END_MESSAGE_MAP()
354 return handled; 363 return handled;
355 } 364 }
356 365
357 void ClientSideDetectionHost::DidNavigateMainFrame( 366 void ClientSideDetectionHost::DidFinishNavigation(
358 const content::LoadCommittedDetails& details, 367 content::NavigationHandle* navigation_handle) {
359 const content::FrameNavigateParams& params) { 368 if (!navigation_handle->IsInMainFrame() || !navigation_handle->HasCommitted())
369 return;
370
360 // TODO(noelutz): move this DCHECK to WebContents and fix all the unit tests 371 // TODO(noelutz): move this DCHECK to WebContents and fix all the unit tests
361 // that don't call this method on the UI thread. 372 // that don't call this method on the UI thread.
362 // DCHECK_CURRENTLY_ON(BrowserThread::UI); 373 // DCHECK_CURRENTLY_ON(BrowserThread::UI);
363 if (details.is_in_page) { 374 if (navigation_handle->IsSamePage()) {
364 // If the navigation is within the same page, the user isn't really 375 // If the navigation is within the same page, the user isn't really
365 // navigating away. We don't need to cancel a pending callback or 376 // navigating away. We don't need to cancel a pending callback or
366 // begin a new classification. 377 // begin a new classification.
367 return; 378 return;
368 } 379 }
369 // Cancel any pending classification request. 380 // Cancel any pending classification request.
370 if (classification_request_.get()) { 381 if (classification_request_.get()) {
371 classification_request_->Cancel(); 382 classification_request_->Cancel();
372 } 383 }
373 // If we navigate away and there currently is a pending phishing 384 // If we navigate away and there currently is a pending phishing
374 // report request we have to cancel it to make sure we don't display 385 // report request we have to cancel it to make sure we don't display
375 // an interstitial for the wrong page. Note that this won't cancel 386 // an interstitial for the wrong page. Note that this won't cancel
376 // the server ping back but only cancel the showing of the 387 // the server ping back but only cancel the showing of the
377 // interstial. 388 // interstial.
378 weak_factory_.InvalidateWeakPtrs(); 389 weak_factory_.InvalidateWeakPtrs();
379 390
380 if (!csd_service_) { 391 if (!csd_service_) {
381 return; 392 return;
382 } 393 }
383 browse_info_.reset(new BrowseInfo); 394 browse_info_.reset(new BrowseInfo);
384 395
385 // Store redirect chain information. 396 // Store redirect chain information.
386 if (params.url.host() != cur_host_) { 397 if (navigation_handle->GetURL().host() != cur_host_) {
387 cur_host_ = params.url.host(); 398 cur_host_ = navigation_handle->GetURL().host();
388 cur_host_redirects_ = params.redirects; 399 cur_host_redirects_ = navigation_handle->GetRedirectChain();
389 } 400 }
390 browse_info_->url = params.url; 401 browse_info_->url = navigation_handle->GetURL();
391 browse_info_->host_redirects = cur_host_redirects_; 402 browse_info_->host_redirects = cur_host_redirects_;
392 browse_info_->url_redirects = params.redirects; 403 browse_info_->url_redirects = navigation_handle->GetRedirectChain();
393 browse_info_->referrer = params.referrer.url; 404 browse_info_->referrer = navigation_handle->GetReferrer().url;
394 browse_info_->http_status_code = details.http_status_code; 405 if (navigation_handle->GetResponseHeaders()) {
406 browse_info_->http_status_code =
407 navigation_handle->GetResponseHeaders()->response_code();
408 }
395 409
396 should_extract_malware_features_ = true; 410 should_extract_malware_features_ = true;
397 should_classify_for_malware_ = false; 411 should_classify_for_malware_ = false;
398 pageload_complete_ = false; 412 pageload_complete_ = false;
399 413
400 // Check whether we can cassify the current URL for phishing or malware. 414 // Check whether we can cassify the current URL for phishing or malware.
401 classification_request_ = new ShouldClassifyUrlRequest( 415 classification_request_ = new ShouldClassifyUrlRequest(
402 params, 416 navigation_handle,
403 base::Bind(&ClientSideDetectionHost::OnPhishingPreClassificationDone, 417 base::Bind(&ClientSideDetectionHost::OnPhishingPreClassificationDone,
404 weak_factory_.GetWeakPtr()), 418 weak_factory_.GetWeakPtr()),
405 base::Bind(&ClientSideDetectionHost::OnMalwarePreClassificationDone, 419 base::Bind(&ClientSideDetectionHost::OnMalwarePreClassificationDone,
406 weak_factory_.GetWeakPtr()), 420 weak_factory_.GetWeakPtr()),
407 web_contents(), csd_service_, database_manager_.get(), this); 421 web_contents(), csd_service_, database_manager_.get(), this);
408 classification_request_->Start(); 422 classification_request_->Start();
409 } 423 }
410 424
411 void ClientSideDetectionHost::OnSafeBrowsingHit( 425 void ClientSideDetectionHost::OnSafeBrowsingHit(
412 const security_interstitials::UnsafeResource& resource) { 426 const security_interstitials::UnsafeResource& resource) {
(...skipping 20 matching lines...) Expand all
433 // malicious URL to the server. 447 // malicious URL to the server.
434 unsafe_resource_.reset(new security_interstitials::UnsafeResource(resource)); 448 unsafe_resource_.reset(new security_interstitials::UnsafeResource(resource));
435 unsafe_resource_->callback.Reset(); // Don't do anything stupid. 449 unsafe_resource_->callback.Reset(); // Don't do anything stupid.
436 } 450 }
437 451
438 scoped_refptr<SafeBrowsingDatabaseManager> 452 scoped_refptr<SafeBrowsingDatabaseManager>
439 ClientSideDetectionHost::database_manager() { 453 ClientSideDetectionHost::database_manager() {
440 return database_manager_; 454 return database_manager_;
441 } 455 }
442 456
457 void ClientSideDetectionHost::IgnoreMimeTypeCheckForTesting(bool ignore) {
458 g_ignore_mime_type_check = ignore;
459 }
460
443 void ClientSideDetectionHost::WebContentsDestroyed() { 461 void ClientSideDetectionHost::WebContentsDestroyed() {
444 // Tell any pending classification request that it is being canceled. 462 // Tell any pending classification request that it is being canceled.
445 if (classification_request_.get()) { 463 if (classification_request_.get()) {
446 classification_request_->Cancel(); 464 classification_request_->Cancel();
447 } 465 }
448 // Cancel all pending feature extractions. 466 // Cancel all pending feature extractions.
449 feature_extractor_.reset(); 467 feature_extractor_.reset();
450 } 468 }
451 469
452 void ClientSideDetectionHost::OnPhishingPreClassificationDone( 470 void ClientSideDetectionHost::OnPhishingPreClassificationDone(
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 ui_manager_->RemoveObserver(this); 733 ui_manager_->RemoveObserver(this);
716 734
717 ui_manager_ = ui_manager; 735 ui_manager_ = ui_manager;
718 if (ui_manager) 736 if (ui_manager)
719 ui_manager_->AddObserver(this); 737 ui_manager_->AddObserver(this);
720 738
721 database_manager_ = database_manager; 739 database_manager_ = database_manager;
722 } 740 }
723 741
724 } // namespace safe_browsing 742 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698