printing.patch 38 KB

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