Commit a01798fe authored by Weiyong Yao's avatar Weiyong Yao Committed by Commit Bot

Add stream type to DesktopStreamsRegistry APIs

As we're going to use DesktopStreamRegistry for both desktopCapture
and tabCapture registry, it's important to let getUserMedia() to be
called with corresponding source type, 'desktop' or 'tab', which will
lead to different UI indicator.
This cl is to add the source type at adding/verifying request to
the registry.

Bug: 831722
Change-Id: If53022ec35c3c3b7993e41149e381b96b3e48877
Reviewed-on: https://chromium-review.googlesource.com/1149192Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarYuri Wiitala <miu@chromium.org>
Commit-Queue: Weiyong Yao <braveyao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#581108}
parent c5c275db
...@@ -242,7 +242,7 @@ void DesktopCaptureChooseDesktopMediaFunctionBase::OnPickerDialogResults( ...@@ -242,7 +242,7 @@ void DesktopCaptureChooseDesktopMediaFunctionBase::OnPickerDialogResults(
content::RenderFrameHost* const main_frame = web_contents()->GetMainFrame(); content::RenderFrameHost* const main_frame = web_contents()->GetMainFrame();
result = content::DesktopStreamsRegistry::GetInstance()->RegisterStream( result = content::DesktopStreamsRegistry::GetInstance()->RegisterStream(
main_frame->GetProcess()->GetID(), main_frame->GetRoutingID(), origin_, main_frame->GetProcess()->GetID(), main_frame->GetRoutingID(), origin_,
source, extension()->name()); source, extension()->name(), content::kRegistryStreamTypeDesktop);
} }
Options options; Options options;
......
...@@ -321,7 +321,7 @@ std::string TabCaptureRegistry::AddRequest( ...@@ -321,7 +321,7 @@ std::string TabCaptureRegistry::AddRequest(
if (main_frame) { if (main_frame) {
device_id = content::DesktopStreamsRegistry::GetInstance()->RegisterStream( device_id = content::DesktopStreamsRegistry::GetInstance()->RegisterStream(
main_frame->GetProcess()->GetID(), main_frame->GetRoutingID(), origin, main_frame->GetProcess()->GetID(), main_frame->GetRoutingID(), origin,
source, extension_name); source, extension_name, content::kRegistryStreamTypeTab);
} }
return device_id; return device_id;
......
...@@ -420,7 +420,8 @@ void DesktopCaptureAccessHandler::HandleRequest( ...@@ -420,7 +420,8 @@ void DesktopCaptureAccessHandler::HandleRequest(
content::DesktopStreamsRegistry::GetInstance()->RequestMediaForStreamId( content::DesktopStreamsRegistry::GetInstance()->RequestMediaForStreamId(
request.requested_video_device_id, request.requested_video_device_id,
main_frame->GetProcess()->GetID(), main_frame->GetRoutingID(), main_frame->GetProcess()->GetID(), main_frame->GetRoutingID(),
request.security_origin, &original_extension_name); request.security_origin, &original_extension_name,
content::kRegistryStreamTypeDesktop);
} }
// Received invalid device id. // Received invalid device id.
......
...@@ -50,7 +50,8 @@ std::string DesktopStreamsRegistryImpl::RegisterStream( ...@@ -50,7 +50,8 @@ std::string DesktopStreamsRegistryImpl::RegisterStream(
int render_frame_id, int render_frame_id,
const GURL& origin, const GURL& origin,
const DesktopMediaID& source, const DesktopMediaID& source,
const std::string& extension_name) { const std::string& extension_name,
const DesktopStreamRegistryType type) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
std::string id = GenerateRandomStreamId(); std::string id = GenerateRandomStreamId();
...@@ -61,6 +62,7 @@ std::string DesktopStreamsRegistryImpl::RegisterStream( ...@@ -61,6 +62,7 @@ std::string DesktopStreamsRegistryImpl::RegisterStream(
stream.origin = origin; stream.origin = origin;
stream.source = source; stream.source = source;
stream.extension_name = extension_name; stream.extension_name = extension_name;
stream.type = type;
BrowserThread::PostDelayedTask( BrowserThread::PostDelayedTask(
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
...@@ -76,7 +78,8 @@ DesktopMediaID DesktopStreamsRegistryImpl::RequestMediaForStreamId( ...@@ -76,7 +78,8 @@ DesktopMediaID DesktopStreamsRegistryImpl::RequestMediaForStreamId(
int render_process_id, int render_process_id,
int render_frame_id, int render_frame_id,
const GURL& origin, const GURL& origin,
std::string* extension_name) { std::string* extension_name,
const DesktopStreamRegistryType type) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
StreamsMap::iterator it = approved_streams_.find(id); StreamsMap::iterator it = approved_streams_.find(id);
...@@ -86,7 +89,7 @@ DesktopMediaID DesktopStreamsRegistryImpl::RequestMediaForStreamId( ...@@ -86,7 +89,7 @@ DesktopMediaID DesktopStreamsRegistryImpl::RequestMediaForStreamId(
if (it == approved_streams_.end() || if (it == approved_streams_.end() ||
render_process_id != it->second.render_process_id || render_process_id != it->second.render_process_id ||
render_frame_id != it->second.render_frame_id || render_frame_id != it->second.render_frame_id ||
origin != it->second.origin) { origin != it->second.origin || type != it->second.type) {
return DesktopMediaID(); return DesktopMediaID();
} }
......
...@@ -28,13 +28,16 @@ class CONTENT_EXPORT DesktopStreamsRegistryImpl ...@@ -28,13 +28,16 @@ class CONTENT_EXPORT DesktopStreamsRegistryImpl
int render_frame_id, int render_frame_id,
const GURL& origin, const GURL& origin,
const DesktopMediaID& source, const DesktopMediaID& source,
const std::string& extension_name) override; const std::string& extension_name,
const DesktopStreamRegistryType type) override;
DesktopMediaID RequestMediaForStreamId(const std::string& id, DesktopMediaID RequestMediaForStreamId(
int render_process_id, const std::string& id,
int render_frame_id, int render_process_id,
const GURL& origin, int render_frame_id,
std::string* extension_name) override; const GURL& origin,
std::string* extension_name,
const DesktopStreamRegistryType type) override;
private: private:
// Type used to store list of accepted desktop media streams. // Type used to store list of accepted desktop media streams.
...@@ -46,6 +49,7 @@ class CONTENT_EXPORT DesktopStreamsRegistryImpl ...@@ -46,6 +49,7 @@ class CONTENT_EXPORT DesktopStreamsRegistryImpl
GURL origin; GURL origin;
DesktopMediaID source; DesktopMediaID source;
std::string extension_name; std::string extension_name;
DesktopStreamRegistryType type;
}; };
typedef std::map<std::string, ApprovedDesktopMediaStream> StreamsMap; typedef std::map<std::string, ApprovedDesktopMediaStream> StreamsMap;
......
...@@ -1175,7 +1175,7 @@ DesktopMediaID MediaStreamManager::ResolveTabCaptureDeviceIdOnUIThread( ...@@ -1175,7 +1175,7 @@ DesktopMediaID MediaStreamManager::ResolveTabCaptureDeviceIdOnUIThread(
// Resolve DesktopMediaID for the specified device id. // Resolve DesktopMediaID for the specified device id.
return DesktopStreamsRegistry::GetInstance()->RequestMediaForStreamId( return DesktopStreamsRegistry::GetInstance()->RequestMediaForStreamId(
capture_device_id, requesting_process_id, requesting_frame_id, origin, capture_device_id, requesting_process_id, requesting_frame_id, origin,
nullptr); nullptr, kRegistryStreamTypeTab);
} }
void MediaStreamManager::FinishTabCaptureRequestSetupWithDeviceId( void MediaStreamManager::FinishTabCaptureRequestSetupWithDeviceId(
......
...@@ -11,10 +11,15 @@ class GURL; ...@@ -11,10 +11,15 @@ class GURL;
namespace content { namespace content {
enum DesktopStreamRegistryType {
kRegistryStreamTypeDesktop,
kRegistryStreamTypeTab
};
struct DesktopMediaID; struct DesktopMediaID;
// Interface to DesktopStreamsRegistry which is used to store accepted desktop // Interface to DesktopStreamsRegistry which is used to store accepted desktop
// media streams for Desktop Capture API. Single instance of this class is // media streams for Desktop/Tab Capture API. Single instance of this class is
// created at first time use. This should be called on UI thread. // created at first time use. This should be called on UI thread.
class CONTENT_EXPORT DesktopStreamsRegistry { class CONTENT_EXPORT DesktopStreamsRegistry {
public: public:
...@@ -22,27 +27,30 @@ class CONTENT_EXPORT DesktopStreamsRegistry { ...@@ -22,27 +27,30 @@ class CONTENT_EXPORT DesktopStreamsRegistry {
static DesktopStreamsRegistry* GetInstance(); static DesktopStreamsRegistry* GetInstance();
// Adds new stream to the registry. Called by the implementation of // Adds new stream to the registry. Called by the implementation of either
// desktopCapture.chooseDesktopMedia() API after user has approved access to // desktopCapture API or tabCapture API, differentiated by |type|, after user
// |source| for the |origin|. Returns identifier of the new stream. // has approved access to |source| for the |origin|. Returns identifier of
// the new stream.
// |render_frame_id| refers to the RenderFrame requesting the stream. // |render_frame_id| refers to the RenderFrame requesting the stream.
virtual std::string RegisterStream(int render_process_id, virtual std::string RegisterStream(int render_process_id,
int render_frame_id, int render_frame_id,
const GURL& origin, const GURL& origin,
const DesktopMediaID& source, const DesktopMediaID& source,
const std::string& extension_name) = 0; const std::string& extension_name,
const DesktopStreamRegistryType type) = 0;
// Validates stream identifier specified in getUserMedia(). Returns null // Validates stream identifier specified in getUserMedia(). Returns null
// DesktopMediaID if the specified |id| is invalid, i.e. wasn't generated // DesktopMediaID if the specified |id| is invalid, i.e. wasn't generated
// using RegisterStream() or if it was generated for a different // using RegisterStream() or if it was generated for a different
// RenderFrame/origin. Otherwise returns ID of the source and removes it from // RenderFrame/origin/type. Otherwise returns ID of the source and removes it
// the registry. // from the registry.
virtual DesktopMediaID RequestMediaForStreamId( virtual DesktopMediaID RequestMediaForStreamId(
const std::string& id, const std::string& id,
int render_process_id, int render_process_id,
int render_frame_id, int render_frame_id,
const GURL& origin, const GURL& origin,
std::string* extension_name) = 0; std::string* extension_name,
const DesktopStreamRegistryType type) = 0;
}; };
} // namespace content } // namespace content
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment