| 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 20 matching lines...) Expand all Loading... |
| 31 #include <map> | 31 #include <map> |
| 32 #include <string> | 32 #include <string> |
| 33 #include <vector> | 33 #include <vector> |
| 34 | 34 |
| 35 #include <stdint.h> | 35 #include <stdint.h> |
| 36 | 36 |
| 37 #include "base/gtest_prod_util.h" | 37 #include "base/gtest_prod_util.h" |
| 38 #include "base/macros.h" | 38 #include "base/macros.h" |
| 39 #include "base/task/cancelable_task_tracker.h" | 39 #include "base/task/cancelable_task_tracker.h" |
| 40 #include "chrome/browser/interstitials/chrome_metrics_helper.h" | 40 #include "chrome/browser/interstitials/chrome_metrics_helper.h" |
| 41 #include "chrome/browser/interstitials/security_interstitial_page.h" | |
| 42 #include "chrome/browser/safe_browsing/ui_manager.h" | 41 #include "chrome/browser/safe_browsing/ui_manager.h" |
| 42 #include "components/security_interstitials/content/security_interstitial_page.h
" |
| 43 #include "components/security_interstitials/core/safe_browsing_error_ui.h" | 43 #include "components/security_interstitials/core/safe_browsing_error_ui.h" |
| 44 #include "content/public/browser/interstitial_page_delegate.h" | 44 #include "content/public/browser/interstitial_page_delegate.h" |
| 45 #include "url/gurl.h" | 45 #include "url/gurl.h" |
| 46 | 46 |
| 47 namespace safe_browsing { | 47 namespace safe_browsing { |
| 48 | 48 |
| 49 class SafeBrowsingBlockingPageFactory; | 49 class SafeBrowsingBlockingPageFactory; |
| 50 class ThreatDetails; | 50 class ThreatDetails; |
| 51 | 51 |
| 52 class SafeBrowsingBlockingPage : public SecurityInterstitialPage { | 52 class SafeBrowsingBlockingPage |
| 53 : public security_interstitials::SecurityInterstitialPage { |
| 53 public: | 54 public: |
| 54 typedef security_interstitials::UnsafeResource UnsafeResource; | 55 typedef security_interstitials::UnsafeResource UnsafeResource; |
| 55 typedef security_interstitials::SafeBrowsingErrorUI SafeBrowsingErrorUI; | 56 typedef security_interstitials::SafeBrowsingErrorUI SafeBrowsingErrorUI; |
| 56 typedef std::vector<UnsafeResource> UnsafeResourceList; | 57 typedef std::vector<UnsafeResource> UnsafeResourceList; |
| 57 typedef std::map<content::WebContents*, UnsafeResourceList> UnsafeResourceMap; | 58 typedef std::map<content::WebContents*, UnsafeResourceList> UnsafeResourceMap; |
| 58 | 59 |
| 59 // Interstitial type, used in tests. | 60 // Interstitial type, used in tests. |
| 60 static content::InterstitialPageDelegate::TypeID kTypeForTesting; | 61 static content::InterstitialPageDelegate::TypeID kTypeForTesting; |
| 61 | 62 |
| 62 ~SafeBrowsingBlockingPage() override; | 63 ~SafeBrowsingBlockingPage() override; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 bool ShouldCreateNewNavigation() const override; | 124 bool ShouldCreateNewNavigation() const override; |
| 124 void PopulateInterstitialStrings( | 125 void PopulateInterstitialStrings( |
| 125 base::DictionaryValue* load_time_data) override; | 126 base::DictionaryValue* load_time_data) override; |
| 126 | 127 |
| 127 // After a safe browsing interstitial where the user opted-in to the | 128 // After a safe browsing interstitial where the user opted-in to the |
| 128 // report but clicked "proceed anyway", we delay the call to | 129 // report but clicked "proceed anyway", we delay the call to |
| 129 // ThreatDetails::FinishCollection() by this much time (in | 130 // ThreatDetails::FinishCollection() by this much time (in |
| 130 // milliseconds), in order to get data from the blocked resource itself. | 131 // milliseconds), in order to get data from the blocked resource itself. |
| 131 int64_t threat_details_proceed_delay_ms_; | 132 int64_t threat_details_proceed_delay_ms_; |
| 132 | 133 |
| 133 // Checks if we should even show the extended reporting option. We don't show | |
| 134 // it in incognito mode or if kSafeBrowsingExtendedReportingOptInAllowed | |
| 135 // preference is disabled. | |
| 136 bool CanShowExtendedReportingOption(); | |
| 137 | |
| 138 // Called when the insterstitial is going away. If there is a | 134 // Called when the insterstitial is going away. If there is a |
| 139 // pending threat details object, we look at the user's | 135 // pending threat details object, we look at the user's |
| 140 // preferences, and if the option to send threat details is | 136 // preferences, and if the option to send threat details is |
| 141 // enabled, the report is scheduled to be sent on the |ui_manager_|. | 137 // enabled, the report is scheduled to be sent on the |ui_manager_|. |
| 142 void FinishThreatDetails(int64_t delay_ms, bool did_proceed, int num_visits); | 138 void FinishThreatDetails(int64_t delay_ms, bool did_proceed, int num_visits); |
| 143 | 139 |
| 144 // A list of SafeBrowsingUIManager::UnsafeResource for a tab that the user | 140 // A list of SafeBrowsingUIManager::UnsafeResource for a tab that the user |
| 145 // should be warned about. They are queued when displaying more than one | 141 // should be warned about. They are queued when displaying more than one |
| 146 // interstitial at a time. | 142 // interstitial at a time. |
| 147 static UnsafeResourceMap* GetUnsafeResourcesMap(); | 143 static UnsafeResourceMap* GetUnsafeResourcesMap(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 const UnsafeResourceList& unsafe_resources, | 183 const UnsafeResourceList& unsafe_resources, |
| 188 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason); | 184 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason); |
| 189 static std::string GetExtraMetricsSuffix( | 185 static std::string GetExtraMetricsSuffix( |
| 190 const UnsafeResourceList& unsafe_resources); | 186 const UnsafeResourceList& unsafe_resources); |
| 191 static std::string GetSamplingEventName( | 187 static std::string GetSamplingEventName( |
| 192 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason); | 188 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason); |
| 193 | 189 |
| 194 static SafeBrowsingErrorUI::SBInterstitialReason GetInterstitialReason( | 190 static SafeBrowsingErrorUI::SBInterstitialReason GetInterstitialReason( |
| 195 const UnsafeResourceList& unsafe_resources); | 191 const UnsafeResourceList& unsafe_resources); |
| 196 | 192 |
| 197 static std::unique_ptr<ChromeMetricsHelper> CreateMetricsHelper( | 193 std::unique_ptr<security_interstitials::SecurityInterstitialControllerClient> |
| 194 CreateControllerClient( |
| 198 content::WebContents* web_contents, | 195 content::WebContents* web_contents, |
| 199 const UnsafeResourceList& unsafe_resources); | 196 const UnsafeResourceList& unsafe_resources); |
| 200 | 197 |
| 201 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPage); | 198 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPage); |
| 202 }; | 199 }; |
| 203 | 200 |
| 204 // Factory for creating SafeBrowsingBlockingPage. Useful for tests. | 201 // Factory for creating SafeBrowsingBlockingPage. Useful for tests. |
| 205 class SafeBrowsingBlockingPageFactory { | 202 class SafeBrowsingBlockingPageFactory { |
| 206 public: | 203 public: |
| 207 virtual ~SafeBrowsingBlockingPageFactory() { } | 204 virtual ~SafeBrowsingBlockingPageFactory() { } |
| 208 | 205 |
| 209 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( | 206 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( |
| 210 SafeBrowsingUIManager* ui_manager, | 207 SafeBrowsingUIManager* ui_manager, |
| 211 content::WebContents* web_contents, | 208 content::WebContents* web_contents, |
| 212 const GURL& main_frame_url, | 209 const GURL& main_frame_url, |
| 213 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) = 0; | 210 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) = 0; |
| 214 }; | 211 }; |
| 215 | 212 |
| 216 } // namespace safe_browsing | 213 } // namespace safe_browsing |
| 217 | 214 |
| 218 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ | 215 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ |
| OLD | NEW |