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 #ifndef CHROME_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_HOST_H_ | 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_HOST_H_ |
6 #define CHROME_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_HOST_H_ | 6 #define CHROME_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_HOST_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_callback_factory.h" | 11 #include "base/memory/scoped_callback_factory.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" | 13 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" |
14 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 14 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 15 #include "content/browser/tab_contents/navigation_controller.h" |
15 #include "content/browser/tab_contents/tab_contents_observer.h" | 16 #include "content/browser/tab_contents/tab_contents_observer.h" |
16 #include "content/common/notification_registrar.h" | 17 #include "content/common/notification_registrar.h" |
17 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
18 | 19 |
19 class NotificationDetails; | 20 class NotificationDetails; |
20 class NotificationSource; | 21 class NotificationSource; |
21 class TabContents; | 22 class TabContents; |
22 | 23 |
23 namespace safe_browsing { | 24 namespace safe_browsing { |
24 class ClientPhishingRequest; | 25 class ClientPhishingRequest; |
25 class ClientSideDetectionService; | 26 class ClientSideDetectionService; |
26 | 27 |
27 // This class is used to receive the IPC from the renderer which | 28 // This class is used to receive the IPC from the renderer which |
28 // notifies the browser that a URL was classified as phishing. This | 29 // notifies the browser that a URL was classified as phishing. This |
29 // class relays this information to the client-side detection service | 30 // class relays this information to the client-side detection service |
30 // class which sends a ping to a server to validate the verdict. | 31 // class which sends a ping to a server to validate the verdict. |
31 // TODO(noelutz): move all client-side detection IPCs to this class. | 32 // TODO(noelutz): move all client-side detection IPCs to this class. |
32 class ClientSideDetectionHost : public TabContentsObserver, | 33 class ClientSideDetectionHost : public TabContentsObserver, |
33 public NotificationObserver { | 34 public NotificationObserver, |
| 35 public SafeBrowsingService::Observer { |
34 public: | 36 public: |
35 // The caller keeps ownership of the tab object and is responsible for | 37 // The caller keeps ownership of the tab object and is responsible for |
36 // ensuring that it stays valid until TabContentsDestroyed is called. | 38 // ensuring that it stays valid until TabContentsDestroyed is called. |
37 static ClientSideDetectionHost* Create(TabContents* tab); | 39 static ClientSideDetectionHost* Create(TabContents* tab); |
38 virtual ~ClientSideDetectionHost(); | 40 virtual ~ClientSideDetectionHost(); |
39 | 41 |
40 // From TabContentsObserver. | 42 // From TabContentsObserver. |
41 virtual bool OnMessageReceived(const IPC::Message& message); | 43 virtual bool OnMessageReceived(const IPC::Message& message); |
42 | 44 |
43 // From TabContentsObserver. If we navigate away we cancel all pending | 45 // From TabContentsObserver. If we navigate away we cancel all pending |
44 // callbacks that could show an interstitial, and check to see whether | 46 // callbacks that could show an interstitial, and check to see whether |
45 // we should classify the new URL. | 47 // we should classify the new URL. |
46 virtual void DidNavigateMainFramePostCommit( | 48 virtual void DidNavigateMainFramePostCommit( |
47 const content::LoadCommittedDetails& details, | 49 const content::LoadCommittedDetails& details, |
48 const ViewHostMsg_FrameNavigate_Params& params); | 50 const ViewHostMsg_FrameNavigate_Params& params); |
49 | 51 |
| 52 // Called when the SafeBrowsingService found a hit with one of the |
| 53 // SafeBrowsing lists. This method is called on the UI thread. |
| 54 virtual void OnSafeBrowsingHit( |
| 55 const SafeBrowsingService::UnsafeResource& resource); |
| 56 |
50 protected: | 57 protected: |
51 // From TabContentsObserver. Called when the TabContents is being destroyed. | 58 // From TabContentsObserver. Called when the TabContents is being destroyed. |
52 virtual void TabContentsDestroyed(TabContents* tab); | 59 virtual void TabContentsDestroyed(TabContents* tab); |
53 | 60 |
54 private: | 61 private: |
55 friend class ClientSideDetectionHostTest; | 62 friend class ClientSideDetectionHostTest; |
56 class ShouldClassifyUrlRequest; | 63 class ShouldClassifyUrlRequest; |
57 friend class ShouldClassifyUrlRequest; | 64 friend class ShouldClassifyUrlRequest; |
58 | 65 |
59 explicit ClientSideDetectionHost(TabContents* tab); | 66 explicit ClientSideDetectionHost(TabContents* tab); |
60 | 67 |
61 // Verdict is an encoded ClientPhishingRequest protocol message. | 68 // Verdict is an encoded ClientPhishingRequest protocol message. |
62 void OnDetectedPhishingSite(const std::string& verdict); | 69 void OnPhishingDetectionDone(const std::string& verdict); |
63 | 70 |
64 // Callback that is called when the server ping back is | 71 // Callback that is called when the server ping back is |
65 // done. Display an interstitial if |is_phishing| is true. | 72 // done. Display an interstitial if |is_phishing| is true. |
66 // Otherwise, we do nothing. Called in UI thread. | 73 // Otherwise, we do nothing. Called in UI thread. |
67 void MaybeShowPhishingWarning(GURL phishing_url, bool is_phishing); | 74 void MaybeShowPhishingWarning(GURL phishing_url, bool is_phishing); |
68 | 75 |
69 // Callback that is called when the browser feature extractor is done. | 76 // Callback that is called when the browser feature extractor is done. |
70 // This method is responsible for deleting the request object. Called on | 77 // This method is responsible for deleting the request object. Called on |
71 // the UI thread. | 78 // the UI thread. |
72 void FeatureExtractionDone(bool success, ClientPhishingRequest* request); | 79 void FeatureExtractionDone(bool success, ClientPhishingRequest* request); |
73 | 80 |
74 // From NotificationObserver. Called when a notification comes in. This | 81 // From NotificationObserver. Called when a notification comes in. This |
75 // method is called in the UI thread. | 82 // method is called in the UI thread. |
76 virtual void Observe(int type, | 83 virtual void Observe(int type, |
77 const NotificationSource& source, | 84 const NotificationSource& source, |
78 const NotificationDetails& details); | 85 const NotificationDetails& details); |
79 | 86 |
| 87 // Returns true if the user has seen a regular SafeBrowsing |
| 88 // interstitial for the current page. This is only true if the user has |
| 89 // actually clicked through the warning. This method is called on the UI |
| 90 // thread. |
| 91 bool DidShowSBInterstitial(); |
| 92 |
80 // Used for testing. This function does not take ownership of the service | 93 // Used for testing. This function does not take ownership of the service |
81 // class. | 94 // class. |
82 void set_client_side_detection_service(ClientSideDetectionService* service); | 95 void set_client_side_detection_service(ClientSideDetectionService* service); |
83 | 96 |
84 // Used for testing. This function does not take ownership of the service | 97 // Used for testing. This function does not take ownership of the service |
85 // class. | 98 // class. |
86 void set_safe_browsing_service(SafeBrowsingService* service); | 99 void set_safe_browsing_service(SafeBrowsingService* service); |
87 | 100 |
88 // This pointer may be NULL if client-side phishing detection is disabled. | 101 // This pointer may be NULL if client-side phishing detection is disabled. |
89 ClientSideDetectionService* csd_service_; | 102 ClientSideDetectionService* csd_service_; |
90 // This pointer may be NULL if SafeBrowsing is disabled. | 103 // This pointer may be NULL if SafeBrowsing is disabled. |
91 scoped_refptr<SafeBrowsingService> sb_service_; | 104 scoped_refptr<SafeBrowsingService> sb_service_; |
92 // Keep a handle to the latest classification request so that we can cancel | 105 // Keep a handle to the latest classification request so that we can cancel |
93 // it if necessary. | 106 // it if necessary. |
94 scoped_refptr<ShouldClassifyUrlRequest> classification_request_; | 107 scoped_refptr<ShouldClassifyUrlRequest> classification_request_; |
95 // Browser-side feature extractor. | 108 // Browser-side feature extractor. |
96 scoped_ptr<BrowserFeatureExtractor> feature_extractor_; | 109 scoped_ptr<BrowserFeatureExtractor> feature_extractor_; |
97 // Keeps some info about the current page visit while the renderer | 110 // Keeps some info about the current page visit while the renderer |
98 // classification is going on. Since we cancel classification on | 111 // classification is going on. Since we cancel classification on |
99 // every page load we can simply keep this data around as a member | 112 // every page load we can simply keep this data around as a member |
100 // variable. This information will be passed on to the feature extractor. | 113 // variable. This information will be passed on to the feature extractor. |
101 scoped_ptr<BrowseInfo> browse_info_; | 114 scoped_ptr<BrowseInfo> browse_info_; |
102 // Handles registering notifications with the NotificationService. | 115 // Handles registering notifications with the NotificationService. |
103 NotificationRegistrar registrar_; | 116 NotificationRegistrar registrar_; |
104 | 117 |
105 base::ScopedCallbackFactory<ClientSideDetectionHost> cb_factory_; | 118 base::ScopedCallbackFactory<ClientSideDetectionHost> cb_factory_; |
106 | 119 |
| 120 // Unique page ID of the most recent unsafe site that was loaded in this tab. |
| 121 int unsafe_unique_page_id_; |
| 122 |
107 DISALLOW_COPY_AND_ASSIGN(ClientSideDetectionHost); | 123 DISALLOW_COPY_AND_ASSIGN(ClientSideDetectionHost); |
108 }; | 124 }; |
109 | 125 |
110 } // namespace safe_browsing | 126 } // namespace safe_browsing |
111 | 127 |
112 #endif // CHROME_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_HOST_H_ | 128 #endif // CHROME_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_HOST_H_ |
OLD | NEW |