OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef HEADLESS_LIB_BROWSER_HEADLESS_PRINT_MANAGER_H_ | |
6 #define HEADLESS_LIB_BROWSER_HEADLESS_PRINT_MANAGER_H_ | |
7 | |
8 #include <memory> | |
9 #include <string> | |
10 | |
11 #include "components/printing/browser/print_manager.h" | |
12 #include "content/public/browser/render_frame_host.h" | |
13 #include "content/public/browser/web_contents_user_data.h" | |
14 | |
15 struct PrintHostMsg_DidPrintPage_Params; | |
16 | |
17 namespace printing { | |
18 | |
19 class HeadlessPrintManager | |
20 : public PrintManager, | |
21 public content::WebContentsUserData<HeadlessPrintManager> { | |
22 public: | |
23 enum PrintResult { | |
24 kPrintSuccess, | |
Lei Zhang
2017/03/29 05:30:16
Chromium C++ style diverges slightly from Google s
jzfeng
2017/03/30 03:04:57
Done.
| |
25 kPrintingFailed, | |
26 kInvalidPrinterSettings, | |
27 kInvalidMemoryHandle, | |
28 kMetafileMapError, | |
29 kUnexpectedValidMemoryHandle, | |
30 kMetafileInvalidHeader, | |
31 kMetafileGetDataError, | |
32 kDuplicatedPrintingError, | |
Eric Seckler
2017/03/29 11:21:20
nit: kSimultaneousPrintActive?
jzfeng
2017/03/30 03:04:57
Done.
| |
33 }; | |
34 | |
35 using GetPDFCallback = base::Callback<void(PrintResult, const std::string&)>; | |
36 | |
37 ~HeadlessPrintManager() override; | |
38 | |
39 static std::string PrintResultToErrMsg(PrintResult result); | |
40 static std::unique_ptr<base::DictionaryValue> PDFContentsToDictionaryValue( | |
41 const std::string& data); | |
42 | |
43 // Prints the current document immediately. Since the rendering is | |
44 // asynchronous, the actual printing will not be completed on the return of | |
45 // this function. | |
Lei Zhang
2017/03/29 05:30:16
You may want to say |callback| will always get cal
jzfeng
2017/03/30 03:04:57
Done.
| |
46 void GetPDFContents(content::RenderFrameHost* rfh, | |
47 const GetPDFCallback& callback); | |
48 | |
49 private: | |
50 explicit HeadlessPrintManager(content::WebContents* web_contents); | |
51 friend class content::WebContentsUserData<HeadlessPrintManager>; | |
52 | |
53 // content::WebContentsObserver implementation. | |
54 bool OnMessageReceived(const IPC::Message& message, | |
55 content::RenderFrameHost* render_frame_host) override; | |
56 | |
57 // IPC Message handlers. | |
58 void OnGetDefaultPrintSettings(IPC::Message* reply_msg); | |
59 void OnShowInvalidPrinterSettingsError(); | |
60 void OnPrintingFailed(int cookie) override; | |
61 void OnDidPrintPage(const PrintHostMsg_DidPrintPage_Params& params); | |
62 | |
63 void Reset(); | |
64 void ReleaseJob(PrintResult result); | |
65 | |
66 content::RenderFrameHost* printing_rfh_; | |
67 GetPDFCallback callback_; | |
68 std::string data_; | |
69 bool is_active_; | |
Lei Zhang
2017/03/29 05:30:16
You may want to just remove this and check if |cal
jzfeng
2017/03/30 03:04:57
Cool! Done.
| |
70 | |
71 #if !defined(OS_MACOSX) | |
72 // Set to true when OnDidPrintPage() should be expecting the first page. | |
73 bool expecting_first_page_; | |
74 #endif | |
75 | |
76 DISALLOW_COPY_AND_ASSIGN(HeadlessPrintManager); | |
77 }; | |
78 | |
79 } // namespace printing | |
80 | |
81 #endif // HEADLESS_LIB_BROWSER_HEADLESS_PRINT_MANAGER_H_ | |
OLD | NEW |