| 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/client_side_detection_host.h" | 5 #include "chrome/browser/safe_browsing/client_side_detection_host.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 IPC_END_MESSAGE_MAP() | 283 IPC_END_MESSAGE_MAP() |
| 284 return handled; | 284 return handled; |
| 285 } | 285 } |
| 286 | 286 |
| 287 void ClientSideDetectionHost::DidNavigateMainFramePostCommit( | 287 void ClientSideDetectionHost::DidNavigateMainFramePostCommit( |
| 288 const content::LoadCommittedDetails& details, | 288 const content::LoadCommittedDetails& details, |
| 289 const ViewHostMsg_FrameNavigate_Params& params) { | 289 const ViewHostMsg_FrameNavigate_Params& params) { |
| 290 // TODO(noelutz): move this DCHECK to TabContents and fix all the unit tests | 290 // TODO(noelutz): move this DCHECK to TabContents and fix all the unit tests |
| 291 // that don't call this method on the UI thread. | 291 // that don't call this method on the UI thread. |
| 292 // DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 292 // DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 293 | |
| 294 if (details.is_in_page) { | 293 if (details.is_in_page) { |
| 295 // If the navigation is within the same page, the user isn't really | 294 // If the navigation is within the same page, the user isn't really |
| 296 // navigating away. We don't need to cancel a pending callback or | 295 // navigating away. We don't need to cancel a pending callback or |
| 297 // begin a new classification. | 296 // begin a new classification. |
| 298 return; | 297 return; |
| 299 } | 298 } |
| 300 | |
| 301 // If we navigate away and there currently is a pending phishing | 299 // If we navigate away and there currently is a pending phishing |
| 302 // report request we have to cancel it to make sure we don't display | 300 // report request we have to cancel it to make sure we don't display |
| 303 // an interstitial for the wrong page. Note that this won't cancel | 301 // an interstitial for the wrong page. Note that this won't cancel |
| 304 // the server ping back but only cancel the showing of the | 302 // the server ping back but only cancel the showing of the |
| 305 // interstial. | 303 // interstial. |
| 306 cb_factory_.RevokeAll(); | 304 cb_factory_.RevokeAll(); |
| 307 | 305 |
| 308 if (csd_service_) { | 306 if (!csd_service_) { |
| 309 // Cancel any pending classification request. | 307 return; |
| 310 if (classification_request_.get()) { | 308 } |
| 311 classification_request_->Cancel(); | |
| 312 } | |
| 313 | 309 |
| 314 // Notify the renderer if it should classify this URL. | 310 // Cancel any pending classification request. |
| 315 classification_request_ = new ShouldClassifyUrlRequest(params, | 311 if (classification_request_.get()) { |
| 316 tab_contents(), | 312 classification_request_->Cancel(); |
| 317 csd_service_, | |
| 318 sb_service_, | |
| 319 this); | |
| 320 classification_request_->Start(); | |
| 321 } | 313 } |
| 314 browse_info_.reset(new BrowseInfo); |
| 315 browse_info_->url = params.url; |
| 316 browse_info_->referrer = params.referrer; |
| 317 browse_info_->transition = params.transition; |
| 318 |
| 319 // Notify the renderer if it should classify this URL. |
| 320 classification_request_ = new ShouldClassifyUrlRequest(params, |
| 321 tab_contents(), |
| 322 csd_service_, |
| 323 sb_service_, |
| 324 this); |
| 325 classification_request_->Start(); |
| 322 } | 326 } |
| 323 | 327 |
| 324 void ClientSideDetectionHost::TabContentsDestroyed(TabContents* tab) { | 328 void ClientSideDetectionHost::TabContentsDestroyed(TabContents* tab) { |
| 325 DCHECK(tab); | 329 DCHECK(tab); |
| 326 // Tell any pending classification request that it is being canceled. | 330 // Tell any pending classification request that it is being canceled. |
| 327 if (classification_request_.get()) { | 331 if (classification_request_.get()) { |
| 328 classification_request_->Cancel(); | 332 classification_request_->Cancel(); |
| 329 } | 333 } |
| 330 // Cancel all pending feature extractions. | 334 // Cancel all pending feature extractions. |
| 331 feature_extractor_.reset(); | 335 feature_extractor_.reset(); |
| 332 } | 336 } |
| 333 | 337 |
| 334 void ClientSideDetectionHost::OnDetectedPhishingSite( | 338 void ClientSideDetectionHost::OnDetectedPhishingSite( |
| 335 const std::string& verdict_str) { | 339 const std::string& verdict_str) { |
| 336 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 340 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 337 // There is something seriously wrong if there is no service class but | 341 // There is something seriously wrong if there is no service class but |
| 338 // this method is called. The renderer should not start phishing detection | 342 // this method is called. The renderer should not start phishing detection |
| 339 // if there isn't any service class in the browser. | 343 // if there isn't any service class in the browser. |
| 340 DCHECK(csd_service_); | 344 DCHECK(csd_service_); |
| 345 // There shouldn't be any pending requests because we revoke them everytime |
| 346 // we navigate away. |
| 347 DCHECK(!cb_factory_.HasPendingCallbacks()); |
| 348 DCHECK(browse_info_.get()); |
| 349 |
| 341 // We parse the protocol buffer here. If we're unable to parse it we won't | 350 // We parse the protocol buffer here. If we're unable to parse it we won't |
| 342 // send the verdict further. | 351 // send the verdict further. |
| 343 scoped_ptr<ClientPhishingRequest> verdict(new ClientPhishingRequest); | 352 scoped_ptr<ClientPhishingRequest> verdict(new ClientPhishingRequest); |
| 344 if (csd_service_ && | 353 if (csd_service_ && |
| 354 !cb_factory_.HasPendingCallbacks() && |
| 355 browse_info_.get() && |
| 345 verdict->ParseFromString(verdict_str) && | 356 verdict->ParseFromString(verdict_str) && |
| 346 verdict->IsInitialized()) { | 357 verdict->IsInitialized()) { |
| 347 // There shouldn't be any pending requests because we revoke them everytime | 358 if (browse_info_->url.spec() != verdict->url()) { |
| 348 // we navigate away. | 359 // I'm not sure we can DCHECK on this one so we keep stats around to see |
| 349 DCHECK(!cb_factory_.HasPendingCallbacks()); | 360 // whether this actually happens in practice. |
| 350 | 361 UMA_HISTOGRAM_COUNTS("SBClientPhishing.BrowserRendererUrlMismatch", 1); |
| 362 VLOG(2) << "Browser and renderer URL do not match: " |
| 363 << browse_info_->url.spec() << " vs. " << verdict->url(); |
| 364 } |
| 351 // Start browser-side feature extraction. Once we're done it will send | 365 // Start browser-side feature extraction. Once we're done it will send |
| 352 // the client verdict request. | 366 // the client verdict request. |
| 353 feature_extractor_->ExtractFeatures( | 367 feature_extractor_->ExtractFeatures( |
| 368 *browse_info_, |
| 354 verdict.release(), | 369 verdict.release(), |
| 355 NewCallback(this, &ClientSideDetectionHost::FeatureExtractionDone)); | 370 NewCallback(this, &ClientSideDetectionHost::FeatureExtractionDone)); |
| 356 } | 371 } |
| 372 browse_info_.reset(); |
| 357 } | 373 } |
| 358 | 374 |
| 359 void ClientSideDetectionHost::MaybeShowPhishingWarning(GURL phishing_url, | 375 void ClientSideDetectionHost::MaybeShowPhishingWarning(GURL phishing_url, |
| 360 bool is_phishing) { | 376 bool is_phishing) { |
| 361 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 377 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 362 VLOG(2) << "Received server phishing verdict for URL:" << phishing_url | 378 VLOG(2) << "Received server phishing verdict for URL:" << phishing_url |
| 363 << " is_phishing:" << is_phishing; | 379 << " is_phishing:" << is_phishing; |
| 364 if (is_phishing) { | 380 if (is_phishing) { |
| 365 DCHECK(tab_contents()); | 381 DCHECK(tab_contents()); |
| 366 if (sb_service_) { | 382 if (sb_service_) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 ClientSideDetectionService* service) { | 420 ClientSideDetectionService* service) { |
| 405 csd_service_ = service; | 421 csd_service_ = service; |
| 406 } | 422 } |
| 407 | 423 |
| 408 void ClientSideDetectionHost::set_safe_browsing_service( | 424 void ClientSideDetectionHost::set_safe_browsing_service( |
| 409 SafeBrowsingService* service) { | 425 SafeBrowsingService* service) { |
| 410 sb_service_ = service; | 426 sb_service_ = service; |
| 411 } | 427 } |
| 412 | 428 |
| 413 } // namespace safe_browsing | 429 } // namespace safe_browsing |
| OLD | NEW |