#ifndef COMPONENTS_SAFE_BROWSING_CONTENT_BROWSER_BASE_BLOCKING_PAGE_H_
#define COMPONENTS_SAFE_BROWSING_CONTENT_BROWSER_BASE_BLOCKING_PAGE_H_
#include <map>
#include <string>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "components/safe_browsing/content/browser/base_ui_manager.h"
#include "components/safe_browsing/core/browser/db/v4_protocol_manager_util.h"
#include "components/security_interstitials/content/security_interstitial_page.h"
#include "components/security_interstitials/core/base_safe_browsing_error_ui.h"
#include "components/security_interstitials/core/metrics_helper.h"
#include "url/gurl.h"
namespace content {
class NavigationHandle;
}
namespace security_interstitials {
class SettingsPageHelper;
}
namespace safe_browsing {
class BaseBlockingPage
: public security_interstitials::SecurityInterstitialPage {
public:
typedef security_interstitials::UnsafeResource UnsafeResource;
typedef security_interstitials::BaseSafeBrowsingErrorUI
BaseSafeBrowsingErrorUI;
typedef std::vector<UnsafeResource> UnsafeResourceList;
typedef std::unordered_map<content::WebContents*, UnsafeResourceList>
UnsafeResourceMap;
BaseBlockingPage(const BaseBlockingPage&) = delete;
BaseBlockingPage& operator=(const BaseBlockingPage&) = delete;
~BaseBlockingPage() override;
static const BaseSafeBrowsingErrorUI::SBErrorDisplayOptions
CreateDefaultDisplayOptions(const UnsafeResourceList& unsafe_resources);
static bool IsMainPageLoadBlocked(const UnsafeResourceList& unsafe_resources);
void CommandReceived(const std::string& command) override;
static bool ShouldReportThreatDetails(SBThreatType threat_type);
static security_interstitials::MetricsHelper::ReportDetails GetReportingInfo(
const UnsafeResourceList& unsafe_resources);
static std::unique_ptr<
security_interstitials::SecurityInterstitialControllerClient>
CreateControllerClient(
content::WebContents* web_contents,
const UnsafeResourceList& unsafe_resources,
BaseUIManager* ui_manager,
PrefService* pref_service,
std::unique_ptr<security_interstitials::SettingsPageHelper>
settings_page_helper);
virtual void CreatedPostCommitErrorPageNavigation(
content::NavigationHandle* error_page_navigation_handle) {}
protected:
BaseBlockingPage(
BaseUIManager* ui_manager,
content::WebContents* web_contents,
const GURL& main_frame_url,
const UnsafeResourceList& unsafe_resources,
std::unique_ptr<
security_interstitials::SecurityInterstitialControllerClient>
controller_client,
const BaseSafeBrowsingErrorUI::SBErrorDisplayOptions& display_options);
void PopulateInterstitialStrings(base::Value::Dict& load_time_data) override;
void OnInterstitialClosing() override {}
virtual void FinishThreatDetails(const base::TimeDelta& delay,
bool did_proceed,
int num_visits);
static UnsafeResourceMap* GetUnsafeResourcesMap();
static std::string GetMetricPrefix(
const UnsafeResourceList& unsafe_resources,
BaseSafeBrowsingErrorUI::SBInterstitialReason interstitial_reason);
static std::string GetExtraMetricsSuffix(
const UnsafeResourceList& unsafe_resources);
static BaseSafeBrowsingErrorUI::SBInterstitialReason GetInterstitialReason(
const UnsafeResourceList& unsafe_resources);
BaseUIManager* ui_manager() const;
const GURL main_frame_url() const;
UnsafeResourceList unsafe_resources() const;
bool proceeded() const;
int64_t threat_details_proceed_delay() const;
BaseSafeBrowsingErrorUI* sb_error_ui() const;
void set_proceeded(bool proceeded);
void SetThreatDetailsProceedDelayForTesting(int64_t delay);
int GetHTMLTemplateId() override;
void set_sb_error_ui(std::unique_ptr<BaseSafeBrowsingErrorUI> sb_error_ui);
void OnDontProceedDone();
private:
raw_ptr<BaseUIManager> ui_manager_;
GURL main_frame_url_;
const int navigation_entry_index_to_remove_;
UnsafeResourceList unsafe_resources_;
bool proceeded_;
int64_t threat_details_proceed_delay_ms_;
std::unique_ptr<BaseSafeBrowsingErrorUI> sb_error_ui_;
};
}
#endif