Chromium Code Reviews| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 } | 83 } |
| 84 | 84 |
| 85 // InterstitialPageDelegate method: | 85 // InterstitialPageDelegate method: |
| 86 virtual void CommandReceived(const std::string& command) OVERRIDE; | 86 virtual void CommandReceived(const std::string& command) OVERRIDE; |
| 87 virtual void OverrideRendererPrefs( | 87 virtual void OverrideRendererPrefs( |
| 88 content::RendererPreferences* prefs) OVERRIDE; | 88 content::RendererPreferences* prefs) OVERRIDE; |
| 89 virtual void OnProceed() OVERRIDE; | 89 virtual void OnProceed() OVERRIDE; |
| 90 virtual void OnDontProceed() OVERRIDE; | 90 virtual void OnDontProceed() OVERRIDE; |
| 91 | 91 |
| 92 protected: | 92 protected: |
| 93 template <class TestSBInterstitialPage> | |
| 94 friend class SafeBrowsingBlockingPageTest; | 93 friend class SafeBrowsingBlockingPageTest; |
| 95 template <class TestSBInterstitialPage> | |
| 96 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | 94 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
| 97 ProceedThenDontProceed); | 95 ProceedThenDontProceed); |
| 98 | 96 |
| 99 void DontCreateViewForTesting(); | 97 void DontCreateViewForTesting(); |
| 100 void Show(); | 98 void Show(); |
| 101 void SetReportingPreference(bool report); | 99 void SetReportingPreference(bool report); |
| 102 void UpdateReportingPref(); // Used for the transition from old to new pref. | 100 void UpdateReportingPref(); // Used for the transition from old to new pref. |
| 103 | 101 |
| 104 // Don't instantiate this class directly, use ShowBlockingPage instead. | 102 // Don't instantiate this class directly, use ShowBlockingPage instead. |
| 105 SafeBrowsingBlockingPage(SafeBrowsingUIManager* ui_manager, | 103 SafeBrowsingBlockingPage(SafeBrowsingUIManager* ui_manager, |
| 106 content::WebContents* web_contents, | 104 content::WebContents* web_contents, |
| 107 const UnsafeResourceList& unsafe_resources); | 105 const UnsafeResourceList& unsafe_resources); |
| 108 | 106 |
| 109 // After a malware interstitial where the user opted-in to the | 107 // After a malware interstitial where the user opted-in to the |
| 110 // report but clicked "proceed anyway", we delay the call to | 108 // report but clicked "proceed anyway", we delay the call to |
| 111 // MalwareDetails::FinishCollection() by this much time (in | 109 // MalwareDetails::FinishCollection() by this much time (in |
| 112 // milliseconds), in order to get data from the blocked resource itself. | 110 // milliseconds), in order to get data from the blocked resource itself. |
| 113 int64 malware_details_proceed_delay_ms_; | 111 int64 malware_details_proceed_delay_ms_; |
| 114 content::InterstitialPage* interstitial_page() const { | 112 content::InterstitialPage* interstitial_page() const { |
| 115 return interstitial_page_; | 113 return interstitial_page_; |
| 116 } | 114 } |
| 117 | 115 |
| 118 template <class TestSBInterstitialPage> | |
| 119 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | 116 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
| 120 MalwareReportsTransitionDisabled); | 117 MalwareReportsTransitionDisabled); |
| 121 template <class TestSBInterstitialPage> | |
| 122 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | 118 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
| 123 MalwareReportsToggling); | 119 MalwareReportsToggling); |
| 124 | 120 |
| 125 enum BlockingPageEvent { | 121 enum BlockingPageEvent { |
| 126 SHOW, | 122 SHOW, |
| 127 PROCEED, | 123 PROCEED, |
| 128 DONT_PROCEED, | 124 DONT_PROCEED, |
| 129 SHOW_ADVANCED, | 125 SHOW_ADVANCED, |
| 130 }; | 126 }; |
| 131 | 127 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 // SafeBrowsingBlockingPage. | 225 // SafeBrowsingBlockingPage. |
| 230 static SafeBrowsingBlockingPageFactory* factory_; | 226 static SafeBrowsingBlockingPageFactory* factory_; |
| 231 | 227 |
| 232 // How many times is this same URL in history? Used for histogramming. | 228 // How many times is this same URL in history? Used for histogramming. |
| 233 int num_visits_; | 229 int num_visits_; |
| 234 base::CancelableTaskTracker request_tracker_; | 230 base::CancelableTaskTracker request_tracker_; |
| 235 | 231 |
| 236 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPage); | 232 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPage); |
| 237 }; | 233 }; |
| 238 | 234 |
| 239 class SafeBrowsingBlockingPageV1 : public SafeBrowsingBlockingPage { | |
| 240 public: | |
| 241 // Don't instantiate this class directly, use ShowBlockingPage instead. | |
| 242 SafeBrowsingBlockingPageV1(SafeBrowsingUIManager* ui_manager, | |
| 243 content::WebContents* web_contents, | |
| 244 const UnsafeResourceList& unsafe_resources); | |
| 245 | |
| 246 // InterstitialPageDelegate method: | |
| 247 virtual std::string GetHTMLContents() OVERRIDE; | |
| 248 | |
| 249 private: | |
| 250 // Fills the passed dictionary with the strings passed to JS Template when | |
| 251 // creating the HTML. | |
| 252 void PopulateMultipleThreatStringDictionary(base::DictionaryValue* strings); | |
| 253 void PopulateMalwareStringDictionary(base::DictionaryValue* strings); | |
| 254 void PopulatePhishingStringDictionary(base::DictionaryValue* strings); | |
| 255 | |
| 256 // A helper method used by the Populate methods above used to populate common | |
| 257 // fields. | |
| 258 void PopulateStringDictionary(base::DictionaryValue* strings, | |
| 259 const base::string16& title, | |
| 260 const base::string16& headline, | |
| 261 const base::string16& description1, | |
| 262 const base::string16& description2, | |
| 263 const base::string16& description3); | |
| 264 | |
| 265 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageV1); | |
| 266 }; | |
| 267 | |
| 268 class SafeBrowsingBlockingPageV2 : public SafeBrowsingBlockingPage { | |
| 269 public: | |
| 270 // Don't instantiate this class directly, use ShowBlockingPage instead. | |
| 271 SafeBrowsingBlockingPageV2(SafeBrowsingUIManager* ui_manager, | |
| 272 content::WebContents* web_contents, | |
| 273 const UnsafeResourceList& unsafe_resources); | |
| 274 | |
| 275 // InterstitialPageDelegate method: | |
| 276 virtual std::string GetHTMLContents() OVERRIDE; | |
| 277 | |
| 278 private: | |
| 279 // Fills the passed dictionary with the strings passed to JS Template when | |
| 280 // creating the HTML. | |
| 281 void PopulateMultipleThreatStringDictionary(base::DictionaryValue* strings); | |
| 282 void PopulateMalwareStringDictionary(base::DictionaryValue* strings); | |
| 283 void PopulatePhishingStringDictionary(base::DictionaryValue* strings); | |
| 284 | |
| 285 // A helper method used by the Populate methods above used to populate common | |
| 286 // fields. | |
| 287 void PopulateStringDictionary(base::DictionaryValue* strings, | |
| 288 const base::string16& title, | |
| 289 const base::string16& headline, | |
| 290 const base::string16& description1, | |
| 291 const base::string16& description2, | |
| 292 const base::string16& description3); | |
| 293 | |
| 294 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageV2); | |
| 295 }; | |
| 296 | |
| 297 class SafeBrowsingBlockingPageV3 : public SafeBrowsingBlockingPage { | 235 class SafeBrowsingBlockingPageV3 : public SafeBrowsingBlockingPage { |
|
Dan Beam
2014/08/07 22:05:08
why do we need SafeBrowsingBlockingPageV3 any more
felt
2014/08/08 00:30:29
Done.
| |
| 298 public: | 236 public: |
| 299 SafeBrowsingBlockingPageV3(SafeBrowsingUIManager* ui_manager, | 237 SafeBrowsingBlockingPageV3(SafeBrowsingUIManager* ui_manager, |
| 300 content::WebContents* web_contents, | 238 content::WebContents* web_contents, |
| 301 const UnsafeResourceList& unsafe_resources); | 239 const UnsafeResourceList& unsafe_resources); |
| 302 | 240 |
| 303 // InterstitialPageDelegate method: | 241 // InterstitialPageDelegate method: |
| 304 virtual std::string GetHTMLContents() OVERRIDE; | 242 virtual std::string GetHTMLContents() OVERRIDE; |
| 305 | 243 |
| 306 private: | 244 private: |
| 307 // Fills the passed dictionary with the values to be passed to the template | 245 // Fills the passed dictionary with the values to be passed to the template |
| 308 // when creating the HTML. | 246 // when creating the HTML. |
| 309 void PopulateMalwareLoadTimeData(base::DictionaryValue* load_time_data); | 247 void PopulateMalwareLoadTimeData(base::DictionaryValue* load_time_data); |
| 310 void PopulatePhishingLoadTimeData(base::DictionaryValue* load_time_data); | 248 void PopulatePhishingLoadTimeData(base::DictionaryValue* load_time_data); |
| 311 | 249 |
| 312 // For the M37 FieldTrial: this contains the name of the condition. | |
| 313 std::string trial_condition_; | |
| 314 | |
| 315 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageV3); | 250 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageV3); |
| 316 }; | 251 }; |
| 317 | 252 |
| 318 // Factory for creating SafeBrowsingBlockingPage. Useful for tests. | 253 // Factory for creating SafeBrowsingBlockingPage. Useful for tests. |
| 319 class SafeBrowsingBlockingPageFactory { | 254 class SafeBrowsingBlockingPageFactory { |
| 320 public: | 255 public: |
| 321 virtual ~SafeBrowsingBlockingPageFactory() { } | 256 virtual ~SafeBrowsingBlockingPageFactory() { } |
| 322 | 257 |
| 323 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( | 258 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( |
| 324 SafeBrowsingUIManager* ui_manager, | 259 SafeBrowsingUIManager* ui_manager, |
| 325 content::WebContents* web_contents, | 260 content::WebContents* web_contents, |
| 326 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) = 0; | 261 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) = 0; |
| 327 }; | 262 }; |
| 328 | 263 |
| 329 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ | 264 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ |
| OLD | NEW |