Bug 794571 - Device storage - Add 'sdcard' device storage type. r=sicking
authorDoug Turner <dougt@dougt.org>
Fri, 28 Sep 2012 09:50:13 -0700
changeset 108483 495f94453fb3e5b6adc7776001fa425e5690be2f
parent 108482 134946c7225357477c442b320a1b5f518ee4e483
child 108484 57c89d10f0ab4364ff44afd45d5f657ffda365bd
push id15537
push userdougt@mozilla.com
push dateFri, 28 Sep 2012 16:50:24 +0000
treeherdermozilla-inbound@495f94453fb3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking
bugs794571
milestone18.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 794571 - Device storage - Add 'sdcard' device storage type. r=sicking
dom/devicestorage/nsDeviceStorage.cpp
dom/devicestorage/test/test_add.html
--- a/dom/devicestorage/nsDeviceStorage.cpp
+++ b/dom/devicestorage/nsDeviceStorage.cpp
@@ -54,16 +54,17 @@
 #include "nsIVolumeService.h"
 #endif
 
 #define DEVICESTORAGE_PROPERTIES "chrome://global/content/devicestorage.properties"
 #define DEVICESTORAGE_PICTURES   "pictures"
 #define DEVICESTORAGE_VIDEOS     "videos"
 #define DEVICESTORAGE_MUSIC      "music"
 #define DEVICESTORAGE_APPS       "apps"
+#define DEVICESTORAGE_SDCARD     "sdcard"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 using namespace mozilla::dom::devicestorage;
 
 #include "nsDirectoryServiceDefs.h"
 
 nsAutoPtr<DeviceStorageTypeChecker> DeviceStorageTypeChecker::sDeviceStorageTypeChecker;
@@ -129,30 +130,32 @@ DeviceStorageTypeChecker::Check(const ns
   if (aType.EqualsLiteral(DEVICESTORAGE_VIDEOS)) {
     return StringBeginsWith(mimeType, NS_LITERAL_STRING("video/"));
   }
 
   if (aType.EqualsLiteral(DEVICESTORAGE_MUSIC)) {
     return StringBeginsWith(mimeType, NS_LITERAL_STRING("audio/"));
   }
 
-  if (aType.EqualsLiteral(DEVICESTORAGE_APPS)) {
-    // Apps have no restriction on mime types
+  if (aType.EqualsLiteral(DEVICESTORAGE_APPS) ||
+      aType.EqualsLiteral(DEVICESTORAGE_SDCARD)) {
+    // Apps and sdcard have no restriction on mime types
     return true;
   }
 
   return false;
 }
 
 bool
 DeviceStorageTypeChecker::Check(const nsAString& aType, nsIFile* aFile)
 {
   NS_ASSERTION(aFile, "Calling Check without a file");
 
-  if (aType.EqualsLiteral(DEVICESTORAGE_APPS)) {
+  if (aType.EqualsLiteral(DEVICESTORAGE_APPS) ||
+      aType.EqualsLiteral(DEVICESTORAGE_SDCARD)) {
     // apps have no restrictions on what file extensions used.
     return true;
   }
 
   nsString path;
   aFile->GetPath(path);
 
   int32_t dotIdx = path.RFindChar(PRUnichar('.'));
@@ -181,17 +184,18 @@ DeviceStorageTypeChecker::Check(const ns
 }
 
 nsresult
 DeviceStorageTypeChecker::GetPermissionForType(const nsAString& aType, nsACString& aPermissionResult)
 {
   if (!aType.EqualsLiteral(DEVICESTORAGE_PICTURES) &&
       !aType.EqualsLiteral(DEVICESTORAGE_VIDEOS) &&
       !aType.EqualsLiteral(DEVICESTORAGE_MUSIC) &&
-      !aType.EqualsLiteral(DEVICESTORAGE_APPS)) {
+      !aType.EqualsLiteral(DEVICESTORAGE_APPS) &&
+      !aType.EqualsLiteral(DEVICESTORAGE_SDCARD)) {
     // unknown type
     return NS_ERROR_FAILURE;
   }
 
   aPermissionResult.AssignLiteral("device-storage:");
   aPermissionResult.Append(NS_ConvertUTF16toUTF8(aType));
   return NS_OK;
 }
@@ -673,16 +677,30 @@ nsDOMDeviceStorage::SetRootDirectoryForT
 #else
     dirService->Get(NS_APP_USER_PROFILE_50_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f));
     if (f) {
       f->AppendRelativeNativePath(NS_LITERAL_CSTRING("webapps"));
     }
 #endif
   }
 
+   // default SDCard
+   else if (aType.EqualsLiteral(DEVICESTORAGE_SDCARD)) {
+ #ifdef MOZ_WIDGET_GONK
+     NS_NewLocalFile(NS_LITERAL_STRING("/sdcard"), false, getter_AddRefs(f));
+ #else
+    // Eventually, on desktop, we want to do something smarter -- for example,
+    // detect when an sdcard is inserted, and use that instead of this.
+    dirService->Get(NS_APP_USER_PROFILE_50_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f));
+    if (f) {
+      f->AppendRelativeNativePath(NS_LITERAL_CSTRING("fake-sdcard"));
+    }
+#endif
+  }
+
   // in testing, we default all device storage types to a temp directory
   if (f && mozilla::Preferences::GetBool("device.storage.testing", false)) {
     dirService->Get(NS_OS_TEMP_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f));
     if (f) {
       f->AppendRelativeNativePath(NS_LITERAL_CSTRING("device-storage-testing"));
       f->Create(nsIFile::DIRECTORY_TYPE, 0777);
       f->Normalize();
     }
--- a/dom/devicestorage/test/test_add.html
+++ b/dom/devicestorage/test/test_add.html
@@ -30,16 +30,17 @@ function add(storage, mime) {
   dump("adding: " + mime + "\n");
   return navigator.getDeviceStorage(storage).add(createRandomBlob(mime));
 }
 
 var tests = [
   function () { return add("pictures", "image/png")},
   function () { return add("videos",   "video/webm")},
   function () { return add("music",    "audio/wav")},
+  function () { return add("sdcard",   "maple/cookies")},
 ];
 
 function fail(e) {
   ok(false, "onerror was called");
   devicestorage_cleanup();
 }
 
 function next(e) {