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 PRINT_SUCCESS, |
| 25 PRINTING_FAILED, |
| 26 INVALID_PRINTER_SETTINGS, |
| 27 INVALID_MEMORY_HANDLE, |
| 28 METAFILE_MAP_ERROR, |
| 29 UNEXPECTED_VALID_MEMORY_HANDLE, |
| 30 METAFILE_INVALID_HEADER, |
| 31 METAFILE_GET_DATA_ERROR, |
| 32 SIMULTANEOUS_PRINT_ACTIVE, |
| 33 }; |
| 34 |
| 35 using GetPDFCallback = base::Callback<void(PrintResult, const std::string&)>; |
| 36 |
| 37 ~HeadlessPrintManager() override; |
| 38 |
| 39 static std::string PrintResultToString(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, and |callback| will always get called when printing |
| 46 // finishes. |
| 47 void GetPDFContents(content::RenderFrameHost* rfh, |
| 48 const GetPDFCallback& callback); |
| 49 |
| 50 private: |
| 51 explicit HeadlessPrintManager(content::WebContents* web_contents); |
| 52 friend class content::WebContentsUserData<HeadlessPrintManager>; |
| 53 |
| 54 // content::WebContentsObserver implementation. |
| 55 bool OnMessageReceived(const IPC::Message& message, |
| 56 content::RenderFrameHost* render_frame_host) override; |
| 57 |
| 58 // IPC Message handlers. |
| 59 void OnGetDefaultPrintSettings(IPC::Message* reply_msg); |
| 60 void OnShowInvalidPrinterSettingsError(); |
| 61 void OnPrintingFailed(int cookie) override; |
| 62 void OnDidPrintPage(const PrintHostMsg_DidPrintPage_Params& params); |
| 63 |
| 64 void Reset(); |
| 65 void ReleaseJob(PrintResult result); |
| 66 |
| 67 content::RenderFrameHost* printing_rfh_; |
| 68 GetPDFCallback callback_; |
| 69 std::string data_; |
| 70 |
| 71 // Set to true when OnDidPrintPage() should be expecting the first page. |
| 72 bool expecting_first_page_; |
| 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(HeadlessPrintManager); |
| 75 }; |
| 76 |
| 77 } // namespace printing |
| 78 |
| 79 #endif // HEADLESS_LIB_BROWSER_HEADLESS_PRINT_MANAGER_H_ |
OLD | NEW |