OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 HEADLESS_LIB_BROWSER_HEADLESS_PRINT_MANAGER_H_ | 5 #ifndef HEADLESS_LIB_BROWSER_HEADLESS_PRINT_MANAGER_H_ |
6 #define HEADLESS_LIB_BROWSER_HEADLESS_PRINT_MANAGER_H_ | 6 #define HEADLESS_LIB_BROWSER_HEADLESS_PRINT_MANAGER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "components/printing/browser/print_manager.h" | 11 #include "components/printing/browser/print_manager.h" |
12 #include "content/public/browser/render_frame_host.h" | 12 #include "content/public/browser/render_frame_host.h" |
13 #include "content/public/browser/web_contents_user_data.h" | 13 #include "content/public/browser/web_contents_user_data.h" |
14 #include "printing/print_settings.h" | |
14 | 15 |
15 struct PrintHostMsg_DidPrintPage_Params; | 16 struct PrintHostMsg_DidPrintPage_Params; |
17 struct PrintHostMsg_ScriptedPrint_Params; | |
18 struct PrintMsg_PrintPages_Params; | |
16 | 19 |
17 namespace printing { | 20 namespace printing { |
18 | 21 |
22 struct HeadlessPrintSettings { | |
Lei Zhang
2017/04/20 08:35:58
https://google.github.io/styleguide/cppguide.html#
jzfeng
2017/04/27 06:56:07
Done. Changed struct to class.
| |
23 enum PaperType { | |
24 LETTER, | |
25 LEGAL, | |
26 A4, | |
27 A3, | |
28 }; | |
29 | |
30 HeadlessPrintSettings(); | |
31 HeadlessPrintSettings(const HeadlessPrintSettings& obj); | |
32 ~HeadlessPrintSettings(); | |
33 | |
34 int GetDPI(); | |
35 gfx::Size PaperSizeInPixel(); | |
36 PageMargins MarginInPoints(); | |
37 | |
38 int dpi; | |
39 PaperType paper_type; | |
40 | |
41 MarginType margin_type; | |
42 double margin_top_in_inch; | |
43 double margin_bottom_in_inch; | |
44 double margin_left_in_inch; | |
45 double margin_right_in_inch; | |
46 | |
47 bool landscape; | |
48 bool display_header_footer; | |
49 bool should_print_backgrounds; | |
50 double scale; | |
Lei Zhang
2017/04/20 08:35:58
Mention 1 = 100%?
jzfeng
2017/04/27 06:56:07
Done.
| |
51 | |
52 PageRanges page_ranges; | |
53 }; | |
54 | |
19 class HeadlessPrintManager | 55 class HeadlessPrintManager |
20 : public PrintManager, | 56 : public PrintManager, |
21 public content::WebContentsUserData<HeadlessPrintManager> { | 57 public content::WebContentsUserData<HeadlessPrintManager> { |
22 public: | 58 public: |
23 enum PrintResult { | 59 enum PrintResult { |
24 PRINT_SUCCESS, | 60 PRINT_SUCCESS, |
25 PRINTING_FAILED, | 61 PRINTING_FAILED, |
26 INVALID_PRINTER_SETTINGS, | 62 INVALID_PRINTER_SETTINGS, |
27 INVALID_MEMORY_HANDLE, | 63 INVALID_MEMORY_HANDLE, |
28 METAFILE_MAP_ERROR, | 64 METAFILE_MAP_ERROR, |
29 UNEXPECTED_VALID_MEMORY_HANDLE, | 65 UNEXPECTED_VALID_MEMORY_HANDLE, |
30 METAFILE_INVALID_HEADER, | 66 METAFILE_INVALID_HEADER, |
31 METAFILE_GET_DATA_ERROR, | 67 METAFILE_GET_DATA_ERROR, |
32 SIMULTANEOUS_PRINT_ACTIVE, | 68 SIMULTANEOUS_PRINT_ACTIVE, |
69 EXCEED_PAGE_LIMIT, | |
Eric Seckler
2017/04/20 09:15:28
nit: PAGE_COUNT_EXCEEDED?
jzfeng
2017/04/27 06:56:06
Done.
| |
33 }; | 70 }; |
34 | 71 |
35 using GetPDFCallback = base::Callback<void(PrintResult, const std::string&)>; | 72 using GetPDFCallback = base::Callback<void(PrintResult, const std::string&)>; |
36 | 73 |
37 ~HeadlessPrintManager() override; | 74 ~HeadlessPrintManager() override; |
38 | 75 |
39 static std::string PrintResultToString(PrintResult result); | 76 static std::string PrintResultToString(PrintResult result); |
40 static std::unique_ptr<base::DictionaryValue> PDFContentsToDictionaryValue( | 77 static std::unique_ptr<base::DictionaryValue> PDFContentsToDictionaryValue( |
41 const std::string& data); | 78 const std::string& data); |
42 | 79 |
43 // Prints the current document immediately. Since the rendering is | 80 // Prints the current document immediately. Since the rendering is |
44 // asynchronous, the actual printing will not be completed on the return of | 81 // asynchronous, the actual printing will not be completed on the return of |
45 // this function, and |callback| will always get called when printing | 82 // this function, and |callback| will always get called when printing |
46 // finishes. | 83 // finishes. |
47 void GetPDFContents(content::RenderFrameHost* rfh, | 84 void GetPDFContents(content::RenderFrameHost* rfh, |
85 HeadlessPrintSettings settings, | |
Lei Zhang
2017/04/20 08:35:58
Don't pass by value.
jzfeng
2017/04/27 06:56:06
Done.
| |
48 const GetPDFCallback& callback); | 86 const GetPDFCallback& callback); |
49 | 87 |
50 private: | 88 private: |
51 explicit HeadlessPrintManager(content::WebContents* web_contents); | 89 explicit HeadlessPrintManager(content::WebContents* web_contents); |
52 friend class content::WebContentsUserData<HeadlessPrintManager>; | 90 friend class content::WebContentsUserData<HeadlessPrintManager>; |
53 | 91 |
92 std::unique_ptr<PrintMsg_PrintPages_Params> PrintParams( | |
93 HeadlessPrintSettings settings); | |
54 // content::WebContentsObserver implementation. | 94 // content::WebContentsObserver implementation. |
55 bool OnMessageReceived(const IPC::Message& message, | 95 bool OnMessageReceived(const IPC::Message& message, |
56 content::RenderFrameHost* render_frame_host) override; | 96 content::RenderFrameHost* render_frame_host) override; |
57 | 97 |
58 // IPC Message handlers. | 98 // IPC Message handlers. |
59 void OnGetDefaultPrintSettings(IPC::Message* reply_msg); | 99 void OnGetDefaultPrintSettings(IPC::Message* reply_msg); |
100 void OnScriptedPrint(const PrintHostMsg_ScriptedPrint_Params& params, | |
101 IPC::Message* reply_msg); | |
60 void OnShowInvalidPrinterSettingsError(); | 102 void OnShowInvalidPrinterSettingsError(); |
61 void OnPrintingFailed(int cookie) override; | 103 void OnPrintingFailed(int cookie) override; |
104 void OnDidGetPrintedPagesCount(int cookie, int number_pages) override; | |
62 void OnDidPrintPage(const PrintHostMsg_DidPrintPage_Params& params); | 105 void OnDidPrintPage(const PrintHostMsg_DidPrintPage_Params& params); |
63 | 106 |
64 void Reset(); | 107 void Reset(); |
65 void ReleaseJob(PrintResult result); | 108 void ReleaseJob(PrintResult result); |
66 | 109 |
67 content::RenderFrameHost* printing_rfh_; | 110 content::RenderFrameHost* printing_rfh_; |
68 GetPDFCallback callback_; | 111 GetPDFCallback callback_; |
112 std::unique_ptr<PrintMsg_PrintPages_Params> print_params_; | |
69 std::string data_; | 113 std::string data_; |
70 | 114 |
71 // Set to true when OnDidPrintPage() should be expecting the first page. | 115 // Set to true when OnDidPrintPage() should be expecting the first page. |
72 bool expecting_first_page_; | 116 bool expecting_first_page_; |
73 | 117 |
74 DISALLOW_COPY_AND_ASSIGN(HeadlessPrintManager); | 118 DISALLOW_COPY_AND_ASSIGN(HeadlessPrintManager); |
75 }; | 119 }; |
76 | 120 |
77 } // namespace printing | 121 } // namespace printing |
78 | 122 |
79 #endif // HEADLESS_LIB_BROWSER_HEADLESS_PRINT_MANAGER_H_ | 123 #endif // HEADLESS_LIB_BROWSER_HEADLESS_PRINT_MANAGER_H_ |
OLD | NEW |