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_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 BaseBlockingPage { |
53 : public security_interstitials::SecurityInterstitialPage { | |
54 public: | 47 public: |
55 typedef security_interstitials::UnsafeResource UnsafeResource; | |
56 typedef security_interstitials::SafeBrowsingErrorUI SafeBrowsingErrorUI; | |
57 typedef std::vector<UnsafeResource> UnsafeResourceList; | |
58 typedef std::map<content::WebContents*, UnsafeResourceList> UnsafeResourceMap; | |
59 | |
60 // Interstitial type, used in tests. | 48 // Interstitial type, used in tests. |
61 static content::InterstitialPageDelegate::TypeID kTypeForTesting; | 49 static content::InterstitialPageDelegate::TypeID kTypeForTesting; |
62 | 50 |
63 ~SafeBrowsingBlockingPage() override; | 51 ~SafeBrowsingBlockingPage() override; |
64 | 52 |
65 // Creates a blocking page. Use ShowBlockingPage if you don't need to access | 53 // Creates a blocking page. Use ShowBlockingPage if you don't need to access |
66 // the blocking page directly. | 54 // the blocking page directly. |
67 static SafeBrowsingBlockingPage* CreateBlockingPage( | 55 static SafeBrowsingBlockingPage* CreateBlockingPage( |
68 SafeBrowsingUIManager* ui_manager, | 56 BaseUIManager* ui_manager, |
69 content::WebContents* web_contents, | 57 content::WebContents* web_contents, |
70 const GURL& main_frame_url, | 58 const GURL& main_frame_url, |
71 const UnsafeResource& unsafe_resource); | 59 const UnsafeResource& unsafe_resource); |
72 | 60 |
73 // Shows a blocking page warning the user about phishing/malware for a | 61 // Shows a blocking page warning the user about phishing/malware for a |
74 // specific resource. | 62 // specific resource. |
75 // You can call this method several times, if an interstitial is already | 63 // 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 | 64 // showing, the new one will be queued and displayed if the user decides |
77 // to proceed on the currently showing interstitial. | 65 // to proceed on the currently showing interstitial. |
78 static void ShowBlockingPage( | 66 static void ShowBlockingPage(BaseUIManager* ui_manager, |
79 SafeBrowsingUIManager* ui_manager, const UnsafeResource& resource); | 67 const UnsafeResource& resource); |
80 | 68 |
81 // Makes the passed |factory| the factory used to instantiate | 69 // Makes the passed |factory| the factory used to instantiate |
82 // SafeBrowsingBlockingPage objects. Useful for tests. | 70 // SafeBrowsingBlockingPage objects. Useful for tests. |
83 static void RegisterFactory(SafeBrowsingBlockingPageFactory* factory) { | 71 static void RegisterFactory(SafeBrowsingBlockingPageFactory* factory) { |
84 factory_ = factory; | 72 factory_ = factory; |
85 } | 73 } |
86 | 74 |
87 // InterstitialPageDelegate method: | 75 // InterstitialPageDelegate method: |
88 void OnProceed() override; | 76 void OnProceed() override; |
89 void OnDontProceed() override; | |
90 void CommandReceived(const std::string& command) override; | |
91 void OverrideRendererPrefs(content::RendererPreferences* prefs) override; | 77 void OverrideRendererPrefs(content::RendererPreferences* prefs) override; |
92 content::InterstitialPageDelegate::TypeID GetTypeForTesting() const override; | 78 content::InterstitialPageDelegate::TypeID GetTypeForTesting() const override; |
93 | 79 |
94 // Checks the threat type to decide if we should report ThreatDetails. | 80 // Checks the threat type to decide if we should report ThreatDetails. |
95 static bool ShouldReportThreatDetails(SBThreatType threat_type); | 81 static bool ShouldReportThreatDetails(SBThreatType threat_type); |
96 | 82 |
97 protected: | 83 protected: |
98 friend class SafeBrowsingBlockingPageFactoryImpl; | 84 friend class SafeBrowsingBlockingPageFactoryImpl; |
99 friend class SafeBrowsingBlockingPageTest; | 85 friend class SafeBrowsingBlockingPageTest; |
100 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | 86 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
101 ProceedThenDontProceed); | 87 ProceedThenDontProceed); |
102 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | 88 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
103 MalwareReportsDisabled); | 89 MalwareReportsDisabled); |
104 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | 90 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
105 MalwareReportsToggling); | 91 MalwareReportsToggling); |
106 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | 92 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
107 ExtendedReportingNotShownOnSecurePage); | 93 ExtendedReportingNotShownOnSecurePage); |
108 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | 94 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
109 MalwareReportsTransitionDisabled); | 95 MalwareReportsTransitionDisabled); |
110 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | 96 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
111 ExtendedReportingNotShownInIncognito); | 97 ExtendedReportingNotShownInIncognito); |
112 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | 98 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
113 ExtendedReportingNotShownNotAllowExtendedReporting); | 99 ExtendedReportingNotShownNotAllowExtendedReporting); |
114 | 100 |
115 void UpdateReportingPref(); // Used for the transition from old to new pref. | 101 void UpdateReportingPref(); // Used for the transition from old to new pref. |
116 | 102 |
117 // Don't instantiate this class directly, use ShowBlockingPage instead. | 103 // Don't instantiate this class directly, use ShowBlockingPage instead. |
118 SafeBrowsingBlockingPage(SafeBrowsingUIManager* ui_manager, | 104 SafeBrowsingBlockingPage( |
119 content::WebContents* web_contents, | 105 BaseUIManager* ui_manager, |
120 const GURL& main_frame_url, | 106 content::WebContents* web_contents, |
121 const UnsafeResourceList& unsafe_resources); | 107 const GURL& main_frame_url, |
122 | 108 const UnsafeResourceList& unsafe_resources, |
123 // SecurityInterstitialPage methods: | 109 SafeBrowsingErrorUI::SBErrorDisplayOptions* display_options); |
124 bool ShouldCreateNewNavigation() const override; | |
125 void PopulateInterstitialStrings( | |
126 base::DictionaryValue* load_time_data) override; | |
127 | 110 |
128 // After a safe browsing interstitial where the user opted-in to the | 111 // After a safe browsing interstitial where the user opted-in to the |
129 // report but clicked "proceed anyway", we delay the call to | 112 // report but clicked "proceed anyway", we delay the call to |
130 // ThreatDetails::FinishCollection() by this much time (in | 113 // ThreatDetails::FinishCollection() by this much time (in |
131 // milliseconds), in order to get data from the blocked resource itself. | 114 // milliseconds), in order to get data from the blocked resource itself. |
132 int64_t threat_details_proceed_delay_ms_; | 115 int64_t threat_details_proceed_delay_ms_; |
133 | 116 |
134 // Called when the interstitial is going away. If there is a | 117 // Called when the interstitial is going away. If there is a |
135 // pending threat details object, we look at the user's | 118 // pending threat details object, we look at the user's |
136 // preferences, and if the option to send threat details is | 119 // preferences, and if the option to send threat details is |
137 // enabled, the report is scheduled to be sent on the |ui_manager_|. | 120 // 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); | 121 void FinishThreatDetails(int64_t delay_ms, |
meacer
2017/01/11 01:33:30
nit: I know this is existing code, but delay_ms co
Jialiu Lin
2017/01/11 02:53:15
Done.
| |
139 | 122 bool did_proceed, |
140 // A list of SafeBrowsingUIManager::UnsafeResource for a tab that the user | 123 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 | 124 |
166 // A ThreatDetails object that we start generating when the | 125 // A ThreatDetails object that we start generating when the |
167 // blocking page is shown. The object will be sent when the warning | 126 // blocking page is shown. The object will be sent when the warning |
168 // is gone (if the user enables the feature). | 127 // is gone (if the user enables the feature). |
169 scoped_refptr<ThreatDetails> threat_details_; | 128 scoped_refptr<ThreatDetails> threat_details_; |
170 | 129 |
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. | 130 // The factory used to instantiate SafeBrowsingBlockingPage objects. |
177 // Useful for tests, so they can provide their own implementation of | 131 // Useful for tests, so they can provide their own implementation of |
178 // SafeBrowsingBlockingPage. | 132 // SafeBrowsingBlockingPage. |
179 static SafeBrowsingBlockingPageFactory* factory_; | 133 static SafeBrowsingBlockingPageFactory* factory_; |
180 | 134 |
181 private: | 135 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( | 136 static std::string GetSamplingEventName( |
188 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason); | 137 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason); |
189 | 138 |
190 static SafeBrowsingErrorUI::SBInterstitialReason GetInterstitialReason( | 139 static std::unique_ptr< |
191 const UnsafeResourceList& unsafe_resources); | 140 security_interstitials::SecurityInterstitialControllerClient> |
192 | 141 CreateControllerClient(content::WebContents* web_contents, |
193 std::unique_ptr<security_interstitials::SecurityInterstitialControllerClient> | 142 const UnsafeResourceList& unsafe_resources); |
194 CreateControllerClient( | |
195 content::WebContents* web_contents, | |
196 const UnsafeResourceList& unsafe_resources); | |
197 | 143 |
198 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPage); | 144 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPage); |
199 }; | 145 }; |
200 | 146 |
201 // Factory for creating SafeBrowsingBlockingPage. Useful for tests. | 147 // Factory for creating SafeBrowsingBlockingPage. Useful for tests. |
202 class SafeBrowsingBlockingPageFactory { | 148 class SafeBrowsingBlockingPageFactory { |
203 public: | 149 public: |
204 virtual ~SafeBrowsingBlockingPageFactory() { } | 150 virtual ~SafeBrowsingBlockingPageFactory() { } |
205 | 151 |
206 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( | 152 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( |
207 SafeBrowsingUIManager* ui_manager, | 153 BaseUIManager* ui_manager, |
208 content::WebContents* web_contents, | 154 content::WebContents* web_contents, |
209 const GURL& main_frame_url, | 155 const GURL& main_frame_url, |
210 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) = 0; | 156 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) = 0; |
211 }; | 157 }; |
212 | 158 |
213 } // namespace safe_browsing | 159 } // namespace safe_browsing |
214 | 160 |
215 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ | 161 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ |
OLD | NEW |