Skip to content

Commit

Permalink
Remove Windows specific pdf to emf conversion code for now
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrunal Kapade committed Aug 17, 2016
1 parent e8bc8e3 commit 3c27e36
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 130 deletions.
100 changes: 0 additions & 100 deletions runtime/browser/printing/print_job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@


#if defined(OS_WIN)
#include "xwalk/runtime/browser/printing/pdf_to_emf_converter.h"
#include "printing/pdf_render_settings.h"
#endif

Expand Down Expand Up @@ -223,101 +222,6 @@ printing::PrintedDocument* PrintJob::document() const {
return document_.get();
}

#if defined(OS_WIN)

class PrintJob::PdfToEmfState {
public:
PdfToEmfState(const gfx::Size& page_size, const gfx::Rect& content_area)
: page_count_(0),
current_page_(0),
pages_in_progress_(0),
page_size_(page_size),
content_area_(content_area),
converter_(PdfToEmfConverter::CreateDefault()) {}

void Start(const scoped_refptr<base::RefCountedMemory>& data,
const PdfRenderSettings& conversion_settings,
const PdfToEmfConverter::StartCallback& start_callback) {
converter_->Start(data, conversion_settings, start_callback);
}

void GetMorePages(
const PdfToEmfConverter::GetPageCallback& get_page_callback) {
const int kMaxNumberOfTempFilesPerDocument = 3;
while (pages_in_progress_ < kMaxNumberOfTempFilesPerDocument &&
current_page_ < page_count_) {
++pages_in_progress_;
converter_->GetPage(current_page_++, get_page_callback);
}
}

void OnPageProcessed(
const PdfToEmfConverter::GetPageCallback& get_page_callback) {
--pages_in_progress_;
GetMorePages(get_page_callback);
// Release converter if we don't need this any more.
if (!pages_in_progress_ && current_page_ >= page_count_)
converter_.reset();
}

void set_page_count(int page_count) { page_count_ = page_count; }
gfx::Size page_size() const { return page_size_; }
gfx::Rect content_area() const { return content_area_; }

private:
int page_count_;
int current_page_;
int pages_in_progress_;
gfx::Size page_size_;
gfx::Rect content_area_;
std::unique_ptr<PdfToEmfConverter> converter_;
};

void PrintJob::StartPdfToEmfConversion(
const scoped_refptr<base::RefCountedMemory>& bytes,
const gfx::Size& page_size,
const gfx::Rect& content_area) {
DCHECK(!ptd_to_emf_state_.get());
ptd_to_emf_state_.reset(new PdfToEmfState(page_size, content_area));
const int kPrinterDpi = settings().dpi();
ptd_to_emf_state_->Start(
bytes,
printing::PdfRenderSettings(content_area, kPrinterDpi, true),
base::Bind(&PrintJob::OnPdfToEmfStarted, this));
}

void PrintJob::OnPdfToEmfStarted(int page_count) {
if (page_count <= 0) {
ptd_to_emf_state_.reset();
Cancel();
return;
}
ptd_to_emf_state_->set_page_count(page_count);
ptd_to_emf_state_->GetMorePages(
base::Bind(&PrintJob::OnPdfToEmfPageConverted, this));
}

void PrintJob::OnPdfToEmfPageConverted(int page_number,
float scale_factor,
std::unique_ptr<MetafilePlayer> emf) {
DCHECK(ptd_to_emf_state_);
if (!document_.get() || !emf) {
ptd_to_emf_state_.reset();
Cancel();
return;
}

// Update the rendered document. It will send notifications to the listener.
document_->SetPage(page_number, std::move(emf), scale_factor,
ptd_to_emf_state_->page_size(),
ptd_to_emf_state_->content_area());

ptd_to_emf_state_->GetMorePages(
base::Bind(&PrintJob::OnPdfToEmfPageConverted, this));
}

#endif // OS_WIN

void PrintJob::UpdatePrintedDocument(printing::PrintedDocument* new_document) {
if (document_.get() == new_document)
return;
Expand Down Expand Up @@ -367,10 +271,6 @@ void PrintJob::OnNotifyPrintJobEvent(const JobEventDetails& event_details) {
break;
}
case JobEventDetails::PAGE_DONE:
#if defined(OS_WIN)
ptd_to_emf_state_->OnPageProcessed(
base::Bind(&PrintJob::OnPdfToEmfPageConverted, this));
#endif // OS_WIN
break;
default: {
NOTREACHED();
Expand Down
19 changes: 0 additions & 19 deletions runtime/browser/printing/print_job.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,6 @@ class PrintJob : public PrintJobWorkerOwner,
// Access the current printed document. Warning: may be NULL.
printing::PrintedDocument* document() const;

#if defined(OS_WIN)
void StartPdfToEmfConversion(
const scoped_refptr<base::RefCountedMemory>& bytes,
const gfx::Size& page_size,
const gfx::Rect& content_area);
#endif // OS_WIN

protected:
~PrintJob() override;

Expand All @@ -125,13 +118,6 @@ class PrintJob : public PrintJobWorkerOwner,

void HoldUntilStopIsCalled();

#if defined(OS_WIN)
void OnPdfToEmfStarted(int page_count);
void OnPdfToEmfPageConverted(int page_number,
float scale_factor,
std::unique_ptr<MetafilePlayer> emf);
#endif // OS_WIN

content::NotificationRegistrar registrar_;

// Source that generates the PrintedPage's (i.e. a WebContents). It will be
Expand All @@ -156,11 +142,6 @@ class PrintJob : public PrintJobWorkerOwner,
// the notified calls Cancel() again.
bool is_canceling_;

#if defined(OS_WIN)
class PdfToEmfState;
std::unique_ptr<PdfToEmfState> ptd_to_emf_state_;
#endif // OS_WIN

// Used at shutdown so that we can quit a nested message loop.
base::WeakPtrFactory<PrintJob> quit_factory_;

Expand Down
12 changes: 1 addition & 11 deletions runtime/browser/printing/print_view_manager_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,7 @@ void PrintViewManagerBase::OnDidPrintPage(
}
}

#if defined(OS_WIN)
if (metafile_must_be_valid) {
scoped_refptr<base::RefCountedBytes> bytes = new base::RefCountedBytes(
reinterpret_cast<const unsigned char*>(shared_buf->memory()),
params.data_size);

document->DebugDumpData(bytes.get(), FILE_PATH_LITERAL(".pdf"));
print_job_->StartPdfToEmfConversion(
bytes, params.page_size, params.content_area);
}
#else
#if !defined(OS_WIN)
// Update the rendered document. It will send notifications to the listener.
document->SetPage(params.page_number, std::move(metafile), params.page_size,
params.content_area);
Expand Down

0 comments on commit 3c27e36

Please sign in to comment.