| 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 "content/renderer/pepper/pepper_plugin_delegate_impl.h" | 5 #include "content/renderer/pepper/pepper_plugin_delegate_impl.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <cstddef> | 8 #include <cstddef> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <queue> | 10 #include <queue> |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 #include "third_party/WebKit/public/web/WebView.h" | 85 #include "third_party/WebKit/public/web/WebView.h" |
| 86 #include "ui/gfx/size.h" | 86 #include "ui/gfx/size.h" |
| 87 #include "url/gurl.h" | 87 #include "url/gurl.h" |
| 88 | 88 |
| 89 using WebKit::WebFrame; | 89 using WebKit::WebFrame; |
| 90 | 90 |
| 91 namespace content { | 91 namespace content { |
| 92 | 92 |
| 93 namespace { | 93 namespace { |
| 94 | 94 |
| 95 class PluginInstanceLockTarget : public MouseLockDispatcher::LockTarget { | |
| 96 public: | |
| 97 PluginInstanceLockTarget(PepperPluginInstanceImpl* plugin) | |
| 98 : plugin_(plugin) {} | |
| 99 | |
| 100 virtual void OnLockMouseACK(bool succeeded) OVERRIDE { | |
| 101 plugin_->OnLockMouseACK(succeeded); | |
| 102 } | |
| 103 | |
| 104 virtual void OnMouseLockLost() OVERRIDE { | |
| 105 plugin_->OnMouseLockLost(); | |
| 106 } | |
| 107 | |
| 108 virtual bool HandleMouseLockedInputEvent( | |
| 109 const WebKit::WebMouseEvent &event) OVERRIDE { | |
| 110 plugin_->HandleMouseLockedInputEvent(event); | |
| 111 return true; | |
| 112 } | |
| 113 | |
| 114 private: | |
| 115 PepperPluginInstanceImpl* plugin_; | |
| 116 }; | |
| 117 | |
| 118 void CreateHostForInProcessModule(RenderViewImpl* render_view, | 95 void CreateHostForInProcessModule(RenderViewImpl* render_view, |
| 119 PluginModule* module, | 96 PluginModule* module, |
| 120 const WebPluginInfo& webplugin_info) { | 97 const WebPluginInfo& webplugin_info) { |
| 121 // First time an in-process plugin was used, make a host for it. | 98 // First time an in-process plugin was used, make a host for it. |
| 122 const PepperPluginInfo* info = | 99 const PepperPluginInfo* info = |
| 123 PepperPluginRegistry::GetInstance()->GetInfoForPlugin(webplugin_info); | 100 PepperPluginRegistry::GetInstance()->GetInfoForPlugin(webplugin_info); |
| 124 DCHECK(!info->is_out_of_process); | 101 DCHECK(!info->is_out_of_process); |
| 125 | 102 |
| 126 ppapi::PpapiPermissions perms( | 103 ppapi::PpapiPermissions perms( |
| 127 PepperPluginRegistry::GetInstance()->GetInfoForPlugin( | 104 PepperPluginRegistry::GetInstance()->GetInfoForPlugin( |
| 128 webplugin_info)->permissions); | 105 webplugin_info)->permissions); |
| 129 RendererPpapiHostImpl* host_impl = | 106 RendererPpapiHostImpl* host_impl = |
| 130 RendererPpapiHostImpl::CreateOnModuleForInProcess( | 107 RendererPpapiHostImpl::CreateOnModuleForInProcess( |
| 131 module, perms); | 108 module, perms); |
| 132 render_view->PpapiPluginCreated(host_impl); | 109 render_view->PpapiPluginCreated(host_impl); |
| 133 } | 110 } |
| 134 | 111 |
| 135 } // namespace | 112 } // namespace |
| 136 | 113 |
| 137 PepperPluginDelegateImpl::PepperPluginDelegateImpl(RenderViewImpl* render_view) | 114 PepperPluginDelegateImpl::PepperPluginDelegateImpl(RenderViewImpl* render_view) |
| 138 : RenderViewObserver(render_view), | 115 : RenderViewObserver(render_view), |
| 139 render_view_(render_view), | 116 render_view_(render_view), |
| 140 pepper_browser_connection_(this), | 117 pepper_browser_connection_(this), |
| 141 focused_plugin_(NULL), | 118 focused_plugin_(NULL), |
| 142 last_mouse_event_target_(NULL) { | 119 last_mouse_event_target_(NULL) { |
| 143 } | 120 } |
| 144 | 121 |
| 145 PepperPluginDelegateImpl::~PepperPluginDelegateImpl() { | 122 PepperPluginDelegateImpl::~PepperPluginDelegateImpl() { |
| 146 DCHECK(mouse_lock_instances_.empty()); | |
| 147 } | 123 } |
| 148 | 124 |
| 149 WebKit::WebPlugin* PepperPluginDelegateImpl::CreatePepperWebPlugin( | 125 WebKit::WebPlugin* PepperPluginDelegateImpl::CreatePepperWebPlugin( |
| 150 const WebPluginInfo& webplugin_info, | 126 const WebPluginInfo& webplugin_info, |
| 151 const WebKit::WebPluginParams& params) { | 127 const WebKit::WebPluginParams& params) { |
| 152 bool pepper_plugin_was_registered = false; | 128 bool pepper_plugin_was_registered = false; |
| 153 scoped_refptr<PluginModule> pepper_module( | 129 scoped_refptr<PluginModule> pepper_module( |
| 154 CreatePepperPluginModule(webplugin_info, &pepper_plugin_was_registered)); | 130 CreatePepperPluginModule(webplugin_info, &pepper_plugin_was_registered)); |
| 155 | 131 |
| 156 if (pepper_plugin_was_registered) { | 132 if (pepper_plugin_was_registered) { |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 bool PepperPluginDelegateImpl::IsPluginAcceptingCompositionEvents() const { | 478 bool PepperPluginDelegateImpl::IsPluginAcceptingCompositionEvents() const { |
| 503 if (!focused_plugin_) | 479 if (!focused_plugin_) |
| 504 return false; | 480 return false; |
| 505 return focused_plugin_->IsPluginAcceptingCompositionEvents(); | 481 return focused_plugin_->IsPluginAcceptingCompositionEvents(); |
| 506 } | 482 } |
| 507 | 483 |
| 508 bool PepperPluginDelegateImpl::CanComposeInline() const { | 484 bool PepperPluginDelegateImpl::CanComposeInline() const { |
| 509 return IsPluginAcceptingCompositionEvents(); | 485 return IsPluginAcceptingCompositionEvents(); |
| 510 } | 486 } |
| 511 | 487 |
| 512 void PepperPluginDelegateImpl::PluginCrashed( | |
| 513 PepperPluginInstanceImpl* instance) { | |
| 514 render_view_->PluginCrashed(instance->module()->path(), | |
| 515 instance->module()->GetPeerProcessId()); | |
| 516 UnSetAndDeleteLockTargetAdapter(instance); | |
| 517 } | |
| 518 | |
| 519 void PepperPluginDelegateImpl::InstanceCreated( | 488 void PepperPluginDelegateImpl::InstanceCreated( |
| 520 PepperPluginInstanceImpl* instance) { | 489 PepperPluginInstanceImpl* instance) { |
| 521 active_instances_.insert(instance); | 490 active_instances_.insert(instance); |
| 522 | 491 |
| 523 // Set the initial focus. | 492 // Set the initial focus. |
| 524 instance->SetContentAreaFocus(render_view_->has_focus()); | 493 instance->SetContentAreaFocus(render_view_->has_focus()); |
| 525 } | 494 } |
| 526 | 495 |
| 527 void PepperPluginDelegateImpl::InstanceDeleted( | 496 void PepperPluginDelegateImpl::InstanceDeleted( |
| 528 PepperPluginInstanceImpl* instance) { | 497 PepperPluginInstanceImpl* instance) { |
| 529 active_instances_.erase(instance); | 498 active_instances_.erase(instance); |
| 530 UnSetAndDeleteLockTargetAdapter(instance); | |
| 531 | 499 |
| 532 if (last_mouse_event_target_ == instance) | 500 if (last_mouse_event_target_ == instance) |
| 533 last_mouse_event_target_ = NULL; | 501 last_mouse_event_target_ = NULL; |
| 534 if (focused_plugin_ == instance) | 502 if (focused_plugin_ == instance) |
| 535 PluginFocusChanged(instance, false); | 503 PluginFocusChanged(instance, false); |
| 536 } | 504 } |
| 537 | 505 |
| 538 // If a broker has not already been created for this plugin, creates one. | 506 // If a broker has not already been created for this plugin, creates one. |
| 539 PepperBroker* PepperPluginDelegateImpl::ConnectToBroker( | 507 PepperBroker* PepperPluginDelegateImpl::ConnectToBroker( |
| 540 PPB_Broker_Impl* client) { | 508 PPB_Broker_Impl* client) { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 // event, it will notify us via DidReceiveMouseEvent() and set itself as | 608 // event, it will notify us via DidReceiveMouseEvent() and set itself as |
| 641 // |last_mouse_event_target_|. | 609 // |last_mouse_event_target_|. |
| 642 last_mouse_event_target_ = NULL; | 610 last_mouse_event_target_ = NULL; |
| 643 } | 611 } |
| 644 | 612 |
| 645 scoped_refptr<base::MessageLoopProxy> | 613 scoped_refptr<base::MessageLoopProxy> |
| 646 PepperPluginDelegateImpl::GetFileThreadMessageLoopProxy() { | 614 PepperPluginDelegateImpl::GetFileThreadMessageLoopProxy() { |
| 647 return RenderThreadImpl::current()->GetFileThreadMessageLoopProxy(); | 615 return RenderThreadImpl::current()->GetFileThreadMessageLoopProxy(); |
| 648 } | 616 } |
| 649 | 617 |
| 650 uint32 PepperPluginDelegateImpl::TCPSocketCreate() { | |
| 651 // This was used for PPB_TCPSocket_Private creation. And it shouldn't be | |
| 652 // needed anymore. | |
| 653 // TODO(yzshen): Remove TCP socket-related contents from the plugin delegate. | |
| 654 uint32 socket_id = 0; | |
| 655 Send(new PpapiHostMsg_PPBTCPSocket_CreatePrivate( | |
| 656 routing_id(), 0, &socket_id)); | |
| 657 return socket_id; | |
| 658 } | |
| 659 | |
| 660 void PepperPluginDelegateImpl::TCPSocketConnect( | |
| 661 PPB_TCPSocket_Private_Impl* socket, | |
| 662 uint32 socket_id, | |
| 663 const std::string& host, | |
| 664 uint16_t port) { | |
| 665 RegisterTCPSocket(socket, socket_id); | |
| 666 Send(new PpapiHostMsg_PPBTCPSocket_Connect( | |
| 667 routing_id(), socket_id, host, port)); | |
| 668 } | |
| 669 | |
| 670 void PepperPluginDelegateImpl::TCPSocketConnectWithNetAddress( | |
| 671 PPB_TCPSocket_Private_Impl* socket, | |
| 672 uint32 socket_id, | |
| 673 const PP_NetAddress_Private& addr) { | |
| 674 RegisterTCPSocket(socket, socket_id); | |
| 675 Send(new PpapiHostMsg_PPBTCPSocket_ConnectWithNetAddress( | |
| 676 routing_id(), socket_id, addr)); | |
| 677 } | |
| 678 | |
| 679 void PepperPluginDelegateImpl::TCPSocketSSLHandshake( | |
| 680 uint32 socket_id, | |
| 681 const std::string& server_name, | |
| 682 uint16_t server_port, | |
| 683 const std::vector<std::vector<char> >& trusted_certs, | |
| 684 const std::vector<std::vector<char> >& untrusted_certs) { | |
| 685 DCHECK(tcp_sockets_.Lookup(socket_id)); | |
| 686 Send(new PpapiHostMsg_PPBTCPSocket_SSLHandshake( | |
| 687 socket_id, server_name, server_port, trusted_certs, untrusted_certs)); | |
| 688 } | |
| 689 | |
| 690 void PepperPluginDelegateImpl::TCPSocketRead(uint32 socket_id, | |
| 691 int32_t bytes_to_read) { | |
| 692 DCHECK(tcp_sockets_.Lookup(socket_id)); | |
| 693 Send(new PpapiHostMsg_PPBTCPSocket_Read(socket_id, bytes_to_read)); | |
| 694 } | |
| 695 | |
| 696 void PepperPluginDelegateImpl::TCPSocketWrite(uint32 socket_id, | |
| 697 const std::string& buffer) { | |
| 698 DCHECK(tcp_sockets_.Lookup(socket_id)); | |
| 699 Send(new PpapiHostMsg_PPBTCPSocket_Write(socket_id, buffer)); | |
| 700 } | |
| 701 | |
| 702 void PepperPluginDelegateImpl::TCPSocketDisconnect(uint32 socket_id) { | |
| 703 // There is no DCHECK(tcp_sockets_.Lookup(socket_id)) because this method | |
| 704 // can be called before TCPSocketConnect or TCPSocketConnectWithNetAddress. | |
| 705 Send(new PpapiHostMsg_PPBTCPSocket_Disconnect(socket_id)); | |
| 706 if (tcp_sockets_.Lookup(socket_id)) | |
| 707 tcp_sockets_.Remove(socket_id); | |
| 708 } | |
| 709 | |
| 710 void PepperPluginDelegateImpl::TCPSocketSetOption( | |
| 711 uint32 socket_id, | |
| 712 PP_TCPSocket_Option name, | |
| 713 const ppapi::SocketOptionData& value) { | |
| 714 DCHECK(tcp_sockets_.Lookup(socket_id)); | |
| 715 Send(new PpapiHostMsg_PPBTCPSocket_SetOption(socket_id, name, value)); | |
| 716 } | |
| 717 | |
| 718 void PepperPluginDelegateImpl::RegisterTCPSocket( | 618 void PepperPluginDelegateImpl::RegisterTCPSocket( |
| 719 PPB_TCPSocket_Private_Impl* socket, | 619 PPB_TCPSocket_Private_Impl* socket, |
| 720 uint32 socket_id) { | 620 uint32 socket_id) { |
| 721 tcp_sockets_.AddWithID(socket, socket_id); | 621 tcp_sockets_.AddWithID(socket, socket_id); |
| 722 } | 622 } |
| 723 | 623 |
| 724 void PepperPluginDelegateImpl::TCPServerSocketListen( | 624 void PepperPluginDelegateImpl::UnregisterTCPSocket(uint32 socket_id) { |
| 725 PP_Resource socket_resource, | 625 // There is no DCHECK(tcp_sockets_.Lookup(socket_id)) because this method |
| 726 const PP_NetAddress_Private& addr, | 626 // can be called before TCPSocketConnect or TCPSocketConnectWithNetAddress. |
| 727 int32_t backlog) { | 627 if (tcp_sockets_.Lookup(socket_id)) |
| 728 Send(new PpapiHostMsg_PPBTCPServerSocket_Listen( | 628 tcp_sockets_.Remove(socket_id); |
| 729 routing_id(), 0, socket_resource, addr, backlog)); | |
| 730 } | 629 } |
| 731 | 630 |
| 732 void PepperPluginDelegateImpl::TCPServerSocketAccept(uint32 server_socket_id) { | 631 void PepperPluginDelegateImpl::TCPServerSocketStopListening(uint32 socket_id) { |
| 733 DCHECK(tcp_server_sockets_.Lookup(server_socket_id)); | 632 tcp_server_sockets_.Remove(socket_id); |
| 734 Send(new PpapiHostMsg_PPBTCPServerSocket_Accept( | |
| 735 routing_id(), server_socket_id)); | |
| 736 } | |
| 737 | |
| 738 void PepperPluginDelegateImpl::TCPServerSocketStopListening( | |
| 739 PP_Resource socket_resource, | |
| 740 uint32 socket_id) { | |
| 741 if (socket_id != 0) { | |
| 742 Send(new PpapiHostMsg_PPBTCPServerSocket_Destroy(socket_id)); | |
| 743 tcp_server_sockets_.Remove(socket_id); | |
| 744 } | |
| 745 } | 633 } |
| 746 | 634 |
| 747 void PepperPluginDelegateImpl::HandleDocumentLoad( | 635 void PepperPluginDelegateImpl::HandleDocumentLoad( |
| 748 PepperPluginInstanceImpl* instance, | 636 PepperPluginInstanceImpl* instance, |
| 749 const WebKit::WebURLResponse& response) { | 637 const WebKit::WebURLResponse& response) { |
| 750 DCHECK(!instance->document_loader()); | 638 DCHECK(!instance->document_loader()); |
| 751 | 639 |
| 752 PP_Instance pp_instance = instance->pp_instance(); | 640 PP_Instance pp_instance = instance->pp_instance(); |
| 753 RendererPpapiHostImpl* host_impl = instance->module()->renderer_ppapi_host(); | 641 RendererPpapiHostImpl* host_impl = instance->module()->renderer_ppapi_host(); |
| 754 | 642 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 812 // managed externally. | 700 // managed externally. |
| 813 return CreateOutOfProcessModule(module.get(), | 701 return CreateOutOfProcessModule(module.get(), |
| 814 path, | 702 path, |
| 815 permissions, | 703 permissions, |
| 816 channel_handle, | 704 channel_handle, |
| 817 peer_pid, | 705 peer_pid, |
| 818 plugin_child_id, | 706 plugin_child_id, |
| 819 true); // is_external = true | 707 true); // is_external = true |
| 820 } | 708 } |
| 821 | 709 |
| 822 bool PepperPluginDelegateImpl::LockMouse(PepperPluginInstanceImpl* instance) { | |
| 823 return GetMouseLockDispatcher(instance)->LockMouse( | |
| 824 GetOrCreateLockTargetAdapter(instance)); | |
| 825 } | |
| 826 | |
| 827 void PepperPluginDelegateImpl::UnlockMouse(PepperPluginInstanceImpl* instance) { | |
| 828 GetMouseLockDispatcher(instance)->UnlockMouse( | |
| 829 GetOrCreateLockTargetAdapter(instance)); | |
| 830 } | |
| 831 | |
| 832 bool PepperPluginDelegateImpl::IsMouseLocked( | |
| 833 PepperPluginInstanceImpl* instance) { | |
| 834 return GetMouseLockDispatcher(instance)->IsMouseLockedTo( | |
| 835 GetOrCreateLockTargetAdapter(instance)); | |
| 836 } | |
| 837 | |
| 838 void PepperPluginDelegateImpl::DidChangeCursor( | 710 void PepperPluginDelegateImpl::DidChangeCursor( |
| 839 PepperPluginInstanceImpl* instance, | 711 PepperPluginInstanceImpl* instance, |
| 840 const WebKit::WebCursorInfo& cursor) { | 712 const WebKit::WebCursorInfo& cursor) { |
| 841 // Update the cursor appearance immediately if the requesting plugin is the | 713 // Update the cursor appearance immediately if the requesting plugin is the |
| 842 // one which receives the last mouse event. Otherwise, the new cursor won't be | 714 // one which receives the last mouse event. Otherwise, the new cursor won't be |
| 843 // picked up until the plugin gets the next input event. That is bad if, e.g., | 715 // picked up until the plugin gets the next input event. That is bad if, e.g., |
| 844 // the plugin would like to set an invisible cursor when there isn't any user | 716 // the plugin would like to set an invisible cursor when there isn't any user |
| 845 // input for a while. | 717 // input for a while. |
| 846 if (instance == last_mouse_event_target_) | 718 if (instance == last_mouse_event_target_) |
| 847 render_view_->didChangeCursor(cursor); | 719 render_view_->didChangeCursor(cursor); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 973 bool succeeded = (accepted_socket_id != 0); | 845 bool succeeded = (accepted_socket_id != 0); |
| 974 socket->OnAcceptCompleted(succeeded, | 846 socket->OnAcceptCompleted(succeeded, |
| 975 accepted_socket_id, | 847 accepted_socket_id, |
| 976 local_addr, | 848 local_addr, |
| 977 remote_addr); | 849 remote_addr); |
| 978 } else if (accepted_socket_id != 0) { | 850 } else if (accepted_socket_id != 0) { |
| 979 Send(new PpapiHostMsg_PPBTCPSocket_Disconnect(accepted_socket_id)); | 851 Send(new PpapiHostMsg_PPBTCPSocket_Disconnect(accepted_socket_id)); |
| 980 } | 852 } |
| 981 } | 853 } |
| 982 | 854 |
| 983 int PepperPluginDelegateImpl::GetRoutingID() const { | |
| 984 return routing_id(); | |
| 985 } | |
| 986 | |
| 987 MouseLockDispatcher::LockTarget* | |
| 988 PepperPluginDelegateImpl::GetOrCreateLockTargetAdapter( | |
| 989 PepperPluginInstanceImpl* instance) { | |
| 990 MouseLockDispatcher::LockTarget* target = mouse_lock_instances_[instance]; | |
| 991 if (target) | |
| 992 return target; | |
| 993 | |
| 994 return mouse_lock_instances_[instance] = | |
| 995 new PluginInstanceLockTarget(instance); | |
| 996 } | |
| 997 | |
| 998 void PepperPluginDelegateImpl::UnSetAndDeleteLockTargetAdapter( | |
| 999 PepperPluginInstanceImpl* instance) { | |
| 1000 LockTargetMap::iterator it = mouse_lock_instances_.find(instance); | |
| 1001 if (it != mouse_lock_instances_.end()) { | |
| 1002 MouseLockDispatcher::LockTarget* target = it->second; | |
| 1003 GetMouseLockDispatcher(instance)->OnLockTargetDestroyed(target); | |
| 1004 delete target; | |
| 1005 mouse_lock_instances_.erase(it); | |
| 1006 } | |
| 1007 } | |
| 1008 | |
| 1009 MouseLockDispatcher* PepperPluginDelegateImpl::GetMouseLockDispatcher( | |
| 1010 PepperPluginInstanceImpl* instance) { | |
| 1011 if (instance->flash_fullscreen()) { | |
| 1012 RenderWidgetFullscreenPepper* container = | |
| 1013 static_cast<RenderWidgetFullscreenPepper*>( | |
| 1014 instance->fullscreen_container()); | |
| 1015 return container->mouse_lock_dispatcher(); | |
| 1016 } else { | |
| 1017 return render_view_->mouse_lock_dispatcher(); | |
| 1018 } | |
| 1019 } | |
| 1020 | |
| 1021 } // namespace content | 855 } // namespace content |
| OLD | NEW |