 Chromium Code Reviews
 Chromium Code Reviews Issue 7015026:
  Cancel prerenders for pages that call window.print()  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 7015026:
  Cancel prerenders for pages that call window.print()  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| 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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 WebNode duplicate_node(context_menu_node); | 264 WebNode duplicate_node(context_menu_node); | 
| 263 Print(duplicate_node.document().frame(), &duplicate_node); | 265 Print(duplicate_node.document().frame(), &duplicate_node); | 
| 264 } | 266 } | 
| 265 } | 267 } | 
| 266 | 268 | 
| 267 void PrintWebViewHelper::Print(WebKit::WebFrame* frame, WebKit::WebNode* node) { | 269 void PrintWebViewHelper::Print(WebKit::WebFrame* frame, WebKit::WebNode* node) { | 
| 268 // If still not finished with earlier print request simply ignore. | 270 // If still not finished with earlier print request simply ignore. | 
| 269 if (print_web_view_) | 271 if (print_web_view_) | 
| 270 return; | 272 return; | 
| 271 | 273 | 
| 274 // Allow Prerendering to cancel this if necessary. | |
| 
Lei Zhang
2011/05/14 04:11:56
I would put this at the top of PrintWebViewHelper:
 
dominich
2011/05/16 16:28:00
Done.
 | |
| 275 if (prerender::PrerenderHelper::IsPrerendering(render_view())) { | |
| 276 Send(new ViewHostMsg_CancelPrerenderForPrinting( | |
| 277 render_view()->routing_id())); | |
| 278 return; | |
| 279 } | |
| 280 | |
| 272 // Initialize print settings. | 281 // Initialize print settings. | 
| 273 if (!InitPrintSettings(frame, node)) | 282 if (!InitPrintSettings(frame, node)) | 
| 274 return; // Failed to init print page settings. | 283 return; // Failed to init print page settings. | 
| 275 | 284 | 
| 276 int expected_pages_count = 0; | 285 int expected_pages_count = 0; | 
| 277 bool use_browser_overlays = true; | 286 bool use_browser_overlays = true; | 
| 278 | 287 | 
| 279 // Prepare once to calculate the estimated page count. This must be in | 288 // Prepare once to calculate the estimated page count. This must be in | 
| 280 // a scope for itself (see comments on PrepareFrameAndViewForPrint). | 289 // a scope for itself (see comments on PrepareFrameAndViewForPrint). | 
| 281 { | 290 { | 
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 690 | 699 | 
| 691 void PrintWebViewHelper::ResetScriptedPrintCount() { | 700 void PrintWebViewHelper::ResetScriptedPrintCount() { | 
| 692 // Reset cancel counter on successful print. | 701 // Reset cancel counter on successful print. | 
| 693 user_cancelled_scripted_print_count_ = 0; | 702 user_cancelled_scripted_print_count_ = 0; | 
| 694 } | 703 } | 
| 695 | 704 | 
| 696 void PrintWebViewHelper::IncrementScriptedPrintCount() { | 705 void PrintWebViewHelper::IncrementScriptedPrintCount() { | 
| 697 ++user_cancelled_scripted_print_count_; | 706 ++user_cancelled_scripted_print_count_; | 
| 698 last_cancelled_script_print_ = base::Time::Now(); | 707 last_cancelled_script_print_ = base::Time::Now(); | 
| 699 } | 708 } | 
| OLD | NEW |