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/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 // Creates and returns a print dialog. 34 static printing::PrintDialogGtkInterface* CreatePrintDialog( 35 PrintingContextLinux* context); 36 37 // Returns the paper size in device units. 38 static gfx::Size GetPdfPaperSize(printing::PrintingContextLinux* context); 39 40 // Notify the client when printing has started. 41 static void OnPrintStart(CefRefPtr<CefBrowserHostBase> browser); 42 43 // PrintDialogGtkInterface implementation. 44 void UseDefaultSettings() override; 45 void UpdateSettings( 46 std::unique_ptr<printing::PrintSettings> settings) override; 47 void ShowDialog( 48 gfx::NativeView parent_view, 49 bool has_selection, 50 PrintingContextLinux::PrintSettingsCallback callback) override; 51 void PrintDocument(const printing::MetafilePlayer& metafile, 52 const std::u16string& document_name) override; 53 void AddRefToDialog() override; 54 void ReleaseDialog() override; 55 56 private: 57 friend class base::DeleteHelper<CefPrintDialogLinux>; 58 friend class base::RefCountedThreadSafe< 59 CefPrintDialogLinux, 60 content::BrowserThread::DeleteOnUIThread>; 61 friend struct content::BrowserThread::DeleteOnThread< 62 content::BrowserThread::UI>; 63 friend class CefPrintDialogCallbackImpl; 64 friend class CefPrintJobCallbackImpl; 65 66 explicit CefPrintDialogLinux(PrintingContextLinux* context); 67 ~CefPrintDialogLinux() override; 68 69 void SetHandler(); 70 void ReleaseHandler(); 71 72 bool UpdateSettings(std::unique_ptr<printing::PrintSettings> settings, 73 bool get_defaults); 74 75 // Prints document named |document_name|. 76 void SendDocumentToPrinter(const std::u16string& document_name); 77 78 // Handles print dialog response. 79 void OnPrintContinue(CefRefPtr<CefPrintSettings> settings); 80 void OnPrintCancel(); 81 82 // Handles print job response. 83 void OnJobCompleted(); 84 85 CefRefPtr<CefPrintHandler> handler_; 86 87 // Printing dialog callback. 88 PrintingContextLinux::PrintSettingsCallback callback_; 89 PrintingContextLinux* context_; 90 CefRefPtr<CefBrowserHostBase> browser_; 91 92 base::FilePath path_to_pdf_; 93 94 DISALLOW_COPY_AND_ASSIGN(CefPrintDialogLinux); 95 }; 96 97 #endif // LIBCEF_BROWSER_PRINTING_PRINT_DIALOG_LINUX_H_ 98