#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "extensions/browser/user_script_loader.h"
#include <stddef.h>
#include <set>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include "base/functional/bind.h"
#include "base/memory/writable_shared_memory_region.h"
#include "base/observer_list.h"
#include "base/strings/string_util.h"
#include "base/types/pass_key.h"
#include "base/version.h"
#include "build/build_config.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/renderer_startup_helper.h"
#include "extensions/browser/script_injection_tracker.h"
#include "extensions/common/mojom/run_location.mojom-shared.h"
#include "extensions/common/permissions/permissions_data.h"
#if BUILDFLAG(ENABLE_GUEST_VIEW)
#include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
#endif
BrowserThread;
BrowserContext;
namespace extensions {
namespace {
const char kUserScriptLoaderDestroyedErrorMsg[] = …;
const char kNoScriptChangesErrorMsg[] = …;
#if DCHECK_IS_ON()
bool AreScriptsUnique(const UserScriptList& scripts) { … }
#endif
bool GetDeclarationValue(std::string_view line,
std::string_view prefix,
std::string* value) { … }
#if BUILDFLAG(ENABLE_GUEST_VIEW)
bool CanExecuteScriptEverywhere(BrowserContext* browser_context,
const mojom::HostID& host_id) { … }
#endif
}
bool UserScriptLoader::ParseMetadataHeader(std::string_view script_text,
UserScript* script) { … }
UserScriptLoader::UserScriptLoader(BrowserContext* browser_context,
const mojom::HostID& host_id)
: … { … }
UserScriptLoader::~UserScriptLoader() { … }
void UserScriptLoader::AddScripts(UserScriptList scripts,
ScriptsLoadedCallback callback) { … }
void UserScriptLoader::AddScripts(UserScriptList scripts,
int render_process_id,
int render_frame_id,
ScriptsLoadedCallback callback) { … }
void UserScriptLoader::RemoveScripts(const std::set<std::string>& script_ids,
ScriptsLoadedCallback callback) { … }
void UserScriptLoader::OnRenderProcessHostCreated(
content::RenderProcessHost* process_host) { … }
bool UserScriptLoader::ScriptsMayHaveChanged() const { … }
void UserScriptLoader::AttemptLoad(ScriptsLoadedCallback callback) { … }
void UserScriptLoader::StartLoad() { … }
bool UserScriptLoader::HasLoadedScripts() const { … }
base::ReadOnlySharedMemoryRegion UserScriptLoader::Serialize(
const UserScriptList& scripts) { … }
void UserScriptLoader::AddObserver(Observer* observer) { … }
void UserScriptLoader::RemoveObserver(Observer* observer) { … }
void UserScriptLoader::StartLoadForTesting(ScriptsLoadedCallback callback) { … }
void UserScriptLoader::SetReady(bool ready) { … }
void UserScriptLoader::OnScriptsLoaded(
UserScriptList user_scripts,
base::ReadOnlySharedMemoryRegion shared_memory) { … }
UserScriptLoader::SendUpdateResult UserScriptLoader::SendUpdate(
content::RenderProcessHost* process,
const base::ReadOnlySharedMemoryRegion& shared_memory) { … }
}