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

Side by Side Diff: webkit/glue/plugins/pepper_plugin_instance.cc

Issue 3255003: Pull new PPAPI, rename non-P0 interfaces to Dev, rename DeviceContext2D to Gr... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 3 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 #include "webkit/glue/plugins/pepper_plugin_instance.h" 5 #include "webkit/glue/plugins/pepper_plugin_instance.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/histogram.h" 8 #include "base/histogram.h"
9 #if defined(OS_MACOSX) 9 #if defined(OS_MACOSX)
10 #include "base/mac_util.h" 10 #include "base/mac_util.h"
11 #include "base/scoped_cftyperef.h" 11 #include "base/scoped_cftyperef.h"
12 #endif 12 #endif
13 #include "base/scoped_ptr.h" 13 #include "base/scoped_ptr.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "gfx/rect.h" 15 #include "gfx/rect.h"
16 #if defined(OS_WIN) 16 #if defined(OS_WIN)
17 #include "gfx/codec/jpeg_codec.h" 17 #include "gfx/codec/jpeg_codec.h"
18 #include "gfx/gdi_util.h" 18 #include "gfx/gdi_util.h"
19 #endif 19 #endif
20 #include "gfx/skia_util.h" 20 #include "gfx/skia_util.h"
21 #include "printing/native_metafile.h" 21 #include "printing/native_metafile.h"
22 #include "printing/units.h" 22 #include "printing/units.h"
23 #include "skia/ext/vector_platform_device.h" 23 #include "skia/ext/vector_platform_device.h"
24 #include "skia/ext/platform_canvas.h" 24 #include "skia/ext/platform_canvas.h"
25 #include "third_party/ppapi/c/dev/ppb_find_dev.h"
26 #include "third_party/ppapi/c/dev/ppp_find_dev.h"
27 #include "third_party/ppapi/c/dev/ppp_zoom_dev.h"
28 #include "third_party/ppapi/c/pp_event.h"
25 #include "third_party/ppapi/c/pp_instance.h" 29 #include "third_party/ppapi/c/pp_instance.h"
26 #include "third_party/ppapi/c/pp_event.h"
27 #include "third_party/ppapi/c/pp_rect.h" 30 #include "third_party/ppapi/c/pp_rect.h"
28 #include "third_party/ppapi/c/pp_resource.h" 31 #include "third_party/ppapi/c/pp_resource.h"
29 #include "third_party/ppapi/c/pp_var.h" 32 #include "third_party/ppapi/c/pp_var.h"
30 #include "third_party/ppapi/c/ppb_core.h" 33 #include "third_party/ppapi/c/ppb_core.h"
31 #include "third_party/ppapi/c/ppb_find.h"
32 #include "third_party/ppapi/c/ppb_instance.h" 34 #include "third_party/ppapi/c/ppb_instance.h"
33 #include "third_party/ppapi/c/ppp_find.h"
34 #include "third_party/ppapi/c/ppp_instance.h" 35 #include "third_party/ppapi/c/ppp_instance.h"
35 #include "third_party/ppapi/c/ppp_zoom.h"
36 #include "third_party/WebKit/WebKit/chromium/public/WebCursorInfo.h" 36 #include "third_party/WebKit/WebKit/chromium/public/WebCursorInfo.h"
37 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" 37 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
38 #include "third_party/WebKit/WebKit/chromium/public/WebElement.h" 38 #include "third_party/WebKit/WebKit/chromium/public/WebElement.h"
39 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" 39 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
40 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" 40 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h"
41 #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" 41 #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h"
42 #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" 42 #include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
43 #include "webkit/glue/plugins/pepper_buffer.h" 43 #include "webkit/glue/plugins/pepper_buffer.h"
44 #include "webkit/glue/plugins/pepper_device_context_2d.h" 44 #include "webkit/glue/plugins/pepper_graphics_2d.h"
45 #include "webkit/glue/plugins/pepper_event_conversion.h" 45 #include "webkit/glue/plugins/pepper_event_conversion.h"
46 #include "webkit/glue/plugins/pepper_image_data.h" 46 #include "webkit/glue/plugins/pepper_image_data.h"
47 #include "webkit/glue/plugins/pepper_plugin_delegate.h" 47 #include "webkit/glue/plugins/pepper_plugin_delegate.h"
48 #include "webkit/glue/plugins/pepper_plugin_module.h" 48 #include "webkit/glue/plugins/pepper_plugin_module.h"
49 #include "webkit/glue/plugins/pepper_string.h" 49 #include "webkit/glue/plugins/pepper_string.h"
50 #include "webkit/glue/plugins/pepper_url_loader.h" 50 #include "webkit/glue/plugins/pepper_url_loader.h"
51 #include "webkit/glue/plugins/pepper_var.h" 51 #include "webkit/glue/plugins/pepper_var.h"
52 52
53 using WebKit::WebCanvas; 53 using WebKit::WebCanvas;
54 using WebKit::WebCursorInfo; 54 using WebKit::WebCursorInfo;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 return instance->GetWindowObject(); 139 return instance->GetWindowObject();
140 } 140 }
141 141
142 PP_Var GetOwnerElementObject(PP_Instance instance_id) { 142 PP_Var GetOwnerElementObject(PP_Instance instance_id) {
143 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id); 143 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
144 if (!instance) 144 if (!instance)
145 return PP_MakeVoid(); 145 return PP_MakeVoid();
146 return instance->GetOwnerElementObject(); 146 return instance->GetOwnerElementObject();
147 } 147 }
148 148
149 bool BindGraphicsDeviceContext(PP_Instance instance_id, PP_Resource device_id) { 149 bool BindGraphics(PP_Instance instance_id, PP_Resource device_id) {
150 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id); 150 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
151 if (!instance) 151 if (!instance)
152 return false; 152 return false;
153 return instance->BindGraphicsDeviceContext(device_id); 153 return instance->BindGraphics(device_id);
154 } 154 }
155 155
156 bool IsFullFrame(PP_Instance instance_id) { 156 bool IsFullFrame(PP_Instance instance_id) {
157 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id); 157 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
158 if (!instance) 158 if (!instance)
159 return false; 159 return false;
160 return instance->full_frame(); 160 return instance->full_frame();
161 } 161 }
162 162
163 const PPB_Instance ppb_instance = { 163 const PPB_Instance ppb_instance = {
164 &GetWindowObject, 164 &GetWindowObject,
165 &GetOwnerElementObject, 165 &GetOwnerElementObject,
166 &BindGraphicsDeviceContext, 166 &BindGraphics,
167 &IsFullFrame, 167 &IsFullFrame,
168 }; 168 };
169 169
170 void NumberOfFindResultsChanged(PP_Instance instance_id, 170 void NumberOfFindResultsChanged(PP_Instance instance_id,
171 int32_t total, 171 int32_t total,
172 bool final_result) { 172 bool final_result) {
173 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id); 173 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
174 if (!instance) 174 if (!instance)
175 return; 175 return;
176 176
177 DCHECK_NE(instance->find_identifier(), -1); 177 DCHECK_NE(instance->find_identifier(), -1);
178 instance->delegate()->DidChangeNumberOfFindResults( 178 instance->delegate()->DidChangeNumberOfFindResults(
179 instance->find_identifier(), total, final_result); 179 instance->find_identifier(), total, final_result);
180 } 180 }
181 181
182 void SelectedFindResultChanged(PP_Instance instance_id, 182 void SelectedFindResultChanged(PP_Instance instance_id,
183 int32_t index) { 183 int32_t index) {
184 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id); 184 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
185 if (!instance) 185 if (!instance)
186 return; 186 return;
187 187
188 DCHECK_NE(instance->find_identifier(), -1); 188 DCHECK_NE(instance->find_identifier(), -1);
189 instance->delegate()->DidChangeSelectedFindResult( 189 instance->delegate()->DidChangeSelectedFindResult(
190 instance->find_identifier(), index); 190 instance->find_identifier(), index);
191 } 191 }
192 192
193 const PPB_Find ppb_find = { 193 const PPB_Find_Dev ppb_find = {
194 &NumberOfFindResultsChanged, 194 &NumberOfFindResultsChanged,
195 &SelectedFindResultChanged, 195 &SelectedFindResultChanged,
196 }; 196 };
197 197
198 } // namespace 198 } // namespace
199 199
200 PluginInstance::PluginInstance(PluginDelegate* delegate, 200 PluginInstance::PluginInstance(PluginDelegate* delegate,
201 PluginModule* module, 201 PluginModule* module,
202 const PPP_Instance* instance_interface) 202 const PPP_Instance* instance_interface)
203 : delegate_(delegate), 203 : delegate_(delegate),
(...skipping 25 matching lines...) Expand all
229 const PPB_Instance* PluginInstance::GetInterface() { 229 const PPB_Instance* PluginInstance::GetInterface() {
230 return &ppb_instance; 230 return &ppb_instance;
231 } 231 }
232 232
233 // static 233 // static
234 PluginInstance* PluginInstance::FromPPInstance(PP_Instance instance) { 234 PluginInstance* PluginInstance::FromPPInstance(PP_Instance instance) {
235 return reinterpret_cast<PluginInstance*>(instance); 235 return reinterpret_cast<PluginInstance*>(instance);
236 } 236 }
237 237
238 // static 238 // static
239 const PPB_Find* PluginInstance::GetFindInterface() { 239 const PPB_Find_Dev* PluginInstance::GetFindInterface() {
240 return &ppb_find; 240 return &ppb_find;
241 } 241 }
242 242
243 PP_Instance PluginInstance::GetPPInstance() { 243 PP_Instance PluginInstance::GetPPInstance() {
244 return reinterpret_cast<intptr_t>(this); 244 return reinterpret_cast<intptr_t>(this);
245 } 245 }
246 246
247 void PluginInstance::Paint(WebCanvas* canvas, 247 void PluginInstance::Paint(WebCanvas* canvas,
248 const gfx::Rect& plugin_rect, 248 const gfx::Rect& plugin_rect,
249 const gfx::Rect& paint_rect) { 249 const gfx::Rect& paint_rect) {
250 if (device_context_2d_) 250 if (bound_graphics_2d_)
251 device_context_2d_->Paint(canvas, plugin_rect, paint_rect); 251 bound_graphics_2d_->Paint(canvas, plugin_rect, paint_rect);
252 } 252 }
253 253
254 void PluginInstance::InvalidateRect(const gfx::Rect& rect) { 254 void PluginInstance::InvalidateRect(const gfx::Rect& rect) {
255 if (!container_ || position_.IsEmpty()) 255 if (!container_ || position_.IsEmpty())
256 return; // Nothing to do. 256 return; // Nothing to do.
257 if (rect.IsEmpty()) 257 if (rect.IsEmpty())
258 container_->invalidate(); 258 container_->invalidate();
259 else 259 else
260 container_->invalidateRect(rect); 260 container_->invalidateRect(rect);
261 } 261 }
262 262
263 PP_Var PluginInstance::GetWindowObject() { 263 PP_Var PluginInstance::GetWindowObject() {
264 if (!container_) 264 if (!container_)
265 return PP_MakeVoid(); 265 return PP_MakeVoid();
266 266
267 WebFrame* frame = container_->element().document().frame(); 267 WebFrame* frame = container_->element().document().frame();
268 if (!frame) 268 if (!frame)
269 return PP_MakeVoid(); 269 return PP_MakeVoid();
270 270
271 return NPObjectToPPVar(frame->windowObject()); 271 return NPObjectToPPVar(frame->windowObject());
272 } 272 }
273 273
274 PP_Var PluginInstance::GetOwnerElementObject() { 274 PP_Var PluginInstance::GetOwnerElementObject() {
275 if (!container_) 275 if (!container_)
276 return PP_MakeVoid(); 276 return PP_MakeVoid();
277 277
278 return NPObjectToPPVar(container_->scriptableObjectForElement()); 278 return NPObjectToPPVar(container_->scriptableObjectForElement());
279 } 279 }
280 280
281 bool PluginInstance::BindGraphicsDeviceContext(PP_Resource device_id) { 281 bool PluginInstance::BindGraphics(PP_Resource device_id) {
282 if (!device_id) { 282 if (!device_id) {
283 // Special-case clearing the current device. 283 // Special-case clearing the current device.
284 if (device_context_2d_) { 284 if (bound_graphics_2d_) {
285 device_context_2d_->BindToInstance(NULL); 285 bound_graphics_2d_->BindToInstance(NULL);
286 device_context_2d_ = NULL; 286 bound_graphics_2d_ = NULL;
287 InvalidateRect(gfx::Rect()); 287 InvalidateRect(gfx::Rect());
288 } 288 }
289 return true; 289 return true;
290 } 290 }
291 291
292 scoped_refptr<DeviceContext2D> device_2d = 292 scoped_refptr<Graphics2D> device_2d = Resource::GetAs<Graphics2D>(device_id);
293 Resource::GetAs<DeviceContext2D>(device_id);
294 293
295 if (device_2d) { 294 if (device_2d) {
296 if (!device_2d->BindToInstance(this)) 295 if (!device_2d->BindToInstance(this))
297 return false; // Can't bind to more than one instance. 296 return false; // Can't bind to more than one instance.
298 297
299 // See http://crbug.com/49403: this can be further optimized by keeping the 298 // See http://crbug.com/49403: this can be further optimized by keeping the
300 // old device around and painting from it. 299 // old device around and painting from it.
301 if (device_context_2d_.get()) { 300 if (bound_graphics_2d_.get()) {
302 // Start the new image with the content of the old image until the plugin 301 // Start the new image with the content of the old image until the plugin
303 // repaints. 302 // repaints.
304 const SkBitmap* old_backing_bitmap = 303 const SkBitmap* old_backing_bitmap =
305 device_context_2d_->image_data()->GetMappedBitmap(); 304 bound_graphics_2d_->image_data()->GetMappedBitmap();
306 SkRect old_size = SkRect::MakeWH( 305 SkRect old_size = SkRect::MakeWH(
307 SkScalar(static_cast<float>(old_backing_bitmap->width())), 306 SkScalar(static_cast<float>(old_backing_bitmap->width())),
308 SkScalar(static_cast<float>(old_backing_bitmap->height()))); 307 SkScalar(static_cast<float>(old_backing_bitmap->height())));
309 308
310 SkCanvas canvas(*device_2d->image_data()->GetMappedBitmap()); 309 SkCanvas canvas(*device_2d->image_data()->GetMappedBitmap());
311 canvas.drawBitmap(*old_backing_bitmap, 0, 0); 310 canvas.drawBitmap(*old_backing_bitmap, 0, 0);
312 311
313 // Fill in any extra space with white. 312 // Fill in any extra space with white.
314 canvas.clipRect(old_size, SkRegion::kDifference_Op); 313 canvas.clipRect(old_size, SkRegion::kDifference_Op);
315 canvas.drawARGB(255, 255, 255, 255); 314 canvas.drawARGB(255, 255, 255, 255);
316 } 315 }
317 316
318 device_context_2d_ = device_2d; 317 bound_graphics_2d_ = device_2d;
319 // BindToInstance will have invalidated the plugin if necessary. 318 // BindToInstance will have invalidated the plugin if necessary.
320 } 319 }
321 320
322 return true; 321 return true;
323 } 322 }
324 323
325 bool PluginInstance::SetCursor(PP_CursorType_Dev type) { 324 bool PluginInstance::SetCursor(PP_CursorType_Dev type) {
326 cursor_.reset(new WebCursorInfo(static_cast<WebCursorInfo::Type>(type))); 325 cursor_.reset(new WebCursorInfo(static_cast<WebCursorInfo::Type>(type)));
327 return true; 326 return true;
328 } 327 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 clip_ = clip; 389 clip_ = clip;
391 } 390 }
392 391
393 PP_Rect pp_position, pp_clip; 392 PP_Rect pp_position, pp_clip;
394 RectToPPRect(position_, &pp_position); 393 RectToPPRect(position_, &pp_position);
395 RectToPPRect(clip_, &pp_clip); 394 RectToPPRect(clip_, &pp_clip);
396 instance_interface_->ViewChanged(GetPPInstance(), &pp_position, &pp_clip); 395 instance_interface_->ViewChanged(GetPPInstance(), &pp_position, &pp_clip);
397 } 396 }
398 397
399 void PluginInstance::ViewInitiatedPaint() { 398 void PluginInstance::ViewInitiatedPaint() {
400 if (device_context_2d_) 399 if (bound_graphics_2d_)
401 device_context_2d_->ViewInitiatedPaint(); 400 bound_graphics_2d_->ViewInitiatedPaint();
402 } 401 }
403 402
404 void PluginInstance::ViewFlushedPaint() { 403 void PluginInstance::ViewFlushedPaint() {
405 if (device_context_2d_) 404 if (bound_graphics_2d_)
406 device_context_2d_->ViewFlushedPaint(); 405 bound_graphics_2d_->ViewFlushedPaint();
407 } 406 }
408 407
409 string16 PluginInstance::GetSelectedText(bool html) { 408 string16 PluginInstance::GetSelectedText(bool html) {
410 PP_Var rv = instance_interface_->GetSelectedText(GetPPInstance(), html); 409 PP_Var rv = instance_interface_->GetSelectedText(GetPPInstance(), html);
411 String* string = GetString(rv); 410 String* string = GetString(rv);
412 if (!string) 411 if (!string)
413 return string16(); 412 return string16();
414 return UTF8ToUTF16(string->value()); 413 return UTF8ToUTF16(string->value());
415 } 414 }
416 415
(...skipping 23 matching lines...) Expand all
440 void PluginInstance::StopFind() { 439 void PluginInstance::StopFind() {
441 if (!LoadFindInterface()) 440 if (!LoadFindInterface())
442 return; 441 return;
443 find_identifier_ = -1; 442 find_identifier_ = -1;
444 plugin_find_interface_->StopFind(GetPPInstance()); 443 plugin_find_interface_->StopFind(GetPPInstance());
445 } 444 }
446 445
447 bool PluginInstance::LoadFindInterface() { 446 bool PluginInstance::LoadFindInterface() {
448 if (!plugin_find_interface_) { 447 if (!plugin_find_interface_) {
449 plugin_find_interface_ = 448 plugin_find_interface_ =
450 reinterpret_cast<const PPP_Find*>(module_->GetPluginInterface( 449 reinterpret_cast<const PPP_Find_Dev*>(module_->GetPluginInterface(
451 PPP_FIND_INTERFACE)); 450 PPP_FIND_DEV_INTERFACE));
452 } 451 }
453 452
454 return !!plugin_find_interface_; 453 return !!plugin_find_interface_;
455 } 454 }
456 455
457 bool PluginInstance::LoadZoomInterface() { 456 bool PluginInstance::LoadZoomInterface() {
458 if (!plugin_zoom_interface_) { 457 if (!plugin_zoom_interface_) {
459 plugin_zoom_interface_ = 458 plugin_zoom_interface_ =
460 reinterpret_cast<const PPP_Zoom*>(module_->GetPluginInterface( 459 reinterpret_cast<const PPP_Zoom_Dev*>(module_->GetPluginInterface(
461 PPP_ZOOM_INTERFACE)); 460 PPP_ZOOM_DEV_INTERFACE));
462 } 461 }
463 462
464 return !!plugin_zoom_interface_; 463 return !!plugin_zoom_interface_;
465 } 464 }
466 465
467 bool PluginInstance::GetPreferredPrintOutputFormat( 466 bool PluginInstance::GetPreferredPrintOutputFormat(
468 PP_PrintOutputFormat* format) { 467 PP_PrintOutputFormat_Dev* format) {
469 if (!plugin_print_interface_) { 468 if (!plugin_print_interface_) {
470 plugin_print_interface_ = 469 plugin_print_interface_ =
471 reinterpret_cast<const PPP_Printing*>(module_->GetPluginInterface( 470 reinterpret_cast<const PPP_Printing_Dev*>(module_->GetPluginInterface(
472 PPP_PRINTING_INTERFACE)); 471 PPP_PRINTING_DEV_INTERFACE));
473 } 472 }
474 if (!plugin_print_interface_) 473 if (!plugin_print_interface_)
475 return false; 474 return false;
476 uint32_t format_count = 0; 475 uint32_t format_count = 0;
477 PP_PrintOutputFormat* supported_formats = 476 PP_PrintOutputFormat_Dev* supported_formats =
478 plugin_print_interface_->QuerySupportedFormats(GetPPInstance(), 477 plugin_print_interface_->QuerySupportedFormats(GetPPInstance(),
479 &format_count); 478 &format_count);
480 if (!supported_formats) 479 if (!supported_formats)
481 return false; 480 return false;
482 481
483 bool found_supported_format = false; 482 bool found_supported_format = false;
484 for (uint32_t index = 0; index < format_count; index++) { 483 for (uint32_t index = 0; index < format_count; index++) {
485 if (supported_formats[index] == PP_PRINTOUTPUTFORMAT_PDF) { 484 if (supported_formats[index] == PP_PRINTOUTPUTFORMAT_PDF) {
486 // If we found PDF, we are done. 485 // If we found PDF, we are done.
487 found_supported_format = true; 486 found_supported_format = true;
488 *format = PP_PRINTOUTPUTFORMAT_PDF; 487 *format = PP_PRINTOUTPUTFORMAT_PDF;
489 break; 488 break;
490 } else if (supported_formats[index] == PP_PRINTOUTPUTFORMAT_RASTER) { 489 } else if (supported_formats[index] == PP_PRINTOUTPUTFORMAT_RASTER) {
491 // We found raster. Keep looking. 490 // We found raster. Keep looking.
492 found_supported_format = true; 491 found_supported_format = true;
493 *format = PP_PRINTOUTPUTFORMAT_RASTER; 492 *format = PP_PRINTOUTPUTFORMAT_RASTER;
494 } 493 }
495 } 494 }
496 PluginModule::GetCore()->MemFree(supported_formats); 495 PluginModule::GetCore()->MemFree(supported_formats);
497 return found_supported_format; 496 return found_supported_format;
498 } 497 }
499 498
500 bool PluginInstance::SupportsPrintInterface() { 499 bool PluginInstance::SupportsPrintInterface() {
501 PP_PrintOutputFormat format; 500 PP_PrintOutputFormat_Dev format;
502 return GetPreferredPrintOutputFormat(&format); 501 return GetPreferredPrintOutputFormat(&format);
503 } 502 }
504 503
505 int PluginInstance::PrintBegin(const gfx::Rect& printable_area, 504 int PluginInstance::PrintBegin(const gfx::Rect& printable_area,
506 int printer_dpi) { 505 int printer_dpi) {
507 PP_PrintOutputFormat format; 506 PP_PrintOutputFormat_Dev format;
508 if (!GetPreferredPrintOutputFormat(&format)) { 507 if (!GetPreferredPrintOutputFormat(&format)) {
509 // PrintBegin should not have been called since SupportsPrintInterface 508 // PrintBegin should not have been called since SupportsPrintInterface
510 // would have returned false; 509 // would have returned false;
511 NOTREACHED(); 510 NOTREACHED();
512 return 0; 511 return 0;
513 } 512 }
514 513
515 PP_PrintSettings print_settings; 514 PP_PrintSettings_Dev print_settings;
516 RectToPPRect(printable_area, &print_settings.printable_area); 515 RectToPPRect(printable_area, &print_settings.printable_area);
517 print_settings.dpi = printer_dpi; 516 print_settings.dpi = printer_dpi;
518 print_settings.orientation = PP_PRINTORIENTATION_NORMAL; 517 print_settings.orientation = PP_PRINTORIENTATION_NORMAL;
519 print_settings.grayscale = false; 518 print_settings.grayscale = false;
520 print_settings.format = format; 519 print_settings.format = format;
521 int num_pages = plugin_print_interface_->Begin(GetPPInstance(), 520 int num_pages = plugin_print_interface_->Begin(GetPPInstance(),
522 &print_settings); 521 &print_settings);
523 if (!num_pages) 522 if (!num_pages)
524 return 0; 523 return 0;
525 current_print_settings_ = print_settings; 524 current_print_settings_ = print_settings;
526 #if defined (OS_LINUX) 525 #if defined (OS_LINUX)
527 num_pages_ = num_pages; 526 num_pages_ = num_pages;
528 pdf_output_done_ = false; 527 pdf_output_done_ = false;
529 #endif // (OS_LINUX) 528 #endif // (OS_LINUX)
530 return num_pages; 529 return num_pages;
531 } 530 }
532 531
533 bool PluginInstance::PrintPage(int page_number, WebKit::WebCanvas* canvas) { 532 bool PluginInstance::PrintPage(int page_number, WebKit::WebCanvas* canvas) {
534 DCHECK(plugin_print_interface_); 533 DCHECK(plugin_print_interface_);
535 PP_PrintPageNumberRange page_range; 534 PP_PrintPageNumberRange_Dev page_range;
536 #if defined(OS_LINUX) 535 #if defined(OS_LINUX)
537 if (current_print_settings_.format == PP_PRINTOUTPUTFORMAT_PDF) { 536 if (current_print_settings_.format == PP_PRINTOUTPUTFORMAT_PDF) {
538 // On Linux we will try and output all pages as PDF in the first call to 537 // On Linux we will try and output all pages as PDF in the first call to
539 // PrintPage. This is a temporary hack. 538 // PrintPage. This is a temporary hack.
540 // TODO(sanjeevr): Remove this hack and fix this by changing the print 539 // TODO(sanjeevr): Remove this hack and fix this by changing the print
541 // interfaces for WebFrame and WebPlugin. 540 // interfaces for WebFrame and WebPlugin.
542 if (page_number != 0) 541 if (page_number != 0)
543 return pdf_output_done_; 542 return pdf_output_done_;
544 page_range.first_page_number = 0; 543 page_range.first_page_number = 0;
545 page_range.last_page_number = num_pages_ - 1; 544 page_range.last_page_number = num_pages_ - 1;
(...skipping 30 matching lines...) Expand all
576 last_printed_page_ = NULL; 575 last_printed_page_ = NULL;
577 #elif defined(OS_LINUX) 576 #elif defined(OS_LINUX)
578 num_pages_ = 0; 577 num_pages_ = 0;
579 pdf_output_done_ = false; 578 pdf_output_done_ = false;
580 #endif // defined(OS_LINUX) 579 #endif // defined(OS_LINUX)
581 } 580 }
582 581
583 void PluginInstance::Graphics3DContextLost() { 582 void PluginInstance::Graphics3DContextLost() {
584 if (!plugin_graphics_3d_interface_) { 583 if (!plugin_graphics_3d_interface_) {
585 plugin_graphics_3d_interface_ = 584 plugin_graphics_3d_interface_ =
586 reinterpret_cast<const PPP_Graphics3D*>(module_->GetPluginInterface( 585 reinterpret_cast<const PPP_Graphics3D_Dev*>(module_->GetPluginInterface(
587 PPP_GRAPHICS_3D_INTERFACE)); 586 PPP_GRAPHICS_3D_DEV_INTERFACE));
588 } 587 }
589 if (plugin_graphics_3d_interface_) 588 if (plugin_graphics_3d_interface_)
590 plugin_graphics_3d_interface_->Graphics3DContextLost(GetPPInstance()); 589 plugin_graphics_3d_interface_->Graphics3DContextLost(GetPPInstance());
591 } 590 }
592 591
593 bool PluginInstance::PrintPDFOutput(PP_Resource print_output, 592 bool PluginInstance::PrintPDFOutput(PP_Resource print_output,
594 WebKit::WebCanvas* canvas) { 593 WebKit::WebCanvas* canvas) {
595 scoped_refptr<Buffer> buffer(Resource::GetAs<Buffer>(print_output)); 594 scoped_refptr<Buffer> buffer(Resource::GetAs<Buffer>(print_output));
596 if (!buffer.get() || !buffer->is_mapped() || !buffer->size()) { 595 if (!buffer.get() || !buffer->is_mapped() || !buffer->size()) {
597 NOTREACHED(); 596 NOTREACHED();
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 bounds.size.width = dest_rect.width(); 809 bounds.size.width = dest_rect.width();
811 bounds.size.height = dest_rect.height(); 810 bounds.size.height = dest_rect.height();
812 811
813 CGContextDrawImage(canvas, bounds, image); 812 CGContextDrawImage(canvas, bounds, image);
814 CGContextRestoreGState(canvas); 813 CGContextRestoreGState(canvas);
815 } 814 }
816 #endif // defined(OS_MACOSX) 815 #endif // defined(OS_MACOSX)
817 816
818 817
819 } // namespace pepper 818 } // namespace pepper
OLDNEW
« no previous file with comments | « webkit/glue/plugins/pepper_plugin_instance.h ('k') | webkit/glue/plugins/pepper_plugin_module.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698