| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #ifndef COMPONENTS_SAFE_BROWSING_BASE_BLOCKING_PAGE_H_ | 5 #ifndef COMPONENTS_SAFE_BROWSING_BASE_BLOCKING_PAGE_H_ |
| 6 #define COMPONENTS_SAFE_BROWSING_BASE_BLOCKING_PAGE_H_ | 6 #define COMPONENTS_SAFE_BROWSING_BASE_BLOCKING_PAGE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "components/safe_browsing/base_ui_manager.h" | 13 #include "components/safe_browsing/base_ui_manager.h" |
| 14 #include "components/security_interstitials/content/security_interstitial_page.h
" | 14 #include "components/security_interstitials/content/security_interstitial_page.h
" |
| 15 #include "components/security_interstitials/core/base_safe_browsing_error_ui.h" |
| 15 #include "components/security_interstitials/core/metrics_helper.h" | 16 #include "components/security_interstitials/core/metrics_helper.h" |
| 16 #include "components/security_interstitials/core/safe_browsing_error_ui.h" | |
| 17 #include "content/public/browser/interstitial_page_delegate.h" | 17 #include "content/public/browser/interstitial_page_delegate.h" |
| 18 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 19 | 19 |
| 20 namespace safe_browsing { | 20 namespace safe_browsing { |
| 21 | 21 |
| 22 // Base class for managing the SafeBrowsing interstitial pages. | 22 // Base class for managing the SafeBrowsing interstitial pages. |
| 23 class BaseBlockingPage | 23 class BaseBlockingPage |
| 24 : public security_interstitials::SecurityInterstitialPage { | 24 : public security_interstitials::SecurityInterstitialPage { |
| 25 public: | 25 public: |
| 26 typedef security_interstitials::UnsafeResource UnsafeResource; | 26 typedef security_interstitials::UnsafeResource UnsafeResource; |
| 27 typedef security_interstitials::SafeBrowsingErrorUI SafeBrowsingErrorUI; | 27 typedef security_interstitials::BaseSafeBrowsingErrorUI |
| 28 BaseSafeBrowsingErrorUI; |
| 28 typedef std::vector<UnsafeResource> UnsafeResourceList; | 29 typedef std::vector<UnsafeResource> UnsafeResourceList; |
| 29 typedef std::unordered_map<content::WebContents*, UnsafeResourceList> | 30 typedef std::unordered_map<content::WebContents*, UnsafeResourceList> |
| 30 UnsafeResourceMap; | 31 UnsafeResourceMap; |
| 31 | 32 |
| 32 ~BaseBlockingPage() override; | 33 ~BaseBlockingPage() override; |
| 33 | 34 |
| 34 static const SafeBrowsingErrorUI::SBErrorDisplayOptions | 35 static const BaseSafeBrowsingErrorUI::SBErrorDisplayOptions |
| 35 CreateDefaultDisplayOptions(const UnsafeResourceList& unsafe_resources); | 36 CreateDefaultDisplayOptions(const UnsafeResourceList& unsafe_resources); |
| 36 | 37 |
| 37 // Shows a blocking page warning the user about phishing/malware for a | 38 // Shows a blocking page warning the user about phishing/malware for a |
| 38 // specific resource. | 39 // specific resource. |
| 39 // This can be called several times. If an interstitial is already showing | 40 // This can be called several times. If an interstitial is already showing |
| 40 // and the user decides to proceed, it will be discarded and a new one will be | 41 // and the user decides to proceed, it will be discarded and a new one will be |
| 41 // displayed. | 42 // displayed. |
| 42 static void ShowBlockingPage(BaseUIManager* ui_manager, | 43 static void ShowBlockingPage(BaseUIManager* ui_manager, |
| 43 const UnsafeResource& resource); | 44 const UnsafeResource& resource); |
| 44 | 45 |
| 45 // Returns true if the passed |unsafe_resources| is blocking the load of | 46 // Returns true if the passed |unsafe_resources| is blocking the load of |
| 46 // the main page. | 47 // the main page. |
| 47 static bool IsMainPageLoadBlocked(const UnsafeResourceList& unsafe_resources); | 48 static bool IsMainPageLoadBlocked(const UnsafeResourceList& unsafe_resources); |
| 48 | 49 |
| 49 // InterstitialPageDelegate methods: | 50 // InterstitialPageDelegate methods: |
| 50 void OnProceed() override; | 51 void OnProceed() override; |
| 51 void OnDontProceed() override; | 52 void OnDontProceed() override; |
| 52 void CommandReceived(const std::string& command) override; | 53 void CommandReceived(const std::string& command) override; |
| 53 | 54 |
| 54 protected: | 55 protected: |
| 55 // Don't instantiate this class directly, use ShowBlockingPage instead. | 56 // Don't instantiate this class directly, use ShowBlockingPage instead. |
| 56 BaseBlockingPage( | 57 BaseBlockingPage( |
| 57 BaseUIManager* ui_manager, | 58 BaseUIManager* ui_manager, |
| 58 content::WebContents* web_contents, | 59 content::WebContents* web_contents, |
| 59 const GURL& main_frame_url, | 60 const GURL& main_frame_url, |
| 60 const UnsafeResourceList& unsafe_resources, | 61 const UnsafeResourceList& unsafe_resources, |
| 61 std::unique_ptr< | 62 std::unique_ptr< |
| 62 security_interstitials::SecurityInterstitialControllerClient> | 63 security_interstitials::SecurityInterstitialControllerClient> |
| 63 controller_client, | 64 controller_client, |
| 64 const SafeBrowsingErrorUI::SBErrorDisplayOptions& display_options); | 65 const BaseSafeBrowsingErrorUI::SBErrorDisplayOptions& display_options); |
| 65 | 66 |
| 66 // SecurityInterstitialPage methods: | 67 // SecurityInterstitialPage methods: |
| 67 bool ShouldCreateNewNavigation() const override; | 68 bool ShouldCreateNewNavigation() const override; |
| 68 void PopulateInterstitialStrings( | 69 void PopulateInterstitialStrings( |
| 69 base::DictionaryValue* load_time_data) override; | 70 base::DictionaryValue* load_time_data) override; |
| 70 | 71 |
| 71 // Called when the interstitial is going away. Intentionally do nothing in | 72 // Called when the interstitial is going away. Intentionally do nothing in |
| 72 // this base class. | 73 // this base class. |
| 73 virtual void FinishThreatDetails(const base::TimeDelta& delay, | 74 virtual void FinishThreatDetails(const base::TimeDelta& delay, |
| 74 bool did_proceed, | 75 bool did_proceed, |
| 75 int num_visits); | 76 int num_visits); |
| 76 | 77 |
| 77 // A list of SafeBrowsingUIManager::UnsafeResource for a tab that the user | 78 // A list of SafeBrowsingUIManager::UnsafeResource for a tab that the user |
| 78 // should be warned about. They are queued when displaying more than one | 79 // should be warned about. They are queued when displaying more than one |
| 79 // interstitial at a time. | 80 // interstitial at a time. |
| 80 static UnsafeResourceMap* GetUnsafeResourcesMap(); | 81 static UnsafeResourceMap* GetUnsafeResourcesMap(); |
| 81 | 82 |
| 82 static std::string GetMetricPrefix( | 83 static std::string GetMetricPrefix( |
| 83 const UnsafeResourceList& unsafe_resources, | 84 const UnsafeResourceList& unsafe_resources, |
| 84 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason); | 85 BaseSafeBrowsingErrorUI::SBInterstitialReason interstitial_reason); |
| 85 | 86 |
| 86 static std::string GetExtraMetricsSuffix( | 87 static std::string GetExtraMetricsSuffix( |
| 87 const UnsafeResourceList& unsafe_resources); | 88 const UnsafeResourceList& unsafe_resources); |
| 88 | 89 |
| 89 // Return the most severe interstitial reason from a list of unsafe resources. | 90 // Return the most severe interstitial reason from a list of unsafe resources. |
| 90 // Severity ranking: malware > UwS (harmful) > phishing. | 91 // Severity ranking: malware > UwS (harmful) > phishing. |
| 91 static SafeBrowsingErrorUI::SBInterstitialReason GetInterstitialReason( | 92 static BaseSafeBrowsingErrorUI::SBInterstitialReason GetInterstitialReason( |
| 92 const UnsafeResourceList& unsafe_resources); | 93 const UnsafeResourceList& unsafe_resources); |
| 93 | 94 |
| 94 BaseUIManager* ui_manager() const; | 95 BaseUIManager* ui_manager() const; |
| 95 | 96 |
| 96 const GURL main_frame_url() const; | 97 const GURL main_frame_url() const; |
| 97 | 98 |
| 98 UnsafeResourceList unsafe_resources() const; | 99 UnsafeResourceList unsafe_resources() const; |
| 99 | 100 |
| 100 SafeBrowsingErrorUI* sb_error_ui() const; | 101 BaseSafeBrowsingErrorUI* sb_error_ui() const; |
| 101 | 102 |
| 102 void set_proceeded(bool proceeded); | 103 void set_proceeded(bool proceeded); |
| 103 | 104 |
| 104 static security_interstitials::MetricsHelper::ReportDetails GetReportingInfo( | 105 static security_interstitials::MetricsHelper::ReportDetails GetReportingInfo( |
| 105 const UnsafeResourceList& unsafe_resources); | 106 const UnsafeResourceList& unsafe_resources); |
| 106 | 107 |
| 107 // Called after OnProceed(). Does nothing in this class, but can be overridden | 108 // Called after OnProceed(). Does nothing in this class, but can be overridden |
| 108 // to handle malicious subresources. | 109 // to handle malicious subresources. |
| 109 virtual void HandleSubresourcesAfterProceed(); | 110 virtual void HandleSubresourcesAfterProceed(); |
| 110 | 111 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 124 GURL main_frame_url_; | 125 GURL main_frame_url_; |
| 125 | 126 |
| 126 // The index of a navigation entry that should be removed when DontProceed() | 127 // The index of a navigation entry that should be removed when DontProceed() |
| 127 // is invoked, -1 if entry should not be removed. | 128 // is invoked, -1 if entry should not be removed. |
| 128 const int navigation_entry_index_to_remove_; | 129 const int navigation_entry_index_to_remove_; |
| 129 | 130 |
| 130 // The list of unsafe resources this page is warning about. | 131 // The list of unsafe resources this page is warning about. |
| 131 UnsafeResourceList unsafe_resources_; | 132 UnsafeResourceList unsafe_resources_; |
| 132 | 133 |
| 133 // For displaying safe browsing interstitial. | 134 // For displaying safe browsing interstitial. |
| 134 std::unique_ptr<SafeBrowsingErrorUI> sb_error_ui_; | 135 std::unique_ptr<BaseSafeBrowsingErrorUI> sb_error_ui_; |
| 135 | 136 |
| 136 // Indicate whether user has proceeded this blocking page. | 137 // Indicate whether user has proceeded this blocking page. |
| 137 bool proceeded_; | 138 bool proceeded_; |
| 138 | 139 |
| 139 // After a safe browsing interstitial where the user opted-in to the | 140 // After a safe browsing interstitial where the user opted-in to the |
| 140 // report but clicked "proceed anyway", we delay the call to | 141 // report but clicked "proceed anyway", we delay the call to |
| 141 // ThreatDetails::FinishCollection() by this much time (in | 142 // ThreatDetails::FinishCollection() by this much time (in |
| 142 // milliseconds), in order to get data from the blocked resource itself. | 143 // milliseconds), in order to get data from the blocked resource itself. |
| 143 int64_t threat_details_proceed_delay_ms_; | 144 int64_t threat_details_proceed_delay_ms_; |
| 144 | 145 |
| 145 DISALLOW_COPY_AND_ASSIGN(BaseBlockingPage); | 146 DISALLOW_COPY_AND_ASSIGN(BaseBlockingPage); |
| 146 }; | 147 }; |
| 147 | 148 |
| 148 } // namespace safe_browsing | 149 } // namespace safe_browsing |
| 149 | 150 |
| 150 #endif // COMPONENTS_SAFE_BROWSING_BASE_BLOCKING_PAGE_H_ | 151 #endif // COMPONENTS_SAFE_BROWSING_BASE_BLOCKING_PAGE_H_ |
| OLD | NEW |