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 18 matching lines...) Expand all Loading... |
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 "base/gtest_prod_util.h" | 35 #include "base/gtest_prod_util.h" |
36 #include "base/task/cancelable_task_tracker.h" | 36 #include "base/task/cancelable_task_tracker.h" |
37 #include "base/time/time.h" | 37 #include "base/time/time.h" |
38 #include "chrome/browser/history/history_service.h" | 38 #include "chrome/browser/history/history_service.h" |
| 39 #include "chrome/browser/interstitials/security_interstitial_page.h" |
39 #include "chrome/browser/safe_browsing/ui_manager.h" | 40 #include "chrome/browser/safe_browsing/ui_manager.h" |
40 #include "content/public/browser/interstitial_page_delegate.h" | |
41 #include "url/gurl.h" | 41 #include "url/gurl.h" |
42 | 42 |
43 class MalwareDetails; | 43 class MalwareDetails; |
44 class SafeBrowsingBlockingPageFactory; | 44 class SafeBrowsingBlockingPageFactory; |
45 | 45 |
46 namespace base { | 46 namespace base { |
47 class DictionaryValue; | |
48 class MessageLoop; | 47 class MessageLoop; |
49 } | 48 } |
50 | 49 |
51 namespace content { | |
52 class InterstitialPage; | |
53 class WebContents; | |
54 } | |
55 | |
56 #if defined(ENABLE_EXTENSIONS) | 50 #if defined(ENABLE_EXTENSIONS) |
57 namespace extensions { | 51 namespace extensions { |
58 class ExperienceSamplingEvent; | 52 class ExperienceSamplingEvent; |
59 } | 53 } |
60 #endif | 54 #endif |
61 | 55 |
62 class SafeBrowsingBlockingPage : public content::InterstitialPageDelegate { | 56 class SafeBrowsingBlockingPage : public SecurityInterstitialPage { |
63 public: | 57 public: |
64 typedef SafeBrowsingUIManager::UnsafeResource UnsafeResource; | 58 typedef SafeBrowsingUIManager::UnsafeResource UnsafeResource; |
65 typedef std::vector<UnsafeResource> UnsafeResourceList; | 59 typedef std::vector<UnsafeResource> UnsafeResourceList; |
66 typedef std::map<content::WebContents*, UnsafeResourceList> UnsafeResourceMap; | 60 typedef std::map<content::WebContents*, UnsafeResourceList> UnsafeResourceMap; |
67 | 61 |
68 virtual ~SafeBrowsingBlockingPage(); | 62 virtual ~SafeBrowsingBlockingPage(); |
69 | 63 |
70 // Creates a blocking page. Use ShowBlockingPage if you don't need to access | 64 // Creates a blocking page. Use ShowBlockingPage if you don't need to access |
71 // the blocking page directly. | 65 // the blocking page directly. |
72 static SafeBrowsingBlockingPage* CreateBlockingPage( | 66 static SafeBrowsingBlockingPage* CreateBlockingPage( |
73 SafeBrowsingUIManager* ui_manager, | 67 SafeBrowsingUIManager* ui_manager, |
74 content::WebContents* web_contents, | 68 content::WebContents* web_contents, |
75 const UnsafeResource& unsafe_resource); | 69 const UnsafeResource& unsafe_resource); |
76 | 70 |
77 // Shows a blocking page warning the user about phishing/malware for a | 71 // Shows a blocking page warning the user about phishing/malware for a |
78 // specific resource. | 72 // specific resource. |
79 // You can call this method several times, if an interstitial is already | 73 // You can call this method several times, if an interstitial is already |
80 // showing, the new one will be queued and displayed if the user decides | 74 // showing, the new one will be queued and displayed if the user decides |
81 // to proceed on the currently showing interstitial. | 75 // to proceed on the currently showing interstitial. |
82 static void ShowBlockingPage( | 76 static void ShowBlockingPage( |
83 SafeBrowsingUIManager* ui_manager, const UnsafeResource& resource); | 77 SafeBrowsingUIManager* ui_manager, const UnsafeResource& resource); |
84 | 78 |
85 // Makes the passed |factory| the factory used to instantiate | 79 // Makes the passed |factory| the factory used to instantiate |
86 // SafeBrowsingBlockingPage objects. Useful for tests. | 80 // SafeBrowsingBlockingPage objects. Useful for tests. |
87 static void RegisterFactory(SafeBrowsingBlockingPageFactory* factory) { | 81 static void RegisterFactory(SafeBrowsingBlockingPageFactory* factory) { |
88 factory_ = factory; | 82 factory_ = factory; |
89 } | 83 } |
90 | 84 |
91 // InterstitialPageDelegate method: | 85 // InterstitialPageDelegate method: |
92 virtual std::string GetHTMLContents() OVERRIDE; | |
93 virtual void OnProceed() OVERRIDE; | 86 virtual void OnProceed() OVERRIDE; |
94 virtual void OnDontProceed() OVERRIDE; | 87 virtual void OnDontProceed() OVERRIDE; |
95 virtual void CommandReceived(const std::string& command) OVERRIDE; | 88 virtual void CommandReceived(const std::string& command) OVERRIDE; |
96 virtual void OverrideRendererPrefs( | 89 virtual void OverrideRendererPrefs( |
97 content::RendererPreferences* prefs) OVERRIDE; | 90 content::RendererPreferences* prefs) OVERRIDE; |
98 | 91 |
| 92 // SecurityInterstitialPage method: |
| 93 virtual SecurityInterstitialPage::Type GetTypeForTesting() const OVERRIDE; |
| 94 |
99 protected: | 95 protected: |
100 friend class SafeBrowsingBlockingPageTest; | 96 friend class SafeBrowsingBlockingPageTest; |
101 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | 97 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
102 ProceedThenDontProceed); | 98 ProceedThenDontProceed); |
103 | |
104 void DontCreateViewForTesting(); | |
105 void Show(); | |
106 void SetReportingPreference(bool report); | 99 void SetReportingPreference(bool report); |
107 void UpdateReportingPref(); // Used for the transition from old to new pref. | 100 void UpdateReportingPref(); // Used for the transition from old to new pref. |
108 | 101 |
109 // Don't instantiate this class directly, use ShowBlockingPage instead. | 102 // Don't instantiate this class directly, use ShowBlockingPage instead. |
110 SafeBrowsingBlockingPage(SafeBrowsingUIManager* ui_manager, | 103 SafeBrowsingBlockingPage(SafeBrowsingUIManager* ui_manager, |
111 content::WebContents* web_contents, | 104 content::WebContents* web_contents, |
112 const UnsafeResourceList& unsafe_resources); | 105 const UnsafeResourceList& unsafe_resources); |
113 | 106 |
| 107 // SecurityInterstitialPage methods: |
| 108 virtual bool ShouldCreateNewNavigation() const OVERRIDE; |
| 109 virtual void PopulateLoadTimeData( |
| 110 base::DictionaryValue* load_time_data) OVERRIDE; |
| 111 |
114 // After a malware interstitial where the user opted-in to the | 112 // After a malware interstitial where the user opted-in to the |
115 // report but clicked "proceed anyway", we delay the call to | 113 // report but clicked "proceed anyway", we delay the call to |
116 // MalwareDetails::FinishCollection() by this much time (in | 114 // MalwareDetails::FinishCollection() by this much time (in |
117 // milliseconds), in order to get data from the blocked resource itself. | 115 // milliseconds), in order to get data from the blocked resource itself. |
118 int64 malware_details_proceed_delay_ms_; | 116 int64 malware_details_proceed_delay_ms_; |
119 content::InterstitialPage* interstitial_page() const { | |
120 return interstitial_page_; | |
121 } | |
122 | 117 |
123 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | 118 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
124 MalwareReportsTransitionDisabled); | 119 MalwareReportsTransitionDisabled); |
125 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | 120 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
126 MalwareReportsToggling); | 121 MalwareReportsToggling); |
127 | 122 |
128 // These enums are used for histograms. Don't reorder, delete, or insert | 123 // These enums are used for histograms. Don't reorder, delete, or insert |
129 // elements. New elements should be added before MAX_ACTION only. | 124 // elements. New elements should be added before MAX_ACTION only. |
130 enum Decision { | 125 enum Decision { |
131 SHOW, | 126 SHOW, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 // The list of unsafe resources this page is warning about. | 194 // The list of unsafe resources this page is warning about. |
200 UnsafeResourceList unsafe_resources_; | 195 UnsafeResourceList unsafe_resources_; |
201 | 196 |
202 // A MalwareDetails object that we start generating when the | 197 // A MalwareDetails object that we start generating when the |
203 // blocking page is shown. The object will be sent when the warning | 198 // blocking page is shown. The object will be sent when the warning |
204 // is gone (if the user enables the feature). | 199 // is gone (if the user enables the feature). |
205 scoped_refptr<MalwareDetails> malware_details_; | 200 scoped_refptr<MalwareDetails> malware_details_; |
206 | 201 |
207 bool proceeded_; | 202 bool proceeded_; |
208 | 203 |
209 content::WebContents* web_contents_; | |
210 GURL url_; | |
211 content::InterstitialPage* interstitial_page_; // Owns us | |
212 | |
213 // Whether the interstitial should create a view. | |
214 bool create_view_; | |
215 | |
216 // Which type of interstitial this is. | 204 // Which type of interstitial this is. |
217 enum { | 205 enum { |
218 TYPE_MALWARE, | 206 TYPE_MALWARE, |
219 TYPE_HARMFUL, | 207 TYPE_HARMFUL, |
220 TYPE_PHISHING, | 208 TYPE_PHISHING, |
221 } interstitial_type_; | 209 } interstitial_type_; |
222 | 210 |
223 // The factory used to instantiate SafeBrowsingBlockingPage objects. | 211 // The factory used to instantiate SafeBrowsingBlockingPage objects. |
224 // Usefull for tests, so they can provide their own implementation of | 212 // Usefull for tests, so they can provide their own implementation of |
225 // SafeBrowsingBlockingPage. | 213 // SafeBrowsingBlockingPage. |
(...skipping 22 matching lines...) Expand all Loading... |
248 public: | 236 public: |
249 virtual ~SafeBrowsingBlockingPageFactory() { } | 237 virtual ~SafeBrowsingBlockingPageFactory() { } |
250 | 238 |
251 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( | 239 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( |
252 SafeBrowsingUIManager* ui_manager, | 240 SafeBrowsingUIManager* ui_manager, |
253 content::WebContents* web_contents, | 241 content::WebContents* web_contents, |
254 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) = 0; | 242 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) = 0; |
255 }; | 243 }; |
256 | 244 |
257 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ | 245 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ |
OLD | NEW |