printing.patch 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Shelley Vohr <[email protected]>
  3. Date: Fri, 7 Jun 2019 13:59:37 -0700
  4. Subject: printing.patch
  5. Add changeset that was previously applied to sources in chromium_src. The
  6. majority of changes originally come from these PRs:
  7. * https://github.com/electron/electron/pull/1835
  8. * https://github.com/electron/electron/pull/8596
  9. This patch also fixes callback for manual user cancellation and success.
  10. diff --git a/BUILD.gn b/BUILD.gn
  11. index ad4b830fa0932340b7c6b45d94ebf49afb4b7f73..4acc0a5befd0da25460de37eef7c4aabfd291659 100644
  12. --- a/BUILD.gn
  13. +++ b/BUILD.gn
  14. @@ -964,7 +964,6 @@ if (is_win) {
  15. "//media:media_unittests",
  16. "//media/midi:midi_unittests",
  17. "//net:net_unittests",
  18. - "//printing:printing_unittests",
  19. "//sql:sql_unittests",
  20. "//third_party/breakpad:symupload($host_toolchain)",
  21. "//ui/base:ui_base_unittests",
  22. @@ -973,6 +972,10 @@ if (is_win) {
  23. "//ui/views:views_unittests",
  24. "//url:url_unittests",
  25. ]
  26. +
  27. + if (enable_printing) {
  28. + deps += [ "//printing:printing_unittests" ]
  29. + }
  30. }
  31. }
  32. diff --git a/chrome/browser/printing/print_job.cc b/chrome/browser/printing/print_job.cc
  33. index 57c9c4408946066cd89304d50798a3719c8012d5..1c44d16c792a497623333ee4cb89005e59b8e529 100644
  34. --- a/chrome/browser/printing/print_job.cc
  35. +++ b/chrome/browser/printing/print_job.cc
  36. @@ -92,6 +92,7 @@ bool PrintWithReducedRasterization(PrefService* prefs) {
  37. return base::FeatureList::IsEnabled(features::kPrintWithReducedRasterization);
  38. }
  39. +#if 0
  40. PrefService* GetPrefsForWebContents(content::WebContents* web_contents) {
  41. // TODO(thestig): Figure out why crbug.com/1083911 occurred, which is likely
  42. // because `web_contents` was null. As a result, this section has many more
  43. @@ -106,6 +107,7 @@ content::WebContents* GetWebContents(content::GlobalRenderFrameHostId rfh_id) {
  44. auto* rfh = content::RenderFrameHost::FromID(rfh_id);
  45. return rfh ? content::WebContents::FromRenderFrameHost(rfh) : nullptr;
  46. }
  47. +#endif
  48. #endif // BUILDFLAG(IS_WIN)
  49. @@ -146,10 +148,8 @@ void PrintJob::Initialize(std::unique_ptr<PrinterQuery> query,
  50. #if BUILDFLAG(IS_WIN)
  51. pdf_page_mapping_ = PageNumber::GetPages(settings->ranges(), page_count);
  52. - PrefService* prefs = GetPrefsForWebContents(GetWebContents(rfh_id_));
  53. - if (prefs && prefs->IsManagedPreference(prefs::kPdfUseSkiaRendererEnabled)) {
  54. - use_skia_ = prefs->GetBoolean(prefs::kPdfUseSkiaRendererEnabled);
  55. - }
  56. + // TODO(codebytere): should we enable this later?
  57. + use_skia_ = false;
  58. #endif
  59. auto new_doc = base::MakeRefCounted<PrintedDocument>(std::move(settings),
  60. @@ -386,8 +386,10 @@ void PrintJob::StartPdfToEmfConversion(
  61. const PrintSettings& settings = document()->settings();
  62. +#if 0
  63. PrefService* prefs = GetPrefsForWebContents(GetWebContents(rfh_id_));
  64. - bool print_with_reduced_rasterization = PrintWithReducedRasterization(prefs);
  65. +#endif
  66. + bool print_with_reduced_rasterization = PrintWithReducedRasterization(nullptr);
  67. using RenderMode = PdfRenderSettings::Mode;
  68. RenderMode mode = print_with_reduced_rasterization
  69. @@ -479,8 +481,10 @@ void PrintJob::StartPdfToPostScriptConversion(
  70. if (ps_level2) {
  71. mode = PdfRenderSettings::Mode::POSTSCRIPT_LEVEL2;
  72. } else {
  73. +#if 0
  74. PrefService* prefs = GetPrefsForWebContents(GetWebContents(rfh_id_));
  75. - mode = PrintWithPostScriptType42Fonts(prefs)
  76. +#endif
  77. + mode = PrintWithPostScriptType42Fonts(nullptr)
  78. ? PdfRenderSettings::Mode::POSTSCRIPT_LEVEL3_WITH_TYPE42_FONTS
  79. : PdfRenderSettings::Mode::POSTSCRIPT_LEVEL3;
  80. }
  81. diff --git a/chrome/browser/printing/print_view_manager_base.cc b/chrome/browser/printing/print_view_manager_base.cc
  82. index f4ca9223cab8dc6c44af5015004c06568a6ca586..9a4718534106f0121494a01ee71d53bc3784daed 100644
  83. --- a/chrome/browser/printing/print_view_manager_base.cc
  84. +++ b/chrome/browser/printing/print_view_manager_base.cc
  85. @@ -22,7 +22,9 @@
  86. #include "build/chromeos_buildflags.h"
  87. #include "chrome/browser/bad_message.h"
  88. #include "chrome/browser/browser_process.h"
  89. +#if 0 // Electron does not use Chrome error dialogs
  90. #include "chrome/browser/printing/print_error_dialog.h"
  91. +#endif
  92. #include "chrome/browser/printing/print_job.h"
  93. #include "chrome/browser/printing/print_job_manager.h"
  94. #include "chrome/browser/printing/print_view_manager_common.h"
  95. @@ -80,6 +82,20 @@ namespace printing {
  96. namespace {
  97. +std::string PrintReasonFromPrintStatus(PrintViewManager::PrintStatus status) {
  98. + if (status == PrintViewManager::PrintStatus::kInvalid) {
  99. + return "Invalid printer settings";
  100. + } else if (status == PrintViewManager::PrintStatus::kCanceled) {
  101. + return "Print job canceled";
  102. + } else if (status == PrintViewManager::PrintStatus::kFailed) {
  103. + return "Print job failed";
  104. + }
  105. + return "";
  106. +}
  107. +
  108. +using PrintSettingsCallback =
  109. + base::OnceCallback<void(std::unique_ptr<PrinterQuery>)>;
  110. +
  111. void OnDidGetDefaultPrintSettings(
  112. scoped_refptr<PrintQueriesQueue> queue,
  113. bool want_pdf_settings,
  114. @@ -88,9 +104,11 @@ void OnDidGetDefaultPrintSettings(
  115. DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
  116. if (printer_query->last_status() != mojom::ResultCode::kSuccess) {
  117. +#if 0 // Electron does not use Chrome error dialogs
  118. if (!want_pdf_settings) {
  119. ShowPrintErrorDialogForInvalidPrinterError();
  120. }
  121. +#endif
  122. std::move(callback).Run(nullptr);
  123. return;
  124. }
  125. @@ -100,9 +118,11 @@ void OnDidGetDefaultPrintSettings(
  126. params->document_cookie = printer_query->cookie();
  127. if (!PrintMsgPrintParamsIsValid(*params)) {
  128. +#if 0 // Electron does not use Chrome error dialogs
  129. if (!want_pdf_settings) {
  130. ShowPrintErrorDialogForInvalidPrinterError();
  131. }
  132. +#endif
  133. std::move(callback).Run(nullptr);
  134. return;
  135. }
  136. @@ -119,7 +139,8 @@ void OnDidScriptedPrint(
  137. if (printer_query->last_status() != mojom::ResultCode::kSuccess ||
  138. !printer_query->settings().dpi()) {
  139. - std::move(callback).Run(nullptr);
  140. + bool canceled = printer_query->last_status() == mojom::ResultCode::kCanceled;
  141. + std::move(callback).Run(nullptr, canceled);
  142. return;
  143. }
  144. @@ -129,12 +150,12 @@ void OnDidScriptedPrint(
  145. params->params.get());
  146. params->params->document_cookie = printer_query->cookie();
  147. if (!PrintMsgPrintParamsIsValid(*params->params)) {
  148. - std::move(callback).Run(nullptr);
  149. + std::move(callback).Run(nullptr, false);
  150. return;
  151. }
  152. params->pages = printer_query->settings().ranges();
  153. - std::move(callback).Run(std::move(params));
  154. + std::move(callback).Run(std::move(params), false);
  155. queue->QueuePrinterQuery(std::move(printer_query));
  156. }
  157. @@ -186,9 +207,11 @@ PrintViewManagerBase::PrintViewManagerBase(content::WebContents* web_contents)
  158. : PrintManager(web_contents),
  159. queue_(g_browser_process->print_job_manager()->queue()) {
  160. DCHECK(queue_);
  161. +#if 0 // Printing is always enabled.
  162. Profile* profile =
  163. Profile::FromBrowserContext(web_contents->GetBrowserContext());
  164. - printing_enabled_.Init(prefs::kPrintingEnabled, profile->GetPrefs());
  165. + printing_enabled_.Init(prefs::kPrintingEnabled, profile->GetPrefs());
  166. +#endif
  167. }
  168. PrintViewManagerBase::~PrintViewManagerBase() {
  169. @@ -211,12 +234,20 @@ void PrintViewManagerBase::DisableThirdPartyBlocking() {
  170. }
  171. #endif // BUILDFLAG(IS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
  172. -bool PrintViewManagerBase::PrintNow(content::RenderFrameHost* rfh) {
  173. +bool PrintViewManagerBase::PrintNow(content::RenderFrameHost* rfh,
  174. + bool silent,
  175. + base::Value::Dict settings,
  176. + CompletionCallback callback) {
  177. if (!StartPrintCommon(rfh)) {
  178. return false;
  179. }
  180. +#if 0
  181. CompletePrintNow(rfh);
  182. +#endif
  183. + callback_ = std::move(callback);
  184. +
  185. + GetPrintRenderFrame(rfh)->PrintRequestedPages(silent, std::move(settings));
  186. return true;
  187. }
  188. @@ -341,12 +372,13 @@ void PrintViewManagerBase::OnDidUpdatePrintableArea(
  189. }
  190. PRINTER_LOG(EVENT) << "Paper printable area updated for vendor id "
  191. << print_settings->requested_media().vendor_id;
  192. - CompleteUpdatePrintSettings(std::move(job_settings),
  193. + CompleteUpdatePrintSettings(nullptr /* printer_query */, std::move(job_settings),
  194. std::move(print_settings), std::move(callback));
  195. }
  196. #endif
  197. void PrintViewManagerBase::CompleteUpdatePrintSettings(
  198. + std::unique_ptr<PrinterQuery> printer_query,
  199. base::Value::Dict job_settings,
  200. std::unique_ptr<PrintSettings> print_settings,
  201. UpdatePrintSettingsCallback callback) {
  202. @@ -354,7 +386,8 @@ void PrintViewManagerBase::CompleteUpdatePrintSettings(
  203. settings->pages = GetPageRangesFromJobSettings(job_settings);
  204. settings->params = mojom::PrintParams::New();
  205. RenderParamsFromPrintSettings(*print_settings, settings->params.get());
  206. - settings->params->document_cookie = PrintSettings::NewCookie();
  207. + settings->params->document_cookie = printer_query ? printer_query->cookie()
  208. + : PrintSettings::NewCookie();
  209. if (!PrintMsgPrintParamsIsValid(*settings->params)) {
  210. mojom::PrinterType printer_type = static_cast<mojom::PrinterType>(
  211. *job_settings.FindInt(kSettingPrinterType));
  212. @@ -366,6 +399,10 @@ void PrintViewManagerBase::CompleteUpdatePrintSettings(
  213. return;
  214. }
  215. + if (printer_query && printer_query->cookie() && printer_query->settings().dpi()) {
  216. + queue_->QueuePrinterQuery(std::move(printer_query));
  217. + }
  218. +
  219. set_cookie(settings->params->document_cookie);
  220. std::move(callback).Run(std::move(settings));
  221. }
  222. @@ -504,7 +541,8 @@ void PrintViewManagerBase::GetDefaultPrintSettingsReply(
  223. void PrintViewManagerBase::ScriptedPrintReply(
  224. ScriptedPrintCallback callback,
  225. int process_id,
  226. - mojom::PrintPagesParamsPtr params) {
  227. + mojom::PrintPagesParamsPtr params,
  228. + bool canceled) {
  229. DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
  230. #if BUILDFLAG(ENABLE_OOP_PRINTING)
  231. @@ -519,12 +557,15 @@ void PrintViewManagerBase::ScriptedPrintReply(
  232. return;
  233. }
  234. + if (canceled)
  235. + UserInitCanceled();
  236. +
  237. if (params) {
  238. set_cookie(params->params->document_cookie);
  239. - std::move(callback).Run(std::move(params));
  240. + std::move(callback).Run(std::move(params), canceled);
  241. } else {
  242. set_cookie(PrintSettings::NewInvalidCookie());
  243. - std::move(callback).Run(nullptr);
  244. + std::move(callback).Run(nullptr, false);
  245. }
  246. }
  247. @@ -652,10 +693,12 @@ void PrintViewManagerBase::DidPrintDocument(
  248. void PrintViewManagerBase::GetDefaultPrintSettings(
  249. GetDefaultPrintSettingsCallback callback) {
  250. DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
  251. +#if 0 // Printing is always enabled.
  252. if (!printing_enabled_.GetValue()) {
  253. GetDefaultPrintSettingsReply(std::move(callback), nullptr);
  254. return;
  255. }
  256. +#endif
  257. #if BUILDFLAG(ENABLE_OOP_PRINTING)
  258. if (ShouldPrintJobOop() &&
  259. #if BUILDFLAG(ENABLE_PRINT_CONTENT_ANALYSIS)
  260. @@ -707,10 +750,12 @@ void PrintViewManagerBase::UpdatePrintSettings(
  261. base::Value::Dict job_settings,
  262. UpdatePrintSettingsCallback callback) {
  263. DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
  264. +#if 0 // Printing is always enabled.
  265. if (!printing_enabled_.GetValue()) {
  266. std::move(callback).Run(nullptr);
  267. return;
  268. }
  269. +#endif // Printing is always enabled.
  270. absl::optional<int> printer_type_value =
  271. job_settings.FindInt(kSettingPrinterType);
  272. @@ -721,6 +766,7 @@ void PrintViewManagerBase::UpdatePrintSettings(
  273. mojom::PrinterType printer_type =
  274. static_cast<mojom::PrinterType>(*printer_type_value);
  275. +#if 0 // Printing is always enabled.
  276. if (printer_type != mojom::PrinterType::kExtension &&
  277. printer_type != mojom::PrinterType::kPdf &&
  278. printer_type != mojom::PrinterType::kLocal) {
  279. @@ -740,6 +786,7 @@ void PrintViewManagerBase::UpdatePrintSettings(
  280. if (value > 0)
  281. job_settings.Set(kSettingRasterizePdfDpi, value);
  282. }
  283. +#endif // Printing is always enabled.
  284. std::unique_ptr<PrintSettings> print_settings =
  285. PrintSettingsFromJobSettings(job_settings);
  286. @@ -759,7 +806,21 @@ void PrintViewManagerBase::UpdatePrintSettings(
  287. }
  288. }
  289. -#if BUILDFLAG(IS_WIN)
  290. + std::unique_ptr<PrinterQuery> query =
  291. + queue_->CreatePrinterQuery(GetCurrentTargetFrame()->GetGlobalId());
  292. + auto* query_ptr = query.get();
  293. + // We need to clone this before calling SetSettings because some environments
  294. + // evaluate job_settings.Clone() first, and some std::move(job_settings) first,
  295. + // for the former things work correctly but for the latter the cloned value is null.
  296. + auto job_settings_copy = job_settings.Clone();
  297. + query_ptr->SetSettings(
  298. + std::move(job_settings_copy),
  299. + base::BindOnce(&PrintViewManagerBase::CompleteUpdatePrintSettings,
  300. + weak_ptr_factory_.GetWeakPtr(), std::move(query),
  301. + std::move(job_settings), std::move(print_settings),
  302. + std::move(callback)));
  303. +
  304. +#if 0 // See https://chromium-review.googlesource.com/412367
  305. // TODO(crbug.com/1424368): Remove this if the printable areas can be made
  306. // fully available from `PrintBackend::GetPrinterSemanticCapsAndDefaults()`
  307. // for in-browser queries.
  308. @@ -781,8 +842,6 @@ void PrintViewManagerBase::UpdatePrintSettings(
  309. }
  310. #endif
  311. - CompleteUpdatePrintSettings(std::move(job_settings),
  312. - std::move(print_settings), std::move(callback));
  313. }
  314. void PrintViewManagerBase::SetAccessibilityTree(
  315. @@ -798,7 +857,7 @@ void PrintViewManagerBase::SetAccessibilityTree(
  316. void PrintViewManagerBase::IsPrintingEnabled(
  317. IsPrintingEnabledCallback callback) {
  318. DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
  319. - std::move(callback).Run(printing_enabled_.GetValue());
  320. + std::move(callback).Run(true);
  321. }
  322. void PrintViewManagerBase::ScriptedPrint(mojom::ScriptedPrintParamsPtr params,
  323. @@ -814,13 +873,13 @@ void PrintViewManagerBase::ScriptedPrint(mojom::ScriptedPrintParamsPtr params,
  324. // didn't happen for some reason.
  325. bad_message::ReceivedBadMessage(
  326. render_process_host, bad_message::PVMB_SCRIPTED_PRINT_FENCED_FRAME);
  327. - std::move(callback).Run(nullptr);
  328. + std::move(callback).Run(nullptr, false);
  329. return;
  330. }
  331. #if BUILDFLAG(ENABLE_OOP_PRINTING)
  332. if (ShouldPrintJobOop() && !query_with_ui_client_id_.has_value()) {
  333. // Renderer process has requested settings outside of the expected setup.
  334. - std::move(callback).Run(nullptr);
  335. + std::move(callback).Run(nullptr, false);
  336. return;
  337. }
  338. #endif
  339. @@ -862,6 +921,7 @@ void PrintViewManagerBase::PrintingFailed(int32_t cookie,
  340. PrintManager::PrintingFailed(cookie, reason);
  341. +#if 0 // Electron does not use Chromium error dialogs
  342. // `PrintingFailed()` can occur because asynchronous compositing results
  343. // don't complete until after a print job has already failed and been
  344. // destroyed. In such cases the error notification to the user will
  345. @@ -871,7 +931,7 @@ void PrintViewManagerBase::PrintingFailed(int32_t cookie,
  346. print_job_->document()->cookie() == cookie) {
  347. ShowPrintErrorDialogForGenericError();
  348. }
  349. -
  350. +#endif
  351. ReleasePrinterQuery();
  352. }
  353. @@ -883,15 +943,24 @@ void PrintViewManagerBase::RemoveTestObserver(TestObserver& observer) {
  354. test_observers_.RemoveObserver(&observer);
  355. }
  356. +void PrintViewManagerBase::ShowInvalidPrinterSettingsError() {
  357. + if (!callback_.is_null()) {
  358. + printing_status_ = PrintStatus::kInvalid;
  359. + TerminatePrintJob(true);
  360. + }
  361. +}
  362. +
  363. void PrintViewManagerBase::RenderFrameHostStateChanged(
  364. content::RenderFrameHost* render_frame_host,
  365. content::RenderFrameHost::LifecycleState /*old_state*/,
  366. content::RenderFrameHost::LifecycleState new_state) {
  367. +#if 0
  368. if (new_state == content::RenderFrameHost::LifecycleState::kActive &&
  369. render_frame_host->GetProcess()->IsPdf() &&
  370. !render_frame_host->GetMainFrame()->GetParentOrOuterDocument()) {
  371. GetPrintRenderFrame(render_frame_host)->ConnectToPdfRenderer();
  372. }
  373. +#endif
  374. }
  375. void PrintViewManagerBase::RenderFrameDeleted(
  376. @@ -943,7 +1012,12 @@ void PrintViewManagerBase::OnJobDone() {
  377. // Printing is done, we don't need it anymore.
  378. // print_job_->is_job_pending() may still be true, depending on the order
  379. // of object registration.
  380. - printing_succeeded_ = true;
  381. + printing_status_ = PrintStatus::kSucceeded;
  382. + ReleasePrintJob();
  383. +}
  384. +
  385. +void PrintViewManagerBase::UserInitCanceled() {
  386. + printing_status_ = PrintStatus::kCanceled;
  387. ReleasePrintJob();
  388. }
  389. @@ -952,9 +1026,10 @@ void PrintViewManagerBase::OnCanceling() {
  390. }
  391. void PrintViewManagerBase::OnFailed() {
  392. +#if 0 // Electron does not use Chromium error dialogs
  393. if (!canceling_job_)
  394. ShowPrintErrorDialogForGenericError();
  395. -
  396. +#endif
  397. TerminatePrintJob(true);
  398. }
  399. @@ -964,7 +1039,7 @@ bool PrintViewManagerBase::RenderAllMissingPagesNow() {
  400. // Is the document already complete?
  401. if (print_job_->document() && print_job_->document()->IsComplete()) {
  402. - printing_succeeded_ = true;
  403. + printing_status_ = PrintStatus::kSucceeded;
  404. return true;
  405. }
  406. @@ -1017,7 +1092,10 @@ bool PrintViewManagerBase::SetupNewPrintJob(
  407. // Disconnect the current `print_job_`.
  408. auto weak_this = weak_ptr_factory_.GetWeakPtr();
  409. - DisconnectFromCurrentPrintJob();
  410. + if (callback_.is_null()) {
  411. + // Disconnect the current |print_job_| only when calling window.print()
  412. + DisconnectFromCurrentPrintJob();
  413. + }
  414. if (!weak_this)
  415. return false;
  416. @@ -1037,7 +1115,7 @@ bool PrintViewManagerBase::SetupNewPrintJob(
  417. #endif
  418. print_job_->AddObserver(*this);
  419. - printing_succeeded_ = false;
  420. + printing_status_ = PrintStatus::kFailed;
  421. return true;
  422. }
  423. @@ -1105,6 +1183,11 @@ void PrintViewManagerBase::ReleasePrintJob() {
  424. }
  425. #endif
  426. + if (!callback_.is_null()) {
  427. + bool success = printing_status_ == PrintStatus::kSucceeded;
  428. + std::move(callback_).Run(success, PrintReasonFromPrintStatus(printing_status_));
  429. + }
  430. +
  431. if (!print_job_)
  432. return;
  433. @@ -1112,7 +1195,7 @@ void PrintViewManagerBase::ReleasePrintJob() {
  434. // printing_rfh_ should only ever point to a RenderFrameHost with a live
  435. // RenderFrame.
  436. DCHECK(rfh->IsRenderFrameLive());
  437. - GetPrintRenderFrame(rfh)->PrintingDone(printing_succeeded_);
  438. + GetPrintRenderFrame(rfh)->PrintingDone(printing_status_ == PrintStatus::kSucceeded);
  439. }
  440. print_job_->RemoveObserver(*this);
  441. @@ -1154,7 +1237,7 @@ bool PrintViewManagerBase::RunInnerMessageLoop() {
  442. }
  443. bool PrintViewManagerBase::OpportunisticallyCreatePrintJob(int cookie) {
  444. - if (print_job_)
  445. + if (print_job_ && print_job_->document())
  446. return true;
  447. if (!cookie) {
  448. @@ -1300,7 +1383,7 @@ void PrintViewManagerBase::ReleasePrinterQuery() {
  449. }
  450. void PrintViewManagerBase::CompletePrintNow(content::RenderFrameHost* rfh) {
  451. - GetPrintRenderFrame(rfh)->PrintRequestedPages();
  452. + GetPrintRenderFrame(rfh)->PrintRequestedPages(/*silent=*/true, /*job_settings=*/base::Value::Dict());
  453. for (auto& observer : GetTestObservers()) {
  454. observer.OnPrintNow(rfh);
  455. @@ -1350,7 +1433,7 @@ void PrintViewManagerBase::CompleteScriptedPrintAfterContentAnalysis(
  456. set_analyzing_content(/*analyzing=*/false);
  457. if (!allowed || !printing_rfh_ || IsCrashed() ||
  458. !printing_rfh_->IsRenderFrameLive()) {
  459. - std::move(callback).Run(nullptr);
  460. + std::move(callback).Run(nullptr, false);
  461. return;
  462. }
  463. CompleteScriptedPrint(printing_rfh_, std::move(params), std::move(callback));
  464. diff --git a/chrome/browser/printing/print_view_manager_base.h b/chrome/browser/printing/print_view_manager_base.h
  465. index ae2339d1ab82bd7cfa971ed03a188cfc26d6e1c0..186414ee72c6b431b87b02623abd4d1903de812b 100644
  466. --- a/chrome/browser/printing/print_view_manager_base.h
  467. +++ b/chrome/browser/printing/print_view_manager_base.h
  468. @@ -44,6 +44,8 @@ namespace printing {
  469. class PrintQueriesQueue;
  470. class PrinterQuery;
  471. +using CompletionCallback = base::OnceCallback<void(bool, const std::string&)>;
  472. +
  473. // Base class for managing the print commands for a WebContents.
  474. class PrintViewManagerBase : public PrintManager, public PrintJob::Observer {
  475. public:
  476. @@ -77,7 +79,10 @@ class PrintViewManagerBase : public PrintManager, public PrintJob::Observer {
  477. // Prints the current document immediately. Since the rendering is
  478. // asynchronous, the actual printing will not be completed on the return of
  479. // this function. Returns false if printing is impossible at the moment.
  480. - virtual bool PrintNow(content::RenderFrameHost* rfh);
  481. + virtual bool PrintNow(content::RenderFrameHost* rfh,
  482. + bool silent = true,
  483. + base::Value::Dict settings = {},
  484. + CompletionCallback callback = {});
  485. // Like PrintNow(), but for the node under the context menu, instead of the
  486. // entire frame.
  487. @@ -131,8 +136,10 @@ class PrintViewManagerBase : public PrintManager, public PrintJob::Observer {
  488. void IsPrintingEnabled(IsPrintingEnabledCallback callback) override;
  489. void ScriptedPrint(mojom::ScriptedPrintParamsPtr params,
  490. ScriptedPrintCallback callback) override;
  491. + void ShowInvalidPrinterSettingsError() override;
  492. void PrintingFailed(int32_t cookie,
  493. mojom::PrintFailureReason reason) override;
  494. + void UserInitCanceled();
  495. // Adds and removes observers for `PrintViewManagerBase` events. The order in
  496. // which notifications are sent to observers is undefined. Observers must be
  497. @@ -140,6 +147,14 @@ class PrintViewManagerBase : public PrintManager, public PrintJob::Observer {
  498. void AddTestObserver(TestObserver& observer);
  499. void RemoveTestObserver(TestObserver& observer);
  500. + enum class PrintStatus {
  501. + kSucceeded,
  502. + kCanceled,
  503. + kFailed,
  504. + kInvalid,
  505. + kUnknown
  506. + };
  507. +
  508. protected:
  509. explicit PrintViewManagerBase(content::WebContents* web_contents);
  510. @@ -281,6 +296,7 @@ class PrintViewManagerBase : public PrintManager, public PrintJob::Observer {
  511. bool success);
  512. #endif
  513. void CompleteUpdatePrintSettings(
  514. + std::unique_ptr<PrinterQuery> printer_query,
  515. base::Value::Dict job_settings,
  516. std::unique_ptr<PrintSettings> print_settings,
  517. UpdatePrintSettingsCallback callback);
  518. @@ -310,7 +326,8 @@ class PrintViewManagerBase : public PrintManager, public PrintJob::Observer {
  519. // Runs `callback` with `params` to reply to ScriptedPrint().
  520. void ScriptedPrintReply(ScriptedPrintCallback callback,
  521. int process_id,
  522. - mojom::PrintPagesParamsPtr params);
  523. + mojom::PrintPagesParamsPtr params,
  524. + bool canceled);
  525. // Requests the RenderView to render all the missing pages for the print job.
  526. // No-op if no print job is pending. Returns true if at least one page has
  527. @@ -391,8 +408,11 @@ class PrintViewManagerBase : public PrintManager, public PrintJob::Observer {
  528. // The current RFH that is printing with a system printing dialog.
  529. raw_ptr<content::RenderFrameHost> printing_rfh_ = nullptr;
  530. + // Respond with success of the print job.
  531. + CompletionCallback callback_;
  532. +
  533. // Indication of success of the print job.
  534. - bool printing_succeeded_ = false;
  535. + PrintStatus printing_status_ = PrintStatus::kUnknown;
  536. // Indication that the job is getting canceled.
  537. bool canceling_job_ = false;
  538. diff --git a/chrome/browser/printing/printer_query.cc b/chrome/browser/printing/printer_query.cc
  539. index 57de2cf6fe6a6ff52b823ddd0079a9587e002416..52eec5ce4ad743543ae3b12b3cfe04e180f1292b 100644
  540. --- a/chrome/browser/printing/printer_query.cc
  541. +++ b/chrome/browser/printing/printer_query.cc
  542. @@ -355,17 +355,19 @@ void PrinterQuery::UpdatePrintSettings(base::Value::Dict new_settings,
  543. #endif // BUILDFLAG(IS_LINUX) && BUILDFLAG(USE_CUPS)
  544. }
  545. - mojom::ResultCode result;
  546. {
  547. #if BUILDFLAG(IS_WIN)
  548. // Blocking is needed here because Windows printer drivers are oftentimes
  549. // not thread-safe and have to be accessed on the UI thread.
  550. base::ScopedAllowBlocking allow_blocking;
  551. #endif
  552. - result = printing_context_->UpdatePrintSettings(std::move(new_settings));
  553. + // Reset settings from previous print job
  554. + printing_context_->ResetSettings();
  555. + mojom::ResultCode result_code = printing_context_->UseDefaultSettings();
  556. + if (result_code == mojom::ResultCode::kSuccess)
  557. + result_code = printing_context_->UpdatePrintSettings(std::move(new_settings));
  558. + InvokeSettingsCallback(std::move(callback), result_code);
  559. }
  560. -
  561. - InvokeSettingsCallback(std::move(callback), result);
  562. }
  563. #if BUILDFLAG(IS_CHROMEOS)
  564. diff --git a/chrome/browser/ui/webui/print_preview/fake_print_render_frame.cc b/chrome/browser/ui/webui/print_preview/fake_print_render_frame.cc
  565. index e83cf407beebcec5ccf7eaa991f43d4d3713833b..5e770a6a840b48e07ff056fe038aad54e526429e 100644
  566. --- a/chrome/browser/ui/webui/print_preview/fake_print_render_frame.cc
  567. +++ b/chrome/browser/ui/webui/print_preview/fake_print_render_frame.cc
  568. @@ -21,7 +21,7 @@ FakePrintRenderFrame::FakePrintRenderFrame(
  569. FakePrintRenderFrame::~FakePrintRenderFrame() = default;
  570. -void FakePrintRenderFrame::PrintRequestedPages() {}
  571. +void FakePrintRenderFrame::PrintRequestedPages(bool /*silent*/, ::base::Value::Dict /*settings*/) {}
  572. void FakePrintRenderFrame::PrintWithParams(mojom::PrintPagesParamsPtr params,
  573. PrintWithParamsCallback callback) {
  574. diff --git a/chrome/browser/ui/webui/print_preview/fake_print_render_frame.h b/chrome/browser/ui/webui/print_preview/fake_print_render_frame.h
  575. index 32403bb077dcbbffe6a3a862feff619e980c5f93..af773c93ab969a5dc483cc63384851ff62cf51ec 100644
  576. --- a/chrome/browser/ui/webui/print_preview/fake_print_render_frame.h
  577. +++ b/chrome/browser/ui/webui/print_preview/fake_print_render_frame.h
  578. @@ -25,7 +25,7 @@ class FakePrintRenderFrame : public mojom::PrintRenderFrame {
  579. private:
  580. // printing::mojom::PrintRenderFrame:
  581. - void PrintRequestedPages() override;
  582. + void PrintRequestedPages(bool silent, ::base::Value::Dict settings) override;
  583. void PrintWithParams(mojom::PrintPagesParamsPtr params,
  584. PrintWithParamsCallback callback) override;
  585. void PrintForSystemDialog() override;
  586. diff --git a/components/printing/browser/print_manager.cc b/components/printing/browser/print_manager.cc
  587. index 21c81377d32ae8d4185598a7eba88ed1d2063ef0..0767f4e9369e926b1cea99178c1a1975941f1765 100644
  588. --- a/components/printing/browser/print_manager.cc
  589. +++ b/components/printing/browser/print_manager.cc
  590. @@ -47,6 +47,8 @@ void PrintManager::IsPrintingEnabled(IsPrintingEnabledCallback callback) {
  591. std::move(callback).Run(true);
  592. }
  593. +void PrintManager::ShowInvalidPrinterSettingsError() {}
  594. +
  595. void PrintManager::PrintingFailed(int32_t cookie,
  596. mojom::PrintFailureReason reason) {
  597. // Note: Not redundant with cookie checks in the same method in other parts of
  598. diff --git a/components/printing/browser/print_manager.h b/components/printing/browser/print_manager.h
  599. index ca71560874a0189068dd11fbc039f5673bf6bd96..a8551d95e64da2afbc1685b2df8f1fc377c7117b 100644
  600. --- a/components/printing/browser/print_manager.h
  601. +++ b/components/printing/browser/print_manager.h
  602. @@ -48,6 +48,7 @@ class PrintManager : public content::WebContentsObserver,
  603. DidPrintDocumentCallback callback) override;
  604. void IsPrintingEnabled(IsPrintingEnabledCallback callback) override;
  605. void DidShowPrintDialog() override;
  606. + void ShowInvalidPrinterSettingsError() override;
  607. void PrintingFailed(int32_t cookie,
  608. mojom::PrintFailureReason reason) override;
  609. diff --git a/components/printing/common/print.mojom b/components/printing/common/print.mojom
  610. index 3f9a514fb41d72c5d06de6ac989f9d7c0513a4e7..0e7ada9df962808dad7caf074a08ebdedbd45604 100644
  611. --- a/components/printing/common/print.mojom
  612. +++ b/components/printing/common/print.mojom
  613. @@ -300,7 +300,7 @@ union PrintWithParamsResult {
  614. interface PrintRenderFrame {
  615. // Tells the RenderFrame to switch the CSS to print media type, render every
  616. // requested page, and then switch back the CSS to display media type.
  617. - PrintRequestedPages();
  618. + PrintRequestedPages(bool silent, mojo_base.mojom.DictionaryValue settings);
  619. // Requests the frame to be printed with specified parameters. This is used
  620. // to programmatically produce PDF by request from the browser (e.g. over
  621. @@ -394,7 +394,10 @@ interface PrintManagerHost {
  622. // UI to the user to select the final print settings. If the user cancels or
  623. // an error occurs, return null.
  624. [Sync]
  625. - ScriptedPrint(ScriptedPrintParams params) => (PrintPagesParams? settings);
  626. + ScriptedPrint(ScriptedPrintParams params) => (PrintPagesParams? settings, bool canceled);
  627. +
  628. + // Tells the browser that there are invalid printer settings.
  629. + ShowInvalidPrinterSettingsError();
  630. // Tells the browser printing failed.
  631. PrintingFailed(int32 cookie, PrintFailureReason reason);
  632. diff --git a/components/printing/renderer/print_render_frame_helper.cc b/components/printing/renderer/print_render_frame_helper.cc
  633. index 6000a308a23627e87afd9d979f8cb732a0db71bc..dfa51e2d8d31b34a605ac8dbfcb911b81d70da14 100644
  634. --- a/components/printing/renderer/print_render_frame_helper.cc
  635. +++ b/components/printing/renderer/print_render_frame_helper.cc
  636. @@ -47,6 +47,7 @@
  637. #include "printing/mojom/print.mojom.h"
  638. #include "printing/page_number.h"
  639. #include "printing/print_job_constants.h"
  640. +#include "printing/print_settings.h"
  641. #include "printing/units.h"
  642. #include "services/metrics/public/cpp/ukm_source_id.h"
  643. #include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
  644. @@ -1217,14 +1218,14 @@ void PrintRenderFrameHelper::ScriptedPrint(bool user_initiated) {
  645. }
  646. print_in_progress_ = true;
  647. -
  648. auto weak_this = weak_ptr_factory_.GetWeakPtr();
  649. web_frame->DispatchBeforePrintEvent(/*print_client=*/nullptr);
  650. if (!weak_this) {
  651. return;
  652. }
  653. - Print(web_frame, blink::WebNode(), PrintRequestType::kScripted);
  654. + Print(web_frame, blink::WebNode(), PrintRequestType::kScripted,
  655. + false /* silent */, base::Value::Dict() /* new_settings */);
  656. if (!weak_this) {
  657. return;
  658. }
  659. @@ -1255,7 +1256,7 @@ void PrintRenderFrameHelper::BindPrintRenderFrameReceiver(
  660. receivers_.Add(this, std::move(receiver));
  661. }
  662. -void PrintRenderFrameHelper::PrintRequestedPages() {
  663. +void PrintRenderFrameHelper::PrintRequestedPages(bool silent, base::Value::Dict settings) {
  664. ScopedIPC scoped_ipc(weak_ptr_factory_.GetWeakPtr());
  665. if (ipc_nesting_level_ > kAllowedIpcDepthForPrint)
  666. return;
  667. @@ -1270,7 +1271,7 @@ void PrintRenderFrameHelper::PrintRequestedPages() {
  668. // plugin node and print that instead.
  669. auto plugin = delegate_->GetPdfElement(frame);
  670. - Print(frame, plugin, PrintRequestType::kRegular);
  671. + Print(frame, plugin, PrintRequestType::kRegular, silent, std::move(settings));
  672. if (render_frame_gone_) {
  673. return;
  674. @@ -1359,7 +1360,8 @@ void PrintRenderFrameHelper::PrintForSystemDialog() {
  675. }
  676. Print(frame, print_preview_context_.source_node(),
  677. - PrintRequestType::kRegular);
  678. + PrintRequestType::kRegular, false,
  679. + base::Value::Dict());
  680. if (render_frame_gone_) {
  681. return;
  682. }
  683. @@ -1422,6 +1424,8 @@ void PrintRenderFrameHelper::PrintPreview(base::Value::Dict settings) {
  684. if (ipc_nesting_level_ > kAllowedIpcDepthForPrint)
  685. return;
  686. + blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
  687. + print_preview_context_.InitWithFrame(frame);
  688. print_preview_context_.OnPrintPreview();
  689. #if BUILDFLAG(IS_CHROMEOS_ASH)
  690. @@ -2046,7 +2050,8 @@ void PrintRenderFrameHelper::PrintNode(const blink::WebNode& node) {
  691. }
  692. Print(duplicate_node.GetDocument().GetFrame(), duplicate_node,
  693. - PrintRequestType::kRegular);
  694. + PrintRequestType::kRegular, false /* silent */,
  695. + base::Value::Dict() /* new_settings */);
  696. // Check if `this` is still valid.
  697. if (!weak_this) {
  698. return;
  699. @@ -2062,17 +2067,19 @@ void PrintRenderFrameHelper::PrintNode(const blink::WebNode& node) {
  700. void PrintRenderFrameHelper::Print(blink::WebLocalFrame* frame,
  701. const blink::WebNode& node,
  702. - PrintRequestType print_request_type) {
  703. + PrintRequestType print_request_type,
  704. + bool silent,
  705. + base::Value::Dict settings) {
  706. // If still not finished with earlier print request simply ignore.
  707. if (prep_frame_view_)
  708. return;
  709. FrameReference frame_ref(frame);
  710. - if (!InitPrintSettings(frame, node)) {
  711. + if (!InitPrintSettings(frame, node, std::move(settings))) {
  712. // Browser triggered this code path. It already knows about the failure.
  713. notify_browser_of_print_failure_ = false;
  714. -
  715. + GetPrintManagerHost()->ShowInvalidPrinterSettingsError();
  716. DidFinishPrinting(PrintingResult::kFailPrintInit);
  717. return;
  718. }
  719. @@ -2093,8 +2100,15 @@ void PrintRenderFrameHelper::Print(blink::WebLocalFrame* frame,
  720. print_pages_params_->params->print_scaling_option;
  721. auto self = weak_ptr_factory_.GetWeakPtr();
  722. - mojom::PrintPagesParamsPtr print_settings = GetPrintSettingsFromUser(
  723. + mojom::PrintPagesParamsPtr print_settings;
  724. +
  725. + if (silent) {
  726. + print_settings = mojom::PrintPagesParams::New();
  727. + print_settings->params = print_pages_params_->params->Clone();
  728. + } else {
  729. + print_settings = GetPrintSettingsFromUser(
  730. frame_ref.GetFrame(), node, expected_page_count, print_request_type);
  731. + }
  732. // Check if `this` is still valid.
  733. if (!self)
  734. return;
  735. @@ -2333,25 +2347,33 @@ void PrintRenderFrameHelper::IPCProcessed() {
  736. }
  737. bool PrintRenderFrameHelper::InitPrintSettings(blink::WebLocalFrame* frame,
  738. - const blink::WebNode& node) {
  739. + const blink::WebNode& node,
  740. + base::Value::Dict new_settings) {
  741. // Reset to default values.
  742. ignore_css_margins_ = false;
  743. - mojom::PrintPagesParams settings;
  744. - GetPrintManagerHost()->GetDefaultPrintSettings(&settings.params);
  745. + mojom::PrintPagesParamsPtr settings;
  746. + if (new_settings.empty()) {
  747. + settings = mojom::PrintPagesParams::New();
  748. + settings->params = mojom::PrintParams::New();
  749. + GetPrintManagerHost()->GetDefaultPrintSettings(&settings->params);
  750. + } else {
  751. + GetPrintManagerHost()->UpdatePrintSettings(
  752. + std::move(new_settings), &settings);
  753. + }
  754. // Check if the printer returned any settings, if the settings are null,
  755. // assume there are no printer drivers configured. So safely terminate.
  756. - if (!settings.params) {
  757. + if (!settings || !settings->params) {
  758. // Caller will reset `print_pages_params_`.
  759. return false;
  760. }
  761. bool fit_to_paper_size = !IsPrintingPdfFrame(frame, node);
  762. - settings.params->print_scaling_option =
  763. + settings->params->print_scaling_option =
  764. fit_to_paper_size ? mojom::PrintScalingOption::kFitToPrintableArea
  765. : mojom::PrintScalingOption::kSourceSize;
  766. - SetPrintPagesParams(settings);
  767. + SetPrintPagesParams(*settings);
  768. return true;
  769. }
  770. @@ -2458,7 +2480,7 @@ mojom::PrintPagesParamsPtr PrintRenderFrameHelper::GetPrintSettingsFromUser(
  771. std::move(params),
  772. base::BindOnce(
  773. [](base::OnceClosure quit_closure, mojom::PrintPagesParamsPtr* output,
  774. - mojom::PrintPagesParamsPtr input) {
  775. + mojom::PrintPagesParamsPtr input, bool canceled) {
  776. *output = std::move(input);
  777. std::move(quit_closure).Run();
  778. },
  779. diff --git a/components/printing/renderer/print_render_frame_helper.h b/components/printing/renderer/print_render_frame_helper.h
  780. index c68b68767ac52602981278ec655d9ccfad0c30ab..df2ea4524584417d859e1a22ec8a49c88e534ae3 100644
  781. --- a/components/printing/renderer/print_render_frame_helper.h
  782. +++ b/components/printing/renderer/print_render_frame_helper.h
  783. @@ -248,7 +248,7 @@ class PrintRenderFrameHelper
  784. mojo::PendingAssociatedReceiver<mojom::PrintRenderFrame> receiver);
  785. // printing::mojom::PrintRenderFrame:
  786. - void PrintRequestedPages() override;
  787. + void PrintRequestedPages(bool silent, base::Value::Dict settings) override;
  788. void PrintWithParams(mojom::PrintPagesParamsPtr params,
  789. PrintWithParamsCallback callback) override;
  790. #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
  791. @@ -318,7 +318,9 @@ class PrintRenderFrameHelper
  792. // WARNING: |this| may be gone after this method returns.
  793. void Print(blink::WebLocalFrame* frame,
  794. const blink::WebNode& node,
  795. - PrintRequestType print_request_type);
  796. + PrintRequestType print_request_type,
  797. + bool silent,
  798. + base::Value::Dict settings);
  799. // Notification when printing is done - signal tear-down/free resources.
  800. void DidFinishPrinting(PrintingResult result);
  801. @@ -328,7 +330,8 @@ class PrintRenderFrameHelper
  802. // Initialize print page settings with default settings.
  803. // Used only for native printing workflow.
  804. bool InitPrintSettings(blink::WebLocalFrame* frame,
  805. - const blink::WebNode& node);
  806. + const blink::WebNode& node,
  807. + base::Value::Dict new_settings);
  808. // Calculate number of pages in source document.
  809. uint32_t CalculateNumberOfPages(blink::WebLocalFrame* frame,
  810. diff --git a/content/browser/BUILD.gn b/content/browser/BUILD.gn
  811. index 4c66836806fcda70c76aa026549cdc9aa4cb675f..74fb7ae02010812e9d2796ef4eba35854f00b296 100644
  812. --- a/content/browser/BUILD.gn
  813. +++ b/content/browser/BUILD.gn
  814. @@ -2992,8 +2992,9 @@ source_set("browser") {
  815. "//ppapi/shared_impl",
  816. ]
  817. - assert(enable_printing)
  818. - deps += [ "//printing" ]
  819. + if (enable_printing) {
  820. + deps += [ "//printing" ]
  821. + }
  822. if (is_chromeos) {
  823. sources += [
  824. diff --git a/printing/printing_context.cc b/printing/printing_context.cc
  825. index 94f51e9f280a4282a3e9676c2895703e1bf55422..94555c2577d821ce2cbb521eee269138bbbf1a2b 100644
  826. --- a/printing/printing_context.cc
  827. +++ b/printing/printing_context.cc
  828. @@ -145,7 +145,6 @@ void PrintingContext::UsePdfSettings() {
  829. mojom::ResultCode PrintingContext::UpdatePrintSettings(
  830. base::Value::Dict job_settings) {
  831. - ResetSettings();
  832. {
  833. std::unique_ptr<PrintSettings> settings =
  834. PrintSettingsFromJobSettings(job_settings);
  835. diff --git a/printing/printing_context.h b/printing/printing_context.h
  836. index 6db58a9992642e557bac669b10f109bf6fd0f6ad..e1a5fcdca50d612dcb56faaf846752a44a697b84 100644
  837. --- a/printing/printing_context.h
  838. +++ b/printing/printing_context.h
  839. @@ -202,6 +202,9 @@ class COMPONENT_EXPORT(PRINTING) PrintingContext {
  840. bool PrintingAborted() const { return abort_printing_; }
  841. + // Reinitializes the settings for object reuse.
  842. + void ResetSettings();
  843. +
  844. int job_id() const { return job_id_; }
  845. protected:
  846. @@ -213,9 +216,6 @@ class COMPONENT_EXPORT(PRINTING) PrintingContext {
  847. Delegate* delegate,
  848. ProcessBehavior process_behavior);
  849. - // Reinitializes the settings for object reuse.
  850. - void ResetSettings();
  851. -
  852. // Does bookkeeping when an error occurs.
  853. virtual mojom::ResultCode OnError();
  854. diff --git a/sandbox/policy/mac/sandbox_mac.mm b/sandbox/policy/mac/sandbox_mac.mm
  855. index 2dd2b99216e6ebc1e326b9ff61ea2254ea7df4e9..3cc24bed974ba52a12272bc856d085cc890859c0 100644
  856. --- a/sandbox/policy/mac/sandbox_mac.mm
  857. +++ b/sandbox/policy/mac/sandbox_mac.mm
  858. @@ -37,6 +37,10 @@
  859. #include "sandbox/policy/mac/utility.sb.h"
  860. #include "sandbox/policy/mojom/sandbox.mojom.h"
  861. +#if BUILDFLAG(ENABLE_PRINTING)
  862. +#include "sandbox/policy/mac/print_backend.sb.h"
  863. +#endif
  864. +
  865. namespace sandbox::policy {
  866. base::FilePath GetCanonicalPath(const base::FilePath& path) {