Browse Source

FileChooser: actually do store URL security bookmark in a smart pointer (as it was originally on an internal branch). Also update the docs to clearly indicate that a user has to use URL returned from FileChooser.

tags/2021-05-28
Lukasz Kozakiewicz 8 years ago
parent
commit
7297f62182
4 changed files with 47 additions and 12 deletions
  1. +18
    -5
      modules/juce_core/network/juce_URL.cpp
  2. +11
    -1
      modules/juce_core/network/juce_URL.h
  3. +16
    -6
      modules/juce_gui_basics/filebrowser/juce_FileChooser.h
  4. +2
    -0
      modules/juce_gui_basics/native/juce_ios_FileChooser.mm

+ 18
- 5
modules/juce_core/network/juce_URL.cpp View File

@@ -198,7 +198,7 @@ URL::URL (URL&& other)
parameterValues (static_cast<StringArray&&> (other.parameterValues)),
filesToUpload (static_cast<ReferenceCountedArray<Upload>&&> (other.filesToUpload))
#if JUCE_IOS
, bookmark (other.bookmark)
, bookmark (static_cast<Bookmark::Ptr&&> (other.bookmark))
#endif
{
}
@@ -210,8 +210,8 @@ URL& URL::operator= (URL&& other)
parameterNames = static_cast<StringArray&&> (other.parameterNames);
parameterValues = static_cast<StringArray&&> (other.parameterValues);
filesToUpload = static_cast<ReferenceCountedArray<Upload>&&> (other.filesToUpload);
#if JUCE_IOS
bookmark = other.bookmark;
#if JUCE_IOS
bookmark = static_cast<Bookmark::Ptr&&> (other.bookmark);
#endif
return *this;
@@ -501,14 +501,27 @@ bool URL::isProbablyAnEmailAddress (const String& possibleEmailAddress)
}
#if JUCE_IOS
URL::Bookmark::Bookmark (void* bookmarkToUse)
: data (bookmarkToUse)
{
}
URL::Bookmark::~Bookmark()
{
[(NSData*) data release];
}
void setURLBookmark (URL& u, void* bookmark)
{
u.bookmark = bookmark;
u.bookmark = new URL::Bookmark (bookmark);
}
void* getURLBookmark (URL& u)
{
return u.bookmark;
if (u.bookmark.get() == nullptr)
return nullptr;
return u.bookmark.get()->data;
}
template <typename Stream> struct iOSFileStreamWrapperFlush { static void flush (Stream*) {} };


+ 11
- 1
modules/juce_core/network/juce_URL.h View File

@@ -529,7 +529,17 @@ private:
ReferenceCountedArray<Upload> filesToUpload;
#if JUCE_IOS
void* bookmark;
struct Bookmark : public ReferenceCountedObject
{
using Ptr = ReferenceCountedObjectPtr<Bookmark>;
Bookmark (void*);
~Bookmark();
void* data;
};
Bookmark::Ptr bookmark;
friend void setURLBookmark (URL&, void*);
friend void* getURLBookmark (URL&);


+ 16
- 6
modules/juce_gui_basics/filebrowser/juce_FileChooser.h View File

@@ -237,9 +237,14 @@ public:
may return a URL to a remote document. If a local file is chosen then you can
convert this file to a JUCE File class via the URL::getLocalFile method.
Note: on iOS it is best to dispose any copies of returned URL as soon as
you finish dealing with the file. This is because URL might be security
scoped and a system allows only for a limited number of such URLs.
Note: on iOS you must use the returned URL object directly (you are also
allowed to copy- or move-construct another URL from the returned URL), rather
than just storing the path as a String and then creating a new URL from that
String. This is because the returned URL contains internally a security
bookmark that is required to access the files pointed by it. Then, once you stop
dealing with the file pointed by the URL, you should dispose that URL object,
so that the security bookmark can be released by the system (only a limited
number of such URLs is allowed).
@see getResult, URL::getLocalFile
*/
@@ -255,9 +260,14 @@ public:
This array may be empty if no files were chosen, or can contain multiple entries
if multiple files were chosen.
Note: on iOS it is best to dispose any copies of returned URLs as soon as
you finish dealing with the file. This is because URLs might be security
scoped and a system allows only for a limited number of such URLs.
Note: on iOS you must use the returned URL object directly (you are also
allowed to copy- or move-construct another URL from the returned URL), rather
than just storing the path as a String and then creating a new URL from that
String. This is because the returned URL contains internally a security
bookmark that is required to access the files pointed by it. Then, once you stop
dealing with the file pointed by the URL, you should dispose that URL object,
so that the security bookmark can be released by the system (only a limited
number of such URLs is allowed).
@see getResults, URL::getLocalFile
*/


+ 2
- 0
modules/juce_gui_basics/native/juce_ios_FileChooser.mm View File

@@ -217,6 +217,8 @@ private:
relativeToURL: nil
error: &error];
[bookmark retain];
[url stopAccessingSecurityScopedResource];
URL juceUrl (nsStringToJuce ([url absoluteString]));


Loading…
Cancel
Save