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

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

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

Powered by Google App Engine
This is Rietveld 408576698