| 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" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() { | 109 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() { |
| 110 frame_->printEnd(); | 110 frame_->printEnd(); |
| 111 web_view_->resize(prev_view_size_); | 111 web_view_->resize(prev_view_size_); |
| 112 if (WebFrame* web_frame = web_view_->mainFrame()) | 112 if (WebFrame* web_frame = web_view_->mainFrame()) |
| 113 web_frame->setScrollOffset(prev_scroll_offset_); | 113 web_frame->setScrollOffset(prev_scroll_offset_); |
| 114 } | 114 } |
| 115 | 115 |
| 116 | 116 |
| 117 PrintWebViewHelper::PrintWebViewHelper(RenderView* render_view) | 117 PrintWebViewHelper::PrintWebViewHelper(RenderView* render_view) |
| 118 : RenderViewObserver(render_view), | 118 : RenderViewObserver(render_view), |
| 119 RenderViewObserverTracker<PrintWebViewHelper>(render_view), |
| 119 print_web_view_(NULL), | 120 print_web_view_(NULL), |
| 120 script_initiated_preview_frame_(NULL), | 121 script_initiated_preview_frame_(NULL), |
| 121 context_menu_preview_node_(NULL), | 122 context_menu_preview_node_(NULL), |
| 122 user_cancelled_scripted_print_count_(0) { | 123 user_cancelled_scripted_print_count_(0) { |
| 123 is_preview_ = CommandLine::ForCurrentProcess()->HasSwitch( | 124 is_preview_ = CommandLine::ForCurrentProcess()->HasSwitch( |
| 124 switches::kEnablePrintPreview); | 125 switches::kEnablePrintPreview); |
| 125 } | 126 } |
| 126 | 127 |
| 127 PrintWebViewHelper::~PrintWebViewHelper() {} | 128 PrintWebViewHelper::~PrintWebViewHelper() {} |
| 128 | 129 |
| 129 void PrintWebViewHelper::ScriptInitiatedPrint(WebKit::WebFrame* frame) { | 130 // Prints |frame| which called window.print(). |
| 131 void PrintWebViewHelper::printPage(WebKit::WebFrame* frame) { |
| 130 DCHECK(frame); | 132 DCHECK(frame); |
| 131 | 133 |
| 132 if (IsScriptInitiatedPrintTooFrequent(frame)) | 134 if (IsScriptInitiatedPrintTooFrequent(frame)) |
| 133 return; | 135 return; |
| 134 IncrementScriptedPrintCount(); | 136 IncrementScriptedPrintCount(); |
| 135 | 137 |
| 136 if (is_preview_) { | 138 if (is_preview_) { |
| 137 script_initiated_preview_frame_ = frame; | 139 script_initiated_preview_frame_ = frame; |
| 138 if (!render_view()->Send(new PrintHostMsg_ScriptInitiatedPrintPreview( | 140 if (!render_view()->Send(new PrintHostMsg_ScriptInitiatedPrintPreview( |
| 139 render_view()->routing_id()))) { | 141 render_view()->routing_id()))) { |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 | 687 |
| 686 void PrintWebViewHelper::ResetScriptedPrintCount() { | 688 void PrintWebViewHelper::ResetScriptedPrintCount() { |
| 687 // Reset cancel counter on successful print. | 689 // Reset cancel counter on successful print. |
| 688 user_cancelled_scripted_print_count_ = 0; | 690 user_cancelled_scripted_print_count_ = 0; |
| 689 } | 691 } |
| 690 | 692 |
| 691 void PrintWebViewHelper::IncrementScriptedPrintCount() { | 693 void PrintWebViewHelper::IncrementScriptedPrintCount() { |
| 692 ++user_cancelled_scripted_print_count_; | 694 ++user_cancelled_scripted_print_count_; |
| 693 last_cancelled_script_print_ = base::Time::Now(); | 695 last_cancelled_script_print_ = base::Time::Now(); |
| 694 } | 696 } |
| OLD | NEW |