| 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 55 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
| 56 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | 56 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
| 57 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" | 57 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" |
| 58 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" | 58 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" |
| 59 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 59 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 60 #include "ui/gfx/rect.h" | 60 #include "ui/gfx/rect.h" |
| 61 #include "ui/gfx/skia_util.h" | 61 #include "ui/gfx/skia_util.h" |
| 62 #include "webkit/plugins/ppapi/common.h" | 62 #include "webkit/plugins/ppapi/common.h" |
| 63 #include "webkit/plugins/ppapi/event_conversion.h" | 63 #include "webkit/plugins/ppapi/event_conversion.h" |
| 64 #include "webkit/plugins/ppapi/fullscreen_container.h" | 64 #include "webkit/plugins/ppapi/fullscreen_container.h" |
| 65 #include "webkit/plugins/ppapi/host_globals.h" |
| 65 #include "webkit/plugins/ppapi/message_channel.h" | 66 #include "webkit/plugins/ppapi/message_channel.h" |
| 66 #include "webkit/plugins/ppapi/npapi_glue.h" | 67 #include "webkit/plugins/ppapi/npapi_glue.h" |
| 67 #include "webkit/plugins/ppapi/plugin_delegate.h" | 68 #include "webkit/plugins/ppapi/plugin_delegate.h" |
| 68 #include "webkit/plugins/ppapi/plugin_module.h" | 69 #include "webkit/plugins/ppapi/plugin_module.h" |
| 69 #include "webkit/plugins/ppapi/plugin_object.h" | 70 #include "webkit/plugins/ppapi/plugin_object.h" |
| 70 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" | 71 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" |
| 71 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" | 72 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" |
| 72 #include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h" | 73 #include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h" |
| 73 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" | 74 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" |
| 74 #include "webkit/plugins/ppapi/ppb_surface_3d_impl.h" | 75 #include "webkit/plugins/ppapi/ppb_surface_3d_impl.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 95 #include "ui/gfx/codec/jpeg_codec.h" | 96 #include "ui/gfx/codec/jpeg_codec.h" |
| 96 #include "ui/gfx/gdi_util.h" | 97 #include "ui/gfx/gdi_util.h" |
| 97 #endif | 98 #endif |
| 98 | 99 |
| 99 #if defined(OS_MACOSX) && defined(USE_SKIA) | 100 #if defined(OS_MACOSX) && defined(USE_SKIA) |
| 100 #include "skia/ext/skia_utils_mac.h" | 101 #include "skia/ext/skia_utils_mac.h" |
| 101 #endif | 102 #endif |
| 102 | 103 |
| 103 using base::StringPrintf; | 104 using base::StringPrintf; |
| 104 using ppapi::InputEventImpl; | 105 using ppapi::InputEventImpl; |
| 106 using ppapi::PpapiGlobals; |
| 105 using ppapi::StringVar; | 107 using ppapi::StringVar; |
| 106 using ppapi::thunk::EnterResourceNoLock; | 108 using ppapi::thunk::EnterResourceNoLock; |
| 107 using ppapi::thunk::PPB_Buffer_API; | 109 using ppapi::thunk::PPB_Buffer_API; |
| 108 using ppapi::thunk::PPB_Graphics2D_API; | 110 using ppapi::thunk::PPB_Graphics2D_API; |
| 109 using ppapi::thunk::PPB_Graphics3D_API; | 111 using ppapi::thunk::PPB_Graphics3D_API; |
| 110 using ppapi::thunk::PPB_ImageData_API; | 112 using ppapi::thunk::PPB_ImageData_API; |
| 111 using ppapi::thunk::PPB_Instance_FunctionAPI; | 113 using ppapi::thunk::PPB_Instance_FunctionAPI; |
| 112 using ppapi::thunk::PPB_Surface3D_API; | 114 using ppapi::thunk::PPB_Surface3D_API; |
| 113 using ppapi::Var; | 115 using ppapi::Var; |
| 114 using WebKit::WebBindings; | 116 using WebKit::WebBindings; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 *output = PP_MakeRectFromXYWH(input.x(), input.y(), | 237 *output = PP_MakeRectFromXYWH(input.x(), input.y(), |
| 236 input.width(), input.height()); | 238 input.width(), input.height()); |
| 237 } | 239 } |
| 238 | 240 |
| 239 // Sets |*security_origin| to be the WebKit security origin associated with the | 241 // Sets |*security_origin| to be the WebKit security origin associated with the |
| 240 // document containing the given plugin instance. On success, returns true. If | 242 // document containing the given plugin instance. On success, returns true. If |
| 241 // the instance is invalid, returns false and |*security_origin| will be | 243 // the instance is invalid, returns false and |*security_origin| will be |
| 242 // unchanged. | 244 // unchanged. |
| 243 bool SecurityOriginForInstance(PP_Instance instance_id, | 245 bool SecurityOriginForInstance(PP_Instance instance_id, |
| 244 WebKit::WebSecurityOrigin* security_origin) { | 246 WebKit::WebSecurityOrigin* security_origin) { |
| 245 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); | 247 PluginInstance* instance = |
| 248 HostGlobals::Get()->host_resource_tracker()->GetInstance(instance_id); |
| 246 if (!instance) | 249 if (!instance) |
| 247 return false; | 250 return false; |
| 248 | 251 |
| 249 WebElement plugin_element = instance->container()->element(); | 252 WebElement plugin_element = instance->container()->element(); |
| 250 *security_origin = plugin_element.document().securityOrigin(); | 253 *security_origin = plugin_element.document().securityOrigin(); |
| 251 return true; | 254 return true; |
| 252 } | 255 } |
| 253 | 256 |
| 254 } // namespace | 257 } // namespace |
| 255 | 258 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 fullscreen_(false), | 302 fullscreen_(false), |
| 300 message_channel_(NULL), | 303 message_channel_(NULL), |
| 301 sad_plugin_(NULL), | 304 sad_plugin_(NULL), |
| 302 input_event_mask_(0), | 305 input_event_mask_(0), |
| 303 filtered_input_event_mask_(0), | 306 filtered_input_event_mask_(0), |
| 304 text_input_type_(kPluginDefaultTextInputType), | 307 text_input_type_(kPluginDefaultTextInputType), |
| 305 text_input_caret_(0, 0, 0, 0), | 308 text_input_caret_(0, 0, 0, 0), |
| 306 text_input_caret_bounds_(0, 0, 0, 0), | 309 text_input_caret_bounds_(0, 0, 0, 0), |
| 307 text_input_caret_set_(false), | 310 text_input_caret_set_(false), |
| 308 lock_mouse_callback_(PP_BlockUntilComplete()) { | 311 lock_mouse_callback_(PP_BlockUntilComplete()) { |
| 309 pp_instance_ = ResourceTracker::Get()->AddInstance(this); | 312 pp_instance_ = HostGlobals::Get()->host_resource_tracker()->AddInstance(this); |
| 310 | 313 |
| 311 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); | 314 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); |
| 312 DCHECK(delegate); | 315 DCHECK(delegate); |
| 313 module_->InstanceCreated(this); | 316 module_->InstanceCreated(this); |
| 314 delegate_->InstanceCreated(this); | 317 delegate_->InstanceCreated(this); |
| 315 message_channel_.reset(new MessageChannel(this)); | 318 message_channel_.reset(new MessageChannel(this)); |
| 316 } | 319 } |
| 317 | 320 |
| 318 PluginInstance::~PluginInstance() { | 321 PluginInstance::~PluginInstance() { |
| 319 DCHECK(!fullscreen_container_); | 322 DCHECK(!fullscreen_container_); |
| 320 | 323 |
| 321 // Free all the plugin objects. This will automatically clear the back- | 324 // Free all the plugin objects. This will automatically clear the back- |
| 322 // pointer from the NPObject so WebKit can't call into the plugin any more. | 325 // pointer from the NPObject so WebKit can't call into the plugin any more. |
| 323 // | 326 // |
| 324 // Swap out the set so we can delete from it (the objects will try to | 327 // Swap out the set so we can delete from it (the objects will try to |
| 325 // unregister themselves inside the delete call). | 328 // unregister themselves inside the delete call). |
| 326 PluginObjectSet plugin_object_copy; | 329 PluginObjectSet plugin_object_copy; |
| 327 live_plugin_objects_.swap(plugin_object_copy); | 330 live_plugin_objects_.swap(plugin_object_copy); |
| 328 for (PluginObjectSet::iterator i = plugin_object_copy.begin(); | 331 for (PluginObjectSet::iterator i = plugin_object_copy.begin(); |
| 329 i != plugin_object_copy.end(); ++i) | 332 i != plugin_object_copy.end(); ++i) |
| 330 delete *i; | 333 delete *i; |
| 331 | 334 |
| 332 if (lock_mouse_callback_.func) | 335 if (lock_mouse_callback_.func) |
| 333 PP_RunAndClearCompletionCallback(&lock_mouse_callback_, PP_ERROR_ABORTED); | 336 PP_RunAndClearCompletionCallback(&lock_mouse_callback_, PP_ERROR_ABORTED); |
| 334 | 337 |
| 335 delegate_->InstanceDeleted(this); | 338 delegate_->InstanceDeleted(this); |
| 336 module_->InstanceDeleted(this); | 339 module_->InstanceDeleted(this); |
| 337 | 340 |
| 338 ResourceTracker::Get()->InstanceDeleted(pp_instance_); | 341 HostGlobals::Get()->host_resource_tracker()->InstanceDeleted(pp_instance_); |
| 339 } | 342 } |
| 340 | 343 |
| 341 // NOTE: Any of these methods that calls into the plugin needs to take into | 344 // NOTE: Any of these methods that calls into the plugin needs to take into |
| 342 // account that the plugin may use Var to remove the <embed> from the DOM, which | 345 // account that the plugin may use Var to remove the <embed> from the DOM, which |
| 343 // will make the WebPluginImpl drop its reference, usually the last one. If a | 346 // will make the WebPluginImpl drop its reference, usually the last one. If a |
| 344 // method needs to access a member of the instance after the call has returned, | 347 // method needs to access a member of the instance after the call has returned, |
| 345 // then it needs to keep its own reference on the stack. | 348 // then it needs to keep its own reference on the stack. |
| 346 | 349 |
| 347 void PluginInstance::Delete() { | 350 void PluginInstance::Delete() { |
| 348 // Keep a reference on the stack. See NOTE above. | 351 // Keep a reference on the stack. See NOTE above. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 | 419 |
| 417 void PluginInstance::CommitBackingTexture() { | 420 void PluginInstance::CommitBackingTexture() { |
| 418 if (fullscreen_container_) | 421 if (fullscreen_container_) |
| 419 fullscreen_container_->Invalidate(); | 422 fullscreen_container_->Invalidate(); |
| 420 else if (container_) | 423 else if (container_) |
| 421 container_->commitBackingTexture(); | 424 container_->commitBackingTexture(); |
| 422 } | 425 } |
| 423 | 426 |
| 424 void PluginInstance::InstanceCrashed() { | 427 void PluginInstance::InstanceCrashed() { |
| 425 // Force free all resources and vars. | 428 // Force free all resources and vars. |
| 426 ResourceTracker::Get()->InstanceCrashed(pp_instance()); | 429 HostGlobals::Get()->host_resource_tracker()->InstanceCrashed(pp_instance()); |
| 427 | 430 |
| 428 // Free any associated graphics. | 431 // Free any associated graphics. |
| 429 SetFullscreen(false, false); | 432 SetFullscreen(false, false); |
| 430 FlashSetFullscreen(false, false); | 433 FlashSetFullscreen(false, false); |
| 431 bound_graphics_ = NULL; | 434 bound_graphics_ = NULL; |
| 432 InvalidateRect(gfx::Rect()); | 435 InvalidateRect(gfx::Rect()); |
| 433 | 436 |
| 434 delegate()->PluginCrashed(this); | 437 delegate()->PluginCrashed(this); |
| 435 } | 438 } |
| 436 | 439 |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 if (!LoadSelectionInterface()) | 866 if (!LoadSelectionInterface()) |
| 864 return string16(); | 867 return string16(); |
| 865 | 868 |
| 866 PP_Var rv = plugin_selection_interface_->GetSelectedText(pp_instance(), | 869 PP_Var rv = plugin_selection_interface_->GetSelectedText(pp_instance(), |
| 867 PP_FromBool(html)); | 870 PP_FromBool(html)); |
| 868 StringVar* string = StringVar::FromPPVar(rv); | 871 StringVar* string = StringVar::FromPPVar(rv); |
| 869 string16 selection; | 872 string16 selection; |
| 870 if (string) | 873 if (string) |
| 871 selection = UTF8ToUTF16(string->value()); | 874 selection = UTF8ToUTF16(string->value()); |
| 872 // Release the ref the plugin transfered to us. | 875 // Release the ref the plugin transfered to us. |
| 873 ResourceTracker::Get()->GetVarTracker()->ReleaseVar(rv); | 876 HostGlobals::Get()->GetVarTracker()->ReleaseVar(rv); |
| 874 return selection; | 877 return selection; |
| 875 } | 878 } |
| 876 | 879 |
| 877 string16 PluginInstance::GetLinkAtPosition(const gfx::Point& point) { | 880 string16 PluginInstance::GetLinkAtPosition(const gfx::Point& point) { |
| 878 // Keep a reference on the stack. See NOTE above. | 881 // Keep a reference on the stack. See NOTE above. |
| 879 scoped_refptr<PluginInstance> ref(this); | 882 scoped_refptr<PluginInstance> ref(this); |
| 880 if (!LoadPdfInterface()) | 883 if (!LoadPdfInterface()) |
| 881 return string16(); | 884 return string16(); |
| 882 | 885 |
| 883 PP_Point p; | 886 PP_Point p; |
| 884 p.x = point.x(); | 887 p.x = point.x(); |
| 885 p.y = point.y(); | 888 p.y = point.y(); |
| 886 PP_Var rv = plugin_pdf_interface_->GetLinkAtPosition(pp_instance(), p); | 889 PP_Var rv = plugin_pdf_interface_->GetLinkAtPosition(pp_instance(), p); |
| 887 StringVar* string = StringVar::FromPPVar(rv); | 890 StringVar* string = StringVar::FromPPVar(rv); |
| 888 string16 link; | 891 string16 link; |
| 889 if (string) | 892 if (string) |
| 890 link = UTF8ToUTF16(string->value()); | 893 link = UTF8ToUTF16(string->value()); |
| 891 // Release the ref the plugin transfered to us. | 894 // Release the ref the plugin transfered to us. |
| 892 ResourceTracker::Get()->GetVarTracker()->ReleaseVar(rv); | 895 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(rv); |
| 893 return link; | 896 return link; |
| 894 } | 897 } |
| 895 | 898 |
| 896 void PluginInstance::Zoom(double factor, bool text_only) { | 899 void PluginInstance::Zoom(double factor, bool text_only) { |
| 897 // Keep a reference on the stack. See NOTE above. | 900 // Keep a reference on the stack. See NOTE above. |
| 898 scoped_refptr<PluginInstance> ref(this); | 901 scoped_refptr<PluginInstance> ref(this); |
| 899 if (!LoadZoomInterface()) | 902 if (!LoadZoomInterface()) |
| 900 return; | 903 return; |
| 901 plugin_zoom_interface_->Zoom(pp_instance(), factor, PP_FromBool(text_only)); | 904 plugin_zoom_interface_->Zoom(pp_instance(), factor, PP_FromBool(text_only)); |
| 902 } | 905 } |
| (...skipping 1161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2064 screen_size_for_fullscreen_ = gfx::Size(); | 2067 screen_size_for_fullscreen_ = gfx::Size(); |
| 2065 WebElement element = container_->element(); | 2068 WebElement element = container_->element(); |
| 2066 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); | 2069 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); |
| 2067 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); | 2070 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); |
| 2068 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); | 2071 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); |
| 2069 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); | 2072 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); |
| 2070 } | 2073 } |
| 2071 | 2074 |
| 2072 } // namespace ppapi | 2075 } // namespace ppapi |
| 2073 } // namespace webkit | 2076 } // namespace webkit |
| OLD | NEW |