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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 } | 76 } |
77 | 77 |
78 // InterstitialPageDelegate method: | 78 // InterstitialPageDelegate method: |
79 virtual void CommandReceived(const std::string& command) OVERRIDE; | 79 virtual void CommandReceived(const std::string& command) OVERRIDE; |
80 virtual void OverrideRendererPrefs( | 80 virtual void OverrideRendererPrefs( |
81 content::RendererPreferences* prefs) OVERRIDE; | 81 content::RendererPreferences* prefs) OVERRIDE; |
82 virtual void OnProceed() OVERRIDE; | 82 virtual void OnProceed() OVERRIDE; |
83 virtual void OnDontProceed() OVERRIDE; | 83 virtual void OnDontProceed() OVERRIDE; |
84 | 84 |
85 protected: | 85 protected: |
86 template <class TestSBInterstitialPage> | |
87 friend class SafeBrowsingBlockingPageTest; | 86 friend class SafeBrowsingBlockingPageTest; |
88 template <class TestSBInterstitialPage> | |
89 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | 87 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
90 ProceedThenDontProceed); | 88 ProceedThenDontProceed); |
91 | 89 |
92 void SetReportingPreference(bool report); | 90 void SetReportingPreference(bool report); |
93 void UpdateReportingPref(); // Used for the transition from old to new pref. | 91 void UpdateReportingPref(); // Used for the transition from old to new pref. |
94 | 92 |
95 // Don't instanciate this class directly, use ShowBlockingPage instead. | 93 // Don't instanciate this class directly, use ShowBlockingPage instead. |
96 SafeBrowsingBlockingPage(SafeBrowsingUIManager* ui_manager, | 94 SafeBrowsingBlockingPage(SafeBrowsingUIManager* ui_manager, |
97 content::WebContents* web_contents, | 95 content::WebContents* web_contents, |
98 const UnsafeResourceList& unsafe_resources); | 96 const UnsafeResourceList& unsafe_resources); |
99 | 97 |
100 // After a malware interstitial where the user opted-in to the | 98 // After a malware interstitial where the user opted-in to the |
101 // report but clicked "proceed anyway", we delay the call to | 99 // report but clicked "proceed anyway", we delay the call to |
102 // MalwareDetails::FinishCollection() by this much time (in | 100 // MalwareDetails::FinishCollection() by this much time (in |
103 // milliseconds), in order to get data from the blocked resource itself. | 101 // milliseconds), in order to get data from the blocked resource itself. |
104 int64 malware_details_proceed_delay_ms_; | 102 int64 malware_details_proceed_delay_ms_; |
105 content::InterstitialPage* interstitial_page() const { | 103 content::InterstitialPage* interstitial_page() const { |
106 return interstitial_page_; | 104 return interstitial_page_; |
107 } | 105 } |
108 | 106 |
109 template <class TestSBInterstitialPage> | |
110 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | 107 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
111 MalwareReportsTransitionDisabled); | 108 MalwareReportsTransitionDisabled); |
112 template <class TestSBInterstitialPage> | |
113 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | 109 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
114 MalwareReportsToggling); | 110 MalwareReportsToggling); |
115 | 111 |
116 enum BlockingPageEvent { | 112 enum BlockingPageEvent { |
117 SHOW, | 113 SHOW, |
118 PROCEED, | 114 PROCEED, |
119 DONT_PROCEED, | 115 DONT_PROCEED, |
120 SHOW_ADVANCED, | 116 SHOW_ADVANCED, |
121 }; | 117 }; |
122 | 118 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 // SafeBrowsingBlockingPage. | 213 // SafeBrowsingBlockingPage. |
218 static SafeBrowsingBlockingPageFactory* factory_; | 214 static SafeBrowsingBlockingPageFactory* factory_; |
219 | 215 |
220 // How many times is this same URL in history? Used for histogramming. | 216 // How many times is this same URL in history? Used for histogramming. |
221 int num_visits_; | 217 int num_visits_; |
222 base::CancelableTaskTracker request_tracker_; | 218 base::CancelableTaskTracker request_tracker_; |
223 | 219 |
224 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPage); | 220 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPage); |
225 }; | 221 }; |
226 | 222 |
227 class SafeBrowsingBlockingPageV2 : public SafeBrowsingBlockingPage { | |
228 public: | |
229 // Don't instanciate this class directly, use ShowBlockingPage instead. | |
230 SafeBrowsingBlockingPageV2(SafeBrowsingUIManager* ui_manager, | |
231 content::WebContents* web_contents, | |
232 const UnsafeResourceList& unsafe_resources); | |
233 | |
234 // InterstitialPageDelegate method: | |
235 virtual std::string GetHTMLContents() OVERRIDE; | |
236 | |
237 private: | |
238 // Fills the passed dictionary with the strings passed to JS Template when | |
239 // creating the HTML. | |
240 void PopulateMultipleThreatStringDictionary(base::DictionaryValue* strings); | |
241 void PopulateMalwareStringDictionary(base::DictionaryValue* strings); | |
242 void PopulatePhishingStringDictionary(base::DictionaryValue* strings); | |
243 | |
244 // A helper method used by the Populate methods above used to populate common | |
245 // fields. | |
246 void PopulateStringDictionary(base::DictionaryValue* strings, | |
247 const base::string16& title, | |
248 const base::string16& headline, | |
249 const base::string16& description1, | |
250 const base::string16& description2, | |
251 const base::string16& description3); | |
252 | |
253 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageV2); | |
254 }; | |
255 | |
256 class SafeBrowsingBlockingPageV3 : public SafeBrowsingBlockingPage { | 223 class SafeBrowsingBlockingPageV3 : public SafeBrowsingBlockingPage { |
257 public: | 224 public: |
258 SafeBrowsingBlockingPageV3(SafeBrowsingUIManager* ui_manager, | 225 SafeBrowsingBlockingPageV3(SafeBrowsingUIManager* ui_manager, |
259 content::WebContents* web_contents, | 226 content::WebContents* web_contents, |
260 const UnsafeResourceList& unsafe_resources); | 227 const UnsafeResourceList& unsafe_resources); |
261 | 228 |
262 // InterstitialPageDelegate method: | 229 // InterstitialPageDelegate method: |
263 virtual std::string GetHTMLContents() OVERRIDE; | 230 virtual std::string GetHTMLContents() OVERRIDE; |
264 | 231 |
265 private: | 232 private: |
266 // Fills the passed dictionary with the values to be passed to the template | 233 // Fills the passed dictionary with the values to be passed to the template |
267 // when creating the HTML. | 234 // when creating the HTML. |
268 void PopulateMalwareLoadTimeData(base::DictionaryValue* load_time_data); | 235 void PopulateMalwareLoadTimeData(base::DictionaryValue* load_time_data); |
269 void PopulatePhishingLoadTimeData(base::DictionaryValue* load_time_data); | 236 void PopulatePhishingLoadTimeData(base::DictionaryValue* load_time_data); |
270 | 237 |
271 // For the M37 FieldTrial: this contains the name of the condition. | |
272 std::string trial_condition_; | |
273 | |
274 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageV3); | 238 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageV3); |
275 }; | 239 }; |
276 | 240 |
277 // Factory for creating SafeBrowsingBlockingPage. Useful for tests. | 241 // Factory for creating SafeBrowsingBlockingPage. Useful for tests. |
278 class SafeBrowsingBlockingPageFactory { | 242 class SafeBrowsingBlockingPageFactory { |
279 public: | 243 public: |
280 virtual ~SafeBrowsingBlockingPageFactory() { } | 244 virtual ~SafeBrowsingBlockingPageFactory() { } |
281 | 245 |
282 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( | 246 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( |
283 SafeBrowsingUIManager* ui_manager, | 247 SafeBrowsingUIManager* ui_manager, |
284 content::WebContents* web_contents, | 248 content::WebContents* web_contents, |
285 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) = 0; | 249 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) = 0; |
286 }; | 250 }; |
287 | 251 |
288 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ | 252 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ |
OLD | NEW |