Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / printing / printing_message_filter.h
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
17 struct PrintHostMsg_ScriptedPrint_Params;
18 class Profile;
19 class ProfileIOData;
20
21 namespace base {
22 class DictionaryValue;
23 class FilePath;
24 }
25
26 namespace content {
27 class WebContents;
28 }
29
30 namespace printing {
31
32 class PrintJobManager;
33 class PrintQueriesQueue;
34 class PrinterQuery;
35
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 {
39  public:
40   PrintingMessageFilter(int render_process_id, Profile* profile);
41
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;
46
47  private:
48   ~PrintingMessageFilter() override;
49
50 #if defined(OS_WIN)
51   // Used to pass resulting EMF from renderer to browser in printing.
52   void OnDuplicateSection(base::SharedMemoryHandle renderer_handle,
53                           base::SharedMemoryHandle* browser_handle);
54 #endif
55
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);
63 #endif
64
65 #if defined(OS_CHROMEOS)
66   void CreatePrintDialogForFile(int render_view_id, const base::FilePath& path);
67 #endif
68
69 #if defined(OS_ANDROID)
70   // Updates the file descriptor for the PrintViewManagerBasic of a given
71   // render_view_id.
72   void UpdateFileDescriptor(int render_view_id, int fd);
73 #endif
74
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);
78
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
82   // to base::Bind.
83   struct GetPrintSettingsForRenderViewParams;
84
85   // Checks if printing is enabled.
86   void OnIsPrintingEnabled(bool* is_enabled);
87
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);
92
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);
100
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
103   // the IO thread.
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);
109
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,
114                         bool* cancel);
115 #endif
116
117   ProfileIOData* profile_io_data_;
118
119   const int render_process_id_;
120
121   scoped_refptr<PrintQueriesQueue> queue_;
122
123   DISALLOW_COPY_AND_ASSIGN(PrintingMessageFilter);
124 };
125
126 }  // namespace printing
127
128 #endif  // CHROME_BROWSER_PRINTING_PRINTING_MESSAGE_FILTER_H_