electron/patches/common/chromium/mas_no_private_api.patch

422 lines
16 KiB
Diff
Raw Normal View History

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2018-09-21 00:30:26 +00:00
From: Cheng Zhao <zcbenz@gmail.com>
2018-10-09 17:37:20 +00:00
Date: Tue, 9 Oct 2018 10:36:20 -0700
2018-09-21 00:30:26 +00:00
Subject: mas_no_private_api.patch
Guard usages in blink of private Mac APIs by MAS_BUILD, so they can be
excluded for people who want to submit their apps to the Mac App store.
diff --git a/content/browser/accessibility/browser_accessibility_cocoa.h b/content/browser/accessibility/browser_accessibility_cocoa.h
index 44c85b5ad571c39c4580cb9d0cdf08f694c1dfb4..1714c403edf21092e43192f25cf0c19f50dd8486 100644
--- a/content/browser/accessibility/browser_accessibility_cocoa.h
+++ b/content/browser/accessibility/browser_accessibility_cocoa.h
@@ -111,7 +111,9 @@ struct AXTextEdit {
@property(nonatomic, readonly) NSNumber* enabled;
// Returns a text marker that points to the last character in the document that
// can be selected with Voiceover.
+#ifndef MAS_BUILD
@property(nonatomic, readonly) id endTextMarker;
+#endif
@property(nonatomic, readonly) NSNumber* expanded;
@property(nonatomic, readonly) NSNumber* focused;
@property(nonatomic, readonly) NSNumber* grabbed;
@@ -147,12 +149,16 @@ struct AXTextEdit {
@property(nonatomic, readonly) NSArray* selectedChildren;
@property(nonatomic, readonly) NSString* selectedText;
@property(nonatomic, readonly) NSValue* selectedTextRange;
+#ifndef MAS_BUILD
@property(nonatomic, readonly) id selectedTextMarkerRange;
+#endif
@property(nonatomic, readonly) NSValue* size;
@property(nonatomic, readonly) NSString* sortDirection;
// Returns a text marker that points to the first character in the document that
// can be selected with Voiceover.
+#ifndef MAS_BUILD
@property(nonatomic, readonly) id startTextMarker;
+#endif
// A string indicating the subrole of this object as far as accessibility
// is concerned.
@property(nonatomic, readonly) NSString* subrole;
diff --git a/content/browser/accessibility/browser_accessibility_cocoa.mm b/content/browser/accessibility/browser_accessibility_cocoa.mm
2018-10-24 23:25:48 +00:00
index 06db282cd7415e21d91f4209a51b96f408475c75..980e2387756ea8e01396b84d95844964bba90d0c 100644
--- a/content/browser/accessibility/browser_accessibility_cocoa.mm
+++ b/content/browser/accessibility/browser_accessibility_cocoa.mm
2018-10-24 23:25:48 +00:00
@@ -135,6 +135,7 @@
// VoiceOver uses -1 to mean "no limit" for AXResultsLimit.
const int kAXResultsLimitNoLimit = -1;
+#ifndef MAS_BUILD
extern "C" {
// The following are private accessibility APIs required for cursor navigation
2018-10-24 23:25:48 +00:00
@@ -341,6 +342,7 @@ void AddMisspelledTextAttributes(
AddMisspelledTextAttributes(text_only_objects, attributed_text);
return [attributed_text attributedSubstringFromRange:range];
}
+#endif
// Returns an autoreleased copy of the AXNodeData's attribute.
NSString* NSStringForStringAttribute(
2018-10-24 23:25:48 +00:00
@@ -595,7 +597,9 @@ + (void)initialize {
{NSAccessibilityDOMIdentifierAttribute, @"domIdentifier"},
{NSAccessibilityEditableAncestorAttribute, @"editableAncestor"},
{NSAccessibilityEnabledAttribute, @"enabled"},
+#ifndef MAS_BUILD
{NSAccessibilityEndTextMarkerAttribute, @"endTextMarker"},
+#endif
{NSAccessibilityExpandedAttribute, @"expanded"},
2018-09-21 00:30:26 +00:00
{NSAccessibilityFocusableAncestorAttribute, @"focusableAncestor"},
{NSAccessibilityFocusedAttribute, @"focused"},
2018-10-24 23:25:48 +00:00
@@ -630,13 +634,17 @@ + (void)initialize {
{NSAccessibilityRowsAttribute, @"rows"},
// TODO(aboxhall): expose
// NSAccessibilityServesAsTitleForUIElementsAttribute
+#ifndef MAS_BUILD
{NSAccessibilityStartTextMarkerAttribute, @"startTextMarker"},
+#endif
{NSAccessibilitySelectedAttribute, @"selected"},
{NSAccessibilitySelectedChildrenAttribute, @"selectedChildren"},
{NSAccessibilitySelectedTextAttribute, @"selectedText"},
{NSAccessibilitySelectedTextRangeAttribute, @"selectedTextRange"},
+#ifndef MAS_BUILD
{NSAccessibilitySelectedTextMarkerRangeAttribute,
@"selectedTextMarkerRange"},
+#endif
{NSAccessibilitySizeAttribute, @"size"},
{NSAccessibilitySortDirectionAttribute, @"sortDirection"},
{NSAccessibilitySubroleAttribute, @"subrole"},
2018-10-24 23:25:48 +00:00
@@ -1116,6 +1124,7 @@ - (NSNumber*)enabled {
2018-09-21 00:30:26 +00:00
ax::mojom::Restriction::kDisabled];
}
+#ifndef MAS_BUILD
// Returns a text marker that points to the last character in the document that
// can be selected with VoiceOver.
- (id)endTextMarker {
2018-10-24 23:25:48 +00:00
@@ -1126,6 +1135,7 @@ - (id)endTextMarker {
BrowserAccessibilityPositionInstance position = root->CreatePositionAt(0);
return CreateTextMarker(position->CreatePositionAtEndOfAnchor());
}
+#endif
- (NSNumber*)expanded {
if (![self instanceActive])
2018-10-24 23:25:48 +00:00
@@ -2034,6 +2044,7 @@ - (NSValue*)selectedTextRange {
return [NSValue valueWithRange:NSMakeRange(selStart, selLength)];
}
+#ifndef MAS_BUILD
- (id)selectedTextMarkerRange {
if (![self instanceActive])
return nil;
2018-10-24 23:25:48 +00:00
@@ -2066,6 +2077,7 @@ - (id)selectedTextMarkerRange {
anchorAffinity, *focusObject,
focusOffset, focusAffinity));
}
+#endif
- (NSValue*)size {
if (![self instanceActive])
2018-10-24 23:25:48 +00:00
@@ -2098,6 +2110,7 @@ - (NSString*)sortDirection {
return nil;
}
+#ifndef MAS_BUILD
// Returns a text marker that points to the first character in the document that
// can be selected with VoiceOver.
- (id)startTextMarker {
2018-10-24 23:25:48 +00:00
@@ -2108,6 +2121,7 @@ - (id)startTextMarker {
BrowserAccessibilityPositionInstance position = root->CreatePositionAt(0);
return CreateTextMarker(position->CreatePositionAtStartOfAnchor());
}
+#endif
// Returns a subrole based upon the role.
- (NSString*) subrole {
2018-10-24 23:25:48 +00:00
@@ -2413,12 +2427,14 @@ - (NSAttributedString*)attributedValueForRange:(NSRange)range {
NSMutableAttributedString* attributedValue =
[[[NSMutableAttributedString alloc] initWithString:value] autorelease];
+#ifndef MAS_BUILD
2018-09-21 00:30:26 +00:00
if (!owner_->IsTextOnlyObject()) {
std::vector<const BrowserAccessibility*> textOnlyObjects =
2018-09-21 00:30:26 +00:00
BrowserAccessibilityManager::FindTextOnlyObjectsInRange(*owner_,
*owner_);
AddMisspelledTextAttributes(textOnlyObjects, attributedValue);
}
+#endif
return [attributedValue attributedSubstringFromRange:range];
}
2018-10-24 23:25:48 +00:00
@@ -2535,6 +2551,7 @@ - (id)accessibilityAttributeValue:(NSString*)attribute
return nil;
}
+#ifndef MAS_BUILD
if ([attribute isEqualToString:@"AXUIElementForTextMarker"]) {
BrowserAccessibilityPositionInstance position =
CreatePositionFromTextMarker(parameter);
2018-10-24 23:25:48 +00:00
@@ -2712,6 +2729,7 @@ - (id)accessibilityAttributeValue:(NSString*)attribute
NSString* text = GetTextForTextMarkerRange(parameter);
return [NSNumber numberWithInt:[text length]];
}
+#endif
if ([attribute isEqualToString:
NSAccessibilityBoundsForRangeParameterizedAttribute]) {
2018-10-24 23:25:48 +00:00
@@ -2749,6 +2767,7 @@ - (id)accessibilityAttributeValue:(NSString*)attribute
return nil;
}
+#ifndef MAS_BUILD
if ([attribute isEqualToString:
NSAccessibilityLineTextMarkerRangeForTextMarkerParameterizedAttribute]) {
BrowserAccessibilityPositionInstance position =
2018-10-24 23:25:48 +00:00
@@ -2828,6 +2847,7 @@ AXPlatformRange range(position->CreatePreviousLineStartPosition(
return @(child->GetIndexInParent());
}
+#endif
return nil;
}
diff --git a/content/browser/accessibility/browser_accessibility_manager_mac.mm b/content/browser/accessibility/browser_accessibility_manager_mac.mm
2018-10-24 23:25:48 +00:00
index 09cb7f8a55d1d85abbe88a2bfe76ff4b9c8f253b..18e262218fe657cde910e4b3eee7a8b524b7b5e8 100644
--- a/content/browser/accessibility/browser_accessibility_manager_mac.mm
+++ b/content/browser/accessibility/browser_accessibility_manager_mac.mm
2018-10-24 23:25:48 +00:00
@@ -459,6 +459,7 @@ void PostAnnouncementNotification(NSString* announcement) {
[user_info setObject:native_focus_object
forKey:NSAccessibilityTextChangeElement];
+#ifndef MAS_BUILD
id selected_text = [native_focus_object selectedTextMarkerRange];
if (selected_text) {
NSString* const NSAccessibilitySelectedTextMarkerRangeAttribute =
2018-10-24 23:25:48 +00:00
@@ -466,6 +467,7 @@ void PostAnnouncementNotification(NSString* announcement) {
[user_info setObject:selected_text
forKey:NSAccessibilitySelectedTextMarkerRangeAttribute];
}
+#endif
}
}
diff --git a/content/renderer/renderer_main_platform_delegate_mac.mm b/content/renderer/renderer_main_platform_delegate_mac.mm
2018-10-24 23:25:48 +00:00
index e2122fb5fe931c911f92e709d1a643cd575972f3..da6847eea755a0b564fcd7daa36c4badc014c7f3 100644
--- a/content/renderer/renderer_main_platform_delegate_mac.mm
+++ b/content/renderer/renderer_main_platform_delegate_mac.mm
2018-10-24 23:25:48 +00:00
@@ -23,10 +23,12 @@
#include "sandbox/mac/system_services.h"
#include "services/service_manager/sandbox/mac/sandbox_mac.h"
+#ifndef MAS_BUILD
extern "C" {
void CGSSetDenyWindowServerConnections(bool);
void CGSShutdownServerConnections();
};
+#endif
namespace content {
2018-10-24 23:25:48 +00:00
@@ -35,6 +37,7 @@
// This disconnects from the window server, and then indicates that Chrome
// should continue execution without access to launchservicesd.
void DisconnectWindowServer() {
+#ifndef MAS_BUILD
// Now disconnect from WindowServer, after all objects have been warmed up.
// Shutting down the connection requires connecting to WindowServer,
// so do this before actually engaging the sandbox. This may cause two log
2018-10-24 23:25:48 +00:00
@@ -43,6 +46,7 @@ void DisconnectWindowServer() {
CGSShutdownServerConnections();
sandbox::DisableLaunchServices();
+#endif
}
// You are about to read a pretty disgusting hack. In a static initializer,
diff --git a/device/bluetooth/bluetooth_adapter_mac.mm b/device/bluetooth/bluetooth_adapter_mac.mm
2018-10-24 23:25:48 +00:00
index 24a63be8a4be4f74f78fec810490d16cffaf43c1..414423de009d14ac6ac7bab2a260b3e0d7085d1f 100644
--- a/device/bluetooth/bluetooth_adapter_mac.mm
+++ b/device/bluetooth/bluetooth_adapter_mac.mm
2018-09-21 00:30:26 +00:00
@@ -34,6 +34,7 @@
#include "device/bluetooth/bluetooth_low_energy_peripheral_manager_delegate.h"
#include "device/bluetooth/bluetooth_socket_mac.h"
+#ifndef MAS_BUILD
extern "C" {
// Undocumented IOBluetooth Preference API [1]. Used by `blueutil` [2] and
// `Karabiner` [3] to programmatically control the Bluetooth state. Calling the
2018-10-24 23:25:48 +00:00
@@ -47,6 +48,7 @@
// [4] https://support.apple.com/kb/PH25091
void IOBluetoothPreferenceSetControllerPowerState(int state);
}
+#endif
namespace {
2018-10-24 23:25:48 +00:00
@@ -120,8 +122,10 @@ CBCentralManagerState GetCBManagerState(CBCentralManager* manager) {
controller_state_function_(
base::BindRepeating(&BluetoothAdapterMac::GetHostControllerState,
base::Unretained(this))),
+#ifndef MAS_BUILD
power_state_function_(
base::BindRepeating(IOBluetoothPreferenceSetControllerPowerState)),
+#endif
should_update_name_(true),
classic_discovery_manager_(
BluetoothDiscoveryManagerMac::CreateClassic(this)),
2018-10-24 23:25:48 +00:00
@@ -317,8 +321,12 @@ CBCentralManagerState GetCBManagerState(CBCentralManager* manager) {
}
bool BluetoothAdapterMac::SetPoweredImpl(bool powered) {
+#ifndef MAS_BUILD
power_state_function_.Run(base::strict_cast<int>(powered));
return true;
+#else
+ return false;
+#endif
}
void BluetoothAdapterMac::RemovePairingDelegateInternal(
diff --git a/media/audio/BUILD.gn b/media/audio/BUILD.gn
2018-10-24 23:25:48 +00:00
index 6b7eccaf55c1b81a8db03c96f9c4353716fa8eed..7011139d73253a9f6771f0be4e6c8827493a64ea 100644
--- a/media/audio/BUILD.gn
+++ b/media/audio/BUILD.gn
2018-10-24 23:25:48 +00:00
@@ -202,6 +202,12 @@ source_set("audio") {
"mac/scoped_audio_unit.cc",
"mac/scoped_audio_unit.h",
]
+ if (is_mas_build) {
+ sources -= [
+ "mac/coreaudio_dispatch_override.cc",
+ "mac/coreaudio_dispatch_override.h",
+ ]
+ }
libs += [
"AudioToolbox.framework",
"AudioUnit.framework",
diff --git a/media/audio/mac/audio_manager_mac.cc b/media/audio/mac/audio_manager_mac.cc
index 74dd21d45b4ff8da203ef7d759bbccf05033f862..d7dd95b4d461981c36061d1031c932fcb6f2e31b 100644
--- a/media/audio/mac/audio_manager_mac.cc
+++ b/media/audio/mac/audio_manager_mac.cc
2018-09-21 00:30:26 +00:00
@@ -868,7 +868,7 @@ AudioParameters AudioManagerMac::GetPreferredOutputStreamParameters(
void AudioManagerMac::InitializeOnAudioThread() {
DCHECK(GetTaskRunner()->BelongsToCurrentThread());
- InitializeCoreAudioDispatchOverride();
+ // InitializeCoreAudioDispatchOverride();
power_observer_.reset(new AudioPowerObserver());
}
diff --git a/net/dns/dns_config_service_posix.cc b/net/dns/dns_config_service_posix.cc
index 06e9d7969c0f21726de216cd670e4752c8aff6ab..6fc766e981fdc59fcbb3c0780fde87c5cd953e2d 100644
--- a/net/dns/dns_config_service_posix.cc
+++ b/net/dns/dns_config_service_posix.cc
@@ -242,6 +242,7 @@ class DnsConfigServicePosix::Watcher {
bool Watch() {
bool success = true;
+#ifndef MAS_BUILD
if (!config_watcher_.Watch(base::Bind(&Watcher::OnConfigChanged,
base::Unretained(this)))) {
LOG(ERROR) << "DNS config watch failed to start.";
@@ -263,6 +264,7 @@ class DnsConfigServicePosix::Watcher {
DNS_CONFIG_WATCH_MAX);
}
#endif // !defined(OS_ANDROID) && !defined(OS_IOS)
+#endif
return success;
}
diff --git a/sandbox/mac/sandbox_compiler.cc b/sandbox/mac/sandbox_compiler.cc
index e524aa7b851022abed1edac39e18d8d92e5349b4..718d3f963da5c1a15a1bdb0e6043f89bc0f940f8 100644
--- a/sandbox/mac/sandbox_compiler.cc
+++ b/sandbox/mac/sandbox_compiler.cc
@@ -28,6 +28,7 @@ bool SandboxCompiler::InsertStringParam(const std::string& key,
}
bool SandboxCompiler::CompileAndApplyProfile(std::string* error) {
+#ifndef MAS_BUILD
char* error_internal = nullptr;
std::vector<const char*> params;
@@ -44,6 +45,7 @@ bool SandboxCompiler::CompileAndApplyProfile(std::string* error) {
sandbox::Seatbelt::FreeError(error_internal);
return false;
}
+#endif
return true;
}
diff --git a/sandbox/mac/seatbelt.cc b/sandbox/mac/seatbelt.cc
index dfba0bded9e34be276ed111cbab44210a95b9875..876f96999f53b4666508f783a33cea245d1bc03e 100644
--- a/sandbox/mac/seatbelt.cc
+++ b/sandbox/mac/seatbelt.cc
@@ -64,7 +64,11 @@ void Seatbelt::FreeError(char* errorbuf) {
// static
bool Seatbelt::IsSandboxed() {
+#ifndef MAS_BUILD
return ::sandbox_check(getpid(), NULL, 0);
+#else
+ return true;
+#endif
}
} // namespace sandbox
diff --git a/sandbox/mac/seatbelt_extension.cc b/sandbox/mac/seatbelt_extension.cc
index 9073364142e8f98c8872d9b5509f92f433e06624..2356add74dfae98299a4e2b207aa26fc109f47f3 100644
--- a/sandbox/mac/seatbelt_extension.cc
+++ b/sandbox/mac/seatbelt_extension.cc
@@ -8,6 +8,7 @@
#include "base/memory/ptr_util.h"
#include "sandbox/mac/seatbelt_extension_token.h"
+#ifndef MAS_BUILD
// libsandbox private API.
extern "C" {
extern const char* APP_SANDBOX_READ;
@@ -18,6 +19,7 @@ char* sandbox_extension_issue_file(const char* type,
const char* path,
uint32_t flags);
}
+#endif
namespace sandbox {
@@ -46,7 +48,11 @@ std::unique_ptr<SeatbeltExtension> SeatbeltExtension::FromToken(
bool SeatbeltExtension::Consume() {
DCHECK(!token_.empty());
+#ifndef MAS_BUILD
handle_ = sandbox_extension_consume(token_.c_str());
+#else
+ handle_ = -1;
+#endif
return handle_ > 0;
}
@@ -58,7 +64,11 @@ bool SeatbeltExtension::ConsumePermanently() {
}
bool SeatbeltExtension::Revoke() {
+#ifndef MAS_BUILD
int rv = sandbox_extension_release(handle_);
+#else
+ int rv = -1;
+#endif
handle_ = 0;
token_.clear();
return rv == 0;
@@ -76,9 +86,11 @@ SeatbeltExtension::SeatbeltExtension(const std::string& token)
char* SeatbeltExtension::IssueToken(SeatbeltExtension::Type type,
const std::string& resource) {
switch (type) {
+#ifndef MAS_BUILD
case FILE_READ:
return sandbox_extension_issue_file(APP_SANDBOX_READ, resource.c_str(),
0);
+#endif
default:
NOTREACHED();
return nullptr;