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 3 // found in the LICENSE file. 4 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_DISPATCHER_HOST_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_DISPATCHER_HOST_H_ 7 8 #include <map> 9 #include <string> 10 #include <utility> 11 12 #include "content/browser/renderer_host/media/media_stream_manager.h" 13 #include "content/browser/renderer_host/media/media_stream_requester.h" 14 #include "content/common/content_export.h" 15 #include "content/common/media/media_stream_options.h" 16 #include "content/public/browser/browser_message_filter.h" 17 #include "content/public/browser/resource_context.h" 18 19 namespace content { 20 21 class MediaStreamManager; 22 class ResourceContext; 23 24 // MediaStreamDispatcherHost is a delegate for Media Stream API messages used by 25 // MediaStreamImpl. It's the complement of MediaStreamDispatcher 26 // (owned by RenderView). 27 class CONTENT_EXPORT MediaStreamDispatcherHost : public BrowserMessageFilter, 28 public MediaStreamRequester { 29 public: 30 MediaStreamDispatcherHost( 31 int render_process_id, 32 const ResourceContext::SaltCallback& salt_callback, 33 MediaStreamManager* media_stream_manager, 34 ResourceContext* resource_context); 35 36 // MediaStreamRequester implementation. 37 virtual void StreamGenerated( 38 int render_view_id, 39 int page_request_id, 40 const std::string& label, 41 const StreamDeviceInfoArray& audio_devices, 42 const StreamDeviceInfoArray& video_devices) OVERRIDE; 43 virtual void StreamGenerationFailed( 44 int render_view_id, 45 int page_request_id, 46 content::MediaStreamRequestResult result) OVERRIDE; 47 virtual void DeviceStopped(int render_view_id, 48 const std::string& label, 49 const StreamDeviceInfo& device) OVERRIDE; 50 virtual void DevicesEnumerated(int render_view_id, 51 int page_request_id, 52 const std::string& label, 53 const StreamDeviceInfoArray& devices) OVERRIDE; 54 virtual void DeviceOpened(int render_view_id, 55 int page_request_id, 56 const std::string& label, 57 const StreamDeviceInfo& video_device) OVERRIDE; 58 59 // BrowserMessageFilter implementation. 60 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 61 virtual void OnChannelClosing() OVERRIDE; 62 63 protected: 64 virtual ~MediaStreamDispatcherHost(); 65 66 private: 67 friend class MockMediaStreamDispatcherHost; 68 69 void OnGenerateStream(int render_view_id, 70 int page_request_id, 71 const StreamOptions& components, 72 const GURL& security_origin, 73 bool user_gesture); 74 void OnCancelGenerateStream(int render_view_id, 75 int page_request_id); 76 void OnStopStreamDevice(int render_view_id, 77 const std::string& device_id); 78 79 void OnEnumerateDevices(int render_view_id, 80 int page_request_id, 81 MediaStreamType type, 82 const GURL& security_origin, 83 bool hide_labels_if_no_access); 84 85 void OnCancelEnumerateDevices(int render_view_id, 86 int page_request_id); 87 88 void OnOpenDevice(int render_view_id, 89 int page_request_id, 90 const std::string& device_id, 91 MediaStreamType type, 92 const GURL& security_origin); 93 94 void OnCloseDevice(int render_view_id, 95 const std::string& label); 96 97 void StoreRequest(int render_view_id, 98 int page_request_id, 99 const std::string& label); 100 101 bool IsURLAllowed(const GURL& url); 102 103 int render_process_id_; 104 ResourceContext::SaltCallback salt_callback_; 105 MediaStreamManager* media_stream_manager_; 106 107 // Owned by ProfileIOData which is guaranteed to outlive MSDH. 108 ResourceContext* const resource_context_; 109 110 DISALLOW_COPY_AND_ASSIGN(MediaStreamDispatcherHost); 111 }; 112 113 } // namespace content 114 115 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_DISPATCHER_HOST_H_ 116