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 // Creates a blocking page. Use ShowBlockingPage if you don't need to access | |
| 38 // the blocking page directly. | |
| 39 static BaseBlockingPage* CreateBlockingPage( | |
|
meacer
2017/01/11 01:33:31
This seems to be called only from BaseBlockingPage
Jialiu Lin
2017/01/11 02:53:15
Removed this function and directly call constructo
| |
| 40 BaseUIManager* ui_manager, | |
| 41 content::WebContents* web_contents, | |
| 42 const GURL& main_frame_url, | |
| 43 const UnsafeResource& unsafe_resource); | |
| 44 | |
| 45 // Shows a blocking page warning the user about phishing/malware for a | |
| 46 // specific resource. | |
| 47 // You can call this method several times, if an interstitial is already | |
|
meacer
2017/01/11 01:33:31
tiny nit: might want to reword this sentence a bit
Jialiu Lin
2017/01/11 02:53:16
Done.
| |
| 48 // showing, the new one will be queued and displayed if the user decides | |
| 49 // to proceed on the currently showing interstitial. | |
| 50 static void ShowBlockingPage(BaseUIManager* ui_manager, | |
| 51 const UnsafeResource& resource); | |
| 52 | |
| 53 // Returns true if the passed |unsafe_resources| is blocking the load of | |
| 54 // the main page. | |
| 55 static bool IsMainPageLoadBlocked(const UnsafeResourceList& unsafe_resources); | |
| 56 | |
| 57 // InterstitialPageDelegate method: | |
|
meacer
2017/01/11 01:33:31
nit: methods -> methods?
Jialiu Lin
2017/01/11 02:53:16
Done.
| |
| 58 void OnProceed() override; | |
| 59 void OnDontProceed() override; | |
| 60 void CommandReceived(const std::string& command) override; | |
| 61 | |
| 62 protected: | |
| 63 // Don't instantiate this class directly, use ShowBlockingPage instead. | |
| 64 BaseBlockingPage( | |
| 65 BaseUIManager* ui_manager, | |
| 66 content::WebContents* web_contents, | |
| 67 const GURL& main_frame_url, | |
| 68 const UnsafeResourceList& unsafe_resources, | |
| 69 std::unique_ptr< | |
| 70 security_interstitials::SecurityInterstitialControllerClient> | |
| 71 controller_client, | |
| 72 SafeBrowsingErrorUI::SBErrorDisplayOptions* display_options); | |
| 73 | |
| 74 // SecurityInterstitialPage methods: | |
| 75 bool ShouldCreateNewNavigation() const override; | |
| 76 void PopulateInterstitialStrings( | |
| 77 base::DictionaryValue* load_time_data) override; | |
| 78 | |
| 79 // Called when the interstitial is going away. Intentionally do nothing in | |
| 80 // this base class. Overrided by SafeBrowsingBlockingPage class. | |
|
meacer
2017/01/11 01:33:31
nit: Overrided -> Overridden (though I think only
Jialiu Lin
2017/01/11 02:53:16
Done.
| |
| 81 virtual void FinishThreatDetails(int64_t delay_ms, | |
| 82 bool did_proceed, | |
| 83 int num_visits); | |
| 84 | |
| 85 // A list of SafeBrowsingUIManager::UnsafeResource for a tab that the user | |
| 86 // should be warned about. They are queued when displaying more than one | |
|
meacer
2017/01/11 01:33:31
nit: Double spaces after period
Jialiu Lin
2017/01/11 02:53:16
Done.
| |
| 87 // interstitial at a time. | |
| 88 static UnsafeResourceMap* GetUnsafeResourcesMap(); | |
| 89 | |
| 90 static std::string GetMetricPrefix( | |
| 91 const UnsafeResourceList& unsafe_resources, | |
| 92 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason); | |
| 93 | |
| 94 static std::string GetExtraMetricsSuffix( | |
| 95 const UnsafeResourceList& unsafe_resources); | |
| 96 | |
| 97 static SafeBrowsingErrorUI::SBInterstitialReason GetInterstitialReason( | |
| 98 const UnsafeResourceList& unsafe_resources); | |
| 99 | |
| 100 // For reporting back user actions. | |
| 101 BaseUIManager* ui_manager_; | |
|
meacer
2017/01/11 01:33:31
In general fields shouldn't directly made availabl
Jialiu Lin
2017/01/11 02:53:16
Done.
| |
| 102 | |
| 103 // The URL of the main frame that caused the warning. | |
| 104 GURL main_frame_url_; | |
| 105 | |
| 106 // The index of a navigation entry that should be removed when DontProceed() | |
| 107 // is invoked, -1 if entry should not be removed. | |
| 108 const int navigation_entry_index_to_remove_; | |
| 109 | |
| 110 // The list of unsafe resources this page is warning about. | |
| 111 UnsafeResourceList unsafe_resources_; | |
| 112 | |
| 113 // For displaying safe browsing interstitial. | |
| 114 std::unique_ptr<SafeBrowsingErrorUI> sb_error_ui_; | |
| 115 | |
| 116 // Indicate whether user has proceeded this blocking page. | |
| 117 bool proceeded_; | |
| 118 | |
| 119 // Which type of Safe Browsing interstitial this is. | |
| 120 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason_; | |
| 121 | |
| 122 private: | |
| 123 static std::unique_ptr< | |
| 124 security_interstitials::SecurityInterstitialControllerClient> | |
| 125 CreateControllerClient(content::WebContents* web_contents, | |
| 126 const UnsafeResourceList& unsafe_resources, | |
| 127 history::HistoryService* history_service, | |
| 128 const std::string& app_locale, | |
| 129 const GURL& default_safe_page); | |
| 130 | |
| 131 static SafeBrowsingErrorUI::SBErrorDisplayOptions* | |
| 132 CreateDefaultDisplayOptions(const UnsafeResourceList& unsafe_resources); | |
| 133 | |
| 134 DISALLOW_COPY_AND_ASSIGN(BaseBlockingPage); | |
| 135 }; | |
| 136 | |
| 137 } // namespace safe_browsing | |
| 138 | |
| 139 #endif // COMPONENTS_SAFE_BROWSING_BASE_BLOCKING_PAGE_H_ | |
| OLD | NEW |