| 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" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/task.h" | 13 #include "base/task.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" | |
| 17 #include "chrome/browser/safe_browsing/client_side_detection_service.h" | 16 #include "chrome/browser/safe_browsing/client_side_detection_service.h" |
| 18 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 17 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 19 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 20 #include "chrome/common/safe_browsing/csd.pb.h" | 19 #include "chrome/common/safe_browsing/csd.pb.h" |
| 21 #include "chrome/common/safe_browsing/safebrowsing_messages.h" | 20 #include "chrome/common/safe_browsing/safebrowsing_messages.h" |
| 22 #include "content/browser/browser_thread.h" | 21 #include "content/browser/browser_thread.h" |
| 23 #include "content/browser/renderer_host/render_process_host.h" | 22 #include "content/browser/renderer_host/render_process_host.h" |
| 24 #include "content/browser/renderer_host/render_view_host.h" | 23 #include "content/browser/renderer_host/render_view_host.h" |
| 25 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 24 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
| 26 #include "content/browser/tab_contents/navigation_details.h" | 25 #include "content/browser/tab_contents/navigation_details.h" |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 | 257 |
| 259 // static | 258 // static |
| 260 ClientSideDetectionHost* ClientSideDetectionHost::Create( | 259 ClientSideDetectionHost* ClientSideDetectionHost::Create( |
| 261 TabContents* tab) { | 260 TabContents* tab) { |
| 262 return new ClientSideDetectionHost(tab); | 261 return new ClientSideDetectionHost(tab); |
| 263 } | 262 } |
| 264 | 263 |
| 265 ClientSideDetectionHost::ClientSideDetectionHost(TabContents* tab) | 264 ClientSideDetectionHost::ClientSideDetectionHost(TabContents* tab) |
| 266 : TabContentsObserver(tab), | 265 : TabContentsObserver(tab), |
| 267 csd_service_(g_browser_process->safe_browsing_detection_service()), | 266 csd_service_(g_browser_process->safe_browsing_detection_service()), |
| 268 feature_extractor_(new BrowserFeatureExtractor(tab)), | |
| 269 cb_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 267 cb_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 270 DCHECK(tab); | 268 DCHECK(tab); |
| 271 // Note: csd_service_ and sb_service_ might be NULL. | 269 // Note: csd_service_ and sb_service_ might be NULL. |
| 272 sb_service_ = g_browser_process->safe_browsing_service(); | 270 sb_service_ = g_browser_process->safe_browsing_service(); |
| 273 } | 271 } |
| 274 | 272 |
| 275 ClientSideDetectionHost::~ClientSideDetectionHost() { | 273 ClientSideDetectionHost::~ClientSideDetectionHost() { |
| 276 // Tell any pending classification request that it is being canceled. | 274 // Tell any pending classification request that it is being canceled. |
| 277 if (classification_request_.get()) { | 275 if (classification_request_.get()) { |
| 278 classification_request_->Cancel(); | 276 classification_request_->Cancel(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 DCHECK(csd_service_); | 333 DCHECK(csd_service_); |
| 336 // We parse the protocol buffer here. If we're unable to parse it we won't | 334 // We parse the protocol buffer here. If we're unable to parse it we won't |
| 337 // send the verdict further. | 335 // send the verdict further. |
| 338 scoped_ptr<ClientPhishingRequest> verdict(new ClientPhishingRequest); | 336 scoped_ptr<ClientPhishingRequest> verdict(new ClientPhishingRequest); |
| 339 if (csd_service_ && | 337 if (csd_service_ && |
| 340 verdict->ParseFromString(verdict_str) && | 338 verdict->ParseFromString(verdict_str) && |
| 341 verdict->IsInitialized()) { | 339 verdict->IsInitialized()) { |
| 342 // There shouldn't be any pending requests because we revoke them everytime | 340 // There shouldn't be any pending requests because we revoke them everytime |
| 343 // we navigate away. | 341 // we navigate away. |
| 344 DCHECK(!cb_factory_.HasPendingCallbacks()); | 342 DCHECK(!cb_factory_.HasPendingCallbacks()); |
| 345 | 343 VLOG(2) << "Start sending client phishing request for URL: " |
| 346 // Start browser-side feature extraction. Once we're done it will send | 344 << verdict->url(); |
| 347 // the client verdict request. | 345 csd_service_->SendClientReportPhishingRequest( |
| 348 feature_extractor_->ExtractFeatures( | 346 verdict.release(), // The service takes ownership of the verdict. |
| 349 verdict.release(), | 347 cb_factory_.NewCallback( |
| 350 NewCallback(this, &ClientSideDetectionHost::FeatureExtractionDone)); | 348 &ClientSideDetectionHost::MaybeShowPhishingWarning)); |
| 351 } | 349 } |
| 352 } | 350 } |
| 353 | 351 |
| 354 void ClientSideDetectionHost::MaybeShowPhishingWarning(GURL phishing_url, | 352 void ClientSideDetectionHost::MaybeShowPhishingWarning(GURL phishing_url, |
| 355 bool is_phishing) { | 353 bool is_phishing) { |
| 356 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 354 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 357 VLOG(2) << "Received server phishing verdict for URL:" << phishing_url | 355 VLOG(2) << "Received server phishing verdict for URL:" << phishing_url |
| 358 << " is_phishing:" << is_phishing; | 356 << " is_phishing:" << is_phishing; |
| 359 if (is_phishing) { | 357 if (is_phishing) { |
| 360 DCHECK(tab_contents()); | 358 DCHECK(tab_contents()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 372 // We need to stop any pending navigations, otherwise the interstital | 370 // We need to stop any pending navigations, otherwise the interstital |
| 373 // might not get created properly. | 371 // might not get created properly. |
| 374 tab_contents()->controller().DiscardNonCommittedEntries(); | 372 tab_contents()->controller().DiscardNonCommittedEntries(); |
| 375 resource.client = new CsdClient(); // Will delete itself | 373 resource.client = new CsdClient(); // Will delete itself |
| 376 sb_service_->DoDisplayBlockingPage(resource); | 374 sb_service_->DoDisplayBlockingPage(resource); |
| 377 } | 375 } |
| 378 } | 376 } |
| 379 } | 377 } |
| 380 } | 378 } |
| 381 | 379 |
| 382 void ClientSideDetectionHost::FeatureExtractionDone( | |
| 383 bool success, | |
| 384 ClientPhishingRequest* request) { | |
| 385 if (!request) { | |
| 386 DLOG(FATAL) << "Invalid request object in FeatureExtractionDone"; | |
| 387 return; | |
| 388 } | |
| 389 VLOG(2) << "Feature extraction done (success:" << success << ") for URL: " | |
| 390 << request->url() << ". Start sending client phishing request."; | |
| 391 // Send ping no matter what - even if the browser feature extraction failed. | |
| 392 csd_service_->SendClientReportPhishingRequest( | |
| 393 request, // The service takes ownership of the request object. | |
| 394 cb_factory_.NewCallback( | |
| 395 &ClientSideDetectionHost::MaybeShowPhishingWarning)); | |
| 396 } | |
| 397 | |
| 398 void ClientSideDetectionHost::set_client_side_detection_service( | 380 void ClientSideDetectionHost::set_client_side_detection_service( |
| 399 ClientSideDetectionService* service) { | 381 ClientSideDetectionService* service) { |
| 400 csd_service_ = service; | 382 csd_service_ = service; |
| 401 } | 383 } |
| 402 | 384 |
| 403 void ClientSideDetectionHost::set_safe_browsing_service( | 385 void ClientSideDetectionHost::set_safe_browsing_service( |
| 404 SafeBrowsingService* service) { | 386 SafeBrowsingService* service) { |
| 405 sb_service_ = service; | 387 sb_service_ = service; |
| 406 } | 388 } |
| 407 | 389 |
| 408 } // namespace safe_browsing | 390 } // namespace safe_browsing |
| OLD | NEW |