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.
5 #ifndef CHROME_BROWSER_PRINTING_PRINTING_MESSAGE_FILTER_H_
6 #define CHROME_BROWSER_PRINTING_PRINTING_MESSAGE_FILTER_H_
10 #include "base/compiler_specific.h"
11 #include "content/public/browser/browser_message_filter.h"
14 #include "base/memory/shared_memory.h"
17 struct PrintHostMsg_ScriptedPrint_Params;
22 class DictionaryValue;
32 class PrintJobManager;
33 class PrintQueriesQueue;
36 // This class filters out incoming printing related IPC messages for the
37 // renderer process on the IPC thread.
38 class PrintingMessageFilter : public content::BrowserMessageFilter {
40 PrintingMessageFilter(int render_process_id, Profile* profile);
42 // content::BrowserMessageFilter methods.
43 virtual void OverrideThreadForMessage(
44 const IPC::Message& message,
45 content::BrowserThread::ID* thread) OVERRIDE;
46 virtual bool OnMessageReceived(const IPC::Message& message,
47 bool* message_was_ok) OVERRIDE;
50 virtual ~PrintingMessageFilter();
53 // Used to pass resulting EMF from renderer to browser in printing.
54 void OnDuplicateSection(base::SharedMemoryHandle renderer_handle,
55 base::SharedMemoryHandle* browser_handle);
58 #if defined(OS_CHROMEOS) || defined(OS_ANDROID)
59 // Used to ask the browser allocate a temporary file for the renderer
60 // to fill in resulting PDF in renderer.
61 void OnAllocateTempFileForPrinting(int render_view_id,
62 base::FileDescriptor* temp_file_fd,
63 int* sequence_number);
64 void OnTempFileForPrintingWritten(int render_view_id, int sequence_number);
67 #if defined(OS_CHROMEOS)
68 void CreatePrintDialogForFile(int render_view_id, const base::FilePath& path);
71 #if defined(OS_ANDROID)
72 // Updates the file descriptor for the PrintViewManagerBasic of a given
74 void UpdateFileDescriptor(int render_view_id, int fd);
77 // Given a render_view_id get the corresponding WebContents.
78 // Must be called on the UI thread.
79 content::WebContents* GetWebContentsForRenderView(int render_view_id);
81 // GetPrintSettingsForRenderView must be called via PostTask and
82 // base::Bind. Collapse the settings-specific params into a
83 // struct to avoid running into issues with too many params
85 struct GetPrintSettingsForRenderViewParams;
87 // Retrieve print settings. Uses |render_view_id| to get a parent
88 // for any UI created if needed.
89 void GetPrintSettingsForRenderView(
91 GetPrintSettingsForRenderViewParams params,
92 const base::Closure& callback,
93 scoped_refptr<printing::PrinterQuery> printer_query);
95 void OnGetPrintSettingsFailed(
96 const base::Closure& callback,
97 scoped_refptr<printing::PrinterQuery> printer_query);
99 // Checks if printing is enabled.
100 void OnIsPrintingEnabled(bool* is_enabled);
102 // Get the default print setting.
103 void OnGetDefaultPrintSettings(IPC::Message* reply_msg);
104 void OnGetDefaultPrintSettingsReply(
105 scoped_refptr<printing::PrinterQuery> printer_query,
106 IPC::Message* reply_msg);
108 // The renderer host have to show to the user the print dialog and returns
109 // the selected print settings. The task is handled by the print worker
110 // thread and the UI thread. The reply occurs on the IO thread.
111 void OnScriptedPrint(const PrintHostMsg_ScriptedPrint_Params& params,
112 IPC::Message* reply_msg);
113 void OnScriptedPrintReply(
114 scoped_refptr<printing::PrinterQuery> printer_query,
115 IPC::Message* reply_msg);
117 // Modify the current print settings based on |job_settings|. The task is
118 // handled by the print worker thread and the UI thread. The reply occurs on
120 void OnUpdatePrintSettings(int document_cookie,
121 const base::DictionaryValue& job_settings,
122 IPC::Message* reply_msg);
123 void OnUpdatePrintSettingsReply(
124 scoped_refptr<printing::PrinterQuery> printer_query,
125 IPC::Message* reply_msg);
127 #if defined(ENABLE_FULL_PRINTING)
128 // Check to see if print preview has been cancelled.
129 void OnCheckForCancel(int32 preview_ui_id,
130 int preview_request_id,
134 ProfileIOData* profile_io_data_;
136 const int render_process_id_;
138 scoped_refptr<printing::PrintQueriesQueue> queue_;
140 DISALLOW_COPY_AND_ASSIGN(PrintingMessageFilter);
143 #endif // CHROME_BROWSER_PRINTING_PRINTING_MESSAGE_FILTER_H_