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

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

Issue 42553002: Mostly integrate new malware IP blacklist with the csd client. When (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove inline accessor Created 7 years, 1 month 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 | Annotate | Revision Log
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 <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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 243
244 DISALLOW_COPY_AND_ASSIGN(ShouldClassifyUrlRequest); 244 DISALLOW_COPY_AND_ASSIGN(ShouldClassifyUrlRequest);
245 }; 245 };
246 246
247 // static 247 // static
248 ClientSideDetectionHost* ClientSideDetectionHost::Create( 248 ClientSideDetectionHost* ClientSideDetectionHost::Create(
249 WebContents* tab) { 249 WebContents* tab) {
250 return new ClientSideDetectionHost(tab); 250 return new ClientSideDetectionHost(tab);
251 } 251 }
252 252
253 ClientSideDetectionHost::ClientSideDetectionHost(
254 SafeBrowsingDatabaseManager* database_manager)
255 : content::WebContentsObserver(),
256 database_manager_(database_manager),
257 weak_factory_(this) { }
mattm 2013/10/29 01:11:47 It looks like this constructor doesn't initialize
noé 2013/10/31 02:41:12 Done.
258
253 ClientSideDetectionHost::ClientSideDetectionHost(WebContents* tab) 259 ClientSideDetectionHost::ClientSideDetectionHost(WebContents* tab)
254 : content::WebContentsObserver(tab), 260 : content::WebContentsObserver(tab),
255 csd_service_(NULL), 261 csd_service_(NULL),
256 weak_factory_(this), 262 weak_factory_(this),
257 unsafe_unique_page_id_(-1), 263 unsafe_unique_page_id_(-1),
258 malware_killswitch_on_(false), 264 malware_killswitch_on_(false),
259 malware_report_enabled_(false) { 265 malware_report_enabled_(false) {
260 DCHECK(tab); 266 DCHECK(tab);
261 // Note: csd_service_ and sb_service will be NULL here in testing. 267 // Note: csd_service_ and sb_service will be NULL here in testing.
262 csd_service_ = g_browser_process->safe_browsing_detection_service(); 268 csd_service_ = g_browser_process->safe_browsing_detection_service();
263 feature_extractor_.reset(new BrowserFeatureExtractor(tab, csd_service_)); 269 feature_extractor_.reset(new BrowserFeatureExtractor(tab, this));
264 registrar_.Add(this, content::NOTIFICATION_RESOURCE_RESPONSE_STARTED, 270 registrar_.Add(this, content::NOTIFICATION_RESOURCE_RESPONSE_STARTED,
265 content::Source<WebContents>(tab)); 271 content::Source<WebContents>(tab));
266 272
267 scoped_refptr<SafeBrowsingService> sb_service = 273 scoped_refptr<SafeBrowsingService> sb_service =
268 g_browser_process->safe_browsing_service(); 274 g_browser_process->safe_browsing_service();
269 if (sb_service.get()) { 275 if (sb_service.get()) {
270 ui_manager_ = sb_service->ui_manager(); 276 ui_manager_ = sb_service->ui_manager();
271 database_manager_ = sb_service->database_manager(); 277 database_manager_ = sb_service->database_manager();
272 ui_manager_->AddObserver(this); 278 ui_manager_->AddObserver(this);
273 } 279 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 web_contents()->GetController().GetActiveEntry()) { 360 web_contents()->GetController().GetActiveEntry()) {
355 unsafe_unique_page_id_ = 361 unsafe_unique_page_id_ =
356 web_contents()->GetController().GetActiveEntry()->GetUniqueID(); 362 web_contents()->GetController().GetActiveEntry()->GetUniqueID();
357 // We also keep the resource around in order to be able to send the 363 // We also keep the resource around in order to be able to send the
358 // malicious URL to the server. 364 // malicious URL to the server.
359 unsafe_resource_.reset(new SafeBrowsingUIManager::UnsafeResource(resource)); 365 unsafe_resource_.reset(new SafeBrowsingUIManager::UnsafeResource(resource));
360 unsafe_resource_->callback.Reset(); // Don't do anything stupid. 366 unsafe_resource_->callback.Reset(); // Don't do anything stupid.
361 } 367 }
362 } 368 }
363 369
370 scoped_refptr<SafeBrowsingDatabaseManager>
371 ClientSideDetectionHost::database_manager() {
372 return database_manager_;
373 }
374
364 void ClientSideDetectionHost::WebContentsDestroyed(WebContents* tab) { 375 void ClientSideDetectionHost::WebContentsDestroyed(WebContents* tab) {
365 DCHECK(tab); 376 DCHECK(tab);
366 // Tell any pending classification request that it is being canceled. 377 // Tell any pending classification request that it is being canceled.
367 if (classification_request_.get()) { 378 if (classification_request_.get()) {
368 classification_request_->Cancel(); 379 classification_request_->Cancel();
369 } 380 }
370 // Cancel all pending feature extractions. 381 // Cancel all pending feature extractions.
371 feature_extractor_.reset(); 382 feature_extractor_.reset();
372 } 383 }
373 384
(...skipping 18 matching lines...) Expand all
392 verdict->ParseFromString(verdict_str) && 403 verdict->ParseFromString(verdict_str) &&
393 verdict->IsInitialized()) { 404 verdict->IsInitialized()) {
394 // We do the malware IP matching and request sending if the feature 405 // We do the malware IP matching and request sending if the feature
395 // is enabled. 406 // is enabled.
396 if (malware_report_enabled_ && !MalwareKillSwitchIsOn()) { 407 if (malware_report_enabled_ && !MalwareKillSwitchIsOn()) {
397 scoped_ptr<ClientMalwareRequest> malware_verdict( 408 scoped_ptr<ClientMalwareRequest> malware_verdict(
398 new ClientMalwareRequest); 409 new ClientMalwareRequest);
399 // Start browser-side malware feature extraction. Once we're done it will 410 // Start browser-side malware feature extraction. Once we're done it will
400 // send the malware client verdict request. 411 // send the malware client verdict request.
401 malware_verdict->set_url(verdict->url()); 412 malware_verdict->set_url(verdict->url());
413 // This function doesn't expect browse_info_ to stay around after this
414 // function returns.
402 feature_extractor_->ExtractMalwareFeatures( 415 feature_extractor_->ExtractMalwareFeatures(
403 browse_info_.get(), malware_verdict.get()); 416 browse_info_.get(),
404 MalwareFeatureExtractionDone(malware_verdict.Pass()); 417 malware_verdict.release(),
418 base::Bind(&ClientSideDetectionHost::MalwareFeatureExtractionDone,
419 weak_factory_.GetWeakPtr()));
405 } 420 }
406 421
407 // We only send phishing verdict to the server if the verdict is phishing or 422 // We only send phishing verdict to the server if the verdict is phishing or
408 // if a SafeBrowsing interstitial was already shown for this site. E.g., a 423 // if a SafeBrowsing interstitial was already shown for this site. E.g., a
409 // malware or phishing interstitial was shown but the user clicked 424 // malware or phishing interstitial was shown but the user clicked
410 // through. 425 // through.
411 if (verdict->is_phishing() || DidShowSBInterstitial()) { 426 if (verdict->is_phishing() || DidShowSBInterstitial()) {
412 if (DidShowSBInterstitial()) { 427 if (DidShowSBInterstitial()) {
413 browse_info_->unsafe_resource.reset(unsafe_resource_.release()); 428 browse_info_->unsafe_resource.reset(unsafe_resource_.release());
414 } 429 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 } 498 }
484 // If there is true malware verdict, invalidate weakptr so that no longer 499 // If there is true malware verdict, invalidate weakptr so that no longer
485 // consider the phishing vedict. 500 // consider the phishing vedict.
486 weak_factory_.InvalidateWeakPtrs(); 501 weak_factory_.InvalidateWeakPtrs();
487 } 502 }
488 } 503 }
489 504
490 void ClientSideDetectionHost::FeatureExtractionDone( 505 void ClientSideDetectionHost::FeatureExtractionDone(
491 bool success, 506 bool success,
492 ClientPhishingRequest* request) { 507 ClientPhishingRequest* request) {
493 if (!request) { 508 DCHECK(request);
494 DLOG(FATAL) << "Invalid request object in FeatureExtractionDone";
495 return;
496 }
497 VLOG(2) << "Feature extraction done (success:" << success << ") for URL: " 509 VLOG(2) << "Feature extraction done (success:" << success << ") for URL: "
498 << request->url() << ". Start sending client phishing request."; 510 << request->url() << ". Start sending client phishing request.";
499 ClientSideDetectionService::ClientReportPhishingRequestCallback callback; 511 ClientSideDetectionService::ClientReportPhishingRequestCallback callback;
500 // If the client-side verdict isn't phishing we don't care about the server 512 // If the client-side verdict isn't phishing we don't care about the server
501 // response because we aren't going to display a warning. 513 // response because we aren't going to display a warning.
502 if (request->is_phishing()) { 514 if (request->is_phishing()) {
503 callback = base::Bind(&ClientSideDetectionHost::MaybeShowPhishingWarning, 515 callback = base::Bind(&ClientSideDetectionHost::MaybeShowPhishingWarning,
504 weak_factory_.GetWeakPtr()); 516 weak_factory_.GetWeakPtr());
505 } 517 }
506 // Send ping even if the browser feature extraction failed. 518 // Send ping even if the browser feature extraction failed.
507 csd_service_->SendClientReportPhishingRequest( 519 csd_service_->SendClientReportPhishingRequest(
508 request, // The service takes ownership of the request object. 520 request, // The service takes ownership of the request object.
509 callback); 521 callback);
510 } 522 }
511 523
512 void ClientSideDetectionHost::MalwareFeatureExtractionDone( 524 void ClientSideDetectionHost::MalwareFeatureExtractionDone(
525 bool feature_extraction_success,
513 scoped_ptr<ClientMalwareRequest> request) { 526 scoped_ptr<ClientMalwareRequest> request) {
514 if (!request) { 527 DCHECK(request.get());
515 DLOG(FATAL) << "Invalid request object in MalwareFeatureExtractionDone";
516 return;
517 }
518 VLOG(2) << "Malware Feature extraction done for URL: " << request->url() 528 VLOG(2) << "Malware Feature extraction done for URL: " << request->url()
519 << ", with features count:" << request->feature_map_size(); 529 << ", with features count:" << request->feature_map_size();
520 530
521 // Send ping if there is matching features. 531 // Send ping if there is matching features.
522 if (request->feature_map_size() > 0) { 532 if (feature_extraction_success && request->feature_map_size() > 0) {
523 VLOG(1) << "Start sending client malware request."; 533 VLOG(1) << "Start sending client malware request.";
524 ClientSideDetectionService::ClientReportMalwareRequestCallback callback; 534 ClientSideDetectionService::ClientReportMalwareRequestCallback callback;
525 callback = base::Bind(&ClientSideDetectionHost::MaybeShowMalwareWarning, 535 callback = base::Bind(&ClientSideDetectionHost::MaybeShowMalwareWarning,
526 weak_factory_.GetWeakPtr()); 536 weak_factory_.GetWeakPtr());
527 csd_service_->SendClientReportMalwareRequest( 537 csd_service_->SendClientReportMalwareRequest(request.release(), callback);
528 request.release(), // The service takes ownership of the request object
529 callback);
530 } 538 }
531 } 539 }
532 540
533 void ClientSideDetectionHost::UpdateIPUrlMap(const std::string& ip, 541 void ClientSideDetectionHost::UpdateIPUrlMap(const std::string& ip,
534 const std::string& url) { 542 const std::string& url) {
535 if (ip.empty() || url.empty()) 543 if (ip.empty() || url.empty())
536 return; 544 return;
537 545
538 IPUrlMap::iterator it = browse_info_->ips.find(ip); 546 IPUrlMap::iterator it = browse_info_->ips.find(ip);
539 if (it == browse_info_->ips.end()) { 547 if (it == browse_info_->ips.end()) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 603 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
596 return malware_killswitch_on_; 604 return malware_killswitch_on_;
597 } 605 }
598 606
599 void ClientSideDetectionHost::SetMalwareKillSwitch(bool killswitch_on) { 607 void ClientSideDetectionHost::SetMalwareKillSwitch(bool killswitch_on) {
600 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 608 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
601 malware_killswitch_on_ = killswitch_on; 609 malware_killswitch_on_ = killswitch_on;
602 } 610 }
603 611
604 } // namespace safe_browsing 612 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698