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

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

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

Powered by Google App Engine
This is Rietveld 408576698