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

Side by Side Diff: chrome/renderer/print_web_view_helper.cc

Issue 10890054: Reign in print throttling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to start review Created 8 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/renderer/print_web_view_helper.h" 5 #include "chrome/renderer/print_web_view_helper.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 *scale_factor = factor; 520 *scale_factor = factor;
521 } 521 }
522 return result_params; 522 return result_params;
523 } 523 }
524 524
525 bool IsPrintPreviewEnabled() { 525 bool IsPrintPreviewEnabled() {
526 return CommandLine::ForCurrentProcess()->HasSwitch( 526 return CommandLine::ForCurrentProcess()->HasSwitch(
527 switches::kRendererPrintPreview); 527 switches::kRendererPrintPreview);
528 } 528 }
529 529
530 bool IsPrintThrottlingDisabled() {
531 return CommandLine::ForCurrentProcess()->HasSwitch(
532 switches::kDisableScriptedPrintThrottling);
533 }
534
530 } // namespace 535 } // namespace
531 536
532 // static - Not anonymous so that platform implementations can use it. 537 // static - Not anonymous so that platform implementations can use it.
533 void PrintWebViewHelper::PrintHeaderAndFooter( 538 void PrintWebViewHelper::PrintHeaderAndFooter(
534 WebKit::WebCanvas* canvas, 539 WebKit::WebCanvas* canvas,
535 int page_number, 540 int page_number,
536 int total_pages, 541 int total_pages,
537 float webkit_scale_factor, 542 float webkit_scale_factor,
538 const PageSizeMargins& page_layout, 543 const PageSizeMargins& page_layout,
539 const DictionaryValue& header_footer_info) { 544 const DictionaryValue& header_footer_info) {
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 if (WebFrame* web_frame = web_view_->mainFrame()) 715 if (WebFrame* web_frame = web_view_->mainFrame())
711 web_frame->setScrollOffset(prev_scroll_offset_); 716 web_frame->setScrollOffset(prev_scroll_offset_);
712 } 717 }
713 } 718 }
714 719
715 PrintWebViewHelper::PrintWebViewHelper(content::RenderView* render_view) 720 PrintWebViewHelper::PrintWebViewHelper(content::RenderView* render_view)
716 : content::RenderViewObserver(render_view), 721 : content::RenderViewObserver(render_view),
717 content::RenderViewObserverTracker<PrintWebViewHelper>(render_view), 722 content::RenderViewObserverTracker<PrintWebViewHelper>(render_view),
718 print_web_view_(NULL), 723 print_web_view_(NULL),
719 is_preview_enabled_(IsPrintPreviewEnabled()), 724 is_preview_enabled_(IsPrintPreviewEnabled()),
725 is_scripted_print_throttling_disabled_(IsPrintThrottlingDisabled()),
720 is_print_ready_metafile_sent_(false), 726 is_print_ready_metafile_sent_(false),
721 ignore_css_margins_(false), 727 ignore_css_margins_(false),
722 user_cancelled_scripted_print_count_(0), 728 user_cancelled_scripted_print_count_(0),
723 is_scripted_printing_blocked_(false), 729 is_scripted_printing_blocked_(false),
724 notify_browser_of_print_failure_(true), 730 notify_browser_of_print_failure_(true),
725 print_for_preview_(false) { 731 print_for_preview_(false) {
726 } 732 }
727 733
728 PrintWebViewHelper::~PrintWebViewHelper() {} 734 PrintWebViewHelper::~PrintWebViewHelper() {}
729 735
730 bool PrintWebViewHelper::IsScriptInitiatedPrintAllowed( 736 bool PrintWebViewHelper::IsScriptInitiatedPrintAllowed(
731 WebKit::WebFrame* frame) { 737 WebKit::WebFrame* frame, bool user_initiated) {
732 if (is_scripted_printing_blocked_) 738 if (is_scripted_printing_blocked_)
733 return false; 739 return false;
734 return !IsScriptInitiatedPrintTooFrequent(frame); 740 // If preview is enabled, then the print dialog is tab modal, and the user
Lei Zhang 2012/08/30 18:15:31 Keep in mind there's a long term goal to make scri
Scott Byer 2012/08/30 18:22:12 I think the key to keeping the condition would be
741 // can always close the tab on a mis-behaving page (the system print dialog
742 // is app modal). If the print was initiated through user action, don't
743 // throttle. Or, if the command line flag to skip throttling has been set.
744 if (!is_scripted_print_throttling_disabled_ &&
745 !is_preview_enabled_ &&
746 !user_initiated)
747 return !IsScriptInitiatedPrintTooFrequent(frame);
748 return true;
735 } 749 }
736 750
737 // Prints |frame| which called window.print(). 751 // Prints |frame| which called window.print().
738 void PrintWebViewHelper::PrintPage(WebKit::WebFrame* frame) { 752 void PrintWebViewHelper::PrintPage(WebKit::WebFrame* frame,
753 bool user_initiated) {
739 DCHECK(frame); 754 DCHECK(frame);
740 755
741 // Allow Prerendering to cancel this print request if necessary. 756 // Allow Prerendering to cancel this print request if necessary.
742 if (prerender::PrerenderHelper::IsPrerendering(render_view())) { 757 if (prerender::PrerenderHelper::IsPrerendering(render_view())) {
743 Send(new ChromeViewHostMsg_CancelPrerenderForPrinting(routing_id())); 758 Send(new ChromeViewHostMsg_CancelPrerenderForPrinting(routing_id()));
744 return; 759 return;
745 } 760 }
746 761
747 if (!IsScriptInitiatedPrintAllowed(frame)) 762 if (!IsScriptInitiatedPrintAllowed(frame, user_initiated))
748 return; 763 return;
749 IncrementScriptedPrintCount(); 764 IncrementScriptedPrintCount();
750 765
751 if (is_preview_enabled_) { 766 if (is_preview_enabled_) {
752 print_preview_context_.InitWithFrame(frame); 767 print_preview_context_.InitWithFrame(frame);
753 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED); 768 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED);
754 } else { 769 } else {
755 Print(frame, WebNode()); 770 Print(frame, WebNode());
756 } 771 }
757 } 772 }
(...skipping 1122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1880 DCHECK(IsRendering()); 1895 DCHECK(IsRendering());
1881 return prep_frame_view_->GetPrintCanvasSize(); 1896 return prep_frame_view_->GetPrintCanvasSize();
1882 } 1897 }
1883 1898
1884 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { 1899 void PrintWebViewHelper::PrintPreviewContext::ClearContext() {
1885 prep_frame_view_.reset(); 1900 prep_frame_view_.reset();
1886 metafile_.reset(); 1901 metafile_.reset();
1887 pages_to_render_.clear(); 1902 pages_to_render_.clear();
1888 error_ = PREVIEW_ERROR_NONE; 1903 error_ = PREVIEW_ERROR_NONE;
1889 } 1904 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698