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