refactor: enable OOPIF printing to PDF (#36051)
This commit is contained in:
parent
289bdbe4bc
commit
7921fec761
5 changed files with 42 additions and 187 deletions
|
@ -13,6 +13,7 @@
|
|||
#include "base/memory/ref_counted_memory.h"
|
||||
#include "build/build_config.h"
|
||||
#include "chrome/browser/printing/print_view_manager_base.h"
|
||||
#include "components/printing/browser/print_to_pdf/pdf_print_job.h"
|
||||
#include "components/printing/common/print.mojom.h"
|
||||
#include "content/public/browser/render_frame_host.h"
|
||||
#include "content/public/browser/web_contents_observer.h"
|
||||
|
@ -21,29 +22,12 @@
|
|||
|
||||
namespace electron {
|
||||
|
||||
using PrintToPdfCallback = print_to_pdf::PdfPrintJob::PrintToPdfCallback;
|
||||
|
||||
class PrintViewManagerElectron
|
||||
: public printing::PrintViewManagerBase,
|
||||
public content::WebContentsUserData<PrintViewManagerElectron> {
|
||||
public:
|
||||
enum PrintResult {
|
||||
kPrintSuccess,
|
||||
kPrintFailure,
|
||||
kInvalidPrinterSettings,
|
||||
kInvalidMemoryHandle,
|
||||
kMetafileMapError,
|
||||
kMetafileInvalidHeader,
|
||||
kMetafileGetDataError,
|
||||
kSimultaneousPrintActive,
|
||||
kPageRangeSyntaxError,
|
||||
kPageRangeInvalidRange,
|
||||
kPageCountExceeded,
|
||||
kPrintingInProgress
|
||||
};
|
||||
|
||||
using PrintToPDFCallback =
|
||||
base::OnceCallback<void(PrintResult,
|
||||
scoped_refptr<base::RefCountedMemory>)>;
|
||||
|
||||
~PrintViewManagerElectron() override;
|
||||
|
||||
PrintViewManagerElectron(const PrintViewManagerElectron&) = delete;
|
||||
|
@ -54,30 +38,26 @@ class PrintViewManagerElectron
|
|||
receiver,
|
||||
content::RenderFrameHost* rfh);
|
||||
|
||||
static std::string PrintResultToString(PrintResult result);
|
||||
|
||||
void DidPrintToPdf(int cookie,
|
||||
PrintToPdfCallback callback,
|
||||
print_to_pdf::PdfPrintResult result,
|
||||
scoped_refptr<base::RefCountedMemory> memory);
|
||||
void PrintToPdf(content::RenderFrameHost* rfh,
|
||||
const std::string& page_ranges,
|
||||
printing::mojom::PrintPagesParamsPtr print_page_params,
|
||||
PrintToPDFCallback callback);
|
||||
PrintToPdfCallback callback);
|
||||
|
||||
private:
|
||||
friend class content::WebContentsUserData<PrintViewManagerElectron>;
|
||||
|
||||
explicit PrintViewManagerElectron(content::WebContents* web_contents);
|
||||
|
||||
void OnDidPrintWithParams(printing::mojom::PrintWithParamsResultPtr result);
|
||||
|
||||
// WebContentsObserver overrides (via PrintManager):
|
||||
void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override;
|
||||
|
||||
// printing::mojom::PrintManagerHost:
|
||||
void DidGetPrintedPagesCount(int32_t cookie, uint32_t number_pages) override;
|
||||
void GetDefaultPrintSettings(
|
||||
GetDefaultPrintSettingsCallback callback) override;
|
||||
void ScriptedPrint(printing::mojom::ScriptedPrintParamsPtr params,
|
||||
ScriptedPrintCallback callback) override;
|
||||
void ShowInvalidPrinterSettingsError() override;
|
||||
#if BUILDFLAG(ENABLE_PRINT_PREVIEW)
|
||||
void UpdatePrintSettings(int32_t cookie,
|
||||
base::Value::Dict job_settings,
|
||||
|
@ -91,14 +71,9 @@ class PrintViewManagerElectron
|
|||
int32_t request_id,
|
||||
CheckForCancelCallback callback) override;
|
||||
#endif
|
||||
std::vector<int32_t> pdf_jobs_;
|
||||
|
||||
void FailJob(PrintResult result);
|
||||
void Reset();
|
||||
|
||||
raw_ptr<content::RenderFrameHost> printing_rfh_ = nullptr;
|
||||
PrintToPDFCallback callback_;
|
||||
std::string data_;
|
||||
std::vector<int32_t> headless_jobs_;
|
||||
base::WeakPtrFactory<PrintViewManagerElectron> weak_factory_{this};
|
||||
|
||||
WEB_CONTENTS_USER_DATA_KEY_DECL();
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue