| OLD | NEW |
| 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 { |
| 47 | 48 |
| 48 const size_t ClientSideDetectionHost::kMaxUrlsPerIP = 20; | 49 const size_t ClientSideDetectionHost::kMaxUrlsPerIP = 20; |
| 49 const size_t ClientSideDetectionHost::kMaxIPsPerBrowse = 200; | 50 const size_t ClientSideDetectionHost::kMaxIPsPerBrowse = 200; |
| 50 | 51 |
| 51 typedef base::Callback<void(bool)> ShouldClassifyUrlCallback; | 52 typedef base::Callback<void(bool)> ShouldClassifyUrlCallback; |
| 52 | 53 |
| 53 // This class is instantiated each time a new toplevel URL loads, and | 54 // This class is instantiated each time a new toplevel URL loads, and |
| 54 // asynchronously checks whether the malware and phishing classifiers should run | 55 // 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 | 56 // 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 | 57 // 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| | 58 // 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| | 59 // 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. | 60 // alive in a ref pointer for as long as it takes. |
| 60 class ClientSideDetectionHost::ShouldClassifyUrlRequest | 61 class ClientSideDetectionHost::ShouldClassifyUrlRequest |
| 61 : public base::RefCountedThreadSafe< | 62 : public base::RefCountedThreadSafe< |
| 62 ClientSideDetectionHost::ShouldClassifyUrlRequest> { | 63 ClientSideDetectionHost::ShouldClassifyUrlRequest> { |
| 63 public: | 64 public: |
| 64 ShouldClassifyUrlRequest( | 65 ShouldClassifyUrlRequest( |
| 65 const content::FrameNavigateParams& params, | 66 content::NavigationHandle* navigation_handle, |
| 66 const ShouldClassifyUrlCallback& start_phishing_classification, | 67 const ShouldClassifyUrlCallback& start_phishing_classification, |
| 67 const ShouldClassifyUrlCallback& start_malware_classification, | 68 const ShouldClassifyUrlCallback& start_malware_classification, |
| 68 WebContents* web_contents, | 69 WebContents* web_contents, |
| 69 ClientSideDetectionService* csd_service, | 70 ClientSideDetectionService* csd_service, |
| 70 SafeBrowsingDatabaseManager* database_manager, | 71 SafeBrowsingDatabaseManager* database_manager, |
| 71 ClientSideDetectionHost* host) | 72 ClientSideDetectionHost* host) |
| 72 : params_(params), | 73 : web_contents_(web_contents), |
| 73 web_contents_(web_contents), | |
| 74 csd_service_(csd_service), | 74 csd_service_(csd_service), |
| 75 database_manager_(database_manager), | 75 database_manager_(database_manager), |
| 76 host_(host), | 76 host_(host), |
| 77 start_phishing_classification_cb_(start_phishing_classification), | 77 start_phishing_classification_cb_(start_phishing_classification), |
| 78 start_malware_classification_cb_(start_malware_classification) { | 78 start_malware_classification_cb_(start_malware_classification) { |
| 79 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 79 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 80 DCHECK(web_contents_); | 80 DCHECK(web_contents_); |
| 81 DCHECK(csd_service_); | 81 DCHECK(csd_service_); |
| 82 DCHECK(database_manager_.get()); | 82 DCHECK(database_manager_.get()); |
| 83 DCHECK(host_); | 83 DCHECK(host_); |
| 84 url_ = navigation_handle->GetURL(); |
| 85 if (navigation_handle->GetResponseHeaders()) |
| 86 navigation_handle->GetResponseHeaders()->GetMimeType(&mime_type_); |
| 87 socket_address_ = navigation_handle->GetSocketAddress(); |
| 84 } | 88 } |
| 85 | 89 |
| 86 void Start() { | 90 void Start() { |
| 87 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 91 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 88 | 92 |
| 89 // We start by doing some simple checks that can run on the UI thread. | 93 // We start by doing some simple checks that can run on the UI thread. |
| 90 UMA_HISTOGRAM_BOOLEAN("SBClientPhishing.ClassificationStart", 1); | 94 UMA_HISTOGRAM_BOOLEAN("SBClientPhishing.ClassificationStart", 1); |
| 91 UMA_HISTOGRAM_BOOLEAN("SBClientMalware.ClassificationStart", 1); | 95 UMA_HISTOGRAM_BOOLEAN("SBClientMalware.ClassificationStart", 1); |
| 92 | 96 |
| 93 // Only classify [X]HTML documents. | 97 // Only classify [X]HTML documents. |
| 94 if (params_.contents_mime_type != "text/html" && | 98 if (mime_type_ != "text/html" && mime_type_ != "application/xhtml+xml") { |
| 95 params_.contents_mime_type != "application/xhtml+xml") { | 99 DVLOG(1) << "Skipping phishing classification for URL: " << url_ |
| 96 DVLOG(1) << "Skipping phishing classification for URL: " << params_.url | |
| 97 << " because it has an unsupported MIME type: " | 100 << " because it has an unsupported MIME type: " |
| 98 << params_.contents_mime_type; | 101 << mime_type_; |
| 99 DontClassifyForPhishing(NO_CLASSIFY_UNSUPPORTED_MIME_TYPE); | 102 DontClassifyForPhishing(NO_CLASSIFY_UNSUPPORTED_MIME_TYPE); |
| 100 } | 103 } |
| 101 | 104 |
| 102 if (csd_service_->IsPrivateIPAddress(params_.socket_address.host())) { | 105 if (csd_service_->IsPrivateIPAddress(socket_address_.host())) { |
| 103 DVLOG(1) << "Skipping phishing classification for URL: " << params_.url | 106 DVLOG(1) << "Skipping phishing classification for URL: " << url_ |
| 104 << " because of hosting on private IP: " | 107 << " because of hosting on private IP: " |
| 105 << params_.socket_address.host(); | 108 << socket_address_.host(); |
| 106 DontClassifyForPhishing(NO_CLASSIFY_PRIVATE_IP); | 109 DontClassifyForPhishing(NO_CLASSIFY_PRIVATE_IP); |
| 107 DontClassifyForMalware(NO_CLASSIFY_PRIVATE_IP); | 110 DontClassifyForMalware(NO_CLASSIFY_PRIVATE_IP); |
| 108 } | 111 } |
| 109 | 112 |
| 110 // For phishing we only classify HTTP pages. | 113 // For phishing we only classify HTTP pages. |
| 111 if (!params_.url.SchemeIs(url::kHttpScheme)) { | 114 if (!url_.SchemeIs(url::kHttpScheme)) { |
| 112 DVLOG(1) << "Skipping phishing classification for URL: " << params_.url | 115 DVLOG(1) << "Skipping phishing classification for URL: " << url_ |
| 113 << " because it is not HTTP: " | 116 << " because it is not HTTP: " |
| 114 << params_.socket_address.host(); | 117 << socket_address_.host(); |
| 115 DontClassifyForPhishing(NO_CLASSIFY_NOT_HTTP_URL); | 118 DontClassifyForPhishing(NO_CLASSIFY_NOT_HTTP_URL); |
| 116 } | 119 } |
| 117 | 120 |
| 118 // Don't run any classifier if the tab is incognito. | 121 // Don't run any classifier if the tab is incognito. |
| 119 if (web_contents_->GetBrowserContext()->IsOffTheRecord()) { | 122 if (web_contents_->GetBrowserContext()->IsOffTheRecord()) { |
| 120 DVLOG(1) << "Skipping phishing and malware classification for URL: " | 123 DVLOG(1) << "Skipping phishing and malware classification for URL: " |
| 121 << params_.url << " because we're browsing incognito."; | 124 << url_ << " because we're browsing incognito."; |
| 122 DontClassifyForPhishing(NO_CLASSIFY_OFF_THE_RECORD); | 125 DontClassifyForPhishing(NO_CLASSIFY_OFF_THE_RECORD); |
| 123 DontClassifyForMalware(NO_CLASSIFY_OFF_THE_RECORD); | 126 DontClassifyForMalware(NO_CLASSIFY_OFF_THE_RECORD); |
| 124 } | 127 } |
| 125 | 128 |
| 126 // We lookup the csd-whitelist before we lookup the cache because | 129 // We lookup the csd-whitelist before we lookup the cache because |
| 127 // a URL may have recently been whitelisted. If the URL matches | 130 // a URL may have recently been whitelisted. If the URL matches |
| 128 // the csd-whitelist we won't start phishing classification. The | 131 // the csd-whitelist we won't start phishing classification. The |
| 129 // csd-whitelist check has to be done on the IO thread because it | 132 // csd-whitelist check has to be done on the IO thread because it |
| 130 // uses the SafeBrowsing service class. | 133 // uses the SafeBrowsing service class. |
| 131 if (ShouldClassifyForPhishing() || ShouldClassifyForMalware()) { | 134 if (ShouldClassifyForPhishing() || ShouldClassifyForMalware()) { |
| 132 BrowserThread::PostTask( | 135 BrowserThread::PostTask( |
| 133 BrowserThread::IO, | 136 BrowserThread::IO, |
| 134 FROM_HERE, | 137 FROM_HERE, |
| 135 base::Bind(&ShouldClassifyUrlRequest::CheckSafeBrowsingDatabase, | 138 base::Bind(&ShouldClassifyUrlRequest::CheckSafeBrowsingDatabase, |
| 136 this, params_.url)); | 139 this, url_)); |
| 137 } | 140 } |
| 138 } | 141 } |
| 139 | 142 |
| 140 void Cancel() { | 143 void Cancel() { |
| 141 DontClassifyForPhishing(NO_CLASSIFY_CANCEL); | 144 DontClassifyForPhishing(NO_CLASSIFY_CANCEL); |
| 142 DontClassifyForMalware(NO_CLASSIFY_CANCEL); | 145 DontClassifyForMalware(NO_CLASSIFY_CANCEL); |
| 143 // Just to make sure we don't do anything stupid we reset all these | 146 // 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 | 147 // pointers except for the safebrowsing service class which may be |
| 145 // accessed by CheckSafeBrowsingDatabase(). | 148 // accessed by CheckSafeBrowsingDatabase(). |
| 146 web_contents_ = NULL; | 149 web_contents_ = NULL; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 if (phishing_reason != NO_CLASSIFY_MAX) | 247 if (phishing_reason != NO_CLASSIFY_MAX) |
| 245 DontClassifyForPhishing(phishing_reason); | 248 DontClassifyForPhishing(phishing_reason); |
| 246 if (malware_reason != NO_CLASSIFY_MAX) | 249 if (malware_reason != NO_CLASSIFY_MAX) |
| 247 DontClassifyForMalware(malware_reason); | 250 DontClassifyForMalware(malware_reason); |
| 248 if (!ShouldClassifyForMalware() && !ShouldClassifyForPhishing()) { | 251 if (!ShouldClassifyForMalware() && !ShouldClassifyForPhishing()) { |
| 249 return; // No point in doing anything else. | 252 return; // No point in doing anything else. |
| 250 } | 253 } |
| 251 // If result is cached, we don't want to run classification again. | 254 // If result is cached, we don't want to run classification again. |
| 252 // In that case we're just trying to show the warning. | 255 // In that case we're just trying to show the warning. |
| 253 bool is_phishing; | 256 bool is_phishing; |
| 254 if (csd_service_->GetValidCachedResult(params_.url, &is_phishing)) { | 257 if (csd_service_->GetValidCachedResult(url_, &is_phishing)) { |
| 255 DVLOG(1) << "Satisfying request for " << params_.url << " from cache"; | 258 DVLOG(1) << "Satisfying request for " << url_ << " from cache"; |
| 256 UMA_HISTOGRAM_BOOLEAN("SBClientPhishing.RequestSatisfiedFromCache", 1); | 259 UMA_HISTOGRAM_BOOLEAN("SBClientPhishing.RequestSatisfiedFromCache", 1); |
| 257 // Since we are already on the UI thread, this is safe. | 260 // Since we are already on the UI thread, this is safe. |
| 258 host_->MaybeShowPhishingWarning(params_.url, is_phishing); | 261 host_->MaybeShowPhishingWarning(url_, is_phishing); |
| 259 DontClassifyForPhishing(NO_CLASSIFY_RESULT_FROM_CACHE); | 262 DontClassifyForPhishing(NO_CLASSIFY_RESULT_FROM_CACHE); |
| 260 } | 263 } |
| 261 | 264 |
| 262 // We want to limit the number of requests, though we will ignore the | 265 // 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 | 266 // 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 | 267 // 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 | 268 // phishing we want to send a request to the server to give ourselves |
| 266 // a chance to fix misclassifications. | 269 // a chance to fix misclassifications. |
| 267 if (csd_service_->IsInCache(params_.url)) { | 270 if (csd_service_->IsInCache(url_)) { |
| 268 DVLOG(1) << "Reporting limit skipped for " << params_.url | 271 DVLOG(1) << "Reporting limit skipped for " << url_ |
| 269 << " as it was in the cache."; | 272 << " as it was in the cache."; |
| 270 UMA_HISTOGRAM_BOOLEAN("SBClientPhishing.ReportLimitSkipped", 1); | 273 UMA_HISTOGRAM_BOOLEAN("SBClientPhishing.ReportLimitSkipped", 1); |
| 271 } else if (csd_service_->OverPhishingReportLimit()) { | 274 } else if (csd_service_->OverPhishingReportLimit()) { |
| 272 DVLOG(1) << "Too many report phishing requests sent recently, " | 275 DVLOG(1) << "Too many report phishing requests sent recently, " |
| 273 << "not running classification for " << params_.url; | 276 << "not running classification for " << url_; |
| 274 DontClassifyForPhishing(NO_CLASSIFY_TOO_MANY_REPORTS); | 277 DontClassifyForPhishing(NO_CLASSIFY_TOO_MANY_REPORTS); |
| 275 } | 278 } |
| 276 if (csd_service_->OverMalwareReportLimit()) { | 279 if (csd_service_->OverMalwareReportLimit()) { |
| 277 DontClassifyForMalware(NO_CLASSIFY_TOO_MANY_REPORTS); | 280 DontClassifyForMalware(NO_CLASSIFY_TOO_MANY_REPORTS); |
| 278 } | 281 } |
| 279 | 282 |
| 280 // Everything checks out, so start classification. | 283 // Everything checks out, so start classification. |
| 281 // |web_contents_| is safe to call as we will be destructed | 284 // |web_contents_| is safe to call as we will be destructed |
| 282 // before it is. | 285 // before it is. |
| 283 if (ShouldClassifyForPhishing()) { | 286 if (ShouldClassifyForPhishing()) { |
| 284 start_phishing_classification_cb_.Run(true); | 287 start_phishing_classification_cb_.Run(true); |
| 285 // Reset the callback to make sure ShouldClassifyForPhishing() | 288 // Reset the callback to make sure ShouldClassifyForPhishing() |
| 286 // returns false. | 289 // returns false. |
| 287 start_phishing_classification_cb_.Reset(); | 290 start_phishing_classification_cb_.Reset(); |
| 288 } | 291 } |
| 289 if (ShouldClassifyForMalware()) { | 292 if (ShouldClassifyForMalware()) { |
| 290 start_malware_classification_cb_.Run(true); | 293 start_malware_classification_cb_.Run(true); |
| 291 // Reset the callback to make sure ShouldClassifyForMalware() | 294 // Reset the callback to make sure ShouldClassifyForMalware() |
| 292 // returns false. | 295 // returns false. |
| 293 start_malware_classification_cb_.Reset(); | 296 start_malware_classification_cb_.Reset(); |
| 294 } | 297 } |
| 295 } | 298 } |
| 296 | 299 |
| 297 content::FrameNavigateParams params_; | 300 GURL url_; |
| 301 std::string mime_type_; |
| 302 net::HostPortPair socket_address_; |
| 298 WebContents* web_contents_; | 303 WebContents* web_contents_; |
| 299 ClientSideDetectionService* csd_service_; | 304 ClientSideDetectionService* csd_service_; |
| 300 // We keep a ref pointer here just to make sure the safe browsing | 305 // We keep a ref pointer here just to make sure the safe browsing |
| 301 // database manager stays alive long enough. | 306 // database manager stays alive long enough. |
| 302 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; | 307 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; |
| 303 ClientSideDetectionHost* host_; | 308 ClientSideDetectionHost* host_; |
| 304 | 309 |
| 305 ShouldClassifyUrlCallback start_phishing_classification_cb_; | 310 ShouldClassifyUrlCallback start_phishing_classification_cb_; |
| 306 ShouldClassifyUrlCallback start_malware_classification_cb_; | 311 ShouldClassifyUrlCallback start_malware_classification_cb_; |
| 307 | 312 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 content::RenderFrameHost* render_frame_host) { | 352 content::RenderFrameHost* render_frame_host) { |
| 348 bool handled = true; | 353 bool handled = true; |
| 349 IPC_BEGIN_MESSAGE_MAP(ClientSideDetectionHost, message) | 354 IPC_BEGIN_MESSAGE_MAP(ClientSideDetectionHost, message) |
| 350 IPC_MESSAGE_HANDLER(SafeBrowsingHostMsg_PhishingDetectionDone, | 355 IPC_MESSAGE_HANDLER(SafeBrowsingHostMsg_PhishingDetectionDone, |
| 351 OnPhishingDetectionDone) | 356 OnPhishingDetectionDone) |
| 352 IPC_MESSAGE_UNHANDLED(handled = false) | 357 IPC_MESSAGE_UNHANDLED(handled = false) |
| 353 IPC_END_MESSAGE_MAP() | 358 IPC_END_MESSAGE_MAP() |
| 354 return handled; | 359 return handled; |
| 355 } | 360 } |
| 356 | 361 |
| 357 void ClientSideDetectionHost::DidNavigateMainFrame( | 362 void ClientSideDetectionHost::DidFinishNavigation( |
| 358 const content::LoadCommittedDetails& details, | 363 content::NavigationHandle* navigation_handle) { |
| 359 const content::FrameNavigateParams& params) { | 364 if (!navigation_handle->IsInMainFrame() || !navigation_handle->HasCommitted()) |
| 365 return; |
| 366 |
| 360 // TODO(noelutz): move this DCHECK to WebContents and fix all the unit tests | 367 // TODO(noelutz): move this DCHECK to WebContents and fix all the unit tests |
| 361 // that don't call this method on the UI thread. | 368 // that don't call this method on the UI thread. |
| 362 // DCHECK_CURRENTLY_ON(BrowserThread::UI); | 369 // DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 363 if (details.is_in_page) { | 370 if (navigation_handle->IsSamePage()) { |
| 364 // If the navigation is within the same page, the user isn't really | 371 // 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 | 372 // navigating away. We don't need to cancel a pending callback or |
| 366 // begin a new classification. | 373 // begin a new classification. |
| 367 return; | 374 return; |
| 368 } | 375 } |
| 369 // Cancel any pending classification request. | 376 // Cancel any pending classification request. |
| 370 if (classification_request_.get()) { | 377 if (classification_request_.get()) { |
| 371 classification_request_->Cancel(); | 378 classification_request_->Cancel(); |
| 372 } | 379 } |
| 373 // If we navigate away and there currently is a pending phishing | 380 // 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 | 381 // 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 | 382 // an interstitial for the wrong page. Note that this won't cancel |
| 376 // the server ping back but only cancel the showing of the | 383 // the server ping back but only cancel the showing of the |
| 377 // interstial. | 384 // interstial. |
| 378 weak_factory_.InvalidateWeakPtrs(); | 385 weak_factory_.InvalidateWeakPtrs(); |
| 379 | 386 |
| 380 if (!csd_service_) { | 387 if (!csd_service_) { |
| 381 return; | 388 return; |
| 382 } | 389 } |
| 383 browse_info_.reset(new BrowseInfo); | 390 browse_info_.reset(new BrowseInfo); |
| 384 | 391 |
| 385 // Store redirect chain information. | 392 // Store redirect chain information. |
| 386 if (params.url.host() != cur_host_) { | 393 if (navigation_handle->GetURL().host() != cur_host_) { |
| 387 cur_host_ = params.url.host(); | 394 cur_host_ = navigation_handle->GetURL().host(); |
| 388 cur_host_redirects_ = params.redirects; | 395 cur_host_redirects_ = navigation_handle->GetRedirectChain(); |
| 389 } | 396 } |
| 390 browse_info_->url = params.url; | 397 browse_info_->url = navigation_handle->GetURL(); |
| 391 browse_info_->host_redirects = cur_host_redirects_; | 398 browse_info_->host_redirects = cur_host_redirects_; |
| 392 browse_info_->url_redirects = params.redirects; | 399 browse_info_->url_redirects = navigation_handle->GetRedirectChain(); |
| 393 browse_info_->referrer = params.referrer.url; | 400 browse_info_->referrer = navigation_handle->GetReferrer().url; |
| 394 browse_info_->http_status_code = details.http_status_code; | 401 if (navigation_handle->GetResponseHeaders()) { |
| 402 browse_info_->http_status_code = |
| 403 navigation_handle->GetResponseHeaders()->response_code(); |
| 404 } |
| 395 | 405 |
| 396 should_extract_malware_features_ = true; | 406 should_extract_malware_features_ = true; |
| 397 should_classify_for_malware_ = false; | 407 should_classify_for_malware_ = false; |
| 398 pageload_complete_ = false; | 408 pageload_complete_ = false; |
| 399 | 409 |
| 400 // Check whether we can cassify the current URL for phishing or malware. | 410 // Check whether we can cassify the current URL for phishing or malware. |
| 401 classification_request_ = new ShouldClassifyUrlRequest( | 411 classification_request_ = new ShouldClassifyUrlRequest( |
| 402 params, | 412 navigation_handle, |
| 403 base::Bind(&ClientSideDetectionHost::OnPhishingPreClassificationDone, | 413 base::Bind(&ClientSideDetectionHost::OnPhishingPreClassificationDone, |
| 404 weak_factory_.GetWeakPtr()), | 414 weak_factory_.GetWeakPtr()), |
| 405 base::Bind(&ClientSideDetectionHost::OnMalwarePreClassificationDone, | 415 base::Bind(&ClientSideDetectionHost::OnMalwarePreClassificationDone, |
| 406 weak_factory_.GetWeakPtr()), | 416 weak_factory_.GetWeakPtr()), |
| 407 web_contents(), csd_service_, database_manager_.get(), this); | 417 web_contents(), csd_service_, database_manager_.get(), this); |
| 408 classification_request_->Start(); | 418 classification_request_->Start(); |
| 409 } | 419 } |
| 410 | 420 |
| 411 void ClientSideDetectionHost::OnSafeBrowsingHit( | 421 void ClientSideDetectionHost::OnSafeBrowsingHit( |
| 412 const security_interstitials::UnsafeResource& resource) { | 422 const security_interstitials::UnsafeResource& resource) { |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 ui_manager_->RemoveObserver(this); | 725 ui_manager_->RemoveObserver(this); |
| 716 | 726 |
| 717 ui_manager_ = ui_manager; | 727 ui_manager_ = ui_manager; |
| 718 if (ui_manager) | 728 if (ui_manager) |
| 719 ui_manager_->AddObserver(this); | 729 ui_manager_->AddObserver(this); |
| 720 | 730 |
| 721 database_manager_ = database_manager; | 731 database_manager_ = database_manager; |
| 722 } | 732 } |
| 723 | 733 |
| 724 } // namespace safe_browsing | 734 } // namespace safe_browsing |
| OLD | NEW |