| 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 19 matching lines...) Expand all Loading... |
| 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 "chrome/browser/interstitials/security_interstitial_metrics_helper.h" | 37 #include "chrome/browser/interstitials/security_interstitial_metrics_helper.h" |
| 38 #include "chrome/browser/interstitials/security_interstitial_page.h" | 38 #include "chrome/browser/interstitials/security_interstitial_page.h" |
| 39 #include "chrome/browser/safe_browsing/ui_manager.h" | 39 #include "chrome/browser/safe_browsing/ui_manager.h" |
| 40 #include "content/public/browser/interstitial_page_delegate.h" |
| 40 #include "url/gurl.h" | 41 #include "url/gurl.h" |
| 41 | 42 |
| 42 class MalwareDetails; | 43 class MalwareDetails; |
| 43 class SafeBrowsingBlockingPageFactory; | 44 class SafeBrowsingBlockingPageFactory; |
| 44 | 45 |
| 45 namespace base { | 46 namespace base { |
| 46 class MessageLoop; | 47 class MessageLoop; |
| 47 } | 48 } |
| 48 | 49 |
| 49 class SafeBrowsingBlockingPage : public SecurityInterstitialPage { | 50 class SafeBrowsingBlockingPage : public SecurityInterstitialPage { |
| 50 public: | 51 public: |
| 51 typedef SafeBrowsingUIManager::UnsafeResource UnsafeResource; | 52 typedef SafeBrowsingUIManager::UnsafeResource UnsafeResource; |
| 52 typedef std::vector<UnsafeResource> UnsafeResourceList; | 53 typedef std::vector<UnsafeResource> UnsafeResourceList; |
| 53 typedef std::map<content::WebContents*, UnsafeResourceList> UnsafeResourceMap; | 54 typedef std::map<content::WebContents*, UnsafeResourceList> UnsafeResourceMap; |
| 54 | 55 |
| 55 // Interstitial type, used in tests. | 56 // Interstitial type, used in tests. |
| 56 static const void* kTypeForTesting; | 57 static content::InterstitialPageDelegate::TypeID kTypeForTesting; |
| 57 | 58 |
| 58 ~SafeBrowsingBlockingPage() override; | 59 ~SafeBrowsingBlockingPage() override; |
| 59 | 60 |
| 60 // Creates a blocking page. Use ShowBlockingPage if you don't need to access | 61 // Creates a blocking page. Use ShowBlockingPage if you don't need to access |
| 61 // the blocking page directly. | 62 // the blocking page directly. |
| 62 static SafeBrowsingBlockingPage* CreateBlockingPage( | 63 static SafeBrowsingBlockingPage* CreateBlockingPage( |
| 63 SafeBrowsingUIManager* ui_manager, | 64 SafeBrowsingUIManager* ui_manager, |
| 64 content::WebContents* web_contents, | 65 content::WebContents* web_contents, |
| 65 const UnsafeResource& unsafe_resource); | 66 const UnsafeResource& unsafe_resource); |
| 66 | 67 |
| 67 // Shows a blocking page warning the user about phishing/malware for a | 68 // Shows a blocking page warning the user about phishing/malware for a |
| 68 // specific resource. | 69 // specific resource. |
| 69 // You can call this method several times, if an interstitial is already | 70 // You can call this method several times, if an interstitial is already |
| 70 // showing, the new one will be queued and displayed if the user decides | 71 // showing, the new one will be queued and displayed if the user decides |
| 71 // to proceed on the currently showing interstitial. | 72 // to proceed on the currently showing interstitial. |
| 72 static void ShowBlockingPage( | 73 static void ShowBlockingPage( |
| 73 SafeBrowsingUIManager* ui_manager, const UnsafeResource& resource); | 74 SafeBrowsingUIManager* ui_manager, const UnsafeResource& resource); |
| 74 | 75 |
| 75 // Makes the passed |factory| the factory used to instantiate | 76 // Makes the passed |factory| the factory used to instantiate |
| 76 // SafeBrowsingBlockingPage objects. Useful for tests. | 77 // SafeBrowsingBlockingPage objects. Useful for tests. |
| 77 static void RegisterFactory(SafeBrowsingBlockingPageFactory* factory) { | 78 static void RegisterFactory(SafeBrowsingBlockingPageFactory* factory) { |
| 78 factory_ = factory; | 79 factory_ = factory; |
| 79 } | 80 } |
| 80 | 81 |
| 81 // InterstitialPageDelegate method: | 82 // InterstitialPageDelegate method: |
| 82 void OnProceed() override; | 83 void OnProceed() override; |
| 83 void OnDontProceed() override; | 84 void OnDontProceed() override; |
| 84 void CommandReceived(const std::string& command) override; | 85 void CommandReceived(const std::string& command) override; |
| 85 void OverrideRendererPrefs(content::RendererPreferences* prefs) override; | 86 void OverrideRendererPrefs(content::RendererPreferences* prefs) override; |
| 86 | 87 content::InterstitialPageDelegate::TypeID GetTypeForTesting() const override; |
| 87 // SecurityInterstitialPage method: | |
| 88 const void* GetTypeForTesting() const override; | |
| 89 | 88 |
| 90 protected: | 89 protected: |
| 91 friend class SafeBrowsingBlockingPageTest; | 90 friend class SafeBrowsingBlockingPageTest; |
| 92 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, | 91 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingBlockingPageTest, |
| 93 ProceedThenDontProceed); | 92 ProceedThenDontProceed); |
| 94 void SetReportingPreference(bool report); | 93 void SetReportingPreference(bool report); |
| 95 void UpdateReportingPref(); // Used for the transition from old to new pref. | 94 void UpdateReportingPref(); // Used for the transition from old to new pref. |
| 96 | 95 |
| 97 // Don't instantiate this class directly, use ShowBlockingPage instead. | 96 // Don't instantiate this class directly, use ShowBlockingPage instead. |
| 98 SafeBrowsingBlockingPage(SafeBrowsingUIManager* ui_manager, | 97 SafeBrowsingBlockingPage(SafeBrowsingUIManager* ui_manager, |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 public: | 203 public: |
| 205 virtual ~SafeBrowsingBlockingPageFactory() { } | 204 virtual ~SafeBrowsingBlockingPageFactory() { } |
| 206 | 205 |
| 207 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( | 206 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( |
| 208 SafeBrowsingUIManager* ui_manager, | 207 SafeBrowsingUIManager* ui_manager, |
| 209 content::WebContents* web_contents, | 208 content::WebContents* web_contents, |
| 210 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) = 0; | 209 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) = 0; |
| 211 }; | 210 }; |
| 212 | 211 |
| 213 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ | 212 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ |
| OLD | NEW |