printing_context_android.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. #ifndef PRINTING_PRINTING_CONTEXT_ANDROID_H_
  5. #define PRINTING_PRINTING_CONTEXT_ANDROID_H_
  6. #include <string>
  7. #include "base/android/scoped_java_ref.h"
  8. #include "base/file_descriptor_posix.h"
  9. #include "printing/mojom/print.mojom.h"
  10. #include "printing/printing_context.h"
  11. namespace ui {
  12. class WindowAndroid;
  13. }
  14. namespace printing {
  15. // Android subclass of PrintingContext. This class communicates with the
  16. // Java side through JNI.
  17. class COMPONENT_EXPORT(PRINTING) PrintingContextAndroid
  18. : public PrintingContext {
  19. public:
  20. explicit PrintingContextAndroid(Delegate* delegate);
  21. PrintingContextAndroid(const PrintingContextAndroid&) = delete;
  22. PrintingContextAndroid& operator=(const PrintingContextAndroid&) = delete;
  23. ~PrintingContextAndroid() override;
  24. // Called when the page is successfully written to a PDF using the file
  25. // descriptor specified, or when the printing operation failed. On success,
  26. // the PDF has `page_count` pages. Non-positive `page_count` indicates
  27. // failure.
  28. static void PdfWritingDone(int page_count);
  29. static void SetPendingPrint(
  30. ui::WindowAndroid* window,
  31. const base::android::ScopedJavaLocalRef<jobject>& printable,
  32. int render_process_id,
  33. int render_frame_id);
  34. // Called from Java, when printing settings from the user are ready or the
  35. // printing operation is canceled.
  36. void AskUserForSettingsReply(JNIEnv* env,
  37. const base::android::JavaParamRef<jobject>& obj,
  38. jboolean success);
  39. // Called from Java, when a printing process initiated by a script finishes.
  40. void ShowSystemDialogDone(JNIEnv* env,
  41. const base::android::JavaParamRef<jobject>& obj);
  42. // PrintingContext implementation.
  43. void AskUserForSettings(int max_pages,
  44. bool has_selection,
  45. bool is_scripted,
  46. PrintSettingsCallback callback) override;
  47. mojom::ResultCode UseDefaultSettings() override;
  48. gfx::Size GetPdfPaperSizeDeviceUnits() override;
  49. mojom::ResultCode UpdatePrinterSettings(
  50. const PrinterSettings& printer_settings) override;
  51. mojom::ResultCode NewDocument(const std::u16string& document_name) override;
  52. mojom::ResultCode PrintDocument(const MetafilePlayer& metafile,
  53. const PrintSettings& settings,
  54. uint32_t num_pages) override;
  55. mojom::ResultCode DocumentDone() override;
  56. void Cancel() override;
  57. void ReleaseContext() override;
  58. printing::NativeDrawingContext context() const override;
  59. private:
  60. bool is_file_descriptor_valid() const { return fd_ > base::kInvalidFd; }
  61. base::android::ScopedJavaGlobalRef<jobject> j_printing_context_;
  62. // The callback from AskUserForSettings to be called when the settings are
  63. // ready on the Java side
  64. PrintSettingsCallback callback_;
  65. int fd_ = base::kInvalidFd;
  66. };
  67. } // namespace printing
  68. #endif // PRINTING_PRINTING_CONTEXT_ANDROID_H_