Commit 0d9177bc authored by Weiyong Yao's avatar Weiyong Yao Committed by Commit Bot

desktopCapture: Focus on the tab with picker for easy source change

When to change source during a tab sharing session, the new picker will
only be available on the tab which starts the session. If that tab is
not on the front, user may probably miss the picker.

This cl is to bring the tab up to front before showing the picker for
easy notice. If use selects to cancel the source changing, this cl will
activate the previous shared tab to continue the sharing session.

Bug: 892201
Change-Id: I51c6436095df37f3afb3d28aebbfb9e4bb03f3a5
Reviewed-on: https://chromium-review.googlesource.com/c/1423700Reviewed-by: default avatarEmircan Uysaler <emircan@chromium.org>
Commit-Queue: Weiyong Yao <braveyao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#625800}
parent 57dbd81a
...@@ -457,6 +457,10 @@ void DesktopCaptureAccessHandler::ProcessQueuedAccessRequest( ...@@ -457,6 +457,10 @@ void DesktopCaptureAccessHandler::ProcessQueuedAccessRequest(
: true; : true;
pending_request.picker->Show(picker_params, std::move(source_lists), pending_request.picker->Show(picker_params, std::move(source_lists),
done_callback); done_callback);
// Focus on the tab with the picker for easy access.
if (auto* delegate = web_contents->GetDelegate())
delegate->ActivateContents(web_contents);
} }
void DesktopCaptureAccessHandler::OnPickerDialogResults( void DesktopCaptureAccessHandler::OnPickerDialogResults(
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include "content/browser/renderer_host/media/video_capture_manager.h" #include "content/browser/renderer_host/media/video_capture_manager.h"
#include "content/browser/renderer_host/media/video_capture_provider_switcher.h" #include "content/browser/renderer_host/media/video_capture_provider_switcher.h"
#include "content/browser/renderer_host/render_process_host_impl.h" #include "content/browser/renderer_host/render_process_host_impl.h"
#include "content/browser/renderer_host/render_view_host_delegate.h"
#include "content/browser/screenlock_monitor/screenlock_monitor.h" #include "content/browser/screenlock_monitor/screenlock_monitor.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
...@@ -49,7 +50,9 @@ ...@@ -49,7 +50,9 @@
#include "content/public/browser/desktop_media_id.h" #include "content/public/browser/desktop_media_id.h"
#include "content/public/browser/desktop_streams_registry.h" #include "content/public/browser/desktop_streams_registry.h"
#include "content/public/browser/media_observer.h" #include "content/public/browser/media_observer.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents_media_capture_id.h" #include "content/public/browser/web_contents_media_capture_id.h"
#include "content/public/common/content_client.h" #include "content/public/common/content_client.h"
#include "content/public/common/content_features.h" #include "content/public/common/content_features.h"
...@@ -1518,7 +1521,19 @@ void MediaStreamManager::FinalizeRequestFailed( ...@@ -1518,7 +1521,19 @@ void MediaStreamManager::FinalizeRequestFailed(
break; break;
} }
case blink::MEDIA_DEVICE_UPDATE: { case blink::MEDIA_DEVICE_UPDATE: {
// Fail to change desktop capture source, keep everything unchanged. // Fail to change desktop capture source, keep everything unchanged and
// bring the previous shared tab to the front.
for (const auto& device : request->devices) {
if (device.type == blink::MEDIA_GUM_DESKTOP_VIDEO_CAPTURE) {
DesktopMediaID source = DesktopMediaID::Parse(device.id);
DCHECK(source.type == DesktopMediaID::TYPE_WEB_CONTENTS);
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::UI},
base::BindOnce(&MediaStreamManager::ActivateTabOnUIThread,
base::Unretained(this), source));
break;
}
}
return; return;
} }
default: default:
...@@ -2157,6 +2172,15 @@ MediaStreamDevices MediaStreamManager::ConvertToMediaStreamDevices( ...@@ -2157,6 +2172,15 @@ MediaStreamDevices MediaStreamManager::ConvertToMediaStreamDevices(
return devices; return devices;
} }
void MediaStreamManager::ActivateTabOnUIThread(const DesktopMediaID source) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
RenderFrameHost* rfh =
RenderFrameHost::FromID(source.web_contents_id.render_process_id,
source.web_contents_id.main_render_frame_id);
if (rfh)
rfh->GetRenderViewHost()->GetDelegate()->Activate();
}
void MediaStreamManager::OnStreamStarted(const std::string& label) { void MediaStreamManager::OnStreamStarted(const std::string& label) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
DeviceRequest* const request = FindRequest(label); DeviceRequest* const request = FindRequest(label);
......
...@@ -490,6 +490,9 @@ class CONTENT_EXPORT MediaStreamManager ...@@ -490,6 +490,9 @@ class CONTENT_EXPORT MediaStreamManager
blink::MediaStreamType stream_type, blink::MediaStreamType stream_type,
const blink::WebMediaDeviceInfoArray& device_infos); const blink::WebMediaDeviceInfoArray& device_infos);
// Activate the specified tab and bring it to the front.
void ActivateTabOnUIThread(const DesktopMediaID source);
media::AudioSystem* const audio_system_; // not owned media::AudioSystem* const audio_system_; // not owned
scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_; scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_;
scoped_refptr<VideoCaptureManager> video_capture_manager_; scoped_refptr<VideoCaptureManager> video_capture_manager_;
......
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