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

Unified Diff: chrome/renderer/print_web_view_helper.cc

Issue 7993005: Reuse PrintContext to excessively triggering matchMedia('print') listeners. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Adds a unit test and updates DPI on change. Created 9 years, 2 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: 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 4df68f09ebe9fb0d1fea2161c7d888c6ed5e51cc..05b7f42ad5c085510abd233e7ba1c79dd4084dfd 100644
--- a/chrome/renderer/print_web_view_helper.cc
+++ b/chrome/renderer/print_web_view_helper.cc
@@ -372,11 +372,8 @@ PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint(
WebFrame* frame,
const WebNode& node)
: frame_(frame),
- node_to_print_(node),
web_view_(frame->view()),
- dpi_(static_cast<int>(print_params.dpi)),
expected_pages_count_(0),
- use_browser_overlays_(true),
finished_(false) {
gfx::Size canvas_size;
CalculatePrintCanvasSize(print_params, &canvas_size);
@@ -385,7 +382,8 @@ PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint(
prev_scroll_offset_ = web_frame->scrollOffset();
prev_view_size_ = web_view_->size();
- StartPrinting(canvas_size);
+ frame_->printBegin(node);
+ StartPrinting(canvas_size, static_cast<int>(print_params.dpi));
}
PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() {
@@ -397,17 +395,22 @@ void PrepareFrameAndViewForPrint::UpdatePrintParams(
DCHECK(!finished_);
gfx::Size canvas_size;
CalculatePrintCanvasSize(print_params, &canvas_size);
- if (canvas_size == print_canvas_size_)
+ int dpi = static_cast<int>(print_params.dpi);
+ if (canvas_size == print_canvas_size_ && dpi == dpi_)
return;
- frame_->printEnd();
- dpi_ = static_cast<int>(print_params.dpi);
- StartPrinting(canvas_size);
+ StartPrinting(canvas_size, dpi);
+}
+
+bool PrepareFrameAndViewForPrint::ShouldUseBrowserOverlays() const {
+ return frame_->shouldUseBrowserOverlays();
}
void PrepareFrameAndViewForPrint::StartPrinting(
- const gfx::Size& print_canvas_size) {
+ const gfx::Size& print_canvas_size,
+ int dpi) {
print_canvas_size_ = print_canvas_size;
+ dpi_ = dpi;
// Layout page according to printer page size. Since WebKit shrinks the
// size of the page automatically (from 125% to 200%) we trick it to
@@ -420,8 +423,8 @@ void PrepareFrameAndViewForPrint::StartPrinting(
web_view_->resize(print_layout_size);
- expected_pages_count_ = frame_->printBegin(print_canvas_size_, node_to_print_,
- dpi_, &use_browser_overlays_);
+ expected_pages_count_ =
+ frame_->setPageSizeResolution(print_canvas_size_, dpi);
}
void PrepareFrameAndViewForPrint::FinishPrinting() {
@@ -748,10 +751,6 @@ void PrintWebViewHelper::Print(WebKit::WebFrame* frame,
if (expected_page_count)
use_browser_overlays = prepare->ShouldUseBrowserOverlays();
- // Release the prepare before going any further, since we are going to
- // show UI and wait for the user.
- prepare.reset();
-
// Some full screen plugins can say they don't want to print.
if (!expected_page_count) {
DidFinishPrinting(OK); // Release resources and fail silently.
@@ -766,7 +765,7 @@ void PrintWebViewHelper::Print(WebKit::WebFrame* frame,
}
// Render Pages for printing.
- if (!RenderPagesForPrint(frame, node, NULL)) {
+ if (!RenderPagesForPrint(frame, node, prepare.get())) {
LOG(ERROR) << "RenderPagesForPrint failed";
DidFinishPrinting(FAIL_PRINT);
}

Powered by Google App Engine
This is Rietveld 408576698