Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | #include "nsDeviceContextAndroid.h" |
michael@0 | 5 | #include "nsString.h" |
michael@0 | 6 | #include "nsIFile.h" |
michael@0 | 7 | #include "nsIFileStreams.h" |
michael@0 | 8 | #include "nsAutoPtr.h" |
michael@0 | 9 | #include "gfxPDFSurface.h" |
michael@0 | 10 | #include "nsIPrintSettings.h" |
michael@0 | 11 | #include "nsDirectoryServiceDefs.h" |
michael@0 | 12 | |
michael@0 | 13 | NS_IMPL_ISUPPORTS(nsDeviceContextSpecAndroid, nsIDeviceContextSpec) |
michael@0 | 14 | |
michael@0 | 15 | NS_IMETHODIMP |
michael@0 | 16 | nsDeviceContextSpecAndroid::GetSurfaceForPrinter(gfxASurface** aSurface) |
michael@0 | 17 | { |
michael@0 | 18 | nsresult rv = |
michael@0 | 19 | NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(mTempFile)); |
michael@0 | 20 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 21 | |
michael@0 | 22 | nsAutoCString filename("tmp-printing.pdf"); |
michael@0 | 23 | mTempFile->AppendNative(filename); |
michael@0 | 24 | rv = mTempFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0660); |
michael@0 | 25 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 26 | |
michael@0 | 27 | nsCOMPtr<nsIFileOutputStream> stream = do_CreateInstance("@mozilla.org/network/file-output-stream;1"); |
michael@0 | 28 | rv = stream->Init(mTempFile, -1, -1, 0); |
michael@0 | 29 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 30 | |
michael@0 | 31 | nsRefPtr<gfxASurface> surface; |
michael@0 | 32 | |
michael@0 | 33 | // XXX: what should we do here for size? screen size? |
michael@0 | 34 | gfxSize surfaceSize(480, 800); |
michael@0 | 35 | |
michael@0 | 36 | surface = new gfxPDFSurface(stream, surfaceSize); |
michael@0 | 37 | |
michael@0 | 38 | |
michael@0 | 39 | NS_ABORT_IF_FALSE(surface, "valid address expected"); |
michael@0 | 40 | surface.swap(*aSurface); |
michael@0 | 41 | return NS_OK; |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | NS_IMETHODIMP |
michael@0 | 45 | nsDeviceContextSpecAndroid::Init(nsIWidget* aWidget, |
michael@0 | 46 | nsIPrintSettings* aPS, |
michael@0 | 47 | bool aIsPrintPreview) |
michael@0 | 48 | { |
michael@0 | 49 | mPrintSettings = aPS; |
michael@0 | 50 | return NS_OK; |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | NS_IMETHODIMP |
michael@0 | 54 | nsDeviceContextSpecAndroid::BeginDocument(const nsAString& aTitle, |
michael@0 | 55 | char16_t* aPrintToFileName, |
michael@0 | 56 | int32_t aStartPage, |
michael@0 | 57 | int32_t aEndPage) |
michael@0 | 58 | { |
michael@0 | 59 | return NS_OK; |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | NS_IMETHODIMP |
michael@0 | 63 | nsDeviceContextSpecAndroid::EndDocument() |
michael@0 | 64 | { |
michael@0 | 65 | nsXPIDLString targetPath; |
michael@0 | 66 | nsCOMPtr<nsIFile> destFile; |
michael@0 | 67 | mPrintSettings->GetToFileName(getter_Copies(targetPath)); |
michael@0 | 68 | |
michael@0 | 69 | nsresult rv = NS_NewNativeLocalFile(NS_ConvertUTF16toUTF8(targetPath), |
michael@0 | 70 | false, getter_AddRefs(destFile)); |
michael@0 | 71 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 72 | |
michael@0 | 73 | nsAutoString destLeafName; |
michael@0 | 74 | rv = destFile->GetLeafName(destLeafName); |
michael@0 | 75 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 76 | |
michael@0 | 77 | nsCOMPtr<nsIFile> destDir; |
michael@0 | 78 | rv = destFile->GetParent(getter_AddRefs(destDir)); |
michael@0 | 79 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 80 | |
michael@0 | 81 | rv = mTempFile->MoveTo(destDir, destLeafName); |
michael@0 | 82 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 83 | |
michael@0 | 84 | destFile->SetPermissions(0666); |
michael@0 | 85 | return NS_OK; |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | NS_IMETHODIMP |
michael@0 | 89 | nsDeviceContextSpecAndroid::GetPath (const char** aPath) |
michael@0 | 90 | { |
michael@0 | 91 | return NS_OK; |
michael@0 | 92 | } |