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/browser_feature_extractor.h" |
17 #include "chrome/browser/safe_browsing/client_side_detection_service.h" | 17 #include "chrome/browser/safe_browsing/client_side_detection_service.h" |
18 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 18 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
19 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
20 #include "chrome/common/safe_browsing/csd.pb.h" | 20 #include "chrome/common/safe_browsing/csd.pb.h" |
21 #include "chrome/common/safe_browsing/safebrowsing_messages.h" | 21 #include "chrome/common/safe_browsing/safebrowsing_messages.h" |
22 #include "content/browser/browser_thread.h" | 22 #include "content/browser/browser_thread.h" |
23 #include "content/browser/renderer_host/render_process_host.h" | 23 #include "content/browser/renderer_host/render_process_host.h" |
24 #include "content/browser/renderer_host/render_view_host.h" | 24 #include "content/browser/renderer_host/render_view_host.h" |
25 #include "content/browser/renderer_host/render_view_host_delegate.h" | 25 #include "content/browser/renderer_host/render_view_host_delegate.h" |
26 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 26 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
27 #include "content/browser/renderer_host/resource_request_details.h" | 27 #include "content/browser/renderer_host/resource_request_details.h" |
28 #include "content/browser/tab_contents/navigation_details.h" | 28 #include "content/browser/tab_contents/navigation_details.h" |
29 #include "content/browser/tab_contents/tab_contents.h" | 29 #include "content/browser/tab_contents/tab_contents.h" |
| 30 #include "content/common/content_notification_types.h" |
30 #include "content/common/notification_service.h" | 31 #include "content/common/notification_service.h" |
31 #include "content/common/notification_type.h" | |
32 #include "content/common/view_messages.h" | 32 #include "content/common/view_messages.h" |
33 #include "googleurl/src/gurl.h" | 33 #include "googleurl/src/gurl.h" |
34 | 34 |
35 namespace safe_browsing { | 35 namespace safe_browsing { |
36 | 36 |
37 // This class is instantiated each time a new toplevel URL loads, and | 37 // This class is instantiated each time a new toplevel URL loads, and |
38 // asynchronously checks whether the phishing classifier should run for this | 38 // asynchronously checks whether the phishing classifier should run for this |
39 // URL. If so, it notifies the renderer with a StartPhishingDetection IPC. | 39 // URL. If so, it notifies the renderer with a StartPhishingDetection IPC. |
40 // Objects of this class are ref-counted and will be destroyed once nobody | 40 // Objects of this class are ref-counted and will be destroyed once nobody |
41 // uses it anymore. If |tab_contents|, |csd_service| or |host| go away you need | 41 // uses it anymore. If |tab_contents|, |csd_service| or |host| go away you need |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 : TabContentsObserver(tab), | 268 : TabContentsObserver(tab), |
269 csd_service_(g_browser_process->safe_browsing_detection_service()), | 269 csd_service_(g_browser_process->safe_browsing_detection_service()), |
270 feature_extractor_( | 270 feature_extractor_( |
271 new BrowserFeatureExtractor( | 271 new BrowserFeatureExtractor( |
272 tab, | 272 tab, |
273 g_browser_process->safe_browsing_detection_service())), | 273 g_browser_process->safe_browsing_detection_service())), |
274 cb_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 274 cb_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
275 DCHECK(tab); | 275 DCHECK(tab); |
276 // Note: csd_service_ and sb_service_ might be NULL. | 276 // Note: csd_service_ and sb_service_ might be NULL. |
277 sb_service_ = g_browser_process->safe_browsing_service(); | 277 sb_service_ = g_browser_process->safe_browsing_service(); |
278 registrar_.Add(this, NotificationType::RESOURCE_RESPONSE_STARTED, | 278 registrar_.Add(this, content::NOTIFICATION_RESOURCE_RESPONSE_STARTED, |
279 Source<RenderViewHostDelegate>(tab)); | 279 Source<RenderViewHostDelegate>(tab)); |
280 } | 280 } |
281 | 281 |
282 ClientSideDetectionHost::~ClientSideDetectionHost() {} | 282 ClientSideDetectionHost::~ClientSideDetectionHost() {} |
283 | 283 |
284 bool ClientSideDetectionHost::OnMessageReceived(const IPC::Message& message) { | 284 bool ClientSideDetectionHost::OnMessageReceived(const IPC::Message& message) { |
285 bool handled = true; | 285 bool handled = true; |
286 IPC_BEGIN_MESSAGE_MAP(ClientSideDetectionHost, message) | 286 IPC_BEGIN_MESSAGE_MAP(ClientSideDetectionHost, message) |
287 IPC_MESSAGE_HANDLER(SafeBrowsingHostMsg_DetectedPhishingSite, | 287 IPC_MESSAGE_HANDLER(SafeBrowsingHostMsg_DetectedPhishingSite, |
288 OnDetectedPhishingSite) | 288 OnDetectedPhishingSite) |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 } | 416 } |
417 VLOG(2) << "Feature extraction done (success:" << success << ") for URL: " | 417 VLOG(2) << "Feature extraction done (success:" << success << ") for URL: " |
418 << request->url() << ". Start sending client phishing request."; | 418 << request->url() << ". Start sending client phishing request."; |
419 // Send ping no matter what - even if the browser feature extraction failed. | 419 // Send ping no matter what - even if the browser feature extraction failed. |
420 csd_service_->SendClientReportPhishingRequest( | 420 csd_service_->SendClientReportPhishingRequest( |
421 request, // The service takes ownership of the request object. | 421 request, // The service takes ownership of the request object. |
422 cb_factory_.NewCallback( | 422 cb_factory_.NewCallback( |
423 &ClientSideDetectionHost::MaybeShowPhishingWarning)); | 423 &ClientSideDetectionHost::MaybeShowPhishingWarning)); |
424 } | 424 } |
425 | 425 |
426 void ClientSideDetectionHost::Observe(NotificationType type, | 426 void ClientSideDetectionHost::Observe(int type, |
427 const NotificationSource& source, | 427 const NotificationSource& source, |
428 const NotificationDetails& details) { | 428 const NotificationDetails& details) { |
429 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 429 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
430 DCHECK_EQ(type.value, NotificationType::RESOURCE_RESPONSE_STARTED); | 430 DCHECK_EQ(type, content::NOTIFICATION_RESOURCE_RESPONSE_STARTED); |
431 const ResourceRequestDetails* req = Details<ResourceRequestDetails>( | 431 const ResourceRequestDetails* req = Details<ResourceRequestDetails>( |
432 details).ptr(); | 432 details).ptr(); |
433 if (req && browse_info_.get()) { | 433 if (req && browse_info_.get()) { |
434 browse_info_->ips.insert(req->socket_address().host()); | 434 browse_info_->ips.insert(req->socket_address().host()); |
435 } | 435 } |
436 } | 436 } |
437 | 437 |
438 void ClientSideDetectionHost::set_client_side_detection_service( | 438 void ClientSideDetectionHost::set_client_side_detection_service( |
439 ClientSideDetectionService* service) { | 439 ClientSideDetectionService* service) { |
440 csd_service_ = service; | 440 csd_service_ = service; |
441 } | 441 } |
442 | 442 |
443 void ClientSideDetectionHost::set_safe_browsing_service( | 443 void ClientSideDetectionHost::set_safe_browsing_service( |
444 SafeBrowsingService* service) { | 444 SafeBrowsingService* service) { |
445 sb_service_ = service; | 445 sb_service_ = service; |
446 } | 446 } |
447 | 447 |
448 } // namespace safe_browsing | 448 } // namespace safe_browsing |
OLD | NEW |