diff --git a/cobalt/BUILD.gn b/cobalt/BUILD.gn index 0e8901255339..b51b6ad8ac3d 100644 --- a/cobalt/BUILD.gn +++ b/cobalt/BUILD.gn @@ -45,6 +45,7 @@ if (!is_android) { defines = [] deps = [ + "//cobalt/renderer:renderer", "//cobalt/user_agent", "//content/public/app", "//content/shell:content_shell_app", diff --git a/cobalt/android/BUILD.gn b/cobalt/android/BUILD.gn index 831a54795fc5..5798338fa21b 100644 --- a/cobalt/android/BUILD.gn +++ b/cobalt/android/BUILD.gn @@ -168,6 +168,7 @@ shared_library("libcobalt_content_shell_content_view") { # TODO(b/375655377): remove testonly testonly = true deps = [ + "//cobalt/renderer:renderer", "//cobalt/user_agent", # TODO: what can be removed in the dependencies? diff --git a/cobalt/cobalt_main_delegate.cc b/cobalt/cobalt_main_delegate.cc index b1c7ed74a425..04fd36bc1dcb 100644 --- a/cobalt/cobalt_main_delegate.cc +++ b/cobalt/cobalt_main_delegate.cc @@ -14,6 +14,7 @@ #include "cobalt/cobalt_main_delegate.h" #include "cobalt/cobalt_content_browser_client.h" +#include "cobalt/renderer/cobalt_content_renderer_client.h" #include "content/public/browser/render_frame_host.h" namespace cobalt { @@ -29,6 +30,12 @@ CobaltMainDelegate::CreateContentBrowserClient() { return browser_client_.get(); } +content::ContentRendererClient* +CobaltMainDelegate::CreateContentRendererClient() { + renderer_client_ = std::make_unique(); + return renderer_client_.get(); +} + absl::optional CobaltMainDelegate::PostEarlyInitialization( InvokedIn invoked_in) { content::RenderFrameHost::AllowInjectingJavaScript(); diff --git a/cobalt/cobalt_main_delegate.h b/cobalt/cobalt_main_delegate.h index 3c400f6dd0bc..146fdd9ce1a2 100644 --- a/cobalt/cobalt_main_delegate.h +++ b/cobalt/cobalt_main_delegate.h @@ -16,6 +16,7 @@ #define COBALT_COBALT_MAIN_DELEGATE_H_ #include "build/build_config.h" +#include "cobalt/renderer/cobalt_content_renderer_client.h" #include "content/shell/app/shell_main_delegate.h" namespace cobalt { @@ -29,9 +30,13 @@ class CobaltMainDelegate : public content::ShellMainDelegate { // ContentMainDelegate implementation: content::ContentBrowserClient* CreateContentBrowserClient() override; + content::ContentRendererClient* CreateContentRendererClient() override; absl::optional PostEarlyInitialization(InvokedIn invoked_in) override; ~CobaltMainDelegate() override; + + private: + std::unique_ptr renderer_client_; }; } // namespace cobalt diff --git a/cobalt/common/shell_switches.cc b/cobalt/common/shell_switches.cc new file mode 100644 index 000000000000..b191d6c3aaea --- /dev/null +++ b/cobalt/common/shell_switches.cc @@ -0,0 +1,15 @@ +// Copyright 2025 The Cobalt Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "cobalt/common/shell_switches.h" + +#include "base/command_line.h" + +namespace switches { + +// Exposes the window.internals object to JavaScript for interactive development +// and debugging of web tests that rely on it. +const char kExposeInternalsForTesting[] = "expose-internals-for-testing"; + +} // namespace switches diff --git a/cobalt/common/shell_switches.h b/cobalt/common/shell_switches.h new file mode 100644 index 000000000000..6d89ad728097 --- /dev/null +++ b/cobalt/common/shell_switches.h @@ -0,0 +1,18 @@ +// Copyright 2025 The Cobalt Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Defines all the Cobalt command-line switches. + +#ifndef COBALT_COMMON_SHELL_SWITCHES_H_ +#define COBALT_COMMON_SHELL_SWITCHES_H_ + +#include "build/build_config.h" + +namespace switches { + +extern const char kExposeInternalsForTesting[]; + +} // namespace switches + +#endif // COBALT_COMMON_SHELL_SWITCHES_H_ diff --git a/cobalt/renderer/BUILD.gn b/cobalt/renderer/BUILD.gn new file mode 100644 index 000000000000..73d80ea2fc06 --- /dev/null +++ b/cobalt/renderer/BUILD.gn @@ -0,0 +1,32 @@ +# Copyright 2025 The Cobalt Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +source_set("renderer") { + sources = [ + "cobalt_content_renderer_client.cc", + "cobalt_content_renderer_client.h", + ] + + deps = [ + "//components/cdm/renderer", + "//components/network_hints/renderer", + "//components/web_cache/renderer", + "//content/public/common", + "//content/public/renderer", + "//content/test:content_test_mojo_bindings", + "//media/mojo:buildflags", + "//starboard:starboard_headers_only", + "//v8", + ] +} diff --git a/cobalt/renderer/cobalt_content_renderer_client.cc b/cobalt/renderer/cobalt_content_renderer_client.cc new file mode 100644 index 000000000000..13485a2b9513 --- /dev/null +++ b/cobalt/renderer/cobalt_content_renderer_client.cc @@ -0,0 +1,295 @@ +// Copyright 2025 The Cobalt Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "cobalt/renderer/cobalt_content_renderer_client.h" + +#include + +#include "base/check_op.h" +#include "base/command_line.h" +#include "base/files/file.h" +#include "base/functional/bind.h" +#include "base/notreached.h" +#include "base/strings/string_number_conversions.h" +#include "base/task/single_thread_task_runner.h" +#include "cobalt/common/shell_switches.h" +#include "components/cdm/renderer/external_clear_key_key_system_info.h" +#include "components/network_hints/renderer/web_prescient_networking_impl.h" +#include "components/web_cache/renderer/web_cache_impl.h" +#include "content/public/common/pseudonymization_util.h" +#include "content/public/common/web_identity.h" +#include "content/public/renderer/render_frame.h" +#include "content/public/renderer/render_thread.h" +#include "content/public/test/test_service.mojom.h" +#include "mojo/public/cpp/bindings/binder_map.h" +#include "mojo/public/cpp/bindings/pending_receiver.h" +#include "mojo/public/cpp/bindings/receiver.h" +#include "mojo/public/cpp/system/message_pipe.h" +#include "net/base/net_errors.h" +#include "ppapi/buildflags/buildflags.h" +#include "sandbox/policy/sandbox.h" +#include "third_party/blink/public/platform/url_loader_throttle_provider.h" +#include "third_party/blink/public/platform/web_url_error.h" +#include "third_party/blink/public/web/modules/credentialmanagement/throttle_helper.h" +#include "third_party/blink/public/web/web_local_frame.h" +#include "third_party/blink/public/web/web_testing_support.h" +#include "third_party/blink/public/web/web_view.h" +#include "v8/include/v8.h" + +#if BUILDFLAG(USE_STARBOARD_MEDIA) +#include "components/cdm/renderer/widevine_key_system_info.h" +#include "starboard/media.h" +#endif // BUILDFLAG(USE_STARBOARD_MEDIA) + +#if BUILDFLAG(ENABLE_PLUGINS) +#include "ppapi/shared_impl/ppapi_switches.h" // nogncheck +#endif + +#if BUILDFLAG(ENABLE_MOJO_CDM) +#include "base/feature_list.h" +#include "media/base/media_switches.h" +#endif + +namespace cobalt { + +namespace { + +class CobaltContentRendererUrlLoaderThrottleProvider + : public blink::URLLoaderThrottleProvider { + public: + std::unique_ptr Clone() override { + return std::make_unique(); + } + + blink::WebVector> CreateThrottles( + int render_frame_id, + const blink::WebURLRequest& request) override { + blink::WebVector> throttles; + // Workers can call us on a background thread. We don't care about such + // requests because we purposefully only look at resources from frames + // that the user can interact with.` + content::RenderFrame* frame = + content::RenderThread::IsMainThread() + ? content::RenderFrame::FromRoutingID(render_frame_id) + : nullptr; + if (frame) { + auto throttle = content::MaybeCreateIdentityUrlLoaderThrottle( + base::BindRepeating(blink::SetIdpSigninStatus, frame->GetWebFrame())); + if (throttle) { + throttles.push_back(std::move(throttle)); + } + } + + return throttles; + } + + void SetOnline(bool is_online) override {} +}; + +} // namespace + +CobaltContentRendererClient::CobaltContentRendererClient() {} +CobaltContentRendererClient::~CobaltContentRendererClient() {} + +void CobaltContentRendererClient::RenderThreadStarted() { + web_cache_impl_ = std::make_unique(); +} + +void CobaltContentRendererClient::ExposeInterfacesToBrowser( + mojo::BinderMap* binders) { + binders->Add( + base::BindRepeating(&web_cache::WebCacheImpl::BindReceiver, + base::Unretained(web_cache_impl_.get())), + base::SingleThreadTaskRunner::GetCurrentDefault()); +} + +void CobaltContentRendererClient::RenderFrameCreated( + content::RenderFrame* render_frame) {} + +void CobaltContentRendererClient::PrepareErrorPage( + content::RenderFrame* render_frame, + const blink::WebURLError& error, + const std::string& http_method, + content::mojom::AlternativeErrorPageOverrideInfoPtr + alternative_error_page_info, + std::string* error_html) { + if (error_html && error_html->empty()) { + *error_html = + "ErrorCould not load the requested " + "resource.
Error code: " + + base::NumberToString(error.reason()) + + (error.reason() < 0 ? " (" + net::ErrorToString(error.reason()) + ")" + : "") + + ""; + } +} + +void CobaltContentRendererClient::PrepareErrorPageForHttpStatusError( + content::RenderFrame* render_frame, + const blink::WebURLError& error, + const std::string& http_method, + int http_status, + content::mojom::AlternativeErrorPageOverrideInfoPtr + alternative_error_page_info, + std::string* error_html) { + if (error_html) { + *error_html = + "ErrorServer returned HTTP status " + + base::NumberToString(http_status) + ""; + } +} + +void CobaltContentRendererClient::DidInitializeWorkerContextOnWorkerThread( + v8::Local context) { + if (base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kExposeInternalsForTesting)) { + blink::WebTestingSupport::InjectInternalsObject(context); + } +} + +std::unique_ptr +CobaltContentRendererClient::CreateURLLoaderThrottleProvider( + blink::URLLoaderThrottleProviderType provider_type) { + return std::make_unique(); +} + +#if BUILDFLAG(USE_STARBOARD_MEDIA) +media::SupportedCodecs GetStarboardEmeSupportedCodecs() { + media::SupportedCodecs codecs = + ::media::EME_CODEC_AAC | ::media::EME_CODEC_AVC1 | + ::media::EME_CODEC_VP9_PROFILE0 | ::media::EME_CODEC_VP9_PROFILE2 | + ::media::EME_CODEC_VP8 | ::media::EME_CODEC_OPUS | + ::media::EME_CODEC_VORBIS | ::media::EME_CODEC_MPEG_H_AUDIO | + ::media::EME_CODEC_FLAC | ::media::EME_CODEC_HEVC_PROFILE_MAIN | + ::media::EME_CODEC_HEVC_PROFILE_MAIN10 | ::media::EME_CODEC_AV1 | + ::media::EME_CODEC_AC3 | ::media::EME_CODEC_EAC3; + // TODO(b/375232937) Add IAMF + return codecs; +} + +#if BUILDFLAG(IS_ANDROID) +void AddStarboardCmaKeySystems(::media::KeySystemInfos* key_system_infos) { + media::SupportedCodecs codecs = GetStarboardEmeSupportedCodecs(); + + using Robustness = cdm::WidevineKeySystemInfo::Robustness; + + const base::flat_set kEncryptionSchemes = { + media::EncryptionScheme::kCenc, media::EncryptionScheme::kCbcs}; + + const base::flat_set kSessionTypes = { + media::CdmSessionType::kTemporary}; + + key_system_infos->emplace_back(new cdm::WidevineKeySystemInfo( + codecs, // Regular codecs. + kEncryptionSchemes, // Encryption schemes. + kSessionTypes, // Session types. + codecs, // Hardware secure codecs. + kEncryptionSchemes, // Hardware secure encryption schemes. + kSessionTypes, // Hardware secure session types. + Robustness::HW_SECURE_CRYPTO, // Max audio robustness. + Robustness::HW_SECURE_ALL, // Max video robustness. + media::EmeFeatureSupport::ALWAYS_ENABLED, // Persistent state. + media::EmeFeatureSupport::ALWAYS_ENABLED)); // Distinctive identifier. +} +#endif + +void CobaltContentRendererClient::GetSupportedKeySystems( + media::GetSupportedKeySystemsCB cb) { + media::KeySystemInfos key_systems; +#if BUILDFLAG(IS_ANDROID) + AddStarboardCmaKeySystems(&key_systems); + std::move(cb).Run(std::move(key_systems)); +#endif +} + +#else // BUILDFLAG(USE_STARBOARD_MEDIA) + +#if BUILDFLAG(ENABLE_MOJO_CDM) +void CobaltContentRendererClient::GetSupportedKeySystems( + media::GetSupportedKeySystemsCB cb) { + media::KeySystemInfos key_systems; + if (base::FeatureList::IsEnabled(media::kExternalClearKeyForTesting)) { + key_systems.push_back( + std::make_unique()); + } + std::move(cb).Run(std::move(key_systems)); +} +#endif + +#endif // BUILDFLAG(USE_STARBOARD_MEDIA) + +#if BUILDFLAG(USE_STARBOARD_MEDIA) +// TODO(b/376542844): Eliminate the usage of hardcoded MIME string once we +// support to query codec capabilities with configs. +std::string GetMimeFromAudioType(const media::AudioType& type) { + // The MIME string is for very basic audio codec supportability check. + switch (type.codec) { + case media::AudioCodec::kAAC: + return "audio/mp4; codecs=\"mp4a.40.2\""; + case media::AudioCodec::kAC3: + return "audio/mp4; codecs=\"ac-3\""; + case media::AudioCodec::kEAC3: + return "audio/mp4; codecs=\"ec-3\""; + case media::AudioCodec::kOpus: + return "audio/webm; codecs=\"opus\""; + // TODO(b/375232937): Support IAMF + default: + return ""; + } +} + +// TODO(b/376542844): Eliminate the usage of hardcoded MIME string once we +// support to query codec capabilities with configs. The profile information +// gets lost with hardcoded MIME string. This can sometimes cause issues. For +// example, vp9 profile 2 indicates hdr support, so an implementation accepts +// "codecs=vp9" may reject "codecs=vp9.2". +std::string GetMimeFromVideoType(const media::VideoType& type) { + // The MIME string is for very basic video codec supportability check. + switch (type.codec) { + case media::VideoCodec::kH264: + return "video/mp4; codecs=\"avc1.4d4015\""; + case media::VideoCodec::kVP9: + return "video/webm; codecs=\"vp9\""; + case media::VideoCodec::kAV1: + return "video/mp4; codecs=\"av01.0.08M.08\""; + default: + return ""; + } +} + +bool CobaltContentRendererClient::IsSupportedAudioType( + const media::AudioType& type) { + std::string mime = GetMimeFromAudioType(type); + SbMediaSupportType support_type = kSbMediaSupportTypeNotSupported; + if (!mime.empty()) { + support_type = SbMediaCanPlayMimeAndKeySystem(mime.c_str(), ""); + } + bool result = support_type != kSbMediaSupportTypeNotSupported; + LOG(INFO) << __func__ << "(" << type.codec << ") -> " + << (result ? "true" : "false"); + return result; +} + +bool CobaltContentRendererClient::IsSupportedVideoType( + const media::VideoType& type) { + std::string mime = GetMimeFromVideoType(type); + SbMediaSupportType support_type = kSbMediaSupportTypeNotSupported; + if (!mime.empty()) { + support_type = SbMediaCanPlayMimeAndKeySystem(mime.c_str(), ""); + } + bool result = support_type != kSbMediaSupportTypeNotSupported; + LOG(INFO) << __func__ << "(" << type.codec << ") -> " + << (result ? "true" : "false"); + return result; +} +#endif // BUILDFLAG(USE_STARBOARD_MEDIA) + +std::unique_ptr +CobaltContentRendererClient::CreatePrescientNetworking( + content::RenderFrame* render_frame) { + return std::make_unique( + render_frame); +} + +} // namespace cobalt diff --git a/cobalt/renderer/cobalt_content_renderer_client.h b/cobalt/renderer/cobalt_content_renderer_client.h new file mode 100644 index 000000000000..855c705cdb66 --- /dev/null +++ b/cobalt/renderer/cobalt_content_renderer_client.h @@ -0,0 +1,79 @@ +// Copyright 2025 The Cobalt Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COBALT_RENDERER_COBALT_CONTENT_RENDERER_CLIENT_H_ +#define COBALT_RENDERER_COBALT_CONTENT_RENDERER_CLIENT_H_ + +#include +#include + +#include "build/build_config.h" +#include "content/public/common/alternative_error_page_override_info.mojom-forward.h" +#include "content/public/renderer/content_renderer_client.h" +#include "media/mojo/buildflags.h" + +// For BUILDFLAG(USE_STARBOARD_MEDIA) +#include "build/build_config.h" + +namespace blink { +class URLLoaderThrottleProvider; +enum class URLLoaderThrottleProviderType; +} // namespace blink + +namespace web_cache { +class WebCacheImpl; +} + +namespace cobalt { + +class CobaltContentRendererClient : public content::ContentRendererClient { + public: + CobaltContentRendererClient(); + ~CobaltContentRendererClient() override; + + // ContentRendererClient implementation. + void RenderThreadStarted() override; + void ExposeInterfacesToBrowser(mojo::BinderMap* binders) override; + void RenderFrameCreated(content::RenderFrame* render_frame) override; + void PrepareErrorPage(content::RenderFrame* render_frame, + const blink::WebURLError& error, + const std::string& http_method, + content::mojom::AlternativeErrorPageOverrideInfoPtr + alternative_error_page_info, + std::string* error_html) override; + void PrepareErrorPageForHttpStatusError( + content::RenderFrame* render_frame, + const blink::WebURLError& error, + const std::string& http_method, + int http_status, + content::mojom::AlternativeErrorPageOverrideInfoPtr + alternative_error_page_info, + std::string* error_html) override; + + void DidInitializeWorkerContextOnWorkerThread( + v8::Local context) override; + + std::unique_ptr + CreateURLLoaderThrottleProvider( + blink::URLLoaderThrottleProviderType provider_type) override; + +#if BUILDFLAG(ENABLE_MOJO_CDM) + void GetSupportedKeySystems(media::GetSupportedKeySystemsCB cb) override; +#endif + +#if BUILDFLAG(USE_STARBOARD_MEDIA) + bool IsSupportedAudioType(const media::AudioType& type) override; + bool IsSupportedVideoType(const media::VideoType& type) override; +#endif // BUILDFLAG(USE_STARBOARD_MEDIA) + + std::unique_ptr CreatePrescientNetworking( + content::RenderFrame* render_frame) override; + + private: + std::unique_ptr web_cache_impl_; +}; + +} // namespace cobalt + +#endif // COBALT_RENDERER_COBALT_CONTENT_RENDERER_CLIENT_H_ diff --git a/content/shell/renderer/shell_content_renderer_client.cc b/content/shell/renderer/shell_content_renderer_client.cc index 6b60a6254a3e..0ffa369c1668 100644 --- a/content/shell/renderer/shell_content_renderer_client.cc +++ b/content/shell/renderer/shell_content_renderer_client.cc @@ -40,11 +40,6 @@ #include "third_party/blink/public/web/web_view.h" #include "v8/include/v8.h" -#if BUILDFLAG(USE_STARBOARD_MEDIA) -#include "starboard/media.h" -#include "components/cdm/renderer/widevine_key_system_info.h" -#endif // BUILDFLAG(USE_STARBOARD_MEDIA) - #if BUILDFLAG(ENABLE_PLUGINS) #include "ppapi/shared_impl/ppapi_switches.h" // nogncheck #endif @@ -271,63 +266,6 @@ ShellContentRendererClient::CreateURLLoaderThrottleProvider( return std::make_unique(); } -#if BUILDFLAG(USE_STARBOARD_MEDIA) -media::SupportedCodecs GetStarboardEmeSupportedCodecs() { - media::SupportedCodecs codecs = ::media::EME_CODEC_AAC | - ::media::EME_CODEC_AVC1 | - ::media::EME_CODEC_VP9_PROFILE0 | - ::media::EME_CODEC_VP9_PROFILE2 | - ::media::EME_CODEC_VP8 | - ::media::EME_CODEC_OPUS | - ::media::EME_CODEC_VORBIS | - ::media::EME_CODEC_MPEG_H_AUDIO | - ::media::EME_CODEC_FLAC | - ::media::EME_CODEC_HEVC_PROFILE_MAIN | - ::media::EME_CODEC_HEVC_PROFILE_MAIN10 | - ::media::EME_CODEC_AV1 | - ::media::EME_CODEC_AC3 | - ::media::EME_CODEC_EAC3; - // TODO(b/375232937) Add IAMF - return codecs; -} - -#if BUILDFLAG(IS_ANDROID) -void AddStarboardCmaKeySystems(::media::KeySystemInfos* key_system_infos) { - media::SupportedCodecs codecs = GetStarboardEmeSupportedCodecs(); - - using Robustness = cdm::WidevineKeySystemInfo::Robustness; - - const base::flat_set kEncryptionSchemes = { - media::EncryptionScheme::kCenc, media::EncryptionScheme::kCbcs}; - - const base::flat_set kSessionTypes = { - media::CdmSessionType::kTemporary}; - - key_system_infos->emplace_back(new cdm::WidevineKeySystemInfo( - codecs, // Regular codecs. - kEncryptionSchemes, // Encryption schemes. - kSessionTypes, // Session types. - codecs, // Hardware secure codecs. - kEncryptionSchemes, // Hardware secure encryption schemes. - kSessionTypes, // Hardware secure session types. - Robustness::HW_SECURE_CRYPTO, // Max audio robustness. - Robustness::HW_SECURE_ALL, // Max video robustness. - media::EmeFeatureSupport::ALWAYS_ENABLED, // Persistent state. - media::EmeFeatureSupport::ALWAYS_ENABLED)); // Distinctive identifier. -} -#endif - -void ShellContentRendererClient::GetSupportedKeySystems( - media::GetSupportedKeySystemsCB cb) { - media::KeySystemInfos key_systems; -#if BUILDFLAG(IS_ANDROID) - AddStarboardCmaKeySystems(&key_systems); - std::move(cb).Run(std::move(key_systems)); -#endif -} - -#else // BUILDFLAG(USE_STARBOARD_MEDIA) - #if BUILDFLAG(ENABLE_MOJO_CDM) void ShellContentRendererClient::GetSupportedKeySystems( media::GetSupportedKeySystemsCB cb) { @@ -339,74 +277,6 @@ void ShellContentRendererClient::GetSupportedKeySystems( } #endif -#endif // BUILDFLAG(USE_STARBOARD_MEDIA) - -#if BUILDFLAG(USE_STARBOARD_MEDIA) -// TODO(b/376542844): Eliminate the usage of hardcoded MIME string once we -// support to query codec capabilities with configs. -std::string GetMimeFromAudioType(const media::AudioType& type) { - // The MIME string is for very basic audio codec supportability check. - switch (type.codec) { - case media::AudioCodec::kAAC: - return "audio/mp4; codecs=\"mp4a.40.2\""; - case media::AudioCodec::kAC3: - return "audio/mp4; codecs=\"ac-3\""; - case media::AudioCodec::kEAC3: - return "audio/mp4; codecs=\"ec-3\""; - case media::AudioCodec::kOpus: - return "audio/webm; codecs=\"opus\""; - // TODO(b/375232937): Support IAMF - default: - return ""; - } -} - -// TODO(b/376542844): Eliminate the usage of hardcoded MIME string once we -// support to query codec capabilities with configs. The profile information -// gets lost with hardcoded MIME string. This can sometimes cause issues. For -// example, vp9 profile 2 indicates hdr support, so an implementation accepts -// "codecs=vp9" may reject "codecs=vp9.2". -std::string GetMimeFromVideoType(const media::VideoType& type) { - // The MIME string is for very basic video codec supportability check. - switch (type.codec) { - case media::VideoCodec::kH264: - return "video/mp4; codecs=\"avc1.4d4015\""; - case media::VideoCodec::kVP9: - return "video/webm; codecs=\"vp9\""; - case media::VideoCodec::kAV1: - return "video/mp4; codecs=\"av01.0.08M.08\""; - default: - return ""; - } -} - -bool ShellContentRendererClient::IsSupportedAudioType( - const media::AudioType& type) { - std::string mime = GetMimeFromAudioType(type); - SbMediaSupportType support_type = kSbMediaSupportTypeNotSupported; - if (!mime.empty()) { - support_type = SbMediaCanPlayMimeAndKeySystem(mime.c_str(), ""); - } - bool result = support_type != kSbMediaSupportTypeNotSupported; - LOG(INFO) << __func__ << "(" << type.codec << ") -> " - << (result ? "true" : "false"); - return result; -} - -bool ShellContentRendererClient::IsSupportedVideoType( - const media::VideoType& type) { - std::string mime = GetMimeFromVideoType(type); - SbMediaSupportType support_type = kSbMediaSupportTypeNotSupported; - if (!mime.empty()) { - support_type = SbMediaCanPlayMimeAndKeySystem(mime.c_str(), ""); - } - bool result = support_type != kSbMediaSupportTypeNotSupported; - LOG(INFO) << __func__ << "(" << type.codec << ") -> " - << (result ? "true" : "false"); - return result; -} -#endif // BUILDFLAG(USE_STARBOARD_MEDIA) - std::unique_ptr ShellContentRendererClient::CreatePrescientNetworking( RenderFrame* render_frame) { diff --git a/content/shell/renderer/shell_content_renderer_client.h b/content/shell/renderer/shell_content_renderer_client.h index 34b17d5ad682..9109e002b3ca 100644 --- a/content/shell/renderer/shell_content_renderer_client.h +++ b/content/shell/renderer/shell_content_renderer_client.h @@ -13,9 +13,6 @@ #include "content/public/renderer/content_renderer_client.h" #include "media/mojo/buildflags.h" -// For BUILDFLAG(USE_STARBOARD_MEDIA) -#include "build/build_config.h" - namespace blink { class URLLoaderThrottleProvider; enum class URLLoaderThrottleProviderType; @@ -62,11 +59,6 @@ class ShellContentRendererClient : public ContentRendererClient { void GetSupportedKeySystems(media::GetSupportedKeySystemsCB cb) override; #endif -#if BUILDFLAG(USE_STARBOARD_MEDIA) - bool IsSupportedAudioType(const media::AudioType& type) override; - bool IsSupportedVideoType(const media::VideoType& type) override; -#endif // BUILDFLAG(USE_STARBOARD_MEDIA) - std::unique_ptr CreatePrescientNetworking( RenderFrame* render_frame) override;