| 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/safe_browsing_service.h" | 13 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 14 #include "content/browser/tab_contents/tab_contents_observer.h" | 14 #include "content/browser/tab_contents/tab_contents_observer.h" |
| 15 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 16 | 16 |
| 17 class TabContents; | 17 class TabContents; |
| 18 | 18 |
| 19 namespace safe_browsing { | 19 namespace safe_browsing { |
| 20 | 20 class BrowserFeatureExtractor; |
| 21 class ClientPhishingRequest; |
| 21 class ClientSideDetectionService; | 22 class ClientSideDetectionService; |
| 22 | 23 |
| 23 // This class is used to receive the IPC from the renderer which | 24 // This class is used to receive the IPC from the renderer which |
| 24 // notifies the browser that a URL was classified as phishing. This | 25 // notifies the browser that a URL was classified as phishing. This |
| 25 // class relays this information to the client-side detection service | 26 // class relays this information to the client-side detection service |
| 26 // class which sends a ping to a server to validate the verdict. | 27 // class which sends a ping to a server to validate the verdict. |
| 27 // TODO(noelutz): move all client-side detection IPCs to this class. | 28 // TODO(noelutz): move all client-side detection IPCs to this class. |
| 28 class ClientSideDetectionHost : public TabContentsObserver { | 29 class ClientSideDetectionHost : public TabContentsObserver { |
| 29 public: | 30 public: |
| 30 // The caller keeps ownership of the tab object and is responsible for | 31 // The caller keeps ownership of the tab object and is responsible for |
| 31 // ensuring that it stays valid for the entire lifetime of this object. | 32 // ensuring that it stays valid until TabContentsDestroyed is called. |
| 32 static ClientSideDetectionHost* Create(TabContents* tab); | 33 static ClientSideDetectionHost* Create(TabContents* tab); |
| 33 virtual ~ClientSideDetectionHost(); | 34 virtual ~ClientSideDetectionHost(); |
| 34 | 35 |
| 35 // From TabContentsObserver. | 36 // From TabContentsObserver. |
| 36 virtual bool OnMessageReceived(const IPC::Message& message); | 37 virtual bool OnMessageReceived(const IPC::Message& message); |
| 37 | 38 |
| 38 // From TabContentsObserver. If we navigate away we cancel all pending | 39 // From TabContentsObserver. If we navigate away we cancel all pending |
| 39 // callbacks that could show an interstitial, and check to see whether | 40 // callbacks that could show an interstitial, and check to see whether |
| 40 // we should classify the new URL. | 41 // we should classify the new URL. |
| 41 virtual void DidNavigateMainFramePostCommit( | 42 virtual void DidNavigateMainFramePostCommit( |
| 42 const content::LoadCommittedDetails& details, | 43 const content::LoadCommittedDetails& details, |
| 43 const ViewHostMsg_FrameNavigate_Params& params); | 44 const ViewHostMsg_FrameNavigate_Params& params); |
| 44 | 45 |
| 46 protected: |
| 47 // From TabContentsObserver. Called when the TabContents is being destroyed. |
| 48 virtual void TabContentsDestroyed(TabContents* tab); |
| 49 |
| 45 private: | 50 private: |
| 46 friend class ClientSideDetectionHostTest; | 51 friend class ClientSideDetectionHostTest; |
| 47 class ShouldClassifyUrlRequest; | 52 class ShouldClassifyUrlRequest; |
| 48 friend class ShouldClassifyUrlRequest; | 53 friend class ShouldClassifyUrlRequest; |
| 49 | 54 |
| 50 explicit ClientSideDetectionHost(TabContents* tab); | 55 explicit ClientSideDetectionHost(TabContents* tab); |
| 51 | 56 |
| 52 // Verdict is an encoded ClientPhishingRequest protocol message. | 57 // Verdict is an encoded ClientPhishingRequest protocol message. |
| 53 void OnDetectedPhishingSite(const std::string& verdict); | 58 void OnDetectedPhishingSite(const std::string& verdict); |
| 54 | 59 |
| 55 // Callback that is called when the server ping back is | 60 // Callback that is called when the server ping back is |
| 56 // done. Display an interstitial if |is_phishing| is true. | 61 // done. Display an interstitial if |is_phishing| is true. |
| 57 // Otherwise, we do nothing. Called in UI thread. | 62 // Otherwise, we do nothing. Called in UI thread. |
| 58 void MaybeShowPhishingWarning(GURL phishing_url, bool is_phishing); | 63 void MaybeShowPhishingWarning(GURL phishing_url, bool is_phishing); |
| 59 | 64 |
| 65 // Callback that is called when the browser feature extractor is done. |
| 66 // This method is responsible for deleting the request object. Called on |
| 67 // the UI thread. |
| 68 void FeatureExtractionDone(bool success, ClientPhishingRequest* request); |
| 69 |
| 60 // Used for testing. This function does not take ownership of the service | 70 // Used for testing. This function does not take ownership of the service |
| 61 // class. | 71 // class. |
| 62 void set_client_side_detection_service(ClientSideDetectionService* service); | 72 void set_client_side_detection_service(ClientSideDetectionService* service); |
| 63 | 73 |
| 64 // Used for testing. This function does not take ownership of the service | 74 // Used for testing. This function does not take ownership of the service |
| 65 // class. | 75 // class. |
| 66 void set_safe_browsing_service(SafeBrowsingService* service); | 76 void set_safe_browsing_service(SafeBrowsingService* service); |
| 67 | 77 |
| 68 // This pointer may be NULL if client-side phishing detection is disabled. | 78 // This pointer may be NULL if client-side phishing detection is disabled. |
| 69 ClientSideDetectionService* csd_service_; | 79 ClientSideDetectionService* csd_service_; |
| 70 // This pointer may be NULL if SafeBrowsing is disabled. | 80 // This pointer may be NULL if SafeBrowsing is disabled. |
| 71 scoped_refptr<SafeBrowsingService> sb_service_; | 81 scoped_refptr<SafeBrowsingService> sb_service_; |
| 72 // Keep a handle to the latest classification request so that we can cancel | 82 // Keep a handle to the latest classification request so that we can cancel |
| 73 // it if necessary. | 83 // it if necessary. |
| 74 scoped_refptr<ShouldClassifyUrlRequest> classification_request_; | 84 scoped_refptr<ShouldClassifyUrlRequest> classification_request_; |
| 85 // Browser-side feature extractor. |
| 86 scoped_ptr<BrowserFeatureExtractor> feature_extractor_; |
| 75 | 87 |
| 76 base::ScopedCallbackFactory<ClientSideDetectionHost> cb_factory_; | 88 base::ScopedCallbackFactory<ClientSideDetectionHost> cb_factory_; |
| 77 | 89 |
| 78 DISALLOW_COPY_AND_ASSIGN(ClientSideDetectionHost); | 90 DISALLOW_COPY_AND_ASSIGN(ClientSideDetectionHost); |
| 79 }; | 91 }; |
| 80 | 92 |
| 81 } // namespace safe_browsing | 93 } // namespace safe_browsing |
| 82 | 94 |
| 83 #endif // CHROME_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_HOST_H_ | 95 #endif // CHROME_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_HOST_H_ |
| OLD | NEW |