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()) |
| 824 on_stop_loading_closure_.Run(); | |
| 825 else | |
| 826 NOTREACHED(); | |
|
Vitaly Buka (NO REVIEWS)
2014/08/06 08:53:57
NOTREACHED is incorrect here. DidStopLoading is go
ivandavid
2014/08/06 19:00:17
Done.
| |
| 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 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1692 print_preview_context_.IsModifiable())); | 1695 print_preview_context_.IsModifiable())); |
| 1693 } | 1696 } |
| 1694 } | 1697 } |
| 1695 | 1698 |
| 1696 void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) { | 1699 void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) { |
| 1697 const bool is_modifiable = print_preview_context_.IsModifiable(); | 1700 const bool is_modifiable = print_preview_context_.IsModifiable(); |
| 1698 const bool has_selection = print_preview_context_.HasSelection(); | 1701 const bool has_selection = print_preview_context_.HasSelection(); |
| 1699 PrintHostMsg_RequestPrintPreview_Params params; | 1702 PrintHostMsg_RequestPrintPreview_Params params; |
| 1700 params.is_modifiable = is_modifiable; | 1703 params.is_modifiable = is_modifiable; |
| 1701 params.has_selection = has_selection; | 1704 params.has_selection = has_selection; |
| 1705 on_stop_loading_closure_ = | |
|
Vitaly Buka (NO REVIEWS)
2014/08/06 08:53:57
this piece should be on line 1718
ivandavid
2014/08/06 19:00:17
Ok. I put it after the comment.
ivandavid
2014/08/06 19:00:17
Done.
| |
| 1706 base::Bind(&PrintWebViewHelper::ShowScriptedPrintPreview, | |
| 1707 base::Unretained(this)); | |
| 1708 | |
| 1702 switch (type) { | 1709 switch (type) { |
| 1703 case PRINT_PREVIEW_SCRIPTED: { | 1710 case PRINT_PREVIEW_SCRIPTED: { |
| 1704 // Shows scripted print preview in two stages. | 1711 // Shows scripted print preview in two stages. |
| 1705 // 1. PrintHostMsg_SetupScriptedPrintPreview blocks this call and JS by | 1712 // 1. PrintHostMsg_SetupScriptedPrintPreview blocks this call and JS by |
| 1706 // pumping messages here. | 1713 // pumping messages here. |
| 1707 // 2. PrintHostMsg_ShowScriptedPrintPreview shows preview once the | 1714 // 2. PrintHostMsg_ShowScriptedPrintPreview shows preview once the |
| 1708 // document has been loaded. | 1715 // document has been loaded. |
| 1709 is_scripted_preview_delayed_ = true; | 1716 is_scripted_preview_delayed_ = true; |
| 1710 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) { | 1717 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) { |
| 1711 // Wait for DidStopLoading. Plugins may not know the correct | 1718 // Wait for DidStopLoading. Plugins may not know the correct |
| 1712 // |is_modifiable| value until they are fully loaded, which occurs when | 1719 // |is_modifiable| value until they are fully loaded, which occurs when |
| 1713 // DidStopLoading() is called. Defer showing the preview until then. | 1720 // DidStopLoading() is called. Defer showing the preview until then. |
| 1714 } else { | 1721 } else { |
| 1715 base::MessageLoop::current()->PostTask( | 1722 base::MessageLoop::current()->PostTask( |
| 1716 FROM_HERE, | 1723 FROM_HERE, |
| 1717 base::Bind(&PrintWebViewHelper::ShowScriptedPrintPreview, | 1724 base::Bind(&PrintWebViewHelper::ShowScriptedPrintPreview, |
| 1718 weak_ptr_factory_.GetWeakPtr())); | 1725 weak_ptr_factory_.GetWeakPtr())); |
| 1719 } | 1726 } |
| 1720 IPC::SyncMessage* msg = | 1727 IPC::SyncMessage* msg = |
| 1721 new PrintHostMsg_SetupScriptedPrintPreview(routing_id()); | 1728 new PrintHostMsg_SetupScriptedPrintPreview(routing_id()); |
| 1722 msg->EnableMessagePumping(); | 1729 msg->EnableMessagePumping(); |
| 1723 Send(msg); | 1730 Send(msg); |
| 1724 is_scripted_preview_delayed_ = false; | 1731 is_scripted_preview_delayed_ = false; |
| 1725 return; | 1732 return; |
| 1726 } | 1733 } |
| 1727 case PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME: { | 1734 case PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME: { |
| 1735 // Wait for DidStopLoading. Continuing with this function while | |
| 1736 // |is_loading_| is true will cause print preview to hang when try to | |
| 1737 // print a PDF document. | |
| 1738 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) { | |
|
Vitaly Buka (NO REVIEWS)
2014/08/06 08:53:57
Same is needed for PRINT_PREVIEW_USER_INITIATED_CO
ivandavid
2014/08/06 19:00:16
Done.
ivandavid
2014/08/06 19:00:16
Is it supposed to bind RequestPrintPreview() or Sh
Vitaly Buka (NO REVIEWS)
2014/08/06 21:00:36
Yes, it should be RequestPrintPreview. Bind of Req
| |
| 1739 on_stop_loading_closure_ = | |
| 1740 base::Bind(&PrintWebViewHelper::RequestPrintPreview, | |
| 1741 base::Unretained(this), | |
| 1742 type); | |
| 1743 return; | |
| 1744 } | |
| 1745 | |
| 1728 break; | 1746 break; |
| 1729 } | 1747 } |
| 1730 case PRINT_PREVIEW_USER_INITIATED_SELECTION: { | 1748 case PRINT_PREVIEW_USER_INITIATED_SELECTION: { |
| 1731 DCHECK(has_selection); | 1749 DCHECK(has_selection); |
| 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: { |
| 1736 params.webnode_only = true; | 1754 params.webnode_only = true; |
| 1737 break; | 1755 break; |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2031 } | 2049 } |
| 2032 | 2050 |
| 2033 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { | 2051 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { |
| 2034 prep_frame_view_.reset(); | 2052 prep_frame_view_.reset(); |
| 2035 metafile_.reset(); | 2053 metafile_.reset(); |
| 2036 pages_to_render_.clear(); | 2054 pages_to_render_.clear(); |
| 2037 error_ = PREVIEW_ERROR_NONE; | 2055 error_ = PREVIEW_ERROR_NONE; |
| 2038 } | 2056 } |
| 2039 | 2057 |
| 2040 } // namespace printing | 2058 } // namespace printing |
| OLD | NEW |