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) OVERRIDE;
49 virtual ~PrintingMessageFilter();
52 // Used to pass resulting EMF from renderer to browser in printing.
53 void OnDuplicateSection(base::SharedMemoryHandle renderer_handle,
54 base::SharedMemoryHandle* browser_handle);
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);
66 #if defined(OS_CHROMEOS)
67 void CreatePrintDialogForFile(int render_view_id, const base::FilePath& path);
70 #if defined(OS_ANDROID)
71 // Updates the file descriptor for the PrintViewManagerBasic of a given
73 void UpdateFileDescriptor(int render_view_id, int fd);
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);
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
84 struct GetPrintSettingsForRenderViewParams;
86 // Checks if printing is enabled.
87 void OnIsPrintingEnabled(bool* is_enabled);
89 // Get the default print setting.
90 void OnGetDefaultPrintSettings(IPC::Message* reply_msg);
91 void OnGetDefaultPrintSettingsReply(scoped_refptr<PrinterQuery> printer_query,
92 IPC::Message* reply_msg);
94 // The renderer host have to show to the user the print dialog and returns
95 // the selected print settings. The task is handled by the print worker
96 // thread and the UI thread. The reply occurs on the IO thread.
97 void OnScriptedPrint(const PrintHostMsg_ScriptedPrint_Params& params,
98 IPC::Message* reply_msg);
99 void OnScriptedPrintReply(scoped_refptr<PrinterQuery> printer_query,
100 IPC::Message* reply_msg);
102 // Modify the current print settings based on |job_settings|. The task is
103 // handled by the print worker thread and the UI thread. The reply occurs on
105 void OnUpdatePrintSettings(int document_cookie,
106 const base::DictionaryValue& job_settings,
107 IPC::Message* reply_msg);
108 void OnUpdatePrintSettingsReply(scoped_refptr<PrinterQuery> printer_query,
109 IPC::Message* reply_msg);
111 #if defined(ENABLE_FULL_PRINTING)
112 // Check to see if print preview has been cancelled.
113 void OnCheckForCancel(int32 preview_ui_id,
114 int preview_request_id,
118 ProfileIOData* profile_io_data_;
120 const int render_process_id_;
122 scoped_refptr<PrintQueriesQueue> queue_;
124 DISALLOW_COPY_AND_ASSIGN(PrintingMessageFilter);
127 } // namespace printing
129 #endif // CHROME_BROWSER_PRINTING_PRINTING_MESSAGE_FILTER_H_