summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/print_web_view_helper.cc
diff options
context:
space:
mode:
authorscottbyer@chromium.org <scottbyer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-19 21:36:11 +0000
committerscottbyer@chromium.org <scottbyer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-19 21:36:11 +0000
commitb0553c7e1b6a27836ad06ac2e88ccf83e2873bb1 (patch)
tree724976499fae1b135284c1ecafa9a733f4a4c100 /chrome/renderer/print_web_view_helper.cc
parentd46a4cdb31cea518f6878e8451129cdf810d5686 (diff)
downloadchromium_src-b0553c7e1b6a27836ad06ac2e88ccf83e2873bb1.zip
chromium_src-b0553c7e1b6a27836ad06ac2e88ccf83e2873bb1.tar.gz
chromium_src-b0553c7e1b6a27836ad06ac2e88ccf83e2873bb1.tar.bz2
Reign in print throttling.
Don't throttle the frequency of calls to window.print() from JavaScript if the action was user initiated (e.g., clicking on a button), if print preview is active (which is tab-modal, so the user can easily stop any attempted DOS), or if a flag on the command line is given (say, you want to run chromium for a point-of-sale system). BUG=50186 TEST=Go to a web page with a print button - should be able to click on the button and cancel the print quickly without ever seeing the dreaded warning from 50186 in the console. Review URL: https://chromiumcodereview.appspot.com/10890054 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@157612 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/print_web_view_helper.cc')
-rw-r--r--chrome/renderer/print_web_view_helper.cc23
1 files changed, 19 insertions, 4 deletions
diff --git a/chrome/renderer/print_web_view_helper.cc b/chrome/renderer/print_web_view_helper.cc
index ccf7789..5ba2c80 100644
--- a/chrome/renderer/print_web_view_helper.cc
+++ b/chrome/renderer/print_web_view_helper.cc
@@ -527,6 +527,11 @@ bool IsPrintPreviewEnabled() {
switches::kRendererPrintPreview);
}
+bool IsPrintThrottlingDisabled() {
+ return CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kDisableScriptedPrintThrottling);
+}
+
} // namespace
// static - Not anonymous so that platform implementations can use it.
@@ -717,6 +722,7 @@ PrintWebViewHelper::PrintWebViewHelper(content::RenderView* render_view)
content::RenderViewObserverTracker<PrintWebViewHelper>(render_view),
print_web_view_(NULL),
is_preview_enabled_(IsPrintPreviewEnabled()),
+ is_scripted_print_throttling_disabled_(IsPrintThrottlingDisabled()),
is_print_ready_metafile_sent_(false),
ignore_css_margins_(false),
user_cancelled_scripted_print_count_(0),
@@ -728,14 +734,23 @@ PrintWebViewHelper::PrintWebViewHelper(content::RenderView* render_view)
PrintWebViewHelper::~PrintWebViewHelper() {}
bool PrintWebViewHelper::IsScriptInitiatedPrintAllowed(
- WebKit::WebFrame* frame) {
+ WebKit::WebFrame* frame, bool user_initiated) {
if (is_scripted_printing_blocked_)
return false;
- return !IsScriptInitiatedPrintTooFrequent(frame);
+ // If preview is enabled, then the print dialog is tab modal, and the user
+ // can always close the tab on a mis-behaving page (the system print dialog
+ // is app modal). If the print was initiated through user action, don't
+ // throttle. Or, if the command line flag to skip throttling has been set.
+ if (!is_scripted_print_throttling_disabled_ &&
+ !is_preview_enabled_ &&
+ !user_initiated)
+ return !IsScriptInitiatedPrintTooFrequent(frame);
+ return true;
}
// Prints |frame| which called window.print().
-void PrintWebViewHelper::PrintPage(WebKit::WebFrame* frame) {
+void PrintWebViewHelper::PrintPage(WebKit::WebFrame* frame,
+ bool user_initiated) {
DCHECK(frame);
// Allow Prerendering to cancel this print request if necessary.
@@ -744,7 +759,7 @@ void PrintWebViewHelper::PrintPage(WebKit::WebFrame* frame) {
return;
}
- if (!IsScriptInitiatedPrintAllowed(frame))
+ if (!IsScriptInitiatedPrintAllowed(frame, user_initiated))
return;
IncrementScriptedPrintCount();