diff options
Diffstat (limited to 'src/core/renderer/content_renderer_client_qt.cpp')
-rw-r--r-- | src/core/renderer/content_renderer_client_qt.cpp | 276 |
1 files changed, 192 insertions, 84 deletions
diff --git a/src/core/renderer/content_renderer_client_qt.cpp b/src/core/renderer/content_renderer_client_qt.cpp index 372c519f1..cc127e55f 100644 --- a/src/core/renderer/content_renderer_client_qt.cpp +++ b/src/core/renderer/content_renderer_client_qt.cpp @@ -3,54 +3,54 @@ #include "renderer/content_renderer_client_qt.h" -#include "extensions/buildflags/buildflags.h" -#include "printing/buildflags/buildflags.h" #include "renderer/content_settings_observer_qt.h" -#include "base/strings/string_split.h" -#if QT_CONFIG(webengine_spellchecker) -#include "components/spellcheck/renderer/spellcheck.h" -#include "components/spellcheck/renderer/spellcheck_provider.h" -#endif +#include "renderer/render_configuration.h" +#include "renderer/render_frame_observer_qt.h" +#include "renderer/user_resource_controller.h" +#include "renderer/web_engine_page_render_frame.h" +#include "web_engine_library_info.h" + +#include "base/task/sequenced_task_runner.h" #include "components/autofill/content/renderer/autofill_agent.h" -#include "components/autofill/content/renderer/autofill_assistant_agent.h" #include "components/autofill/content/renderer/password_autofill_agent.h" #include "components/autofill/content/renderer/password_generation_agent.h" -#include "components/cdm/renderer/external_clear_key_key_system_properties.h" -#include "components/cdm/renderer/widevine_key_system_properties.h" +#include "components/cdm/renderer/external_clear_key_key_system_info.h" +#include "components/cdm/renderer/widevine_key_system_info.h" #include "components/error_page/common/error.h" #include "components/error_page/common/localized_error.h" +#include "components/grit/components_resources.h" #include "components/network_hints/renderer/web_prescient_networking_impl.h" -#if QT_CONFIG(webengine_printing_and_pdf) -#include "components/printing/renderer/print_render_frame_helper.h" -#endif #include "components/visitedlink/renderer/visitedlink_reader.h" #include "components/web_cache/renderer/web_cache_impl.h" #include "content/public/renderer/render_frame.h" -#include "content/public/child/child_thread.h" #include "content/public/common/url_constants.h" #include "content/public/renderer/render_thread.h" -#include "content/public/renderer/render_view.h" -#include "media/base/key_system_properties.h" +#include "extensions/buildflags/buildflags.h" +#include "media/base/key_system_info.h" +#include "media/cdm/cdm_capability.h" #include "media/media_buildflags.h" #include "mojo/public/cpp/bindings/binder_map.h" #include "net/base/net_errors.h" #include "ppapi/buildflags/buildflags.h" -#include "services/service_manager/public/cpp/connector.h" -#include "services/service_manager/public/cpp/interface_provider.h" +#include "printing/buildflags/buildflags.h" +#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h" #include "third_party/blink/public/platform/web_url_error.h" -#include "third_party/blink/public/platform/web_url_request.h" -#include "third_party/blink/public/web/web_security_policy.h" #include "ui/base/resource/resource_bundle.h" #include "ui/base/webui/jstemplate_builder.h" +#if QT_CONFIG(webengine_spellchecker) +#include "components/spellcheck/renderer/spellcheck.h" +#include "components/spellcheck/renderer/spellcheck_provider.h" +#endif + #if QT_CONFIG(webengine_printing_and_pdf) #include "renderer/print_web_view_helper_delegate_qt.h" + +#include "components/pdf/renderer/internal_plugin_renderer_helpers.h" +#include "components/pdf/renderer/pdf_internal_plugin_delegate.h" +#include "components/printing/renderer/print_render_frame_helper.h" #endif -#include "renderer/render_frame_observer_qt.h" -#include "renderer/web_engine_page_render_frame.h" -#include "renderer/render_configuration.h" -#include "renderer/user_resource_controller.h" #if QT_CONFIG(webengine_webchannel) #include "renderer/web_channel_ipc_transport.h" #endif @@ -58,35 +58,35 @@ #if BUILDFLAG(ENABLE_EXTENSIONS) #include "common/extensions/extensions_client_qt.h" #include "extensions/extensions_renderer_client_qt.h" + +#include "extensions/common/constants.h" #include "extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container_manager.h" #include "mojo/public/cpp/bindings/associated_remote.h" -#endif //ENABLE_EXTENSIONS +#include "services/service_manager/public/cpp/binder_registry.h" +#include "third_party/blink/public/web/web_security_policy.h" +#endif // ENABLE_EXTENSIONS #if BUILDFLAG(ENABLE_PLUGINS) #include "content/renderer/render_frame_impl.h" #include "plugins/loadable_plugin_placeholder_qt.h" #endif // ENABLE_PLUGINS -#include "services/service_manager/public/cpp/binder_registry.h" -#include "services/service_manager/public/cpp/connector.h" - -#include "components/grit/components_resources.h" - #if BUILDFLAG(ENABLE_LIBRARY_CDMS) #include "base/feature_list.h" #include "content/public/renderer/key_system_support.h" #include "media/base/media_switches.h" #include "media/base/video_codecs.h" +#include "media/cdm/clear_key_cdm_common.h" #include "third_party/widevine/cdm/buildflags.h" +#if BUILDFLAG(ENABLE_WIDEVINE) #include "third_party/widevine/cdm/widevine_cdm_common.h" #endif +#endif #if QT_CONFIG(webengine_webrtc) && QT_CONFIG(webengine_extensions) #include "chrome/renderer/media/webrtc_logging_agent_impl.h" #endif -#include "web_engine_library_info.h" - namespace QtWebEngineCore { ContentRendererClientQt::ContentRendererClientQt() @@ -131,30 +131,34 @@ void ContentRendererClientQt::RenderThreadStarted() void ContentRendererClientQt::ExposeInterfacesToBrowser(mojo::BinderMap* binders) { - binders->Add(m_visitedLinkReader->GetBindCallback(), base::SequencedTaskRunnerHandle::Get()); + binders->Add<visitedlink::mojom::VisitedLinkNotificationSink>( + m_visitedLinkReader->GetBindCallback(), base::SingleThreadTaskRunner::GetCurrentDefault()); - binders->Add(base::BindRepeating(&web_cache::WebCacheImpl::BindReceiver, - base::Unretained(m_webCacheImpl.get())), - base::SequencedTaskRunnerHandle::Get()); + binders->Add<web_cache::mojom::WebCache>( + base::BindRepeating(&web_cache::WebCacheImpl::BindReceiver, + base::Unretained(m_webCacheImpl.get())), + base::SingleThreadTaskRunner::GetCurrentDefault()); #if QT_CONFIG(webengine_spellchecker) - binders->Add(base::BindRepeating( + binders->Add<spellcheck::mojom::SpellChecker>( + base::BindRepeating( [](ContentRendererClientQt *client, mojo::PendingReceiver<spellcheck::mojom::SpellChecker> receiver) { if (!client->m_spellCheck) client->InitSpellCheck(); client->m_spellCheck->BindReceiver(std::move(receiver)); }, this), - base::SequencedTaskRunnerHandle::Get()); + base::SingleThreadTaskRunner::GetCurrentDefault()); #endif #if QT_CONFIG(webengine_webrtc) && QT_CONFIG(webengine_extensions) - binders->Add(base::BindRepeating( + binders->Add<chrome::mojom::WebRtcLoggingAgent>( + base::BindRepeating( [](ContentRendererClientQt *client, mojo::PendingReceiver<chrome::mojom::WebRtcLoggingAgent> receiver) { client->GetWebRtcLoggingAgent()->AddReceiver(std::move(receiver)); }, this), - base::SequencedTaskRunnerHandle::Get()); + base::SingleThreadTaskRunner::GetCurrentDefault()); #endif } @@ -183,16 +187,15 @@ void ContentRendererClientQt::RenderFrameCreated(content::RenderFrame *render_fr blink::AssociatedInterfaceRegistry *associated_interfaces = render_frame_observer->associatedInterfaces(); #if BUILDFLAG(ENABLE_EXTENSIONS) - associated_interfaces->AddInterface(base::BindRepeating( - &extensions::MimeHandlerViewContainerManager::BindReceiver, - render_frame->GetRoutingID())); + associated_interfaces->AddInterface<extensions::mojom::MimeHandlerViewContainerManager>( + base::BindRepeating( + &extensions::MimeHandlerViewContainerManager::BindReceiver, + render_frame->GetRoutingID())); auto registry = std::make_unique<service_manager::BinderRegistry>(); ExtensionsRendererClientQt::GetInstance()->RenderFrameCreated(render_frame, render_frame_observer->registry()); #endif - autofill::AutofillAssistantAgent *autofill_assistant_agent = - new autofill::AutofillAssistantAgent(render_frame); autofill::PasswordAutofillAgent *password_autofill_agent = new autofill::PasswordAutofillAgent(render_frame, associated_interfaces); autofill::PasswordGenerationAgent *password_generation_agent = @@ -200,7 +203,17 @@ void ContentRendererClientQt::RenderFrameCreated(content::RenderFrame *render_fr associated_interfaces); new autofill::AutofillAgent(render_frame, password_autofill_agent, password_generation_agent, - autofill_assistant_agent, associated_interfaces); + associated_interfaces); +} + +void ContentRendererClientQt::WebViewCreated(blink::WebView *web_view, + bool was_created_by_renderer, + const url::Origin *outermost_origin) +{ + Q_UNUSED(was_created_by_renderer); +#if BUILDFLAG(ENABLE_EXTENSIONS) + ExtensionsRendererClientQt::GetInstance()->WebViewCreated(web_view, outermost_origin); +#endif } void ContentRendererClientQt::RunScriptsAtDocumentStart(content::RenderFrame *render_frame) @@ -238,6 +251,7 @@ void ContentRendererClientQt::RunScriptsAtDocumentIdle(content::RenderFrame *ren void ContentRendererClientQt::PrepareErrorPage(content::RenderFrame *renderFrame, const blink::WebURLError &web_error, const std::string &httpMethod, + content::mojom::AlternativeErrorPageOverrideInfoPtr alternative_error_page_info, std::string *errorHtml) { GetNavigationErrorStringsInternal( @@ -251,6 +265,7 @@ void ContentRendererClientQt::PrepareErrorPageForHttpStatusError(content::Render const blink::WebURLError &error, const std::string &httpMethod, int http_status, + content::mojom::AlternativeErrorPageOverrideInfoPtr alternative_error_page_info, std::string *errorHtml) { GetNavigationErrorStringsInternal(renderFrame, httpMethod, @@ -274,11 +289,12 @@ void ContentRendererClientQt::GetNavigationErrorStringsInternal(content::RenderF // TODO(elproxy): We could potentially get better diagnostics here by first calling // NetErrorHelper::GetErrorStringsForDnsProbe, but that one is harder to untangle. + base::Value::Dict error_page_params; error_page::LocalizedError::PageState errorPageState = error_page::LocalizedError::GetPageState( error.reason(), error.domain(), error.url(), isPost, false, error.stale_copy_in_cache(), false, - RenderConfiguration::is_incognito_process(), false, false, false, locale, false); + RenderConfiguration::is_incognito_process(), false, false, false, locale, false, &error_page_params); resourceId = IDR_NET_ERROR_HTML; @@ -287,7 +303,7 @@ void ContentRendererClientQt::GetNavigationErrorStringsInternal(content::RenderF if (template_html.empty()) NOTREACHED() << "unable to load template. ID: " << resourceId; else // "t" is the id of the templates root node. - *errorHtml = webui::GetTemplatesHtml(template_html, &errorPageState.strings, "t"); + *errorHtml = webui::GetTemplatesHtml(template_html, errorPageState.strings, "t"); } } @@ -306,6 +322,66 @@ std::unique_ptr<blink::WebPrescientNetworking> ContentRendererClientQt::CreatePr return std::make_unique<network_hints::WebPrescientNetworkingImpl>(render_frame); } +namespace { +bool IsPdfExtensionOrigin(const url::Origin &origin) +{ +#if BUILDFLAG(ENABLE_EXTENSIONS) + return origin.scheme() == extensions::kExtensionScheme && + origin.host() == extension_misc::kPdfExtensionId; +#else + return false; +#endif +} + +#if BUILDFLAG(ENABLE_PLUGINS) +void AppendParams(const std::vector<content::WebPluginMimeType::Param> &additional_params, + blink::WebVector<blink::WebString> *existing_names, + blink::WebVector<blink::WebString> *existing_values) +{ + DCHECK(existing_names->size() == existing_values->size()); + size_t existing_size = existing_names->size(); + size_t total_size = existing_size + additional_params.size(); + + blink::WebVector<blink::WebString> names(total_size); + blink::WebVector<blink::WebString> values(total_size); + + for (size_t i = 0; i < existing_size; ++i) { + names[i] = (*existing_names)[i]; + values[i] = (*existing_values)[i]; + } + + for (size_t i = 0; i < additional_params.size(); ++i) { + names[existing_size + i] = blink::WebString::FromUTF16(additional_params[i].name); + values[existing_size + i] = blink::WebString::FromUTF16(additional_params[i].value); + } + + existing_names->Swap(names); + existing_values->Swap(values); +} +#endif // BUILDFLAG(ENABLE_PLUGINS) + +#if QT_CONFIG(webengine_printing_and_pdf) +// based on chrome/renderer/pdf/chrome_pdf_internal_plugin_delegate.cc: +class PdfInternalPluginDelegateQt final + : public pdf::PdfInternalPluginDelegate +{ +public: + PdfInternalPluginDelegateQt() = default; + PdfInternalPluginDelegateQt(const PdfInternalPluginDelegateQt &) = delete; + PdfInternalPluginDelegateQt& operator=(const PdfInternalPluginDelegateQt &) = delete; + ~PdfInternalPluginDelegateQt() override = default; + + // `pdf::PdfInternalPluginDelegate`: + bool IsAllowedOrigin(const url::Origin &origin) const override; +}; + +bool PdfInternalPluginDelegateQt::IsAllowedOrigin(const url::Origin &origin) const +{ + return IsPdfExtensionOrigin(origin); +} +#endif +} // namespace + bool ContentRendererClientQt::IsPluginHandledExternally(content::RenderFrame *render_frame, const blink::WebElement &plugin_element, const GURL &original_url, @@ -320,6 +396,8 @@ bool ContentRendererClientQt::IsPluginHandledExternally(content::RenderFrame *re original_url, original_mime_type, &found, &plugin_info, &mime_type); if (!found) return false; + if (IsPdfExtensionOrigin(render_frame->GetWebFrame()->GetSecurityOrigin())) + return true; return extensions::MimeHandlerViewContainerManager::Get( content::RenderFrame::FromWebFrame( plugin_element.GetDocument().GetFrame()), @@ -337,7 +415,7 @@ bool ContentRendererClientQt::OverrideCreatePlugin(content::RenderFrame *render_ #if BUILDFLAG(ENABLE_EXTENSIONS) if (!ExtensionsRendererClientQt::GetInstance()->OverrideCreatePlugin(render_frame, params)) return false; -#endif //ENABLE_EXTENSIONS +#endif // ENABLE_EXTENSIONS #if BUILDFLAG(ENABLE_PLUGINS) content::WebPluginInfo info; @@ -346,11 +424,25 @@ bool ContentRendererClientQt::OverrideCreatePlugin(content::RenderFrame *render_ static_cast<content::RenderFrameImpl *>(render_frame)->GetPepperHost()->GetPluginInfo( params.url, params.mime_type.Utf8(), &found, &info, &mime_type); - if (!found) + if (!found) { *plugin = LoadablePluginPlaceholderQt::CreateLoadableMissingPlugin(render_frame, params)->plugin(); - else - *plugin = render_frame->CreatePlugin(info, params); -#endif // BUILDFLAG(ENABLE_PLUGINS) + return true; + } + if (info.name == u"Chromium PDF Viewer") { + blink::WebPluginParams new_params(params); + for (const auto& mime_type : info.mime_types) { + if (mime_type.mime_type == params.mime_type.Utf8()) { + AppendParams(mime_type.additional_params, &new_params.attribute_names, + &new_params.attribute_values); + break; + } + } + + *plugin = pdf::CreateInternalPlugin(std::move(new_params), render_frame, std::make_unique<PdfInternalPluginDelegateQt>()); + return true; + } + *plugin = render_frame->CreatePlugin(info, params); +#endif // BUILDFLAG(ENABLE_PLUGINS) return true; } @@ -382,22 +474,21 @@ void ContentRendererClientQt::GetInterface(const std::string &interface_name, mo #if BUILDFLAG(ENABLE_LIBRARY_CDMS) // External Clear Key (used for testing). -static void AddExternalClearKey(std::vector<std::unique_ptr<media::KeySystemProperties>> *key_systems) +static void AddExternalClearKey(const media::mojom::KeySystemCapabilityPtr &capability, + media::KeySystemInfos* key_systems) { - static const char kExternalClearKeyKeySystem[] = "org.chromium.externalclearkey"; - - // TODO(xhwang): Actually use `capability` to determine capabilities. - media::mojom::KeySystemCapabilityPtr capability; - if (!content::IsKeySystemSupported(kExternalClearKeyKeySystem, &capability)) { - DVLOG(1) << "External Clear Key not supported"; + Q_UNUSED(capability); + if (!base::FeatureList::IsEnabled(media::kExternalClearKeyForTesting)) { + DLOG(ERROR) << "ExternalClearKey supported despite not enabled."; return; } - key_systems->push_back(std::make_unique<cdm::ExternalClearKeyProperties>()); + // TODO(xhwang): Actually use `capability` to determine capabilities. + key_systems->push_back(std::make_unique<cdm::ExternalClearKeyKeySystemInfo>()); } #if BUILDFLAG(ENABLE_WIDEVINE) -media::SupportedCodecs GetVP9Codecs(const std::vector<media::VideoCodecProfile> &profiles) +media::SupportedCodecs GetVP9Codecs(const base::flat_set<media::VideoCodecProfile> &profiles) { if (profiles.empty()) { // If no profiles are specified, then all are supported. @@ -424,7 +515,7 @@ media::SupportedCodecs GetVP9Codecs(const std::vector<media::VideoCodecProfile> } #if BUILDFLAG(ENABLE_PLATFORM_HEVC) -SupportedCodecs GetHevcCodecs(const std::vector<media::VideoCodecProfile> &profiles) +media::SupportedCodecs GetHevcCodecs(const base::flat_set<media::VideoCodecProfile> &profiles) { // If no profiles are specified, then all are supported. if (profiles.empty()) { @@ -485,7 +576,7 @@ static media::SupportedCodecs GetSupportedCodecs(const media::CdmCapability& cap supported_codecs |= media::EME_CODEC_VP8; break; case media::VideoCodec::kVP9: - supported_codecs |= GetVP9Codecs(codec.second); + supported_codecs |= GetVP9Codecs(codec.second.supported_profiles); break; case media::VideoCodec::kAV1: supported_codecs |= media::EME_CODEC_AV1; @@ -497,7 +588,7 @@ static media::SupportedCodecs GetSupportedCodecs(const media::CdmCapability& cap #endif // BUILDFLAG(USE_PROPRIETARY_CODECS) #if BUILDFLAG(ENABLE_PLATFORM_HEVC) case media::VideoCodec::kHEVC: - supported_codecs |= GetHevcCodecs(codec.second); + supported_codecs |= GetHevcCodecs(codec.second.supported_profiles); break; #endif // BUILDFLAG(ENABLE_PLATFORM_HEVC) default: @@ -509,19 +600,16 @@ static media::SupportedCodecs GetSupportedCodecs(const media::CdmCapability& cap return supported_codecs; } -static void AddWidevine(std::vector<std::unique_ptr<media::KeySystemProperties>> *key_systems) +static void AddWidevine(const media::mojom::KeySystemCapabilityPtr &capability, + media::KeySystemInfos *key_systems) { - media::mojom::KeySystemCapabilityPtr capability; - if (!content::IsKeySystemSupported(kWidevineKeySystem, &capability)) { - DVLOG(1) << "Widevine CDM is not currently available."; - return; - } - // Codecs and encryption schemes. media::SupportedCodecs codecs = media::EME_CODEC_NONE; media::SupportedCodecs hw_secure_codecs = media::EME_CODEC_NONE; base::flat_set<media::EncryptionScheme> encryption_schemes; base::flat_set<media::EncryptionScheme> hw_secure_encryption_schemes; + base::flat_set<media::CdmSessionType> session_types; + base::flat_set<media::CdmSessionType> hw_secure_session_types; if (capability->sw_secure_capability) { codecs = GetSupportedCodecs(capability->sw_secure_capability.value(), /*is_secure=*/false); encryption_schemes = capability->sw_secure_capability->encryption_schemes; @@ -541,7 +629,7 @@ static void AddWidevine(std::vector<std::unique_ptr<media::KeySystemProperties>> } // Robustness. - using Robustness = cdm::WidevineKeySystemProperties::Robustness; + using Robustness = cdm::WidevineKeySystemInfo::Robustness; auto max_audio_robustness = Robustness::SW_SECURE_CRYPTO; auto max_video_robustness = Robustness::SW_SECURE_DECODE; @@ -550,32 +638,52 @@ static void AddWidevine(std::vector<std::unique_ptr<media::KeySystemProperties>> max_video_robustness = Robustness::HW_SECURE_ALL; } - auto persistent_license_support = media::EmeSessionTypeSupport::NOT_SUPPORTED; - // Others. auto persistent_state_support = media::EmeFeatureSupport::REQUESTABLE; auto distinctive_identifier_support = media::EmeFeatureSupport::NOT_SUPPORTED; - key_systems->emplace_back(new cdm::WidevineKeySystemProperties( - codecs, encryption_schemes, hw_secure_codecs, - hw_secure_encryption_schemes, max_audio_robustness, max_video_robustness, - persistent_license_support, persistent_state_support, + key_systems->emplace_back(new cdm::WidevineKeySystemInfo( + codecs, std::move(encryption_schemes), std::move(session_types), + hw_secure_codecs, std::move(hw_secure_encryption_schemes), + std::move(hw_secure_session_types), + max_audio_robustness, max_video_robustness, + persistent_state_support, distinctive_identifier_support)); } #endif // BUILDFLAG(ENABLE_WIDEVINE) #endif // BUILDFLAG(ENABLE_LIBRARY_CDMS) -void ContentRendererClientQt::AddSupportedKeySystems(std::vector<std::unique_ptr<media::KeySystemProperties>> *key_systems) +void OnKeySystemSupportUpdated(media::GetSupportedKeySystemsCB cb, + content::KeySystemCapabilityPtrMap key_system_capabilities) { + media::KeySystemInfos key_systems; + for (const auto &entry : key_system_capabilities) { #if BUILDFLAG(ENABLE_LIBRARY_CDMS) - if (base::FeatureList::IsEnabled(media::kExternalClearKeyForTesting)) - AddExternalClearKey(key_systems); - + const auto &key_system = entry.first; + const auto &capability = entry.second; #if BUILDFLAG(ENABLE_WIDEVINE) - AddWidevine(key_systems); + if (key_system == kWidevineKeySystem) { + AddWidevine(capability, &key_systems); + continue; + } #endif // BUILDFLAG(ENABLE_WIDEVINE) + if (key_system == media::kExternalClearKeyKeySystem) { + AddExternalClearKey(capability, &key_systems); + continue; + } + + DLOG(ERROR) << "Unrecognized key system: " << key_system; #endif // BUILDFLAG(ENABLE_LIBRARY_CDMS) + } + + cb.Run(std::move(key_systems)); +} + +void ContentRendererClientQt::GetSupportedKeySystems(media::GetSupportedKeySystemsCB cb) +{ + content::ObserveKeySystemSupportUpdate( + base::BindRepeating(&OnKeySystemSupportUpdated, std::move(cb))); } #if QT_CONFIG(webengine_spellchecker) |