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

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: 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
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) {
745 } 749 }
746 750
747 PrintWebViewHelper::~PrintWebViewHelper() {} 751 PrintWebViewHelper::~PrintWebViewHelper() {}
748 752
749 bool PrintWebViewHelper::IsScriptInitiatedPrintAllowed( 753 bool PrintWebViewHelper::IsScriptInitiatedPrintAllowed(
750 WebKit::WebFrame* frame, bool user_initiated) { 754 WebKit::WebFrame* frame, bool user_initiated) {
751 if (is_scripted_printing_blocked_) 755 if (is_scripted_printing_blocked_)
752 return false; 756 return false;
753 // If preview is enabled, then the print dialog is tab modal, and the user 757 // 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 758 // 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 759 // 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. 760 // throttle. Or, if the command line flag to skip throttling has been set.
757 if (!is_scripted_print_throttling_disabled_ && 761 if (!is_scripted_print_throttling_disabled_ &&
758 !is_preview_enabled_ && 762 !is_preview_enabled_ &&
759 !user_initiated) 763 !user_initiated)
760 return !IsScriptInitiatedPrintTooFrequent(frame); 764 return !IsScriptInitiatedPrintTooFrequent(frame);
761 return true; 765 return true;
762 } 766 }
763 767
768 void PrintWebViewHelper::DidStartLoading() {
769 is_loading_ = true;
770 }
771
772 void PrintWebViewHelper::DidStopLoading() {
773 is_loading_ = false;
774 ShowScriptedPrintPreview();
775 }
776
764 // Prints |frame| which called window.print(). 777 // Prints |frame| which called window.print().
765 void PrintWebViewHelper::PrintPage(WebKit::WebFrame* frame, 778 void PrintWebViewHelper::PrintPage(WebKit::WebFrame* frame,
766 bool user_initiated) { 779 bool user_initiated) {
767 DCHECK(frame); 780 DCHECK(frame);
768 781
769 // Allow Prerendering to cancel this print request if necessary. 782 // Allow Prerendering to cancel this print request if necessary.
770 if (prerender::PrerenderHelper::IsPrerendering(render_view())) { 783 if (prerender::PrerenderHelper::IsPrerendering(render_view())) {
771 Send(new ChromeViewHostMsg_CancelPrerenderForPrinting(routing_id())); 784 Send(new ChromeViewHostMsg_CancelPrerenderForPrinting(routing_id()));
772 return; 785 return;
773 } 786 }
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after
1651 void PrintWebViewHelper::ResetScriptedPrintCount() { 1664 void PrintWebViewHelper::ResetScriptedPrintCount() {
1652 // Reset cancel counter on successful print. 1665 // Reset cancel counter on successful print.
1653 user_cancelled_scripted_print_count_ = 0; 1666 user_cancelled_scripted_print_count_ = 0;
1654 } 1667 }
1655 1668
1656 void PrintWebViewHelper::IncrementScriptedPrintCount() { 1669 void PrintWebViewHelper::IncrementScriptedPrintCount() {
1657 ++user_cancelled_scripted_print_count_; 1670 ++user_cancelled_scripted_print_count_;
1658 last_cancelled_script_print_ = base::Time::Now(); 1671 last_cancelled_script_print_ = base::Time::Now();
1659 } 1672 }
1660 1673
1674
1675 void PrintWebViewHelper::ShowScriptedPrintPreview() {
1676 if (is_scripted_preview_delayed_) {
1677 is_scripted_preview_delayed_ = false;
1678 Send(new PrintHostMsg_ShowScriptedPrintPreview(routing_id(),
1679 print_preview_context_.IsModifiable()));
1680 }
1681 }
1682
1661 void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) { 1683 void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) {
1662 const bool is_modifiable = print_preview_context_.IsModifiable(); 1684 const bool is_modifiable = print_preview_context_.IsModifiable();
1663 const bool has_selection = print_preview_context_.HasSelection(); 1685 const bool has_selection = print_preview_context_.HasSelection();
1664 old_print_pages_params_.reset(); 1686 old_print_pages_params_.reset();
1665 PrintHostMsg_RequestPrintPreview_Params params; 1687 PrintHostMsg_RequestPrintPreview_Params params;
1666 params.is_modifiable = is_modifiable; 1688 params.is_modifiable = is_modifiable;
1667 params.has_selection = has_selection; 1689 params.has_selection = has_selection;
1668 switch (type) { 1690 switch (type) {
1669 case PRINT_PREVIEW_SCRIPTED: { 1691 case PRINT_PREVIEW_SCRIPTED: {
1692 // Shows scripted print preview in two stages.
1693 // 1. PrintHostMsg_SetupScriptedPrintPreview blocks this call and JS by
1694 // pumping messages here.
1695 // 2. PrintHostMsg_ShowScriptedPrintPreview shows preview
1696 // if is_modifiable is available.
1697 is_scripted_preview_delayed_ = true;
1698 base::Closure task =
1699 base::Bind(&PrintWebViewHelper::ShowScriptedPrintPreview,
1700 AsWeakPtr());
1701 if (is_modifiable && is_loading_ &&
1702 GetPlugin(print_preview_context_.source_frame())) {
1703 // Plugins may change is_modifiable from True to False after loading
1704 // data. It may happen in DidStopLoading handler.
1705 // If DidStopLoading was not called in 1min we will use whatever we
1706 // have.
1707 base::MessageLoop::current()->PostDelayedTask(
Lei Zhang 2013/09/03 20:07:26 I don't think it's worth handling this case. If th
Vitaly Buka (NO REVIEWS) 2013/09/04 00:22:39 Done.
1708 FROM_HERE, task, base::TimeDelta::FromMinutes(1));
1709 } else {
1710 base::MessageLoop::current()->PostTask(FROM_HERE, task);
1711 }
1670 IPC::SyncMessage* msg = 1712 IPC::SyncMessage* msg =
1671 new PrintHostMsg_ScriptedPrintPreview(routing_id(), is_modifiable); 1713 new PrintHostMsg_SetupScriptedPrintPreview(routing_id());
1672 msg->EnableMessagePumping(); 1714 msg->EnableMessagePumping();
1673 Send(msg); 1715 Send(msg);
1716 is_scripted_preview_delayed_ = false;
1674 return; 1717 return;
1675 } 1718 }
1676 case PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME: { 1719 case PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME: {
1677 break; 1720 break;
1678 } 1721 }
1679 case PRINT_PREVIEW_USER_INITIATED_SELECTION: { 1722 case PRINT_PREVIEW_USER_INITIATED_SELECTION: {
1680 DCHECK(has_selection); 1723 DCHECK(has_selection);
1681 params.selection_only = has_selection; 1724 params.selection_only = has_selection;
1682 break; 1725 break;
1683 } 1726 }
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1979 } 2022 }
1980 2023
1981 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { 2024 void PrintWebViewHelper::PrintPreviewContext::ClearContext() {
1982 prep_frame_view_.reset(); 2025 prep_frame_view_.reset();
1983 metafile_.reset(); 2026 metafile_.reset();
1984 pages_to_render_.clear(); 2027 pages_to_render_.clear();
1985 error_ = PREVIEW_ERROR_NONE; 2028 error_ = PREVIEW_ERROR_NONE;
1986 } 2029 }
1987 2030
1988 } // namespace printing 2031 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698