Commit 36deecf7 authored by Jordan Bayles's avatar Jordan Bayles Committed by Commit Bot

Show Screen Recording prompt on Mac 10.15+

Currently, in Chrome when trying to cast the screen we check for
permission and tell the user to check System settings if we aren't
allowed to cast the screen.  However, apps don't show up in System
settings until the user has already approved or denied permission for
them through a modal dialog that only appears if you try to capture a
stream in your application without checking permission.

This patch adds a call to CGDisplayStreamCreate in a new method in
permissions_utils.h,  TryPromptUserForScreenCapture.

Bug: 1139695
Change-Id: I719aa6fb4188e723faa1fee3d3b51243edb0059e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2495824
Commit-Queue: Jordan Bayles <jophba@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Reviewed-by: default avatarTakumi Fujimoto <takumif@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821528}
parent e4e77790
......@@ -386,7 +386,8 @@ bool MediaRouterUI::CreateRoute(const MediaSink::Id& sink_id,
const bool screen_capture_allowed =
screen_capture_allowed_for_testing_.has_value()
? *screen_capture_allowed_for_testing_
: ui::IsScreenCaptureAllowed();
: (ui::IsScreenCaptureAllowed() ||
ui::TryPromptUserForScreenCapture());
if (!screen_capture_allowed) {
SendIssueForScreenPermission(sink_id);
return false;
......
......@@ -16,6 +16,15 @@ namespace ui {
// has been granted.
COMPONENT_EXPORT(UI_BASE) bool IsScreenCaptureAllowed();
// Heuristic to prompt the user if they have never been prompted for permission.
// Starting on macOS 10.15, not only can we not tell if we have has permission
// granted, we also can't tell if we have requested the permission before. We
// must try capture a stream and the OS will show a modal dialog asking the user
// for permission if Chrome is not in the permission app list, then return
// a stream based on whether permission is granted.
// Returns whether or not permission was granted.
COMPONENT_EXPORT(UI_BASE) bool TryPromptUserForScreenCapture();
} // namespace ui
#endif // UI_BASE_COCOA_PERMISSIONS_UTILS_H_
......@@ -8,6 +8,7 @@
#include <Foundation/Foundation.h>
#include "base/mac/foundation_util.h"
#include "base/mac/mac_util.h"
#include "base/mac/scoped_cftyperef.h"
namespace ui {
......@@ -16,7 +17,7 @@ namespace ui {
// or dock window running on another process is visible.
// See https://crbug.com/993692.
bool IsScreenCaptureAllowed() {
if (@available(macOS 10.15, *)) {
if (base::mac::IsAtLeastOS10_15()) {
base::ScopedCFTypeRef<CFArrayRef> window_list(
CGWindowListCopyWindowInfo(kCGWindowListOptionAll, kCGNullWindowID));
int current_pid = [[NSProcessInfo processInfo] processIdentifier];
......@@ -49,4 +50,22 @@ bool IsScreenCaptureAllowed() {
return true;
}
bool TryPromptUserForScreenCapture() {
if (base::mac::IsAtLeastOS10_15()) {
// On 10.15+, macOS will show the permissions prompt for Screen Recording
// if we request to create a display stream and our application is not
// in the applications list in System permissions. Stream creation will
// fail if the user denies permission, or if our application is already
// in the system permssion and is unchecked.
base::ScopedCFTypeRef<CGDisplayStreamRef> stream(CGDisplayStreamCreate(
CGMainDisplayID(), 1, 1, 'BGRA', nullptr,
^(CGDisplayStreamFrameStatus status, uint64_t displayTime,
IOSurfaceRef frameSurface, CGDisplayStreamUpdateRef updateRef){
}));
return stream != nullptr;
} else {
return true;
}
}
} // namespace ui
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