OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | |
Lei Zhang
2017/03/29 01:38:03
no "(c)"
jzfeng
2017/03/29 03:50:13
Done.
| |
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 ~HeadlessPrintManager() override; | |
24 | |
25 enum PrintResult { | |
Lei Zhang
2017/03/29 01:38:03
nit: This and the callback defintion goes first, p
jzfeng
2017/03/29 03:50:13
Done.
| |
26 kPrintSuccess, | |
27 kPrintingFailed, | |
28 kInvalidPrinterSettings, | |
29 kInvalidMemoryHandle, | |
30 kMetafileMapError, | |
31 kUnexpectedValidMemoryHandle, | |
32 kMetafileInvalidHeader, | |
33 kMetafileGetDataError, | |
34 kDuplicatedPrintingError, | |
35 }; | |
36 | |
37 using GetPDFCallback = base::Callback<void(PrintResult, const std::string&)>; | |
38 // Prints the current document immediately. Since the rendering is | |
39 // asynchronous, the actual printing will not be completed on the return of | |
40 // this function. Returns false if printing is impossible at the moment. | |
41 bool GetPDFContents(content::RenderFrameHost* rfh, GetPDFCallback callback); | |
Lei Zhang
2017/03/29 01:38:03
nit: Pass callbacks by const-ref here too.
jzfeng
2017/03/29 03:50:13
Done.
| |
42 static std::string PrintResultToErrMsg(PrintResult result); | |
43 static std::unique_ptr<base::DictionaryValue> PDFContentsToDictionaryValue( | |
44 const std::string& data); | |
45 | |
46 private: | |
47 explicit HeadlessPrintManager(content::WebContents* web_contents); | |
48 friend class content::WebContentsUserData<HeadlessPrintManager>; | |
Lei Zhang
2017/03/29 01:38:03
nit: friends first in this section.
jzfeng
2017/03/29 03:50:13
I see both content/public/browser/web_contents_use
Lei Zhang
2017/03/29 05:30:15
I guess it doesn't matter since https://google.git
| |
49 | |
50 // content::WebContentsObserver implementation. | |
51 bool OnMessageReceived(const IPC::Message& message, | |
52 content::RenderFrameHost* render_frame_host) override; | |
53 | |
54 // IPC Message handlers. | |
55 void OnGetDefaultPrintSettings(IPC::Message* reply_msg); | |
56 void OnShowInvalidPrinterSettingsError(); | |
57 void OnPrintingFailed(int cookie) override; | |
58 void OnDidPrintPage(const PrintHostMsg_DidPrintPage_Params& params); | |
59 | |
60 void ReleaseJob(PrintResult result); | |
61 | |
62 content::RenderFrameHost* printing_rfh_; | |
63 GetPDFCallback callback_; | |
64 std::string data_; | |
65 bool is_active_; | |
66 | |
67 #if !defined(OS_MACOSX) | |
68 // Set to true when OnDidPrintPage() should be expecting the first page. | |
69 bool expecting_first_page_; | |
70 #endif | |
71 | |
72 DISALLOW_COPY_AND_ASSIGN(HeadlessPrintManager); | |
73 }; | |
74 | |
75 } // namespace printing | |
76 | |
77 #endif // HEADLESS_LIB_BROWSER_HEADLESS_PRINT_MANAGER_H_ | |
OLD | NEW |