#include "content/web_test/browser/web_test_content_browser_client.h"
#include <algorithm>
#include <iterator>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/no_destructor.h"
#include "base/path_service.h"
#include "base/strings/pattern.h"
#include "base/strings/stringprintf.h"
#include "base/task/single_thread_task_runner.h"
#include "build/build_config.h"
#include "cc/base/switches.h"
#include "components/origin_trials/common/features.h"
#include "content/browser/renderer_host/render_frame_host_impl.h"
#include "content/public/browser/browser_child_process_observer.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_data.h"
#include "content/public/browser/client_hints_controller_delegate.h"
#include "content/public/browser/login_delegate.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/overlay_window.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/site_isolation_policy.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_switches.h"
#include "content/shell/browser/shell_browser_context.h"
#include "content/shell/browser/shell_content_browser_client.h"
#include "content/test/data/mojo_bindings_web_test.test-mojom.h"
#include "content/test/data/mojo_web_test_helper_test.mojom.h"
#include "content/test/mock_badge_service.h"
#include "content/test/mock_clipboard_host.h"
#include "content/web_test/browser/fake_bluetooth_chooser.h"
#include "content/web_test/browser/fake_bluetooth_chooser_factory.h"
#include "content/web_test/browser/fake_bluetooth_delegate.h"
#include "content/web_test/browser/mojo_echo.h"
#include "content/web_test/browser/mojo_optional_numerics_unittest.h"
#include "content/web_test/browser/mojo_web_test_helper.h"
#include "content/web_test/browser/web_test_bluetooth_fake_adapter_setter_impl.h"
#include "content/web_test/browser/web_test_browser_context.h"
#include "content/web_test/browser/web_test_browser_main_parts.h"
#include "content/web_test/browser/web_test_control_host.h"
#include "content/web_test/browser/web_test_cookie_manager.h"
#include "content/web_test/browser/web_test_device_posture_provider.h"
#include "content/web_test/browser/web_test_fedcm_manager.h"
#include "content/web_test/browser/web_test_origin_trial_throttle.h"
#include "content/web_test/browser/web_test_permission_manager.h"
#include "content/web_test/browser/web_test_sensor_provider_manager.h"
#include "content/web_test/browser/web_test_storage_access_manager.h"
#include "content/web_test/browser/web_test_tts_platform.h"
#include "content/web_test/common/web_test_bluetooth_fake_adapter_setter.mojom.h"
#include "content/web_test/common/web_test_string_util.h"
#include "content/web_test/common/web_test_switches.h"
#include "device/bluetooth/emulation/fake_bluetooth.h"
#include "device/bluetooth/public/mojom/emulation/fake_bluetooth.mojom.h"
#include "gpu/config/gpu_switches.h"
#include "mojo/public/cpp/bindings/associated_receiver_set.h"
#include "mojo/public/cpp/bindings/binder_map.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/bindings/remote_set.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "net/net_buildflags.h"
#include "net/proxy_resolution/proxy_config_with_annotation.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "services/device/public/cpp/compute_pressure/buildflags.h"
#include "services/network/public/mojom/network_context.mojom.h"
#include "services/network/public/mojom/network_service.mojom.h"
#include "services/proxy_resolver/proxy_resolver_factory_impl.h"
#include "services/proxy_resolver/public/mojom/proxy_resolver.mojom.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/cpp/manifest.h"
#include "services/service_manager/public/cpp/manifest_builder.h"
#include "services/service_manager/public/mojom/connector.mojom.h"
#include "storage/browser/quota/quota_settings.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
#include "third_party/blink/public/common/web_preferences/web_preferences.h"
#include "third_party/blink/public/mojom/device_posture/device_posture_provider_automation.mojom.h"
#include "ui/base/ui_base_switches.h"
#include "url/origin.h"
#include "url/url_constants.h"
#if BUILDFLAG(ENABLE_COMPUTE_PRESSURE)
#include "content/web_test/browser/web_test_pressure_manager.h"
#endif
#if BUILDFLAG(IS_WIN)
#include "base/strings/utf_string_conversions.h"
#include "sandbox/policy/features.h"
#include "sandbox/policy/mojom/sandbox.mojom.h"
#include "sandbox/policy/win/sandbox_win.h"
#include "sandbox/win/src/sandbox.h"
#endif
namespace content {
namespace {
WebTestContentBrowserClient* g_web_test_browser_client;
void BindWebTestHelper(
RenderFrameHost* render_frame_host,
mojo::PendingReceiver<mojom::MojoWebTestHelper> receiver) { … }
class BoundsMatchVideoSizeOverlayWindow : public VideoOverlayWindow { … };
void CreateChildProcessCrashWatcher() { … }
class MojoWebTestCounterImpl : public mojo_bindings_test::mojom::Counter { … };
class MojoWebTestProxyResolverFactory
: public proxy_resolver::mojom::ProxyResolverFactory { … };
}
WebTestContentBrowserClient::WebTestContentBrowserClient() { … }
WebTestContentBrowserClient::~WebTestContentBrowserClient() { … }
WebTestContentBrowserClient* WebTestContentBrowserClient::Get() { … }
WebTestBrowserContext* WebTestContentBrowserClient::GetWebTestBrowserContext() { … }
void WebTestContentBrowserClient::SetPopupBlockingEnabled(bool block_popups) { … }
void WebTestContentBrowserClient::ResetMockClipboardHosts() { … }
std::unique_ptr<FakeBluetoothChooser>
WebTestContentBrowserClient::GetNextFakeBluetoothChooser() { … }
void WebTestContentBrowserClient::BrowserChildProcessHostCreated(
BrowserChildProcessHost* host) { … }
void WebTestContentBrowserClient::ExposeInterfacesToRenderer(
service_manager::BinderRegistry* registry,
blink::AssociatedInterfaceRegistry* associated_registry,
RenderProcessHost* render_process_host) { … }
void WebTestContentBrowserClient::
RegisterAssociatedInterfaceBindersForRenderFrameHost(
RenderFrameHost& render_frame_host,
blink::AssociatedInterfaceRegistry& associated_registry) { … }
void WebTestContentBrowserClient::BindPermissionAutomation(
mojo::PendingReceiver<blink::test::mojom::PermissionAutomation> receiver) { … }
void WebTestContentBrowserClient::BindStorageAccessAutomation(
mojo::PendingReceiver<blink::test::mojom::StorageAccessAutomation>
receiver) { … }
void WebTestContentBrowserClient::OverrideWebkitPrefs(
WebContents* web_contents,
blink::web_pref::WebPreferences* prefs) { … }
std::vector<std::unique_ptr<content::NavigationThrottle>>
WebTestContentBrowserClient::CreateThrottlesForNavigation(
content::NavigationHandle* navigation_handle) { … }
void WebTestContentBrowserClient::AppendExtraCommandLineSwitches(
base::CommandLine* command_line,
int child_process_id) { … }
std::unique_ptr<BrowserMainParts>
WebTestContentBrowserClient::CreateBrowserMainParts(
bool ) { … }
std::unique_ptr<VideoOverlayWindow>
WebTestContentBrowserClient::CreateWindowForVideoPictureInPicture(
VideoPictureInPictureWindowController* controller) { … }
std::vector<url::Origin>
WebTestContentBrowserClient::GetOriginsRequiringDedicatedProcess() { … }
bool WebTestContentBrowserClient::CanCreateWindow(
content::RenderFrameHost* opener,
const GURL& opener_url,
const GURL& opener_top_level_frame_url,
const url::Origin& source_origin,
content::mojom::WindowContainerType container_type,
const GURL& target_url,
const content::Referrer& referrer,
const std::string& frame_name,
WindowOpenDisposition disposition,
const blink::mojom::WindowFeatures& features,
bool user_gesture,
bool opener_suppressed,
bool* no_javascript_access) { … }
void WebTestContentBrowserClient::RegisterBrowserInterfaceBindersForFrame(
RenderFrameHost* render_frame_host,
mojo::BinderMapWithContext<content::RenderFrameHost*>* map) { … }
bool WebTestContentBrowserClient::CanAcceptUntrustedExchangesIfNeeded() { … }
BluetoothDelegate* WebTestContentBrowserClient::GetBluetoothDelegate() { … }
void WebTestContentBrowserClient::ResetFakeBluetoothDelegate() { … }
content::TtsPlatform* WebTestContentBrowserClient::GetTtsPlatform() { … }
void WebTestContentBrowserClient::BindClipboardHost(
RenderFrameHost* render_frame_host,
mojo::PendingReceiver<blink::mojom::ClipboardHost> receiver) { … }
void WebTestContentBrowserClient::BindBadgeService(
RenderFrameHost* render_frame_host,
mojo::PendingReceiver<blink::mojom::BadgeService> receiver) { … }
void WebTestContentBrowserClient::BindCookieManagerAutomation(
RenderFrameHost* render_frame_host,
mojo::PendingReceiver<blink::test::mojom::CookieManagerAutomation>
receiver) { … }
void WebTestContentBrowserClient::BindDevicePostureProviderAutomation(
RenderFrameHost* render_frame_host,
mojo::PendingReceiver<blink::test::mojom::DevicePostureProviderAutomation>
receiver) { … }
void WebTestContentBrowserClient::BindFedCmAutomation(
RenderFrameHost* render_frame_host,
mojo::PendingReceiver<blink::test::mojom::FederatedAuthRequestAutomation>
receiver) { … }
void WebTestContentBrowserClient::BindWebSensorProviderAutomation(
RenderFrameHost* render_frame_host,
mojo::PendingReceiver<blink::test::mojom::WebSensorProviderAutomation>
receiver) { … }
void WebTestContentBrowserClient::ResetWebSensorProviderAutomation() { … }
#if BUILDFLAG(ENABLE_COMPUTE_PRESSURE)
void WebTestContentBrowserClient::BindWebPressureManagerAutomation(
RenderFrameHost* render_frame_host,
mojo::PendingReceiver<blink::test::mojom::WebPressureManagerAutomation>
receiver) { … }
#endif
std::unique_ptr<LoginDelegate> WebTestContentBrowserClient::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) { … }
void WebTestContentBrowserClient::ConfigureNetworkContextParamsForShell(
BrowserContext* context,
network::mojom::NetworkContextParams* context_params,
cert_verifier::mojom::CertVerifierCreationParams*
cert_verifier_creation_params) { … }
void WebTestContentBrowserClient::CreateFakeBluetoothChooserFactory(
mojo::PendingReceiver<mojom::FakeBluetoothChooserFactory> receiver) { … }
void WebTestContentBrowserClient::BindWebTestControlHost(
int render_process_id,
mojo::PendingAssociatedReceiver<mojom::WebTestControlHost> receiver) { … }
void WebTestContentBrowserClient::BindNonAssociatedWebTestControlHost(
mojo::PendingReceiver<mojom::NonAssociatedWebTestControlHost> receiver) { … }
#if BUILDFLAG(IS_WIN)
bool WebTestContentBrowserClient::PreSpawnChild(
sandbox::TargetConfig* config,
sandbox::mojom::Sandbox sandbox_type,
ChildSpawnFlags flags) {
return true;
}
#endif
std::string WebTestContentBrowserClient::GetAcceptLangs(
BrowserContext* context) { … }
bool WebTestContentBrowserClient::IsInterestGroupAPIAllowed(
content::RenderFrameHost* render_frame_host,
InterestGroupApiOperation operation,
const url::Origin& top_frame_origin,
const url::Origin& api_origin) { … }
bool WebTestContentBrowserClient::IsPrivacySandboxReportingDestinationAttested(
content::BrowserContext* browser_context,
const url::Origin& destination_origin,
content::PrivacySandboxInvokingAPI invoking_api,
bool post_impression_reporting) { … }
void WebTestContentBrowserClient::GetHyphenationDictionary(
base::OnceCallback<void(const base::FilePath&)> callback) { … }
void WebTestContentBrowserClient::
RegisterMojoBinderPoliciesForSameOriginPrerendering(
MojoBinderPolicyMap& policy_map) { … }
void WebTestContentBrowserClient::RegisterMojoBinderPoliciesForPreview(
MojoBinderPolicyMap& policy_map) { … }
}