#include "chrome/browser/extensions/activity_log/activity_log.h"
#include <stddef.h>
#include <memory>
#include <set>
#include <utility>
#include <vector>
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/json/json_string_value_serializer.h"
#include "base/logging.h"
#include "base/memory/scoped_refptr.h"
#include "base/one_shot_event.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_checker.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/activity_log/activity_action_constants.h"
#include "chrome/browser/extensions/activity_log/counting_policy.h"
#include "chrome/browser/extensions/activity_log/fullstream_ui_policy.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/preloading/prefetch/no_state_prefetch/no_state_prefetch_manager_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "components/no_state_prefetch/browser/no_state_prefetch_manager.h"
#include "components/sync_preferences/pref_service_syncable.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/api_activity_monitor.h"
#include "extensions/browser/extension_registry_factory.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extension_system_provider.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/renderer_startup_helper.h"
#include "extensions/common/extension.h"
#include "extensions/common/features/feature.h"
#include "extensions/common/features/feature_provider.h"
#include "extensions/common/hashed_extension_id.h"
#include "extensions/common/mojom/renderer.mojom.h"
#include "third_party/re2/src/re2/re2.h"
#include "url/gurl.h"
constants;
namespace extensions {
namespace {
kArgUrlPlaceholder;
BrowserThread;
const char kDomXhrPrefix[] = …;
enum Transformation { … };
struct ApiInfo { … };
static const ApiInfo kApiInfoTable[] = …;
class ApiInfoDatabase { … };
bool GetUrlForTabId(int tab_id,
Profile* profile,
GURL* url,
bool* is_incognito) { … }
bool ResolveUrl(const GURL& base, const std::string& arg, GURL* arg_out) { … }
void ExtractUrls(scoped_refptr<Action> action, Profile* profile) { … }
ActivityLog* SafeGetActivityLog(content::BrowserContext* browser_context) { … }
bool IsExtensionAllowlisted(const std::string& extension_id) { … }
void LogApiActivity(content::BrowserContext* browser_context,
const std::string& extension_id,
const std::string& activity_name,
const base::Value::List& args,
Action::ActionType type) { … }
void LogApiEvent(content::BrowserContext* browser_context,
const std::string& extension_id,
const std::string& event_name,
const base::Value::List& args) { … }
void LogApiFunction(content::BrowserContext* browser_context,
const std::string& extension_id,
const std::string& event_name,
const base::Value::List& args) { … }
void LogWebRequestActivity(content::BrowserContext* browser_context,
const std::string& extension_id,
const GURL& url,
bool is_incognito,
const std::string& api_call,
base::Value::Dict details) { … }
void SetActivityHandlers() { … }
}
static base::LazyInstance<BrowserContextKeyedAPIFactory<ActivityLog>>::
DestructorAtExit g_activity_log_factory = …;
BrowserContextKeyedAPIFactory<ActivityLog>* ActivityLog::GetFactoryInstance() { … }
ActivityLog* ActivityLog::GetInstance(content::BrowserContext* context) { … }
ActivityLog::ActivityLog(content::BrowserContext* context)
: … { … }
void ActivityLog::SetDatabasePolicy(
ActivityLogPolicy::PolicyType policy_type) { … }
ActivityLog::~ActivityLog() { … }
void ActivityLog::ChooseDatabasePolicy() { … }
bool ActivityLog::IsDatabaseEnabled() { … }
bool ActivityLog::IsWatchdogAppActive() { … }
void ActivityLog::UpdateCachedConsumerCount() { … }
void ActivityLog::SetWatchdogAppActiveForTesting(bool active) { … }
void ActivityLog::SetHasListeners(bool has_listeners) { … }
void ActivityLog::OnExtensionLoaded(content::BrowserContext* browser_context,
const Extension* extension) { … }
void ActivityLog::OnExtensionUnloaded(content::BrowserContext* browser_context,
const Extension* extension,
UnloadedExtensionReason reason) { … }
void ActivityLog::OnExtensionUninstalled(
content::BrowserContext* browser_context,
const Extension* extension,
extensions::UninstallReason reason) { … }
void ActivityLog::AddObserver(ActivityLog::Observer* observer) { … }
void ActivityLog::RemoveObserver(ActivityLog::Observer* observer) { … }
void ActivityLog::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) { … }
void ActivityLog::LogAction(scoped_refptr<Action> action) { … }
bool ActivityLog::ShouldLog(const std::string& extension_id) const { … }
void ActivityLog::OnScriptsExecuted(content::WebContents* web_contents,
const ExecutingScriptsMap& extension_ids,
const GURL& on_url) { … }
void ActivityLog::ObserveScripts(ScriptExecutor* executor) { … }
void ActivityLog::GetFilteredActions(
const std::string& extension_id,
const Action::ActionType type,
const std::string& api_name,
const std::string& page_url,
const std::string& arg_url,
const int daysAgo,
base::OnceCallback<
void(std::unique_ptr<std::vector<scoped_refptr<Action>>>)> callback) { … }
void ActivityLog::RemoveActions(const std::vector<int64_t>& action_ids) { … }
void ActivityLog::RemoveExtensionData(const std::string& extension_id) { … }
void ActivityLog::RemoveURLs(const std::vector<GURL>& restrict_urls) { … }
void ActivityLog::RemoveURLs(const std::set<GURL>& restrict_urls) { … }
void ActivityLog::RemoveURL(const GURL& url) { … }
void ActivityLog::DeleteDatabase() { … }
void ActivityLog::CheckActive(bool use_cached) { … }
void ActivityLog::OnExtensionSystemReady() { … }
template <>
void BrowserContextKeyedAPIFactory<ActivityLog>::DeclareFactoryDependencies() { … }
}