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