| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/linked_ptr.h" | 10 #include "base/memory/linked_ptr.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 #endif | 91 #endif |
| 92 | 92 |
| 93 #if defined(OS_WIN) | 93 #if defined(OS_WIN) |
| 94 #include "base/metrics/histogram.h" | 94 #include "base/metrics/histogram.h" |
| 95 #include "skia/ext/platform_canvas.h" | 95 #include "skia/ext/platform_canvas.h" |
| 96 #include "ui/gfx/codec/jpeg_codec.h" | 96 #include "ui/gfx/codec/jpeg_codec.h" |
| 97 #include "ui/gfx/gdi_util.h" | 97 #include "ui/gfx/gdi_util.h" |
| 98 #endif | 98 #endif |
| 99 | 99 |
| 100 using base::StringPrintf; | 100 using base::StringPrintf; |
| 101 using ppapi::ApiCallbackType; |
| 101 using ppapi::InputEventData; | 102 using ppapi::InputEventData; |
| 102 using ppapi::PPB_InputEvent_Shared; | 103 using ppapi::PPB_InputEvent_Shared; |
| 103 using ppapi::PpapiGlobals; | 104 using ppapi::PpapiGlobals; |
| 104 using ppapi::PPB_View_Shared; | 105 using ppapi::PPB_View_Shared; |
| 105 using ppapi::ScopedPPResource; | 106 using ppapi::ScopedPPResource; |
| 106 using ppapi::StringVar; | 107 using ppapi::StringVar; |
| 108 using ppapi::TrackedCallback; |
| 107 using ppapi::thunk::EnterResourceNoLock; | 109 using ppapi::thunk::EnterResourceNoLock; |
| 108 using ppapi::thunk::PPB_Buffer_API; | 110 using ppapi::thunk::PPB_Buffer_API; |
| 109 using ppapi::thunk::PPB_Graphics2D_API; | 111 using ppapi::thunk::PPB_Graphics2D_API; |
| 110 using ppapi::thunk::PPB_Graphics3D_API; | 112 using ppapi::thunk::PPB_Graphics3D_API; |
| 111 using ppapi::thunk::PPB_ImageData_API; | 113 using ppapi::thunk::PPB_ImageData_API; |
| 112 using ppapi::thunk::PPB_Instance_FunctionAPI; | 114 using ppapi::thunk::PPB_Instance_FunctionAPI; |
| 113 using ppapi::Var; | 115 using ppapi::Var; |
| 114 using ppapi::ViewData; | 116 using ppapi::ViewData; |
| 115 using WebKit::WebBindings; | 117 using WebKit::WebBindings; |
| 116 using WebKit::WebCanvas; | 118 using WebKit::WebCanvas; |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 message_channel_(NULL), | 310 message_channel_(NULL), |
| 309 sad_plugin_(NULL), | 311 sad_plugin_(NULL), |
| 310 input_event_mask_(0), | 312 input_event_mask_(0), |
| 311 filtered_input_event_mask_(0), | 313 filtered_input_event_mask_(0), |
| 312 text_input_type_(kPluginDefaultTextInputType), | 314 text_input_type_(kPluginDefaultTextInputType), |
| 313 text_input_caret_(0, 0, 0, 0), | 315 text_input_caret_(0, 0, 0, 0), |
| 314 text_input_caret_bounds_(0, 0, 0, 0), | 316 text_input_caret_bounds_(0, 0, 0, 0), |
| 315 text_input_caret_set_(false), | 317 text_input_caret_set_(false), |
| 316 selection_caret_(0), | 318 selection_caret_(0), |
| 317 selection_anchor_(0), | 319 selection_anchor_(0), |
| 318 lock_mouse_callback_(PP_BlockUntilComplete()), | |
| 319 pending_user_gesture_(0.0) { | 320 pending_user_gesture_(0.0) { |
| 320 pp_instance_ = HostGlobals::Get()->AddInstance(this); | 321 pp_instance_ = HostGlobals::Get()->AddInstance(this); |
| 321 | 322 |
| 322 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); | 323 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); |
| 323 DCHECK(delegate); | 324 DCHECK(delegate); |
| 324 module_->InstanceCreated(this); | 325 module_->InstanceCreated(this); |
| 325 delegate_->InstanceCreated(this); | 326 delegate_->InstanceCreated(this); |
| 326 message_channel_.reset(new MessageChannel(this)); | 327 message_channel_.reset(new MessageChannel(this)); |
| 327 | 328 |
| 328 view_data_.is_page_visible = delegate->IsPageVisible(); | 329 view_data_.is_page_visible = delegate->IsPageVisible(); |
| 329 } | 330 } |
| 330 | 331 |
| 331 PluginInstance::~PluginInstance() { | 332 PluginInstance::~PluginInstance() { |
| 332 DCHECK(!fullscreen_container_); | 333 DCHECK(!fullscreen_container_); |
| 333 | 334 |
| 334 // Free all the plugin objects. This will automatically clear the back- | 335 // Free all the plugin objects. This will automatically clear the back- |
| 335 // pointer from the NPObject so WebKit can't call into the plugin any more. | 336 // pointer from the NPObject so WebKit can't call into the plugin any more. |
| 336 // | 337 // |
| 337 // Swap out the set so we can delete from it (the objects will try to | 338 // Swap out the set so we can delete from it (the objects will try to |
| 338 // unregister themselves inside the delete call). | 339 // unregister themselves inside the delete call). |
| 339 PluginObjectSet plugin_object_copy; | 340 PluginObjectSet plugin_object_copy; |
| 340 live_plugin_objects_.swap(plugin_object_copy); | 341 live_plugin_objects_.swap(plugin_object_copy); |
| 341 for (PluginObjectSet::iterator i = plugin_object_copy.begin(); | 342 for (PluginObjectSet::iterator i = plugin_object_copy.begin(); |
| 342 i != plugin_object_copy.end(); ++i) | 343 i != plugin_object_copy.end(); ++i) |
| 343 delete *i; | 344 delete *i; |
| 344 | 345 |
| 345 if (lock_mouse_callback_.func) | 346 if (lock_mouse_callback_) |
| 346 PP_RunAndClearCompletionCallback(&lock_mouse_callback_, PP_ERROR_ABORTED); | 347 TrackedCallback::ClearAndAbort(&lock_mouse_callback_); |
| 347 | 348 |
| 348 delegate_->InstanceDeleted(this); | 349 delegate_->InstanceDeleted(this); |
| 349 module_->InstanceDeleted(this); | 350 module_->InstanceDeleted(this); |
| 350 | 351 |
| 351 HostGlobals::Get()->InstanceDeleted(pp_instance_); | 352 HostGlobals::Get()->InstanceDeleted(pp_instance_); |
| 352 } | 353 } |
| 353 | 354 |
| 354 // NOTE: Any of these methods that calls into the plugin needs to take into | 355 // NOTE: Any of these methods that calls into the plugin needs to take into |
| 355 // account that the plugin may use Var to remove the <embed> from the DOM, which | 356 // account that the plugin may use Var to remove the <embed> from the DOM, which |
| 356 // will make the WebPluginImpl drop its reference, usually the last one. If a | 357 // will make the WebPluginImpl drop its reference, usually the last one. If a |
| (...skipping 1347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1704 bool PluginInstance::IsProcessingUserGesture() { | 1705 bool PluginInstance::IsProcessingUserGesture() { |
| 1705 PP_TimeTicks now = | 1706 PP_TimeTicks now = |
| 1706 ::ppapi::TimeTicksToPPTimeTicks(base::TimeTicks::Now()); | 1707 ::ppapi::TimeTicksToPPTimeTicks(base::TimeTicks::Now()); |
| 1707 // Give a lot of slack so tests won't be flaky. Well behaved plugins will | 1708 // Give a lot of slack so tests won't be flaky. Well behaved plugins will |
| 1708 // close the user gesture. | 1709 // close the user gesture. |
| 1709 const PP_TimeTicks kUserGestureDurationInSeconds = 10.0; | 1710 const PP_TimeTicks kUserGestureDurationInSeconds = 10.0; |
| 1710 return (now - pending_user_gesture_ < kUserGestureDurationInSeconds); | 1711 return (now - pending_user_gesture_ < kUserGestureDurationInSeconds); |
| 1711 } | 1712 } |
| 1712 | 1713 |
| 1713 void PluginInstance::OnLockMouseACK(bool succeeded) { | 1714 void PluginInstance::OnLockMouseACK(bool succeeded) { |
| 1714 if (!lock_mouse_callback_.func) { | 1715 if (!lock_mouse_callback_) { |
| 1715 NOTREACHED(); | 1716 NOTREACHED(); |
| 1716 return; | 1717 return; |
| 1717 } | 1718 } |
| 1718 PP_RunAndClearCompletionCallback(&lock_mouse_callback_, | 1719 TrackedCallback::ClearAndRun(&lock_mouse_callback_, |
| 1719 succeeded ? PP_OK : PP_ERROR_FAILED); | 1720 succeeded ? PP_OK : PP_ERROR_FAILED); |
| 1720 } | 1721 } |
| 1721 | 1722 |
| 1722 void PluginInstance::OnMouseLockLost() { | 1723 void PluginInstance::OnMouseLockLost() { |
| 1723 if (LoadMouseLockInterface()) | 1724 if (LoadMouseLockInterface()) |
| 1724 plugin_mouse_lock_interface_->MouseLockLost(pp_instance()); | 1725 plugin_mouse_lock_interface_->MouseLockLost(pp_instance()); |
| 1725 } | 1726 } |
| 1726 | 1727 |
| 1727 void PluginInstance::HandleMouseLockedInputEvent( | 1728 void PluginInstance::HandleMouseLockedInputEvent( |
| 1728 const WebKit::WebMouseEvent& event) { | 1729 const WebKit::WebMouseEvent& event) { |
| 1729 // |cursor_info| is ignored since it is hidden when the mouse is locked. | 1730 // |cursor_info| is ignored since it is hidden when the mouse is locked. |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2031 // TODO(yzshen): Implement it. | 2032 // TODO(yzshen): Implement it. |
| 2032 NOTIMPLEMENTED(); | 2033 NOTIMPLEMENTED(); |
| 2033 return false; | 2034 return false; |
| 2034 #endif | 2035 #endif |
| 2035 | 2036 |
| 2036 DoSetCursor(custom_cursor.release()); | 2037 DoSetCursor(custom_cursor.release()); |
| 2037 return PP_TRUE; | 2038 return PP_TRUE; |
| 2038 } | 2039 } |
| 2039 | 2040 |
| 2040 int32_t PluginInstance::LockMouse(PP_Instance instance, | 2041 int32_t PluginInstance::LockMouse(PP_Instance instance, |
| 2041 PP_CompletionCallback callback) { | 2042 ApiCallbackType callback) { |
| 2042 if (!callback.func) { | 2043 if (TrackedCallback::IsPending(lock_mouse_callback_)) |
| 2043 // Don't support synchronous call. | |
| 2044 return PP_ERROR_BLOCKS_MAIN_THREAD; | |
| 2045 } | |
| 2046 if (lock_mouse_callback_.func) // A lock is pending. | |
| 2047 return PP_ERROR_INPROGRESS; | 2044 return PP_ERROR_INPROGRESS; |
| 2048 | 2045 |
| 2049 if (delegate()->IsMouseLocked(this)) | 2046 if (delegate()->IsMouseLocked(this)) |
| 2050 return PP_OK; | 2047 return PP_OK; |
| 2051 | 2048 |
| 2052 if (!CanAccessMainFrame()) | 2049 if (!CanAccessMainFrame()) |
| 2053 return PP_ERROR_NOACCESS; | 2050 return PP_ERROR_NOACCESS; |
| 2054 | 2051 |
| 2055 if (delegate()->LockMouse(this)) { | 2052 if (delegate()->LockMouse(this)) { |
| 2056 lock_mouse_callback_ = callback; | 2053 lock_mouse_callback_ = callback; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2185 screen_size_for_fullscreen_ = gfx::Size(); | 2182 screen_size_for_fullscreen_ = gfx::Size(); |
| 2186 WebElement element = container_->element(); | 2183 WebElement element = container_->element(); |
| 2187 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); | 2184 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); |
| 2188 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); | 2185 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); |
| 2189 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); | 2186 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); |
| 2190 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); | 2187 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); |
| 2191 } | 2188 } |
| 2192 | 2189 |
| 2193 } // namespace ppapi | 2190 } // namespace ppapi |
| 2194 } // namespace webkit | 2191 } // namespace webkit |
| OLD | NEW |