Skip to content

Commit

Permalink
8236685: [macOs] Remove obsolete file dialog subclasses
Browse files Browse the repository at this point in the history
Reviewed-by: arapte, prr
  • Loading branch information
kevinrushforth committed Mar 6, 2020
1 parent f25e8cf commit cfa1193
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 121 deletions.
Expand Up @@ -60,6 +60,4 @@

+ (BOOL)syncRenderingDisabled;

+ (BOOL)isSandboxed;

@end
Expand Up @@ -755,44 +755,6 @@ + (BOOL)syncRenderingDisabled {
return disableSyncRendering;
}

+ (BOOL)isSandboxed
{
static int isSandboxed = -1;

if (isSandboxed == -1) {
isSandboxed = 0;

NSBundle *mainBundle = [NSBundle mainBundle];
NSURL *url = [mainBundle bundleURL];
SecStaticCodeRef staticCodeRef = NULL;
SecStaticCodeCreateWithPath((CFURLRef)url, kSecCSDefaultFlags, &staticCodeRef);

if (staticCodeRef) {
// Check if the app is signed
OSStatus res_signed = SecStaticCodeCheckValidityWithErrors(staticCodeRef, kSecCSBasicValidateOnly, NULL, NULL);
if (res_signed == errSecSuccess) {
// It is signed, now check if it's sandboxed
SecRequirementRef sandboxRequirementRef = NULL;
SecRequirementCreateWithString(CFSTR("entitlement[\"com.apple.security.app-sandbox\"] exists"), kSecCSDefaultFlags, &sandboxRequirementRef);

if (sandboxRequirementRef) {
OSStatus res_sandboxed = SecStaticCodeCheckValidityWithErrors(staticCodeRef, kSecCSBasicValidateOnly, sandboxRequirementRef, NULL);
if (res_sandboxed == errSecSuccess) {
// Yep, sandboxed
isSandboxed = 1;
}

CFRelease(sandboxRequirementRef);
}
}

CFRelease(staticCodeRef);
}
}

return isSandboxed == 1 ? YES : NO;
}

@end

#pragma mark --- JNI
Expand Down
84 changes: 3 additions & 81 deletions modules/javafx.graphics/src/main/native-glass/mac/GlassDialogs.m
Expand Up @@ -38,84 +38,6 @@
#define LOG(MSG, ...) GLASS_LOG(MSG, ## __VA_ARGS__);
#endif

static BOOL doPerformKeyEquivalent(NSEvent* theEvent, NSWindow* panel)
{
NSResponder* responder = [panel firstResponder];
if ([responder isKindOfClass:[NSText class]])
{
NSText* text = (NSText*)responder;
if ([theEvent type] == NSKeyDown
&& ([theEvent modifierFlags] & NSDeviceIndependentModifierFlagsMask) == NSCommandKeyMask)
{
NSRange range = [text selectedRange];
BOOL hasSelectedText = range.length > 0;
if ([theEvent keyCode] == 7 && hasSelectedText) // Cmd + X - Cut
{
[text cut:panel];
return true;
}
if ([theEvent keyCode] == 8 && hasSelectedText) // Cmd + C - Copy
{
[text copy:panel];
return true;
}
if ([theEvent keyCode] == 9) // Cmd + V - Paste
{
[text paste:panel];
return true;
}
}
}
return false;
}

/*
* Function to determine whether or not to use raw NSPanel classes
* (either NSSavePanel or NSOpenPanel).
*
* Return: YES if we need to use the raw NSPanel classes; NO if we
* can use the Glass subclasses
*/
static BOOL useNSPanel()
{
// As of macOS 10.15 all file dialogs are out of process, so we
// effectively can't subclass them.
if (@available(macOS 10.15, *)) {
return YES;
} else {
return [GlassApplication isSandboxed];
}
}

@interface GlassSavePanel : NSSavePanel
@end

@implementation GlassSavePanel

- (BOOL)performKeyEquivalent:(NSEvent *)theEvent
{
if (doPerformKeyEquivalent(theEvent, self)) {
return true;
}
return [super performKeyEquivalent:theEvent];
}
@end

@interface GlassOpenPanel : NSOpenPanel
@end

@implementation GlassOpenPanel

- (BOOL)performKeyEquivalent:(NSEvent *)theEvent
{
if (doPerformKeyEquivalent(theEvent, self)) {
return true;
}
return [super performKeyEquivalent:theEvent];
}
@end


#pragma mark --- Dispatcher

@interface DialogDispatcher : NSObject
Expand Down Expand Up @@ -503,7 +425,7 @@ static jobject convertNSURLtoFile(JNIEnv *env, NSURL *url)
GLASS_ASSERT_MAIN_JAVA_THREAD(env);
GLASS_POOL_ENTER;
{
NSOpenPanel *panel = useNSPanel() ? [NSOpenPanel openPanel] : [GlassOpenPanel openPanel];
NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel setAllowsMultipleSelection:(jMultipleMode==JNI_TRUE)];
[panel setTitle:[GlassHelper nsStringWithJavaString:jTitle withEnv:env]];
NSString *folder = [GlassHelper nsStringWithJavaString:jFolder withEnv:env];
Expand Down Expand Up @@ -579,7 +501,7 @@ static jobject convertNSURLtoFile(JNIEnv *env, NSURL *url)
GLASS_ASSERT_MAIN_JAVA_THREAD(env);
GLASS_POOL_ENTER;
{
NSSavePanel *panel = useNSPanel() ? [NSSavePanel savePanel] : [GlassSavePanel savePanel];
NSSavePanel *panel = [NSSavePanel savePanel];
[panel setTitle:[GlassHelper nsStringWithJavaString:jTitle withEnv:env]];
NSString *folder = [GlassHelper nsStringWithJavaString:jFolder withEnv:env];
if ([folder length] > 0)
Expand Down Expand Up @@ -651,7 +573,7 @@ static jobject convertNSURLtoFile(JNIEnv *env, NSURL *url)
GLASS_ASSERT_MAIN_JAVA_THREAD(env);
GLASS_POOL_ENTER;
{
NSOpenPanel *panel = useNSPanel() ? [NSOpenPanel openPanel] : [GlassOpenPanel openPanel];
NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel setTitle:[GlassHelper nsStringWithJavaString:jTitle withEnv:env]];
NSString *folder = [GlassHelper nsStringWithJavaString:jFolder withEnv:env];
if ([folder length] > 0)
Expand Down

0 comments on commit cfa1193

Please sign in to comment.