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

Unified Diff: chrome/renderer/printing/print_web_view_helper.cc

Issue 488853002: Removed --disable-print-preview switch and policy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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
Index: chrome/renderer/printing/print_web_view_helper.cc
diff --git a/chrome/renderer/printing/print_web_view_helper.cc b/chrome/renderer/printing/print_web_view_helper.cc
index a34ff1d2fe91acebc579b2a147596a5e18da3a11..02ccfcfff0b62cd038c96f4be50bbb43a5a8d5d4 100644
--- a/chrome/renderer/printing/print_web_view_helper.cc
+++ b/chrome/renderer/printing/print_web_view_helper.cc
@@ -400,16 +400,6 @@ PrintMsg_Print_Params CalculatePrintParamsForCss(
return result_params;
}
-bool IsPrintPreviewEnabled() {
- return CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kRendererPrintPreview);
-}
-
-bool IsPrintThrottlingDisabled() {
- return CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kDisableScriptedPrintThrottling);
-}
-
} // namespace
FrameReference::FrameReference(blink::WebLocalFrame* frame) {
@@ -781,11 +771,8 @@ PrintWebViewHelper::PrintWebViewHelper(content::RenderView* render_view)
: content::RenderViewObserver(render_view),
content::RenderViewObserverTracker<PrintWebViewHelper>(render_view),
reset_prep_frame_view_(false),
- 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),
is_scripted_printing_blocked_(false),
notify_browser_of_print_failure_(true),
print_for_preview_(false),
@@ -804,14 +791,6 @@ bool PrintWebViewHelper::IsScriptInitiatedPrintAllowed(
#endif // defined(OS_ANDROID)
if (is_scripted_printing_blocked_)
return false;
- // 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;
}
@@ -841,14 +820,8 @@ void PrintWebViewHelper::PrintPage(blink::WebLocalFrame* frame,
if (!IsScriptInitiatedPrintAllowed(frame, user_initiated))
return;
- IncrementScriptedPrintCount();
-
- if (is_preview_enabled_) {
- print_preview_context_.InitWithFrame(frame);
- RequestPrintPreview(PRINT_PREVIEW_SCRIPTED);
- } else {
- Print(frame, blink::WebNode());
- }
+ print_preview_context_.InitWithFrame(frame);
+ RequestPrintPreview(PRINT_PREVIEW_SCRIPTED);
}
bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) {
@@ -860,8 +833,6 @@ bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(PrintMsg_PrintPreview, OnPrintPreview)
IPC_MESSAGE_HANDLER(PrintMsg_PrintForPrintPreview, OnPrintForPrintPreview)
IPC_MESSAGE_HANDLER(PrintMsg_PrintingDone, OnPrintingDone)
- IPC_MESSAGE_HANDLER(PrintMsg_ResetScriptedPrintCount,
- ResetScriptedPrintCount)
IPC_MESSAGE_HANDLER(PrintMsg_SetScriptedPrintingBlocked,
SetScriptedPrintBlocked)
IPC_MESSAGE_UNHANDLED(handled = false)
@@ -871,7 +842,6 @@ bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) {
void PrintWebViewHelper::OnPrintForPrintPreview(
const base::DictionaryValue& job_settings) {
- DCHECK(is_preview_enabled_);
// If still not finished with earlier print request simply ignore.
if (prep_frame_view_)
return;
@@ -1005,7 +975,6 @@ bool PrintWebViewHelper::IsPrintToPdfRequested(
}
void PrintWebViewHelper::OnPrintPreview(const base::DictionaryValue& settings) {
- DCHECK(is_preview_enabled_);
print_preview_context_.OnPrintPreview();
UMA_HISTOGRAM_ENUMERATION("PrintPreview.PreviewEvent",
@@ -1208,7 +1177,6 @@ void PrintWebViewHelper::SetScriptedPrintBlocked(bool blocked) {
}
void PrintWebViewHelper::OnInitiatePrintPreview(bool selection_only) {
- DCHECK(is_preview_enabled_);
blink::WebLocalFrame* frame = NULL;
GetPrintFrame(&frame);
DCHECK(frame);
@@ -1242,13 +1210,8 @@ void PrintWebViewHelper::PrintNode(const blink::WebNode& node) {
// Make a copy of the node, in case RenderView::OnContextMenuClosed resets
// its |context_menu_node_|.
- if (is_preview_enabled_) {
- print_preview_context_.InitWithNode(node);
- RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE);
- } else {
- blink::WebNode duplicate_node(node);
- Print(duplicate_node.document().frame(), duplicate_node);
- }
+ print_preview_context_.InitWithNode(node);
+ RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE);
print_node_in_progress_ = false;
}
@@ -1285,7 +1248,6 @@ void PrintWebViewHelper::Print(blink::WebLocalFrame* frame,
LOG(ERROR) << "RenderPagesForPrint failed";
DidFinishPrinting(FAIL_PRINT);
}
- ResetScriptedPrintCount();
}
void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) {
@@ -1305,7 +1267,6 @@ void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) {
break;
case FAIL_PREVIEW:
- DCHECK(is_preview_enabled_);
int cookie = print_pages_params_ ?
print_pages_params_->params.document_cookie : 0;
if (notify_browser_of_print_failure_) {
@@ -1474,7 +1435,6 @@ bool PrintWebViewHelper::UpdatePrintSettings(
blink::WebLocalFrame* frame,
const blink::WebNode& node,
const base::DictionaryValue& passed_job_settings) {
- DCHECK(is_preview_enabled_);
const base::DictionaryValue* job_settings = &passed_job_settings;
base::DictionaryValue modified_job_settings;
if (job_settings->empty()) {
@@ -1623,54 +1583,6 @@ bool PrintWebViewHelper::CopyMetafileDataToSharedMem(
}
#endif // defined(OS_POSIX)
-bool PrintWebViewHelper::IsScriptInitiatedPrintTooFrequent(
- blink::WebFrame* frame) {
- const int kMinSecondsToIgnoreJavascriptInitiatedPrint = 2;
- const int kMaxSecondsToIgnoreJavascriptInitiatedPrint = 32;
- bool too_frequent = false;
-
- // Check if there is script repeatedly trying to print and ignore it if too
- // frequent. The first 3 times, we use a constant wait time, but if this
- // gets excessive, we switch to exponential wait time. So for a page that
- // calls print() in a loop the user will need to cancel the print dialog
- // after: [2, 2, 2, 4, 8, 16, 32, 32, ...] seconds.
- // This gives the user time to navigate from the page.
- if (user_cancelled_scripted_print_count_ > 0) {
- base::TimeDelta diff = base::Time::Now() - last_cancelled_script_print_;
- int min_wait_seconds = kMinSecondsToIgnoreJavascriptInitiatedPrint;
- if (user_cancelled_scripted_print_count_ > 3) {
- min_wait_seconds = std::min(
- kMinSecondsToIgnoreJavascriptInitiatedPrint <<
- (user_cancelled_scripted_print_count_ - 3),
- kMaxSecondsToIgnoreJavascriptInitiatedPrint);
- }
- if (diff.InSeconds() < min_wait_seconds) {
- too_frequent = true;
- }
- }
-
- if (!too_frequent)
- return false;
-
- blink::WebString message(
- blink::WebString::fromUTF8("Ignoring too frequent calls to print()."));
- frame->addMessageToConsole(
- blink::WebConsoleMessage(
- blink::WebConsoleMessage::LevelWarning, message));
- return true;
-}
-
-void PrintWebViewHelper::ResetScriptedPrintCount() {
- // Reset cancel counter on successful print.
- user_cancelled_scripted_print_count_ = 0;
-}
-
-void PrintWebViewHelper::IncrementScriptedPrintCount() {
- ++user_cancelled_scripted_print_count_;
- last_cancelled_script_print_ = base::Time::Now();
-}
-
-
void PrintWebViewHelper::ShowScriptedPrintPreview() {
if (is_scripted_preview_delayed_) {
is_scripted_preview_delayed_ = false;
« no previous file with comments | « chrome/renderer/printing/print_web_view_helper.h ('k') | chrome/renderer/printing/print_web_view_helper_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698