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

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

Issue 2829973002: add customized printing setting for headless (Closed)
Patch Set: adjust command interface and add unit tests Created 3 years, 8 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
index 6d35bfae461d890d9a9d3d529c413c6b3ec82aa7..88acce26d839bb886d37045a81daf81d84795d5d 100644
--- a/headless/lib/browser/headless_print_manager.h
+++ b/headless/lib/browser/headless_print_manager.h
@@ -7,16 +7,59 @@
#include <memory>
#include <string>
+#include <vector>
#include "components/printing/browser/print_manager.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents_user_data.h"
+#include "printing/print_settings.h"
+#include "printing/printing_export.h"
struct PrintHostMsg_DidPrintPage_Params;
+struct PrintHostMsg_ScriptedPrint_Params;
+struct PrintMsg_PrintPages_Params;
namespace printing {
-class HeadlessPrintManager
+// Exported for tests.
+class PRINTING_EXPORT HeadlessPrintSettings {
+ public:
+ enum PaperType {
+ NA_LETTER,
+ NA_LEGAL,
+ ISO_A4,
+ ISO_A3,
+ CUSTOM,
+ };
+
+ HeadlessPrintSettings();
+ HeadlessPrintSettings(const HeadlessPrintSettings& obj);
+ ~HeadlessPrintSettings();
+
+ gfx::Size PaperSizeInPoints();
+ PageMargins MarginInPoints();
+
+ PaperType paper_type;
+ double paper_width_in_inch;
+ double paper_height_in_inch;
+
+ MarginType margin_type;
+ double margin_top_in_inch;
+ double margin_bottom_in_inch;
+ double margin_left_in_inch;
+ double margin_right_in_inch;
+
+ bool landscape;
+ bool display_header_footer;
+ bool should_print_backgrounds;
+ // scale = 1 means 100%.
+ double scale;
+
+ std::string page_ranges;
+};
+
+// Exported for tests.
+class PRINTING_EXPORT HeadlessPrintManager
: public PrintManager,
public content::WebContentsUserData<HeadlessPrintManager> {
public:
@@ -30,6 +73,14 @@ class HeadlessPrintManager
METAFILE_INVALID_HEADER,
METAFILE_GET_DATA_ERROR,
SIMULTANEOUS_PRINT_ACTIVE,
+ PAGE_RANGE_SYNTAX_ERROR,
+ PAGE_COUNT_EXCEEDED,
+ };
+
+ enum PageRangeStatus {
+ NO_ERROR,
+ SYNTAX_ERROR,
+ LIMIT_ERROR,
};
using GetPDFCallback = base::Callback<void(PrintResult, const std::string&)>;
@@ -39,26 +90,35 @@ class HeadlessPrintManager
static std::string PrintResultToString(PrintResult result);
static std::unique_ptr<base::DictionaryValue> PDFContentsToDictionaryValue(
const std::string& data);
+ static PageRangeStatus PageRangeTextToPages(std::string page_range_text,
+ int pages_count,
+ std::vector<int>* pages);
// Prints the current document immediately. Since the rendering is
// asynchronous, the actual printing will not be completed on the return of
// this function, and |callback| will always get called when printing
// finishes.
void GetPDFContents(content::RenderFrameHost* rfh,
+ const HeadlessPrintSettings& settings,
const GetPDFCallback& callback);
private:
explicit HeadlessPrintManager(content::WebContents* web_contents);
friend class content::WebContentsUserData<HeadlessPrintManager>;
+ std::unique_ptr<PrintMsg_PrintPages_Params> PrintParams(
+ HeadlessPrintSettings settings);
// 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 OnScriptedPrint(const PrintHostMsg_ScriptedPrint_Params& params,
+ IPC::Message* reply_msg);
void OnShowInvalidPrinterSettingsError();
void OnPrintingFailed(int cookie) override;
+ void OnDidGetPrintedPagesCount(int cookie, int number_pages) override;
void OnDidPrintPage(const PrintHostMsg_DidPrintPage_Params& params);
void Reset();
@@ -66,6 +126,8 @@ class HeadlessPrintManager
content::RenderFrameHost* printing_rfh_;
GetPDFCallback callback_;
+ std::unique_ptr<PrintMsg_PrintPages_Params> print_params_;
+ std::string page_ranges_text_;
std::string data_;
// Set to true when OnDidPrintPage() should be expecting the first page.

Powered by Google App Engine
This is Rietveld 408576698