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

Unified Diff: chrome/renderer/print_web_view_helper.cc

Issue 7822014: Fix the print preview regression bug caused by r98926. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 9 years, 4 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
« no previous file with comments | « chrome/renderer/print_web_view_helper.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/print_web_view_helper.cc
diff --git a/chrome/renderer/print_web_view_helper.cc b/chrome/renderer/print_web_view_helper.cc
index 36726eee4667e71193e7de272e489219da218c46..b7b386626e1fc07b74cd53e247ec2fa407ca3b12 100644
--- a/chrome/renderer/print_web_view_helper.cc
+++ b/chrome/renderer/print_web_view_helper.cc
@@ -702,19 +702,32 @@ bool PrintWebViewHelper::CreatePreviewDocument() {
if (CheckForCancel())
return false;
- int page_number;
- while ((page_number = print_preview_context_.GetNextPageNumber()) >= 0) {
+ while (!print_preview_context_.IsFinalPageRendered()) {
+ int page_number = print_preview_context_.GetNextPageNumber();
+ DCHECK(page_number >= 0);
if (!RenderPreviewPage(page_number))
return false;
+
if (CheckForCancel())
return false;
+
+ // We must call PrepareFrameAndViewForPrint::FinishPrinting() (by way of
+ // print_preview_context_.AllPagesRendered()) before calling
+ // FinalizePrintReadyDocument() when printing a PDF because the plugin
+ // code does not generate output until we call FinishPrinting(). We do not
+ // generate draft pages for PDFs, so IsFinalPageRendered() and
+ // IsLastPageOfPrintReadyMetafile() will be true in the same iteration of
+ // the loop.
+ if (print_preview_context_.IsFinalPageRendered())
+ print_preview_context_.AllPagesRendered();
+
if (print_preview_context_.IsLastPageOfPrintReadyMetafile()) {
- // Finished generating preview. Finalize the document.
+ DCHECK(print_preview_context_.IsModifiable() ||
+ print_preview_context_.IsFinalPageRendered());
if (!FinalizePrintReadyDocument())
return false;
}
}
- print_preview_context_.AllPagesRendered();
print_preview_context_.Finished();
return true;
}
@@ -1379,11 +1392,11 @@ bool PrintWebViewHelper::PrintPreviewContext::CreatePreviewDocument(
if (selected_page_count == 0) {
print_ready_metafile_page_count_ = total_page_count_;
// Render all pages.
- for (int i = 0; i < total_page_count_; i++)
+ for (int i = 0; i < total_page_count_; ++i)
pages_to_render_.push_back(i);
} else if (generate_draft_pages_) {
int pages_index = 0;
- for (int i = 0; i < total_page_count_; i++) {
+ for (int i = 0; i < total_page_count_; ++i) {
if (pages_index < selected_page_count && i == pages[pages_index]) {
pages_index++;
continue;
@@ -1446,7 +1459,7 @@ void PrintWebViewHelper::PrintPreviewContext::Failed() {
int PrintWebViewHelper::PrintPreviewContext::GetNextPageNumber() {
DCHECK_EQ(RENDERING, state_);
- if ((size_t)(current_page_index_) == pages_to_render_.size())
+ if (IsFinalPageRendered())
return -1;
return pages_to_render_[current_page_index_++];
}
@@ -1470,6 +1483,10 @@ bool PrintWebViewHelper::PrintPreviewContext::IsLastPageOfPrintReadyMetafile()
return current_page_index_ == print_ready_metafile_page_count_;
}
+bool PrintWebViewHelper::PrintPreviewContext::IsFinalPageRendered() const {
+ return static_cast<size_t>(current_page_index_) == pages_to_render_.size();
+}
+
void PrintWebViewHelper::PrintPreviewContext::set_generate_draft_pages(
bool generate_draft_pages) {
generate_draft_pages_ = generate_draft_pages;
« no previous file with comments | « chrome/renderer/print_web_view_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698