avayvod@chromium.org | 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 | |
avayvod@chromium.org | b25f003 | 2013-08-19 22:26:25 | [diff] [blame] | 8 | #include <string> |
| 9 | |
| 10 | #include "base/android/scoped_java_ref.h" |
avi | 126e93c | 2015-12-21 21:48:16 | [diff] [blame] | 11 | #include "base/macros.h" |
avayvod@chromium.org | b25f003 | 2013-08-19 22:26:25 | [diff] [blame] | 12 | #include "printing/printing_context.h" |
| 13 | |
| 14 | namespace printing { |
| 15 | |
dgn | 4c172eea | 2014-12-15 21:11:23 | [diff] [blame] | 16 | // Android subclass of PrintingContext. This class communicates with the |
avayvod@chromium.org | b25f003 | 2013-08-19 22:26:25 | [diff] [blame] | 17 | // Java side through JNI. |
| 18 | class PRINTING_EXPORT PrintingContextAndroid : public PrintingContext { |
| 19 | public: |
Vitaly Buka | bd7c981 | 2014-08-26 08:57:54 | [diff] [blame] | 20 | explicit PrintingContextAndroid(Delegate* delegate); |
dcheng | ff7922e | 2015-02-06 03:37:13 | [diff] [blame] | 21 | ~PrintingContextAndroid() override; |
avayvod@chromium.org | b25f003 | 2013-08-19 22:26:25 | [diff] [blame] | 22 | |
| 23 | // Called when the page is successfully written to a PDF using the file |
Shimi Zhang | b414956 | 2017-06-30 02:41:23 | [diff] [blame] | 24 | // descriptor specified, or when the printing operation failed. On success, |
| 25 | // the PDF written to |fd| has |page_count| pages. Non-positive |page_count| |
| 26 | // indicates failure. |
| 27 | static void PdfWritingDone(int fd, int page_count); |
avayvod@chromium.org | b25f003 | 2013-08-19 22:26:25 | [diff] [blame] | 28 | |
| 29 | // Called from Java, when printing settings from the user are ready or the |
| 30 | // printing operation is canceled. |
torne | 6f3f097 | 2015-11-25 18:04:30 | [diff] [blame] | 31 | void AskUserForSettingsReply(JNIEnv* env, |
| 32 | const base::android::JavaParamRef<jobject>& obj, |
| 33 | jboolean success); |
avayvod@chromium.org | b25f003 | 2013-08-19 22:26:25 | [diff] [blame] | 34 | |
dgn | 4c172eea | 2014-12-15 21:11:23 | [diff] [blame] | 35 | // Called from Java, when a printing process initiated by a script finishes. |
torne | 6f3f097 | 2015-11-25 18:04:30 | [diff] [blame] | 36 | void ShowSystemDialogDone(JNIEnv* env, |
| 37 | const base::android::JavaParamRef<jobject>& obj); |
dgn | 4c172eea | 2014-12-15 21:11:23 | [diff] [blame] | 38 | |
avayvod@chromium.org | b25f003 | 2013-08-19 22:26:25 | [diff] [blame] | 39 | // PrintingContext implementation. |
dcheng | ff7922e | 2015-02-06 03:37:13 | [diff] [blame] | 40 | void AskUserForSettings(int max_pages, |
| 41 | bool has_selection, |
| 42 | bool is_scripted, |
| 43 | const PrintSettingsCallback& callback) override; |
| 44 | Result UseDefaultSettings() override; |
| 45 | gfx::Size GetPdfPaperSizeDeviceUnits() override; |
| 46 | Result UpdatePrinterSettings(bool external_preview, |
vitalybuka | 95fa3c9 | 2015-05-05 03:03:32 | [diff] [blame] | 47 | bool show_system_dialog, |
| 48 | int page_count) override; |
dcheng | ff7922e | 2015-02-06 03:37:13 | [diff] [blame] | 49 | Result NewDocument(const base::string16& document_name) override; |
| 50 | Result NewPage() override; |
| 51 | Result PageDone() override; |
| 52 | Result DocumentDone() override; |
| 53 | void Cancel() override; |
| 54 | void ReleaseContext() override; |
Nico Weber | 8e55956 | 2017-10-03 01:25:26 | [diff] [blame] | 55 | printing::NativeDrawingContext context() const override; |
avayvod@chromium.org | b25f003 | 2013-08-19 22:26:25 | [diff] [blame] | 56 | |
avayvod@chromium.org | b25f003 | 2013-08-19 22:26:25 | [diff] [blame] | 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_ |