#include "content/shell/browser/shell_content_browser_client.h"
#include <stddef.h>
#include <functional>
#include <memory>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/containers/fixed_flat_set.h"
#include "base/containers/flat_set.h"
#include "base/feature_list.h"
#include "base/files/file.h"
#include "base/files/file_util.h"
#include "base/functional/callback_helpers.h"
#include "base/logging.h"
#include "base/no_destructor.h"
#include "base/path_service.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/sequence_local_storage_slot.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "cc/base/switches.h"
#include "components/custom_handlers/protocol_handler_registry.h"
#include "components/custom_handlers/protocol_handler_throttle.h"
#include "components/custom_handlers/simple_protocol_handler_registry_factory.h"
#include "components/metrics/client_info.h"
#include "components/metrics/metrics_service.h"
#include "components/metrics/metrics_state_manager.h"
#include "components/metrics/test/test_enabled_state_provider.h"
#include "components/network_hints/browser/simple_network_hints_handler_impl.h"
#include "components/performance_manager/embedder/performance_manager_registry.h"
#include "components/prefs/json_pref_store.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service_factory.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "components/variations/platform_field_trials.h"
#include "components/variations/pref_names.h"
#include "components/variations/service/safe_seed_manager.h"
#include "components/variations/service/variations_field_trial_creator.h"
#include "components/variations/service/variations_service.h"
#include "components/variations/service/variations_service_client.h"
#include "components/variations/synthetic_trial_registry.h"
#include "components/variations/variations_safe_seed_store_local_state.h"
#include "components/variations/variations_switches.h"
#include "content/public/browser/client_certificate_delegate.h"
#include "content/public/browser/login_delegate.h"
#include "content/public/browser/navigation_throttle.h"
#include "content/public/browser/network_service_instance.h"
#include "content/public/browser/page_navigator.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents_view_delegate.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switch_dependent_feature_overrides.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/isolated_world_ids.h"
#include "content/public/common/url_constants.h"
#include "content/public/common/user_agent.h"
#include "content/shell/browser/shell.h"
#include "content/shell/browser/shell_browser_context.h"
#include "content/shell/browser/shell_browser_main_parts.h"
#include "content/shell/browser/shell_devtools_manager_delegate.h"
#include "content/shell/browser/shell_paths.h"
#include "content/shell/browser/shell_web_contents_view_delegate_creator.h"
#include "content/shell/common/shell_controller.test-mojom.h"
#include "content/shell/common/shell_switches.h"
#include "media/mojo/buildflags.h"
#include "media/mojo/mojom/media_service.mojom.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "net/base/features.h"
#include "net/dns/public/dns_over_https_config.h"
#include "net/dns/public/secure_dns_mode.h"
#include "net/ssl/client_cert_identity.h"
#include "services/device/public/cpp/geolocation/location_system_permission_status.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/cpp/network_service_buildflags.h"
#include "services/network/public/mojom/network_context.mojom.h"
#include "services/network/public/mojom/network_service.mojom.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/permissions_policy/origin_with_possible_wildcards.h"
#include "third_party/blink/public/common/user_agent/user_agent_metadata.h"
#include "third_party/blink/public/common/web_preferences/web_preferences.h"
#include "third_party/blink/public/mojom/permissions_policy/permissions_policy_feature.mojom-shared.h"
#include "ui/base/ui_base_features.h"
#include "ui/base/ui_base_switches.h"
#include "url/gurl.h"
#include "url/origin.h"
#if BUILDFLAG(IS_ANDROID)
#include "base/android/apk_assets.h"
#include "base/android/path_utils.h"
#include "components/variations/android/variations_seed_bridge.h"
#include "content/shell/android/shell_descriptors.h"
#endif
#if BUILDFLAG(IS_ANDROID)
#include "components/crash/content/browser/crash_handler_host_linux.h"
#endif
#if BUILDFLAG(IS_MAC)
#include "services/device/public/cpp/test/fake_geolocation_system_permission_manager.h"
#endif
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
#include "components/crash/core/app/crash_switches.h"
#include "components/crash/core/app/crashpad.h"
#include "content/public/common/content_descriptors.h"
#endif
#if BUILDFLAG(ENABLE_CAST_RENDERER)
#include "media/mojo/services/media_service_factory.h"
#endif
#if BUILDFLAG(IS_CT_SUPPORTED)
#include "services/network/public/mojom/ct_log_info.mojom.h"
#endif
#if BUILDFLAG(IS_IOS)
#include "components/permissions/bluetooth_delegate_impl.h"
#include "content/shell/browser/bluetooth/shell_bluetooth_delegate_impl_client.h"
#endif
#if BUILDFLAG(IS_WIN)
#include "media/mojo/mojom/media_foundation_preferences.mojom.h"
#include "media/mojo/services/media_foundation_preferences.h"
#endif
namespace content {
namespace {
std::vector<ShellContentBrowserClient*>&
GetShellContentBrowserClientInstancesImpl() { … }
#if BUILDFLAG(IS_ANDROID)
int GetCrashSignalFD(const base::CommandLine& command_line) {
return crashpad::CrashHandlerHost::Get()->GetDeathSignalSocket();
}
#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
int GetCrashSignalFD(const base::CommandLine& command_line) { … }
#endif
class ShellControllerImpl : public mojom::ShellController { … };
class ShellVariationsServiceClient
: public variations::VariationsServiceClient { … };
void BindNetworkHintsHandler(
content::RenderFrameHost* frame_host,
mojo::PendingReceiver<network_hints::mojom::NetworkHintsHandler> receiver) { … }
#if BUILDFLAG(IS_WIN)
void BindMediaFoundationPreferences(
content::RenderFrameHost* frame_host,
mojo::PendingReceiver<media::mojom::MediaFoundationPreferences> receiver) {
MediaFoundationPreferencesImpl::Create(
frame_host->GetSiteInstance()->GetSiteURL(), base::NullCallback(),
std::move(receiver));
}
#endif
base::flat_set<url::Origin> GetIsolatedContextOriginSetFromFlag() { … }
struct SharedState { … };
SharedState& GetSharedState() { … }
std::unique_ptr<PrefService> CreateLocalState() { … }
bool AreIsolatedWebAppsEnabled() { … }
}
std::string GetShellLanguage() { … }
blink::UserAgentMetadata GetShellUserAgentMetadata() { … }
bool ShellContentBrowserClient::allow_any_cors_exempt_header_for_browser_ = …;
ShellContentBrowserClient* ShellContentBrowserClient::Get() { … }
ShellContentBrowserClient::ShellContentBrowserClient() { … }
ShellContentBrowserClient::~ShellContentBrowserClient() { … }
std::unique_ptr<BrowserMainParts>
ShellContentBrowserClient::CreateBrowserMainParts(
bool ) { … }
bool ShellContentBrowserClient::HasCustomSchemeHandler(
content::BrowserContext* browser_context,
const std::string& scheme) { … }
std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
ShellContentBrowserClient::CreateURLLoaderThrottles(
const network::ResourceRequest& request,
BrowserContext* browser_context,
const base::RepeatingCallback<WebContents*()>& wc_getter,
NavigationUIData* navigation_ui_data,
int frame_tree_node_id,
std::optional<int64_t> navigation_id) { … }
bool ShellContentBrowserClient::IsHandledURL(const GURL& url) { … }
bool ShellContentBrowserClient::AreIsolatedWebAppsEnabled(
BrowserContext* browser_context) { … }
void ShellContentBrowserClient::AppendExtraCommandLineSwitches(
base::CommandLine* command_line,
int child_process_id) { … }
device::GeolocationSystemPermissionManager*
ShellContentBrowserClient::GetGeolocationSystemPermissionManager() { … }
std::string ShellContentBrowserClient::GetAcceptLangs(BrowserContext* context) { … }
std::string ShellContentBrowserClient::GetDefaultDownloadName() { … }
std::unique_ptr<WebContentsViewDelegate>
ShellContentBrowserClient::GetWebContentsViewDelegate(
WebContents* web_contents) { … }
bool ShellContentBrowserClient::IsIsolatedContextAllowedForUrl(
BrowserContext* browser_context,
const GURL& lock_url) { … }
bool ShellContentBrowserClient::IsSharedStorageAllowed(
content::BrowserContext* browser_context,
content::RenderFrameHost* rfh,
const url::Origin& top_frame_origin,
const url::Origin& accessing_origin,
std::string* out_debug_message,
bool* out_block_is_site_setting_specific) { … }
bool ShellContentBrowserClient::IsSharedStorageSelectURLAllowed(
content::BrowserContext* browser_context,
const url::Origin& top_frame_origin,
const url::Origin& accessing_origin,
std::string* out_debug_message,
bool* out_block_is_site_setting_specific) { … }
bool ShellContentBrowserClient::IsCookieDeprecationLabelAllowed(
content::BrowserContext* browser_context) { … }
bool ShellContentBrowserClient::IsCookieDeprecationLabelAllowedForContext(
content::BrowserContext* browser_context,
const url::Origin& top_frame_origin,
const url::Origin& context_origin) { … }
GeneratedCodeCacheSettings
ShellContentBrowserClient::GetGeneratedCodeCacheSettings(
content::BrowserContext* context) { … }
base::OnceClosure ShellContentBrowserClient::SelectClientCertificate(
BrowserContext* browser_context,
int process_id,
WebContents* web_contents,
net::SSLCertRequestInfo* cert_request_info,
net::ClientCertIdentityList client_certs,
std::unique_ptr<ClientCertificateDelegate> delegate) { … }
SpeechRecognitionManagerDelegate*
ShellContentBrowserClient::CreateSpeechRecognitionManagerDelegate() { … }
void ShellContentBrowserClient::OverrideWebkitPrefs(
WebContents* web_contents,
blink::web_pref::WebPreferences* prefs) { … }
std::unique_ptr<content::DevToolsManagerDelegate>
ShellContentBrowserClient::CreateDevToolsManagerDelegate() { … }
void ShellContentBrowserClient::ExposeInterfacesToRenderer(
service_manager::BinderRegistry* registry,
blink::AssociatedInterfaceRegistry* associated_registry,
RenderProcessHost* render_process_host) { … }
mojo::Remote<::media::mojom::MediaService>
ShellContentBrowserClient::RunSecondaryMediaService() { … }
void ShellContentBrowserClient::RegisterBrowserInterfaceBindersForFrame(
RenderFrameHost* render_frame_host,
mojo::BinderMapWithContext<RenderFrameHost*>* map) { … }
void ShellContentBrowserClient::OpenURL(
SiteInstance* site_instance,
const OpenURLParams& params,
base::OnceCallback<void(WebContents*)> callback) { … }
std::vector<std::unique_ptr<NavigationThrottle>>
ShellContentBrowserClient::CreateThrottlesForNavigation(
NavigationHandle* navigation_handle) { … }
std::unique_ptr<LoginDelegate> ShellContentBrowserClient::CreateLoginDelegate(
const net::AuthChallengeInfo& auth_info,
content::WebContents* web_contents,
content::BrowserContext* browser_context,
const content::GlobalRequestID& request_id,
bool is_request_for_primary_main_frame,
const GURL& url,
scoped_refptr<net::HttpResponseHeaders> response_headers,
bool first_auth_attempt,
LoginAuthRequiredCallback auth_required_callback) { … }
base::Value::Dict ShellContentBrowserClient::GetNetLogConstants() { … }
base::FilePath
ShellContentBrowserClient::GetSandboxedStorageServiceDataDirectory() { … }
base::FilePath ShellContentBrowserClient::GetFirstPartySetsDirectory() { … }
std::optional<base::FilePath>
ShellContentBrowserClient::GetLocalTracesDirectory() { … }
std::string ShellContentBrowserClient::GetUserAgent() { … }
blink::UserAgentMetadata ShellContentBrowserClient::GetUserAgentMetadata() { … }
void ShellContentBrowserClient::OverrideURLLoaderFactoryParams(
BrowserContext* browser_context,
const url::Origin& origin,
bool is_for_isolated_world,
network::mojom::URLLoaderFactoryParams* factory_params) { … }
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
void ShellContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
const base::CommandLine& command_line,
int child_process_id,
content::PosixFileDescriptorInfo* mappings) { … }
#endif
void ShellContentBrowserClient::OnNetworkServiceCreated(
network::mojom::NetworkService* network_service) { … }
void ShellContentBrowserClient::ConfigureNetworkContextParams(
BrowserContext* context,
bool in_memory,
const base::FilePath& relative_partition_path,
network::mojom::NetworkContextParams* network_context_params,
cert_verifier::mojom::CertVerifierCreationParams*
cert_verifier_creation_params) { … }
std::vector<base::FilePath>
ShellContentBrowserClient::GetNetworkContextsParentDirectory() { … }
#if BUILDFLAG(IS_IOS)
BluetoothDelegate* ShellContentBrowserClient::GetBluetoothDelegate() {
if (!bluetooth_delegate_) {
bluetooth_delegate_ = std::make_unique<permissions::BluetoothDelegateImpl>(
std::make_unique<ShellBluetoothDelegateImplClient>());
}
return bluetooth_delegate_.get();
}
#endif
void ShellContentBrowserClient::BindBrowserControlInterface(
mojo::ScopedMessagePipeHandle pipe) { … }
void ShellContentBrowserClient::set_browser_main_parts(
ShellBrowserMainParts* parts) { … }
ShellBrowserContext* ShellContentBrowserClient::browser_context() { … }
ShellBrowserContext*
ShellContentBrowserClient::off_the_record_browser_context() { … }
ShellBrowserMainParts* ShellContentBrowserClient::shell_browser_main_parts() { … }
void ShellContentBrowserClient::ConfigureNetworkContextParamsForShell(
BrowserContext* context,
network::mojom::NetworkContextParams* context_params,
cert_verifier::mojom::CertVerifierCreationParams*
cert_verifier_creation_params) { … }
void ShellContentBrowserClient::GetHyphenationDictionary(
base::OnceCallback<void(const base::FilePath&)> callback) { … }
bool ShellContentBrowserClient::HasErrorPage(int http_status_code) { … }
void ShellContentBrowserClient::OnWebContentsCreated(
WebContents* web_contents) { … }
void ShellContentBrowserClient::CreateFeatureListAndFieldTrials() { … }
void ShellContentBrowserClient::SetUpFieldTrials() { … }
std::optional<blink::ParsedPermissionsPolicy>
ShellContentBrowserClient::GetPermissionsPolicyForIsolatedWebApp(
WebContents* web_contents,
const url::Origin& app_origin) { … }
const std::vector<ShellContentBrowserClient*>&
ShellContentBrowserClient::GetShellContentBrowserClientInstances() { … }
}