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

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

Issue 8231030: PrintPreview: [Win] Added a temporary hack to print blank pdf pages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 2 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 | « no previous file | 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/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 namespace ppapi { 123 namespace ppapi {
124 124
125 #if defined(OS_WIN) 125 #if defined(OS_WIN)
126 // Exported by pdf.dll 126 // Exported by pdf.dll
127 typedef bool (*RenderPDFPageToDCProc)( 127 typedef bool (*RenderPDFPageToDCProc)(
128 const unsigned char* pdf_buffer, int buffer_size, int page_number, HDC dc, 128 const unsigned char* pdf_buffer, int buffer_size, int page_number, HDC dc,
129 int dpi_x, int dpi_y, int bounds_origin_x, int bounds_origin_y, 129 int dpi_x, int dpi_y, int bounds_origin_x, int bounds_origin_y,
130 int bounds_width, int bounds_height, bool fit_to_bounds, 130 int bounds_width, int bounds_height, bool fit_to_bounds,
131 bool stretch_to_bounds, bool keep_aspect_ratio, bool center_in_bounds, 131 bool stretch_to_bounds, bool keep_aspect_ratio, bool center_in_bounds,
132 bool autorotate); 132 bool autorotate);
133
134 void DrawEmptyRectangle(HDC dc) {
135 // TODO(sanjeevr): This is a temporary hack. If we output a JPEG
136 // to the EMF, the EnumEnhMetaFile call fails in the browser
137 // process. The failure also happens if we output nothing here.
138 // We need to investigate the reason for this failure and fix it.
139 // In the meantime this temporary hack of drawing an empty
140 // rectangle in the DC gets us by.
141 Rectangle(dc, 0, 0, 0, 0);
142 }
133 #endif // defined(OS_WIN) 143 #endif // defined(OS_WIN)
134 144
135 namespace { 145 namespace {
136 146
137 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, np_name) \ 147 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, np_name) \
138 COMPILE_ASSERT(static_cast<int>(WebCursorInfo::webkit_name) \ 148 COMPILE_ASSERT(static_cast<int>(WebCursorInfo::webkit_name) \
139 == static_cast<int>(np_name), \ 149 == static_cast<int>(np_name), \
140 mismatching_enums) 150 mismatching_enums)
141 151
142 COMPILE_ASSERT_MATCHING_ENUM(TypePointer, PP_CURSORTYPE_POINTER); 152 COMPILE_ASSERT_MATCHING_ENUM(TypePointer, PP_CURSORTYPE_POINTER);
(...skipping 1012 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 printing::Metafile* metafile = 1165 printing::Metafile* metafile =
1156 printing::MetafileSkiaWrapper::GetMetafileFromCanvas(*canvas); 1166 printing::MetafileSkiaWrapper::GetMetafileFromCanvas(*canvas);
1157 if (metafile) { 1167 if (metafile) {
1158 // We only have a metafile when doing print preview, so we just want to 1168 // We only have a metafile when doing print preview, so we just want to
1159 // pass the PDF off to preview. 1169 // pass the PDF off to preview.
1160 ret = metafile->InitFromData(mapper.data(), mapper.size()); 1170 ret = metafile->InitFromData(mapper.data(), mapper.size());
1161 } else { 1171 } else {
1162 // On Windows, we now need to render the PDF to the DC that backs the 1172 // On Windows, we now need to render the PDF to the DC that backs the
1163 // supplied canvas. 1173 // supplied canvas.
1164 HDC dc = skia::BeginPlatformPaint(canvas); 1174 HDC dc = skia::BeginPlatformPaint(canvas);
1175 DrawEmptyRectangle(dc);
1165 gfx::Size size_in_pixels; 1176 gfx::Size size_in_pixels;
1166 size_in_pixels.set_width(printing::ConvertUnit( 1177 size_in_pixels.set_width(printing::ConvertUnit(
1167 current_print_settings_.printable_area.size.width, 1178 current_print_settings_.printable_area.size.width,
1168 static_cast<int>(printing::kPointsPerInch), 1179 static_cast<int>(printing::kPointsPerInch),
1169 current_print_settings_.dpi)); 1180 current_print_settings_.dpi));
1170 size_in_pixels.set_height(printing::ConvertUnit( 1181 size_in_pixels.set_height(printing::ConvertUnit(
1171 current_print_settings_.printable_area.size.height, 1182 current_print_settings_.printable_area.size.height,
1172 static_cast<int>(printing::kPointsPerInch), 1183 static_cast<int>(printing::kPointsPerInch),
1173 current_print_settings_.dpi)); 1184 current_print_settings_.dpi));
1174 // We need to render using the actual printer DPI (rendering to a smaller 1185 // We need to render using the actual printer DPI (rendering to a smaller
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1274 static_cast<int>(bitmap.rowBytes()), 100, &compressed_image); 1285 static_cast<int>(bitmap.rowBytes()), 100, &compressed_image);
1275 UMA_HISTOGRAM_TIMES("PepperPluginPrint.RasterBitmapCompressTime", 1286 UMA_HISTOGRAM_TIMES("PepperPluginPrint.RasterBitmapCompressTime",
1276 base::TimeTicks::Now() - start_time); 1287 base::TimeTicks::Now() - start_time);
1277 if (!encoded) { 1288 if (!encoded) {
1278 NOTREACHED(); 1289 NOTREACHED();
1279 return false; 1290 return false;
1280 } 1291 }
1281 1292
1282 skia::ScopedPlatformPaint scoped_platform_paint(canvas); 1293 skia::ScopedPlatformPaint scoped_platform_paint(canvas);
1283 HDC dc = scoped_platform_paint.GetPlatformSurface(); 1294 HDC dc = scoped_platform_paint.GetPlatformSurface();
1284 // TODO(sanjeevr): This is a temporary hack. If we output a JPEG 1295 DrawEmptyRectangle(dc);
1285 // to the EMF, the EnumEnhMetaFile call fails in the browser
1286 // process. The failure also happens if we output nothing here.
1287 // We need to investigate the reason for this failure and fix it.
1288 // In the meantime this temporary hack of drawing an empty
1289 // rectangle in the DC gets us by.
1290 Rectangle(dc, 0, 0, 0, 0);
1291 BITMAPINFOHEADER bmi = {0}; 1296 BITMAPINFOHEADER bmi = {0};
1292 gfx::CreateBitmapHeader(bitmap.width(), bitmap.height(), &bmi); 1297 gfx::CreateBitmapHeader(bitmap.width(), bitmap.height(), &bmi);
1293 bmi.biCompression = BI_JPEG; 1298 bmi.biCompression = BI_JPEG;
1294 bmi.biSizeImage = compressed_image.size(); 1299 bmi.biSizeImage = compressed_image.size();
1295 bmi.biHeight = -bmi.biHeight; 1300 bmi.biHeight = -bmi.biHeight;
1296 StretchDIBits(dc, printable_area.x(), printable_area.y(), 1301 StretchDIBits(dc, printable_area.x(), printable_area.y(),
1297 printable_area.width(), printable_area.height(), 1302 printable_area.width(), printable_area.height(),
1298 0, 0, bitmap.width(), bitmap.height(), 1303 0, 0, bitmap.width(), bitmap.height(),
1299 &compressed_image.front(), 1304 &compressed_image.front(),
1300 reinterpret_cast<const BITMAPINFO*>(&bmi), 1305 reinterpret_cast<const BITMAPINFO*>(&bmi),
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
1806 } 1811 }
1807 WebKit::WebDocument main_document = 1812 WebKit::WebDocument main_document =
1808 containing_document.frame()->view()->mainFrame()->document(); 1813 containing_document.frame()->view()->mainFrame()->document();
1809 1814
1810 return containing_document.securityOrigin().canAccess( 1815 return containing_document.securityOrigin().canAccess(
1811 main_document.securityOrigin()); 1816 main_document.securityOrigin());
1812 } 1817 }
1813 1818
1814 } // namespace ppapi 1819 } // namespace ppapi
1815 } // namespace webkit 1820 } // namespace webkit
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698