OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_HOST_H_ |
| 6 #define CHROME_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_HOST_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/basictypes.h" |
| 10 #include "base/ref_counted.h" |
| 11 #include "base/scoped_callback_factory.h" |
| 12 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 13 #include "chrome/browser/tab_contents/tab_contents_observer.h" |
| 14 #include "googleurl/src/gurl.h" |
| 15 |
| 16 class TabContents; |
| 17 |
| 18 namespace safe_browsing { |
| 19 |
| 20 class ClientSideDetectionService; |
| 21 |
| 22 // This class is used to receive the IPC from the renderer which |
| 23 // notifies the browser that a URL was classified as phishing. This |
| 24 // class relays this information to the client-side detection service |
| 25 // class which sends a ping to a server to validate the verdict. |
| 26 // TODO(noelutz): move all client-side detection IPCs to this class. |
| 27 class ClientSideDetectionHost : public TabContentsObserver { |
| 28 public: |
| 29 // The caller keeps ownership of the tab object and is responsible for |
| 30 // ensuring that it stays valid for the entire lifetime of this object. |
| 31 explicit ClientSideDetectionHost(TabContents* tab); |
| 32 virtual ~ClientSideDetectionHost(); |
| 33 |
| 34 // From TabContentsObserver. |
| 35 virtual bool OnMessageReceived(const IPC::Message& message); |
| 36 |
| 37 // From TabContentsObserver. If we navigate away we cancel all pending |
| 38 // callbacks that could show an interstitial. |
| 39 virtual void DidNavigateMainFramePostCommit( |
| 40 const NavigationController::LoadCommittedDetails& details, |
| 41 const ViewHostMsg_FrameNavigate_Params& params); |
| 42 |
| 43 private: |
| 44 friend class ClientSideDetectionHostTest; |
| 45 |
| 46 void OnDetectedPhishingSite(const GURL& phishing_url, double phishing_score); |
| 47 |
| 48 // Callback that is called when the server ping back is |
| 49 // done. Display an interstitial if |is_phishing| is true. |
| 50 // Otherwise, we do nothgin. Called in UI thread. |
| 51 void MaybeShowPhishingWarning(GURL phishing_url, bool is_phishing); |
| 52 |
| 53 // Used for testing. This function does not take ownership of the service |
| 54 // class. |
| 55 void set_client_side_detection_service(ClientSideDetectionService* service); |
| 56 |
| 57 // Used for testing. This function does not take ownership of the service |
| 58 // class. |
| 59 void set_safe_browsing_service(SafeBrowsingService* service); |
| 60 |
| 61 // This pointer may be NULL if client-side phishing detection is disabled. |
| 62 ClientSideDetectionService* service_; |
| 63 // This pointer may be NULL if SafeBrowsing is disabled. |
| 64 scoped_refptr<SafeBrowsingService> sb_service_; |
| 65 |
| 66 base::ScopedCallbackFactory<ClientSideDetectionHost> cb_factory_; |
| 67 |
| 68 DISALLOW_COPY_AND_ASSIGN(ClientSideDetectionHost); |
| 69 }; |
| 70 |
| 71 } // namespace safe_browsing |
| 72 |
| 73 #endif // CHROME_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_HOST_H_ |
OLD | NEW |