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_plugin_delegate_impl.h" | 5 #include "content/renderer/pepper_plugin_delegate_impl.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <map> | |
8 #include <queue> | 9 #include <queue> |
9 | 10 |
10 #include "base/bind.h" | 11 #include "base/bind.h" |
11 #include "base/callback.h" | 12 #include "base/callback.h" |
12 #include "base/command_line.h" | 13 #include "base/command_line.h" |
13 #include "base/file_path.h" | 14 #include "base/file_path.h" |
14 #include "base/file_util_proxy.h" | 15 #include "base/file_util_proxy.h" |
15 #include "base/logging.h" | 16 #include "base/logging.h" |
16 #include "base/memory/scoped_ptr.h" | |
17 #include "base/memory/weak_ptr.h" | |
18 #include "base/string_split.h" | 17 #include "base/string_split.h" |
19 #include "base/sync_socket.h" | 18 #include "base/sync_socket.h" |
20 #include "base/time.h" | 19 #include "base/time.h" |
21 #include "content/common/child_process.h" | 20 #include "content/common/child_process.h" |
22 #include "content/common/child_process_messages.h" | 21 #include "content/common/child_process_messages.h" |
23 #include "content/common/child_thread.h" | 22 #include "content/common/child_thread.h" |
24 #include "content/common/file_system/file_system_dispatcher.h" | 23 #include "content/common/file_system/file_system_dispatcher.h" |
25 #include "content/common/file_system_messages.h" | 24 #include "content/common/file_system_messages.h" |
26 #include "content/common/media/audio_messages.h" | 25 #include "content/common/media/audio_messages.h" |
27 #include "content/common/pepper_file_messages.h" | 26 #include "content/common/pepper_file_messages.h" |
28 #include "content/common/pepper_plugin_registry.h" | 27 #include "content/common/pepper_plugin_registry.h" |
29 #include "content/common/pepper_messages.h" | 28 #include "content/common/pepper_messages.h" |
30 #include "content/common/quota_dispatcher.h" | 29 #include "content/common/quota_dispatcher.h" |
31 #include "content/common/view_messages.h" | 30 #include "content/common/view_messages.h" |
32 #include "content/public/common/content_switches.h" | 31 #include "content/public/common/content_switches.h" |
33 #include "content/public/renderer/content_renderer_client.h" | 32 #include "content/public/renderer/content_renderer_client.h" |
34 #include "content/renderer/gamepad_shared_memory_reader.h" | 33 #include "content/renderer/gamepad_shared_memory_reader.h" |
35 #include "content/renderer/gpu/command_buffer_proxy.h" | 34 #include "content/renderer/gpu/command_buffer_proxy.h" |
36 #include "content/renderer/gpu/gpu_channel_host.h" | 35 #include "content/renderer/gpu/gpu_channel_host.h" |
37 #include "content/renderer/gpu/renderer_gl_context.h" | 36 #include "content/renderer/gpu/renderer_gl_context.h" |
38 #include "content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h" | 37 #include "content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h" |
39 #include "content/renderer/media/audio_input_message_filter.h" | 38 #include "content/renderer/media/audio_input_message_filter.h" |
40 #include "content/renderer/media/audio_message_filter.h" | 39 #include "content/renderer/media/audio_message_filter.h" |
40 #include "content/renderer/media/media_stream_dispatcher.h" | |
41 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" | |
41 #include "content/renderer/media/video_capture_impl_manager.h" | 42 #include "content/renderer/media/video_capture_impl_manager.h" |
42 #include "content/renderer/p2p/p2p_transport_impl.h" | 43 #include "content/renderer/p2p/p2p_transport_impl.h" |
43 #include "content/renderer/pepper_platform_context_3d_impl.h" | 44 #include "content/renderer/pepper_platform_context_3d_impl.h" |
44 #include "content/renderer/pepper_platform_video_decoder_impl.h" | 45 #include "content/renderer/pepper_platform_video_decoder_impl.h" |
45 #include "content/renderer/render_thread_impl.h" | 46 #include "content/renderer/render_thread_impl.h" |
46 #include "content/renderer/render_view_impl.h" | 47 #include "content/renderer/render_view_impl.h" |
47 #include "content/renderer/render_widget_fullscreen_pepper.h" | 48 #include "content/renderer/render_widget_fullscreen_pepper.h" |
48 #include "content/renderer/webplugin_delegate_proxy.h" | 49 #include "content/renderer/webplugin_delegate_proxy.h" |
49 #include "ipc/ipc_channel_handle.h" | 50 #include "ipc/ipc_channel_handle.h" |
50 #include "media/audio/audio_manager_base.h" | 51 #include "media/audio/audio_manager_base.h" |
51 #include "media/video/capture/video_capture_proxy.h" | 52 #include "media/video/capture/video_capture_proxy.h" |
52 #include "ppapi/c/dev/pp_video_dev.h" | 53 #include "ppapi/c/dev/pp_video_dev.h" |
53 #include "ppapi/c/pp_errors.h" | 54 #include "ppapi/c/pp_errors.h" |
54 #include "ppapi/c/private/ppb_flash.h" | 55 #include "ppapi/c/private/ppb_flash.h" |
55 #include "ppapi/c/private/ppb_flash_net_connector.h" | 56 #include "ppapi/c/private/ppb_flash_net_connector.h" |
56 #include "ppapi/proxy/host_dispatcher.h" | 57 #include "ppapi/proxy/host_dispatcher.h" |
57 #include "ppapi/proxy/ppapi_messages.h" | 58 #include "ppapi/proxy/ppapi_messages.h" |
59 #include "ppapi/shared_impl/ppb_device_ref_shared.h" | |
58 #include "ppapi/shared_impl/platform_file.h" | 60 #include "ppapi/shared_impl/platform_file.h" |
59 #include "ppapi/shared_impl/ppapi_preferences.h" | 61 #include "ppapi/shared_impl/ppapi_preferences.h" |
60 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | 62 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
61 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 63 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
62 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserComplet ion.h" | 64 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserComplet ion.h" |
63 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams. h" | 65 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams. h" |
64 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 66 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
65 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 67 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
66 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 68 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
67 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" | 69 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
580 NOTREACHED(); | 582 NOTREACHED(); |
581 } | 583 } |
582 virtual void DidFail(quota::QuotaStatusCode error) OVERRIDE { | 584 virtual void DidFail(quota::QuotaStatusCode error) OVERRIDE { |
583 callback_.Run(0); | 585 callback_.Run(0); |
584 } | 586 } |
585 private: | 587 private: |
586 PluginCallback callback_; | 588 PluginCallback callback_; |
587 }; | 589 }; |
588 | 590 |
589 class PlatformVideoCaptureImpl | 591 class PlatformVideoCaptureImpl |
590 : public webkit::ppapi::PluginDelegate::PlatformVideoCapture { | 592 : public webkit::ppapi::PluginDelegate::PlatformVideoCapture, |
593 public media::VideoCapture::EventHandler { | |
591 public: | 594 public: |
592 PlatformVideoCaptureImpl(media::VideoCapture::EventHandler* handler) | 595 PlatformVideoCaptureImpl( |
593 : handler_proxy_(new media::VideoCaptureHandlerProxy( | 596 const base::WeakPtr<PepperPluginDelegateImpl>& plugin_delegate, |
594 handler, base::MessageLoopProxy::current())) { | 597 const std::string& device_id, |
598 webkit::ppapi::PluginDelegate::PlatformVideoCaptureEventHandler* handler); | |
599 virtual ~PlatformVideoCaptureImpl(); | |
600 | |
601 // webkit::ppapi::PluginDelegate::PlatformVideoCapture implementation. | |
602 virtual void StartCapture(EventHandler* handler, | |
603 const VideoCaptureCapability& capability) OVERRIDE; | |
604 virtual void StopCapture(EventHandler* handler) OVERRIDE; | |
605 virtual void FeedBuffer(scoped_refptr<VideoFrameBuffer> buffer) OVERRIDE; | |
606 virtual bool CaptureStarted() OVERRIDE; | |
607 virtual int CaptureWidth() OVERRIDE; | |
608 virtual int CaptureHeight() OVERRIDE; | |
609 virtual int CaptureFrameRate() OVERRIDE; | |
610 virtual void DetachEventHandler() OVERRIDE; | |
611 | |
612 // media::VideoCapture::EventHandler implementation | |
613 virtual void OnStarted(VideoCapture* capture) OVERRIDE; | |
614 virtual void OnStopped(VideoCapture* capture) OVERRIDE; | |
615 virtual void OnPaused(VideoCapture* capture) OVERRIDE; | |
616 virtual void OnError(VideoCapture* capture, int error_code) OVERRIDE; | |
617 virtual void OnRemoved(VideoCapture* capture) OVERRIDE; | |
618 virtual void OnBufferReady(VideoCapture* capture, | |
619 scoped_refptr<VideoFrameBuffer> buffer) OVERRIDE; | |
620 virtual void OnDeviceInfoReceived( | |
621 VideoCapture* capture, | |
622 const media::VideoCaptureParams& device_info) OVERRIDE; | |
623 | |
624 private: | |
625 void Initialize(); | |
626 | |
627 void OnDeviceOpened(int request_id, | |
628 bool succeeded, | |
629 const std::string& label); | |
630 | |
631 base::WeakPtr<PepperPluginDelegateImpl> plugin_delegate_; | |
632 | |
633 std::string device_id_; | |
634 std::string label_; | |
635 int session_id_; | |
636 | |
637 scoped_ptr<media::VideoCaptureHandlerProxy> handler_proxy_; | |
638 | |
639 webkit::ppapi::PluginDelegate::PlatformVideoCaptureEventHandler* handler_; | |
640 | |
641 media::VideoCapture* video_capture_; | |
642 | |
643 // StartCapture() must be balanced by StopCapture(), otherwise this object | |
644 // will leak. | |
645 bool unbalanced_start_; | |
646 | |
647 base::WeakPtrFactory<PlatformVideoCaptureImpl> weak_ptr_factory_; | |
piman
2012/01/28 08:26:55
Do we actually need this? This class is already re
yzshen1
2012/01/29 21:58:32
Done. Thanks for pointing this out.
On 2012/01/28
| |
648 }; | |
649 | |
650 PlatformVideoCaptureImpl::PlatformVideoCaptureImpl( | |
651 const base::WeakPtr<PepperPluginDelegateImpl>& plugin_delegate, | |
652 const std::string& device_id, | |
653 webkit::ppapi::PluginDelegate::PlatformVideoCaptureEventHandler* handler) | |
654 : plugin_delegate_(plugin_delegate), | |
655 device_id_(device_id), | |
656 session_id_(0), | |
657 ALLOW_THIS_IN_INITIALIZER_LIST( | |
658 handler_proxy_(new media::VideoCaptureHandlerProxy( | |
659 this, base::MessageLoopProxy::current()))), | |
660 handler_(handler), | |
661 video_capture_(NULL), | |
662 unbalanced_start_(false), | |
663 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | |
664 if (device_id.empty()) { | |
665 // "1" is the session ID for the default device. | |
666 session_id_ = 1; | |
667 Initialize(); | |
668 } else { | |
669 // We need to open the device and obtain the label and session ID before | |
670 // initializing. | |
671 if (plugin_delegate_) { | |
672 plugin_delegate_->OpenDevice( | |
673 PP_DEVICETYPE_DEV_VIDEOCAPTURE, device_id, | |
674 base::Bind(&PlatformVideoCaptureImpl::OnDeviceOpened, | |
675 weak_ptr_factory_.GetWeakPtr())); | |
676 } | |
677 } | |
678 } | |
679 | |
680 PlatformVideoCaptureImpl::~PlatformVideoCaptureImpl() { | |
681 if (video_capture_) { | |
595 VideoCaptureImplManager* manager = | 682 VideoCaptureImplManager* manager = |
596 RenderThreadImpl::current()->video_capture_impl_manager(); | 683 RenderThreadImpl::current()->video_capture_impl_manager(); |
597 // 1 means the "default" video capture device. | 684 manager->RemoveDevice(session_id_, handler_proxy_.get()); |
598 // TODO(piman): Add a way to enumerate devices and pass them through the | 685 } |
599 // API. | 686 |
600 video_capture_ = manager->AddDevice(1, handler_proxy_.get()); | 687 if (plugin_delegate_ && !label_.empty()) |
601 } | 688 plugin_delegate_->CloseDevice(label_); |
602 | 689 } |
603 // Overrides from media::VideoCapture::EventHandler | 690 |
604 virtual ~PlatformVideoCaptureImpl() { | 691 void PlatformVideoCaptureImpl::StartCapture( |
605 VideoCaptureImplManager* manager = | 692 EventHandler* handler, |
606 RenderThreadImpl::current()->video_capture_impl_manager(); | 693 const VideoCaptureCapability& capability) { |
607 manager->RemoveDevice(1, handler_proxy_.get()); | 694 DCHECK(handler == handler_); |
608 } | 695 |
609 | 696 if (unbalanced_start_) |
610 virtual void StartCapture( | 697 return; |
611 EventHandler* handler, | 698 |
612 const VideoCaptureCapability& capability) OVERRIDE { | 699 if (video_capture_) { |
613 DCHECK(handler == handler_proxy_->proxied()); | 700 unbalanced_start_ = true; |
701 AddRef(); // Will be balanced in OnRemoved(). | |
614 video_capture_->StartCapture(handler_proxy_.get(), capability); | 702 video_capture_->StartCapture(handler_proxy_.get(), capability); |
615 } | 703 } |
616 | 704 } |
617 virtual void StopCapture(EventHandler* handler) OVERRIDE { | 705 |
618 DCHECK(handler == handler_proxy_->proxied()); | 706 void PlatformVideoCaptureImpl::StopCapture(EventHandler* handler) { |
707 DCHECK(handler == handler_); | |
708 if (!unbalanced_start_) | |
709 return; | |
710 | |
711 if (video_capture_) { | |
712 unbalanced_start_ = false; | |
619 video_capture_->StopCapture(handler_proxy_.get()); | 713 video_capture_->StopCapture(handler_proxy_.get()); |
620 } | 714 } |
621 | 715 } |
622 virtual void FeedBuffer(scoped_refptr<VideoFrameBuffer> buffer) OVERRIDE { | 716 |
717 void PlatformVideoCaptureImpl::FeedBuffer( | |
718 scoped_refptr<VideoFrameBuffer> buffer) { | |
719 if (video_capture_) | |
623 video_capture_->FeedBuffer(buffer); | 720 video_capture_->FeedBuffer(buffer); |
624 } | 721 } |
625 | 722 |
626 virtual bool CaptureStarted() OVERRIDE { | 723 bool PlatformVideoCaptureImpl::CaptureStarted() { |
627 return handler_proxy_->state().started; | 724 return handler_proxy_->state().started; |
628 } | 725 } |
629 | 726 |
630 virtual int CaptureWidth() OVERRIDE { | 727 int PlatformVideoCaptureImpl::CaptureWidth() { |
631 return handler_proxy_->state().width; | 728 return handler_proxy_->state().width; |
632 } | 729 } |
633 | 730 |
634 virtual int CaptureHeight() OVERRIDE { | 731 int PlatformVideoCaptureImpl::CaptureHeight() { |
635 return handler_proxy_->state().height; | 732 return handler_proxy_->state().height; |
636 } | 733 } |
637 | 734 |
638 virtual int CaptureFrameRate() OVERRIDE { | 735 int PlatformVideoCaptureImpl::CaptureFrameRate() { |
639 return handler_proxy_->state().frame_rate; | 736 return handler_proxy_->state().frame_rate; |
640 } | 737 } |
641 | 738 |
642 private: | 739 void PlatformVideoCaptureImpl::DetachEventHandler() { |
643 scoped_ptr<media::VideoCaptureHandlerProxy> handler_proxy_; | 740 handler_ = NULL; |
644 media::VideoCapture* video_capture_; | 741 StopCapture(NULL); |
645 }; | 742 } |
743 | |
744 void PlatformVideoCaptureImpl::OnStarted(VideoCapture* capture) { | |
745 if (handler_) | |
746 handler_->OnStarted(capture); | |
747 } | |
748 | |
749 void PlatformVideoCaptureImpl::OnStopped(VideoCapture* capture) { | |
750 if (handler_) | |
751 handler_->OnStopped(capture); | |
752 } | |
753 | |
754 void PlatformVideoCaptureImpl::OnPaused(VideoCapture* capture) { | |
755 if (handler_) | |
756 handler_->OnPaused(capture); | |
757 } | |
758 | |
759 void PlatformVideoCaptureImpl::OnError(VideoCapture* capture, int error_code) { | |
760 if (handler_) | |
761 handler_->OnError(capture, error_code); | |
762 } | |
763 | |
764 void PlatformVideoCaptureImpl::OnRemoved(VideoCapture* capture) { | |
765 if (handler_) | |
766 handler_->OnRemoved(capture); | |
767 | |
768 Release(); // Balance the AddRef() in StartCapture(). | |
769 } | |
770 | |
771 void PlatformVideoCaptureImpl::OnBufferReady( | |
772 VideoCapture* capture, | |
773 scoped_refptr<VideoFrameBuffer> buffer) { | |
774 if (handler_) { | |
775 handler_->OnBufferReady(capture, buffer); | |
776 } else { | |
777 // Even after handler_ is detached, we have to return buffers that are in | |
778 // flight to us. Otherwise VideoCaptureController will not tear down. | |
779 FeedBuffer(buffer); | |
780 } | |
781 } | |
782 | |
783 void PlatformVideoCaptureImpl::OnDeviceInfoReceived( | |
784 VideoCapture* capture, | |
785 const media::VideoCaptureParams& device_info) { | |
786 if (handler_) | |
787 handler_->OnDeviceInfoReceived(capture, device_info); | |
788 } | |
789 | |
790 void PlatformVideoCaptureImpl::Initialize() { | |
791 VideoCaptureImplManager* manager = | |
792 RenderThreadImpl::current()->video_capture_impl_manager(); | |
793 video_capture_ = manager->AddDevice(session_id_, handler_proxy_.get()); | |
794 } | |
795 | |
796 void PlatformVideoCaptureImpl::OnDeviceOpened(int request_id, | |
797 bool succeeded, | |
798 const std::string& label) { | |
799 succeeded = succeeded && plugin_delegate_; | |
800 if (succeeded) { | |
801 label_ = label; | |
802 session_id_ = plugin_delegate_->GetSessionID(PP_DEVICETYPE_DEV_VIDEOCAPTURE, | |
803 label); | |
804 Initialize(); | |
805 } | |
806 | |
807 if (handler_) | |
808 handler_->OnInitialized(this, succeeded); | |
809 } | |
810 | |
811 media_stream::MediaStreamType FromPepperDeviceType(PP_DeviceType_Dev type) { | |
812 switch (type) { | |
813 case PP_DEVICETYPE_DEV_INVALID: | |
814 return media_stream::kNoService; | |
815 case PP_DEVICETYPE_DEV_AUDIOCAPTURE: | |
816 return media_stream::kAudioCapture; | |
817 case PP_DEVICETYPE_DEV_VIDEOCAPTURE: | |
818 return media_stream::kVideoCapture; | |
819 default: | |
820 NOTREACHED(); | |
821 return media_stream::kNoService; | |
822 } | |
823 } | |
824 | |
825 PP_DeviceType_Dev FromMediaStreamType(media_stream::MediaStreamType type) { | |
826 switch (type) { | |
827 case media_stream::kNoService: | |
828 return PP_DEVICETYPE_DEV_INVALID; | |
829 case media_stream::kAudioCapture: | |
830 return PP_DEVICETYPE_DEV_AUDIOCAPTURE; | |
831 case media_stream::kVideoCapture: | |
832 return PP_DEVICETYPE_DEV_VIDEOCAPTURE; | |
833 default: | |
834 NOTREACHED(); | |
835 return PP_DEVICETYPE_DEV_INVALID; | |
836 } | |
837 } | |
838 | |
839 ppapi::DeviceRefData FromStreamDeviceInfo( | |
840 const media_stream::StreamDeviceInfo& info) { | |
841 ppapi::DeviceRefData data; | |
842 data.id = info.device_id; | |
843 data.name = info.name; | |
844 data.type = FromMediaStreamType(info.stream_type); | |
845 return data; | |
846 } | |
646 | 847 |
647 } // namespace | 848 } // namespace |
648 | 849 |
649 BrokerDispatcherWrapper::BrokerDispatcherWrapper() { | 850 BrokerDispatcherWrapper::BrokerDispatcherWrapper() { |
650 } | 851 } |
651 | 852 |
652 BrokerDispatcherWrapper::~BrokerDispatcherWrapper() { | 853 BrokerDispatcherWrapper::~BrokerDispatcherWrapper() { |
653 } | 854 } |
654 | 855 |
655 bool BrokerDispatcherWrapper::Init( | 856 bool BrokerDispatcherWrapper::Init( |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
837 } | 1038 } |
838 | 1039 |
839 // TOOD(ddorwin): Change the IPC to asynchronous: Queue an object containing | 1040 // TOOD(ddorwin): Change the IPC to asynchronous: Queue an object containing |
840 // client and plugin_socket.release(), then return. | 1041 // client and plugin_socket.release(), then return. |
841 // That message handler will then call client->BrokerConnected() with the | 1042 // That message handler will then call client->BrokerConnected() with the |
842 // saved pipe handle. | 1043 // saved pipe handle. |
843 // Temporarily, just call back. | 1044 // Temporarily, just call back. |
844 client->BrokerConnected(ppapi::PlatformFileToInt(plugin_handle), result); | 1045 client->BrokerConnected(ppapi::PlatformFileToInt(plugin_handle), result); |
845 } | 1046 } |
846 | 1047 |
1048 class PepperPluginDelegateImpl::DeviceEnumerationEventHandler | |
1049 : public MediaStreamDispatcherEventHandler { | |
1050 public: | |
1051 DeviceEnumerationEventHandler() : next_id_(1) { | |
1052 } | |
1053 | |
1054 virtual ~DeviceEnumerationEventHandler() { | |
1055 DCHECK(enumerate_callbacks_.empty()); | |
1056 DCHECK(open_callbacks_.empty()); | |
1057 } | |
1058 | |
1059 int RegisterEnumerateDevicesCallback( | |
1060 const EnumerateDevicesCallback& callback) { | |
1061 enumerate_callbacks_[next_id_] = callback; | |
1062 return next_id_++; | |
1063 } | |
1064 | |
1065 int RegisterOpenDeviceCallback(const OpenDeviceCallback& callback) { | |
1066 open_callbacks_[next_id_] = callback; | |
1067 return next_id_++; | |
1068 } | |
1069 | |
1070 // MediaStreamDispatcherEventHandler implementation. | |
1071 virtual void OnStreamGenerated( | |
1072 int request_id, | |
1073 const std::string& label, | |
1074 const media_stream::StreamDeviceInfoArray& audio_device_array, | |
1075 const media_stream::StreamDeviceInfoArray& video_device_array) OVERRIDE { | |
1076 } | |
1077 | |
1078 virtual void OnStreamGenerationFailed(int request_id) OVERRIDE { | |
1079 } | |
1080 | |
1081 virtual void OnVideoDeviceFailed(const std::string& label, | |
1082 int index) OVERRIDE { | |
1083 } | |
1084 | |
1085 virtual void OnAudioDeviceFailed(const std::string& label, | |
1086 int index) OVERRIDE { | |
1087 } | |
1088 | |
1089 virtual void OnDevicesEnumerated( | |
1090 int request_id, | |
1091 const media_stream::StreamDeviceInfoArray& device_array) OVERRIDE { | |
1092 NotifyDevicesEnumerated(request_id, true, device_array); | |
1093 } | |
1094 | |
1095 virtual void OnDevicesEnumerationFailed(int request_id) OVERRIDE { | |
1096 NotifyDevicesEnumerated(request_id, false, | |
1097 media_stream::StreamDeviceInfoArray()); | |
1098 } | |
1099 | |
1100 virtual void OnDeviceOpened( | |
1101 int request_id, | |
1102 const std::string& label, | |
1103 const media_stream::StreamDeviceInfo& device_info) OVERRIDE { | |
1104 NotifyDeviceOpened(request_id, true, label); | |
1105 } | |
1106 | |
1107 virtual void OnDeviceOpenFailed(int request_id) OVERRIDE { | |
1108 NotifyDeviceOpened(request_id, false, ""); | |
1109 } | |
1110 | |
1111 private: | |
1112 void NotifyDevicesEnumerated( | |
1113 int request_id, | |
1114 bool succeeded, | |
1115 const media_stream::StreamDeviceInfoArray& device_array) { | |
1116 EnumerateCallbackMap::iterator iter = enumerate_callbacks_.find(request_id); | |
1117 if (iter == enumerate_callbacks_.end()) { | |
1118 NOTREACHED(); | |
1119 return; | |
1120 } | |
1121 | |
1122 EnumerateDevicesCallback callback = iter->second; | |
1123 enumerate_callbacks_.erase(iter); | |
1124 | |
1125 std::vector<ppapi::DeviceRefData> devices; | |
1126 if (succeeded) { | |
1127 devices.reserve(device_array.size()); | |
1128 for (media_stream::StreamDeviceInfoArray::const_iterator info = | |
1129 device_array.begin(); info != device_array.end(); ++info) { | |
1130 devices.push_back(FromStreamDeviceInfo(*info)); | |
1131 } | |
1132 } | |
1133 callback.Run(request_id, succeeded, devices); | |
1134 } | |
1135 | |
1136 void NotifyDeviceOpened(int request_id, | |
1137 bool succeeded, | |
1138 const std::string& label) { | |
1139 OpenCallbackMap::iterator iter = open_callbacks_.find(request_id); | |
1140 if (iter == open_callbacks_.end()) { | |
1141 NOTREACHED(); | |
1142 return; | |
1143 } | |
1144 | |
1145 OpenDeviceCallback callback = iter->second; | |
1146 open_callbacks_.erase(iter); | |
1147 | |
1148 callback.Run(request_id, succeeded, label); | |
1149 } | |
1150 | |
1151 int next_id_; | |
1152 | |
1153 typedef std::map<int, EnumerateDevicesCallback> EnumerateCallbackMap; | |
1154 EnumerateCallbackMap enumerate_callbacks_; | |
1155 | |
1156 typedef std::map<int, OpenDeviceCallback> OpenCallbackMap; | |
1157 OpenCallbackMap open_callbacks_; | |
1158 | |
1159 DISALLOW_COPY_AND_ASSIGN(DeviceEnumerationEventHandler); | |
1160 }; | |
1161 | |
847 PepperPluginDelegateImpl::PepperPluginDelegateImpl(RenderViewImpl* render_view) | 1162 PepperPluginDelegateImpl::PepperPluginDelegateImpl(RenderViewImpl* render_view) |
848 : content::RenderViewObserver(render_view), | 1163 : content::RenderViewObserver(render_view), |
849 render_view_(render_view), | 1164 render_view_(render_view), |
850 has_saved_context_menu_action_(false), | 1165 has_saved_context_menu_action_(false), |
851 saved_context_menu_action_(0), | 1166 saved_context_menu_action_(0), |
852 focused_plugin_(NULL), | 1167 focused_plugin_(NULL), |
853 mouse_lock_owner_(NULL), | 1168 mouse_lock_owner_(NULL), |
854 mouse_locked_(false), | 1169 mouse_locked_(false), |
855 pending_lock_request_(false), | 1170 pending_lock_request_(false), |
856 pending_unlock_request_(false), | 1171 pending_unlock_request_(false), |
857 last_mouse_event_target_(NULL) { | 1172 last_mouse_event_target_(NULL), |
1173 device_enumeration_event_handler_(new DeviceEnumerationEventHandler()) { | |
858 } | 1174 } |
859 | 1175 |
860 PepperPluginDelegateImpl::~PepperPluginDelegateImpl() { | 1176 PepperPluginDelegateImpl::~PepperPluginDelegateImpl() { |
861 DCHECK(!mouse_lock_owner_); | 1177 DCHECK(!mouse_lock_owner_); |
862 } | 1178 } |
863 | 1179 |
864 scoped_refptr<webkit::ppapi::PluginModule> | 1180 scoped_refptr<webkit::ppapi::PluginModule> |
865 PepperPluginDelegateImpl::CreatePepperPluginModule( | 1181 PepperPluginDelegateImpl::CreatePepperPluginModule( |
866 const webkit::WebPluginInfo& webplugin_info, | 1182 const webkit::WebPluginInfo& webplugin_info, |
867 bool* pepper_plugin_was_registered) { | 1183 bool* pepper_plugin_was_registered) { |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1221 if (!render_view_->webkit_preferences().accelerated_plugins_enabled) | 1537 if (!render_view_->webkit_preferences().accelerated_plugins_enabled) |
1222 return NULL; | 1538 return NULL; |
1223 return new PlatformContext3DImpl(this); | 1539 return new PlatformContext3DImpl(this); |
1224 #else | 1540 #else |
1225 return NULL; | 1541 return NULL; |
1226 #endif | 1542 #endif |
1227 } | 1543 } |
1228 | 1544 |
1229 webkit::ppapi::PluginDelegate::PlatformVideoCapture* | 1545 webkit::ppapi::PluginDelegate::PlatformVideoCapture* |
1230 PepperPluginDelegateImpl::CreateVideoCapture( | 1546 PepperPluginDelegateImpl::CreateVideoCapture( |
1231 media::VideoCapture::EventHandler* handler) { | 1547 const std::string& device_id, |
1232 return new PlatformVideoCaptureImpl(handler); | 1548 PlatformVideoCaptureEventHandler* handler) { |
1549 return new PlatformVideoCaptureImpl(AsWeakPtr(), device_id, handler); | |
1233 } | 1550 } |
1234 | 1551 |
1235 webkit::ppapi::PluginDelegate::PlatformVideoDecoder* | 1552 webkit::ppapi::PluginDelegate::PlatformVideoDecoder* |
1236 PepperPluginDelegateImpl::CreateVideoDecoder( | 1553 PepperPluginDelegateImpl::CreateVideoDecoder( |
1237 media::VideoDecodeAccelerator::Client* client, | 1554 media::VideoDecodeAccelerator::Client* client, |
1238 int32 command_buffer_route_id) { | 1555 int32 command_buffer_route_id) { |
1239 return new PlatformVideoDecoderImpl(client, command_buffer_route_id); | 1556 return new PlatformVideoDecoderImpl(client, command_buffer_route_id); |
1240 } | 1557 } |
1241 | 1558 |
1242 void PepperPluginDelegateImpl::NumberOfFindResultsChanged(int identifier, | 1559 void PepperPluginDelegateImpl::NumberOfFindResultsChanged(int identifier, |
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2037 void PepperPluginDelegateImpl::SampleGamepads(WebKit::WebGamepads* data) { | 2354 void PepperPluginDelegateImpl::SampleGamepads(WebKit::WebGamepads* data) { |
2038 if (!gamepad_shared_memory_reader_.get()) | 2355 if (!gamepad_shared_memory_reader_.get()) |
2039 gamepad_shared_memory_reader_.reset(new content::GamepadSharedMemoryReader); | 2356 gamepad_shared_memory_reader_.reset(new content::GamepadSharedMemoryReader); |
2040 gamepad_shared_memory_reader_->SampleGamepads(*data); | 2357 gamepad_shared_memory_reader_->SampleGamepads(*data); |
2041 } | 2358 } |
2042 | 2359 |
2043 bool PepperPluginDelegateImpl::IsPageVisible() const { | 2360 bool PepperPluginDelegateImpl::IsPageVisible() const { |
2044 return !render_view_->is_hidden(); | 2361 return !render_view_->is_hidden(); |
2045 } | 2362 } |
2046 | 2363 |
2364 int PepperPluginDelegateImpl::EnumerateDevices( | |
2365 PP_DeviceType_Dev type, | |
2366 const EnumerateDevicesCallback& callback) { | |
2367 int request_id = | |
2368 device_enumeration_event_handler_->RegisterEnumerateDevicesCallback( | |
2369 callback); | |
2370 render_view_->media_stream_dispatcher()->EnumerateDevices( | |
2371 request_id, device_enumeration_event_handler_.get(), | |
2372 FromPepperDeviceType(type), ""); | |
2373 return request_id; | |
2374 } | |
2375 | |
2047 bool PepperPluginDelegateImpl::OnMessageReceived(const IPC::Message& message) { | 2376 bool PepperPluginDelegateImpl::OnMessageReceived(const IPC::Message& message) { |
2048 bool handled = true; | 2377 bool handled = true; |
2049 IPC_BEGIN_MESSAGE_MAP(PepperPluginDelegateImpl, message) | 2378 IPC_BEGIN_MESSAGE_MAP(PepperPluginDelegateImpl, message) |
2050 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_ConnectACK, | 2379 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_ConnectACK, |
2051 OnTCPSocketConnectACK) | 2380 OnTCPSocketConnectACK) |
2052 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_SSLHandshakeACK, | 2381 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_SSLHandshakeACK, |
2053 OnTCPSocketSSLHandshakeACK) | 2382 OnTCPSocketSSLHandshakeACK) |
2054 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_ReadACK, OnTCPSocketReadACK) | 2383 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_ReadACK, OnTCPSocketReadACK) |
2055 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_WriteACK, OnTCPSocketWriteACK) | 2384 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_WriteACK, OnTCPSocketWriteACK) |
2056 IPC_MESSAGE_HANDLER(PpapiMsg_PPBUDPSocket_BindACK, OnUDPSocketBindACK) | 2385 IPC_MESSAGE_HANDLER(PpapiMsg_PPBUDPSocket_BindACK, OnUDPSocketBindACK) |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2138 webkit::ppapi::PPB_UDPSocket_Private_Impl* socket = | 2467 webkit::ppapi::PPB_UDPSocket_Private_Impl* socket = |
2139 udp_sockets_.Lookup(socket_id); | 2468 udp_sockets_.Lookup(socket_id); |
2140 if (socket) | 2469 if (socket) |
2141 socket->OnSendToCompleted(succeeded, bytes_written); | 2470 socket->OnSendToCompleted(succeeded, bytes_written); |
2142 } | 2471 } |
2143 | 2472 |
2144 int PepperPluginDelegateImpl::GetRoutingId() const { | 2473 int PepperPluginDelegateImpl::GetRoutingId() const { |
2145 return render_view_->routing_id(); | 2474 return render_view_->routing_id(); |
2146 } | 2475 } |
2147 | 2476 |
2477 int PepperPluginDelegateImpl::OpenDevice(PP_DeviceType_Dev type, | |
2478 const std::string& device_id, | |
2479 const OpenDeviceCallback& callback) { | |
2480 int request_id = | |
2481 device_enumeration_event_handler_->RegisterOpenDeviceCallback(callback); | |
2482 render_view_->media_stream_dispatcher()->OpenDevice( | |
2483 request_id, device_enumeration_event_handler_.get(), device_id, | |
2484 FromPepperDeviceType(type), ""); | |
2485 return request_id; | |
2486 } | |
2487 | |
2488 void PepperPluginDelegateImpl::CloseDevice(const std::string& label) { | |
2489 render_view_->media_stream_dispatcher()->CloseDevice(label); | |
2490 } | |
2491 | |
2492 int PepperPluginDelegateImpl::GetSessionID(PP_DeviceType_Dev type, | |
2493 const std::string& label) { | |
2494 switch (type) { | |
2495 case PP_DEVICETYPE_DEV_AUDIOCAPTURE: | |
2496 return render_view_->media_stream_dispatcher()->audio_session_id(label, | |
2497 0); | |
2498 case PP_DEVICETYPE_DEV_VIDEOCAPTURE: | |
2499 return render_view_->media_stream_dispatcher()->video_session_id(label, | |
2500 0); | |
2501 default: | |
2502 NOTREACHED(); | |
2503 return 0; | |
2504 } | |
2505 } | |
2506 | |
2148 RendererGLContext* | 2507 RendererGLContext* |
2149 PepperPluginDelegateImpl::GetParentContextForPlatformContext3D() { | 2508 PepperPluginDelegateImpl::GetParentContextForPlatformContext3D() { |
2150 WebGraphicsContext3DCommandBufferImpl* context = | 2509 WebGraphicsContext3DCommandBufferImpl* context = |
2151 static_cast<WebGraphicsContext3DCommandBufferImpl*>( | 2510 static_cast<WebGraphicsContext3DCommandBufferImpl*>( |
2152 render_view_->webview()->graphicsContext3D()); | 2511 render_view_->webview()->graphicsContext3D()); |
2153 if (!context) | 2512 if (!context) |
2154 return NULL; | 2513 return NULL; |
2155 if (!context->makeContextCurrent() || context->isContextLost()) | 2514 if (!context->makeContextCurrent() || context->isContextLost()) |
2156 return NULL; | 2515 return NULL; |
2157 | 2516 |
2158 RendererGLContext* parent_context = context->context(); | 2517 RendererGLContext* parent_context = context->context(); |
2159 if (!parent_context) | 2518 if (!parent_context) |
2160 return NULL; | 2519 return NULL; |
2161 return parent_context; | 2520 return parent_context; |
2162 } | 2521 } |
2163 | 2522 |
2164 bool PepperPluginDelegateImpl::CanUseSocketAPIs() { | 2523 bool PepperPluginDelegateImpl::CanUseSocketAPIs() { |
2165 WebView* webview = render_view_->webview(); | 2524 WebView* webview = render_view_->webview(); |
2166 WebFrame* main_frame = webview ? webview->mainFrame() : NULL; | 2525 WebFrame* main_frame = webview ? webview->mainFrame() : NULL; |
2167 GURL url(main_frame ? GURL(main_frame->document().url()) : GURL()); | 2526 GURL url(main_frame ? GURL(main_frame->document().url()) : GURL()); |
2168 if (!url.is_valid()) | 2527 if (!url.is_valid()) |
2169 return false; | 2528 return false; |
2170 | 2529 |
2171 return content::GetContentClient()->renderer()->AllowSocketAPI(url); | 2530 return content::GetContentClient()->renderer()->AllowSocketAPI(url); |
2172 } | 2531 } |
OLD | NEW |