OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_HANDLER_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_HANDLER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
15 #include "chrome/browser/printing/print_view_manager_observer.h" | 15 #include "chrome/browser/printing/print_view_manager_observer.h" |
16 #include "chrome/browser/ui/shell_dialogs.h" | 16 #include "chrome/browser/ui/shell_dialogs.h" |
17 #include "content/browser/webui/web_ui.h" | 17 #include "content/browser/webui/web_ui.h" |
18 #include "printing/print_job_constants.h" | 18 #include "printing/print_job_constants.h" |
19 | 19 |
20 class FilePath; | 20 class FilePath; |
21 class PrintSystemTaskProxy; | 21 class PrintSystemTaskProxy; |
22 class TabContentsWrapper; | 22 class TabContentsWrapper; |
23 | 23 |
24 namespace base { | 24 namespace base { |
25 class DictionaryValue; | 25 class DictionaryValue; |
26 class StringValue; | 26 class StringValue; |
27 } | 27 } |
28 | 28 |
29 namespace printing { | 29 namespace printing { |
| 30 struct PageSizeMargins; |
30 class PrintBackend; | 31 class PrintBackend; |
31 } | 32 } |
32 | 33 |
33 // The handler for Javascript messages related to the print preview dialog. | 34 // The handler for Javascript messages related to the print preview dialog. |
34 class PrintPreviewHandler : public WebUIMessageHandler, | 35 class PrintPreviewHandler : public WebUIMessageHandler, |
35 public base::SupportsWeakPtr<PrintPreviewHandler>, | 36 public base::SupportsWeakPtr<PrintPreviewHandler>, |
36 public SelectFileDialog::Listener, | 37 public SelectFileDialog::Listener, |
37 public printing::PrintViewManagerObserver { | 38 public printing::PrintViewManagerObserver { |
38 public: | 39 public: |
39 PrintPreviewHandler(); | 40 PrintPreviewHandler(); |
(...skipping 20 matching lines...) Expand all Loading... |
60 void OnTabDestroyed(); | 61 void OnTabDestroyed(); |
61 | 62 |
62 // Called when print preview failed. | 63 // Called when print preview failed. |
63 void OnPrintPreviewFailed(); | 64 void OnPrintPreviewFailed(); |
64 | 65 |
65 // Called when the user press ctrl+shift+p to display the native system | 66 // Called when the user press ctrl+shift+p to display the native system |
66 // dialog. | 67 // dialog. |
67 void ShowSystemDialog(); | 68 void ShowSystemDialog(); |
68 | 69 |
69 private: | 70 private: |
| 71 friend class PrintPreviewHandlerTest; |
70 friend class PrintSystemTaskProxy; | 72 friend class PrintSystemTaskProxy; |
| 73 FRIEND_TEST_ALL_PREFIXES(PrintPreviewHandlerTest, StickyMarginsCustom); |
| 74 FRIEND_TEST_ALL_PREFIXES(PrintPreviewHandlerTest, StickyMarginsDefault); |
| 75 FRIEND_TEST_ALL_PREFIXES(PrintPreviewHandlerTest, |
| 76 StickyMarginsCustomThenDefault); |
| 77 FRIEND_TEST_ALL_PREFIXES(PrintPreviewHandlerTest, |
| 78 GetLastUsedMarginSettingsCustom); |
| 79 FRIEND_TEST_ALL_PREFIXES(PrintPreviewHandlerTest, |
| 80 GetLastUsedMarginSettingsDefault); |
71 | 81 |
72 TabContentsWrapper* preview_tab_wrapper() const; | 82 TabContentsWrapper* preview_tab_wrapper() const; |
73 TabContents* preview_tab() const; | 83 TabContents* preview_tab() const; |
74 | 84 |
75 // Gets the default printer. |args| is unused. | |
76 void HandleGetDefaultPrinter(const base::ListValue* args); | |
77 | |
78 // Gets the list of printers. |args| is unused. | 85 // Gets the list of printers. |args| is unused. |
79 void HandleGetPrinters(const base::ListValue* args); | 86 void HandleGetPrinters(const base::ListValue* args); |
80 | 87 |
81 // Asks the initiator renderer to generate a preview. First element of |args| | 88 // Asks the initiator renderer to generate a preview. First element of |args| |
82 // is a job settings JSON string. | 89 // is a job settings JSON string. |
83 void HandleGetPreview(const base::ListValue* args); | 90 void HandleGetPreview(const base::ListValue* args); |
84 | 91 |
85 // Gets the job settings from Web UI and initiate printing. First element of | 92 // Gets the job settings from Web UI and initiate printing. First element of |
86 // |args| is a job settings JSON string. | 93 // |args| is a job settings JSON string. |
87 void HandlePrint(const base::ListValue* args); | 94 void HandlePrint(const base::ListValue* args); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 // Asks the browser to show the native printer management dialog. | 131 // Asks the browser to show the native printer management dialog. |
125 // |args| is unused. | 132 // |args| is unused. |
126 void HandleManagePrinters(const base::ListValue* args); | 133 void HandleManagePrinters(const base::ListValue* args); |
127 | 134 |
128 // Asks the browser to show the cloud print dialog. | 135 // Asks the browser to show the cloud print dialog. |
129 void HandlePrintWithCloudPrint(); | 136 void HandlePrintWithCloudPrint(); |
130 | 137 |
131 // Asks the browser to close the preview tab. |args| is unused. | 138 // Asks the browser to close the preview tab. |args| is unused. |
132 void HandleClosePreviewTab(const base::ListValue* args); | 139 void HandleClosePreviewTab(const base::ListValue* args); |
133 | 140 |
134 // Asks the browser for the title of the initiator tab. | 141 // Asks the browser for several settings that are needed before the first |
135 // |args| is unused. | 142 // preview is displayed. |
136 void HandleGetInitiatorTabTitle(const base::ListValue* args); | 143 void HandleGetInitialSettings(const base::ListValue* args); |
137 | 144 |
138 // Asks the browser for the number formatting and measurement system according | 145 void SendInitialSettings( |
139 // to the current locale. | 146 const std::string& default_printer, |
140 void HandleGetNumberFormatAndMeasurementSystem(const base::ListValue* args); | 147 const std::string& cloud_print_data); |
141 | 148 |
142 // Sends the printer capabilities to the Web UI. |settings_info| contains | 149 // Sends the printer capabilities to the Web UI. |settings_info| contains |
143 // printer capabilities information. | 150 // printer capabilities information. |
144 void SendPrinterCapabilities(const base::DictionaryValue& settings_info); | 151 void SendPrinterCapabilities(const base::DictionaryValue& settings_info); |
145 | 152 |
146 // Sends the default printer to the Web UI. | |
147 void SendDefaultPrinter(const base::StringValue& default_printer, | |
148 const base::StringValue& cloud_print_data); | |
149 | |
150 // Send the list of printers to the Web UI. | 153 // Send the list of printers to the Web UI. |
151 void SetupPrinterList(const base::ListValue& printers); | 154 void SetupPrinterList(const base::ListValue& printers); |
152 | 155 |
153 // Send whether cloud print integration should be enabled. | 156 // Send whether cloud print integration should be enabled. |
154 void SendCloudPrintEnabled(); | 157 void SendCloudPrintEnabled(); |
155 | 158 |
156 // Send the PDF data to the cloud to print. | 159 // Send the PDF data to the cloud to print. |
157 void SendCloudPrintJob(const base::DictionaryValue& settings, | 160 void SendCloudPrintJob(const base::DictionaryValue& settings, |
158 std::string print_ticket); | 161 std::string print_ticket); |
159 | 162 |
(...skipping 11 matching lines...) Expand all Loading... |
171 | 174 |
172 // Hides the preview tab for printing. | 175 // Hides the preview tab for printing. |
173 void HidePreviewTab(); | 176 void HidePreviewTab(); |
174 | 177 |
175 // Clears initiator tab details for this preview tab. | 178 // Clears initiator tab details for this preview tab. |
176 void ClearInitiatorTabDetails(); | 179 void ClearInitiatorTabDetails(); |
177 | 180 |
178 // Posts a task to save to pdf at |print_to_pdf_path_|. | 181 // Posts a task to save to pdf at |print_to_pdf_path_|. |
179 void PostPrintToPdfTask(); | 182 void PostPrintToPdfTask(); |
180 | 183 |
| 184 // Populates |settings| according to the current locale. |
| 185 void GetNumberFormatAndMeasurementSystem(base::DictionaryValue* settings); |
| 186 |
| 187 // Populates |last_used_custom_margins| according to the last used margin |
| 188 // settings. |
| 189 void GetLastUsedMarginSettings( |
| 190 base::DictionaryValue* last_used_custom_margins); |
| 191 |
181 // Pointer to current print system. | 192 // Pointer to current print system. |
182 scoped_refptr<printing::PrintBackend> print_backend_; | 193 scoped_refptr<printing::PrintBackend> print_backend_; |
183 | 194 |
184 // The underlying dialog object. | 195 // The underlying dialog object. |
185 scoped_refptr<SelectFileDialog> select_file_dialog_; | 196 scoped_refptr<SelectFileDialog> select_file_dialog_; |
186 | 197 |
187 static FilePath* last_saved_path_; | 198 static FilePath* last_saved_path_; |
188 static std::string* last_used_printer_cloud_print_data_; | 199 static std::string* last_used_printer_cloud_print_data_; |
189 static std::string* last_used_printer_name_; | 200 static std::string* last_used_printer_name_; |
190 static printing::ColorModels last_used_color_model_; | 201 static printing::ColorModels last_used_color_model_; |
191 static printing::MarginType last_used_margins_type_; | 202 static printing::MarginType last_used_margins_type_; |
| 203 static printing::PageSizeMargins* last_used_page_size_margins_; |
192 | 204 |
193 // A count of how many requests received to regenerate preview data. | 205 // A count of how many requests received to regenerate preview data. |
194 // Initialized to 0 then incremented and emitted to a histogram. | 206 // Initialized to 0 then incremented and emitted to a histogram. |
195 int regenerate_preview_request_count_; | 207 int regenerate_preview_request_count_; |
196 | 208 |
197 // A count of how many requests received to show manage printers dialog. | 209 // A count of how many requests received to show manage printers dialog. |
198 int manage_printers_dialog_request_count_; | 210 int manage_printers_dialog_request_count_; |
199 | 211 |
200 // Whether we have already logged a failed print preview. | 212 // Whether we have already logged a failed print preview. |
201 bool reported_failed_preview_; | 213 bool reported_failed_preview_; |
202 | 214 |
203 // Whether we have already logged the number of printers this session. | 215 // Whether we have already logged the number of printers this session. |
204 bool has_logged_printers_count_; | 216 bool has_logged_printers_count_; |
205 | 217 |
206 // Holds the path to the print to pdf request. It is empty if no such request | 218 // Holds the path to the print to pdf request. It is empty if no such request |
207 // exists. | 219 // exists. |
208 scoped_ptr<FilePath> print_to_pdf_path_; | 220 scoped_ptr<FilePath> print_to_pdf_path_; |
209 | 221 |
210 DISALLOW_COPY_AND_ASSIGN(PrintPreviewHandler); | 222 DISALLOW_COPY_AND_ASSIGN(PrintPreviewHandler); |
211 }; | 223 }; |
212 | 224 |
213 #endif // CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_HANDLER_H_ | 225 #endif // CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_HANDLER_H_ |
OLD | NEW |