#include "extensions/browser/extension_function.h"
#include <memory>
#include <numeric>
#include <tuple>
#include <utility>
#include "base/dcheck_is_on.h"
#include "base/debug/crash_logging.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/singleton.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
#include "base/no_destructor.h"
#include "base/not_fatal_until.h"
#include "base/synchronization/lock.h"
#include "base/task/single_thread_task_runner.h"
#include "base/threading/thread_checker.h"
#include "base/trace_event/memory_allocator_dump.h"
#include "base/trace_event/memory_dump_manager.h"
#include "base/trace_event/memory_dump_provider.h"
#include "base/trace_event/trace_event.h"
#include "components/keyed_service/content/browser_context_keyed_service_shutdown_notifier_factory.h"
#include "components/keyed_service/core/keyed_service_shutdown_notifier.h"
#include "content/public/browser/browser_context.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 "content/public/browser/web_contents_observer.h"
#include "extensions/browser/bad_message.h"
#include "extensions/browser/browser_frame_context_data.h"
#include "extensions/browser/browser_process_context_data.h"
#include "extensions/browser/extension_function_crash_keys.h"
#include "extensions/browser/extension_function_dispatcher.h"
#include "extensions/browser/extension_function_registry.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_util.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/renderer_startup_helper.h"
#include "extensions/browser/service_worker/service_worker_keepalive.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension_api.h"
#include "extensions/common/mojom/renderer.mojom.h"
#include "third_party/blink/public/mojom/devtools/inspector_issue.mojom.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_object.mojom-forward.h"
BrowserThread;
WebContents;
ErrorUtils;
ExtensionAPI;
Feature;
namespace {
class ExtensionFunctionMemoryDumpProvider
: public base::trace_event::MemoryDumpProvider { … };
void EnsureMemoryDumpProviderExists() { … }
void LogUma(bool success,
base::TimeDelta elapsed_time,
extensions::functions::HistogramValue histogram_value) { … }
void LogBadMessage(extensions::functions::HistogramValue histogram_value) { … }
template <class T>
void ReceivedBadMessage(T* bad_message_sender,
extensions::bad_message::BadMessageReason reason,
extensions::functions::HistogramValue histogram_value) { … }
class UserGestureForTests { … };
UserGestureForTests* UserGestureForTests::GetInstance() { … }
UserGestureForTests::UserGestureForTests() : … { … }
bool UserGestureForTests::HaveGesture() { … }
void UserGestureForTests::IncrementCount() { … }
void UserGestureForTests::DecrementCount() { … }
class BrowserContextShutdownNotifierFactory
: public BrowserContextKeyedServiceShutdownNotifierFactory { … };
}
void ExtensionFunction::EnsureShutdownNotifierFactoryBuilt() { … }
bool ExtensionFunction::ignore_all_did_respond_for_testing_do_not_use = …;
const char ExtensionFunction::kUnknownErrorDoNotUse[] = …;
class ExtensionFunction::RenderFrameHostTracker
: public content::WebContentsObserver { … };
ExtensionFunction::ResponseValue::ResponseValue(bool success, PassKey)
: … { … }
ExtensionFunction::ResponseValue::ResponseValue(ResponseValue&& other) =
default;
ExtensionFunction::ResponseValue::~ResponseValue() = default;
ExtensionFunction::ExtensionFunction() { … }
ExtensionFunction::RespondNowAction::RespondNowAction(
ResponseValue result,
SendResponseCallback send_response)
: … { … }
ExtensionFunction::RespondNowAction::RespondNowAction(
RespondNowAction&& other) = default;
ExtensionFunction::RespondNowAction::~RespondNowAction() = default;
void ExtensionFunction::RespondNowAction::Execute() { … }
ExtensionFunction::ResponseAction::ResponseAction(PassKey) { … }
ExtensionFunction::ResponseAction::ResponseAction(RespondNowAction action,
PassKey)
: … { … }
ExtensionFunction::ResponseAction::ResponseAction(ResponseAction&& other) =
default;
ExtensionFunction::ResponseAction::~ResponseAction() = default;
void ExtensionFunction::ResponseAction::Execute() { … }
ExtensionFunction::~ExtensionFunction() { … }
void ExtensionFunction::AddResponseTarget() { … }
std::unique_ptr<extensions::ContextData> ExtensionFunction::GetContextData()
const { … }
bool ExtensionFunction::HasPermission() const { … }
void ExtensionFunction::RespondWithError(std::string error) { … }
bool ExtensionFunction::PreRunValidation(std::string* error) { … }
ExtensionFunction::ResponseAction ExtensionFunction::RunWithValidation() { … }
bool ExtensionFunction::ShouldSkipQuotaLimiting() const { … }
void ExtensionFunction::OnQuotaExceeded(std::string violation_error) { … }
void ExtensionFunction::SetArgs(base::Value::List args) { … }
const base::Value::List* ExtensionFunction::GetResultListForTest() const { … }
const std::string& ExtensionFunction::GetError() const { … }
void ExtensionFunction::SetName(const char* name) { … }
void ExtensionFunction::SetBadMessage() { … }
bool ExtensionFunction::user_gesture() const { … }
void ExtensionFunction::ResetServiceWorkerKeepalive() { … }
void ExtensionFunction::SetBrowserContextForTesting(
content::BrowserContext* context) { … }
content::BrowserContext* ExtensionFunction::browser_context() const { … }
void ExtensionFunction::SetDispatcher(
const base::WeakPtr<extensions::ExtensionFunctionDispatcher>& dispatcher) { … }
void ExtensionFunction::Shutdown() { … }
void ExtensionFunction::SetRenderFrameHost(
content::RenderFrameHost* render_frame_host) { … }
content::WebContents* ExtensionFunction::GetSenderWebContents() { … }
bool ExtensionFunction::ShouldKeepWorkerAliveIndefinitely() { … }
void ExtensionFunction::OnResponseAck() { … }
ExtensionFunction::ResponseValue ExtensionFunction::NoArguments() { … }
ExtensionFunction::ResponseValue ExtensionFunction::ArgumentList(
base::Value::List results) { … }
ExtensionFunction::ResponseValue ExtensionFunction::Error(std::string error) { … }
ExtensionFunction::ResponseValue ExtensionFunction::ErrorWithArguments(
base::Value::List args,
const std::string& error) { … }
ExtensionFunction::ResponseValue ExtensionFunction::BadMessage() { … }
ExtensionFunction::ResponseAction ExtensionFunction::RespondNow(
ResponseValue result) { … }
ExtensionFunction::ResponseAction ExtensionFunction::RespondLater() { … }
ExtensionFunction::ResponseAction ExtensionFunction::AlreadyResponded() { … }
ExtensionFunction::ResponseAction ExtensionFunction::ValidationFailure(
ExtensionFunction* function) { … }
void ExtensionFunction::Respond(ResponseValue result) { … }
void ExtensionFunction::OnResponded() { … }
bool ExtensionFunction::HasOptionalArgument(size_t index) { … }
void ExtensionFunction::WriteToConsole(blink::mojom::ConsoleMessageLevel level,
const std::string& message) { … }
void ExtensionFunction::ReportInspectorIssue(
blink::mojom::InspectorIssueInfoPtr info) { … }
void ExtensionFunction::SetTransferredBlobs(
std::vector<blink::mojom::SerializedBlobPtr> blobs) { … }
void ExtensionFunction::SendResponseImpl(bool success) { … }
ExtensionFunction::ScopedUserGestureForTests::ScopedUserGestureForTests() { … }
ExtensionFunction::ScopedUserGestureForTests::~ScopedUserGestureForTests() { … }
ExtensionFunction::ResponseValue ExtensionFunction::CreateArgumentListResponse(
base::Value::List result) { … }
ExtensionFunction::ResponseValue
ExtensionFunction::CreateErrorWithArgumentsResponse(base::Value::List result,
const std::string& error) { … }
ExtensionFunction::ResponseValue ExtensionFunction::CreateErrorResponseValue(
std::string error) { … }
ExtensionFunction::ResponseValue ExtensionFunction::CreateBadMessageResponse() { … }
void ExtensionFunction::SetFunctionResults(base::Value::List results) { … }
void ExtensionFunction::SetFunctionError(std::string error) { … }