From 62acd1ee4654215cb0899242b4fe5ad231ac1785 Mon Sep 17 00:00:00 2001 From: Mark Finkle Date: Mon, 18 Jan 2016 14:21:39 -0500 Subject: [PATCH] Bug 1240534 - Don't delete the temporary PDF file until printing service is really done with it r=sebastian --- .../java/org/mozilla/gecko/PrintHelper.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/mobile/android/base/java/org/mozilla/gecko/PrintHelper.java b/mobile/android/base/java/org/mozilla/gecko/PrintHelper.java index 19116cc06139..077b2d29b4a5 100644 --- a/mobile/android/base/java/org/mozilla/gecko/PrintHelper.java +++ b/mobile/android/base/java/org/mozilla/gecko/PrintHelper.java @@ -81,9 +81,6 @@ public class PrintHelper { } callback.onWriteFinished(new PageRange[] { PageRange.ALL_PAGES }); - - // File is not really deleted until the input stream closes it - pdfFile.delete(); } catch (FileNotFoundException ee) { Log.d(LOGTAG, "Unable to find the temporary PDF file."); } catch (IOException ioe) { @@ -97,7 +94,7 @@ public class PrintHelper { } @Override - public void onLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes, CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras){ + public void onLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes, CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras) { if (cancellationSignal.isCanceled()) { callback.onLayoutCancelled(); return; @@ -106,6 +103,18 @@ public class PrintHelper { PrintDocumentInfo pdi = new PrintDocumentInfo.Builder(filePath).setContentType(PrintDocumentInfo.CONTENT_TYPE_DOCUMENT).build(); callback.onLayoutFinished(pdi, true); } + + @Override + public void onFinish() { + // Remove the temporary file when the printing system is finished. + try { + File pdfFile = new File(filePath); + pdfFile.delete(); + } catch (NullPointerException npe) { + // Silence the exception. We only want to delete a real file. We don't + // care if the file doesn't exist. + } + } }; printManager.print(jobName, pda, null);