| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/process_util.h" | 11 #include "base/process_util.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 14 #include "chrome/common/print_messages.h" | 14 #include "chrome/common/print_messages.h" |
| 15 #include "chrome/common/render_messages.h" |
| 16 #include "chrome/renderer/prerender/prerender_helper.h" |
| 15 #include "content/renderer/render_view.h" | 17 #include "content/renderer/render_view.h" |
| 16 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
| 17 #include "printing/metafile.h" | 19 #include "printing/metafile.h" |
| 18 #include "printing/units.h" | 20 #include "printing/units.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h" |
| 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" |
| 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 notify_browser_of_print_failure_(true) { | 127 notify_browser_of_print_failure_(true) { |
| 126 is_preview_ = switches::IsPrintPreviewEnabled(); | 128 is_preview_ = switches::IsPrintPreviewEnabled(); |
| 127 } | 129 } |
| 128 | 130 |
| 129 PrintWebViewHelper::~PrintWebViewHelper() {} | 131 PrintWebViewHelper::~PrintWebViewHelper() {} |
| 130 | 132 |
| 131 // Prints |frame| which called window.print(). | 133 // Prints |frame| which called window.print(). |
| 132 void PrintWebViewHelper::PrintPage(WebKit::WebFrame* frame) { | 134 void PrintWebViewHelper::PrintPage(WebKit::WebFrame* frame) { |
| 133 DCHECK(frame); | 135 DCHECK(frame); |
| 134 | 136 |
| 137 // Allow Prerendering to cancel this print request if necessary. |
| 138 if (prerender::PrerenderHelper::IsPrerendering(render_view())) { |
| 139 Send(new ViewHostMsg_CancelPrerenderForPrinting(routing_id())); |
| 140 return; |
| 141 } |
| 142 |
| 135 if (IsScriptInitiatedPrintTooFrequent(frame)) | 143 if (IsScriptInitiatedPrintTooFrequent(frame)) |
| 136 return; | 144 return; |
| 137 IncrementScriptedPrintCount(); | 145 IncrementScriptedPrintCount(); |
| 138 | 146 |
| 139 if (is_preview_) { | 147 if (is_preview_) { |
| 140 script_initiated_preview_frame_ = frame; | 148 script_initiated_preview_frame_ = frame; |
| 141 Send(new PrintHostMsg_ScriptInitiatedPrintPreview(routing_id())); | 149 Send(new PrintHostMsg_ScriptInitiatedPrintPreview(routing_id())); |
| 142 } else { | 150 } else { |
| 143 Print(frame, NULL); | 151 Print(frame, NULL); |
| 144 } | 152 } |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 | 698 |
| 691 void PrintWebViewHelper::ResetScriptedPrintCount() { | 699 void PrintWebViewHelper::ResetScriptedPrintCount() { |
| 692 // Reset cancel counter on successful print. | 700 // Reset cancel counter on successful print. |
| 693 user_cancelled_scripted_print_count_ = 0; | 701 user_cancelled_scripted_print_count_ = 0; |
| 694 } | 702 } |
| 695 | 703 |
| 696 void PrintWebViewHelper::IncrementScriptedPrintCount() { | 704 void PrintWebViewHelper::IncrementScriptedPrintCount() { |
| 697 ++user_cancelled_scripted_print_count_; | 705 ++user_cancelled_scripted_print_count_; |
| 698 last_cancelled_script_print_ = base::Time::Now(); | 706 last_cancelled_script_print_ = base::Time::Now(); |
| 699 } | 707 } |
| OLD | NEW |