OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // The Safe Browsing service is responsible for downloading anti-phishing and | 5 // The Safe Browsing service is responsible for downloading anti-phishing and |
6 // anti-malware tables and checking urls against them. | 6 // anti-malware tables and checking urls against them. |
7 | 7 |
8 #ifndef CHROME_BROWSER_SAFE_BROWSING_UI_MANAGER_H_ | 8 #ifndef CHROME_BROWSER_SAFE_BROWSING_UI_MANAGER_H_ |
9 #define CHROME_BROWSER_SAFE_BROWSING_UI_MANAGER_H_ | 9 #define CHROME_BROWSER_SAFE_BROWSING_UI_MANAGER_H_ |
10 | 10 |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/observer_list.h" | |
16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
17 #include "chrome/browser/permissions/permission_uma_util.h" | 18 #include "chrome/browser/permissions/permission_uma_util.h" |
18 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 19 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
19 #include "components/safe_browsing/base_ui_manager.h" | 20 #include "components/safe_browsing/base_ui_manager.h" |
20 | 21 |
21 class GURL; | 22 class GURL; |
22 | 23 |
23 namespace content { | 24 namespace content { |
24 class WebContents; | 25 class WebContents; |
25 struct PermissionReportInfo; | 26 struct PermissionReportInfo; |
26 } // namespace content | 27 } // namespace content |
27 | 28 |
29 namespace history { | |
30 class HistoryService; | |
31 } // namespace history | |
32 | |
28 namespace safe_browsing { | 33 namespace safe_browsing { |
29 | 34 |
30 struct HitReport; | 35 struct HitReport; |
31 | 36 |
32 // Construction needs to happen on the main thread. | 37 // Construction needs to happen on the main thread. |
33 class SafeBrowsingUIManager : public BaseSafeBrowsingUIManager { | 38 class SafeBrowsingUIManager : public BaseUIManager { |
34 public: | 39 public: |
40 // Observer class can be used to get notified when a SafeBrowsing hit | |
41 // was found. | |
meacer
2017/01/11 01:33:30
nit: was -> is
Jialiu Lin
2017/01/11 02:53:15
Done.
| |
42 class Observer { | |
43 public: | |
44 // The |resource| was classified as unsafe by SafeBrowsing, and is | |
45 // not whitelisted. | |
meacer
2017/01/11 01:33:30
nit: maybe say "Called when |resource| is classifi
Jialiu Lin
2017/01/11 02:53:15
Done.
| |
46 // The |resource| must not be accessed after OnSafeBrowsingHit returns. | |
47 // This method will be called on the UI thread. | |
48 virtual void OnSafeBrowsingHit(const UnsafeResource& resource) = 0; | |
49 | |
50 protected: | |
51 Observer() {} | |
52 virtual ~Observer() {} | |
53 | |
54 private: | |
55 DISALLOW_COPY_AND_ASSIGN(Observer); | |
56 }; | |
57 | |
35 explicit SafeBrowsingUIManager( | 58 explicit SafeBrowsingUIManager( |
36 const scoped_refptr<SafeBrowsingService>& service); | 59 const scoped_refptr<SafeBrowsingService>& service); |
37 | 60 |
38 // Called to stop or shutdown operations on the io_thread. This may be called | 61 // Called to stop or shutdown operations on the io_thread. This may be called |
39 // multiple times during the life of the UIManager. Should be called | 62 // multiple times during the life of the UIManager. Should be called |
40 // on IO thread. If shutdown is true, the manager is disabled permanently. | 63 // on IO thread. If shutdown is true, the manager is disabled permanently. |
41 void StopOnIOThread(bool shutdown) override; | 64 void StopOnIOThread(bool shutdown) override; |
42 | 65 |
43 // Called on the UI thread to display an interstitial page. | 66 // Called on the UI thread to display an interstitial page. |
44 // |url| is the url of the resource that matches a safe browsing list. | 67 // |url| is the url of the resource that matches a safe browsing list. |
45 // If the request contained a chain of redirects, |url| is the last url | 68 // If the request contained a chain of redirects, |url| is the last url |
46 // in the chain, and |original_url| is the first one (the root of the | 69 // in the chain, and |original_url| is the first one (the root of the |
47 // chain). Otherwise, |original_url| = |url|. | 70 // chain). Otherwise, |original_url| = |url|. |
48 void DisplayBlockingPage(const UnsafeResource& resource) override; | 71 void DisplayBlockingPage(const UnsafeResource& resource) override; |
49 | 72 |
50 // Log the user perceived delay caused by SafeBrowsing. This delay is the time | |
51 // delta starting from when we would have started reading data from the | |
52 // network, and ending when the SafeBrowsing check completes indicating that | |
53 // the current page is 'safe'. | |
54 void LogPauseDelay(base::TimeDelta time) override; | |
55 | |
56 // Called on the IO thread by the ThreatDetails with the serialized | 73 // Called on the IO thread by the ThreatDetails with the serialized |
57 // protocol buffer, so the service can send it over. | 74 // protocol buffer, so the service can send it over. |
58 void SendSerializedThreatDetails(const std::string& serialized) override; | 75 void SendSerializedThreatDetails(const std::string& serialized) override; |
59 | 76 |
60 // Report hits to the unsafe contents (malware, phishing, unsafe download URL) | 77 // Report hits to the unsafe contents (malware, phishing, unsafe download URL) |
61 // to the server. Can only be called on UI thread. If |post_data| is | 78 // to the server. Can only be called on UI thread. If |post_data| is |
62 // non-empty, the request will be sent as a POST instead of a GET. | 79 // non-empty, the request will be sent as a POST instead of a GET. |
63 // Will report only for UMA || is_extended_reporting. | 80 // Will report only for UMA || is_extended_reporting. |
64 void MaybeReportSafeBrowsingHit( | 81 void MaybeReportSafeBrowsingHit( |
65 const safe_browsing::HitReport& hit_report) override; | 82 const safe_browsing::HitReport& hit_report) override; |
66 | 83 |
67 // Report permission action to SafeBrowsing servers. Can only be called on UI | 84 // Report permission action to SafeBrowsing servers. Can only be called on UI |
68 // thread. | 85 // thread. |
69 void ReportPermissionAction(const PermissionReportInfo& report_info); | 86 void ReportPermissionAction(const PermissionReportInfo& report_info); |
70 | 87 |
71 // Creates the whitelist URL set for tests that create a blocking page | 88 // Creates the whitelist URL set for tests that create a blocking page |
72 // themselves and then simulate OnBlockingPageDone(). OnBlockingPageDone() | 89 // themselves and then simulate OnBlockingPageDone(). OnBlockingPageDone() |
73 // expects the whitelist to exist, but the tests don't necessarily call | 90 // expects the whitelist to exist, but the tests don't necessarily call |
74 // DisplayBlockingPage(), which creates it. | 91 // DisplayBlockingPage(), which creates it. |
75 static void CreateWhitelistForTesting(content::WebContents* web_contents); | 92 static void CreateWhitelistForTesting(content::WebContents* web_contents); |
76 | 93 |
94 // Add and remove observers. These methods must be invoked on the UI thread. | |
meacer
2017/01/11 01:33:30
tiny nit: Single space after the period.
Jialiu Lin
2017/01/11 02:53:15
Good eye! Done.
| |
95 void AddObserver(Observer* observer); | |
96 void RemoveObserver(Observer* remove); | |
97 | |
98 const std::string app_locale() const override; | |
99 history::HistoryService* history_service( | |
100 content::WebContents* web_contents) override; | |
101 const GURL default_safe_page() const override; | |
102 | |
77 protected: | 103 protected: |
78 ~SafeBrowsingUIManager() override; | 104 ~SafeBrowsingUIManager() override; |
79 | 105 |
80 // Call protocol manager on IO thread to report hits of unsafe contents. | 106 // Call protocol manager on IO thread to report hits of unsafe contents. |
81 void ReportSafeBrowsingHitOnIOThread( | 107 void ReportSafeBrowsingHitOnIOThread( |
82 const safe_browsing::HitReport& hit_report) override; | 108 const safe_browsing::HitReport& hit_report) override; |
83 | 109 |
84 private: | 110 private: |
85 friend class SafeBrowsingUIManagerTest; | 111 friend class SafeBrowsingUIManagerTest; |
86 friend class TestSafeBrowsingUIManager; | 112 friend class TestSafeBrowsingUIManager; |
87 | 113 |
88 // Report permission action to SafeBrowsing servers. | 114 // Report permission action to SafeBrowsing servers. |
89 void ReportPermissionActionOnIOThread( | 115 void ReportPermissionActionOnIOThread( |
90 const PermissionReportInfo& report_info); | 116 const PermissionReportInfo& report_info); |
91 | 117 |
92 static GURL GetMainFrameWhitelistUrlForResourceForTesting( | 118 static GURL GetMainFrameWhitelistUrlForResourceForTesting( |
93 const safe_browsing::SafeBrowsingUIManager::UnsafeResource& resource); | 119 const safe_browsing::SafeBrowsingUIManager::UnsafeResource& resource); |
94 | 120 |
95 // Safebrowsing service. | 121 // Safebrowsing service. |
96 scoped_refptr<SafeBrowsingService> sb_service_; | 122 scoped_refptr<SafeBrowsingService> sb_service_; |
97 | 123 |
124 base::ObserverList<Observer> observer_list_; | |
125 | |
98 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingUIManager); | 126 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingUIManager); |
99 }; | 127 }; |
100 | 128 |
101 } // namespace safe_browsing | 129 } // namespace safe_browsing |
102 | 130 |
103 #endif // CHROME_BROWSER_SAFE_BROWSING_UI_MANAGER_H_ | 131 #endif // CHROME_BROWSER_SAFE_BROWSING_UI_MANAGER_H_ |
OLD | NEW |