#include "components/safe_browsing/content/browser/threat_details.h"
#include <stddef.h>
#include <stdint.h>
#include <memory>
#include <unordered_set>
#include <utility>
#include <vector>
#include "base/containers/contains.h"
#include "base/containers/fixed_flat_set.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/lazy_instance.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "components/back_forward_cache/back_forward_cache_disable.h"
#include "components/history/core/browser/history_service.h"
#include "components/safe_browsing/content/browser/async_check_tracker.h"
#include "components/safe_browsing/content/browser/base_ui_manager.h"
#include "components/safe_browsing/content/browser/client_report_util.h"
#include "components/safe_browsing/content/browser/threat_details_cache.h"
#include "components/safe_browsing/content/browser/threat_details_history.h"
#include "components/safe_browsing/content/browser/unsafe_resource_util.h"
#include "components/safe_browsing/content/browser/web_contents_key.h"
#include "components/safe_browsing/content/browser/web_ui/safe_browsing_ui.h"
#include "components/safe_browsing/core/browser/db/hit_report.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/proto/csd.pb.h"
#include "content/public/browser/back_forward_cache.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/mojom/fetch_api.mojom.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/protobuf/src/google/protobuf/repeated_ptr_field.h"
BrowserThread;
NavigationEntry;
WebContents;
static const uint32_t kMaxDomNodes = …;
namespace safe_browsing {
ThreatDetailsFactory* ThreatDetails::factory_ = …;
namespace {
const int kElementIdNoParent = …;
const int kThreatDetailsUserGestureLimit = …;
StringSet;
struct AllowlistedHttpsHeadersTraits
: base::internal::DestructorAtExitLazyInstanceTraits<StringSet> { … };
base::LazyInstance<StringSet, AllowlistedHttpsHeadersTraits>
g_https_headers_allowlist = …;
void ClearHttpsResource(ClientSafeBrowsingReportRequest::Resource* resource) { … }
std::string GetElementKey(const int frame_tree_node_id,
const int element_node_id) { … }
void TrimElements(const std::set<int> target_ids,
ElementMap* elements,
ResourceMap* resources) { … }
}
class ThreatDetailsFactoryImpl : public ThreatDetailsFactory { … };
static base::LazyInstance<ThreatDetailsFactoryImpl>::DestructorAtExit
g_threat_details_factory_impl = …;
std::unique_ptr<ThreatDetails> ThreatDetails::NewThreatDetails(
BaseUIManager* ui_manager,
WebContents* web_contents,
const UnsafeResource& resource,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
history::HistoryService* history_service,
ReferrerChainProvider* referrer_chain_provider,
bool trim_to_ad_tags,
ThreatDetailsDoneCallback done_callback) { … }
ThreatDetails::ThreatDetails(
BaseUIManager* ui_manager,
content::WebContents* web_contents,
const UnsafeResource& resource,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
history::HistoryService* history_service,
ReferrerChainProvider* referrer_chain_provider,
bool trim_to_ad_tags,
ThreatDetailsDoneCallback done_callback)
: … { … }
ThreatDetails::ThreatDetails()
: … { … }
ThreatDetails::~ThreatDetails() = default;
ClientSafeBrowsingReportRequest::Resource* ThreatDetails::FindOrCreateResource(
const GURL& url) { … }
HTMLElement* ThreatDetails::FindOrCreateElement(
const std::string& element_key) { … }
ClientSafeBrowsingReportRequest::Resource* ThreatDetails::AddUrl(
const GURL& url,
const GURL& parent,
const std::string& tagname,
const std::vector<GURL>* children) { … }
void ThreatDetails::AddDomElement(
const int frame_tree_node_id,
const int element_node_id,
const std::string& tagname,
const int parent_element_node_id,
const std::vector<mojom::AttributeNameValuePtr> attributes,
const std::string& inner_html,
const ClientSafeBrowsingReportRequest::Resource* resource) { … }
void ThreatDetails::StartCollection() { … }
void ThreatDetails::RequestThreatDOMDetails(content::RenderFrameHost* frame) { … }
void ThreatDetails::OnReceivedThreatDOMDetails(
mojo::Remote<mojom::ThreatReporter> threat_reporter,
content::WeakDocumentPtr sender,
std::vector<mojom::ThreatDOMDetailsNodePtr> params) { … }
void ThreatDetails::AddDOMDetails(
const int frame_tree_node_id,
std::vector<mojom::ThreatDOMDetailsNodePtr> params,
const KeyToFrameTreeIdMap& child_frame_tree_map) { … }
void ThreatDetails::FinishCollection(
bool did_proceed,
int num_visit,
std::unique_ptr<security_interstitials::InterstitialInteractionMap>
interstitial_interactions,
std::optional<int64_t> warning_shown_ts) { … }
void ThreatDetails::OnRedirectionCollectionReady() { … }
void ThreatDetails::AddRedirectUrlList(const std::vector<GURL>& urls) { … }
void ThreatDetails::OnCacheCollectionReady() { … }
bool ThreatDetails::ShouldFillReferrerChain() { … }
void ThreatDetails::FillReferrerChain(
google::protobuf::RepeatedPtrField<ReferrerChainEntry>*
out_referrer_chain) { … }
bool ThreatDetails::ShouldFillInterstitialInteractions() { … }
void ThreatDetails::MaybeAttachThreatDetailsAndLaunchSurvey() { … }
void ThreatDetails::AllDone() { … }
base::WeakPtr<ThreatDetails> ThreatDetails::GetWeakPtr() { … }
}