#include "chrome/browser/extensions/chrome_extensions_browser_client.h"
#include <memory>
#include <optional>
#include <utility>
#include "base/command_line.h"
#include "base/logging.h"
#include "base/memory/scoped_refptr.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "base/values.h"
#include "base/version.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/app_mode/app_mode_utils.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/download/download_prefs.h"
#include "chrome/browser/extensions/activity_log/activity_action_constants.h"
#include "chrome/browser/extensions/activity_log/activity_actions.h"
#include "chrome/browser/extensions/activity_log/activity_log.h"
#include "chrome/browser/extensions/api/chrome_extensions_api_client.h"
#include "chrome/browser/extensions/api/preference/cookie_controls_mode_transformer.h"
#include "chrome/browser/extensions/api/preference/network_prediction_transformer.h"
#include "chrome/browser/extensions/api/preference/privacy_sandbox_transformer.h"
#include "chrome/browser/extensions/api/preference/protected_content_enabled_transformer.h"
#include "chrome/browser/extensions/api/proxy/proxy_api.h"
#include "chrome/browser/extensions/api/runtime/chrome_runtime_api_delegate.h"
#include "chrome/browser/extensions/chrome_component_extension_resource_manager.h"
#include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
#include "chrome/browser/extensions/chrome_extension_host_delegate.h"
#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
#include "chrome/browser/extensions/chrome_extensions_browser_api_provider.h"
#include "chrome/browser/extensions/chrome_extensions_browser_interface_binders.h"
#include "chrome/browser/extensions/chrome_kiosk_delegate.h"
#include "chrome/browser/extensions/chrome_process_manager_delegate.h"
#include "chrome/browser/extensions/chrome_url_request_util.h"
#include "chrome/browser/extensions/error_console/error_console.h"
#include "chrome/browser/extensions/event_router_forwarder.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system_factory.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/favicon/favicon_util.h"
#include "chrome/browser/extensions/menu_manager.h"
#include "chrome/browser/extensions/pref_mapping.h"
#include "chrome/browser/extensions/updater/chrome_update_client_config.h"
#include "chrome/browser/external_protocol/external_protocol_handler.h"
#include "chrome/browser/media/webrtc/media_device_salt_service_factory.h"
#include "chrome/browser/net/system_network_context_manager.h"
#include "chrome/browser/prefetch/pref_names.h"
#include "chrome/browser/preloading/preloading_prefs.h"
#include "chrome/browser/profiles/keep_alive/profile_keep_alive_types.h"
#include "chrome/browser/profiles/keep_alive/scoped_profile_keep_alive.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_selections.h"
#include "chrome/browser/renderer_host/chrome_navigation_ui_data.h"
#include "chrome/browser/safe_browsing/extension_telemetry/declarative_net_request_action_signal.h"
#include "chrome/browser/safe_browsing/extension_telemetry/declarative_net_request_signal.h"
#include "chrome/browser/safe_browsing/extension_telemetry/extension_telemetry_service.h"
#include "chrome/browser/safe_browsing/extension_telemetry/extension_telemetry_service_factory.h"
#include "chrome/browser/safe_browsing/extension_telemetry/remote_host_contacted_signal.h"
#include "chrome/browser/safe_browsing/extension_telemetry/tabs_execute_script_signal.h"
#include "chrome/browser/task_manager/web_contents_tags.h"
#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
#include "chrome/browser/usb/usb_chooser_context.h"
#include "chrome/browser/usb/usb_chooser_context_factory.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_url_info.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_url_loader_factory.h"
#include "chrome/browser/web_applications/web_app_command_scheduler.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/common/channel_info.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "components/content_settings/core/common/pref_names.h"
#include "components/embedder_support/user_agent_utils.h"
#include "components/privacy_sandbox/privacy_sandbox_prefs.h"
#include "components/proxy_config/proxy_config_pref_names.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/sessions/content/session_tab_helper.h"
#include "components/update_client/update_client.h"
#include "components/version_info/version_info.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/site_instance.h"
#include "content/public/browser/storage_partition_config.h"
#include "content/public/common/content_switches.h"
#include "extensions/browser/api/content_settings/content_settings_service.h"
#include "extensions/browser/api/core_extensions_browser_api_provider.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extension_util.h"
#include "extensions/browser/extensions_browser_interface_binders.h"
#include "extensions/browser/pref_names.h"
#include "extensions/browser/updater/scoped_extension_updater_keep_alive.h"
#include "extensions/browser/url_request_util.h"
#include "extensions/common/extension_id.h"
#include "extensions/common/extension_urls.h"
#include "extensions/common/features/feature_channel.h"
#include "extensions/common/mojom/view_type.mojom.h"
#include "extensions/common/permissions/permission_set.h"
#include "ipc/ipc_message.h"
#include "url/gurl.h"
#include "url/origin.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "ash/constants/ash_switches.h"
#include "chrome/browser/ash/login/demo_mode/demo_session.h"
#include "chrome/browser/ash/profiles/profile_helper.h"
#include "chrome/browser/extensions/updater/chromeos_extension_cache_delegate.h"
#include "chrome/browser/extensions/updater/extension_cache_impl.h"
#include "components/user_manager/user_manager.h"
#else
#include "extensions/browser/updater/null_extension_cache.h"
#endif
#if BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/chromeos/policy/dlp/dlp_content_manager.h"
#include "chromeos/components/mgs/managed_guest_session_utils.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "chromeos/startup/browser_params_proxy.h"
#endif
namespace extensions {
namespace {
const char kCrxUrlPath[] = …;
const char kJsonUrlPath[] = …;
bool g_did_chrome_update_for_testing = …;
bool ExtensionsDisabled(const base::CommandLine& command_line) { … }
class UpdaterKeepAlive : public ScopedExtensionUpdaterKeepAlive { … };
bool ShouldLogExtensionAction(content::BrowserContext* browser_context,
const ExtensionId& extension_id) { … }
void AddActionToExtensionActivityLog(content::BrowserContext* browser_context,
scoped_refptr<Action> action) { … }
bool RegisterTransformers() { … }
}
ChromeExtensionsBrowserClient::ChromeExtensionsBrowserClient()
: … { … }
ChromeExtensionsBrowserClient::~ChromeExtensionsBrowserClient() { … }
void ChromeExtensionsBrowserClient::StartTearDown() { … }
bool ChromeExtensionsBrowserClient::IsShuttingDown() { … }
bool ChromeExtensionsBrowserClient::AreExtensionsDisabled(
const base::CommandLine& command_line,
content::BrowserContext* context) { … }
bool ChromeExtensionsBrowserClient::IsValidContext(void* context) { … }
bool ChromeExtensionsBrowserClient::IsSameContext(
content::BrowserContext* first,
content::BrowserContext* second) { … }
bool ChromeExtensionsBrowserClient::HasOffTheRecordContext(
content::BrowserContext* context) { … }
content::BrowserContext* ChromeExtensionsBrowserClient::GetOffTheRecordContext(
content::BrowserContext* context) { … }
content::BrowserContext* ChromeExtensionsBrowserClient::GetOriginalContext(
content::BrowserContext* context) { … }
content::BrowserContext*
ChromeExtensionsBrowserClient::GetContextRedirectedToOriginal(
content::BrowserContext* context,
bool force_guest_profile) { … }
content::BrowserContext* ChromeExtensionsBrowserClient::GetContextOwnInstance(
content::BrowserContext* context,
bool force_guest_profile) { … }
content::BrowserContext*
ChromeExtensionsBrowserClient::GetContextForOriginalOnly(
content::BrowserContext* context,
bool force_guest_profile) { … }
bool ChromeExtensionsBrowserClient::AreExtensionsDisabledForContext(
content::BrowserContext* context) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
std::string ChromeExtensionsBrowserClient::GetUserIdHashFromContext(
content::BrowserContext* context) {
return ash::ProfileHelper::GetUserIdHashFromProfile(
static_cast<Profile*>(context));
}
#endif
#if BUILDFLAG(IS_CHROMEOS_LACROS)
bool ChromeExtensionsBrowserClient::IsFromMainProfile(
content::BrowserContext* browser_context) {
return Profile::FromBrowserContext(browser_context)->IsMainProfile();
}
#endif
bool ChromeExtensionsBrowserClient::IsGuestSession(
content::BrowserContext* context) const { … }
bool ChromeExtensionsBrowserClient::IsExtensionIncognitoEnabled(
const ExtensionId& extension_id,
content::BrowserContext* context) const { … }
bool ChromeExtensionsBrowserClient::CanExtensionCrossIncognito(
const Extension* extension,
content::BrowserContext* context) const { … }
base::FilePath ChromeExtensionsBrowserClient::GetBundleResourcePath(
const network::ResourceRequest& request,
const base::FilePath& extension_resources_path,
int* resource_id) const { … }
void ChromeExtensionsBrowserClient::LoadResourceFromResourceBundle(
const network::ResourceRequest& request,
mojo::PendingReceiver<network::mojom::URLLoader> loader,
const base::FilePath& resource_relative_path,
int resource_id,
scoped_refptr<net::HttpResponseHeaders> headers,
mojo::PendingRemote<network::mojom::URLLoaderClient> client) { … }
bool ChromeExtensionsBrowserClient::AllowCrossRendererResourceLoad(
const network::ResourceRequest& request,
network::mojom::RequestDestination destination,
ui::PageTransition page_transition,
int child_id,
bool is_incognito,
const Extension* extension,
const ExtensionSet& extensions,
const ProcessMap& process_map,
const GURL& upstream_url) { … }
PrefService* ChromeExtensionsBrowserClient::GetPrefServiceForContext(
content::BrowserContext* context) { … }
void ChromeExtensionsBrowserClient::GetEarlyExtensionPrefsObservers(
content::BrowserContext* context,
std::vector<EarlyExtensionPrefsObserver*>* observers) const { … }
ProcessManagerDelegate*
ChromeExtensionsBrowserClient::GetProcessManagerDelegate() const { … }
mojo::PendingRemote<network::mojom::URLLoaderFactory>
ChromeExtensionsBrowserClient::GetControlledFrameEmbedderURLLoader(
const url::Origin& app_origin,
int frame_tree_node_id,
content::BrowserContext* browser_context) { … }
std::unique_ptr<ExtensionHostDelegate>
ChromeExtensionsBrowserClient::CreateExtensionHostDelegate() { … }
bool ChromeExtensionsBrowserClient::DidVersionUpdate(
content::BrowserContext* context) { … }
void ChromeExtensionsBrowserClient::PermitExternalProtocolHandler() { … }
bool ChromeExtensionsBrowserClient::IsInDemoMode() { … }
bool ChromeExtensionsBrowserClient::IsScreensaverInDemoMode(
const std::string& app_id) { … }
bool ChromeExtensionsBrowserClient::IsRunningInForcedAppMode() { … }
bool ChromeExtensionsBrowserClient::IsAppModeForcedForApp(
const ExtensionId& extension_id) { … }
bool ChromeExtensionsBrowserClient::IsLoggedInAsPublicAccount() { … }
ExtensionSystemProvider*
ChromeExtensionsBrowserClient::GetExtensionSystemFactory() { … }
void ChromeExtensionsBrowserClient::RegisterBrowserInterfaceBindersForFrame(
mojo::BinderMapWithContext<content::RenderFrameHost*>* binder_map,
content::RenderFrameHost* render_frame_host,
const Extension* extension) const { … }
std::unique_ptr<RuntimeAPIDelegate>
ChromeExtensionsBrowserClient::CreateRuntimeAPIDelegate(
content::BrowserContext* context) const { … }
const ComponentExtensionResourceManager*
ChromeExtensionsBrowserClient::GetComponentExtensionResourceManager() { … }
void ChromeExtensionsBrowserClient::BroadcastEventToRenderers(
events::HistogramValue histogram_value,
const std::string& event_name,
base::Value::List args,
bool dispatch_to_off_the_record_profiles) { … }
ExtensionCache* ChromeExtensionsBrowserClient::GetExtensionCache() { … }
bool ChromeExtensionsBrowserClient::IsBackgroundUpdateAllowed() { … }
bool ChromeExtensionsBrowserClient::IsMinBrowserVersionSupported(
const std::string& min_version) { … }
ExtensionWebContentsObserver*
ChromeExtensionsBrowserClient::GetExtensionWebContentsObserver(
content::WebContents* web_contents) { … }
void ChromeExtensionsBrowserClient::ReportError(
content::BrowserContext* context,
std::unique_ptr<ExtensionError> error) { … }
void ChromeExtensionsBrowserClient::CleanUpWebView(
content::BrowserContext* browser_context,
int embedder_process_id,
int view_instance_id) { … }
void ChromeExtensionsBrowserClient::ClearBackForwardCache() { … }
void ChromeExtensionsBrowserClient::AttachExtensionTaskManagerTag(
content::WebContents* web_contents,
mojom::ViewType view_type) { … }
scoped_refptr<update_client::UpdateClient>
ChromeExtensionsBrowserClient::CreateUpdateClient(
content::BrowserContext* context) { … }
std::unique_ptr<ScopedExtensionUpdaterKeepAlive>
ChromeExtensionsBrowserClient::CreateUpdaterKeepAlive(
content::BrowserContext* context) { … }
bool ChromeExtensionsBrowserClient::IsActivityLoggingEnabled(
content::BrowserContext* context) { … }
void ChromeExtensionsBrowserClient::GetTabAndWindowIdForWebContents(
content::WebContents* web_contents,
int* tab_id,
int* window_id) { … }
KioskDelegate* ChromeExtensionsBrowserClient::GetKioskDelegate() { … }
bool ChromeExtensionsBrowserClient::IsLockScreenContext(
content::BrowserContext* context) { … }
std::string ChromeExtensionsBrowserClient::GetApplicationLocale() { … }
bool ChromeExtensionsBrowserClient::IsExtensionEnabled(
const ExtensionId& extension_id,
content::BrowserContext* context) const { … }
bool ChromeExtensionsBrowserClient::IsWebUIAllowedToMakeNetworkRequests(
const url::Origin& origin) { … }
network::mojom::NetworkContext*
ChromeExtensionsBrowserClient::GetSystemNetworkContext() { … }
UserScriptListener* ChromeExtensionsBrowserClient::GetUserScriptListener() { … }
void ChromeExtensionsBrowserClient::SignalContentScriptsLoaded(
content::BrowserContext* context) { … }
std::string ChromeExtensionsBrowserClient::GetUserAgent() const { … }
bool ChromeExtensionsBrowserClient::ShouldSchemeBypassNavigationChecks(
const std::string& scheme) const { … }
base::FilePath ChromeExtensionsBrowserClient::GetSaveFilePath(
content::BrowserContext* context) { … }
void ChromeExtensionsBrowserClient::SetLastSaveFilePath(
content::BrowserContext* context,
const base::FilePath& path) { … }
bool ChromeExtensionsBrowserClient::HasIsolatedStorage(
const ExtensionId& extension_id,
content::BrowserContext* context) { … }
bool ChromeExtensionsBrowserClient::IsScreenshotRestricted(
content::WebContents* web_contents) const { … }
bool ChromeExtensionsBrowserClient::IsValidTabId(
content::BrowserContext* context,
int tab_id) const { … }
void ChromeExtensionsBrowserClient::NotifyExtensionApiTabExecuteScript(
content::BrowserContext* context,
const ExtensionId& extension_id,
const std::string& code) const { … }
bool ChromeExtensionsBrowserClient::IsExtensionTelemetryServiceEnabled(
content::BrowserContext* context) const { … }
void ChromeExtensionsBrowserClient::NotifyExtensionApiDeclarativeNetRequest(
content::BrowserContext* context,
const ExtensionId& extension_id,
const std::vector<api::declarative_net_request::Rule>& rules) const { … }
void ChromeExtensionsBrowserClient::
NotifyExtensionDeclarativeNetRequestRedirectAction(
content::BrowserContext* context,
const ExtensionId& extension_id,
const GURL& request_url,
const GURL& redirect_url) const { … }
void ChromeExtensionsBrowserClient::NotifyExtensionRemoteHostContacted(
content::BrowserContext* context,
const ExtensionId& extension_id,
const GURL& url) const { … }
void ChromeExtensionsBrowserClient::set_did_chrome_update_for_testing(
bool did_update) { … }
bool ChromeExtensionsBrowserClient::IsUsbDeviceAllowedByPolicy(
content::BrowserContext* context,
const ExtensionId& extension_id,
int vendor_id,
int product_id) const { … }
void ChromeExtensionsBrowserClient::GetFavicon(
content::BrowserContext* browser_context,
const Extension* extension,
const GURL& url,
base::CancelableTaskTracker* tracker,
base::OnceCallback<void(scoped_refptr<base::RefCountedMemory> bitmap_data)>
callback) const { … }
std::vector<content::BrowserContext*>
ChromeExtensionsBrowserClient::GetRelatedContextsForExtension(
content::BrowserContext* browser_context,
const Extension& extension) const { … }
void ChromeExtensionsBrowserClient::AddAdditionalAllowedHosts(
const PermissionSet& desired_permissions,
PermissionSet* granted_permissions) const { … }
void ChromeExtensionsBrowserClient::AddAPIActionToActivityLog(
content::BrowserContext* browser_context,
const ExtensionId& extension_id,
const std::string& call_name,
base::Value::List args,
const std::string& extra) { … }
void ChromeExtensionsBrowserClient::AddEventToActivityLog(
content::BrowserContext* browser_context,
const ExtensionId& extension_id,
const std::string& call_name,
base::Value::List args,
const std::string& extra) { … }
void ChromeExtensionsBrowserClient::AddDOMActionToActivityLog(
content::BrowserContext* browser_context,
const ExtensionId& extension_id,
const std::string& call_name,
base::Value::List args,
const GURL& url,
const std::u16string& url_title,
int call_type) { … }
void ChromeExtensionsBrowserClient::AddAPIActionOrEventToActivityLog(
content::BrowserContext* browser_context,
const ExtensionId& extension_id,
Action::ActionType action_type,
const std::string& call_name,
base::Value::List args,
const std::string& extra) { … }
void ChromeExtensionsBrowserClient::GetWebViewStoragePartitionConfig(
content::BrowserContext* browser_context,
content::SiteInstance* owner_site_instance,
const std::string& partition_name,
bool in_memory,
base::OnceCallback<void(std::optional<content::StoragePartitionConfig>)>
callback) { … }
void ChromeExtensionsBrowserClient::CreatePasswordReuseDetectionManager(
content::WebContents* web_contents) const { … }
media_device_salt::MediaDeviceSaltService*
ChromeExtensionsBrowserClient::GetMediaDeviceSaltService(
content::BrowserContext* context) { … }
}