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 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 } | 298 } |
299 | 299 |
300 bool PrintingNodeOrPdfFrame(const blink::WebLocalFrame* frame, | 300 bool PrintingNodeOrPdfFrame(const blink::WebLocalFrame* frame, |
301 const blink::WebNode& node) { | 301 const blink::WebNode& node) { |
302 if (!node.isNull()) | 302 if (!node.isNull()) |
303 return true; | 303 return true; |
304 blink::WebPlugin* plugin = GetPlugin(frame); | 304 blink::WebPlugin* plugin = GetPlugin(frame); |
305 return plugin && plugin->supportsPaginatedPrint(); | 305 return plugin && plugin->supportsPaginatedPrint(); |
306 } | 306 } |
307 | 307 |
| 308 #if defined(ENABLE_PRINT_PREVIEW) |
| 309 // Returns true if the current destination printer is PRINT_TO_PDF. |
| 310 bool IsPrintToPdfRequested(const base::DictionaryValue& job_settings) { |
| 311 bool print_to_pdf = false; |
| 312 if (!job_settings.GetBoolean(kSettingPrintToPDF, &print_to_pdf)) |
| 313 NOTREACHED(); |
| 314 return print_to_pdf; |
| 315 } |
| 316 |
308 bool PrintingFrameHasPageSizeStyle(blink::WebFrame* frame, | 317 bool PrintingFrameHasPageSizeStyle(blink::WebFrame* frame, |
309 int total_page_count) { | 318 int total_page_count) { |
310 if (!frame) | 319 if (!frame) |
311 return false; | 320 return false; |
312 bool frame_has_custom_page_size_style = false; | 321 bool frame_has_custom_page_size_style = false; |
313 for (int i = 0; i < total_page_count; ++i) { | 322 for (int i = 0; i < total_page_count; ++i) { |
314 if (frame->hasCustomPageSizeStyle(i)) { | 323 if (frame->hasCustomPageSizeStyle(i)) { |
315 frame_has_custom_page_size_style = true; | 324 frame_has_custom_page_size_style = true; |
316 break; | 325 break; |
317 } | 326 } |
318 } | 327 } |
319 return frame_has_custom_page_size_style; | 328 return frame_has_custom_page_size_style; |
320 } | 329 } |
| 330 #endif // defined(ENABLE_PRINT_PREVIEW) |
321 | 331 |
322 // Disable scaling when either: | 332 // Disable scaling when either: |
323 // - The PDF specifies disabling scaling. | 333 // - The PDF specifies disabling scaling. |
324 // - All the pages in the PDF are the same size, and that size is the same as | 334 // - All the pages in the PDF are the same size, and that size is the same as |
325 // the paper size. | 335 // the paper size. |
326 bool PDFShouldDisableScalingBasedOnPreset( | 336 bool PDFShouldDisableScalingBasedOnPreset( |
327 const blink::WebPrintPresetOptions& options, | 337 const blink::WebPrintPresetOptions& options, |
328 const PrintMsg_Print_Params& params) { | 338 const PrintMsg_Print_Params& params) { |
329 if (options.isScalingDisabled) | 339 if (options.isScalingDisabled) |
330 return true; | 340 return true; |
(...skipping 17 matching lines...) Expand all Loading... |
348 bool PDFShouldDisableScaling(blink::WebLocalFrame* frame, | 358 bool PDFShouldDisableScaling(blink::WebLocalFrame* frame, |
349 const blink::WebNode& node, | 359 const blink::WebNode& node, |
350 const PrintMsg_Print_Params& params) { | 360 const PrintMsg_Print_Params& params) { |
351 const bool kDefaultPDFShouldDisableScalingSetting = true; | 361 const bool kDefaultPDFShouldDisableScalingSetting = true; |
352 blink::WebPrintPresetOptions preset_options; | 362 blink::WebPrintPresetOptions preset_options; |
353 if (!frame->getPrintPresetOptionsForPlugin(node, &preset_options)) | 363 if (!frame->getPrintPresetOptionsForPlugin(node, &preset_options)) |
354 return kDefaultPDFShouldDisableScalingSetting; | 364 return kDefaultPDFShouldDisableScalingSetting; |
355 return PDFShouldDisableScalingBasedOnPreset(preset_options, params); | 365 return PDFShouldDisableScalingBasedOnPreset(preset_options, params); |
356 } | 366 } |
357 | 367 |
| 368 #if defined(ENABLE_BASIC_PRINTING) |
358 MarginType GetMarginsForPdf(blink::WebLocalFrame* frame, | 369 MarginType GetMarginsForPdf(blink::WebLocalFrame* frame, |
359 const blink::WebNode& node, | 370 const blink::WebNode& node, |
360 const PrintMsg_Print_Params& params) { | 371 const PrintMsg_Print_Params& params) { |
361 return PDFShouldDisableScaling(frame, node, params) ? | 372 return PDFShouldDisableScaling(frame, node, params) ? |
362 NO_MARGINS : PRINTABLE_AREA_MARGINS; | 373 NO_MARGINS : PRINTABLE_AREA_MARGINS; |
363 } | 374 } |
| 375 #endif |
364 | 376 |
| 377 #if defined(ENABLE_PRINT_PREVIEW) |
365 bool FitToPageEnabled(const base::DictionaryValue& job_settings) { | 378 bool FitToPageEnabled(const base::DictionaryValue& job_settings) { |
366 bool fit_to_paper_size = false; | 379 bool fit_to_paper_size = false; |
367 if (!job_settings.GetBoolean(kSettingFitToPageEnabled, &fit_to_paper_size)) { | 380 if (!job_settings.GetBoolean(kSettingFitToPageEnabled, &fit_to_paper_size)) { |
368 NOTREACHED(); | 381 NOTREACHED(); |
369 } | 382 } |
370 return fit_to_paper_size; | 383 return fit_to_paper_size; |
371 } | 384 } |
372 | 385 |
373 // Returns the print scaling option to retain/scale/crop the source page size | 386 // Returns the print scaling option to retain/scale/crop the source page size |
374 // to fit the printable area of the paper. | 387 // to fit the printable area of the paper. |
(...skipping 21 matching lines...) Expand all Loading... |
396 if (!source_is_html) { | 409 if (!source_is_html) { |
397 if (!FitToPageEnabled(job_settings)) | 410 if (!FitToPageEnabled(job_settings)) |
398 return blink::WebPrintScalingOptionNone; | 411 return blink::WebPrintScalingOptionNone; |
399 | 412 |
400 bool no_plugin_scaling = PDFShouldDisableScaling(frame, node, params); | 413 bool no_plugin_scaling = PDFShouldDisableScaling(frame, node, params); |
401 if (params.is_first_request && no_plugin_scaling) | 414 if (params.is_first_request && no_plugin_scaling) |
402 return blink::WebPrintScalingOptionNone; | 415 return blink::WebPrintScalingOptionNone; |
403 } | 416 } |
404 return blink::WebPrintScalingOptionFitToPrintableArea; | 417 return blink::WebPrintScalingOptionFitToPrintableArea; |
405 } | 418 } |
| 419 #endif // defined(ENABLE_PRINT_PREVIEW) |
406 | 420 |
407 PrintMsg_Print_Params CalculatePrintParamsForCss( | 421 PrintMsg_Print_Params CalculatePrintParamsForCss( |
408 blink::WebFrame* frame, | 422 blink::WebFrame* frame, |
409 int page_index, | 423 int page_index, |
410 const PrintMsg_Print_Params& page_params, | 424 const PrintMsg_Print_Params& page_params, |
411 bool ignore_css_margins, | 425 bool ignore_css_margins, |
412 bool fit_to_page, | 426 bool fit_to_page, |
413 double* scale_factor) { | 427 double* scale_factor) { |
414 PrintMsg_Print_Params css_params = | 428 PrintMsg_Print_Params css_params = |
415 GetCssPrintParams(frame, page_index, page_params); | 429 GetCssPrintParams(frame, page_index, page_params); |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
865 // Allow Prerendering to cancel this print request if necessary. | 879 // Allow Prerendering to cancel this print request if necessary. |
866 if (delegate_->CancelPrerender(render_view(), routing_id())) | 880 if (delegate_->CancelPrerender(render_view(), routing_id())) |
867 return; | 881 return; |
868 | 882 |
869 if (!IsScriptInitiatedPrintAllowed(frame, user_initiated)) | 883 if (!IsScriptInitiatedPrintAllowed(frame, user_initiated)) |
870 return; | 884 return; |
871 | 885 |
872 if (delegate_->OverridePrint(frame)) | 886 if (delegate_->OverridePrint(frame)) |
873 return; | 887 return; |
874 | 888 |
875 if (!g_is_preview_enabled) { | 889 if (g_is_preview_enabled) { |
876 Print(frame, blink::WebNode(), true); | 890 #if defined(ENABLE_PRINT_PREVIEW) |
877 } else { | |
878 print_preview_context_.InitWithFrame(frame); | 891 print_preview_context_.InitWithFrame(frame); |
879 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED); | 892 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED); |
| 893 #endif |
| 894 } else { |
| 895 #if defined(ENABLE_BASIC_PRINTING) |
| 896 Print(frame, blink::WebNode(), true); |
| 897 #endif |
880 } | 898 } |
881 } | 899 } |
882 | 900 |
883 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { | 901 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { |
884 // The class is not designed to handle recursive messages. This is not | 902 // The class is not designed to handle recursive messages. This is not |
885 // expected during regular flow. However, during rendering of content for | 903 // expected during regular flow. However, during rendering of content for |
886 // printing, lower level code may run nested message loop. E.g. PDF may has | 904 // printing, lower level code may run nested message loop. E.g. PDF may has |
887 // script to show message box http://crbug.com/502562. In that moment browser | 905 // script to show message box http://crbug.com/502562. In that moment browser |
888 // may receive updated printer capabilities and decide to restart print | 906 // may receive updated printer capabilities and decide to restart print |
889 // preview generation. When this happened message handling function may | 907 // preview generation. When this happened message handling function may |
890 // choose to ignore message or safely crash process. | 908 // choose to ignore message or safely crash process. |
891 ++ipc_nesting_level_; | 909 ++ipc_nesting_level_; |
892 | 910 |
893 bool handled = true; | 911 bool handled = true; |
894 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) | 912 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) |
895 #if defined(ENABLE_BASIC_PRINTING) | 913 #if defined(ENABLE_BASIC_PRINTING) |
896 IPC_MESSAGE_HANDLER(PrintMsg_PrintPages, OnPrintPages) | 914 IPC_MESSAGE_HANDLER(PrintMsg_PrintPages, OnPrintPages) |
897 IPC_MESSAGE_HANDLER(PrintMsg_PrintForSystemDialog, OnPrintForSystemDialog) | 915 IPC_MESSAGE_HANDLER(PrintMsg_PrintForSystemDialog, OnPrintForSystemDialog) |
898 #endif // ENABLE_BASIC_PRINTING | 916 #endif // defined(ENABLE_BASIC_PRINTING) |
| 917 #if defined(ENABLE_BASIC_PRINTING) && defined(ENABLE_PRINT_PREVIEW) |
| 918 IPC_MESSAGE_HANDLER(PrintMsg_PrintForPrintPreview, OnPrintForPrintPreview) |
| 919 #endif |
| 920 #if defined(ENABLE_PRINT_PREVIEW) |
899 IPC_MESSAGE_HANDLER(PrintMsg_InitiatePrintPreview, OnInitiatePrintPreview) | 921 IPC_MESSAGE_HANDLER(PrintMsg_InitiatePrintPreview, OnInitiatePrintPreview) |
900 IPC_MESSAGE_HANDLER(PrintMsg_PrintPreview, OnPrintPreview) | 922 IPC_MESSAGE_HANDLER(PrintMsg_PrintPreview, OnPrintPreview) |
901 IPC_MESSAGE_HANDLER(PrintMsg_PrintForPrintPreview, OnPrintForPrintPreview) | |
902 IPC_MESSAGE_HANDLER(PrintMsg_PrintingDone, OnPrintingDone) | 923 IPC_MESSAGE_HANDLER(PrintMsg_PrintingDone, OnPrintingDone) |
| 924 #endif // defined(ENABLE_PRINT_PREVIEW) |
903 IPC_MESSAGE_HANDLER(PrintMsg_SetScriptedPrintingBlocked, | 925 IPC_MESSAGE_HANDLER(PrintMsg_SetScriptedPrintingBlocked, |
904 SetScriptedPrintBlocked) | 926 SetScriptedPrintBlocked) |
905 IPC_MESSAGE_UNHANDLED(handled = false) | 927 IPC_MESSAGE_UNHANDLED(handled = false) |
906 IPC_END_MESSAGE_MAP() | 928 IPC_END_MESSAGE_MAP() |
907 | 929 |
908 --ipc_nesting_level_; | 930 --ipc_nesting_level_; |
909 return handled; | 931 return handled; |
910 } | 932 } |
911 | 933 |
| 934 bool PrintWebViewHelper::GetPrintFrame(blink::WebLocalFrame** frame) { |
| 935 DCHECK(frame); |
| 936 blink::WebView* webView = render_view()->GetWebView(); |
| 937 DCHECK(webView); |
| 938 if (!webView) |
| 939 return false; |
| 940 |
| 941 // If the user has selected text in the currently focused frame we print |
| 942 // only that frame (this makes print selection work for multiple frames). |
| 943 blink::WebLocalFrame* focusedFrame = |
| 944 webView->focusedFrame()->toWebLocalFrame(); |
| 945 *frame = focusedFrame->hasSelection() |
| 946 ? focusedFrame |
| 947 : webView->mainFrame()->toWebLocalFrame(); |
| 948 return true; |
| 949 } |
| 950 |
| 951 #if defined(ENABLE_BASIC_PRINTING) |
| 952 void PrintWebViewHelper::OnPrintPages() { |
| 953 CHECK_LE(ipc_nesting_level_, 1); |
| 954 blink::WebLocalFrame* frame; |
| 955 if (!GetPrintFrame(&frame)) |
| 956 return; |
| 957 // If we are printing a PDF extension frame, find the plugin node and print |
| 958 // that instead. |
| 959 auto plugin = delegate_->GetPdfElement(frame); |
| 960 Print(frame, plugin, false); |
| 961 } |
| 962 |
| 963 void PrintWebViewHelper::OnPrintForSystemDialog() { |
| 964 CHECK_LE(ipc_nesting_level_, 1); |
| 965 blink::WebLocalFrame* frame = print_preview_context_.source_frame(); |
| 966 if (!frame) { |
| 967 NOTREACHED(); |
| 968 return; |
| 969 } |
| 970 Print(frame, print_preview_context_.source_node(), false); |
| 971 } |
| 972 #endif // defined(ENABLE_BASIC_PRINTING) |
| 973 |
| 974 #if defined(ENABLE_BASIC_PRINTING) && defined(ENABLE_PRINT_PREVIEW) |
912 void PrintWebViewHelper::OnPrintForPrintPreview( | 975 void PrintWebViewHelper::OnPrintForPrintPreview( |
913 const base::DictionaryValue& job_settings) { | 976 const base::DictionaryValue& job_settings) { |
914 CHECK_LE(ipc_nesting_level_, 1); | 977 CHECK_LE(ipc_nesting_level_, 1); |
915 // If still not finished with earlier print request simply ignore. | 978 // If still not finished with earlier print request simply ignore. |
916 if (prep_frame_view_) | 979 if (prep_frame_view_) |
917 return; | 980 return; |
918 | 981 |
919 if (!render_view()->GetWebView()) | 982 if (!render_view()->GetWebView()) |
920 return; | 983 return; |
921 blink::WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); | 984 blink::WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
966 // See http://crbug.com/123408 | 1029 // See http://crbug.com/123408 |
967 PrintMsg_Print_Params& print_params = print_pages_params_->params; | 1030 PrintMsg_Print_Params& print_params = print_pages_params_->params; |
968 print_params.printable_area = gfx::Rect(print_params.page_size); | 1031 print_params.printable_area = gfx::Rect(print_params.page_size); |
969 | 1032 |
970 // Render Pages for printing. | 1033 // Render Pages for printing. |
971 if (!RenderPagesForPrint(plugin_frame, plugin_element)) { | 1034 if (!RenderPagesForPrint(plugin_frame, plugin_element)) { |
972 LOG(ERROR) << "RenderPagesForPrint failed"; | 1035 LOG(ERROR) << "RenderPagesForPrint failed"; |
973 DidFinishPrinting(FAIL_PRINT); | 1036 DidFinishPrinting(FAIL_PRINT); |
974 } | 1037 } |
975 } | 1038 } |
976 | 1039 #endif // defined(ENABLE_BASIC_PRINTING) && defined(ENABLE_PRINT_PREVIEW) |
977 bool PrintWebViewHelper::GetPrintFrame(blink::WebLocalFrame** frame) { | |
978 DCHECK(frame); | |
979 blink::WebView* webView = render_view()->GetWebView(); | |
980 DCHECK(webView); | |
981 if (!webView) | |
982 return false; | |
983 | |
984 // If the user has selected text in the currently focused frame we print | |
985 // only that frame (this makes print selection work for multiple frames). | |
986 blink::WebLocalFrame* focusedFrame = | |
987 webView->focusedFrame()->toWebLocalFrame(); | |
988 *frame = focusedFrame->hasSelection() | |
989 ? focusedFrame | |
990 : webView->mainFrame()->toWebLocalFrame(); | |
991 return true; | |
992 } | |
993 | |
994 #if defined(ENABLE_BASIC_PRINTING) | |
995 void PrintWebViewHelper::OnPrintPages() { | |
996 CHECK_LE(ipc_nesting_level_, 1); | |
997 blink::WebLocalFrame* frame; | |
998 if (!GetPrintFrame(&frame)) | |
999 return; | |
1000 // If we are printing a PDF extension frame, find the plugin node and print | |
1001 // that instead. | |
1002 auto plugin = delegate_->GetPdfElement(frame); | |
1003 Print(frame, plugin, false); | |
1004 } | |
1005 | |
1006 void PrintWebViewHelper::OnPrintForSystemDialog() { | |
1007 CHECK_LE(ipc_nesting_level_, 1); | |
1008 blink::WebLocalFrame* frame = print_preview_context_.source_frame(); | |
1009 if (!frame) { | |
1010 NOTREACHED(); | |
1011 return; | |
1012 } | |
1013 Print(frame, print_preview_context_.source_node(), false); | |
1014 } | |
1015 #endif // ENABLE_BASIC_PRINTING | |
1016 | 1040 |
1017 void PrintWebViewHelper::GetPageSizeAndContentAreaFromPageLayout( | 1041 void PrintWebViewHelper::GetPageSizeAndContentAreaFromPageLayout( |
1018 const PageSizeMargins& page_layout_in_points, | 1042 const PageSizeMargins& page_layout_in_points, |
1019 gfx::Size* page_size, | 1043 gfx::Size* page_size, |
1020 gfx::Rect* content_area) { | 1044 gfx::Rect* content_area) { |
1021 *page_size = gfx::Size( | 1045 *page_size = gfx::Size( |
1022 page_layout_in_points.content_width + page_layout_in_points.margin_right + | 1046 page_layout_in_points.content_width + page_layout_in_points.margin_right + |
1023 page_layout_in_points.margin_left, | 1047 page_layout_in_points.margin_left, |
1024 page_layout_in_points.content_height + page_layout_in_points.margin_top + | 1048 page_layout_in_points.content_height + page_layout_in_points.margin_top + |
1025 page_layout_in_points.margin_bottom); | 1049 page_layout_in_points.margin_bottom); |
1026 *content_area = gfx::Rect(page_layout_in_points.margin_left, | 1050 *content_area = gfx::Rect(page_layout_in_points.margin_left, |
1027 page_layout_in_points.margin_top, | 1051 page_layout_in_points.margin_top, |
1028 page_layout_in_points.content_width, | 1052 page_layout_in_points.content_width, |
1029 page_layout_in_points.content_height); | 1053 page_layout_in_points.content_height); |
1030 } | 1054 } |
1031 | 1055 |
1032 void PrintWebViewHelper::UpdateFrameMarginsCssInfo( | 1056 void PrintWebViewHelper::UpdateFrameMarginsCssInfo( |
1033 const base::DictionaryValue& settings) { | 1057 const base::DictionaryValue& settings) { |
1034 int margins_type = 0; | 1058 int margins_type = 0; |
1035 if (!settings.GetInteger(kSettingMarginsType, &margins_type)) | 1059 if (!settings.GetInteger(kSettingMarginsType, &margins_type)) |
1036 margins_type = DEFAULT_MARGINS; | 1060 margins_type = DEFAULT_MARGINS; |
1037 ignore_css_margins_ = (margins_type != DEFAULT_MARGINS); | 1061 ignore_css_margins_ = (margins_type != DEFAULT_MARGINS); |
1038 } | 1062 } |
1039 | 1063 |
1040 bool PrintWebViewHelper::IsPrintToPdfRequested( | 1064 #if defined(ENABLE_PRINT_PREVIEW) |
1041 const base::DictionaryValue& job_settings) { | |
1042 bool print_to_pdf = false; | |
1043 if (!job_settings.GetBoolean(kSettingPrintToPDF, &print_to_pdf)) | |
1044 NOTREACHED(); | |
1045 return print_to_pdf; | |
1046 } | |
1047 | |
1048 void PrintWebViewHelper::OnPrintPreview(const base::DictionaryValue& settings) { | 1065 void PrintWebViewHelper::OnPrintPreview(const base::DictionaryValue& settings) { |
1049 CHECK_LE(ipc_nesting_level_, 1); | 1066 CHECK_LE(ipc_nesting_level_, 1); |
1050 | 1067 |
1051 print_preview_context_.OnPrintPreview(); | 1068 print_preview_context_.OnPrintPreview(); |
1052 | 1069 |
1053 UMA_HISTOGRAM_ENUMERATION("PrintPreview.PreviewEvent", | 1070 UMA_HISTOGRAM_ENUMERATION("PrintPreview.PreviewEvent", |
1054 PREVIEW_EVENT_REQUESTED, PREVIEW_EVENT_MAX); | 1071 PREVIEW_EVENT_REQUESTED, PREVIEW_EVENT_MAX); |
1055 | 1072 |
1056 if (!print_preview_context_.source_frame()) { | 1073 if (!print_preview_context_.source_frame()) { |
1057 DidFinishPrinting(FAIL_PREVIEW); | 1074 DidFinishPrinting(FAIL_PREVIEW); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1225 print_preview_context_.total_page_count(); | 1242 print_preview_context_.total_page_count(); |
1226 preview_params.modifiable = print_preview_context_.IsModifiable(); | 1243 preview_params.modifiable = print_preview_context_.IsModifiable(); |
1227 preview_params.preview_request_id = | 1244 preview_params.preview_request_id = |
1228 print_pages_params_->params.preview_request_id; | 1245 print_pages_params_->params.preview_request_id; |
1229 | 1246 |
1230 is_print_ready_metafile_sent_ = true; | 1247 is_print_ready_metafile_sent_ = true; |
1231 | 1248 |
1232 Send(new PrintHostMsg_MetafileReadyForPrinting(routing_id(), preview_params)); | 1249 Send(new PrintHostMsg_MetafileReadyForPrinting(routing_id(), preview_params)); |
1233 return true; | 1250 return true; |
1234 } | 1251 } |
| 1252 #endif // defined(ENABLE_PRINT_PREVIEW) |
1235 | 1253 |
1236 void PrintWebViewHelper::OnPrintingDone(bool success) { | 1254 void PrintWebViewHelper::OnPrintingDone(bool success) { |
1237 CHECK_LE(ipc_nesting_level_, 1); | 1255 CHECK_LE(ipc_nesting_level_, 1); |
1238 notify_browser_of_print_failure_ = false; | 1256 notify_browser_of_print_failure_ = false; |
1239 if (!success) | 1257 if (!success) |
1240 LOG(ERROR) << "Failure in OnPrintingDone"; | 1258 LOG(ERROR) << "Failure in OnPrintingDone"; |
1241 DidFinishPrinting(success ? OK : FAIL_PRINT); | 1259 DidFinishPrinting(success ? OK : FAIL_PRINT); |
1242 } | 1260 } |
1243 | 1261 |
1244 void PrintWebViewHelper::SetScriptedPrintBlocked(bool blocked) { | 1262 void PrintWebViewHelper::SetScriptedPrintBlocked(bool blocked) { |
1245 is_scripted_printing_blocked_ = blocked; | 1263 is_scripted_printing_blocked_ = blocked; |
1246 } | 1264 } |
1247 | 1265 |
| 1266 #if defined(ENABLE_PRINT_PREVIEW) |
1248 void PrintWebViewHelper::OnInitiatePrintPreview(bool selection_only) { | 1267 void PrintWebViewHelper::OnInitiatePrintPreview(bool selection_only) { |
1249 CHECK_LE(ipc_nesting_level_, 1); | 1268 CHECK_LE(ipc_nesting_level_, 1); |
1250 blink::WebLocalFrame* frame = NULL; | 1269 blink::WebLocalFrame* frame = NULL; |
1251 GetPrintFrame(&frame); | 1270 GetPrintFrame(&frame); |
1252 DCHECK(frame); | 1271 DCHECK(frame); |
1253 // If we are printing a PDF extension frame, find the plugin node and print | 1272 // If we are printing a PDF extension frame, find the plugin node and print |
1254 // that instead. | 1273 // that instead. |
1255 auto plugin = delegate_->GetPdfElement(frame); | 1274 auto plugin = delegate_->GetPdfElement(frame); |
1256 if (!plugin.isNull()) { | 1275 if (!plugin.isNull()) { |
1257 PrintNode(plugin); | 1276 PrintNode(plugin); |
1258 return; | 1277 return; |
1259 } | 1278 } |
1260 print_preview_context_.InitWithFrame(frame); | 1279 print_preview_context_.InitWithFrame(frame); |
1261 RequestPrintPreview(selection_only | 1280 RequestPrintPreview(selection_only |
1262 ? PRINT_PREVIEW_USER_INITIATED_SELECTION | 1281 ? PRINT_PREVIEW_USER_INITIATED_SELECTION |
1263 : PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME); | 1282 : PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME); |
1264 } | 1283 } |
| 1284 #endif |
1265 | 1285 |
1266 bool PrintWebViewHelper::IsPrintingEnabled() { | 1286 bool PrintWebViewHelper::IsPrintingEnabled() { |
1267 bool result = false; | 1287 bool result = false; |
1268 Send(new PrintHostMsg_IsPrintingEnabled(routing_id(), &result)); | 1288 Send(new PrintHostMsg_IsPrintingEnabled(routing_id(), &result)); |
1269 return result; | 1289 return result; |
1270 } | 1290 } |
1271 | 1291 |
1272 void PrintWebViewHelper::PrintNode(const blink::WebNode& node) { | 1292 void PrintWebViewHelper::PrintNode(const blink::WebNode& node) { |
1273 if (node.isNull() || !node.document().frame()) { | 1293 if (node.isNull() || !node.document().frame()) { |
1274 // This can occur when the context menu refers to an invalid WebNode. | 1294 // This can occur when the context menu refers to an invalid WebNode. |
1275 // See http://crbug.com/100890#c17 for a repro case. | 1295 // See http://crbug.com/100890#c17 for a repro case. |
1276 return; | 1296 return; |
1277 } | 1297 } |
1278 | 1298 |
1279 if (print_node_in_progress_) { | 1299 if (print_node_in_progress_) { |
1280 // This can happen as a result of processing sync messages when printing | 1300 // This can happen as a result of processing sync messages when printing |
1281 // from ppapi plugins. It's a rare case, so its OK to just fail here. | 1301 // from ppapi plugins. It's a rare case, so its OK to just fail here. |
1282 // See http://crbug.com/159165. | 1302 // See http://crbug.com/159165. |
1283 return; | 1303 return; |
1284 } | 1304 } |
1285 | 1305 |
1286 print_node_in_progress_ = true; | 1306 print_node_in_progress_ = true; |
1287 | 1307 |
1288 // Make a copy of the node, in case RenderView::OnContextMenuClosed resets | 1308 // Make a copy of the node, in case RenderView::OnContextMenuClosed resets |
1289 // its |context_menu_node_|. | 1309 // its |context_menu_node_|. |
1290 if (!g_is_preview_enabled) { | 1310 if (g_is_preview_enabled) { |
| 1311 #if defined(ENABLE_PRINT_PREVIEW) |
| 1312 print_preview_context_.InitWithNode(node); |
| 1313 RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE); |
| 1314 #endif |
| 1315 } else { |
| 1316 #if defined(ENABLE_BASIC_PRINTING) |
1291 blink::WebNode duplicate_node(node); | 1317 blink::WebNode duplicate_node(node); |
1292 Print(duplicate_node.document().frame(), duplicate_node, false); | 1318 Print(duplicate_node.document().frame(), duplicate_node, false); |
1293 } else { | 1319 #endif |
1294 print_preview_context_.InitWithNode(node); | |
1295 RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE); | |
1296 } | 1320 } |
1297 | 1321 |
1298 print_node_in_progress_ = false; | 1322 print_node_in_progress_ = false; |
1299 } | 1323 } |
1300 | 1324 |
| 1325 #if defined(ENABLE_BASIC_PRINTING) |
1301 void PrintWebViewHelper::Print(blink::WebLocalFrame* frame, | 1326 void PrintWebViewHelper::Print(blink::WebLocalFrame* frame, |
1302 const blink::WebNode& node, | 1327 const blink::WebNode& node, |
1303 bool is_scripted) { | 1328 bool is_scripted) { |
1304 // If still not finished with earlier print request simply ignore. | 1329 // If still not finished with earlier print request simply ignore. |
1305 if (prep_frame_view_) | 1330 if (prep_frame_view_) |
1306 return; | 1331 return; |
1307 | 1332 |
1308 FrameReference frame_ref(frame); | 1333 FrameReference frame_ref(frame); |
1309 | 1334 |
1310 int expected_page_count = 0; | 1335 int expected_page_count = 0; |
(...skipping 16 matching lines...) Expand all Loading... |
1327 return; | 1352 return; |
1328 } | 1353 } |
1329 | 1354 |
1330 // Render Pages for printing. | 1355 // Render Pages for printing. |
1331 if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) { | 1356 if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) { |
1332 LOG(ERROR) << "RenderPagesForPrint failed"; | 1357 LOG(ERROR) << "RenderPagesForPrint failed"; |
1333 DidFinishPrinting(FAIL_PRINT); | 1358 DidFinishPrinting(FAIL_PRINT); |
1334 } | 1359 } |
1335 scripting_throttler_.Reset(); | 1360 scripting_throttler_.Reset(); |
1336 } | 1361 } |
| 1362 #endif // defined(ENABLE_BASIC_PRINTING) |
1337 | 1363 |
1338 void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) { | 1364 void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) { |
1339 switch (result) { | 1365 switch (result) { |
1340 case OK: | 1366 case OK: |
1341 break; | 1367 break; |
1342 | 1368 |
1343 case FAIL_PRINT_INIT: | 1369 case FAIL_PRINT_INIT: |
1344 DCHECK(!notify_browser_of_print_failure_); | 1370 DCHECK(!notify_browser_of_print_failure_); |
1345 break; | 1371 break; |
1346 | 1372 |
1347 case FAIL_PRINT: | 1373 case FAIL_PRINT: |
1348 if (notify_browser_of_print_failure_ && print_pages_params_) { | 1374 if (notify_browser_of_print_failure_ && print_pages_params_) { |
1349 int cookie = print_pages_params_->params.document_cookie; | 1375 int cookie = print_pages_params_->params.document_cookie; |
1350 Send(new PrintHostMsg_PrintingFailed(routing_id(), cookie)); | 1376 Send(new PrintHostMsg_PrintingFailed(routing_id(), cookie)); |
1351 } | 1377 } |
1352 break; | 1378 break; |
1353 | 1379 |
| 1380 #if defined(ENABLE_PRINT_PREVIEW) |
1354 case FAIL_PREVIEW: | 1381 case FAIL_PREVIEW: |
1355 int cookie = | 1382 int cookie = |
1356 print_pages_params_ ? print_pages_params_->params.document_cookie : 0; | 1383 print_pages_params_ ? print_pages_params_->params.document_cookie : 0; |
1357 if (notify_browser_of_print_failure_) { | 1384 if (notify_browser_of_print_failure_) { |
1358 LOG(ERROR) << "CreatePreviewDocument failed"; | 1385 LOG(ERROR) << "CreatePreviewDocument failed"; |
1359 Send(new PrintHostMsg_PrintPreviewFailed(routing_id(), cookie)); | 1386 Send(new PrintHostMsg_PrintPreviewFailed(routing_id(), cookie)); |
1360 } else { | 1387 } else { |
1361 Send(new PrintHostMsg_PrintPreviewCancelled(routing_id(), cookie)); | 1388 Send(new PrintHostMsg_PrintPreviewCancelled(routing_id(), cookie)); |
1362 } | 1389 } |
1363 print_preview_context_.Failed(notify_browser_of_print_failure_); | 1390 print_preview_context_.Failed(notify_browser_of_print_failure_); |
1364 break; | 1391 break; |
| 1392 #endif // defined(ENABLE_PRINT_PREVIEW) |
1365 } | 1393 } |
1366 prep_frame_view_.reset(); | 1394 prep_frame_view_.reset(); |
1367 print_pages_params_.reset(); | 1395 print_pages_params_.reset(); |
1368 notify_browser_of_print_failure_ = true; | 1396 notify_browser_of_print_failure_ = true; |
1369 } | 1397 } |
1370 | 1398 |
| 1399 #if defined(ENABLE_BASIC_PRINTING) |
1371 void PrintWebViewHelper::OnFramePreparedForPrintPages() { | 1400 void PrintWebViewHelper::OnFramePreparedForPrintPages() { |
1372 PrintPages(); | 1401 PrintPages(); |
1373 FinishFramePrinting(); | 1402 FinishFramePrinting(); |
1374 } | 1403 } |
1375 | 1404 |
1376 void PrintWebViewHelper::PrintPages() { | 1405 void PrintWebViewHelper::PrintPages() { |
1377 if (!prep_frame_view_) // Printing is already canceled or failed. | 1406 if (!prep_frame_view_) // Printing is already canceled or failed. |
1378 return; | 1407 return; |
| 1408 |
1379 prep_frame_view_->StartPrinting(); | 1409 prep_frame_view_->StartPrinting(); |
1380 | 1410 |
1381 int page_count = prep_frame_view_->GetExpectedPageCount(); | 1411 int page_count = prep_frame_view_->GetExpectedPageCount(); |
1382 if (!page_count) { | 1412 if (!page_count) { |
1383 LOG(ERROR) << "Can't print 0 pages."; | 1413 LOG(ERROR) << "Can't print 0 pages."; |
1384 return DidFinishPrinting(FAIL_PRINT); | 1414 return DidFinishPrinting(FAIL_PRINT); |
1385 } | 1415 } |
1386 | 1416 |
1387 const PrintMsg_PrintPages_Params& params = *print_pages_params_; | 1417 const PrintMsg_PrintPages_Params& params = *print_pages_params_; |
1388 const PrintMsg_Print_Params& print_params = params.params; | 1418 const PrintMsg_Print_Params& print_params = params.params; |
1389 | 1419 |
1390 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | 1420 #if !defined(OS_ANDROID) |
1391 // TODO(vitalybuka): should be page_count or valid pages from params.pages. | 1421 // TODO(vitalybuka): should be page_count or valid pages from params.pages. |
1392 // See http://crbug.com/161576 | 1422 // See http://crbug.com/161576 |
1393 Send(new PrintHostMsg_DidGetPrintedPagesCount(routing_id(), | 1423 Send(new PrintHostMsg_DidGetPrintedPagesCount(routing_id(), |
1394 print_params.document_cookie, | 1424 print_params.document_cookie, |
1395 page_count)); | 1425 page_count)); |
1396 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | 1426 #endif // !defined(OS_ANDROID) |
1397 | 1427 |
1398 if (print_params.preview_ui_id < 0) { | 1428 if (print_params.preview_ui_id < 0) { |
1399 // Printing for system dialog. | 1429 // Printing for system dialog. |
1400 int printed_count = params.pages.empty() ? page_count : params.pages.size(); | 1430 int printed_count = params.pages.empty() ? page_count : params.pages.size(); |
1401 #if defined(OS_CHROMEOS) | |
1402 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToCloudPrintWebDialog", | |
1403 printed_count); | |
1404 #else | |
1405 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.SystemDialog", printed_count); | 1431 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.SystemDialog", printed_count); |
1406 #endif // defined(OS_CHROMEOS) | |
1407 } | 1432 } |
1408 | 1433 |
1409 if (!PrintPagesNative(prep_frame_view_->frame(), page_count)) { | 1434 if (!PrintPagesNative(prep_frame_view_->frame(), page_count)) { |
1410 LOG(ERROR) << "Printing failed."; | 1435 LOG(ERROR) << "Printing failed."; |
1411 return DidFinishPrinting(FAIL_PRINT); | 1436 return DidFinishPrinting(FAIL_PRINT); |
1412 } | 1437 } |
1413 } | 1438 } |
1414 | 1439 |
1415 void PrintWebViewHelper::FinishFramePrinting() { | 1440 void PrintWebViewHelper::FinishFramePrinting() { |
1416 prep_frame_view_.reset(); | 1441 prep_frame_view_.reset(); |
1417 } | 1442 } |
| 1443 #endif // defined(ENABLE_BASIC_PRINTING) |
1418 | 1444 |
1419 // static - Not anonymous so that platform implementations can use it. | 1445 // static - Not anonymous so that platform implementations can use it. |
1420 void PrintWebViewHelper::ComputePageLayoutInPointsForCss( | 1446 void PrintWebViewHelper::ComputePageLayoutInPointsForCss( |
1421 blink::WebFrame* frame, | 1447 blink::WebFrame* frame, |
1422 int page_index, | 1448 int page_index, |
1423 const PrintMsg_Print_Params& page_params, | 1449 const PrintMsg_Print_Params& page_params, |
1424 bool ignore_css_margins, | 1450 bool ignore_css_margins, |
1425 double* scale_factor, | 1451 double* scale_factor, |
1426 PageSizeMargins* page_layout_in_points) { | 1452 PageSizeMargins* page_layout_in_points) { |
1427 PrintMsg_Print_Params params = CalculatePrintParamsForCss( | 1453 PrintMsg_Print_Params params = CalculatePrintParamsForCss( |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1488 } | 1514 } |
1489 | 1515 |
1490 const PrintMsg_Print_Params& params = print_pages_params_->params; | 1516 const PrintMsg_Print_Params& params = print_pages_params_->params; |
1491 PrepareFrameAndViewForPrint prepare(params, frame, node, ignore_css_margins_); | 1517 PrepareFrameAndViewForPrint prepare(params, frame, node, ignore_css_margins_); |
1492 prepare.StartPrinting(); | 1518 prepare.StartPrinting(); |
1493 | 1519 |
1494 *number_of_pages = prepare.GetExpectedPageCount(); | 1520 *number_of_pages = prepare.GetExpectedPageCount(); |
1495 return true; | 1521 return true; |
1496 } | 1522 } |
1497 | 1523 |
| 1524 #if defined(ENABLE_PRINT_PREVIEW) |
1498 bool PrintWebViewHelper::SetOptionsFromPdfDocument( | 1525 bool PrintWebViewHelper::SetOptionsFromPdfDocument( |
1499 PrintHostMsg_SetOptionsFromDocument_Params* options) { | 1526 PrintHostMsg_SetOptionsFromDocument_Params* options) { |
1500 blink::WebLocalFrame* source_frame = print_preview_context_.source_frame(); | 1527 blink::WebLocalFrame* source_frame = print_preview_context_.source_frame(); |
1501 const blink::WebNode& source_node = print_preview_context_.source_node(); | 1528 const blink::WebNode& source_node = print_preview_context_.source_node(); |
1502 | 1529 |
1503 blink::WebPrintPresetOptions preset_options; | 1530 blink::WebPrintPresetOptions preset_options; |
1504 if (!source_frame->getPrintPresetOptionsForPlugin(source_node, | 1531 if (!source_frame->getPrintPresetOptionsForPlugin(source_node, |
1505 &preset_options)) { | 1532 &preset_options)) { |
1506 return false; | 1533 return false; |
1507 } | 1534 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1596 if (!print_for_preview_) | 1623 if (!print_for_preview_) |
1597 print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS); | 1624 print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS); |
1598 else | 1625 else |
1599 Send(new PrintHostMsg_ShowInvalidPrinterSettingsError(routing_id())); | 1626 Send(new PrintHostMsg_ShowInvalidPrinterSettingsError(routing_id())); |
1600 | 1627 |
1601 return false; | 1628 return false; |
1602 } | 1629 } |
1603 | 1630 |
1604 return true; | 1631 return true; |
1605 } | 1632 } |
| 1633 #endif // defined(ENABLE_PRINT_PREVIEW) |
1606 | 1634 |
| 1635 #if defined(ENABLE_BASIC_PRINTING) |
1607 bool PrintWebViewHelper::GetPrintSettingsFromUser(blink::WebLocalFrame* frame, | 1636 bool PrintWebViewHelper::GetPrintSettingsFromUser(blink::WebLocalFrame* frame, |
1608 const blink::WebNode& node, | 1637 const blink::WebNode& node, |
1609 int expected_pages_count, | 1638 int expected_pages_count, |
1610 bool is_scripted) { | 1639 bool is_scripted) { |
1611 PrintHostMsg_ScriptedPrint_Params params; | 1640 PrintHostMsg_ScriptedPrint_Params params; |
1612 PrintMsg_PrintPages_Params print_settings; | 1641 PrintMsg_PrintPages_Params print_settings; |
1613 | 1642 |
1614 params.cookie = print_pages_params_->params.document_cookie; | 1643 params.cookie = print_pages_params_->params.document_cookie; |
1615 params.has_selection = frame->hasSelection(); | 1644 params.has_selection = frame->hasSelection(); |
1616 params.expected_pages_count = expected_pages_count; | 1645 params.expected_pages_count = expected_pages_count; |
(...skipping 19 matching lines...) Expand all Loading... |
1636 Send(msg); | 1665 Send(msg); |
1637 print_settings.params.print_scaling_option = scaling_option; | 1666 print_settings.params.print_scaling_option = scaling_option; |
1638 SetPrintPagesParams(print_settings); | 1667 SetPrintPagesParams(print_settings); |
1639 return (print_settings.params.dpi && print_settings.params.document_cookie); | 1668 return (print_settings.params.dpi && print_settings.params.document_cookie); |
1640 } | 1669 } |
1641 | 1670 |
1642 bool PrintWebViewHelper::RenderPagesForPrint(blink::WebLocalFrame* frame, | 1671 bool PrintWebViewHelper::RenderPagesForPrint(blink::WebLocalFrame* frame, |
1643 const blink::WebNode& node) { | 1672 const blink::WebNode& node) { |
1644 if (!frame || prep_frame_view_) | 1673 if (!frame || prep_frame_view_) |
1645 return false; | 1674 return false; |
| 1675 |
1646 const PrintMsg_PrintPages_Params& params = *print_pages_params_; | 1676 const PrintMsg_PrintPages_Params& params = *print_pages_params_; |
1647 const PrintMsg_Print_Params& print_params = params.params; | 1677 const PrintMsg_Print_Params& print_params = params.params; |
1648 prep_frame_view_.reset(new PrepareFrameAndViewForPrint( | 1678 prep_frame_view_.reset(new PrepareFrameAndViewForPrint( |
1649 print_params, frame, node, ignore_css_margins_)); | 1679 print_params, frame, node, ignore_css_margins_)); |
1650 DCHECK(!print_pages_params_->params.selection_only || | 1680 DCHECK(!print_pages_params_->params.selection_only || |
1651 print_pages_params_->pages.empty()); | 1681 print_pages_params_->pages.empty()); |
1652 prep_frame_view_->CopySelectionIfNeeded( | 1682 prep_frame_view_->CopySelectionIfNeeded( |
1653 render_view()->GetWebkitPreferences(), | 1683 render_view()->GetWebkitPreferences(), |
1654 base::Bind(&PrintWebViewHelper::OnFramePreparedForPrintPages, | 1684 base::Bind(&PrintWebViewHelper::OnFramePreparedForPrintPages, |
1655 base::Unretained(this))); | 1685 base::Unretained(this))); |
1656 return true; | 1686 return true; |
1657 } | 1687 } |
| 1688 #endif // defined(ENABLE_BASIC_PRINTING) |
1658 | 1689 |
1659 #if defined(OS_POSIX) | 1690 #if defined(OS_POSIX) |
1660 bool PrintWebViewHelper::CopyMetafileDataToSharedMem( | 1691 bool PrintWebViewHelper::CopyMetafileDataToSharedMem( |
1661 const PdfMetafileSkia& metafile, | 1692 const PdfMetafileSkia& metafile, |
1662 base::SharedMemoryHandle* shared_mem_handle) { | 1693 base::SharedMemoryHandle* shared_mem_handle) { |
1663 uint32_t buf_size = metafile.GetDataSize(); | 1694 uint32_t buf_size = metafile.GetDataSize(); |
1664 if (buf_size == 0) | 1695 if (buf_size == 0) |
1665 return false; | 1696 return false; |
1666 | 1697 |
1667 scoped_ptr<base::SharedMemory> shared_buf( | 1698 scoped_ptr<base::SharedMemory> shared_buf( |
1668 content::RenderThread::Get()->HostAllocateSharedMemoryBuffer(buf_size)); | 1699 content::RenderThread::Get()->HostAllocateSharedMemoryBuffer(buf_size)); |
1669 if (!shared_buf) | 1700 if (!shared_buf) |
1670 return false; | 1701 return false; |
1671 | 1702 |
1672 if (!shared_buf->Map(buf_size)) | 1703 if (!shared_buf->Map(buf_size)) |
1673 return false; | 1704 return false; |
1674 | 1705 |
1675 if (!metafile.GetData(shared_buf->memory(), buf_size)) | 1706 if (!metafile.GetData(shared_buf->memory(), buf_size)) |
1676 return false; | 1707 return false; |
1677 | 1708 |
1678 return shared_buf->GiveToProcess(base::GetCurrentProcessHandle(), | 1709 return shared_buf->GiveToProcess(base::GetCurrentProcessHandle(), |
1679 shared_mem_handle); | 1710 shared_mem_handle); |
1680 } | 1711 } |
1681 #endif // defined(OS_POSIX) | 1712 #endif // defined(OS_POSIX) |
1682 | 1713 |
| 1714 #if defined(ENABLE_PRINT_PREVIEW) |
1683 void PrintWebViewHelper::ShowScriptedPrintPreview() { | 1715 void PrintWebViewHelper::ShowScriptedPrintPreview() { |
1684 if (is_scripted_preview_delayed_) { | 1716 if (is_scripted_preview_delayed_) { |
1685 is_scripted_preview_delayed_ = false; | 1717 is_scripted_preview_delayed_ = false; |
1686 Send(new PrintHostMsg_ShowScriptedPrintPreview( | 1718 Send(new PrintHostMsg_ShowScriptedPrintPreview( |
1687 routing_id(), print_preview_context_.IsModifiable())); | 1719 routing_id(), print_preview_context_.IsModifiable())); |
1688 } | 1720 } |
1689 } | 1721 } |
1690 | 1722 |
1691 void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) { | 1723 void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) { |
1692 const bool is_modifiable = print_preview_context_.IsModifiable(); | 1724 const bool is_modifiable = print_preview_context_.IsModifiable(); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1800 return false; | 1832 return false; |
1801 } | 1833 } |
1802 preview_page_params.data_size = metafile->GetDataSize(); | 1834 preview_page_params.data_size = metafile->GetDataSize(); |
1803 preview_page_params.page_number = page_number; | 1835 preview_page_params.page_number = page_number; |
1804 preview_page_params.preview_request_id = | 1836 preview_page_params.preview_request_id = |
1805 print_pages_params_->params.preview_request_id; | 1837 print_pages_params_->params.preview_request_id; |
1806 | 1838 |
1807 Send(new PrintHostMsg_DidPreviewPage(routing_id(), preview_page_params)); | 1839 Send(new PrintHostMsg_DidPreviewPage(routing_id(), preview_page_params)); |
1808 return true; | 1840 return true; |
1809 } | 1841 } |
| 1842 #endif // defined(ENABLE_PRINT_PREVIEW) |
1810 | 1843 |
1811 PrintWebViewHelper::PrintPreviewContext::PrintPreviewContext() | 1844 PrintWebViewHelper::PrintPreviewContext::PrintPreviewContext() |
1812 : total_page_count_(0), | 1845 : total_page_count_(0), |
1813 current_page_index_(0), | 1846 current_page_index_(0), |
1814 generate_draft_pages_(true), | 1847 generate_draft_pages_(true), |
1815 print_ready_metafile_page_count_(0), | 1848 print_ready_metafile_page_count_(0), |
1816 error_(PREVIEW_ERROR_NONE), | 1849 error_(PREVIEW_ERROR_NONE), |
1817 state_(UNINITIALIZED) { | 1850 state_(UNINITIALIZED) { |
1818 } | 1851 } |
1819 | 1852 |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2091 blink::WebConsoleMessage::LevelWarning, message)); | 2124 blink::WebConsoleMessage::LevelWarning, message)); |
2092 return false; | 2125 return false; |
2093 } | 2126 } |
2094 | 2127 |
2095 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2128 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
2096 // Reset counter on successful print. | 2129 // Reset counter on successful print. |
2097 count_ = 0; | 2130 count_ = 0; |
2098 } | 2131 } |
2099 | 2132 |
2100 } // namespace printing | 2133 } // namespace printing |
OLD | NEW |