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 if (ipc_nesting_level_> 1) |
| 954 return; |
| 955 blink::WebLocalFrame* frame; |
| 956 if (!GetPrintFrame(&frame)) |
| 957 return; |
| 958 // If we are printing a PDF extension frame, find the plugin node and print |
| 959 // that instead. |
| 960 auto plugin = delegate_->GetPdfElement(frame); |
| 961 Print(frame, plugin, false); |
| 962 } |
| 963 |
| 964 void PrintWebViewHelper::OnPrintForSystemDialog() { |
| 965 if (ipc_nesting_level_> 1) |
| 966 return; |
| 967 blink::WebLocalFrame* frame = print_preview_context_.source_frame(); |
| 968 if (!frame) { |
| 969 NOTREACHED(); |
| 970 return; |
| 971 } |
| 972 Print(frame, print_preview_context_.source_node(), false); |
| 973 } |
| 974 #endif // defined(ENABLE_BASIC_PRINTING) |
| 975 |
| 976 #if defined(ENABLE_BASIC_PRINTING) && defined(ENABLE_PRINT_PREVIEW) |
912 void PrintWebViewHelper::OnPrintForPrintPreview( | 977 void PrintWebViewHelper::OnPrintForPrintPreview( |
913 const base::DictionaryValue& job_settings) { | 978 const base::DictionaryValue& job_settings) { |
914 CHECK_LE(ipc_nesting_level_, 1); | 979 CHECK_LE(ipc_nesting_level_, 1); |
915 // If still not finished with earlier print request simply ignore. | 980 // If still not finished with earlier print request simply ignore. |
916 if (prep_frame_view_) | 981 if (prep_frame_view_) |
917 return; | 982 return; |
918 | 983 |
919 if (!render_view()->GetWebView()) | 984 if (!render_view()->GetWebView()) |
920 return; | 985 return; |
921 blink::WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); | 986 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 | 1031 // See http://crbug.com/123408 |
967 PrintMsg_Print_Params& print_params = print_pages_params_->params; | 1032 PrintMsg_Print_Params& print_params = print_pages_params_->params; |
968 print_params.printable_area = gfx::Rect(print_params.page_size); | 1033 print_params.printable_area = gfx::Rect(print_params.page_size); |
969 | 1034 |
970 // Render Pages for printing. | 1035 // Render Pages for printing. |
971 if (!RenderPagesForPrint(plugin_frame, plugin_element)) { | 1036 if (!RenderPagesForPrint(plugin_frame, plugin_element)) { |
972 LOG(ERROR) << "RenderPagesForPrint failed"; | 1037 LOG(ERROR) << "RenderPagesForPrint failed"; |
973 DidFinishPrinting(FAIL_PRINT); | 1038 DidFinishPrinting(FAIL_PRINT); |
974 } | 1039 } |
975 } | 1040 } |
976 | 1041 #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 if (ipc_nesting_level_> 1) | |
997 return; | |
998 blink::WebLocalFrame* frame; | |
999 if (!GetPrintFrame(&frame)) | |
1000 return; | |
1001 // If we are printing a PDF extension frame, find the plugin node and print | |
1002 // that instead. | |
1003 auto plugin = delegate_->GetPdfElement(frame); | |
1004 Print(frame, plugin, false); | |
1005 } | |
1006 | |
1007 void PrintWebViewHelper::OnPrintForSystemDialog() { | |
1008 if (ipc_nesting_level_> 1) | |
1009 return; | |
1010 blink::WebLocalFrame* frame = print_preview_context_.source_frame(); | |
1011 if (!frame) { | |
1012 NOTREACHED(); | |
1013 return; | |
1014 } | |
1015 Print(frame, print_preview_context_.source_node(), false); | |
1016 } | |
1017 #endif // ENABLE_BASIC_PRINTING | |
1018 | 1042 |
1019 void PrintWebViewHelper::GetPageSizeAndContentAreaFromPageLayout( | 1043 void PrintWebViewHelper::GetPageSizeAndContentAreaFromPageLayout( |
1020 const PageSizeMargins& page_layout_in_points, | 1044 const PageSizeMargins& page_layout_in_points, |
1021 gfx::Size* page_size, | 1045 gfx::Size* page_size, |
1022 gfx::Rect* content_area) { | 1046 gfx::Rect* content_area) { |
1023 *page_size = gfx::Size( | 1047 *page_size = gfx::Size( |
1024 page_layout_in_points.content_width + page_layout_in_points.margin_right + | 1048 page_layout_in_points.content_width + page_layout_in_points.margin_right + |
1025 page_layout_in_points.margin_left, | 1049 page_layout_in_points.margin_left, |
1026 page_layout_in_points.content_height + page_layout_in_points.margin_top + | 1050 page_layout_in_points.content_height + page_layout_in_points.margin_top + |
1027 page_layout_in_points.margin_bottom); | 1051 page_layout_in_points.margin_bottom); |
1028 *content_area = gfx::Rect(page_layout_in_points.margin_left, | 1052 *content_area = gfx::Rect(page_layout_in_points.margin_left, |
1029 page_layout_in_points.margin_top, | 1053 page_layout_in_points.margin_top, |
1030 page_layout_in_points.content_width, | 1054 page_layout_in_points.content_width, |
1031 page_layout_in_points.content_height); | 1055 page_layout_in_points.content_height); |
1032 } | 1056 } |
1033 | 1057 |
1034 void PrintWebViewHelper::UpdateFrameMarginsCssInfo( | 1058 void PrintWebViewHelper::UpdateFrameMarginsCssInfo( |
1035 const base::DictionaryValue& settings) { | 1059 const base::DictionaryValue& settings) { |
1036 int margins_type = 0; | 1060 int margins_type = 0; |
1037 if (!settings.GetInteger(kSettingMarginsType, &margins_type)) | 1061 if (!settings.GetInteger(kSettingMarginsType, &margins_type)) |
1038 margins_type = DEFAULT_MARGINS; | 1062 margins_type = DEFAULT_MARGINS; |
1039 ignore_css_margins_ = (margins_type != DEFAULT_MARGINS); | 1063 ignore_css_margins_ = (margins_type != DEFAULT_MARGINS); |
1040 } | 1064 } |
1041 | 1065 |
1042 bool PrintWebViewHelper::IsPrintToPdfRequested( | 1066 #if defined(ENABLE_PRINT_PREVIEW) |
1043 const base::DictionaryValue& job_settings) { | |
1044 bool print_to_pdf = false; | |
1045 if (!job_settings.GetBoolean(kSettingPrintToPDF, &print_to_pdf)) | |
1046 NOTREACHED(); | |
1047 return print_to_pdf; | |
1048 } | |
1049 | |
1050 void PrintWebViewHelper::OnPrintPreview(const base::DictionaryValue& settings) { | 1067 void PrintWebViewHelper::OnPrintPreview(const base::DictionaryValue& settings) { |
1051 if (ipc_nesting_level_ > 1) | 1068 if (ipc_nesting_level_ > 1) |
1052 return; | 1069 return; |
1053 | 1070 |
1054 print_preview_context_.OnPrintPreview(); | 1071 print_preview_context_.OnPrintPreview(); |
1055 | 1072 |
1056 UMA_HISTOGRAM_ENUMERATION("PrintPreview.PreviewEvent", | 1073 UMA_HISTOGRAM_ENUMERATION("PrintPreview.PreviewEvent", |
1057 PREVIEW_EVENT_REQUESTED, PREVIEW_EVENT_MAX); | 1074 PREVIEW_EVENT_REQUESTED, PREVIEW_EVENT_MAX); |
1058 | 1075 |
1059 if (!print_preview_context_.source_frame()) { | 1076 if (!print_preview_context_.source_frame()) { |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1228 print_preview_context_.total_page_count(); | 1245 print_preview_context_.total_page_count(); |
1229 preview_params.modifiable = print_preview_context_.IsModifiable(); | 1246 preview_params.modifiable = print_preview_context_.IsModifiable(); |
1230 preview_params.preview_request_id = | 1247 preview_params.preview_request_id = |
1231 print_pages_params_->params.preview_request_id; | 1248 print_pages_params_->params.preview_request_id; |
1232 | 1249 |
1233 is_print_ready_metafile_sent_ = true; | 1250 is_print_ready_metafile_sent_ = true; |
1234 | 1251 |
1235 Send(new PrintHostMsg_MetafileReadyForPrinting(routing_id(), preview_params)); | 1252 Send(new PrintHostMsg_MetafileReadyForPrinting(routing_id(), preview_params)); |
1236 return true; | 1253 return true; |
1237 } | 1254 } |
| 1255 #endif // defined(ENABLE_PRINT_PREVIEW) |
1238 | 1256 |
1239 void PrintWebViewHelper::OnPrintingDone(bool success) { | 1257 void PrintWebViewHelper::OnPrintingDone(bool success) { |
1240 if (ipc_nesting_level_ > 1) | 1258 if (ipc_nesting_level_ > 1) |
1241 return; | 1259 return; |
1242 notify_browser_of_print_failure_ = false; | 1260 notify_browser_of_print_failure_ = false; |
1243 if (!success) | 1261 if (!success) |
1244 LOG(ERROR) << "Failure in OnPrintingDone"; | 1262 LOG(ERROR) << "Failure in OnPrintingDone"; |
1245 DidFinishPrinting(success ? OK : FAIL_PRINT); | 1263 DidFinishPrinting(success ? OK : FAIL_PRINT); |
1246 } | 1264 } |
1247 | 1265 |
1248 void PrintWebViewHelper::SetScriptedPrintBlocked(bool blocked) { | 1266 void PrintWebViewHelper::SetScriptedPrintBlocked(bool blocked) { |
1249 is_scripted_printing_blocked_ = blocked; | 1267 is_scripted_printing_blocked_ = blocked; |
1250 } | 1268 } |
1251 | 1269 |
| 1270 #if defined(ENABLE_PRINT_PREVIEW) |
1252 void PrintWebViewHelper::OnInitiatePrintPreview(bool selection_only) { | 1271 void PrintWebViewHelper::OnInitiatePrintPreview(bool selection_only) { |
1253 if (ipc_nesting_level_ > 1) | 1272 if (ipc_nesting_level_ > 1) |
1254 return; | 1273 return; |
1255 blink::WebLocalFrame* frame = NULL; | 1274 blink::WebLocalFrame* frame = NULL; |
1256 GetPrintFrame(&frame); | 1275 GetPrintFrame(&frame); |
1257 DCHECK(frame); | 1276 DCHECK(frame); |
1258 // If we are printing a PDF extension frame, find the plugin node and print | 1277 // If we are printing a PDF extension frame, find the plugin node and print |
1259 // that instead. | 1278 // that instead. |
1260 auto plugin = delegate_->GetPdfElement(frame); | 1279 auto plugin = delegate_->GetPdfElement(frame); |
1261 if (!plugin.isNull()) { | 1280 if (!plugin.isNull()) { |
1262 PrintNode(plugin); | 1281 PrintNode(plugin); |
1263 return; | 1282 return; |
1264 } | 1283 } |
1265 print_preview_context_.InitWithFrame(frame); | 1284 print_preview_context_.InitWithFrame(frame); |
1266 RequestPrintPreview(selection_only | 1285 RequestPrintPreview(selection_only |
1267 ? PRINT_PREVIEW_USER_INITIATED_SELECTION | 1286 ? PRINT_PREVIEW_USER_INITIATED_SELECTION |
1268 : PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME); | 1287 : PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME); |
1269 } | 1288 } |
| 1289 #endif |
1270 | 1290 |
1271 bool PrintWebViewHelper::IsPrintingEnabled() { | 1291 bool PrintWebViewHelper::IsPrintingEnabled() { |
1272 bool result = false; | 1292 bool result = false; |
1273 Send(new PrintHostMsg_IsPrintingEnabled(routing_id(), &result)); | 1293 Send(new PrintHostMsg_IsPrintingEnabled(routing_id(), &result)); |
1274 return result; | 1294 return result; |
1275 } | 1295 } |
1276 | 1296 |
1277 void PrintWebViewHelper::PrintNode(const blink::WebNode& node) { | 1297 void PrintWebViewHelper::PrintNode(const blink::WebNode& node) { |
1278 if (node.isNull() || !node.document().frame()) { | 1298 if (node.isNull() || !node.document().frame()) { |
1279 // This can occur when the context menu refers to an invalid WebNode. | 1299 // This can occur when the context menu refers to an invalid WebNode. |
1280 // See http://crbug.com/100890#c17 for a repro case. | 1300 // See http://crbug.com/100890#c17 for a repro case. |
1281 return; | 1301 return; |
1282 } | 1302 } |
1283 | 1303 |
1284 if (print_node_in_progress_) { | 1304 if (print_node_in_progress_) { |
1285 // This can happen as a result of processing sync messages when printing | 1305 // This can happen as a result of processing sync messages when printing |
1286 // from ppapi plugins. It's a rare case, so its OK to just fail here. | 1306 // from ppapi plugins. It's a rare case, so its OK to just fail here. |
1287 // See http://crbug.com/159165. | 1307 // See http://crbug.com/159165. |
1288 return; | 1308 return; |
1289 } | 1309 } |
1290 | 1310 |
1291 print_node_in_progress_ = true; | 1311 print_node_in_progress_ = true; |
1292 | 1312 |
1293 // Make a copy of the node, in case RenderView::OnContextMenuClosed resets | 1313 // Make a copy of the node, in case RenderView::OnContextMenuClosed resets |
1294 // its |context_menu_node_|. | 1314 // its |context_menu_node_|. |
1295 if (!g_is_preview_enabled) { | 1315 if (g_is_preview_enabled) { |
| 1316 #if defined(ENABLE_PRINT_PREVIEW) |
| 1317 print_preview_context_.InitWithNode(node); |
| 1318 RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE); |
| 1319 #endif |
| 1320 } else { |
| 1321 #if defined(ENABLE_BASIC_PRINTING) |
1296 blink::WebNode duplicate_node(node); | 1322 blink::WebNode duplicate_node(node); |
1297 Print(duplicate_node.document().frame(), duplicate_node, false); | 1323 Print(duplicate_node.document().frame(), duplicate_node, false); |
1298 } else { | 1324 #endif |
1299 print_preview_context_.InitWithNode(node); | |
1300 RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE); | |
1301 } | 1325 } |
1302 | 1326 |
1303 print_node_in_progress_ = false; | 1327 print_node_in_progress_ = false; |
1304 } | 1328 } |
1305 | 1329 |
| 1330 #if defined(ENABLE_BASIC_PRINTING) |
1306 void PrintWebViewHelper::Print(blink::WebLocalFrame* frame, | 1331 void PrintWebViewHelper::Print(blink::WebLocalFrame* frame, |
1307 const blink::WebNode& node, | 1332 const blink::WebNode& node, |
1308 bool is_scripted) { | 1333 bool is_scripted) { |
1309 // If still not finished with earlier print request simply ignore. | 1334 // If still not finished with earlier print request simply ignore. |
1310 if (prep_frame_view_) | 1335 if (prep_frame_view_) |
1311 return; | 1336 return; |
1312 | 1337 |
1313 FrameReference frame_ref(frame); | 1338 FrameReference frame_ref(frame); |
1314 | 1339 |
1315 int expected_page_count = 0; | 1340 int expected_page_count = 0; |
(...skipping 16 matching lines...) Expand all Loading... |
1332 return; | 1357 return; |
1333 } | 1358 } |
1334 | 1359 |
1335 // Render Pages for printing. | 1360 // Render Pages for printing. |
1336 if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) { | 1361 if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) { |
1337 LOG(ERROR) << "RenderPagesForPrint failed"; | 1362 LOG(ERROR) << "RenderPagesForPrint failed"; |
1338 DidFinishPrinting(FAIL_PRINT); | 1363 DidFinishPrinting(FAIL_PRINT); |
1339 } | 1364 } |
1340 scripting_throttler_.Reset(); | 1365 scripting_throttler_.Reset(); |
1341 } | 1366 } |
| 1367 #endif // defined(ENABLE_BASIC_PRINTING) |
1342 | 1368 |
1343 void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) { | 1369 void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) { |
1344 switch (result) { | 1370 switch (result) { |
1345 case OK: | 1371 case OK: |
1346 break; | 1372 break; |
1347 | 1373 |
1348 case FAIL_PRINT_INIT: | 1374 case FAIL_PRINT_INIT: |
1349 DCHECK(!notify_browser_of_print_failure_); | 1375 DCHECK(!notify_browser_of_print_failure_); |
1350 break; | 1376 break; |
1351 | 1377 |
1352 case FAIL_PRINT: | 1378 case FAIL_PRINT: |
1353 if (notify_browser_of_print_failure_ && print_pages_params_) { | 1379 if (notify_browser_of_print_failure_ && print_pages_params_) { |
1354 int cookie = print_pages_params_->params.document_cookie; | 1380 int cookie = print_pages_params_->params.document_cookie; |
1355 Send(new PrintHostMsg_PrintingFailed(routing_id(), cookie)); | 1381 Send(new PrintHostMsg_PrintingFailed(routing_id(), cookie)); |
1356 } | 1382 } |
1357 break; | 1383 break; |
1358 | 1384 |
| 1385 #if defined(ENABLE_PRINT_PREVIEW) |
1359 case FAIL_PREVIEW: | 1386 case FAIL_PREVIEW: |
1360 int cookie = | 1387 int cookie = |
1361 print_pages_params_ ? print_pages_params_->params.document_cookie : 0; | 1388 print_pages_params_ ? print_pages_params_->params.document_cookie : 0; |
1362 if (notify_browser_of_print_failure_) { | 1389 if (notify_browser_of_print_failure_) { |
1363 LOG(ERROR) << "CreatePreviewDocument failed"; | 1390 LOG(ERROR) << "CreatePreviewDocument failed"; |
1364 Send(new PrintHostMsg_PrintPreviewFailed(routing_id(), cookie)); | 1391 Send(new PrintHostMsg_PrintPreviewFailed(routing_id(), cookie)); |
1365 } else { | 1392 } else { |
1366 Send(new PrintHostMsg_PrintPreviewCancelled(routing_id(), cookie)); | 1393 Send(new PrintHostMsg_PrintPreviewCancelled(routing_id(), cookie)); |
1367 } | 1394 } |
1368 print_preview_context_.Failed(notify_browser_of_print_failure_); | 1395 print_preview_context_.Failed(notify_browser_of_print_failure_); |
1369 break; | 1396 break; |
| 1397 #endif // defined(ENABLE_PRINT_PREVIEW) |
1370 } | 1398 } |
1371 prep_frame_view_.reset(); | 1399 prep_frame_view_.reset(); |
1372 print_pages_params_.reset(); | 1400 print_pages_params_.reset(); |
1373 notify_browser_of_print_failure_ = true; | 1401 notify_browser_of_print_failure_ = true; |
1374 } | 1402 } |
1375 | 1403 |
| 1404 #if defined(ENABLE_BASIC_PRINTING) |
1376 void PrintWebViewHelper::OnFramePreparedForPrintPages() { | 1405 void PrintWebViewHelper::OnFramePreparedForPrintPages() { |
1377 PrintPages(); | 1406 PrintPages(); |
1378 FinishFramePrinting(); | 1407 FinishFramePrinting(); |
1379 } | 1408 } |
1380 | 1409 |
1381 void PrintWebViewHelper::PrintPages() { | 1410 void PrintWebViewHelper::PrintPages() { |
1382 if (!prep_frame_view_) // Printing is already canceled or failed. | 1411 if (!prep_frame_view_) // Printing is already canceled or failed. |
1383 return; | 1412 return; |
| 1413 |
1384 prep_frame_view_->StartPrinting(); | 1414 prep_frame_view_->StartPrinting(); |
1385 | 1415 |
1386 int page_count = prep_frame_view_->GetExpectedPageCount(); | 1416 int page_count = prep_frame_view_->GetExpectedPageCount(); |
1387 if (!page_count) { | 1417 if (!page_count) { |
1388 LOG(ERROR) << "Can't print 0 pages."; | 1418 LOG(ERROR) << "Can't print 0 pages."; |
1389 return DidFinishPrinting(FAIL_PRINT); | 1419 return DidFinishPrinting(FAIL_PRINT); |
1390 } | 1420 } |
1391 | 1421 |
1392 const PrintMsg_PrintPages_Params& params = *print_pages_params_; | 1422 const PrintMsg_PrintPages_Params& params = *print_pages_params_; |
1393 const PrintMsg_Print_Params& print_params = params.params; | 1423 const PrintMsg_Print_Params& print_params = params.params; |
1394 | 1424 |
1395 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | 1425 #if !defined(OS_ANDROID) |
1396 // TODO(vitalybuka): should be page_count or valid pages from params.pages. | 1426 // TODO(vitalybuka): should be page_count or valid pages from params.pages. |
1397 // See http://crbug.com/161576 | 1427 // See http://crbug.com/161576 |
1398 Send(new PrintHostMsg_DidGetPrintedPagesCount(routing_id(), | 1428 Send(new PrintHostMsg_DidGetPrintedPagesCount(routing_id(), |
1399 print_params.document_cookie, | 1429 print_params.document_cookie, |
1400 page_count)); | 1430 page_count)); |
1401 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | 1431 #endif // !defined(OS_ANDROID) |
1402 | 1432 |
1403 if (print_params.preview_ui_id < 0) { | 1433 if (print_params.preview_ui_id < 0) { |
1404 // Printing for system dialog. | 1434 // Printing for system dialog. |
1405 int printed_count = params.pages.empty() ? page_count : params.pages.size(); | 1435 int printed_count = params.pages.empty() ? page_count : params.pages.size(); |
1406 #if defined(OS_CHROMEOS) | |
1407 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToCloudPrintWebDialog", | |
1408 printed_count); | |
1409 #else | |
1410 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.SystemDialog", printed_count); | 1436 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.SystemDialog", printed_count); |
1411 #endif // defined(OS_CHROMEOS) | |
1412 } | 1437 } |
1413 | 1438 |
1414 if (!PrintPagesNative(prep_frame_view_->frame(), page_count)) { | 1439 if (!PrintPagesNative(prep_frame_view_->frame(), page_count)) { |
1415 LOG(ERROR) << "Printing failed."; | 1440 LOG(ERROR) << "Printing failed."; |
1416 return DidFinishPrinting(FAIL_PRINT); | 1441 return DidFinishPrinting(FAIL_PRINT); |
1417 } | 1442 } |
1418 } | 1443 } |
1419 | 1444 |
1420 void PrintWebViewHelper::FinishFramePrinting() { | 1445 void PrintWebViewHelper::FinishFramePrinting() { |
1421 prep_frame_view_.reset(); | 1446 prep_frame_view_.reset(); |
1422 } | 1447 } |
| 1448 #endif // defined(ENABLE_BASIC_PRINTING) |
1423 | 1449 |
1424 // static - Not anonymous so that platform implementations can use it. | 1450 // static - Not anonymous so that platform implementations can use it. |
1425 void PrintWebViewHelper::ComputePageLayoutInPointsForCss( | 1451 void PrintWebViewHelper::ComputePageLayoutInPointsForCss( |
1426 blink::WebFrame* frame, | 1452 blink::WebFrame* frame, |
1427 int page_index, | 1453 int page_index, |
1428 const PrintMsg_Print_Params& page_params, | 1454 const PrintMsg_Print_Params& page_params, |
1429 bool ignore_css_margins, | 1455 bool ignore_css_margins, |
1430 double* scale_factor, | 1456 double* scale_factor, |
1431 PageSizeMargins* page_layout_in_points) { | 1457 PageSizeMargins* page_layout_in_points) { |
1432 PrintMsg_Print_Params params = CalculatePrintParamsForCss( | 1458 PrintMsg_Print_Params params = CalculatePrintParamsForCss( |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1493 } | 1519 } |
1494 | 1520 |
1495 const PrintMsg_Print_Params& params = print_pages_params_->params; | 1521 const PrintMsg_Print_Params& params = print_pages_params_->params; |
1496 PrepareFrameAndViewForPrint prepare(params, frame, node, ignore_css_margins_); | 1522 PrepareFrameAndViewForPrint prepare(params, frame, node, ignore_css_margins_); |
1497 prepare.StartPrinting(); | 1523 prepare.StartPrinting(); |
1498 | 1524 |
1499 *number_of_pages = prepare.GetExpectedPageCount(); | 1525 *number_of_pages = prepare.GetExpectedPageCount(); |
1500 return true; | 1526 return true; |
1501 } | 1527 } |
1502 | 1528 |
| 1529 #if defined(ENABLE_PRINT_PREVIEW) |
1503 bool PrintWebViewHelper::SetOptionsFromPdfDocument( | 1530 bool PrintWebViewHelper::SetOptionsFromPdfDocument( |
1504 PrintHostMsg_SetOptionsFromDocument_Params* options) { | 1531 PrintHostMsg_SetOptionsFromDocument_Params* options) { |
1505 blink::WebLocalFrame* source_frame = print_preview_context_.source_frame(); | 1532 blink::WebLocalFrame* source_frame = print_preview_context_.source_frame(); |
1506 const blink::WebNode& source_node = print_preview_context_.source_node(); | 1533 const blink::WebNode& source_node = print_preview_context_.source_node(); |
1507 | 1534 |
1508 blink::WebPrintPresetOptions preset_options; | 1535 blink::WebPrintPresetOptions preset_options; |
1509 if (!source_frame->getPrintPresetOptionsForPlugin(source_node, | 1536 if (!source_frame->getPrintPresetOptionsForPlugin(source_node, |
1510 &preset_options)) { | 1537 &preset_options)) { |
1511 return false; | 1538 return false; |
1512 } | 1539 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1601 if (!print_for_preview_) | 1628 if (!print_for_preview_) |
1602 print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS); | 1629 print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS); |
1603 else | 1630 else |
1604 Send(new PrintHostMsg_ShowInvalidPrinterSettingsError(routing_id())); | 1631 Send(new PrintHostMsg_ShowInvalidPrinterSettingsError(routing_id())); |
1605 | 1632 |
1606 return false; | 1633 return false; |
1607 } | 1634 } |
1608 | 1635 |
1609 return true; | 1636 return true; |
1610 } | 1637 } |
| 1638 #endif // defined(ENABLE_PRINT_PREVIEW) |
1611 | 1639 |
| 1640 #if defined(ENABLE_BASIC_PRINTING) |
1612 bool PrintWebViewHelper::GetPrintSettingsFromUser(blink::WebLocalFrame* frame, | 1641 bool PrintWebViewHelper::GetPrintSettingsFromUser(blink::WebLocalFrame* frame, |
1613 const blink::WebNode& node, | 1642 const blink::WebNode& node, |
1614 int expected_pages_count, | 1643 int expected_pages_count, |
1615 bool is_scripted) { | 1644 bool is_scripted) { |
1616 PrintHostMsg_ScriptedPrint_Params params; | 1645 PrintHostMsg_ScriptedPrint_Params params; |
1617 PrintMsg_PrintPages_Params print_settings; | 1646 PrintMsg_PrintPages_Params print_settings; |
1618 | 1647 |
1619 params.cookie = print_pages_params_->params.document_cookie; | 1648 params.cookie = print_pages_params_->params.document_cookie; |
1620 params.has_selection = frame->hasSelection(); | 1649 params.has_selection = frame->hasSelection(); |
1621 params.expected_pages_count = expected_pages_count; | 1650 params.expected_pages_count = expected_pages_count; |
(...skipping 19 matching lines...) Expand all Loading... |
1641 Send(msg); | 1670 Send(msg); |
1642 print_settings.params.print_scaling_option = scaling_option; | 1671 print_settings.params.print_scaling_option = scaling_option; |
1643 SetPrintPagesParams(print_settings); | 1672 SetPrintPagesParams(print_settings); |
1644 return (print_settings.params.dpi && print_settings.params.document_cookie); | 1673 return (print_settings.params.dpi && print_settings.params.document_cookie); |
1645 } | 1674 } |
1646 | 1675 |
1647 bool PrintWebViewHelper::RenderPagesForPrint(blink::WebLocalFrame* frame, | 1676 bool PrintWebViewHelper::RenderPagesForPrint(blink::WebLocalFrame* frame, |
1648 const blink::WebNode& node) { | 1677 const blink::WebNode& node) { |
1649 if (!frame || prep_frame_view_) | 1678 if (!frame || prep_frame_view_) |
1650 return false; | 1679 return false; |
| 1680 |
1651 const PrintMsg_PrintPages_Params& params = *print_pages_params_; | 1681 const PrintMsg_PrintPages_Params& params = *print_pages_params_; |
1652 const PrintMsg_Print_Params& print_params = params.params; | 1682 const PrintMsg_Print_Params& print_params = params.params; |
1653 prep_frame_view_.reset(new PrepareFrameAndViewForPrint( | 1683 prep_frame_view_.reset(new PrepareFrameAndViewForPrint( |
1654 print_params, frame, node, ignore_css_margins_)); | 1684 print_params, frame, node, ignore_css_margins_)); |
1655 DCHECK(!print_pages_params_->params.selection_only || | 1685 DCHECK(!print_pages_params_->params.selection_only || |
1656 print_pages_params_->pages.empty()); | 1686 print_pages_params_->pages.empty()); |
1657 prep_frame_view_->CopySelectionIfNeeded( | 1687 prep_frame_view_->CopySelectionIfNeeded( |
1658 render_view()->GetWebkitPreferences(), | 1688 render_view()->GetWebkitPreferences(), |
1659 base::Bind(&PrintWebViewHelper::OnFramePreparedForPrintPages, | 1689 base::Bind(&PrintWebViewHelper::OnFramePreparedForPrintPages, |
1660 base::Unretained(this))); | 1690 base::Unretained(this))); |
1661 return true; | 1691 return true; |
1662 } | 1692 } |
| 1693 #endif // defined(ENABLE_BASIC_PRINTING) |
1663 | 1694 |
1664 #if defined(OS_POSIX) | 1695 #if defined(OS_POSIX) |
1665 bool PrintWebViewHelper::CopyMetafileDataToSharedMem( | 1696 bool PrintWebViewHelper::CopyMetafileDataToSharedMem( |
1666 const PdfMetafileSkia& metafile, | 1697 const PdfMetafileSkia& metafile, |
1667 base::SharedMemoryHandle* shared_mem_handle) { | 1698 base::SharedMemoryHandle* shared_mem_handle) { |
1668 uint32_t buf_size = metafile.GetDataSize(); | 1699 uint32_t buf_size = metafile.GetDataSize(); |
1669 if (buf_size == 0) | 1700 if (buf_size == 0) |
1670 return false; | 1701 return false; |
1671 | 1702 |
1672 scoped_ptr<base::SharedMemory> shared_buf( | 1703 scoped_ptr<base::SharedMemory> shared_buf( |
1673 content::RenderThread::Get()->HostAllocateSharedMemoryBuffer(buf_size)); | 1704 content::RenderThread::Get()->HostAllocateSharedMemoryBuffer(buf_size)); |
1674 if (!shared_buf) | 1705 if (!shared_buf) |
1675 return false; | 1706 return false; |
1676 | 1707 |
1677 if (!shared_buf->Map(buf_size)) | 1708 if (!shared_buf->Map(buf_size)) |
1678 return false; | 1709 return false; |
1679 | 1710 |
1680 if (!metafile.GetData(shared_buf->memory(), buf_size)) | 1711 if (!metafile.GetData(shared_buf->memory(), buf_size)) |
1681 return false; | 1712 return false; |
1682 | 1713 |
1683 return shared_buf->GiveToProcess(base::GetCurrentProcessHandle(), | 1714 return shared_buf->GiveToProcess(base::GetCurrentProcessHandle(), |
1684 shared_mem_handle); | 1715 shared_mem_handle); |
1685 } | 1716 } |
1686 #endif // defined(OS_POSIX) | 1717 #endif // defined(OS_POSIX) |
1687 | 1718 |
| 1719 #if defined(ENABLE_PRINT_PREVIEW) |
1688 void PrintWebViewHelper::ShowScriptedPrintPreview() { | 1720 void PrintWebViewHelper::ShowScriptedPrintPreview() { |
1689 if (is_scripted_preview_delayed_) { | 1721 if (is_scripted_preview_delayed_) { |
1690 is_scripted_preview_delayed_ = false; | 1722 is_scripted_preview_delayed_ = false; |
1691 Send(new PrintHostMsg_ShowScriptedPrintPreview( | 1723 Send(new PrintHostMsg_ShowScriptedPrintPreview( |
1692 routing_id(), print_preview_context_.IsModifiable())); | 1724 routing_id(), print_preview_context_.IsModifiable())); |
1693 } | 1725 } |
1694 } | 1726 } |
1695 | 1727 |
1696 void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) { | 1728 void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) { |
1697 const bool is_modifiable = print_preview_context_.IsModifiable(); | 1729 const bool is_modifiable = print_preview_context_.IsModifiable(); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1805 return false; | 1837 return false; |
1806 } | 1838 } |
1807 preview_page_params.data_size = metafile->GetDataSize(); | 1839 preview_page_params.data_size = metafile->GetDataSize(); |
1808 preview_page_params.page_number = page_number; | 1840 preview_page_params.page_number = page_number; |
1809 preview_page_params.preview_request_id = | 1841 preview_page_params.preview_request_id = |
1810 print_pages_params_->params.preview_request_id; | 1842 print_pages_params_->params.preview_request_id; |
1811 | 1843 |
1812 Send(new PrintHostMsg_DidPreviewPage(routing_id(), preview_page_params)); | 1844 Send(new PrintHostMsg_DidPreviewPage(routing_id(), preview_page_params)); |
1813 return true; | 1845 return true; |
1814 } | 1846 } |
| 1847 #endif // defined(ENABLE_PRINT_PREVIEW) |
1815 | 1848 |
1816 PrintWebViewHelper::PrintPreviewContext::PrintPreviewContext() | 1849 PrintWebViewHelper::PrintPreviewContext::PrintPreviewContext() |
1817 : total_page_count_(0), | 1850 : total_page_count_(0), |
1818 current_page_index_(0), | 1851 current_page_index_(0), |
1819 generate_draft_pages_(true), | 1852 generate_draft_pages_(true), |
1820 print_ready_metafile_page_count_(0), | 1853 print_ready_metafile_page_count_(0), |
1821 error_(PREVIEW_ERROR_NONE), | 1854 error_(PREVIEW_ERROR_NONE), |
1822 state_(UNINITIALIZED) { | 1855 state_(UNINITIALIZED) { |
1823 } | 1856 } |
1824 | 1857 |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2096 blink::WebConsoleMessage::LevelWarning, message)); | 2129 blink::WebConsoleMessage::LevelWarning, message)); |
2097 return false; | 2130 return false; |
2098 } | 2131 } |
2099 | 2132 |
2100 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2133 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
2101 // Reset counter on successful print. | 2134 // Reset counter on successful print. |
2102 count_ = 0; | 2135 count_ = 0; |
2103 } | 2136 } |
2104 | 2137 |
2105 } // namespace printing | 2138 } // namespace printing |
OLD | NEW |