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

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

Issue 6990051: Unix ifdefs patch for ui/ and webkit/ (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: 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
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_POSIX) && !defined(OS_MACOSX)
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) 356 #if defined(OS_POSIX) && !defined(OS_MACOSX)
357 canvas_(NULL), 357 canvas_(NULL),
358 #endif // defined(OS_LINUX) 358 #endif // OS_POSIX && !OS_MACOSX
359 plugin_print_interface_(NULL), 359 plugin_print_interface_(NULL),
360 plugin_graphics_3d_interface_(NULL), 360 plugin_graphics_3d_interface_(NULL),
361 always_on_top_(false), 361 always_on_top_(false),
362 fullscreen_container_(NULL), 362 fullscreen_container_(NULL),
363 fullscreen_(false), 363 fullscreen_(false),
364 message_channel_(NULL), 364 message_channel_(NULL),
365 sad_plugin_(NULL) { 365 sad_plugin_(NULL) {
366 pp_instance_ = ResourceTracker::Get()->AddInstance(this); 366 pp_instance_ = ResourceTracker::Get()->AddInstance(this);
367 367
368 memset(&current_print_settings_, 0, sizeof(current_print_settings_)); 368 memset(&current_print_settings_, 0, sizeof(current_print_settings_));
(...skipping 12 matching lines...) Expand all
381 PluginObjectSet plugin_object_copy; 381 PluginObjectSet plugin_object_copy;
382 live_plugin_objects_.swap(plugin_object_copy); 382 live_plugin_objects_.swap(plugin_object_copy);
383 for (PluginObjectSet::iterator i = plugin_object_copy.begin(); 383 for (PluginObjectSet::iterator i = plugin_object_copy.begin();
384 i != plugin_object_copy.end(); ++i) 384 i != plugin_object_copy.end(); ++i)
385 delete *i; 385 delete *i;
386 386
387 delegate_->InstanceDeleted(this); 387 delegate_->InstanceDeleted(this);
388 module_->InstanceDeleted(this); 388 module_->InstanceDeleted(this);
389 389
390 ResourceTracker::Get()->InstanceDeleted(pp_instance_); 390 ResourceTracker::Get()->InstanceDeleted(pp_instance_);
391 #if defined(OS_LINUX) 391 #if defined(OS_POSIX) && !defined(OS_MACOSX)
392 ranges_.clear(); 392 ranges_.clear();
393 #endif // defined(OS_LINUX) 393 #endif // OS_POSIX && !OS_MACOSX
394 } 394 }
395 395
396 // static 396 // static
397 const PPB_Instance* PluginInstance::GetInterface() { 397 const PPB_Instance* PluginInstance::GetInterface() {
398 return &ppb_instance; 398 return &ppb_instance;
399 } 399 }
400 400
401 // static 401 // static
402 const PPB_Find_Dev* PluginInstance::GetFindInterface() { 402 const PPB_Find_Dev* PluginInstance::GetFindInterface() {
403 return &ppb_find; 403 return &ppb_find;
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after
1118 break; 1118 break;
1119 default: 1119 default:
1120 return 0; 1120 return 0;
1121 } 1121 }
1122 num_pages = plugin_print_interface_->Begin_0_3(pp_instance(), 1122 num_pages = plugin_print_interface_->Begin_0_3(pp_instance(),
1123 &print_settings_0_3); 1123 &print_settings_0_3);
1124 } 1124 }
1125 if (!num_pages) 1125 if (!num_pages)
1126 return 0; 1126 return 0;
1127 current_print_settings_ = print_settings; 1127 current_print_settings_ = print_settings;
1128 #if defined(OS_LINUX) 1128 #if defined(OS_POSIX) && !defined(OS_MACOSX)
1129 canvas_ = NULL; 1129 canvas_ = NULL;
1130 ranges_.clear(); 1130 ranges_.clear();
1131 #endif // defined(OS_LINUX) 1131 #endif // OS_POSIX && !OS_MACOSX
1132 return num_pages; 1132 return num_pages;
1133 } 1133 }
1134 1134
1135 bool PluginInstance::PrintPage(int page_number, WebKit::WebCanvas* canvas) { 1135 bool PluginInstance::PrintPage(int page_number, WebKit::WebCanvas* canvas) {
1136 DCHECK(plugin_print_interface_.get()); 1136 DCHECK(plugin_print_interface_.get());
1137 PP_PrintPageNumberRange_Dev page_range; 1137 PP_PrintPageNumberRange_Dev page_range;
1138 page_range.first_page_number = page_range.last_page_number = page_number; 1138 page_range.first_page_number = page_range.last_page_number = page_number;
1139 #if defined(OS_LINUX) 1139 #if defined(OS_POSIX) && !defined(OS_MACOSX)
1140 ranges_.push_back(page_range); 1140 ranges_.push_back(page_range);
1141 canvas_ = canvas; 1141 canvas_ = canvas;
1142 return true; 1142 return true;
1143 #else 1143 #else
1144 return PrintPageHelper(&page_range, 1, canvas); 1144 return PrintPageHelper(&page_range, 1, canvas);
1145 #endif // defined(OS_LINUX) 1145 #endif // defined(OS_POSIX) && !defined(OS_MACOSX)
1146 } 1146 }
1147 1147
1148 bool PluginInstance::PrintPageHelper(PP_PrintPageNumberRange_Dev* page_ranges, 1148 bool PluginInstance::PrintPageHelper(PP_PrintPageNumberRange_Dev* page_ranges,
1149 int num_ranges, 1149 int num_ranges,
1150 WebKit::WebCanvas* canvas) { 1150 WebKit::WebCanvas* canvas) {
1151 // Keep a reference on the stack. See NOTE above. 1151 // Keep a reference on the stack. See NOTE above.
1152 scoped_refptr<PluginInstance> ref(this); 1152 scoped_refptr<PluginInstance> ref(this);
1153 PP_Resource print_output = plugin_print_interface_->PrintPages( 1153 PP_Resource print_output = plugin_print_interface_->PrintPages(
1154 pp_instance(), page_ranges, num_ranges); 1154 pp_instance(), page_ranges, num_ranges);
1155 if (!print_output) 1155 if (!print_output)
1156 return false; 1156 return false;
1157 1157
1158 bool ret = false; 1158 bool ret = false;
1159 1159
1160 if (current_print_settings_.format == PP_PRINTOUTPUTFORMAT_PDF) 1160 if (current_print_settings_.format == PP_PRINTOUTPUTFORMAT_PDF)
1161 ret = PrintPDFOutput(print_output, canvas); 1161 ret = PrintPDFOutput(print_output, canvas);
1162 else if (current_print_settings_.format == PP_PRINTOUTPUTFORMAT_RASTER) 1162 else if (current_print_settings_.format == PP_PRINTOUTPUTFORMAT_RASTER)
1163 ret = PrintRasterOutput(print_output, canvas); 1163 ret = PrintRasterOutput(print_output, canvas);
1164 1164
1165 // Now we need to release the print output resource. 1165 // Now we need to release the print output resource.
1166 PluginModule::GetCore()->ReleaseResource(print_output); 1166 PluginModule::GetCore()->ReleaseResource(print_output);
1167 1167
1168 return ret; 1168 return ret;
1169 } 1169 }
1170 1170
1171 void PluginInstance::PrintEnd() { 1171 void PluginInstance::PrintEnd() {
1172 // Keep a reference on the stack. See NOTE above. 1172 // Keep a reference on the stack. See NOTE above.
1173 scoped_refptr<PluginInstance> ref(this); 1173 scoped_refptr<PluginInstance> ref(this);
1174 #if defined(OS_LINUX) 1174 #if defined(OS_POSIX) && !defined(OS_MACOSX)
1175 // This hack is here because all pages need to be written to PDF at once. 1175 // This hack is here because all pages need to be written to PDF at once.
1176 if (!ranges_.empty()) 1176 if (!ranges_.empty())
1177 PrintPageHelper(&(ranges_.front()), ranges_.size(), canvas_); 1177 PrintPageHelper(&(ranges_.front()), ranges_.size(), canvas_);
1178 canvas_ = NULL; 1178 canvas_ = NULL;
1179 ranges_.clear(); 1179 ranges_.clear();
1180 #endif // defined(OS_LINUX) 1180 #endif // OS_POSIX && !OS_MACOSX
1181 1181
1182 DCHECK(plugin_print_interface_.get()); 1182 DCHECK(plugin_print_interface_.get());
1183 if (plugin_print_interface_.get()) 1183 if (plugin_print_interface_.get())
1184 plugin_print_interface_->End(pp_instance()); 1184 plugin_print_interface_->End(pp_instance());
1185 1185
1186 memset(&current_print_settings_, 0, sizeof(current_print_settings_)); 1186 memset(&current_print_settings_, 0, sizeof(current_print_settings_));
1187 #if defined(OS_MACOSX) 1187 #if defined(OS_MACOSX)
1188 last_printed_page_ = NULL; 1188 last_printed_page_ = NULL;
1189 #endif // defined(OS_MACOSX) 1189 #endif // defined(OS_MACOSX)
1190 } 1190 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 if (!pdf_module) 1286 if (!pdf_module)
1287 return false; 1287 return false;
1288 RenderPDFPageToDCProc render_proc = 1288 RenderPDFPageToDCProc render_proc =
1289 reinterpret_cast<RenderPDFPageToDCProc>( 1289 reinterpret_cast<RenderPDFPageToDCProc>(
1290 GetProcAddress(pdf_module, "RenderPDFPageToDC")); 1290 GetProcAddress(pdf_module, "RenderPDFPageToDC"));
1291 if (!render_proc) 1291 if (!render_proc)
1292 return false; 1292 return false;
1293 #endif // defined(OS_WIN) 1293 #endif // defined(OS_WIN)
1294 1294
1295 bool ret = false; 1295 bool ret = false;
1296 #if defined(OS_LINUX) 1296 #if defined(OS_MACOSX)
1297 // On Linux we just set the final bits in the native metafile
1298 // (NativeMetafile and PreviewMetafile must have compatible formats,
1299 // i.e. both PDF for this to work).
1300 printing::Metafile* metafile =
1301 printing::MetafileSkiaWrapper::GetMetafileFromCanvas(canvas);
1302 DCHECK(metafile != NULL);
1303 if (metafile)
1304 ret = metafile->InitFromData(buffer->mapped_buffer(), buffer->size());
1305 #elif defined(OS_MACOSX)
1306 printing::NativeMetafile metafile; 1297 printing::NativeMetafile metafile;
1307 // Create a PDF metafile and render from there into the passed in context. 1298 // Create a PDF metafile and render from there into the passed in context.
1308 if (metafile.InitFromData(buffer->mapped_buffer(), buffer->size())) { 1299 if (metafile.InitFromData(buffer->mapped_buffer(), buffer->size())) {
1309 // Flip the transform. 1300 // Flip the transform.
1310 CGContextSaveGState(canvas); 1301 CGContextSaveGState(canvas);
1311 CGContextTranslateCTM(canvas, 0, 1302 CGContextTranslateCTM(canvas, 0,
1312 current_print_settings_.printable_area.size.height); 1303 current_print_settings_.printable_area.size.height);
1313 CGContextScaleCTM(canvas, 1.0, -1.0); 1304 CGContextScaleCTM(canvas, 1.0, -1.0);
1314 CGRect page_rect; 1305 CGRect page_rect;
1315 page_rect.origin.x = current_print_settings_.printable_area.point.x; 1306 page_rect.origin.x = current_print_settings_.printable_area.point.x;
1316 page_rect.origin.y = current_print_settings_.printable_area.point.y; 1307 page_rect.origin.y = current_print_settings_.printable_area.point.y;
1317 page_rect.size.width = current_print_settings_.printable_area.size.width; 1308 page_rect.size.width = current_print_settings_.printable_area.size.width;
1318 page_rect.size.height = current_print_settings_.printable_area.size.height; 1309 page_rect.size.height = current_print_settings_.printable_area.size.height;
1319 1310
1320 ret = metafile.RenderPage(1, canvas, page_rect, true, false, true, true); 1311 ret = metafile.RenderPage(1, canvas, page_rect, true, false, true, true);
1321 CGContextRestoreGState(canvas); 1312 CGContextRestoreGState(canvas);
1322 } 1313 }
1314 #elif defined(OS_POSIX)
1315 // On Unix, we just set the final bits in the native metafile
1316 // (NativeMetafile and PreviewMetafile must have compatible formats,
1317 // i.e. both PDF for this to work).
1318 printing::Metafile* metafile =
1319 printing::MetafileSkiaWrapper::GetMetafileFromCanvas(canvas);
1320 DCHECK(metafile != NULL);
1321 if (metafile)
1322 ret = metafile->InitFromData(buffer->mapped_buffer(), buffer->size());
1323 #elif defined(OS_WIN) 1323 #elif defined(OS_WIN)
1324 // On Windows, we now need to render the PDF to the DC that backs the 1324 // On Windows, we now need to render the PDF to the DC that backs the
1325 // supplied canvas. 1325 // supplied canvas.
1326 HDC dc = skia::BeginPlatformPaint(canvas); 1326 HDC dc = skia::BeginPlatformPaint(canvas);
1327 gfx::Size size_in_pixels; 1327 gfx::Size size_in_pixels;
1328 size_in_pixels.set_width( 1328 size_in_pixels.set_width(
1329 printing::ConvertUnit(current_print_settings_.printable_area.size.width, 1329 printing::ConvertUnit(current_print_settings_.printable_area.size.width,
1330 static_cast<int>(printing::kPointsPerInch), 1330 static_cast<int>(printing::kPointsPerInch),
1331 current_print_settings_.dpi)); 1331 current_print_settings_.dpi));
1332 size_in_pixels.set_height( 1332 size_in_pixels.set_height(
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1560 return found->second; 1560 return found->second;
1561 } 1561 }
1562 1562
1563 bool PluginInstance::IsFullPagePlugin() const { 1563 bool PluginInstance::IsFullPagePlugin() const {
1564 WebFrame* frame = container()->element().document().frame(); 1564 WebFrame* frame = container()->element().document().frame();
1565 return frame->view()->mainFrame()->document().isPluginDocument(); 1565 return frame->view()->mainFrame()->document().isPluginDocument();
1566 } 1566 }
1567 1567
1568 } // namespace ppapi 1568 } // namespace ppapi
1569 } // namespace webkit 1569 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698