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