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