#include "components/safe_browsing/content/browser/safe_browsing_navigation_observer_manager.h"
#include <iterator>
#include <memory>
#include <vector>
#include "base/containers/contains.h"
#include "base/feature_list.h"
#include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/rand_util.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "components/prefs/pref_service.h"
#include "components/safe_browsing/content/browser/safe_browsing_navigation_observer.h"
#include "components/safe_browsing/content/browser/safe_browsing_navigation_observer_manager_util.h"
#include "components/safe_browsing/content/browser/web_ui/safe_browsing_ui.h"
#include "components/safe_browsing/core/browser/referrer_chain_provider.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "components/safe_browsing/core/common/utils.h"
#include "components/sessions/content/session_tab_helper.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/global_routing_id.h"
#include "content/public/browser/navigation_details.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/service_worker_context.h"
#include "content/public/browser/web_contents.h"
#include "crypto/sha2.h"
#include "ui/base/clipboard/clipboard.h"
WebContents;
namespace safe_browsing {
namespace {
static constexpr base::TimeDelta kUserGestureTTL = …;
static constexpr base::TimeDelta kNavigationFootprintTTL = …;
static const int kNavigationRecordMaxSize = …;
static const int kReferrerChainMaxLength = …;
constexpr size_t kMaxNumberOfNavigationsToAppend = …;
bool IsEventExpired(const base::Time& event_time, base::TimeDelta ttl) { … }
ReferrerChainEntry::URLType GetURLTypeAndAdjustAttributionResult(
size_t user_gesture_count,
SafeBrowsingNavigationObserverManager::AttributionResult* out_result) { … }
std::string ShortOriginForReporting(const std::string& url) { … }
}
const char ReferrerChainData::kDownloadReferrerChainDataKey[] = …;
ReferrerChainData::ReferrerChainData(
ReferrerChainProvider::AttributionResult attribution_result,
std::unique_ptr<ReferrerChain> referrer_chain,
size_t referrer_chain_length,
size_t recent_navigations_to_collect)
: … { … }
ReferrerChainData::~ReferrerChainData() { … }
ReferrerChain* ReferrerChainData::GetReferrerChain() { … }
NavigationEventList::NavigationEventList(std::size_t size_limit)
: … { … }
NavigationEventList::~NavigationEventList() = default;
std::optional<size_t> NavigationEventList::FindNavigationEvent(
const base::Time& last_event_timestamp,
const GURL& target_url,
const GURL& target_main_frame_url,
SessionID target_tab_id,
const content::GlobalRenderFrameHostId& outermost_main_frame_id,
size_t start_index) { … }
NavigationEvent* NavigationEventList::FindPendingNavigationEvent(
const GURL& target_url) { … }
size_t NavigationEventList::FindRetargetingNavigationEvent(
const base::Time& last_event_timestamp,
SessionID target_tab_id,
size_t start_index) { … }
void NavigationEventList::RecordNavigationEvent(
std::unique_ptr<NavigationEvent> nav_event,
std::optional<CopyPasteEntry> last_copy_paste_entry) { … }
void NavigationEventList::RecordPendingNavigationEvent(
content::NavigationHandle* navigation_handle,
std::unique_ptr<NavigationEvent> nav_event) { … }
void NavigationEventList::AddRedirectUrlToPendingNavigationEvent(
content::NavigationHandle* navigation_handle,
const GURL& server_redirect_url) { … }
void NavigationEventList::RemovePendingNavigationEvent(
content::NavigationHandle* navigation_handle) { … }
std::size_t NavigationEventList::CleanUpNavigationEvents() { … }
CopyPasteEntry::CopyPasteEntry(GURL target,
GURL source_frame_url,
GURL source_main_frame_url,
base::Time recorded_time)
: … { … }
CopyPasteEntry::CopyPasteEntry(const CopyPasteEntry& other) = default;
bool SafeBrowsingNavigationObserverManager::IsUserGestureExpired(
const base::Time& timestamp) { … }
GURL SafeBrowsingNavigationObserverManager::ClearURLRef(const GURL& url) { … }
bool SafeBrowsingNavigationObserverManager::IsEnabledAndReady(
PrefService* prefs,
bool has_safe_browsing_service) { … }
void SafeBrowsingNavigationObserverManager::SanitizeReferrerChain(
ReferrerChain* referrer_chain) { … }
SafeBrowsingNavigationObserverManager::SafeBrowsingNavigationObserverManager(
PrefService* pref_service,
content::ServiceWorkerContext* context)
: … { … }
void SafeBrowsingNavigationObserverManager::RecordNavigationEvent(
content::NavigationHandle* navigation_handle,
std::unique_ptr<NavigationEvent> nav_event) { … }
void SafeBrowsingNavigationObserverManager::RecordPendingNavigationEvent(
content::NavigationHandle* navigation_handle,
std::unique_ptr<NavigationEvent> nav_event) { … }
void SafeBrowsingNavigationObserverManager::
AddRedirectUrlToPendingNavigationEvent(
content::NavigationHandle* navigation_handle,
const GURL& server_redirect_url) { … }
void SafeBrowsingNavigationObserverManager::RecordUserGestureForWebContents(
content::WebContents* web_contents) { … }
void SafeBrowsingNavigationObserverManager::OnUserGestureConsumed(
content::WebContents* web_contents) { … }
bool SafeBrowsingNavigationObserverManager::HasUserGesture(
content::WebContents* web_contents) { … }
bool SafeBrowsingNavigationObserverManager::HasUnexpiredUserGesture(
content::WebContents* web_contents) { … }
void SafeBrowsingNavigationObserverManager::RecordHostToIpMapping(
const std::string& host,
const std::string& ip) { … }
void SafeBrowsingNavigationObserverManager::OnWebContentDestroyed(
content::WebContents* web_contents) { … }
void SafeBrowsingNavigationObserverManager::CleanUpStaleNavigationFootprints() { … }
SafeBrowsingNavigationObserverManager::AttributionResult
SafeBrowsingNavigationObserverManager::IdentifyReferrerChainByEventURL(
const GURL& event_url,
SessionID event_tab_id,
const content::GlobalRenderFrameHostId& outermost_main_frame_id,
int user_gesture_count_limit,
ReferrerChain* out_referrer_chain) { … }
SafeBrowsingNavigationObserverManager::AttributionResult
SafeBrowsingNavigationObserverManager::IdentifyReferrerChainByEventURL(
const GURL& event_url,
SessionID event_tab_id,
int user_gesture_count_limit,
ReferrerChain* out_referrer_chain) { … }
SafeBrowsingNavigationObserverManager::AttributionResult
SafeBrowsingNavigationObserverManager::IdentifyReferrerChainByPendingEventURL(
const GURL& event_url,
int user_gesture_count_limit,
ReferrerChain* out_referrer_chain) { … }
SafeBrowsingNavigationObserverManager::AttributionResult
SafeBrowsingNavigationObserverManager::IdentifyReferrerChainByRenderFrameHost(
content::RenderFrameHost* render_frame_host,
int user_gesture_count_limit,
ReferrerChain* out_referrer_chain) { … }
SafeBrowsingNavigationObserverManager::AttributionResult
SafeBrowsingNavigationObserverManager::IdentifyReferrerChainByHostingPage(
const GURL& initiating_frame_url,
const GURL& initiating_main_frame_url,
const content::GlobalRenderFrameHostId& initiating_outermost_main_frame_id,
SessionID tab_id,
bool has_user_gesture,
int user_gesture_count_limit,
ReferrerChain* out_referrer_chain) { … }
SafeBrowsingNavigationObserverManager::
~SafeBrowsingNavigationObserverManager() { … }
void SafeBrowsingNavigationObserverManager::RecordNewWebContents(
content::WebContents* source_web_contents,
content::RenderFrameHost* source_render_frame_host,
const GURL& target_url,
ui::PageTransition page_transition,
content::WebContents* target_web_contents,
bool renderer_initiated) { … }
size_t SafeBrowsingNavigationObserverManager::CountOfRecentNavigationsToAppend(
content::BrowserContext* browser_context,
PrefService* prefs,
AttributionResult result) { … }
void SafeBrowsingNavigationObserverManager::AppendRecentNavigations(
size_t recent_navigation_count,
ReferrerChain* out_referrer_chain) { … }
void SafeBrowsingNavigationObserverManager::OnCopyURL(
const GURL& url,
const GURL& source_frame_url,
const GURL& source_main_frame_url) { … }
void SafeBrowsingNavigationObserverManager::CleanUpNavigationEvents() { … }
void SafeBrowsingNavigationObserverManager::CleanUpUserGestures() { … }
void SafeBrowsingNavigationObserverManager::CleanUpIpAddresses() { … }
void SafeBrowsingNavigationObserverManager::CleanUpCopyData() { … }
void SafeBrowsingNavigationObserverManager::
CleanUpNotificationNavigationEvents() { … }
bool SafeBrowsingNavigationObserverManager::IsCleanUpScheduled() const { … }
void SafeBrowsingNavigationObserverManager::ScheduleNextCleanUpAfterInterval(
base::TimeDelta interval) { … }
void SafeBrowsingNavigationObserverManager::OnClientNavigated(
const GURL& script_url,
const GURL& url) { … }
void SafeBrowsingNavigationObserverManager::OnWindowOpened(
const GURL& script_url,
const GURL& url) { … }
void SafeBrowsingNavigationObserverManager::RecordNotificationNavigationEvent(
const GURL& script_url,
const GURL& url) { … }
void SafeBrowsingNavigationObserverManager::MaybeAddToReferrerChain(
ReferrerChain* referrer_chain,
NavigationEvent* nav_event,
const GURL& destination_main_frame_url,
ReferrerChainEntry::URLType type) { … }
void SafeBrowsingNavigationObserverManager::GetRemainingReferrerChain(
size_t last_nav_event_traced_index,
int current_user_gesture_count,
int user_gesture_count_limit,
ReferrerChain* out_referrer_chain,
SafeBrowsingNavigationObserverManager::AttributionResult* out_result) { … }
void SafeBrowsingNavigationObserverManager::
GetRemainingReferrerChainForNavEvent(
NavigationEvent* last_nav_event_traced,
size_t last_nav_event_traced_index,
int current_user_gesture_count,
int user_gesture_count_limit,
ReferrerChain* out_referrer_chain,
SafeBrowsingNavigationObserverManager::AttributionResult* out_result) { … }
void SafeBrowsingNavigationObserverManager::RemoveSafeBrowsingAllowlistDomains(
ReferrerChain* out_referrer_chain) { … }
}