#include "extensions/browser/script_injection_tracker.h"
#include "base/check_is_test.h"
#include "base/containers/contains.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ref.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_number_conversions.h"
#include "base/trace_event/typed_macros.h"
#include "components/sessions/content/session_tab_helper.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/global_routing_id.h"
#include "content/public/browser/navigation_handle.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 "extensions/browser/browser_frame_context_data.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/url_loader_factory_manager.h"
#include "extensions/browser/user_script_manager.h"
#include "extensions/common/constants.h"
#include "extensions/common/content_script_injection_url_getter.h"
#include "extensions/common/extension.h"
#include "extensions/common/manifest_handlers/content_scripts_handler.h"
#include "extensions/common/permissions/permissions_data.h"
#include "extensions/common/trace_util.h"
#include "extensions/common/user_script.h"
#include "services/metrics/public/cpp/metrics_utils.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#if BUILDFLAG(ENABLE_GUEST_VIEW)
#include "components/guest_view/browser/guest_view_base.h"
#include "extensions/browser/guest_view/web_view/web_view_content_script_manager.h"
#endif
ChromeTrackEvent;
namespace extensions {
namespace {
class RenderProcessHostUserData : public base::SupportsUserData::Data { … };
const char* RenderProcessHostUserData::kUserDataKey = …;
std::vector<const UserScript*> GetVectorFromScriptList(
const UserScriptList& scripts) { … }
std::vector<const UserScript*> GetLoadedDynamicScripts(
const ExtensionId& extension_id,
UserScript::Source source,
content::RenderProcessHost& process) { … }
GURL GetEffectiveDocumentURL(
content::RenderFrameHost* frame,
const GURL& document_url,
MatchOriginAsFallbackBehavior match_origin_as_fallback) { … }
bool CanExtensionScriptsAffectFrame(content::RenderFrameHost& frame,
const Extension& extension) { … }
bool DoesScriptMatch(const Extension& extension,
const UserScript& script,
content::RenderFrameHost& frame,
const GURL& url) { … }
void HandleProgrammaticScriptInjection(
base::PassKey<ScriptInjectionTracker> pass_key,
ScriptInjectionTracker::ScriptType script_type,
content::RenderFrameHost* frame,
const Extension& extension) { … }
bool DoScriptsMatch(const Extension& extension,
const std::vector<const UserScript*>& scripts,
content::RenderFrameHost& frame,
const GURL& url) { … }
bool DoWebViewScripstMatch(const Extension& extension,
content::RenderFrameHost& frame) { … }
bool DoStaticContentScriptsMatch(const Extension& extension,
content::RenderFrameHost& frame,
const GURL& url) { … }
bool DoDynamicContentScriptsMatch(const Extension& extension,
content::RenderFrameHost& frame,
const GURL& url) { … }
bool DoUserScriptsMatch(const Extension& extension,
content::RenderFrameHost& frame,
const GURL& url) { … }
std::vector<const Extension*> GetExtensionsInjectingContentScripts(
const ExtensionSet& extensions,
content::RenderFrameHost& frame,
const GURL& url) { … }
void AddMatchingScriptsToProcess(const Extension& extension,
content::RenderProcessHost& process) { … }
std::vector<const Extension*> GetExtensionsInjectingUserScripts(
const ExtensionSet& extensions,
content::RenderFrameHost& frame,
const GURL& url) { … }
void RecordUkm(content::NavigationHandle* navigation,
int extensions_injecting_content_script_count) { … }
const Extension* FindExtensionByHostId(content::BrowserContext* browser_context,
const mojom::HostID& host_id) { … }
void StoreExtensionsInjectingScripts(
const std::vector<const Extension*>& extensions,
ScriptInjectionTracker::ScriptType script_type,
content::RenderProcessHost& process) { … }
bool DidProcessRunScriptFromExtension(
ScriptInjectionTracker::ScriptType script_type,
const content::RenderProcessHost& process,
const ExtensionId& extension_id) { … }
}
ExtensionIdSet
ScriptInjectionTracker::GetExtensionsThatRanContentScriptsInProcess(
const content::RenderProcessHost& process) { … }
bool ScriptInjectionTracker::DidProcessRunContentScriptFromExtension(
const content::RenderProcessHost& process,
const ExtensionId& extension_id) { … }
bool ScriptInjectionTracker::DidProcessRunUserScriptFromExtension(
const content::RenderProcessHost& process,
const ExtensionId& extension_id) { … }
void ScriptInjectionTracker::ReadyToCommitNavigation(
base::PassKey<ExtensionWebContentsObserver> pass_key,
content::NavigationHandle* navigation) { … }
void ScriptInjectionTracker::DidFinishNavigation(
base::PassKey<ExtensionWebContentsObserver> pass_key,
content::NavigationHandle* navigation) { … }
void ScriptInjectionTracker::WillExecuteCode(
base::PassKey<ScriptExecutor> pass_key,
ScriptType script_type,
content::RenderFrameHost* frame,
const mojom::HostID& host_id) { … }
void ScriptInjectionTracker::WillExecuteCode(
base::PassKey<RequestContentScript> pass_key,
content::RenderFrameHost* frame,
const Extension& extension) { … }
void ScriptInjectionTracker::WillGrantActiveTab(
base::PassKey<ActiveTabPermissionGranter> pass_key,
const Extension& extension,
content::RenderProcessHost& process) { … }
void ScriptInjectionTracker::DidUpdateScriptsInRenderer(
base::PassKey<UserScriptLoader> pass_key,
const mojom::HostID& host_id,
content::RenderProcessHost& process) { … }
void ScriptInjectionTracker::DidUpdatePermissionsInRenderer(
base::PassKey<PermissionsUpdater> pass_key,
const Extension& extension,
content::RenderProcessHost& process) { … }
bool ScriptInjectionTracker::DoStaticContentScriptsMatchForTesting(
const Extension& extension,
content::RenderFrameHost* frame,
const GURL& url) { … }
namespace debug {
namespace {
base::debug::CrashKeyString* GetRegistryStatusCrashKey() { … }
std::string GetRegistryStatusValue(const ExtensionId& extension_id,
content::BrowserContext& browser_context) { … }
base::debug::CrashKeyString* GetIsIncognitoCrashKey() { … }
base::debug::CrashKeyString* GetLastCommittedOriginCrashKey() { … }
base::debug::CrashKeyString* GetLastCommittedUrlCrashKey() { … }
base::debug::CrashKeyString* GetLifecycleStateCrashKey() { … }
#if BUILDFLAG(ENABLE_GUEST_VIEW)
base::debug::CrashKeyString* GetIsGuestCrashKey() { … }
#endif
base::debug::CrashKeyString* GetDoWebViewScriptsMatchCrashKey() { … }
base::debug::CrashKeyString* GetDoStaticContentScriptsMatchCrashKey() { … }
base::debug::CrashKeyString* GetDoDynamicContentScriptsMatchCrashKey() { … }
base::debug::CrashKeyString* GetDoUserScriptsMatchCrashKey() { … }
const char* BoolToCrashKeyValue(bool value) { … }
}
ScopedScriptInjectionTrackerFailureCrashKeys::
ScopedScriptInjectionTrackerFailureCrashKeys(
content::BrowserContext& browser_context,
const ExtensionId& extension_id)
: … { … }
ScopedScriptInjectionTrackerFailureCrashKeys::
ScopedScriptInjectionTrackerFailureCrashKeys(
content::RenderFrameHost& frame,
const ExtensionId& extension_id)
: … { … }
ScopedScriptInjectionTrackerFailureCrashKeys::
~ScopedScriptInjectionTrackerFailureCrashKeys() = default;
}
}