OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_UI_PROXY_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_UI_PROXY_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_UI_PROXY_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_UI_PROXY_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 | 34 |
35 virtual ~MediaStreamUIProxy(); | 35 virtual ~MediaStreamUIProxy(); |
36 | 36 |
37 // Requests access for the MediaStream by calling | 37 // Requests access for the MediaStream by calling |
38 // WebContentsDelegate::RequestMediaAccessPermission(). The specified | 38 // WebContentsDelegate::RequestMediaAccessPermission(). The specified |
39 // |response_callback| is called when the WebContentsDelegate approves or | 39 // |response_callback| is called when the WebContentsDelegate approves or |
40 // denies request. | 40 // denies request. |
41 virtual void RequestAccess(const MediaStreamRequest& request, | 41 virtual void RequestAccess(const MediaStreamRequest& request, |
42 const ResponseCallback& response_callback); | 42 const ResponseCallback& response_callback); |
43 | 43 |
| 44 // Checks if we have permission to access the microphone or camera. Note that |
| 45 // this does not query the user, it checks any stored settings such as policy |
| 46 // or extension permissions. |type| must be MEDIA_DEVICE_AUDIO_CAPTURE |
| 47 // or MEDIA_DEVICE_VIDEO_CAPTURE. |
| 48 virtual void CheckAccess(const GURL& security_origin, |
| 49 MediaStreamType type, |
| 50 int render_process_id, |
| 51 int render_frame_id, |
| 52 const base::Callback<void(bool)>& callback); |
| 53 |
44 // Notifies the UI that the MediaStream has been started. Must be called after | 54 // Notifies the UI that the MediaStream has been started. Must be called after |
45 // access has been approved using RequestAccess(). |stop_callback| is be | 55 // access has been approved using RequestAccess(). |stop_callback| is be |
46 // called on the IO thread after the user has requests the stream to be | 56 // called on the IO thread after the user has requests the stream to be |
47 // stopped. |window_id_callback| is called on the IO thread with the platform- | 57 // stopped. |window_id_callback| is called on the IO thread with the platform- |
48 // dependent window ID of the UI. | 58 // dependent window ID of the UI. |
49 virtual void OnStarted(const base::Closure& stop_callback, | 59 virtual void OnStarted(const base::Closure& stop_callback, |
50 const WindowIdCallback& window_id_callback); | 60 const WindowIdCallback& window_id_callback); |
51 | 61 |
52 void SetRenderFrameHostDelegateForTests(RenderFrameHostDelegate* delegate); | 62 void SetRenderFrameHostDelegateForTests(RenderFrameHostDelegate* delegate); |
53 | 63 |
54 protected: | 64 protected: |
55 explicit MediaStreamUIProxy(RenderFrameHostDelegate* test_render_delegate); | 65 explicit MediaStreamUIProxy(RenderFrameHostDelegate* test_render_delegate); |
56 | 66 |
57 private: | 67 private: |
58 class Core; | 68 class Core; |
59 friend class Core; | 69 friend class Core; |
60 friend class FakeMediaStreamUIProxy; | 70 friend class FakeMediaStreamUIProxy; |
61 | 71 |
62 void ProcessAccessRequestResponse( | 72 void ProcessAccessRequestResponse( |
63 const MediaStreamDevices& devices, | 73 const MediaStreamDevices& devices, |
64 content::MediaStreamRequestResult result); | 74 content::MediaStreamRequestResult result); |
65 void ProcessStopRequestFromUI(); | 75 void ProcessStopRequestFromUI(); |
66 void OnWindowId(const WindowIdCallback& window_id_callback, | 76 void OnWindowId(const WindowIdCallback& window_id_callback, |
67 gfx::NativeViewId* window_id); | 77 gfx::NativeViewId* window_id); |
| 78 void OnCheckedAccess(const base::Callback<void(bool)>& callback, |
| 79 bool have_access); |
68 | 80 |
69 scoped_ptr<Core, content::BrowserThread::DeleteOnUIThread> core_; | 81 scoped_ptr<Core, content::BrowserThread::DeleteOnUIThread> core_; |
70 ResponseCallback response_callback_; | 82 ResponseCallback response_callback_; |
71 base::Closure stop_callback_; | 83 base::Closure stop_callback_; |
72 | 84 |
73 base::WeakPtrFactory<MediaStreamUIProxy> weak_factory_; | 85 base::WeakPtrFactory<MediaStreamUIProxy> weak_factory_; |
74 | 86 |
75 DISALLOW_COPY_AND_ASSIGN(MediaStreamUIProxy); | 87 DISALLOW_COPY_AND_ASSIGN(MediaStreamUIProxy); |
76 }; | 88 }; |
77 | 89 |
78 class CONTENT_EXPORT FakeMediaStreamUIProxy : public MediaStreamUIProxy { | 90 class CONTENT_EXPORT FakeMediaStreamUIProxy : public MediaStreamUIProxy { |
79 public: | 91 public: |
80 explicit FakeMediaStreamUIProxy(); | 92 explicit FakeMediaStreamUIProxy(); |
81 virtual ~FakeMediaStreamUIProxy(); | 93 virtual ~FakeMediaStreamUIProxy(); |
82 | 94 |
83 void SetAvailableDevices(const MediaStreamDevices& devices); | 95 void SetAvailableDevices(const MediaStreamDevices& devices); |
| 96 void SetMicAccess(bool access); |
| 97 void SetCameraAccess(bool access); |
84 | 98 |
85 // MediaStreamUIProxy overrides. | 99 // MediaStreamUIProxy overrides. |
86 virtual void RequestAccess( | 100 virtual void RequestAccess( |
87 const MediaStreamRequest& request, | 101 const MediaStreamRequest& request, |
88 const ResponseCallback& response_callback) OVERRIDE; | 102 const ResponseCallback& response_callback) OVERRIDE; |
| 103 virtual void CheckAccess(const GURL& security_origin, |
| 104 MediaStreamType type, |
| 105 int render_process_id, |
| 106 int render_frame_id, |
| 107 const base::Callback<void(bool)>& callback) OVERRIDE; |
89 virtual void OnStarted(const base::Closure& stop_callback, | 108 virtual void OnStarted(const base::Closure& stop_callback, |
90 const WindowIdCallback& window_id_callback) OVERRIDE; | 109 const WindowIdCallback& window_id_callback) OVERRIDE; |
91 | 110 |
92 private: | 111 private: |
| 112 // This is used for RequestAccess(). |
93 MediaStreamDevices devices_; | 113 MediaStreamDevices devices_; |
94 | 114 |
| 115 // These are used for CheckAccess(). |
| 116 bool mic_access_; |
| 117 bool camera_access_; |
| 118 |
95 DISALLOW_COPY_AND_ASSIGN(FakeMediaStreamUIProxy); | 119 DISALLOW_COPY_AND_ASSIGN(FakeMediaStreamUIProxy); |
96 }; | 120 }; |
97 | 121 |
98 } // namespace content | 122 } // namespace content |
99 | 123 |
100 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_UI_PROXY_H_ | 124 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_UI_PROXY_H_ |
OLD | NEW |