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

Side by Side Diff: chrome/renderer/printing/print_web_view_helper.cc

Issue 23855002: Fixing spreadsheets printing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/printing/print_web_view_helper.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/printing/print_web_view_helper.h" 5 #include "chrome/renderer/printing/print_web_view_helper.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 dpi, print_params.desired_dpi); 297 dpi, print_params.desired_dpi);
298 298
299 webkit_print_params->paperSize.width = 299 webkit_print_params->paperSize.width =
300 ConvertUnit(print_params.page_size.width(), dpi, 300 ConvertUnit(print_params.page_size.width(), dpi,
301 print_params.desired_dpi); 301 print_params.desired_dpi);
302 webkit_print_params->paperSize.height = 302 webkit_print_params->paperSize.height =
303 ConvertUnit(print_params.page_size.height(), dpi, 303 ConvertUnit(print_params.page_size.height(), dpi,
304 print_params.desired_dpi); 304 print_params.desired_dpi);
305 } 305 }
306 306
307 WebKit::WebPlugin* GetPlugin(const WebKit::WebFrame* frame) {
308 return frame->document().isPluginDocument() ?
309 frame->document().to<WebKit::WebPluginDocument>().plugin() : NULL;
310 }
311
307 bool PrintingNodeOrPdfFrame(const WebKit::WebFrame* frame, 312 bool PrintingNodeOrPdfFrame(const WebKit::WebFrame* frame,
308 const WebKit::WebNode& node) { 313 const WebKit::WebNode& node) {
309 if (!node.isNull()) 314 if (!node.isNull())
310 return true; 315 return true;
311 if (!frame->document().isPluginDocument()) 316 WebKit::WebPlugin* plugin = GetPlugin(frame);
312 return false;
313 WebKit::WebPlugin* plugin =
314 frame->document().to<WebKit::WebPluginDocument>().plugin();
315 return plugin && plugin->supportsPaginatedPrint(); 317 return plugin && plugin->supportsPaginatedPrint();
316 } 318 }
317 319
318 bool PrintingFrameHasPageSizeStyle(WebKit::WebFrame* frame, 320 bool PrintingFrameHasPageSizeStyle(WebKit::WebFrame* frame,
319 int total_page_count) { 321 int total_page_count) {
320 if (!frame) 322 if (!frame)
321 return false; 323 return false;
322 bool frame_has_custom_page_size_style = false; 324 bool frame_has_custom_page_size_style = false;
323 for (int i = 0; i < total_page_count; ++i) { 325 for (int i = 0; i < total_page_count; ++i) {
324 if (frame->hasCustomPageSizeStyle(i)) { 326 if (frame->hasCustomPageSizeStyle(i)) {
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 content::RenderViewObserverTracker<PrintWebViewHelper>(render_view), 736 content::RenderViewObserverTracker<PrintWebViewHelper>(render_view),
735 reset_prep_frame_view_(false), 737 reset_prep_frame_view_(false),
736 is_preview_enabled_(IsPrintPreviewEnabled()), 738 is_preview_enabled_(IsPrintPreviewEnabled()),
737 is_scripted_print_throttling_disabled_(IsPrintThrottlingDisabled()), 739 is_scripted_print_throttling_disabled_(IsPrintThrottlingDisabled()),
738 is_print_ready_metafile_sent_(false), 740 is_print_ready_metafile_sent_(false),
739 ignore_css_margins_(false), 741 ignore_css_margins_(false),
740 user_cancelled_scripted_print_count_(0), 742 user_cancelled_scripted_print_count_(0),
741 is_scripted_printing_blocked_(false), 743 is_scripted_printing_blocked_(false),
742 notify_browser_of_print_failure_(true), 744 notify_browser_of_print_failure_(true),
743 print_for_preview_(false), 745 print_for_preview_(false),
744 print_node_in_progress_(false) { 746 print_node_in_progress_(false),
747 is_loading_(false),
748 is_scripted_preview_delayed_(false),
749 weak_ptr_factory_(this) {
745 } 750 }
746 751
747 PrintWebViewHelper::~PrintWebViewHelper() {} 752 PrintWebViewHelper::~PrintWebViewHelper() {}
748 753
749 bool PrintWebViewHelper::IsScriptInitiatedPrintAllowed( 754 bool PrintWebViewHelper::IsScriptInitiatedPrintAllowed(
750 WebKit::WebFrame* frame, bool user_initiated) { 755 WebKit::WebFrame* frame, bool user_initiated) {
751 if (is_scripted_printing_blocked_) 756 if (is_scripted_printing_blocked_)
752 return false; 757 return false;
753 // If preview is enabled, then the print dialog is tab modal, and the user 758 // If preview is enabled, then the print dialog is tab modal, and the user
754 // can always close the tab on a mis-behaving page (the system print dialog 759 // can always close the tab on a mis-behaving page (the system print dialog
755 // is app modal). If the print was initiated through user action, don't 760 // is app modal). If the print was initiated through user action, don't
756 // throttle. Or, if the command line flag to skip throttling has been set. 761 // throttle. Or, if the command line flag to skip throttling has been set.
757 if (!is_scripted_print_throttling_disabled_ && 762 if (!is_scripted_print_throttling_disabled_ &&
758 !is_preview_enabled_ && 763 !is_preview_enabled_ &&
759 !user_initiated) 764 !user_initiated)
760 return !IsScriptInitiatedPrintTooFrequent(frame); 765 return !IsScriptInitiatedPrintTooFrequent(frame);
761 return true; 766 return true;
762 } 767 }
763 768
769 void PrintWebViewHelper::DidStartLoading() {
770 is_loading_ = true;
771 }
772
773 void PrintWebViewHelper::DidStopLoading() {
774 is_loading_ = false;
775 ShowScriptedPrintPreview();
776 }
777
764 // Prints |frame| which called window.print(). 778 // Prints |frame| which called window.print().
765 void PrintWebViewHelper::PrintPage(WebKit::WebFrame* frame, 779 void PrintWebViewHelper::PrintPage(WebKit::WebFrame* frame,
766 bool user_initiated) { 780 bool user_initiated) {
767 DCHECK(frame); 781 DCHECK(frame);
768 782
769 // Allow Prerendering to cancel this print request if necessary. 783 // Allow Prerendering to cancel this print request if necessary.
770 if (prerender::PrerenderHelper::IsPrerendering(render_view())) { 784 if (prerender::PrerenderHelper::IsPrerendering(render_view())) {
771 Send(new ChromeViewHostMsg_CancelPrerenderForPrinting(routing_id())); 785 Send(new ChromeViewHostMsg_CancelPrerenderForPrinting(routing_id()));
772 return; 786 return;
773 } 787 }
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after
1651 void PrintWebViewHelper::ResetScriptedPrintCount() { 1665 void PrintWebViewHelper::ResetScriptedPrintCount() {
1652 // Reset cancel counter on successful print. 1666 // Reset cancel counter on successful print.
1653 user_cancelled_scripted_print_count_ = 0; 1667 user_cancelled_scripted_print_count_ = 0;
1654 } 1668 }
1655 1669
1656 void PrintWebViewHelper::IncrementScriptedPrintCount() { 1670 void PrintWebViewHelper::IncrementScriptedPrintCount() {
1657 ++user_cancelled_scripted_print_count_; 1671 ++user_cancelled_scripted_print_count_;
1658 last_cancelled_script_print_ = base::Time::Now(); 1672 last_cancelled_script_print_ = base::Time::Now();
1659 } 1673 }
1660 1674
1675
1676 void PrintWebViewHelper::ShowScriptedPrintPreview() {
1677 if (is_scripted_preview_delayed_) {
1678 is_scripted_preview_delayed_ = false;
1679 Send(new PrintHostMsg_ShowScriptedPrintPreview(routing_id(),
1680 print_preview_context_.IsModifiable()));
1681 }
1682 }
1683
1661 void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) { 1684 void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) {
1662 const bool is_modifiable = print_preview_context_.IsModifiable(); 1685 const bool is_modifiable = print_preview_context_.IsModifiable();
1663 const bool has_selection = print_preview_context_.HasSelection(); 1686 const bool has_selection = print_preview_context_.HasSelection();
1664 old_print_pages_params_.reset(); 1687 old_print_pages_params_.reset();
1665 PrintHostMsg_RequestPrintPreview_Params params; 1688 PrintHostMsg_RequestPrintPreview_Params params;
1666 params.is_modifiable = is_modifiable; 1689 params.is_modifiable = is_modifiable;
1667 params.has_selection = has_selection; 1690 params.has_selection = has_selection;
1668 switch (type) { 1691 switch (type) {
1669 case PRINT_PREVIEW_SCRIPTED: { 1692 case PRINT_PREVIEW_SCRIPTED: {
1693 // Shows scripted print preview in two stages.
1694 // 1. PrintHostMsg_SetupScriptedPrintPreview blocks this call and JS by
1695 // pumping messages here.
1696 // 2. PrintHostMsg_ShowScriptedPrintPreview shows preview once the
1697 // document has been loaded.
1698 is_scripted_preview_delayed_ = true;
1699 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) {
1700 // Wait for DidStopLoading. Plugins may not know the correct
1701 // |is_modifiable| value until they are fully loaded, which occurs when
1702 // DidStopLoading() is called. Defer showing the preview until then.
1703 } else {
1704 base::MessageLoop::current()->PostTask(
1705 FROM_HERE,
1706 base::Bind(&PrintWebViewHelper::ShowScriptedPrintPreview,
1707 weak_ptr_factory_.GetWeakPtr()));
1708 }
1670 IPC::SyncMessage* msg = 1709 IPC::SyncMessage* msg =
1671 new PrintHostMsg_ScriptedPrintPreview(routing_id(), is_modifiable); 1710 new PrintHostMsg_SetupScriptedPrintPreview(routing_id());
1672 msg->EnableMessagePumping(); 1711 msg->EnableMessagePumping();
1673 Send(msg); 1712 Send(msg);
1713 is_scripted_preview_delayed_ = false;
1674 return; 1714 return;
1675 } 1715 }
1676 case PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME: { 1716 case PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME: {
1677 break; 1717 break;
1678 } 1718 }
1679 case PRINT_PREVIEW_USER_INITIATED_SELECTION: { 1719 case PRINT_PREVIEW_USER_INITIATED_SELECTION: {
1680 DCHECK(has_selection); 1720 DCHECK(has_selection);
1681 params.selection_only = has_selection; 1721 params.selection_only = has_selection;
1682 break; 1722 break;
1683 } 1723 }
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1979 } 2019 }
1980 2020
1981 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { 2021 void PrintWebViewHelper::PrintPreviewContext::ClearContext() {
1982 prep_frame_view_.reset(); 2022 prep_frame_view_.reset();
1983 metafile_.reset(); 2023 metafile_.reset();
1984 pages_to_render_.clear(); 2024 pages_to_render_.clear();
1985 error_ = PREVIEW_ERROR_NONE; 2025 error_ = PREVIEW_ERROR_NONE;
1986 } 2026 }
1987 2027
1988 } // namespace printing 2028 } // namespace printing
OLDNEW
« no previous file with comments | « chrome/renderer/printing/print_web_view_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698