| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 SafeBrowsingService* service, | 67 SafeBrowsingService* service, |
| 68 const SafeBrowsingService::UnsafeResource& resource); | 68 const SafeBrowsingService::UnsafeResource& resource); |
| 69 | 69 |
| 70 // Makes the passed |factory| the factory used to instanciate | 70 // Makes the passed |factory| the factory used to instanciate |
| 71 // SafeBrowsingBlockingPage objects. Usefull for tests. | 71 // SafeBrowsingBlockingPage objects. Usefull for tests. |
| 72 static void RegisterFactory(SafeBrowsingBlockingPageFactory* factory) { | 72 static void RegisterFactory(SafeBrowsingBlockingPageFactory* factory) { |
| 73 factory_ = factory; | 73 factory_ = factory; |
| 74 } | 74 } |
| 75 | 75 |
| 76 // InterstitialPageDelegate method: | 76 // InterstitialPageDelegate method: |
| 77 virtual std::string GetHTMLContents() OVERRIDE; | |
| 78 virtual void CommandReceived(const std::string& command) OVERRIDE; | 77 virtual void CommandReceived(const std::string& command) OVERRIDE; |
| 79 virtual void OverrideRendererPrefs( | 78 virtual void OverrideRendererPrefs( |
| 80 content::RendererPreferences* prefs) OVERRIDE; | 79 content::RendererPreferences* prefs) OVERRIDE; |
| 81 virtual void OnProceed() OVERRIDE; | 80 virtual void OnProceed() OVERRIDE; |
| 82 virtual void OnDontProceed() OVERRIDE; | 81 virtual void OnDontProceed() OVERRIDE; |
| 83 | 82 |
| 84 protected: | 83 protected: |
| 85 friend class SafeBrowsingBlockingPageTest; | 84 friend class SafeBrowsingBlockingPageTest; |
| 86 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | 85 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
| 87 ProceedThenDontProceed); | 86 ProceedThenDontProceed); |
| 87 friend class SafeBrowsingBlockingPageV2Test; |
| 88 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageV2Test, |
| 89 ProceedThenDontProceed); |
| 88 | 90 |
| 89 void SetReportingPreference(bool report); | 91 void SetReportingPreference(bool report); |
| 90 | 92 |
| 91 // Don't instanciate this class directly, use ShowBlockingPage instead. | 93 // Don't instanciate this class directly, use ShowBlockingPage instead. |
| 92 SafeBrowsingBlockingPage(SafeBrowsingService* service, | 94 SafeBrowsingBlockingPage(SafeBrowsingService* service, |
| 93 content::WebContents* web_contents, | 95 content::WebContents* web_contents, |
| 94 const UnsafeResourceList& unsafe_resources); | 96 const UnsafeResourceList& unsafe_resources); |
| 95 | 97 |
| 96 // After a malware interstitial where the user opted-in to the | 98 // After a malware interstitial where the user opted-in to the |
| 97 // report but clicked "proceed anyway", we delay the call to | 99 // report but clicked "proceed anyway", we delay the call to |
| 98 // MalwareDetails::FinishCollection() by this much time (in | 100 // MalwareDetails::FinishCollection() by this much time (in |
| 99 // milliseconds), in order to get data from the blocked resource itself. | 101 // milliseconds), in order to get data from the blocked resource itself. |
| 100 int64 malware_details_proceed_delay_ms_; | 102 int64 malware_details_proceed_delay_ms_; |
| 101 content::InterstitialPage* interstitial_page() const { | 103 content::InterstitialPage* interstitial_page() const { |
| 102 return interstitial_page_; | 104 return interstitial_page_; |
| 103 } | 105 } |
| 104 | 106 |
| 105 private: | |
| 106 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, MalwareReports); | 107 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, MalwareReports); |
| 108 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageV2Test, MalwareReports); |
| 107 | 109 |
| 108 enum BlockingPageEvent { | 110 enum BlockingPageEvent { |
| 109 SHOW, | 111 SHOW, |
| 110 PROCEED, | 112 PROCEED, |
| 111 DONT_PROCEED, | 113 DONT_PROCEED, |
| 112 }; | 114 }; |
| 113 | 115 |
| 114 // Fills the passed dictionary with the strings passed to JS Template when | |
| 115 // creating the HTML. | |
| 116 void PopulateMultipleThreatStringDictionary(base::DictionaryValue* strings); | |
| 117 void PopulateMalwareStringDictionary(base::DictionaryValue* strings); | |
| 118 void PopulatePhishingStringDictionary(base::DictionaryValue* strings); | |
| 119 | |
| 120 // A helper method used by the Populate methods above used to populate common | |
| 121 // fields. | |
| 122 void PopulateStringDictionary(base::DictionaryValue* strings, | |
| 123 const string16& title, | |
| 124 const string16& headline, | |
| 125 const string16& description1, | |
| 126 const string16& description2, | |
| 127 const string16& description3); | |
| 128 | |
| 129 // Records a user action for this interstitial, using the form | 116 // Records a user action for this interstitial, using the form |
| 130 // SBInterstitial[Phishing|Malware|Multiple][Show|Proceed|DontProceed]. | 117 // SBInterstitial[Phishing|Malware|Multiple][Show|Proceed|DontProceed]. |
| 131 void RecordUserAction(BlockingPageEvent event); | 118 void RecordUserAction(BlockingPageEvent event); |
| 132 | 119 |
| 133 // Records the time it took for the user to react to the | 120 // Records the time it took for the user to react to the |
| 134 // interstitial. We won't double-count if this method is called | 121 // interstitial. We won't double-count if this method is called |
| 135 // multiple times. | 122 // multiple times. |
| 136 void RecordUserReactionTime(const std::string& command); | 123 void RecordUserReactionTime(const std::string& command); |
| 137 | 124 |
| 138 // Checks if we should even show the malware details option. For example, we | 125 // Checks if we should even show the malware details option. For example, we |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 180 |
| 194 content::WebContents* web_contents_; | 181 content::WebContents* web_contents_; |
| 195 GURL url_; | 182 GURL url_; |
| 196 content::InterstitialPage* interstitial_page_; // Owns us | 183 content::InterstitialPage* interstitial_page_; // Owns us |
| 197 | 184 |
| 198 // Time when the interstitial was show. This variable is set in | 185 // Time when the interstitial was show. This variable is set in |
| 199 // GetHTMLContents() which is called right before the interstitial | 186 // GetHTMLContents() which is called right before the interstitial |
| 200 // is shown to the user. Will return is_null() once we reported the | 187 // is shown to the user. Will return is_null() once we reported the |
| 201 // user action. | 188 // user action. |
| 202 base::TimeTicks interstitial_show_time_; | 189 base::TimeTicks interstitial_show_time_; |
| 203 // True if the interstitial that is shown is a malware interstitial | 190 |
| 204 // and false if it's a phishing interstitial. If it's a multi-threat | 191 // Whether the user has expanded the "see more" section of the page already |
| 205 // interstitial we'll say it's malware. | 192 // during this interstitial page. |
| 206 bool is_malware_interstitial_; | 193 bool has_expanded_see_more_section_; |
| 194 |
| 195 // Which type of interstitial this is. |
| 196 enum { |
| 197 TYPE_MALWARE, |
| 198 TYPE_PHISHING, |
| 199 TYPE_MALWARE_AND_PHISHING, |
| 200 } interstitial_type_; |
| 207 | 201 |
| 208 // The factory used to instanciate SafeBrowsingBlockingPage objects. | 202 // The factory used to instanciate SafeBrowsingBlockingPage objects. |
| 209 // Usefull for tests, so they can provide their own implementation of | 203 // Usefull for tests, so they can provide their own implementation of |
| 210 // SafeBrowsingBlockingPage. | 204 // SafeBrowsingBlockingPage. |
| 211 static SafeBrowsingBlockingPageFactory* factory_; | 205 static SafeBrowsingBlockingPageFactory* factory_; |
| 212 | 206 |
| 213 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPage); | 207 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPage); |
| 214 }; | 208 }; |
| 215 | 209 |
| 210 class SafeBrowsingBlockingPageV1 : public SafeBrowsingBlockingPage { |
| 211 public: |
| 212 // Don't instanciate this class directly, use ShowBlockingPage instead. |
| 213 SafeBrowsingBlockingPageV1(SafeBrowsingService* service, |
| 214 content::WebContents* web_contents, |
| 215 const UnsafeResourceList& unsafe_resources); |
| 216 |
| 217 // InterstitialPageDelegate method: |
| 218 virtual std::string GetHTMLContents() OVERRIDE; |
| 219 |
| 220 private: |
| 221 // Fills the passed dictionary with the strings passed to JS Template when |
| 222 // creating the HTML. |
| 223 void PopulateMultipleThreatStringDictionary(base::DictionaryValue* strings); |
| 224 void PopulateMalwareStringDictionary(base::DictionaryValue* strings); |
| 225 void PopulatePhishingStringDictionary(base::DictionaryValue* strings); |
| 226 |
| 227 // A helper method used by the Populate methods above used to populate common |
| 228 // fields. |
| 229 void PopulateStringDictionary(base::DictionaryValue* strings, |
| 230 const string16& title, |
| 231 const string16& headline, |
| 232 const string16& description1, |
| 233 const string16& description2, |
| 234 const string16& description3); |
| 235 |
| 236 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageV1); |
| 237 }; |
| 238 |
| 239 class SafeBrowsingBlockingPageV2 : public SafeBrowsingBlockingPage { |
| 240 public: |
| 241 // Don't instanciate this class directly, use ShowBlockingPage instead. |
| 242 SafeBrowsingBlockingPageV2(SafeBrowsingService* service, |
| 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 string16& title, |
| 260 const string16& headline, |
| 261 const string16& description1, |
| 262 const string16& description2, |
| 263 const string16& description3, |
| 264 const string16& description4); |
| 265 |
| 266 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageV2); |
| 267 }; |
| 268 |
| 216 // Factory for creating SafeBrowsingBlockingPage. Useful for tests. | 269 // Factory for creating SafeBrowsingBlockingPage. Useful for tests. |
| 217 class SafeBrowsingBlockingPageFactory { | 270 class SafeBrowsingBlockingPageFactory { |
| 218 public: | 271 public: |
| 219 virtual ~SafeBrowsingBlockingPageFactory() { } | 272 virtual ~SafeBrowsingBlockingPageFactory() { } |
| 220 | 273 |
| 221 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( | 274 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( |
| 222 SafeBrowsingService* service, | 275 SafeBrowsingService* service, |
| 223 content::WebContents* web_contents, | 276 content::WebContents* web_contents, |
| 224 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) = 0; | 277 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) = 0; |
| 225 }; | 278 }; |
| 226 | 279 |
| 227 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ | 280 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ |
| OLD | NEW |