1 // Copyright (c) 2011 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 CHROME_BROWSER_PRINTING_PRINTING_MESSAGE_FILTER_H_ 6 #define CHROME_BROWSER_PRINTING_PRINTING_MESSAGE_FILTER_H_ 7 #pragma once 8 9 #include "content/browser/browser_message_filter.h" 10 11 #if defined(OS_WIN) 12 #include "base/shared_memory.h" 13 #endif 14 15 class DictionaryValue; 16 struct PrintHostMsg_ScriptedPrint_Params; 17 18 namespace printing { 19 class PrinterQuery; 20 class PrintJobManager; 21 } 22 23 // This class filters out incoming printing related IPC messages for the 24 // renderer process on the IPC thread. 25 class PrintingMessageFilter : public BrowserMessageFilter { 26 public: 27 PrintingMessageFilter(); 28 29 // BrowserMessageFilter methods. 30 virtual void OverrideThreadForMessage(const IPC::Message& message, 31 BrowserThread::ID* thread); 32 virtual bool OnMessageReceived(const IPC::Message& message, 33 bool* message_was_ok); 34 35 private: 36 virtual ~PrintingMessageFilter(); 37 38 #if defined(OS_WIN) 39 // Used to pass resulting EMF from renderer to browser in printing. 40 void OnDuplicateSection(base::SharedMemoryHandle renderer_handle, 41 base::SharedMemoryHandle* browser_handle); 42 #endif 43 44 #if defined(OS_CHROMEOS) 45 // Used to ask the browser allocate a temporary file for the renderer 46 // to fill in resulting PDF in renderer. 47 void OnAllocateTempFileForPrinting(base::FileDescriptor* temp_file_fd, 48 int* sequence_number); 49 void OnTempFileForPrintingWritten(int sequence_number); 50 #endif 51 52 // A javascript code requested to print the current page. This is done in two 53 // steps and this is the first step. Get the print setting right here 54 // synchronously. It will hang the I/O completely. 55 void OnGetDefaultPrintSettings(IPC::Message* reply_msg); 56 void OnGetDefaultPrintSettingsReply( 57 scoped_refptr<printing::PrinterQuery> printer_query, 58 IPC::Message* reply_msg); 59 60 // A javascript code requested to print the current page. The renderer host 61 // have to show to the user the print dialog and returns the selected print 62 // settings. 63 void OnScriptedPrint(const PrintHostMsg_ScriptedPrint_Params& params, 64 IPC::Message* reply_msg); 65 void OnScriptedPrintReply( 66 scoped_refptr<printing::PrinterQuery> printer_query, 67 int routing_id, 68 IPC::Message* reply_msg); 69 70 void OnUpdatePrintSettings(int document_cookie, 71 const DictionaryValue& job_settings, 72 IPC::Message* reply_msg); 73 void OnUpdatePrintSettingsReply( 74 scoped_refptr<printing::PrinterQuery> printer_query, 75 IPC::Message* reply_msg); 76 77 printing::PrintJobManager* print_job_manager_; 78 79 bool cloud_print_enabled_; 80 81 DISALLOW_COPY_AND_ASSIGN(PrintingMessageFilter); 82 }; 83 84 #endif // CHROME_BROWSER_PRINTING_PRINTING_MESSAGE_FILTER_H_ 85