Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: content/renderer/pepper_plugin_delegate_impl.cc

Issue 7863003: Mouse lock implementation, including the renderer side and the Windows version of the browser side. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/renderer/pepper_plugin_delegate_impl.h ('k') | content/renderer/render_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "content/renderer/pepper_plugin_delegate_impl.h" 5 #include "content/renderer/pepper_plugin_delegate_impl.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <queue> 8 #include <queue>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "content/renderer/webplugin_delegate_proxy.h" 45 #include "content/renderer/webplugin_delegate_proxy.h"
46 #include "ipc/ipc_channel_handle.h" 46 #include "ipc/ipc_channel_handle.h"
47 #include "media/video/capture/video_capture_proxy.h" 47 #include "media/video/capture/video_capture_proxy.h"
48 #include "ppapi/c/dev/pp_video_dev.h" 48 #include "ppapi/c/dev/pp_video_dev.h"
49 #include "ppapi/c/pp_errors.h" 49 #include "ppapi/c/pp_errors.h"
50 #include "ppapi/c/private/ppb_flash.h" 50 #include "ppapi/c/private/ppb_flash.h"
51 #include "ppapi/c/private/ppb_flash_net_connector.h" 51 #include "ppapi/c/private/ppb_flash_net_connector.h"
52 #include "ppapi/proxy/host_dispatcher.h" 52 #include "ppapi/proxy/host_dispatcher.h"
53 #include "ppapi/proxy/ppapi_messages.h" 53 #include "ppapi/proxy/ppapi_messages.h"
54 #include "ppapi/shared_impl/ppapi_preferences.h" 54 #include "ppapi/shared_impl/ppapi_preferences.h"
55 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
55 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserComplet ion.h" 56 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserComplet ion.h"
56 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams. h" 57 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams. h"
58 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
57 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" 59 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
58 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" 60 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h"
59 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 61 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
60 #include "ui/gfx/size.h" 62 #include "ui/gfx/size.h"
61 #include "ui/gfx/surface/transport_dib.h" 63 #include "ui/gfx/surface/transport_dib.h"
62 #include "webkit/fileapi/file_system_callback_dispatcher.h" 64 #include "webkit/fileapi/file_system_callback_dispatcher.h"
63 #include "webkit/glue/context_menu.h" 65 #include "webkit/glue/context_menu.h"
64 #include "webkit/plugins/npapi/webplugin.h" 66 #include "webkit/plugins/npapi/webplugin.h"
65 #include "webkit/plugins/ppapi/file_path.h" 67 #include "webkit/plugins/ppapi/file_path.h"
66 #include "webkit/plugins/ppapi/ppb_file_io_impl.h" 68 #include "webkit/plugins/ppapi/ppb_file_io_impl.h"
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 // saved pipe handle. 658 // saved pipe handle.
657 // Temporarily, just call back. 659 // Temporarily, just call back.
658 client->BrokerConnected(PlatformFileToInt(plugin_handle), result); 660 client->BrokerConnected(PlatformFileToInt(plugin_handle), result);
659 } 661 }
660 662
661 PepperPluginDelegateImpl::PepperPluginDelegateImpl(RenderView* render_view) 663 PepperPluginDelegateImpl::PepperPluginDelegateImpl(RenderView* render_view)
662 : render_view_(render_view), 664 : render_view_(render_view),
663 has_saved_context_menu_action_(false), 665 has_saved_context_menu_action_(false),
664 saved_context_menu_action_(0), 666 saved_context_menu_action_(0),
665 id_generator_(0), 667 id_generator_(0),
666 is_pepper_plugin_focused_(false) { 668 is_pepper_plugin_focused_(false),
669 mouse_lock_owner_(NULL),
670 mouse_locked_(false),
671 pending_lock_request_(false),
672 pending_unlock_request_(false) {
667 } 673 }
668 674
669 PepperPluginDelegateImpl::~PepperPluginDelegateImpl() { 675 PepperPluginDelegateImpl::~PepperPluginDelegateImpl() {
676 DCHECK(!mouse_lock_owner_);
670 } 677 }
671 678
672 scoped_refptr<webkit::ppapi::PluginModule> 679 scoped_refptr<webkit::ppapi::PluginModule>
673 PepperPluginDelegateImpl::CreatePepperPluginModule( 680 PepperPluginDelegateImpl::CreatePepperPluginModule(
674 const webkit::WebPluginInfo& webplugin_info, 681 const webkit::WebPluginInfo& webplugin_info,
675 bool* pepper_plugin_was_registered) { 682 bool* pepper_plugin_was_registered) {
676 *pepper_plugin_was_registered = true; 683 *pepper_plugin_was_registered = true;
677 684
678 // See if a module has already been loaded for this plugin. 685 // See if a module has already been loaded for this plugin.
679 FilePath path(webplugin_info.path); 686 FilePath path(webplugin_info.path);
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 void PepperPluginDelegateImpl::PluginFocusChanged(bool focused) { 851 void PepperPluginDelegateImpl::PluginFocusChanged(bool focused) {
845 is_pepper_plugin_focused_ = focused; 852 is_pepper_plugin_focused_ = focused;
846 if (render_view_) 853 if (render_view_)
847 render_view_->PpapiPluginFocusChanged(); 854 render_view_->PpapiPluginFocusChanged();
848 } 855 }
849 856
850 void PepperPluginDelegateImpl::PluginCrashed( 857 void PepperPluginDelegateImpl::PluginCrashed(
851 webkit::ppapi::PluginInstance* instance) { 858 webkit::ppapi::PluginInstance* instance) {
852 subscribed_to_policy_updates_.erase(instance); 859 subscribed_to_policy_updates_.erase(instance);
853 render_view_->PluginCrashed(instance->module()->path()); 860 render_view_->PluginCrashed(instance->module()->path());
861
862 UnlockMouse(instance);
854 } 863 }
855 864
856 void PepperPluginDelegateImpl::InstanceCreated( 865 void PepperPluginDelegateImpl::InstanceCreated(
857 webkit::ppapi::PluginInstance* instance) { 866 webkit::ppapi::PluginInstance* instance) {
858 active_instances_.insert(instance); 867 active_instances_.insert(instance);
859 868
860 // Set the initial focus. 869 // Set the initial focus.
861 instance->SetContentAreaFocus(render_view_->has_focus()); 870 instance->SetContentAreaFocus(render_view_->has_focus());
862 } 871 }
863 872
864 void PepperPluginDelegateImpl::InstanceDeleted( 873 void PepperPluginDelegateImpl::InstanceDeleted(
865 webkit::ppapi::PluginInstance* instance) { 874 webkit::ppapi::PluginInstance* instance) {
866 active_instances_.erase(instance); 875 active_instances_.erase(instance);
867 subscribed_to_policy_updates_.erase(instance); 876 subscribed_to_policy_updates_.erase(instance);
877
878 if (mouse_lock_owner_ && mouse_lock_owner_ == instance) {
879 // UnlockMouse() will determine whether a ViewHostMsg_UnlockMouse needs to
880 // be sent, and set internal state properly. We only need to forget about
881 // the current |mouse_lock_owner_|.
882 UnlockMouse(mouse_lock_owner_);
883 mouse_lock_owner_ = NULL;
884 }
868 } 885 }
869 886
870 SkBitmap* PepperPluginDelegateImpl::GetSadPluginBitmap() { 887 SkBitmap* PepperPluginDelegateImpl::GetSadPluginBitmap() {
871 return content::GetContentClient()->renderer()->GetSadPluginBitmap(); 888 return content::GetContentClient()->renderer()->GetSadPluginBitmap();
872 } 889 }
873 890
874 webkit::ppapi::PluginDelegate::PlatformImage2D* 891 webkit::ppapi::PluginDelegate::PlatformImage2D*
875 PepperPluginDelegateImpl::CreateImage2D(int width, int height) { 892 PepperPluginDelegateImpl::CreateImage2D(int width, int height) {
876 uint32 buffer_size = width * height * 4; 893 uint32 buffer_size = width * height * 4;
877 894
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 messages_waiting_replies_.Remove(message_id); 1037 messages_waiting_replies_.Remove(message_id);
1021 callback->Run(error_code, base::PassPlatformFile(&file)); 1038 callback->Run(error_code, base::PassPlatformFile(&file));
1022 // Make sure we won't leak file handle if the requester has died. 1039 // Make sure we won't leak file handle if the requester has died.
1023 if (file != base::kInvalidPlatformFileValue) 1040 if (file != base::kInvalidPlatformFileValue)
1024 base::FileUtilProxy::Close(GetFileThreadMessageLoopProxy(), file, NULL); 1041 base::FileUtilProxy::Close(GetFileThreadMessageLoopProxy(), file, NULL);
1025 delete callback; 1042 delete callback;
1026 } 1043 }
1027 1044
1028 void PepperPluginDelegateImpl::OnSetFocus(bool has_focus) { 1045 void PepperPluginDelegateImpl::OnSetFocus(bool has_focus) {
1029 for (std::set<webkit::ppapi::PluginInstance*>::iterator i = 1046 for (std::set<webkit::ppapi::PluginInstance*>::iterator i =
1030 active_instances_.begin(); 1047 active_instances_.begin();
1031 i != active_instances_.end(); ++i) 1048 i != active_instances_.end(); ++i)
1032 (*i)->SetContentAreaFocus(has_focus); 1049 (*i)->SetContentAreaFocus(has_focus);
1033 } 1050 }
1034 1051
1035 bool PepperPluginDelegateImpl::IsPluginFocused() const { 1052 bool PepperPluginDelegateImpl::IsPluginFocused() const {
1036 return is_pepper_plugin_focused_; 1053 return is_pepper_plugin_focused_;
1037 } 1054 }
1038 1055
1056 void PepperPluginDelegateImpl::OnLockMouseACK(bool succeeded) {
1057 DCHECK(!mouse_locked_ && pending_lock_request_);
1058
1059 mouse_locked_ = succeeded;
1060 pending_lock_request_ = false;
1061 if (pending_unlock_request_ && !succeeded) {
1062 // We have sent an unlock request after the lock request. However, since
1063 // the lock request has failed, the unlock request will be ignored by the
1064 // browser side and there won't be any response to it.
1065 pending_unlock_request_ = false;
1066 }
1067 // If the PluginInstance has been deleted, |mouse_lock_owner_| can be NULL.
1068 if (mouse_lock_owner_) {
1069 webkit::ppapi::PluginInstance* last_mouse_lock_owner = mouse_lock_owner_;
1070 if (!succeeded) {
1071 // Reset |mouse_lock_owner_| to NULL before calling OnLockMouseACK(), so
1072 // that if OnLockMouseACK() results in calls to any mouse lock method
1073 // (e.g., LockMouse()), the method will see consistent internal state.
1074 mouse_lock_owner_ = NULL;
1075 }
1076
1077 last_mouse_lock_owner->OnLockMouseACK(succeeded ? PP_OK : PP_ERROR_FAILED);
1078 }
1079 }
1080
1081 void PepperPluginDelegateImpl::OnMouseLockLost() {
1082 DCHECK(mouse_locked_ && !pending_lock_request_);
1083
1084 mouse_locked_ = false;
1085 pending_unlock_request_ = false;
1086 // If the PluginInstance has been deleted, |mouse_lock_owner_| can be NULL.
1087 if (mouse_lock_owner_) {
1088 // Reset |mouse_lock_owner_| to NULL before calling OnMouseLockLost(), so
1089 // that if OnMouseLockLost() results in calls to any mouse lock method
1090 // (e.g., LockMouse()), the method will see consistent internal state.
1091 webkit::ppapi::PluginInstance* last_mouse_lock_owner = mouse_lock_owner_;
1092 mouse_lock_owner_ = NULL;
1093
1094 last_mouse_lock_owner->OnMouseLockLost();
1095 }
1096 }
1097
1098 bool PepperPluginDelegateImpl::DispatchLockedMouseEvent(
1099 const WebKit::WebMouseEvent& event) {
1100 if (mouse_locked_) {
1101 if (mouse_lock_owner_) {
1102 // |cursor_info| is ignored since it is hidden when the mouse is locked.
1103 WebKit::WebCursorInfo cursor_info;
1104 mouse_lock_owner_->HandleInputEvent(event, &cursor_info);
1105 }
1106
1107 // If the mouse is locked, only the current owner of the mouse lock can
1108 // process mouse events.
1109 return true;
1110 }
1111 return false;
1112 }
1113
1039 bool PepperPluginDelegateImpl::OpenFileSystem( 1114 bool PepperPluginDelegateImpl::OpenFileSystem(
1040 const GURL& url, 1115 const GURL& url,
1041 fileapi::FileSystemType type, 1116 fileapi::FileSystemType type,
1042 long long size, 1117 long long size,
1043 fileapi::FileSystemCallbackDispatcher* dispatcher) { 1118 fileapi::FileSystemCallbackDispatcher* dispatcher) {
1044 FileSystemDispatcher* file_system_dispatcher = 1119 FileSystemDispatcher* file_system_dispatcher =
1045 ChildThread::current()->file_system_dispatcher(); 1120 ChildThread::current()->file_system_dispatcher();
1046 return file_system_dispatcher->OpenFileSystem( 1121 return file_system_dispatcher->OpenFileSystem(
1047 url.GetWithEmptyPath(), type, size, true /* create */, dispatcher); 1122 url.GetWithEmptyPath(), type, size, true /* create */, dispatcher);
1048 } 1123 }
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
1483 DLOG(WARNING) << "Browser failed to allocate shared memory"; 1558 DLOG(WARNING) << "Browser failed to allocate shared memory";
1484 return NULL; 1559 return NULL;
1485 } 1560 }
1486 return new base::SharedMemory(handle, false); 1561 return new base::SharedMemory(handle, false);
1487 } 1562 }
1488 1563
1489 ppapi::Preferences PepperPluginDelegateImpl::GetPreferences() { 1564 ppapi::Preferences PepperPluginDelegateImpl::GetPreferences() {
1490 return ppapi::Preferences(render_view_->webkit_preferences()); 1565 return ppapi::Preferences(render_view_->webkit_preferences());
1491 } 1566 }
1492 1567
1568 void PepperPluginDelegateImpl::LockMouse(
1569 webkit::ppapi::PluginInstance* instance) {
1570 DCHECK(instance);
1571 if (!MouseLockedOrPending()) {
1572 DCHECK(!mouse_lock_owner_);
1573 pending_lock_request_ = true;
1574 mouse_lock_owner_ = instance;
1575
1576 render_view_->Send(
1577 new ViewHostMsg_LockMouse(render_view_->routing_id()));
1578 } else if (instance != mouse_lock_owner_) {
1579 // Another plugin instance is using mouse lock. Fail immediately.
1580 instance->OnLockMouseACK(PP_ERROR_FAILED);
1581 } else {
1582 if (mouse_locked_) {
1583 instance->OnLockMouseACK(PP_OK);
1584 } else if (pending_lock_request_) {
1585 instance->OnLockMouseACK(PP_ERROR_INPROGRESS);
1586 } else {
1587 // The only case left here is
1588 // !mouse_locked_ && !pending_lock_request_ && pending_unlock_request_,
1589 // which is not possible.
1590 NOTREACHED();
1591 instance->OnLockMouseACK(PP_ERROR_FAILED);
1592 }
1593 }
1594 }
1595
1596 void PepperPluginDelegateImpl::UnlockMouse(
1597 webkit::ppapi::PluginInstance* instance) {
1598 DCHECK(instance);
1599
1600 // If no one is using mouse lock or the user is not |instance|, ignore
1601 // the unlock request.
1602 if (MouseLockedOrPending() && mouse_lock_owner_ == instance) {
1603 if (mouse_locked_ || pending_lock_request_) {
1604 DCHECK(!mouse_locked_ || !pending_lock_request_);
1605 if (!pending_unlock_request_) {
1606 pending_unlock_request_ = true;
1607
1608 render_view_->Send(
1609 new ViewHostMsg_UnlockMouse(render_view_->routing_id()));
1610 }
1611 } else {
1612 // The only case left here is
1613 // !mouse_locked_ && !pending_lock_request_ && pending_unlock_request_,
1614 // which is not possible.
1615 NOTREACHED();
1616 }
1617 }
1618 }
1619
1493 int PepperPluginDelegateImpl::GetRoutingId() const { 1620 int PepperPluginDelegateImpl::GetRoutingId() const {
1494 return render_view_->routing_id(); 1621 return render_view_->routing_id();
1495 } 1622 }
1496 1623
1497 void PepperPluginDelegateImpl::PublishInitialPolicy( 1624 void PepperPluginDelegateImpl::PublishInitialPolicy(
1498 scoped_refptr<webkit::ppapi::PluginInstance> instance, 1625 scoped_refptr<webkit::ppapi::PluginInstance> instance,
1499 const std::string& policy) { 1626 const std::string& policy) {
1500 instance->HandlePolicyUpdate(policy); 1627 instance->HandlePolicyUpdate(policy);
1501 } 1628 }
OLDNEW
« no previous file with comments | « content/renderer/pepper_plugin_delegate_impl.h ('k') | content/renderer/render_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698