#include "chrome/browser/printing/print_job_worker.h"
#include <memory>
#include <string>
#include <utility>
#include "base/compiler_specific.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/numerics/safe_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/printing/print_job.h"
#include "chrome/grit/generated_resources.h"
#include "components/device_event_log/device_event_log.h"
#include "components/enterprise/buildflags/buildflags.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/global_routing_id.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "printing/mojom/print.mojom.h"
#include "printing/print_job_constants.h"
#include "printing/printed_document.h"
#include "printing/printing_context.h"
#include "printing/printing_utils.h"
#include "ui/base/l10n/l10n_util.h"
#if BUILDFLAG(IS_WIN)
#include "base/threading/thread_restrictions.h"
#include "chrome/browser/printing/xps_features.h"
#include "printing/printed_page_win.h"
#endif
BrowserThread;
namespace printing {
namespace {
void DocDoneNotificationCallback(PrintJob* print_job,
int job_id,
PrintedDocument* document) { … }
void FailedNotificationCallback(PrintJob* print_job) { … }
}
PrintJobWorker::PrintJobWorker(
std::unique_ptr<PrintingContext::Delegate> printing_context_delegate,
std::unique_ptr<PrintingContext> printing_context,
PrintJob* print_job)
: … { … }
PrintJobWorker::~PrintJobWorker() { … }
bool PrintJobWorker::StartPrintingSanityCheck(
const PrintedDocument* new_document) const { … }
std::u16string PrintJobWorker::GetDocumentName(
const PrintedDocument* new_document) const { … }
bool PrintJobWorker::SetupDocument(const std::u16string& document_name) { … }
void PrintJobWorker::StartPrinting(PrintedDocument* new_document) { … }
void PrintJobWorker::OnDocumentChanged(PrintedDocument* new_document) { … }
void PrintJobWorker::PostWaitForPage() { … }
void PrintJobWorker::OnNewPage() { … }
#if BUILDFLAG(IS_WIN)
bool PrintJobWorker::OnNewPageHelperGdi() {
if (page_number_ == PageNumber::npos()) {
int page_count = document_->page_count();
if (!page_count) {
return false;
}
page_number_.Init(document_->settings().ranges(), page_count);
}
while (true) {
scoped_refptr<PrintedPage> page = document_->GetPage(page_number_.ToUint());
if (!page) {
PostWaitForPage();
return false;
}
if (!SpoolPage(page.get()))
return false;
++page_number_;
if (page_number_ == PageNumber::npos())
break;
}
return true;
}
#endif
void PrintJobWorker::Cancel() { … }
#if BUILDFLAG(ENTERPRISE_CONTENT_ANALYSIS)
void PrintJobWorker::CleanupAfterContentAnalysisDenial() { … }
#endif
bool PrintJobWorker::IsRunning() const { … }
bool PrintJobWorker::PostTask(const base::Location& from_here,
base::OnceClosure task) { … }
void PrintJobWorker::StopSoon() { … }
void PrintJobWorker::Stop() { … }
bool PrintJobWorker::Start() { … }
void PrintJobWorker::CheckDocumentSpoolingComplete() { … }
void PrintJobWorker::OnDocumentDone() { … }
void PrintJobWorker::FinishDocumentDone(int job_id) { … }
#if BUILDFLAG(IS_WIN)
bool PrintJobWorker::SpoolPage(PrintedPage* page) {
DCHECK(task_runner_->RunsTasksInCurrentSequence());
DCHECK_NE(page_number_, PageNumber::npos());
if (document_->RenderPrintedPage(*page, printing_context_.get()) !=
mojom::ResultCode::kSuccess) {
OnFailure();
return false;
}
DCHECK(print_job_);
print_job_->PostTask(FROM_HERE,
base::BindOnce(&PrintJob::OnPageDone, print_job_,
base::RetainedRef(page)));
return true;
}
#endif
bool PrintJobWorker::SpoolDocument() { … }
void PrintJobWorker::OnCancel() { … }
void PrintJobWorker::OnFailure() { … }
}