| 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 18 matching lines...) Expand all Loading... |
| 29 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ | 29 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ |
| 30 | 30 |
| 31 #include <map> | 31 #include <map> |
| 32 #include <string> | 32 #include <string> |
| 33 #include <vector> | 33 #include <vector> |
| 34 | 34 |
| 35 #include "base/gtest_prod_util.h" | 35 #include "base/gtest_prod_util.h" |
| 36 #include "base/task/cancelable_task_tracker.h" | 36 #include "base/task/cancelable_task_tracker.h" |
| 37 #include "base/time/time.h" | 37 #include "base/time/time.h" |
| 38 #include "chrome/browser/history/history_service.h" | 38 #include "chrome/browser/history/history_service.h" |
| 39 #include "chrome/browser/interstitials/security_interstitial_page.h" |
| 39 #include "chrome/browser/safe_browsing/ui_manager.h" | 40 #include "chrome/browser/safe_browsing/ui_manager.h" |
| 40 #include "content/public/browser/interstitial_page_delegate.h" | |
| 41 #include "url/gurl.h" | 41 #include "url/gurl.h" |
| 42 | 42 |
| 43 class MalwareDetails; | 43 class MalwareDetails; |
| 44 class SafeBrowsingBlockingPageFactory; | 44 class SafeBrowsingBlockingPageFactory; |
| 45 | 45 |
| 46 namespace base { | 46 namespace base { |
| 47 class DictionaryValue; | |
| 48 class MessageLoop; | 47 class MessageLoop; |
| 49 } | 48 } |
| 50 | 49 |
| 51 namespace content { | |
| 52 class InterstitialPage; | |
| 53 class WebContents; | |
| 54 } | |
| 55 | |
| 56 #if defined(ENABLE_EXTENSIONS) | 50 #if defined(ENABLE_EXTENSIONS) |
| 57 namespace extensions { | 51 namespace extensions { |
| 58 class ExperienceSamplingEvent; | 52 class ExperienceSamplingEvent; |
| 59 } | 53 } |
| 60 #endif | 54 #endif |
| 61 | 55 |
| 62 class SafeBrowsingBlockingPage : public content::InterstitialPageDelegate { | 56 class SafeBrowsingBlockingPage : public SecurityInterstitialPage { |
| 63 public: | 57 public: |
| 64 typedef SafeBrowsingUIManager::UnsafeResource UnsafeResource; | 58 typedef SafeBrowsingUIManager::UnsafeResource UnsafeResource; |
| 65 typedef std::vector<UnsafeResource> UnsafeResourceList; | 59 typedef std::vector<UnsafeResource> UnsafeResourceList; |
| 66 typedef std::map<content::WebContents*, UnsafeResourceList> UnsafeResourceMap; | 60 typedef std::map<content::WebContents*, UnsafeResourceList> UnsafeResourceMap; |
| 67 | 61 |
| 62 // Interstitial type, used in tests. |
| 63 static const void* kTypeForTesting; |
| 64 |
| 68 ~SafeBrowsingBlockingPage() override; | 65 ~SafeBrowsingBlockingPage() override; |
| 69 | 66 |
| 70 // Creates a blocking page. Use ShowBlockingPage if you don't need to access | 67 // Creates a blocking page. Use ShowBlockingPage if you don't need to access |
| 71 // the blocking page directly. | 68 // the blocking page directly. |
| 72 static SafeBrowsingBlockingPage* CreateBlockingPage( | 69 static SafeBrowsingBlockingPage* CreateBlockingPage( |
| 73 SafeBrowsingUIManager* ui_manager, | 70 SafeBrowsingUIManager* ui_manager, |
| 74 content::WebContents* web_contents, | 71 content::WebContents* web_contents, |
| 75 const UnsafeResource& unsafe_resource); | 72 const UnsafeResource& unsafe_resource); |
| 76 | 73 |
| 77 // Shows a blocking page warning the user about phishing/malware for a | 74 // Shows a blocking page warning the user about phishing/malware for a |
| 78 // specific resource. | 75 // specific resource. |
| 79 // You can call this method several times, if an interstitial is already | 76 // You can call this method several times, if an interstitial is already |
| 80 // showing, the new one will be queued and displayed if the user decides | 77 // showing, the new one will be queued and displayed if the user decides |
| 81 // to proceed on the currently showing interstitial. | 78 // to proceed on the currently showing interstitial. |
| 82 static void ShowBlockingPage( | 79 static void ShowBlockingPage( |
| 83 SafeBrowsingUIManager* ui_manager, const UnsafeResource& resource); | 80 SafeBrowsingUIManager* ui_manager, const UnsafeResource& resource); |
| 84 | 81 |
| 85 // Makes the passed |factory| the factory used to instantiate | 82 // Makes the passed |factory| the factory used to instantiate |
| 86 // SafeBrowsingBlockingPage objects. Useful for tests. | 83 // SafeBrowsingBlockingPage objects. Useful for tests. |
| 87 static void RegisterFactory(SafeBrowsingBlockingPageFactory* factory) { | 84 static void RegisterFactory(SafeBrowsingBlockingPageFactory* factory) { |
| 88 factory_ = factory; | 85 factory_ = factory; |
| 89 } | 86 } |
| 90 | 87 |
| 91 // InterstitialPageDelegate method: | 88 // InterstitialPageDelegate method: |
| 92 std::string GetHTMLContents() override; | |
| 93 void OnProceed() override; | 89 void OnProceed() override; |
| 94 void OnDontProceed() override; | 90 void OnDontProceed() override; |
| 95 void CommandReceived(const std::string& command) override; | 91 void CommandReceived(const std::string& command) override; |
| 96 void OverrideRendererPrefs(content::RendererPreferences* prefs) override; | 92 void OverrideRendererPrefs(content::RendererPreferences* prefs) override; |
| 97 | 93 |
| 94 // SecurityInterstitialPage method: |
| 95 const void* GetTypeForTesting() const override; |
| 96 |
| 98 protected: | 97 protected: |
| 99 friend class SafeBrowsingBlockingPageTest; | 98 friend class SafeBrowsingBlockingPageTest; |
| 100 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | 99 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
| 101 ProceedThenDontProceed); | 100 ProceedThenDontProceed); |
| 102 | |
| 103 void DontCreateViewForTesting(); | |
| 104 void Show(); | |
| 105 void SetReportingPreference(bool report); | 101 void SetReportingPreference(bool report); |
| 106 void UpdateReportingPref(); // Used for the transition from old to new pref. | 102 void UpdateReportingPref(); // Used for the transition from old to new pref. |
| 107 | 103 |
| 108 // Don't instantiate this class directly, use ShowBlockingPage instead. | 104 // Don't instantiate this class directly, use ShowBlockingPage instead. |
| 109 SafeBrowsingBlockingPage(SafeBrowsingUIManager* ui_manager, | 105 SafeBrowsingBlockingPage(SafeBrowsingUIManager* ui_manager, |
| 110 content::WebContents* web_contents, | 106 content::WebContents* web_contents, |
| 111 const UnsafeResourceList& unsafe_resources); | 107 const UnsafeResourceList& unsafe_resources); |
| 112 | 108 |
| 109 // SecurityInterstitialPage methods: |
| 110 bool ShouldCreateNewNavigation() const override; |
| 111 void PopulateInterstitialStrings( |
| 112 base::DictionaryValue* load_time_data) override; |
| 113 |
| 113 // After a malware interstitial where the user opted-in to the | 114 // After a malware interstitial where the user opted-in to the |
| 114 // report but clicked "proceed anyway", we delay the call to | 115 // report but clicked "proceed anyway", we delay the call to |
| 115 // MalwareDetails::FinishCollection() by this much time (in | 116 // MalwareDetails::FinishCollection() by this much time (in |
| 116 // milliseconds), in order to get data from the blocked resource itself. | 117 // milliseconds), in order to get data from the blocked resource itself. |
| 117 int64 malware_details_proceed_delay_ms_; | 118 int64 malware_details_proceed_delay_ms_; |
| 118 content::InterstitialPage* interstitial_page() const { | |
| 119 return interstitial_page_; | |
| 120 } | |
| 121 | 119 |
| 122 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | 120 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
| 123 MalwareReportsTransitionDisabled); | 121 MalwareReportsTransitionDisabled); |
| 124 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | 122 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
| 125 MalwareReportsToggling); | 123 MalwareReportsToggling); |
| 126 | 124 |
| 127 // These enums are used for histograms. Don't reorder, delete, or insert | 125 // These enums are used for histograms. Don't reorder, delete, or insert |
| 128 // elements. New elements should be added before MAX_ACTION only. | 126 // elements. New elements should be added before MAX_ACTION only. |
| 129 enum Decision { | 127 enum Decision { |
| 130 SHOW, | 128 SHOW, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 // The list of unsafe resources this page is warning about. | 196 // The list of unsafe resources this page is warning about. |
| 199 UnsafeResourceList unsafe_resources_; | 197 UnsafeResourceList unsafe_resources_; |
| 200 | 198 |
| 201 // A MalwareDetails object that we start generating when the | 199 // A MalwareDetails object that we start generating when the |
| 202 // blocking page is shown. The object will be sent when the warning | 200 // blocking page is shown. The object will be sent when the warning |
| 203 // is gone (if the user enables the feature). | 201 // is gone (if the user enables the feature). |
| 204 scoped_refptr<MalwareDetails> malware_details_; | 202 scoped_refptr<MalwareDetails> malware_details_; |
| 205 | 203 |
| 206 bool proceeded_; | 204 bool proceeded_; |
| 207 | 205 |
| 208 content::WebContents* web_contents_; | |
| 209 GURL url_; | |
| 210 content::InterstitialPage* interstitial_page_; // Owns us | |
| 211 | |
| 212 // Whether the interstitial should create a view. | |
| 213 bool create_view_; | |
| 214 | |
| 215 // Which type of interstitial this is. | 206 // Which type of interstitial this is. |
| 216 enum { | 207 enum { |
| 217 TYPE_MALWARE, | 208 TYPE_MALWARE, |
| 218 TYPE_HARMFUL, | 209 TYPE_HARMFUL, |
| 219 TYPE_PHISHING, | 210 TYPE_PHISHING, |
| 220 } interstitial_type_; | 211 } interstitial_type_; |
| 221 | 212 |
| 222 // The factory used to instantiate SafeBrowsingBlockingPage objects. | 213 // The factory used to instantiate SafeBrowsingBlockingPage objects. |
| 223 // Usefull for tests, so they can provide their own implementation of | 214 // Usefull for tests, so they can provide their own implementation of |
| 224 // SafeBrowsingBlockingPage. | 215 // SafeBrowsingBlockingPage. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 247 public: | 238 public: |
| 248 virtual ~SafeBrowsingBlockingPageFactory() { } | 239 virtual ~SafeBrowsingBlockingPageFactory() { } |
| 249 | 240 |
| 250 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( | 241 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( |
| 251 SafeBrowsingUIManager* ui_manager, | 242 SafeBrowsingUIManager* ui_manager, |
| 252 content::WebContents* web_contents, | 243 content::WebContents* web_contents, |
| 253 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) = 0; | 244 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) = 0; |
| 254 }; | 245 }; |
| 255 | 246 |
| 256 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ | 247 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ |
| OLD | NEW |