#include "extensions/renderer/script_injection_manager.h"
#include <memory>
#include <optional>
#include <utility>
#include <vector>
#include "base/auto_reset.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/ranges/algorithm.h"
#include "base/values.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_frame_observer.h"
#include "content/public/renderer/render_thread.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_features.h"
#include "extensions/common/extension_id.h"
#include "extensions/common/extension_set.h"
#include "extensions/common/mojom/host_id.mojom.h"
#include "extensions/renderer/extension_frame_helper.h"
#include "extensions/renderer/extension_injection_host.h"
#include "extensions/renderer/programmatic_script_injector.h"
#include "extensions/renderer/renderer_extension_registry.h"
#include "extensions/renderer/script_injection.h"
#include "extensions/renderer/scripts_run_info.h"
#include "extensions/renderer/web_ui_injection_host.h"
#include "ipc/ipc_message_macros.h"
#include "third_party/blink/public/platform/web_url_error.h"
#include "third_party/blink/public/web/web_document.h"
#include "third_party/blink/public/web/web_frame.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "third_party/blink/public/web/web_view.h"
#include "url/gurl.h"
namespace extensions {
namespace {
const int kScriptIdleTimeoutInMs = …;
std::optional<mojom::RunLocation> NextRunLocation(
mojom::RunLocation run_location) { … }
}
class ScriptInjectionManager::RFOHelper : public content::RenderFrameObserver { … };
ScriptInjectionManager::RFOHelper::RFOHelper(content::RenderFrame* render_frame,
ScriptInjectionManager* manager)
: … { … }
ScriptInjectionManager::RFOHelper::~RFOHelper() { … }
void ScriptInjectionManager::RFOHelper::Initialize() { … }
void ScriptInjectionManager::RFOHelper::DidCreateNewDocument() { … }
void ScriptInjectionManager::RFOHelper::DidCreateDocumentElement() { … }
void ScriptInjectionManager::RFOHelper::DidFailProvisionalLoad() { … }
void ScriptInjectionManager::RFOHelper::DidDispatchDOMContentLoadedEvent() { … }
void ScriptInjectionManager::RFOHelper::WillDetach(
blink::DetachReason detach_reason) { … }
void ScriptInjectionManager::RFOHelper::OnDestruct() { … }
void ScriptInjectionManager::RFOHelper::OnStop() { … }
void ScriptInjectionManager::RFOHelper::RunIdle() { … }
void ScriptInjectionManager::RFOHelper::StartInjectScripts(
mojom::RunLocation run_location) { … }
void ScriptInjectionManager::RFOHelper::InvalidateAndResetFrame(
bool force_reset) { … }
ScriptInjectionManager::ScriptInjectionManager(
UserScriptSetManager* user_script_set_manager)
: … { … }
ScriptInjectionManager::~ScriptInjectionManager() { … }
void ScriptInjectionManager::OnRenderFrameCreated(
content::RenderFrame* render_frame) { … }
void ScriptInjectionManager::OnExtensionUnloaded(
const ExtensionId& extension_id) { … }
void ScriptInjectionManager::OnInjectionFinished(ScriptInjection* injection) { … }
void ScriptInjectionManager::OnUserScriptsUpdated(
const mojom::HostID& changed_host) { … }
void ScriptInjectionManager::RemoveObserver(RFOHelper* helper) { … }
void ScriptInjectionManager::InvalidateForFrame(content::RenderFrame* frame) { … }
void ScriptInjectionManager::StartInjectScripts(
content::RenderFrame* frame,
mojom::RunLocation run_location) { … }
void ScriptInjectionManager::InjectScripts(content::RenderFrame* frame,
mojom::RunLocation run_location) { … }
void ScriptInjectionManager::OnInjectionStatusUpdated(
ScriptInjection::InjectionStatus status,
ScriptInjection* injection) { … }
void ScriptInjectionManager::TryToInject(
std::unique_ptr<ScriptInjection> injection,
mojom::RunLocation run_location,
ScriptsRunInfo* scripts_run_info) { … }
void ScriptInjectionManager::HandleExecuteCode(
mojom::ExecuteCodeParamsPtr params,
mojom::LocalFrame::ExecuteCodeCallback callback,
content::RenderFrame* render_frame) { … }
void ScriptInjectionManager::ExecuteDeclarativeScript(
content::RenderFrame* render_frame,
int tab_id,
const ExtensionId& extension_id,
const std::string& script_id,
const GURL& url) { … }
void ScriptInjectionManager::OnPermitScriptInjectionHandled(
ScriptInjection* injection) { … }
}