#include "chrome/browser/printing/print_job.h"
+#include <memory>
+#include <utility>
+
#include "base/bind.h"
#include "base/bind_helpers.h"
+#include "base/location.h"
+#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
+#include "base/single_thread_task_runner.h"
#include "base/threading/thread_restrictions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/threading/worker_pool.h"
-#include "base/timer/timer.h"
+#include "build/build_config.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/printing/print_job_worker.h"
#include "content/public/browser/browser_thread.h"
#include "printing/pdf_render_settings.h"
#endif
-
using base::TimeDelta;
+namespace printing {
+
namespace {
// Helper function to ensure |owner| is valid until at least |callback| returns.
-void HoldRefCallback(const scoped_refptr<printing::PrintJobWorkerOwner>& owner,
+void HoldRefCallback(const scoped_refptr<PrintJobWorkerOwner>& owner,
const base::Closure& callback) {
callback.Run();
}
} // namespace
-namespace printing {
-
PrintJob::PrintJob()
- : source_(NULL),
- worker_(),
- settings_(),
+ : source_(nullptr),
is_job_pending_(false),
is_canceling_(false),
quit_factory_(this) {
PrintedPagesSource* source,
int page_count) {
DCHECK(!source_);
- DCHECK(!worker_.get());
+ DCHECK(!worker_);
DCHECK(!is_job_pending_);
DCHECK(!is_canceling_);
DCHECK(!document_.get());
source_ = source;
- worker_.reset(job->DetachWorker(this));
+ worker_ = job->DetachWorker(this);
settings_ = job->settings();
PrintedDocument* new_doc =
const content::NotificationSource& source,
const content::NotificationDetails& details) {
DCHECK(RunsTasksOnCurrentThread());
- switch (type) {
- case chrome::NOTIFICATION_PRINT_JOB_EVENT: {
- OnNotifyPrintJobEvent(*content::Details<JobEventDetails>(details).ptr());
- break;
- }
- default: {
- break;
- }
- }
+ DCHECK_EQ(chrome::NOTIFICATION_PRINT_JOB_EVENT, type);
+
+ OnNotifyPrintJobEvent(*content::Details<JobEventDetails>(details).ptr());
}
void PrintJob::GetSettingsDone(const PrintSettings& new_settings,
NOTREACHED();
}
-PrintJobWorker* PrintJob::DetachWorker(PrintJobWorkerOwner* new_owner) {
+std::unique_ptr<PrintJobWorker> PrintJob::DetachWorker(
+ PrintJobWorkerOwner* new_owner) {
NOTREACHED();
- return NULL;
+ return nullptr;
}
const PrintSettings& PrintJob::settings() const {
}
int PrintJob::cookie() const {
+ // Always use an invalid cookie in this case.
if (!document_.get())
- // Always use an invalid cookie in this case.
return 0;
return document_->cookie();
}
void PrintJob::StartPrinting() {
DCHECK(RunsTasksOnCurrentThread());
- DCHECK(worker_->IsRunning());
- DCHECK(!is_job_pending_);
- if (!worker_->IsRunning() || is_job_pending_)
+ if (!worker_->IsRunning() || is_job_pending_) {
+ NOTREACHED();
return;
+ }
// Real work is done in PrintJobWorker::StartPrinting().
worker_->PostTask(FROM_HERE,
- base::Bind(&HoldRefCallback,
- make_scoped_refptr(this),
+ base::Bind(&HoldRefCallback, make_scoped_refptr(this),
base::Bind(&PrintJobWorker::StartPrinting,
base::Unretained(worker_.get()),
base::RetainedRef(document_))));
// Tell everyone!
scoped_refptr<JobEventDetails> details(
- new JobEventDetails(JobEventDetails::NEW_DOC, document_.get(), NULL));
+ new JobEventDetails(JobEventDetails::NEW_DOC, document_.get(), nullptr));
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_PRINT_JOB_EVENT,
content::Source<PrintJob>(this),
ControlledWorkerShutdown();
} else {
// Flush the cached document.
- UpdatePrintedDocument(NULL);
+ is_job_pending_ = false;
+ UpdatePrintedDocument(nullptr);
}
}
}
// Make sure a Cancel() is broadcast.
scoped_refptr<JobEventDetails> details(
- new JobEventDetails(JobEventDetails::FAILED, NULL, NULL));
+ new JobEventDetails(JobEventDetails::FAILED, nullptr, nullptr));
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_PRINT_JOB_EVENT,
content::Source<PrintJob>(this),
}
void PrintJob::DisconnectSource() {
- source_ = NULL;
+ source_ = nullptr;
if (document_.get())
document_->DisconnectSource();
}
void Start(const scoped_refptr<base::RefCountedMemory>& data,
const PdfRenderSettings& conversion_settings,
+ bool print_text_with_gdi,
const PdfToEmfConverter::StartCallback& start_callback) {
- converter_->Start(data, conversion_settings, start_callback);
+ converter_->Start(data, conversion_settings, print_text_with_gdi,
+ start_callback);
}
void GetMorePages(
std::unique_ptr<PdfToEmfConverter> converter_;
};
+void PrintJob::AppendPrintedPage(int page_number) {
+ pdf_page_mapping_.push_back(page_number);
+}
+
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 gfx::Rect& content_area,
+ bool print_text_with_gdi) {
+ DCHECK(!pdf_to_emf_state_);
+ pdf_to_emf_state_ = base::MakeUnique<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));
+ pdf_to_emf_state_->Start(
+ bytes, PdfRenderSettings(content_area, kPrinterDpi, true),
+ print_text_with_gdi, base::Bind(&PrintJob::OnPdfToEmfStarted, this));
}
void PrintJob::OnPdfToEmfStarted(int page_count) {
if (page_count <= 0) {
- ptd_to_emf_state_.reset();
+ pdf_to_emf_state_.reset();
Cancel();
return;
}
- ptd_to_emf_state_->set_page_count(page_count);
- ptd_to_emf_state_->GetMorePages(
+ pdf_to_emf_state_->set_page_count(page_count);
+ pdf_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();
+ DCHECK(pdf_to_emf_state_);
+ if (!document_.get() || !emf || page_number < 0 ||
+ static_cast<size_t>(page_number) >= pdf_page_mapping_.size()) {
+ pdf_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());
+ document_->SetPage(pdf_page_mapping_[page_number], std::move(emf),
+ scale_factor, pdf_to_emf_state_->page_size(),
+ pdf_to_emf_state_->content_area());
- ptd_to_emf_state_->GetMorePages(
+ pdf_to_emf_state_->GetMorePages(
base::Bind(&PrintJob::OnPdfToEmfPageConverted, this));
}
document_ = new_document;
- if (document_.get()) {
+ if (document_.get())
settings_ = document_->settings();
- }
if (worker_) {
DCHECK(!is_job_pending_);
// Sync the document with the worker.
worker_->PostTask(FROM_HERE,
- base::Bind(&HoldRefCallback,
- make_scoped_refptr(this),
+ base::Bind(&HoldRefCallback, make_scoped_refptr(this),
base::Bind(&PrintJobWorker::OnDocumentChanged,
base::Unretained(worker_.get()),
base::RetainedRef(document_))));
}
case JobEventDetails::PAGE_DONE:
#if defined(OS_WIN)
- ptd_to_emf_state_->OnPageProcessed(
+ pdf_to_emf_state_->OnPageProcessed(
base::Bind(&PrintJob::OnPdfToEmfPageConverted, this));
-#endif // OS_WIN
+#endif // defined(OS_WIN)
break;
default: {
NOTREACHED();
Stop();
scoped_refptr<JobEventDetails> details(
- new JobEventDetails(JobEventDetails::JOB_DONE, document_.get(), NULL));
+ new JobEventDetails(JobEventDetails::JOB_DONE, document_.get(), nullptr));
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_PRINT_JOB_EVENT,
content::Source<PrintJob>(this),
// to wait on the thread to quit before continuing.
if (worker_->IsRunning()) {
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
- FROM_HERE,
- base::Bind(&PrintJob::ControlledWorkerShutdown, this),
+ FROM_HERE, base::Bind(&PrintJob::ControlledWorkerShutdown, this),
base::TimeDelta::FromMilliseconds(100));
return;
}
is_job_pending_ = false;
registrar_.RemoveAll();
- UpdatePrintedDocument(NULL);
+ UpdatePrintedDocument(nullptr);
}
void PrintJob::HoldUntilStopIsCalled() {
#define CHROME_BROWSER_PRINTING_PRINT_JOB_H_
#include <memory>
+#include <vector>
+#include "base/macros.h"
#include "base/memory/weak_ptr.h"
-#include "base/message_loop/message_loop.h"
+#include "build/build_config.h"
#include "chrome/browser/printing/print_job_worker_owner.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
-class Thread;
-
namespace base {
class RefCountedMemory;
}
int page_count);
// content::NotificationObserver implementation.
- virtual void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) override;
+ void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) override;
// PrintJobWorkerOwner implementation.
- virtual void GetSettingsDone(const PrintSettings& new_settings,
- PrintingContext::Result result) override;
- virtual PrintJobWorker* DetachWorker(PrintJobWorkerOwner* new_owner) override;
- virtual const PrintSettings& settings() const override;
- virtual int cookie() const override;
+ void GetSettingsDone(const PrintSettings& new_settings,
+ PrintingContext::Result result) override;
+ std::unique_ptr<PrintJobWorker> DetachWorker(
+ PrintJobWorkerOwner* new_owner) override;
+ const PrintSettings& settings() const override;
+ int cookie() const override;
// Starts the actual printing. Signals the worker that it should begin to
// spool as soon as data is available.
PrintedDocument* document() const;
#if defined(OS_WIN)
+ // Let the PrintJob know the 0-based |page_number| of a given printed page.
+ void AppendPrintedPage(int page_number);
+
void StartPdfToEmfConversion(
const scoped_refptr<base::RefCountedMemory>& bytes,
const gfx::Size& page_size,
- const gfx::Rect& content_area);
-
- void OnPdfToEmfStarted(int page_count);
- void OnPdfToEmfPageConverted(int page_number,
- float scale_factor,
- std::unique_ptr<MetafilePlayer> emf);
-
-#endif // OS_WIN
+ const gfx::Rect& content_area,
+ bool print_text_with_gdi);
+#endif // defined(OS_WIN)
protected:
- virtual ~PrintJob();
+ ~PrintJob() override;
private:
- // Updates document_ to a new instance.
+ // Updates |document_| to a new instance.
void UpdatePrintedDocument(PrintedDocument* new_document);
// Processes a NOTIFY_PRINT_JOB_EVENT notification.
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 // defined(OS_WIN)
+
content::NotificationRegistrar registrar_;
// Source that generates the PrintedPage's (i.e. a WebContents). It will be
#if defined(OS_WIN)
class PdfToEmfState;
- std::unique_ptr<PdfToEmfState> ptd_to_emf_state_;
-#endif // OS_WIN
+ std::unique_ptr<PdfToEmfState> pdf_to_emf_state_;
+ std::vector<int> pdf_page_mapping_;
+#endif // defined(OS_WIN)
// Used at shutdown so that we can quit a nested message loop.
base::WeakPtrFactory<PrintJob> quit_factory_;
for (PrinterQueries::iterator itr = queued_queries_.begin();
itr != queued_queries_.end(); ++itr) {
if ((*itr)->cookie() == document_cookie && !(*itr)->is_callback_pending()) {
- scoped_refptr<printing::PrinterQuery> current_query(*itr);
+ scoped_refptr<PrinterQuery> current_query(*itr);
queued_queries_.erase(itr);
DCHECK(current_query->is_valid());
return current_query;
scoped_refptr<PrinterQuery> PrintQueriesQueue::CreatePrinterQuery(
int render_process_id,
- int render_view_id) {
- scoped_refptr<PrinterQuery> job =
- new printing::PrinterQuery(render_process_id, render_view_id);
- return job;
+ int render_frame_id) {
+ return make_scoped_refptr(
+ new PrinterQuery(render_process_id, render_frame_id));
}
void PrintQueriesQueue::Shutdown() {
}
scoped_refptr<PrintQueriesQueue> PrintJobManager::queue() {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (!queue_.get())
queue_ = new PrintQueriesQueue();
return queue_;
}
void PrintJobManager::Shutdown() {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(!is_shutdown_);
is_shutdown_ = true;
registrar_.RemoveAll();
}
void PrintJobManager::StopJobs(bool wait_for_finish) {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// Copy the array since it can be modified in transit.
PrintJobs to_stop;
to_stop.swap(current_jobs_);
void PrintJobManager::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
- switch (type) {
- case chrome::NOTIFICATION_PRINT_JOB_EVENT: {
- OnPrintJobEvent(content::Source<PrintJob>(source).ptr(),
- *content::Details<JobEventDetails>(details).ptr());
- break;
- }
- default: {
- NOTREACHED();
- break;
- }
- }
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ DCHECK_EQ(chrome::NOTIFICATION_PRINT_JOB_EVENT, type);
+
+ OnPrintJobEvent(content::Source<PrintJob>(source).ptr(),
+ *content::Details<JobEventDetails>(details).ptr());
}
void PrintJobManager::OnPrintJobEvent(
#include <vector>
#include "base/logging.h"
+#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/synchronization/lock.h"
#include "base/threading/non_thread_safe.h"
// Creates new query.
scoped_refptr<PrinterQuery> CreatePrinterQuery(int render_process_id,
- int render_view_id);
+ int render_frame_id);
void Shutdown();
class PrintJobManager : public content::NotificationObserver {
public:
PrintJobManager();
- virtual ~PrintJobManager();
+ ~PrintJobManager() override;
// On browser quit, we should wait to have the print job finished.
void Shutdown();
// content::NotificationObserver
- virtual void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) override;
+ void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) override;
// Returns queries queue. Never returns NULL. Must be called on Browser UI
// Thread. Reference could be stored and used from any thread.
#include "chrome/browser/printing/print_job_worker.h"
+#include <memory>
+
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/callback.h"
#include "base/compiler_specific.h"
+#include "base/location.h"
+#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h"
+#include "base/single_thread_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/values.h"
+#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/printing/print_job.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
-#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "printing/print_job_constants.h"
#include "printing/printed_document.h"
namespace {
// Helper function to ensure |owner| is valid until at least |callback| returns.
-void HoldRefCallback(const scoped_refptr<printing::PrintJobWorkerOwner>& owner,
+void HoldRefCallback(const scoped_refptr<PrintJobWorkerOwner>& owner,
const base::Closure& callback) {
callback.Run();
}
class PrintingContextDelegate : public PrintingContext::Delegate {
public:
- PrintingContextDelegate(int render_process_id, int render_view_id);
- virtual ~PrintingContextDelegate();
+ PrintingContextDelegate(int render_process_id, int render_frame_id);
+ ~PrintingContextDelegate() override;
+
+ gfx::NativeView GetParentView() override;
+ std::string GetAppLocale() override;
- virtual gfx::NativeView GetParentView() override;
- virtual std::string GetAppLocale() override;
+ // Not exposed to PrintingContext::Delegate because of dependency issues.
+ content::WebContents* GetWebContents();
private:
- int render_process_id_;
- int render_view_id_;
+ const int render_process_id_;
+ const int render_frame_id_;
};
PrintingContextDelegate::PrintingContextDelegate(int render_process_id,
- int render_view_id)
+ int render_frame_id)
: render_process_id_(render_process_id),
- render_view_id_(render_view_id) {
-}
+ render_frame_id_(render_frame_id) {}
PrintingContextDelegate::~PrintingContextDelegate() {
}
gfx::NativeView PrintingContextDelegate::GetParentView() {
+ content::WebContents* wc = GetWebContents();
+ return wc ? wc->GetNativeView() : nullptr;
+}
+
+content::WebContents* PrintingContextDelegate::GetWebContents() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- content::RenderViewHost* view =
- content::RenderViewHost::FromID(render_process_id_, render_view_id_);
- if (!view)
- return NULL;
- content::WebContents* wc = content::WebContents::FromRenderViewHost(view);
- return wc ? wc->GetNativeView() : NULL;
+ auto* rfh =
+ content::RenderFrameHost::FromID(render_process_id_, render_frame_id_);
+ return rfh ? content::WebContents::FromRenderFrameHost(rfh) : nullptr;
}
std::string PrintingContextDelegate::GetAppLocale() {
content::Details<JobEventDetails>(details));
}
+void PostOnOwnerThread(const scoped_refptr<PrintJobWorkerOwner>& owner,
+ const PrintingContext::PrintSettingsCallback& callback,
+ PrintingContext::Result result) {
+ owner->PostTask(FROM_HERE, base::Bind(&HoldRefCallback, owner,
+ base::Bind(callback, result)));
+}
+
} // namespace
PrintJobWorker::PrintJobWorker(int render_process_id,
- int render_view_id,
+ int render_frame_id,
PrintJobWorkerOwner* owner)
: owner_(owner), thread_("Printing_Worker"), weak_factory_(this) {
// The object is created in the IO thread.
DCHECK(owner_->RunsTasksOnCurrentThread());
- printing_context_delegate_.reset(
- new PrintingContextDelegate(render_process_id, render_view_id));
+ printing_context_delegate_ = base::MakeUnique<PrintingContextDelegate>(
+ render_process_id, render_frame_id);
printing_context_ = PrintingContext::Create(printing_context_delegate_.get());
}
owner_ = new_owner;
}
-void PrintJobWorker::GetSettings(
- bool ask_user_for_settings,
- int document_page_count,
- bool has_selection,
- MarginType margin_type) {
+void PrintJobWorker::GetSettings(bool ask_user_for_settings,
+ int document_page_count,
+ bool has_selection,
+ MarginType margin_type,
+ bool is_scripted,
+ bool is_modifiable) {
DCHECK(task_runner_->RunsTasksOnCurrentThread());
DCHECK_EQ(page_number_, PageNumber::npos());
// should happen on the same thread. See http://crbug.com/73466
// MessageLoop::current()->SetNestableTasksAllowed(true);
printing_context_->set_margin_type(margin_type);
+ printing_context_->set_is_modifiable(is_modifiable);
// When we delegate to a destination, we don't ask the user for settings.
// TODO(mad): Ask the destination for settings.
base::Bind(&PrintJobWorker::GetSettingsWithUI,
base::Unretained(this),
document_page_count,
- has_selection)));
+ has_selection,
+ is_scripted)));
} else {
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
void PrintJobWorker::GetSettingsWithUI(
int document_page_count,
- bool has_selection) {
+ bool has_selection,
+ bool is_scripted) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- printing_context_->AskUserForSettings(
- document_page_count,
- has_selection,
- false,
- base::Bind(&PrintJobWorker::GetSettingsWithUIDone,
- base::Unretained(this)));
-}
-void PrintJobWorker::GetSettingsWithUIDone(PrintingContext::Result result) {
- PostTask(FROM_HERE,
- base::Bind(&HoldRefCallback,
- make_scoped_refptr(owner_),
- base::Bind(&PrintJobWorker::GetSettingsDone,
- base::Unretained(this),
- result)));
+ // weak_factory_ creates pointers valid only on owner_ thread.
+ printing_context_->AskUserForSettings(
+ document_page_count, has_selection, is_scripted,
+ base::Bind(&PostOnOwnerThread, make_scoped_refptr(owner_),
+ base::Bind(&PrintJobWorker::GetSettingsDone,
+ weak_factory_.GetWeakPtr())));
}
void PrintJobWorker::UseDefaultSettings() {
base::string16 document_name =
printing::SimplifyDocumentTitle(document_->name());
- if (document_name.empty()) {
- }
PrintingContext::Result result =
printing_context_->NewDocument(document_name);
if (result != PrintingContext::OK) {
DCHECK_NE(page_number_, PageNumber::npos());
// Signal everyone that the page is about to be printed.
- owner_->PostTask(FROM_HERE,
- base::Bind(&NotificationCallback, base::RetainedRef(owner_),
- JobEventDetails::NEW_PAGE, base::RetainedRef(document_),
- base::RetainedRef(page)));
+ owner_->PostTask(
+ FROM_HERE,
+ base::Bind(&NotificationCallback, base::RetainedRef(owner_),
+ JobEventDetails::NEW_PAGE, base::RetainedRef(document_),
+ base::RetainedRef(page)));
// Preprocess.
if (printing_context_->NewPage() != PrintingContext::OK) {
// We may loose our last reference by broadcasting the FAILED event.
scoped_refptr<PrintJobWorkerOwner> handle(owner_);
- owner_->PostTask(
- FROM_HERE,
- base::Bind(&NotificationCallback, base::RetainedRef(owner_),
- JobEventDetails::FAILED,
- base::RetainedRef(document_), nullptr));
+ owner_->PostTask(FROM_HERE,
+ base::Bind(&NotificationCallback, base::RetainedRef(owner_),
+ JobEventDetails::FAILED,
+ base::RetainedRef(document_), nullptr));
Cancel();
// Makes sure the variables are reinitialized.
#include <memory>
+#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/threading/thread.h"
+#include "chrome/browser/printing/printer_query.h"
#include "content/public/browser/browser_thread.h"
#include "printing/page_number.h"
#include "printing/print_job_constants.h"
class PrintJobWorker {
public:
PrintJobWorker(int render_process_id,
- int render_view_id,
+ int render_frame_id,
PrintJobWorkerOwner* owner);
virtual ~PrintJobWorker();
void SetNewOwner(PrintJobWorkerOwner* new_owner);
// Initializes the print settings. If |ask_user_for_settings| is true, a
- // Print... dialog box will be shown to ask the user his preference.
- void GetSettings(
- bool ask_user_for_settings,
- int document_page_count,
- bool has_selection,
- MarginType margin_type);
+ // Print... dialog box will be shown to ask the user their preference.
+ // |is_scripted| should be true for calls coming straight from window.print().
+ // |is_modifiable| implies HTML and not other formats like PDF.
+ void GetSettings(bool ask_user_for_settings,
+ int document_page_count,
+ bool has_selection,
+ MarginType margin_type,
+ bool is_scripted,
+ bool is_modifiable);
// Set the new print settings.
void SetSettings(std::unique_ptr<base::DictionaryValue> new_settings);
// but sticks with this for consistency.
void GetSettingsWithUI(
int document_page_count,
- bool has_selection);
-
- // The callback used by PrintingContext::GetSettingsWithUI() to notify this
- // object that the print settings are set. This is needed in order to bounce
- // back into the IO thread for GetSettingsDone().
- void GetSettingsWithUIDone(PrintingContext::Result result);
+ bool has_selection,
+ bool is_scripted);
// Called on the UI thread to update the print settings.
void UpdatePrintSettings(std::unique_ptr<base::DictionaryValue> new_settings);
#include "chrome/browser/printing/print_job_worker_owner.h"
-#include "base/message_loop/message_loop.h"
+#include "base/location.h"
+#include "base/single_thread_task_runner.h"
+#include "base/threading/thread_task_runner_handle.h"
namespace printing {
PrintJobWorkerOwner::PrintJobWorkerOwner()
- : task_runner_(base::MessageLoop::current()->task_runner()) {
-}
+ : task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
PrintJobWorkerOwner::~PrintJobWorkerOwner() {
}
#ifndef CHROME_BROWSER_PRINTING_PRINT_JOB_WORKER_OWNER_H__
#define CHROME_BROWSER_PRINTING_PRINT_JOB_WORKER_OWNER_H__
+#include <memory>
+
#include "base/memory/ref_counted.h"
#include "printing/printing_context.h"
PrintingContext::Result result) = 0;
// Detach the PrintJobWorker associated to this object.
- virtual PrintJobWorker* DetachWorker(PrintJobWorkerOwner* new_owner) = 0;
+ virtual std::unique_ptr<PrintJobWorker> DetachWorker(
+ PrintJobWorkerOwner* new_owner) = 0;
// Access the current settings.
virtual const PrintSettings& settings() const = 0;
#include "chrome/browser/printing/printer_query.h"
#include "chrome/common/print_messages.h"
#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "printing/page_size_margins.h"
options.GetInteger(printing::kPreviewRequestID, &request_id);
print_to_pdf_callback_map_[request_id] = callback;
- content::RenderViewHost* rvh = web_contents()->GetRenderViewHost();
- rvh->Send(new PrintMsg_PrintPreview(rvh->GetRoutingID(), options));
+ content::RenderFrameHost* rfh = web_contents()->GetMainFrame();
+ rfh->Send(new PrintMsg_PrintPreview(rfh->GetRoutingID(), options));
}
void PrintPreviewMessageHandler::RunPrintToPDFCallback(
#include "chrome/browser/printing/printer_query.h"
+#include <memory>
+#include <utility>
+
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/message_loop/message_loop.h"
namespace printing {
-PrinterQuery::PrinterQuery(int render_process_id, int render_view_id)
- : worker_(new PrintJobWorker(render_process_id, render_view_id, this)),
+PrinterQuery::PrinterQuery(int render_process_id, int render_frame_id)
+ : worker_(new PrintJobWorker(render_process_id, render_frame_id, this)),
is_print_dialog_box_shown_(false),
cookie_(PrintSettings::NewCookie()),
last_status_(PrintingContext::FAILED) {
// The job should be finished (or at least canceled) when it is destroyed.
DCHECK(!is_print_dialog_box_shown_);
// If this fires, it is that this pending printer context has leaked.
- DCHECK(!worker_.get());
+ DCHECK(!worker_);
}
void PrinterQuery::GetSettingsDone(const PrintSettings& new_settings,
}
}
-PrintJobWorker* PrinterQuery::DetachWorker(PrintJobWorkerOwner* new_owner) {
+std::unique_ptr<PrintJobWorker> PrinterQuery::DetachWorker(
+ PrintJobWorkerOwner* new_owner) {
DCHECK(callback_.is_null());
- DCHECK(worker_.get());
+ DCHECK(worker_);
worker_->SetNewOwner(new_owner);
- return worker_.release();
+ return std::move(worker_);
}
const PrintSettings& PrinterQuery::settings() const {
return cookie_;
}
-void PrinterQuery::GetSettings(
- GetSettingsAskParam ask_user_for_settings,
- int expected_page_count,
- bool has_selection,
- MarginType margin_type,
- const base::Closure& callback) {
+void PrinterQuery::GetSettings(GetSettingsAskParam ask_user_for_settings,
+ int expected_page_count,
+ bool has_selection,
+ MarginType margin_type,
+ bool is_scripted,
+ bool is_modifiable,
+ const base::Closure& callback) {
DCHECK(RunsTasksOnCurrentThread());
- DCHECK(!is_print_dialog_box_shown_);
+ DCHECK(!is_print_dialog_box_shown_ || !is_scripted);
StartWorker(callback);
// Real work is done in PrintJobWorker::GetSettings().
- is_print_dialog_box_shown_ = ask_user_for_settings == ASK_USER;
- worker_->PostTask(FROM_HERE,
- base::Bind(&PrintJobWorker::GetSettings,
- base::Unretained(worker_.get()),
- is_print_dialog_box_shown_,
- expected_page_count,
- has_selection,
- margin_type));
+ is_print_dialog_box_shown_ =
+ ask_user_for_settings == GetSettingsAskParam::ASK_USER;
+ worker_->PostTask(
+ FROM_HERE,
+ base::Bind(&PrintJobWorker::GetSettings, base::Unretained(worker_.get()),
+ is_print_dialog_box_shown_, expected_page_count, has_selection,
+ margin_type, is_scripted, is_modifiable));
}
-void PrinterQuery::SetSettings(std::unique_ptr<base::DictionaryValue> new_settings,
- const base::Closure& callback) {
+void PrinterQuery::SetSettings(
+ std::unique_ptr<base::DictionaryValue> new_settings,
+ const base::Closure& callback) {
StartWorker(callback);
worker_->PostTask(FROM_HERE,
void PrinterQuery::StartWorker(const base::Closure& callback) {
DCHECK(callback_.is_null());
- DCHECK(worker_.get());
+ DCHECK(worker_);
// Lazily create the worker thread. There is one worker thread per print job.
if (!worker_->IsRunning())
}
void PrinterQuery::StopWorker() {
- if (worker_.get()) {
+ if (worker_) {
// http://crbug.com/66082: We're blocking on the PrinterQuery's worker
// thread. It's not clear to me if this may result in blocking the current
// thread for an unacceptable time. We should probably fix it.
}
bool PrinterQuery::is_valid() const {
- return worker_.get() != NULL;
+ return !!worker_;
}
} // namespace printing
#include "base/callback.h"
#include "base/compiler_specific.h"
+#include "base/macros.h"
#include "chrome/browser/printing/print_job_worker_owner.h"
#include "printing/print_job_constants.h"
class PrinterQuery : public PrintJobWorkerOwner {
public:
// GetSettings() UI parameter.
- enum GetSettingsAskParam {
+ enum class GetSettingsAskParam {
DEFAULTS,
ASK_USER,
};
- PrinterQuery(int render_process_id, int render_view_id);
+ PrinterQuery(int render_process_id, int render_frame_id);
// PrintJobWorkerOwner implementation.
- virtual void GetSettingsDone(const PrintSettings& new_settings,
- PrintingContext::Result result) override;
- virtual PrintJobWorker* DetachWorker(PrintJobWorkerOwner* new_owner) override;
- virtual const PrintSettings& settings() const override;
- virtual int cookie() const override;
+ void GetSettingsDone(const PrintSettings& new_settings,
+ PrintingContext::Result result) override;
+ std::unique_ptr<PrintJobWorker> DetachWorker(
+ PrintJobWorkerOwner* new_owner) override;
+ const PrintSettings& settings() const override;
+ int cookie() const override;
// Initializes the printing context. It is fine to call this function multiple
// times to reinitialize the settings. |web_contents_observer| can be queried
// to find the owner of the print setting dialog box. It is unused when
// |ask_for_user_settings| is DEFAULTS.
- void GetSettings(
- GetSettingsAskParam ask_user_for_settings,
- int expected_page_count,
- bool has_selection,
- MarginType margin_type,
- const base::Closure& callback);
+ void GetSettings(GetSettingsAskParam ask_user_for_settings,
+ int expected_page_count,
+ bool has_selection,
+ MarginType margin_type,
+ bool is_scripted,
+ bool is_modifiable,
+ const base::Closure& callback);
// Updates the current settings with |new_settings| dictionary values.
void SetSettings(std::unique_ptr<base::DictionaryValue> new_settings,
bool is_valid() const;
private:
- virtual ~PrinterQuery();
+ ~PrinterQuery() override;
// Lazy create the worker thread. There is one worker thread per print job.
void StartWorker(const base::Closure& callback);
#include "chrome/browser/profiles/profile_io_data.h"
#include "chrome/common/print_messages.h"
#include "content/public/browser/browser_thread.h"
-#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
+#include "content/public/browser/render_frame_host.h"
#include "content/public/common/child_process_host.h"
+#include "printing/features/features.h"
-#if defined(ENABLE_FULL_PRINTING)
-#include "chrome/browser/ui/webui/print_preview/print_preview_ui.h"
-#endif
-
-#if defined(OS_CHROMEOS)
-#include <fcntl.h>
-
-#include <map>
-
-#include "base/files/file_util.h"
-#include "base/lazy_instance.h"
-#include "chrome/browser/printing/print_dialog_cloud.h"
-#endif
#if defined(OS_ANDROID)
#include "base/strings/string_number_conversions.h"
namespace {
-#if defined(OS_CHROMEOS)
-typedef std::map<int, base::FilePath> SequenceToPathMap;
-
-struct PrintingSequencePathMap {
- SequenceToPathMap map;
- int sequence;
-};
-
-// No locking, only access on the FILE thread.
-static base::LazyInstance<PrintingSequencePathMap>
- g_printing_file_descriptor_map = LAZY_INSTANCE_INITIALIZER;
-#endif
-
void RenderParamsFromPrintSettings(const PrintSettings& settings,
PrintMsg_Print_Params* params) {
params->page_size = settings.page_setup_device_units().physical_size();
params->margin_top = settings.page_setup_device_units().content_area().y();
params->margin_left = settings.page_setup_device_units().content_area().x();
params->dpi = settings.dpi();
+ params->scale_factor = settings.scale_factor();
// Currently hardcoded at 72dpi. See PrintSettings' constructor.
params->desired_dpi = settings.desired_dpi();
// Always use an invalid cookie.
params->selection_only = settings.selection_only();
params->supports_alpha_blend = settings.supports_alpha_blend();
params->should_print_backgrounds = settings.should_print_backgrounds();
+ params->display_header_footer = settings.display_header_footer();
params->title = settings.title();
params->url = settings.url();
}
+#if defined(OS_ANDROID)
+content::WebContents* GetWebContentsForRenderFrame(int render_process_id,
+ int render_frame_id) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ content::RenderFrameHost* frame =
+ content::RenderFrameHost::FromID(render_process_id, render_frame_id);
+ return frame ? content::WebContents::FromRenderFrameHost(frame) : nullptr;
+}
+
+PrintViewManagerBasic* GetPrintManager(int render_process_id,
+ int render_frame_id) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ content::WebContents* web_contents =
+ GetWebContentsForRenderFrame(render_process_id, render_frame_id);
+ return web_contents ? PrintViewManagerBasic::FromWebContents(web_contents)
+ : nullptr;
+}
+#endif
+
} // namespace
PrintingMessageFilter::PrintingMessageFilter(int render_process_id)
PrintingMessageFilter::~PrintingMessageFilter() {
}
+void PrintingMessageFilter::OnDestruct() const {
+ BrowserThread::DeleteOnUIThread::Destruct(this);
+}
+
void PrintingMessageFilter::OverrideThreadForMessage(
const IPC::Message& message, BrowserThread::ID* thread) {
-#if defined(OS_CHROMEOS)
- if (message.type() == PrintHostMsg_AllocateTempFileForPrinting::ID ||
- message.type() == PrintHostMsg_TempFileForPrintingWritten::ID) {
- *thread = BrowserThread::FILE;
- }
-#elif defined(OS_ANDROID)
+#if defined(OS_ANDROID)
if (message.type() == PrintHostMsg_AllocateTempFileForPrinting::ID ||
message.type() == PrintHostMsg_TempFileForPrintingWritten::ID) {
*thread = BrowserThread::UI;
bool PrintingMessageFilter::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(PrintingMessageFilter, message)
-#if defined(OS_WIN)
- IPC_MESSAGE_HANDLER(PrintHostMsg_DuplicateSection, OnDuplicateSection)
-#endif
-#if defined(OS_CHROMEOS) || defined(OS_ANDROID)
+#if defined(OS_ANDROID)
IPC_MESSAGE_HANDLER(PrintHostMsg_AllocateTempFileForPrinting,
OnAllocateTempFileForPrinting)
IPC_MESSAGE_HANDLER(PrintHostMsg_TempFileForPrintingWritten,
IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_ScriptedPrint, OnScriptedPrint)
IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_UpdatePrintSettings,
OnUpdatePrintSettings)
-#if defined(ENABLE_FULL_PRINTING)
- IPC_MESSAGE_HANDLER(PrintHostMsg_CheckForCancel, OnCheckForCancel)
-#endif
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
-#if defined(OS_WIN)
-void PrintingMessageFilter::OnDuplicateSection(
- base::SharedMemoryHandle renderer_handle,
- base::SharedMemoryHandle* browser_handle) {
- // Duplicate the handle in this process right now so the memory is kept alive
- // (even if it is not mapped)
- base::SharedMemory shared_buf(renderer_handle, true);
- shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), browser_handle);
-}
-#endif
-
-#if defined(OS_CHROMEOS) || defined(OS_ANDROID)
+#if defined(OS_ANDROID)
void PrintingMessageFilter::OnAllocateTempFileForPrinting(
- int render_view_id,
+ int render_frame_id,
base::FileDescriptor* temp_file_fd,
int* sequence_number) {
-#if defined(OS_CHROMEOS)
- // TODO(thestig): Use |render_view_id| for Chrome OS.
- DCHECK_CURRENTLY_ON(BrowserThread::FILE);
- temp_file_fd->fd = *sequence_number = -1;
- temp_file_fd->auto_close = false;
-
- SequenceToPathMap* map = &g_printing_file_descriptor_map.Get().map;
- *sequence_number = g_printing_file_descriptor_map.Get().sequence++;
-
- base::FilePath path;
- if (base::CreateTemporaryFile(&path)) {
- int fd = open(path.value().c_str(), O_WRONLY);
- if (fd >= 0) {
- SequenceToPathMap::iterator it = map->find(*sequence_number);
- if (it != map->end()) {
- NOTREACHED() << "Sequence number already in use. seq=" <<
- *sequence_number;
- } else {
- (*map)[*sequence_number] = path;
- temp_file_fd->fd = fd;
- temp_file_fd->auto_close = true;
- }
- }
- }
-#elif defined(OS_ANDROID)
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- content::WebContents* wc = GetWebContentsForRenderView(render_view_id);
- if (!wc)
- return;
PrintViewManagerBasic* print_view_manager =
- PrintViewManagerBasic::FromWebContents(wc);
+ GetPrintManager(render_process_id_, render_frame_id);
+ if (!print_view_manager)
+ return;
+
// The file descriptor is originally created in & passed from the Android
// side, and it will handle the closing.
- const base::FileDescriptor& file_descriptor =
- print_view_manager->file_descriptor();
- temp_file_fd->fd = file_descriptor.fd;
+ temp_file_fd->fd = print_view_manager->file_descriptor().fd;
temp_file_fd->auto_close = false;
-#endif
}
-void PrintingMessageFilter::OnTempFileForPrintingWritten(int render_view_id,
+void PrintingMessageFilter::OnTempFileForPrintingWritten(int render_frame_id,
int sequence_number) {
-#if defined(OS_CHROMEOS)
- DCHECK_CURRENTLY_ON(BrowserThread::FILE);
- SequenceToPathMap* map = &g_printing_file_descriptor_map.Get().map;
- SequenceToPathMap::iterator it = map->find(sequence_number);
- if (it == map->end()) {
- NOTREACHED() << "Got a sequence that we didn't pass to the "
- "renderer: " << sequence_number;
- return;
- }
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(&PrintingMessageFilter::CreatePrintDialogForFile,
- this, render_view_id, it->second));
-
- // Erase the entry in the map.
- map->erase(it);
-#elif defined(OS_ANDROID)
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- content::WebContents* wc = GetWebContentsForRenderView(render_view_id);
- if (!wc)
- return;
PrintViewManagerBasic* print_view_manager =
- PrintViewManagerBasic::FromWebContents(wc);
- const base::FileDescriptor& file_descriptor =
- print_view_manager->file_descriptor();
- PrintingContextAndroid::PdfWritingDone(file_descriptor.fd, true);
- // Invalidate the file descriptor so it doesn't accidentally get reused.
- print_view_manager->set_file_descriptor(base::FileDescriptor(-1, false));
-#endif
-}
-#endif // defined(OS_CHROMEOS) || defined(OS_ANDROID)
-
-#if defined(OS_CHROMEOS)
-void PrintingMessageFilter::CreatePrintDialogForFile(
- int render_view_id,
- const base::FilePath& path) {
- content::WebContents* wc = GetWebContentsForRenderView(render_view_id);
- if (!wc)
- return;
- print_dialog_cloud::CreatePrintDialogForFile(
- wc->GetBrowserContext(),
- wc->GetTopLevelNativeWindow(),
- path,
- wc->GetTitle(),
- base::string16(),
- std::string("application/pdf"));
-}
-#endif // defined(OS_CHROMEOS)
-
-content::WebContents* PrintingMessageFilter::GetWebContentsForRenderView(
- int render_view_id) {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
- content::RenderViewHost* view = content::RenderViewHost::FromID(
- render_process_id_, render_view_id);
- return view ? content::WebContents::FromRenderViewHost(view) : NULL;
+ GetPrintManager(render_process_id_, render_frame_id);
+ if (print_view_manager)
+ print_view_manager->PdfWritingDone(true);
}
+#endif // defined(OS_ANDROID)
void PrintingMessageFilter::OnGetDefaultPrintSettings(IPC::Message* reply_msg) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
scoped_refptr<PrinterQuery> printer_query;
-#if 0
- if (!profile_io_data_->printing_enabled()->GetValue()) {
+ if (false) {
// Reply with NULL query.
OnGetDefaultPrintSettingsReply(printer_query, reply_msg);
return;
}
-#endif
printer_query = queue_->PopPrinterQuery(0);
if (!printer_query.get()) {
printer_query =
// Loads default settings. This is asynchronous, only the IPC message sender
// will hang until the settings are retrieved.
printer_query->GetSettings(
- PrinterQuery::DEFAULTS,
- 0,
- false,
- DEFAULT_MARGINS,
- base::Bind(&PrintingMessageFilter::OnGetDefaultPrintSettingsReply,
- this,
- printer_query,
- reply_msg));
+ PrinterQuery::GetSettingsAskParam::DEFAULTS, 0, false, DEFAULT_MARGINS,
+ false, false,
+ base::Bind(&PrintingMessageFilter::OnGetDefaultPrintSettingsReply, this,
+ printer_query, reply_msg));
}
void PrintingMessageFilter::OnGetDefaultPrintSettingsReply(
queue_->CreatePrinterQuery(render_process_id_, reply_msg->routing_id());
}
printer_query->GetSettings(
- PrinterQuery::ASK_USER,
- params.expected_pages_count,
- params.has_selection,
- params.margin_type,
- base::Bind(&PrintingMessageFilter::OnScriptedPrintReply,
- this,
- printer_query,
- reply_msg));
+ PrinterQuery::GetSettingsAskParam::ASK_USER, params.expected_pages_count,
+ params.has_selection, params.margin_type, true, true,
+ base::Bind(&PrintingMessageFilter::OnScriptedPrintReply, this,
+ printer_query, reply_msg));
}
void PrintingMessageFilter::OnScriptedPrintReply(
params.params.document_cookie = printer_query->cookie();
params.pages = PageRange::GetPages(printer_query->settings().ranges());
}
- PrintHostMsg_UpdatePrintSettings::WriteReplyParams(
- reply_msg,
- params,
- printer_query.get() &&
- (printer_query->last_status() == printing::PrintingContext::CANCEL));
+ bool canceled = printer_query.get() &&
+ (printer_query->last_status() == PrintingContext::CANCEL);
+ PrintHostMsg_UpdatePrintSettings::WriteReplyParams(reply_msg, params,
+ canceled);
Send(reply_msg);
// If user hasn't cancelled.
if (printer_query.get()) {
#include "base/compiler_specific.h"
#include "content/public/browser/browser_message_filter.h"
-#if defined(OS_WIN)
-#include "base/memory/shared_memory.h"
-#endif
-
struct PrintHostMsg_ScriptedPrint_Params;
-class Profile;
-class ProfileIOData;
namespace base {
class DictionaryValue;
namespace printing {
-class PrintJobManager;
class PrintQueriesQueue;
class PrinterQuery;
bool OnMessageReceived(const IPC::Message& message) override;
private:
+ friend class base::DeleteHelper<PrintingMessageFilter>;
+ friend class content::BrowserThread;
+
virtual ~PrintingMessageFilter();
-#if defined(OS_WIN)
- // Used to pass resulting EMF from renderer to browser in printing.
- void OnDuplicateSection(base::SharedMemoryHandle renderer_handle,
- base::SharedMemoryHandle* browser_handle);
-#endif
+ void OnDestruct() const override;
-#if defined(OS_CHROMEOS) || defined(OS_ANDROID)
+#if defined(OS_ANDROID)
// Used to ask the browser allocate a temporary file for the renderer
// to fill in resulting PDF in renderer.
- void OnAllocateTempFileForPrinting(int render_view_id,
+ void OnAllocateTempFileForPrinting(int render_frame_id,
base::FileDescriptor* temp_file_fd,
int* sequence_number);
- void OnTempFileForPrintingWritten(int render_view_id, int sequence_number);
-#endif
+ void OnTempFileForPrintingWritten(int render_frame_id, int sequence_number);
-#if defined(OS_CHROMEOS)
- void CreatePrintDialogForFile(int render_view_id, const base::FilePath& path);
-#endif
-
-#if defined(OS_ANDROID)
// Updates the file descriptor for the PrintViewManagerBasic of a given
- // render_view_id.
- void UpdateFileDescriptor(int render_view_id, int fd);
+ // render_frame_id.
+ void UpdateFileDescriptor(int render_frame_id, int fd);
#endif
- // Given a render_view_id get the corresponding WebContents.
- // Must be called on the UI thread.
- content::WebContents* GetWebContentsForRenderView(int render_view_id);
-
- // GetPrintSettingsForRenderView must be called via PostTask and
- // base::Bind. Collapse the settings-specific params into a
- // struct to avoid running into issues with too many params
- // to base::Bind.
- struct GetPrintSettingsForRenderViewParams;
-
// Get the default print setting.
void OnGetDefaultPrintSettings(IPC::Message* reply_msg);
void OnGetDefaultPrintSettingsReply(scoped_refptr<PrinterQuery> printer_query,
void OnUpdatePrintSettingsReply(scoped_refptr<PrinterQuery> printer_query,
IPC::Message* reply_msg);
-#if defined(ENABLE_FULL_PRINTING)
- // Check to see if print preview has been cancelled.
- void OnCheckForCancel(int32_t preview_ui_id,
- int preview_request_id,
- bool* cancel);
-#endif
-
const int render_process_id_;
scoped_refptr<PrintQueriesQueue> queue_;
#include "ui/gfx/geometry/size.h"
PrintMsg_Print_Params::PrintMsg_Print_Params()
- : page_size(),
- content_size(),
- printable_area(),
- margin_top(0),
- margin_left(0),
- dpi(0),
- min_shrink(0),
- max_shrink(0),
- desired_dpi(0),
- document_cookie(0),
- selection_only(false),
- supports_alpha_blend(false),
- print_scaling_option(blink::WebPrintScalingOptionSourceSize),
- title(),
- url(),
- should_print_backgrounds(false) {
-}
+ : page_size(),
+ content_size(),
+ printable_area(),
+ margin_top(0),
+ margin_left(0),
+ dpi(0),
+ scale_factor(1.0f),
+ desired_dpi(0),
+ document_cookie(0),
+ selection_only(false),
+ supports_alpha_blend(false),
+ preview_ui_id(-1),
+ preview_request_id(0),
+ is_first_request(false),
+ print_scaling_option(blink::WebPrintScalingOptionSourceSize),
+ print_to_pdf(false),
+ display_header_footer(false),
+ title(),
+ url(),
+ should_print_backgrounds(false) {}
PrintMsg_Print_Params::~PrintMsg_Print_Params() {}
margin_top = 0;
margin_left = 0;
dpi = 0;
- min_shrink = 0;
- max_shrink = 0;
+ scale_factor = 1.0f;
desired_dpi = 0;
document_cookie = 0;
selection_only = false;
supports_alpha_blend = false;
+ preview_ui_id = -1;
+ preview_request_id = 0;
+ is_first_request = false;
print_scaling_option = blink::WebPrintScalingOptionSourceSize;
- title.clear();
- url.clear();
+ print_to_pdf = false;
+ display_header_footer = false;
+ title = base::string16();
+ url = base::string16();
should_print_backgrounds = false;
}
int margin_top;
int margin_left;
double dpi;
- double min_shrink;
- double max_shrink;
+ double scale_factor;
int desired_dpi;
+ bool rasterize_pdf;
int document_cookie;
bool selection_only;
bool supports_alpha_blend;
+ int32_t preview_ui_id;
int preview_request_id;
+ bool is_first_request;
blink::WebPrintScalingOption print_scaling_option;
bool print_to_pdf;
+ bool display_header_footer;
base::string16 title;
base::string16 url;
bool should_print_backgrounds;
// Specifies dots per inch.
IPC_STRUCT_TRAITS_MEMBER(dpi)
- // Minimum shrink factor. See PrintSettings::min_shrink for more information.
- IPC_STRUCT_TRAITS_MEMBER(min_shrink)
-
- // Maximum shrink factor. See PrintSettings::max_shrink for more information.
- IPC_STRUCT_TRAITS_MEMBER(max_shrink)
+ // Specifies the scale factor in percent
+ IPC_STRUCT_TRAITS_MEMBER(scale_factor)
// Desired apparent dpi on paper.
IPC_STRUCT_TRAITS_MEMBER(desired_dpi)
// Does the printer support alpha blending?
IPC_STRUCT_TRAITS_MEMBER(supports_alpha_blend)
+ // *** Parameters below are used only for print preview. ***
+
+ // The print preview ui associated with this request.
+ IPC_STRUCT_TRAITS_MEMBER(preview_ui_id)
+
+ // The id of the preview request.
+ IPC_STRUCT_TRAITS_MEMBER(preview_request_id)
+
+ // True if this is the first preview request.
+ IPC_STRUCT_TRAITS_MEMBER(is_first_request)
+
// Specifies the page scaling option for preview printing.
IPC_STRUCT_TRAITS_MEMBER(print_scaling_option)
+ // True if print to pdf is requested.
+ IPC_STRUCT_TRAITS_MEMBER(print_to_pdf)
+
+ // Specifies if the header and footer should be rendered.
+ IPC_STRUCT_TRAITS_MEMBER(display_header_footer)
+
// Title string to be printed as header if requested by the user.
IPC_STRUCT_TRAITS_MEMBER(title)
SetPrintPagesParams(settings);
- if (!PrintMsg_Print_Params_IsValid(settings.params)) {
- if (!print_for_preview_)
- print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS);
- return false;
- }
+ if (PrintMsg_Print_Params_IsValid(settings.params))
+ return true;
- return true;
+ if (print_for_preview_)
+ Send(new PrintHostMsg_ShowInvalidPrinterSettingsError(routing_id()));
+ else
+ print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS);
+ return false;
}
-
bool PrintWebViewHelper::GetPrintSettingsFromUser(blink::WebLocalFrame* frame,
const blink::WebNode& node,
int expected_pages_count) {
void PrintWebViewHelper::SetPrintPagesParams(
const PrintMsg_PrintPages_Params& settings) {
print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings));
+ Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(),
+ settings.params.document_cookie));
}
bool PrintWebViewHelper::PreviewPageRendered(int page_number,