| OLD | NEW |
| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 #include "ui/gfx/skia_util.h" | 48 #include "ui/gfx/skia_util.h" |
| 49 #include "webkit/plugins/ppapi/common.h" | 49 #include "webkit/plugins/ppapi/common.h" |
| 50 #include "webkit/plugins/ppapi/event_conversion.h" | 50 #include "webkit/plugins/ppapi/event_conversion.h" |
| 51 #include "webkit/plugins/ppapi/fullscreen_container.h" | 51 #include "webkit/plugins/ppapi/fullscreen_container.h" |
| 52 #include "webkit/plugins/ppapi/message_channel.h" | 52 #include "webkit/plugins/ppapi/message_channel.h" |
| 53 #include "webkit/plugins/ppapi/plugin_delegate.h" | 53 #include "webkit/plugins/ppapi/plugin_delegate.h" |
| 54 #include "webkit/plugins/ppapi/plugin_module.h" | 54 #include "webkit/plugins/ppapi/plugin_module.h" |
| 55 #include "webkit/plugins/ppapi/plugin_object.h" | 55 #include "webkit/plugins/ppapi/plugin_object.h" |
| 56 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" | 56 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" |
| 57 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" | 57 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" |
| 58 #include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h" |
| 58 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" | 59 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" |
| 59 #include "webkit/plugins/ppapi/ppb_input_event_impl.h" | 60 #include "webkit/plugins/ppapi/ppb_input_event_impl.h" |
| 60 #include "webkit/plugins/ppapi/ppb_surface_3d_impl.h" | 61 #include "webkit/plugins/ppapi/ppb_surface_3d_impl.h" |
| 61 #include "webkit/plugins/ppapi/ppb_url_loader_impl.h" | 62 #include "webkit/plugins/ppapi/ppb_url_loader_impl.h" |
| 62 #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h" | 63 #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h" |
| 63 #include "webkit/plugins/ppapi/ppp_pdf.h" | 64 #include "webkit/plugins/ppapi/ppp_pdf.h" |
| 64 #include "webkit/plugins/ppapi/string.h" | 65 #include "webkit/plugins/ppapi/string.h" |
| 65 #include "webkit/plugins/ppapi/var.h" | 66 #include "webkit/plugins/ppapi/var.h" |
| 66 #include "webkit/plugins/sad_plugin.h" | 67 #include "webkit/plugins/sad_plugin.h" |
| 67 | 68 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 82 #include "ui/gfx/gdi_util.h" | 83 #include "ui/gfx/gdi_util.h" |
| 83 #endif | 84 #endif |
| 84 | 85 |
| 85 #if defined(OS_MACOSX) && defined(USE_SKIA) | 86 #if defined(OS_MACOSX) && defined(USE_SKIA) |
| 86 #include "skia/ext/skia_utils_mac.h" | 87 #include "skia/ext/skia_utils_mac.h" |
| 87 #endif | 88 #endif |
| 88 | 89 |
| 89 using ppapi::thunk::EnterResourceNoLock; | 90 using ppapi::thunk::EnterResourceNoLock; |
| 90 using ppapi::thunk::PPB_Buffer_API; | 91 using ppapi::thunk::PPB_Buffer_API; |
| 91 using ppapi::thunk::PPB_Graphics2D_API; | 92 using ppapi::thunk::PPB_Graphics2D_API; |
| 93 using ppapi::thunk::PPB_Graphics3D_API; |
| 92 using ppapi::thunk::PPB_ImageData_API; | 94 using ppapi::thunk::PPB_ImageData_API; |
| 93 using ppapi::thunk::PPB_Instance_FunctionAPI; | 95 using ppapi::thunk::PPB_Instance_FunctionAPI; |
| 94 using ppapi::thunk::PPB_Surface3D_API; | 96 using ppapi::thunk::PPB_Surface3D_API; |
| 95 using WebKit::WebBindings; | 97 using WebKit::WebBindings; |
| 96 using WebKit::WebCanvas; | 98 using WebKit::WebCanvas; |
| 97 using WebKit::WebCursorInfo; | 99 using WebKit::WebCursorInfo; |
| 98 using WebKit::WebDocument; | 100 using WebKit::WebDocument; |
| 99 using WebKit::WebFrame; | 101 using WebKit::WebFrame; |
| 100 using WebKit::WebInputEvent; | 102 using WebKit::WebInputEvent; |
| 101 using WebKit::WebPluginContainer; | 103 using WebKit::WebPluginContainer; |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 container_->scrollRect(dx, dy, rect); | 316 container_->scrollRect(dx, dy, rect); |
| 315 } else { | 317 } else { |
| 316 // Can't do optimized scrolling since there could be other elements on top | 318 // Can't do optimized scrolling since there could be other elements on top |
| 317 // of us. | 319 // of us. |
| 318 InvalidateRect(rect); | 320 InvalidateRect(rect); |
| 319 } | 321 } |
| 320 } | 322 } |
| 321 } | 323 } |
| 322 | 324 |
| 323 unsigned PluginInstance::GetBackingTextureId() { | 325 unsigned PluginInstance::GetBackingTextureId() { |
| 324 if (!bound_graphics_3d()) | 326 if (bound_graphics_3d()) |
| 325 return 0; | 327 return bound_graphics_3d()->GetBackingTextureId(); |
| 328 else if (bound_surface_3d()) |
| 329 return bound_surface_3d()->GetBackingTextureId(); |
| 326 | 330 |
| 327 return bound_graphics_3d()->GetBackingTextureId(); | 331 return 0; |
| 328 } | 332 } |
| 329 | 333 |
| 330 void PluginInstance::CommitBackingTexture() { | 334 void PluginInstance::CommitBackingTexture() { |
| 331 if (fullscreen_container_) | 335 if (fullscreen_container_) |
| 332 fullscreen_container_->Invalidate(); | 336 fullscreen_container_->Invalidate(); |
| 333 else | 337 else |
| 334 container_->commitBackingTexture(); | 338 container_->commitBackingTexture(); |
| 335 } | 339 } |
| 336 | 340 |
| 337 void PluginInstance::InstanceCrashed() { | 341 void PluginInstance::InstanceCrashed() { |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 has_content_area_focus_ = has_focus; | 543 has_content_area_focus_ = has_focus; |
| 540 if (PluginHasFocus() != old_plugin_focus) { | 544 if (PluginHasFocus() != old_plugin_focus) { |
| 541 instance_interface_->DidChangeFocus(pp_instance(), | 545 instance_interface_->DidChangeFocus(pp_instance(), |
| 542 BoolToPPBool(PluginHasFocus())); | 546 BoolToPPBool(PluginHasFocus())); |
| 543 } | 547 } |
| 544 } | 548 } |
| 545 | 549 |
| 546 void PluginInstance::ViewInitiatedPaint() { | 550 void PluginInstance::ViewInitiatedPaint() { |
| 547 if (bound_graphics_2d()) | 551 if (bound_graphics_2d()) |
| 548 bound_graphics_2d()->ViewInitiatedPaint(); | 552 bound_graphics_2d()->ViewInitiatedPaint(); |
| 549 if (bound_graphics_3d()) | 553 else if (bound_graphics_3d()) |
| 550 bound_graphics_3d()->ViewInitiatedPaint(); | 554 bound_graphics_3d()->ViewInitiatedPaint(); |
| 555 else if (bound_surface_3d()) |
| 556 bound_surface_3d()->ViewInitiatedPaint(); |
| 551 } | 557 } |
| 552 | 558 |
| 553 void PluginInstance::ViewFlushedPaint() { | 559 void PluginInstance::ViewFlushedPaint() { |
| 554 // Keep a reference on the stack. See NOTE above. | 560 // Keep a reference on the stack. See NOTE above. |
| 555 scoped_refptr<PluginInstance> ref(this); | 561 scoped_refptr<PluginInstance> ref(this); |
| 556 if (bound_graphics_2d()) | 562 if (bound_graphics_2d()) |
| 557 bound_graphics_2d()->ViewFlushedPaint(); | 563 bound_graphics_2d()->ViewFlushedPaint(); |
| 558 if (bound_graphics_3d()) | 564 else if (bound_graphics_3d()) |
| 559 bound_graphics_3d()->ViewFlushedPaint(); | 565 bound_graphics_3d()->ViewFlushedPaint(); |
| 566 else if (bound_surface_3d()) |
| 567 bound_surface_3d()->ViewFlushedPaint(); |
| 560 } | 568 } |
| 561 | 569 |
| 562 bool PluginInstance::GetBitmapForOptimizedPluginPaint( | 570 bool PluginInstance::GetBitmapForOptimizedPluginPaint( |
| 563 const gfx::Rect& paint_bounds, | 571 const gfx::Rect& paint_bounds, |
| 564 TransportDIB** dib, | 572 TransportDIB** dib, |
| 565 gfx::Rect* location, | 573 gfx::Rect* location, |
| 566 gfx::Rect* clip) { | 574 gfx::Rect* clip) { |
| 567 if (!always_on_top_) | 575 if (!always_on_top_) |
| 568 return false; | 576 return false; |
| 569 if (!bound_graphics_2d() || !bound_graphics_2d()->is_always_opaque()) | 577 if (!bound_graphics_2d() || !bound_graphics_2d()->is_always_opaque()) |
| (...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1260 | 1268 |
| 1261 PPB_Graphics2D_Impl* PluginInstance::bound_graphics_2d() const { | 1269 PPB_Graphics2D_Impl* PluginInstance::bound_graphics_2d() const { |
| 1262 if (bound_graphics_.get() == NULL) | 1270 if (bound_graphics_.get() == NULL) |
| 1263 return NULL; | 1271 return NULL; |
| 1264 | 1272 |
| 1265 if (bound_graphics_->AsPPB_Graphics2D_API()) | 1273 if (bound_graphics_->AsPPB_Graphics2D_API()) |
| 1266 return static_cast<PPB_Graphics2D_Impl*>(bound_graphics_.get()); | 1274 return static_cast<PPB_Graphics2D_Impl*>(bound_graphics_.get()); |
| 1267 return NULL; | 1275 return NULL; |
| 1268 } | 1276 } |
| 1269 | 1277 |
| 1270 PPB_Surface3D_Impl* PluginInstance::bound_graphics_3d() const { | 1278 PPB_Graphics3D_Impl* PluginInstance::bound_graphics_3d() const { |
| 1279 if (bound_graphics_.get() == NULL) |
| 1280 return NULL; |
| 1281 |
| 1282 if (bound_graphics_->AsPPB_Graphics3D_API()) |
| 1283 return static_cast<PPB_Graphics3D_Impl*>(bound_graphics_.get()); |
| 1284 return NULL; |
| 1285 } |
| 1286 |
| 1287 PPB_Surface3D_Impl* PluginInstance::bound_surface_3d() const { |
| 1271 if (bound_graphics_.get() == NULL) | 1288 if (bound_graphics_.get() == NULL) |
| 1272 return NULL; | 1289 return NULL; |
| 1273 | 1290 |
| 1274 if (bound_graphics_->AsPPB_Surface3D_API()) | 1291 if (bound_graphics_->AsPPB_Surface3D_API()) |
| 1275 return static_cast<PPB_Surface3D_Impl*>(bound_graphics_.get()); | 1292 return static_cast<PPB_Surface3D_Impl*>(bound_graphics_.get()); |
| 1276 return NULL; | 1293 return NULL; |
| 1277 } | 1294 } |
| 1278 | 1295 |
| 1279 void PluginInstance::setBackingTextureId(unsigned int id) { | 1296 void PluginInstance::setBackingTextureId(unsigned int id) { |
| 1280 // If we have a full-screen container_ then the plugin is fullscreen, | 1297 // If we have a full-screen container_ then the plugin is fullscreen, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1340 return this; | 1357 return this; |
| 1341 } | 1358 } |
| 1342 | 1359 |
| 1343 PP_Bool PluginInstance::BindGraphics(PP_Instance instance, | 1360 PP_Bool PluginInstance::BindGraphics(PP_Instance instance, |
| 1344 PP_Resource device) { | 1361 PP_Resource device) { |
| 1345 if (!device) { | 1362 if (!device) { |
| 1346 // Special-case clearing the current device. | 1363 // Special-case clearing the current device. |
| 1347 if (bound_graphics_.get()) { | 1364 if (bound_graphics_.get()) { |
| 1348 if (bound_graphics_2d()) { | 1365 if (bound_graphics_2d()) { |
| 1349 bound_graphics_2d()->BindToInstance(NULL); | 1366 bound_graphics_2d()->BindToInstance(NULL); |
| 1350 } else if (bound_graphics_.get()) { | 1367 } else if (bound_graphics_3d()) { |
| 1368 bound_graphics_3d()->BindToInstance(false); |
| 1369 } else if (bound_surface_3d()) { |
| 1351 bound_graphics_3d()->BindToInstance(false); | 1370 bound_graphics_3d()->BindToInstance(false); |
| 1352 } | 1371 } |
| 1353 setBackingTextureId(0); | 1372 setBackingTextureId(0); |
| 1354 InvalidateRect(gfx::Rect()); | 1373 InvalidateRect(gfx::Rect()); |
| 1355 } | 1374 } |
| 1356 bound_graphics_ = NULL; | 1375 bound_graphics_ = NULL; |
| 1357 return PP_TRUE; | 1376 return PP_TRUE; |
| 1358 } | 1377 } |
| 1359 | 1378 |
| 1379 // Refuse to bind if we're transitioning to fullscreen. |
| 1380 if (fullscreen_container_ && !fullscreen_) |
| 1381 return PP_FALSE; |
| 1382 |
| 1360 EnterResourceNoLock<PPB_Graphics2D_API> enter_2d(device, false); | 1383 EnterResourceNoLock<PPB_Graphics2D_API> enter_2d(device, false); |
| 1361 PPB_Graphics2D_Impl* graphics_2d = enter_2d.succeeded() ? | 1384 PPB_Graphics2D_Impl* graphics_2d = enter_2d.succeeded() ? |
| 1362 static_cast<PPB_Graphics2D_Impl*>(enter_2d.object()) : NULL; | 1385 static_cast<PPB_Graphics2D_Impl*>(enter_2d.object()) : NULL; |
| 1363 EnterResourceNoLock<PPB_Surface3D_API> enter_3d(device, false); | 1386 EnterResourceNoLock<PPB_Graphics3D_API> enter_3d(device, false); |
| 1364 PPB_Surface3D_Impl* graphics_3d = enter_3d.succeeded() ? | 1387 PPB_Graphics3D_Impl* graphics_3d = enter_3d.succeeded() ? |
| 1365 static_cast<PPB_Surface3D_Impl*>(enter_3d.object()) : NULL; | 1388 static_cast<PPB_Graphics3D_Impl*>(enter_3d.object()) : NULL; |
| 1389 EnterResourceNoLock<PPB_Surface3D_API> enter_surface_3d(device, false); |
| 1390 PPB_Surface3D_Impl* surface_3d = enter_surface_3d.succeeded() ? |
| 1391 static_cast<PPB_Surface3D_Impl*>(enter_surface_3d.object()) : NULL; |
| 1366 | 1392 |
| 1367 if (graphics_2d) { | 1393 if (graphics_2d) { |
| 1368 // Refuse to bind if we're transitioning to fullscreen. | |
| 1369 if (fullscreen_container_ && !fullscreen_) | |
| 1370 return PP_FALSE; | |
| 1371 if (graphics_2d->instance() != this) | 1394 if (graphics_2d->instance() != this) |
| 1372 return PP_FALSE; // Can't bind other instance's contexts. | 1395 return PP_FALSE; // Can't bind other instance's contexts. |
| 1373 if (!graphics_2d->BindToInstance(this)) | 1396 if (!graphics_2d->BindToInstance(this)) |
| 1374 return PP_FALSE; // Can't bind to more than one instance. | 1397 return PP_FALSE; // Can't bind to more than one instance. |
| 1375 | 1398 |
| 1376 bound_graphics_ = graphics_2d; | 1399 bound_graphics_ = graphics_2d; |
| 1377 setBackingTextureId(0); | 1400 setBackingTextureId(0); |
| 1378 // BindToInstance will have invalidated the plugin if necessary. | 1401 // BindToInstance will have invalidated the plugin if necessary. |
| 1379 } else if (graphics_3d) { | 1402 } else if (graphics_3d) { |
| 1380 // Refuse to bind if we're transitioning to fullscreen. | |
| 1381 if (fullscreen_container_ && !fullscreen_) | |
| 1382 return PP_FALSE; | |
| 1383 // Make sure graphics can only be bound to the instance it is | 1403 // Make sure graphics can only be bound to the instance it is |
| 1384 // associated with. | 1404 // associated with. |
| 1385 if (graphics_3d->instance() != this) | 1405 if (graphics_3d->instance() != this) |
| 1386 return PP_FALSE; | 1406 return PP_FALSE; |
| 1387 if (!graphics_3d->BindToInstance(true)) | 1407 if (!graphics_3d->BindToInstance(true)) |
| 1388 return PP_FALSE; | 1408 return PP_FALSE; |
| 1389 | 1409 |
| 1410 bound_graphics_ = graphics_3d; |
| 1390 setBackingTextureId(graphics_3d->GetBackingTextureId()); | 1411 setBackingTextureId(graphics_3d->GetBackingTextureId()); |
| 1391 bound_graphics_ = graphics_3d; | 1412 } else if (surface_3d) { |
| 1413 // Make sure graphics can only be bound to the instance it is |
| 1414 // associated with. |
| 1415 if (surface_3d->instance() != this) |
| 1416 return PP_FALSE; |
| 1417 if (!surface_3d->BindToInstance(true)) |
| 1418 return PP_FALSE; |
| 1419 |
| 1420 bound_graphics_ = surface_3d; |
| 1421 setBackingTextureId(surface_3d->GetBackingTextureId()); |
| 1392 } else { | 1422 } else { |
| 1393 // The device is not a valid resource type. | 1423 // The device is not a valid resource type. |
| 1394 return PP_FALSE; | 1424 return PP_FALSE; |
| 1395 } | 1425 } |
| 1396 | 1426 |
| 1397 return PP_TRUE; | 1427 return PP_TRUE; |
| 1398 } | 1428 } |
| 1399 | 1429 |
| 1400 PP_Bool PluginInstance::IsFullFrame(PP_Instance instance) { | 1430 PP_Bool PluginInstance::IsFullFrame(PP_Instance instance) { |
| 1401 return PP_FromBool(full_frame()); | 1431 return PP_FromBool(full_frame()); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1537 } | 1567 } |
| 1538 delegate()->ZoomLimitsChanged(minimum_factor, maximium_factor); | 1568 delegate()->ZoomLimitsChanged(minimum_factor, maximium_factor); |
| 1539 } | 1569 } |
| 1540 | 1570 |
| 1541 void PluginInstance::PostMessage(PP_Instance instance, PP_Var message) { | 1571 void PluginInstance::PostMessage(PP_Instance instance, PP_Var message) { |
| 1542 message_channel_->PostMessageToJavaScript(message); | 1572 message_channel_->PostMessageToJavaScript(message); |
| 1543 } | 1573 } |
| 1544 | 1574 |
| 1545 } // namespace ppapi | 1575 } // namespace ppapi |
| 1546 } // namespace webkit | 1576 } // namespace webkit |
| OLD | NEW |