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

Side by Side Diff: chrome/renderer/webplugin_delegate_pepper.cc

Issue 2863019: Added support for vector printing for Pepper v1 plugins for Windows. Mac and ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Typo fixed Created 10 years, 6 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #define PEPPER_APIS_ENABLED 1 5 #define PEPPER_APIS_ENABLED 1
6 6
7 #include "chrome/renderer/webplugin_delegate_pepper.h" 7 #include "chrome/renderer/webplugin_delegate_pepper.h"
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #if defined(OS_LINUX) 12 #if defined(OS_LINUX)
13 #include <unistd.h> 13 #include <unistd.h>
14 #endif 14 #endif
15 15
16 #include "base/file_util.h" 16 #include "base/file_util.h"
17 #include "base/keyboard_codes.h" 17 #include "base/keyboard_codes.h"
18 #if defined(OS_MACOSX) 18 #if defined(OS_MACOSX)
19 #include "base/mac_util.h" 19 #include "base/mac_util.h"
20 #endif 20 #endif
21 #include "base/md5.h" 21 #include "base/md5.h"
22 #include "base/message_loop.h" 22 #include "base/message_loop.h"
23 #include "base/path_service.h"
23 #include "base/process_util.h" 24 #include "base/process_util.h"
24 #if defined(OS_MACOSX) 25 #if defined(OS_MACOSX)
25 #include "base/scoped_cftyperef.h" 26 #include "base/scoped_cftyperef.h"
26 #endif 27 #endif
27 #include "base/scoped_ptr.h" 28 #include "base/scoped_ptr.h"
28 #include "base/stats_counters.h" 29 #include "base/stats_counters.h"
29 #include "base/string_util.h" 30 #include "base/string_util.h"
30 #include "base/time.h" 31 #include "base/time.h"
32 #include "chrome/common/chrome_paths.h"
31 #include "chrome/common/render_messages.h" 33 #include "chrome/common/render_messages.h"
32 #include "chrome/renderer/pepper_widget.h" 34 #include "chrome/renderer/pepper_widget.h"
33 #include "chrome/renderer/render_thread.h" 35 #include "chrome/renderer/render_thread.h"
34 #if defined(OS_LINUX) 36 #if defined(OS_LINUX)
35 #include "chrome/renderer/renderer_sandbox_support_linux.h" 37 #include "chrome/renderer/renderer_sandbox_support_linux.h"
36 #endif 38 #endif
37 #include "chrome/renderer/webplugin_delegate_proxy.h" 39 #include "chrome/renderer/webplugin_delegate_proxy.h"
38 #include "gfx/blit.h" 40 #include "gfx/blit.h"
39 #if defined(OS_WIN) 41 #if defined(OS_WIN)
40 #include "gfx/codec/jpeg_codec.h" 42 #include "gfx/codec/jpeg_codec.h"
41 #include "gfx/gdi_util.h" 43 #include "gfx/gdi_util.h"
44 #include "printing/units.h"
42 #include "skia/ext/vector_platform_device.h" 45 #include "skia/ext/vector_platform_device.h"
43 #endif 46 #endif
44 #include "third_party/npapi/bindings/npapi_extensions.h" 47 #include "third_party/npapi/bindings/npapi_extensions.h"
45 #include "third_party/npapi/bindings/npapi_extensions_private.h" 48 #include "third_party/npapi/bindings/npapi_extensions_private.h"
46 #include "third_party/WebKit/WebKit/chromium/public/WebCursorInfo.h" 49 #include "third_party/WebKit/WebKit/chromium/public/WebCursorInfo.h"
47 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" 50 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h"
48 #include "webkit/glue/plugins/plugin_constants_win.h" 51 #include "webkit/glue/plugins/plugin_constants_win.h"
49 #include "webkit/glue/plugins/plugin_instance.h" 52 #include "webkit/glue/plugins/plugin_instance.h"
50 #include "webkit/glue/plugins/plugin_lib.h" 53 #include "webkit/glue/plugins/plugin_lib.h"
51 #include "webkit/glue/plugins/plugin_list.h" 54 #include "webkit/glue/plugins/plugin_list.h"
55 #include "webkit/glue/plugins/plugin_host.h"
52 #include "webkit/glue/plugins/plugin_stream_url.h" 56 #include "webkit/glue/plugins/plugin_stream_url.h"
53 #include "webkit/glue/webkit_glue.h" 57 #include "webkit/glue/webkit_glue.h"
54 58
55 #if defined(ENABLE_GPU) 59 #if defined(ENABLE_GPU)
56 #include "webkit/glue/plugins/plugin_constants_win.h" 60 #include "webkit/glue/plugins/plugin_constants_win.h"
57 #endif 61 #endif
58 62
59 using gpu::Buffer; 63 using gpu::Buffer;
60 using webkit_glue::WebPlugin; 64 using webkit_glue::WebPlugin;
61 using webkit_glue::WebPluginDelegate; 65 using webkit_glue::WebPluginDelegate;
(...skipping 13 matching lines...) Expand all
75 79
76 struct Device3DImpl { 80 struct Device3DImpl {
77 gpu::CommandBuffer* command_buffer; 81 gpu::CommandBuffer* command_buffer;
78 bool dynamically_created; 82 bool dynamically_created;
79 }; 83 };
80 84
81 const int32 kDefaultCommandBufferSize = 1024 * 1024; 85 const int32 kDefaultCommandBufferSize = 1024 * 1024;
82 86
83 } // namespace 87 } // namespace
84 88
89 static const float kPointsPerInch = 72.0;
90
91 #if defined(OS_WIN)
92 // Exported by pdf.dll
93 typedef bool (__stdcall *RenderPDFPageToDCProc)(
94 const unsigned char* pdf_buffer, int buffer_size, int page_number, HDC dc,
95 int dpi_x, int dpi_y, int bounds_origin_x, int bounds_origin_y,
96 int bounds_width, int bounds_height, bool fit_to_bounds,
97 bool stretch_to_bounds, bool keep_aspect_ratio, bool center_in_bounds);
98 #endif // defined(OS_WIN)
99
85 WebPluginDelegatePepper* WebPluginDelegatePepper::Create( 100 WebPluginDelegatePepper* WebPluginDelegatePepper::Create(
86 const FilePath& filename, 101 const FilePath& filename,
87 const std::string& mime_type, 102 const std::string& mime_type,
88 const base::WeakPtr<RenderView>& render_view) { 103 const base::WeakPtr<RenderView>& render_view) {
89 scoped_refptr<NPAPI::PluginLib> plugin_lib = 104 scoped_refptr<NPAPI::PluginLib> plugin_lib =
90 NPAPI::PluginLib::CreatePluginLib(filename); 105 NPAPI::PluginLib::CreatePluginLib(filename);
91 if (plugin_lib.get() == NULL) 106 if (plugin_lib.get() == NULL)
92 return NULL; 107 return NULL;
93 108
94 NPError err = plugin_lib->NP_Initialize(); 109 NPError err = plugin_lib->NP_Initialize();
(...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 NPRect np_printable_area = {0}; 1121 NPRect np_printable_area = {0};
1107 np_printable_area.left = printable_area.x(); 1122 np_printable_area.left = printable_area.x();
1108 np_printable_area.top = printable_area.y(); 1123 np_printable_area.top = printable_area.y();
1109 np_printable_area.right = np_printable_area.left + printable_area.width(); 1124 np_printable_area.right = np_printable_area.left + printable_area.width();
1110 np_printable_area.bottom = np_printable_area.top + printable_area.height(); 1125 np_printable_area.bottom = np_printable_area.top + printable_area.height();
1111 if (NPERR_NO_ERROR == print_extensions->printBegin(instance()->npp(), 1126 if (NPERR_NO_ERROR == print_extensions->printBegin(instance()->npp(),
1112 &np_printable_area, 1127 &np_printable_area,
1113 printer_dpi, 1128 printer_dpi,
1114 &num_pages)) { 1129 &num_pages)) {
1115 current_printable_area_ = printable_area; 1130 current_printable_area_ = printable_area;
1131 current_printer_dpi_ = printer_dpi;
1116 } 1132 }
1117 } 1133 }
1118 return num_pages; 1134 return num_pages;
1119 } 1135 }
1120 1136
1137 bool WebPluginDelegatePepper::VectorPrintPage(int page_number,
1138 WebKit::WebCanvas* canvas) {
1139 #if !defined(OS_WIN)
1140 // TODO(sanjeevr): Add vector print support for Mac and Linux.
1141 return false;
1142 #endif // !defined(OS_WIN)
1143 NPPPrintExtensions* print_extensions = GetPrintExtensions();
1144 if (!print_extensions)
1145 return false;
1146 #if defined(OS_WIN)
1147 // For Windows, we need the PDF DLL to render the output PDF to a DC.
1148 FilePath pdf_path;
1149 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path);
1150 HMODULE pdf_module = GetModuleHandle(pdf_path.value().c_str());
1151 if (!pdf_module)
1152 return false;
1153 RenderPDFPageToDCProc render_proc =
1154 reinterpret_cast<RenderPDFPageToDCProc>(
1155 GetProcAddress(pdf_module, "RenderPDFPageToDC"));
1156 if (!render_proc)
1157 return false;
1158 #endif // defined(OS_WIN)
1159
1160 unsigned char* pdf_output = NULL;
1161 int32 output_size = 0;
1162 NPError err = print_extensions->printPageAsPDF(instance()->npp(), page_number,
1163 &pdf_output, &output_size);
1164 if (err != NPERR_NO_ERROR)
1165 return false;
1166
1167 bool ret = false;
1168 #if defined(OS_WIN)
1169 // On Windows, we now need to render the PDF to the DC that backs the
1170 // supplied canvas.
1171 skia::VectorPlatformDevice& device =
1172 static_cast<skia::VectorPlatformDevice&>(
1173 canvas->getTopPlatformDevice());
1174 HDC dc = device.getBitmapDC();
1175 gfx::Size size_in_pixels;
1176 size_in_pixels.set_width(
1177 printing::ConvertUnit(current_printable_area_.width(),
1178 static_cast<int>(kPointsPerInch),
1179 current_printer_dpi_));
1180 size_in_pixels.set_height(
1181 printing::ConvertUnit(current_printable_area_.height(),
1182 static_cast<int>(kPointsPerInch),
1183 current_printer_dpi_));
1184 // We need to render using the actual printer DPI (rendering to a smaller
1185 // set of pixels leads to a blurry output). However, we need to counter the
1186 // scaling up that will happen in the browser.
1187 XFORM xform = {0};
1188 xform.eM11 = xform.eM22 = kPointsPerInch / current_printer_dpi_;
1189 ModifyWorldTransform(dc, &xform, MWT_LEFTMULTIPLY);
1190
1191 ret = render_proc(pdf_output, output_size, 0, dc, current_printer_dpi_,
1192 current_printer_dpi_, 0, 0, size_in_pixels.width(),
1193 size_in_pixels.height(), true, false, true, true);
1194 #endif // defined(OS_WIN)
1195
1196 NPAPI::PluginHost::Singleton()->host_functions()->memfree(pdf_output);
1197 return ret;
1198 }
1199
1121 bool WebPluginDelegatePepper::PrintPage(int page_number, 1200 bool WebPluginDelegatePepper::PrintPage(int page_number,
1122 WebKit::WebCanvas* canvas) { 1201 WebKit::WebCanvas* canvas) {
1123 NPPPrintExtensions* print_extensions = GetPrintExtensions(); 1202 NPPPrintExtensions* print_extensions = GetPrintExtensions();
1124 if (!print_extensions) 1203 if (!print_extensions)
1125 return false; 1204 return false;
1126 1205
1206 // First try and use vector print.
1207 if (VectorPrintPage(page_number, canvas))
1208 return true;
1209
1127 DCHECK(!current_printable_area_.IsEmpty()); 1210 DCHECK(!current_printable_area_.IsEmpty());
1128 1211
1129 // Calculate the width and height needed for the raster image. 1212 // Calculate the width and height needed for the raster image.
1130 NPRect np_printable_area = {0}; 1213 NPRect np_printable_area = {0};
1131 np_printable_area.left = current_printable_area_.x(); 1214 np_printable_area.left = current_printable_area_.x();
1132 np_printable_area.top = current_printable_area_.y(); 1215 np_printable_area.top = current_printable_area_.y();
1133 np_printable_area.right = 1216 np_printable_area.right =
1134 current_printable_area_.x() + current_printable_area_.width(); 1217 current_printable_area_.x() + current_printable_area_.width();
1135 np_printable_area.bottom = 1218 np_printable_area.bottom =
1136 current_printable_area_.y() + current_printable_area_.height(); 1219 current_printable_area_.y() + current_printable_area_.height();
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 canvas->drawBitmapRect(committed, &src_rect, dest_rect); 1283 canvas->drawBitmapRect(committed, &src_rect, dest_rect);
1201 #endif // defined(OS_MACOSX) 1284 #endif // defined(OS_MACOSX)
1202 return true; 1285 return true;
1203 } 1286 }
1204 1287
1205 void WebPluginDelegatePepper::PrintEnd() { 1288 void WebPluginDelegatePepper::PrintEnd() {
1206 NPPPrintExtensions* print_extensions = GetPrintExtensions(); 1289 NPPPrintExtensions* print_extensions = GetPrintExtensions();
1207 if (print_extensions) 1290 if (print_extensions)
1208 print_extensions->printEnd(instance()->npp()); 1291 print_extensions->printEnd(instance()->npp());
1209 current_printable_area_ = gfx::Rect(); 1292 current_printable_area_ = gfx::Rect();
1293 current_printer_dpi_ = -1;
1210 #if defined(OS_MACOSX) 1294 #if defined(OS_MACOSX)
1211 last_printed_page_ = SkBitmap(); 1295 last_printed_page_ = SkBitmap();
1212 #endif // defined(OS_MACOSX) 1296 #endif // defined(OS_MACOSX)
1213 } 1297 }
1214 1298
1215 bool WebPluginDelegatePepper::SupportsFind() { 1299 bool WebPluginDelegatePepper::SupportsFind() {
1216 return GetFindExtensions() != NULL; 1300 return GetFindExtensions() != NULL;
1217 } 1301 }
1218 1302
1219 1303
1220 WebPluginDelegatePepper::WebPluginDelegatePepper( 1304 WebPluginDelegatePepper::WebPluginDelegatePepper(
1221 const base::WeakPtr<RenderView>& render_view, 1305 const base::WeakPtr<RenderView>& render_view,
1222 NPAPI::PluginInstance *instance) 1306 NPAPI::PluginInstance *instance)
1223 : render_view_(render_view), 1307 : render_view_(render_view),
1224 plugin_(NULL), 1308 plugin_(NULL),
1225 instance_(instance), 1309 instance_(instance),
1226 nested_delegate_(NULL), 1310 nested_delegate_(NULL),
1311 current_printer_dpi_(-1),
1227 #if defined(ENABLE_GPU) 1312 #if defined(ENABLE_GPU)
1228 command_buffer_(NULL), 1313 command_buffer_(NULL),
1229 #endif 1314 #endif
1230 find_identifier_(-1), 1315 find_identifier_(-1),
1231 method_factory3d_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 1316 method_factory3d_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
1232 current_choose_file_callback_(NULL), 1317 current_choose_file_callback_(NULL),
1233 current_choose_file_user_data_(NULL) { 1318 current_choose_file_user_data_(NULL) {
1234 // For now we keep a window struct, although it isn't used. 1319 // For now we keep a window struct, although it isn't used.
1235 memset(&window_, 0, sizeof(window_)); 1320 memset(&window_, 0, sizeof(window_));
1236 // All Pepper plugins are windowless and transparent. 1321 // All Pepper plugins are windowless and transparent.
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
1611 bounds.origin.x = dest_rect.x(); 1696 bounds.origin.x = dest_rect.x();
1612 bounds.origin.y = canvas_height - dest_rect.y() - dest_rect.height(); 1697 bounds.origin.y = canvas_height - dest_rect.y() - dest_rect.height();
1613 bounds.size.width = dest_rect.width(); 1698 bounds.size.width = dest_rect.width();
1614 bounds.size.height = dest_rect.height(); 1699 bounds.size.height = dest_rect.height();
1615 1700
1616 CGContextDrawImage(canvas, bounds, image); 1701 CGContextDrawImage(canvas, bounds, image);
1617 CGContextRestoreGState(canvas); 1702 CGContextRestoreGState(canvas);
1618 } 1703 }
1619 #endif // defined(OS_MACOSX) 1704 #endif // defined(OS_MACOSX)
1620 1705
OLDNEW
« no previous file with comments | « chrome/renderer/webplugin_delegate_pepper.h ('k') | third_party/npapi/bindings/npapi_extensions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698