| 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 <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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 database_manager_->MatchCsdWhitelistUrl(url)) { | 170 database_manager_->MatchCsdWhitelistUrl(url)) { |
| 171 // We're done. There is no point in going back to the UI thread. | 171 // We're done. There is no point in going back to the UI thread. |
| 172 VLOG(1) << "Skipping phishing classification for URL: " << url | 172 VLOG(1) << "Skipping phishing classification for URL: " << url |
| 173 << " because it matches the csd whitelist"; | 173 << " because it matches the csd whitelist"; |
| 174 UMA_HISTOGRAM_ENUMERATION("SBClientPhishing.PreClassificationCheckFail", | 174 UMA_HISTOGRAM_ENUMERATION("SBClientPhishing.PreClassificationCheckFail", |
| 175 NO_CLASSIFY_MATCH_CSD_WHITELIST, | 175 NO_CLASSIFY_MATCH_CSD_WHITELIST, |
| 176 NO_CLASSIFY_MAX); | 176 NO_CLASSIFY_MAX); |
| 177 return; | 177 return; |
| 178 } | 178 } |
| 179 | 179 |
| 180 host_->malware_killswitch_on_ = database_manager_->MalwareKillSwitchOn(); | |
| 181 | |
| 182 BrowserThread::PostTask( | 180 BrowserThread::PostTask( |
| 183 BrowserThread::UI, | 181 BrowserThread::UI, |
| 184 FROM_HERE, | 182 FROM_HERE, |
| 185 base::Bind(&ShouldClassifyUrlRequest::CheckCache, this)); | 183 base::Bind(&ShouldClassifyUrlRequest::CheckCache, this)); |
| 186 } | 184 } |
| 187 | 185 |
| 188 void CheckCache() { | 186 void CheckCache() { |
| 189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 187 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 190 if (canceled_) { | 188 if (canceled_) { |
| 191 return; | 189 return; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 ClientSideDetectionHost* ClientSideDetectionHost::Create( | 244 ClientSideDetectionHost* ClientSideDetectionHost::Create( |
| 247 WebContents* tab) { | 245 WebContents* tab) { |
| 248 return new ClientSideDetectionHost(tab); | 246 return new ClientSideDetectionHost(tab); |
| 249 } | 247 } |
| 250 | 248 |
| 251 ClientSideDetectionHost::ClientSideDetectionHost(WebContents* tab) | 249 ClientSideDetectionHost::ClientSideDetectionHost(WebContents* tab) |
| 252 : content::WebContentsObserver(tab), | 250 : content::WebContentsObserver(tab), |
| 253 csd_service_(NULL), | 251 csd_service_(NULL), |
| 254 weak_factory_(this), | 252 weak_factory_(this), |
| 255 unsafe_unique_page_id_(-1), | 253 unsafe_unique_page_id_(-1), |
| 256 malware_killswitch_on_(false), | |
| 257 malware_report_enabled_(false) { | 254 malware_report_enabled_(false) { |
| 258 DCHECK(tab); | 255 DCHECK(tab); |
| 259 // Note: csd_service_ and sb_service will be NULL here in testing. | 256 // Note: csd_service_ and sb_service will be NULL here in testing. |
| 260 csd_service_ = g_browser_process->safe_browsing_detection_service(); | 257 csd_service_ = g_browser_process->safe_browsing_detection_service(); |
| 261 feature_extractor_.reset(new BrowserFeatureExtractor(tab, csd_service_)); | 258 feature_extractor_.reset(new BrowserFeatureExtractor(tab, csd_service_)); |
| 262 registrar_.Add(this, content::NOTIFICATION_RESOURCE_RESPONSE_STARTED, | 259 registrar_.Add(this, content::NOTIFICATION_RESOURCE_RESPONSE_STARTED, |
| 263 content::Source<WebContents>(tab)); | 260 content::Source<WebContents>(tab)); |
| 264 | 261 |
| 265 scoped_refptr<SafeBrowsingService> sb_service = | 262 scoped_refptr<SafeBrowsingService> sb_service = |
| 266 g_browser_process->safe_browsing_service(); | 263 g_browser_process->safe_browsing_service(); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 DCHECK(browse_info_.get()); | 379 DCHECK(browse_info_.get()); |
| 383 | 380 |
| 384 // We parse the protocol buffer here. If we're unable to parse it we won't | 381 // We parse the protocol buffer here. If we're unable to parse it we won't |
| 385 // send the verdict further. | 382 // send the verdict further. |
| 386 scoped_ptr<ClientPhishingRequest> verdict(new ClientPhishingRequest); | 383 scoped_ptr<ClientPhishingRequest> verdict(new ClientPhishingRequest); |
| 387 if (csd_service_ && | 384 if (csd_service_ && |
| 388 !weak_factory_.HasWeakPtrs() && | 385 !weak_factory_.HasWeakPtrs() && |
| 389 browse_info_.get() && | 386 browse_info_.get() && |
| 390 verdict->ParseFromString(verdict_str) && | 387 verdict->ParseFromString(verdict_str) && |
| 391 verdict->IsInitialized()) { | 388 verdict->IsInitialized()) { |
| 392 // We do the malware IP matching and request sending if the feature | 389 if (malware_report_enabled_) { |
| 393 // is enabled | |
| 394 if (malware_report_enabled_ && !malware_killswitch_on_) { | |
| 395 scoped_ptr<ClientMalwareRequest> malware_verdict( | 390 scoped_ptr<ClientMalwareRequest> malware_verdict( |
| 396 new ClientMalwareRequest); | 391 new ClientMalwareRequest); |
| 397 // Start browser-side malware feature extraction. Once we're done it will | 392 // Start browser-side malware feature extraction. Once we're done it will |
| 398 // send the malware client verdict request. | 393 // send the malware client verdict request. |
| 399 malware_verdict->set_url(verdict->url()); | 394 malware_verdict->set_url(verdict->url()); |
| 400 feature_extractor_->ExtractMalwareFeatures( | 395 feature_extractor_->ExtractMalwareFeatures( |
| 401 browse_info_.get(), malware_verdict.get()); | 396 browse_info_.get(), |
| 397 malware_verdict.get()); |
| 402 MalwareFeatureExtractionDone(malware_verdict.Pass()); | 398 MalwareFeatureExtractionDone(malware_verdict.Pass()); |
| 403 } | 399 } |
| 404 | 400 |
| 405 // We only send phishing verdict to the server if the verdict is phishing or | 401 // We only send phishing verdict to the server if the verdict is phishing or |
| 406 // if a SafeBrowsing interstitial was already shown for this site. E.g., a | 402 // if a SafeBrowsing interstitial was already shown for this site. E.g., a |
| 407 // malware or phishing interstitial was shown but the user clicked | 403 // malware or phishing interstitial was shown but the user clicked |
| 408 // through. | 404 // through. |
| 409 if (verdict->is_phishing() || DidShowSBInterstitial()) { | 405 if (verdict->is_phishing() || DidShowSBInterstitial()) { |
| 410 if (DidShowSBInterstitial()) { | 406 if (DidShowSBInterstitial()) { |
| 411 browse_info_->unsafe_resource.reset(unsafe_resource_.release()); | 407 browse_info_->unsafe_resource.reset(unsafe_resource_.release()); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 ui_manager_->RemoveObserver(this); | 539 ui_manager_->RemoveObserver(this); |
| 544 | 540 |
| 545 ui_manager_ = ui_manager; | 541 ui_manager_ = ui_manager; |
| 546 if (ui_manager) | 542 if (ui_manager) |
| 547 ui_manager_->AddObserver(this); | 543 ui_manager_->AddObserver(this); |
| 548 | 544 |
| 549 database_manager_ = database_manager; | 545 database_manager_ = database_manager; |
| 550 } | 546 } |
| 551 | 547 |
| 552 } // namespace safe_browsing | 548 } // namespace safe_browsing |
| OLD | NEW |