• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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_UI_WEBUI_PRINT_PREVIEW_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_HANDLER_H_
7 #pragma once
8 
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/weak_ptr.h"
11 #include "chrome/browser/ui/shell_dialogs.h"
12 #include "content/browser/webui/web_ui.h"
13 
14 class FilePath;
15 class PrintSystemTaskProxy;
16 class FundamentalValue;
17 
18 namespace printing {
19 class PrintBackend;
20 }
21 
22 // The handler for Javascript messages related to the "print preview" dialog.
23 class PrintPreviewHandler : public WebUIMessageHandler,
24                             public base::SupportsWeakPtr<PrintPreviewHandler>,
25                             public SelectFileDialog::Listener {
26  public:
27   PrintPreviewHandler();
28   virtual ~PrintPreviewHandler();
29 
30   // WebUIMessageHandler implementation.
31   virtual void RegisterMessages();
32 
33   // SelectFileDialog::Listener implementation.
34   virtual void FileSelected(const FilePath& path, int index, void* params);
35 
36   // Displays a modal dialog, prompting the user to select a file.
37   void SelectFile(const FilePath& default_path);
38 
39  private:
40   friend class PrintSystemTaskProxy;
41 
42   // Get the list of printers. |args| is unused.
43   void HandleGetPrinters(const ListValue* args);
44 
45   // Ask the initiator renderer to generate a preview.
46   // First element of |args| is a job settings JSON string.
47   void HandleGetPreview(const ListValue* args);
48 
49   // Get the job settings from Web UI and initiate printing.
50   // First element of |args| is a job settings JSON string.
51   void HandlePrint(const ListValue* args);
52 
53   // Get the printer capabilities.
54   // First element of |args| is the printer name.
55   void HandleGetPrinterCapabilities(const ListValue* args);
56 
57   // Send the printer capabilities to the Web UI.
58   // |settings_info| contains printer capabilities information.
59   void SendPrinterCapabilities(const DictionaryValue& settings_info);
60 
61   // Send the list of printers to the Web UI.
62   void SendPrinterList(const ListValue& printers,
63                        const FundamentalValue& default_printer_index);
64 
65   // Helper function to process the color setting in the dictionary.
66   void ProcessColorSetting(const DictionaryValue& settings);
67 
68   // Helper function to process the landscape setting in the dictionary.
69   void ProcessLandscapeSetting(const DictionaryValue& settings);
70 
71   // Pointer to current print system.
72   scoped_refptr<printing::PrintBackend> print_backend_;
73 
74   // The underlying dialog object.
75   scoped_refptr<SelectFileDialog> select_file_dialog_;
76 
77   static FilePath* last_saved_path_;
78 
79   DISALLOW_COPY_AND_ASSIGN(PrintPreviewHandler);
80 };
81 
82 #endif  // CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_HANDLER_H_
83