aw_content_browser_client.cc 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "android_webview/browser/aw_content_browser_client.h"
  5. #include <memory>
  6. #include <string>
  7. #include <utility>
  8. #include <vector>
  9. #include "android_webview/browser/aw_browser_context.h"
  10. #include "android_webview/browser/aw_browser_main_parts.h"
  11. #include "android_webview/browser/aw_contents.h"
  12. #include "android_webview/browser/aw_contents_client_bridge.h"
  13. #include "android_webview/browser/aw_contents_io_thread_client.h"
  14. #include "android_webview/browser/aw_cookie_access_policy.h"
  15. #include "android_webview/browser/aw_devtools_manager_delegate.h"
  16. #include "android_webview/browser/aw_feature_list_creator.h"
  17. #include "android_webview/browser/aw_http_auth_handler.h"
  18. #include "android_webview/browser/aw_quota_permission_context.h"
  19. #include "android_webview/browser/aw_resource_context.h"
  20. #include "android_webview/browser/aw_settings.h"
  21. #include "android_webview/browser/aw_speech_recognition_manager_delegate.h"
  22. #include "android_webview/browser/aw_web_contents_view_delegate.h"
  23. #include "android_webview/browser/cookie_manager.h"
  24. #include "android_webview/browser/network_service/aw_proxy_config_monitor.h"
  25. #include "android_webview/browser/network_service/aw_proxying_restricted_cookie_manager.h"
  26. #include "android_webview/browser/network_service/aw_proxying_url_loader_factory.h"
  27. #include "android_webview/browser/network_service/aw_url_loader_throttle.h"
  28. #include "android_webview/browser/safe_browsing/aw_safe_browsing_navigation_throttle.h"
  29. #include "android_webview/browser/safe_browsing/aw_url_checker_delegate_impl.h"
  30. #include "android_webview/browser/tracing/aw_tracing_delegate.h"
  31. #include "android_webview/common/aw_content_client.h"
  32. #include "android_webview/common/aw_descriptors.h"
  33. #include "android_webview/common/aw_features.h"
  34. #include "android_webview/common/aw_switches.h"
  35. #include "android_webview/common/mojom/render_message_filter.mojom.h"
  36. #include "android_webview/common/url_constants.h"
  37. #include "base/android/build_info.h"
  38. #include "base/android/locale_utils.h"
  39. #include "base/base_paths_android.h"
  40. #include "base/base_switches.h"
  41. #include "base/bind.h"
  42. #include "base/callback.h"
  43. #include "base/callback_helpers.h"
  44. #include "base/command_line.h"
  45. #include "base/feature_list.h"
  46. #include "base/files/scoped_file.h"
  47. #include "base/memory/ptr_util.h"
  48. #include "base/path_service.h"
  49. #include "base/strings/utf_string_conversions.h"
  50. #include "base/task/thread_pool/thread_pool_instance.h"
  51. #include "build/build_config.h"
  52. #include "components/cdm/browser/cdm_message_filter_android.h"
  53. #include "components/crash/content/browser/crash_handler_host_linux.h"
  54. #include "components/embedder_support/switches.h"
  55. #include "components/embedder_support/user_agent_utils.h"
  56. #include "components/navigation_interception/intercept_navigation_delegate.h"
  57. #include "components/page_load_metrics/browser/metrics_navigation_throttle.h"
  58. #include "components/page_load_metrics/browser/metrics_web_contents_observer.h"
  59. #include "components/policy/content/policy_blocklist_navigation_throttle.h"
  60. #include "components/policy/core/browser/browser_policy_connector_base.h"
  61. #include "components/prefs/pref_service.h"
  62. #include "components/safe_browsing/content/browser/browser_url_loader_throttle.h"
  63. #include "components/safe_browsing/content/browser/mojo_safe_browsing_impl.h"
  64. #include "components/safe_browsing/core/common/features.h"
  65. #include "components/url_matcher/url_matcher.h"
  66. #include "components/url_matcher/url_util.h"
  67. #include "content/public/browser/browser_associated_interface.h"
  68. #include "content/public/browser/browser_message_filter.h"
  69. #include "content/public/browser/browser_task_traits.h"
  70. #include "content/public/browser/browser_thread.h"
  71. #include "content/public/browser/child_process_security_policy.h"
  72. #include "content/public/browser/client_certificate_delegate.h"
  73. #include "content/public/browser/file_url_loader.h"
  74. #include "content/public/browser/navigation_handle.h"
  75. #include "content/public/browser/navigation_throttle.h"
  76. #include "content/public/browser/network_service_instance.h"
  77. #include "content/public/browser/render_frame_host.h"
  78. #include "content/public/browser/render_process_host.h"
  79. #include "content/public/browser/render_view_host.h"
  80. #include "content/public/browser/shared_cors_origin_access_list.h"
  81. #include "content/public/browser/site_isolation_policy.h"
  82. #include "content/public/browser/storage_partition.h"
  83. #include "content/public/browser/web_contents.h"
  84. #include "content/public/common/content_descriptors.h"
  85. #include "content/public/common/content_features.h"
  86. #include "content/public/common/content_switches.h"
  87. #include "content/public/common/url_constants.h"
  88. #include "content/public/common/user_agent.h"
  89. #include "mojo/public/cpp/bindings/pending_associated_receiver.h"
  90. #include "mojo/public/cpp/bindings/pending_receiver.h"
  91. #include "net/android/network_library.h"
  92. #include "net/cookies/site_for_cookies.h"
  93. #include "net/http/http_util.h"
  94. #include "net/net_buildflags.h"
  95. #include "net/ssl/ssl_cert_request_info.h"
  96. #include "net/ssl/ssl_info.h"
  97. #include "services/metrics/public/cpp/ukm_source_id.h"
  98. #include "services/network/network_service.h"
  99. #include "services/network/public/cpp/resource_request.h"
  100. #include "services/network/public/mojom/cookie_manager.mojom-forward.h"
  101. #include "services/network/public/mojom/fetch_api.mojom.h"
  102. #include "services/network/public/mojom/network_context.mojom.h"
  103. #include "services/service_manager/public/cpp/binder_registry.h"
  104. #include "services/service_manager/public/cpp/interface_provider.h"
  105. #include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
  106. #include "third_party/blink/public/common/loader/url_loader_throttle.h"
  107. #include "third_party/blink/public/common/web_preferences/web_preferences.h"
  108. #include "ui/base/resource/resource_bundle.h"
  109. #include "ui/base/resource/resource_bundle_android.h"
  110. #include "ui/display/util/display_util.h"
  111. #include "ui/gfx/image/image_skia.h"
  112. #include "ui/resources/grit/ui_resources.h"
  113. using content::BrowserThread;
  114. using content::WebContents;
  115. namespace android_webview {
  116. namespace {
  117. static bool g_should_create_thread_pool = true;
  118. #if DCHECK_IS_ON()
  119. // A boolean value to determine if the NetworkContext has been created yet. This
  120. // exists only to check correctness: g_check_cleartext_permitted may only be set
  121. // before the NetworkContext has been created (otherwise,
  122. // g_check_cleartext_permitted won't have any effect).
  123. bool g_created_network_context_params = false;
  124. #endif
  125. // On apps targeting API level O or later, check cleartext is enforced.
  126. bool g_check_cleartext_permitted = false;
  127. // TODO(sgurun) move this to its own file.
  128. // This class handles android_webview.mojom.RenderMessageFilter Mojo interface's
  129. // methods on IO thread.
  130. class AwContentsMessageFilter
  131. : public content::BrowserMessageFilter,
  132. public content::BrowserAssociatedInterface<mojom::RenderMessageFilter> {
  133. public:
  134. explicit AwContentsMessageFilter(int process_id);
  135. AwContentsMessageFilter(const AwContentsMessageFilter&) = delete;
  136. AwContentsMessageFilter& operator=(const AwContentsMessageFilter&) = delete;
  137. // BrowserMessageFilter methods.
  138. bool OnMessageReceived(const IPC::Message& message) override;
  139. // mojom::RenderMessageFilter overrides:
  140. void SubFrameCreated(int parent_render_frame_id,
  141. int child_render_frame_id) override;
  142. private:
  143. ~AwContentsMessageFilter() override;
  144. int process_id_;
  145. };
  146. AwContentsMessageFilter::AwContentsMessageFilter(int process_id)
  147. : content::BrowserAssociatedInterface<mojom::RenderMessageFilter>(this),
  148. process_id_(process_id) {}
  149. AwContentsMessageFilter::~AwContentsMessageFilter() = default;
  150. bool AwContentsMessageFilter::OnMessageReceived(const IPC::Message& message) {
  151. return false;
  152. }
  153. void AwContentsMessageFilter::SubFrameCreated(int parent_render_frame_id,
  154. int child_render_frame_id) {
  155. DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
  156. AwContentsIoThreadClient::SubFrameCreated(process_id_, parent_render_frame_id,
  157. child_render_frame_id);
  158. }
  159. } // anonymous namespace
  160. std::string GetProduct() {
  161. return embedder_support::GetProductAndVersion();
  162. }
  163. std::string GetUserAgent() {
  164. // "Version/4.0" had been hardcoded in the legacy WebView.
  165. std::string product = "Version/4.0 " + GetProduct();
  166. if (base::CommandLine::ForCurrentProcess()->HasSwitch(
  167. switches::kUseMobileUserAgent)) {
  168. product += " Mobile";
  169. }
  170. return content::BuildUserAgentFromProductAndExtraOSInfo(
  171. product, "; wv", content::IncludeAndroidBuildNumber::Include);
  172. }
  173. // TODO(yirui): can use similar logic as in PrependToAcceptLanguagesIfNecessary
  174. // in chrome/browser/android/preferences/pref_service_bridge.cc
  175. // static
  176. std::string AwContentBrowserClient::GetAcceptLangsImpl() {
  177. // Start with the current locale(s) in BCP47 format.
  178. std::string locales_string = AwContents::GetLocaleList();
  179. // If accept languages do not contain en-US, add in en-US which will be
  180. // used with a lower q-value.
  181. if (locales_string.find("en-US") == std::string::npos)
  182. locales_string += ",en-US";
  183. return locales_string;
  184. }
  185. // static
  186. void AwContentBrowserClient::set_check_cleartext_permitted(bool permitted) {
  187. #if DCHECK_IS_ON()
  188. DCHECK(!g_created_network_context_params);
  189. #endif
  190. g_check_cleartext_permitted = permitted;
  191. }
  192. // static
  193. bool AwContentBrowserClient::get_check_cleartext_permitted() {
  194. return g_check_cleartext_permitted;
  195. }
  196. AwContentBrowserClient::AwContentBrowserClient(
  197. AwFeatureListCreator* aw_feature_list_creator)
  198. : sniff_file_urls_(AwSettings::GetAllowSniffingFileUrls()),
  199. aw_feature_list_creator_(aw_feature_list_creator) {
  200. // |aw_feature_list_creator| should not be null. The AwBrowserContext will
  201. // take the PrefService owned by the creator as the Local State instead
  202. // of loading the JSON file from disk.
  203. DCHECK(aw_feature_list_creator_);
  204. }
  205. AwContentBrowserClient::~AwContentBrowserClient() {}
  206. void AwContentBrowserClient::OnNetworkServiceCreated(
  207. network::mojom::NetworkService* network_service) {
  208. content::GetNetworkService()->SetUpHttpAuth(
  209. network::mojom::HttpAuthStaticParams::New());
  210. content::GetNetworkService()->ConfigureHttpAuthPrefs(
  211. AwBrowserProcess::GetInstance()->CreateHttpAuthDynamicParams());
  212. }
  213. void AwContentBrowserClient::ConfigureNetworkContextParams(
  214. content::BrowserContext* context,
  215. bool in_memory,
  216. const base::FilePath& relative_partition_path,
  217. network::mojom::NetworkContextParams* network_context_params,
  218. cert_verifier::mojom::CertVerifierCreationParams*
  219. cert_verifier_creation_params) {
  220. DCHECK(context);
  221. content::GetNetworkService()->ConfigureHttpAuthPrefs(
  222. AwBrowserProcess::GetInstance()->CreateHttpAuthDynamicParams());
  223. AwBrowserContext* aw_context = static_cast<AwBrowserContext*>(context);
  224. aw_context->ConfigureNetworkContextParams(in_memory, relative_partition_path,
  225. network_context_params,
  226. cert_verifier_creation_params);
  227. mojo::PendingRemote<network::mojom::CookieManager> cookie_manager_remote;
  228. network_context_params->cookie_manager =
  229. cookie_manager_remote.InitWithNewPipeAndPassReceiver();
  230. #if DCHECK_IS_ON()
  231. g_created_network_context_params = true;
  232. #endif
  233. // Pass the mojo::PendingRemote<network::mojom::CookieManager> to
  234. // android_webview::CookieManager, so it can implement its APIs with this mojo
  235. // CookieManager.
  236. aw_context->GetCookieManager()->SetMojoCookieManager(
  237. std::move(cookie_manager_remote));
  238. }
  239. AwBrowserContext* AwContentBrowserClient::InitBrowserContext() {
  240. browser_context_ = std::make_unique<AwBrowserContext>();
  241. return browser_context_.get();
  242. }
  243. std::unique_ptr<content::BrowserMainParts>
  244. AwContentBrowserClient::CreateBrowserMainParts(bool /* is_integration_test */) {
  245. return std::make_unique<AwBrowserMainParts>(this);
  246. }
  247. std::unique_ptr<content::WebContentsViewDelegate>
  248. AwContentBrowserClient::GetWebContentsViewDelegate(
  249. content::WebContents* web_contents) {
  250. return std::make_unique<AwWebContentsViewDelegate>(web_contents);
  251. }
  252. void AwContentBrowserClient::RenderProcessWillLaunch(
  253. content::RenderProcessHost* host) {
  254. // Grant content: scheme access to the whole renderer process, since we impose
  255. // per-view access checks, and access is granted by default (see
  256. // AwSettings.mAllowContentUrlAccess).
  257. content::ChildProcessSecurityPolicy::GetInstance()->GrantRequestScheme(
  258. host->GetID(), url::kContentScheme);
  259. host->AddFilter(new AwContentsMessageFilter(host->GetID()));
  260. // WebView always allows persisting data.
  261. host->AddFilter(new cdm::CdmMessageFilterAndroid(true, false));
  262. }
  263. bool AwContentBrowserClient::IsExplicitNavigation(
  264. ui::PageTransition transition) {
  265. return ui::PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_TYPED);
  266. }
  267. bool AwContentBrowserClient::IsHandledURL(const GURL& url) {
  268. if (!url.is_valid()) {
  269. // We handle error cases.
  270. return true;
  271. }
  272. const std::string scheme = url.scheme();
  273. DCHECK_EQ(scheme, base::ToLowerASCII(scheme));
  274. static const char* const kProtocolList[] = {
  275. url::kHttpScheme,
  276. url::kHttpsScheme,
  277. #if BUILDFLAG(ENABLE_WEBSOCKETS)
  278. url::kWsScheme,
  279. url::kWssScheme,
  280. #endif // BUILDFLAG(ENABLE_WEBSOCKETS)
  281. url::kDataScheme,
  282. url::kBlobScheme,
  283. url::kFileSystemScheme,
  284. content::kChromeUIScheme,
  285. url::kContentScheme,
  286. };
  287. if (scheme == url::kFileScheme) {
  288. // Return false for the "special" file URLs, so they can be loaded
  289. // even if access to file: scheme is not granted to the child process.
  290. return !IsAndroidSpecialFileUrl(url);
  291. }
  292. for (const char* supported_protocol : kProtocolList) {
  293. if (scheme == supported_protocol)
  294. return true;
  295. }
  296. return false;
  297. }
  298. bool AwContentBrowserClient::ForceSniffingFileUrlsForHtml() {
  299. return sniff_file_urls_;
  300. }
  301. void AwContentBrowserClient::AppendExtraCommandLineSwitches(
  302. base::CommandLine* command_line,
  303. int child_process_id) {
  304. if (!command_line->HasSwitch(switches::kSingleProcess)) {
  305. // The only kind of a child process WebView can have is renderer or utility.
  306. std::string process_type =
  307. command_line->GetSwitchValueASCII(switches::kProcessType);
  308. DCHECK(process_type == switches::kRendererProcess ||
  309. process_type == switches::kUtilityProcess)
  310. << process_type;
  311. static const char* const kSwitchNames[] = {
  312. ::switches::kEnableCrashReporter,
  313. ::switches::kEnableCrashReporterForTesting,
  314. embedder_support::kOriginTrialDisabledFeatures,
  315. };
  316. command_line->CopySwitchesFrom(*base::CommandLine::ForCurrentProcess(),
  317. kSwitchNames, std::size(kSwitchNames));
  318. }
  319. }
  320. std::string AwContentBrowserClient::GetApplicationLocale() {
  321. return base::android::GetDefaultLocaleString();
  322. }
  323. std::string AwContentBrowserClient::GetAcceptLangs(
  324. content::BrowserContext* context) {
  325. return GetAcceptLangsImpl();
  326. }
  327. gfx::ImageSkia AwContentBrowserClient::GetDefaultFavicon() {
  328. ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
  329. // TODO(boliu): Bundle our own default favicon?
  330. return rb.GetImageNamed(IDR_DEFAULT_FAVICON).AsImageSkia();
  331. }
  332. scoped_refptr<content::QuotaPermissionContext>
  333. AwContentBrowserClient::CreateQuotaPermissionContext() {
  334. return new AwQuotaPermissionContext;
  335. }
  336. content::GeneratedCodeCacheSettings
  337. AwContentBrowserClient::GetGeneratedCodeCacheSettings(
  338. content::BrowserContext* context) {
  339. // WebView limits the main HTTP cache to 20MB; we need to set a comparable
  340. // limit for the code cache since the source file needs to be in the HTTP
  341. // cache for the code cache entry to be used. There are two code caches that
  342. // both use this value, so we pass 10MB to keep the total disk usage to
  343. // roughly 2x what it was before the code cache was implemented.
  344. // TODO(crbug/893318): webview should have smarter cache sizing logic.
  345. AwBrowserContext* browser_context = static_cast<AwBrowserContext*>(context);
  346. return content::GeneratedCodeCacheSettings(true, 10 * 1024 * 1024,
  347. browser_context->GetCacheDir());
  348. }
  349. void AwContentBrowserClient::AllowCertificateError(
  350. content::WebContents* web_contents,
  351. int cert_error,
  352. const net::SSLInfo& ssl_info,
  353. const GURL& request_url,
  354. bool is_primary_main_frame_request,
  355. bool strict_enforcement,
  356. base::OnceCallback<void(content::CertificateRequestResultType)> callback) {
  357. AwContentsClientBridge* client =
  358. AwContentsClientBridge::FromWebContents(web_contents);
  359. bool cancel_request = true;
  360. // We only call the callback once but we must pass ownership to a function
  361. // that conditionally calls it.
  362. auto split_callback = base::SplitOnceCallback(std::move(callback));
  363. if (client) {
  364. client->AllowCertificateError(cert_error, ssl_info.cert.get(), request_url,
  365. std::move(split_callback.first),
  366. &cancel_request);
  367. }
  368. if (cancel_request) {
  369. std::move(split_callback.second)
  370. .Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
  371. }
  372. }
  373. base::OnceClosure AwContentBrowserClient::SelectClientCertificate(
  374. content::WebContents* web_contents,
  375. net::SSLCertRequestInfo* cert_request_info,
  376. net::ClientCertIdentityList client_certs,
  377. std::unique_ptr<content::ClientCertificateDelegate> delegate) {
  378. AwContentsClientBridge* client =
  379. AwContentsClientBridge::FromWebContents(web_contents);
  380. if (client)
  381. client->SelectClientCertificate(cert_request_info, std::move(delegate));
  382. return base::OnceClosure();
  383. }
  384. bool AwContentBrowserClient::CanCreateWindow(
  385. content::RenderFrameHost* opener,
  386. const GURL& opener_url,
  387. const GURL& opener_top_level_frame_url,
  388. const url::Origin& source_origin,
  389. content::mojom::WindowContainerType container_type,
  390. const GURL& target_url,
  391. const content::Referrer& referrer,
  392. const std::string& frame_name,
  393. WindowOpenDisposition disposition,
  394. const blink::mojom::WindowFeatures& features,
  395. bool user_gesture,
  396. bool opener_suppressed,
  397. bool* no_javascript_access) {
  398. // We unconditionally allow popup windows at this stage and will give
  399. // the embedder the opporunity to handle displaying of the popup in
  400. // WebContentsDelegate::AddContents (via the
  401. // AwContentsClient.onCreateWindow callback).
  402. // Note that if the embedder has blocked support for creating popup
  403. // windows through AwSettings, then we won't get to this point as
  404. // the popup creation will have been blocked at the WebKit level.
  405. if (no_javascript_access) {
  406. *no_javascript_access = false;
  407. }
  408. content::WebContents* web_contents =
  409. content::WebContents::FromRenderFrameHost(opener);
  410. AwSettings* settings = AwSettings::FromWebContents(web_contents);
  411. return (settings && settings->GetJavaScriptCanOpenWindowsAutomatically()) ||
  412. user_gesture;
  413. }
  414. base::FilePath AwContentBrowserClient::GetDefaultDownloadDirectory() {
  415. // Android WebView does not currently use the Chromium downloads system.
  416. // Download requests are cancelled immediately when recognized; see
  417. // AwResourceDispatcherHost::CreateResourceHandlerForDownload. However the
  418. // download system still tries to start up and calls this before recognizing
  419. // the request has been cancelled.
  420. return base::FilePath();
  421. }
  422. std::string AwContentBrowserClient::GetDefaultDownloadName() {
  423. NOTREACHED() << "Android WebView does not use chromium downloads";
  424. return std::string();
  425. }
  426. void AwContentBrowserClient::DidCreatePpapiPlugin(
  427. content::BrowserPpapiHost* browser_host) {
  428. NOTREACHED() << "Android WebView does not support plugins";
  429. }
  430. bool AwContentBrowserClient::AllowPepperSocketAPI(
  431. content::BrowserContext* browser_context,
  432. const GURL& url,
  433. bool private_api,
  434. const content::SocketPermissionRequest* params) {
  435. NOTREACHED() << "Android WebView does not support plugins";
  436. return false;
  437. }
  438. bool AwContentBrowserClient::IsPepperVpnProviderAPIAllowed(
  439. content::BrowserContext* browser_context,
  440. const GURL& url) {
  441. NOTREACHED() << "Android WebView does not support plugins";
  442. return false;
  443. }
  444. content::TracingDelegate* AwContentBrowserClient::GetTracingDelegate() {
  445. return new AwTracingDelegate();
  446. }
  447. void AwContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
  448. const base::CommandLine& command_line,
  449. int child_process_id,
  450. content::PosixFileDescriptorInfo* mappings) {
  451. base::MemoryMappedFile::Region region;
  452. int fd = ui::GetMainAndroidPackFd(&region);
  453. mappings->ShareWithRegion(kAndroidWebViewMainPakDescriptor, fd, region);
  454. fd = ui::GetCommonResourcesPackFd(&region);
  455. mappings->ShareWithRegion(kAndroidWebView100PercentPakDescriptor, fd, region);
  456. fd = ui::GetLocalePackFd(&region);
  457. mappings->ShareWithRegion(kAndroidWebViewLocalePakDescriptor, fd, region);
  458. int crash_signal_fd =
  459. crashpad::CrashHandlerHost::Get()->GetDeathSignalSocket();
  460. if (crash_signal_fd >= 0) {
  461. mappings->Share(kCrashDumpSignal, crash_signal_fd);
  462. }
  463. }
  464. void AwContentBrowserClient::OverrideWebkitPrefs(
  465. content::WebContents* web_contents,
  466. blink::web_pref::WebPreferences* web_prefs) {
  467. AwSettings* aw_settings = AwSettings::FromWebContents(web_contents);
  468. if (aw_settings) {
  469. aw_settings->PopulateWebPreferences(web_prefs);
  470. }
  471. }
  472. std::vector<std::unique_ptr<content::NavigationThrottle>>
  473. AwContentBrowserClient::CreateThrottlesForNavigation(
  474. content::NavigationHandle* navigation_handle) {
  475. std::vector<std::unique_ptr<content::NavigationThrottle>> throttles;
  476. // We allow intercepting only navigations within main frames. This
  477. // is used to post onPageStarted. We handle shouldOverrideUrlLoading
  478. // via a sync IPC.
  479. if (navigation_handle->IsInMainFrame()) {
  480. // MetricsNavigationThrottle requires that it runs before
  481. // NavigationThrottles that may delay or cancel navigations, so only
  482. // NavigationThrottles that don't delay or cancel navigations (e.g.
  483. // throttles that are only observing callbacks without affecting navigation
  484. // behavior) should be added before MetricsNavigationThrottle.
  485. throttles.push_back(page_load_metrics::MetricsNavigationThrottle::Create(
  486. navigation_handle));
  487. }
  488. // Use Synchronous mode for the navigation interceptor, since this class
  489. // doesn't actually call into an arbitrary client, it just posts a task to
  490. // call onPageStarted. shouldOverrideUrlLoading happens earlier (see
  491. // ContentBrowserClient::ShouldOverrideUrlLoading).
  492. std::unique_ptr<content::NavigationThrottle> intercept_navigation_throttle =
  493. navigation_interception::InterceptNavigationDelegate::
  494. MaybeCreateThrottleFor(navigation_handle,
  495. navigation_interception::SynchronyMode::kSync);
  496. if (intercept_navigation_throttle)
  497. throttles.push_back(std::move(intercept_navigation_throttle));
  498. throttles.push_back(std::make_unique<PolicyBlocklistNavigationThrottle>(
  499. navigation_handle,
  500. AwBrowserContext::FromWebContents(navigation_handle->GetWebContents())));
  501. std::unique_ptr<AwSafeBrowsingNavigationThrottle> safe_browsing_throttle =
  502. AwSafeBrowsingNavigationThrottle::MaybeCreateThrottleFor(
  503. navigation_handle);
  504. if (safe_browsing_throttle)
  505. throttles.push_back(std::move(safe_browsing_throttle));
  506. return throttles;
  507. }
  508. std::unique_ptr<content::DevToolsManagerDelegate>
  509. AwContentBrowserClient::CreateDevToolsManagerDelegate() {
  510. return std::make_unique<AwDevToolsManagerDelegate>();
  511. }
  512. std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
  513. AwContentBrowserClient::CreateURLLoaderThrottles(
  514. const network::ResourceRequest& request,
  515. content::BrowserContext* browser_context,
  516. const base::RepeatingCallback<content::WebContents*()>& wc_getter,
  517. content::NavigationUIData* navigation_ui_data,
  518. int frame_tree_node_id) {
  519. DCHECK_CURRENTLY_ON(BrowserThread::UI);
  520. std::vector<std::unique_ptr<blink::URLLoaderThrottle>> result;
  521. result.push_back(safe_browsing::BrowserURLLoaderThrottle::Create(
  522. base::BindOnce(
  523. [](AwContentBrowserClient* client) {
  524. return client->GetSafeBrowsingUrlCheckerDelegate();
  525. },
  526. base::Unretained(this)),
  527. wc_getter, frame_tree_node_id,
  528. // TODO(crbug.com/1033760): rt_lookup_service is
  529. // used to perform real time URL check, which is gated by UKM opted-in.
  530. // Since AW currently doesn't support UKM, this feature is not enabled.
  531. /* rt_lookup_service */ nullptr));
  532. if (request.destination == network::mojom::RequestDestination::kDocument) {
  533. const bool is_load_url =
  534. request.transition_type & ui::PAGE_TRANSITION_FROM_API;
  535. const bool is_go_back_forward =
  536. request.transition_type & ui::PAGE_TRANSITION_FORWARD_BACK;
  537. const bool is_reload = ui::PageTransitionCoreTypeIs(
  538. static_cast<ui::PageTransition>(request.transition_type),
  539. ui::PAGE_TRANSITION_RELOAD);
  540. if (is_load_url || is_go_back_forward || is_reload) {
  541. result.push_back(
  542. std::make_unique<AwURLLoaderThrottle>(static_cast<AwResourceContext*>(
  543. browser_context->GetResourceContext())));
  544. }
  545. }
  546. return result;
  547. }
  548. scoped_refptr<safe_browsing::UrlCheckerDelegate>
  549. AwContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate() {
  550. DCHECK_CURRENTLY_ON(BrowserThread::IO);
  551. if (!safe_browsing_url_checker_delegate_) {
  552. safe_browsing_url_checker_delegate_ = new AwUrlCheckerDelegateImpl(
  553. AwBrowserProcess::GetInstance()->GetSafeBrowsingDBManager(),
  554. AwBrowserProcess::GetInstance()->GetSafeBrowsingUIManager(),
  555. AwBrowserProcess::GetInstance()->GetSafeBrowsingAllowlistManager());
  556. }
  557. return safe_browsing_url_checker_delegate_;
  558. }
  559. bool AwContentBrowserClient::ShouldOverrideUrlLoading(
  560. int frame_tree_node_id,
  561. bool browser_initiated,
  562. const GURL& gurl,
  563. const std::string& request_method,
  564. bool has_user_gesture,
  565. bool is_redirect,
  566. bool is_outermost_main_frame,
  567. ui::PageTransition transition,
  568. bool* ignore_navigation) {
  569. *ignore_navigation = false;
  570. // Only GETs can be overridden.
  571. if (request_method != "GET")
  572. return true;
  573. bool application_initiated =
  574. browser_initiated || transition & ui::PAGE_TRANSITION_FORWARD_BACK;
  575. // Don't offer application-initiated navigations unless it's a redirect.
  576. if (application_initiated && !is_redirect)
  577. return true;
  578. // For HTTP schemes, only top-level navigations can be overridden. Similarly,
  579. // WebView Classic lets app override only top level about:blank navigations.
  580. // So we filter out non-top about:blank navigations here.
  581. //
  582. // The uuid-in-package scheme is used for subframe navigation with WebBundles
  583. // (https://github.com/WICG/webpackage/blob/main/explainers/subresource-loading-opaque-origin-iframes.md),
  584. // so treat it in the same way as http(s).
  585. //
  586. // Note: about:blank navigations are not received in this path at the moment,
  587. // they use the old SYNC IPC path as they are not handled by network stack.
  588. // However, the old path should be removed in future.
  589. if (!is_outermost_main_frame &&
  590. (gurl.SchemeIs(url::kHttpScheme) || gurl.SchemeIs(url::kHttpsScheme) ||
  591. gurl.SchemeIs(url::kAboutScheme) ||
  592. gurl.SchemeIs(url::kUuidInPackageScheme)))
  593. return true;
  594. WebContents* web_contents =
  595. WebContents::FromFrameTreeNodeId(frame_tree_node_id);
  596. if (web_contents == nullptr)
  597. return true;
  598. AwContentsClientBridge* client_bridge =
  599. AwContentsClientBridge::FromWebContents(web_contents);
  600. if (client_bridge == nullptr)
  601. return true;
  602. std::u16string url = base::UTF8ToUTF16(gurl.possibly_invalid_spec());
  603. AwSettings* aw_settings = AwSettings::FromWebContents(web_contents);
  604. if ((gurl.SchemeIs(url::kHttpScheme) || gurl.SchemeIs(url::kHttpsScheme)) &&
  605. aw_settings->enterprise_authentication_app_link_policy_enabled() &&
  606. android_webview::AwBrowserProcess::GetInstance()
  607. ->GetEnterpriseAuthenticationAppLinkManager()
  608. ->IsEnterpriseAuthenticationUrl(gurl)) {
  609. bool success = client_bridge->SendBrowseIntent(url);
  610. if (success) {
  611. *ignore_navigation = true;
  612. return true;
  613. }
  614. }
  615. return client_bridge->ShouldOverrideUrlLoading(
  616. url, has_user_gesture, is_redirect, is_outermost_main_frame,
  617. ignore_navigation);
  618. }
  619. bool AwContentBrowserClient::
  620. ShouldIgnoreInitialNavigationEntryNavigationStateChangedForLegacySupport() {
  621. // On Android WebView, we should not fire the initial NavigationEntry
  622. // creation/modification NavigationStateChanged calls to preserve legacy
  623. // behavior (not firing extra onPageFinished calls), as initial
  624. // NavigationEntries used to not exist. See https://crbug.com/1277414.
  625. // However, if kWebViewSynthesizePageLoadOnlyOnInitialMainDocumentAccess is
  626. // enabled, we won't need to ignore the extra NavigationStateChanged() calls,
  627. // because they won't trigger synthesized page loads and won't cause extra
  628. // onPageFinished calls.
  629. return !base::FeatureList::IsEnabled(
  630. features::kWebViewSynthesizePageLoadOnlyOnInitialMainDocumentAccess);
  631. }
  632. bool AwContentBrowserClient::SupportsAvoidUnnecessaryBeforeUnloadCheckSync() {
  633. // WebView allows the embedder to override navigation in such a way that
  634. // might trigger reentrancy if this returned true. See comments in
  635. // ContentBrowserClient::SupportsAvoidUnnecessaryBeforeUnloadCheckSync() for
  636. // more details.
  637. return false;
  638. }
  639. bool AwContentBrowserClient::CreateThreadPool(base::StringPiece name) {
  640. if (g_should_create_thread_pool) {
  641. base::ThreadPoolInstance::Create(name);
  642. return true;
  643. }
  644. return false;
  645. }
  646. std::unique_ptr<content::LoginDelegate>
  647. AwContentBrowserClient::CreateLoginDelegate(
  648. const net::AuthChallengeInfo& auth_info,
  649. content::WebContents* web_contents,
  650. const content::GlobalRequestID& request_id,
  651. bool is_request_for_primary_main_frame,
  652. const GURL& url,
  653. scoped_refptr<net::HttpResponseHeaders> response_headers,
  654. bool first_auth_attempt,
  655. LoginAuthRequiredCallback auth_required_callback) {
  656. return std::make_unique<AwHttpAuthHandler>(auth_info, web_contents,
  657. first_auth_attempt,
  658. std::move(auth_required_callback));
  659. }
  660. bool AwContentBrowserClient::HandleExternalProtocol(
  661. const GURL& url,
  662. content::WebContents::Getter web_contents_getter,
  663. int frame_tree_node_id,
  664. content::NavigationUIData* navigation_data,
  665. bool is_primary_main_frame,
  666. bool /* is_in_fenced_frame_tree */,
  667. network::mojom::WebSandboxFlags /*sandbox_flags*/,
  668. ui::PageTransition page_transition,
  669. bool has_user_gesture,
  670. const absl::optional<url::Origin>& initiating_origin,
  671. content::RenderFrameHost* initiator_document,
  672. mojo::PendingRemote<network::mojom::URLLoaderFactory>* out_factory) {
  673. // Sandbox flags
  674. // =============
  675. //
  676. // Contrary to the chrome/ implementation, sandbox flags are ignored. Webview
  677. // by itself to not invoke external apps. However it let the embedding
  678. // app to intercept the request and decide what to do. We need to be careful
  679. // here not breaking applications, so the sandbox flags are ignored.
  680. mojo::PendingReceiver<network::mojom::URLLoaderFactory> receiver =
  681. out_factory->InitWithNewPipeAndPassReceiver();
  682. // We don't need to care for |security_options| as the factories constructed
  683. // below are used only for navigation.
  684. if (content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) {
  685. // Manages its own lifetime.
  686. new android_webview::AwProxyingURLLoaderFactory(
  687. frame_tree_node_id, std::move(receiver), mojo::NullRemote(),
  688. true /* intercept_only */, absl::nullopt /* security_options */);
  689. } else {
  690. content::GetIOThreadTaskRunner({})->PostTask(
  691. FROM_HERE,
  692. base::BindOnce(
  693. [](mojo::PendingReceiver<network::mojom::URLLoaderFactory> receiver,
  694. int frame_tree_node_id) {
  695. // Manages its own lifetime.
  696. new android_webview::AwProxyingURLLoaderFactory(
  697. frame_tree_node_id, std::move(receiver), mojo::NullRemote(),
  698. true /* intercept_only */,
  699. absl::nullopt /* security_options */);
  700. },
  701. std::move(receiver), frame_tree_node_id));
  702. }
  703. return false;
  704. }
  705. void AwContentBrowserClient::RegisterNonNetworkSubresourceURLLoaderFactories(
  706. int render_process_id,
  707. int render_frame_id,
  708. const absl::optional<url::Origin>& request_initiator_origin,
  709. NonNetworkURLLoaderFactoryMap* factories) {
  710. WebContents* web_contents = content::WebContents::FromRenderFrameHost(
  711. content::RenderFrameHost::FromID(render_process_id, render_frame_id));
  712. AwSettings* aw_settings = AwSettings::FromWebContents(web_contents);
  713. if (aw_settings && aw_settings->GetAllowFileAccess()) {
  714. AwBrowserContext* aw_browser_context =
  715. AwBrowserContext::FromWebContents(web_contents);
  716. factories->emplace(
  717. url::kFileScheme,
  718. content::CreateFileURLLoaderFactory(
  719. aw_browser_context->GetPath(),
  720. aw_browser_context->GetSharedCorsOriginAccessList()));
  721. }
  722. }
  723. bool AwContentBrowserClient::ShouldAllowNoLongerUsedProcessToExit() {
  724. // TODO(crbug.com/1268454): Add Android WebView support for allowing a
  725. // renderer process to exit when only non-live RenderFrameHosts remain,
  726. // without consulting the app's OnRenderProcessGone crash handlers.
  727. return false;
  728. }
  729. bool AwContentBrowserClient::ShouldIsolateErrorPage(bool in_main_frame) {
  730. return false;
  731. }
  732. bool AwContentBrowserClient::ShouldEnableStrictSiteIsolation() {
  733. // TODO(lukasza): When/if we eventually add OOPIF support for AW we should
  734. // consider running AW tests with and without site-per-process (and this might
  735. // require returning true below). Adding OOPIF support for AW is tracked by
  736. // https://crbug.com/806404.
  737. return false;
  738. }
  739. size_t AwContentBrowserClient::GetMaxRendererProcessCountOverride() {
  740. // TODO(crbug.com/806404): These options can currently can only be turned by
  741. // by manually overriding command line switches because
  742. // `ShouldDisableSiteIsolation` returns true. Should coordinate if/when
  743. // enabling this in production.
  744. if (content::SiteIsolationPolicy::UseDedicatedProcessesForAllSites() ||
  745. content::SiteIsolationPolicy::AreIsolatedOriginsEnabled() ||
  746. content::SiteIsolationPolicy::IsStrictOriginIsolationEnabled()) {
  747. // Do not restrict the max renderer process count for these site isolation
  748. // modes. This allows OOPIFs to happen on android webview.
  749. return 0u; // Use default.
  750. }
  751. return 1u;
  752. }
  753. bool AwContentBrowserClient::ShouldDisableSiteIsolation(
  754. content::SiteIsolationMode site_isolation_mode) {
  755. // Since AW does not yet support OOPIFs, we must return true here to disable
  756. // features that may trigger OOPIFs, such as origin isolation.
  757. //
  758. // Adding OOPIF support for AW is tracked by https://crbug.com/806404.
  759. return true;
  760. }
  761. bool AwContentBrowserClient::ShouldLockProcessToSite(
  762. content::BrowserContext* browser_context,
  763. const GURL& effective_url) {
  764. // TODO(lukasza): https://crbug.com/806404: Once Android WebView supports
  765. // OOPIFs, we should remove this ShouldLockProcess overload. Till then,
  766. // returning false helps avoid accidentally applying citadel-style Site
  767. // Isolation enforcement to Android WebView (and causing incorrect renderer
  768. // kills).
  769. return false;
  770. }
  771. bool AwContentBrowserClient::WillCreateURLLoaderFactory(
  772. content::BrowserContext* browser_context,
  773. content::RenderFrameHost* frame,
  774. int render_process_id,
  775. URLLoaderFactoryType type,
  776. const url::Origin& request_initiator,
  777. absl::optional<int64_t> navigation_id,
  778. ukm::SourceIdObj ukm_source_id,
  779. mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver,
  780. mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>*
  781. header_client,
  782. bool* bypass_redirect_checks,
  783. bool* disable_secure_dns,
  784. network::mojom::URLLoaderFactoryOverridePtr* factory_override) {
  785. DCHECK_CURRENTLY_ON(BrowserThread::UI);
  786. mojo::PendingReceiver<network::mojom::URLLoaderFactory> proxied_receiver;
  787. mojo::PendingRemote<network::mojom::URLLoaderFactory> target_factory_remote;
  788. if (factory_override) {
  789. // We are interested in factories "inside" of CORS, so use
  790. // |factory_override|.
  791. *factory_override = network::mojom::URLLoaderFactoryOverride::New();
  792. proxied_receiver =
  793. (*factory_override)
  794. ->overriding_factory.InitWithNewPipeAndPassReceiver();
  795. (*factory_override)->overridden_factory_receiver =
  796. target_factory_remote.InitWithNewPipeAndPassReceiver();
  797. (*factory_override)->skip_cors_enabled_scheme_check = true;
  798. } else {
  799. // In this case, |factory_override| is not given. But all callers of
  800. // ContentBrowserClient::WillCreateURLLoaderFactory guarantee that
  801. // |factory_override| is null only when the security features on the network
  802. // service is no-op for requests coming to the URLLoaderFactory. Hence we
  803. // can use |factory_receiver| here.
  804. proxied_receiver = std::move(*factory_receiver);
  805. *factory_receiver = target_factory_remote.InitWithNewPipeAndPassReceiver();
  806. }
  807. // Android WebView has one non off-the-record browser context.
  808. if (frame) {
  809. auto security_options =
  810. absl::make_optional<AwProxyingURLLoaderFactory::SecurityOptions>();
  811. security_options->disable_web_security =
  812. base::CommandLine::ForCurrentProcess()->HasSwitch(
  813. switches::kDisableWebSecurity);
  814. const auto& preferences =
  815. WebContents::FromRenderFrameHost(frame)->GetOrCreateWebPreferences();
  816. // See also //android_webview/docs/cors-and-webview-api.md to understand how
  817. // each settings affect CORS behaviors on file:// and content://.
  818. if (request_initiator.scheme() == url::kFileScheme) {
  819. security_options->disable_web_security |=
  820. preferences.allow_universal_access_from_file_urls;
  821. // Usual file:// to file:// requests are mapped to kNoCors if the setting
  822. // is set to true. Howover, file:///android_{asset|res}/ still uses kCors
  823. // and needs to permit it in the |security_options|.
  824. security_options->allow_cors_to_same_scheme =
  825. preferences.allow_file_access_from_file_urls;
  826. } else if (request_initiator.scheme() == url::kContentScheme) {
  827. security_options->allow_cors_to_same_scheme =
  828. preferences.allow_file_access_from_file_urls ||
  829. preferences.allow_universal_access_from_file_urls;
  830. }
  831. content::GetIOThreadTaskRunner({})->PostTask(
  832. FROM_HERE,
  833. base::BindOnce(&AwProxyingURLLoaderFactory::CreateProxy,
  834. frame->GetFrameTreeNodeId(), std::move(proxied_receiver),
  835. std::move(target_factory_remote), security_options));
  836. } else {
  837. // A service worker and worker subresources set nullptr to |frame|, and
  838. // work without seeing the AllowUniversalAccessFromFileURLs setting. So,
  839. // we don't pass a valid |security_options| here.
  840. content::GetIOThreadTaskRunner({})->PostTask(
  841. FROM_HERE, base::BindOnce(&AwProxyingURLLoaderFactory::CreateProxy,
  842. content::RenderFrameHost::kNoFrameTreeNodeId,
  843. std::move(proxied_receiver),
  844. std::move(target_factory_remote),
  845. absl::nullopt /* security_options */));
  846. }
  847. return true;
  848. }
  849. uint32_t AwContentBrowserClient::GetWebSocketOptions(
  850. content::RenderFrameHost* frame) {
  851. uint32_t options = network::mojom::kWebSocketOptionNone;
  852. if (!frame) {
  853. return options;
  854. }
  855. content::WebContents* web_contents =
  856. content::WebContents::FromRenderFrameHost(frame);
  857. AwContents* aw_contents = AwContents::FromWebContents(web_contents);
  858. bool global_cookie_policy =
  859. AwCookieAccessPolicy::GetInstance()->GetShouldAcceptCookies();
  860. bool third_party_cookie_policy = aw_contents->AllowThirdPartyCookies();
  861. if (!global_cookie_policy) {
  862. options |= network::mojom::kWebSocketOptionBlockAllCookies;
  863. } else if (!third_party_cookie_policy) {
  864. options |= network::mojom::kWebSocketOptionBlockThirdPartyCookies;
  865. }
  866. return options;
  867. }
  868. bool AwContentBrowserClient::WillCreateRestrictedCookieManager(
  869. network::mojom::RestrictedCookieManagerRole role,
  870. content::BrowserContext* browser_context,
  871. const url::Origin& origin,
  872. const net::IsolationInfo& isolation_info,
  873. bool is_service_worker,
  874. int process_id,
  875. int routing_id,
  876. mojo::PendingReceiver<network::mojom::RestrictedCookieManager>* receiver) {
  877. mojo::PendingReceiver<network::mojom::RestrictedCookieManager> orig_receiver =
  878. std::move(*receiver);
  879. mojo::PendingRemote<network::mojom::RestrictedCookieManager>
  880. target_rcm_remote;
  881. *receiver = target_rcm_remote.InitWithNewPipeAndPassReceiver();
  882. AwProxyingRestrictedCookieManager::CreateAndBind(
  883. std::move(target_rcm_remote), is_service_worker, process_id, routing_id,
  884. std::move(orig_receiver));
  885. return false; // only made a proxy, still need the actual impl to be made.
  886. }
  887. std::string AwContentBrowserClient::GetProduct() {
  888. return android_webview::GetProduct();
  889. }
  890. std::string AwContentBrowserClient::GetUserAgent() {
  891. return android_webview::GetUserAgent();
  892. }
  893. content::ContentBrowserClient::WideColorGamutHeuristic
  894. AwContentBrowserClient::GetWideColorGamutHeuristic() {
  895. if (base::FeatureList::IsEnabled(features::kWebViewWideColorGamutSupport))
  896. return WideColorGamutHeuristic::kUseWindow;
  897. if (display::HasForceDisplayColorProfile() &&
  898. display::GetForcedDisplayColorProfile() ==
  899. gfx::ColorSpace::CreateDisplayP3D65()) {
  900. return WideColorGamutHeuristic::kUseWindow;
  901. }
  902. return WideColorGamutHeuristic::kNone;
  903. }
  904. void AwContentBrowserClient::LogWebFeatureForCurrentPage(
  905. content::RenderFrameHost* render_frame_host,
  906. blink::mojom::WebFeature feature) {
  907. DCHECK_CURRENTLY_ON(BrowserThread::UI);
  908. page_load_metrics::MetricsWebContentsObserver::RecordFeatureUsage(
  909. render_frame_host, feature);
  910. }
  911. bool AwContentBrowserClient::ShouldAllowInsecurePrivateNetworkRequests(
  912. content::BrowserContext* browser_context,
  913. const url::Origin& origin) {
  914. // Webview does not implement support for deprecation trials, so webview apps
  915. // broken by Private Network Access restrictions cannot help themselves by
  916. // registering for the trial.
  917. // See crbug.com/1255675.
  918. return true;
  919. }
  920. content::SpeechRecognitionManagerDelegate*
  921. AwContentBrowserClient::CreateSpeechRecognitionManagerDelegate() {
  922. return new AwSpeechRecognitionManagerDelegate();
  923. }
  924. bool AwContentBrowserClient::HasErrorPage(int http_status_code) {
  925. return http_status_code >= 400;
  926. }
  927. bool AwContentBrowserClient::SuppressDifferentOriginSubframeJSDialogs(
  928. content::BrowserContext* browser_context) {
  929. return base::FeatureList::IsEnabled(
  930. features::kWebViewSuppressDifferentOriginSubframeJSDialogs);
  931. }
  932. // static
  933. void AwContentBrowserClient::DisableCreatingThreadPool() {
  934. g_should_create_thread_pool = false;
  935. }
  936. } // namespace android_webview