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(
content::RenderFrameHost* const main_frame = web_contents()->GetMainFrame();
result = content::DesktopStreamsRegistry::GetInstance()->RegisterStream(
main_frame->GetProcess()->GetID(), main_frame->GetRoutingID(), origin_,
source, extension()->name());
source, extension()->name(), content::kRegistryStreamTypeDesktop);
}
Options options;
......
......@@ -321,7 +321,7 @@ std::string TabCaptureRegistry::AddRequest(
if (main_frame) {
device_id = content::DesktopStreamsRegistry::GetInstance()->RegisterStream(
main_frame->GetProcess()->GetID(), main_frame->GetRoutingID(), origin,
source, extension_name);
source, extension_name, content::kRegistryStreamTypeTab);
}
return device_id;
......
......@@ -420,7 +420,8 @@ void DesktopCaptureAccessHandler::HandleRequest(
content::DesktopStreamsRegistry::GetInstance()->RequestMediaForStreamId(
request.requested_video_device_id,
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.
......
......@@ -50,7 +50,8 @@ std::string DesktopStreamsRegistryImpl::RegisterStream(
int render_frame_id,
const GURL& origin,
const DesktopMediaID& source,
const std::string& extension_name) {
const std::string& extension_name,
const DesktopStreamRegistryType type) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
std::string id = GenerateRandomStreamId();
......@@ -61,6 +62,7 @@ std::string DesktopStreamsRegistryImpl::RegisterStream(
stream.origin = origin;
stream.source = source;
stream.extension_name = extension_name;
stream.type = type;
BrowserThread::PostDelayedTask(
BrowserThread::UI, FROM_HERE,
......@@ -76,7 +78,8 @@ DesktopMediaID DesktopStreamsRegistryImpl::RequestMediaForStreamId(
int render_process_id,
int render_frame_id,
const GURL& origin,
std::string* extension_name) {
std::string* extension_name,
const DesktopStreamRegistryType type) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
StreamsMap::iterator it = approved_streams_.find(id);
......@@ -86,7 +89,7 @@ DesktopMediaID DesktopStreamsRegistryImpl::RequestMediaForStreamId(
if (it == approved_streams_.end() ||
render_process_id != it->second.render_process_id ||
render_frame_id != it->second.render_frame_id ||
origin != it->second.origin) {
origin != it->second.origin || type != it->second.type) {
return DesktopMediaID();
}
......
......@@ -28,13 +28,16 @@ class CONTENT_EXPORT DesktopStreamsRegistryImpl
int render_frame_id,
const GURL& origin,
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(
const std::string& id,
int render_process_id,
int render_frame_id,
const GURL& origin,
std::string* extension_name) override;
std::string* extension_name,
const DesktopStreamRegistryType type) override;
private:
// Type used to store list of accepted desktop media streams.
......@@ -46,6 +49,7 @@ class CONTENT_EXPORT DesktopStreamsRegistryImpl
GURL origin;
DesktopMediaID source;
std::string extension_name;
DesktopStreamRegistryType type;
};
typedef std::map<std::string, ApprovedDesktopMediaStream> StreamsMap;
......
......@@ -1175,7 +1175,7 @@ DesktopMediaID MediaStreamManager::ResolveTabCaptureDeviceIdOnUIThread(
// Resolve DesktopMediaID for the specified device id.
return DesktopStreamsRegistry::GetInstance()->RequestMediaForStreamId(
capture_device_id, requesting_process_id, requesting_frame_id, origin,
nullptr);
nullptr, kRegistryStreamTypeTab);
}
void MediaStreamManager::FinishTabCaptureRequestSetupWithDeviceId(
......
......@@ -11,10 +11,15 @@ class GURL;
namespace content {
enum DesktopStreamRegistryType {
kRegistryStreamTypeDesktop,
kRegistryStreamTypeTab
};
struct DesktopMediaID;
// 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.
class CONTENT_EXPORT DesktopStreamsRegistry {
public:
......@@ -22,27 +27,30 @@ class CONTENT_EXPORT DesktopStreamsRegistry {
static DesktopStreamsRegistry* GetInstance();
// Adds new stream to the registry. Called by the implementation of
// desktopCapture.chooseDesktopMedia() API after user has approved access to
// |source| for the |origin|. Returns identifier of the new stream.
// Adds new stream to the registry. Called by the implementation of either
// desktopCapture API or tabCapture API, differentiated by |type|, after user
// has approved access to |source| for the |origin|. Returns identifier of
// the new stream.
// |render_frame_id| refers to the RenderFrame requesting the stream.
virtual std::string RegisterStream(int render_process_id,
int render_frame_id,
const GURL& origin,
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
// DesktopMediaID if the specified |id| is invalid, i.e. wasn't generated
// using RegisterStream() or if it was generated for a different
// RenderFrame/origin. Otherwise returns ID of the source and removes it from
// the registry.
// RenderFrame/origin/type. Otherwise returns ID of the source and removes it
// from the registry.
virtual DesktopMediaID RequestMediaForStreamId(
const std::string& id,
int render_process_id,
int render_frame_id,
const GURL& origin,
std::string* extension_name) = 0;
std::string* extension_name,
const DesktopStreamRegistryType type) = 0;
};
} // 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