• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2014 The Chromium Embedded Framework Authors.
2 // Portions copyright (c) 2012 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 
6 #ifndef LIBCEF_BROWSER_PRINTING_PRINT_DIALOG_LINUX_H_
7 #define LIBCEF_BROWSER_PRINTING_PRINT_DIALOG_LINUX_H_
8 
9 #include "include/cef_print_handler.h"
10 #include "libcef/browser/browser_host_base.h"
11 
12 #include "base/compiler_specific.h"
13 #include "base/files/file_path.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/task/sequenced_task_runner_helpers.h"
16 #include "content/public/browser/browser_thread.h"
17 #include "printing/print_dialog_gtk_interface.h"
18 #include "printing/printing_context_linux.h"
19 
20 namespace printing {
21 class MetafilePlayer;
22 class PrintSettings;
23 }  // namespace printing
24 
25 using printing::PrintingContextLinux;
26 
27 // Needs to be freed on the UI thread to clean up its member variables.
28 class CefPrintDialogLinux : public printing::PrintDialogGtkInterface,
29                             public base::RefCountedThreadSafe<
30                                 CefPrintDialogLinux,
31                                 content::BrowserThread::DeleteOnUIThread> {
32  public:
33   CefPrintDialogLinux(const CefPrintDialogLinux&) = delete;
34   CefPrintDialogLinux& operator=(const CefPrintDialogLinux&) = delete;
35 
36   // Creates and returns a print dialog.
37   static printing::PrintDialogGtkInterface* CreatePrintDialog(
38       PrintingContextLinux* context);
39 
40   // Returns the paper size in device units.
41   static gfx::Size GetPdfPaperSize(printing::PrintingContextLinux* context);
42 
43   // Notify the client when printing has started.
44   static void OnPrintStart(CefRefPtr<CefBrowserHostBase> browser);
45 
46   // PrintDialogGtkInterface implementation.
47   void UseDefaultSettings() override;
48   void UpdateSettings(
49       std::unique_ptr<printing::PrintSettings> settings) override;
50   void ShowDialog(
51       gfx::NativeView parent_view,
52       bool has_selection,
53       PrintingContextLinux::PrintSettingsCallback callback) override;
54   void PrintDocument(const printing::MetafilePlayer& metafile,
55                      const std::u16string& document_name) override;
56   void AddRefToDialog() override;
57   void ReleaseDialog() override;
58 
59  private:
60   friend class base::DeleteHelper<CefPrintDialogLinux>;
61   friend class base::RefCountedThreadSafe<
62       CefPrintDialogLinux,
63       content::BrowserThread::DeleteOnUIThread>;
64   friend struct content::BrowserThread::DeleteOnThread<
65       content::BrowserThread::UI>;
66   friend class CefPrintDialogCallbackImpl;
67   friend class CefPrintJobCallbackImpl;
68 
69   explicit CefPrintDialogLinux(PrintingContextLinux* context);
70   ~CefPrintDialogLinux() override;
71 
72   void SetHandler();
73   void ReleaseHandler();
74 
75   bool UpdateSettings(std::unique_ptr<printing::PrintSettings> settings,
76                       bool get_defaults);
77 
78   // Prints document named |document_name|.
79   void SendDocumentToPrinter(const std::u16string& document_name);
80 
81   // Handles print dialog response.
82   void OnPrintContinue(CefRefPtr<CefPrintSettings> settings);
83   void OnPrintCancel();
84 
85   // Handles print job response.
86   void OnJobCompleted();
87 
88   CefRefPtr<CefPrintHandler> handler_;
89 
90   // Printing dialog callback.
91   PrintingContextLinux::PrintSettingsCallback callback_;
92   PrintingContextLinux* context_;
93   CefRefPtr<CefBrowserHostBase> browser_;
94 
95   base::FilePath path_to_pdf_;
96 };
97 
98 #endif  // LIBCEF_BROWSER_PRINTING_PRINT_DIALOG_LINUX_H_
99