#include "extensions/renderer/script_context.h"
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/containers/flat_set.h"
#include "base/logging.h"
#include "base/no_destructor.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/url_constants.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/v8_value_converter.h"
#include "extensions/common/constants.h"
#include "extensions/common/content_script_injection_url_getter.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_api.h"
#include "extensions/common/extension_urls.h"
#include "extensions/common/manifest_handlers/sandboxed_page_info.h"
#include "extensions/common/mojom/context_type.mojom.h"
#include "extensions/common/permissions/permissions_data.h"
#include "extensions/common/switches.h"
#include "extensions/renderer/dispatcher.h"
#include "extensions/renderer/isolated_world_manager.h"
#include "extensions/renderer/renderer_context_data.h"
#include "extensions/renderer/renderer_extension_registry.h"
#include "extensions/renderer/renderer_frame_context_data.h"
#include "extensions/renderer/v8_helpers.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_registration.mojom.h"
#include "third_party/blink/public/web/web_document_loader.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "v8/include/v8-context.h"
#include "v8/include/v8-debug.h"
#include "v8/include/v8-function.h"
#include "v8/include/v8-isolate.h"
#include "v8/include/v8-microtask-queue.h"
#include "v8/include/v8-primitive.h"
namespace extensions {
namespace {
GURL GetEffectiveDocumentURL(
blink::WebLocalFrame* frame,
const GURL& document_url,
MatchOriginAsFallbackBehavior match_origin_as_fallback,
bool allow_inaccessible_parents) { … }
std::string GetContextTypeDescriptionString(mojom::ContextType context_type) { … }
static std::string ToStringOrDefault(v8::Isolate* isolate,
const v8::Local<v8::String>& v8_string,
const std::string& dflt) { … }
FrameToDocumentLoader;
FrameToDocumentLoader& FrameDocumentLoaderMap() { … }
blink::WebDocumentLoader* CurrentDocumentLoader(
const blink::WebLocalFrame* frame) { … }
}
ScriptContext::ScopedFrameDocumentLoader::ScopedFrameDocumentLoader(
blink::WebLocalFrame* frame,
blink::WebDocumentLoader* document_loader)
: … { … }
ScriptContext::ScopedFrameDocumentLoader::~ScopedFrameDocumentLoader() { … }
ScriptContext::ScriptContext(const v8::Local<v8::Context>& v8_context,
blink::WebLocalFrame* web_frame,
const mojom::HostID& host_id,
const Extension* extension,
std::optional<int> blink_isolated_world_id,
mojom::ContextType context_type,
const Extension* effective_extension,
mojom::ContextType effective_context_type)
: … { … }
ScriptContext::~ScriptContext() { … }
bool ScriptContext::IsSandboxedPage(const GURL& url) { … }
void ScriptContext::SetModuleSystem(
std::unique_ptr<ModuleSystem> module_system) { … }
void ScriptContext::Invalidate() { … }
void ScriptContext::AddInvalidationObserver(base::OnceClosure observer) { … }
const std::string& ScriptContext::GetExtensionID() const { … }
content::RenderFrame* ScriptContext::GetRenderFrame() const { … }
void ScriptContext::SafeCallFunction(const v8::Local<v8::Function>& function,
int argc,
v8::Local<v8::Value> argv[]) { … }
void ScriptContext::SafeCallFunction(
const v8::Local<v8::Function>& function,
int argc,
v8::Local<v8::Value> argv[],
blink::WebScriptExecutionCallback callback) { … }
Feature::Availability ScriptContext::GetAvailability(
const std::string& api_name) { … }
Feature::Availability ScriptContext::GetAvailability(
const std::string& api_name,
CheckAliasStatus check_alias) { … }
std::string ScriptContext::GetContextTypeDescription() const { … }
std::string ScriptContext::GetEffectiveContextTypeDescription() const { … }
const GURL& ScriptContext::service_worker_scope() const { … }
bool ScriptContext::IsForServiceWorker() const { … }
bool ScriptContext::IsAnyFeatureAvailableToContext(
const Feature& api,
CheckAliasStatus check_alias) { … }
GURL ScriptContext::GetDocumentLoaderURLForFrame(
const blink::WebLocalFrame* frame) { … }
GURL ScriptContext::GetAccessCheckedFrameURL(
const blink::WebLocalFrame* frame) { … }
GURL ScriptContext::GetEffectiveDocumentURLForContext(
blink::WebLocalFrame* frame,
const GURL& document_url,
bool match_about_blank) { … }
GURL ScriptContext::GetEffectiveDocumentURLForInjection(
blink::WebLocalFrame* frame,
const GURL& document_url,
MatchOriginAsFallbackBehavior match_origin_as_fallback) { … }
bool ScriptContext::HasAPIPermission(mojom::APIPermissionID permission) const { … }
bool ScriptContext::HasAccessOrThrowError(const std::string& name) { … }
std::string ScriptContext::GetDebugString() const { … }
std::string ScriptContext::GetStackTraceAsString() const { … }
std::optional<StackTrace> ScriptContext::GetStackTrace(int frame_limit) { … }
v8::Local<v8::Value> ScriptContext::RunScript(
v8::Local<v8::String> name,
v8::Local<v8::String> code,
RunScriptExceptionHandler exception_handler,
v8::ScriptCompiler::NoCacheReason no_cache_reason) { … }
}