printing_message_filter.h revision 3551c9c881056c480085172ff9840cab31610854
1// Copyright (c) 2012 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 8#include <string> 9 10#include "base/compiler_specific.h" 11#include "content/public/browser/browser_message_filter.h" 12 13#if defined(OS_WIN) 14#include "base/memory/shared_memory.h" 15#endif 16 17struct PrintHostMsg_ScriptedPrint_Params; 18class Profile; 19class ProfileIOData; 20 21namespace base { 22class DictionaryValue; 23class FilePath; 24} 25 26namespace content { 27class WebContents; 28} 29 30namespace printing { 31class PrinterQuery; 32class PrintJobManager; 33} 34 35// This class filters out incoming printing related IPC messages for the 36// renderer process on the IPC thread. 37class PrintingMessageFilter : public content::BrowserMessageFilter { 38 public: 39 PrintingMessageFilter(int render_process_id, Profile* profile); 40 41 // content::BrowserMessageFilter methods. 42 virtual void OverrideThreadForMessage( 43 const IPC::Message& message, 44 content::BrowserThread::ID* thread) OVERRIDE; 45 virtual bool OnMessageReceived(const IPC::Message& message, 46 bool* message_was_ok) OVERRIDE; 47 48 private: 49 virtual ~PrintingMessageFilter(); 50 51#if defined(OS_WIN) 52 // Used to pass resulting EMF from renderer to browser in printing. 53 void OnDuplicateSection(base::SharedMemoryHandle renderer_handle, 54 base::SharedMemoryHandle* browser_handle); 55#endif 56 57#if defined(OS_CHROMEOS) || defined(OS_ANDROID) 58 // Used to ask the browser allocate a temporary file for the renderer 59 // to fill in resulting PDF in renderer. 60 void OnAllocateTempFileForPrinting(int render_view_id, 61 base::FileDescriptor* temp_file_fd, 62 int* sequence_number); 63 void OnTempFileForPrintingWritten(int render_view_id, int sequence_number); 64#endif 65 66#if defined(OS_CHROMEOS) 67 void CreatePrintDialogForFile(int render_view_id, const base::FilePath& path); 68#endif 69 70#if defined(OS_ANDROID) 71 // Updates the file descriptor for the PrintViewManagerBasic of a given 72 // render_view_id. 73 void UpdateFileDescriptor(int render_view_id, int fd); 74#endif 75 76 // Given a render_view_id get the corresponding WebContents. 77 // Must be called on the UI thread. 78 content::WebContents* GetWebContentsForRenderView(int render_view_id); 79 80 // GetPrintSettingsForRenderView must be called via PostTask and 81 // base::Bind. Collapse the settings-specific params into a 82 // struct to avoid running into issues with too many params 83 // to base::Bind. 84 struct GetPrintSettingsForRenderViewParams; 85 86 // Retrieve print settings. Uses |render_view_id| to get a parent 87 // for any UI created if needed. 88 void GetPrintSettingsForRenderView( 89 int render_view_id, 90 GetPrintSettingsForRenderViewParams params, 91 const base::Closure& callback, 92 scoped_refptr<printing::PrinterQuery> printer_query); 93 94 // Checks if printing is enabled. 95 void OnIsPrintingEnabled(bool* is_enabled); 96 97 // Get the default print setting. 98 void OnGetDefaultPrintSettings(IPC::Message* reply_msg); 99 void OnGetDefaultPrintSettingsReply( 100 scoped_refptr<printing::PrinterQuery> printer_query, 101 IPC::Message* reply_msg); 102 103 // The renderer host have to show to the user the print dialog and returns 104 // the selected print settings. The task is handled by the print worker 105 // thread and the UI thread. The reply occurs on the IO thread. 106 void OnScriptedPrint(const PrintHostMsg_ScriptedPrint_Params& params, 107 IPC::Message* reply_msg); 108 void OnScriptedPrintReply( 109 scoped_refptr<printing::PrinterQuery> printer_query, 110 IPC::Message* reply_msg); 111 112 // Modify the current print settings based on |job_settings|. The task is 113 // handled by the print worker thread and the UI thread. The reply occurs on 114 // the IO thread. 115 void OnUpdatePrintSettings(int document_cookie, 116 const base::DictionaryValue& job_settings, 117 IPC::Message* reply_msg); 118 void OnUpdatePrintSettingsReply( 119 scoped_refptr<printing::PrinterQuery> printer_query, 120 IPC::Message* reply_msg); 121 122#if defined(ENABLE_FULL_PRINTING) 123 // Check to see if print preview has been cancelled. 124 void OnCheckForCancel(int32 preview_ui_id, 125 int preview_request_id, 126 bool* cancel); 127#endif 128 129 printing::PrintJobManager* print_job_manager_; 130 131 ProfileIOData* profile_io_data_; 132 133 const int render_process_id_; 134 135 DISALLOW_COPY_AND_ASSIGN(PrintingMessageFilter); 136}; 137 138#endif // CHROME_BROWSER_PRINTING_PRINTING_MESSAGE_FILTER_H_ 139