OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 15 matching lines...) Expand all Loading... |
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 #pragma once | 30 #pragma once |
31 | 31 |
32 #include <map> | 32 #include <map> |
33 #include <vector> | 33 #include <vector> |
34 | 34 |
35 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 35 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
36 #include "chrome/browser/tab_contents/chrome_interstitial_page.h" | 36 #include "content/public/browser/interstitial_page_delegate.h" |
37 #include "googleurl/src/gurl.h" | 37 #include "googleurl/src/gurl.h" |
38 | 38 |
| 39 class InterstitialPage; |
| 40 class MalwareDetails; |
39 class MessageLoop; | 41 class MessageLoop; |
40 class SafeBrowsingBlockingPageFactory; | 42 class SafeBrowsingBlockingPageFactory; |
41 class MalwareDetails; | |
42 class TabContents; | |
43 | 43 |
44 namespace base { | 44 namespace base { |
45 class DictionaryValue; | 45 class DictionaryValue; |
46 } | 46 } |
47 | 47 |
48 class SafeBrowsingBlockingPage : public ChromeInterstitialPage { | 48 namespace content { |
| 49 class WebContents; |
| 50 } |
| 51 |
| 52 class SafeBrowsingBlockingPage : public content::InterstitialPageDelegate { |
49 public: | 53 public: |
50 typedef std::vector<SafeBrowsingService::UnsafeResource> UnsafeResourceList; | 54 typedef std::vector<SafeBrowsingService::UnsafeResource> UnsafeResourceList; |
51 typedef std::map<content::WebContents*, UnsafeResourceList> UnsafeResourceMap; | 55 typedef std::map<content::WebContents*, UnsafeResourceList> UnsafeResourceMap; |
52 | 56 |
53 virtual ~SafeBrowsingBlockingPage(); | 57 virtual ~SafeBrowsingBlockingPage(); |
54 | 58 |
55 // Shows a blocking page warning the user about phishing/malware for a | 59 // Shows a blocking page warning the user about phishing/malware for a |
56 // specific resource. | 60 // specific resource. |
57 // You can call this method several times, if an interstitial is already | 61 // You can call this method several times, if an interstitial is already |
58 // showing, the new one will be queued and displayed if the user decides | 62 // showing, the new one will be queued and displayed if the user decides |
59 // to proceed on the currently showing interstitial. | 63 // to proceed on the currently showing interstitial. |
60 static void ShowBlockingPage( | 64 static void ShowBlockingPage( |
61 SafeBrowsingService* service, | 65 SafeBrowsingService* service, |
62 const SafeBrowsingService::UnsafeResource& resource); | 66 const SafeBrowsingService::UnsafeResource& resource); |
63 | 67 |
64 // Makes the passed |factory| the factory used to instanciate | 68 // Makes the passed |factory| the factory used to instanciate |
65 // SafeBrowsingBlockingPage objects. Usefull for tests. | 69 // SafeBrowsingBlockingPage objects. Usefull for tests. |
66 static void RegisterFactory(SafeBrowsingBlockingPageFactory* factory) { | 70 static void RegisterFactory(SafeBrowsingBlockingPageFactory* factory) { |
67 factory_ = factory; | 71 factory_ = factory; |
68 } | 72 } |
69 | 73 |
70 // ChromeInterstitialPage method: | 74 // InterstitialPageDelegate method: |
71 virtual std::string GetHTMLContents() OVERRIDE; | 75 virtual std::string GetHTMLContents() OVERRIDE; |
72 virtual void Proceed() OVERRIDE; | 76 virtual void CommandReceived(const std::string& command) OVERRIDE; |
73 virtual void DontProceed() OVERRIDE; | 77 virtual void OverrideRendererPrefs( |
| 78 content::RendererPreferences* prefs) OVERRIDE; |
| 79 virtual void OnProceed() OVERRIDE; |
| 80 virtual void OnDontProceed() OVERRIDE; |
74 | 81 |
75 protected: | 82 protected: |
76 friend class SafeBrowsingBlockingPageTest; | 83 friend class SafeBrowsingBlockingPageTest; |
77 | 84 friend class TestSafeBrowsingBlockingPage; |
78 // ChromeInterstitialPage method: | 85 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
79 virtual void CommandReceived(const std::string& command) OVERRIDE; | 86 ProceedThenDontProceed); |
80 | 87 |
81 void SetReportingPreference(bool report); | 88 void SetReportingPreference(bool report); |
82 | 89 |
83 // Don't instanciate this class directly, use ShowBlockingPage instead. | 90 // Don't instanciate this class directly, use ShowBlockingPage instead. |
84 SafeBrowsingBlockingPage(SafeBrowsingService* service, | 91 SafeBrowsingBlockingPage(SafeBrowsingService* service, |
85 content::WebContents* web_contents, | 92 content::WebContents* web_contents, |
86 const UnsafeResourceList& unsafe_resources); | 93 const UnsafeResourceList& unsafe_resources); |
87 | 94 |
88 // After a malware interstitial where the user opted-in to the | 95 // After a malware interstitial where the user opted-in to the |
89 // report but clicked "proceed anyway", we delay the call to | 96 // report but clicked "proceed anyway", we delay the call to |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 int navigation_entry_index_to_remove_; | 169 int navigation_entry_index_to_remove_; |
163 | 170 |
164 // The list of unsafe resources this page is warning about. | 171 // The list of unsafe resources this page is warning about. |
165 UnsafeResourceList unsafe_resources_; | 172 UnsafeResourceList unsafe_resources_; |
166 | 173 |
167 // A MalwareDetails object that we start generating when the | 174 // A MalwareDetails object that we start generating when the |
168 // blocking page is shown. The object will be sent when the warning | 175 // blocking page is shown. The object will be sent when the warning |
169 // is gone (if the user enables the feature). | 176 // is gone (if the user enables the feature). |
170 scoped_refptr<MalwareDetails> malware_details_; | 177 scoped_refptr<MalwareDetails> malware_details_; |
171 | 178 |
| 179 bool proceeded_; |
| 180 |
| 181 content::WebContents* web_contents_; |
| 182 GURL url_; |
| 183 InterstitialPage* interstitial_page_; // Owns us |
| 184 |
172 // The factory used to instanciate SafeBrowsingBlockingPage objects. | 185 // The factory used to instanciate SafeBrowsingBlockingPage objects. |
173 // Usefull for tests, so they can provide their own implementation of | 186 // Usefull for tests, so they can provide their own implementation of |
174 // SafeBrowsingBlockingPage. | 187 // SafeBrowsingBlockingPage. |
175 static SafeBrowsingBlockingPageFactory* factory_; | 188 static SafeBrowsingBlockingPageFactory* factory_; |
176 | 189 |
177 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPage); | 190 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPage); |
178 }; | 191 }; |
179 | 192 |
180 // Factory for creating SafeBrowsingBlockingPage. Useful for tests. | 193 // Factory for creating SafeBrowsingBlockingPage. Useful for tests. |
181 class SafeBrowsingBlockingPageFactory { | 194 class SafeBrowsingBlockingPageFactory { |
182 public: | 195 public: |
183 virtual ~SafeBrowsingBlockingPageFactory() { } | 196 virtual ~SafeBrowsingBlockingPageFactory() { } |
184 | 197 |
185 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( | 198 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( |
186 SafeBrowsingService* service, | 199 SafeBrowsingService* service, |
187 content::WebContents* web_contents, | 200 content::WebContents* web_contents, |
188 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) = 0; | 201 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) = 0; |
189 }; | 202 }; |
190 | 203 |
191 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ | 204 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ |
OLD | NEW |