Upload upstream chromium 73.0.3683.0
[platform/framework/web/chromium-efl.git] / printing / printing_context_android.h
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 <string>
9
10 #include "base/android/scoped_java_ref.h"
11 #include "base/macros.h"
12 #include "printing/printing_context.h"
13
14 namespace printing {
15
16 class MetafilePlayer;
17
18 // Android subclass of PrintingContext. This class communicates with the
19 // Java side through JNI.
20 class PRINTING_EXPORT PrintingContextAndroid : public PrintingContext {
21  public:
22   explicit PrintingContextAndroid(Delegate* delegate);
23   ~PrintingContextAndroid() override;
24
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
28   // failure.
29   static void PdfWritingDone(int page_count);
30
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,
35                                jboolean success);
36
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);
40
41   // Prints the document contained in |metafile|.
42   void PrintDocument(const MetafilePlayer& metafile);
43
44   // PrintingContext implementation.
45   void AskUserForSettings(int max_pages,
46                           bool has_selection,
47                           bool is_scripted,
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;
61
62  private:
63   // TODO(thestig): Use |base::kInvalidFd| once available.
64   bool is_file_descriptor_valid() const { return fd_ > -1; }
65
66   base::android::ScopedJavaGlobalRef<jobject> j_printing_context_;
67
68   // The callback from AskUserForSettings to be called when the settings are
69   // ready on the Java side
70   PrintSettingsCallback callback_;
71
72   int fd_ = -1;
73
74   DISALLOW_COPY_AND_ASSIGN(PrintingContextAndroid);
75 };
76
77 }  // namespace printing
78
79 #endif  // PRINTING_PRINTING_CONTEXT_ANDROID_H_