Chromium Code Reviews| 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/message_loop.h" | |
| 8 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 9 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
| 10 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 11 #include "ppapi/c/dev/ppb_find_dev.h" | 12 #include "ppapi/c/dev/ppb_find_dev.h" |
| 12 #include "ppapi/c/dev/ppb_fullscreen_dev.h" | 13 #include "ppapi/c/dev/ppb_fullscreen_dev.h" |
| 13 #include "ppapi/c/dev/ppb_zoom_dev.h" | 14 #include "ppapi/c/dev/ppb_zoom_dev.h" |
| 14 #include "ppapi/c/dev/ppp_find_dev.h" | 15 #include "ppapi/c/dev/ppp_find_dev.h" |
| 15 #include "ppapi/c/dev/ppp_selection_dev.h" | 16 #include "ppapi/c/dev/ppp_selection_dev.h" |
| 16 #include "ppapi/c/dev/ppp_zoom_dev.h" | 17 #include "ppapi/c/dev/ppp_zoom_dev.h" |
| 17 #include "ppapi/c/pp_input_event.h" | 18 #include "ppapi/c/pp_input_event.h" |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); | 241 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); |
| 241 if (!instance) | 242 if (!instance) |
| 242 return PP_FALSE; | 243 return PP_FALSE; |
| 243 return BoolToPPBool(instance->IsFullscreen()); | 244 return BoolToPPBool(instance->IsFullscreen()); |
| 244 } | 245 } |
| 245 | 246 |
| 246 PP_Bool SetFullscreen(PP_Instance instance_id, PP_Bool fullscreen) { | 247 PP_Bool SetFullscreen(PP_Instance instance_id, PP_Bool fullscreen) { |
| 247 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); | 248 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); |
| 248 if (!instance) | 249 if (!instance) |
| 249 return PP_FALSE; | 250 return PP_FALSE; |
| 250 return BoolToPPBool(instance->SetFullscreen(PPBoolToBool(fullscreen))); | 251 instance->SetFullscreen(PPBoolToBool(fullscreen), true); |
| 252 return PP_TRUE; | |
| 251 } | 253 } |
| 252 | 254 |
| 255 PP_Bool GetScreenSize(PP_Instance instance_id, PP_Size* size) { | |
|
viettrungluu
2011/03/08 00:06:01
Maybe it should return an int32_t error code?
Tho
| |
| 256 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); | |
|
viettrungluu
2011/03/08 00:06:01
I usually like to do |if (!size) return PP_ERROR_B
piman
2011/03/08 00:55:30
Done.
| |
| 257 if (!instance) | |
| 258 return PP_FALSE; | |
| 259 gfx::Size screen_size = instance->delegate()->GetScreenSize(); | |
| 260 *size = PP_MakeSize(screen_size.width(), screen_size.height()); | |
| 261 return PP_TRUE; | |
| 262 } | |
| 263 | |
| 264 | |
| 253 const PPB_Fullscreen_Dev ppb_fullscreen = { | 265 const PPB_Fullscreen_Dev ppb_fullscreen = { |
| 254 &IsFullscreen, | 266 &IsFullscreen, |
| 255 &SetFullscreen, | 267 &SetFullscreen, |
| 268 &GetScreenSize | |
| 256 }; | 269 }; |
| 257 | 270 |
| 258 void ZoomChanged(PP_Instance instance_id, double factor) { | 271 void ZoomChanged(PP_Instance instance_id, double factor) { |
| 259 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); | 272 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); |
| 260 if (!instance) | 273 if (!instance) |
| 261 return; | 274 return; |
| 262 | 275 |
| 263 // We only want to tell the page to change its zoom if the whole page is the | 276 // We only want to tell the page to change its zoom if the whole page is the |
| 264 // plugin. If we're in an iframe, then don't do anything. | 277 // plugin. If we're in an iframe, then don't do anything. |
| 265 if (!instance->IsFullPagePlugin()) | 278 if (!instance->IsFullPagePlugin()) |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 plugin_find_interface_(NULL), | 327 plugin_find_interface_(NULL), |
| 315 plugin_pdf_interface_(NULL), | 328 plugin_pdf_interface_(NULL), |
| 316 plugin_selection_interface_(NULL), | 329 plugin_selection_interface_(NULL), |
| 317 plugin_zoom_interface_(NULL), | 330 plugin_zoom_interface_(NULL), |
| 318 #if defined(OS_LINUX) | 331 #if defined(OS_LINUX) |
| 319 canvas_(NULL), | 332 canvas_(NULL), |
| 320 #endif // defined(OS_LINUX) | 333 #endif // defined(OS_LINUX) |
| 321 plugin_print_interface_(NULL), | 334 plugin_print_interface_(NULL), |
| 322 plugin_graphics_3d_interface_(NULL), | 335 plugin_graphics_3d_interface_(NULL), |
| 323 always_on_top_(false), | 336 always_on_top_(false), |
| 324 fullscreen_container_(NULL) { | 337 fullscreen_container_(NULL), |
| 338 fullscreen_(false) { | |
| 325 pp_instance_ = ResourceTracker::Get()->AddInstance(this); | 339 pp_instance_ = ResourceTracker::Get()->AddInstance(this); |
| 326 | 340 |
| 327 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); | 341 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); |
| 328 DCHECK(delegate); | 342 DCHECK(delegate); |
| 329 module_->InstanceCreated(this); | 343 module_->InstanceCreated(this); |
| 330 delegate_->InstanceCreated(this); | 344 delegate_->InstanceCreated(this); |
| 331 } | 345 } |
| 332 | 346 |
| 333 PluginInstance::~PluginInstance() { | 347 PluginInstance::~PluginInstance() { |
| 334 // Free all the plugin objects. This will automatically clear the back- | 348 // Free all the plugin objects. This will automatically clear the back- |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 426 fullscreen_container_->Invalidate(); | 440 fullscreen_container_->Invalidate(); |
| 427 else | 441 else |
| 428 container_->commitBackingTexture(); | 442 container_->commitBackingTexture(); |
| 429 } | 443 } |
| 430 | 444 |
| 431 void PluginInstance::InstanceCrashed() { | 445 void PluginInstance::InstanceCrashed() { |
| 432 // Force free all resources and vars. | 446 // Force free all resources and vars. |
| 433 ResourceTracker::Get()->InstanceCrashed(pp_instance()); | 447 ResourceTracker::Get()->InstanceCrashed(pp_instance()); |
| 434 | 448 |
| 435 // Free any associated graphics. | 449 // Free any associated graphics. |
| 436 SetFullscreen(false); | 450 SetFullscreen(false, false); |
| 437 bound_graphics_ = NULL; | 451 bound_graphics_ = NULL; |
| 438 InvalidateRect(gfx::Rect()); | 452 InvalidateRect(gfx::Rect()); |
| 439 | 453 |
| 440 // TODO(brettw) show a crashed plugin screen. | 454 // TODO(brettw) show a crashed plugin screen. |
| 441 } | 455 } |
| 442 | 456 |
| 443 PP_Var PluginInstance::GetWindowObject() { | 457 PP_Var PluginInstance::GetWindowObject() { |
| 444 if (!container_) | 458 if (!container_) |
| 445 return PP_MakeUndefined(); | 459 return PP_MakeUndefined(); |
| 446 | 460 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 472 bound_graphics_ = NULL; | 486 bound_graphics_ = NULL; |
| 473 return true; | 487 return true; |
| 474 } | 488 } |
| 475 | 489 |
| 476 scoped_refptr<PPB_Graphics2D_Impl> graphics_2d = | 490 scoped_refptr<PPB_Graphics2D_Impl> graphics_2d = |
| 477 Resource::GetAs<PPB_Graphics2D_Impl>(graphics_id); | 491 Resource::GetAs<PPB_Graphics2D_Impl>(graphics_id); |
| 478 scoped_refptr<PPB_Surface3D_Impl> graphics_3d = | 492 scoped_refptr<PPB_Surface3D_Impl> graphics_3d = |
| 479 Resource::GetAs<PPB_Surface3D_Impl>(graphics_id); | 493 Resource::GetAs<PPB_Surface3D_Impl>(graphics_id); |
| 480 | 494 |
| 481 if (graphics_2d) { | 495 if (graphics_2d) { |
| 496 // Refuse to bind if we're transitioning to fullscreen. | |
| 497 if (fullscreen_container_ && !fullscreen_) | |
| 498 return false; | |
| 482 if (!graphics_2d->BindToInstance(this)) | 499 if (!graphics_2d->BindToInstance(this)) |
| 483 return false; // Can't bind to more than one instance. | 500 return false; // Can't bind to more than one instance. |
| 484 | 501 |
| 485 // See http://crbug.com/49403: this can be further optimized by keeping the | 502 // See http://crbug.com/49403: this can be further optimized by keeping the |
| 486 // old device around and painting from it. | 503 // old device around and painting from it. |
| 487 if (bound_graphics_2d()) { | 504 if (bound_graphics_2d()) { |
| 488 // Start the new image with the content of the old image until the plugin | 505 // Start the new image with the content of the old image until the plugin |
| 489 // repaints. | 506 // repaints. |
| 490 // Use ImageDataAutoMapper to ensure the image data is valid. | 507 // Use ImageDataAutoMapper to ensure the image data is valid. |
| 491 ImageDataAutoMapper mapper(bound_graphics_2d()->image_data()); | 508 ImageDataAutoMapper mapper(bound_graphics_2d()->image_data()); |
| 492 if (!mapper.is_valid()) | 509 if (!mapper.is_valid()) |
| 493 return false; | 510 return false; |
| 494 const SkBitmap* old_backing_bitmap = | 511 const SkBitmap* old_backing_bitmap = |
| 495 bound_graphics_2d()->image_data()->GetMappedBitmap(); | 512 bound_graphics_2d()->image_data()->GetMappedBitmap(); |
| 496 SkRect old_size = SkRect::MakeWH( | 513 SkRect old_size = SkRect::MakeWH( |
| 497 SkScalar(static_cast<float>(old_backing_bitmap->width())), | 514 SkScalar(static_cast<float>(old_backing_bitmap->width())), |
| 498 SkScalar(static_cast<float>(old_backing_bitmap->height()))); | 515 SkScalar(static_cast<float>(old_backing_bitmap->height()))); |
| 499 | 516 |
| 500 SkCanvas canvas(*graphics_2d->image_data()->GetMappedBitmap()); | 517 SkCanvas canvas(*graphics_2d->image_data()->GetMappedBitmap()); |
| 501 canvas.drawBitmap(*old_backing_bitmap, 0, 0); | 518 canvas.drawBitmap(*old_backing_bitmap, 0, 0); |
| 502 | 519 |
| 503 // Fill in any extra space with white. | 520 // Fill in any extra space with white. |
| 504 canvas.clipRect(old_size, SkRegion::kDifference_Op); | 521 canvas.clipRect(old_size, SkRegion::kDifference_Op); |
| 505 canvas.drawARGB(255, 255, 255, 255); | 522 canvas.drawARGB(255, 255, 255, 255); |
| 506 } | 523 } |
| 507 | 524 |
| 508 bound_graphics_ = graphics_2d; | 525 bound_graphics_ = graphics_2d; |
| 509 // BindToInstance will have invalidated the plugin if necessary. | 526 // BindToInstance will have invalidated the plugin if necessary. |
| 510 } else if (graphics_3d) { | 527 } else if (graphics_3d) { |
| 528 // Refuse to bind if we're transitioning to fullscreen. | |
| 529 if (fullscreen_container_ && !fullscreen_) | |
| 530 return false; | |
| 511 // Make sure graphics can only be bound to the instance it is | 531 // Make sure graphics can only be bound to the instance it is |
| 512 // associated with. | 532 // associated with. |
| 513 if (graphics_3d->instance() != this) | 533 if (graphics_3d->instance() != this) |
| 514 return false; | 534 return false; |
| 515 if (!graphics_3d->BindToInstance(true)) | 535 if (!graphics_3d->BindToInstance(true)) |
| 516 return false; | 536 return false; |
| 517 | 537 |
| 518 bound_graphics_ = graphics_3d; | 538 bound_graphics_ = graphics_3d; |
| 519 } | 539 } |
| 520 | 540 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 628 *cursor_info = *cursor_; | 648 *cursor_info = *cursor_; |
| 629 return rv; | 649 return rv; |
| 630 } | 650 } |
| 631 | 651 |
| 632 PP_Var PluginInstance::GetInstanceObject() { | 652 PP_Var PluginInstance::GetInstanceObject() { |
| 633 return instance_interface_->GetInstanceObject(pp_instance()); | 653 return instance_interface_->GetInstanceObject(pp_instance()); |
| 634 } | 654 } |
| 635 | 655 |
| 636 void PluginInstance::ViewChanged(const gfx::Rect& position, | 656 void PluginInstance::ViewChanged(const gfx::Rect& position, |
| 637 const gfx::Rect& clip) { | 657 const gfx::Rect& clip) { |
| 658 fullscreen_ = (fullscreen_container_ != NULL); | |
| 638 position_ = position; | 659 position_ = position; |
| 639 | 660 |
| 640 if (clip.IsEmpty()) { | 661 if (clip.IsEmpty()) { |
| 641 // WebKit can give weird (x,y) positions for empty clip rects (since the | 662 // WebKit can give weird (x,y) positions for empty clip rects (since the |
| 642 // position technically doesn't matter). But we want to make these | 663 // position technically doesn't matter). But we want to make these |
| 643 // consistent since this is given to the plugin, so force everything to 0 | 664 // consistent since this is given to the plugin, so force everything to 0 |
| 644 // in the "everything is clipped" case. | 665 // in the "everything is clipped" case. |
| 645 clip_ = gfx::Rect(); | 666 clip_ = gfx::Rect(); |
| 646 } else { | 667 } else { |
| 647 clip_ = clip; | 668 clip_ = clip; |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 831 PPP_ZOOM_DEV_INTERFACE)); | 852 PPP_ZOOM_DEV_INTERFACE)); |
| 832 } | 853 } |
| 833 | 854 |
| 834 return !!plugin_zoom_interface_; | 855 return !!plugin_zoom_interface_; |
| 835 } | 856 } |
| 836 | 857 |
| 837 bool PluginInstance::PluginHasFocus() const { | 858 bool PluginInstance::PluginHasFocus() const { |
| 838 return has_webkit_focus_ && has_content_area_focus_; | 859 return has_webkit_focus_ && has_content_area_focus_; |
| 839 } | 860 } |
| 840 | 861 |
| 862 void PluginInstance::ReportGeometry() { | |
| 863 // If this call was delayed, we may have transitioned back to fullscreen in | |
| 864 // the mean time, so only report the geometry if we are actually in normal | |
| 865 // mode. | |
| 866 if (container_ && !fullscreen_container_) | |
| 867 container_->reportGeometry(); | |
| 868 } | |
| 869 | |
| 841 bool PluginInstance::GetPreferredPrintOutputFormat( | 870 bool PluginInstance::GetPreferredPrintOutputFormat( |
| 842 PP_PrintOutputFormat_Dev* format) { | 871 PP_PrintOutputFormat_Dev* format) { |
| 843 // Keep a reference on the stack. See NOTE above. | 872 // Keep a reference on the stack. See NOTE above. |
| 844 scoped_refptr<PluginInstance> ref(this); | 873 scoped_refptr<PluginInstance> ref(this); |
| 845 if (!plugin_print_interface_) { | 874 if (!plugin_print_interface_) { |
| 846 plugin_print_interface_ = | 875 plugin_print_interface_ = |
| 847 reinterpret_cast<const PPP_Printing_Dev*>(module_->GetPluginInterface( | 876 reinterpret_cast<const PPP_Printing_Dev*>(module_->GetPluginInterface( |
| 848 PPP_PRINTING_DEV_INTERFACE)); | 877 PPP_PRINTING_DEV_INTERFACE)); |
| 849 } | 878 } |
| 850 if (!plugin_print_interface_) | 879 if (!plugin_print_interface_) |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 959 if (plugin_print_interface_) | 988 if (plugin_print_interface_) |
| 960 plugin_print_interface_->End(pp_instance()); | 989 plugin_print_interface_->End(pp_instance()); |
| 961 | 990 |
| 962 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); | 991 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); |
| 963 #if defined(OS_MACOSX) | 992 #if defined(OS_MACOSX) |
| 964 last_printed_page_ = NULL; | 993 last_printed_page_ = NULL; |
| 965 #endif // defined(OS_MACOSX) | 994 #endif // defined(OS_MACOSX) |
| 966 } | 995 } |
| 967 | 996 |
| 968 bool PluginInstance::IsFullscreen() { | 997 bool PluginInstance::IsFullscreen() { |
| 998 return fullscreen_; | |
| 999 } | |
| 1000 | |
| 1001 bool PluginInstance::IsFullscreenOrPending() { | |
| 969 return fullscreen_container_ != NULL; | 1002 return fullscreen_container_ != NULL; |
| 970 } | 1003 } |
| 971 | 1004 |
| 972 bool PluginInstance::SetFullscreen(bool fullscreen) { | 1005 void PluginInstance::SetFullscreen(bool fullscreen, bool delay_report) { |
| 973 // Keep a reference on the stack. See NOTE above. | 1006 // Keep a reference on the stack. See NOTE above. |
| 974 scoped_refptr<PluginInstance> ref(this); | 1007 scoped_refptr<PluginInstance> ref(this); |
| 1008 | |
| 1009 // We check whether we are trying to switch to the state we're already going | |
| 1010 // to (i.e. if we're already switching to fullscreen but the fullscreen | |
| 1011 // container isn't ready yet, don't do anything more). | |
| 975 bool is_fullscreen = (fullscreen_container_ != NULL); | 1012 bool is_fullscreen = (fullscreen_container_ != NULL); |
| 976 if (fullscreen == is_fullscreen) | 1013 if (fullscreen == is_fullscreen) |
|
viettrungluu
2011/03/08 00:06:01
Probably better to write this as |if (fullscreen =
piman
2011/03/08 00:55:30
Done.
| |
| 977 return true; | 1014 return; |
| 1015 | |
| 1016 BindGraphics(0); | |
| 978 VLOG(1) << "Setting fullscreen to " << (fullscreen ? "on" : "off"); | 1017 VLOG(1) << "Setting fullscreen to " << (fullscreen ? "on" : "off"); |
| 979 if (fullscreen) { | 1018 if (fullscreen) { |
| 980 fullscreen_container_ = delegate_->CreateFullscreenContainer(this); | 1019 fullscreen_container_ = delegate_->CreateFullscreenContainer(this); |
| 981 } else { | 1020 } else { |
| 982 fullscreen_container_->Destroy(); | 1021 fullscreen_container_->Destroy(); |
| 983 fullscreen_container_ = NULL; | 1022 fullscreen_container_ = NULL; |
| 984 // TODO(piman): currently the fullscreen container resizes the plugin to the | 1023 fullscreen_ = false; |
| 985 // fullscreen size so we need to reset the size here. Eventually it will | 1024 if (!delay_report) { |
| 986 // transparently scale and this won't be necessary. | 1025 ReportGeometry(); |
| 987 if (container_) { | 1026 } else { |
| 988 container_->reportGeometry(); | 1027 MessageLoop::current()->PostTask( |
| 989 container_->invalidate(); | 1028 FROM_HERE, NewRunnableMethod(this, &PluginInstance::ReportGeometry)); |
| 990 } | 1029 } |
| 991 } | 1030 } |
| 992 return true; | |
| 993 } | 1031 } |
| 994 | 1032 |
| 995 bool PluginInstance::NavigateToURL(const char* url, const char* target) { | 1033 bool PluginInstance::NavigateToURL(const char* url, const char* target) { |
| 996 if (!url || !target || !container_) | 1034 if (!url || !target || !container_) |
| 997 return false; | 1035 return false; |
| 998 | 1036 |
| 999 WebDocument document = container_->element().document(); | 1037 WebDocument document = container_->element().document(); |
| 1000 GURL complete_url = document.completeURL(WebString::fromUTF8(url)); | 1038 GURL complete_url = document.completeURL(WebString::fromUTF8(url)); |
| 1001 // Don't try to deal with the security issues of javascript. | 1039 // Don't try to deal with the security issues of javascript. |
| 1002 if (complete_url.SchemeIs("javascript")) | 1040 if (complete_url.SchemeIs("javascript")) |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1298 return found->second; | 1336 return found->second; |
| 1299 } | 1337 } |
| 1300 | 1338 |
| 1301 bool PluginInstance::IsFullPagePlugin() const { | 1339 bool PluginInstance::IsFullPagePlugin() const { |
| 1302 WebFrame* frame = container()->element().document().frame(); | 1340 WebFrame* frame = container()->element().document().frame(); |
| 1303 return frame->view()->mainFrame()->document().isPluginDocument(); | 1341 return frame->view()->mainFrame()->document().isPluginDocument(); |
| 1304 } | 1342 } |
| 1305 | 1343 |
| 1306 } // namespace ppapi | 1344 } // namespace ppapi |
| 1307 } // namespace webkit | 1345 } // namespace webkit |
| OLD | NEW |