Home | History | Annotate | Download | only in printing
      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   virtual void OverrideThreadForMessage(
     44       const IPC::Message& message,
     45       content::BrowserThread::ID* thread) OVERRIDE;
     46   virtual bool OnMessageReceived(const IPC::Message& message) 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   // Checks if printing is enabled.
     87   void OnIsPrintingEnabled(bool* is_enabled);
     88 
     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);
     93 
     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);
    101 
    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
    104   // the IO thread.
    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);
    110 
    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,
    115                         bool* cancel);
    116 #endif
    117 
    118   ProfileIOData* profile_io_data_;
    119 
    120   const int render_process_id_;
    121 
    122   scoped_refptr<PrintQueriesQueue> queue_;
    123 
    124   DISALLOW_COPY_AND_ASSIGN(PrintingMessageFilter);
    125 };
    126 
    127 }  // namespace printing
    128 
    129 #endif  // CHROME_BROWSER_PRINTING_PRINTING_MESSAGE_FILTER_H_
    130