print_view_manager_electron.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright 2020 Microsoft, Inc. All rights reserved.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ELECTRON_SHELL_BROWSER_PRINTING_PRINT_VIEW_MANAGER_ELECTRON_H_
  5. #define ELECTRON_SHELL_BROWSER_PRINTING_PRINT_VIEW_MANAGER_ELECTRON_H_
  6. #include <string>
  7. #include <vector>
  8. #include "base/memory/ref_counted_memory.h"
  9. #include "build/build_config.h"
  10. #include "chrome/browser/printing/print_view_manager_base.h"
  11. #include "components/printing/browser/print_to_pdf/pdf_print_job.h"
  12. #include "components/printing/common/print.mojom.h"
  13. #include "content/public/browser/render_frame_host.h"
  14. #include "content/public/browser/web_contents_observer.h"
  15. #include "content/public/browser/web_contents_user_data.h"
  16. #include "printing/print_settings.h"
  17. namespace electron {
  18. using PrintToPdfCallback = print_to_pdf::PdfPrintJob::PrintToPdfCallback;
  19. class PrintViewManagerElectron
  20. : public printing::PrintViewManagerBase,
  21. public content::WebContentsUserData<PrintViewManagerElectron> {
  22. public:
  23. ~PrintViewManagerElectron() override;
  24. PrintViewManagerElectron(const PrintViewManagerElectron&) = delete;
  25. PrintViewManagerElectron& operator=(const PrintViewManagerElectron&) = delete;
  26. static void BindPrintManagerHost(
  27. mojo::PendingAssociatedReceiver<printing::mojom::PrintManagerHost>
  28. receiver,
  29. content::RenderFrameHost* rfh);
  30. void DidPrintToPdf(int cookie,
  31. PrintToPdfCallback callback,
  32. print_to_pdf::PdfPrintResult result,
  33. scoped_refptr<base::RefCountedMemory> memory);
  34. void PrintToPdf(content::RenderFrameHost* rfh,
  35. const std::string& page_ranges,
  36. printing::mojom::PrintPagesParamsPtr print_page_params,
  37. PrintToPdfCallback callback);
  38. private:
  39. friend class content::WebContentsUserData<PrintViewManagerElectron>;
  40. explicit PrintViewManagerElectron(content::WebContents* web_contents);
  41. // printing::mojom::PrintManagerHost:
  42. void DidGetPrintedPagesCount(int32_t cookie, uint32_t number_pages) override;
  43. void GetDefaultPrintSettings(
  44. GetDefaultPrintSettingsCallback callback) override;
  45. void ScriptedPrint(printing::mojom::ScriptedPrintParamsPtr params,
  46. ScriptedPrintCallback callback) override;
  47. #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
  48. void SetupScriptedPrintPreview(
  49. SetupScriptedPrintPreviewCallback callback) override;
  50. void ShowScriptedPrintPreview(bool source_is_modifiable) override;
  51. void RequestPrintPreview(
  52. printing::mojom::RequestPrintPreviewParamsPtr params) override;
  53. void CheckForCancel(int32_t preview_ui_id,
  54. int32_t request_id,
  55. CheckForCancelCallback callback) override;
  56. #endif
  57. std::vector<int32_t> pdf_jobs_;
  58. base::WeakPtrFactory<PrintViewManagerElectron> weak_factory_{this};
  59. WEB_CONTENTS_USER_DATA_KEY_DECL();
  60. };
  61. } // namespace electron
  62. #endif // ELECTRON_SHELL_BROWSER_PRINTING_PRINT_VIEW_MANAGER_ELECTRON_H_