Chromium Code Reviews| 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()) |
|
Vitaly Buka (NO REVIEWS)
2014/08/14 05:19:43
on_stop_loading_closure_.reset() after run
ivandavid
2014/08/15 00:35:23
Done.
| |
| 824 on_stop_loading_closure_.Run(); | |
| 824 } | 825 } |
| 825 | 826 |
| 826 // Prints |frame| which called window.print(). | 827 // Prints |frame| which called window.print(). |
| 827 void PrintWebViewHelper::PrintPage(blink::WebLocalFrame* frame, | 828 void PrintWebViewHelper::PrintPage(blink::WebLocalFrame* frame, |
| 828 bool user_initiated) { | 829 bool user_initiated) { |
| 829 DCHECK(frame); | 830 DCHECK(frame); |
| 830 | 831 |
| 831 // Allow Prerendering to cancel this print request if necessary. | 832 // Allow Prerendering to cancel this print request if necessary. |
| 832 if (prerender::PrerenderHelper::IsPrerendering( | 833 if (prerender::PrerenderHelper::IsPrerendering( |
| 833 render_view()->GetMainRenderFrame())) { | 834 render_view()->GetMainRenderFrame())) { |
| (...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1692 print_preview_context_.IsModifiable())); | 1693 print_preview_context_.IsModifiable())); |
| 1693 } | 1694 } |
| 1694 } | 1695 } |
| 1695 | 1696 |
| 1696 void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) { | 1697 void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) { |
| 1697 const bool is_modifiable = print_preview_context_.IsModifiable(); | 1698 const bool is_modifiable = print_preview_context_.IsModifiable(); |
| 1698 const bool has_selection = print_preview_context_.HasSelection(); | 1699 const bool has_selection = print_preview_context_.HasSelection(); |
| 1699 PrintHostMsg_RequestPrintPreview_Params params; | 1700 PrintHostMsg_RequestPrintPreview_Params params; |
| 1700 params.is_modifiable = is_modifiable; | 1701 params.is_modifiable = is_modifiable; |
| 1701 params.has_selection = has_selection; | 1702 params.has_selection = has_selection; |
| 1703 DCHECK(!GetPlugin(print_preview_context_.source_frame())); | |
|
Vitaly Buka (NO REVIEWS)
2014/08/14 05:19:43
this DCHECK makes no sense
if it was correct, all
ivandavid
2014/08/15 00:35:23
Done.
| |
| 1702 switch (type) { | 1704 switch (type) { |
| 1703 case PRINT_PREVIEW_SCRIPTED: { | 1705 case PRINT_PREVIEW_SCRIPTED: { |
| 1704 // Shows scripted print preview in two stages. | 1706 // Shows scripted print preview in two stages. |
| 1705 // 1. PrintHostMsg_SetupScriptedPrintPreview blocks this call and JS by | 1707 // 1. PrintHostMsg_SetupScriptedPrintPreview blocks this call and JS by |
| 1706 // pumping messages here. | 1708 // pumping messages here. |
| 1707 // 2. PrintHostMsg_ShowScriptedPrintPreview shows preview once the | 1709 // 2. PrintHostMsg_ShowScriptedPrintPreview shows preview once the |
| 1708 // document has been loaded. | 1710 // document has been loaded. |
| 1709 is_scripted_preview_delayed_ = true; | 1711 is_scripted_preview_delayed_ = true; |
| 1710 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) { | 1712 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) { |
| 1711 // Wait for DidStopLoading. Plugins may not know the correct | 1713 // Wait for DidStopLoading. Plugins may not know the correct |
| 1712 // |is_modifiable| value until they are fully loaded, which occurs when | 1714 // |is_modifiable| value until they are fully loaded, which occurs when |
| 1713 // DidStopLoading() is called. Defer showing the preview until then. | 1715 // DidStopLoading() is called. Defer showing the preview until then. |
| 1716 on_stop_loading_closure_ = | |
| 1717 base::Bind(&PrintWebViewHelper::ShowScriptedPrintPreview, | |
| 1718 base::Unretained(this)); | |
| 1714 } else { | 1719 } else { |
| 1715 base::MessageLoop::current()->PostTask( | 1720 base::MessageLoop::current()->PostTask( |
| 1716 FROM_HERE, | 1721 FROM_HERE, |
| 1717 base::Bind(&PrintWebViewHelper::ShowScriptedPrintPreview, | 1722 base::Bind(&PrintWebViewHelper::ShowScriptedPrintPreview, |
| 1718 weak_ptr_factory_.GetWeakPtr())); | 1723 weak_ptr_factory_.GetWeakPtr())); |
| 1719 } | 1724 } |
| 1720 IPC::SyncMessage* msg = | 1725 IPC::SyncMessage* msg = |
| 1721 new PrintHostMsg_SetupScriptedPrintPreview(routing_id()); | 1726 new PrintHostMsg_SetupScriptedPrintPreview(routing_id()); |
| 1722 msg->EnableMessagePumping(); | 1727 msg->EnableMessagePumping(); |
| 1723 Send(msg); | 1728 Send(msg); |
| 1724 is_scripted_preview_delayed_ = false; | 1729 is_scripted_preview_delayed_ = false; |
| 1725 return; | 1730 return; |
| 1726 } | 1731 } |
| 1727 case PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME: { | 1732 case PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME: { |
| 1733 // Wait for DidStopLoading. Continuing with this function while | |
| 1734 // |is_loading_| is true will cause print preview to hang when try to | |
| 1735 // print a PDF document. | |
| 1736 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) { | |
| 1737 on_stop_loading_closure_ = | |
| 1738 base::Bind(&PrintWebViewHelper::RequestPrintPreview, | |
| 1739 base::Unretained(this), | |
| 1740 type); | |
| 1741 return; | |
| 1742 } | |
| 1743 | |
| 1728 break; | 1744 break; |
| 1729 } | 1745 } |
| 1730 case PRINT_PREVIEW_USER_INITIATED_SELECTION: { | 1746 case PRINT_PREVIEW_USER_INITIATED_SELECTION: { |
| 1731 DCHECK(has_selection); | 1747 DCHECK(has_selection); |
| 1732 params.selection_only = has_selection; | 1748 params.selection_only = has_selection; |
| 1733 break; | 1749 break; |
| 1734 } | 1750 } |
| 1735 case PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE: { | 1751 case PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE: { |
| 1752 // Same situation as in PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME. | |
| 1753 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) { | |
| 1754 on_stop_loading_closure_ = | |
| 1755 base::Bind(&PrintWebViewHelper::RequestPrintPreview, | |
| 1756 base::Unretained(this), | |
| 1757 type); | |
| 1758 return; | |
| 1759 } | |
| 1760 | |
| 1736 params.webnode_only = true; | 1761 params.webnode_only = true; |
| 1737 break; | 1762 break; |
| 1738 } | 1763 } |
| 1739 default: { | 1764 default: { |
| 1740 NOTREACHED(); | 1765 NOTREACHED(); |
| 1741 return; | 1766 return; |
| 1742 } | 1767 } |
| 1743 } | 1768 } |
| 1744 Send(new PrintHostMsg_RequestPrintPreview(routing_id(), params)); | 1769 Send(new PrintHostMsg_RequestPrintPreview(routing_id(), params)); |
| 1745 } | 1770 } |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2031 } | 2056 } |
| 2032 | 2057 |
| 2033 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { | 2058 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { |
| 2034 prep_frame_view_.reset(); | 2059 prep_frame_view_.reset(); |
| 2035 metafile_.reset(); | 2060 metafile_.reset(); |
| 2036 pages_to_render_.clear(); | 2061 pages_to_render_.clear(); |
| 2037 error_ = PREVIEW_ERROR_NONE; | 2062 error_ = PREVIEW_ERROR_NONE; |
| 2038 } | 2063 } |
| 2039 | 2064 |
| 2040 } // namespace printing | 2065 } // namespace printing |
| OLD | NEW |