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