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 25 matching lines...) Expand all Loading... |
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: |
70 friend class PrintSystemTaskProxy; | 71 friend class PrintSystemTaskProxy; |
71 | 72 |
72 TabContentsWrapper* preview_tab_wrapper() const; | 73 TabContentsWrapper* preview_tab_wrapper() const; |
73 TabContents* preview_tab() const; | 74 TabContents* preview_tab() const; |
74 | 75 |
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. | 76 // Gets the list of printers. |args| is unused. |
79 void HandleGetPrinters(const base::ListValue* args); | 77 void HandleGetPrinters(const base::ListValue* args); |
80 | 78 |
81 // Asks the initiator renderer to generate a preview. First element of |args| | 79 // Asks the initiator renderer to generate a preview. First element of |args| |
82 // is a job settings JSON string. | 80 // is a job settings JSON string. |
83 void HandleGetPreview(const base::ListValue* args); | 81 void HandleGetPreview(const base::ListValue* args); |
84 | 82 |
85 // Gets the job settings from Web UI and initiate printing. First element of | 83 // Gets the job settings from Web UI and initiate printing. First element of |
86 // |args| is a job settings JSON string. | 84 // |args| is a job settings JSON string. |
87 void HandlePrint(const base::ListValue* args); | 85 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. | 122 // Asks the browser to show the native printer management dialog. |
125 // |args| is unused. | 123 // |args| is unused. |
126 void HandleManagePrinters(const base::ListValue* args); | 124 void HandleManagePrinters(const base::ListValue* args); |
127 | 125 |
128 // Asks the browser to show the cloud print dialog. | 126 // Asks the browser to show the cloud print dialog. |
129 void HandlePrintWithCloudPrint(); | 127 void HandlePrintWithCloudPrint(); |
130 | 128 |
131 // Asks the browser to close the preview tab. |args| is unused. | 129 // Asks the browser to close the preview tab. |args| is unused. |
132 void HandleClosePreviewTab(const base::ListValue* args); | 130 void HandleClosePreviewTab(const base::ListValue* args); |
133 | 131 |
134 // Asks the browser for the title of the initiator tab. | 132 // Asks the browser for several settings that are needed before the first |
135 // |args| is unused. | 133 // preview is displayed. |
136 void HandleGetInitiatorTabTitle(const base::ListValue* args); | 134 void HandleGetInitialSettings(const base::ListValue* args); |
137 | 135 |
138 // Asks the browser for the number formatting and measurement system according | 136 void SendInitialSettings( |
139 // to the current locale. | 137 const std::string& default_printer, |
140 void HandleGetNumberFormatAndMeasurementSystem(const base::ListValue* args); | 138 const std::string& cloud_print_data); |
141 | 139 |
142 // Sends the printer capabilities to the Web UI. |settings_info| contains | 140 // Sends the printer capabilities to the Web UI. |settings_info| contains |
143 // printer capabilities information. | 141 // printer capabilities information. |
144 void SendPrinterCapabilities(const base::DictionaryValue& settings_info); | 142 void SendPrinterCapabilities(const base::DictionaryValue& settings_info); |
145 | 143 |
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. | 144 // Send the list of printers to the Web UI. |
151 void SetupPrinterList(const base::ListValue& printers); | 145 void SetupPrinterList(const base::ListValue& printers); |
152 | 146 |
153 // Send whether cloud print integration should be enabled. | 147 // Send whether cloud print integration should be enabled. |
154 void SendCloudPrintEnabled(); | 148 void SendCloudPrintEnabled(); |
155 | 149 |
156 // Send the PDF data to the cloud to print. | 150 // Send the PDF data to the cloud to print. |
157 void SendCloudPrintJob(const base::DictionaryValue& settings, | 151 void SendCloudPrintJob(const base::DictionaryValue& settings, |
158 std::string print_ticket); | 152 std::string print_ticket); |
159 | 153 |
(...skipping 11 matching lines...) Expand all Loading... |
171 | 165 |
172 // Hides the preview tab for printing. | 166 // Hides the preview tab for printing. |
173 void HidePreviewTab(); | 167 void HidePreviewTab(); |
174 | 168 |
175 // Clears initiator tab details for this preview tab. | 169 // Clears initiator tab details for this preview tab. |
176 void ClearInitiatorTabDetails(); | 170 void ClearInitiatorTabDetails(); |
177 | 171 |
178 // Posts a task to save to pdf at |print_to_pdf_path_|. | 172 // Posts a task to save to pdf at |print_to_pdf_path_|. |
179 void PostPrintToPdfTask(); | 173 void PostPrintToPdfTask(); |
180 | 174 |
| 175 // Populates |settings| according to the current locale. |
| 176 void GetNumberFormatAndMeasurementSystem(base::DictionaryValue* settings); |
| 177 |
| 178 // Populates |last_used_custom_margins| according to the last used margin |
| 179 // settings. |
| 180 void GetLastUsedMarginSettings( |
| 181 base::DictionaryValue* last_used_custom_margins); |
| 182 |
181 // Pointer to current print system. | 183 // Pointer to current print system. |
182 scoped_refptr<printing::PrintBackend> print_backend_; | 184 scoped_refptr<printing::PrintBackend> print_backend_; |
183 | 185 |
184 // The underlying dialog object. | 186 // The underlying dialog object. |
185 scoped_refptr<SelectFileDialog> select_file_dialog_; | 187 scoped_refptr<SelectFileDialog> select_file_dialog_; |
186 | 188 |
187 static FilePath* last_saved_path_; | 189 static FilePath* last_saved_path_; |
188 static std::string* last_used_printer_cloud_print_data_; | 190 static std::string* last_used_printer_cloud_print_data_; |
189 static std::string* last_used_printer_name_; | 191 static std::string* last_used_printer_name_; |
190 static printing::ColorModels last_used_color_model_; | 192 static printing::ColorModels last_used_color_model_; |
191 static printing::MarginType last_used_margins_type_; | 193 static printing::MarginType last_used_margins_type_; |
| 194 static printing::PageSizeMargins* last_used_page_size_margins_; |
192 | 195 |
193 // A count of how many requests received to regenerate preview data. | 196 // A count of how many requests received to regenerate preview data. |
194 // Initialized to 0 then incremented and emitted to a histogram. | 197 // Initialized to 0 then incremented and emitted to a histogram. |
195 int regenerate_preview_request_count_; | 198 int regenerate_preview_request_count_; |
196 | 199 |
197 // A count of how many requests received to show manage printers dialog. | 200 // A count of how many requests received to show manage printers dialog. |
198 int manage_printers_dialog_request_count_; | 201 int manage_printers_dialog_request_count_; |
199 | 202 |
200 // Whether we have already logged a failed print preview. | 203 // Whether we have already logged a failed print preview. |
201 bool reported_failed_preview_; | 204 bool reported_failed_preview_; |
202 | 205 |
203 // Whether we have already logged the number of printers this session. | 206 // Whether we have already logged the number of printers this session. |
204 bool has_logged_printers_count_; | 207 bool has_logged_printers_count_; |
205 | 208 |
206 // Holds the path to the print to pdf request. It is empty if no such request | 209 // Holds the path to the print to pdf request. It is empty if no such request |
207 // exists. | 210 // exists. |
208 scoped_ptr<FilePath> print_to_pdf_path_; | 211 scoped_ptr<FilePath> print_to_pdf_path_; |
209 | 212 |
| 213 friend class PrintPreviewHandlerTest; |
| 214 FRIEND_TEST_ALL_PREFIXES(PrintPreviewHandlerTest, StickyMarginsCustom); |
| 215 FRIEND_TEST_ALL_PREFIXES(PrintPreviewHandlerTest, StickyMarginsDefault); |
| 216 FRIEND_TEST_ALL_PREFIXES(PrintPreviewHandlerTest, |
| 217 StickyMarginsCustomThenDefault); |
| 218 FRIEND_TEST_ALL_PREFIXES(PrintPreviewHandlerTest, |
| 219 GetLastUsedMarginSettingsCustom); |
| 220 FRIEND_TEST_ALL_PREFIXES(PrintPreviewHandlerTest, |
| 221 GetLastUsedMarginSettingsDefault); |
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 |