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

Side by Side Diff: webkit/plugins/ppapi/ppapi_plugin_instance.cc

Issue 7065011: Change printing of PDFs for preview on Windows to not rasterize. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 9 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « webkit/plugins/ppapi/ppapi_plugin_instance.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "webkit/plugins/ppapi/ppapi_plugin_instance.h" 5 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 #include "webkit/plugins/ppapi/string.h" 60 #include "webkit/plugins/ppapi/string.h"
61 #include "webkit/plugins/ppapi/var.h" 61 #include "webkit/plugins/ppapi/var.h"
62 #include "webkit/plugins/sad_plugin.h" 62 #include "webkit/plugins/sad_plugin.h"
63 63
64 #if defined(OS_MACOSX) 64 #if defined(OS_MACOSX)
65 #include "base/mac/mac_util.h" 65 #include "base/mac/mac_util.h"
66 #include "base/mac/scoped_cftyperef.h" 66 #include "base/mac/scoped_cftyperef.h"
67 #include "printing/metafile_impl.h" 67 #include "printing/metafile_impl.h"
68 #endif 68 #endif
69 69
70 #if defined(OS_LINUX) 70 #if defined(OS_LINUX) || defined(OS_WIN)
71 #include "printing/metafile.h" 71 #include "printing/metafile.h"
72 #include "printing/metafile_skia_wrapper.h" 72 #include "printing/metafile_skia_wrapper.h"
73 #endif 73 #endif
74 74
75 #if defined(OS_WIN) 75 #if defined(OS_WIN)
76 #include "skia/ext/vector_platform_device_emf_win.h" 76 #include "skia/ext/vector_platform_device_emf_win.h"
77 #include "ui/gfx/codec/jpeg_codec.h" 77 #include "ui/gfx/codec/jpeg_codec.h"
78 #include "ui/gfx/gdi_util.h" 78 #include "ui/gfx/gdi_util.h"
79 #endif 79 #endif
80 80
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 has_webkit_focus_(false), 346 has_webkit_focus_(false),
347 has_content_area_focus_(false), 347 has_content_area_focus_(false),
348 find_identifier_(-1), 348 find_identifier_(-1),
349 plugin_find_interface_(NULL), 349 plugin_find_interface_(NULL),
350 plugin_messaging_interface_(NULL), 350 plugin_messaging_interface_(NULL),
351 plugin_pdf_interface_(NULL), 351 plugin_pdf_interface_(NULL),
352 plugin_private_interface_(NULL), 352 plugin_private_interface_(NULL),
353 plugin_selection_interface_(NULL), 353 plugin_selection_interface_(NULL),
354 plugin_zoom_interface_(NULL), 354 plugin_zoom_interface_(NULL),
355 checked_for_plugin_messaging_interface_(false), 355 checked_for_plugin_messaging_interface_(false),
356 #if defined(OS_LINUX)
357 canvas_(NULL),
358 #endif // defined(OS_LINUX)
359 plugin_print_interface_(NULL), 356 plugin_print_interface_(NULL),
360 plugin_graphics_3d_interface_(NULL), 357 plugin_graphics_3d_interface_(NULL),
361 always_on_top_(false), 358 always_on_top_(false),
362 fullscreen_container_(NULL), 359 fullscreen_container_(NULL),
363 fullscreen_(false), 360 fullscreen_(false),
364 message_channel_(NULL), 361 message_channel_(NULL),
365 sad_plugin_(NULL) { 362 sad_plugin_(NULL) {
366 pp_instance_ = ResourceTracker::Get()->AddInstance(this); 363 pp_instance_ = ResourceTracker::Get()->AddInstance(this);
367 364
368 memset(&current_print_settings_, 0, sizeof(current_print_settings_)); 365 memset(&current_print_settings_, 0, sizeof(current_print_settings_));
(...skipping 12 matching lines...) Expand all
381 PluginObjectSet plugin_object_copy; 378 PluginObjectSet plugin_object_copy;
382 live_plugin_objects_.swap(plugin_object_copy); 379 live_plugin_objects_.swap(plugin_object_copy);
383 for (PluginObjectSet::iterator i = plugin_object_copy.begin(); 380 for (PluginObjectSet::iterator i = plugin_object_copy.begin();
384 i != plugin_object_copy.end(); ++i) 381 i != plugin_object_copy.end(); ++i)
385 delete *i; 382 delete *i;
386 383
387 delegate_->InstanceDeleted(this); 384 delegate_->InstanceDeleted(this);
388 module_->InstanceDeleted(this); 385 module_->InstanceDeleted(this);
389 386
390 ResourceTracker::Get()->InstanceDeleted(pp_instance_); 387 ResourceTracker::Get()->InstanceDeleted(pp_instance_);
391 #if defined(OS_LINUX)
392 ranges_.clear();
393 #endif // defined(OS_LINUX)
394 } 388 }
395 389
396 // static 390 // static
397 const PPB_Instance* PluginInstance::GetInterface() { 391 const PPB_Instance* PluginInstance::GetInterface() {
398 return &ppb_instance; 392 return &ppb_instance;
399 } 393 }
400 394
401 // static 395 // static
402 const PPB_Find_Dev* PluginInstance::GetFindInterface() { 396 const PPB_Find_Dev* PluginInstance::GetFindInterface() {
403 return &ppb_find; 397 return &ppb_find;
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after
1118 break; 1112 break;
1119 default: 1113 default:
1120 return 0; 1114 return 0;
1121 } 1115 }
1122 num_pages = plugin_print_interface_->Begin_0_3(pp_instance(), 1116 num_pages = plugin_print_interface_->Begin_0_3(pp_instance(),
1123 &print_settings_0_3); 1117 &print_settings_0_3);
1124 } 1118 }
1125 if (!num_pages) 1119 if (!num_pages)
1126 return 0; 1120 return 0;
1127 current_print_settings_ = print_settings; 1121 current_print_settings_ = print_settings;
1128 #if defined(OS_LINUX) 1122 #if WEBKIT_USING_SKIA
1129 canvas_ = NULL; 1123 canvas_ = NULL;
1130 ranges_.clear(); 1124 ranges_.clear();
1131 #endif // defined(OS_LINUX) 1125 #endif // WEBKIT_USING_SKIA
1132 return num_pages; 1126 return num_pages;
1133 } 1127 }
1134 1128
1135 bool PluginInstance::PrintPage(int page_number, WebKit::WebCanvas* canvas) { 1129 bool PluginInstance::PrintPage(int page_number, WebKit::WebCanvas* canvas) {
1136 DCHECK(plugin_print_interface_.get()); 1130 DCHECK(plugin_print_interface_.get());
1137 PP_PrintPageNumberRange_Dev page_range; 1131 PP_PrintPageNumberRange_Dev page_range;
1138 page_range.first_page_number = page_range.last_page_number = page_number; 1132 page_range.first_page_number = page_range.last_page_number = page_number;
1139 #if defined(OS_LINUX) 1133 #if WEBKIT_USING_SKIA
1140 ranges_.push_back(page_range); 1134 // The canvas only has a metafile on it for print preview.
1141 canvas_ = canvas; 1135 if (printing::MetafileSkiaWrapper::GetMetafileFromCanvas(canvas)) {
1142 return true; 1136 ranges_.push_back(page_range);
1143 #else 1137 canvas_ = canvas;
1144 return PrintPageHelper(&page_range, 1, canvas); 1138 return true;
1145 #endif // defined(OS_LINUX) 1139 } else
1140 #endif // WEBKIT_USING_SKIA
1141 {
1142 return PrintPageHelper(&page_range, 1, canvas);
1143 }
1146 } 1144 }
1147 1145
1148 bool PluginInstance::PrintPageHelper(PP_PrintPageNumberRange_Dev* page_ranges, 1146 bool PluginInstance::PrintPageHelper(PP_PrintPageNumberRange_Dev* page_ranges,
1149 int num_ranges, 1147 int num_ranges,
1150 WebKit::WebCanvas* canvas) { 1148 WebKit::WebCanvas* canvas) {
1151 // Keep a reference on the stack. See NOTE above. 1149 // Keep a reference on the stack. See NOTE above.
1152 scoped_refptr<PluginInstance> ref(this); 1150 scoped_refptr<PluginInstance> ref(this);
1153 PP_Resource print_output = plugin_print_interface_->PrintPages( 1151 PP_Resource print_output = plugin_print_interface_->PrintPages(
1154 pp_instance(), page_ranges, num_ranges); 1152 pp_instance(), page_ranges, num_ranges);
1155 if (!print_output) 1153 if (!print_output)
1156 return false; 1154 return false;
1157 1155
1158 bool ret = false; 1156 bool ret = false;
1159 1157
1160 if (current_print_settings_.format == PP_PRINTOUTPUTFORMAT_PDF) 1158 if (current_print_settings_.format == PP_PRINTOUTPUTFORMAT_PDF)
1161 ret = PrintPDFOutput(print_output, canvas); 1159 ret = PrintPDFOutput(print_output, canvas);
1162 else if (current_print_settings_.format == PP_PRINTOUTPUTFORMAT_RASTER) 1160 else if (current_print_settings_.format == PP_PRINTOUTPUTFORMAT_RASTER)
1163 ret = PrintRasterOutput(print_output, canvas); 1161 ret = PrintRasterOutput(print_output, canvas);
1164 1162
1165 // Now we need to release the print output resource. 1163 // Now we need to release the print output resource.
1166 PluginModule::GetCore()->ReleaseResource(print_output); 1164 PluginModule::GetCore()->ReleaseResource(print_output);
1167 1165
1168 return ret; 1166 return ret;
1169 } 1167 }
1170 1168
1171 void PluginInstance::PrintEnd() { 1169 void PluginInstance::PrintEnd() {
1172 // Keep a reference on the stack. See NOTE above. 1170 // Keep a reference on the stack. See NOTE above.
1173 scoped_refptr<PluginInstance> ref(this); 1171 scoped_refptr<PluginInstance> ref(this);
1174 #if defined(OS_LINUX) 1172 #if WEBKIT_USING_SKIA
1175 // This hack is here because all pages need to be written to PDF at once.
1176 if (!ranges_.empty()) 1173 if (!ranges_.empty())
1177 PrintPageHelper(&(ranges_.front()), ranges_.size(), canvas_); 1174 PrintPageHelper(&(ranges_.front()), ranges_.size(), canvas_.get());
1178 canvas_ = NULL; 1175 canvas_ = NULL;
1179 ranges_.clear(); 1176 ranges_.clear();
1180 #endif // defined(OS_LINUX) 1177 #endif // WEBKIT_USING_SKIA
1181 1178
1182 DCHECK(plugin_print_interface_.get()); 1179 DCHECK(plugin_print_interface_.get());
1183 if (plugin_print_interface_.get()) 1180 if (plugin_print_interface_.get())
1184 plugin_print_interface_->End(pp_instance()); 1181 plugin_print_interface_->End(pp_instance());
1185 1182
1186 memset(&current_print_settings_, 0, sizeof(current_print_settings_)); 1183 memset(&current_print_settings_, 0, sizeof(current_print_settings_));
1187 #if defined(OS_MACOSX) 1184 #if defined(OS_MACOSX)
1188 last_printed_page_ = NULL; 1185 last_printed_page_ = NULL;
1189 #endif // defined(OS_MACOSX) 1186 #endif // defined(OS_MACOSX)
1190 } 1187 }
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1314 CGRect page_rect; 1311 CGRect page_rect;
1315 page_rect.origin.x = current_print_settings_.printable_area.point.x; 1312 page_rect.origin.x = current_print_settings_.printable_area.point.x;
1316 page_rect.origin.y = current_print_settings_.printable_area.point.y; 1313 page_rect.origin.y = current_print_settings_.printable_area.point.y;
1317 page_rect.size.width = current_print_settings_.printable_area.size.width; 1314 page_rect.size.width = current_print_settings_.printable_area.size.width;
1318 page_rect.size.height = current_print_settings_.printable_area.size.height; 1315 page_rect.size.height = current_print_settings_.printable_area.size.height;
1319 1316
1320 ret = metafile.RenderPage(1, canvas, page_rect, true, false, true, true); 1317 ret = metafile.RenderPage(1, canvas, page_rect, true, false, true, true);
1321 CGContextRestoreGState(canvas); 1318 CGContextRestoreGState(canvas);
1322 } 1319 }
1323 #elif defined(OS_WIN) 1320 #elif defined(OS_WIN)
1324 // On Windows, we now need to render the PDF to the DC that backs the 1321 printing::Metafile* metafile =
1325 // supplied canvas. 1322 printing::MetafileSkiaWrapper::GetMetafileFromCanvas(canvas);
1326 HDC dc = skia::BeginPlatformPaint(canvas); 1323 if (metafile) {
1327 gfx::Size size_in_pixels; 1324 // We only have a metafile when doing print preview, so we just want to
1328 size_in_pixels.set_width( 1325 // pass the PDF off to preview.
1329 printing::ConvertUnit(current_print_settings_.printable_area.size.width, 1326 ret = metafile->InitFromData(buffer->mapped_buffer(), buffer->size());
1330 static_cast<int>(printing::kPointsPerInch), 1327 } else {
1331 current_print_settings_.dpi)); 1328 // On Windows, we now need to render the PDF to the DC that backs the
1332 size_in_pixels.set_height( 1329 // supplied canvas.
1333 printing::ConvertUnit(current_print_settings_.printable_area.size.height, 1330 HDC dc = skia::BeginPlatformPaint(canvas);
1334 static_cast<int>(printing::kPointsPerInch), 1331 gfx::Size size_in_pixels;
1335 current_print_settings_.dpi)); 1332 size_in_pixels.set_width(printing::ConvertUnit(
1336 // We need to render using the actual printer DPI (rendering to a smaller 1333 current_print_settings_.printable_area.size.width,
1337 // set of pixels leads to a blurry output). However, we need to counter the 1334 static_cast<int>(printing::kPointsPerInch),
1338 // scaling up that will happen in the browser. 1335 current_print_settings_.dpi));
1339 XFORM xform = {0}; 1336 size_in_pixels.set_height(printing::ConvertUnit(
1340 xform.eM11 = xform.eM22 = static_cast<float>(printing::kPointsPerInch) / 1337 current_print_settings_.printable_area.size.height,
1341 static_cast<float>(current_print_settings_.dpi); 1338 static_cast<int>(printing::kPointsPerInch),
1342 ModifyWorldTransform(dc, &xform, MWT_LEFTMULTIPLY); 1339 current_print_settings_.dpi));
1340 // We need to render using the actual printer DPI (rendering to a smaller
1341 // set of pixels leads to a blurry output). However, we need to counter the
1342 // scaling up that will happen in the browser.
1343 XFORM xform = {0};
1344 xform.eM11 = xform.eM22 = static_cast<float>(printing::kPointsPerInch) /
1345 static_cast<float>(current_print_settings_.dpi);
1346 ModifyWorldTransform(dc, &xform, MWT_LEFTMULTIPLY);
1343 1347
1344 ret = render_proc(buffer->mapped_buffer(), buffer->size(), 0, dc, 1348 ret = render_proc(buffer->mapped_buffer(), buffer->size(), 0, dc,
1345 current_print_settings_.dpi, current_print_settings_.dpi, 1349 current_print_settings_.dpi, current_print_settings_.dpi,
1346 0, 0, size_in_pixels.width(), 1350 0, 0, size_in_pixels.width(),
1347 size_in_pixels.height(), true, false, true, true); 1351 size_in_pixels.height(), true, false, true, true);
1348 skia::EndPlatformPaint(canvas); 1352 skia::EndPlatformPaint(canvas);
1353 }
1349 #endif // defined(OS_WIN) 1354 #endif // defined(OS_WIN)
1350 1355
1351 return ret; 1356 return ret;
1352 } 1357 }
1353 1358
1354 bool PluginInstance::PrintRasterOutput(PP_Resource print_output, 1359 bool PluginInstance::PrintRasterOutput(PP_Resource print_output,
1355 WebKit::WebCanvas* canvas) { 1360 WebKit::WebCanvas* canvas) {
1356 scoped_refptr<PPB_ImageData_Impl> image( 1361 scoped_refptr<PPB_ImageData_Impl> image(
1357 Resource::GetAs<PPB_ImageData_Impl>(print_output)); 1362 Resource::GetAs<PPB_ImageData_Impl>(print_output));
1358 if (!image.get() || !image->is_mapped()) 1363 if (!image.get() || !image->is_mapped())
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
1560 return found->second; 1565 return found->second;
1561 } 1566 }
1562 1567
1563 bool PluginInstance::IsFullPagePlugin() const { 1568 bool PluginInstance::IsFullPagePlugin() const {
1564 WebFrame* frame = container()->element().document().frame(); 1569 WebFrame* frame = container()->element().document().frame();
1565 return frame->view()->mainFrame()->document().isPluginDocument(); 1570 return frame->view()->mainFrame()->document().isPluginDocument();
1566 } 1571 }
1567 1572
1568 } // namespace ppapi 1573 } // namespace ppapi
1569 } // namespace webkit 1574 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppapi_plugin_instance.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698