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/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" | 17 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" |
18 #include "chrome/browser/safe_browsing/client_side_detection_service.h" | 18 #include "chrome/browser/safe_browsing/client_side_detection_service.h" |
19 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 19 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
20 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
21 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
22 #include "chrome/common/safe_browsing/csd.pb.h" | 22 #include "chrome/common/safe_browsing/csd.pb.h" |
23 #include "chrome/common/safe_browsing/safebrowsing_messages.h" | 23 #include "chrome/common/safe_browsing/safebrowsing_messages.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/view_messages.h" | |
31 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
32 #include "content/public/browser/notification_details.h" | 31 #include "content/public/browser/notification_details.h" |
33 #include "content/public/browser/notification_source.h" | 32 #include "content/public/browser/notification_source.h" |
34 #include "content/public/browser/notification_types.h" | 33 #include "content/public/browser/notification_types.h" |
35 #include "content/public/browser/render_process_host.h" | 34 #include "content/public/browser/render_process_host.h" |
| 35 #include "content/public/common/frame_navigate_params.h" |
36 #include "googleurl/src/gurl.h" | 36 #include "googleurl/src/gurl.h" |
37 | 37 |
38 using content::BrowserThread; | 38 using content::BrowserThread; |
39 | 39 |
40 namespace safe_browsing { | 40 namespace safe_browsing { |
41 | 41 |
42 // This class is instantiated each time a new toplevel URL loads, and | 42 // This class is instantiated each time a new toplevel URL loads, and |
43 // asynchronously checks whether the phishing classifier should run for this | 43 // asynchronously checks whether the phishing classifier should run for this |
44 // URL. If so, it notifies the renderer with a StartPhishingDetection IPC. | 44 // URL. If so, it notifies the renderer with a StartPhishingDetection IPC. |
45 // Objects of this class are ref-counted and will be destroyed once nobody | 45 // Objects of this class are ref-counted and will be destroyed once nobody |
46 // uses it anymore. If |tab_contents|, |csd_service| or |host| go away you need | 46 // uses it anymore. If |tab_contents|, |csd_service| or |host| go away you need |
47 // to call Cancel(). We keep the |sb_service| alive in a ref pointer for as | 47 // to call Cancel(). We keep the |sb_service| alive in a ref pointer for as |
48 // long as it takes. | 48 // long as it takes. |
49 class ClientSideDetectionHost::ShouldClassifyUrlRequest | 49 class ClientSideDetectionHost::ShouldClassifyUrlRequest |
50 : public base::RefCountedThreadSafe< | 50 : public base::RefCountedThreadSafe< |
51 ClientSideDetectionHost::ShouldClassifyUrlRequest> { | 51 ClientSideDetectionHost::ShouldClassifyUrlRequest> { |
52 public: | 52 public: |
53 ShouldClassifyUrlRequest(const ViewHostMsg_FrameNavigate_Params& params, | 53 ShouldClassifyUrlRequest(const content::FrameNavigateParams& params, |
54 TabContents* tab_contents, | 54 TabContents* tab_contents, |
55 ClientSideDetectionService* csd_service, | 55 ClientSideDetectionService* csd_service, |
56 SafeBrowsingService* sb_service, | 56 SafeBrowsingService* sb_service, |
57 ClientSideDetectionHost* host) | 57 ClientSideDetectionHost* host) |
58 : canceled_(false), | 58 : canceled_(false), |
59 params_(params), | 59 params_(params), |
60 tab_contents_(tab_contents), | 60 tab_contents_(tab_contents), |
61 csd_service_(csd_service), | 61 csd_service_(csd_service), |
62 sb_service_(sb_service), | 62 sb_service_(sb_service), |
63 host_(host) { | 63 host_(host) { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 VLOG(1) << "Instruct renderer to start phishing detection for URL: " | 207 VLOG(1) << "Instruct renderer to start phishing detection for URL: " |
208 << params_.url; | 208 << params_.url; |
209 RenderViewHost* rvh = tab_contents_->render_view_host(); | 209 RenderViewHost* rvh = tab_contents_->render_view_host(); |
210 rvh->Send(new SafeBrowsingMsg_StartPhishingDetection( | 210 rvh->Send(new SafeBrowsingMsg_StartPhishingDetection( |
211 rvh->routing_id(), params_.url)); | 211 rvh->routing_id(), params_.url)); |
212 } | 212 } |
213 | 213 |
214 // No need to protect |canceled_| with a lock because it is only read and | 214 // No need to protect |canceled_| with a lock because it is only read and |
215 // written by the UI thread. | 215 // written by the UI thread. |
216 bool canceled_; | 216 bool canceled_; |
217 ViewHostMsg_FrameNavigate_Params params_; | 217 content::FrameNavigateParams params_; |
218 TabContents* tab_contents_; | 218 TabContents* tab_contents_; |
219 ClientSideDetectionService* csd_service_; | 219 ClientSideDetectionService* csd_service_; |
220 // We keep a ref pointer here just to make sure the service class stays alive | 220 // We keep a ref pointer here just to make sure the service class stays alive |
221 // long enough. | 221 // long enough. |
222 scoped_refptr<SafeBrowsingService> sb_service_; | 222 scoped_refptr<SafeBrowsingService> sb_service_; |
223 ClientSideDetectionHost* host_; | 223 ClientSideDetectionHost* host_; |
224 | 224 |
225 DISALLOW_COPY_AND_ASSIGN(ShouldClassifyUrlRequest); | 225 DISALLOW_COPY_AND_ASSIGN(ShouldClassifyUrlRequest); |
226 }; | 226 }; |
227 | 227 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 IPC_BEGIN_MESSAGE_MAP(ClientSideDetectionHost, message) | 285 IPC_BEGIN_MESSAGE_MAP(ClientSideDetectionHost, message) |
286 IPC_MESSAGE_HANDLER(SafeBrowsingHostMsg_PhishingDetectionDone, | 286 IPC_MESSAGE_HANDLER(SafeBrowsingHostMsg_PhishingDetectionDone, |
287 OnPhishingDetectionDone) | 287 OnPhishingDetectionDone) |
288 IPC_MESSAGE_UNHANDLED(handled = false) | 288 IPC_MESSAGE_UNHANDLED(handled = false) |
289 IPC_END_MESSAGE_MAP() | 289 IPC_END_MESSAGE_MAP() |
290 return handled; | 290 return handled; |
291 } | 291 } |
292 | 292 |
293 void ClientSideDetectionHost::DidNavigateMainFrame( | 293 void ClientSideDetectionHost::DidNavigateMainFrame( |
294 const content::LoadCommittedDetails& details, | 294 const content::LoadCommittedDetails& details, |
295 const ViewHostMsg_FrameNavigate_Params& params) { | 295 const content::FrameNavigateParams& params) { |
296 // TODO(noelutz): move this DCHECK to TabContents and fix all the unit tests | 296 // TODO(noelutz): move this DCHECK to TabContents and fix all the unit tests |
297 // that don't call this method on the UI thread. | 297 // that don't call this method on the UI thread. |
298 // DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 298 // DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
299 if (details.is_in_page) { | 299 if (details.is_in_page) { |
300 // If the navigation is within the same page, the user isn't really | 300 // If the navigation is within the same page, the user isn't really |
301 // navigating away. We don't need to cancel a pending callback or | 301 // navigating away. We don't need to cancel a pending callback or |
302 // begin a new classification. | 302 // begin a new classification. |
303 return; | 303 return; |
304 } | 304 } |
305 // If we navigate away and there currently is a pending phishing | 305 // If we navigate away and there currently is a pending phishing |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 if (sb_service_) { | 489 if (sb_service_) { |
490 sb_service_->RemoveObserver(this); | 490 sb_service_->RemoveObserver(this); |
491 } | 491 } |
492 sb_service_ = service; | 492 sb_service_ = service; |
493 if (sb_service_) { | 493 if (sb_service_) { |
494 sb_service_->AddObserver(this); | 494 sb_service_->AddObserver(this); |
495 } | 495 } |
496 } | 496 } |
497 | 497 |
498 } // namespace safe_browsing | 498 } // namespace safe_browsing |
OLD | NEW |