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/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" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "ppapi/c/dev/ppb_find_dev.h" | 12 #include "ppapi/c/dev/ppb_find_dev.h" |
| 13 #include "ppapi/c/dev/ppb_fullscreen_dev.h" | 13 #include "ppapi/c/dev/ppb_fullscreen_dev.h" |
| 14 #include "ppapi/c/dev/ppb_zoom_dev.h" | 14 #include "ppapi/c/dev/ppb_zoom_dev.h" |
| 15 #include "ppapi/c/dev/ppp_find_dev.h" | 15 #include "ppapi/c/dev/ppp_find_dev.h" |
| 16 #include "ppapi/c/dev/ppp_selection_dev.h" | 16 #include "ppapi/c/dev/ppp_selection_dev.h" |
| 17 #include "ppapi/c/dev/ppp_zoom_dev.h" | 17 #include "ppapi/c/dev/ppp_zoom_dev.h" |
| 18 #include "ppapi/c/pp_input_event.h" | 18 #include "ppapi/c/pp_input_event.h" |
| 19 #include "ppapi/c/pp_instance.h" | 19 #include "ppapi/c/pp_instance.h" |
| 20 #include "ppapi/c/pp_rect.h" | 20 #include "ppapi/c/pp_rect.h" |
| 21 #include "ppapi/c/pp_resource.h" | 21 #include "ppapi/c/pp_resource.h" |
| 22 #include "ppapi/c/pp_var.h" | 22 #include "ppapi/c/pp_var.h" |
| 23 #include "ppapi/c/ppb_core.h" | 23 #include "ppapi/c/ppb_core.h" |
| 24 #include "ppapi/c/ppb_instance.h" | 24 #include "ppapi/c/ppb_instance.h" |
| 25 #include "ppapi/c/ppb_messaging.h" | 25 #include "ppapi/c/ppb_messaging.h" |
| 26 #include "ppapi/c/ppp_instance.h" | 26 #include "ppapi/c/ppp_instance.h" |
| 27 #include "ppapi/c/ppp_messaging.h" | 27 #include "ppapi/c/ppp_messaging.h" |
| 28 #include "ppapi/c/private/ppb_instance_private.h" | |
| 29 #include "ppapi/c/private/ppp_instance_private.h" | |
| 28 #include "printing/units.h" | 30 #include "printing/units.h" |
| 29 #include "skia/ext/platform_canvas.h" | 31 #include "skia/ext/platform_canvas.h" |
| 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
| 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
| 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 37 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 38 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
| 37 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h" | 39 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h" |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 } | 208 } |
| 207 | 209 |
| 208 const PPB_Instance ppb_instance = { | 210 const PPB_Instance ppb_instance = { |
| 209 &GetWindowObject, | 211 &GetWindowObject, |
| 210 &GetOwnerElementObject, | 212 &GetOwnerElementObject, |
| 211 &BindGraphics, | 213 &BindGraphics, |
| 212 &IsFullFrame, | 214 &IsFullFrame, |
| 213 &ExecuteScript, | 215 &ExecuteScript, |
| 214 }; | 216 }; |
| 215 | 217 |
| 218 const PPB_Instance_Private ppb_instance_private = { | |
| 219 &GetWindowObject, | |
| 220 &GetOwnerElementObject, | |
| 221 &ExecuteScript | |
| 222 }; | |
| 223 | |
| 216 void NumberOfFindResultsChanged(PP_Instance instance_id, | 224 void NumberOfFindResultsChanged(PP_Instance instance_id, |
| 217 int32_t total, | 225 int32_t total, |
| 218 PP_Bool final_result) { | 226 PP_Bool final_result) { |
| 219 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); | 227 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); |
| 220 if (!instance) | 228 if (!instance) |
| 221 return; | 229 return; |
| 222 | 230 |
| 223 DCHECK_NE(instance->find_identifier(), -1); | 231 DCHECK_NE(instance->find_identifier(), -1); |
| 224 instance->delegate()->NumberOfFindResultsChanged( | 232 instance->delegate()->NumberOfFindResultsChanged( |
| 225 instance->find_identifier(), total, PPBoolToBool(final_result)); | 233 instance->find_identifier(), total, PPBoolToBool(final_result)); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 const PPB_Fullscreen_Dev* PluginInstance::GetFullscreenInterface() { | 406 const PPB_Fullscreen_Dev* PluginInstance::GetFullscreenInterface() { |
| 399 return &ppb_fullscreen; | 407 return &ppb_fullscreen; |
| 400 } | 408 } |
| 401 | 409 |
| 402 // static | 410 // static |
| 403 const PPB_Messaging* PluginInstance::GetMessagingInterface() { | 411 const PPB_Messaging* PluginInstance::GetMessagingInterface() { |
| 404 return &ppb_messaging; | 412 return &ppb_messaging; |
| 405 } | 413 } |
| 406 | 414 |
| 407 // static | 415 // static |
| 416 const PPB_Instance_Private* PluginInstance::GetPrivateInterface() { | |
| 417 return &ppb_instance_private; | |
| 418 } | |
| 419 | |
| 420 // static | |
| 408 const PPB_Zoom_Dev* PluginInstance::GetZoomInterface() { | 421 const PPB_Zoom_Dev* PluginInstance::GetZoomInterface() { |
| 409 return &ppb_zoom; | 422 return &ppb_zoom; |
| 410 } | 423 } |
| 411 | 424 |
| 412 // NOTE: Any of these methods that calls into the plugin needs to take into | 425 // NOTE: Any of these methods that calls into the plugin needs to take into |
| 413 // account that the plugin may use Var to remove the <embed> from the DOM, which | 426 // account that the plugin may use Var to remove the <embed> from the DOM, which |
| 414 // will make the WebPluginImpl drop its reference, usually the last one. If a | 427 // will make the WebPluginImpl drop its reference, usually the last one. If a |
| 415 // method needs to access a member of the instance after the call has returned, | 428 // method needs to access a member of the instance after the call has returned, |
| 416 // then it needs to keep its own reference on the stack. | 429 // then it needs to keep its own reference on the stack. |
| 417 | 430 |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 732 | 745 |
| 733 void PluginInstance::HandleMessage(PP_Var message) { | 746 void PluginInstance::HandleMessage(PP_Var message) { |
| 734 // Keep a reference on the stack. See NOTE above. | 747 // Keep a reference on the stack. See NOTE above. |
| 735 scoped_refptr<PluginInstance> ref(this); | 748 scoped_refptr<PluginInstance> ref(this); |
| 736 if (!LoadMessagingInterface()) | 749 if (!LoadMessagingInterface()) |
| 737 return; | 750 return; |
| 738 plugin_messaging_interface_->HandleMessage(pp_instance(), message); | 751 plugin_messaging_interface_->HandleMessage(pp_instance(), message); |
| 739 } | 752 } |
| 740 | 753 |
| 741 PP_Var PluginInstance::GetInstanceObject() { | 754 PP_Var PluginInstance::GetInstanceObject() { |
| 755 // Try the private interface first. If it is not supported, we fall back to | |
| 756 // the primary PPP_Instance interface. | |
| 757 // TODO(dmichael): Remove support for PPP_Instance.GetInstanceObject | |
| 758 if (LoadPrivateInterface()) { | |
| 759 return plugin_private_interface_->GetInstanceObject(pp_instance()); | |
| 760 } | |
| 742 return instance_interface_->GetInstanceObject(pp_instance()); | 761 return instance_interface_->GetInstanceObject(pp_instance()); |
| 743 } | 762 } |
| 744 | 763 |
| 745 void PluginInstance::ViewChanged(const gfx::Rect& position, | 764 void PluginInstance::ViewChanged(const gfx::Rect& position, |
| 746 const gfx::Rect& clip) { | 765 const gfx::Rect& clip) { |
| 747 fullscreen_ = (fullscreen_container_ != NULL); | 766 fullscreen_ = (fullscreen_container_ != NULL); |
| 748 position_ = position; | 767 position_ = position; |
| 749 | 768 |
| 750 if (clip.IsEmpty()) { | 769 if (clip.IsEmpty()) { |
| 751 // WebKit can give weird (x,y) positions for empty clip rects (since the | 770 // WebKit can give weird (x,y) positions for empty clip rects (since the |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 938 bool PluginInstance::LoadSelectionInterface() { | 957 bool PluginInstance::LoadSelectionInterface() { |
| 939 if (!plugin_selection_interface_) { | 958 if (!plugin_selection_interface_) { |
| 940 plugin_selection_interface_ = | 959 plugin_selection_interface_ = |
| 941 reinterpret_cast<const PPP_Selection_Dev*>(module_->GetPluginInterface( | 960 reinterpret_cast<const PPP_Selection_Dev*>(module_->GetPluginInterface( |
| 942 PPP_SELECTION_DEV_INTERFACE)); | 961 PPP_SELECTION_DEV_INTERFACE)); |
| 943 } | 962 } |
| 944 | 963 |
| 945 return !!plugin_selection_interface_; | 964 return !!plugin_selection_interface_; |
| 946 } | 965 } |
| 947 | 966 |
| 967 bool PluginInstance::LoadPrivateInterface() { | |
| 968 if (!plugin_private_interface_) { | |
| 969 plugin_private_interface_ = reinterpret_cast<const PPP_Instance_Private*>( | |
|
dmichael (off chromium)
2011/04/18 18:58:16
Note I very nearly used static_cast, but went for
brettw
2011/04/18 21:13:26
static_cast is better. Most of the reinterpret cas
| |
| 970 module_->GetPluginInterface(PPP_INSTANCE_PRIVATE_INTERFACE)); | |
| 971 } | |
| 972 | |
| 973 return !!plugin_private_interface_; | |
| 974 } | |
| 975 | |
| 948 bool PluginInstance::LoadZoomInterface() { | 976 bool PluginInstance::LoadZoomInterface() { |
| 949 if (!plugin_zoom_interface_) { | 977 if (!plugin_zoom_interface_) { |
| 950 plugin_zoom_interface_ = | 978 plugin_zoom_interface_ = |
| 951 reinterpret_cast<const PPP_Zoom_Dev*>(module_->GetPluginInterface( | 979 reinterpret_cast<const PPP_Zoom_Dev*>(module_->GetPluginInterface( |
| 952 PPP_ZOOM_DEV_INTERFACE)); | 980 PPP_ZOOM_DEV_INTERFACE)); |
| 953 } | 981 } |
| 954 | 982 |
| 955 return !!plugin_zoom_interface_; | 983 return !!plugin_zoom_interface_; |
| 956 } | 984 } |
| 957 | 985 |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1465 return found->second; | 1493 return found->second; |
| 1466 } | 1494 } |
| 1467 | 1495 |
| 1468 bool PluginInstance::IsFullPagePlugin() const { | 1496 bool PluginInstance::IsFullPagePlugin() const { |
| 1469 WebFrame* frame = container()->element().document().frame(); | 1497 WebFrame* frame = container()->element().document().frame(); |
| 1470 return frame->view()->mainFrame()->document().isPluginDocument(); | 1498 return frame->view()->mainFrame()->document().isPluginDocument(); |
| 1471 } | 1499 } |
| 1472 | 1500 |
| 1473 } // namespace ppapi | 1501 } // namespace ppapi |
| 1474 } // namespace webkit | 1502 } // namespace webkit |
| OLD | NEW |