Chromium Code Reviews| Index: content/renderer/pepper_plugin_delegate_impl.cc |
| diff --git a/content/renderer/pepper_plugin_delegate_impl.cc b/content/renderer/pepper_plugin_delegate_impl.cc |
| index 8bc1fb89596aa2ed5f2fc695ee99f66b8c27a685..ed62863cd2914048dc5e83e0164c817f7fcf9d45 100644 |
| --- a/content/renderer/pepper_plugin_delegate_impl.cc |
| +++ b/content/renderer/pepper_plugin_delegate_impl.cc |
| @@ -852,15 +852,10 @@ PepperPluginDelegateImpl::PepperPluginDelegateImpl(RenderViewImpl* render_view) |
| has_saved_context_menu_action_(false), |
| saved_context_menu_action_(0), |
| focused_plugin_(NULL), |
| - mouse_lock_owner_(NULL), |
| - mouse_locked_(false), |
| - pending_lock_request_(false), |
| - pending_unlock_request_(false), |
| last_mouse_event_target_(NULL) { |
| } |
| PepperPluginDelegateImpl::~PepperPluginDelegateImpl() { |
| - DCHECK(!mouse_lock_owner_); |
| } |
| scoped_refptr<webkit::ppapi::PluginModule> |
| @@ -1148,8 +1143,7 @@ bool PepperPluginDelegateImpl::CanComposeInline() const { |
| void PepperPluginDelegateImpl::PluginCrashed( |
| webkit::ppapi::PluginInstance* instance) { |
| render_view_->PluginCrashed(instance->module()->path()); |
| - |
| - UnlockMouse(instance); |
| + UnSetAndDeleteLockTargetAdapter(instance); |
| } |
| void PepperPluginDelegateImpl::InstanceCreated( |
| @@ -1163,14 +1157,8 @@ void PepperPluginDelegateImpl::InstanceCreated( |
| void PepperPluginDelegateImpl::InstanceDeleted( |
| webkit::ppapi::PluginInstance* instance) { |
| active_instances_.erase(instance); |
| + UnSetAndDeleteLockTargetAdapter(instance); |
| - if (mouse_lock_owner_ && mouse_lock_owner_ == instance) { |
| - // UnlockMouse() will determine whether a ViewHostMsg_UnlockMouse needs to |
| - // be sent, and set internal state properly. We only need to forget about |
| - // the current |mouse_lock_owner_|. |
| - UnlockMouse(mouse_lock_owner_); |
| - mouse_lock_owner_ = NULL; |
| - } |
| if (last_mouse_event_target_ == instance) |
| last_mouse_event_target_ = NULL; |
| if (focused_plugin_ == instance) |
| @@ -1361,50 +1349,7 @@ bool PepperPluginDelegateImpl::IsPluginFocused() const { |
| return focused_plugin_ != NULL; |
| } |
| -void PepperPluginDelegateImpl::OnLockMouseACK(bool succeeded) { |
| - DCHECK(!mouse_locked_ && pending_lock_request_); |
| - |
| - mouse_locked_ = succeeded; |
| - pending_lock_request_ = false; |
| - if (pending_unlock_request_ && !succeeded) { |
| - // We have sent an unlock request after the lock request. However, since |
| - // the lock request has failed, the unlock request will be ignored by the |
| - // browser side and there won't be any response to it. |
| - pending_unlock_request_ = false; |
| - } |
| - // If the PluginInstance has been deleted, |mouse_lock_owner_| can be NULL. |
| - if (mouse_lock_owner_) { |
| - webkit::ppapi::PluginInstance* last_mouse_lock_owner = mouse_lock_owner_; |
| - if (!succeeded) { |
| - // Reset |mouse_lock_owner_| to NULL before calling OnLockMouseACK(), so |
| - // that if OnLockMouseACK() results in calls to any mouse lock method |
| - // (e.g., LockMouse()), the method will see consistent internal state. |
| - mouse_lock_owner_ = NULL; |
| - } |
| - |
| - last_mouse_lock_owner->OnLockMouseACK(succeeded ? PP_OK : PP_ERROR_FAILED); |
| - } |
| -} |
| - |
| -void PepperPluginDelegateImpl::OnMouseLockLost() { |
| - DCHECK(mouse_locked_ && !pending_lock_request_); |
| - |
| - mouse_locked_ = false; |
| - pending_unlock_request_ = false; |
| - // If the PluginInstance has been deleted, |mouse_lock_owner_| can be NULL. |
| - if (mouse_lock_owner_) { |
| - // Reset |mouse_lock_owner_| to NULL before calling OnMouseLockLost(), so |
| - // that if OnMouseLockLost() results in calls to any mouse lock method |
| - // (e.g., LockMouse()), the method will see consistent internal state. |
| - webkit::ppapi::PluginInstance* last_mouse_lock_owner = mouse_lock_owner_; |
| - mouse_lock_owner_ = NULL; |
| - |
| - last_mouse_lock_owner->OnMouseLockLost(); |
| - } |
| -} |
| - |
| -bool PepperPluginDelegateImpl::HandleMouseEvent( |
| - const WebKit::WebMouseEvent& event) { |
| +void PepperPluginDelegateImpl::WillHandleMouseEvent() { |
| // This method is called for every mouse event that the render view receives. |
| // And then the mouse event is forwarded to WebKit, which dispatches it to the |
| // event target. Potentially a Pepper plugin will receive the event. |
| @@ -1413,19 +1358,6 @@ bool PepperPluginDelegateImpl::HandleMouseEvent( |
| // event, it will notify us via DidReceiveMouseEvent() and set itself as |
| // |last_mouse_event_target_|. |
| last_mouse_event_target_ = NULL; |
| - |
| - if (mouse_locked_) { |
| - if (mouse_lock_owner_) { |
| - // |cursor_info| is ignored since it is hidden when the mouse is locked. |
| - WebKit::WebCursorInfo cursor_info; |
| - mouse_lock_owner_->HandleInputEvent(event, &cursor_info); |
| - } |
| - |
| - // If the mouse is locked, only the current owner of the mouse lock can |
| - // process mouse events. |
| - return true; |
| - } |
| - return false; |
| } |
| bool PepperPluginDelegateImpl::OpenFileSystem( |
| @@ -1963,56 +1895,23 @@ ppapi::Preferences PepperPluginDelegateImpl::GetPreferences() { |
| return ppapi::Preferences(render_view_->webkit_preferences()); |
| } |
| -void PepperPluginDelegateImpl::LockMouse( |
| +bool PepperPluginDelegateImpl::LockMouse( |
| webkit::ppapi::PluginInstance* instance) { |
| - DCHECK(instance); |
| - if (!MouseLockedOrPending()) { |
| - DCHECK(!mouse_lock_owner_); |
| - pending_lock_request_ = true; |
| - mouse_lock_owner_ = instance; |
| - |
| - render_view_->Send( |
| - new ViewHostMsg_LockMouse(render_view_->routing_id())); |
| - } else if (instance != mouse_lock_owner_) { |
| - // Another plugin instance is using mouse lock. Fail immediately. |
| - instance->OnLockMouseACK(PP_ERROR_FAILED); |
| - } else { |
| - if (mouse_locked_) { |
| - instance->OnLockMouseACK(PP_OK); |
| - } else if (pending_lock_request_) { |
| - instance->OnLockMouseACK(PP_ERROR_INPROGRESS); |
| - } else { |
| - // The only case left here is |
| - // !mouse_locked_ && !pending_lock_request_ && pending_unlock_request_, |
| - // which is not possible. |
| - NOTREACHED(); |
| - instance->OnLockMouseACK(PP_ERROR_FAILED); |
| - } |
| - } |
| + |
| + return render_view_->mouse_lock_dispatcher()->LockMouse( |
| + GetOrCreateLockTargetAdapter(instance)); |
| } |
| void PepperPluginDelegateImpl::UnlockMouse( |
| webkit::ppapi::PluginInstance* instance) { |
| - DCHECK(instance); |
| - |
| - // If no one is using mouse lock or the user is not |instance|, ignore |
| - // the unlock request. |
| - if (MouseLockedOrPending() && mouse_lock_owner_ == instance) { |
| - if (mouse_locked_ || pending_lock_request_) { |
| - DCHECK(!mouse_locked_ || !pending_lock_request_); |
| - if (!pending_unlock_request_) { |
| - pending_unlock_request_ = true; |
| - |
| - render_view_->Send( |
| - new ViewHostMsg_UnlockMouse(render_view_->routing_id())); |
| - } |
| - } else { |
| - // The only case left here is |
| - // !mouse_locked_ && !pending_lock_request_ && pending_unlock_request_, |
| - // which is not possible. |
| - NOTREACHED(); |
| - } |
| - } |
| + render_view_->mouse_lock_dispatcher()->UnlockMouse( |
| + GetOrCreateLockTargetAdapter(instance)); |
| +} |
| + |
| +bool PepperPluginDelegateImpl::IsMouseLocked( |
| + webkit::ppapi::PluginInstance* instance) { |
| + return render_view_->mouse_lock_dispatcher()->IsMouseLockedTo( |
| + GetOrCreateLockTargetAdapter(instance)); |
| } |
| void PepperPluginDelegateImpl::DidChangeCursor( |
| @@ -2172,3 +2071,23 @@ bool PepperPluginDelegateImpl::CanUseSocketAPIs() { |
| return content::GetContentClient()->renderer()->AllowSocketAPI(url); |
| } |
| + |
| +MouseLockDispatcher::LockTarget* |
| + PepperPluginDelegateImpl::GetOrCreateLockTargetAdapter( |
| + webkit::ppapi::PluginInstance* instance) { |
| + MouseLockDispatcher::LockTarget* target = mouse_lock_instances_[instance]; |
| + if (target) |
| + return target; |
| + |
| + return mouse_lock_instances_[instance] = |
| + MouseLockDispatcher::CreateLockTarget(instance); |
|
yzshen1
2012/01/24 18:56:08
4 space indent, please.
scheib
2012/01/25 00:27:11
Done.
|
| +} |
| + |
| +void PepperPluginDelegateImpl::UnSetAndDeleteLockTargetAdapter( |
| + webkit::ppapi::PluginInstance* instance) { |
| + if (mouse_lock_instances_.find(instance) != mouse_lock_instances_.end()) { |
| + render_view_->mouse_lock_dispatcher()->UnlockMouseAndClearTarget( |
| + mouse_lock_instances_[instance]); |
| + mouse_lock_instances_.erase(instance); |
|
piman
2012/01/24 02:27:37
I think you still need to delete the LockTarget he
scheib
2012/01/25 00:27:11
Done.
|
| + } |
| +} |