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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 |
| 10 #include <algorithm> |
9 #include <string> | 11 #include <string> |
10 #include <utility> | 12 #include <utility> |
11 | 13 |
12 #include "base/auto_reset.h" | 14 #include "base/auto_reset.h" |
13 #include "base/json/json_writer.h" | 15 #include "base/json/json_writer.h" |
14 #include "base/location.h" | 16 #include "base/location.h" |
15 #include "base/logging.h" | 17 #include "base/logging.h" |
16 #include "base/macros.h" | 18 #include "base/macros.h" |
17 #include "base/metrics/histogram_macros.h" | 19 #include "base/metrics/histogram_macros.h" |
18 #include "base/process/process_handle.h" | 20 #include "base/process/process_handle.h" |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 result_params.page_size.height() - result_params.margin_top - | 502 result_params.page_size.height() - result_params.margin_top - |
501 default_margin_bottom); | 503 default_margin_bottom); |
502 } else { | 504 } else { |
503 // Using the CSS parameters. Scale CSS content size. | 505 // Using the CSS parameters. Scale CSS content size. |
504 result_params.content_size = | 506 result_params.content_size = |
505 ScaleAndRoundSize(result_params.content_size, *scale_factor); | 507 ScaleAndRoundSize(result_params.content_size, *scale_factor); |
506 if (fit_to_page) { | 508 if (fit_to_page) { |
507 double factor = FitPrintParamsToPage(params, &result_params); | 509 double factor = FitPrintParamsToPage(params, &result_params); |
508 if (scale_factor) | 510 if (scale_factor) |
509 *scale_factor = (*scale_factor) * factor; | 511 *scale_factor = (*scale_factor) * factor; |
510 } else { // !fit_to_page | 512 } else { |
511 // Already scaled the page, need to also scale the CSS margins since they | 513 // Already scaled the page, need to also scale the CSS margins since they |
512 // are begin applied | 514 // are begin applied |
513 result_params.margin_left = | 515 result_params.margin_left = |
514 ScaleAndRound(result_params.margin_left, page_scaling); | 516 ScaleAndRound(result_params.margin_left, page_scaling); |
515 result_params.margin_top = | 517 result_params.margin_top = |
516 ScaleAndRound(result_params.margin_top, page_scaling); | 518 ScaleAndRound(result_params.margin_top, page_scaling); |
517 } | 519 } |
518 } | 520 } |
519 | 521 |
520 return result_params; | 522 return result_params; |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 // the number that produces output with the correct physical size for elements | 749 // the number that produces output with the correct physical size for elements |
748 // that are specified in cm, mm, pt etc. | 750 // that are specified in cm, mm, pt etc. |
749 // This is important for sites that try to fill the page. | 751 // This is important for sites that try to fill the page. |
750 gfx::Size print_layout_size(web_print_params_.printContentArea.width, | 752 gfx::Size print_layout_size(web_print_params_.printContentArea.width, |
751 web_print_params_.printContentArea.height); | 753 web_print_params_.printContentArea.height); |
752 print_layout_size.set_height( | 754 print_layout_size.set_height( |
753 ScaleAndRound(print_layout_size.height(), kPrintingMinimumShrinkFactor)); | 755 ScaleAndRound(print_layout_size.height(), kPrintingMinimumShrinkFactor)); |
754 | 756 |
755 if (!frame()) | 757 if (!frame()) |
756 return; | 758 return; |
| 759 |
| 760 // Backup size and offset if it's a local frame. |
757 blink::WebView* web_view = frame_.view(); | 761 blink::WebView* web_view = frame_.view(); |
758 // Backup size and offset. | 762 if (blink::WebFrame* web_frame = web_view->mainFrame()) { |
759 if (blink::WebFrame* web_frame = web_view->mainFrame()) | 763 if (web_frame->isWebLocalFrame()) |
760 prev_scroll_offset_ = web_frame->scrollOffset(); | 764 prev_scroll_offset_ = web_frame->scrollOffset(); |
| 765 } |
761 prev_view_size_ = web_view->size(); | 766 prev_view_size_ = web_view->size(); |
762 | 767 |
763 web_view->resize(print_layout_size); | 768 web_view->resize(print_layout_size); |
764 } | 769 } |
765 | 770 |
766 void PrepareFrameAndViewForPrint::StartPrinting() { | 771 void PrepareFrameAndViewForPrint::StartPrinting() { |
767 blink::WebView* web_view = frame_.view(); | 772 blink::WebView* web_view = frame_.view(); |
768 web_view->settings()->setShouldPrintBackgrounds(should_print_backgrounds_); | 773 web_view->settings()->setShouldPrintBackgrounds(should_print_backgrounds_); |
769 expected_pages_count_ = | 774 expected_pages_count_ = |
770 frame()->printBegin(web_print_params_, node_to_print_); | 775 frame()->printBegin(web_print_params_, node_to_print_); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
838 blink::WebLocalFrame* frame = blink::WebLocalFrame::create(scope, this); | 843 blink::WebLocalFrame* frame = blink::WebLocalFrame::create(scope, this); |
839 parent->appendChild(frame); | 844 parent->appendChild(frame); |
840 return frame; | 845 return frame; |
841 } | 846 } |
842 | 847 |
843 void PrepareFrameAndViewForPrint::CallOnReady() { | 848 void PrepareFrameAndViewForPrint::CallOnReady() { |
844 return on_ready_.Run(); // Can delete |this|. | 849 return on_ready_.Run(); // Can delete |this|. |
845 } | 850 } |
846 | 851 |
847 void PrepareFrameAndViewForPrint::RestoreSize() { | 852 void PrepareFrameAndViewForPrint::RestoreSize() { |
848 if (frame()) { | 853 if (!frame()) |
849 blink::WebView* web_view = frame_.GetFrame()->view(); | 854 return; |
850 web_view->resize(prev_view_size_); | 855 |
851 if (blink::WebFrame* web_frame = web_view->mainFrame()) | 856 blink::WebView* web_view = frame_.GetFrame()->view(); |
| 857 web_view->resize(prev_view_size_); |
| 858 if (blink::WebFrame* web_frame = web_view->mainFrame()) { |
| 859 if (web_frame->isWebLocalFrame()) |
852 web_frame->setScrollOffset(prev_scroll_offset_); | 860 web_frame->setScrollOffset(prev_scroll_offset_); |
853 } | 861 } |
854 } | 862 } |
855 | 863 |
856 void PrepareFrameAndViewForPrint::FinishPrinting() { | 864 void PrepareFrameAndViewForPrint::FinishPrinting() { |
857 blink::WebLocalFrame* frame = frame_.GetFrame(); | 865 blink::WebLocalFrame* frame = frame_.GetFrame(); |
858 if (frame) { | 866 if (frame) { |
859 blink::WebView* web_view = frame->view(); | 867 blink::WebView* web_view = frame->view(); |
860 if (is_printing_started_) { | 868 if (is_printing_started_) { |
861 is_printing_started_ = false; | 869 is_printing_started_ = false; |
(...skipping 15 matching lines...) Expand all Loading... |
877 } | 885 } |
878 | 886 |
879 bool PrintWebViewHelper::Delegate::IsAskPrintSettingsEnabled() { | 887 bool PrintWebViewHelper::Delegate::IsAskPrintSettingsEnabled() { |
880 return true; | 888 return true; |
881 } | 889 } |
882 | 890 |
883 bool PrintWebViewHelper::Delegate::IsScriptedPrintEnabled() { | 891 bool PrintWebViewHelper::Delegate::IsScriptedPrintEnabled() { |
884 return true; | 892 return true; |
885 } | 893 } |
886 | 894 |
887 PrintWebViewHelper::PrintWebViewHelper(content::RenderView* render_view, | 895 PrintWebViewHelper::PrintWebViewHelper(content::RenderFrame* render_frame, |
888 std::unique_ptr<Delegate> delegate) | 896 std::unique_ptr<Delegate> delegate) |
889 : content::RenderViewObserver(render_view), | 897 : content::RenderFrameObserver(render_frame), |
890 content::RenderViewObserverTracker<PrintWebViewHelper>(render_view), | 898 content::RenderFrameObserverTracker<PrintWebViewHelper>(render_frame), |
891 reset_prep_frame_view_(false), | 899 reset_prep_frame_view_(false), |
892 is_print_ready_metafile_sent_(false), | 900 is_print_ready_metafile_sent_(false), |
893 ignore_css_margins_(false), | 901 ignore_css_margins_(false), |
894 is_scripted_printing_blocked_(false), | 902 is_printing_enabled_(true), |
895 notify_browser_of_print_failure_(true), | 903 notify_browser_of_print_failure_(true), |
896 print_for_preview_(false), | 904 print_for_preview_(false), |
897 delegate_(std::move(delegate)), | 905 delegate_(std::move(delegate)), |
898 print_node_in_progress_(false), | 906 print_node_in_progress_(false), |
899 is_loading_(false), | 907 is_loading_(false), |
900 is_scripted_preview_delayed_(false), | 908 is_scripted_preview_delayed_(false), |
901 ipc_nesting_level_(0), | 909 ipc_nesting_level_(0), |
902 weak_ptr_factory_(this) { | 910 weak_ptr_factory_(this) { |
903 if (!delegate_->IsPrintPreviewEnabled()) | 911 if (!delegate_->IsPrintPreviewEnabled()) |
904 DisablePreview(); | 912 DisablePreview(); |
905 } | 913 } |
906 | 914 |
907 PrintWebViewHelper::~PrintWebViewHelper() { | 915 PrintWebViewHelper::~PrintWebViewHelper() { |
908 } | 916 } |
909 | 917 |
910 // static | 918 // static |
911 void PrintWebViewHelper::DisablePreview() { | 919 void PrintWebViewHelper::DisablePreview() { |
912 g_is_preview_enabled = false; | 920 g_is_preview_enabled = false; |
913 } | 921 } |
914 | 922 |
915 bool PrintWebViewHelper::IsScriptInitiatedPrintAllowed(blink::WebFrame* frame, | 923 bool PrintWebViewHelper::IsScriptInitiatedPrintAllowed(blink::WebFrame* frame, |
916 bool user_initiated) { | 924 bool user_initiated) { |
917 if (!delegate_->IsScriptedPrintEnabled()) | 925 if (!is_printing_enabled_ || !delegate_->IsScriptedPrintEnabled()) |
918 return false; | 926 return false; |
919 | 927 |
920 // If preview is enabled, then the print dialog is tab modal, and the user | 928 // If preview is enabled, then the print dialog is tab modal, and the user |
921 // can always close the tab on a mis-behaving page (the system print dialog | 929 // can always close the tab on a mis-behaving page (the system print dialog |
922 // is app modal). If the print was initiated through user action, don't | 930 // is app modal). If the print was initiated through user action, don't |
923 // throttle. Or, if the command line flag to skip throttling has been set. | 931 // throttle. Or, if the command line flag to skip throttling has been set. |
924 return !is_scripted_printing_blocked_ && | 932 return user_initiated || g_is_preview_enabled || |
925 (user_initiated || g_is_preview_enabled || | 933 scripting_throttler_.IsAllowed(frame); |
926 scripting_throttler_.IsAllowed(frame)); | |
927 } | 934 } |
928 | 935 |
929 void PrintWebViewHelper::DidStartLoading() { | 936 void PrintWebViewHelper::DidStartProvisionalLoad() { |
930 is_loading_ = true; | 937 is_loading_ = true; |
931 } | 938 } |
932 | 939 |
933 void PrintWebViewHelper::DidStopLoading() { | 940 void PrintWebViewHelper::DidFailProvisionalLoad( |
| 941 const blink::WebURLError& error) { |
| 942 DidFinishLoad(); |
| 943 } |
| 944 |
| 945 void PrintWebViewHelper::DidFinishLoad() { |
934 is_loading_ = false; | 946 is_loading_ = false; |
935 if (!on_stop_loading_closure_.is_null()) { | 947 if (!on_stop_loading_closure_.is_null()) { |
936 on_stop_loading_closure_.Run(); | 948 on_stop_loading_closure_.Run(); |
937 on_stop_loading_closure_.Reset(); | 949 on_stop_loading_closure_.Reset(); |
938 } | 950 } |
939 } | 951 } |
940 | 952 |
941 // Prints |frame| which called window.print(). | 953 void PrintWebViewHelper::ScriptedPrint(bool user_initiated) { |
942 void PrintWebViewHelper::PrintPage(blink::WebLocalFrame* frame, | |
943 bool user_initiated) { | |
944 DCHECK(frame); | |
945 | |
946 // Allow Prerendering to cancel this print request if necessary. | 954 // Allow Prerendering to cancel this print request if necessary. |
947 if (delegate_->CancelPrerender(render_view(), routing_id())) | 955 if (delegate_->CancelPrerender(render_frame())) |
948 return; | 956 return; |
949 | 957 |
950 if (!IsScriptInitiatedPrintAllowed(frame, user_initiated)) | 958 blink::WebLocalFrame* web_frame = render_frame()->GetWebFrame(); |
| 959 if (!IsScriptInitiatedPrintAllowed(web_frame, user_initiated)) |
951 return; | 960 return; |
952 | 961 |
953 if (delegate_->OverridePrint(frame)) | 962 if (delegate_->OverridePrint(web_frame)) |
954 return; | 963 return; |
955 | 964 |
956 if (g_is_preview_enabled) { | 965 if (g_is_preview_enabled) { |
957 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) | 966 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
958 print_preview_context_.InitWithFrame(frame); | 967 print_preview_context_.InitWithFrame(web_frame); |
959 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED); | 968 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED); |
960 #endif | 969 #endif |
961 } else { | 970 } else { |
962 #if BUILDFLAG(ENABLE_BASIC_PRINTING) | 971 #if BUILDFLAG(ENABLE_BASIC_PRINTING) |
963 Print(frame, blink::WebNode(), true); | 972 Print(web_frame, blink::WebNode(), true /* is_scripted? */); |
964 #endif | 973 #endif |
965 } | 974 } |
966 } | 975 } |
967 | 976 |
968 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { | 977 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { |
969 // The class is not designed to handle recursive messages. This is not | 978 // The class is not designed to handle recursive messages. This is not |
970 // expected during regular flow. However, during rendering of content for | 979 // expected during regular flow. However, during rendering of content for |
971 // printing, lower level code may run nested message loop. E.g. PDF may has | 980 // printing, lower level code may run nested message loop. E.g. PDF may has |
972 // script to show message box http://crbug.com/502562. In that moment browser | 981 // script to show message box http://crbug.com/502562. In that moment browser |
973 // may receive updated printer capabilities and decide to restart print | 982 // may receive updated printer capabilities and decide to restart print |
974 // preview generation. When this happened message handling function may | 983 // preview generation. When this happened message handling function may |
975 // choose to ignore message or safely crash process. | 984 // choose to ignore message or safely crash process. |
976 ++ipc_nesting_level_; | 985 ++ipc_nesting_level_; |
977 | 986 |
978 bool handled = true; | 987 bool handled = true; |
979 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) | 988 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) |
980 #if BUILDFLAG(ENABLE_BASIC_PRINTING) | 989 #if BUILDFLAG(ENABLE_BASIC_PRINTING) |
981 IPC_MESSAGE_HANDLER(PrintMsg_PrintPages, OnPrintPages) | 990 IPC_MESSAGE_HANDLER(PrintMsg_PrintPages, OnPrintPages) |
982 IPC_MESSAGE_HANDLER(PrintMsg_PrintForSystemDialog, OnPrintForSystemDialog) | 991 IPC_MESSAGE_HANDLER(PrintMsg_PrintForSystemDialog, OnPrintForSystemDialog) |
983 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) | 992 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) |
984 #if BUILDFLAG(ENABLE_BASIC_PRINTING) && BUILDFLAG(ENABLE_PRINT_PREVIEW) | 993 #if BUILDFLAG(ENABLE_BASIC_PRINTING) && BUILDFLAG(ENABLE_PRINT_PREVIEW) |
985 IPC_MESSAGE_HANDLER(PrintMsg_PrintForPrintPreview, OnPrintForPrintPreview) | 994 IPC_MESSAGE_HANDLER(PrintMsg_PrintForPrintPreview, OnPrintForPrintPreview) |
986 #endif | 995 #endif |
987 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) | 996 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
988 IPC_MESSAGE_HANDLER(PrintMsg_InitiatePrintPreview, OnInitiatePrintPreview) | 997 IPC_MESSAGE_HANDLER(PrintMsg_InitiatePrintPreview, OnInitiatePrintPreview) |
989 IPC_MESSAGE_HANDLER(PrintMsg_PrintPreview, OnPrintPreview) | 998 IPC_MESSAGE_HANDLER(PrintMsg_PrintPreview, OnPrintPreview) |
990 IPC_MESSAGE_HANDLER(PrintMsg_PrintingDone, OnPrintingDone) | 999 IPC_MESSAGE_HANDLER(PrintMsg_PrintingDone, OnPrintingDone) |
991 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) | 1000 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) |
992 IPC_MESSAGE_HANDLER(PrintMsg_SetScriptedPrintingBlocked, | 1001 IPC_MESSAGE_HANDLER(PrintMsg_SetPrintingEnabled, OnSetPrintingEnabled) |
993 SetScriptedPrintBlocked) | |
994 IPC_MESSAGE_UNHANDLED(handled = false) | 1002 IPC_MESSAGE_UNHANDLED(handled = false) |
995 IPC_END_MESSAGE_MAP() | 1003 IPC_END_MESSAGE_MAP() |
996 | 1004 |
997 --ipc_nesting_level_; | 1005 --ipc_nesting_level_; |
998 return handled; | 1006 return handled; |
999 } | 1007 } |
1000 | 1008 |
1001 void PrintWebViewHelper::OnDestruct() { | 1009 void PrintWebViewHelper::OnDestruct() { |
1002 delete this; | 1010 delete this; |
1003 } | 1011 } |
1004 | 1012 |
1005 bool PrintWebViewHelper::GetPrintFrame(blink::WebLocalFrame** frame) { | |
1006 DCHECK(frame); | |
1007 blink::WebView* webView = render_view()->GetWebView(); | |
1008 DCHECK(webView); | |
1009 if (!webView) | |
1010 return false; | |
1011 | |
1012 // If the user has selected text in the currently focused frame we print | |
1013 // only that frame (this makes print selection work for multiple frames). | |
1014 blink::WebLocalFrame* focusedFrame = webView->focusedFrame(); | |
1015 *frame = focusedFrame->hasSelection() | |
1016 ? focusedFrame | |
1017 : webView->mainFrame()->toWebLocalFrame(); | |
1018 return true; | |
1019 } | |
1020 | |
1021 #if BUILDFLAG(ENABLE_BASIC_PRINTING) | 1013 #if BUILDFLAG(ENABLE_BASIC_PRINTING) |
1022 void PrintWebViewHelper::OnPrintPages() { | 1014 void PrintWebViewHelper::OnPrintPages() { |
1023 if (ipc_nesting_level_> 1) | 1015 if (ipc_nesting_level_> 1) |
1024 return; | 1016 return; |
1025 blink::WebLocalFrame* frame; | 1017 |
1026 if (!GetPrintFrame(&frame)) | 1018 blink::WebLocalFrame* frame = render_frame()->GetWebFrame(); |
1027 return; | 1019 |
1028 // If we are printing a PDF extension frame, find the plugin node and print | 1020 // If we are printing a PDF extension frame, find the plugin node and print |
1029 // that instead. | 1021 // that instead. |
1030 auto plugin = delegate_->GetPdfElement(frame); | 1022 auto plugin = delegate_->GetPdfElement(frame); |
1031 Print(frame, plugin, false); | 1023 Print(frame, plugin, false /* is_scripted? */); |
1032 } | 1024 } |
1033 | 1025 |
1034 void PrintWebViewHelper::OnPrintForSystemDialog() { | 1026 void PrintWebViewHelper::OnPrintForSystemDialog() { |
1035 if (ipc_nesting_level_> 1) | 1027 if (ipc_nesting_level_> 1) |
1036 return; | 1028 return; |
1037 blink::WebLocalFrame* frame = print_preview_context_.source_frame(); | 1029 blink::WebLocalFrame* frame = print_preview_context_.source_frame(); |
1038 if (!frame) { | 1030 if (!frame) { |
1039 NOTREACHED(); | 1031 NOTREACHED(); |
1040 return; | 1032 return; |
1041 } | 1033 } |
1042 Print(frame, print_preview_context_.source_node(), false); | 1034 Print(frame, print_preview_context_.source_node(), false); |
1043 } | 1035 } |
1044 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) | 1036 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) |
1045 | 1037 |
1046 #if BUILDFLAG(ENABLE_BASIC_PRINTING) && BUILDFLAG(ENABLE_PRINT_PREVIEW) | 1038 #if BUILDFLAG(ENABLE_BASIC_PRINTING) && BUILDFLAG(ENABLE_PRINT_PREVIEW) |
1047 void PrintWebViewHelper::OnPrintForPrintPreview( | 1039 void PrintWebViewHelper::OnPrintForPrintPreview( |
1048 const base::DictionaryValue& job_settings) { | 1040 const base::DictionaryValue& job_settings) { |
1049 CHECK_LE(ipc_nesting_level_, 1); | 1041 CHECK_LE(ipc_nesting_level_, 1); |
1050 // If still not finished with earlier print request simply ignore. | 1042 // If still not finished with earlier print request simply ignore. |
1051 if (prep_frame_view_) | 1043 if (prep_frame_view_) |
1052 return; | 1044 return; |
1053 | 1045 |
1054 if (!render_view()->GetWebView()) | 1046 blink::WebDocument document = render_frame()->GetWebFrame()->document(); |
1055 return; | |
1056 blink::WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); | |
1057 if (!main_frame) | |
1058 return; | |
1059 | |
1060 blink::WebDocument document = main_frame->document(); | |
1061 // <object>/<iframe> with id="pdf-viewer" is created in | 1047 // <object>/<iframe> with id="pdf-viewer" is created in |
1062 // chrome/browser/resources/print_preview/print_preview.js | 1048 // chrome/browser/resources/print_preview/print_preview.js |
1063 blink::WebElement pdf_element = document.getElementById("pdf-viewer"); | 1049 blink::WebElement pdf_element = document.getElementById("pdf-viewer"); |
1064 if (pdf_element.isNull()) { | 1050 if (pdf_element.isNull()) { |
1065 NOTREACHED(); | 1051 NOTREACHED(); |
1066 return; | 1052 return; |
1067 } | 1053 } |
1068 | 1054 |
1069 // The out-of-process plugin element is nested within a frame. In tests, there | 1055 // The out-of-process plugin element is nested within a frame. In tests, there |
1070 // may not be an iframe containing the out-of-process plugin, so continue with | 1056 // may not be an iframe containing the out-of-process plugin, so continue with |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1197 if (prep_frame_view_ && prep_frame_view_->IsLoadingSelection()) { | 1183 if (prep_frame_view_ && prep_frame_view_->IsLoadingSelection()) { |
1198 reset_prep_frame_view_ = true; | 1184 reset_prep_frame_view_ = true; |
1199 return; | 1185 return; |
1200 } | 1186 } |
1201 | 1187 |
1202 const PrintMsg_Print_Params& print_params = print_pages_params_->params; | 1188 const PrintMsg_Print_Params& print_params = print_pages_params_->params; |
1203 prep_frame_view_.reset(new PrepareFrameAndViewForPrint( | 1189 prep_frame_view_.reset(new PrepareFrameAndViewForPrint( |
1204 print_params, print_preview_context_.source_frame(), | 1190 print_params, print_preview_context_.source_frame(), |
1205 print_preview_context_.source_node(), ignore_css_margins_)); | 1191 print_preview_context_.source_node(), ignore_css_margins_)); |
1206 prep_frame_view_->CopySelectionIfNeeded( | 1192 prep_frame_view_->CopySelectionIfNeeded( |
1207 render_view()->GetWebkitPreferences(), | 1193 render_frame()->GetWebkitPreferences(), |
1208 base::Bind(&PrintWebViewHelper::OnFramePreparedForPreviewDocument, | 1194 base::Bind(&PrintWebViewHelper::OnFramePreparedForPreviewDocument, |
1209 base::Unretained(this))); | 1195 base::Unretained(this))); |
1210 } | 1196 } |
1211 | 1197 |
1212 void PrintWebViewHelper::OnFramePreparedForPreviewDocument() { | 1198 void PrintWebViewHelper::OnFramePreparedForPreviewDocument() { |
1213 if (reset_prep_frame_view_) { | 1199 if (reset_prep_frame_view_) { |
1214 PrepareFrameForPreviewDocument(); | 1200 PrepareFrameForPreviewDocument(); |
1215 return; | 1201 return; |
1216 } | 1202 } |
1217 DidFinishPrinting(CreatePreviewDocument() ? OK : FAIL_PREVIEW); | 1203 DidFinishPrinting(CreatePreviewDocument() ? OK : FAIL_PREVIEW); |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1382 | 1368 |
1383 void PrintWebViewHelper::OnPrintingDone(bool success) { | 1369 void PrintWebViewHelper::OnPrintingDone(bool success) { |
1384 if (ipc_nesting_level_ > 1) | 1370 if (ipc_nesting_level_ > 1) |
1385 return; | 1371 return; |
1386 notify_browser_of_print_failure_ = false; | 1372 notify_browser_of_print_failure_ = false; |
1387 if (!success) | 1373 if (!success) |
1388 LOG(ERROR) << "Failure in OnPrintingDone"; | 1374 LOG(ERROR) << "Failure in OnPrintingDone"; |
1389 DidFinishPrinting(success ? OK : FAIL_PRINT); | 1375 DidFinishPrinting(success ? OK : FAIL_PRINT); |
1390 } | 1376 } |
1391 | 1377 |
1392 void PrintWebViewHelper::SetScriptedPrintBlocked(bool blocked) { | 1378 void PrintWebViewHelper::OnSetPrintingEnabled(bool enabled) { |
1393 is_scripted_printing_blocked_ = blocked; | 1379 is_printing_enabled_ = enabled; |
1394 } | 1380 } |
1395 | 1381 |
1396 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) | 1382 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
1397 void PrintWebViewHelper::OnInitiatePrintPreview(bool selection_only) { | 1383 void PrintWebViewHelper::OnInitiatePrintPreview(bool has_selection) { |
1398 if (ipc_nesting_level_ > 1) | 1384 if (ipc_nesting_level_ > 1) |
1399 return; | 1385 return; |
1400 blink::WebLocalFrame* frame = NULL; | 1386 |
1401 GetPrintFrame(&frame); | 1387 blink::WebLocalFrame* frame = render_frame()->GetWebFrame(); |
1402 DCHECK(frame); | 1388 |
1403 // If we are printing a PDF extension frame, find the plugin node and print | 1389 // If we are printing a PDF extension frame, find the plugin node and print |
1404 // that instead. | 1390 // that instead. |
1405 auto plugin = delegate_->GetPdfElement(frame); | 1391 auto plugin = delegate_->GetPdfElement(frame); |
1406 if (!plugin.isNull()) { | 1392 if (!plugin.isNull()) { |
1407 PrintNode(plugin); | 1393 PrintNode(plugin); |
1408 return; | 1394 return; |
1409 } | 1395 } |
1410 print_preview_context_.InitWithFrame(frame); | 1396 print_preview_context_.InitWithFrame(frame); |
1411 RequestPrintPreview(selection_only | 1397 RequestPrintPreview(has_selection |
1412 ? PRINT_PREVIEW_USER_INITIATED_SELECTION | 1398 ? PRINT_PREVIEW_USER_INITIATED_SELECTION |
1413 : PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME); | 1399 : PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME); |
1414 } | 1400 } |
1415 #endif | 1401 #endif |
1416 | 1402 |
1417 bool PrintWebViewHelper::IsPrintingEnabled() { | 1403 bool PrintWebViewHelper::IsPrintingEnabled() const { |
1418 bool result = false; | 1404 return is_printing_enabled_; |
1419 Send(new PrintHostMsg_IsPrintingEnabled(routing_id(), &result)); | |
1420 return result; | |
1421 } | 1405 } |
1422 | 1406 |
1423 void PrintWebViewHelper::PrintNode(const blink::WebNode& node) { | 1407 void PrintWebViewHelper::PrintNode(const blink::WebNode& node) { |
1424 if (node.isNull() || !node.document().frame()) { | 1408 if (node.isNull() || !node.document().frame()) { |
1425 // This can occur when the context menu refers to an invalid WebNode. | 1409 // This can occur when the context menu refers to an invalid WebNode. |
1426 // See http://crbug.com/100890#c17 for a repro case. | 1410 // See http://crbug.com/100890#c17 for a repro case. |
1427 return; | 1411 return; |
1428 } | 1412 } |
1429 | 1413 |
1430 if (print_node_in_progress_) { | 1414 if (print_node_in_progress_) { |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1805 if (!frame || prep_frame_view_) | 1789 if (!frame || prep_frame_view_) |
1806 return false; | 1790 return false; |
1807 | 1791 |
1808 const PrintMsg_PrintPages_Params& params = *print_pages_params_; | 1792 const PrintMsg_PrintPages_Params& params = *print_pages_params_; |
1809 const PrintMsg_Print_Params& print_params = params.params; | 1793 const PrintMsg_Print_Params& print_params = params.params; |
1810 prep_frame_view_.reset(new PrepareFrameAndViewForPrint( | 1794 prep_frame_view_.reset(new PrepareFrameAndViewForPrint( |
1811 print_params, frame, node, ignore_css_margins_)); | 1795 print_params, frame, node, ignore_css_margins_)); |
1812 DCHECK(!print_pages_params_->params.selection_only || | 1796 DCHECK(!print_pages_params_->params.selection_only || |
1813 print_pages_params_->pages.empty()); | 1797 print_pages_params_->pages.empty()); |
1814 prep_frame_view_->CopySelectionIfNeeded( | 1798 prep_frame_view_->CopySelectionIfNeeded( |
1815 render_view()->GetWebkitPreferences(), | 1799 render_frame()->GetWebkitPreferences(), |
1816 base::Bind(&PrintWebViewHelper::OnFramePreparedForPrintPages, | 1800 base::Bind(&PrintWebViewHelper::OnFramePreparedForPrintPages, |
1817 base::Unretained(this))); | 1801 base::Unretained(this))); |
1818 return true; | 1802 return true; |
1819 } | 1803 } |
1820 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) | 1804 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) |
1821 | 1805 |
1822 #if !defined(OS_MACOSX) | 1806 #if !defined(OS_MACOSX) |
1823 void PrintWebViewHelper::PrintPageInternal( | 1807 void PrintWebViewHelper::PrintPageInternal( |
1824 const PrintMsg_PrintPage_Params& params, | 1808 const PrintMsg_PrintPage_Params& params, |
1825 blink::WebLocalFrame* frame, | 1809 blink::WebLocalFrame* frame, |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2335 blink::WebConsoleMessage::LevelWarning, message)); | 2319 blink::WebConsoleMessage::LevelWarning, message)); |
2336 return false; | 2320 return false; |
2337 } | 2321 } |
2338 | 2322 |
2339 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2323 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
2340 // Reset counter on successful print. | 2324 // Reset counter on successful print. |
2341 count_ = 0; | 2325 count_ = 0; |
2342 } | 2326 } |
2343 | 2327 |
2344 } // namespace printing | 2328 } // namespace printing |
OLD | NEW |