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 22 matching lines...) Expand all Loading... |
33 #include <vector> | 33 #include <vector> |
34 | 34 |
35 #include <stdint.h> | 35 #include <stdint.h> |
36 | 36 |
37 #include "base/gtest_prod_util.h" | 37 #include "base/gtest_prod_util.h" |
38 #include "base/macros.h" | 38 #include "base/macros.h" |
39 #include "base/task/cancelable_task_tracker.h" | 39 #include "base/task/cancelable_task_tracker.h" |
40 #include "chrome/browser/interstitials/chrome_metrics_helper.h" | 40 #include "chrome/browser/interstitials/chrome_metrics_helper.h" |
41 #include "chrome/browser/interstitials/security_interstitial_page.h" | 41 #include "chrome/browser/interstitials/security_interstitial_page.h" |
42 #include "chrome/browser/safe_browsing/ui_manager.h" | 42 #include "chrome/browser/safe_browsing/ui_manager.h" |
| 43 #include "components/security_interstitials/core/safe_browsing_error_ui.h" |
43 #include "content/public/browser/interstitial_page_delegate.h" | 44 #include "content/public/browser/interstitial_page_delegate.h" |
44 #include "url/gurl.h" | 45 #include "url/gurl.h" |
45 | 46 |
46 namespace safe_browsing { | 47 namespace safe_browsing { |
47 | 48 |
48 class SafeBrowsingBlockingPageFactory; | 49 class SafeBrowsingBlockingPageFactory; |
49 class ThreatDetails; | 50 class ThreatDetails; |
50 | 51 |
51 class SafeBrowsingBlockingPage : public SecurityInterstitialPage { | 52 class SafeBrowsingBlockingPage : public SecurityInterstitialPage { |
52 public: | 53 public: |
53 typedef security_interstitials::UnsafeResource UnsafeResource; | 54 typedef security_interstitials::UnsafeResource UnsafeResource; |
| 55 typedef security_interstitials::SafeBrowsingErrorUI SafeBrowsingErrorUI; |
54 typedef std::vector<UnsafeResource> UnsafeResourceList; | 56 typedef std::vector<UnsafeResource> UnsafeResourceList; |
55 typedef std::map<content::WebContents*, UnsafeResourceList> UnsafeResourceMap; | 57 typedef std::map<content::WebContents*, UnsafeResourceList> UnsafeResourceMap; |
56 | 58 |
57 // Interstitial type, used in tests. | 59 // Interstitial type, used in tests. |
58 static content::InterstitialPageDelegate::TypeID kTypeForTesting; | 60 static content::InterstitialPageDelegate::TypeID kTypeForTesting; |
59 | 61 |
60 ~SafeBrowsingBlockingPage() override; | 62 ~SafeBrowsingBlockingPage() override; |
61 | 63 |
62 // Creates a blocking page. Use ShowBlockingPage if you don't need to access | 64 // Creates a blocking page. Use ShowBlockingPage if you don't need to access |
63 // the blocking page directly. | 65 // the blocking page directly. |
(...skipping 21 matching lines...) Expand all Loading... |
85 void OnProceed() override; | 87 void OnProceed() override; |
86 void OnDontProceed() override; | 88 void OnDontProceed() override; |
87 void CommandReceived(const std::string& command) override; | 89 void CommandReceived(const std::string& command) override; |
88 void OverrideRendererPrefs(content::RendererPreferences* prefs) override; | 90 void OverrideRendererPrefs(content::RendererPreferences* prefs) override; |
89 content::InterstitialPageDelegate::TypeID GetTypeForTesting() const override; | 91 content::InterstitialPageDelegate::TypeID GetTypeForTesting() const override; |
90 | 92 |
91 // Checks the threat type to decide if we should report ThreatDetails. | 93 // Checks the threat type to decide if we should report ThreatDetails. |
92 static bool ShouldReportThreatDetails(SBThreatType threat_type); | 94 static bool ShouldReportThreatDetails(SBThreatType threat_type); |
93 | 95 |
94 protected: | 96 protected: |
| 97 friend class SafeBrowsingBlockingPageFactoryImpl; |
95 friend class SafeBrowsingBlockingPageTest; | 98 friend class SafeBrowsingBlockingPageTest; |
96 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | 99 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
97 ProceedThenDontProceed); | 100 ProceedThenDontProceed); |
98 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | 101 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
99 MalwareReportsDisabled); | 102 MalwareReportsDisabled); |
100 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | 103 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
101 MalwareReportsToggling); | 104 MalwareReportsToggling); |
102 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | 105 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
103 ExtendedReportingNotShownOnSecurePage); | 106 ExtendedReportingNotShownOnSecurePage); |
| 107 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
| 108 MalwareReportsTransitionDisabled); |
104 FRIEND_TEST_ALL_PREFIXES( | 109 FRIEND_TEST_ALL_PREFIXES( |
105 SafeBrowsingBlockingPageTest, | 110 SafeBrowsingBlockingPageTest, |
106 ExtendedReportingNotShownOnSecurePageWithSecureSubresource); | 111 ExtendedReportingNotShownOnSecurePageWithSecureSubresource); |
107 FRIEND_TEST_ALL_PREFIXES( | 112 FRIEND_TEST_ALL_PREFIXES( |
108 SafeBrowsingBlockingPageTest, | 113 SafeBrowsingBlockingPageTest, |
109 ExtendedReportingNotShownOnSecurePageWithInsecureSubresource); | 114 ExtendedReportingNotShownOnSecurePageWithInsecureSubresource); |
110 FRIEND_TEST_ALL_PREFIXES( | 115 FRIEND_TEST_ALL_PREFIXES( |
111 SafeBrowsingBlockingPageTest, | 116 SafeBrowsingBlockingPageTest, |
112 ExtendedReportingOnInsecurePageWithSecureSubresource); | 117 ExtendedReportingOnInsecurePageWithSecureSubresource); |
113 FRIEND_TEST_ALL_PREFIXES( | 118 FRIEND_TEST_ALL_PREFIXES( |
(...skipping 12 matching lines...) Expand all Loading... |
126 bool ShouldCreateNewNavigation() const override; | 131 bool ShouldCreateNewNavigation() const override; |
127 void PopulateInterstitialStrings( | 132 void PopulateInterstitialStrings( |
128 base::DictionaryValue* load_time_data) override; | 133 base::DictionaryValue* load_time_data) override; |
129 | 134 |
130 // After a safe browsing interstitial where the user opted-in to the | 135 // After a safe browsing interstitial where the user opted-in to the |
131 // report but clicked "proceed anyway", we delay the call to | 136 // report but clicked "proceed anyway", we delay the call to |
132 // ThreatDetails::FinishCollection() by this much time (in | 137 // ThreatDetails::FinishCollection() by this much time (in |
133 // milliseconds), in order to get data from the blocked resource itself. | 138 // milliseconds), in order to get data from the blocked resource itself. |
134 int64_t threat_details_proceed_delay_ms_; | 139 int64_t threat_details_proceed_delay_ms_; |
135 | 140 |
136 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | |
137 MalwareReportsTransitionDisabled); | |
138 | |
139 // Checks if we should even show the threat details option. For example, we | 141 // Checks if we should even show the threat details option. For example, we |
140 // don't show it in incognito mode. | 142 // don't show it in incognito mode. |
141 bool CanShowThreatDetailsOption(); | 143 bool CanShowThreatDetailsOption(); |
142 | 144 |
143 // Called when the insterstitial is going away. If there is a | 145 // Called when the insterstitial is going away. If there is a |
144 // pending threat details object, we look at the user's | 146 // pending threat details object, we look at the user's |
145 // preferences, and if the option to send threat details is | 147 // preferences, and if the option to send threat details is |
146 // enabled, the report is scheduled to be sent on the |ui_manager_|. | 148 // enabled, the report is scheduled to be sent on the |ui_manager_|. |
147 void FinishThreatDetails(int64_t delay_ms, bool did_proceed, int num_visits); | 149 void FinishThreatDetails(int64_t delay_ms, bool did_proceed, int num_visits); |
148 | 150 |
149 // A list of SafeBrowsingUIManager::UnsafeResource for a tab that the user | 151 // A list of SafeBrowsingUIManager::UnsafeResource for a tab that the user |
150 // should be warned about. They are queued when displaying more than one | 152 // should be warned about. They are queued when displaying more than one |
151 // interstitial at a time. | 153 // interstitial at a time. |
152 static UnsafeResourceMap* GetUnsafeResourcesMap(); | 154 static UnsafeResourceMap* GetUnsafeResourcesMap(); |
153 | 155 |
154 // Returns true if the passed |unsafe_resources| is blocking the load of | 156 // Returns true if the passed |unsafe_resources| is blocking the load of |
155 // the main page. | 157 // the main page. |
156 static bool IsMainPageLoadBlocked( | 158 static bool IsMainPageLoadBlocked( |
157 const UnsafeResourceList& unsafe_resources); | 159 const UnsafeResourceList& unsafe_resources); |
158 | 160 |
159 friend class SafeBrowsingBlockingPageFactoryImpl; | |
160 | |
161 // For reporting back user actions. | 161 // For reporting back user actions. |
162 SafeBrowsingUIManager* ui_manager_; | 162 SafeBrowsingUIManager* ui_manager_; |
163 | 163 |
164 // True if the interstitial is blocking the main page because it is on one | 164 // For displaying safe browsing interstitial. |
165 // of our lists. False if a subresource is being blocked, or in the case of | 165 std::unique_ptr<SafeBrowsingErrorUI> sb_error_ui_; |
166 // client-side detection where the interstitial is shown after page load | |
167 // finishes. | |
168 bool is_main_frame_load_blocked_; | |
169 | 166 |
170 // The URL of the main frame that caused the warning. | 167 // The URL of the main frame that caused the warning. |
171 GURL main_frame_url_; | 168 GURL main_frame_url_; |
172 | 169 |
173 // The index of a navigation entry that should be removed when DontProceed() | 170 // The index of a navigation entry that should be removed when DontProceed() |
174 // is invoked, -1 if not entry should be removed. | 171 // is invoked, -1 if not entry should be removed. |
175 int navigation_entry_index_to_remove_; | 172 int navigation_entry_index_to_remove_; |
176 | 173 |
177 // The list of unsafe resources this page is warning about. | 174 // The list of unsafe resources this page is warning about. |
178 UnsafeResourceList unsafe_resources_; | 175 UnsafeResourceList unsafe_resources_; |
179 | 176 |
180 // A ThreatDetails object that we start generating when the | 177 // A ThreatDetails object that we start generating when the |
181 // blocking page is shown. The object will be sent when the warning | 178 // blocking page is shown. The object will be sent when the warning |
182 // is gone (if the user enables the feature). | 179 // is gone (if the user enables the feature). |
183 scoped_refptr<ThreatDetails> threat_details_; | 180 scoped_refptr<ThreatDetails> threat_details_; |
184 | 181 |
185 bool proceeded_; | 182 bool proceeded_; |
186 | 183 |
187 // Which type of Safe Browsing interstitial this is. | 184 // Which type of Safe Browsing interstitial this is. |
188 enum SBInterstitialReason { | 185 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason_; |
189 SB_REASON_MALWARE, | |
190 SB_REASON_HARMFUL, | |
191 SB_REASON_PHISHING, | |
192 }; | |
193 SBInterstitialReason interstitial_reason_; | |
194 | 186 |
195 // The factory used to instantiate SafeBrowsingBlockingPage objects. | 187 // The factory used to instantiate SafeBrowsingBlockingPage objects. |
196 // Useful for tests, so they can provide their own implementation of | 188 // Useful for tests, so they can provide their own implementation of |
197 // SafeBrowsingBlockingPage. | 189 // SafeBrowsingBlockingPage. |
198 static SafeBrowsingBlockingPageFactory* factory_; | 190 static SafeBrowsingBlockingPageFactory* factory_; |
199 | 191 |
200 private: | 192 private: |
201 // Fills the passed dictionary with the values to be passed to the template | 193 static std::string GetMetricPrefix( |
202 // when creating the HTML. | 194 const UnsafeResourceList& unsafe_resources, |
203 void PopulateExtendedReportingOption(base::DictionaryValue* load_time_data); | 195 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason); |
204 void PopulateMalwareLoadTimeData(base::DictionaryValue* load_time_data); | |
205 void PopulateHarmfulLoadTimeData(base::DictionaryValue* load_time_data); | |
206 void PopulatePhishingLoadTimeData(base::DictionaryValue* load_time_data); | |
207 | |
208 static std::string GetMetricPrefix(const UnsafeResourceList& unsafe_resources, | |
209 SBInterstitialReason interstitial_reason); | |
210 static std::string GetExtraMetricsSuffix( | 196 static std::string GetExtraMetricsSuffix( |
211 const UnsafeResourceList& unsafe_resources); | 197 const UnsafeResourceList& unsafe_resources); |
212 static std::string GetRapporPrefix(SBInterstitialReason interstitial_reason); | |
213 static std::string GetDeprecatedRapporPrefix( | |
214 SBInterstitialReason interstitial_reason); | |
215 static std::string GetSamplingEventName( | 198 static std::string GetSamplingEventName( |
216 SBInterstitialReason interstitial_reason); | 199 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason); |
217 | 200 |
218 static SBInterstitialReason GetInterstitialReason( | 201 static SafeBrowsingErrorUI::SBInterstitialReason GetInterstitialReason( |
219 const UnsafeResourceList& unsafe_resources); | 202 const UnsafeResourceList& unsafe_resources); |
220 | 203 |
221 static std::unique_ptr<ChromeMetricsHelper> CreateMetricsHelper( | 204 static std::unique_ptr<ChromeMetricsHelper> CreateMetricsHelper( |
222 content::WebContents* web_contents, | 205 content::WebContents* web_contents, |
223 const UnsafeResourceList& unsafe_resources); | 206 const UnsafeResourceList& unsafe_resources); |
224 | 207 |
225 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPage); | 208 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPage); |
226 }; | 209 }; |
227 | 210 |
228 // Factory for creating SafeBrowsingBlockingPage. Useful for tests. | 211 // Factory for creating SafeBrowsingBlockingPage. Useful for tests. |
229 class SafeBrowsingBlockingPageFactory { | 212 class SafeBrowsingBlockingPageFactory { |
230 public: | 213 public: |
231 virtual ~SafeBrowsingBlockingPageFactory() { } | 214 virtual ~SafeBrowsingBlockingPageFactory() { } |
232 | 215 |
233 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( | 216 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( |
234 SafeBrowsingUIManager* ui_manager, | 217 SafeBrowsingUIManager* ui_manager, |
235 content::WebContents* web_contents, | 218 content::WebContents* web_contents, |
236 const GURL& main_frame_url, | 219 const GURL& main_frame_url, |
237 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) = 0; | 220 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) = 0; |
238 }; | 221 }; |
239 | 222 |
240 } // namespace safe_browsing | 223 } // namespace safe_browsing |
241 | 224 |
242 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ | 225 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ |
OLD | NEW |