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 // Classes for managing the SafeBrowsing interstitial pages. | 5 // Classes for managing the SafeBrowsing interstitial pages. |
6 // | 6 // |
7 // When a user is about to visit a page the SafeBrowsing system has deemed to | 7 // When a user is about to visit a page the SafeBrowsing system has deemed to |
8 // be malicious, either as malware or a phishing page, we show an interstitial | 8 // be malicious, either as malware or a phishing page, we show an interstitial |
9 // page with some options (go back, continue) to give the user a chance to avoid | 9 // page with some options (go back, continue) to give the user a chance to avoid |
10 // the harmful page. | 10 // the harmful page. |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ | 28 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ |
29 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ | 29 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ |
30 | 30 |
31 #include <map> | 31 #include <map> |
32 #include <string> | 32 #include <string> |
33 #include <vector> | 33 #include <vector> |
34 | 34 |
35 #include "base/gtest_prod_util.h" | 35 #include "base/gtest_prod_util.h" |
36 #include "base/macros.h" | 36 #include "base/macros.h" |
37 #include "base/task/cancelable_task_tracker.h" | |
38 #include "chrome/browser/safe_browsing/ui_manager.h" | |
39 #include "components/safe_browsing/base_blocking_page.h" | 37 #include "components/safe_browsing/base_blocking_page.h" |
| 38 #include "components/safe_browsing/base_ui_manager.h" |
40 | 39 |
41 namespace safe_browsing { | 40 namespace safe_browsing { |
42 | 41 |
43 class SafeBrowsingBlockingPageFactory; | 42 class SafeBrowsingBlockingPageFactory; |
44 class ThreatDetails; | 43 class ThreatDetails; |
45 | 44 |
46 class SafeBrowsingBlockingPage : public BaseBlockingPage { | 45 class SafeBrowsingBlockingPage : public BaseBlockingPage { |
47 public: | 46 public: |
48 // Interstitial type, used in tests. | 47 // Interstitial type, used in tests. |
49 static content::InterstitialPageDelegate::TypeID kTypeForTesting; | 48 static content::InterstitialPageDelegate::TypeID kTypeForTesting; |
(...skipping 16 matching lines...) Expand all Loading... |
66 static void ShowBlockingPage(BaseUIManager* ui_manager, | 65 static void ShowBlockingPage(BaseUIManager* ui_manager, |
67 const UnsafeResource& resource); | 66 const UnsafeResource& resource); |
68 | 67 |
69 // Makes the passed |factory| the factory used to instantiate | 68 // Makes the passed |factory| the factory used to instantiate |
70 // SafeBrowsingBlockingPage objects. Useful for tests. | 69 // SafeBrowsingBlockingPage objects. Useful for tests. |
71 static void RegisterFactory(SafeBrowsingBlockingPageFactory* factory) { | 70 static void RegisterFactory(SafeBrowsingBlockingPageFactory* factory) { |
72 factory_ = factory; | 71 factory_ = factory; |
73 } | 72 } |
74 | 73 |
75 // InterstitialPageDelegate method: | 74 // InterstitialPageDelegate method: |
76 void OnProceed() override; | |
77 void OverrideRendererPrefs(content::RendererPreferences* prefs) override; | 75 void OverrideRendererPrefs(content::RendererPreferences* prefs) override; |
78 content::InterstitialPageDelegate::TypeID GetTypeForTesting() const override; | 76 content::InterstitialPageDelegate::TypeID GetTypeForTesting() const override; |
79 | 77 |
80 // Checks the threat type to decide if we should report ThreatDetails. | 78 // Checks the threat type to decide if we should report ThreatDetails. |
81 static bool ShouldReportThreatDetails(SBThreatType threat_type); | 79 static bool ShouldReportThreatDetails(SBThreatType threat_type); |
82 | 80 |
83 protected: | 81 protected: |
84 friend class SafeBrowsingBlockingPageFactoryImpl; | 82 friend class SafeBrowsingBlockingPageFactoryImpl; |
85 friend class SafeBrowsingBlockingPageTest; | 83 friend class SafeBrowsingBlockingPageTest; |
86 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | 84 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
(...skipping 14 matching lines...) Expand all Loading... |
101 void UpdateReportingPref(); // Used for the transition from old to new pref. | 99 void UpdateReportingPref(); // Used for the transition from old to new pref. |
102 | 100 |
103 // Don't instantiate this class directly, use ShowBlockingPage instead. | 101 // Don't instantiate this class directly, use ShowBlockingPage instead. |
104 SafeBrowsingBlockingPage( | 102 SafeBrowsingBlockingPage( |
105 BaseUIManager* ui_manager, | 103 BaseUIManager* ui_manager, |
106 content::WebContents* web_contents, | 104 content::WebContents* web_contents, |
107 const GURL& main_frame_url, | 105 const GURL& main_frame_url, |
108 const UnsafeResourceList& unsafe_resources, | 106 const UnsafeResourceList& unsafe_resources, |
109 const SafeBrowsingErrorUI::SBErrorDisplayOptions& display_options); | 107 const SafeBrowsingErrorUI::SBErrorDisplayOptions& display_options); |
110 | 108 |
111 // After a safe browsing interstitial where the user opted-in to the | 109 // Called after the user clicks OnProceed(). If the page has malicious |
112 // report but clicked "proceed anyway", we delay the call to | 110 // subresources, then we show another interstitial. |
113 // ThreatDetails::FinishCollection() by this much time (in | 111 void HandleSubresourcesAfterProceed() override; |
114 // milliseconds), in order to get data from the blocked resource itself. | |
115 int64_t threat_details_proceed_delay_ms_; | |
116 | 112 |
117 // Called when the interstitial is going away. If there is a | 113 // Called when the interstitial is going away. If there is a |
118 // pending threat details object, we look at the user's | 114 // pending threat details object, we look at the user's |
119 // preferences, and if the option to send threat details is | 115 // preferences, and if the option to send threat details is |
120 // enabled, the report is scheduled to be sent on the |ui_manager_|. | 116 // enabled, the report is scheduled to be sent on the |ui_manager_|. |
121 void FinishThreatDetails(const base::TimeDelta& delay, | 117 void FinishThreatDetails(const base::TimeDelta& delay, |
122 bool did_proceed, | 118 bool did_proceed, |
123 int num_visits) override; | 119 int num_visits) override; |
124 | 120 |
125 // A ThreatDetails object that we start generating when the | 121 // A ThreatDetails object that we start generating when the |
126 // blocking page is shown. The object will be sent when the warning | 122 // blocking page is shown. The object will be sent when the warning |
127 // is gone (if the user enables the feature). | 123 // is gone (if the user enables the feature). |
128 scoped_refptr<ThreatDetails> threat_details_; | 124 scoped_refptr<ThreatDetails> threat_details_; |
129 | 125 |
130 // The factory used to instantiate SafeBrowsingBlockingPage objects. | 126 // The factory used to instantiate SafeBrowsingBlockingPage objects. |
131 // Useful for tests, so they can provide their own implementation of | 127 // Useful for tests, so they can provide their own implementation of |
132 // SafeBrowsingBlockingPage. | 128 // SafeBrowsingBlockingPage. |
133 static SafeBrowsingBlockingPageFactory* factory_; | 129 static SafeBrowsingBlockingPageFactory* factory_; |
134 | |
135 private: | 130 private: |
136 static std::string GetSamplingEventName( | 131 static std::string GetSamplingEventName( |
137 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason); | 132 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason); |
138 | 133 |
139 static std::unique_ptr< | 134 static std::unique_ptr< |
140 security_interstitials::SecurityInterstitialControllerClient> | 135 security_interstitials::SecurityInterstitialControllerClient> |
141 CreateControllerClient(content::WebContents* web_contents, | 136 CreateControllerClient(content::WebContents* web_contents, |
142 const UnsafeResourceList& unsafe_resources); | 137 const UnsafeResourceList& unsafe_resources, |
| 138 const BaseUIManager* ui_manager); |
143 | 139 |
144 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPage); | 140 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPage); |
145 }; | 141 }; |
146 | 142 |
147 // Factory for creating SafeBrowsingBlockingPage. Useful for tests. | 143 // Factory for creating SafeBrowsingBlockingPage. Useful for tests. |
148 class SafeBrowsingBlockingPageFactory { | 144 class SafeBrowsingBlockingPageFactory { |
149 public: | 145 public: |
150 virtual ~SafeBrowsingBlockingPageFactory() { } | 146 virtual ~SafeBrowsingBlockingPageFactory() { } |
151 | 147 |
152 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( | 148 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( |
153 BaseUIManager* ui_manager, | 149 BaseUIManager* ui_manager, |
154 content::WebContents* web_contents, | 150 content::WebContents* web_contents, |
155 const GURL& main_frame_url, | 151 const GURL& main_frame_url, |
156 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) = 0; | 152 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) = 0; |
157 }; | 153 }; |
158 | 154 |
159 } // namespace safe_browsing | 155 } // namespace safe_browsing |
160 | 156 |
161 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ | 157 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ |
OLD | NEW |