bug 1174704 - Implement GetUserDataDirectoryHome for iOS. r=froydnj
authorTed Mielczarek <ted@mielczarek.org>
Wed, 18 Mar 2015 22:23:28 -0400
changeset 269995 783903e5da3b3e33a52458be4d44d5359e3d013e
parent 269994 4f0455f1a2320e793bc3a002f46ebdbde2297d61
child 269996 3d0a10b024c80e5914d6986ed434f977a9299a5c
push idunknown
push userunknown
push dateunknown
reviewersfroydnj
bugs1174704
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 1174704 - Implement GetUserDataDirectoryHome for iOS. r=froydnj
toolkit/xre/UIKitDirProvider.h
toolkit/xre/UIKitDirProvider.mm
toolkit/xre/moz.build
toolkit/xre/nsXREDirProvider.cpp
new file mode 100644
--- /dev/null
+++ b/toolkit/xre/UIKitDirProvider.h
@@ -0,0 +1,13 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef TOOLKIT_XRE_UIKITDIRPROVIDER_H_
+#define TOOLKIT_XRE_UIKITDIRPROVIDER_H_
+
+#include "nsString.h"
+
+bool GetUIKitDirectory(bool aLocal, nsACString& aUserDir);
+
+#endif // TOOLKIT_XRE_UIKITDIRPROVIDER_H_
new file mode 100644
--- /dev/null
+++ b/toolkit/xre/UIKitDirProvider.mm
@@ -0,0 +1,19 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <Foundation/Foundation.h>
+
+#include "UIKitDirProvider.h"
+
+bool GetUIKitDirectory(bool aLocal, nsACString& aUserDir)
+{
+  NSSearchPathDirectory directory = aLocal ? NSCachesDirectory : NSApplicationSupportDirectory;
+  NSArray* paths = NSSearchPathForDirectoriesInDomains(directory, NSUserDomainMask, YES);
+  if ([paths count] == 0) {
+    return false;
+  }
+  aUserDir = [[paths objectAtIndex:0] UTF8String];
+  return true;
+}
--- a/toolkit/xre/moz.build
+++ b/toolkit/xre/moz.build
@@ -35,16 +35,21 @@ elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'co
         'nsCommandLineServiceMac.cpp',
     ]
     UNIFIED_SOURCES += [
         'MacApplicationDelegate.mm',
         'MacAutoreleasePool.mm',
         'MacLaunchHelper.mm',
         'nsNativeAppSupportCocoa.mm',
     ]
+elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'uikit':
+    UNIFIED_SOURCES += [
+        'nsNativeAppSupportDefault.cpp',
+        'UIKitDirProvider.mm',
+    ]
 elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'qt':
     EXPORTS += ['nsQAppInstance.h']
     SOURCES += [
         '!moc_nsNativeAppSupportQt.cpp',
         'nsNativeAppSupportQt.cpp',
         'nsQAppInstance.cpp',
     ]
 elif CONFIG['MOZ_ENABLE_GTK']:
--- a/toolkit/xre/nsXREDirProvider.cpp
+++ b/toolkit/xre/nsXREDirProvider.cpp
@@ -47,16 +47,19 @@
 #include "nsILocalFileMac.h"
 // for chflags()
 #include <sys/stat.h>
 #include <unistd.h>
 #endif
 #ifdef XP_UNIX
 #include <ctype.h>
 #endif
+#ifdef XP_IOS
+#include "UIKitDirProvider.h"
+#endif
 
 #if defined(XP_MACOSX)
 #define APP_REGISTRY_NAME "Application Registry"
 #elif defined(XP_WIN)
 #define APP_REGISTRY_NAME "registry.dat"
 #else
 #define APP_REGISTRY_NAME "appreg"
 #endif
@@ -1230,16 +1233,24 @@ nsXREDirProvider::GetUserDataDirectoryHo
 
   nsCOMPtr<nsILocalFileMac> dirFileMac = do_QueryInterface(localDir);
   NS_ENSURE_TRUE(dirFileMac, NS_ERROR_UNEXPECTED);
 
   rv = dirFileMac->InitWithFSRef(&fsRef);
   NS_ENSURE_SUCCESS(rv, rv);
 
   localDir = do_QueryInterface(dirFileMac, &rv);
+#elif defined(XP_IOS)
+  nsAutoCString userDir;
+  if (GetUIKitDirectory(aLocal, userDir)) {
+    rv = NS_NewNativeLocalFile(userDir, true, getter_AddRefs(localDir));
+  } else {
+    rv = NS_ERROR_FAILURE;
+  }
+  NS_ENSURE_SUCCESS(rv, rv);
 #elif defined(XP_WIN)
   nsString path;
   if (aLocal) {
     rv = GetShellFolderPath(CSIDL_LOCAL_APPDATA, path);
     if (NS_FAILED(rv))
       rv = GetRegWindowsAppDataFolder(aLocal, path);
   }
   if (!aLocal || NS_FAILED(rv)) {