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

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

Issue 467343003: Defer request to print a PDF when the user initiates the entire frame and the PDF hasn't loaded. (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
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 773 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 is_scripted_print_throttling_disabled_(IsPrintThrottlingDisabled()), 784 is_scripted_print_throttling_disabled_(IsPrintThrottlingDisabled()),
785 is_print_ready_metafile_sent_(false), 785 is_print_ready_metafile_sent_(false),
786 ignore_css_margins_(false), 786 ignore_css_margins_(false),
787 user_cancelled_scripted_print_count_(0), 787 user_cancelled_scripted_print_count_(0),
788 is_scripted_printing_blocked_(false), 788 is_scripted_printing_blocked_(false),
789 notify_browser_of_print_failure_(true), 789 notify_browser_of_print_failure_(true),
790 print_for_preview_(false), 790 print_for_preview_(false),
791 print_node_in_progress_(false), 791 print_node_in_progress_(false),
792 is_loading_(false), 792 is_loading_(false),
793 is_scripted_preview_delayed_(false), 793 is_scripted_preview_delayed_(false),
794 weak_ptr_factory_(this) { 794 weak_ptr_factory_(this),
795 on_stop_loading_type_(PRINT_PREVIEW_SCRIPTED) {
795 } 796 }
796 797
797 PrintWebViewHelper::~PrintWebViewHelper() {} 798 PrintWebViewHelper::~PrintWebViewHelper() {}
798 799
799 bool PrintWebViewHelper::IsScriptInitiatedPrintAllowed( 800 bool PrintWebViewHelper::IsScriptInitiatedPrintAllowed(
800 blink::WebFrame* frame, bool user_initiated) { 801 blink::WebFrame* frame, bool user_initiated) {
801 #if defined(OS_ANDROID) 802 #if defined(OS_ANDROID)
802 return false; 803 return false;
803 #endif // defined(OS_ANDROID) 804 #endif // defined(OS_ANDROID)
804 if (is_scripted_printing_blocked_) 805 if (is_scripted_printing_blocked_)
805 return false; 806 return false;
806 // If preview is enabled, then the print dialog is tab modal, and the user 807 // If preview is enabled, then the print dialog is tab modal, and the user
807 // can always close the tab on a mis-behaving page (the system print dialog 808 // can always close the tab on a mis-behaving page (the system print dialog
808 // is app modal). If the print was initiated through user action, don't 809 // is app modal). If the print was initiated through user action, don't
809 // throttle. Or, if the command line flag to skip throttling has been set. 810 // throttle. Or, if the command line flag to skip throttling has been set.
810 if (!is_scripted_print_throttling_disabled_ && 811 if (!is_scripted_print_throttling_disabled_ &&
811 !is_preview_enabled_ && 812 !is_preview_enabled_ &&
812 !user_initiated) 813 !user_initiated)
813 return !IsScriptInitiatedPrintTooFrequent(frame); 814 return !IsScriptInitiatedPrintTooFrequent(frame);
814 return true; 815 return true;
815 } 816 }
816 817
817 void PrintWebViewHelper::DidStartLoading() { 818 void PrintWebViewHelper::DidStartLoading() {
818 is_loading_ = true; 819 is_loading_ = true;
819 } 820 }
820 821
821 void PrintWebViewHelper::DidStopLoading() { 822 void PrintWebViewHelper::DidStopLoading() {
822 is_loading_ = false; 823 is_loading_ = false;
823 ShowScriptedPrintPreview(); 824
825 // |on_stop_loading_type_| should be reset to the default value
826 // PRINT_PREVIEW_SCRIPTED after is its equal to
827 // PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME because the race condition has
828 // been handled.
829 if (on_stop_loading_type_ == PRINT_PREVIEW_SCRIPTED) {
830 ShowScriptedPrintPreview();
831 } else if (on_stop_loading_type_ ==
832 PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME) {
833 RequestPrintPreview(on_stop_loading_type_);
834 on_stop_loading_type_ = PRINT_PREVIEW_SCRIPTED;
835 }
824 } 836 }
825 837
826 // Prints |frame| which called window.print(). 838 // Prints |frame| which called window.print().
827 void PrintWebViewHelper::PrintPage(blink::WebLocalFrame* frame, 839 void PrintWebViewHelper::PrintPage(blink::WebLocalFrame* frame,
828 bool user_initiated) { 840 bool user_initiated) {
829 DCHECK(frame); 841 DCHECK(frame);
830 842
831 // Allow Prerendering to cancel this print request if necessary. 843 // Allow Prerendering to cancel this print request if necessary.
832 if (prerender::PrerenderHelper::IsPrerendering( 844 if (prerender::PrerenderHelper::IsPrerendering(
833 render_view()->GetMainRenderFrame())) { 845 render_view()->GetMainRenderFrame())) {
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after
1717 base::Bind(&PrintWebViewHelper::ShowScriptedPrintPreview, 1729 base::Bind(&PrintWebViewHelper::ShowScriptedPrintPreview,
1718 weak_ptr_factory_.GetWeakPtr())); 1730 weak_ptr_factory_.GetWeakPtr()));
1719 } 1731 }
1720 IPC::SyncMessage* msg = 1732 IPC::SyncMessage* msg =
1721 new PrintHostMsg_SetupScriptedPrintPreview(routing_id()); 1733 new PrintHostMsg_SetupScriptedPrintPreview(routing_id());
1722 msg->EnableMessagePumping(); 1734 msg->EnableMessagePumping();
1723 Send(msg); 1735 Send(msg);
1724 is_scripted_preview_delayed_ = false; 1736 is_scripted_preview_delayed_ = false;
1725 return; 1737 return;
1726 } 1738 }
1727 case PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME: { 1739 case PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME: {
ivandavid 2014/08/13 20:58:55 This is the only case where we should handle the r
Vitaly Buka (NO REVIEWS) 2014/08/13 23:39:45 No, it is not. Try to 1. open huge pdf (for exam
ivandavid 2014/08/14 03:38:13 Done.
ivandavid 2014/08/14 03:38:13 Oh OK. I figured why the PRINT_PREVIEW_USER_INITIA
1740 // Handles case where this function has been called, but DidStopLoading()
1741 // hasn't been called yet. RequestPrintPreview() will be called again, at
1742 // the end of DidStopLoading() with the same value for |type|.
1743 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) {
1744 on_stop_loading_type_ = PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME;
1745 return;
1746 }
1747
1728 break; 1748 break;
1729 } 1749 }
1730 case PRINT_PREVIEW_USER_INITIATED_SELECTION: { 1750 case PRINT_PREVIEW_USER_INITIATED_SELECTION: {
1731 DCHECK(has_selection); 1751 DCHECK(has_selection);
1732 params.selection_only = has_selection; 1752 params.selection_only = has_selection;
Vitaly Buka (NO REVIEWS) 2014/08/13 23:39:45 could you please put DCHECK(!GetPlugin(print_previ
1733 break; 1753 break;
1734 } 1754 }
1735 case PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE: { 1755 case PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE: {
1736 params.webnode_only = true; 1756 params.webnode_only = true;
1737 break; 1757 break;
1738 } 1758 }
1739 default: { 1759 default: {
1740 NOTREACHED(); 1760 NOTREACHED();
1741 return; 1761 return;
1742 } 1762 }
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
2031 } 2051 }
2032 2052
2033 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { 2053 void PrintWebViewHelper::PrintPreviewContext::ClearContext() {
2034 prep_frame_view_.reset(); 2054 prep_frame_view_.reset();
2035 metafile_.reset(); 2055 metafile_.reset();
2036 pages_to_render_.clear(); 2056 pages_to_render_.clear();
2037 error_ = PREVIEW_ERROR_NONE; 2057 error_ = PREVIEW_ERROR_NONE;
2038 } 2058 }
2039 2059
2040 } // namespace printing 2060 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698