summaryrefslogtreecommitdiffstats
path: root/src/core/printing/print_view_manager_base_qt.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/printing/print_view_manager_base_qt.cpp')
-rw-r--r--src/core/printing/print_view_manager_base_qt.cpp190
1 files changed, 76 insertions, 114 deletions
diff --git a/src/core/printing/print_view_manager_base_qt.cpp b/src/core/printing/print_view_manager_base_qt.cpp
index a170c95ba..3af6ecf44 100644
--- a/src/core/printing/print_view_manager_base_qt.cpp
+++ b/src/core/printing/print_view_manager_base_qt.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebEngine module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 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
// This is based on chrome/browser/printing/print_view_manager_base.cc:
// Copyright 2013 The Chromium Authors. All rights reserved.
@@ -49,7 +13,6 @@
#include "base/memory/ref_counted_memory.h"
#include "base/run_loop.h"
-#include "base/single_thread_task_runner.h"
#include "base/task/current_thread.h"
#include "base/task/post_task.h"
#include "base/timer/timer.h"
@@ -90,7 +53,7 @@ void GetDefaultPrintSettingsReplyOnIO(scoped_refptr<printing::PrintQueriesQueue>
{
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
printing::mojom::PrintParamsPtr params = printing::mojom::PrintParams::New();
- if (printer_query && printer_query->last_status() == printing::PrintingContext::OK) {
+ if (printer_query && printer_query->last_status() == printing::mojom::ResultCode::kSuccess) {
RenderParamsFromPrintSettings(printer_query->settings(), params.get());
params->document_cookie = printer_query->cookie();
}
@@ -113,22 +76,29 @@ void GetDefaultPrintSettingsReplyOnIO(scoped_refptr<printing::PrintQueriesQueue>
void GetDefaultPrintSettingsOnIO(printing::mojom::PrintManagerHost::GetDefaultPrintSettingsCallback callback,
scoped_refptr<printing::PrintQueriesQueue> queue,
- int process_id, int routing_id)
+ bool is_modifiable,
+ content::GlobalRenderFrameHostId rfh_id)
{
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
std::unique_ptr<printing::PrinterQuery> printer_query = queue->PopPrinterQuery(0);
if (!printer_query)
- printer_query = queue->CreatePrinterQuery(process_id, routing_id);
+ 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->GetSettings(
- printing::PrinterQuery::GetSettingsAskParam::DEFAULTS, 0, false,
- printing::mojom::MarginType::kDefaultMargins, false, false,
- base::BindOnce(&GetDefaultPrintSettingsReplyOnIO, queue,
- std::move(printer_query), std::move(callback)));
+ 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();
+ params->params = printing::mojom::PrintParams::New();
+ return params;
}
// Runs |callback| with |params| to reply to
@@ -137,11 +107,8 @@ void UpdatePrintSettingsReply(printing::mojom::PrintManagerHost::UpdatePrintSett
printing::mojom::PrintPagesParamsPtr params, bool canceled)
{
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- if (!params) {
- // Fills |params| with initial values.
- params = printing::mojom::PrintPagesParams::New();
- params->params = printing::mojom::PrintParams::New();
- }
+ if (!params)
+ params = CreateEmptyPrintPagesParamsPtr();
std::move(callback).Run(std::move(params), canceled);
}
@@ -154,12 +121,12 @@ void UpdatePrintSettingsReplyOnIO(scoped_refptr<printing::PrintQueriesQueue> que
DCHECK(printer_query);
auto params = printing::mojom::PrintPagesParams::New();
params->params = printing::mojom::PrintParams::New();
- if (printer_query->last_status() == printing::PrintingContext::OK) {
+ 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());
}
- bool canceled = printer_query->last_status() == printing::PrintingContext::CANCEL;
+ bool canceled = printer_query->last_status() == printing::mojom::ResultCode::kAccessDenied;
content::GetUIThreadTaskRunner({})->PostTask(
FROM_HERE,
@@ -175,13 +142,13 @@ void UpdatePrintSettingsReplyOnIO(scoped_refptr<printing::PrintQueriesQueue> que
void UpdatePrintSettingsOnIO(int32_t cookie,
printing::mojom::PrintManagerHost::UpdatePrintSettingsCallback callback,
scoped_refptr<printing::PrintQueriesQueue> queue,
- base::Value job_settings,
+ base::Value::Dict job_settings,
int process_id, int routing_id)
{
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
std::unique_ptr<printing::PrinterQuery> printer_query = queue->PopPrinterQuery(cookie);
if (!printer_query)
- printer_query = queue->CreatePrinterQuery(content::ChildProcessHost::kInvalidUniqueID, MSG_ROUTING_NONE);
+ printer_query = queue->CreatePrinterQuery(content::GlobalRenderFrameHostId());
auto *printer_query_ptr = printer_query.get();
printer_query_ptr->SetSettings(
@@ -191,37 +158,13 @@ void UpdatePrintSettingsOnIO(int32_t cookie,
process_id, routing_id));
}
-// Runs |callback| with |params| to reply to
-// mojom::PrintManagerHost::ScriptedPrint.
-void ScriptedPrintReply(printing::mojom::PrintManagerHost::ScriptedPrintCallback callback,
- printing::mojom::PrintPagesParamsPtr params,
- int process_id)
-{
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
-
- if (!content::RenderProcessHost::FromID(process_id)) {
- // Early return if the renderer is not alive.
- return;
- }
-
- if (!params) {
- // Fills |params| with initial values.
- params = printing::mojom::PrintPagesParams::New();
- params->params = printing::mojom::PrintParams::New();
- }
- std::move(callback).Run(std::move(params));
-}
-
void ScriptedPrintReplyOnIO(scoped_refptr<printing::PrintQueriesQueue> queue,
std::unique_ptr<printing::PrinterQuery> printer_query,
- printing::mojom::PrintManagerHost::ScriptedPrintCallback callback,
- int process_id)
+ printing::mojom::PrintManagerHost::ScriptedPrintCallback callback)
{
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
- auto params = printing::mojom::PrintPagesParams::New();
- params->params = printing::mojom::PrintParams::New();
- if (printer_query->last_status() == printing::PrintingContext::OK &&
- printer_query->settings().dpi()) {
+ 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());
@@ -229,8 +172,7 @@ void ScriptedPrintReplyOnIO(scoped_refptr<printing::PrintQueriesQueue> queue,
bool has_valid_cookie = params->params->document_cookie;
bool has_dpi = !params->params->dpi.IsEmpty();
content::GetUIThreadTaskRunner({})->PostTask(
- FROM_HERE, base::BindOnce(&ScriptedPrintReply, std::move(callback),
- std::move(params), process_id));
+ FROM_HERE, base::BindOnce(std::move(callback), std::move(params)));
if (has_dpi && has_valid_cookie) {
queue->QueuePrinterQuery(std::move(printer_query));
@@ -242,22 +184,20 @@ void ScriptedPrintReplyOnIO(scoped_refptr<printing::PrintQueriesQueue> queue,
void ScriptedPrintOnIO(printing::mojom::ScriptedPrintParamsPtr params,
printing::mojom::PrintManagerHost::ScriptedPrintCallback callback,
scoped_refptr<printing::PrintQueriesQueue> queue,
- int process_id,
- int routing_id)
+ bool is_modifiable,
+ content::GlobalRenderFrameHostId rfh_id)
{
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
std::unique_ptr<printing::PrinterQuery> printer_query = queue->PopPrinterQuery(params->cookie);
if (!printer_query)
- printer_query = queue->CreatePrinterQuery(process_id, routing_id);
+ printer_query = queue->CreatePrinterQuery(rfh_id);
auto *printer_query_ptr = printer_query.get();
- printer_query_ptr->GetSettings(
- printing::PrinterQuery::GetSettingsAskParam::ASK_USER, params->expected_pages_count,
- params->has_selection, params->margin_type, params->is_scripted,
- params->is_modifiable,
- base::BindOnce(&ScriptedPrintReplyOnIO, queue, std::move(printer_query),
- std::move(callback), process_id));
+ 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
@@ -285,6 +225,25 @@ void PrintViewManagerBaseQt::SetPrintingRFH(content::RenderFrameHost *rfh)
m_printingRFH = rfh;
}
+void PrintViewManagerBaseQt::ScriptedPrintReply(ScriptedPrintCallback callback,
+ int process_id,
+ printing::mojom::PrintPagesParamsPtr params) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+
+#if BUILDFLAG(ENABLE_OOP_PRINTING)
+ // Finished getting all settings (defaults and from user), no further need
+ // to be registered as a system print client.
+ UnregisterSystemPrintClient();
+#endif
+ if (!content::RenderProcessHost::FromID(process_id)) {
+ // Early return if the renderer is not alive.
+ return;
+ }
+
+// set_cookie(params->params->document_cookie);
+ std::move(callback).Run(std::move(params));
+}
+
void PrintViewManagerBaseQt::UpdatePrintingEnabled()
{
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
@@ -371,14 +330,15 @@ void PrintViewManagerBaseQt::DidPrintDocument(printing::mojom::DidPrintDocumentP
void PrintViewManagerBaseQt::GetDefaultPrintSettings(GetDefaultPrintSettingsCallback callback)
{
- content::RenderFrameHost* render_frame_host =
- print_manager_host_receivers_.GetCurrentTargetFrame();
-
+ content::RenderFrameHost *render_frame_host =
+ 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_frame_host->GetProcess()->GetID(),
- render_frame_host->GetRoutingID()));
+ !render_process_host->IsPdf(),
+ render_frame_host->GetGlobalId()));
}
void PrintViewManagerBaseQt::PrintingFailed(int32_t cookie)
@@ -399,12 +359,16 @@ void PrintViewManagerBaseQt::ScriptedPrint(printing::mojom::ScriptedPrintParamsP
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
content::RenderFrameHost *render_frame_host =
print_manager_host_receivers_.GetCurrentTargetFrame();
+ content::RenderProcessHost *render_process_host =
+ render_frame_host->GetProcess();
+ 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),
- m_printerQueriesQueue, render_frame_host->GetProcess()->GetID(),
- render_frame_host->GetRoutingID()));
+ base::BindOnce(&ScriptedPrintOnIO, std::move(params), std::move(callback_wrapper),
+ m_printerQueriesQueue, !render_process_host->IsPdf(), render_frame_host->GetGlobalId()));
}
void PrintViewManagerBaseQt::ShowInvalidPrinterSettingsError()
@@ -464,9 +428,6 @@ void PrintViewManagerBaseQt::OnNotifyPrintJobEvent(const printing::JobEventDetai
// break;
// }
case printing::JobEventDetails::NEW_DOC:
-#if defined(OS_WIN)
- case printing::JobEventDetails::PAGE_DONE:
-#endif
case printing::JobEventDetails::DOC_DONE: {
// Don't care about the actual printing process.
break;
@@ -501,8 +462,8 @@ bool PrintViewManagerBaseQt::RenderAllMissingPagesNow()
// We can't print if there is no renderer.
if (!web_contents() ||
- !web_contents()->GetRenderViewHost() ||
- !web_contents()->GetRenderViewHost()->IsRenderViewLive()) {
+ !web_contents()->GetMainFrame() ||
+ !web_contents()->GetMainFrame()->IsRenderFrameLive()) {
return false;
}
@@ -544,8 +505,8 @@ bool PrintViewManagerBaseQt::CreateNewPrintJob(std::unique_ptr<printing::Printer
DisconnectFromCurrentPrintJob();
// We can't print if there is no renderer.
- if (!web_contents()->GetRenderViewHost() ||
- !web_contents()->GetRenderViewHost()->IsRenderViewLive()) {
+ if (!web_contents()->GetMainFrame() ||
+ !web_contents()->GetMainFrame()->IsRenderFrameLive()) {
return false;
}
@@ -553,7 +514,7 @@ bool PrintViewManagerBaseQt::CreateNewPrintJob(std::unique_ptr<printing::Printer
// view and switch to it, initialize the printer and show the print dialog.
DCHECK(!m_printJob.get());
- m_printJob = base::MakeRefCounted<printing::PrintJob>();
+ m_printJob = base::MakeRefCounted<printing::PrintJob>(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<printing::PrintJob>(m_printJob.get()));
@@ -635,7 +596,7 @@ bool PrintViewManagerBaseQt::RunInnerMessageLoop()
base::OneShotTimer quit_timer;
base::RunLoop run_loop;
quit_timer.Start(FROM_HERE,
- base::TimeDelta::FromMilliseconds(kPrinterSettingsTimeout),
+ base::Milliseconds(kPrinterSettingsTimeout),
run_loop.QuitWhenIdleClosure());
m_quitInnerLoop = run_loop.QuitClosure();
@@ -718,15 +679,16 @@ void PrintViewManagerBaseQt::StopWorker(int documentCookie)
void PrintViewManagerBaseQt::SendPrintingEnabled(bool enabled, content::RenderFrameHost* rfh)
{
- GetPrintRenderFrame(rfh)->SetPrintingEnabled(enabled);
+ if (rfh->IsRenderFrameLive())
+ GetPrintRenderFrame(rfh)->SetPrintingEnabled(enabled);
}
-void PrintViewManagerBaseQt::UpdatePrintSettings(int32_t cookie, base::Value job_settings,
+void PrintViewManagerBaseQt::UpdatePrintSettings(int32_t cookie, base::Value::Dict job_settings,
UpdatePrintSettingsCallback callback)
{
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- if (!job_settings.FindIntKey(printing::kSettingPrinterType)) {
+ if (!job_settings.FindInt(printing::kSettingPrinterType)) {
UpdatePrintSettingsReply(std::move(callback), nullptr, false);
return;
}