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

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

Issue 463123004: Revert of r287982 Fix for race condition... (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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
« 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 802 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 if (!on_stop_loading_closure_.is_null()) 823 ShowScriptedPrintPreview();
824 on_stop_loading_closure_.Run();
825 } 824 }
826 825
827 // Prints |frame| which called window.print(). 826 // Prints |frame| which called window.print().
828 void PrintWebViewHelper::PrintPage(blink::WebLocalFrame* frame, 827 void PrintWebViewHelper::PrintPage(blink::WebLocalFrame* frame,
829 bool user_initiated) { 828 bool user_initiated) {
830 DCHECK(frame); 829 DCHECK(frame);
831 830
832 // Allow Prerendering to cancel this print request if necessary. 831 // Allow Prerendering to cancel this print request if necessary.
833 if (prerender::PrerenderHelper::IsPrerendering( 832 if (prerender::PrerenderHelper::IsPrerendering(
834 render_view()->GetMainRenderFrame())) { 833 render_view()->GetMainRenderFrame())) {
(...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after
1705 // Shows scripted print preview in two stages. 1704 // Shows scripted print preview in two stages.
1706 // 1. PrintHostMsg_SetupScriptedPrintPreview blocks this call and JS by 1705 // 1. PrintHostMsg_SetupScriptedPrintPreview blocks this call and JS by
1707 // pumping messages here. 1706 // pumping messages here.
1708 // 2. PrintHostMsg_ShowScriptedPrintPreview shows preview once the 1707 // 2. PrintHostMsg_ShowScriptedPrintPreview shows preview once the
1709 // document has been loaded. 1708 // document has been loaded.
1710 is_scripted_preview_delayed_ = true; 1709 is_scripted_preview_delayed_ = true;
1711 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) { 1710 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) {
1712 // Wait for DidStopLoading. Plugins may not know the correct 1711 // Wait for DidStopLoading. Plugins may not know the correct
1713 // |is_modifiable| value until they are fully loaded, which occurs when 1712 // |is_modifiable| value until they are fully loaded, which occurs when
1714 // DidStopLoading() is called. Defer showing the preview until then. 1713 // DidStopLoading() is called. Defer showing the preview until then.
1715 on_stop_loading_closure_ =
1716 base::Bind(&PrintWebViewHelper::ShowScriptedPrintPreview,
Vitaly Buka (NO REVIEWS) 2014/08/12 19:10:26 probably issue is some how related to these lines
1717 base::Unretained(this));
1718 } else { 1714 } else {
1719 base::MessageLoop::current()->PostTask( 1715 base::MessageLoop::current()->PostTask(
1720 FROM_HERE, 1716 FROM_HERE,
1721 base::Bind(&PrintWebViewHelper::ShowScriptedPrintPreview, 1717 base::Bind(&PrintWebViewHelper::ShowScriptedPrintPreview,
1722 weak_ptr_factory_.GetWeakPtr())); 1718 weak_ptr_factory_.GetWeakPtr()));
1723 } 1719 }
1724 IPC::SyncMessage* msg = 1720 IPC::SyncMessage* msg =
1725 new PrintHostMsg_SetupScriptedPrintPreview(routing_id()); 1721 new PrintHostMsg_SetupScriptedPrintPreview(routing_id());
1726 msg->EnableMessagePumping(); 1722 msg->EnableMessagePumping();
1727 Send(msg); 1723 Send(msg);
1728 is_scripted_preview_delayed_ = false; 1724 is_scripted_preview_delayed_ = false;
1729 return; 1725 return;
1730 } 1726 }
1731 case PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME: { 1727 case PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME: {
1732 // Wait for DidStopLoading. Continuing with this function while
1733 // |is_loading_| is true will cause print preview to hang when try to
1734 // print a PDF document.
1735 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) {
1736 on_stop_loading_closure_ =
1737 base::Bind(&PrintWebViewHelper::RequestPrintPreview,
1738 base::Unretained(this),
1739 type);
1740 return;
1741 }
1742
1743 break; 1728 break;
1744 } 1729 }
1745 case PRINT_PREVIEW_USER_INITIATED_SELECTION: { 1730 case PRINT_PREVIEW_USER_INITIATED_SELECTION: {
1746 DCHECK(has_selection); 1731 DCHECK(has_selection);
1747 params.selection_only = has_selection; 1732 params.selection_only = has_selection;
1748 break; 1733 break;
1749 } 1734 }
1750 case PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE: { 1735 case PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE: {
1751 // Same situation as in PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME.
1752 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) {
1753 on_stop_loading_closure_ =
1754 base::Bind(&PrintWebViewHelper::RequestPrintPreview,
1755 base::Unretained(this),
1756 type);
1757 return;
1758 }
1759
1760 params.webnode_only = true; 1736 params.webnode_only = true;
1761 break; 1737 break;
1762 } 1738 }
1763 default: { 1739 default: {
1764 NOTREACHED(); 1740 NOTREACHED();
1765 return; 1741 return;
1766 } 1742 }
1767 } 1743 }
1768 Send(new PrintHostMsg_RequestPrintPreview(routing_id(), params)); 1744 Send(new PrintHostMsg_RequestPrintPreview(routing_id(), params));
1769 } 1745 }
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
2055 } 2031 }
2056 2032
2057 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { 2033 void PrintWebViewHelper::PrintPreviewContext::ClearContext() {
2058 prep_frame_view_.reset(); 2034 prep_frame_view_.reset();
2059 metafile_.reset(); 2035 metafile_.reset();
2060 pages_to_render_.clear(); 2036 pages_to_render_.clear();
2061 error_ = PREVIEW_ERROR_NONE; 2037 error_ = PREVIEW_ERROR_NONE;
2062 } 2038 }
2063 2039
2064 } // namespace printing 2040 } // 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