| 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 14 matching lines...) Expand all Loading... |
| 25 // decides to proceed in the first interstitial, we display all queued unsafe | 25 // decides to proceed in the first interstitial, we display all queued unsafe |
| 26 // resources in a new interstitial. | 26 // resources in a new interstitial. |
| 27 | 27 |
| 28 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ | 28 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ |
| 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 <stdint.h> | |
| 36 | |
| 37 #include "base/gtest_prod_util.h" | 35 #include "base/gtest_prod_util.h" |
| 38 #include "base/macros.h" | 36 #include "base/macros.h" |
| 39 #include "base/task/cancelable_task_tracker.h" | 37 #include "base/task/cancelable_task_tracker.h" |
| 40 #include "chrome/browser/interstitials/chrome_metrics_helper.h" | |
| 41 #include "chrome/browser/safe_browsing/ui_manager.h" | 38 #include "chrome/browser/safe_browsing/ui_manager.h" |
| 42 #include "components/security_interstitials/content/security_interstitial_page.h
" | 39 #include "components/safe_browsing/base_safe_browsing_blocking_page.h" |
| 43 #include "components/security_interstitials/core/safe_browsing_error_ui.h" | |
| 44 #include "content/public/browser/interstitial_page_delegate.h" | |
| 45 #include "url/gurl.h" | |
| 46 | 40 |
| 47 namespace safe_browsing { | 41 namespace safe_browsing { |
| 48 | 42 |
| 49 class SafeBrowsingBlockingPageFactory; | 43 class SafeBrowsingBlockingPageFactory; |
| 50 class ThreatDetails; | 44 class ThreatDetails; |
| 51 | 45 |
| 52 class SafeBrowsingBlockingPage | 46 class SafeBrowsingBlockingPage : public BaseSafeBrowsingBlockingPage { |
| 53 : public security_interstitials::SecurityInterstitialPage { | |
| 54 public: | 47 public: |
| 55 typedef security_interstitials::UnsafeResource UnsafeResource; | 48 typedef security_interstitials::UnsafeResource UnsafeResource; |
| 56 typedef security_interstitials::SafeBrowsingErrorUI SafeBrowsingErrorUI; | 49 typedef security_interstitials::SafeBrowsingErrorUI SafeBrowsingErrorUI; |
| 57 typedef std::vector<UnsafeResource> UnsafeResourceList; | 50 typedef std::vector<UnsafeResource> UnsafeResourceList; |
| 58 typedef std::map<content::WebContents*, UnsafeResourceList> UnsafeResourceMap; | 51 typedef std::map<content::WebContents*, UnsafeResourceList> UnsafeResourceMap; |
| 59 | 52 |
| 60 // Interstitial type, used in tests. | 53 // Interstitial type, used in tests. |
| 61 static content::InterstitialPageDelegate::TypeID kTypeForTesting; | 54 static content::InterstitialPageDelegate::TypeID kTypeForTesting; |
| 62 | 55 |
| 63 ~SafeBrowsingBlockingPage() override; | 56 ~SafeBrowsingBlockingPage() override; |
| 64 | 57 |
| 65 // Creates a blocking page. Use ShowBlockingPage if you don't need to access | 58 // Creates a blocking page. Use ShowBlockingPage if you don't need to access |
| 66 // the blocking page directly. | 59 // the blocking page directly. |
| 67 static SafeBrowsingBlockingPage* CreateBlockingPage( | 60 static SafeBrowsingBlockingPage* CreateBlockingPage( |
| 68 SafeBrowsingUIManager* ui_manager, | 61 BaseSafeBrowsingUIManager* ui_manager, |
| 69 content::WebContents* web_contents, | 62 content::WebContents* web_contents, |
| 70 const GURL& main_frame_url, | 63 const GURL& main_frame_url, |
| 71 const UnsafeResource& unsafe_resource); | 64 const UnsafeResource& unsafe_resource); |
| 72 | 65 |
| 73 // Shows a blocking page warning the user about phishing/malware for a | 66 // Shows a blocking page warning the user about phishing/malware for a |
| 74 // specific resource. | 67 // specific resource. |
| 75 // You can call this method several times, if an interstitial is already | 68 // You can call this method several times, if an interstitial is already |
| 76 // showing, the new one will be queued and displayed if the user decides | 69 // showing, the new one will be queued and displayed if the user decides |
| 77 // to proceed on the currently showing interstitial. | 70 // to proceed on the currently showing interstitial. |
| 78 static void ShowBlockingPage( | 71 static void ShowBlockingPage(BaseSafeBrowsingUIManager* ui_manager, |
| 79 SafeBrowsingUIManager* ui_manager, const UnsafeResource& resource); | 72 const UnsafeResource& resource); |
| 80 | 73 |
| 81 // Makes the passed |factory| the factory used to instantiate | 74 // Makes the passed |factory| the factory used to instantiate |
| 82 // SafeBrowsingBlockingPage objects. Useful for tests. | 75 // SafeBrowsingBlockingPage objects. Useful for tests. |
| 83 static void RegisterFactory(SafeBrowsingBlockingPageFactory* factory) { | 76 static void RegisterFactory(SafeBrowsingBlockingPageFactory* factory) { |
| 84 factory_ = factory; | 77 factory_ = factory; |
| 85 } | 78 } |
| 86 | 79 |
| 87 // InterstitialPageDelegate method: | 80 // InterstitialPageDelegate method: |
| 88 void OnProceed() override; | 81 void OnProceed() override; |
| 89 void OnDontProceed() override; | |
| 90 void CommandReceived(const std::string& command) override; | |
| 91 void OverrideRendererPrefs(content::RendererPreferences* prefs) override; | 82 void OverrideRendererPrefs(content::RendererPreferences* prefs) override; |
| 92 content::InterstitialPageDelegate::TypeID GetTypeForTesting() const override; | 83 content::InterstitialPageDelegate::TypeID GetTypeForTesting() const override; |
| 93 | 84 |
| 94 // Checks the threat type to decide if we should report ThreatDetails. | 85 // Checks the threat type to decide if we should report ThreatDetails. |
| 95 static bool ShouldReportThreatDetails(SBThreatType threat_type); | 86 static bool ShouldReportThreatDetails(SBThreatType threat_type); |
| 96 | 87 |
| 97 protected: | 88 protected: |
| 98 friend class SafeBrowsingBlockingPageFactoryImpl; | 89 friend class SafeBrowsingBlockingPageFactoryImpl; |
| 99 friend class SafeBrowsingBlockingPageTest; | 90 friend class SafeBrowsingBlockingPageTest; |
| 100 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | 91 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
| 101 ProceedThenDontProceed); | 92 ProceedThenDontProceed); |
| 102 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | 93 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
| 103 MalwareReportsDisabled); | 94 MalwareReportsDisabled); |
| 104 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | 95 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
| 105 MalwareReportsToggling); | 96 MalwareReportsToggling); |
| 106 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | 97 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
| 107 ExtendedReportingNotShownOnSecurePage); | 98 ExtendedReportingNotShownOnSecurePage); |
| 108 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | 99 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
| 109 MalwareReportsTransitionDisabled); | 100 MalwareReportsTransitionDisabled); |
| 110 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | 101 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
| 111 ExtendedReportingNotShownInIncognito); | 102 ExtendedReportingNotShownInIncognito); |
| 112 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | 103 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
| 113 ExtendedReportingNotShownNotAllowExtendedReporting); | 104 ExtendedReportingNotShownNotAllowExtendedReporting); |
| 114 | 105 |
| 115 void UpdateReportingPref(); // Used for the transition from old to new pref. | 106 void UpdateReportingPref(); // Used for the transition from old to new pref. |
| 116 | 107 |
| 117 // Don't instantiate this class directly, use ShowBlockingPage instead. | 108 // Don't instantiate this class directly, use ShowBlockingPage instead. |
| 118 SafeBrowsingBlockingPage(SafeBrowsingUIManager* ui_manager, | 109 SafeBrowsingBlockingPage( |
| 119 content::WebContents* web_contents, | 110 BaseSafeBrowsingUIManager* ui_manager, |
| 120 const GURL& main_frame_url, | 111 content::WebContents* web_contents, |
| 121 const UnsafeResourceList& unsafe_resources); | 112 const GURL& main_frame_url, |
| 122 | 113 const UnsafeResourceList& unsafe_resources, |
| 123 // SecurityInterstitialPage methods: | 114 SafeBrowsingErrorUI::SBErrorDisplayOptions* display_options); |
| 124 bool ShouldCreateNewNavigation() const override; | |
| 125 void PopulateInterstitialStrings( | |
| 126 base::DictionaryValue* load_time_data) override; | |
| 127 | 115 |
| 128 // After a safe browsing interstitial where the user opted-in to the | 116 // After a safe browsing interstitial where the user opted-in to the |
| 129 // report but clicked "proceed anyway", we delay the call to | 117 // report but clicked "proceed anyway", we delay the call to |
| 130 // ThreatDetails::FinishCollection() by this much time (in | 118 // ThreatDetails::FinishCollection() by this much time (in |
| 131 // milliseconds), in order to get data from the blocked resource itself. | 119 // milliseconds), in order to get data from the blocked resource itself. |
| 132 int64_t threat_details_proceed_delay_ms_; | 120 int64_t threat_details_proceed_delay_ms_; |
| 133 | 121 |
| 134 // Called when the interstitial is going away. If there is a | 122 // Called when the interstitial is going away. If there is a |
| 135 // pending threat details object, we look at the user's | 123 // pending threat details object, we look at the user's |
| 136 // preferences, and if the option to send threat details is | 124 // preferences, and if the option to send threat details is |
| 137 // enabled, the report is scheduled to be sent on the |ui_manager_|. | 125 // enabled, the report is scheduled to be sent on the |ui_manager_|. |
| 138 void FinishThreatDetails(int64_t delay_ms, bool did_proceed, int num_visits); | 126 void FinishThreatDetails(int64_t delay_ms, |
| 139 | 127 bool did_proceed, |
| 140 // A list of SafeBrowsingUIManager::UnsafeResource for a tab that the user | 128 int num_visits) override; |
| 141 // should be warned about. They are queued when displaying more than one | |
| 142 // interstitial at a time. | |
| 143 static UnsafeResourceMap* GetUnsafeResourcesMap(); | |
| 144 | |
| 145 // Returns true if the passed |unsafe_resources| is blocking the load of | |
| 146 // the main page. | |
| 147 static bool IsMainPageLoadBlocked( | |
| 148 const UnsafeResourceList& unsafe_resources); | |
| 149 | |
| 150 // For reporting back user actions. | |
| 151 SafeBrowsingUIManager* ui_manager_; | |
| 152 | |
| 153 // For displaying safe browsing interstitial. | |
| 154 std::unique_ptr<SafeBrowsingErrorUI> sb_error_ui_; | |
| 155 | |
| 156 // The URL of the main frame that caused the warning. | |
| 157 GURL main_frame_url_; | |
| 158 | |
| 159 // The index of a navigation entry that should be removed when DontProceed() | |
| 160 // is invoked, -1 if not entry should be removed. | |
| 161 int navigation_entry_index_to_remove_; | |
| 162 | |
| 163 // The list of unsafe resources this page is warning about. | |
| 164 UnsafeResourceList unsafe_resources_; | |
| 165 | 129 |
| 166 // A ThreatDetails object that we start generating when the | 130 // A ThreatDetails object that we start generating when the |
| 167 // blocking page is shown. The object will be sent when the warning | 131 // blocking page is shown. The object will be sent when the warning |
| 168 // is gone (if the user enables the feature). | 132 // is gone (if the user enables the feature). |
| 169 scoped_refptr<ThreatDetails> threat_details_; | 133 scoped_refptr<ThreatDetails> threat_details_; |
| 170 | 134 |
| 171 bool proceeded_; | |
| 172 | |
| 173 // Which type of Safe Browsing interstitial this is. | |
| 174 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason_; | |
| 175 | |
| 176 // The factory used to instantiate SafeBrowsingBlockingPage objects. | 135 // The factory used to instantiate SafeBrowsingBlockingPage objects. |
| 177 // Useful for tests, so they can provide their own implementation of | 136 // Useful for tests, so they can provide their own implementation of |
| 178 // SafeBrowsingBlockingPage. | 137 // SafeBrowsingBlockingPage. |
| 179 static SafeBrowsingBlockingPageFactory* factory_; | 138 static SafeBrowsingBlockingPageFactory* factory_; |
| 180 | 139 |
| 181 private: | 140 private: |
| 182 static std::string GetMetricPrefix( | |
| 183 const UnsafeResourceList& unsafe_resources, | |
| 184 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason); | |
| 185 static std::string GetExtraMetricsSuffix( | |
| 186 const UnsafeResourceList& unsafe_resources); | |
| 187 static std::string GetSamplingEventName( | 141 static std::string GetSamplingEventName( |
| 188 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason); | 142 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason); |
| 189 | 143 |
| 190 static SafeBrowsingErrorUI::SBInterstitialReason GetInterstitialReason( | 144 static std::unique_ptr< |
| 191 const UnsafeResourceList& unsafe_resources); | 145 security_interstitials::SecurityInterstitialControllerClient> |
| 192 | 146 CreateControllerClient(content::WebContents* web_contents, |
| 193 std::unique_ptr<security_interstitials::SecurityInterstitialControllerClient> | 147 const UnsafeResourceList& unsafe_resources); |
| 194 CreateControllerClient( | |
| 195 content::WebContents* web_contents, | |
| 196 const UnsafeResourceList& unsafe_resources); | |
| 197 | 148 |
| 198 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPage); | 149 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPage); |
| 199 }; | 150 }; |
| 200 | 151 |
| 201 // Factory for creating SafeBrowsingBlockingPage. Useful for tests. | 152 // Factory for creating SafeBrowsingBlockingPage. Useful for tests. |
| 202 class SafeBrowsingBlockingPageFactory { | 153 class SafeBrowsingBlockingPageFactory { |
| 203 public: | 154 public: |
| 204 virtual ~SafeBrowsingBlockingPageFactory() { } | 155 virtual ~SafeBrowsingBlockingPageFactory() { } |
| 205 | 156 |
| 206 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( | 157 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( |
| 207 SafeBrowsingUIManager* ui_manager, | 158 BaseSafeBrowsingUIManager* ui_manager, |
| 208 content::WebContents* web_contents, | 159 content::WebContents* web_contents, |
| 209 const GURL& main_frame_url, | 160 const GURL& main_frame_url, |
| 210 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) = 0; | 161 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) = 0; |
| 211 }; | 162 }; |
| 212 | 163 |
| 213 } // namespace safe_browsing | 164 } // namespace safe_browsing |
| 214 | 165 |
| 215 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ | 166 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ |
| OLD | NEW |