diff options
author | Tor Lillqvist <tml@iki.fi> | 2013-08-23 09:51:48 +0300 |
---|---|---|
committer | Tor Lillqvist <tml@iki.fi> | 2013-08-23 21:33:41 +0300 |
commit | d22c94dbf16d18bce39f060aa21f3083169426ca (patch) | |
tree | 881dc658f3109135100b010e38b48442c7dcf655 /sal | |
parent | 523df6efab74549f1e0d061d48160978ce038f37 (diff) |
Make our File>Recent Documents work better when sandboxed
Store security scope bookmarks for files selected in the file picker
in the user data. (I looked into storing it in the LO "registry" in
the Histories/PickList thingies, but that was horribly complex.)
When opening a file, if we have stored a security scope bookmark for
it, use that while opening the file.
Change-Id: I347ae2dd815299441c17467d9b66a226061d0ed2
Diffstat (limited to 'sal')
-rw-r--r-- | sal/Library_sal.mk | 3 | ||||
-rw-r--r-- | sal/osl/unx/file.cxx | 50 |
2 files changed, 49 insertions, 4 deletions
diff --git a/sal/Library_sal.mk b/sal/Library_sal.mk index 37e01a6bcba9..093546fc9e0d 100644 --- a/sal/Library_sal.mk +++ b/sal/Library_sal.mk @@ -75,6 +75,7 @@ ifeq ($(OS),MACOSX) $(eval $(call gb_Library_use_system_darwin_frameworks,sal,\ Carbon \ CoreFoundation \ + Foundation \ )) endif @@ -122,7 +123,7 @@ $(eval $(call gb_Library_add_cobjects,sal,\ sal/osl/all/filepath \ )) -ifeq ($(OS),IOS) +ifneq (,$(filter IOS MACOSX,$(OS))) $(eval $(call gb_Library_add_cxxflags,sal,\ $(gb_OBJCXXFLAGS) \ )) diff --git a/sal/osl/unx/file.cxx b/sal/osl/unx/file.cxx index 279b3211c895..cf9e49132d05 100644 --- a/sal/osl/unx/file.cxx +++ b/sal/osl/unx/file.cxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: ObjC; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * @@ -43,8 +43,7 @@ #include <sys/mount.h> #define HAVE_O_EXLOCK -// add MACOSX Time Value -#include <CoreFoundation/CoreFoundation.h> +#include <Foundation/Foundation.h> #endif /* MACOSX */ @@ -843,6 +842,17 @@ SAL_CALL osl_openMemoryAsFile( void *address, size_t size, oslFileHandle *pHandl #define OPEN_CREATE_FLAGS ( O_CREAT | O_RDWR ) #endif +#if defined(MACOSX) && MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 && HAVE_FEATURE_MACOSX_SANDBOX + +static NSUserDefaults *userDefaults = NULL; + +static void get_user_defaults() +{ + userDefaults = [NSUserDefaults standardUserDefaults]; +} + +#endif + oslFileError SAL_CALL osl_openFilePath( const char *cpFilePath, oslFileHandle* pHandle, sal_uInt32 uFlags ) { @@ -906,8 +916,42 @@ SAL_CALL osl_openFilePath( const char *cpFilePath, oslFileHandle* pHandle, sal_u flags = osl_file_adjustLockFlags (cpFilePath, flags); } +#if defined(MACOSX) && MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 && HAVE_FEATURE_MACOSX_SANDBOX + static pthread_once_t once = PTHREAD_ONCE_INIT; + pthread_once(&once, &get_user_defaults); + NSURL *fileURL = NULL; + NSData *data = NULL; + NSURL *scopeURL = NULL; + BOOL stale; + + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + + if (userDefaults != NULL) + fileURL = [NSURL fileURLWithPath:[NSString stringWithUTF8String:cpFilePath]]; + + if (fileURL != NULL) + data = [userDefaults dataForKey:[@"bookmarkFor:" stringByAppendingString:[fileURL absoluteString]]]; + + if (data != NULL) + scopeURL = [NSURL URLByResolvingBookmarkData:data + options:NSURLBookmarkResolutionWithSecurityScope + relativeToURL:nil + bookmarkDataIsStale:&stale + error:nil]; + if (scopeURL != NULL) + [scopeURL startAccessingSecurityScopedResource]; +#endif + /* open the file */ int fd = open( cpFilePath, flags, mode ); + + +#if defined(MACOSX) && MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 && HAVE_FEATURE_MACOSX_SANDBOX + if (scopeURL != NULL) + [scopeURL stopAccessingSecurityScopedResource]; + [pool release]; +#endif + #ifdef IOS /* Horrible hack: If opening for RDWR and getting EPERM, just try * again for RDONLY. Quicker this way than to figure out why |