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 void OverrideThreadForMessage(const IPC::Message& message,
44 content::BrowserThread::ID* thread) override;
45 bool OnMessageReceived(const IPC::Message& message) override;
48 ~PrintingMessageFilter() override;
51 // Used to pass resulting EMF from renderer to browser in printing.
52 void OnDuplicateSection(base::SharedMemoryHandle renderer_handle,
53 base::SharedMemoryHandle* browser_handle);
56 #if defined(OS_CHROMEOS) || defined(OS_ANDROID)
57 // Used to ask the browser allocate a temporary file for the renderer
58 // to fill in resulting PDF in renderer.
59 void OnAllocateTempFileForPrinting(int render_view_id,
60 base::FileDescriptor* temp_file_fd,
61 int* sequence_number);
62 void OnTempFileForPrintingWritten(int render_view_id, int sequence_number);
65 #if defined(OS_CHROMEOS)
66 void CreatePrintDialogForFile(int render_view_id, const base::FilePath& path);
69 #if defined(OS_ANDROID)
70 // Updates the file descriptor for the PrintViewManagerBasic of a given
72 void UpdateFileDescriptor(int render_view_id, int fd);
75 // Given a render_view_id get the corresponding WebContents.
76 // Must be called on the UI thread.
77 content::WebContents* GetWebContentsForRenderView(int render_view_id);
79 // GetPrintSettingsForRenderView must be called via PostTask and
80 // base::Bind. Collapse the settings-specific params into a
81 // struct to avoid running into issues with too many params
83 struct GetPrintSettingsForRenderViewParams;
85 // Checks if printing is enabled.
86 void OnIsPrintingEnabled(bool* is_enabled);
88 // Get the default print setting.
89 void OnGetDefaultPrintSettings(IPC::Message* reply_msg);
90 void OnGetDefaultPrintSettingsReply(scoped_refptr<PrinterQuery> printer_query,
91 IPC::Message* reply_msg);
93 // The renderer host have to show to the user the print dialog and returns
94 // the selected print settings. The task is handled by the print worker
95 // thread and the UI thread. The reply occurs on the IO thread.
96 void OnScriptedPrint(const PrintHostMsg_ScriptedPrint_Params& params,
97 IPC::Message* reply_msg);
98 void OnScriptedPrintReply(scoped_refptr<PrinterQuery> printer_query,
99 IPC::Message* reply_msg);
101 // Modify the current print settings based on |job_settings|. The task is
102 // handled by the print worker thread and the UI thread. The reply occurs on
104 void OnUpdatePrintSettings(int document_cookie,
105 const base::DictionaryValue& job_settings,
106 IPC::Message* reply_msg);
107 void OnUpdatePrintSettingsReply(scoped_refptr<PrinterQuery> printer_query,
108 IPC::Message* reply_msg);
110 #if defined(ENABLE_PRINT_PREVIEW)
111 // Check to see if print preview has been cancelled.
112 void OnCheckForCancel(int32 preview_ui_id,
113 int preview_request_id,
117 ProfileIOData* profile_io_data_;
119 const int render_process_id_;
121 scoped_refptr<PrintQueriesQueue> queue_;
123 DISALLOW_COPY_AND_ASSIGN(PrintingMessageFilter);
126 } // namespace printing
128 #endif // CHROME_BROWSER_PRINTING_PRINTING_MESSAGE_FILTER_H_