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

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

Issue 2653963002: [Experimental] Supporting OOPIF printing
Patch Set: Rename service, fix for webview, and connect to DiscardableMemoryManager Created 3 years, 8 months 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 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 24 matching lines...) Expand all
35 #include "printing/features/features.h" 35 #include "printing/features/features.h"
36 #include "printing/metafile_skia_wrapper.h" 36 #include "printing/metafile_skia_wrapper.h"
37 #include "printing/pdf_metafile_skia.h" 37 #include "printing/pdf_metafile_skia.h"
38 #include "printing/units.h" 38 #include "printing/units.h"
39 #include "third_party/WebKit/public/platform/WebDoubleSize.h" 39 #include "third_party/WebKit/public/platform/WebDoubleSize.h"
40 #include "third_party/WebKit/public/platform/WebSize.h" 40 #include "third_party/WebKit/public/platform/WebSize.h"
41 #include "third_party/WebKit/public/platform/WebURLRequest.h" 41 #include "third_party/WebKit/public/platform/WebURLRequest.h"
42 #include "third_party/WebKit/public/web/WebConsoleMessage.h" 42 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
43 #include "third_party/WebKit/public/web/WebDocument.h" 43 #include "third_party/WebKit/public/web/WebDocument.h"
44 #include "third_party/WebKit/public/web/WebElement.h" 44 #include "third_party/WebKit/public/web/WebElement.h"
45 #include "third_party/WebKit/public/web/WebFrame.h"
45 #include "third_party/WebKit/public/web/WebFrameClient.h" 46 #include "third_party/WebKit/public/web/WebFrameClient.h"
46 #include "third_party/WebKit/public/web/WebFrameOwnerProperties.h" 47 #include "third_party/WebKit/public/web/WebFrameOwnerProperties.h"
47 #include "third_party/WebKit/public/web/WebFrameWidget.h" 48 #include "third_party/WebKit/public/web/WebFrameWidget.h"
48 #include "third_party/WebKit/public/web/WebLocalFrame.h" 49 #include "third_party/WebKit/public/web/WebLocalFrame.h"
49 #include "third_party/WebKit/public/web/WebPlugin.h" 50 #include "third_party/WebKit/public/web/WebPlugin.h"
50 #include "third_party/WebKit/public/web/WebPluginDocument.h" 51 #include "third_party/WebKit/public/web/WebPluginDocument.h"
51 #include "third_party/WebKit/public/web/WebPrintParams.h" 52 #include "third_party/WebKit/public/web/WebPrintParams.h"
52 #include "third_party/WebKit/public/web/WebPrintPresetOptions.h" 53 #include "third_party/WebKit/public/web/WebPrintPresetOptions.h"
53 #include "third_party/WebKit/public/web/WebSandboxFlags.h" 54 #include "third_party/WebKit/public/web/WebSandboxFlags.h"
54 #include "third_party/WebKit/public/web/WebScriptSource.h" 55 #include "third_party/WebKit/public/web/WebScriptSource.h"
55 #include "third_party/WebKit/public/web/WebSettings.h" 56 #include "third_party/WebKit/public/web/WebSettings.h"
56 #include "third_party/WebKit/public/web/WebView.h" 57 #include "third_party/WebKit/public/web/WebView.h"
57 #include "third_party/WebKit/public/web/WebViewClient.h" 58 #include "third_party/WebKit/public/web/WebViewClient.h"
59 //#include "third_party/WebKit/Source/web/WebRemoteFrameImpl.h"
58 #include "third_party/skia/include/core/SkCanvas.h" 60 #include "third_party/skia/include/core/SkCanvas.h"
59 #include "ui/base/resource/resource_bundle.h" 61 #include "ui/base/resource/resource_bundle.h"
60 62
61 using content::WebPreferences; 63 using content::WebPreferences;
62 64
63 namespace printing { 65 namespace printing {
64 66
65 namespace { 67 namespace {
66 68
67 #define STATIC_ASSERT_ENUM(a, b) \ 69 #define STATIC_ASSERT_ENUM(a, b) \
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 double scale_factor = 1.0f; 731 double scale_factor = 1.0f;
730 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) 732 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
731 if (print_params.scale_factor >= PrintWebViewHelper::kEpsilon) 733 if (print_params.scale_factor >= PrintWebViewHelper::kEpsilon)
732 scale_factor = print_params.scale_factor; 734 scale_factor = print_params.scale_factor;
733 #endif 735 #endif
734 print_params = CalculatePrintParamsForCss( 736 print_params = CalculatePrintParamsForCss(
735 frame, 0, print_params, ignore_css_margins, fit_to_page, &scale_factor); 737 frame, 0, print_params, ignore_css_margins, fit_to_page, &scale_factor);
736 frame->printEnd(); 738 frame->printEnd();
737 } 739 }
738 ComputeWebKitPrintParamsInDesiredDpi(print_params, &web_print_params_); 740 ComputeWebKitPrintParamsInDesiredDpi(print_params, &web_print_params_);
741 web_print_params_.rootFrameRoutingId =
742 content::RenderFrame::FromWebFrame(frame)->GetRoutingID();
739 } 743 }
740 744
741 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() { 745 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() {
742 FinishPrinting(); 746 FinishPrinting();
743 } 747 }
744 748
745 void PrepareFrameAndViewForPrint::ResizeForPrinting() { 749 void PrepareFrameAndViewForPrint::ResizeForPrinting() {
746 // Layout page according to printer page size. Since WebKit shrinks the 750 // Layout page according to printer page size. Since WebKit shrinks the
747 // size of the page automatically (from 133.3% to 200%) we trick it to 751 // size of the page automatically (from 133.3% to 200%) we trick it to
748 // think the page is 133.3% larger so the size of the page is correct for 752 // think the page is 133.3% larger so the size of the page is correct for
(...skipping 11 matching lines...) Expand all
760 if (!frame()) 764 if (!frame())
761 return; 765 return;
762 766
763 // Backup size and offset if it's a local frame. 767 // Backup size and offset if it's a local frame.
764 blink::WebView* web_view = frame_.view(); 768 blink::WebView* web_view = frame_.view();
765 if (blink::WebFrame* web_frame = web_view->mainFrame()) { 769 if (blink::WebFrame* web_frame = web_view->mainFrame()) {
766 if (web_frame->isWebLocalFrame()) 770 if (web_frame->isWebLocalFrame())
767 prev_scroll_offset_ = web_frame->getScrollOffset(); 771 prev_scroll_offset_ = web_frame->getScrollOffset();
768 } 772 }
769 prev_view_size_ = web_view->size(); 773 prev_view_size_ = web_view->size();
770
771 web_view->resize(print_layout_size); 774 web_view->resize(print_layout_size);
772 } 775 }
773 776
774 void PrepareFrameAndViewForPrint::StartPrinting() { 777 void PrepareFrameAndViewForPrint::StartPrinting() {
775 blink::WebView* web_view = frame_.view(); 778 blink::WebView* web_view = frame_.view();
776 web_view->settings()->setShouldPrintBackgrounds(should_print_backgrounds_); 779 web_view->settings()->setShouldPrintBackgrounds(should_print_backgrounds_);
777 expected_pages_count_ = 780 expected_pages_count_ =
778 frame()->printBegin(web_print_params_, node_to_print_); 781 frame()->printBegin(web_print_params_, node_to_print_);
779 ResizeForPrinting(); 782 ResizeForPrinting();
780 is_printing_started_ = true; 783 is_printing_started_ = true;
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 #endif 977 #endif
975 } else { 978 } else {
976 #if BUILDFLAG(ENABLE_BASIC_PRINTING) 979 #if BUILDFLAG(ENABLE_BASIC_PRINTING)
977 Print(web_frame, blink::WebNode(), true /* is_scripted? */); 980 Print(web_frame, blink::WebNode(), true /* is_scripted? */);
978 #endif 981 #endif
979 } 982 }
980 // WARNING: |this| may be gone at this point. Do not do any more work here and 983 // WARNING: |this| may be gone at this point. Do not do any more work here and
981 // just return. 984 // just return.
982 } 985 }
983 986
987 void PrintWebViewHelper::PrintFrame(const gfx::Rect& rect, int src_id) {
988 if (ipc_nesting_level_ > 1)
989 return;
990
991 PrintMsg_PrintPages_Params settings;
992 settings.params.dpi = 300;
993 settings.params.desired_dpi = 300;
994 settings.params.selection_only = false;
995 settings.params.should_print_backgrounds = true;
996 settings.params.page_size = rect.size();
997 settings.params.content_size = rect.size();
998 settings.params.printable_area = rect;
999 settings.params.is_first_request = true;
1000 settings.params.print_to_pdf = false;
1001 settings.params.display_header_footer = false;
1002 settings.params.document_cookie = -1;
1003 settings.params.is_subframe = true;
1004
1005 blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
1006 FrameReference frame_ref(frame);
1007
1008 // If we are printing a PDF extension frame, find the plugin node and print
1009 // that instead.
1010 auto node = delegate_->GetPdfElement(frame);
1011
1012 // Handle settings.
1013 ignore_css_margins_ = false;
1014 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings));
1015
1016 prep_frame_view_.reset(new PrepareFrameAndViewForPrint(
1017 print_pages_params_->params, frame, node, ignore_css_margins_));
1018 prep_frame_view_->StartPrinting();
1019
1020 int page_count = prep_frame_view_->GetExpectedPageCount();
1021 if (!page_count) {
1022 return DidFinishPrinting(FAIL_PRINT);
1023 }
1024
1025 if (!PrintPagesNative(prep_frame_view_->frame(), page_count)) {
1026 return DidFinishPrinting(FAIL_PRINT);
1027 }
1028
1029 FinishFramePrinting();
1030 scripting_throttler_.Reset();
1031 }
1032
984 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { 1033 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) {
985 // The class is not designed to handle recursive messages. This is not 1034 // The class is not designed to handle recursive messages. This is not
986 // expected during regular flow. However, during rendering of content for 1035 // expected during regular flow. However, during rendering of content for
987 // printing, lower level code may run nested message loop. E.g. PDF may has 1036 // printing, lower level code may run nested message loop. E.g. PDF may has
988 // script to show message box http://crbug.com/502562. In that moment browser 1037 // script to show message box http://crbug.com/502562. In that moment browser
989 // may receive updated printer capabilities and decide to restart print 1038 // may receive updated printer capabilities and decide to restart print
990 // preview generation. When this happened message handling function may 1039 // preview generation. When this happened message handling function may
991 // choose to ignore message or safely crash process. 1040 // choose to ignore message or safely crash process.
992 ++ipc_nesting_level_; 1041 ++ipc_nesting_level_;
993 1042
994 auto self = weak_ptr_factory_.GetWeakPtr(); 1043 auto self = weak_ptr_factory_.GetWeakPtr();
995 1044
996 bool handled = true; 1045 bool handled = true;
997 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) 1046 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message)
998 #if BUILDFLAG(ENABLE_BASIC_PRINTING) 1047 #if BUILDFLAG(ENABLE_BASIC_PRINTING)
999 IPC_MESSAGE_HANDLER(PrintMsg_PrintPages, OnPrintPages) 1048 IPC_MESSAGE_HANDLER(PrintMsg_PrintPages, OnPrintPages)
1049 IPC_MESSAGE_HANDLER(PrintMsg_PrintPagesWithSettings,
1050 OnPrintPagesWithSettings)
1000 IPC_MESSAGE_HANDLER(PrintMsg_PrintForSystemDialog, OnPrintForSystemDialog) 1051 IPC_MESSAGE_HANDLER(PrintMsg_PrintForSystemDialog, OnPrintForSystemDialog)
1001 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) 1052 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING)
1002 #if BUILDFLAG(ENABLE_BASIC_PRINTING) && BUILDFLAG(ENABLE_PRINT_PREVIEW) 1053 #if BUILDFLAG(ENABLE_BASIC_PRINTING) && BUILDFLAG(ENABLE_PRINT_PREVIEW)
1003 IPC_MESSAGE_HANDLER(PrintMsg_PrintForPrintPreview, OnPrintForPrintPreview) 1054 IPC_MESSAGE_HANDLER(PrintMsg_PrintForPrintPreview, OnPrintForPrintPreview)
1004 #endif 1055 #endif
1005 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) 1056 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
1006 IPC_MESSAGE_HANDLER(PrintMsg_InitiatePrintPreview, OnInitiatePrintPreview) 1057 IPC_MESSAGE_HANDLER(PrintMsg_InitiatePrintPreview, OnInitiatePrintPreview)
1007 IPC_MESSAGE_HANDLER(PrintMsg_PrintPreview, OnPrintPreview) 1058 IPC_MESSAGE_HANDLER(PrintMsg_PrintPreview, OnPrintPreview)
1008 IPC_MESSAGE_HANDLER(PrintMsg_PrintingDone, OnPrintingDone) 1059 IPC_MESSAGE_HANDLER(PrintMsg_PrintingDone, OnPrintingDone)
1009 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) 1060 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
(...skipping 19 matching lines...) Expand all
1029 blink::WebLocalFrame* frame = render_frame()->GetWebFrame(); 1080 blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
1030 1081
1031 // If we are printing a PDF extension frame, find the plugin node and print 1082 // If we are printing a PDF extension frame, find the plugin node and print
1032 // that instead. 1083 // that instead.
1033 auto plugin = delegate_->GetPdfElement(frame); 1084 auto plugin = delegate_->GetPdfElement(frame);
1034 Print(frame, plugin, false /* is_scripted? */); 1085 Print(frame, plugin, false /* is_scripted? */);
1035 // WARNING: |this| may be gone at this point. Do not do any more work here and 1086 // WARNING: |this| may be gone at this point. Do not do any more work here and
1036 // just return. 1087 // just return.
1037 } 1088 }
1038 1089
1090 void PrintWebViewHelper::OnPrintPagesWithSettings(const gfx::Rect& rect) {
1091 if (ipc_nesting_level_ > 1)
1092 return;
1093
1094 PrintMsg_PrintPages_Params settings;
1095 settings.params.dpi = 300;
1096 settings.params.desired_dpi = 300;
1097 settings.params.selection_only = false;
1098 settings.params.should_print_backgrounds = true;
1099 // settings.params.page_size = rect.size();
1100 settings.params.page_size = gfx::Size(500, 300);
1101 // settings.params.content_size = rect.size();
1102 settings.params.content_size = gfx::Size(500, 300);
1103 // settings.params.printable_area = rect;
1104 settings.params.printable_area = gfx::Rect(500, 300);
1105 settings.params.is_first_request = true;
1106 settings.params.print_to_pdf = false;
1107 settings.params.display_header_footer = false;
1108 settings.params.document_cookie = -1;
1109 settings.params.is_subframe = true;
1110
1111 blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
1112 FrameReference frame_ref(frame);
1113
1114 // If we are printing a PDF extension frame, find the plugin node and print
1115 // that instead.
1116 auto node = delegate_->GetPdfElement(frame);
1117
1118 // Handle settings.
1119 ignore_css_margins_ = false;
1120 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings));
1121
1122 prep_frame_view_.reset(new PrepareFrameAndViewForPrint(
1123 print_pages_params_->params, frame, node, ignore_css_margins_));
1124 prep_frame_view_->StartPrinting();
1125
1126 int page_count = prep_frame_view_->GetExpectedPageCount();
1127 if (!page_count) {
1128 return DidFinishPrinting(FAIL_PRINT);
1129 }
1130
1131 if (!PrintPagesNative(prep_frame_view_->frame(), page_count)) {
1132 return DidFinishPrinting(FAIL_PRINT);
1133 }
1134
1135 FinishFramePrinting();
1136 scripting_throttler_.Reset();
1137 }
1138
1039 void PrintWebViewHelper::OnPrintForSystemDialog() { 1139 void PrintWebViewHelper::OnPrintForSystemDialog() {
1040 if (ipc_nesting_level_> 1) 1140 if (ipc_nesting_level_> 1)
1041 return; 1141 return;
1042 blink::WebLocalFrame* frame = print_preview_context_.source_frame(); 1142 blink::WebLocalFrame* frame = print_preview_context_.source_frame();
1043 if (!frame) { 1143 if (!frame) {
1044 NOTREACHED(); 1144 NOTREACHED();
1045 return; 1145 return;
1046 } 1146 }
1047 Print(frame, print_preview_context_.source_node(), false); 1147 Print(frame, print_preview_context_.source_node(), false);
1048 // WARNING: |this| may be gone at this point. Do not do any more work here and 1148 // WARNING: |this| may be gone at this point. Do not do any more work here and
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
1333 draft_metafile.reset(new PdfMetafileSkia(PDF_SKIA_DOCUMENT_TYPE)); 1433 draft_metafile.reset(new PdfMetafileSkia(PDF_SKIA_DOCUMENT_TYPE));
1334 initial_render_metafile = draft_metafile.get(); 1434 initial_render_metafile = draft_metafile.get();
1335 } 1435 }
1336 1436
1337 base::TimeTicks begin_time = base::TimeTicks::Now(); 1437 base::TimeTicks begin_time = base::TimeTicks::Now();
1338 PrintPageInternal(page_params, print_preview_context_.prepared_frame(), 1438 PrintPageInternal(page_params, print_preview_context_.prepared_frame(),
1339 initial_render_metafile, nullptr, nullptr, nullptr); 1439 initial_render_metafile, nullptr, nullptr, nullptr);
1340 print_preview_context_.RenderedPreviewPage( 1440 print_preview_context_.RenderedPreviewPage(
1341 base::TimeTicks::Now() - begin_time); 1441 base::TimeTicks::Now() - begin_time);
1342 if (draft_metafile.get()) { 1442 if (draft_metafile.get()) {
1343 draft_metafile->FinishDocument(); 1443 draft_metafile->FinishAllPages();
1344 } else if (print_preview_context_.IsModifiable() && 1444 } else if (print_preview_context_.IsModifiable() &&
1345 print_preview_context_.generate_draft_pages()) { 1445 print_preview_context_.generate_draft_pages()) {
1346 DCHECK(!draft_metafile.get()); 1446 DCHECK(!draft_metafile.get());
1347 draft_metafile = 1447 draft_metafile =
1348 print_preview_context_.metafile()->GetMetafileForCurrentPage( 1448 print_preview_context_.metafile()->GetMetafileForCurrentPage(
1349 PDF_SKIA_DOCUMENT_TYPE); 1449 PDF_SKIA_DOCUMENT_TYPE);
1350 } 1450 }
1351 return PreviewPageRendered(page_number, draft_metafile.get()); 1451 return PreviewPageRendered(page_number, draft_metafile.get());
1352 } 1452 }
1353 #endif // !defined(OS_MACOSX) && BUILDFLAG(ENABLE_PRINT_PREVIEW) 1453 #endif // !defined(OS_MACOSX) && BUILDFLAG(ENABLE_PRINT_PREVIEW)
1354 1454
1355 bool PrintWebViewHelper::FinalizePrintReadyDocument() { 1455 bool PrintWebViewHelper::FinalizePrintReadyDocument() {
1356 DCHECK(!is_print_ready_metafile_sent_); 1456 DCHECK(!is_print_ready_metafile_sent_);
1357 print_preview_context_.FinalizePrintReadyDocument(); 1457 print_preview_context_.FinalizePrintReadyDocument();
1358 1458
1359 PdfMetafileSkia* metafile = print_preview_context_.metafile(); 1459 PdfMetafileSkia* metafile = print_preview_context_.metafile();
1360 PrintHostMsg_DidPreviewDocument_Params preview_params; 1460 PrintHostMsg_DidPreviewDocument_Params preview_params;
1361 1461
1362 // Ask the browser to create the shared memory for us.
1363 if (!CopyMetafileDataToSharedMem(*metafile, 1462 if (!CopyMetafileDataToSharedMem(*metafile,
1364 &(preview_params.metafile_data_handle))) { 1463 &preview_params.metafile_data_handle,
1464 &preview_params.data_size)) {
1365 LOG(ERROR) << "CopyMetafileDataToSharedMem failed"; 1465 LOG(ERROR) << "CopyMetafileDataToSharedMem failed";
1366 print_preview_context_.set_error(PREVIEW_ERROR_METAFILE_COPY_FAILED); 1466 print_preview_context_.set_error(PREVIEW_ERROR_METAFILE_COPY_FAILED);
1367 return false; 1467 return false;
1368 } 1468 }
1369 1469
1370 preview_params.data_size = metafile->GetDataSize();
1371 preview_params.document_cookie = print_pages_params_->params.document_cookie; 1470 preview_params.document_cookie = print_pages_params_->params.document_cookie;
1372 preview_params.expected_pages_count = 1471 preview_params.expected_pages_count =
1373 print_preview_context_.total_page_count(); 1472 print_preview_context_.total_page_count();
1374 preview_params.modifiable = print_preview_context_.IsModifiable(); 1473 preview_params.modifiable = print_preview_context_.IsModifiable();
1375 preview_params.preview_request_id = 1474 preview_params.preview_request_id =
1376 print_pages_params_->params.preview_request_id; 1475 print_pages_params_->params.preview_request_id;
1476 preview_params.is_subframe = print_pages_params_->params.is_subframe;
1377 1477
1378 is_print_ready_metafile_sent_ = true; 1478 is_print_ready_metafile_sent_ = true;
1379 1479
1380 Send(new PrintHostMsg_MetafileReadyForPrinting(routing_id(), preview_params)); 1480 Send(new PrintHostMsg_MetafileReadyForPrinting(routing_id(), preview_params));
1381 return true; 1481 return true;
1382 } 1482 }
1383 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) 1483 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
1384 1484
1385 void PrintWebViewHelper::OnPrintingDone(bool success) { 1485 void PrintWebViewHelper::OnPrintingDone(bool success) {
1386 if (ipc_nesting_level_ > 1) 1486 if (ipc_nesting_level_ > 1)
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1731 modified_job_settings.SetBoolean(kSettingHeaderFooterEnabled, false); 1831 modified_job_settings.SetBoolean(kSettingHeaderFooterEnabled, false);
1732 modified_job_settings.SetInteger(kSettingMarginsType, NO_MARGINS); 1832 modified_job_settings.SetInteger(kSettingMarginsType, NO_MARGINS);
1733 job_settings = &modified_job_settings; 1833 job_settings = &modified_job_settings;
1734 } 1834 }
1735 1835
1736 // Send the cookie so that UpdatePrintSettings can reuse PrinterQuery when 1836 // Send the cookie so that UpdatePrintSettings can reuse PrinterQuery when
1737 // possible. 1837 // possible.
1738 int cookie = 1838 int cookie =
1739 print_pages_params_ ? print_pages_params_->params.document_cookie : 0; 1839 print_pages_params_ ? print_pages_params_->params.document_cookie : 0;
1740 PrintMsg_PrintPages_Params settings; 1840 PrintMsg_PrintPages_Params settings;
1841 // Initial frame should be the root frame.
1842 settings.params.is_subframe = false;
1741 bool canceled = false; 1843 bool canceled = false;
1742 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), cookie, *job_settings, 1844 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), cookie, *job_settings,
1743 &settings, &canceled)); 1845 &settings, &canceled));
1744 if (canceled) { 1846 if (canceled) {
1745 notify_browser_of_print_failure_ = false; 1847 notify_browser_of_print_failure_ = false;
1746 return false; 1848 return false;
1747 } 1849 }
1748 1850
1749 if (!job_settings->GetInteger(kPreviewUIID, &settings.params.preview_ui_id)) { 1851 if (!job_settings->GetInteger(kPreviewUIID, &settings.params.preview_ui_id)) {
1750 NOTREACHED(); 1852 NOTREACHED();
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1919 DCHECK_GT(webkit_scale_factor, 0.0f); 2021 DCHECK_GT(webkit_scale_factor, 0.0f);
1920 2022
1921 // Done printing. Close the canvas to retrieve the compiled metafile. 2023 // Done printing. Close the canvas to retrieve the compiled metafile.
1922 if (!metafile->FinishPage()) 2024 if (!metafile->FinishPage())
1923 NOTREACHED() << "metafile failed"; 2025 NOTREACHED() << "metafile failed";
1924 } 2026 }
1925 #endif // !defined(OS_MACOSX) 2027 #endif // !defined(OS_MACOSX)
1926 2028
1927 bool PrintWebViewHelper::CopyMetafileDataToSharedMem( 2029 bool PrintWebViewHelper::CopyMetafileDataToSharedMem(
1928 const PdfMetafileSkia& metafile, 2030 const PdfMetafileSkia& metafile,
1929 base::SharedMemoryHandle* shared_mem_handle) { 2031 base::SharedMemoryHandle* shared_mem_handle,
1930 uint32_t buf_size = metafile.GetDataSize(); 2032 uint32_t* size) {
1931 if (buf_size == 0) 2033 std::string file_name = base::StringPrintf(
2034 "C:\\src\\test_only\\chrome_test_dump\\org_%d.skp", routing_id());
2035 SkFILEWStream file(file_name.c_str());
2036 metafile.GetSkp(&file);
2037 file.fsync();
2038
2039 // Test new utility logic.
2040 size_t buf_size;
2041 std::unique_ptr<char[]> buf = metafile.GetPageDataBuffer(&buf_size);
2042 if (buf_size == 0) {
2043 NOTREACHED() << "Page data is empty";
1932 return false; 2044 return false;
2045 }
1933 2046
1934 std::unique_ptr<base::SharedMemory> shared_buf( 2047 std::unique_ptr<base::SharedMemory> shared_buf(
1935 content::RenderThread::Get()->HostAllocateSharedMemoryBuffer(buf_size)); 2048 content::RenderThread::Get()->HostAllocateSharedMemoryBuffer(buf_size));
1936 if (!shared_buf) 2049 if (!shared_buf || !shared_buf->Map(buf_size)) {
2050 NOTREACHED() << "Map data error";
2051 print_preview_context_.set_error(PREVIEW_ERROR_METAFILE_COPY_FAILED);
1937 return false; 2052 return false;
1938 2053 }
1939 if (!shared_buf->Map(buf_size)) 2054 memcpy(shared_buf->memory(), buf.get(), buf_size);
1940 return false;
1941
1942 if (!metafile.GetData(shared_buf->memory(), buf_size))
1943 return false;
1944 2055
1945 *shared_mem_handle = 2056 *shared_mem_handle =
1946 base::SharedMemory::DuplicateHandle(shared_buf->handle()); 2057 base::SharedMemory::DuplicateHandle(shared_buf->handle());
2058 *size = buf_size;
1947 return true; 2059 return true;
1948 } 2060 }
1949 2061
1950 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) 2062 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
1951 void PrintWebViewHelper::ShowScriptedPrintPreview() { 2063 void PrintWebViewHelper::ShowScriptedPrintPreview() {
1952 if (is_scripted_preview_delayed_) { 2064 if (is_scripted_preview_delayed_) {
1953 is_scripted_preview_delayed_ = false; 2065 is_scripted_preview_delayed_ = false;
1954 Send(new PrintHostMsg_ShowScriptedPrintPreview( 2066 Send(new PrintHostMsg_ShowScriptedPrintPreview(
1955 routing_id(), print_preview_context_.IsModifiable())); 2067 routing_id(), print_preview_context_.IsModifiable()));
1956 } 2068 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
2055 return true; 2167 return true;
2056 } 2168 }
2057 2169
2058 if (!metafile) { 2170 if (!metafile) {
2059 NOTREACHED(); 2171 NOTREACHED();
2060 print_preview_context_.set_error( 2172 print_preview_context_.set_error(
2061 PREVIEW_ERROR_PAGE_RENDERED_WITHOUT_METAFILE); 2173 PREVIEW_ERROR_PAGE_RENDERED_WITHOUT_METAFILE);
2062 return false; 2174 return false;
2063 } 2175 }
2064 2176
2177 // output the debug file.
2178 std::string file_name = base::StringPrintf(
2179 "C:\\src\\test_only\\chrome_test_dump\\org_%d.skp", page_number);
2180 SkFILEWStream file(file_name.c_str());
2181 metafile->GetSkp(&file);
2182 file.fsync();
2183
2065 PrintHostMsg_DidPreviewPage_Params preview_page_params; 2184 PrintHostMsg_DidPreviewPage_Params preview_page_params;
2066 // Get the size of the resulting metafile. 2185 if (!CopyMetafileDataToSharedMem(*metafile,
2067 if (!CopyMetafileDataToSharedMem( 2186 &preview_page_params.metafile_data_handle,
2068 *metafile, &(preview_page_params.metafile_data_handle))) { 2187 &preview_page_params.data_size)) {
2069 LOG(ERROR) << "CopyMetafileDataToSharedMem failed"; 2188 LOG(ERROR) << "CopyMetafileDataToSharedMem failed";
2070 print_preview_context_.set_error(PREVIEW_ERROR_METAFILE_COPY_FAILED); 2189 print_preview_context_.set_error(PREVIEW_ERROR_METAFILE_COPY_FAILED);
2071 return false; 2190 return false;
2072 } 2191 }
2073 preview_page_params.data_size = metafile->GetDataSize(); 2192
2074 preview_page_params.page_number = page_number; 2193 preview_page_params.page_number = page_number;
2075 preview_page_params.preview_request_id = 2194 preview_page_params.preview_request_id =
2076 print_pages_params_->params.preview_request_id; 2195 print_pages_params_->params.preview_request_id;
2196 preview_page_params.is_subframe = print_pages_params_->params.is_subframe;
2077 2197
2078 Send(new PrintHostMsg_DidPreviewPage(routing_id(), preview_page_params)); 2198 Send(new PrintHostMsg_DidPreviewPage(routing_id(), preview_page_params));
2079 return true; 2199 return true;
2080 } 2200 }
2081 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) 2201 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
2082 2202
2083 PrintWebViewHelper::PrintPreviewContext::PrintPreviewContext() 2203 PrintWebViewHelper::PrintPreviewContext::PrintPreviewContext()
2084 : total_page_count_(0), 2204 : total_page_count_(0),
2085 current_page_index_(0), 2205 current_page_index_(0),
2086 generate_draft_pages_(true), 2206 generate_draft_pages_(true),
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
2182 void PrintWebViewHelper::PrintPreviewContext::AllPagesRendered() { 2302 void PrintWebViewHelper::PrintPreviewContext::AllPagesRendered() {
2183 DCHECK_EQ(RENDERING, state_); 2303 DCHECK_EQ(RENDERING, state_);
2184 state_ = DONE; 2304 state_ = DONE;
2185 prep_frame_view_->FinishPrinting(); 2305 prep_frame_view_->FinishPrinting();
2186 } 2306 }
2187 2307
2188 void PrintWebViewHelper::PrintPreviewContext::FinalizePrintReadyDocument() { 2308 void PrintWebViewHelper::PrintPreviewContext::FinalizePrintReadyDocument() {
2189 DCHECK(IsRendering()); 2309 DCHECK(IsRendering());
2190 2310
2191 base::TimeTicks begin_time = base::TimeTicks::Now(); 2311 base::TimeTicks begin_time = base::TimeTicks::Now();
2192 metafile_->FinishDocument(); 2312 metafile_->FinishAllPages();
2193 2313
2194 if (print_ready_metafile_page_count_ <= 0) { 2314 if (print_ready_metafile_page_count_ <= 0) {
2195 NOTREACHED(); 2315 NOTREACHED();
2196 return; 2316 return;
2197 } 2317 }
2198 2318
2199 UMA_HISTOGRAM_MEDIUM_TIMES("PrintPreview.RenderToPDFTime", 2319 UMA_HISTOGRAM_MEDIUM_TIMES("PrintPreview.RenderToPDFTime",
2200 document_render_time_); 2320 document_render_time_);
2201 base::TimeDelta total_time = 2321 base::TimeDelta total_time =
2202 (base::TimeTicks::Now() - begin_time) + document_render_time_; 2322 (base::TimeTicks::Now() - begin_time) + document_render_time_;
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
2360 blink::WebConsoleMessage::LevelWarning, message)); 2480 blink::WebConsoleMessage::LevelWarning, message));
2361 return false; 2481 return false;
2362 } 2482 }
2363 2483
2364 void PrintWebViewHelper::ScriptingThrottler::Reset() { 2484 void PrintWebViewHelper::ScriptingThrottler::Reset() {
2365 // Reset counter on successful print. 2485 // Reset counter on successful print.
2366 count_ = 0; 2486 count_ = 0;
2367 } 2487 }
2368 2488
2369 } // namespace printing 2489 } // namespace printing
OLDNEW
« no previous file with comments | « components/printing/renderer/print_web_view_helper.h ('k') | components/printing/renderer/print_web_view_helper_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698