printing.patch 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941
  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 1845333d12696aaabc798b3c58e34f8ef3f77e4e..664a43872d8016be7744bcf8d09f7b436862b949 100644
  12. --- a/BUILD.gn
  13. +++ b/BUILD.gn
  14. @@ -998,7 +998,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",
  21. "//ui/base:ui_base_unittests",
  22. @@ -1007,6 +1006,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 163eacc8bb6654880d37111923a87ea5a6134485..565258e9bd4cc52e347e1f4a72ee29ec4a847690 100644
  34. --- a/chrome/browser/printing/print_job.cc
  35. +++ b/chrome/browser/printing/print_job.cc
  36. @@ -97,6 +97,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. @@ -111,6 +112,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. @@ -151,10 +153,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. @@ -405,8 +405,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. @@ -498,8 +500,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 5c2be309159b3f7c67601a08366b5221c198a1fb..10ceb545e5ff98b36c57d23584e701ba0e2c752e 100644
  83. --- a/chrome/browser/printing/print_view_manager_base.cc
  84. +++ b/chrome/browser/printing/print_view_manager_base.cc
  85. @@ -87,6 +87,20 @@ namespace printing {
  86. namespace {
  87. +std::string PrintReasonFromPrintStatus(PrintViewManager::PrintStatus status) {
  88. + if (status == PrintViewManager::PrintStatus::kInvalid) {
  89. + return "Invalid printer settings";
  90. + } else if (status == PrintViewManager::PrintStatus::kCanceled) {
  91. + return "Print job canceled";
  92. + } else if (status == PrintViewManager::PrintStatus::kFailed) {
  93. + return "Print job failed";
  94. + }
  95. + return "";
  96. +}
  97. +
  98. +using PrintSettingsCallback =
  99. + base::OnceCallback<void(std::unique_ptr<PrinterQuery>)>;
  100. +
  101. void OnDidGetDefaultPrintSettings(
  102. scoped_refptr<PrintQueriesQueue> queue,
  103. bool want_pdf_settings,
  104. @@ -95,9 +109,9 @@ void OnDidGetDefaultPrintSettings(
  105. DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
  106. if (printer_query->last_status() != mojom::ResultCode::kSuccess) {
  107. - if (!want_pdf_settings) {
  108. +#if 0 // Electron does not use Chromium error dialogs
  109. ShowPrintErrorDialogForInvalidPrinterError();
  110. - }
  111. +#endif
  112. std::move(callback).Run(nullptr);
  113. return;
  114. }
  115. @@ -107,9 +121,9 @@ void OnDidGetDefaultPrintSettings(
  116. params->document_cookie = printer_query->cookie();
  117. if (!PrintMsgPrintParamsIsValid(*params)) {
  118. - if (!want_pdf_settings) {
  119. +#if 0 // Electron does not use Chromium error dialogs
  120. ShowPrintErrorDialogForInvalidPrinterError();
  121. - }
  122. +#endif
  123. std::move(callback).Run(nullptr);
  124. return;
  125. }
  126. @@ -121,14 +135,14 @@ void OnDidGetDefaultPrintSettings(
  127. void OnDidScriptedPrint(
  128. scoped_refptr<PrintQueriesQueue> queue,
  129. std::unique_ptr<PrinterQuery> printer_query,
  130. - mojom::PrintManagerHost::ScriptedPrintCallback callback) {
  131. + mojom::PrintManagerHost::ScriptedPrintCallback callback,
  132. + base::OnceCallback<void()> cancel_job) {
  133. DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
  134. if (printer_query->last_status() != mojom::ResultCode::kSuccess ||
  135. !printer_query->settings().dpi()) {
  136. - // Notify user of the error, unless it was explicitly canceled.
  137. - if (printer_query->last_status() != mojom::ResultCode::kCanceled) {
  138. - ShowPrintErrorDialogForGenericError();
  139. + if (printer_query->last_status() == mojom::ResultCode::kCanceled) {
  140. + std::move(cancel_job).Run();
  141. }
  142. std::move(callback).Run(nullptr);
  143. return;
  144. @@ -186,9 +200,11 @@ PrintViewManagerBase::PrintViewManagerBase(content::WebContents* web_contents)
  145. : PrintManager(web_contents),
  146. queue_(g_browser_process->print_job_manager()->queue()) {
  147. DCHECK(queue_);
  148. +#if 0
  149. Profile* profile =
  150. Profile::FromBrowserContext(web_contents->GetBrowserContext());
  151. printing_enabled_.Init(prefs::kPrintingEnabled, profile->GetPrefs());
  152. +#endif
  153. }
  154. PrintViewManagerBase::~PrintViewManagerBase() {
  155. @@ -212,12 +228,16 @@ void PrintViewManagerBase::DisableThirdPartyBlocking() {
  156. }
  157. #endif // BUILDFLAG(IS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
  158. -bool PrintViewManagerBase::PrintNow(content::RenderFrameHost* rfh) {
  159. +bool PrintViewManagerBase::PrintNow(content::RenderFrameHost* rfh,
  160. + base::Value::Dict settings,
  161. + CompletionCallback callback) {
  162. if (!StartPrintCommon(rfh)) {
  163. return false;
  164. }
  165. - GetPrintRenderFrame(rfh)->PrintRequestedPages();
  166. + callback_ = std::move(callback);
  167. +
  168. + GetPrintRenderFrame(rfh)->PrintRequestedPages(std::move(settings));
  169. for (auto& observer : GetTestObservers()) {
  170. observer.OnPrintNow(rfh);
  171. @@ -299,7 +319,7 @@ void PrintViewManagerBase::PrintDocument(
  172. const gfx::Size& page_size,
  173. const gfx::Rect& content_area,
  174. const gfx::Point& offsets) {
  175. -#if BUILDFLAG(ENTERPRISE_CONTENT_ANALYSIS)
  176. +#if 0
  177. if (content_analysis_before_printing_document_) {
  178. std::move(content_analysis_before_printing_document_)
  179. .Run(print_data, page_size, content_area, offsets);
  180. @@ -346,12 +366,13 @@ void PrintViewManagerBase::OnDidUpdatePrintableArea(
  181. }
  182. PRINTER_LOG(EVENT) << "Paper printable area updated for vendor id "
  183. << print_settings->requested_media().vendor_id;
  184. - CompleteUpdatePrintSettings(std::move(job_settings),
  185. + CompleteUpdatePrintSettings(nullptr /* printer_query */, std::move(job_settings),
  186. std::move(print_settings), std::move(callback));
  187. }
  188. #endif
  189. void PrintViewManagerBase::CompleteUpdatePrintSettings(
  190. + std::unique_ptr<PrinterQuery> printer_query,
  191. base::Value::Dict job_settings,
  192. std::unique_ptr<PrintSettings> print_settings,
  193. UpdatePrintSettingsCallback callback) {
  194. @@ -359,7 +380,8 @@ void PrintViewManagerBase::CompleteUpdatePrintSettings(
  195. settings->pages = GetPageRangesFromJobSettings(job_settings);
  196. settings->params = mojom::PrintParams::New();
  197. RenderParamsFromPrintSettings(*print_settings, settings->params.get());
  198. - settings->params->document_cookie = PrintSettings::NewCookie();
  199. + settings->params->document_cookie = printer_query ? printer_query->cookie()
  200. + : PrintSettings::NewCookie();
  201. if (!PrintMsgPrintParamsIsValid(*settings->params)) {
  202. mojom::PrinterType printer_type = static_cast<mojom::PrinterType>(
  203. *job_settings.FindInt(kSettingPrinterType));
  204. @@ -371,6 +393,10 @@ void PrintViewManagerBase::CompleteUpdatePrintSettings(
  205. return;
  206. }
  207. + if (printer_query && printer_query->cookie() && printer_query->settings().dpi()) {
  208. + queue_->QueuePrinterQuery(std::move(printer_query));
  209. + }
  210. +
  211. set_cookie(settings->params->document_cookie);
  212. std::move(callback).Run(std::move(settings));
  213. }
  214. @@ -412,7 +438,9 @@ void PrintViewManagerBase::OnPrintSettingsDone(
  215. UnregisterSystemPrintClient();
  216. }
  217. #endif
  218. +#if 0 // Electron does not use Chromium error dialogs
  219. ShowPrintErrorDialogForGenericError();
  220. +#endif
  221. std::move(callback).Run(base::Value("Update settings failed"));
  222. return;
  223. }
  224. @@ -441,7 +469,7 @@ void PrintViewManagerBase::StartLocalPrintJob(
  225. PrinterHandler::PrintCallback callback) {
  226. DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
  227. -#if BUILDFLAG(ENTERPRISE_CONTENT_ANALYSIS)
  228. +#if 0
  229. // Populating `content_analysis_before_printing_document_` if needed should be
  230. // done first in this function's workflow, this way other code can check if
  231. // content analysis is going to happen and delay starting `print_job_` to
  232. @@ -674,7 +702,7 @@ void PrintViewManagerBase::GetDefaultPrintSettings(
  233. #if BUILDFLAG(ENABLE_OOP_PRINTING)
  234. if (ShouldPrintJobOop() &&
  235. -#if BUILDFLAG(ENTERPRISE_CONTENT_ANALYSIS)
  236. +#if 0
  237. !analyzing_content_ &&
  238. #endif
  239. !query_with_ui_client_id().has_value()) {
  240. @@ -702,7 +730,7 @@ void PrintViewManagerBase::GetDefaultPrintSettings(
  241. // Sometimes it is desired to get the PDF settings as opposed to the settings
  242. // of the default system print driver.
  243. -#if BUILDFLAG(ENTERPRISE_CONTENT_ANALYSIS)
  244. +#if 0
  245. bool want_pdf_settings = analyzing_content_;
  246. #else
  247. bool want_pdf_settings = false;
  248. @@ -746,10 +774,7 @@ void PrintViewManagerBase::UpdatePrintSettings(
  249. // `job_settings` does not yet contain the rasterized PDF dpi, so if the user
  250. // has the print preference set, fetch it for use in
  251. // `PrintSettingsFromJobSettings()`.
  252. - content::BrowserContext* context =
  253. - web_contents() ? web_contents()->GetBrowserContext() : nullptr;
  254. - PrefService* prefs =
  255. - context ? Profile::FromBrowserContext(context)->GetPrefs() : nullptr;
  256. + PrefService* prefs = nullptr;
  257. if (prefs && prefs->HasPrefPath(prefs::kPrintRasterizePdfDpi)) {
  258. int value = prefs->GetInteger(prefs::kPrintRasterizePdfDpi);
  259. if (value > 0)
  260. @@ -774,8 +799,22 @@ void PrintViewManagerBase::UpdatePrintSettings(
  261. }
  262. }
  263. -#if BUILDFLAG(IS_WIN)
  264. - // TODO(crbug.com/40260379): Remove this if the printable areas can be made
  265. + std::unique_ptr<PrinterQuery> query =
  266. + queue_->CreatePrinterQuery(GetCurrentTargetFrame()->GetGlobalId());
  267. + auto* query_ptr = query.get();
  268. + // We need to clone this before calling SetSettings because some environments
  269. + // evaluate job_settings.Clone() first, and some std::move(job_settings) first,
  270. + // for the former things work correctly but for the latter the cloned value is null.
  271. + auto job_settings_copy = job_settings.Clone();
  272. + query_ptr->SetSettings(
  273. + std::move(job_settings_copy),
  274. + base::BindOnce(&PrintViewManagerBase::CompleteUpdatePrintSettings,
  275. + weak_ptr_factory_.GetWeakPtr(), std::move(query),
  276. + std::move(job_settings), std::move(print_settings),
  277. + std::move(callback)));
  278. +
  279. +#if 0 // See https://chromium-review.googlesource.com/412367
  280. + // TODO(crbug.com/1424368): Remove this if the printable areas can be made
  281. // fully available from `PrintBackend::GetPrinterSemanticCapsAndDefaults()`
  282. // for in-browser queries.
  283. if (printer_type == mojom::PrinterType::kLocal) {
  284. @@ -796,8 +835,6 @@ void PrintViewManagerBase::UpdatePrintSettings(
  285. }
  286. #endif
  287. - CompleteUpdatePrintSettings(std::move(job_settings),
  288. - std::move(print_settings), std::move(callback));
  289. }
  290. void PrintViewManagerBase::SetAccessibilityTree(
  291. @@ -813,7 +850,7 @@ void PrintViewManagerBase::SetAccessibilityTree(
  292. void PrintViewManagerBase::IsPrintingEnabled(
  293. IsPrintingEnabledCallback callback) {
  294. DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
  295. - std::move(callback).Run(GetPrintingEnabledBooleanPref());
  296. + std::move(callback).Run(true);
  297. }
  298. void PrintViewManagerBase::ScriptedPrint(mojom::ScriptedPrintParamsPtr params,
  299. @@ -839,7 +876,7 @@ void PrintViewManagerBase::ScriptedPrint(mojom::ScriptedPrintParamsPtr params,
  300. return;
  301. }
  302. #endif
  303. -#if BUILDFLAG(ENTERPRISE_CONTENT_ANALYSIS)
  304. +#if 0
  305. std::optional<enterprise_connectors::ContentAnalysisDelegate::Data>
  306. scanning_data = enterprise_data_protection::GetPrintAnalysisData(
  307. web_contents(), enterprise_data_protection::PrintScanningContext::
  308. @@ -869,11 +906,9 @@ void PrintViewManagerBase::PrintingFailed(int32_t cookie,
  309. // destroyed. In such cases the error notification to the user will
  310. // have already been displayed, and a second message should not be
  311. // shown.
  312. - if (print_job_ && print_job_->document() &&
  313. - print_job_->document()->cookie() == cookie) {
  314. +#if 0 // Electron does not use Chromium error dialogs
  315. ShowPrintErrorDialogForGenericError();
  316. - }
  317. -
  318. +#endif
  319. ReleasePrinterQuery();
  320. }
  321. @@ -885,15 +920,24 @@ void PrintViewManagerBase::RemoveTestObserver(TestObserver& observer) {
  322. test_observers_.RemoveObserver(&observer);
  323. }
  324. +void PrintViewManagerBase::ShowInvalidPrinterSettingsError() {
  325. + if (!callback_.is_null()) {
  326. + printing_status_ = PrintStatus::kInvalid;
  327. + TerminatePrintJob(true);
  328. + }
  329. +}
  330. +
  331. void PrintViewManagerBase::RenderFrameHostStateChanged(
  332. content::RenderFrameHost* render_frame_host,
  333. content::RenderFrameHost::LifecycleState /*old_state*/,
  334. content::RenderFrameHost::LifecycleState new_state) {
  335. +#if 0
  336. if (new_state == content::RenderFrameHost::LifecycleState::kActive &&
  337. render_frame_host->GetProcess()->IsPdf() &&
  338. !render_frame_host->GetMainFrame()->GetParentOrOuterDocument()) {
  339. GetPrintRenderFrame(render_frame_host)->ConnectToPdfRenderer();
  340. }
  341. +#endif
  342. }
  343. void PrintViewManagerBase::RenderFrameDeleted(
  344. @@ -941,7 +985,7 @@ void PrintViewManagerBase::SystemDialogCancelled() {
  345. #endif
  346. bool PrintViewManagerBase::GetPrintingEnabledBooleanPref() const {
  347. - return printing_enabled_.GetValue();
  348. + return true;
  349. }
  350. void PrintViewManagerBase::OnDocDone(int job_id, PrintedDocument* document) {
  351. @@ -958,7 +1002,12 @@ void PrintViewManagerBase::OnJobDone() {
  352. // Printing is done, we don't need it anymore.
  353. // print_job_->is_job_pending() may still be true, depending on the order
  354. // of object registration.
  355. - printing_succeeded_ = true;
  356. + printing_status_ = PrintStatus::kSucceeded;
  357. + ReleasePrintJob();
  358. +}
  359. +
  360. +void PrintViewManagerBase::UserInitCanceled() {
  361. + printing_status_ = PrintStatus::kCanceled;
  362. ReleasePrintJob();
  363. }
  364. @@ -967,9 +1016,9 @@ void PrintViewManagerBase::OnCanceling() {
  365. }
  366. void PrintViewManagerBase::OnFailed() {
  367. - if (!canceling_job_)
  368. +#if 0 // Electron does not use Chromium error dialogs
  369. ShowPrintErrorDialogForGenericError();
  370. -
  371. +#endif
  372. TerminatePrintJob(true);
  373. }
  374. @@ -979,7 +1028,7 @@ bool PrintViewManagerBase::RenderAllMissingPagesNow() {
  375. // Is the document already complete?
  376. if (print_job_->document() && print_job_->document()->IsComplete()) {
  377. - printing_succeeded_ = true;
  378. + printing_status_ = PrintStatus::kSucceeded;
  379. return true;
  380. }
  381. @@ -1032,7 +1081,10 @@ bool PrintViewManagerBase::SetupNewPrintJob(
  382. // Disconnect the current `print_job_`.
  383. auto weak_this = weak_ptr_factory_.GetWeakPtr();
  384. - DisconnectFromCurrentPrintJob();
  385. + if (callback_.is_null()) {
  386. + // Disconnect the current |print_job_| only when calling window.print()
  387. + DisconnectFromCurrentPrintJob();
  388. + }
  389. if (!weak_this)
  390. return false;
  391. @@ -1052,7 +1104,7 @@ bool PrintViewManagerBase::SetupNewPrintJob(
  392. #endif
  393. print_job_->AddObserver(*this);
  394. - printing_succeeded_ = false;
  395. + printing_status_ = PrintStatus::kFailed;
  396. return true;
  397. }
  398. @@ -1110,7 +1162,7 @@ void PrintViewManagerBase::ReleasePrintJob() {
  399. // Ensure that any residual registration of printing client is released.
  400. // This might be necessary in some abnormal cases, such as the associated
  401. // render process having terminated.
  402. -#if BUILDFLAG(ENTERPRISE_CONTENT_ANALYSIS)
  403. +#if 0
  404. if (!analyzing_content_) {
  405. UnregisterSystemPrintClient();
  406. }
  407. @@ -1120,6 +1172,11 @@ void PrintViewManagerBase::ReleasePrintJob() {
  408. }
  409. #endif
  410. + if (!callback_.is_null()) {
  411. + bool success = printing_status_ == PrintStatus::kSucceeded;
  412. + std::move(callback_).Run(success, PrintReasonFromPrintStatus(printing_status_));
  413. + }
  414. +
  415. if (!print_job_)
  416. return;
  417. @@ -1127,7 +1184,7 @@ void PrintViewManagerBase::ReleasePrintJob() {
  418. // printing_rfh_ should only ever point to a RenderFrameHost with a live
  419. // RenderFrame.
  420. DCHECK(rfh->IsRenderFrameLive());
  421. - GetPrintRenderFrame(rfh)->PrintingDone(printing_succeeded_);
  422. + GetPrintRenderFrame(rfh)->PrintingDone(printing_status_ == PrintStatus::kSucceeded);
  423. }
  424. print_job_->RemoveObserver(*this);
  425. @@ -1169,7 +1226,7 @@ bool PrintViewManagerBase::RunInnerMessageLoop() {
  426. }
  427. bool PrintViewManagerBase::OpportunisticallyCreatePrintJob(int cookie) {
  428. - if (print_job_)
  429. + if (print_job_ && print_job_->document())
  430. return true;
  431. if (!cookie) {
  432. @@ -1192,7 +1249,7 @@ bool PrintViewManagerBase::OpportunisticallyCreatePrintJob(int cookie) {
  433. return false;
  434. }
  435. -#if BUILDFLAG(ENTERPRISE_CONTENT_ANALYSIS)
  436. +#if 0
  437. // Don't start printing if enterprise checks are being performed to check if
  438. // printing is allowed, or if content analysis is going to take place right
  439. // before starting `print_job_`.
  440. @@ -1323,6 +1380,8 @@ void PrintViewManagerBase::CompleteScriptedPrint(
  441. auto callback_wrapper = base::BindOnce(
  442. &PrintViewManagerBase::ScriptedPrintReply, weak_ptr_factory_.GetWeakPtr(),
  443. std::move(callback), render_process_host->GetID());
  444. + auto cancel_job_wrapper = base::BindOnce(
  445. + &PrintViewManagerBase::UserInitCanceled, weak_ptr_factory_.GetWeakPtr());
  446. #if BUILDFLAG(IS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
  447. DisableThirdPartyBlocking();
  448. #endif
  449. @@ -1337,10 +1396,10 @@ void PrintViewManagerBase::CompleteScriptedPrint(
  450. params->expected_pages_count, params->has_selection, params->margin_type,
  451. params->is_scripted, !render_process_host->IsPdf(),
  452. base::BindOnce(&OnDidScriptedPrint, queue_, std::move(printer_query),
  453. - std::move(callback_wrapper)));
  454. + std::move(callback_wrapper), std::move(cancel_job_wrapper)));
  455. }
  456. -#if BUILDFLAG(ENTERPRISE_CONTENT_ANALYSIS)
  457. +#if 0
  458. void PrintViewManagerBase::CompletePrintDocumentAfterContentAnalysis(
  459. scoped_refptr<base::RefCountedMemory> print_data,
  460. const gfx::Size& page_size,
  461. diff --git a/chrome/browser/printing/print_view_manager_base.h b/chrome/browser/printing/print_view_manager_base.h
  462. index 1917f8b94962d7a4c83f139623a5f5d352011627..47ef610c43c4dcfee0cf528eb2e6075b579117ee 100644
  463. --- a/chrome/browser/printing/print_view_manager_base.h
  464. +++ b/chrome/browser/printing/print_view_manager_base.h
  465. @@ -52,6 +52,8 @@ class PrinterQuery;
  466. // rollout.
  467. BASE_DECLARE_FEATURE(kCheckPrintRfhIsActive);
  468. +using CompletionCallback = base::OnceCallback<void(bool, const std::string&)>;
  469. +
  470. // Base class for managing the print commands for a WebContents.
  471. class PrintViewManagerBase : public PrintManager, public PrintJob::Observer {
  472. public:
  473. @@ -87,7 +89,9 @@ class PrintViewManagerBase : public PrintManager, public PrintJob::Observer {
  474. // Prints the current document immediately. Since the rendering is
  475. // asynchronous, the actual printing will not be completed on the return of
  476. // this function. Returns false if printing is impossible at the moment.
  477. - virtual bool PrintNow(content::RenderFrameHost* rfh);
  478. + virtual bool PrintNow(content::RenderFrameHost* rfh,
  479. + base::Value::Dict settings = {},
  480. + CompletionCallback callback = {});
  481. // Like PrintNow(), but for the node under the context menu, instead of the
  482. // entire frame.
  483. @@ -141,8 +145,10 @@ class PrintViewManagerBase : public PrintManager, public PrintJob::Observer {
  484. void IsPrintingEnabled(IsPrintingEnabledCallback callback) override;
  485. void ScriptedPrint(mojom::ScriptedPrintParamsPtr params,
  486. ScriptedPrintCallback callback) override;
  487. + void ShowInvalidPrinterSettingsError() override;
  488. void PrintingFailed(int32_t cookie,
  489. mojom::PrintFailureReason reason) override;
  490. + void UserInitCanceled();
  491. // Adds and removes observers for `PrintViewManagerBase` events. The order in
  492. // which notifications are sent to observers is undefined. Observers must be
  493. @@ -150,6 +156,14 @@ class PrintViewManagerBase : public PrintManager, public PrintJob::Observer {
  494. void AddTestObserver(TestObserver& observer);
  495. void RemoveTestObserver(TestObserver& observer);
  496. + enum class PrintStatus {
  497. + kSucceeded,
  498. + kCanceled,
  499. + kFailed,
  500. + kInvalid,
  501. + kUnknown
  502. + };
  503. +
  504. protected:
  505. #if BUILDFLAG(ENTERPRISE_CONTENT_ANALYSIS)
  506. using PrintDocumentCallback =
  507. @@ -229,7 +243,7 @@ class PrintViewManagerBase : public PrintManager, public PrintJob::Observer {
  508. mojom::ScriptedPrintParamsPtr params,
  509. ScriptedPrintCallback callback);
  510. -#if BUILDFLAG(ENTERPRISE_CONTENT_ANALYSIS)
  511. +#if 0
  512. // Helper method bound to `content_analysis_before_printing_document_` when
  513. // content analysis should happen right before the document is to be printed.
  514. // This method is virtual for testing purposes.
  515. @@ -293,6 +307,7 @@ class PrintViewManagerBase : public PrintManager, public PrintJob::Observer {
  516. bool success);
  517. #endif
  518. void CompleteUpdatePrintSettings(
  519. + std::unique_ptr<PrinterQuery> printer_query,
  520. base::Value::Dict job_settings,
  521. std::unique_ptr<PrintSettings> print_settings,
  522. UpdatePrintSettingsCallback callback);
  523. @@ -387,8 +402,11 @@ class PrintViewManagerBase : public PrintManager, public PrintJob::Observer {
  524. // The current RFH that is printing with a system printing dialog.
  525. raw_ptr<content::RenderFrameHost> printing_rfh_ = nullptr;
  526. + // Respond with success of the print job.
  527. + CompletionCallback callback_;
  528. +
  529. // Indication of success of the print job.
  530. - bool printing_succeeded_ = false;
  531. + PrintStatus printing_status_ = PrintStatus::kUnknown;
  532. // Indication that the job is getting canceled.
  533. bool canceling_job_ = false;
  534. diff --git a/chrome/browser/printing/printer_query.cc b/chrome/browser/printing/printer_query.cc
  535. index 0e48a7582d86c85a826de08af655b29a3ef74fd2..2e67a73611ca2c55ffc002341b0878de7191c932 100644
  536. --- a/chrome/browser/printing/printer_query.cc
  537. +++ b/chrome/browser/printing/printer_query.cc
  538. @@ -355,17 +355,19 @@ void PrinterQuery::UpdatePrintSettings(base::Value::Dict new_settings,
  539. #endif // BUILDFLAG(IS_LINUX) && BUILDFLAG(USE_CUPS)
  540. }
  541. - mojom::ResultCode result;
  542. {
  543. #if BUILDFLAG(IS_WIN)
  544. // Blocking is needed here because Windows printer drivers are oftentimes
  545. // not thread-safe and have to be accessed on the UI thread.
  546. base::ScopedAllowBlocking allow_blocking;
  547. #endif
  548. - result = printing_context_->UpdatePrintSettings(std::move(new_settings));
  549. + // Reset settings from previous print job
  550. + printing_context_->ResetSettings();
  551. + mojom::ResultCode result_code = printing_context_->UseDefaultSettings();
  552. + if (result_code == mojom::ResultCode::kSuccess)
  553. + result_code = printing_context_->UpdatePrintSettings(std::move(new_settings));
  554. + InvokeSettingsCallback(std::move(callback), result_code);
  555. }
  556. -
  557. - InvokeSettingsCallback(std::move(callback), result);
  558. }
  559. #if BUILDFLAG(IS_CHROMEOS)
  560. diff --git a/components/printing/browser/print_manager.cc b/components/printing/browser/print_manager.cc
  561. index 21c81377d32ae8d4185598a7eba88ed1d2063ef0..0767f4e9369e926b1cea99178c1a1975941f1765 100644
  562. --- a/components/printing/browser/print_manager.cc
  563. +++ b/components/printing/browser/print_manager.cc
  564. @@ -47,6 +47,8 @@ void PrintManager::IsPrintingEnabled(IsPrintingEnabledCallback callback) {
  565. std::move(callback).Run(true);
  566. }
  567. +void PrintManager::ShowInvalidPrinterSettingsError() {}
  568. +
  569. void PrintManager::PrintingFailed(int32_t cookie,
  570. mojom::PrintFailureReason reason) {
  571. // Note: Not redundant with cookie checks in the same method in other parts of
  572. diff --git a/components/printing/browser/print_manager.h b/components/printing/browser/print_manager.h
  573. index ca71560874a0189068dd11fbc039f5673bf6bd96..a8551d95e64da2afbc1685b2df8f1fc377c7117b 100644
  574. --- a/components/printing/browser/print_manager.h
  575. +++ b/components/printing/browser/print_manager.h
  576. @@ -48,6 +48,7 @@ class PrintManager : public content::WebContentsObserver,
  577. DidPrintDocumentCallback callback) override;
  578. void IsPrintingEnabled(IsPrintingEnabledCallback callback) override;
  579. void DidShowPrintDialog() override;
  580. + void ShowInvalidPrinterSettingsError() override;
  581. void PrintingFailed(int32_t cookie,
  582. mojom::PrintFailureReason reason) override;
  583. diff --git a/components/printing/common/print.mojom b/components/printing/common/print.mojom
  584. index 3c2fdc9f9a6c60efc4b0afacbfb83eef55917791..8fd9aff538fa03da6c171927c316d4f611c46da1 100644
  585. --- a/components/printing/common/print.mojom
  586. +++ b/components/printing/common/print.mojom
  587. @@ -303,7 +303,7 @@ union PrintWithParamsResult {
  588. interface PrintRenderFrame {
  589. // Tells the RenderFrame to switch the CSS to print media type, render every
  590. // requested page, and then switch back the CSS to display media type.
  591. - PrintRequestedPages();
  592. + PrintRequestedPages(mojo_base.mojom.DictionaryValue settings);
  593. // Requests the frame to be printed with specified parameters. This is used
  594. // to programmatically produce PDF by request from the browser (e.g. over
  595. @@ -392,6 +392,9 @@ interface PrintManagerHost {
  596. [Sync]
  597. ScriptedPrint(ScriptedPrintParams params) => (PrintPagesParams? settings);
  598. + // Tells the browser that there are invalid printer settings.
  599. + ShowInvalidPrinterSettingsError();
  600. +
  601. // Tells the browser printing failed.
  602. PrintingFailed(int32 cookie, PrintFailureReason reason);
  603. diff --git a/components/printing/renderer/print_render_frame_helper.cc b/components/printing/renderer/print_render_frame_helper.cc
  604. index f039e0f694e7db6b14d222b917505ba2c02c7106..6b8493163997718d498e217bcfd261e840d79377 100644
  605. --- a/components/printing/renderer/print_render_frame_helper.cc
  606. +++ b/components/printing/renderer/print_render_frame_helper.cc
  607. @@ -51,6 +51,7 @@
  608. #include "printing/mojom/print.mojom.h"
  609. #include "printing/page_number.h"
  610. #include "printing/print_job_constants.h"
  611. +#include "printing/print_settings.h"
  612. #include "printing/units.h"
  613. #include "services/metrics/public/cpp/ukm_source_id.h"
  614. #include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
  615. @@ -1222,14 +1223,14 @@ void PrintRenderFrameHelper::ScriptedPrint(bool user_initiated) {
  616. }
  617. print_in_progress_ = true;
  618. -
  619. auto weak_this = weak_ptr_factory_.GetWeakPtr();
  620. web_frame->DispatchBeforePrintEvent(/*print_client=*/nullptr);
  621. if (!weak_this) {
  622. return;
  623. }
  624. - Print(web_frame, blink::WebNode(), PrintRequestType::kScripted);
  625. + Print(web_frame, blink::WebNode(), PrintRequestType::kScripted,
  626. + base::Value::Dict());
  627. if (!weak_this) {
  628. return;
  629. }
  630. @@ -1260,12 +1261,14 @@ void PrintRenderFrameHelper::BindPrintRenderFrameReceiver(
  631. receivers_.Add(this, std::move(receiver));
  632. }
  633. -void PrintRenderFrameHelper::PrintRequestedPages() {
  634. - PrintRequestedPagesInternal(/*already_notified_frame=*/false);
  635. +void PrintRenderFrameHelper::PrintRequestedPages(base::Value::Dict settings) {
  636. + PrintRequestedPagesInternal(/*already_notified_frame=*/false,
  637. + std::move(settings));
  638. }
  639. void PrintRenderFrameHelper::PrintRequestedPagesInternal(
  640. - bool already_notified_frame) {
  641. + bool already_notified_frame,
  642. + base::Value::Dict settings) {
  643. ScopedIPC scoped_ipc(weak_ptr_factory_.GetWeakPtr());
  644. if (ipc_nesting_level_ > kAllowedIpcDepthForPrint) {
  645. return;
  646. @@ -1282,9 +1285,10 @@ void PrintRenderFrameHelper::PrintRequestedPagesInternal(
  647. is_loading_ = frame->WillPrintSoon();
  648. if (is_loading_) {
  649. - on_stop_loading_closure_ = base::BindOnce(
  650. - &PrintRenderFrameHelper::PrintRequestedPagesInternal,
  651. - weak_ptr_factory_.GetWeakPtr(), /*already_notified_frame=*/true);
  652. + on_stop_loading_closure_ =
  653. + base::BindOnce(&PrintRenderFrameHelper::PrintRequestedPagesInternal,
  654. + weak_ptr_factory_.GetWeakPtr(),
  655. + /*already_notified_frame=*/true, std::move(settings));
  656. SetupOnStopLoadingTimeout();
  657. return;
  658. }
  659. @@ -1294,7 +1298,7 @@ void PrintRenderFrameHelper::PrintRequestedPagesInternal(
  660. // plugin node and print that instead.
  661. auto plugin = delegate_->GetPdfElement(frame);
  662. - Print(frame, plugin, PrintRequestType::kRegular);
  663. + Print(frame, plugin, PrintRequestType::kRegular, std::move(settings));
  664. if (render_frame_gone_) {
  665. return;
  666. @@ -1451,6 +1455,8 @@ void PrintRenderFrameHelper::PrintPreview(base::Value::Dict settings) {
  667. if (ipc_nesting_level_ > kAllowedIpcDepthForPrint)
  668. return;
  669. + blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
  670. + print_preview_context_.InitWithFrame(frame);
  671. print_preview_context_.OnPrintPreview();
  672. #if BUILDFLAG(IS_CHROMEOS_ASH)
  673. @@ -2043,17 +2049,19 @@ void PrintRenderFrameHelper::PrintNode(const blink::WebNode& node) {
  674. void PrintRenderFrameHelper::Print(blink::WebLocalFrame* frame,
  675. const blink::WebNode& node,
  676. - PrintRequestType print_request_type) {
  677. + PrintRequestType print_request_type,
  678. + base::Value::Dict settings) {
  679. // If still not finished with earlier print request simply ignore.
  680. if (prep_frame_view_)
  681. return;
  682. + bool silent = settings.FindBool("silent").value_or(false);
  683. FrameReference frame_ref(frame);
  684. - if (!InitPrintSettings(frame, node)) {
  685. + if (!InitPrintSettings(frame, node, std::move(settings))) {
  686. // Browser triggered this code path. It already knows about the failure.
  687. notify_browser_of_print_failure_ = false;
  688. -
  689. + GetPrintManagerHost()->ShowInvalidPrinterSettingsError();
  690. DidFinishPrinting(PrintingResult::kFailPrintInit);
  691. return;
  692. }
  693. @@ -2074,8 +2082,15 @@ void PrintRenderFrameHelper::Print(blink::WebLocalFrame* frame,
  694. print_pages_params_->params->print_scaling_option;
  695. auto self = weak_ptr_factory_.GetWeakPtr();
  696. - mojom::PrintPagesParamsPtr print_settings = GetPrintSettingsFromUser(
  697. + mojom::PrintPagesParamsPtr print_settings;
  698. +
  699. + if (silent) {
  700. + print_settings = mojom::PrintPagesParams::New();
  701. + print_settings->params = print_pages_params_->params->Clone();
  702. + } else {
  703. + print_settings = GetPrintSettingsFromUser(
  704. frame_ref.GetFrame(), node, expected_page_count, print_request_type);
  705. + }
  706. // Check if `this` is still valid.
  707. if (!self)
  708. return;
  709. @@ -2336,29 +2351,37 @@ void PrintRenderFrameHelper::IPCProcessed() {
  710. }
  711. bool PrintRenderFrameHelper::InitPrintSettings(blink::WebLocalFrame* frame,
  712. - const blink::WebNode& node) {
  713. + const blink::WebNode& node,
  714. + base::Value::Dict new_settings) {
  715. // Reset to default values.
  716. ignore_css_margins_ = false;
  717. - mojom::PrintPagesParams settings;
  718. - GetPrintManagerHost()->GetDefaultPrintSettings(&settings.params);
  719. + mojom::PrintPagesParamsPtr settings;
  720. + if (new_settings.empty()) {
  721. + settings = mojom::PrintPagesParams::New();
  722. + settings->params = mojom::PrintParams::New();
  723. + GetPrintManagerHost()->GetDefaultPrintSettings(&settings->params);
  724. + } else {
  725. + GetPrintManagerHost()->UpdatePrintSettings(
  726. + std::move(new_settings), &settings);
  727. + }
  728. // Check if the printer returned any settings, if the settings are null,
  729. // assume there are no printer drivers configured. So safely terminate.
  730. - if (!settings.params) {
  731. + if (!settings || !settings->params) {
  732. // Caller will reset `print_pages_params_`.
  733. return false;
  734. }
  735. bool center_on_paper = !IsPrintingPdfFrame(frame, node);
  736. - settings.params->print_scaling_option =
  737. + settings->params->print_scaling_option =
  738. center_on_paper ? mojom::PrintScalingOption::kCenterShrinkToFitPaper
  739. : mojom::PrintScalingOption::kSourceSize;
  740. - RecordDebugEvent(settings.params->printed_doc_type ==
  741. + RecordDebugEvent(settings->params->printed_doc_type ==
  742. mojom::SkiaDocumentType::kMSKP
  743. ? DebugEvent::kSetPrintSettings5
  744. : DebugEvent::kSetPrintSettings6);
  745. - SetPrintPagesParams(settings);
  746. + SetPrintPagesParams(*settings);
  747. return true;
  748. }
  749. diff --git a/components/printing/renderer/print_render_frame_helper.h b/components/printing/renderer/print_render_frame_helper.h
  750. index 14de029740ffbebe06d309651c1a2c007d9fb96b..e9bf9c5bef2a9235260e7d6c8d26d41528e38661 100644
  751. --- a/components/printing/renderer/print_render_frame_helper.h
  752. +++ b/components/printing/renderer/print_render_frame_helper.h
  753. @@ -251,7 +251,7 @@ class PrintRenderFrameHelper
  754. mojo::PendingAssociatedReceiver<mojom::PrintRenderFrame> receiver);
  755. // printing::mojom::PrintRenderFrame:
  756. - void PrintRequestedPages() override;
  757. + void PrintRequestedPages(base::Value::Dict settings) override;
  758. void PrintWithParams(mojom::PrintPagesParamsPtr params,
  759. PrintWithParamsCallback callback) override;
  760. #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
  761. @@ -318,7 +318,8 @@ class PrintRenderFrameHelper
  762. // WARNING: |this| may be gone after this method returns.
  763. void Print(blink::WebLocalFrame* frame,
  764. const blink::WebNode& node,
  765. - PrintRequestType print_request_type);
  766. + PrintRequestType print_request_type,
  767. + base::Value::Dict settings = {});
  768. // Notification when printing is done - signal tear-down/free resources.
  769. void DidFinishPrinting(PrintingResult result);
  770. @@ -328,7 +329,8 @@ class PrintRenderFrameHelper
  771. // Initialize print page settings with default settings.
  772. // Used only for native printing workflow.
  773. bool InitPrintSettings(blink::WebLocalFrame* frame,
  774. - const blink::WebNode& node);
  775. + const blink::WebNode& node,
  776. + base::Value::Dict new_settings);
  777. // Calculate number of pages in source document.
  778. uint32_t CalculateNumberOfPages(blink::WebLocalFrame* frame,
  779. @@ -625,7 +627,8 @@ class PrintRenderFrameHelper
  780. };
  781. void SetupOnStopLoadingTimeout();
  782. - void PrintRequestedPagesInternal(bool already_notified_frame);
  783. + void PrintRequestedPagesInternal(bool already_notified_frame,
  784. + base::Value::Dict settings);
  785. ScriptingThrottler scripting_throttler_;
  786. diff --git a/content/browser/BUILD.gn b/content/browser/BUILD.gn
  787. index 0c6e7e22ca8cc62687bd863268bfc8256ccae8b9..70afbd28b3ec204bf6a87e953aadfe37cf33310e 100644
  788. --- a/content/browser/BUILD.gn
  789. +++ b/content/browser/BUILD.gn
  790. @@ -3005,8 +3005,9 @@ source_set("browser") {
  791. "//ppapi/shared_impl",
  792. ]
  793. - assert(enable_printing)
  794. - deps += [ "//printing" ]
  795. + if (enable_printing) {
  796. + deps += [ "//printing" ]
  797. + }
  798. if (is_chromeos) {
  799. sources += [
  800. diff --git a/printing/printing_context.cc b/printing/printing_context.cc
  801. index e9d9b148387313d8f6dd399d69a69272a511e6b4..a97983e9736daffdfeb713ae7b263f146f79ad0b 100644
  802. --- a/printing/printing_context.cc
  803. +++ b/printing/printing_context.cc
  804. @@ -154,7 +154,6 @@ void PrintingContext::UsePdfSettings() {
  805. mojom::ResultCode PrintingContext::UpdatePrintSettings(
  806. base::Value::Dict job_settings) {
  807. - ResetSettings();
  808. {
  809. std::unique_ptr<PrintSettings> settings =
  810. PrintSettingsFromJobSettings(job_settings);
  811. diff --git a/printing/printing_context.h b/printing/printing_context.h
  812. index 63f170c95050416c595e62f4c460c4cd6b7dbd1c..157e3d046889f9c63fdf0fd5d503890fb82c038d 100644
  813. --- a/printing/printing_context.h
  814. +++ b/printing/printing_context.h
  815. @@ -206,6 +206,9 @@ class COMPONENT_EXPORT(PRINTING) PrintingContext {
  816. bool PrintingAborted() const { return abort_printing_; }
  817. + // Reinitializes the settings for object reuse.
  818. + void ResetSettings();
  819. +
  820. int job_id() const { return job_id_; }
  821. #if BUILDFLAG(ENABLE_OOP_PRINTING)
  822. @@ -224,9 +227,6 @@ class COMPONENT_EXPORT(PRINTING) PrintingContext {
  823. Delegate* delegate,
  824. ProcessBehavior process_behavior);
  825. - // Reinitializes the settings for object reuse.
  826. - void ResetSettings();
  827. -
  828. // Does bookkeeping when an error occurs.
  829. virtual mojom::ResultCode OnError();
  830. diff --git a/sandbox/policy/mac/sandbox_mac.mm b/sandbox/policy/mac/sandbox_mac.mm
  831. index 8bb26f3212d406419d957250adbaf4cb682df801..2345917c71ddf7fda171672b736724087fc873e8 100644
  832. --- a/sandbox/policy/mac/sandbox_mac.mm
  833. +++ b/sandbox/policy/mac/sandbox_mac.mm
  834. @@ -35,6 +35,10 @@
  835. #include "sandbox/policy/mac/utility.sb.h"
  836. #include "sandbox/policy/mojom/sandbox.mojom.h"
  837. +#if BUILDFLAG(ENABLE_PRINTING)
  838. +#include "sandbox/policy/mac/print_backend.sb.h"
  839. +#endif
  840. +
  841. namespace sandbox::policy {
  842. base::FilePath GetCanonicalPath(const base::FilePath& path) {