1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef PRINTING_PRINTING_CONTEXT_ANDROID_H_
6 #define PRINTING_PRINTING_CONTEXT_ANDROID_H_
10 #include "base/android/scoped_java_ref.h"
11 #include "base/macros.h"
12 #include "printing/printing_context.h"
18 // Android subclass of PrintingContext. This class communicates with the
19 // Java side through JNI.
20 class PRINTING_EXPORT PrintingContextAndroid : public PrintingContext {
22 explicit PrintingContextAndroid(Delegate* delegate);
23 ~PrintingContextAndroid() override;
25 // Called when the page is successfully written to a PDF using the file
26 // descriptor specified, or when the printing operation failed. On success,
27 // the PDF has |page_count| pages. Non-positive |page_count| indicates
29 static void PdfWritingDone(int page_count);
31 // Called from Java, when printing settings from the user are ready or the
32 // printing operation is canceled.
33 void AskUserForSettingsReply(JNIEnv* env,
34 const base::android::JavaParamRef<jobject>& obj,
37 // Called from Java, when a printing process initiated by a script finishes.
38 void ShowSystemDialogDone(JNIEnv* env,
39 const base::android::JavaParamRef<jobject>& obj);
41 // Prints the document contained in |metafile|.
42 void PrintDocument(const MetafilePlayer& metafile);
44 // PrintingContext implementation.
45 void AskUserForSettings(int max_pages,
48 PrintSettingsCallback callback) override;
49 Result UseDefaultSettings() override;
50 gfx::Size GetPdfPaperSizeDeviceUnits() override;
51 Result UpdatePrinterSettings(bool external_preview,
52 bool show_system_dialog,
53 int page_count) override;
54 Result NewDocument(const base::string16& document_name) override;
55 Result NewPage() override;
56 Result PageDone() override;
57 Result DocumentDone() override;
58 void Cancel() override;
59 void ReleaseContext() override;
60 printing::NativeDrawingContext context() const override;
63 // TODO(thestig): Use |base::kInvalidFd| once available.
64 bool is_file_descriptor_valid() const { return fd_ > -1; }
66 base::android::ScopedJavaGlobalRef<jobject> j_printing_context_;
68 // The callback from AskUserForSettings to be called when the settings are
69 // ready on the Java side
70 PrintSettingsCallback callback_;
74 DISALLOW_COPY_AND_ASSIGN(PrintingContextAndroid);
77 } // namespace printing
79 #endif // PRINTING_PRINTING_CONTEXT_ANDROID_H_