Chromium Code Reviews| 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(); | |
| 98 | |
| 99 // The URL of the main frame that caused the warning. | |
| 100 GURL main_frame_url_; | |
|
meacer
2017/01/11 18:59:41
nit: Getters for these protected variables as well
Jialiu Lin
2017/01/11 20:13:29
Done.
| |
| 101 | |
| 102 // The index of a navigation entry that should be removed when DontProceed() | |
| 103 // is invoked, -1 if entry should not be removed. | |
| 104 const int navigation_entry_index_to_remove_; | |
| 105 | |
| 106 // The list of unsafe resources this page is warning about. | |
| 107 UnsafeResourceList unsafe_resources_; | |
| 108 | |
| 109 // For displaying safe browsing interstitial. | |
| 110 std::unique_ptr<SafeBrowsingErrorUI> sb_error_ui_; | |
| 111 | |
| 112 // Indicate whether user has proceeded this blocking page. | |
| 113 bool proceeded_; | |
| 114 | |
| 115 // Which type of Safe Browsing interstitial this is. | |
| 116 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason_; | |
| 117 | |
| 118 private: | |
| 119 static std::unique_ptr< | |
| 120 security_interstitials::SecurityInterstitialControllerClient> | |
| 121 CreateControllerClient(content::WebContents* web_contents, | |
| 122 const UnsafeResourceList& unsafe_resources, | |
| 123 history::HistoryService* history_service, | |
| 124 const std::string& app_locale, | |
| 125 const GURL& default_safe_page); | |
| 126 | |
| 127 // For reporting back user actions. | |
| 128 BaseUIManager* ui_manager_; | |
| 129 | |
| 130 DISALLOW_COPY_AND_ASSIGN(BaseBlockingPage); | |
| 131 }; | |
| 132 | |
| 133 } // namespace safe_browsing | |
| 134 | |
| 135 #endif // COMPONENTS_SAFE_BROWSING_BASE_BLOCKING_PAGE_H_ | |
| OLD | NEW |