Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(506)

Unified Diff: headless/lib/browser/headless_print_manager.h

Issue 2780433002: add print to pdf for headless (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: headless/lib/browser/headless_print_manager.h
diff --git a/headless/lib/browser/headless_print_manager.h b/headless/lib/browser/headless_print_manager.h
new file mode 100644
index 0000000000000000000000000000000000000000..0b802e4c71349ec45a7d5847f31b87679806463b
--- /dev/null
+++ b/headless/lib/browser/headless_print_manager.h
@@ -0,0 +1,77 @@
+// 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.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef HEADLESS_LIB_BROWSER_HEADLESS_PRINT_MANAGER_H_
+#define HEADLESS_LIB_BROWSER_HEADLESS_PRINT_MANAGER_H_
+
+#include <memory>
+#include <string>
+
+#include "components/printing/browser/print_manager.h"
+#include "content/public/browser/render_frame_host.h"
+#include "content/public/browser/web_contents_user_data.h"
+
+struct PrintHostMsg_DidPrintPage_Params;
+
+namespace printing {
+
+class HeadlessPrintManager
+ : public PrintManager,
+ public content::WebContentsUserData<HeadlessPrintManager> {
+ public:
+ ~HeadlessPrintManager() override;
+
+ 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.
+ kPrintSuccess,
+ kPrintingFailed,
+ kInvalidPrinterSettings,
+ kInvalidMemoryHandle,
+ kMetafileMapError,
+ kUnexpectedValidMemoryHandle,
+ kMetafileInvalidHeader,
+ kMetafileGetDataError,
+ kDuplicatedPrintingError,
+ };
+
+ using GetPDFCallback = base::Callback<void(PrintResult, const std::string&)>;
+ // Prints the current document immediately. Since the rendering is
+ // asynchronous, the actual printing will not be completed on the return of
+ // this function. Returns false if printing is impossible at the moment.
+ 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.
+ static std::string PrintResultToErrMsg(PrintResult result);
+ static std::unique_ptr<base::DictionaryValue> PDFContentsToDictionaryValue(
+ const std::string& data);
+
+ private:
+ explicit HeadlessPrintManager(content::WebContents* web_contents);
+ 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
+
+ // content::WebContentsObserver implementation.
+ bool OnMessageReceived(const IPC::Message& message,
+ content::RenderFrameHost* render_frame_host) override;
+
+ // IPC Message handlers.
+ void OnGetDefaultPrintSettings(IPC::Message* reply_msg);
+ void OnShowInvalidPrinterSettingsError();
+ void OnPrintingFailed(int cookie) override;
+ void OnDidPrintPage(const PrintHostMsg_DidPrintPage_Params& params);
+
+ void ReleaseJob(PrintResult result);
+
+ content::RenderFrameHost* printing_rfh_;
+ GetPDFCallback callback_;
+ std::string data_;
+ bool is_active_;
+
+#if !defined(OS_MACOSX)
+ // Set to true when OnDidPrintPage() should be expecting the first page.
+ bool expecting_first_page_;
+#endif
+
+ DISALLOW_COPY_AND_ASSIGN(HeadlessPrintManager);
+};
+
+} // namespace printing
+
+#endif // HEADLESS_LIB_BROWSER_HEADLESS_PRINT_MANAGER_H_

Powered by Google App Engine
This is Rietveld 408576698