From 2d002e42a8b6e711e3c9ca5b6dd3611e9d8426ab Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 15 Sep 2022 17:08:33 +0200 Subject: Adaptations for 104-based Change-Id: Ieb44b5c98b3342adca38916d8b77c54e8ed8e1d7 Reviewed-by: Peter Varga Reviewed-by: Michal Klocek --- src/core/CMakeLists.txt | 1 - src/core/accessibility_tree_formatter_qt.cpp | 32 +-- src/core/authentication_dialog_controller.cpp | 3 +- src/core/autofill_client_qt.cpp | 2 +- src/core/autofill_client_qt.h | 2 +- src/core/autofill_popup_controller.cpp | 8 +- src/core/browser_accessibility_qt.cpp | 2 +- src/core/chromium_overrides.cpp | 12 +- src/core/compositor/display_gl_output_surface.cpp | 304 --------------------- src/core/compositor/display_gl_output_surface.h | 113 -------- src/core/compositor/display_overrides.cpp | 12 - src/core/configure/BUILD.root.gn.in | 10 +- src/core/content_browser_client_qt.cpp | 11 +- src/core/content_browser_client_qt.h | 4 +- src/core/content_main_delegate_qt.cpp | 5 - src/core/content_main_delegate_qt.h | 1 - src/core/devtools_frontend_qt.cpp | 1 - src/core/download_manager_delegate_qt.cpp | 3 + src/core/extensions/extension_system_qt.cpp | 9 +- .../extensions/extensions_browser_client_qt.cpp | 8 +- src/core/extensions/extensions_browser_client_qt.h | 2 +- .../pdf_iframe_navigation_throttle_qt.cpp | 4 +- .../file_system_access_permission_context_qt.cpp | 13 +- .../file_system_access_permission_context_qt.h | 1 + .../file_system_access_permission_grant_qt.cpp | 28 +- .../file_system_access_permission_grant_qt.h | 10 +- src/core/login_delegate_qt.cpp | 4 +- src/core/media_capture_devices_dispatcher.cpp | 226 ++++++++++++--- src/core/media_capture_devices_dispatcher.h | 2 +- src/core/net/client_cert_qt.cpp | 5 +- src/core/net/custom_url_loader_factory.cpp | 14 +- ...in_response_interceptor_url_loader_throttle.cpp | 6 +- src/core/net/proxy_config_monitor.cpp | 5 +- .../net/proxying_restricted_cookie_manager_qt.cpp | 8 +- .../net/proxying_restricted_cookie_manager_qt.h | 1 + src/core/net/proxying_url_loader_factory_qt.cpp | 8 +- src/core/net/url_request_custom_job_delegate.cpp | 1 - src/core/ozone/gl_ozone_egl_qt.cpp | 10 +- src/core/ozone/gl_ozone_egl_qt.h | 4 +- src/core/ozone/gl_ozone_glx_qt.cpp | 12 +- src/core/ozone/gl_ozone_glx_qt.h | 6 +- src/core/ozone/gl_surface_egl_qt.cpp | 109 ++++---- src/core/ozone/gl_surface_egl_qt.h | 2 +- src/core/ozone/gl_surface_glx_qt.cpp | 16 +- src/core/ozone/gl_surface_glx_qt.h | 2 +- src/core/ozone/platform_window_qt.cpp | 14 +- src/core/ozone/platform_window_qt.h | 10 +- src/core/permission_manager_qt.cpp | 111 ++++---- src/core/permission_manager_qt.h | 32 ++- src/core/platform_notification_service_qt.cpp | 1 - src/core/pref_service_adapter.cpp | 2 - src/core/printing/print_view_manager_base_qt.cpp | 212 +++++--------- src/core/printing/print_view_manager_base_qt.h | 23 +- src/core/printing/print_view_manager_qt.cpp | 116 ++++---- src/core/printing/print_view_manager_qt.h | 2 +- src/core/profile_io_data_qt.cpp | 1 - src/core/quota_permission_context_qt.cpp | 7 +- src/core/renderer/content_renderer_client_qt.cpp | 14 +- src/core/web_contents_adapter.cpp | 6 +- src/core/web_contents_delegate_qt.cpp | 27 +- src/core/web_contents_delegate_qt.h | 6 +- src/core/web_engine_context.cpp | 3 +- src/core/web_engine_context.h | 1 - src/core/web_engine_context_threads.cpp | 18 +- 64 files changed, 640 insertions(+), 1008 deletions(-) delete mode 100644 src/core/compositor/display_gl_output_surface.cpp delete mode 100644 src/core/compositor/display_gl_output_surface.h diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index ed14bbd31..745bf4cc2 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -212,7 +212,6 @@ foreach(arch ${archs}) extend_gn_target(${buildGn} CONDITION QT_FEATURE_opengl SOURCES compositor/compositor_resource_fence.cpp compositor/compositor_resource_fence.h - compositor/display_gl_output_surface.cpp compositor/display_gl_output_surface.h compositor/display_skia_output_device.cpp compositor/display_skia_output_device.h ) diff --git a/src/core/accessibility_tree_formatter_qt.cpp b/src/core/accessibility_tree_formatter_qt.cpp index 6167bc73b..dcf2aa39d 100644 --- a/src/core/accessibility_tree_formatter_qt.cpp +++ b/src/core/accessibility_tree_formatter_qt.cpp @@ -31,8 +31,8 @@ public: } private: - void RecursiveBuildAccessibilityTree(const BrowserAccessibility &node, base::DictionaryValue *dict) const; - void AddProperties(const BrowserAccessibility &node, base::DictionaryValue *dict) const; + void RecursiveBuildAccessibilityTree(const BrowserAccessibility &node, base::Value::Dict *dict) const; + void AddProperties(const BrowserAccessibility &node, base::Value::Dict *dict) const; std::string ProcessTreeForOutput(const base::DictionaryValue &node) const override; }; @@ -48,33 +48,33 @@ base::Value AccessibilityTreeFormatterQt::BuildTree(ui::AXPlatformNodeDelegate * { BrowserAccessibility *root_internal = BrowserAccessibility::FromAXPlatformNodeDelegate(start); - base::Value dict(base::Value::Type::DICTIONARY); - RecursiveBuildAccessibilityTree(*root_internal, static_cast(&dict)); - return dict; + base::Value::Dict dict; + RecursiveBuildAccessibilityTree(*root_internal, &dict); + return base::Value(std::move(dict)); } -void AccessibilityTreeFormatterQt::RecursiveBuildAccessibilityTree(const BrowserAccessibility &node, base::DictionaryValue *dict) const +void AccessibilityTreeFormatterQt::RecursiveBuildAccessibilityTree(const BrowserAccessibility &node, base::Value::Dict *dict) const { AddProperties(node, dict); - auto children = std::make_unique(); + base::Value::List children; for (size_t i = 0; i < node.PlatformChildCount(); ++i) { - std::unique_ptr child_dict(new base::DictionaryValue); + base::Value::Dict child_dict; content::BrowserAccessibility *child_node = node.PlatformGetChild(i); - RecursiveBuildAccessibilityTree(*child_node, child_dict.get()); - children->Append(std::move(child_dict)); + RecursiveBuildAccessibilityTree(*child_node, &child_dict); + children.Append(std::move(child_dict)); } dict->Set(kChildrenDictAttr, std::move(children)); } -void AccessibilityTreeFormatterQt::AddProperties(const BrowserAccessibility &node, base::DictionaryValue *dict) const +void AccessibilityTreeFormatterQt::AddProperties(const BrowserAccessibility &node, base::Value::Dict *dict) const { - dict->SetInteger("id", node.GetId()); + dict->Set("id", node.GetId()); const QAccessibleInterface *iface = toQAccessibleInterface(&node); - dict->SetString("role", qAccessibleRoleString(iface->role())); + dict->Set("role", qAccessibleRoleString(iface->role())); QAccessible::State state = iface->state(); @@ -129,10 +129,10 @@ void AccessibilityTreeFormatterQt::AddProperties(const BrowserAccessibility &nod states.push_back(base::Value("selected")); if (state.traversed) states.push_back(base::Value("traversed")); - dict->SetKey("states", base::Value(states)); + dict->Set("states", base::Value(states)); - dict->SetString("name", iface->text(QAccessible::Name).toStdString()); - dict->SetString("description", iface->text(QAccessible::Description).toStdString()); + dict->Set("name", iface->text(QAccessible::Name).toStdString()); + dict->Set("description", iface->text(QAccessible::Description).toStdString()); } std::string AccessibilityTreeFormatterQt::ProcessTreeForOutput(const base::DictionaryValue &node) const diff --git a/src/core/authentication_dialog_controller.cpp b/src/core/authentication_dialog_controller.cpp index 5ed38ecbd..4efd5dad3 100644 --- a/src/core/authentication_dialog_controller.cpp +++ b/src/core/authentication_dialog_controller.cpp @@ -4,7 +4,6 @@ #include "authentication_dialog_controller.h" #include "authentication_dialog_controller_p.h" -#include "base/task/post_task.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_task_traits.h" @@ -17,7 +16,7 @@ AuthenticationDialogControllerPrivate::AuthenticationDialogControllerPrivate(bas void AuthenticationDialogControllerPrivate::dialogFinished(bool accepted, const QString &user, const QString &password) { - base::PostTask(FROM_HERE, {content::BrowserThread::UI}, + content::GetUIThreadTaskRunner({})->PostTask(FROM_HERE, base::BindOnce(&LoginDelegateQt::sendAuthToRequester, loginDelegate, accepted, user, password)); } diff --git a/src/core/autofill_client_qt.cpp b/src/core/autofill_client_qt.cpp index fb3f726ae..01b5be768 100644 --- a/src/core/autofill_client_qt.cpp +++ b/src/core/autofill_client_qt.cpp @@ -113,7 +113,7 @@ bool AutofillClientQt::IsPasswordManagerEnabled() return false; } -void AutofillClientQt::PropagateAutofillPredictions(content::RenderFrameHost *, +void AutofillClientQt::PropagateAutofillPredictions(autofill::AutofillDriver *, const std::vector &) { // For testing purposes only. diff --git a/src/core/autofill_client_qt.h b/src/core/autofill_client_qt.h index 967c4b227..95ae460f2 100644 --- a/src/core/autofill_client_qt.h +++ b/src/core/autofill_client_qt.h @@ -54,7 +54,7 @@ public: void HideAutofillPopup(autofill::PopupHidingReason reason) override; bool IsAutocompleteEnabled() override; bool IsPasswordManagerEnabled() override; - void PropagateAutofillPredictions(content::RenderFrameHost *, + void PropagateAutofillPredictions(autofill::AutofillDriver *, const std::vector &) override; diff --git a/src/core/autofill_popup_controller.cpp b/src/core/autofill_popup_controller.cpp index 260b1ca8a..f13188a99 100644 --- a/src/core/autofill_popup_controller.cpp +++ b/src/core/autofill_popup_controller.cpp @@ -26,7 +26,7 @@ void AutofillPopupController::setCurrentIndex(const QModelIndex &index) if (m_currentIndex.isValid()) { const autofill::Suggestion &suggestion = d->suggestions[m_currentIndex.row()]; - d->delegate->DidSelectSuggestion(suggestion.value, suggestion.frontend_id, suggestion.backend_id); + d->delegate->DidSelectSuggestion(suggestion.main_text.value, suggestion.frontend_id, suggestion.GetPayload()); } Q_EMIT currentIndexChanged(index); @@ -79,8 +79,8 @@ void AutofillPopupController::acceptSuggestion() const int index = m_currentIndex.row(); const autofill::Suggestion &suggestion = d->suggestions[index]; - d->delegate->DidAcceptSuggestion(suggestion.value, suggestion.frontend_id, - suggestion.backend_id, index); + d->delegate->DidAcceptSuggestion(suggestion.main_text.value, suggestion.frontend_id, + suggestion.payload, index); } void AutofillPopupController::notifyPopupShown() @@ -105,7 +105,7 @@ void AutofillPopupController::updateModel() { QStringList values; for (size_t i = 0; i < d->suggestions.size(); ++i) { - values.append(QString::fromStdU16String(d->suggestions[i].value)); + values.append(QString::fromStdU16String(d->suggestions[i].main_text.value)); } m_model.setStringList(values); setCurrentIndex(QModelIndex()); diff --git a/src/core/browser_accessibility_qt.cpp b/src/core/browser_accessibility_qt.cpp index 35d5b49d4..dd40eaf49 100644 --- a/src/core/browser_accessibility_qt.cpp +++ b/src/core/browser_accessibility_qt.cpp @@ -263,7 +263,7 @@ int BrowserAccessibilityInterface::indexOfChild(const QAccessibleInterface *ifac { const BrowserAccessibilityInterface *child = static_cast(iface); - return const_cast(child)->q->GetIndexInParent(); + return const_cast(child)->q->GetIndexInParent().value(); } QString BrowserAccessibilityInterface::text(QAccessible::Text t) const diff --git a/src/core/chromium_overrides.cpp b/src/core/chromium_overrides.cpp index 76902bbc4..0b79f2dd4 100644 --- a/src/core/chromium_overrides.cpp +++ b/src/core/chromium_overrides.cpp @@ -45,13 +45,13 @@ class WebContentsView; class WebContentsViewDelegate; class RenderViewHostDelegateView; -WebContentsView* CreateWebContentsView(WebContentsImpl *web_contents, - WebContentsViewDelegate *, +std::unique_ptr CreateWebContentsView(WebContentsImpl *web_contents, + std::unique_ptr delegate, RenderViewHostDelegateView **render_view_host_delegate_view) { QtWebEngineCore::WebContentsViewQt* rv = new QtWebEngineCore::WebContentsViewQt(web_contents); *render_view_host_delegate_view = rv; - return rv; + return std::unique_ptr(rv); } #if defined(Q_OS_DARWIN) @@ -79,9 +79,9 @@ std::unique_ptr GetFontList_SlowBlocking() std::unique_ptr font_list(new base::ListValue); for (auto family : QFontDatabase::families()){ - std::unique_ptr font_item(new base::ListValue()); - font_item->Append(family.toStdString()); - font_item->Append(family.toStdString()); // localized name. + base::Value::List font_item; + font_item.Append(family.toStdString()); + font_item.Append(family.toStdString()); // localized name. // TODO(yusukes): Support localized family names. font_list->Append(std::move(font_item)); } diff --git a/src/core/compositor/display_gl_output_surface.cpp b/src/core/compositor/display_gl_output_surface.cpp deleted file mode 100644 index a13dc2f35..000000000 --- a/src/core/compositor/display_gl_output_surface.cpp +++ /dev/null @@ -1,304 +0,0 @@ -// Copyright (C) 2019 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#include "display_gl_output_surface.h" - -#include "type_conversion.h" - -#include "base/threading/thread_task_runner_handle.h" -#include "components/viz/service/display/display.h" -#include "components/viz/service/display/output_surface_frame.h" -#include "gpu/command_buffer/client/gles2_implementation.h" -#include "gpu/command_buffer/client/gles2_interface.h" -#include "gpu/command_buffer/service/mailbox_manager.h" -#include "gpu/command_buffer/service/texture_base.h" -#include "gpu/ipc/in_process_command_buffer.h" -#include "ui/gfx/buffer_format_util.h" - -namespace QtWebEngineCore { - -DisplayGLOutputSurface::DisplayGLOutputSurface( - scoped_refptr contextProvider) - : OutputSurface(contextProvider) - , Compositor(Compositor::Type::OpenGL) - , m_commandBuffer(contextProvider->command_buffer()) - , m_gl(contextProvider->ContextGL()) - , m_vizContextProvider(contextProvider) -{ - capabilities_.uses_default_gl_framebuffer = false; - m_gl->GenFramebuffers(1, &m_fboId); -} - -DisplayGLOutputSurface::~DisplayGLOutputSurface() -{ - m_vizContextProvider->SetUpdateVSyncParametersCallback(viz::UpdateVSyncParametersCallback()); - m_gl->DeleteFramebuffers(1, &m_fboId); -} - -// Called from viz::Display::Initialize. -void DisplayGLOutputSurface::BindToClient(viz::OutputSurfaceClient *client) -{ - m_client = client; -} - -void DisplayGLOutputSurface::SetFrameSinkId(const viz::FrameSinkId &id) -{ - bind(id); -} - -// Triggered by ui::Compositor::SetVisible(true). -void DisplayGLOutputSurface::EnsureBackbuffer() -{ -} - -// Triggered by ui::Compositor::SetVisible(false). Framebuffer must be cleared. -void DisplayGLOutputSurface::DiscardBackbuffer() -{ - NOTIMPLEMENTED(); - // m_gl->DiscardBackbufferCHROMIUM(); -} - -// Called from viz::DirectRenderer::DrawFrame before rendering starts, but only -// if the parameters differ from the previous Reshape call. -// -// Parameters: -// -// - sizeInPixels comes from ui::Compositor::SetScaleAndSize via -// viz::HostContextFactoryPrivate::ResizeDisplay. -// -// - devicePixelRatio comes from viz::CompositorFrame::device_scale_factor() -// via viz::RootCompositorFrameSinkImpl::SubmitCompositorFrame and -// viz::Display::SetLocalSurfaceId. -// -// - colorSpace and hasAlpha correspond to the color_space and -// has_transparent_background properties of the root viz::RenderPass. -// -// - useStencil should create a stencil buffer, but this is only needed for -// overdraw feedback (--show-overdraw-feedback), so it's safe to ignore. -// Accordingly, capabilities_.supports_stencil should be set to false. -// -void DisplayGLOutputSurface::Reshape(const gfx::Size &sizeInPixels, - float devicePixelRatio, - const gfx::ColorSpace &colorSpace, - gfx::BufferFormat format, - bool /*useStencil*/) -{ - bool hasAlpha = gfx::AlphaBitsForBufferFormat(format) > 0; - m_currentShape = Shape{sizeInPixels, devicePixelRatio, colorSpace, hasAlpha}; - m_gl->ResizeCHROMIUM(sizeInPixels.width(), sizeInPixels.height(), devicePixelRatio, - colorSpace.AsGLColorSpace(), hasAlpha); -} - -std::unique_ptr DisplayGLOutputSurface::makeBuffer(const Shape &shape) -{ - std::unique_ptr buffer = std::make_unique(this); - buffer->shape = shape; - m_gl->GenTextures(1, &buffer->clientId); - m_gl->BindTexture(GL_TEXTURE_2D, buffer->clientId); - m_gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - m_gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - m_gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - m_gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - uint32_t width = shape.sizeInPixels.width(); - uint32_t height = shape.sizeInPixels.height(); - uint32_t format = shape.hasAlpha ? GL_RGBA : GL_RGB; - m_gl->TexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, nullptr); - return buffer; -} - -void DisplayGLOutputSurface::deleteBufferResources(Buffer *buffer) -{ - m_gl->DeleteTextures(1, &buffer->clientId); -} - -// Called by viz::GLRenderer during rendering whenever it switches to the root -// render pass. -void DisplayGLOutputSurface::BindFramebuffer() -{ - if (!m_backBuffer || m_backBuffer->shape != m_currentShape) - m_backBuffer = makeBuffer(m_currentShape); - - m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fboId); - m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_backBuffer->clientId, 0); -} - -// Called from viz::Display::DrawAndSwap after rendering. -// -// Parameters: -// -// - frame.size is the same as the size given to Reshape. -// -// - frame.sub_buffer_rect and frame.content_bounds are never used since these -// are only enabled if gl::GLSurface::SupportsPostSubBuffer() or -// gl::GLSurface::SupportsSwapBuffersWithBounds() are true, respectively, -// but this not the case for any offscreen gl::GLSurface. -// -// - frame.latency_info is viz::CompositorFrame::metadata.latency_info. -void DisplayGLOutputSurface::SwapBuffers(viz::OutputSurfaceFrame frame) -{ - DCHECK(frame.size == m_currentShape.sizeInPixels); - DCHECK(!frame.sub_buffer_rect.has_value()); - DCHECK(frame.content_bounds.empty()); - DCHECK(m_backBuffer); - - m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fboId); - m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0); - gpu::SyncToken syncToken; - m_gl->GenSyncTokenCHROMIUM(syncToken.GetData()); - - unsigned int clientId = m_backBuffer->clientId; - - // Now some thread-hopping: - // - // - We start here on the viz thread (client side of command buffer). - // - // - Then we'll jump to the gpu thread (service side of command buffer) to - // get the real OpenGL texture id. - // - // - Then we'll get a call from the Qt Quick Scene Graph thread (could be - // a separate thread or the main thread). - // - // - Finally we'll return to the viz thread to acknowledge the swap. - - { - QMutexLocker locker(&m_mutex); - m_taskRunner = base::ThreadTaskRunnerHandle::Get(); - m_middleBuffer = std::move(m_backBuffer); - m_middleBuffer->serviceId = 0; - } - - m_commandBuffer->GetTextureQt( - clientId, - base::BindOnce(&DisplayGLOutputSurface::swapBuffersOnGpuThread, base::Unretained(this)), - std::vector{syncToken}); -} - -void DisplayGLOutputSurface::swapBuffersOnGpuThread(unsigned int id, std::unique_ptr fence) -{ - { - QMutexLocker locker(&m_mutex); - m_middleBuffer->serviceId = id; - m_middleBuffer->fence = CompositorResourceFence::create(std::move(fence)); - m_readyToUpdate = true; - } - - if (auto obs = observer()) - obs->readyToSwap(); -} - -void DisplayGLOutputSurface::swapBuffersOnVizThread() -{ - { - QMutexLocker locker(&m_mutex); - m_backBuffer = std::move(m_middleBuffer); - } - - const auto now = base::TimeTicks::Now(); - m_client->DidReceiveSwapBuffersAck(gfx::SwapTimings{now, now, {}, {}, {}}, gfx::GpuFenceHandle()); - m_client->DidReceivePresentationFeedback( - gfx::PresentationFeedback(now, base::TimeDelta(), - gfx::PresentationFeedback::Flags::kVSync)); -} - -void DisplayGLOutputSurface::SetDrawRectangle(const gfx::Rect &) -{ -} - -// Returning true here will cause viz::GLRenderer to try to render the output -// surface as an overlay plane (see viz::DirectRenderer::DrawFrame and -// viz::GLRenderer::ScheduleOverlays). -bool DisplayGLOutputSurface::IsDisplayedAsOverlayPlane() const -{ - return false; -} - -// Only used if IsDisplayedAsOverlayPlane was true (called from -// viz::GLRenderer::ScheduleOverlays). -unsigned DisplayGLOutputSurface::GetOverlayTextureId() const -{ - return 0; -} - -// Called by viz::GLRenderer but always false in all implementations except for -// android_webview::ParentOutputSurface. -bool DisplayGLOutputSurface::HasExternalStencilTest() const -{ - return false; -} - -// Only called if HasExternalStencilTest was true. Dead code? -void DisplayGLOutputSurface::ApplyExternalStencil() -{ - NOTREACHED(); -} - -// Called from GLRenderer::GetFramebufferCopyTextureFormat when using -// glCopyTexSubImage2D on our framebuffer. -uint32_t DisplayGLOutputSurface::GetFramebufferCopyTextureFormat() -{ - return m_currentShape.hasAlpha ? GL_RGBA : GL_RGB; -} - -// Called from viz::DirectRenderer::DrawFrame, only used for overlays. -unsigned DisplayGLOutputSurface::UpdateGpuFence() -{ - NOTREACHED(); - return 0; -} - -void DisplayGLOutputSurface::SetUpdateVSyncParametersCallback(viz::UpdateVSyncParametersCallback callback) -{ - m_vizContextProvider->SetUpdateVSyncParametersCallback(std::move(callback)); -} - -void DisplayGLOutputSurface::SetDisplayTransformHint(gfx::OverlayTransform) -{ -} - -gfx::OverlayTransform DisplayGLOutputSurface::GetDisplayTransform() -{ - return gfx::OVERLAY_TRANSFORM_NONE; -} - -void DisplayGLOutputSurface::swapFrame() -{ - QMutexLocker locker(&m_mutex); - if (m_readyToUpdate) { - std::swap(m_middleBuffer, m_frontBuffer); - m_taskRunner->PostTask(FROM_HERE, - base::BindOnce(&DisplayGLOutputSurface::swapBuffersOnVizThread, - base::Unretained(this))); - m_taskRunner.reset(); - m_readyToUpdate = false; - } -} - -void DisplayGLOutputSurface::waitForTexture() -{ - if (m_frontBuffer && m_frontBuffer->fence) { - m_frontBuffer->fence->wait(); - m_frontBuffer->fence.reset(); - } -} - -int DisplayGLOutputSurface::textureId() -{ - return m_frontBuffer ? m_frontBuffer->serviceId : 0; -} - -QSize DisplayGLOutputSurface::size() -{ - return m_frontBuffer ? toQt(m_frontBuffer->shape.sizeInPixels) : QSize(); -} - -bool DisplayGLOutputSurface::hasAlphaChannel() -{ - return m_frontBuffer ? m_frontBuffer->shape.hasAlpha : false; -} - -float DisplayGLOutputSurface::devicePixelRatio() -{ - return m_frontBuffer ? m_frontBuffer->shape.devicePixelRatio : 1; -} - -} // namespace QtWebEngineCore diff --git a/src/core/compositor/display_gl_output_surface.h b/src/core/compositor/display_gl_output_surface.h deleted file mode 100644 index 28625ef0e..000000000 --- a/src/core/compositor/display_gl_output_surface.h +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright (C) 2019 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#ifndef DISPLAY_GL_OUTPUT_SURFACE_H -#define DISPLAY_GL_OUTPUT_SURFACE_H - -#include "compositor_resource_fence.h" -#include "compositor.h" - -#include "components/viz/common/display/update_vsync_parameters_callback.h" -#include "components/viz/service/display/output_surface.h" -#include "components/viz/service/display_embedder/viz_process_context_provider.h" -#include "gpu/command_buffer/common/mailbox.h" -#include "gpu/command_buffer/common/sync_token.h" - -#include - -namespace QtWebEngineCore { - -class DisplayGLOutputSurface final : public viz::OutputSurface, public Compositor -{ -public: - DisplayGLOutputSurface(scoped_refptr contextProvider); - ~DisplayGLOutputSurface() override; - - // Overridden from viz::OutputSurface. - void BindToClient(viz::OutputSurfaceClient *client) override; - void EnsureBackbuffer() override; - void DiscardBackbuffer() override; - void BindFramebuffer() override; - void SetDrawRectangle(const gfx::Rect &drawRect) override; - bool IsDisplayedAsOverlayPlane() const override; - unsigned GetOverlayTextureId() const override; - void Reshape(const gfx::Size &size, - float devicePixelRatio, - const gfx::ColorSpace &colorSpace, - gfx::BufferFormat format, - bool useStencil) override; - bool HasExternalStencilTest() const override; - void ApplyExternalStencil() override; - uint32_t GetFramebufferCopyTextureFormat() override; - void SwapBuffers(viz::OutputSurfaceFrame frame) override; - unsigned UpdateGpuFence() override; - void SetUpdateVSyncParametersCallback(viz::UpdateVSyncParametersCallback callback) override; - void SetDisplayTransformHint(gfx::OverlayTransform transform) override; - gfx::OverlayTransform GetDisplayTransform() override; - void SetFrameSinkId(const viz::FrameSinkId &id) override; - - // Overridden from Compositor. - void swapFrame() override; - void waitForTexture() override; - int textureId() override; - QSize size() override; - bool hasAlphaChannel() override; - float devicePixelRatio() override; - -private: - struct Shape - { - gfx::Size sizeInPixels; - float devicePixelRatio; - gfx::ColorSpace colorSpace; - bool hasAlpha; - - bool operator==(const Shape &that) const - { - return (sizeInPixels == that.sizeInPixels && - devicePixelRatio == that.devicePixelRatio && - colorSpace == that.colorSpace && - hasAlpha == that.hasAlpha); - } - bool operator!=(const Shape &that) const { return !(*this == that); } - }; - - struct Buffer - { - DisplayGLOutputSurface *parent; - Shape shape; - uint32_t clientId = 0; - uint32_t serviceId = 0; - scoped_refptr fence; - - Buffer(DisplayGLOutputSurface *parent) : parent(parent) {} - ~Buffer() { parent->deleteBufferResources(this); } - }; - - class Texture; - - void swapBuffersOnGpuThread(unsigned int id, std::unique_ptr fence); - void swapBuffersOnVizThread(); - - std::unique_ptr makeBuffer(const Shape &shape); - void deleteBufferResources(Buffer *buffer); - void attachBuffer(); - void detachBuffer(); - - gpu::InProcessCommandBuffer *const m_commandBuffer; - gpu::gles2::GLES2Interface *const m_gl; - mutable QMutex m_mutex; - uint32_t m_fboId = 0; - viz::OutputSurfaceClient *m_client = nullptr; - Shape m_currentShape; - std::unique_ptr m_backBuffer; - std::unique_ptr m_middleBuffer; - std::unique_ptr m_frontBuffer; - bool m_readyToUpdate = false; - scoped_refptr m_taskRunner; - scoped_refptr m_vizContextProvider; -}; - -} // namespace QtWebEngineCore - -#endif // !DISPLAY_GL_OUTPUT_SURFACE_H diff --git a/src/core/compositor/display_overrides.cpp b/src/core/compositor/display_overrides.cpp index bf5daf8e5..aa86861d2 100644 --- a/src/core/compositor/display_overrides.cpp +++ b/src/core/compositor/display_overrides.cpp @@ -1,7 +1,6 @@ // Copyright (C) 2019 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only -#include "display_gl_output_surface.h" #include "display_skia_output_device.h" #include "display_software_output_surface.h" @@ -10,17 +9,6 @@ #include "gpu/ipc/in_process_command_buffer.h" #include -std::unique_ptr -viz::OutputSurfaceProviderImpl::CreateGLOutputSurface( - scoped_refptr context_provider) -{ -#if QT_CONFIG(opengl) - return std::make_unique(std::move(context_provider)); -#else - return nullptr; -#endif // QT_CONFIG(opengl) -} - std::unique_ptr viz::OutputSurfaceProviderImpl::CreateSoftwareOutputSurface() { diff --git a/src/core/configure/BUILD.root.gn.in b/src/core/configure/BUILD.root.gn.in index 604470a68..cdd9c440a 100644 --- a/src/core/configure/BUILD.root.gn.in +++ b/src/core/configure/BUILD.root.gn.in @@ -417,7 +417,7 @@ source_set("qtwebengine_sources") { if (enable_webrtc && enable_extensions) { deps += [ - "//chrome/browser/resources/media:webrtc_logs_resources", + "//chrome/browser/resources/media:resources", "//components/upload_list", "//components/webrtc_logging/browser", "//components/webrtc_logging/common", @@ -548,10 +548,10 @@ repack("qtwebengine_repack_resources") { } if (enable_webrtc && enable_extensions) { sources += [ - "$root_gen_dir/chrome/webrtc_logs_resources.pak", + "$root_gen_dir/chrome/media_resources.pak", ] deps += [ - "//chrome/browser/resources/media:webrtc_logs_resources", + "//chrome/browser/resources/media:resources", ] } if (enable_pdf) { @@ -568,7 +568,6 @@ repack("qtwebengine_repack_resources_100") { sources = [ "$root_gen_dir/chrome/renderer_resources_100_percent.pak", "$root_gen_dir/components/components_resources_100_percent.pak", - "$root_gen_dir/content/app/resources/content_resources_100_percent.pak", "$root_gen_dir/third_party/blink/public/resources/blink_scaled_resources_100_percent.pak", "$root_gen_dir/ui/resources/ui_resources_100_percent.pak", ] @@ -576,7 +575,6 @@ repack("qtwebengine_repack_resources_100") { deps = [ "//chrome/renderer:resources_grit", "//components/resources:components_scaled_resources_grit", - "//content/app/resources:resources_grit", "//third_party/blink/public:scaled_resources_100_percent", "//ui/resources:ui_resources_grd_grit" ] @@ -594,7 +592,6 @@ repack("qtwebengine_repack_resources_200") { sources = [ "$root_gen_dir/chrome/renderer_resources_200_percent.pak", "$root_gen_dir/components/components_resources_200_percent.pak", - "$root_gen_dir/content/app/resources/content_resources_200_percent.pak", "$root_gen_dir/third_party/blink/public/resources/blink_scaled_resources_200_percent.pak", "$root_gen_dir/ui/resources/ui_resources_200_percent.pak", ] @@ -602,7 +599,6 @@ repack("qtwebengine_repack_resources_200") { deps = [ "//chrome/renderer:resources_grit", "//components/resources:components_scaled_resources_grit", - "//content/app/resources:resources_grit", "//third_party/blink/public:scaled_resources_200_percent", "//ui/resources:ui_resources_grd_grit" ] diff --git a/src/core/content_browser_client_qt.cpp b/src/core/content_browser_client_qt.cpp index f662465c0..5a7102b63 100644 --- a/src/core/content_browser_client_qt.cpp +++ b/src/core/content_browser_client_qt.cpp @@ -4,7 +4,6 @@ #include "content_browser_client_qt.h" #include "base/files/file_util.h" -#include "base/task/post_task.h" #include "chrome/browser/tab_contents/form_interaction_tab_helper.h" #include "components/autofill/content/browser/content_autofill_driver_factory.h" #include "components/custom_handlers/protocol_handler_registry.h" @@ -31,9 +30,11 @@ #include "content/public/browser/url_loader_request_interceptor.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_user_data.h" +#include "content/public/browser/web_contents_view_delegate.h" #include "content/public/browser/web_ui_url_loader_factory.h" #include "content/public/common/content_switches.h" #include "content/public/common/main_function_params.h" +#include "content/public/common/url_constants.h" #include "content/public/common/user_agent.h" #include "extensions/buildflags/buildflags.h" #include "mojo/public/cpp/bindings/self_owned_associated_receiver.h" @@ -217,7 +218,7 @@ ContentBrowserClientQt::~ContentBrowserClientQt() { } -std::unique_ptr ContentBrowserClientQt::CreateBrowserMainParts(content::MainFunctionParams) +std::unique_ptr ContentBrowserClientQt::CreateBrowserMainParts(bool) { Q_ASSERT(!m_browserMainParts); auto browserMainParts = std::make_unique(); @@ -727,7 +728,7 @@ bool ContentBrowserClientQt::HandleExternalProtocol(const GURL &url, Q_UNUSED(initiator_document); Q_UNUSED(out_factory); - base::PostTask(FROM_HERE, {content::BrowserThread::UI}, + content::GetUIThreadTaskRunner({})->PostTask(FROM_HERE, base::BindOnce(&LaunchURL, url, std::move(web_contents_getter), @@ -1310,7 +1311,7 @@ void ContentBrowserClientQt::CreateWebSocket( to_url = toGurl(infoPrivate->url); for (auto header = infoPrivate->extraHeaders.constBegin(); header != infoPrivate->extraHeaders.constEnd(); ++header) { std::string h = header.key().toStdString(); - if (base::LowerCaseEqualsASCII(h, net::HttpRequestHeaders::kUserAgent)) + if (base::EqualsCaseInsensitiveASCII(h, net::HttpRequestHeaders::kUserAgent)) addedUserAgent = true; headers.push_back(network::mojom::HttpHeader::New(h, header.value().toStdString())); } @@ -1353,7 +1354,7 @@ void ContentBrowserClientQt::SiteInstanceDeleting(content::SiteInstance *site_in #endif } -content::WebContentsViewDelegate *ContentBrowserClientQt::GetWebContentsViewDelegate(content::WebContents *web_contents) +std::unique_ptr ContentBrowserClientQt::GetWebContentsViewDelegate(content::WebContents *web_contents) { FormInteractionTabHelper::CreateForWebContents(web_contents); FileSystemAccessPermissionRequestManagerQt::CreateForWebContents(web_contents); diff --git a/src/core/content_browser_client_qt.h b/src/core/content_browser_client_qt.h index c16acc304..6cf630581 100644 --- a/src/core/content_browser_client_qt.h +++ b/src/core/content_browser_client_qt.h @@ -42,7 +42,7 @@ class ContentBrowserClientQt : public content::ContentBrowserClient public: ContentBrowserClientQt(); ~ContentBrowserClientQt(); - std::unique_ptr CreateBrowserMainParts(content::MainFunctionParams) override; + std::unique_ptr CreateBrowserMainParts(bool is_integration_test) override; void RenderProcessWillLaunch(content::RenderProcessHost *host) override; gl::GLShareGroup* GetInProcessGpuShareGroup() override; content::MediaObserver* GetMediaObserver() override; @@ -232,7 +232,7 @@ public: void SiteInstanceDeleting(content::SiteInstance *site_instance) override; base::flat_set GetPluginMimeTypesWithExternalHandlers(content::BrowserContext *browser_context) override; - content::WebContentsViewDelegate* GetWebContentsViewDelegate(content::WebContents* web_contents) override; + std::unique_ptr GetWebContentsViewDelegate(content::WebContents *web_contents) override; static std::string getUserAgent(); static blink::UserAgentMetadata getUserAgentMetadata(); diff --git a/src/core/content_main_delegate_qt.cpp b/src/core/content_main_delegate_qt.cpp index bd7a23497..cc5566024 100644 --- a/src/core/content_main_delegate_qt.cpp +++ b/src/core/content_main_delegate_qt.cpp @@ -198,11 +198,6 @@ void ContentMainDelegateQt::PreSandboxStartup() } } -void ContentMainDelegateQt::PostEarlyInitialization(bool) -{ - PostFieldTrialInitialization(); -} - content::ContentClient *ContentMainDelegateQt::CreateContentClient() { return &m_contentClient; diff --git a/src/core/content_main_delegate_qt.h b/src/core/content_main_delegate_qt.h index f88c3dea0..3369beb98 100644 --- a/src/core/content_main_delegate_qt.h +++ b/src/core/content_main_delegate_qt.h @@ -20,7 +20,6 @@ public: // This is where the embedder puts all of its startup code that needs to run // before the sandbox is engaged. void PreSandboxStartup() override; - void PostEarlyInitialization(bool) override; content::ContentClient *CreateContentClient() override; content::ContentBrowserClient* CreateContentBrowserClient() override; diff --git a/src/core/devtools_frontend_qt.cpp b/src/core/devtools_frontend_qt.cpp index 93429057c..ea2118b52 100644 --- a/src/core/devtools_frontend_qt.cpp +++ b/src/core/devtools_frontend_qt.cpp @@ -20,7 +20,6 @@ #include "base/strings/string_number_conversions.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" -#include "base/task/post_task.h" #include "base/values.h" #include "chrome/browser/devtools/devtools_eye_dropper.h" #include "chrome/browser/devtools/devtools_file_helper.h" diff --git a/src/core/download_manager_delegate_qt.cpp b/src/core/download_manager_delegate_qt.cpp index 69803c16b..33783769d 100644 --- a/src/core/download_manager_delegate_qt.cpp +++ b/src/core/download_manager_delegate_qt.cpp @@ -55,6 +55,7 @@ void DownloadManagerDelegateQt::cancelDownload(content::DownloadTargetCallback c download::DownloadItem::UNKNOWN, base::FilePath(), base::FilePath(), + std::string(), absl::nullopt, download::DownloadInterruptReason::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED); } @@ -97,6 +98,7 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(download::DownloadItem * download::DownloadItem::VALIDATED, item->GetForcedFilePath(), item->GetFileNameToReportUser(), + item->GetMimeType(), absl::nullopt, download::DownloadInterruptReason::DOWNLOAD_INTERRUPT_REASON_NONE); return true; @@ -190,6 +192,7 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(download::DownloadItem * download::DownloadItem::VALIDATED, filePathForCallback.AddExtension(toFilePathString("download")), base::FilePath(), + item->GetMimeType(), absl::nullopt, download::DownloadInterruptReason::DOWNLOAD_INTERRUPT_REASON_NONE); } else diff --git a/src/core/extensions/extension_system_qt.cpp b/src/core/extensions/extension_system_qt.cpp index 67750fa6a..0f44b8db3 100644 --- a/src/core/extensions/extension_system_qt.cpp +++ b/src/core/extensions/extension_system_qt.cpp @@ -21,7 +21,6 @@ #include "base/path_service.h" #include "base/strings/string_tokenizer.h" #include "base/strings/utf_string_conversions.h" -#include "base/task/post_task.h" #include "base/time/time.h" #include "base/trace_event/trace_event.h" #include "build/build_config.h" @@ -143,7 +142,7 @@ void ExtensionSystemQt::LoadExtension(std::string extension_id, std::unique_ptr< if (!extension.get()) LOG(ERROR) << error; - base::PostTask(FROM_HERE, {content::BrowserThread::IO}, + content::GetIOThreadTaskRunner({})->PostTask(FROM_HERE, base::BindOnce(&InfoMap::AddExtension, base::Unretained(info_map()), base::RetainedRef(extension), @@ -378,8 +377,7 @@ void ExtensionSystemQt::RegisterExtensionWithRequestContexts(const Extension *ex bool incognito_enabled = false; bool notifications_disabled = false; - base::PostTaskAndReply( - FROM_HERE, {BrowserThread::IO}, + content::GetIOThreadTaskRunner({})->PostTaskAndReply(FROM_HERE, base::BindOnce(&InfoMap::AddExtension, info_map(), base::RetainedRef(extension), install_time, incognito_enabled, notifications_disabled), @@ -388,8 +386,7 @@ void ExtensionSystemQt::RegisterExtensionWithRequestContexts(const Extension *ex void ExtensionSystemQt::UnregisterExtensionWithRequestContexts(const std::string &extension_id) { - base::PostTask( - FROM_HERE, {BrowserThread::IO}, + content::GetIOThreadTaskRunner({})->PostTask(FROM_HERE, base::BindOnce(&InfoMap::RemoveExtension, info_map(), extension_id)); } diff --git a/src/core/extensions/extensions_browser_client_qt.cpp b/src/core/extensions/extensions_browser_client_qt.cpp index f013c04a4..df720987a 100644 --- a/src/core/extensions/extensions_browser_client_qt.cpp +++ b/src/core/extensions/extensions_browser_client_qt.cpp @@ -13,7 +13,6 @@ #include "base/files/file_path.h" #include "base/memory/weak_ptr.h" #include "base/path_service.h" -#include "base/task/post_task.h" #include "base/task/thread_pool.h" #include "base/memory/ref_counted_memory.h" #include "chrome/browser/extensions/api/generated_api_registration.h" @@ -167,9 +166,7 @@ private: if (!head->mime_type.empty()) { head->headers->AddHeader(net::HttpRequestHeaders::kContentType, head->mime_type.c_str()); } - client_->OnReceiveResponse(std::move(head), - mojo::ScopedDataPipeConsumerHandle()); - client_->OnStartLoadingResponseBody(std::move(consumer_handle)); + client_->OnReceiveResponse(std::move(head), std::move(consumer_handle)); uint32_t write_size = data->size(); MojoResult result = producer_handle->WriteData(data->front(), &write_size, MOJO_WRITE_DATA_FLAG_NONE); @@ -449,7 +446,8 @@ const ComponentExtensionResourceManager *ExtensionsBrowserClientQt::GetComponent void ExtensionsBrowserClientQt::BroadcastEventToRenderers(events::HistogramValue histogram_value, const std::string &event_name, - std::unique_ptr args, bool dispatch_to_off_the_record_profiles) + base::Value::List args, + bool dispatch_to_off_the_record_profiles) { NOTIMPLEMENTED(); // TODO : do the event routing diff --git a/src/core/extensions/extensions_browser_client_qt.h b/src/core/extensions/extensions_browser_client_qt.h index e111c1283..a5a35175c 100644 --- a/src/core/extensions/extensions_browser_client_qt.h +++ b/src/core/extensions/extensions_browser_client_qt.h @@ -65,7 +65,7 @@ public: GetComponentExtensionResourceManager() override; void BroadcastEventToRenderers(events::HistogramValue histogram_value, const std::string &event_name, - std::unique_ptr args, + base::Value::List args, bool dispatch_to_off_the_record_profiles) override; ExtensionCache *GetExtensionCache() override; bool IsBackgroundUpdateAllowed() override; diff --git a/src/core/extensions/pdf_iframe_navigation_throttle_qt.cpp b/src/core/extensions/pdf_iframe_navigation_throttle_qt.cpp index a55294981..f09954bd8 100644 --- a/src/core/extensions/pdf_iframe_navigation_throttle_qt.cpp +++ b/src/core/extensions/pdf_iframe_navigation_throttle_qt.cpp @@ -18,7 +18,7 @@ #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_user_data.h" #include "content/public/common/webplugininfo.h" -#include "net/base/escape.h" +#include "base/strings/escape.h" #include "net/http/http_response_headers.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" @@ -167,7 +167,7 @@ void PDFIFrameNavigationThrottleQt::LoadPlaceholderHTML() { // Prepare the params to navigate to the placeholder. std::string html = GetPDFPlaceholderHTML(navigation_handle()->GetURL()); - GURL data_url("data:text/html," + net::EscapePath(html)); + GURL data_url("data:text/html," + base::EscapePath(html)); content::OpenURLParams params = content::OpenURLParams::FromNavigationHandle(navigation_handle()); params.url = data_url; params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; diff --git a/src/core/file_system_access/file_system_access_permission_context_qt.cpp b/src/core/file_system_access/file_system_access_permission_context_qt.cpp index 3a9c80288..7377cea75 100644 --- a/src/core/file_system_access/file_system_access_permission_context_qt.cpp +++ b/src/core/file_system_access/file_system_access_permission_context_qt.cpp @@ -214,7 +214,7 @@ FileSystemAccessPermissionContextQt::GetReadPermissionGrant(const url::Origin &o // |path| changed from being a directory to being a file or vice versa, // don't just re-use the existing grant but revoke the old grant before // creating a new grant. - existing_grant->SetStatus(PermissionStatus::DENIED); + existing_grant->SetStatus(blink::mojom::PermissionStatus::DENIED); existing_grant = nullptr; } @@ -243,7 +243,7 @@ FileSystemAccessPermissionContextQt::GetWritePermissionGrant(const url::Origin & // |path| changed from being a directory to being a file or vice versa, // don't just re-use the existing grant but revoke the old grant before // creating a new grant. - existing_grant->SetStatus(PermissionStatus::DENIED); + existing_grant->SetStatus(blink::mojom::PermissionStatus::DENIED); existing_grant = nullptr; } @@ -371,9 +371,9 @@ void FileSystemAccessPermissionContextQt::NavigatedAwayFromOrigin(const url::Ori OriginState &origin_state = it->second; for (auto &grant : origin_state.read_grants) - grant.second->SetStatus(PermissionStatus::ASK); + grant.second->SetStatus(blink::mojom::PermissionStatus::ASK); for (auto &grant : origin_state.write_grants) - grant.second->SetStatus(PermissionStatus::ASK); + grant.second->SetStatus(blink::mojom::PermissionStatus::ASK); } void FileSystemAccessPermissionContextQt::DidConfirmSensitiveDirectoryAccess( @@ -392,4 +392,9 @@ void FileSystemAccessPermissionContextQt::DidConfirmSensitiveDirectoryAccess( std::move(callback).Run(SensitiveDirectoryResult::kAllowed); } +std::u16string FileSystemAccessPermissionContextQt::GetPickerTitle(const blink::mojom::FilePickerOptionsPtr &) +{ + return {}; +} + } // namespace QtWebEngineCore diff --git a/src/core/file_system_access/file_system_access_permission_context_qt.h b/src/core/file_system_access/file_system_access_permission_context_qt.h index 722e44d14..d2894cc5f 100644 --- a/src/core/file_system_access/file_system_access_permission_context_qt.h +++ b/src/core/file_system_access/file_system_access_permission_context_qt.h @@ -50,6 +50,7 @@ public: FileSystemAccessPermissionContextQt::PathInfo GetLastPickedDirectory(const url::Origin &origin, const std::string &id) override; base::FilePath GetWellKnownDirectoryPath(blink::mojom::WellKnownDirectory directory) override; + std::u16string GetPickerTitle(const blink::mojom::FilePickerOptionsPtr &) override; void NavigatedAwayFromOrigin(const url::Origin &origin); content::BrowserContext *profile() const { return m_profile; } diff --git a/src/core/file_system_access/file_system_access_permission_grant_qt.cpp b/src/core/file_system_access/file_system_access_permission_grant_qt.cpp index 27f225755..8999bf850 100644 --- a/src/core/file_system_access/file_system_access_permission_grant_qt.cpp +++ b/src/core/file_system_access/file_system_access_permission_grant_qt.cpp @@ -30,9 +30,9 @@ void FileSystemAccessPermissionGrantQt::RequestPermission( // Check if a permission request has already been processed previously. This // check is done first because we don't want to reset the status of a // permission if it has already been granted. - if (GetStatus() != PermissionStatus::ASK || !m_context) { - if (GetStatus() == PermissionStatus::GRANTED) - SetStatus(PermissionStatus::GRANTED); + if (GetStatus() != blink::mojom::PermissionStatus::ASK || !m_context) { + if (GetStatus() == blink::mojom::PermissionStatus::GRANTED) + SetStatus(blink::mojom::PermissionStatus::GRANTED); std::move(callback).Run(PermissionRequestOutcome::kRequestAborted); return; } @@ -107,7 +107,7 @@ void FileSystemAccessPermissionGrantQt::RequestPermission( std::move(fullscreen_block)); } -void FileSystemAccessPermissionGrantQt::SetStatus(PermissionStatus status) +void FileSystemAccessPermissionGrantQt::SetStatus(blink::mojom::PermissionStatus status) { bool should_notify = m_status != status; m_status = status; @@ -116,24 +116,24 @@ void FileSystemAccessPermissionGrantQt::SetStatus(PermissionStatus status) } void FileSystemAccessPermissionGrantQt::OnPermissionRequestResult( - base::OnceCallback callback, PermissionAction result) + base::OnceCallback callback, permissions::PermissionAction result) { switch (result) { - case PermissionAction::GRANTED: - SetStatus(PermissionStatus::GRANTED); + case permissions::PermissionAction::GRANTED: + SetStatus(blink::mojom::PermissionStatus::GRANTED); std::move(callback).Run(PermissionRequestOutcome::kUserGranted); break; - case PermissionAction::DENIED: - SetStatus(PermissionStatus::DENIED); + case permissions::PermissionAction::DENIED: + SetStatus(blink::mojom::PermissionStatus::DENIED); std::move(callback).Run(PermissionRequestOutcome::kUserDenied); break; - case PermissionAction::DISMISSED: - case PermissionAction::IGNORED: + case permissions::PermissionAction::DISMISSED: + case permissions::PermissionAction::IGNORED: std::move(callback).Run(PermissionRequestOutcome::kUserDismissed); break; - case PermissionAction::REVOKED: - case PermissionAction::GRANTED_ONCE: - case PermissionAction::NUM: + case permissions::PermissionAction::REVOKED: + case permissions::PermissionAction::GRANTED_ONCE: + case permissions::PermissionAction::NUM: NOTREACHED(); break; } diff --git a/src/core/file_system_access/file_system_access_permission_grant_qt.h b/src/core/file_system_access/file_system_access_permission_grant_qt.h index a54b2a3d3..1984b8f2c 100644 --- a/src/core/file_system_access/file_system_access_permission_grant_qt.h +++ b/src/core/file_system_access/file_system_access_permission_grant_qt.h @@ -14,8 +14,6 @@ namespace QtWebEngineCore { using HandleType = content::FileSystemAccessPermissionContext::HandleType; using GrantType = FileSystemAccessPermissionContextQt::GrantType; -using blink::mojom::PermissionStatus; -using permissions::PermissionAction; class FileSystemAccessPermissionGrantQt : public content::FileSystemAccessPermissionGrant { @@ -25,7 +23,7 @@ public: HandleType handle_type, GrantType type); // content::FileSystemAccessPermissionGrant: - PermissionStatus GetStatus() override { return m_status; } + blink::mojom::PermissionStatus GetStatus() override { return m_status; } base::FilePath GetPath() override { return m_path; } void RequestPermission(content::GlobalRenderFrameHostId frame_id, UserActivationState user_activation_state, @@ -36,11 +34,11 @@ public: const base::FilePath &path() const { return m_path; } GrantType type() const { return m_type; } - void SetStatus(PermissionStatus status); + void SetStatus(blink::mojom::PermissionStatus status); private: void OnPermissionRequestResult(base::OnceCallback callback, - PermissionAction result); + permissions::PermissionAction result); base::WeakPtr const m_context; const url::Origin m_origin; @@ -50,7 +48,7 @@ private: // This member should only be updated via SetStatus(), to make sure // observers are properly notified about any change in status. - PermissionStatus m_status = PermissionStatus::ASK; + blink::mojom::PermissionStatus m_status = blink::mojom::PermissionStatus::ASK; }; } // namespace QtWebEngineCore diff --git a/src/core/login_delegate_qt.cpp b/src/core/login_delegate_qt.cpp index 845872012..140335735 100644 --- a/src/core/login_delegate_qt.cpp +++ b/src/core/login_delegate_qt.cpp @@ -7,7 +7,6 @@ #include "login_delegate_qt.h" -#include "base/task/post_task.h" #include "content/browser/web_contents/web_contents_impl.h" #include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_thread.h" @@ -45,8 +44,7 @@ LoginDelegateQt::LoginDelegateQt(const net::AuthChallengeInfo &authInfo, , m_auth_required_callback(std::move(auth_required_callback)) , m_weakFactory(this) { - base::PostTask( - FROM_HERE, { content::BrowserThread::UI }, + content::GetUIThreadTaskRunner({})->PostTask(FROM_HERE, base::BindOnce(&LoginDelegateQt::triggerDialog, m_weakFactory.GetWeakPtr())); } diff --git a/src/core/media_capture_devices_dispatcher.cpp b/src/core/media_capture_devices_dispatcher.cpp index cddb5a290..a2840b37a 100644 --- a/src/core/media_capture_devices_dispatcher.cpp +++ b/src/core/media_capture_devices_dispatcher.cpp @@ -12,7 +12,7 @@ #include "web_contents_view_qt.h" #include "web_engine_settings.h" -#include "base/task/post_task.h" +#include "base/strings/strcat.h" #include "content/browser/web_contents/web_contents_impl.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/desktop_media_id.h" @@ -22,6 +22,8 @@ #include "media/audio/audio_device_description.h" #include "media/audio/audio_manager_base.h" #include "services/network/public/cpp/is_potentially_trustworthy.h" +#include "third_party/blink/public/mojom/mediastream/media_stream.mojom-shared.h" +#include "third_party/blink/public/mojom/mediastream/media_stream.mojom.h" #if QT_CONFIG(webengine_webrtc) #include "third_party/webrtc/modules/desktop_capture/desktop_capture_options.h" @@ -54,26 +56,166 @@ const blink::MediaStreamDevice *findDeviceWithId(const blink::MediaStreamDevices } // Based on chrome/browser/media/webrtc/desktop_capture_devices_util.cc: -void getDevicesForDesktopCapture(blink::MediaStreamDevices *devices, +media::mojom::CaptureHandlePtr CreateCaptureHandle(content::WebContents *capturer, + const url::Origin &capturer_origin, + const content::DesktopMediaID &captured_id) +{ + if (capturer_origin.opaque()) + return nullptr; + + content::RenderFrameHost *const captured_rfh = + content::RenderFrameHost::FromID( + captured_id.web_contents_id.render_process_id, + captured_id.web_contents_id.main_render_frame_id); + if (!captured_rfh || !captured_rfh->IsActive()) + return nullptr; + + content::WebContents *const captured = content::WebContents::FromRenderFrameHost(captured_rfh); + if (!captured) + return nullptr; + + const auto &captured_config = captured->GetCaptureHandleConfig(); + if (!captured_config.all_origins_permitted && + std::none_of(captured_config.permitted_origins.begin(), + captured_config.permitted_origins.end(), + [capturer_origin](const url::Origin& permitted_origin) { + return capturer_origin.IsSameOriginWith(permitted_origin); + })) + { + return nullptr; + } + + // Observing CaptureHandle when either the capturing or the captured party + // is incognito is disallowed, except for self-capture. + if (capturer->GetPrimaryMainFrame() != captured->GetPrimaryMainFrame()) { + if (capturer->GetBrowserContext()->IsOffTheRecord() || + captured->GetBrowserContext()->IsOffTheRecord()) { + return nullptr; + } + } + + if (!captured_config.expose_origin && captured_config.capture_handle.empty()) + return nullptr; + + auto result = media::mojom::CaptureHandle::New(); + if (captured_config.expose_origin) + result->origin = captured->GetPrimaryMainFrame()->GetLastCommittedOrigin(); + + result->capture_handle = captured_config.capture_handle; + + return result; +} + +// Based on chrome/browser/media/webrtc/desktop_capture_devices_util.cc: +media::mojom::DisplayMediaInformationPtr DesktopMediaIDToDisplayMediaInformation(content::WebContents *capturer, + const url::Origin &capturer_origin, + const content::DesktopMediaID &media_id) +{ + media::mojom::DisplayCaptureSurfaceType display_surface = media::mojom::DisplayCaptureSurfaceType::MONITOR; + bool logical_surface = true; + media::mojom::CursorCaptureType cursor = media::mojom::CursorCaptureType::NEVER; +#if defined(USE_AURA) + const bool uses_aura = (media_id.window_id != content::DesktopMediaID::kNullId ? true : false); +#else + const bool uses_aura = false; +#endif // defined(USE_AURA) + + media::mojom::CaptureHandlePtr capture_handle; + switch (media_id.type) { + case content::DesktopMediaID::TYPE_SCREEN: + display_surface = media::mojom::DisplayCaptureSurfaceType::MONITOR; + cursor = uses_aura ? media::mojom::CursorCaptureType::MOTION + : media::mojom::CursorCaptureType::ALWAYS; + break; + case content::DesktopMediaID::TYPE_WINDOW: + display_surface = media::mojom::DisplayCaptureSurfaceType::WINDOW; + cursor = uses_aura ? media::mojom::CursorCaptureType::MOTION + : media::mojom::CursorCaptureType::ALWAYS; + break; + case content::DesktopMediaID::TYPE_WEB_CONTENTS: + display_surface = media::mojom::DisplayCaptureSurfaceType::BROWSER; + cursor = media::mojom::CursorCaptureType::MOTION; + capture_handle = CreateCaptureHandle(capturer, capturer_origin, media_id); + break; + case content::DesktopMediaID::TYPE_NONE: + break; + } + + return media::mojom::DisplayMediaInformation::New(display_surface, logical_surface, cursor, std::move(capture_handle)); +} + + +// Based on chrome/browser/media/webrtc/desktop_capture_devices_util.cc: +std::string DeviceNamePrefix(content::WebContents *web_contents, + blink::mojom::MediaStreamType requested_stream_type, + const content::DesktopMediaID &media_id) +{ + if (!web_contents || requested_stream_type != blink::mojom::MediaStreamType::DISPLAY_VIDEO_CAPTURE_THIS_TAB) { + return std::string(); + } + + // Note that all of these must still be checked, as the explicit-selection + // dialog for DISPLAY_VIDEO_CAPTURE_THIS_TAB could still return something + // other than the current tab - be it a screen, window, or another tab. + if (media_id.type == content::DesktopMediaID::TYPE_WEB_CONTENTS && + web_contents->GetPrimaryMainFrame()->GetProcess()->GetID() == + media_id.web_contents_id.render_process_id && + web_contents->GetPrimaryMainFrame()->GetRoutingID() == + media_id.web_contents_id.main_render_frame_id) { + return "current-"; + } + + return std::string(); +} + +// Based on chrome/browser/media/webrtc/desktop_capture_devices_util.cc: +std::string DeviceName(content::WebContents *web_contents, + blink::mojom::MediaStreamType requested_stream_type, + const content::DesktopMediaID &media_id) +{ + const std::string prefix = + DeviceNamePrefix(web_contents, requested_stream_type, media_id); + if (media_id.type == content::DesktopMediaID::TYPE_WEB_CONTENTS) { + return base::StrCat({prefix, content::kWebContentsCaptureScheme, + base::UnguessableToken::Create().ToString()}); + } else { + // TODO(crbug.com/1252682): MediaStreamTrack.label leaks internal state for + // screen/window + return base::StrCat({prefix, media_id.ToString()}); + } +} + +// Based on chrome/browser/media/webrtc/desktop_capture_devices_util.cc: +void getDevicesForDesktopCapture(const content::MediaStreamRequest &request, + content::WebContents *web_contents, content::DesktopMediaID mediaId, bool captureAudio, - MediaStreamType videoType, - MediaStreamType audioType) + bool disableLocalEcho, + blink::mojom::StreamDevices &out_devices) { DCHECK_CURRENTLY_ON(BrowserThread::UI); // Add selected desktop source to the list. - devices->push_back(blink::MediaStreamDevice(videoType, mediaId.ToString(), mediaId.ToString())); + blink::MediaStreamDevice device(request.video_type, mediaId.ToString(), + DeviceName(web_contents, request.video_type, mediaId)); + device.display_media_info = DesktopMediaIDToDisplayMediaInformation( + web_contents, url::Origin::Create(request.security_origin), mediaId); + out_devices.video_device = device; + if (captureAudio) { + DCHECK_NE(request.audio_type, blink::mojom::MediaStreamType::NO_SERVICE); + if (mediaId.type == content::DesktopMediaID::TYPE_WEB_CONTENTS) { - devices->push_back( - blink::MediaStreamDevice(audioType, mediaId.ToString(), "Tab audio")); + content::WebContentsMediaCaptureId web_id = mediaId.web_contents_id; + web_id.disable_local_echo = disableLocalEcho; + out_devices.audio_device = blink::MediaStreamDevice(request.audio_type, web_id.ToString(), "Tab audio"); } else { // Use the special loopback device ID for system audio capture. - devices->push_back(blink::MediaStreamDevice( - audioType, - media::AudioDeviceDescription::kLoopbackInputDeviceId, - "System Audio")); + out_devices.audio_device = blink::MediaStreamDevice( + request.audio_type, (disableLocalEcho + ? media::AudioDeviceDescription::kLoopbackWithMuteDeviceId + : media::AudioDeviceDescription::kLoopbackInputDeviceId), + "System Audio"); } } } @@ -201,11 +343,12 @@ WebContentsAdapterClient::MediaRequestFlags mediaRequestFlagsForRequest(const co class MediaStreamUIQt : public content::MediaStreamUI { public: - MediaStreamUIQt(content::WebContents *webContents, const blink::MediaStreamDevices &devices) + MediaStreamUIQt(content::WebContents *webContents, const blink::mojom::StreamDevices &devices) : m_delegate(static_cast(webContents->GetDelegate())->AsWeakPtr()) , m_devices(devices) { - DCHECK(!m_devices.empty()); + DCHECK(m_devices.audio_device.has_value() || + m_devices.video_device.has_value()); } ~MediaStreamUIQt() override @@ -238,9 +381,10 @@ private: Q_UNUSED(label); Q_UNUSED(media_id); } - + void OnDeviceStoppedForSourceChange(const std::string&, const content::DesktopMediaID&, const content::DesktopMediaID&) override + {} base::WeakPtr m_delegate; - const blink::MediaStreamDevices m_devices; + const blink::mojom::StreamDevices m_devices; bool m_started = false; base::RepeatingClosure m_onStop; // currently unused }; @@ -262,7 +406,7 @@ void MediaCaptureDevicesDispatcher::handleMediaAccessPermissionResponse(content: { DCHECK_CURRENTLY_ON(BrowserThread::UI); - blink::MediaStreamDevices devices; + blink::mojom::StreamDevicesSet deviceSet; auto it = m_pendingRequests.find(webContents); if (it == m_pendingRequests.end() || it->second.empty()) return; @@ -289,20 +433,22 @@ void MediaCaptureDevicesDispatcher::handleMediaAccessPermissionResponse(content: if (microphoneRequested || webcamRequested) { switch (request.request_type) { case blink::MEDIA_OPEN_DEVICE_PEPPER_ONLY: - getDefaultDevices("", "", microphoneRequested, webcamRequested, &devices); + getDefaultDevices("", "", microphoneRequested, webcamRequested, deviceSet); break; case blink::MEDIA_DEVICE_ACCESS: case blink::MEDIA_DEVICE_UPDATE: case blink::MEDIA_GENERATE_STREAM: case blink::MEDIA_GET_OPEN_DEVICE: getDefaultDevices(request.requested_audio_device_id, request.requested_video_device_id, - microphoneRequested, webcamRequested, &devices); + microphoneRequested, webcamRequested, deviceSet); break; } } else if (desktopVideoRequested) { + deviceSet.stream_devices.emplace_back(blink::mojom::StreamDevices::New()); bool captureAudio = desktopAudioRequested && m_loopbackAudioSupported; - getDevicesForDesktopCapture(&devices, getDefaultScreenId(), captureAudio, - request.video_type, request.audio_type); + blink::mojom::StreamDevices &stream_devices = *deviceSet.stream_devices[0]; + getDevicesForDesktopCapture(request, webContents, getDefaultScreenId(), captureAudio, + request.disable_local_echo, stream_devices); } } @@ -313,17 +459,17 @@ void MediaCaptureDevicesDispatcher::handleMediaAccessPermissionResponse(content: // Post a task to process next queued request. It has to be done // asynchronously to make sure that calling infobar is not destroyed until // after this function returns. - base::PostTask(FROM_HERE, {BrowserThread::UI}, + content::GetUIThreadTaskRunner({})->PostTask(FROM_HERE, base::BindOnce(&MediaCaptureDevicesDispatcher::ProcessQueuedAccessRequest, base::Unretained(this), webContents)); } - if (devices.empty()) - std::move(callback).Run(devices, MediaStreamRequestResult::INVALID_STATE, + if (deviceSet.stream_devices.empty()) + std::move(callback).Run(deviceSet, MediaStreamRequestResult::INVALID_STATE, std::unique_ptr()); else - std::move(callback).Run(devices, MediaStreamRequestResult::OK, - std::make_unique(webContents, devices)); + std::move(callback).Run(deviceSet, MediaStreamRequestResult::OK, + std::make_unique(webContents, *deviceSet.stream_devices[0])); } MediaCaptureDevicesDispatcher *MediaCaptureDevicesDispatcher::GetInstance() @@ -358,7 +504,7 @@ void MediaCaptureDevicesDispatcher::processMediaAccessRequest(content::WebConten WebContentsAdapterClient::MediaRequestFlags flags = mediaRequestFlagsForRequest(request); if (!flags) { - std::move(callback).Run(blink::MediaStreamDevices(), MediaStreamRequestResult::NOT_SUPPORTED, std::unique_ptr()); + std::move(callback).Run(blink::mojom::StreamDevicesSet(), MediaStreamRequestResult::NOT_SUPPORTED, std::unique_ptr()); return; } @@ -370,7 +516,7 @@ void MediaCaptureDevicesDispatcher::processMediaAccessRequest(content::WebConten QWebEngineSettings::ScreenCaptureEnabled); const bool originIsSecure = network::IsUrlPotentiallyTrustworthy(request.security_origin); if (!screenCaptureEnabled || !originIsSecure) { - std::move(callback).Run(blink::MediaStreamDevices(), MediaStreamRequestResult::INVALID_STATE, std::unique_ptr()); + std::move(callback).Run(blink::mojom::StreamDevicesSet(), MediaStreamRequestResult::INVALID_STATE, std::unique_ptr()); return; } @@ -388,7 +534,7 @@ void MediaCaptureDevicesDispatcher::processMediaAccessRequest(content::WebConten void MediaCaptureDevicesDispatcher::processDesktopCaptureAccessRequest(content::WebContents *webContents, const content::MediaStreamRequest &request, content::MediaResponseCallback callback) { - blink::MediaStreamDevices devices; + blink::mojom::StreamDevicesSet deviceSet; content::WebContents *const web_contents_for_stream = content::WebContents::FromRenderFrameHost( content::RenderFrameHost::FromID(request.render_process_id, request.render_frame_id)); @@ -407,7 +553,7 @@ void MediaCaptureDevicesDispatcher::processDesktopCaptureAccessRequest(content:: // Received invalid device id. if (mediaId.type == content::DesktopMediaID::TYPE_NONE) { - std::move(callback).Run(devices, MediaStreamRequestResult::INVALID_STATE, std::unique_ptr()); + std::move(callback).Run(deviceSet, MediaStreamRequestResult::INVALID_STATE, std::unique_ptr()); return; } @@ -417,14 +563,16 @@ void MediaCaptureDevicesDispatcher::processDesktopCaptureAccessRequest(content:: bool audioSupported = (mediaId.type == content::DesktopMediaID::TYPE_SCREEN && m_loopbackAudioSupported); bool captureAudio = (audioRequested && audioSupported); - getDevicesForDesktopCapture(&devices, mediaId, captureAudio, request.video_type, request.audio_type); + deviceSet.stream_devices.emplace_back(blink::mojom::StreamDevices::New()); + blink::mojom::StreamDevices &stream_devices = *deviceSet.stream_devices[0]; + getDevicesForDesktopCapture(request, webContents, mediaId, captureAudio, request.disable_local_echo, stream_devices); - if (devices.empty()) - std::move(callback).Run(devices, MediaStreamRequestResult::INVALID_STATE, + if (deviceSet.stream_devices.empty()) + std::move(callback).Run(deviceSet, MediaStreamRequestResult::INVALID_STATE, std::unique_ptr()); else - std::move(callback).Run(devices, MediaStreamRequestResult::OK, - std::make_unique(webContents, devices)); + std::move(callback).Run(deviceSet, MediaStreamRequestResult::OK, + std::make_unique(webContents, *deviceSet.stream_devices[0])); } void MediaCaptureDevicesDispatcher::enqueueMediaAccessRequest(content::WebContents *webContents, @@ -453,18 +601,20 @@ void MediaCaptureDevicesDispatcher::ProcessQueuedAccessRequest(content::WebConte } void MediaCaptureDevicesDispatcher::getDefaultDevices(const std::string &audioDeviceId, const std::string &videoDeviceId, - bool audio, bool video, blink::MediaStreamDevices *devices) + bool audio, bool video, blink::mojom::StreamDevicesSet &devicesSet) { DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK(audio || video); + devicesSet.stream_devices.emplace_back(blink::mojom::StreamDevices::New()); + blink::mojom::StreamDevices& devices = *devicesSet.stream_devices[0]; if (audio) { const blink::MediaStreamDevices &audioDevices = content::MediaCaptureDevices::GetInstance()->GetAudioCaptureDevices(); const blink::MediaStreamDevice *device = findDeviceWithId(audioDevices, audioDeviceId); if (!device && !audioDevices.empty()) device = &audioDevices.front(); if (device) - devices->push_back(*device); + devices.audio_device = *device; } if (video) { @@ -473,14 +623,14 @@ void MediaCaptureDevicesDispatcher::getDefaultDevices(const std::string &audioDe if (!device && !videoDevices.empty()) device = &videoDevices.front(); if (device) - devices->push_back(*device); + devices.video_device = *device; } } void MediaCaptureDevicesDispatcher::OnMediaRequestStateChanged(int render_process_id, int render_frame_id, int page_request_id, const GURL &security_origin, blink::mojom::MediaStreamType stream_type, content::MediaRequestState state) { DCHECK_CURRENTLY_ON(BrowserThread::IO); - base::PostTask(FROM_HERE, {BrowserThread::UI}, + content::GetUIThreadTaskRunner({})->PostTask(FROM_HERE, base::BindOnce(&MediaCaptureDevicesDispatcher::updateMediaRequestStateOnUIThread, base::Unretained(this), render_process_id, render_frame_id, page_request_id, security_origin, stream_type, state)); diff --git a/src/core/media_capture_devices_dispatcher.h b/src/core/media_capture_devices_dispatcher.h index cdb84ee24..37f41901b 100644 --- a/src/core/media_capture_devices_dispatcher.h +++ b/src/core/media_capture_devices_dispatcher.h @@ -30,7 +30,7 @@ public: void handleMediaAccessPermissionResponse(content::WebContents *, const QUrl &securityOrigin, WebContentsAdapterClient::MediaRequestFlags); private: - void getDefaultDevices(const std::string &audioDeviceId, const std::string &videoDeviceId, bool audio, bool video, blink::MediaStreamDevices *); + void getDefaultDevices(const std::string &audioDeviceId, const std::string &videoDeviceId, bool audio, bool video, blink::mojom::StreamDevicesSet &devices); // Overridden from content::MediaObserver: void OnAudioCaptureDevicesChanged() override {} diff --git a/src/core/net/client_cert_qt.cpp b/src/core/net/client_cert_qt.cpp index 1e7aa8b6a..d5ea1a776 100644 --- a/src/core/net/client_cert_qt.cpp +++ b/src/core/net/client_cert_qt.cpp @@ -4,7 +4,6 @@ #include "client_cert_qt.h" #include "base/bind.h" -#include "base/task/post_task.h" #include "base/callback_forward.h" #include "content/public/browser/browser_task_traits.h" #include "crypto/crypto_buildflags.h" @@ -118,8 +117,8 @@ void ClientCertStoreQt::GetClientCerts(const net::SSLCertRequestInfo &cert_reque { #if QT_CONFIG(ssl) // Access the user-provided data from the UI thread, but return on whatever thread this is. - bool ok = base::PostTaskAndReplyWithResult( - FROM_HERE, { content::BrowserThread::UI }, + bool ok = content::GetUIThreadTaskRunner({})->PostTaskAndReplyWithResult( + FROM_HERE, base::BindOnce(&ClientCertStoreQt::GetClientCertsOnUIThread, base::Unretained(this), std::cref(cert_request_info)), base::BindOnce(&ClientCertStoreQt::GetClientCertsReturn, diff --git a/src/core/net/custom_url_loader_factory.cpp b/src/core/net/custom_url_loader_factory.cpp index bd7d7dc58..e35f1afb5 100644 --- a/src/core/net/custom_url_loader_factory.cpp +++ b/src/core/net/custom_url_loader_factory.cpp @@ -4,7 +4,6 @@ #include "custom_url_loader_factory.h" #include "base/strings/stringprintf.h" -#include "base/task/post_task.h" #include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_thread.h" #include "mojo/public/cpp/bindings/pending_receiver.h" @@ -64,7 +63,7 @@ public: scoped_refptr proxy = new URLRequestCustomJobProxy(this, m_proxy->m_scheme, m_proxy->m_profileAdapter); m_proxy->m_client = nullptr; // m_taskRunner->PostTask(FROM_HERE, base::BindOnce(&URLRequestCustomJobProxy::release, m_proxy)); - base::PostTask(FROM_HERE, { content::BrowserThread::UI }, + content::GetUIThreadTaskRunner({})->PostTask(FROM_HERE, base::BindOnce(&URLRequestCustomJobProxy::release, m_proxy)); m_proxy = std::move(proxy); if (new_url) @@ -87,7 +86,7 @@ private: mojo::PendingRemote client_remote, QPointer profileAdapter) // ### We can opt to run the url-loader on the UI thread instead - : m_taskRunner(base::CreateSingleThreadTaskRunner({ content::BrowserThread::IO })) + : m_taskRunner(content::GetIOThreadTaskRunner({})) , m_proxy(new URLRequestCustomJobProxy(this, request.url.scheme(), profileAdapter)) , m_receiver(this, std::move(loader)) , m_client(std::move(client_remote)) @@ -151,7 +150,7 @@ private: m_firstBytePosition = m_byteRange.first_byte_position(); // m_taskRunner->PostTask(FROM_HERE, - base::PostTask(FROM_HERE, { content::BrowserThread::UI }, + content::GetUIThreadTaskRunner({})->PostTask(FROM_HERE, base::BindOnce(&URLRequestCustomJobProxy::initialize, m_proxy, m_request.url, m_request.method, m_request.request_initiator, std::move(headers))); } @@ -204,7 +203,7 @@ private: m_device->close(); m_device = nullptr; // m_taskRunner->PostTask(FROM_HERE, base::BindOnce(&URLRequestCustomJobProxy::release, m_proxy)); - base::PostTask(FROM_HERE, { content::BrowserThread::UI }, + content::GetUIThreadTaskRunner({})->PostTask(FROM_HERE, base::BindOnce(&URLRequestCustomJobProxy::release, m_proxy)); if (!wait_for_loader_error || !m_receiver.is_bound()) delete this; @@ -286,8 +285,7 @@ private: m_head->mime_type = m_mimeType; m_head->charset = m_charset; m_headerBytesRead = m_head->headers->raw_headers().length(); - m_client->OnReceiveResponse(std::move(m_head), mojo::ScopedDataPipeConsumerHandle()); - m_client->OnStartLoadingResponseBody(std::move(m_pipeConsumerHandle)); + m_client->OnReceiveResponse(std::move(m_head), std::move(m_pipeConsumerHandle)); m_head = nullptr; m_watcher = std::make_unique( @@ -447,7 +445,7 @@ private: class CustomURLLoaderFactory : public network::mojom::URLLoaderFactory { public: CustomURLLoaderFactory(ProfileAdapter *profileAdapter, mojo::PendingReceiver receiver) - : m_taskRunner(base::CreateSequencedTaskRunner({ content::BrowserThread::IO })) + : m_taskRunner(content::GetIOThreadTaskRunner({})) , m_profileAdapter(profileAdapter) { m_receivers.set_disconnect_handler(base::BindRepeating( diff --git a/src/core/net/plugin_response_interceptor_url_loader_throttle.cpp b/src/core/net/plugin_response_interceptor_url_loader_throttle.cpp index 1bcb3ddea..f61fb704a 100644 --- a/src/core/net/plugin_response_interceptor_url_loader_throttle.cpp +++ b/src/core/net/plugin_response_interceptor_url_loader_throttle.cpp @@ -10,7 +10,6 @@ #include "base/bind.h" #include "base/guid.h" -#include "base/task/post_task.h" #include "chrome/browser/extensions/api/streams_private/streams_private_api.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/browser_thread.h" @@ -151,16 +150,13 @@ void PluginResponseInterceptorURLLoaderThrottle::WillProcessResponse(const GURL producer_handle->WriteData( payload.c_str(), &len, MOJO_WRITE_DATA_FLAG_ALL_OR_NONE)); - - new_client->OnStartLoadingResponseBody(std::move(consumer_handle)); - network::URLLoaderCompletionStatus status(net::OK); status.decoded_body_length = len; new_client->OnComplete(status); mojo::PendingRemote original_loader; mojo::PendingReceiver original_client; - mojo::ScopedDataPipeConsumerHandle body; + mojo::ScopedDataPipeConsumerHandle body = std::move(consumer_handle); delegate_->InterceptResponse(std::move(dummy_new_loader), std::move(new_client_receiver), &original_loader, &original_client, diff --git a/src/core/net/proxy_config_monitor.cpp b/src/core/net/proxy_config_monitor.cpp index d4543947a..96a33f1e3 100644 --- a/src/core/net/proxy_config_monitor.cpp +++ b/src/core/net/proxy_config_monitor.cpp @@ -11,7 +11,6 @@ #include "proxy_config_service_qt.h" #include "base/strings/utf_string_conversions.h" -#include "base/task/post_task.h" #include "build/build_config.h" #include "components/proxy_config/pref_proxy_config_tracker_impl.h" #include "content/public/browser/browser_task_traits.h" @@ -28,9 +27,7 @@ ProxyConfigMonitor::ProxyConfigMonitor(PrefService *prefs) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - proxy_config_service_.reset( - new ProxyConfigServiceQt( - prefs, base::CreateSingleThreadTaskRunner({ BrowserThread::UI }))); + proxy_config_service_.reset(new ProxyConfigServiceQt(prefs, content::GetUIThreadTaskRunner({}))); proxy_config_service_->AddObserver(this); } diff --git a/src/core/net/proxying_restricted_cookie_manager_qt.cpp b/src/core/net/proxying_restricted_cookie_manager_qt.cpp index ab435f8e2..88ce07687 100644 --- a/src/core/net/proxying_restricted_cookie_manager_qt.cpp +++ b/src/core/net/proxying_restricted_cookie_manager_qt.cpp @@ -15,7 +15,6 @@ #include "type_conversion.h" #include "base/memory/ptr_util.h" -#include "base/task/post_task.h" #include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_thread.h" #include "mojo/public/cpp/bindings/self_owned_receiver.h" @@ -29,7 +28,7 @@ void ProxyingRestrictedCookieManagerQt::CreateAndBind(ProfileIODataQt *profileIo { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - base::PostTask(FROM_HERE, {content::BrowserThread::IO}, + content::GetIOThreadTaskRunner({})->PostTask(FROM_HERE, base::BindOnce(&ProxyingRestrictedCookieManagerQt::CreateAndBindOnIoThread, profileIoData, std::move(underlying_rcm), @@ -150,6 +149,11 @@ void ProxyingRestrictedCookieManagerQt::CookiesEnabledFor(const GURL &url, std::move(callback).Run(allowCookies(url, site_for_cookies)); } +void ProxyingRestrictedCookieManagerQt::ConvertPartitionedCookiesToUnpartitioned(const GURL&) +{ + NOTIMPLEMENTED(); +} + bool ProxyingRestrictedCookieManagerQt::allowCookies(const GURL &url, const net::SiteForCookies &site_for_cookies) const { if (!m_profileIoData) diff --git a/src/core/net/proxying_restricted_cookie_manager_qt.h b/src/core/net/proxying_restricted_cookie_manager_qt.h index 7ac6807ac..95e193f76 100644 --- a/src/core/net/proxying_restricted_cookie_manager_qt.h +++ b/src/core/net/proxying_restricted_cookie_manager_qt.h @@ -56,6 +56,7 @@ public: const net::SiteForCookies &site_for_cookies, const url::Origin &top_frame_origin, CookiesEnabledForCallback callback) override; + void ConvertPartitionedCookiesToUnpartitioned(const GURL&) override; // Internal: bool allowCookies(const GURL &url, const net::SiteForCookies &site_for_cookies) const; diff --git a/src/core/net/proxying_url_loader_factory_qt.cpp b/src/core/net/proxying_url_loader_factory_qt.cpp index 0b82ceb41..49c76b84d 100644 --- a/src/core/net/proxying_url_loader_factory_qt.cpp +++ b/src/core/net/proxying_url_loader_factory_qt.cpp @@ -103,7 +103,6 @@ public: void OnUploadProgress(int64_t current_position, int64_t total_size, OnUploadProgressCallback callback) override; void OnReceiveCachedMetadata(mojo_base::BigBuffer data) override; void OnTransferSizeUpdated(int32_t transfer_size_diff) override; - void OnStartLoadingResponseBody(mojo::ScopedDataPipeConsumerHandle body) override; void OnComplete(const network::URLLoaderCompletionStatus &status) override; void OnReceiveEarlyHints(network::mojom::EarlyHintsPtr) override {} @@ -352,7 +351,7 @@ void InterceptedRequest::ContinueAfterIntercept() for (auto header = info.extraHeaders.constBegin(); header != info.extraHeaders.constEnd(); ++header) { std::string h = header.key().toStdString(); - if (base::LowerCaseEqualsASCII(h, "referer")) { + if (base::EqualsCaseInsensitiveASCII(h, "referer")) { request_.referrer = GURL(header.value().toStdString()); } else { request_.headers.SetHeader(h, header.value().toStdString()); @@ -428,11 +427,6 @@ void InterceptedRequest::OnTransferSizeUpdated(int32_t transfer_size_diff) target_client_->OnTransferSizeUpdated(transfer_size_diff); } -void InterceptedRequest::OnStartLoadingResponseBody(mojo::ScopedDataPipeConsumerHandle body) -{ - target_client_->OnStartLoadingResponseBody(std::move(body)); -} - void InterceptedRequest::OnComplete(const network::URLLoaderCompletionStatus &status) { // Only wait for the original loader to possibly have a custom error if the diff --git a/src/core/net/url_request_custom_job_delegate.cpp b/src/core/net/url_request_custom_job_delegate.cpp index d05b7d5a0..22d26f735 100644 --- a/src/core/net/url_request_custom_job_delegate.cpp +++ b/src/core/net/url_request_custom_job_delegate.cpp @@ -4,7 +4,6 @@ #include "url_request_custom_job_delegate.h" #include "url_request_custom_job_proxy.h" -#include "base/task/post_task.h" #include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_thread.h" #include "net/base/net_errors.h" diff --git a/src/core/ozone/gl_ozone_egl_qt.cpp b/src/core/ozone/gl_ozone_egl_qt.cpp index 02c3666b4..efb1dd962 100644 --- a/src/core/ozone/gl_ozone_egl_qt.cpp +++ b/src/core/ozone/gl_ozone_egl_qt.cpp @@ -48,16 +48,12 @@ bool GLOzoneEGLQt::LoadGLES2Bindings(const gl::GLImplementationParts & /*impleme return true; } -bool GLOzoneEGLQt::InitializeGLOneOffPlatform() +gl::GLDisplay *GLOzoneEGLQt::InitializeGLOneOffPlatform(uint64_t system_device_id) { - if (!gl::GLSurfaceEGLQt::InitializeOneOff()) { - LOG(ERROR) << "GLOzoneEGLQt::InitializeOneOff failed."; - return false; - } - return true; + return gl::GLSurfaceEGLQt::InitializeOneOff(system_device_id); } -bool GLOzoneEGLQt::InitializeExtensionSettingsOneOffPlatform() +bool GLOzoneEGLQt::InitializeExtensionSettingsOneOffPlatform(gl::GLDisplay *display) { return gl::GLSurfaceEGLQt::InitializeExtensionSettingsOneOff(); } diff --git a/src/core/ozone/gl_ozone_egl_qt.h b/src/core/ozone/gl_ozone_egl_qt.h index 089e6ba17..59f25a724 100644 --- a/src/core/ozone/gl_ozone_egl_qt.h +++ b/src/core/ozone/gl_ozone_egl_qt.h @@ -12,8 +12,8 @@ namespace ui { class GLOzoneEGLQt : public GLOzoneEGL { public: - bool InitializeGLOneOffPlatform() override; - bool InitializeExtensionSettingsOneOffPlatform() override; + gl::GLDisplay *InitializeGLOneOffPlatform(uint64_t system_device_id) override; + bool InitializeExtensionSettingsOneOffPlatform(gl::GLDisplay *display) override; scoped_refptr CreateViewGLSurface( gfx::AcceleratedWidget window) override; scoped_refptr CreateOffscreenGLSurface( diff --git a/src/core/ozone/gl_ozone_glx_qt.cpp b/src/core/ozone/gl_ozone_glx_qt.cpp index 4c4822944..fa42facac 100644 --- a/src/core/ozone/gl_ozone_glx_qt.cpp +++ b/src/core/ozone/gl_ozone_glx_qt.cpp @@ -16,12 +16,8 @@ namespace ui { -bool GLOzoneGLXQt::InitializeGLOneOffPlatform() { - if (!gl::GLSurfaceGLXQt::InitializeOneOff()) { - LOG(ERROR) << "GLSurfaceGLXQt::InitializeOneOff failed."; - return false; - } - return true; +gl::GLDisplay *GLOzoneGLXQt::InitializeGLOneOffPlatform(uint64_t system_device_id) { + return gl::GLSurfaceGLXQt::InitializeOneOff(system_device_id); } bool GLOzoneGLXQt::InitializeStaticGLBindings( @@ -65,7 +61,7 @@ void GLOzoneGLXQt::SetDisabledExtensionsPlatform( gl::SetDisabledExtensionsGLX(disabled_extensions); } -void GLOzoneGLXQt::ShutdownGL() { +void GLOzoneGLXQt::ShutdownGL(gl::GLDisplay *) { gl::ClearBindingsGL(); gl::ClearBindingsGLX(); } @@ -104,7 +100,7 @@ scoped_refptr GLOzoneGLXQt::CreateOffscreenGLSurface( return nullptr; } -bool GLOzoneGLXQt::InitializeExtensionSettingsOneOffPlatform() +bool GLOzoneGLXQt::InitializeExtensionSettingsOneOffPlatform(gl::GLDisplay *) { return gl::GLSurfaceGLXQt::InitializeExtensionSettingsOneOff(); } diff --git a/src/core/ozone/gl_ozone_glx_qt.h b/src/core/ozone/gl_ozone_glx_qt.h index 77d639a88..ca9ff47a3 100644 --- a/src/core/ozone/gl_ozone_glx_qt.h +++ b/src/core/ozone/gl_ozone_glx_qt.h @@ -15,10 +15,10 @@ public: GLOzoneGLXQt() {} ~GLOzoneGLXQt() override {} - bool InitializeGLOneOffPlatform() override; + gl::GLDisplay *InitializeGLOneOffPlatform(uint64_t system_device_id) override; bool InitializeStaticGLBindings(const gl::GLImplementationParts &implementation) override; - bool InitializeExtensionSettingsOneOffPlatform() override; - void ShutdownGL() override; + bool InitializeExtensionSettingsOneOffPlatform(gl::GLDisplay *display) override; + void ShutdownGL(gl::GLDisplay *display) override; void SetDisabledExtensionsPlatform( const std::string& disabled_extensions) override; bool GetGLWindowSystemBindingInfo( diff --git a/src/core/ozone/gl_surface_egl_qt.cpp b/src/core/ozone/gl_surface_egl_qt.cpp index bd9ec060e..163d9242d 100644 --- a/src/core/ozone/gl_surface_egl_qt.cpp +++ b/src/core/ozone/gl_surface_egl_qt.cpp @@ -25,139 +25,144 @@ using ui::GetLastEGLErrorString; namespace gl { -bool GLSurfaceEGL::InitializeExtensionSettingsOneOff() +bool GLSurfaceEGL::InitializeExtensionSettingsOneOff(GLDisplayEGL* display) { return GLSurfaceEGLQt::InitializeExtensionSettingsOneOff(); } -EGLDisplay GLSurfaceEGL::GetHardwareDisplay() +EGLDisplay GLDisplayEGL::GetHardwareDisplay() { return GLSurfaceQt::g_display ? static_cast(GLSurfaceQt::g_display->GetDisplay()) : EGL_NO_DISPLAY; } -bool GLSurfaceEGL::IsCreateContextRobustnessSupported() +bool GLDisplayEGL::IsCreateContextRobustnessSupported() { return GLContextHelper::isCreateContextRobustnessSupported() && HasEGLExtension("EGL_EXT_create_context_robustness"); } -bool GLSurfaceEGL::IsCreateContextBindGeneratesResourceSupported() +bool GLDisplayEGL::IsCreateContextBindGeneratesResourceSupported() { return false; } -bool GLSurfaceEGL::IsCreateContextWebGLCompatabilitySupported() +bool GLDisplayEGL::IsCreateContextWebGLCompatabilitySupported() { return false; } -bool GLSurfaceEGL::IsEGLSurfacelessContextSupported() +bool GLDisplayEGL::IsEGLSurfacelessContextSupported() { return GLSurfaceEGLQt::g_egl_surfaceless_context_supported; } -bool GLSurfaceEGL::IsEGLContextPrioritySupported() +bool GLDisplayEGL::IsEGLContextPrioritySupported() { return false; } -bool GLSurfaceEGL::IsRobustResourceInitSupported() +bool GLDisplayEGL::IsRobustResourceInitSupported() { return false; } -bool GLSurfaceEGL::IsDisplayTextureShareGroupSupported() +bool GLDisplayEGL::IsDisplayTextureShareGroupSupported() { return false; } -bool GLSurfaceEGL::IsCreateContextClientArraysSupported() +bool GLDisplayEGL::IsCreateContextClientArraysSupported() { return false; } -bool GLSurfaceEGL::IsPixelFormatFloatSupported() +bool GLDisplayEGL::IsPixelFormatFloatSupported() { return false; } -bool GLSurfaceEGL::IsANGLEFeatureControlSupported() +bool GLDisplayEGL::IsANGLEFeatureControlSupported() { return false; } -bool GLSurfaceEGL::IsANGLEPowerPreferenceSupported() +bool GLDisplayEGL::IsANGLEPowerPreferenceSupported() { return false; } -bool GLSurfaceEGL::IsANGLEExternalContextAndSurfaceSupported() +bool GLDisplayEGL::IsANGLEExternalContextAndSurfaceSupported() { return false; } -bool GLSurfaceEGL::IsDisplaySemaphoreShareGroupSupported() +bool GLDisplayEGL::IsDisplaySemaphoreShareGroupSupported() { return false; } -bool GLSurfaceEGL::IsRobustnessVideoMemoryPurgeSupported() +bool GLDisplayEGL::IsRobustnessVideoMemoryPurgeSupported() { return false; } -bool GLSurfaceEGL::IsANGLEContextVirtualizationSupported() +bool GLDisplayEGL::IsANGLEContextVirtualizationSupported() { return false; } -bool GLSurfaceEGL::IsANGLEVulkanImageSupported() +bool GLDisplayEGL::IsANGLEVulkanImageSupported() { return false; } -bool GLSurfaceEGL::IsEGLQueryDeviceSupported() +bool GLDisplayEGL::IsEGLQueryDeviceSupported() { return false; } -void GLSurfaceEGL::ShutdownOneOff() +void GLSurfaceEGL::ShutdownOneOff(GLDisplayEGL *) { } -const char *GLSurfaceEGL::GetEGLClientExtensions() +const char *GetEGLClientExtensions() { return GLSurfaceQt::g_client_extensions.c_str(); } -const char *GLSurfaceEGL::GetEGLExtensions() +const char *GetEGLExtensions() { return GLSurfaceQt::g_extensions.c_str(); } -bool GLSurfaceEGL::HasEGLClientExtension(const char *name) +bool GLDisplayEGL::HasEGLClientExtension(const char *name) { - return ExtensionsContain(GetEGLClientExtensions(), name); + return GLSurface::ExtensionsContain(GetEGLClientExtensions(), name); } -bool GLSurfaceEGL::HasEGLExtension(const char *name) +bool GLDisplayEGL::HasEGLExtension(const char *name) { - return ExtensionsContain(GetEGLExtensions(), name); + return GLSurface::ExtensionsContain(GetEGLExtensions(), name); } -bool GLSurfaceEGL::InitializeOneOff(gl::EGLDisplayPlatform /*native_display*/, uint64_t) +GLDisplayEGL *GLSurfaceEGL::InitializeOneOff(gl::EGLDisplayPlatform /*native_display*/, uint64_t system_id) { - return GLSurfaceEGLQt::InitializeOneOff(); + return static_cast(GLSurfaceEGLQt::InitializeOneOff(system_id)); } -bool GLSurfaceEGL::IsEGLNoConfigContextSupported() +bool GLDisplayEGL::IsEGLNoConfigContextSupported() { return false; } -bool GLSurfaceEGL::IsAndroidNativeFenceSyncSupported() +bool GLDisplayEGL::IsAndroidNativeFenceSyncSupported() { return false; } -DisplayType GLSurfaceEGL::GetDisplayType() +GLDisplayEGL *GLSurfaceEGL::GetGLDisplayEGL() +{ + return static_cast(GLSurfaceEGLQt::g_display); +} + +DisplayType GLDisplayEGL::GetDisplayType() { return DisplayType::DEFAULT; } @@ -181,31 +186,28 @@ GLSurfaceEGLQt::~GLSurfaceEGLQt() Destroy(); } -bool GLSurfaceEGLQt::InitializeOneOff() +gl::GLDisplay *GLSurfaceEGLQt::InitializeOneOff(uint64_t system_device_id) { if (s_initialized) - return true; - - // Must be called before initializing the display. - g_driver_egl.InitializeClientExtensionBindings(); + return g_display; - auto *egl_display = new GLDisplayEGL(); + auto *egl_display = new GLDisplayEGL(system_device_id); g_display = egl_display; egl_display->SetDisplay(GLContextHelper::getEGLDisplay()); if (!g_display->GetDisplay()) { LOG(ERROR) << "GLContextHelper::getEGLDisplay() failed."; - return false; + return nullptr; } g_config = GLContextHelper::getEGLConfig(); if (!g_config) { LOG(ERROR) << "GLContextHelper::getEGLConfig() failed."; - return false; + return nullptr; } if (!eglInitialize(g_display->GetDisplay(), NULL, NULL)) { LOG(ERROR) << "eglInitialize failed with error " << GetLastEGLErrorString(); - return false; + return nullptr; } g_client_extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS); @@ -228,11 +230,8 @@ bool GLSurfaceEGLQt::InitializeOneOff() } } - // Must be called after initializing the display. - g_driver_egl.InitializeExtensionBindings(); - s_initialized = true; - return true; + return g_display; } bool GLSurfaceEGLQt::InitializeExtensionSettingsOneOff() @@ -348,26 +347,18 @@ void* GLSurfacelessQtEGL::GetShareHandle() return NULL; } -std::string DriverEGL::GetPlatformExtensions() +} // namespace gl +#endif // !BUILDFLAG(IS_MAC) + +namespace gl { + +std::string DisplayExtensionsEGL::GetPlatformExtensions(void*) { EGLDisplay display = GLContextHelper::getEGLDisplay(); if (display == EGL_NO_DISPLAY) return ""; - DCHECK(g_driver_egl.fn.eglQueryStringFn); - const char* str = g_driver_egl.fn.eglQueryStringFn(display, EGL_EXTENSIONS); + const char* str = eglQueryString(display, EGL_EXTENSIONS); return str ? std::string(str) : ""; } } // namespace gl -#else -namespace gl { -struct GL_EXPORT DriverEGL { - static std::string GetPlatformExtensions(); -}; - -std::string DriverEGL::GetPlatformExtensions() -{ - return ""; -} -} // namespace gl -#endif // !BUILDFLAG(IS_MAC) diff --git a/src/core/ozone/gl_surface_egl_qt.h b/src/core/ozone/gl_surface_egl_qt.h index 8a799b847..2444ebd4a 100644 --- a/src/core/ozone/gl_surface_egl_qt.h +++ b/src/core/ozone/gl_surface_egl_qt.h @@ -14,7 +14,7 @@ class GLSurfaceEGLQt: public GLSurfaceQt { public: explicit GLSurfaceEGLQt(const gfx::Size& size); - static bool InitializeOneOff(); + static gl::GLDisplay *InitializeOneOff(uint64_t system_device_id); static bool InitializeExtensionSettingsOneOff(); bool Initialize(GLSurfaceFormat format) override; diff --git a/src/core/ozone/gl_surface_glx_qt.cpp b/src/core/ozone/gl_surface_glx_qt.cpp index f97f3de1e..1028f3235 100644 --- a/src/core/ozone/gl_surface_glx_qt.cpp +++ b/src/core/ozone/gl_surface_glx_qt.cpp @@ -86,37 +86,37 @@ GLSurfaceGLXQt::~GLSurfaceGLXQt() Destroy(); } -bool GLSurfaceGLXQt::InitializeOneOff() +GLDisplay *GLSurfaceGLXQt::InitializeOneOff(uint64_t system_device_id) { if (s_initialized) - return true; + return g_display; - g_display = new GLDisplayX11(); + g_display = new GLDisplayX11(system_device_id); if (!g_display->GetDisplay()) { LOG(ERROR) << "GLContextHelper::getXDisplay() failed."; - return false; + return nullptr; } g_config = GLContextHelper::getGlXConfig(); if (!g_config) { LOG(ERROR) << "GLContextHelper::getGlxConfig() failed."; - return false; + return nullptr; } Display* display = static_cast(g_display->GetDisplay()); int major, minor; if (!glXQueryVersion(display, &major, &minor)) { LOG(ERROR) << "glxQueryVersion failed."; - return false; + return nullptr; } if (major == 1 && minor < 3) { LOG(ERROR) << "GLX 1.3 or later is required."; - return false; + return nullptr; } s_initialized = true; - return true; + return g_display; } diff --git a/src/core/ozone/gl_surface_glx_qt.h b/src/core/ozone/gl_surface_glx_qt.h index 6312f6b74..f81f6e9df 100644 --- a/src/core/ozone/gl_surface_glx_qt.h +++ b/src/core/ozone/gl_surface_glx_qt.h @@ -12,7 +12,7 @@ class GLSurfaceGLXQt: public GLSurfaceQt { public: explicit GLSurfaceGLXQt(const gfx::Size& size); - static bool InitializeOneOff(); + static gl::GLDisplay *InitializeOneOff(uint64_t system_device_id); static bool InitializeExtensionSettingsOneOff(); bool Initialize(GLSurfaceFormat format) override; diff --git a/src/core/ozone/platform_window_qt.cpp b/src/core/ozone/platform_window_qt.cpp index 01b0ae139..4a6331c61 100644 --- a/src/core/ozone/platform_window_qt.cpp +++ b/src/core/ozone/platform_window_qt.cpp @@ -24,7 +24,7 @@ PlatformWindowQt::~PlatformWindowQt() ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); } -gfx::Rect PlatformWindowQt::GetBounds() const +gfx::Rect PlatformWindowQt::GetBoundsInPixels() const { return bounds_; } @@ -34,7 +34,7 @@ void PlatformWindowQt::Close() delegate_->OnClosed(); } -void PlatformWindowQt::SetBounds(const gfx::Rect& bounds) +void PlatformWindowQt::SetBoundsInPixels(const gfx::Rect& bounds) { if (bounds == bounds_) return; @@ -47,6 +47,16 @@ bool PlatformWindowQt::CanDispatchEvent(const ui::PlatformEvent& /*ne*/) return true; } +gfx::Rect PlatformWindowQt::GetBoundsInDIP() const +{ + return delegate_->ConvertRectToDIP(bounds_); +} + +void PlatformWindowQt::SetBoundsInDIP(const gfx::Rect &bounds_in_dip) +{ + SetBoundsInPixels(delegate_->ConvertRectToPixels(bounds_in_dip)); +} + uint32_t PlatformWindowQt::DispatchEvent(const ui::PlatformEvent& native_event) { DispatchEventFromNativeUiEvent( diff --git a/src/core/ozone/platform_window_qt.h b/src/core/ozone/platform_window_qt.h index fee4728cf..0d1743f68 100644 --- a/src/core/ozone/platform_window_qt.h +++ b/src/core/ozone/platform_window_qt.h @@ -21,8 +21,10 @@ public: PlatformWindowQt(PlatformWindowDelegate* delegate, const gfx::Rect& bounds); ~PlatformWindowQt() override; // PlatformWindow: - gfx::Rect GetBounds() const override; - void SetBounds(const gfx::Rect& bounds) override; + gfx::Rect GetBoundsInPixels() const override; + void SetBoundsInPixels(const gfx::Rect& bounds) override; + gfx::Rect GetBoundsInDIP() const override; + void SetBoundsInDIP(const gfx::Rect& bounds) override; void Show(bool inactive = false) override { } void Hide() override { } void Close() override; @@ -39,8 +41,8 @@ public: void SetCursor(scoped_refptr) override { } void MoveCursorTo(const gfx::Point&) override { } void ConfineCursorToBounds(const gfx::Rect&) override { } - void SetRestoredBoundsInPixels(const gfx::Rect& bounds) override { } - gfx::Rect GetRestoredBoundsInPixels() const override { return gfx::Rect(); } + void SetRestoredBoundsInDIP(const gfx::Rect& bounds) override { } + gfx::Rect GetRestoredBoundsInDIP() const override { return gfx::Rect(); } void Activate() override { } void Deactivate() override { } void SetUseNativeFrame(bool use_native_frame) override { } diff --git a/src/core/permission_manager_qt.cpp b/src/core/permission_manager_qt.cpp index a1727bda3..b5669eb66 100644 --- a/src/core/permission_manager_qt.cpp +++ b/src/core/permission_manager_qt.cpp @@ -6,9 +6,9 @@ #include "content/browser/renderer_host/render_view_host_delegate.h" #include "content/browser/web_contents/web_contents_impl.h" #include "content/public/browser/permission_controller.h" -#include "content/public/browser/permission_type.h" #include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_view_host.h" +#include "third_party/blink/public/common/permissions/permission_utils.h" #include "type_conversion.h" #include "web_contents_delegate_qt.h" @@ -16,44 +16,44 @@ namespace QtWebEngineCore { -static ProfileAdapter::PermissionType toQt(content::PermissionType type) +static ProfileAdapter::PermissionType toQt(blink::PermissionType type) { switch (type) { - case content::PermissionType::GEOLOCATION: + case blink::PermissionType::GEOLOCATION: return ProfileAdapter::GeolocationPermission; - case content::PermissionType::AUDIO_CAPTURE: + case blink::PermissionType::AUDIO_CAPTURE: return ProfileAdapter::AudioCapturePermission; - case content::PermissionType::VIDEO_CAPTURE: + case blink::PermissionType::VIDEO_CAPTURE: return ProfileAdapter::VideoCapturePermission; - case content::PermissionType::CLIPBOARD_READ_WRITE: + case blink::PermissionType::CLIPBOARD_READ_WRITE: return ProfileAdapter::ClipboardRead; - case content::PermissionType::CLIPBOARD_SANITIZED_WRITE: + case blink::PermissionType::CLIPBOARD_SANITIZED_WRITE: return ProfileAdapter::ClipboardWrite; - case content::PermissionType::NOTIFICATIONS: + case blink::PermissionType::NOTIFICATIONS: return ProfileAdapter::NotificationPermission; - case content::PermissionType::ACCESSIBILITY_EVENTS: - case content::PermissionType::CAMERA_PAN_TILT_ZOOM: - case content::PermissionType::WINDOW_PLACEMENT: + case blink::PermissionType::ACCESSIBILITY_EVENTS: + case blink::PermissionType::CAMERA_PAN_TILT_ZOOM: + case blink::PermissionType::WINDOW_PLACEMENT: return ProfileAdapter::UnsupportedPermission; - case content::PermissionType::MIDI_SYSEX: - case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER: - case content::PermissionType::MIDI: - case content::PermissionType::DURABLE_STORAGE: - case content::PermissionType::BACKGROUND_SYNC: - case content::PermissionType::SENSORS: - case content::PermissionType::PAYMENT_HANDLER: - case content::PermissionType::BACKGROUND_FETCH: - case content::PermissionType::IDLE_DETECTION: - case content::PermissionType::PERIODIC_BACKGROUND_SYNC: - case content::PermissionType::WAKE_LOCK_SCREEN: - case content::PermissionType::WAKE_LOCK_SYSTEM: - case content::PermissionType::NFC: - case content::PermissionType::AR: - case content::PermissionType::VR: - case content::PermissionType::STORAGE_ACCESS_GRANT: - case content::PermissionType::LOCAL_FONTS: - case content::PermissionType::DISPLAY_CAPTURE: - case content::PermissionType::NUM: + case blink::PermissionType::MIDI_SYSEX: + case blink::PermissionType::PROTECTED_MEDIA_IDENTIFIER: + case blink::PermissionType::MIDI: + case blink::PermissionType::DURABLE_STORAGE: + case blink::PermissionType::BACKGROUND_SYNC: + case blink::PermissionType::SENSORS: + case blink::PermissionType::PAYMENT_HANDLER: + case blink::PermissionType::BACKGROUND_FETCH: + case blink::PermissionType::IDLE_DETECTION: + case blink::PermissionType::PERIODIC_BACKGROUND_SYNC: + case blink::PermissionType::WAKE_LOCK_SCREEN: + case blink::PermissionType::WAKE_LOCK_SYSTEM: + case blink::PermissionType::NFC: + case blink::PermissionType::AR: + case blink::PermissionType::VR: + case blink::PermissionType::STORAGE_ACCESS_GRANT: + case blink::PermissionType::LOCAL_FONTS: + case blink::PermissionType::DISPLAY_CAPTURE: + case blink::PermissionType::NUM: LOG(INFO) << "Unexpected unsupported permission type: " << static_cast(type); break; } @@ -130,7 +130,7 @@ void PermissionManagerQt::permissionRequestReply(const QUrl &url, ProfileAdapter bool answerable = true; std::vector result; result.reserve(it->types.size()); - for (content::PermissionType permission : it->types) { + for (blink::PermissionType permission : it->types) { const ProfileAdapter::PermissionType permissionType = toQt(permission); if (permissionType == ProfileAdapter::UnsupportedPermission) { result.push_back(blink::mojom::PermissionStatus::DENIED); @@ -163,7 +163,7 @@ bool PermissionManagerQt::checkPermission(const QUrl &origin, ProfileAdapter::Pe return m_permissions.contains(key) && m_permissions[key]; } -void PermissionManagerQt::RequestPermission(content::PermissionType permission, +void PermissionManagerQt::RequestPermission(blink::PermissionType permission, content::RenderFrameHost *frameHost, const GURL& requesting_origin, bool /*user_gesture*/, @@ -198,7 +198,7 @@ void PermissionManagerQt::RequestPermission(content::PermissionType permission, contentsDelegate->requestFeaturePermission(permissionType, requestOrigin); } -void PermissionManagerQt::RequestPermissions(const std::vector &permissions, +void PermissionManagerQt::RequestPermissions(const std::vector &permissions, content::RenderFrameHost *frameHost, const GURL &requesting_origin, bool /*user_gesture*/, @@ -216,7 +216,7 @@ void PermissionManagerQt::RequestPermissions(const std::vector result; result.reserve(permissions.size()); - for (content::PermissionType permission : permissions) { + for (blink::PermissionType permission : permissions) { const ProfileAdapter::PermissionType permissionType = toQt(permission); if (permissionType == ProfileAdapter::UnsupportedPermission) result.push_back(blink::mojom::PermissionStatus::DENIED); @@ -240,15 +240,23 @@ void PermissionManagerQt::RequestPermissions(const std::vectorrequestFeaturePermission(permissionType, requestOrigin); } } +void PermissionManagerQt::RequestPermissionsFromCurrentDocument(const std::vector &permissions, + content::RenderFrameHost *frameHost, + bool user_gesture, + base::OnceCallback&)> callback) +{ + RequestPermissions(permissions, frameHost, frameHost->GetLastCommittedOrigin().GetURL(), user_gesture, std::move(callback)); +} + blink::mojom::PermissionStatus PermissionManagerQt::GetPermissionStatus( - content::PermissionType permission, + blink::PermissionType permission, const GURL& requesting_origin, const GURL& /*embedding_origin*/) { @@ -264,19 +272,18 @@ blink::mojom::PermissionStatus PermissionManagerQt::GetPermissionStatus( return blink::mojom::PermissionStatus::DENIED; } -blink::mojom::PermissionStatus PermissionManagerQt::GetPermissionStatusForFrame( - content::PermissionType permission, - content::RenderFrameHost *render_frame_host, - const GURL &requesting_origin) +blink::mojom::PermissionStatus PermissionManagerQt::GetPermissionStatusForCurrentDocument( + blink::PermissionType permission, + content::RenderFrameHost *render_frame_host) { - if (permission == content::PermissionType::CLIPBOARD_READ_WRITE || - permission == content::PermissionType::CLIPBOARD_SANITIZED_WRITE) { + if (permission == blink::PermissionType::CLIPBOARD_READ_WRITE || + permission == blink::PermissionType::CLIPBOARD_SANITIZED_WRITE) { WebContentsDelegateQt *delegate = static_cast( content::WebContents::FromRenderFrameHost(render_frame_host)->GetDelegate()); if (!delegate->webEngineSettings()->testAttribute( QWebEngineSettings::JavascriptCanAccessClipboard)) return blink::mojom::PermissionStatus::DENIED; - if (permission == content::PermissionType::CLIPBOARD_READ_WRITE + if (permission == blink::PermissionType::CLIPBOARD_READ_WRITE && !delegate->webEngineSettings()->testAttribute( QWebEngineSettings::JavascriptCanPaste)) return blink::mojom::PermissionStatus::DENIED; @@ -285,22 +292,12 @@ blink::mojom::PermissionStatus PermissionManagerQt::GetPermissionStatusForFrame( return GetPermissionStatus( permission, - requesting_origin, - render_frame_host->GetLastCommittedOrigin().GetURL()); -} - -blink::mojom::PermissionStatus PermissionManagerQt::GetPermissionStatusForCurrentDocument( - content::PermissionType permission, - content::RenderFrameHost *render_frame_host) -{ - return GetPermissionStatusForFrame( - permission, - render_frame_host, + render_frame_host->GetLastCommittedOrigin().GetURL(), render_frame_host->GetLastCommittedOrigin().GetURL()); } blink::mojom::PermissionStatus PermissionManagerQt::GetPermissionStatusForWorker( - content::PermissionType permission, + blink::PermissionType permission, content::RenderProcessHost *render_process_host, const GURL &url) { @@ -308,7 +305,7 @@ blink::mojom::PermissionStatus PermissionManagerQt::GetPermissionStatusForWorker } void PermissionManagerQt::ResetPermission( - content::PermissionType permission, + blink::PermissionType permission, const GURL& requesting_origin, const GURL& /*embedding_origin*/) { @@ -321,7 +318,7 @@ void PermissionManagerQt::ResetPermission( } content::PermissionControllerDelegate::SubscriptionId PermissionManagerQt::SubscribePermissionStatusChange( - content::PermissionType permission, + blink::PermissionType permission, content::RenderProcessHost * /*render_process_host*/, content::RenderFrameHost * /* render_frame_host */, const GURL& requesting_origin, diff --git a/src/core/permission_manager_qt.h b/src/core/permission_manager_qt.h index 566e0839b..00165d258 100644 --- a/src/core/permission_manager_qt.h +++ b/src/core/permission_manager_qt.h @@ -13,8 +13,8 @@ namespace QtWebEngineCore { -class PermissionManagerQt : public content::PermissionControllerDelegate { - +class PermissionManagerQt : public content::PermissionControllerDelegate +{ public: PermissionManagerQt(); ~PermissionManagerQt(); @@ -24,41 +24,43 @@ public: // content::PermissionManager implementation: void RequestPermission( - content::PermissionType permission, + blink::PermissionType permission, content::RenderFrameHost* render_frame_host, const GURL& requesting_origin, bool user_gesture, base::OnceCallback callback) override; blink::mojom::PermissionStatus GetPermissionStatus( - content::PermissionType permission, + blink::PermissionType permission, const GURL& requesting_origin, const GURL& embedding_origin) override; - blink::mojom::PermissionStatus GetPermissionStatusForFrame( - content::PermissionType permission, - content::RenderFrameHost *render_frame_host, - const GURL& requesting_origin) override; - - blink::mojom::PermissionStatus GetPermissionStatusForCurrentDocument(content::PermissionType, content::RenderFrameHost *) override; + blink::mojom::PermissionStatus GetPermissionStatusForCurrentDocument(blink::PermissionType, content::RenderFrameHost *) override; - blink::mojom::PermissionStatus GetPermissionStatusForWorker(content::PermissionType, content::RenderProcessHost *, const GURL &) override; + blink::mojom::PermissionStatus GetPermissionStatusForWorker(blink::PermissionType, content::RenderProcessHost *, const GURL &) override; void ResetPermission( - content::PermissionType permission, + blink::PermissionType permission, const GURL& requesting_origin, const GURL& embedding_origin) override; void RequestPermissions( - const std::vector& permission, + const std::vector& permission, content::RenderFrameHost* render_frame_host, const GURL& requesting_origin, bool user_gesture, base::OnceCallback&)> callback) override; + void RequestPermissionsFromCurrentDocument( + const std::vector& permissions, + content::RenderFrameHost* render_frame_host, + bool user_gesture, + base::OnceCallback&)> callback) override; + content::PermissionControllerDelegate::SubscriptionId SubscribePermissionStatusChange( - content::PermissionType permission, + blink::PermissionType permission, content::RenderProcessHost* render_process_host, content::RenderFrameHost* render_frame_host, const GURL& requesting_origin, @@ -76,7 +78,7 @@ private: }; struct MultiRequest { int id; - std::vector types; + std::vector types; QUrl origin; base::OnceCallback&)> callback; }; diff --git a/src/core/platform_notification_service_qt.cpp b/src/core/platform_notification_service_qt.cpp index 277de55f0..182a5ad84 100644 --- a/src/core/platform_notification_service_qt.cpp +++ b/src/core/platform_notification_service_qt.cpp @@ -6,7 +6,6 @@ #include "chrome/common/pref_names.h" #include "components/prefs/pref_service.h" #include "content/public/browser/browser_thread.h" -#include "content/public/browser/permission_type.h" #include "content/public/browser/notification_event_dispatcher.h" #include "ui/message_center/public/cpp/notification_delegate.h" diff --git a/src/core/pref_service_adapter.cpp b/src/core/pref_service_adapter.cpp index 6445f3175..7283ef231 100644 --- a/src/core/pref_service_adapter.cpp +++ b/src/core/pref_service_adapter.cpp @@ -84,8 +84,6 @@ void PrefServiceAdapter::setup(const ProfileAdapter &profileAdapter) registry->RegisterIntegerPref(prefs::kNotificationNextPersistentId, 10000); registry->RegisterDictionaryPref(prefs::kPushMessagingAppIdentifierMap); registry->RegisterListPref(prefs::kAccountInfo); - registry->RegisterIntegerPref(prefs::kAccountIdMigrationState, - AccountTrackerService::MIGRATION_NOT_STARTED); registry->RegisterStringPref(prefs::kGoogleServicesLastAccountId, std::string()); registry->RegisterStringPref(prefs::kGoogleServicesLastUsername, diff --git a/src/core/printing/print_view_manager_base_qt.cpp b/src/core/printing/print_view_manager_base_qt.cpp index 3af6ecf44..dcbf6a5bc 100644 --- a/src/core/printing/print_view_manager_base_qt.cpp +++ b/src/core/printing/print_view_manager_base_qt.cpp @@ -14,7 +14,7 @@ #include "base/memory/ref_counted_memory.h" #include "base/run_loop.h" #include "base/task/current_thread.h" -#include "base/task/post_task.h" +#include "base/task/thread_pool.h" #include "base/timer/timer.h" #include "base/values.h" #include "chrome/browser/chrome_notification_types.h" @@ -47,21 +47,18 @@ void GetDefaultPrintSettingsReply(printing::mojom::PrintManagerHost::GetDefaultP std::move(callback).Run(std::move(params)); } -void GetDefaultPrintSettingsReplyOnIO(scoped_refptr queue, +void OnDidGetDefaultPrintSettings(scoped_refptr queue, std::unique_ptr printer_query, printing::mojom::PrintManagerHost::GetDefaultPrintSettingsCallback callback) { - DCHECK_CURRENTLY_ON(content::BrowserThread::IO); + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); printing::mojom::PrintParamsPtr params = printing::mojom::PrintParams::New(); if (printer_query && printer_query->last_status() == printing::mojom::ResultCode::kSuccess) { RenderParamsFromPrintSettings(printer_query->settings(), params.get()); params->document_cookie = printer_query->cookie(); } - content::GetUIThreadTaskRunner({})->PostTask( - FROM_HERE, - base::BindOnce(&GetDefaultPrintSettingsReply, - std::move(callback), std::move(params))); + GetDefaultPrintSettingsReply(std::move(callback), std::move(params)); // If printing was enabled. if (printer_query) { @@ -74,26 +71,6 @@ void GetDefaultPrintSettingsReplyOnIO(scoped_refptr } } -void GetDefaultPrintSettingsOnIO(printing::mojom::PrintManagerHost::GetDefaultPrintSettingsCallback callback, - scoped_refptr queue, - bool is_modifiable, - content::GlobalRenderFrameHostId rfh_id) -{ - DCHECK_CURRENTLY_ON(content::BrowserThread::IO); - - std::unique_ptr printer_query = queue->PopPrinterQuery(0); - if (!printer_query) - printer_query = queue->CreatePrinterQuery(rfh_id); - - // Loads default settings. This is asynchronous, only the mojo message sender - // will hang until the settings are retrieved. - auto *printer_query_ptr = printer_query.get(); - printer_query_ptr->GetDefaultSettings( - base::BindOnce(&GetDefaultPrintSettingsReplyOnIO, queue, - std::move(printer_query), std::move(callback)), - is_modifiable); -} - printing::mojom::PrintPagesParamsPtr CreateEmptyPrintPagesParamsPtr() { auto params = printing::mojom::PrintPagesParams::New(); @@ -112,25 +89,23 @@ void UpdatePrintSettingsReply(printing::mojom::PrintManagerHost::UpdatePrintSett std::move(callback).Run(std::move(params), canceled); } -void UpdatePrintSettingsReplyOnIO(scoped_refptr queue, +void OnDidUpdatePrintSettings(scoped_refptr queue, std::unique_ptr printer_query, printing::mojom::PrintManagerHost::UpdatePrintSettingsCallback callback, int process_id, int routing_id) { - DCHECK_CURRENTLY_ON(content::BrowserThread::IO); + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK(printer_query); auto params = printing::mojom::PrintPagesParams::New(); params->params = printing::mojom::PrintParams::New(); if (printer_query->last_status() == printing::mojom::ResultCode::kSuccess) { RenderParamsFromPrintSettings(printer_query->settings(), params->params.get()); params->params->document_cookie = printer_query->cookie(); - params->pages = printing::PageRange::GetPages(printer_query->settings().ranges()); + params->pages = printer_query->settings().ranges(); } - bool canceled = printer_query->last_status() == printing::mojom::ResultCode::kAccessDenied; + bool canceled = printer_query->last_status() == printing::mojom::ResultCode::kCanceled; - content::GetUIThreadTaskRunner({})->PostTask( - FROM_HERE, - base::BindOnce(&UpdatePrintSettingsReply, std::move(callback), std::move(params), canceled)); + UpdatePrintSettingsReply(std::move(callback), std::move(params), canceled); if (printer_query->cookie() && printer_query->settings().dpi()) { queue->QueuePrinterQuery(std::move(printer_query)); @@ -139,40 +114,21 @@ void UpdatePrintSettingsReplyOnIO(scoped_refptr que } } -void UpdatePrintSettingsOnIO(int32_t cookie, - printing::mojom::PrintManagerHost::UpdatePrintSettingsCallback callback, - scoped_refptr queue, - base::Value::Dict job_settings, - int process_id, int routing_id) -{ - DCHECK_CURRENTLY_ON(content::BrowserThread::IO); - std::unique_ptr printer_query = queue->PopPrinterQuery(cookie); - if (!printer_query) - printer_query = queue->CreatePrinterQuery(content::GlobalRenderFrameHostId()); - - auto *printer_query_ptr = printer_query.get(); - printer_query_ptr->SetSettings( - std::move(job_settings), - base::BindOnce(&UpdatePrintSettingsReplyOnIO, - queue, std::move(printer_query), std::move(callback), - process_id, routing_id)); -} -void ScriptedPrintReplyOnIO(scoped_refptr queue, +void OnDidScriptedPrint(scoped_refptr queue, std::unique_ptr printer_query, printing::mojom::PrintManagerHost::ScriptedPrintCallback callback) { - DCHECK_CURRENTLY_ON(content::BrowserThread::IO); + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); printing::mojom::PrintPagesParamsPtr params = CreateEmptyPrintPagesParamsPtr(); if (printer_query->last_status() == printing::mojom::ResultCode::kSuccess && printer_query->settings().dpi()) { RenderParamsFromPrintSettings(printer_query->settings(), params->params.get()); params->params->document_cookie = printer_query->cookie(); - params->pages = printing::PageRange::GetPages(printer_query->settings().ranges()); + params->pages = printer_query->settings().ranges(); } bool has_valid_cookie = params->params->document_cookie; bool has_dpi = !params->params->dpi.IsEmpty(); - content::GetUIThreadTaskRunner({})->PostTask( - FROM_HERE, base::BindOnce(std::move(callback), std::move(params))); + std::move(callback).Run(std::move(params)); if (has_dpi && has_valid_cookie) { queue->QueuePrinterQuery(std::move(printer_query)); @@ -181,25 +137,6 @@ void ScriptedPrintReplyOnIO(scoped_refptr queue, } } -void ScriptedPrintOnIO(printing::mojom::ScriptedPrintParamsPtr params, - printing::mojom::PrintManagerHost::ScriptedPrintCallback callback, - scoped_refptr queue, - bool is_modifiable, - content::GlobalRenderFrameHostId rfh_id) -{ - DCHECK_CURRENTLY_ON(content::BrowserThread::IO); - - std::unique_ptr printer_query = queue->PopPrinterQuery(params->cookie); - if (!printer_query) - printer_query = queue->CreatePrinterQuery(rfh_id); - - auto *printer_query_ptr = printer_query.get(); - printer_query_ptr->GetSettingsFromUser( - params->expected_pages_count, params->has_selection, params->margin_type, - params->is_scripted, is_modifiable, - base::BindOnce(&ScriptedPrintReplyOnIO, queue, std::move(printer_query), std::move(callback))); -} - } // namespace PrintViewManagerBaseQt::PrintViewManagerBaseQt(content::WebContents *contents) @@ -334,21 +271,30 @@ void PrintViewManagerBaseQt::GetDefaultPrintSettings(GetDefaultPrintSettingsCall print_manager_host_receivers_.GetCurrentTargetFrame(); content::RenderProcessHost *render_process_host = render_frame_host->GetProcess(); - content::GetIOThreadTaskRunner({})->PostTask( - FROM_HERE, - base::BindOnce(&GetDefaultPrintSettingsOnIO, std::move(callback), m_printerQueriesQueue, - !render_process_host->IsPdf(), - render_frame_host->GetGlobalId())); + + auto callback_wrapper = + base::BindOnce(&GetDefaultPrintSettingsReply, std::move(callback)); + std::unique_ptr printer_query = m_printerQueriesQueue->PopPrinterQuery(0); + if (!printer_query) + printer_query = m_printerQueriesQueue->CreatePrinterQuery(render_frame_host->GetGlobalId()); + + // Loads default settings. This is asynchronous, only the mojo message sender + // will hang until the settings are retrieved. + auto *printer_query_ptr = printer_query.get(); + printer_query_ptr->GetDefaultSettings( + base::BindOnce(&OnDidGetDefaultPrintSettings, m_printerQueriesQueue, + std::move(printer_query), std::move(callback_wrapper)), + !render_process_host->IsPdf()); } -void PrintViewManagerBaseQt::PrintingFailed(int32_t cookie) +void PrintViewManagerBaseQt::PrintingFailed(int32_t cookie, printing::mojom::PrintFailureReason reason) { // Note: Not redundant with cookie checks in the same method in other parts of // the class hierarchy. if (!IsValidCookie(cookie)) return; - PrintManager::PrintingFailed(cookie); + PrintManager::PrintingFailed(cookie, reason); ReleasePrinterQuery(); } @@ -365,10 +311,17 @@ void PrintViewManagerBaseQt::ScriptedPrint(printing::mojom::ScriptedPrintParamsP auto callback_wrapper = base::BindOnce( &PrintViewManagerBaseQt::ScriptedPrintReply, weak_ptr_factory_.GetWeakPtr(), std::move(callback), render_process_host->GetID()); - content::GetIOThreadTaskRunner({})->PostTask( - FROM_HERE, - base::BindOnce(&ScriptedPrintOnIO, std::move(params), std::move(callback_wrapper), - m_printerQueriesQueue, !render_process_host->IsPdf(), render_frame_host->GetGlobalId())); + + std::unique_ptr printer_query = + m_printerQueriesQueue->PopPrinterQuery(params->cookie); + if (!printer_query) + printer_query = m_printerQueriesQueue->CreatePrinterQuery(render_frame_host->GetGlobalId()); + + auto *printer_query_ptr = printer_query.get(); + printer_query_ptr->GetSettingsFromUser( + params->expected_pages_count, params->has_selection, params->margin_type, + params->is_scripted, !render_process_host->IsPdf(), + base::BindOnce(&OnDidScriptedPrint, m_printerQueriesQueue, std::move(printer_query), std::move(callback_wrapper))); } void PrintViewManagerBaseQt::ShowInvalidPrinterSettingsError() @@ -408,42 +361,22 @@ void PrintViewManagerBaseQt::RenderFrameDeleted(content::RenderFrameHost *render } } -void PrintViewManagerBaseQt::Observe(int type, - const content::NotificationSource& /*source*/, - const content::NotificationDetails& details) +void PrintViewManagerBaseQt::OnDocDone(int /*job_id*/, printing::PrintedDocument * /*document*/) { - DCHECK_EQ(chrome::NOTIFICATION_PRINT_JOB_EVENT, type); - OnNotifyPrintJobEvent(*content::Details(details).ptr()); } -void PrintViewManagerBaseQt::OnNotifyPrintJobEvent(const printing::JobEventDetails& event_details) +void PrintViewManagerBaseQt::OnJobDone() { - switch (event_details.type()) { - case printing::JobEventDetails::FAILED: { - TerminatePrintJob(true); - break; - } -// case printing::JobEventDetails::ALL_PAGES_REQUESTED: { -// ShouldQuitFromInnerMessageLoop(); -// break; -// } - case printing::JobEventDetails::NEW_DOC: - case printing::JobEventDetails::DOC_DONE: { - // Don't care about the actual printing process. - break; - } - case printing::JobEventDetails::JOB_DONE: { - // Printing is done, we don't need it anymore. - // print_job_->is_job_pending() may still be true, depending on the order - // of object registration. - m_didPrintingSucceed = true; - ReleasePrintJob(); - break; - } - default: - NOTREACHED(); - break; - } + // Printing is done, we don't need it anymore. + // print_job_->is_job_pending() may still be true, depending on the order + // of object registration. + m_didPrintingSucceed = true; + ReleasePrintJob(); +} + +void PrintViewManagerBaseQt::OnFailed() +{ + TerminatePrintJob(true); } // Requests the RenderView to render all the missing pages for the print job. @@ -502,11 +435,14 @@ bool PrintViewManagerBaseQt::CreateNewPrintJob(std::unique_ptrGetMainFrame() || - !web_contents()->GetMainFrame()->IsRenderFrameLive()) { + if (!web_contents()->GetPrimaryMainFrame() || + !web_contents()->GetPrimaryMainFrame()->IsRenderFrameLive()) { return false; } @@ -516,8 +452,7 @@ bool PrintViewManagerBaseQt::CreateNewPrintJob(std::unique_ptr(nullptr /*g_browser_process->print_job_manager()*/); m_printJob->Initialize(std::move(query), RenderSourceName(), number_pages_); - m_registrar.Add(this, chrome::NOTIFICATION_PRINT_JOB_EVENT, - content::Source(m_printJob.get())); + m_printJob->AddObserver(*this); m_didPrintingSucceed = false; return true; } @@ -573,8 +508,8 @@ void PrintViewManagerBaseQt::ReleasePrintJob() if (rfh) GetPrintRenderFrame(rfh)->PrintingDone(m_didPrintingSucceed); - m_registrar.Remove(this, chrome::NOTIFICATION_PRINT_JOB_EVENT, - content::Source(m_printJob.get())); + m_printJob->RemoveObserver(*this); + // Don't close the worker thread. m_printJob = nullptr; } @@ -660,8 +595,7 @@ void PrintViewManagerBaseQt::ReleasePrinterQuery() printerQuery = m_printerQueriesQueue->PopPrinterQuery(cookie); if (!printerQuery) return; - base::PostTask(FROM_HERE, {content::BrowserThread::IO}, - base::BindOnce(&printing::PrinterQuery::StopWorker, std::move(printerQuery))); + printerQuery->StopWorker(); } // Originally from print_preview_message_handler.cc: @@ -669,12 +603,11 @@ void PrintViewManagerBaseQt::StopWorker(int documentCookie) { if (documentCookie <= 0) return; - std::unique_ptr printer_query = + std::unique_ptr printerQuery = m_printerQueriesQueue->PopPrinterQuery(documentCookie); - if (printer_query.get()) { - base::PostTask(FROM_HERE, {content::BrowserThread::IO}, - base::BindOnce(&printing::PrinterQuery::StopWorker, std::move(printer_query))); - } + if (!printerQuery) + return; + printerQuery->StopWorker(); } void PrintViewManagerBaseQt::SendPrintingEnabled(bool enabled, content::RenderFrameHost* rfh) @@ -695,13 +628,16 @@ void PrintViewManagerBaseQt::UpdatePrintSettings(int32_t cookie, base::Value::Di content::RenderFrameHost *render_frame_host = print_manager_host_receivers_.GetCurrentTargetFrame(); + std::unique_ptr printer_query = m_printerQueriesQueue->PopPrinterQuery(cookie); + if (!printer_query) + printer_query = m_printerQueriesQueue->CreatePrinterQuery(content::GlobalRenderFrameHostId()); - content::GetIOThreadTaskRunner({})->PostTask( - FROM_HERE, - base::BindOnce(&UpdatePrintSettingsOnIO, cookie, std::move(callback), - m_printerQueriesQueue, std::move(job_settings), - render_frame_host->GetProcess()->GetID(), - render_frame_host->GetRoutingID())); + auto *printer_query_ptr = printer_query.get(); + printer_query_ptr->SetSettings( + std::move(job_settings), + base::BindOnce(&OnDidUpdatePrintSettings, + m_printerQueriesQueue, std::move(printer_query), std::move(callback), + render_frame_host->GetProcess()->GetID(), render_frame_host->GetRoutingID())); } } // namespace QtWebEngineCore diff --git a/src/core/printing/print_view_manager_base_qt.h b/src/core/printing/print_view_manager_base_qt.h index b83a9d286..8201a4225 100644 --- a/src/core/printing/print_view_manager_base_qt.h +++ b/src/core/printing/print_view_manager_base_qt.h @@ -9,6 +9,7 @@ #define PRINT_VIEW_MANAGER_BASE_QT_H #include "base/memory/ref_counted_memory.h" +#include "chrome/browser/printing/print_job.h" #include "components/prefs/pref_member.h" #include "components/printing/browser/print_manager.h" #include "components/printing/common/print.mojom-forward.h" @@ -24,15 +25,13 @@ class RenderFrameHost; } namespace printing { -class JobEventDetails; -class PrintJob; class PrintQueriesQueue; class PrinterQuery; } namespace QtWebEngineCore { -class PrintViewManagerBaseQt : public content::NotificationObserver - , public printing::PrintManager +class PrintViewManagerBaseQt : public printing::PrintManager + , public printing::PrintJob::Observer { public: ~PrintViewManagerBaseQt() override; @@ -52,7 +51,8 @@ public: void ScriptedPrint(printing::mojom::ScriptedPrintParamsPtr, printing::mojom::PrintManagerHost::ScriptedPrintCallback) override; void ShowInvalidPrinterSettingsError() override; - void PrintingFailed(int32_t cookie) override; + void PrintingFailed(int32_t cookie, + printing::mojom::PrintFailureReason reason) override; protected: explicit PrintViewManagerBaseQt(content::WebContents*); @@ -75,20 +75,17 @@ protected: // disconnect from it. void DisconnectFromCurrentPrintJob(); + // PrintJob::Observer overrides: + void OnDocDone(int job_id, printing::PrintedDocument *document) override; + void OnJobDone() override; + void OnFailed() override; + void StopWorker(int documentCookie); private: - // content::NotificationObserver implementation. - void Observe(int, - const content::NotificationSource&, - const content::NotificationDetails&) override; - // content::WebContentsObserver implementation. void DidStartLoading() override; - // Processes a NOTIFY_PRINT_JOB_EVENT notification. - void OnNotifyPrintJobEvent(const printing::JobEventDetails &event_details); - // Requests the RenderView to render all the missing pages for the print job. // No-op if no print job is pending. Returns true if at least one page has // been requested to the renderer. diff --git a/src/core/printing/print_view_manager_qt.cpp b/src/core/printing/print_view_manager_qt.cpp index 6eb3d7419..37657df3a 100644 --- a/src/core/printing/print_view_manager_qt.cpp +++ b/src/core/printing/print_view_manager_qt.cpp @@ -19,7 +19,6 @@ #include "base/values.h" #include "base/memory/ref_counted_memory.h" -#include "base/task/post_task.h" #include "base/task/thread_pool.h" #include "chrome/browser/printing/print_job_manager.h" #include "chrome/browser/printing/printer_query.h" @@ -74,47 +73,47 @@ static void SavePdfFile(scoped_refptr data, base::File file(path, base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE); bool success = file.IsValid() && metafile.SaveTo(&file); - base::PostTask(FROM_HERE, {content::BrowserThread::UI}, + content::GetUIThreadTaskRunner({})->PostTask(FROM_HERE, base::BindOnce(std::move(saveCallback), success)); } -static base::DictionaryValue *createPrintSettings() +static base::Value::Dict createPrintSettings() { - base::DictionaryValue *printSettings = new base::DictionaryValue(); + base::Value::Dict printSettings; // TO DO: Check if we can use the request ID from Qt here somehow. static int internalRequestId = 0; - printSettings->SetBoolean(printing::kIsFirstRequest, internalRequestId++ == 0); - printSettings->SetInteger(printing::kPreviewRequestID, internalRequestId); + printSettings.Set(printing::kIsFirstRequest, internalRequestId++ == 0); + printSettings.Set(printing::kPreviewRequestID, internalRequestId); // The following are standard settings that Chromium expects to be set. - printSettings->SetInteger(printing::kSettingPrinterType, static_cast(printing::mojom::PrinterType::kPdf)); + printSettings.Set(printing::kSettingPrinterType, static_cast(printing::mojom::PrinterType::kPdf)); - printSettings->SetInteger(printing::kSettingDpiHorizontal, printing::kPointsPerInch); - printSettings->SetInteger(printing::kSettingDpiVertical, printing::kPointsPerInch); + printSettings.Set(printing::kSettingDpiHorizontal, printing::kPointsPerInch); + printSettings.Set(printing::kSettingDpiVertical, printing::kPointsPerInch); - printSettings->SetInteger(printing::kSettingDuplexMode, static_cast(printing::mojom::DuplexMode::kSimplex)); - printSettings->SetInteger(printing::kSettingCopies, 1); - printSettings->SetInteger(printing::kSettingPagesPerSheet, 1); - printSettings->SetBoolean(printing::kSettingCollate, false); + printSettings.Set(printing::kSettingDuplexMode, static_cast(printing::mojom::DuplexMode::kSimplex)); + printSettings.Set(printing::kSettingCopies, 1); + printSettings.Set(printing::kSettingPagesPerSheet, 1); + printSettings.Set(printing::kSettingCollate, false); // printSettings->SetBoolean(printing::kSettingGenerateDraftData, false); - printSettings->SetBoolean(printing::kSettingPreviewModifiable, false); + printSettings.Set(printing::kSettingPreviewModifiable, false); - printSettings->SetKey(printing::kSettingShouldPrintSelectionOnly, base::Value(false)); - printSettings->SetKey(printing::kSettingShouldPrintBackgrounds, base::Value(true)); - printSettings->SetKey(printing::kSettingHeaderFooterEnabled, base::Value(false)); - printSettings->SetKey(printing::kSettingRasterizePdf, base::Value(false)); - printSettings->SetInteger(printing::kSettingScaleFactor, 100); - printSettings->SetString(printing::kSettingDeviceName, ""); - printSettings->SetInteger(printing::kPreviewUIID, 12345678); + printSettings.Set(printing::kSettingShouldPrintSelectionOnly, base::Value(false)); + printSettings.Set(printing::kSettingShouldPrintBackgrounds, base::Value(true)); + printSettings.Set(printing::kSettingHeaderFooterEnabled, base::Value(false)); + printSettings.Set(printing::kSettingRasterizePdf, base::Value(false)); + printSettings.Set(printing::kSettingScaleFactor, 100); + printSettings.Set(printing::kSettingDeviceName, ""); + printSettings.Set(printing::kPreviewUIID, 12345678); return printSettings; } -static base::DictionaryValue *createPrintSettingsFromQPageLayout(const QPageLayout &pageLayout, +static base::Value::Dict createPrintSettingsFromQPageLayout(const QPageLayout &pageLayout, bool useCustomMargins) { - base::DictionaryValue *printSettings = createPrintSettings(); + base::Value::Dict printSettings = createPrintSettings(); QRectF pageSizeInMillimeter; if (useCustomMargins) { @@ -122,43 +121,43 @@ static base::DictionaryValue *createPrintSettingsFromQPageLayout(const QPageLayo pageSizeInMillimeter = pageLayout.pageSize().rect(QPageSize::Millimeter); QMargins pageMarginsInPoints = pageLayout.marginsPoints(); - std::unique_ptr marginsDict(new base::DictionaryValue); - marginsDict->SetInteger(printing::kSettingMarginTop, pageMarginsInPoints.top()); - marginsDict->SetInteger(printing::kSettingMarginBottom, pageMarginsInPoints.bottom()); - marginsDict->SetInteger(printing::kSettingMarginLeft, pageMarginsInPoints.left()); - marginsDict->SetInteger(printing::kSettingMarginRight, pageMarginsInPoints.right()); + base::Value::Dict marginsDict; + marginsDict.Set(printing::kSettingMarginTop, pageMarginsInPoints.top()); + marginsDict.Set(printing::kSettingMarginBottom, pageMarginsInPoints.bottom()); + marginsDict.Set(printing::kSettingMarginLeft, pageMarginsInPoints.left()); + marginsDict.Set(printing::kSettingMarginRight, pageMarginsInPoints.right()); - printSettings->Set(printing::kSettingMarginsCustom, std::move(marginsDict)); - printSettings->SetInteger(printing::kSettingMarginsType, (int)printing::mojom::MarginType::kCustomMargins); + printSettings.Set(printing::kSettingMarginsCustom, std::move(marginsDict)); + printSettings.Set(printing::kSettingMarginsType, (int)printing::mojom::MarginType::kCustomMargins); // pageSizeInMillimeter is in portrait orientation. Transpose it if necessary. - printSettings->SetBoolean(printing::kSettingLandscape, pageLayout.orientation() == QPageLayout::Landscape); + printSettings.Set(printing::kSettingLandscape, pageLayout.orientation() == QPageLayout::Landscape); } else { // QPrinter will handle margins pageSizeInMillimeter = pageLayout.paintRect(QPageLayout::Millimeter); - printSettings->SetInteger(printing::kSettingMarginsType, (int)printing::mojom::MarginType::kNoMargins); + printSettings.Set(printing::kSettingMarginsType, (int)printing::mojom::MarginType::kNoMargins); // pageSizeInMillimeter already contains the orientation. - printSettings->SetBoolean(printing::kSettingLandscape, false); + printSettings.Set(printing::kSettingLandscape, false); } //Set page size attributes, chromium expects these in micrometers - std::unique_ptr sizeDict(new base::DictionaryValue); - sizeDict->SetInteger(printing::kSettingMediaSizeWidthMicrons, pageSizeInMillimeter.width() * kMicronsToMillimeter); - sizeDict->SetInteger(printing::kSettingMediaSizeHeightMicrons, pageSizeInMillimeter.height() * kMicronsToMillimeter); - printSettings->Set(printing::kSettingMediaSize, std::move(sizeDict)); + base::Value::Dict sizeDict; + sizeDict.Set(printing::kSettingMediaSizeWidthMicrons, int(pageSizeInMillimeter.width() * kMicronsToMillimeter)); + sizeDict.Set(printing::kSettingMediaSizeHeightMicrons, int(pageSizeInMillimeter.height() * kMicronsToMillimeter)); + printSettings.Set(printing::kSettingMediaSize, std::move(sizeDict)); return printSettings; } -static base::ListValue *createPageRangeSettings(const QList &ranges) +static base::Value::List createPageRangeSettings(const QList &ranges) { - base::ListValue *pageRangeArray = new base::ListValue; + base::Value::List pageRangeArray; for (int i = 0; i < ranges.count(); i++) { - std::unique_ptr pageRange(new base::DictionaryValue); - pageRange->SetInteger(printing::kSettingPageRangeFrom, ranges.at(i).from); - pageRange->SetInteger(printing::kSettingPageRangeTo, ranges.at(i).to); - pageRangeArray->Append(std::move(pageRange)); + base::Value::Dict pageRange; + pageRange.Set(printing::kSettingPageRangeFrom, ranges.at(i).from); + pageRange.Set(printing::kSettingPageRangeTo, ranges.at(i).to); + pageRangeArray.Append(std::move(pageRange)); } return pageRangeArray; } @@ -180,8 +179,8 @@ void PrintViewManagerQt::PrintToPDFFileWithCallback(const QPageLayout &pageLayou if (callback.is_null()) return; - if (m_printSettings || !filePath.length()) { - base::PostTask(FROM_HERE, {content::BrowserThread::UI}, + if (!m_printSettings.empty() || !filePath.length()) { + content::GetUIThreadTaskRunner({})->PostTask(FROM_HERE, base::BindOnce(std::move(callback), false)); return; } @@ -189,7 +188,7 @@ void PrintViewManagerQt::PrintToPDFFileWithCallback(const QPageLayout &pageLayou m_pdfOutputPath = toFilePath(filePath); m_pdfSaveCallback = std::move(callback); if (!PrintToPDFInternal(pageLayout, pageRanges, printInColor)) { - base::PostTask(FROM_HERE, {content::BrowserThread::UI}, + content::GetUIThreadTaskRunner({})->PostTask(FROM_HERE, base::BindOnce(std::move(m_pdfSaveCallback), false)); resetPdfState(); } @@ -205,15 +204,15 @@ void PrintViewManagerQt::PrintToPDFWithCallback(const QPageLayout &pageLayout, return; // If there already is a pending print in progress, don't try starting another one. - if (m_printSettings) { - base::PostTask(FROM_HERE, {content::BrowserThread::UI}, + if (!m_printSettings.empty()) { + content::GetUIThreadTaskRunner({})->PostTask(FROM_HERE, base::BindOnce(std::move(callback), QSharedPointer())); return; } m_pdfPrintCallback = std::move(callback); if (!PrintToPDFInternal(pageLayout, pageRanges, printInColor, useCustomMargins)) { - base::PostTask(FROM_HERE, {content::BrowserThread::UI}, + content::GetUIThreadTaskRunner({})->PostTask(FROM_HERE, base::BindOnce(std::move(m_pdfPrintCallback), QSharedPointer())); resetPdfState(); @@ -228,14 +227,13 @@ bool PrintViewManagerQt::PrintToPDFInternal(const QPageLayout &pageLayout, if (!pageLayout.isValid()) return false; - m_printSettings.reset(createPrintSettingsFromQPageLayout(pageLayout, useCustomMargins)); - m_printSettings->SetBoolean(printing::kSettingShouldPrintBackgrounds, + m_printSettings = createPrintSettingsFromQPageLayout(pageLayout, useCustomMargins); + m_printSettings.Set(printing::kSettingShouldPrintBackgrounds, web_contents()->GetOrCreateWebPreferences().should_print_backgrounds); - m_printSettings->SetInteger(printing::kSettingColor, + m_printSettings.Set(printing::kSettingColor, int(printInColor ? printing::mojom::ColorModel::kColor : printing::mojom::ColorModel::kGrayscale)); if (!pageRanges.isEmpty()) - m_printSettings->Set(printing::kSettingPageRange, - std::unique_ptr(createPageRangeSettings(pageRanges.toRangeList()))); + m_printSettings.Set(printing::kSettingPageRange, createPageRangeSettings(pageRanges.toRangeList())); if (web_contents()->IsCrashed()) return false; @@ -274,7 +272,7 @@ void PrintViewManagerQt::resetPdfState() m_pdfOutputPath.clear(); m_pdfPrintCallback.Reset(); m_pdfSaveCallback.Reset(); - m_printSettings.reset(); + m_printSettings.clear(); } void PrintViewManagerQt::PrintPreviewDone() @@ -289,7 +287,7 @@ void PrintViewManagerQt::PrintPreviewDone() void PrintViewManagerQt::NavigationStopped() { if (!m_pdfPrintCallback.is_null()) { - base::PostTask(FROM_HERE, {content::BrowserThread::UI}, + content::GetUIThreadTaskRunner({})->PostTask(FROM_HERE, base::BindOnce(std::move(m_pdfPrintCallback), QSharedPointer())); } resetPdfState(); @@ -300,7 +298,7 @@ void PrintViewManagerQt::PrimaryMainFrameRenderProcessGone(base::TerminationStat { PrintViewManagerBaseQt::PrimaryMainFrameRenderProcessGone(status); if (!m_pdfPrintCallback.is_null()) { - base::PostTask(FROM_HERE, {content::BrowserThread::UI}, + content::GetUIThreadTaskRunner({})->PostTask(FROM_HERE, base::BindOnce(std::move(m_pdfPrintCallback), QSharedPointer())); } resetPdfState(); @@ -342,7 +340,7 @@ void PrintViewManagerQt::RequestPrintPreview(printing::mojom::RequestPrintPrevie { mojo::AssociatedRemote printRenderFrame; m_printPreviewRfh->GetRemoteAssociatedInterfaces()->GetInterface(&printRenderFrame); - printRenderFrame->PrintPreview(m_printSettings->Clone()); + printRenderFrame->PrintPreview(m_printSettings.Clone()); PrintPreviewDone(); } @@ -375,7 +373,7 @@ void PrintViewManagerQt::MetafileReadyForPrinting(printing::mojom::DidPreviewDoc if (!pdf_print_callback.is_null()) { QSharedPointer data_array = GetStdVectorFromHandle(params->content->metafile_data_region); - base::PostTask(FROM_HERE, {content::BrowserThread::UI}, + content::GetUIThreadTaskRunner({})->PostTask(FROM_HERE, base::BindOnce(std::move(pdf_print_callback), data_array)); } else { scoped_refptr data_bytes = GetBytesFromHandle(params->content->metafile_data_region); diff --git a/src/core/printing/print_view_manager_qt.h b/src/core/printing/print_view_manager_qt.h index 7d0894a0d..956849ef9 100644 --- a/src/core/printing/print_view_manager_qt.h +++ b/src/core/printing/print_view_manager_qt.h @@ -87,7 +87,7 @@ private: base::FilePath m_pdfOutputPath; PrintToPDFCallback m_pdfPrintCallback; PrintToPDFFileCallback m_pdfSaveCallback; - std::unique_ptr m_printSettings; + base::Value::Dict m_printSettings; friend class content::WebContentsUserData; }; diff --git a/src/core/profile_io_data_qt.cpp b/src/core/profile_io_data_qt.cpp index cd381afc5..c11d35c95 100644 --- a/src/core/profile_io_data_qt.cpp +++ b/src/core/profile_io_data_qt.cpp @@ -3,7 +3,6 @@ #include "profile_io_data_qt.h" -#include "base/task/post_task.h" #include "content/browser/storage_partition_impl.h" #include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_thread.h" diff --git a/src/core/quota_permission_context_qt.cpp b/src/core/quota_permission_context_qt.cpp index 5ace64b62..fe2a8433c 100644 --- a/src/core/quota_permission_context_qt.cpp +++ b/src/core/quota_permission_context_qt.cpp @@ -3,7 +3,6 @@ #include "quota_permission_context_qt.h" -#include "base/task/post_task.h" #include "content/browser/web_contents/web_contents_impl.h" #include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_thread.h" @@ -30,8 +29,7 @@ void QuotaPermissionContextQt::RequestQuotaPermission(const StorageQuotaParams & } if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { - base::PostTask( - FROM_HERE, {content::BrowserThread::UI}, + content::GetUIThreadTaskRunner({})->PostTask(FROM_HERE, base::BindOnce(&QuotaPermissionContextQt::RequestQuotaPermission, this, params, render_process_id, std::move(callback))); return; @@ -71,8 +69,7 @@ void QuotaPermissionContextQt::dispatchCallbackOnIOThread(PermissionCallback cal return; if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) { - base::PostTask( - FROM_HERE, {content::BrowserThread::IO}, + content::GetIOThreadTaskRunner({})->PostTask(FROM_HERE, base::BindOnce(&QuotaPermissionContextQt::dispatchCallbackOnIOThread, this, std::move(callback), response)); return; diff --git a/src/core/renderer/content_renderer_client_qt.cpp b/src/core/renderer/content_renderer_client_qt.cpp index 600b23f4b..cdb4fdf12 100644 --- a/src/core/renderer/content_renderer_client_qt.cpp +++ b/src/core/renderer/content_renderer_client_qt.cpp @@ -499,7 +499,7 @@ media::SupportedCodecs GetVP9Codecs(const std::vector } #if BUILDFLAG(ENABLE_PLATFORM_HEVC) -SupportedCodecs GetHevcCodecs(const std::vector &profiles) +media::SupportedCodecs GetHevcCodecs(const base::flat_set &profiles) { // If no profiles are specified, then all are supported. if (profiles.empty()) { @@ -592,6 +592,8 @@ static void AddWidevine(const media::mojom::KeySystemCapabilityPtr &capability, media::SupportedCodecs hw_secure_codecs = media::EME_CODEC_NONE; base::flat_set encryption_schemes; base::flat_set hw_secure_encryption_schemes; + base::flat_set session_types; + base::flat_set 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; @@ -620,16 +622,16 @@ static void AddWidevine(const media::mojom::KeySystemCapabilityPtr &capability, 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, + 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) diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp index 98128ee74..d6c3b37ad 100644 --- a/src/core/web_contents_adapter.cpp +++ b/src/core/web_contents_adapter.cpp @@ -28,7 +28,6 @@ #include "base/command_line.h" #include "base/metrics/user_metrics.h" #include "base/task/current_thread.h" -#include "base/task/post_task.h" #include "base/task/sequence_manager/sequence_manager_impl.h" #include "base/task/sequence_manager/thread_controller_with_message_pump_impl.h" #include "base/values.h" @@ -51,6 +50,7 @@ #include "content/public/browser/favicon_status.h" #include "content/public/common/content_switches.h" #include "content/public/common/drop_data.h" +#include "content/public/common/url_constants.h" #include "extensions/buildflags/buildflags.h" #include "third_party/blink/public/common/page/page_zoom.h" #include "third_party/blink/public/common/page_state/page_state.h" @@ -489,7 +489,7 @@ void WebContentsAdapter::initialize(content::SiteInstance *site) AutofillClientQt::CreateForWebContents(webContents()); autofill::ContentAutofillDriverFactory::CreateForWebContentsAndDelegate( webContents(), AutofillClientQt::FromWebContents(webContents()), - /* app_locale = */ "", autofill::AutofillManager::DISABLE_AUTOFILL_DOWNLOAD_MANAGER); + base::BindRepeating(&autofill::BrowserDriverInitHook, AutofillClientQt::FromWebContents(webContents()), "")); #if QT_CONFIG(webengine_printing_and_pdf) && QT_CONFIG(webengine_extensions) pdf::PDFWebContentsHelper::CreateForWebContentsWithClient( @@ -710,7 +710,7 @@ void WebContentsAdapter::load(const QWebEngineHttpRequest &request) if (resizeNeeded) { // Schedule navigation on the event loop. - base::PostTask(FROM_HERE, {content::BrowserThread::UI}, + content::GetUIThreadTaskRunner({})->PostTask(FROM_HERE, base::BindOnce(&NavigateTask, sharedFromThis().toWeakRef(), std::move(params))); } else { Navigate(this, params); diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp index 66598203e..9544ca55e 100644 --- a/src/core/web_contents_delegate_qt.cpp +++ b/src/core/web_contents_delegate_qt.cpp @@ -48,6 +48,7 @@ #include "content/public/common/url_constants.h" #include "net/base/data_url.h" #include "net/base/url_util.h" +#include "third_party/blink/public/mojom/mediastream/media_stream.mojom.h" #include #include @@ -879,22 +880,36 @@ int &WebContentsDelegateQt::streamCount(blink::mojom::MediaStreamType type) return m_videoStreamCount; } -void WebContentsDelegateQt::addDevices(const blink::MediaStreamDevices &devices) +void WebContentsDelegateQt::addDevices(const blink::mojom::StreamDevices &devices) { - for (const auto &device : devices) - ++streamCount(device.type); + if (devices.audio_device.has_value()) + addDevice(devices.audio_device.value()); + if (devices.video_device.has_value()) + addDevice(devices.video_device.value()); webContentsAdapter()->updateRecommendedState(); } -void WebContentsDelegateQt::removeDevices(const blink::MediaStreamDevices &devices) +void WebContentsDelegateQt::removeDevices(const blink::mojom::StreamDevices &devices) { - for (const auto &device : devices) - ++streamCount(device.type); + if (devices.audio_device.has_value()) + removeDevice(devices.audio_device.value()); + if (devices.video_device.has_value()) + removeDevice(devices.video_device.value()); webContentsAdapter()->updateRecommendedState(); } +void WebContentsDelegateQt::addDevice(const blink::MediaStreamDevice &device) +{ + ++streamCount(device.type); +} + +void WebContentsDelegateQt::removeDevice(const blink::MediaStreamDevice &device) +{ + --streamCount(device.type); +} + FrameFocusedObserver::FrameFocusedObserver(WebContentsAdapterClient *adapterClient) : m_viewClient(adapterClient) {} diff --git a/src/core/web_contents_delegate_qt.h b/src/core/web_contents_delegate_qt.h index 37ab7ef5d..0840fbc45 100644 --- a/src/core/web_contents_delegate_qt.h +++ b/src/core/web_contents_delegate_qt.h @@ -150,8 +150,10 @@ public: using LoadingState = WebContentsAdapterClient::LoadingState; LoadingState loadingState() const { return m_loadingState; } - void addDevices(const blink::MediaStreamDevices &devices); - void removeDevices(const blink::MediaStreamDevices &devices); + void addDevices(const blink::mojom::StreamDevices &devices); + void removeDevices(const blink::mojom::StreamDevices &devices); + void addDevice(const blink::MediaStreamDevice &device); + void removeDevice(const blink::MediaStreamDevice &device); bool isCapturingAudio() const { return m_audioStreamCount > 0; } bool isCapturingVideo() const { return m_videoStreamCount > 0; } diff --git a/src/core/web_engine_context.cpp b/src/core/web_engine_context.cpp index f6c60daf3..f3226939f 100644 --- a/src/core/web_engine_context.cpp +++ b/src/core/web_engine_context.cpp @@ -13,7 +13,6 @@ #include "base/power_monitor/power_monitor_device_source.h" #include "base/run_loop.h" #include "base/strings/string_split.h" -#include "base/task/post_task.h" #include "base/task/sequence_manager/thread_controller_with_message_pump_impl.h" #include "base/task/thread_pool/thread_pool_instance.h" #include "base/threading/thread_restrictions.h" @@ -756,7 +755,7 @@ WebEngineContext::WebEngineContext() m_mainDelegate->PreBrowserMain(); base::MessagePump::OverrideMessagePumpForUIFactory(messagePumpFactory); content::BrowserTaskExecutor::Create(); - m_mainDelegate->PostEarlyInitialization(false); + m_mainDelegate->PostEarlyInitialization({}); content::StartBrowserThreadPool(); content::BrowserTaskExecutor::PostFeatureListSetup(); tracing::InitTracingPostThreadPoolStartAndFeatureList(false); diff --git a/src/core/web_engine_context.h b/src/core/web_engine_context.h index f7dbd1e53..6819d06f0 100644 --- a/src/core/web_engine_context.h +++ b/src/core/web_engine_context.h @@ -21,7 +21,6 @@ class CommandLine; namespace content { class BrowserMainRunner; class ContentMainRunner; -class GpuProcess; class GpuThreadController; class InProcessChildThreadParams; class MojoIpcSupport; diff --git a/src/core/web_engine_context_threads.cpp b/src/core/web_engine_context_threads.cpp index 2d0f8a90c..5e969fb98 100644 --- a/src/core/web_engine_context_threads.cpp +++ b/src/core/web_engine_context_threads.cpp @@ -4,14 +4,14 @@ #include "web_engine_context.h" #include "base/bind.h" -#include "base/task/post_task.h" +#include "base/task/thread_pool.h" #include "base/threading/platform_thread.h" #include "base/threading/thread_restrictions.h" #include "content/browser/gpu/gpu_main_thread_factory.h" #include "content/browser/renderer_host/render_process_host_impl.h" #include "content/browser/utility_process_host.h" +#include "content/child/child_process.h" #include "content/gpu/gpu_child_thread.h" -#include "content/gpu/gpu_process.h" #include "content/gpu/in_process_gpu_thread.h" #include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_thread.h" @@ -29,14 +29,14 @@ struct GpuThreadControllerQt : content::GpuThreadController { GpuThreadControllerQt(const content::InProcessChildThreadParams ¶ms, const gpu::GpuPreferences &gpuPreferences) { - base::PostTask( - FROM_HERE, { content::BrowserThread::UI }, + content::GetUIThreadTaskRunner({})->PostTask( + FROM_HERE, base::BindOnce(&GpuThreadControllerQt::createGpuProcess, params, gpuPreferences)); } ~GpuThreadControllerQt() override { - base::PostTask( - FROM_HERE, { content::BrowserThread::UI }, + content::GetUIThreadTaskRunner({})->PostTask( + FROM_HERE, base::BindOnce(&GpuThreadControllerQt::destroyGpuProcess)); } @@ -48,7 +48,7 @@ struct GpuThreadControllerQt : content::GpuThreadController if (s_gpuProcessDestroyed) return; - s_gpuProcess = std::make_unique(base::ThreadPriority::NORMAL); + s_gpuProcess = std::make_unique(base::ThreadPriority::NORMAL); auto gpuInit = std::make_unique(); gpuInit->InitializeInProcess(base::CommandLine::ForCurrentProcess(), gpuPreferences); auto childThread = new content::GpuChildThread(params, std::move(gpuInit)); @@ -68,11 +68,11 @@ struct GpuThreadControllerQt : content::GpuThreadController s_gpuProcessDestroyed = true; } - static std::unique_ptr s_gpuProcess; + static std::unique_ptr s_gpuProcess; static bool s_gpuProcessDestroyed; }; -std::unique_ptr GpuThreadControllerQt::s_gpuProcess; +std::unique_ptr GpuThreadControllerQt::s_gpuProcess; bool GpuThreadControllerQt::s_gpuProcessDestroyed = false; static std::unique_ptr createGpuThreadController( -- cgit v1.2.3