[email protected] | b25f003 | 2013-08-19 22:26:25 | [diff] [blame] | 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. |
| 4 | |
| 5 | #ifndef PRINTING_PRINTING_CONTEXT_ANDROID_H_ |
| 6 | #define PRINTING_PRINTING_CONTEXT_ANDROID_H_ |
| 7 | |
| 8 | #include <jni.h> |
| 9 | |
| 10 | #include <string> |
| 11 | |
| 12 | #include "base/android/scoped_java_ref.h" |
| 13 | #include "printing/printing_context.h" |
| 14 | |
| 15 | namespace printing { |
| 16 | |
dgn | 4c172eea | 2014-12-15 21:11:23 | [diff] [blame] | 17 | // Android subclass of PrintingContext. This class communicates with the |
[email protected] | b25f003 | 2013-08-19 22:26:25 | [diff] [blame] | 18 | // Java side through JNI. |
| 19 | class PRINTING_EXPORT PrintingContextAndroid : public PrintingContext { |
| 20 | public: |
Vitaly Buka | bd7c981 | 2014-08-26 08:57:54 | [diff] [blame] | 21 | explicit PrintingContextAndroid(Delegate* delegate); |
dcheng | ff7922e | 2015-02-06 03:37:13 | [diff] [blame] | 22 | ~PrintingContextAndroid() override; |
[email protected] | b25f003 | 2013-08-19 22:26:25 | [diff] [blame] | 23 | |
| 24 | // Called when the page is successfully written to a PDF using the file |
| 25 | // descriptor specified, or when the printing operation failed. |
| 26 | static void PdfWritingDone(int fd, bool success); |
| 27 | |
| 28 | // Called from Java, when printing settings from the user are ready or the |
| 29 | // printing operation is canceled. |
[email protected] | b9321a7 | 2013-08-23 12:55:32 | [diff] [blame] | 30 | void AskUserForSettingsReply(JNIEnv* env, jobject obj, jboolean success); |
[email protected] | b25f003 | 2013-08-19 22:26:25 | [diff] [blame] | 31 | |
dgn | 4c172eea | 2014-12-15 21:11:23 | [diff] [blame] | 32 | // Called from Java, when a printing process initiated by a script finishes. |
| 33 | void ShowSystemDialogDone(JNIEnv* env, jobject obj); |
| 34 | |
[email protected] | b25f003 | 2013-08-19 22:26:25 | [diff] [blame] | 35 | // PrintingContext implementation. |
dcheng | ff7922e | 2015-02-06 03:37:13 | [diff] [blame] | 36 | void AskUserForSettings(int max_pages, |
| 37 | bool has_selection, |
| 38 | bool is_scripted, |
| 39 | const PrintSettingsCallback& callback) override; |
| 40 | Result UseDefaultSettings() override; |
| 41 | gfx::Size GetPdfPaperSizeDeviceUnits() override; |
| 42 | Result UpdatePrinterSettings(bool external_preview, |
vitalybuka | 95fa3c9 | 2015-05-05 03:03:32 | [diff] [blame] | 43 | bool show_system_dialog, |
| 44 | int page_count) override; |
dcheng | ff7922e | 2015-02-06 03:37:13 | [diff] [blame] | 45 | Result InitWithSettings(const PrintSettings& settings) override; |
| 46 | Result NewDocument(const base::string16& document_name) override; |
| 47 | Result NewPage() override; |
| 48 | Result PageDone() override; |
| 49 | Result DocumentDone() override; |
| 50 | void Cancel() override; |
| 51 | void ReleaseContext() override; |
| 52 | gfx::NativeDrawingContext context() const override; |
[email protected] | b25f003 | 2013-08-19 22:26:25 | [diff] [blame] | 53 | |
| 54 | // Registers JNI bindings for RegisterContext. |
| 55 | static bool RegisterPrintingContext(JNIEnv* env); |
| 56 | |
| 57 | private: |
| 58 | base::android::ScopedJavaGlobalRef<jobject> j_printing_context_; |
| 59 | |
| 60 | // The callback from AskUserForSettings to be called when the settings are |
| 61 | // ready on the Java side |
| 62 | PrintSettingsCallback callback_; |
| 63 | |
| 64 | DISALLOW_COPY_AND_ASSIGN(PrintingContextAndroid); |
| 65 | }; |
| 66 | |
| 67 | } // namespace printing |
| 68 | |
| 69 | #endif // PRINTING_PRINTING_CONTEXT_ANDROID_H_ |
| 70 | |