OLD | NEW |
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> |
(...skipping 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1125 np_printable_area.right = np_printable_area.left + printable_area.width(); | 1125 np_printable_area.right = np_printable_area.left + printable_area.width(); |
1126 np_printable_area.bottom = np_printable_area.top + printable_area.height(); | 1126 np_printable_area.bottom = np_printable_area.top + printable_area.height(); |
1127 if (NPERR_NO_ERROR == print_extensions->printBegin(instance()->npp(), | 1127 if (NPERR_NO_ERROR == print_extensions->printBegin(instance()->npp(), |
1128 &np_printable_area, | 1128 &np_printable_area, |
1129 printer_dpi, | 1129 printer_dpi, |
1130 &num_pages)) { | 1130 &num_pages)) { |
1131 current_printable_area_ = printable_area; | 1131 current_printable_area_ = printable_area; |
1132 current_printer_dpi_ = printer_dpi; | 1132 current_printer_dpi_ = printer_dpi; |
1133 } | 1133 } |
1134 } | 1134 } |
| 1135 #if defined (OS_LINUX) |
| 1136 num_pages_ = num_pages; |
| 1137 pdf_output_done_ = false; |
| 1138 #endif // (OS_LINUX) |
1135 return num_pages; | 1139 return num_pages; |
1136 } | 1140 } |
1137 | 1141 |
1138 bool WebPluginDelegatePepper::VectorPrintPage(int page_number, | 1142 bool WebPluginDelegatePepper::VectorPrintPage(int page_number, |
1139 WebKit::WebCanvas* canvas) { | 1143 WebKit::WebCanvas* canvas) { |
1140 #if !defined(OS_WIN) && !defined(OS_MACOSX) | |
1141 // TODO(sanjeevr): Add vector print support for Linux. | |
1142 return false; | |
1143 #endif // !defined(OS_WIN) && !defined(OS_MACOSX) | |
1144 NPPPrintExtensions* print_extensions = GetPrintExtensions(); | 1144 NPPPrintExtensions* print_extensions = GetPrintExtensions(); |
1145 if (!print_extensions) | 1145 if (!print_extensions) |
1146 return false; | 1146 return false; |
1147 #if defined(OS_WIN) | 1147 #if defined(OS_WIN) |
1148 // For Windows, we need the PDF DLL to render the output PDF to a DC. | 1148 // For Windows, we need the PDF DLL to render the output PDF to a DC. |
1149 FilePath pdf_path; | 1149 FilePath pdf_path; |
1150 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path); | 1150 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path); |
1151 HMODULE pdf_module = GetModuleHandle(pdf_path.value().c_str()); | 1151 HMODULE pdf_module = GetModuleHandle(pdf_path.value().c_str()); |
1152 if (!pdf_module) | 1152 if (!pdf_module) |
1153 return false; | 1153 return false; |
1154 RenderPDFPageToDCProc render_proc = | 1154 RenderPDFPageToDCProc render_proc = |
1155 reinterpret_cast<RenderPDFPageToDCProc>( | 1155 reinterpret_cast<RenderPDFPageToDCProc>( |
1156 GetProcAddress(pdf_module, "RenderPDFPageToDC")); | 1156 GetProcAddress(pdf_module, "RenderPDFPageToDC")); |
1157 if (!render_proc) | 1157 if (!render_proc) |
1158 return false; | 1158 return false; |
1159 #endif // defined(OS_WIN) | 1159 #endif // defined(OS_WIN) |
1160 | 1160 |
1161 unsigned char* pdf_output = NULL; | 1161 unsigned char* pdf_output = NULL; |
1162 int32 output_size = 0; | 1162 int32 output_size = 0; |
1163 NPError err = print_extensions->printPageAsPDF(instance()->npp(), page_number, | 1163 NPPrintPageNumberRange page_range; |
1164 &pdf_output, &output_size); | 1164 #if defined(OS_LINUX) |
| 1165 // On Linux we will try and output all pages as PDF in the first call to |
| 1166 // PrintPage. This is a temporary hack. |
| 1167 // TODO(sanjeevr): Remove this hack and fix this by changing the print |
| 1168 // interfaces for WebFrame and WebPlugin. |
| 1169 if (page_number != 0) |
| 1170 return pdf_output_done_; |
| 1171 page_range.firstPageNumber = 0; |
| 1172 page_range.lastPageNumber = num_pages_ - 1; |
| 1173 #else // defined(OS_LINUX) |
| 1174 page_range.firstPageNumber = page_range.lastPageNumber = page_number; |
| 1175 #endif // defined(OS_LINUX) |
| 1176 NPError err = print_extensions->printPagesAsPDF(instance()->npp(), |
| 1177 &page_range, 1, |
| 1178 &pdf_output, &output_size); |
1165 if (err != NPERR_NO_ERROR) | 1179 if (err != NPERR_NO_ERROR) |
1166 return false; | 1180 return false; |
1167 | 1181 |
1168 bool ret = false; | 1182 bool ret = false; |
1169 #if defined(OS_MACOSX) | 1183 #if defined(OS_LINUX) |
| 1184 // On Linux we need to get the backing PdfPsMetafile and write the bits |
| 1185 // directly. |
| 1186 cairo_t* context = canvas->beginPlatformPaint(); |
| 1187 printing::NativeMetafile* metafile = |
| 1188 printing::NativeMetafile::FromCairoContext(context); |
| 1189 DCHECK(metafile); |
| 1190 if (metafile) { |
| 1191 ret = metafile->SetRawData(pdf_output, output_size); |
| 1192 if (ret) |
| 1193 pdf_output_done_ = true; |
| 1194 } |
| 1195 canvas->endPlatformPaint(); |
| 1196 #elif defined(OS_MACOSX) |
1170 printing::NativeMetafile metafile; | 1197 printing::NativeMetafile metafile; |
1171 // Create a PDF metafile and render from there into the passed in context. | 1198 // Create a PDF metafile and render from there into the passed in context. |
1172 if (metafile.Init(pdf_output, output_size)) { | 1199 if (metafile.Init(pdf_output, output_size)) { |
1173 // Flip the transform. | 1200 // Flip the transform. |
1174 CGContextSaveGState(canvas); | 1201 CGContextSaveGState(canvas); |
1175 CGContextTranslateCTM(canvas, 0, current_printable_area_.height()); | 1202 CGContextTranslateCTM(canvas, 0, current_printable_area_.height()); |
1176 CGContextScaleCTM(canvas, 1.0, -1.0); | 1203 CGContextScaleCTM(canvas, 1.0, -1.0); |
1177 ret = metafile.RenderPage(1, canvas, current_printable_area_.ToCGRect(), | 1204 ret = metafile.RenderPage(1, canvas, current_printable_area_.ToCGRect(), |
1178 true, false, true, true); | 1205 true, false, true, true); |
1179 CGContextRestoreGState(canvas); | 1206 CGContextRestoreGState(canvas); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1299 } | 1326 } |
1300 | 1327 |
1301 void WebPluginDelegatePepper::PrintEnd() { | 1328 void WebPluginDelegatePepper::PrintEnd() { |
1302 NPPPrintExtensions* print_extensions = GetPrintExtensions(); | 1329 NPPPrintExtensions* print_extensions = GetPrintExtensions(); |
1303 if (print_extensions) | 1330 if (print_extensions) |
1304 print_extensions->printEnd(instance()->npp()); | 1331 print_extensions->printEnd(instance()->npp()); |
1305 current_printable_area_ = gfx::Rect(); | 1332 current_printable_area_ = gfx::Rect(); |
1306 current_printer_dpi_ = -1; | 1333 current_printer_dpi_ = -1; |
1307 #if defined(OS_MACOSX) | 1334 #if defined(OS_MACOSX) |
1308 last_printed_page_ = SkBitmap(); | 1335 last_printed_page_ = SkBitmap(); |
1309 #endif // defined(OS_MACOSX) | 1336 #elif defined(OS_LINUX) |
| 1337 num_pages_ = 0; |
| 1338 pdf_output_done_ = false; |
| 1339 #endif // defined(OS_LINUX) |
1310 } | 1340 } |
1311 | 1341 |
1312 bool WebPluginDelegatePepper::SupportsFind() { | 1342 bool WebPluginDelegatePepper::SupportsFind() { |
1313 return GetFindExtensions() != NULL; | 1343 return GetFindExtensions() != NULL; |
1314 } | 1344 } |
1315 | 1345 |
1316 | 1346 |
1317 WebPluginDelegatePepper::WebPluginDelegatePepper( | 1347 WebPluginDelegatePepper::WebPluginDelegatePepper( |
1318 const base::WeakPtr<RenderView>& render_view, | 1348 const base::WeakPtr<RenderView>& render_view, |
1319 NPAPI::PluginInstance *instance) | 1349 NPAPI::PluginInstance *instance) |
1320 : render_view_(render_view), | 1350 : render_view_(render_view), |
1321 plugin_(NULL), | 1351 plugin_(NULL), |
1322 instance_(instance), | 1352 instance_(instance), |
1323 nested_delegate_(NULL), | 1353 nested_delegate_(NULL), |
1324 current_printer_dpi_(-1), | 1354 current_printer_dpi_(-1), |
| 1355 #if defined (OS_LINUX) |
| 1356 num_pages_(0), |
| 1357 pdf_output_done_(false), |
| 1358 #endif // (OS_LINUX) |
1325 #if defined(ENABLE_GPU) | 1359 #if defined(ENABLE_GPU) |
1326 command_buffer_(NULL), | 1360 command_buffer_(NULL), |
1327 #endif | 1361 #endif |
1328 find_identifier_(-1), | 1362 find_identifier_(-1), |
1329 method_factory3d_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 1363 method_factory3d_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
1330 current_choose_file_callback_(NULL), | 1364 current_choose_file_callback_(NULL), |
1331 current_choose_file_user_data_(NULL) { | 1365 current_choose_file_user_data_(NULL) { |
1332 // For now we keep a window struct, although it isn't used. | 1366 // For now we keep a window struct, although it isn't used. |
1333 memset(&window_, 0, sizeof(window_)); | 1367 memset(&window_, 0, sizeof(window_)); |
1334 // All Pepper plugins are windowless and transparent. | 1368 // All Pepper plugins are windowless and transparent. |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1709 bounds.origin.x = dest_rect.x(); | 1743 bounds.origin.x = dest_rect.x(); |
1710 bounds.origin.y = canvas_height - dest_rect.y() - dest_rect.height(); | 1744 bounds.origin.y = canvas_height - dest_rect.y() - dest_rect.height(); |
1711 bounds.size.width = dest_rect.width(); | 1745 bounds.size.width = dest_rect.width(); |
1712 bounds.size.height = dest_rect.height(); | 1746 bounds.size.height = dest_rect.height(); |
1713 | 1747 |
1714 CGContextDrawImage(canvas, bounds, image); | 1748 CGContextDrawImage(canvas, bounds, image); |
1715 CGContextRestoreGState(canvas); | 1749 CGContextRestoreGState(canvas); |
1716 } | 1750 } |
1717 #endif // defined(OS_MACOSX) | 1751 #endif // defined(OS_MACOSX) |
1718 | 1752 |
OLD | NEW |