michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: #include "nsDeviceContextAndroid.h" michael@0: #include "nsString.h" michael@0: #include "nsIFile.h" michael@0: #include "nsIFileStreams.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "gfxPDFSurface.h" michael@0: #include "nsIPrintSettings.h" michael@0: #include "nsDirectoryServiceDefs.h" michael@0: michael@0: NS_IMPL_ISUPPORTS(nsDeviceContextSpecAndroid, nsIDeviceContextSpec) michael@0: michael@0: NS_IMETHODIMP michael@0: nsDeviceContextSpecAndroid::GetSurfaceForPrinter(gfxASurface** aSurface) michael@0: { michael@0: nsresult rv = michael@0: NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(mTempFile)); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: nsAutoCString filename("tmp-printing.pdf"); michael@0: mTempFile->AppendNative(filename); michael@0: rv = mTempFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0660); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: nsCOMPtr stream = do_CreateInstance("@mozilla.org/network/file-output-stream;1"); michael@0: rv = stream->Init(mTempFile, -1, -1, 0); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: nsRefPtr surface; michael@0: michael@0: // XXX: what should we do here for size? screen size? michael@0: gfxSize surfaceSize(480, 800); michael@0: michael@0: surface = new gfxPDFSurface(stream, surfaceSize); michael@0: michael@0: michael@0: NS_ABORT_IF_FALSE(surface, "valid address expected"); michael@0: surface.swap(*aSurface); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsDeviceContextSpecAndroid::Init(nsIWidget* aWidget, michael@0: nsIPrintSettings* aPS, michael@0: bool aIsPrintPreview) michael@0: { michael@0: mPrintSettings = aPS; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsDeviceContextSpecAndroid::BeginDocument(const nsAString& aTitle, michael@0: char16_t* aPrintToFileName, michael@0: int32_t aStartPage, michael@0: int32_t aEndPage) michael@0: { michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsDeviceContextSpecAndroid::EndDocument() michael@0: { michael@0: nsXPIDLString targetPath; michael@0: nsCOMPtr destFile; michael@0: mPrintSettings->GetToFileName(getter_Copies(targetPath)); michael@0: michael@0: nsresult rv = NS_NewNativeLocalFile(NS_ConvertUTF16toUTF8(targetPath), michael@0: false, getter_AddRefs(destFile)); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: nsAutoString destLeafName; michael@0: rv = destFile->GetLeafName(destLeafName); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: nsCOMPtr destDir; michael@0: rv = destFile->GetParent(getter_AddRefs(destDir)); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: rv = mTempFile->MoveTo(destDir, destLeafName); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: destFile->SetPermissions(0666); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsDeviceContextSpecAndroid::GetPath (const char** aPath) michael@0: { michael@0: return NS_OK; michael@0: }