• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.  There is one MediaStreamDispatcherHost per
26 // RenderProcessHost, the former owned by the latter.
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 
35   // MediaStreamRequester implementation.
36   virtual void StreamGenerated(
37       int render_frame_id,
38       int page_request_id,
39       const std::string& label,
40       const StreamDeviceInfoArray& audio_devices,
41       const StreamDeviceInfoArray& video_devices) OVERRIDE;
42   virtual void StreamGenerationFailed(
43       int render_frame_id,
44       int page_request_id,
45       content::MediaStreamRequestResult result) OVERRIDE;
46   virtual void DeviceStopped(int render_frame_id,
47                              const std::string& label,
48                              const StreamDeviceInfo& device) OVERRIDE;
49   virtual void DevicesEnumerated(int render_frame_id,
50                                  int page_request_id,
51                                  const std::string& label,
52                                  const StreamDeviceInfoArray& devices) OVERRIDE;
53   virtual void DeviceOpened(int render_frame_id,
54                             int page_request_id,
55                             const std::string& label,
56                             const StreamDeviceInfo& video_device) OVERRIDE;
57 
58   // BrowserMessageFilter implementation.
59   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
60   virtual void OnChannelClosing() OVERRIDE;
61 
62  protected:
63   virtual ~MediaStreamDispatcherHost();
64 
65  private:
66   friend class MockMediaStreamDispatcherHost;
67 
68   void OnGenerateStream(int render_frame_id,
69                         int page_request_id,
70                         const StreamOptions& components,
71                         const GURL& security_origin,
72                         bool user_gesture);
73   void OnCancelGenerateStream(int render_frame_id,
74                               int page_request_id);
75   void OnStopStreamDevice(int render_frame_id,
76                           const std::string& device_id);
77 
78   void OnEnumerateDevices(int render_frame_id,
79                           int page_request_id,
80                           MediaStreamType type,
81                           const GURL& security_origin);
82 
83   void OnCancelEnumerateDevices(int render_frame_id,
84                                 int page_request_id);
85 
86   void OnOpenDevice(int render_frame_id,
87                     int page_request_id,
88                     const std::string& device_id,
89                     MediaStreamType type,
90                     const GURL& security_origin);
91 
92   void OnCloseDevice(int render_frame_id,
93                      const std::string& label);
94 
95   void StoreRequest(int render_frame_id,
96                     int page_request_id,
97                     const std::string& label);
98 
99   bool IsURLAllowed(const GURL& url);
100 
101   int render_process_id_;
102   ResourceContext::SaltCallback salt_callback_;
103   MediaStreamManager* media_stream_manager_;
104 
105   DISALLOW_COPY_AND_ASSIGN(MediaStreamDispatcherHost);
106 };
107 
108 }  // namespace content
109 
110 #endif  // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_DISPATCHER_HOST_H_
111