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 "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 Loading... |
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 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 // saved pipe handle. | 645 // saved pipe handle. |
644 // Temporarily, just call back. | 646 // Temporarily, just call back. |
645 client->BrokerConnected(PlatformFileToInt(plugin_handle), result); | 647 client->BrokerConnected(PlatformFileToInt(plugin_handle), result); |
646 } | 648 } |
647 | 649 |
648 PepperPluginDelegateImpl::PepperPluginDelegateImpl(RenderView* render_view) | 650 PepperPluginDelegateImpl::PepperPluginDelegateImpl(RenderView* render_view) |
649 : render_view_(render_view), | 651 : render_view_(render_view), |
650 has_saved_context_menu_action_(false), | 652 has_saved_context_menu_action_(false), |
651 saved_context_menu_action_(0), | 653 saved_context_menu_action_(0), |
652 id_generator_(0), | 654 id_generator_(0), |
653 is_pepper_plugin_focused_(false) { | 655 is_pepper_plugin_focused_(false), |
| 656 mouse_lock_owner_(NULL), |
| 657 mouse_locked_(false), |
| 658 pending_lock_request_(false), |
| 659 pending_unlock_request_(false) { |
654 } | 660 } |
655 | 661 |
656 PepperPluginDelegateImpl::~PepperPluginDelegateImpl() { | 662 PepperPluginDelegateImpl::~PepperPluginDelegateImpl() { |
| 663 DCHECK(!mouse_lock_owner_); |
657 } | 664 } |
658 | 665 |
659 scoped_refptr<webkit::ppapi::PluginModule> | 666 scoped_refptr<webkit::ppapi::PluginModule> |
660 PepperPluginDelegateImpl::CreatePepperPluginModule( | 667 PepperPluginDelegateImpl::CreatePepperPluginModule( |
661 const webkit::WebPluginInfo& webplugin_info, | 668 const webkit::WebPluginInfo& webplugin_info, |
662 bool* pepper_plugin_was_registered) { | 669 bool* pepper_plugin_was_registered) { |
663 *pepper_plugin_was_registered = true; | 670 *pepper_plugin_was_registered = true; |
664 | 671 |
665 // See if a module has already been loaded for this plugin. | 672 // See if a module has already been loaded for this plugin. |
666 FilePath path(webplugin_info.path); | 673 FilePath path(webplugin_info.path); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 void PepperPluginDelegateImpl::PluginFocusChanged(bool focused) { | 837 void PepperPluginDelegateImpl::PluginFocusChanged(bool focused) { |
831 is_pepper_plugin_focused_ = focused; | 838 is_pepper_plugin_focused_ = focused; |
832 if (render_view_) | 839 if (render_view_) |
833 render_view_->PpapiPluginFocusChanged(); | 840 render_view_->PpapiPluginFocusChanged(); |
834 } | 841 } |
835 | 842 |
836 void PepperPluginDelegateImpl::PluginCrashed( | 843 void PepperPluginDelegateImpl::PluginCrashed( |
837 webkit::ppapi::PluginInstance* instance) { | 844 webkit::ppapi::PluginInstance* instance) { |
838 subscribed_to_policy_updates_.erase(instance); | 845 subscribed_to_policy_updates_.erase(instance); |
839 render_view_->PluginCrashed(instance->module()->path()); | 846 render_view_->PluginCrashed(instance->module()->path()); |
| 847 |
| 848 UnlockMouse(instance); |
840 } | 849 } |
841 | 850 |
842 void PepperPluginDelegateImpl::InstanceCreated( | 851 void PepperPluginDelegateImpl::InstanceCreated( |
843 webkit::ppapi::PluginInstance* instance) { | 852 webkit::ppapi::PluginInstance* instance) { |
844 active_instances_.insert(instance); | 853 active_instances_.insert(instance); |
845 | 854 |
846 // Set the initial focus. | 855 // Set the initial focus. |
847 instance->SetContentAreaFocus(render_view_->has_focus()); | 856 instance->SetContentAreaFocus(render_view_->has_focus()); |
848 } | 857 } |
849 | 858 |
850 void PepperPluginDelegateImpl::InstanceDeleted( | 859 void PepperPluginDelegateImpl::InstanceDeleted( |
851 webkit::ppapi::PluginInstance* instance) { | 860 webkit::ppapi::PluginInstance* instance) { |
852 active_instances_.erase(instance); | 861 active_instances_.erase(instance); |
853 subscribed_to_policy_updates_.erase(instance); | 862 subscribed_to_policy_updates_.erase(instance); |
| 863 |
| 864 if (mouse_lock_owner_ && mouse_lock_owner_ == instance) { |
| 865 // UnlockMouse() will determine whether a ViewHostMsg_UnlockMouse needs to |
| 866 // be sent, and set internal state properly. We only need to forget about |
| 867 // the current |mouse_lock_owner_|. |
| 868 UnlockMouse(mouse_lock_owner_); |
| 869 mouse_lock_owner_ = NULL; |
| 870 } |
854 } | 871 } |
855 | 872 |
856 SkBitmap* PepperPluginDelegateImpl::GetSadPluginBitmap() { | 873 SkBitmap* PepperPluginDelegateImpl::GetSadPluginBitmap() { |
857 return content::GetContentClient()->renderer()->GetSadPluginBitmap(); | 874 return content::GetContentClient()->renderer()->GetSadPluginBitmap(); |
858 } | 875 } |
859 | 876 |
860 webkit::ppapi::PluginDelegate::PlatformImage2D* | 877 webkit::ppapi::PluginDelegate::PlatformImage2D* |
861 PepperPluginDelegateImpl::CreateImage2D(int width, int height) { | 878 PepperPluginDelegateImpl::CreateImage2D(int width, int height) { |
862 uint32 buffer_size = width * height * 4; | 879 uint32 buffer_size = width * height * 4; |
863 | 880 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1004 messages_waiting_replies_.Remove(message_id); | 1021 messages_waiting_replies_.Remove(message_id); |
1005 callback->Run(error_code, base::PassPlatformFile(&file)); | 1022 callback->Run(error_code, base::PassPlatformFile(&file)); |
1006 // Make sure we won't leak file handle if the requester has died. | 1023 // Make sure we won't leak file handle if the requester has died. |
1007 if (file != base::kInvalidPlatformFileValue) | 1024 if (file != base::kInvalidPlatformFileValue) |
1008 base::FileUtilProxy::Close(GetFileThreadMessageLoopProxy(), file, NULL); | 1025 base::FileUtilProxy::Close(GetFileThreadMessageLoopProxy(), file, NULL); |
1009 delete callback; | 1026 delete callback; |
1010 } | 1027 } |
1011 | 1028 |
1012 void PepperPluginDelegateImpl::OnSetFocus(bool has_focus) { | 1029 void PepperPluginDelegateImpl::OnSetFocus(bool has_focus) { |
1013 for (std::set<webkit::ppapi::PluginInstance*>::iterator i = | 1030 for (std::set<webkit::ppapi::PluginInstance*>::iterator i = |
1014 active_instances_.begin(); | 1031 active_instances_.begin(); |
1015 i != active_instances_.end(); ++i) | 1032 i != active_instances_.end(); ++i) |
1016 (*i)->SetContentAreaFocus(has_focus); | 1033 (*i)->SetContentAreaFocus(has_focus); |
1017 } | 1034 } |
1018 | 1035 |
1019 bool PepperPluginDelegateImpl::IsPluginFocused() const { | 1036 bool PepperPluginDelegateImpl::IsPluginFocused() const { |
1020 return is_pepper_plugin_focused_; | 1037 return is_pepper_plugin_focused_; |
1021 } | 1038 } |
1022 | 1039 |
| 1040 void PepperPluginDelegateImpl::OnLockMouseACK(bool succeeded) { |
| 1041 DCHECK(!mouse_locked_ && pending_lock_request_); |
| 1042 |
| 1043 mouse_locked_ = succeeded; |
| 1044 pending_lock_request_ = false; |
| 1045 if (pending_unlock_request_ && !succeeded) { |
| 1046 // We have sent an unlock request after the lock request. However, since |
| 1047 // the lock request has failed, the unlock request will be ignored by the |
| 1048 // browser side and there won't be any response to it. |
| 1049 pending_unlock_request_ = false; |
| 1050 } |
| 1051 // If the PluginInstance has been deleted, |mouse_lock_owner_| can be NULL. |
| 1052 if (mouse_lock_owner_) { |
| 1053 webkit::ppapi::PluginInstance* last_mouse_lock_owner = mouse_lock_owner_; |
| 1054 if (!succeeded) { |
| 1055 // Reset |mouse_lock_owner_| to NULL before calling OnLockMouseACK(), so |
| 1056 // that if OnLockMouseACK() results in calls to any mouse lock method |
| 1057 // (e.g., LockMouse()), the method will see consistent internal state. |
| 1058 mouse_lock_owner_ = NULL; |
| 1059 } |
| 1060 |
| 1061 last_mouse_lock_owner->OnLockMouseACK(succeeded ? PP_OK : PP_ERROR_FAILED); |
| 1062 } |
| 1063 } |
| 1064 |
| 1065 void PepperPluginDelegateImpl::OnMouseLockLost() { |
| 1066 DCHECK(mouse_locked_ && !pending_lock_request_); |
| 1067 |
| 1068 mouse_locked_ = false; |
| 1069 pending_unlock_request_ = false; |
| 1070 // If the PluginInstance has been deleted, |mouse_lock_owner_| can be NULL. |
| 1071 if (mouse_lock_owner_) { |
| 1072 // Reset |mouse_lock_owner_| to NULL before calling OnMouseLockLost(), so |
| 1073 // that if OnMouseLockLost() results in calls to any mouse lock method |
| 1074 // (e.g., LockMouse()), the method will see consistent internal state. |
| 1075 webkit::ppapi::PluginInstance* last_mouse_lock_owner = mouse_lock_owner_; |
| 1076 mouse_lock_owner_ = NULL; |
| 1077 |
| 1078 last_mouse_lock_owner->OnMouseLockLost(); |
| 1079 } |
| 1080 } |
| 1081 |
| 1082 bool PepperPluginDelegateImpl::DispatchLockedMouseEvent( |
| 1083 const WebKit::WebMouseEvent& event) { |
| 1084 if (mouse_locked_) { |
| 1085 if (mouse_lock_owner_) { |
| 1086 // |cursor_info| is ignored since it is hidden when the mouse is locked. |
| 1087 WebKit::WebCursorInfo cursor_info; |
| 1088 mouse_lock_owner_->HandleInputEvent(event, &cursor_info); |
| 1089 } |
| 1090 |
| 1091 // If the mouse is locked, only the current owner of the mouse lock can |
| 1092 // process mouse events. |
| 1093 return true; |
| 1094 } |
| 1095 return false; |
| 1096 } |
| 1097 |
1023 bool PepperPluginDelegateImpl::OpenFileSystem( | 1098 bool PepperPluginDelegateImpl::OpenFileSystem( |
1024 const GURL& url, | 1099 const GURL& url, |
1025 fileapi::FileSystemType type, | 1100 fileapi::FileSystemType type, |
1026 long long size, | 1101 long long size, |
1027 fileapi::FileSystemCallbackDispatcher* dispatcher) { | 1102 fileapi::FileSystemCallbackDispatcher* dispatcher) { |
1028 FileSystemDispatcher* file_system_dispatcher = | 1103 FileSystemDispatcher* file_system_dispatcher = |
1029 ChildThread::current()->file_system_dispatcher(); | 1104 ChildThread::current()->file_system_dispatcher(); |
1030 return file_system_dispatcher->OpenFileSystem( | 1105 return file_system_dispatcher->OpenFileSystem( |
1031 url.GetWithEmptyPath(), type, size, true /* create */, dispatcher); | 1106 url.GetWithEmptyPath(), type, size, true /* create */, dispatcher); |
1032 } | 1107 } |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1467 DLOG(WARNING) << "Browser failed to allocate shared memory"; | 1542 DLOG(WARNING) << "Browser failed to allocate shared memory"; |
1468 return NULL; | 1543 return NULL; |
1469 } | 1544 } |
1470 return new base::SharedMemory(handle, false); | 1545 return new base::SharedMemory(handle, false); |
1471 } | 1546 } |
1472 | 1547 |
1473 ppapi::Preferences PepperPluginDelegateImpl::GetPreferences() { | 1548 ppapi::Preferences PepperPluginDelegateImpl::GetPreferences() { |
1474 return ppapi::Preferences(render_view_->webkit_preferences()); | 1549 return ppapi::Preferences(render_view_->webkit_preferences()); |
1475 } | 1550 } |
1476 | 1551 |
| 1552 void PepperPluginDelegateImpl::LockMouse( |
| 1553 webkit::ppapi::PluginInstance* instance) { |
| 1554 DCHECK(instance); |
| 1555 if (!MouseLockedOrPending()) { |
| 1556 DCHECK(!mouse_lock_owner_); |
| 1557 pending_lock_request_ = true; |
| 1558 mouse_lock_owner_ = instance; |
| 1559 |
| 1560 render_view_->Send( |
| 1561 new ViewHostMsg_LockMouse(render_view_->routing_id())); |
| 1562 } else if (instance != mouse_lock_owner_) { |
| 1563 // Another plugin instance is using mouse lock. Fail immediately. |
| 1564 instance->OnLockMouseACK(PP_ERROR_FAILED); |
| 1565 } else { |
| 1566 if (mouse_locked_) { |
| 1567 instance->OnLockMouseACK(PP_OK); |
| 1568 } else if (pending_lock_request_) { |
| 1569 instance->OnLockMouseACK(PP_ERROR_INPROGRESS); |
| 1570 } else { |
| 1571 // The only case left here is |
| 1572 // !mouse_locked_ && !pending_lock_request_ && pending_unlock_request_, |
| 1573 // which is not possible. |
| 1574 NOTREACHED(); |
| 1575 instance->OnLockMouseACK(PP_ERROR_FAILED); |
| 1576 } |
| 1577 } |
| 1578 } |
| 1579 |
| 1580 void PepperPluginDelegateImpl::UnlockMouse( |
| 1581 webkit::ppapi::PluginInstance* instance) { |
| 1582 DCHECK(instance); |
| 1583 |
| 1584 // If no one is using mouse lock or the user is not |instance|, ignore |
| 1585 // the unlock request. |
| 1586 if (MouseLockedOrPending() && mouse_lock_owner_ == instance) { |
| 1587 if (mouse_locked_ || pending_lock_request_) { |
| 1588 DCHECK(!mouse_locked_ || !pending_lock_request_); |
| 1589 if (!pending_unlock_request_) { |
| 1590 pending_unlock_request_ = true; |
| 1591 |
| 1592 render_view_->Send( |
| 1593 new ViewHostMsg_UnlockMouse(render_view_->routing_id())); |
| 1594 } |
| 1595 } else { |
| 1596 // The only case left here is |
| 1597 // !mouse_locked_ && !pending_lock_request_ && pending_unlock_request_, |
| 1598 // which is not possible. |
| 1599 NOTREACHED(); |
| 1600 } |
| 1601 } |
| 1602 } |
| 1603 |
1477 int PepperPluginDelegateImpl::GetRoutingId() const { | 1604 int PepperPluginDelegateImpl::GetRoutingId() const { |
1478 return render_view_->routing_id(); | 1605 return render_view_->routing_id(); |
1479 } | 1606 } |
1480 | 1607 |
1481 void PepperPluginDelegateImpl::PublishInitialPolicy( | 1608 void PepperPluginDelegateImpl::PublishInitialPolicy( |
1482 scoped_refptr<webkit::ppapi::PluginInstance> instance, | 1609 scoped_refptr<webkit::ppapi::PluginInstance> instance, |
1483 const std::string& policy) { | 1610 const std::string& policy) { |
1484 instance->HandlePolicyUpdate(policy); | 1611 instance->HandlePolicyUpdate(policy); |
1485 } | 1612 } |
OLD | NEW |