Commit a1c5be64 authored by garykac's avatar garykac Committed by Commit Bot

Move ScreenRecording permission check to /ui/base/cocoa

This needs to move to a shared location so that the same code can
be used by the Chromoting host.

Change-Id: If860352ef8583d47f268d5cb5b964e3c7f0a2f25
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2141214Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: Gary Kacmarcik <garykac@chromium.org>
Cr-Commit-Position: refs/heads/master@{#757568}
parent 2b17c00a
......@@ -35,6 +35,7 @@
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "media/base/media_switches.h"
#include "ui/base/cocoa/permissions_utils.h"
namespace system_media_permissions {
......@@ -175,37 +176,9 @@ bool IsScreenCaptureAllowed() {
features::kMacSystemScreenCapturePermissionCheck)) {
return true;
}
base::ScopedCFTypeRef<CFArrayRef> window_list(
CGWindowListCopyWindowInfo(kCGWindowListOptionAll, kCGNullWindowID));
int current_pid = [[NSProcessInfo processInfo] processIdentifier];
for (NSDictionary* window in base::mac::CFToNSCast(window_list.get())) {
NSNumber* window_pid =
[window objectForKey:base::mac::CFToNSCast(kCGWindowOwnerPID)];
if (!window_pid || [window_pid integerValue] == current_pid)
continue;
NSString* window_name =
[window objectForKey:base::mac::CFToNSCast(kCGWindowName)];
if (!window_name)
continue;
NSNumber* layer =
[window objectForKey:base::mac::CFToNSCast(kCGWindowLayer)];
if (!layer)
continue;
NSInteger layer_integer = [layer integerValue];
if (layer_integer == CGWindowLevelForKey(kCGNormalWindowLevelKey) ||
layer_integer == CGWindowLevelForKey(kCGDockWindowLevelKey)) {
return true;
}
}
return false;
}
// Screen capture is always allowed in older macOS versions.
return true;
return ui::IsScreenCaptureAllowed();
}
} // namespace
......
......@@ -17,6 +17,7 @@
#include "base/single_thread_task_runner.h"
#include "base/strings/sys_string_conversions.h"
#include "remoting/base/string_resources.h"
#include "ui/base/cocoa/permissions_utils.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/l10n_util_mac.h"
......@@ -117,44 +118,8 @@ bool CanInjectInput() {
return AXIsProcessTrusted();
}
// Heuristic to check screen capture permission. See http://crbug.com/993692
// Screen capture is considered allowed if the name of at least one normal
// or dock window running on another process is visible.
// Copied from
// chrome/browser/media/webrtc/system_media_capture_permissions_mac.mm
// TODO(garykac) Move webrtc version where it can be shared.
bool CanRecordScreen() {
if (@available(macOS 10.15, *)) {
base::ScopedCFTypeRef<CFArrayRef> window_list(
CGWindowListCopyWindowInfo(kCGWindowListOptionAll, kCGNullWindowID));
int current_pid = [[NSProcessInfo processInfo] processIdentifier];
for (NSDictionary* window in base::mac::CFToNSCast(window_list.get())) {
NSNumber* window_pid =
[window objectForKey:base::mac::CFToNSCast(kCGWindowOwnerPID)];
if (!window_pid || [window_pid integerValue] == current_pid)
continue;
NSString* window_name =
[window objectForKey:base::mac::CFToNSCast(kCGWindowName)];
if (!window_name)
continue;
NSNumber* layer =
[window objectForKey:base::mac::CFToNSCast(kCGWindowLayer)];
if (!layer)
continue;
NSInteger layer_integer = [layer integerValue];
if (layer_integer == CGWindowLevelForKey(kCGNormalWindowLevelKey) ||
layer_integer == CGWindowLevelForKey(kCGDockWindowLevelKey)) {
return true;
}
}
return false;
}
// Screen capture is always allowed in older macOS versions.
return true;
return ui::IsScreenCaptureAllowed();
}
// MacOs 10.14+ requires an additional runtime permission for injecting input
......
......@@ -266,6 +266,8 @@ jumbo_component("base") {
"cocoa/focus_window_set.mm",
"cocoa/menu_controller.h",
"cocoa/menu_controller.mm",
"cocoa/permissions_utils.h",
"cocoa/permissions_utils.mm",
"cocoa/quartz_util.h",
"cocoa/quartz_util.mm",
"cocoa/remote_accessibility_api.h",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_BASE_COCOA_PERMISSIONS_UTILS_H_
#define UI_BASE_COCOA_PERMISSIONS_UTILS_H_
#include "ui/base/ui_base_export.h"
namespace ui {
// Heuristic to check screen capture permission.
// Starting on macOS 10.15, the ability to screen capture is restricted and
// requires a permission authorization. There is no direct way to query the
// permission state, so this uses a heuristic to evaluate whether the permission
// has been granted.
UI_BASE_EXPORT bool IsScreenCaptureAllowed();
} // namespace ui
#endif // UI_BASE_COCOA_PERMISSIONS_UTILS_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/base/cocoa/permissions_utils.h"
#include <CoreGraphics/CoreGraphics.h>
#include <Foundation/Foundation.h>
#include "base/mac/foundation_util.h"
#include "base/mac/scoped_cftyperef.h"
namespace ui {
// Screen Capture is considered allowed if the name of at least one normal
// or dock window running on another process is visible.
// See https://crbug.com/993692.
bool IsScreenCaptureAllowed() {
if (@available(macOS 10.15, *)) {
base::ScopedCFTypeRef<CFArrayRef> window_list(
CGWindowListCopyWindowInfo(kCGWindowListOptionAll, kCGNullWindowID));
int current_pid = [[NSProcessInfo processInfo] processIdentifier];
for (NSDictionary* window in base::mac::CFToNSCast(window_list.get())) {
NSNumber* window_pid =
[window objectForKey:base::mac::CFToNSCast(kCGWindowOwnerPID)];
if (!window_pid || [window_pid integerValue] == current_pid)
continue;
NSString* window_name =
[window objectForKey:base::mac::CFToNSCast(kCGWindowName)];
if (!window_name)
continue;
NSNumber* layer =
[window objectForKey:base::mac::CFToNSCast(kCGWindowLayer)];
if (!layer)
continue;
NSInteger layer_integer = [layer integerValue];
if (layer_integer == CGWindowLevelForKey(kCGNormalWindowLevelKey) ||
layer_integer == CGWindowLevelForKey(kCGDockWindowLevelKey)) {
return true;
}
}
return false;
}
// Screen capture is always allowed in older macOS versions.
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