OLD | NEW |
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 802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 return !IsScriptInitiatedPrintTooFrequent(frame); | 813 return !IsScriptInitiatedPrintTooFrequent(frame); |
814 return true; | 814 return true; |
815 } | 815 } |
816 | 816 |
817 void PrintWebViewHelper::DidStartLoading() { | 817 void PrintWebViewHelper::DidStartLoading() { |
818 is_loading_ = true; | 818 is_loading_ = true; |
819 } | 819 } |
820 | 820 |
821 void PrintWebViewHelper::DidStopLoading() { | 821 void PrintWebViewHelper::DidStopLoading() { |
822 is_loading_ = false; | 822 is_loading_ = false; |
823 ShowScriptedPrintPreview(); | 823 if (!on_stop_loading_closure_.is_null()) { |
| 824 on_stop_loading_closure_.Run(); |
| 825 on_stop_loading_closure_.Reset(); |
| 826 } |
824 } | 827 } |
825 | 828 |
826 // Prints |frame| which called window.print(). | 829 // Prints |frame| which called window.print(). |
827 void PrintWebViewHelper::PrintPage(blink::WebLocalFrame* frame, | 830 void PrintWebViewHelper::PrintPage(blink::WebLocalFrame* frame, |
828 bool user_initiated) { | 831 bool user_initiated) { |
829 DCHECK(frame); | 832 DCHECK(frame); |
830 | 833 |
831 // Allow Prerendering to cancel this print request if necessary. | 834 // Allow Prerendering to cancel this print request if necessary. |
832 if (prerender::PrerenderHelper::IsPrerendering( | 835 if (prerender::PrerenderHelper::IsPrerendering( |
833 render_view()->GetMainRenderFrame())) { | 836 render_view()->GetMainRenderFrame())) { |
(...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1704 // Shows scripted print preview in two stages. | 1707 // Shows scripted print preview in two stages. |
1705 // 1. PrintHostMsg_SetupScriptedPrintPreview blocks this call and JS by | 1708 // 1. PrintHostMsg_SetupScriptedPrintPreview blocks this call and JS by |
1706 // pumping messages here. | 1709 // pumping messages here. |
1707 // 2. PrintHostMsg_ShowScriptedPrintPreview shows preview once the | 1710 // 2. PrintHostMsg_ShowScriptedPrintPreview shows preview once the |
1708 // document has been loaded. | 1711 // document has been loaded. |
1709 is_scripted_preview_delayed_ = true; | 1712 is_scripted_preview_delayed_ = true; |
1710 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) { | 1713 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) { |
1711 // Wait for DidStopLoading. Plugins may not know the correct | 1714 // Wait for DidStopLoading. Plugins may not know the correct |
1712 // |is_modifiable| value until they are fully loaded, which occurs when | 1715 // |is_modifiable| value until they are fully loaded, which occurs when |
1713 // DidStopLoading() is called. Defer showing the preview until then. | 1716 // DidStopLoading() is called. Defer showing the preview until then. |
| 1717 on_stop_loading_closure_ = |
| 1718 base::Bind(&PrintWebViewHelper::ShowScriptedPrintPreview, |
| 1719 base::Unretained(this)); |
1714 } else { | 1720 } else { |
1715 base::MessageLoop::current()->PostTask( | 1721 base::MessageLoop::current()->PostTask( |
1716 FROM_HERE, | 1722 FROM_HERE, |
1717 base::Bind(&PrintWebViewHelper::ShowScriptedPrintPreview, | 1723 base::Bind(&PrintWebViewHelper::ShowScriptedPrintPreview, |
1718 weak_ptr_factory_.GetWeakPtr())); | 1724 weak_ptr_factory_.GetWeakPtr())); |
1719 } | 1725 } |
1720 IPC::SyncMessage* msg = | 1726 IPC::SyncMessage* msg = |
1721 new PrintHostMsg_SetupScriptedPrintPreview(routing_id()); | 1727 new PrintHostMsg_SetupScriptedPrintPreview(routing_id()); |
1722 msg->EnableMessagePumping(); | 1728 msg->EnableMessagePumping(); |
1723 Send(msg); | 1729 Send(msg); |
1724 is_scripted_preview_delayed_ = false; | 1730 is_scripted_preview_delayed_ = false; |
1725 return; | 1731 return; |
1726 } | 1732 } |
1727 case PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME: { | 1733 case PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME: { |
| 1734 // Wait for DidStopLoading. Continuing with this function while |
| 1735 // |is_loading_| is true will cause print preview to hang when try to |
| 1736 // print a PDF document. |
| 1737 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) { |
| 1738 on_stop_loading_closure_ = |
| 1739 base::Bind(&PrintWebViewHelper::RequestPrintPreview, |
| 1740 base::Unretained(this), |
| 1741 type); |
| 1742 return; |
| 1743 } |
| 1744 |
1728 break; | 1745 break; |
1729 } | 1746 } |
1730 case PRINT_PREVIEW_USER_INITIATED_SELECTION: { | 1747 case PRINT_PREVIEW_USER_INITIATED_SELECTION: { |
1731 DCHECK(has_selection); | 1748 DCHECK(has_selection); |
| 1749 DCHECK(!GetPlugin(print_preview_context_.source_frame())); |
1732 params.selection_only = has_selection; | 1750 params.selection_only = has_selection; |
1733 break; | 1751 break; |
1734 } | 1752 } |
1735 case PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE: { | 1753 case PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE: { |
| 1754 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) { |
| 1755 on_stop_loading_closure_ = |
| 1756 base::Bind(&PrintWebViewHelper::RequestPrintPreview, |
| 1757 base::Unretained(this), |
| 1758 type); |
| 1759 return; |
| 1760 } |
| 1761 |
1736 params.webnode_only = true; | 1762 params.webnode_only = true; |
1737 break; | 1763 break; |
1738 } | 1764 } |
1739 default: { | 1765 default: { |
1740 NOTREACHED(); | 1766 NOTREACHED(); |
1741 return; | 1767 return; |
1742 } | 1768 } |
1743 } | 1769 } |
1744 Send(new PrintHostMsg_RequestPrintPreview(routing_id(), params)); | 1770 Send(new PrintHostMsg_RequestPrintPreview(routing_id(), params)); |
1745 } | 1771 } |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2031 } | 2057 } |
2032 | 2058 |
2033 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { | 2059 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { |
2034 prep_frame_view_.reset(); | 2060 prep_frame_view_.reset(); |
2035 metafile_.reset(); | 2061 metafile_.reset(); |
2036 pages_to_render_.clear(); | 2062 pages_to_render_.clear(); |
2037 error_ = PREVIEW_ERROR_NONE; | 2063 error_ = PREVIEW_ERROR_NONE; |
2038 } | 2064 } |
2039 | 2065 |
2040 } // namespace printing | 2066 } // namespace printing |
OLD | NEW |