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 "components/printing/renderer/print_web_view_helper.h" | 5 #include "components/printing/renderer/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/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 if (owns_web_view_) { | 749 if (owns_web_view_) { |
750 DCHECK(!frame->isLoading()); | 750 DCHECK(!frame->isLoading()); |
751 owns_web_view_ = false; | 751 owns_web_view_ = false; |
752 web_view->close(); | 752 web_view->close(); |
753 } | 753 } |
754 } | 754 } |
755 frame_.Reset(NULL); | 755 frame_.Reset(NULL); |
756 on_ready_.Reset(); | 756 on_ready_.Reset(); |
757 } | 757 } |
758 | 758 |
| 759 bool PrintWebViewHelper::Delegate::IsAskPrintSettingsEnabled() { |
| 760 return true; |
| 761 } |
| 762 |
| 763 bool PrintWebViewHelper::Delegate::IsScriptedPrintEnabled() { |
| 764 return true; |
| 765 } |
| 766 |
759 PrintWebViewHelper::PrintWebViewHelper( | 767 PrintWebViewHelper::PrintWebViewHelper( |
760 content::RenderView* render_view, | 768 content::RenderView* render_view, |
761 scoped_ptr<Delegate> delegate) | 769 scoped_ptr<Delegate> delegate) |
762 : content::RenderViewObserver(render_view), | 770 : content::RenderViewObserver(render_view), |
763 content::RenderViewObserverTracker<PrintWebViewHelper>(render_view), | 771 content::RenderViewObserverTracker<PrintWebViewHelper>(render_view), |
764 reset_prep_frame_view_(false), | 772 reset_prep_frame_view_(false), |
765 is_print_ready_metafile_sent_(false), | 773 is_print_ready_metafile_sent_(false), |
766 ignore_css_margins_(false), | 774 ignore_css_margins_(false), |
767 is_scripted_printing_blocked_(false), | 775 is_scripted_printing_blocked_(false), |
768 notify_browser_of_print_failure_(true), | 776 notify_browser_of_print_failure_(true), |
769 print_for_preview_(false), | 777 print_for_preview_(false), |
770 delegate_(delegate.Pass()), | 778 delegate_(delegate.Pass()), |
771 print_node_in_progress_(false), | 779 print_node_in_progress_(false), |
772 is_loading_(false), | 780 is_loading_(false), |
773 is_scripted_preview_delayed_(false), | 781 is_scripted_preview_delayed_(false), |
774 weak_ptr_factory_(this) { | 782 weak_ptr_factory_(this) { |
775 if (!delegate_->IsPrintPreviewEnabled()) | 783 if (!delegate_->IsPrintPreviewEnabled()) |
776 DisablePreview(); | 784 DisablePreview(); |
777 } | 785 } |
778 | 786 |
779 PrintWebViewHelper::~PrintWebViewHelper() {} | 787 PrintWebViewHelper::~PrintWebViewHelper() {} |
780 | 788 |
781 // static | 789 // static |
782 void PrintWebViewHelper::DisablePreview() { | 790 void PrintWebViewHelper::DisablePreview() { |
783 g_is_preview_enabled_ = false; | 791 g_is_preview_enabled_ = false; |
784 } | 792 } |
785 | 793 |
786 bool PrintWebViewHelper::IsScriptInitiatedPrintAllowed( | 794 bool PrintWebViewHelper::IsScriptInitiatedPrintAllowed( |
787 blink::WebFrame* frame, bool user_initiated) { | 795 blink::WebFrame* frame, bool user_initiated) { |
| 796 if (!delegate_->IsScriptedPrintEnabled()) |
| 797 return false; |
| 798 |
788 // If preview is enabled, then the print dialog is tab modal, and the user | 799 // If preview is enabled, then the print dialog is tab modal, and the user |
789 // can always close the tab on a mis-behaving page (the system print dialog | 800 // can always close the tab on a mis-behaving page (the system print dialog |
790 // is app modal). If the print was initiated through user action, don't | 801 // is app modal). If the print was initiated through user action, don't |
791 // throttle. Or, if the command line flag to skip throttling has been set. | 802 // throttle. Or, if the command line flag to skip throttling has been set. |
792 return !is_scripted_printing_blocked_ && | 803 return !is_scripted_printing_blocked_ && |
793 (user_initiated || g_is_preview_enabled_ || | 804 (user_initiated || g_is_preview_enabled_ || |
794 scripting_throttler_.IsAllowed(frame)); | 805 scripting_throttler_.IsAllowed(frame)); |
795 } | 806 } |
796 | 807 |
797 void PrintWebViewHelper::DidStartLoading() { | 808 void PrintWebViewHelper::DidStartLoading() { |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1252 return; // Failed to init print page settings. | 1263 return; // Failed to init print page settings. |
1253 } | 1264 } |
1254 | 1265 |
1255 // Some full screen plugins can say they don't want to print. | 1266 // Some full screen plugins can say they don't want to print. |
1256 if (!expected_page_count) { | 1267 if (!expected_page_count) { |
1257 DidFinishPrinting(FAIL_PRINT); | 1268 DidFinishPrinting(FAIL_PRINT); |
1258 return; | 1269 return; |
1259 } | 1270 } |
1260 | 1271 |
1261 // Ask the browser to show UI to retrieve the final print settings. | 1272 // Ask the browser to show UI to retrieve the final print settings. |
1262 if (!GetPrintSettingsFromUser(frame_ref.GetFrame(), node, | 1273 if (delegate_->IsAskPrintSettingsEnabled() && |
| 1274 !GetPrintSettingsFromUser(frame_ref.GetFrame(), node, |
1263 expected_page_count, | 1275 expected_page_count, |
1264 is_scripted)) { | 1276 is_scripted)) { |
1265 DidFinishPrinting(OK); // Release resources and fail silently. | 1277 DidFinishPrinting(OK); // Release resources and fail silently. |
1266 return; | 1278 return; |
1267 } | 1279 } |
1268 | 1280 |
1269 // Render Pages for printing. | 1281 // Render Pages for printing. |
1270 if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) { | 1282 if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) { |
1271 LOG(ERROR) << "RenderPagesForPrint failed"; | 1283 LOG(ERROR) << "RenderPagesForPrint failed"; |
1272 DidFinishPrinting(FAIL_PRINT); | 1284 DidFinishPrinting(FAIL_PRINT); |
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2022 blink::WebConsoleMessage::LevelWarning, message)); | 2034 blink::WebConsoleMessage::LevelWarning, message)); |
2023 return false; | 2035 return false; |
2024 } | 2036 } |
2025 | 2037 |
2026 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2038 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
2027 // Reset counter on successful print. | 2039 // Reset counter on successful print. |
2028 count_ = 0; | 2040 count_ = 0; |
2029 } | 2041 } |
2030 | 2042 |
2031 } // namespace printing | 2043 } // namespace printing |
OLD | NEW |