#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
+#include "content/public/browser/browser_thread.h"
#include "content/public/common/media_stream_request.h"
namespace content {
-class RenderViewHostDelegate;
+class RenderFrameHostDelegate;
// MediaStreamUIProxy proxies calls to media stream UI between IO thread and UI
// thread. One instance of this class is create per MediaStream object. It must
-// be create, used and destroyed on IO thread.
+// be created, used and destroyed on IO thread.
class CONTENT_EXPORT MediaStreamUIProxy {
public:
typedef base::Callback<
static scoped_ptr<MediaStreamUIProxy> Create();
static scoped_ptr<MediaStreamUIProxy> CreateForTests(
- RenderViewHostDelegate* render_delegate);
+ RenderFrameHostDelegate* render_delegate);
virtual ~MediaStreamUIProxy();
virtual void RequestAccess(const MediaStreamRequest& request,
const ResponseCallback& response_callback);
+ // Checks if we have permission to access the microphone or camera. Note that
+ // this does not query the user, it checks any stored settings such as policy
+ // or extension permissions. |type| must be MEDIA_DEVICE_AUDIO_CAPTURE
+ // or MEDIA_DEVICE_VIDEO_CAPTURE.
+ virtual void CheckAccess(const GURL& security_origin,
+ MediaStreamType type,
+ int render_process_id,
+ int render_frame_id,
+ const base::Callback<void(bool)>& callback);
+
// Notifies the UI that the MediaStream has been started. Must be called after
// access has been approved using RequestAccess(). |stop_callback| is be
// called on the IO thread after the user has requests the stream to be
virtual void OnStarted(const base::Closure& stop_callback,
const WindowIdCallback& window_id_callback);
- void SetRenderViewHostDelegateForTests(RenderViewHostDelegate* delegate);
+ void SetRenderFrameHostDelegateForTests(RenderFrameHostDelegate* delegate);
protected:
- MediaStreamUIProxy(RenderViewHostDelegate* test_render_delegate);
+ explicit MediaStreamUIProxy(RenderFrameHostDelegate* test_render_delegate);
private:
class Core;
void ProcessStopRequestFromUI();
void OnWindowId(const WindowIdCallback& window_id_callback,
gfx::NativeViewId* window_id);
+ void OnCheckedAccess(const base::Callback<void(bool)>& callback,
+ bool have_access);
- scoped_ptr<Core> core_;
+ scoped_ptr<Core, content::BrowserThread::DeleteOnUIThread> core_;
ResponseCallback response_callback_;
base::Closure stop_callback_;
class CONTENT_EXPORT FakeMediaStreamUIProxy : public MediaStreamUIProxy {
public:
explicit FakeMediaStreamUIProxy();
- virtual ~FakeMediaStreamUIProxy();
+ ~FakeMediaStreamUIProxy() override;
void SetAvailableDevices(const MediaStreamDevices& devices);
+ void SetMicAccess(bool access);
+ void SetCameraAccess(bool access);
// MediaStreamUIProxy overrides.
- virtual void RequestAccess(
- const MediaStreamRequest& request,
- const ResponseCallback& response_callback) OVERRIDE;
- virtual void OnStarted(const base::Closure& stop_callback,
- const WindowIdCallback& window_id_callback) OVERRIDE;
+ void RequestAccess(const MediaStreamRequest& request,
+ const ResponseCallback& response_callback) override;
+ void CheckAccess(const GURL& security_origin,
+ MediaStreamType type,
+ int render_process_id,
+ int render_frame_id,
+ const base::Callback<void(bool)>& callback) override;
+ void OnStarted(const base::Closure& stop_callback,
+ const WindowIdCallback& window_id_callback) override;
private:
+ // This is used for RequestAccess().
MediaStreamDevices devices_;
+ // These are used for CheckAccess().
+ bool mic_access_;
+ bool camera_access_;
+
DISALLOW_COPY_AND_ASSIGN(FakeMediaStreamUIProxy);
};