OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_SAFE_BROWSING_BASE_BLOCKING_PAGE_H_ |
| 6 #define COMPONENTS_SAFE_BROWSING_BASE_BLOCKING_PAGE_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/macros.h" |
| 13 #include "components/safe_browsing/base_ui_manager.h" |
| 14 #include "components/security_interstitials/content/security_interstitial_page.h
" |
| 15 #include "components/security_interstitials/core/safe_browsing_error_ui.h" |
| 16 #include "content/public/browser/interstitial_page_delegate.h" |
| 17 #include "url/gurl.h" |
| 18 |
| 19 namespace history { |
| 20 class HistoryService; |
| 21 } |
| 22 |
| 23 namespace safe_browsing { |
| 24 |
| 25 // Base class for managing the SafeBrowsing interstitial pages. |
| 26 class BaseBlockingPage |
| 27 : public security_interstitials::SecurityInterstitialPage { |
| 28 public: |
| 29 typedef security_interstitials::UnsafeResource UnsafeResource; |
| 30 typedef security_interstitials::SafeBrowsingErrorUI SafeBrowsingErrorUI; |
| 31 typedef std::vector<UnsafeResource> UnsafeResourceList; |
| 32 typedef std::unordered_map<content::WebContents*, UnsafeResourceList> |
| 33 UnsafeResourceMap; |
| 34 |
| 35 ~BaseBlockingPage() override; |
| 36 |
| 37 static const SafeBrowsingErrorUI::SBErrorDisplayOptions |
| 38 CreateDefaultDisplayOptions(const UnsafeResourceList& unsafe_resources); |
| 39 |
| 40 // Shows a blocking page warning the user about phishing/malware for a |
| 41 // specific resource. |
| 42 // This can be called several times. If an interstitial is already showing |
| 43 // and the user decides to proceed, it will be discarded and a new one will be |
| 44 // displayed. |
| 45 static void ShowBlockingPage(BaseUIManager* ui_manager, |
| 46 const UnsafeResource& resource); |
| 47 |
| 48 // Returns true if the passed |unsafe_resources| is blocking the load of |
| 49 // the main page. |
| 50 static bool IsMainPageLoadBlocked(const UnsafeResourceList& unsafe_resources); |
| 51 |
| 52 // InterstitialPageDelegate methods: |
| 53 void OnProceed() override; |
| 54 void OnDontProceed() override; |
| 55 void CommandReceived(const std::string& command) override; |
| 56 |
| 57 protected: |
| 58 // Don't instantiate this class directly, use ShowBlockingPage instead. |
| 59 BaseBlockingPage( |
| 60 BaseUIManager* ui_manager, |
| 61 content::WebContents* web_contents, |
| 62 const GURL& main_frame_url, |
| 63 const UnsafeResourceList& unsafe_resources, |
| 64 std::unique_ptr< |
| 65 security_interstitials::SecurityInterstitialControllerClient> |
| 66 controller_client, |
| 67 const SafeBrowsingErrorUI::SBErrorDisplayOptions& display_options); |
| 68 |
| 69 // SecurityInterstitialPage methods: |
| 70 bool ShouldCreateNewNavigation() const override; |
| 71 void PopulateInterstitialStrings( |
| 72 base::DictionaryValue* load_time_data) override; |
| 73 |
| 74 // Called when the interstitial is going away. Intentionally do nothing in |
| 75 // this base class. |
| 76 virtual void FinishThreatDetails(const base::TimeDelta& delay, |
| 77 bool did_proceed, |
| 78 int num_visits); |
| 79 |
| 80 // A list of SafeBrowsingUIManager::UnsafeResource for a tab that the user |
| 81 // should be warned about. They are queued when displaying more than one |
| 82 // interstitial at a time. |
| 83 static UnsafeResourceMap* GetUnsafeResourcesMap(); |
| 84 |
| 85 static std::string GetMetricPrefix( |
| 86 const UnsafeResourceList& unsafe_resources, |
| 87 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason); |
| 88 |
| 89 static std::string GetExtraMetricsSuffix( |
| 90 const UnsafeResourceList& unsafe_resources); |
| 91 |
| 92 // Return the most severe interstitial reason from a list of unsafe resources. |
| 93 // Severity ranking: malware > UwS (harmful) > phishing. |
| 94 static SafeBrowsingErrorUI::SBInterstitialReason GetInterstitialReason( |
| 95 const UnsafeResourceList& unsafe_resources); |
| 96 |
| 97 BaseUIManager* ui_manager() const; |
| 98 |
| 99 const GURL main_frame_url() const; |
| 100 |
| 101 UnsafeResourceList unsafe_resources() const; |
| 102 |
| 103 SafeBrowsingErrorUI* sb_error_ui() const; |
| 104 |
| 105 void set_proceeded(bool proceeded); |
| 106 |
| 107 private: |
| 108 static std::unique_ptr< |
| 109 security_interstitials::SecurityInterstitialControllerClient> |
| 110 CreateControllerClient(content::WebContents* web_contents, |
| 111 const UnsafeResourceList& unsafe_resources, |
| 112 history::HistoryService* history_service, |
| 113 const std::string& app_locale, |
| 114 const GURL& default_safe_page); |
| 115 |
| 116 // For reporting back user actions. |
| 117 BaseUIManager* ui_manager_; |
| 118 |
| 119 // The URL of the main frame that caused the warning. |
| 120 GURL main_frame_url_; |
| 121 |
| 122 // The index of a navigation entry that should be removed when DontProceed() |
| 123 // is invoked, -1 if entry should not be removed. |
| 124 const int navigation_entry_index_to_remove_; |
| 125 |
| 126 // The list of unsafe resources this page is warning about. |
| 127 UnsafeResourceList unsafe_resources_; |
| 128 |
| 129 // For displaying safe browsing interstitial. |
| 130 std::unique_ptr<SafeBrowsingErrorUI> sb_error_ui_; |
| 131 |
| 132 // Indicate whether user has proceeded this blocking page. |
| 133 bool proceeded_; |
| 134 |
| 135 DISALLOW_COPY_AND_ASSIGN(BaseBlockingPage); |
| 136 }; |
| 137 |
| 138 } // namespace safe_browsing |
| 139 |
| 140 #endif // COMPONENTS_SAFE_BROWSING_BASE_BLOCKING_PAGE_H_ |
OLD | NEW |