1 // Copyright 2013 The Chromium Authors
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/file_descriptor_posix.h"
12 #include "printing/mojom/print.mojom.h"
13 #include "printing/printing_context.h"
21 // Android subclass of PrintingContext. This class communicates with the
22 // Java side through JNI.
23 class COMPONENT_EXPORT(PRINTING) PrintingContextAndroid
24 : public PrintingContext {
26 explicit PrintingContextAndroid(Delegate* delegate);
27 PrintingContextAndroid(const PrintingContextAndroid&) = delete;
28 PrintingContextAndroid& operator=(const PrintingContextAndroid&) = delete;
29 ~PrintingContextAndroid() override;
31 // Called when the page is successfully written to a PDF using the file
32 // descriptor specified, or when the printing operation failed. On success,
33 // the PDF has `page_count` pages. Non-positive `page_count` indicates
35 static void PdfWritingDone(int page_count);
37 static void SetPendingPrint(
38 ui::WindowAndroid* window,
39 const base::android::ScopedJavaLocalRef<jobject>& printable,
40 int render_process_id,
43 // Called from Java, when printing settings from the user are ready or the
44 // printing operation is canceled.
45 void AskUserForSettingsReply(JNIEnv* env,
46 const base::android::JavaParamRef<jobject>& obj,
49 // Called from Java, when a printing process initiated by a script finishes.
50 void ShowSystemDialogDone(JNIEnv* env,
51 const base::android::JavaParamRef<jobject>& obj);
53 // PrintingContext implementation.
54 void AskUserForSettings(int max_pages,
57 PrintSettingsCallback callback) override;
58 mojom::ResultCode UseDefaultSettings() override;
59 gfx::Size GetPdfPaperSizeDeviceUnits() override;
60 mojom::ResultCode UpdatePrinterSettings(
61 const PrinterSettings& printer_settings) override;
62 mojom::ResultCode NewDocument(const std::u16string& document_name) override;
63 mojom::ResultCode PrintDocument(const MetafilePlayer& metafile,
64 const PrintSettings& settings,
65 uint32_t num_pages) override;
66 mojom::ResultCode DocumentDone() override;
67 void Cancel() override;
68 void ReleaseContext() override;
69 printing::NativeDrawingContext context() const override;
72 bool is_file_descriptor_valid() const { return fd_ > base::kInvalidFd; }
74 base::android::ScopedJavaGlobalRef<jobject> j_printing_context_;
76 // The callback from AskUserForSettings to be called when the settings are
77 // ready on the Java side
78 PrintSettingsCallback callback_;
80 int fd_ = base::kInvalidFd;
83 } // namespace printing
85 #endif // PRINTING_PRINTING_CONTEXT_ANDROID_H_