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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 NO_CLASSIFY_UNSUPPORTED_MIME_TYPE, | 154 NO_CLASSIFY_UNSUPPORTED_MIME_TYPE, |
155 | 155 |
156 NO_CLASSIFY_MAX // Always add new values before this one. | 156 NO_CLASSIFY_MAX // Always add new values before this one. |
157 }; | 157 }; |
158 | 158 |
159 // The destructor can be called either from the UI or the IO thread. | 159 // The destructor can be called either from the UI or the IO thread. |
160 virtual ~ShouldClassifyUrlRequest() { } | 160 virtual ~ShouldClassifyUrlRequest() { } |
161 | 161 |
162 void CheckCsdWhitelist(const GURL& url) { | 162 void CheckCsdWhitelist(const GURL& url) { |
163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
164 if (!sb_service_ || sb_service_->MatchCsdWhitelistUrl(url)) { | 164 if (!sb_service_.get() || sb_service_->MatchCsdWhitelistUrl(url)) { |
165 // We're done. There is no point in going back to the UI thread. | 165 // We're done. There is no point in going back to the UI thread. |
166 VLOG(1) << "Skipping phishing classification for URL: " << url | 166 VLOG(1) << "Skipping phishing classification for URL: " << url |
167 << " because it matches the csd whitelist"; | 167 << " because it matches the csd whitelist"; |
168 UMA_HISTOGRAM_ENUMERATION("SBClientPhishing.PreClassificationCheckFail", | 168 UMA_HISTOGRAM_ENUMERATION("SBClientPhishing.PreClassificationCheckFail", |
169 NO_CLASSIFY_MATCH_CSD_WHITELIST, | 169 NO_CLASSIFY_MATCH_CSD_WHITELIST, |
170 NO_CLASSIFY_MAX); | 170 NO_CLASSIFY_MAX); |
171 return; | 171 return; |
172 } | 172 } |
173 | 173 |
174 BrowserThread::PostTask( | 174 BrowserThread::PostTask( |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 csd_service_(NULL), | 245 csd_service_(NULL), |
246 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 246 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
247 unsafe_unique_page_id_(-1) { | 247 unsafe_unique_page_id_(-1) { |
248 DCHECK(tab); | 248 DCHECK(tab); |
249 csd_service_ = g_browser_process->safe_browsing_detection_service(); | 249 csd_service_ = g_browser_process->safe_browsing_detection_service(); |
250 feature_extractor_.reset(new BrowserFeatureExtractor(tab, csd_service_)); | 250 feature_extractor_.reset(new BrowserFeatureExtractor(tab, csd_service_)); |
251 sb_service_ = g_browser_process->safe_browsing_service(); | 251 sb_service_ = g_browser_process->safe_browsing_service(); |
252 // Note: csd_service_ and sb_service_ will be NULL here in testing. | 252 // Note: csd_service_ and sb_service_ will be NULL here in testing. |
253 registrar_.Add(this, content::NOTIFICATION_RESOURCE_RESPONSE_STARTED, | 253 registrar_.Add(this, content::NOTIFICATION_RESOURCE_RESPONSE_STARTED, |
254 content::Source<WebContents>(tab)); | 254 content::Source<WebContents>(tab)); |
255 if (sb_service_) { | 255 if (sb_service_.get()) { |
256 sb_service_->AddObserver(this); | 256 sb_service_->AddObserver(this); |
257 } | 257 } |
258 } | 258 } |
259 | 259 |
260 ClientSideDetectionHost::~ClientSideDetectionHost() { | 260 ClientSideDetectionHost::~ClientSideDetectionHost() { |
261 if (sb_service_) { | 261 if (sb_service_.get()) { |
262 sb_service_->RemoveObserver(this); | 262 sb_service_->RemoveObserver(this); |
263 } | 263 } |
264 } | 264 } |
265 | 265 |
266 bool ClientSideDetectionHost::OnMessageReceived(const IPC::Message& message) { | 266 bool ClientSideDetectionHost::OnMessageReceived(const IPC::Message& message) { |
267 bool handled = true; | 267 bool handled = true; |
268 IPC_BEGIN_MESSAGE_MAP(ClientSideDetectionHost, message) | 268 IPC_BEGIN_MESSAGE_MAP(ClientSideDetectionHost, message) |
269 IPC_MESSAGE_HANDLER(SafeBrowsingHostMsg_PhishingDetectionDone, | 269 IPC_MESSAGE_HANDLER(SafeBrowsingHostMsg_PhishingDetectionDone, |
270 OnPhishingDetectionDone) | 270 OnPhishingDetectionDone) |
271 IPC_MESSAGE_UNHANDLED(handled = false) | 271 IPC_MESSAGE_UNHANDLED(handled = false) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 cur_host_redirects_ = params.redirects; | 308 cur_host_redirects_ = params.redirects; |
309 } | 309 } |
310 browse_info_->host_redirects = cur_host_redirects_; | 310 browse_info_->host_redirects = cur_host_redirects_; |
311 browse_info_->url_redirects = params.redirects; | 311 browse_info_->url_redirects = params.redirects; |
312 browse_info_->http_status_code = details.http_status_code; | 312 browse_info_->http_status_code = details.http_status_code; |
313 | 313 |
314 // Notify the renderer if it should classify this URL. | 314 // Notify the renderer if it should classify this URL. |
315 classification_request_ = new ShouldClassifyUrlRequest(params, | 315 classification_request_ = new ShouldClassifyUrlRequest(params, |
316 web_contents(), | 316 web_contents(), |
317 csd_service_, | 317 csd_service_, |
318 sb_service_, | 318 sb_service_.get(), |
319 this); | 319 this); |
320 classification_request_->Start(); | 320 classification_request_->Start(); |
321 } | 321 } |
322 | 322 |
323 void ClientSideDetectionHost::OnSafeBrowsingHit( | 323 void ClientSideDetectionHost::OnSafeBrowsingHit( |
324 const SafeBrowsingService::UnsafeResource& resource) { | 324 const SafeBrowsingService::UnsafeResource& resource) { |
325 // Check that this notification is really for us and that it corresponds to | 325 // Check that this notification is really for us and that it corresponds to |
326 // either a malware or phishing hit. In this case we store the unique page | 326 // either a malware or phishing hit. In this case we store the unique page |
327 // ID for later. | 327 // ID for later. |
328 if (web_contents() && | 328 if (web_contents() && |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 browse_info_.reset(); | 391 browse_info_.reset(); |
392 } | 392 } |
393 | 393 |
394 void ClientSideDetectionHost::MaybeShowPhishingWarning(GURL phishing_url, | 394 void ClientSideDetectionHost::MaybeShowPhishingWarning(GURL phishing_url, |
395 bool is_phishing) { | 395 bool is_phishing) { |
396 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 396 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
397 VLOG(2) << "Received server phishing verdict for URL:" << phishing_url | 397 VLOG(2) << "Received server phishing verdict for URL:" << phishing_url |
398 << " is_phishing:" << is_phishing; | 398 << " is_phishing:" << is_phishing; |
399 if (is_phishing) { | 399 if (is_phishing) { |
400 DCHECK(web_contents()); | 400 DCHECK(web_contents()); |
401 if (sb_service_) { | 401 if (sb_service_.get()) { |
402 SafeBrowsingService::UnsafeResource resource; | 402 SafeBrowsingService::UnsafeResource resource; |
403 resource.url = phishing_url; | 403 resource.url = phishing_url; |
404 resource.original_url = phishing_url; | 404 resource.original_url = phishing_url; |
405 resource.is_subresource = false; | 405 resource.is_subresource = false; |
406 resource.threat_type = SafeBrowsingService::CLIENT_SIDE_PHISHING_URL; | 406 resource.threat_type = SafeBrowsingService::CLIENT_SIDE_PHISHING_URL; |
407 resource.render_process_host_id = | 407 resource.render_process_host_id = |
408 web_contents()->GetRenderProcessHost()->GetID(); | 408 web_contents()->GetRenderProcessHost()->GetID(); |
409 resource.render_view_id = | 409 resource.render_view_id = |
410 web_contents()->GetRenderViewHost()->GetRoutingID(); | 410 web_contents()->GetRenderViewHost()->GetRoutingID(); |
411 if (!sb_service_->IsWhitelisted(resource)) { | 411 if (!sb_service_->IsWhitelisted(resource)) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 return (nav_entry && nav_entry->GetUniqueID() == unsafe_unique_page_id_); | 463 return (nav_entry && nav_entry->GetUniqueID() == unsafe_unique_page_id_); |
464 } | 464 } |
465 | 465 |
466 void ClientSideDetectionHost::set_client_side_detection_service( | 466 void ClientSideDetectionHost::set_client_side_detection_service( |
467 ClientSideDetectionService* service) { | 467 ClientSideDetectionService* service) { |
468 csd_service_ = service; | 468 csd_service_ = service; |
469 } | 469 } |
470 | 470 |
471 void ClientSideDetectionHost::set_safe_browsing_service( | 471 void ClientSideDetectionHost::set_safe_browsing_service( |
472 SafeBrowsingService* service) { | 472 SafeBrowsingService* service) { |
473 if (sb_service_) { | 473 if (sb_service_.get()) { |
474 sb_service_->RemoveObserver(this); | 474 sb_service_->RemoveObserver(this); |
475 } | 475 } |
476 sb_service_ = service; | 476 sb_service_ = service; |
477 if (sb_service_) { | 477 if (sb_service_.get()) { |
478 sb_service_->AddObserver(this); | 478 sb_service_->AddObserver(this); |
479 } | 479 } |
480 } | 480 } |
481 | 481 |
482 } // namespace safe_browsing | 482 } // namespace safe_browsing |
OLD | NEW |