From 11c030d54bd035473c7d183a8fa2a1c25f802b0e Mon Sep 17 00:00:00 2001 From: Gaia Pushbot Date: Fri, 2 Aug 2013 15:45:23 -0700 Subject: [PATCH 01/10] Bumping gaia.json for 2 gaia-central revision(s) ======== https://hg.mozilla.org/integration/gaia-central/rev/8561359fa10c Author: David Flanagan Desc: Merge pull request #11241 from huchengtw-moz/gallery/Bug_899098_database_upgrade_message_is_present_when_sd_card_is_empty Bug 899098 - Database Upgrade message is present in Gallery even if the ... r=davidflanagan ======== https://hg.mozilla.org/integration/gaia-central/rev/34b9ba340ab6 Author: John Hu Desc: Bug 899098 - Database Upgrade message is present in Gallery even if the SD card is empty --- b2g/config/gaia.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/b2g/config/gaia.json b/b2g/config/gaia.json index 4008a161ead7..f6560bfaef28 100644 --- a/b2g/config/gaia.json +++ b/b2g/config/gaia.json @@ -1,4 +1,4 @@ { - "revision": "7669b3265def0eed0473acd938897704007afaf3", + "revision": "8561359fa10c204ab1d3660382d5a40604dafa00", "repo_path": "/integration/gaia-central" } From ab18c36791762ee7c42324c87ec286372cfce379 Mon Sep 17 00:00:00 2001 From: Dave Hylands Date: Fri, 2 Aug 2013 16:34:59 -0700 Subject: [PATCH 02/10] Bug 885753 - Change getDeviceStorage to return the default storage area. r=jvarga This removes the entire concept of composite storage. --- dom/base/Navigator.cpp | 2 +- dom/devicestorage/DeviceStorage.h | 40 +- .../DeviceStorageRequestChild.cpp | 6 +- .../DeviceStorageRequestParent.cpp | 6 +- dom/devicestorage/nsDeviceStorage.cpp | 354 +++++------------- 5 files changed, 113 insertions(+), 295 deletions(-) diff --git a/dom/base/Navigator.cpp b/dom/base/Navigator.cpp index 93ff02aa6dea..519980824c51 100644 --- a/dom/base/Navigator.cpp +++ b/dom/base/Navigator.cpp @@ -955,7 +955,7 @@ Navigator::GetDeviceStorages(const nsAString& aType, return; } - nsDOMDeviceStorage::CreateDeviceStoragesFor(mWindow, aType, aStores, false); + nsDOMDeviceStorage::CreateDeviceStoragesFor(mWindow, aType, aStores); mDeviceStorageStores.AppendElements(aStores); } diff --git a/dom/devicestorage/DeviceStorage.h b/dom/devicestorage/DeviceStorage.h index fdb8c33291f5..4960af70a9ab 100644 --- a/dom/devicestorage/DeviceStorage.h +++ b/dom/devicestorage/DeviceStorage.h @@ -68,8 +68,7 @@ public: NS_DECL_THREADSAFE_ISUPPORTS bool IsAvailable(); - bool IsComposite(); - void GetCompositePath(nsAString& aCompositePath); + void GetFullPath(nsAString& aFullPath); // we want to make sure that the names of file can't reach // outside of the type of storage the user asked for. @@ -102,7 +101,6 @@ private: void Init(); void NormalizeFilePath(); void AppendRelativePath(const nsAString& aPath); - void GetStatusInternal(nsAString& aStorageName, nsAString& aStatus); void AccumDirectoryUsage(nsIFile* aFile, uint64_t* aPicturesSoFar, uint64_t* aVideosSoFar, @@ -165,12 +163,11 @@ public: nsDOMDeviceStorage(); - nsresult Init(nsPIDOMWindow* aWindow, const nsAString& aType, - nsTArray >& aStores); nsresult Init(nsPIDOMWindow* aWindow, const nsAString& aType, const nsAString& aVolName); bool IsAvailable(); + bool IsFullPath(const nsAString& aPath) { return aPath.Length() > 0 && aPath.CharAt(0) == '/'; } void SetRootDirectoryForType(const nsAString& aType, const nsAString& aVolName); @@ -234,18 +231,17 @@ public: static void CreateDeviceStoragesFor(nsPIDOMWindow* aWin, const nsAString& aType, - nsTArray >& aStores, - bool aCompositeComponent); + nsTArray >& aStores); void Shutdown(); static void GetOrderedVolumeNames(nsTArray& aVolumeNames); - static void GetWritableStorageName(const nsAString& aStorageType, - nsAString &aStorageName); + static void GetDefaultStorageName(const nsAString& aStorageType, + nsAString &aStorageName); - static bool ParseCompositePath(const nsAString& aCompositePath, - nsAString& aOutStorageName, - nsAString& aOutStoragePath); + static bool ParseFullPath(const nsAString& aFullPath, + nsAString& aOutStorageName, + nsAString& aOutStoragePath); private: ~nsDOMDeviceStorage(); @@ -268,23 +264,8 @@ private: nsString mStorageType; nsCOMPtr mRootDirectory; nsString mStorageName; - bool mCompositeComponent; - // A composite device storage object is one which front-ends for multiple - // real storage objects. The real storage objects will each be stored in - // mStores and will each have a unique mStorageName. The composite storage - // object will have mStorageName == "", and mRootDirectory will be null. - // - // Note that on desktop (or other non-gonk), composite storage areas - // don't exist, and mStorageName will also be "". - // - // A device storage object which is stored in mStores is considered to be - // a composite component. - - bool IsComposite() { return mStores.Length() > 0; } - bool IsCompositeComponent() { return mCompositeComponent; } - nsTArray > mStores; - already_AddRefed GetStorage(const nsAString& aCompositePath, + already_AddRefed GetStorage(const nsAString& aFullPath, nsAString& aOutStoragePath); already_AddRefed GetStorageByName(const nsAString &aStorageName); @@ -306,8 +287,7 @@ private: static mozilla::StaticRefPtr sVolumeNameCache; #ifdef MOZ_WIDGET_GONK - void DispatchMountChangeEvent(nsAString& aVolumeName, - nsAString& aVolumeStatus); + void DispatchMountChangeEvent(nsAString& aVolumeStatus); #endif // nsIDOMDeviceStorage.type diff --git a/dom/devicestorage/DeviceStorageRequestChild.cpp b/dom/devicestorage/DeviceStorageRequestChild.cpp index 0f36dad8bf23..69f1ac03bd01 100644 --- a/dom/devicestorage/DeviceStorageRequestChild.cpp +++ b/dom/devicestorage/DeviceStorageRequestChild.cpp @@ -51,11 +51,11 @@ DeviceStorageRequestChild::Recv__delete__(const DeviceStorageResponseValue& aVal case DeviceStorageResponseValue::TSuccessResponse: { - nsString compositePath; - mFile->GetCompositePath(compositePath); + nsString fullPath; + mFile->GetFullPath(fullPath); AutoJSContext cx; JS::Rooted result(cx, - StringToJsval(mRequest->GetOwner(), compositePath)); + StringToJsval(mRequest->GetOwner(), fullPath)); mRequest->FireSuccess(result); break; } diff --git a/dom/devicestorage/DeviceStorageRequestParent.cpp b/dom/devicestorage/DeviceStorageRequestParent.cpp index 1502c2592870..53e665460536 100644 --- a/dom/devicestorage/DeviceStorageRequestParent.cpp +++ b/dom/devicestorage/DeviceStorageRequestParent.cpp @@ -358,9 +358,9 @@ DeviceStorageRequestParent::PostBlobSuccessEvent::CancelableRun() { nsString mime; CopyASCIItoUTF16(mMimeType, mime); - nsString compositePath; - mFile->GetCompositePath(compositePath); - nsCOMPtr blob = new nsDOMFileFile(compositePath, mime, mLength, mFile->mFile, mLastModificationDate); + nsString fullPath; + mFile->GetFullPath(fullPath); + nsCOMPtr blob = new nsDOMFileFile(fullPath, mime, mLength, mFile->mFile, mLastModificationDate); ContentParent* cp = static_cast(mParent->Manager()); BlobParent* actor = cp->GetOrCreateActorForBlob(blob); diff --git a/dom/devicestorage/nsDeviceStorage.cpp b/dom/devicestorage/nsDeviceStorage.cpp index d36087665ca6..cd5556b031b9 100644 --- a/dom/devicestorage/nsDeviceStorage.cpp +++ b/dom/devicestorage/nsDeviceStorage.cpp @@ -602,26 +602,20 @@ InitDirs() } } -bool DeviceStorageFile::IsComposite() -{ - return DeviceStorageTypeChecker::IsVolumeBased(mStorageType) && - mStorageName.EqualsLiteral(""); -} - void -DeviceStorageFile::GetCompositePath(nsAString &aCompositePath) +DeviceStorageFile::GetFullPath(nsAString &aFullPath) { - aCompositePath.Truncate(); + aFullPath.Truncate(); if (!mStorageName.EqualsLiteral("")) { - aCompositePath.AppendLiteral("/"); - aCompositePath.Append(mStorageName); - aCompositePath.AppendLiteral("/"); + aFullPath.AppendLiteral("/"); + aFullPath.Append(mStorageName); + aFullPath.AppendLiteral("/"); } if (!mRootDir.EqualsLiteral("")) { - aCompositePath.Append(mRootDir); - aCompositePath.AppendLiteral("/"); + aFullPath.Append(mRootDir); + aFullPath.AppendLiteral("/"); } - aCompositePath.Append(mPath); + aFullPath.Append(mPath); } @@ -638,13 +632,6 @@ DeviceStorageFile::GetRootDirectoryForType(const nsAString& aStorageType, #ifdef MOZ_WIDGET_GONK nsString volMountPoint; if (DeviceStorageTypeChecker::IsVolumeBased(aStorageType)) { - if (aStorageName.EqualsLiteral("")) { - // This DeviceStorageFile is for a composite device. Since the composite - // device doesn't have a root, we just allow mFile to be null. These - // should get resolved to real device objects later on. - return; - } - nsCOMPtr vs = do_GetService(NS_VOLUMESERVICE_CONTRACTID); NS_ENSURE_TRUE_VOID(vs); nsresult rv; @@ -724,9 +711,12 @@ DeviceStorageFile::CreateUnique(nsAString& aFileName, nsString storageName; nsString storagePath; - if (!nsDOMDeviceStorage::ParseCompositePath(aFileName, storageName, storagePath)) { + if (!nsDOMDeviceStorage::ParseFullPath(aFileName, storageName, storagePath)) { return nullptr; } + if (storageName.IsEmpty()) { + nsDOMDeviceStorage::GetDefaultStorageName(storageType, storageName); + } nsRefPtr dsf = new DeviceStorageFile(storageType, storageName, storagePath); if (!dsf->mFile) { @@ -998,19 +988,6 @@ DeviceStorageFile::CollectFiles(nsTArray > &aFiles, PRTime aSince) { nsString fullRootPath; - - if (IsComposite()) { - nsDOMDeviceStorage::VolumeNameArray volNames; - nsDOMDeviceStorage::GetOrderedVolumeNames(volNames); - nsDOMDeviceStorage::VolumeNameArray::size_type numVolumes = volNames.Length(); - nsDOMDeviceStorage::VolumeNameArray::index_type i; - for (i = 0; i < numVolumes; i++) { - DeviceStorageFile dsf(mStorageType, volNames[i], mRootDir, EmptyString()); - dsf.mFile->GetPath(fullRootPath); - dsf.collectFilesInternal(aFiles, aSince, fullRootPath); - } - return; - } mFile->GetPath(fullRootPath); collectFilesInternal(aFiles, aSince, fullRootPath); } @@ -1081,19 +1058,6 @@ DeviceStorageFile::AccumDiskUsage(uint64_t* aPicturesSoFar, uint64_t* aMusicSoFar, uint64_t* aTotalSoFar) { - if (IsComposite()) { - nsDOMDeviceStorage::VolumeNameArray volNames; - nsDOMDeviceStorage::GetOrderedVolumeNames(volNames); - nsDOMDeviceStorage::VolumeNameArray::size_type numVolumes = volNames.Length(); - nsDOMDeviceStorage::VolumeNameArray::index_type i; - for (i = 0; i < numVolumes; i++) { - DeviceStorageFile dsf(mStorageType, volNames[i]); - dsf.AccumDiskUsage(aPicturesSoFar, aVideosSoFar, - aMusicSoFar, aTotalSoFar); - } - return; - } - if (!IsAvailable()) { return; } @@ -1205,18 +1169,6 @@ DeviceStorageFile::GetDiskFreeSpace(int64_t* aSoFar) if (!typeChecker) { return; } - if (IsComposite()) { - nsDOMDeviceStorage::VolumeNameArray volNames; - nsDOMDeviceStorage::GetOrderedVolumeNames(volNames); - nsDOMDeviceStorage::VolumeNameArray::size_type numVolumes = volNames.Length(); - nsDOMDeviceStorage::VolumeNameArray::index_type i; - for (i = 0; i < numVolumes; i++) { - DeviceStorageFile dsf(mStorageType, volNames[i]); - dsf.GetDiskFreeSpace(aSoFar); - } - return; - } - if (!mFile || !IsAvailable()) { return; } @@ -1248,46 +1200,13 @@ DeviceStorageFile::GetStatus(nsAString& aStatus) return; } - if (!mStorageName.EqualsLiteral("")) { - GetStatusInternal(mStorageName, aStatus); - return; - } - - // We want a composite status. - aStatus.AssignLiteral("unavailable"); - - nsDOMDeviceStorage::VolumeNameArray volNames; - nsDOMDeviceStorage::GetOrderedVolumeNames(volNames); - nsDOMDeviceStorage::VolumeNameArray::size_type numVolumes = volNames.Length(); - nsDOMDeviceStorage::VolumeNameArray::index_type i; - for (i = 0; i < numVolumes; i++) { - nsString volStatus; - GetStatusInternal(volNames[i], volStatus); - if (volStatus.EqualsLiteral("available")) { - // We found an available volume. We can quit now, since the composite - // status is available if any are available - aStatus = volStatus; - return; - } - if (volStatus.EqualsLiteral("shared")) { - aStatus = volStatus; - // need to keep looking since we might find an available volume later. - } - } -} - -void -DeviceStorageFile::GetStatusInternal(nsAString& aStorageName, nsAString& aStatus) -{ - aStatus.AssignLiteral("unavailable"); - #ifdef MOZ_WIDGET_GONK nsCOMPtr vs = do_GetService(NS_VOLUMESERVICE_CONTRACTID); NS_ENSURE_TRUE_VOID(vs); nsCOMPtr vol; - nsresult rv = vs->GetVolumeByName(aStorageName, getter_AddRefs(vol)); + nsresult rv = vs->GetVolumeByName(mStorageName, getter_AddRefs(vol)); NS_ENSURE_SUCCESS_VOID(rv); int32_t volState; rv = vol->GetState(&volState); @@ -1378,8 +1297,8 @@ nsIFileToJsval(nsPIDOMWindow* aWindow, DeviceStorageFile* aFile) return JSVAL_NULL; } - nsString compositePath; - aFile->GetCompositePath(compositePath); + nsString fullPath; + aFile->GetFullPath(fullPath); // This check is useful to know if somewhere the DeviceStorageFile // has not been properly set. Mimetype is not checked because it can be @@ -1387,7 +1306,7 @@ nsIFileToJsval(nsPIDOMWindow* aWindow, DeviceStorageFile* aFile) NS_ASSERTION(aFile->mLength != UINT64_MAX, "Size not set"); NS_ASSERTION(aFile->mLastModifiedDate != UINT64_MAX, "LastModifiedDate not set"); - nsCOMPtr blob = new nsDOMFileFile(compositePath, aFile->mMimeType, + nsCOMPtr blob = new nsDOMFileFile(fullPath, aFile->mMimeType, aFile->mLength, aFile->mFile, aFile->mLastModifiedDate); return InterfaceToJsval(aWindow, blob, &NS_GET_IID(nsIDOMBlob)); @@ -1893,9 +1812,9 @@ public: return NS_OK; } - nsString compositePath; - mFile->GetCompositePath(compositePath); - nsCOMPtr event = new PostResultEvent(mRequest.forget(), compositePath); + nsString fullPath; + mFile->GetFullPath(fullPath); + nsCOMPtr event = new PostResultEvent(mRequest.forget(), fullPath); NS_DispatchToMainThread(event); return NS_OK; } @@ -1974,9 +1893,9 @@ public: r = new PostErrorEvent(mRequest.forget(), POST_ERROR_EVENT_FILE_DOES_NOT_EXIST); } else { - nsString compositePath; - mFile->GetCompositePath(compositePath); - r = new PostResultEvent(mRequest.forget(), compositePath); + nsString fullPath; + mFile->GetFullPath(fullPath); + r = new PostResultEvent(mRequest.forget(), fullPath); } NS_DispatchToMainThread(r); return NS_OK; @@ -2403,8 +2322,7 @@ NS_IMPL_ADDREF_INHERITED(nsDOMDeviceStorage, nsDOMEventTargetHelper) NS_IMPL_RELEASE_INHERITED(nsDOMDeviceStorage, nsDOMEventTargetHelper) nsDOMDeviceStorage::nsDOMDeviceStorage() - : mCompositeComponent(false), - mIsWatchingFile(false) + : mIsWatchingFile(false) , mAllowedToWatchFile(false) { SetIsDOMBinding(); @@ -2416,17 +2334,6 @@ nsDOMDeviceStorage::WrapObject(JSContext* aCx, JS::Handle aScope) return DeviceStorageBinding::Wrap(aCx, aScope, this); } -nsresult -nsDOMDeviceStorage::Init(nsPIDOMWindow* aWindow, const nsAString &aType, - nsTArray > &aStores) -{ - mStores.AppendElements(aStores); - nsresult rv = Init(aWindow, aType, EmptyString()); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - nsresult nsDOMDeviceStorage::Init(nsPIDOMWindow* aWindow, const nsAString &aType, const nsAString &aVolName) { @@ -2435,15 +2342,11 @@ nsDOMDeviceStorage::Init(nsPIDOMWindow* aWindow, const nsAString &aType, const n NS_ASSERTION(aWindow, "Must have a content dom"); - if (IsComposite()) { - mStorageType = aType; - } else { - SetRootDirectoryForType(aType, aVolName); - if (!mRootDirectory) { - return NS_ERROR_NOT_AVAILABLE; - } + SetRootDirectoryForType(aType, aVolName); + if (!mRootDirectory) { + return NS_ERROR_NOT_AVAILABLE; } - if (!IsCompositeComponent()) { + if (!mStorageName.IsEmpty()) { RegisterForSDCardChanges(this); } @@ -2484,7 +2387,7 @@ nsDOMDeviceStorage::Shutdown() { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); - if (!IsCompositeComponent()) { + if (!mStorageName.IsEmpty()) { UnregisterForSDCardChanges(this); } @@ -2531,37 +2434,27 @@ nsDOMDeviceStorage::CreateDeviceStorageFor(nsPIDOMWindow* aWin, const nsAString &aType, nsDOMDeviceStorage** aStore) { - // Create the underlying non-composite device storage objects - nsTArray > stores; - CreateDeviceStoragesFor(aWin, aType, stores, true); - if (stores.IsEmpty()) { - *aStore = nullptr; - return; - } - + nsString storageName; if (!DeviceStorageTypeChecker::IsVolumeBased(aType)) { - // Since the storage type isn't volume based, don't bother creating - // a composite object. Just use the one we got. - NS_ASSERTION(stores.Length() == 1, "Only expecting a single storage object"); - NS_ADDREF(*aStore = stores[0].get()); - return; + // The storage name will be the empty string + storageName.Truncate(); + } else { + GetDefaultStorageName(aType, storageName); } - // Create the composite device storage object - nsRefPtr composite = new nsDOMDeviceStorage(); - if (NS_FAILED(composite->Init(aWin, aType, stores))) { + nsRefPtr ds = new nsDOMDeviceStorage(); + if (NS_FAILED(ds->Init(aWin, aType, storageName))) { *aStore = nullptr; return; } - NS_ADDREF(*aStore = composite.get()); + NS_ADDREF(*aStore = ds.get()); } // static void nsDOMDeviceStorage::CreateDeviceStoragesFor(nsPIDOMWindow* aWin, const nsAString &aType, - nsTArray > &aStores, - bool aCompositeComponent) + nsTArray > &aStores) { nsresult rv; @@ -2579,7 +2472,6 @@ nsDOMDeviceStorage::CreateDeviceStoragesFor(nsPIDOMWindow* aWin, VolumeNameArray::size_type numVolumeNames = volNames.Length(); for (VolumeNameArray::index_type i = 0; i < numVolumeNames; i++) { nsRefPtr storage = new nsDOMDeviceStorage(); - storage->mCompositeComponent = aCompositeComponent; rv = storage->Init(aWin, aType, volNames[i]); if (NS_FAILED(rv)) { break; @@ -2590,9 +2482,9 @@ nsDOMDeviceStorage::CreateDeviceStoragesFor(nsPIDOMWindow* aWin, // static bool -nsDOMDeviceStorage::ParseCompositePath(const nsAString& aCompositePath, - nsAString& aOutStorageName, - nsAString& aOutStoragePath) +nsDOMDeviceStorage::ParseFullPath(const nsAString& aFullPath, + nsAString& aOutStorageName, + nsAString& aOutStoragePath) { aOutStorageName.Truncate(); aOutStoragePath.Truncate(); @@ -2601,60 +2493,60 @@ nsDOMDeviceStorage::ParseCompositePath(const nsAString& aCompositePath, nsDependentSubstring storageName; - if (StringBeginsWith(aCompositePath, slash)) { - int32_t slashIndex = aCompositePath.FindChar('/', 1); + if (StringBeginsWith(aFullPath, slash)) { + int32_t slashIndex = aFullPath.FindChar('/', 1); if (slashIndex == kNotFound) { // names of the form /filename are illegal return false; } - storageName.Rebind(aCompositePath, 1, slashIndex - 1); - aOutStoragePath = Substring(aCompositePath, slashIndex + 1); + storageName.Rebind(aFullPath, 1, slashIndex - 1); + aOutStoragePath = Substring(aFullPath, slashIndex + 1); } else { - aOutStoragePath = aCompositePath; + aOutStoragePath = aFullPath; } - - if (!storageName.IsEmpty()) { - aOutStorageName = storageName; - return true; - } - - DeviceStorageTypeChecker* typeChecker = DeviceStorageTypeChecker::CreateOrGet(); - NS_ASSERTION(typeChecker, "DeviceStorageTypeChecker is null"); - nsString storageType; - typeChecker->GetTypeFromFileName(aOutStoragePath, storageType); - - nsString defStorageName; - GetWritableStorageName(storageType, defStorageName); - if (defStorageName.IsEmpty()) { - return false; - } - aOutStorageName = defStorageName; + // If no volume name was specified in aFullPath, then aOutStorageName + // will wind up being the empty string. It's up to the caller to figure + // out which storage name to actually use. + aOutStorageName = storageName; return true; } already_AddRefed -nsDOMDeviceStorage::GetStorage(const nsAString& aCompositePath, nsAString& aOutStoragePath) +nsDOMDeviceStorage::GetStorage(const nsAString& aFullPath, nsAString& aOutStoragePath) { - MOZ_ASSERT(IsComposite()); - nsString storageName; - if (!ParseCompositePath(aCompositePath, storageName, aOutStoragePath)) { + if (!ParseFullPath(aFullPath, storageName, aOutStoragePath)) { return nullptr; } - nsRefPtr ds; - ds = GetStorageByName(storageName); + if (storageName.IsEmpty()) { + ds = this; + } else { + ds = GetStorageByName(storageName); + } return ds.forget(); } already_AddRefed nsDOMDeviceStorage::GetStorageByName(const nsAString& aStorageName) { - nsTArray >::size_type n = mStores.Length(); - nsTArray >::index_type i; - for (i = 0; i < n; i++) { - nsRefPtr ds = mStores[i]; - if (ds->mStorageName == aStorageName) { + nsRefPtr ds; + + if (mStorageName.Equals(aStorageName)) { + ds = this; + return ds.forget(); + } + VolumeNameArray volNames; + GetOrderedVolumeNames(volNames); + VolumeNameArray::size_type numVolumes = volNames.Length(); + VolumeNameArray::index_type i; + for (i = 0; i < numVolumes; i++) { + if (volNames[i].Equals(aStorageName)) { + ds = new nsDOMDeviceStorage(); + nsresult rv = ds->Init(GetOwner(), mStorageType, aStorageName); + if (NS_FAILED(rv)) { + return nullptr; + } return ds.forget(); } } @@ -2663,7 +2555,7 @@ nsDOMDeviceStorage::GetStorageByName(const nsAString& aStorageName) // static void -nsDOMDeviceStorage::GetWritableStorageName(const nsAString& aStorageType, +nsDOMDeviceStorage::GetDefaultStorageName(const nsAString& aStorageType, nsAString& aStorageName) { // See if the preferred volume is available. @@ -2671,26 +2563,16 @@ nsDOMDeviceStorage::GetWritableStorageName(const nsAString& aStorageType, nsAdoptingString prefStorageName = mozilla::Preferences::GetString("device.storage.writable.name"); if (prefStorageName) { - DeviceStorageFile dsf(aStorageType, prefStorageName); - if (dsf.IsAvailable()) { - aStorageName = prefStorageName; - return; - } + aStorageName = prefStorageName; + return; } - // No preferred storage, or the preferred storage is unavailable. Find - // the first available storage area. + // No preferred storage, we'll use the first one (which should be sdcard). VolumeNameArray volNames; GetOrderedVolumeNames(volNames); - VolumeNameArray::size_type numVolumes = volNames.Length(); - VolumeNameArray::index_type i; - for (i = 0; i < numVolumes; i++) { - DeviceStorageFile dsf(aStorageType, volNames[i]); - if (dsf.IsAvailable()) { - aStorageName = volNames[i]; - return; - } + if (volNames.Length() > 0) { + aStorageName = volNames[0]; } } @@ -2781,7 +2663,7 @@ nsDOMDeviceStorage::AddNamed(nsIDOMBlob* aBlob, const nsAString& aPath, nsCOMPtr r; - if (IsComposite()) { + if (IsFullPath(aPath)) { nsString storagePath; nsRefPtr ds = GetStorage(aPath, storagePath); if (!ds) { @@ -2843,7 +2725,7 @@ nsDOMDeviceStorage::GetInternal(const nsAString& aPath, bool aEditable, nsRefPtr request = new DOMRequest(win); - if (IsComposite()) { + if (IsFullPath(aPath)) { nsString storagePath; nsRefPtr ds = GetStorage(aPath, storagePath); if (!ds) { @@ -2900,7 +2782,7 @@ nsDOMDeviceStorage::Delete(const nsAString& aPath, ErrorResult& aRv) nsRefPtr request = new DOMRequest(win); - if (IsComposite()) { + if (IsFullPath(aPath)) { nsString storagePath; nsRefPtr ds = GetStorage(aPath, storagePath); if (!ds) { @@ -3035,7 +2917,7 @@ nsDOMDeviceStorage::GetRootDirectoryForFile(const nsAString& aName, nsIFile** aR { nsRefPtr ds; - if (IsComposite()) { + if (IsFullPath(aName)) { nsString storagePath; ds = GetStorage(aName, storagePath); } else { @@ -3051,7 +2933,7 @@ bool nsDOMDeviceStorage::Default() { nsString defaultStorageName; - GetWritableStorageName(mStorageType, defaultStorageName); + GetDefaultStorageName(mStorageType, defaultStorageName); return mStorageName.Equals(defaultStorageName); } @@ -3151,8 +3033,7 @@ nsDOMDeviceStorage::EnumerateInternal(const nsAString& aPath, #ifdef MOZ_WIDGET_GONK void -nsDOMDeviceStorage::DispatchMountChangeEvent(nsAString& aVolumeName, - nsAString& aVolumeStatus) +nsDOMDeviceStorage::DispatchMountChangeEvent(nsAString& aVolumeStatus) { nsCOMPtr event; NS_NewDOMDeviceStorageChangeEvent(getter_AddRefs(event), this, nullptr, nullptr); @@ -3160,7 +3041,7 @@ nsDOMDeviceStorage::DispatchMountChangeEvent(nsAString& aVolumeName, nsCOMPtr ce = do_QueryInterface(event); nsresult rv = ce->InitDeviceStorageChangeEvent(NS_LITERAL_STRING("change"), true, false, - aVolumeName, + mStorageName, aVolumeStatus); if (NS_FAILED(rv)) { return; @@ -3199,7 +3080,7 @@ nsDOMDeviceStorage::Observe(nsISupports *aSubject, const char *aTopic, const PRU #ifdef MOZ_WIDGET_GONK else if (!strcmp(aTopic, NS_VOLUME_STATE_CHANGED)) { - // We only invalidate the used space cache for the volume that actually changed state. + // We invalidate the used space cache for the volume that actually changed state. nsCOMPtr vol = do_QueryInterface(aSubject); if (!vol) { return NS_OK; @@ -3211,13 +3092,15 @@ nsDOMDeviceStorage::Observe(nsISupports *aSubject, const char *aTopic, const PRU NS_ASSERTION(usedSpaceCache, "DeviceStorageUsedSpaceCache is null"); usedSpaceCache->Invalidate(volName); - // But if we're a composite storage area, we want to report a composite availability, - // so we use mStorageName here instead of volName. (Note: for composite devices, - // mStorageName will be the empty string). + if (!volName.Equals(mStorageName)) { + // Not our volume - we can ignore. + return NS_OK; + } + DeviceStorageFile dsf(mStorageType, mStorageName); nsString status; dsf.GetStatus(status); - DispatchMountChangeEvent(mStorageName, status); + DispatchMountChangeEvent(status); return NS_OK; } #endif @@ -3246,10 +3129,10 @@ nsDOMDeviceStorage::Notify(const char* aReason, DeviceStorageFile* aFile) nsString reason; reason.AssignWithConversion(aReason); - nsString compositePath; - aFile->GetCompositePath(compositePath); + nsString fullPath; + aFile->GetFullPath(fullPath); nsresult rv = ce->InitDeviceStorageChangeEvent(NS_LITERAL_STRING("change"), - true, false, compositePath, + true, false, fullPath, reason); NS_ENSURE_SUCCESS(rv, rv); @@ -3269,15 +3152,6 @@ nsDOMDeviceStorage::AddEventListener(const nsAString & aType, if (!win) { return NS_ERROR_UNEXPECTED; } - if (IsComposite()) { - nsTArray >::size_type n = mStores.Length(); - nsTArray >::index_type i; - for (i = 0; i < n; i++) { - nsresult rv = mStores[i]->AddEventListener(aType, aListener, aUseCapture, aWantsUntrusted, aArgc); - NS_ENSURE_SUCCESS(rv, rv); - } - // Fall through, so that we add an event listener for the composite object as well. - } nsRefPtr request = new DOMRequest(win); nsRefPtr dsf = new DeviceStorageFile(mStorageType, @@ -3300,14 +3174,6 @@ nsDOMDeviceStorage::AddEventListener(const nsAString & aType, aRv.Throw(NS_ERROR_UNEXPECTED); return; } - if (IsComposite()) { - nsTArray >::size_type n = mStores.Length(); - nsTArray >::index_type i; - for (i = 0; i < n; i++) { - mStores[i]->AddEventListener(aType, aListener, aUseCapture, aWantsUntrusted, aRv); - } - // Fall through, so that we add an event listener for the composite object as well. - } nsRefPtr request = new DOMRequest(win); nsRefPtr dsf = new DeviceStorageFile(mStorageType, @@ -3325,15 +3191,6 @@ nsDOMDeviceStorage::AddSystemEventListener(const nsAString & aType, bool aWantsUntrusted, uint8_t aArgc) { - if (IsComposite()) { - nsTArray >::size_type n = mStores.Length(); - nsTArray >::index_type i; - for (i = 0; i < n; i++) { - nsresult rv = mStores[i]->AddSystemEventListener(aType, aListener, aUseCapture, aWantsUntrusted, aArgc); - NS_ENSURE_SUCCESS(rv, rv); - } - return NS_OK; - } if (!mIsWatchingFile) { nsCOMPtr obs = mozilla::services::GetObserverService(); obs->AddObserver(this, "file-watcher-update", false); @@ -3348,16 +3205,6 @@ nsDOMDeviceStorage::RemoveEventListener(const nsAString & aType, nsIDOMEventListener *aListener, bool aUseCapture) { - if (IsComposite()) { - nsTArray >::size_type n = mStores.Length(); - nsTArray >::index_type i; - for (i = 0; i < n; i++) { - nsresult rv = mStores[i]->RemoveEventListener(aType, aListener, aUseCapture); - NS_ENSURE_SUCCESS(rv, rv); - } - // Fall through, so that we remove the event listener for the composite - // object as well. - } nsDOMEventTargetHelper::RemoveEventListener(aType, aListener, false); if (mIsWatchingFile && !HasListenersFor(nsGkAtoms::onchange)) { @@ -3374,15 +3221,6 @@ nsDOMDeviceStorage::RemoveEventListener(const nsAString& aType, bool aCapture, ErrorResult& aRv) { - if (IsComposite()) { - nsTArray >::size_type n = mStores.Length(); - nsTArray >::index_type i; - for (i = 0; i < n; i++) { - mStores[i]->RemoveEventListener(aType, aListener, aCapture, aRv); - } - // Fall through, so that we remove the event listener for the composite - // object as well. - } nsDOMEventTargetHelper::RemoveEventListener(aType, aListener, aCapture, aRv); if (mIsWatchingFile && !HasListenersFor(nsGkAtoms::onchange)) { From 75414d2b5288c0a2d919188a615fc897e6dd345d Mon Sep 17 00:00:00 2001 From: Dave Hylands Date: Fri, 2 Aug 2013 16:35:16 -0700 Subject: [PATCH 03/10] Bug 885753 - White space only changes. r=dhylands,jvarga Jan commented that a bunch of my lines were longer than 80 characters. So I went through and fixed the entire file. This changeset should be a white-space only changeset and otherwise has no functional changes. --- dom/devicestorage/DeviceStorage.h | 53 +- .../DeviceStorageRequestChild.cpp | 16 +- .../DeviceStorageRequestParent.cpp | 154 +++--- dom/devicestorage/nsDeviceStorage.cpp | 456 ++++++++++++------ 4 files changed, 433 insertions(+), 246 deletions(-) diff --git a/dom/devicestorage/DeviceStorage.h b/dom/devicestorage/DeviceStorage.h index 4960af70a9ab..d8f73f9f2935 100644 --- a/dom/devicestorage/DeviceStorage.h +++ b/dom/devicestorage/DeviceStorage.h @@ -50,9 +50,10 @@ public: DeviceStorageFile(const nsAString& aStorageType, const nsAString& aStorageName, const nsAString& aPath); - // Used for enumerations. When you call Enumerate, you can pass in a directory to enumerate - // and the results that are returned are relative to that directory, files related to an - // enumeration need to know the "root of the enumeration" directory. + // Used for enumerations. When you call Enumerate, you can pass in a + // directory to enumerate and the results that are returned are relative to + // that directory, files related to an enumeration need to know the "root of + // the enumeration" directory. DeviceStorageFile(const nsAString& aStorageType, const nsAString& aStorageName, const nsAString& aRootDir, @@ -61,9 +62,10 @@ public: void SetPath(const nsAString& aPath); void SetEditable(bool aEditable); - static already_AddRefed CreateUnique(nsAString& aFileName, - uint32_t aFileType, - uint32_t aFileAttributes); + static already_AddRefed + CreateUnique(nsAString& aFileName, + uint32_t aFileType, + uint32_t aFileAttributes); NS_DECL_THREADSAFE_ISUPPORTS @@ -151,11 +153,14 @@ public: NS_DECL_NSIOBSERVER NS_DECL_NSIDOMEVENTTARGET - virtual void AddEventListener(const nsAString& aType, - nsIDOMEventListener* aListener, - bool aUseCapture, - const mozilla::dom::Nullable& aWantsUntrusted, - ErrorResult& aRv) MOZ_OVERRIDE; + + virtual void + AddEventListener(const nsAString& aType, + nsIDOMEventListener* aListener, + bool aUseCapture, + const mozilla::dom::Nullable& aWantsUntrusted, + ErrorResult& aRv) MOZ_OVERRIDE; + virtual void RemoveEventListener(const nsAString& aType, nsIDOMEventListener* aListener, bool aUseCapture, @@ -167,9 +172,13 @@ public: const nsAString& aVolName); bool IsAvailable(); - bool IsFullPath(const nsAString& aPath) { return aPath.Length() > 0 && aPath.CharAt(0) == '/'; } + bool IsFullPath(const nsAString& aPath) + { + return aPath.Length() > 0 && aPath.CharAt(0) == '/'; + } - void SetRootDirectoryForType(const nsAString& aType, const nsAString& aVolName); + void SetRootDirectoryForType(const nsAString& aType, + const nsAString& aVolName); // WebIDL nsPIDOMWindow* @@ -225,13 +234,16 @@ public: // Uses XPCOM GetStorageName - static void CreateDeviceStorageFor(nsPIDOMWindow* aWin, - const nsAString& aType, - nsDOMDeviceStorage** aStore); + static void + CreateDeviceStorageFor(nsPIDOMWindow* aWin, + const nsAString& aType, + nsDOMDeviceStorage** aStore); + + static void + CreateDeviceStoragesFor(nsPIDOMWindow* aWin, + const nsAString& aType, + nsTArray >& aStores); - static void CreateDeviceStoragesFor(nsPIDOMWindow* aWin, - const nsAString& aType, - nsTArray >& aStores); void Shutdown(); static void GetOrderedVolumeNames(nsTArray& aVolumeNames); @@ -267,7 +279,8 @@ private: already_AddRefed GetStorage(const nsAString& aFullPath, nsAString& aOutStoragePath); - already_AddRefed GetStorageByName(const nsAString &aStorageName); + already_AddRefed + GetStorageByName(const nsAString &aStorageName); nsCOMPtr mPrincipal; diff --git a/dom/devicestorage/DeviceStorageRequestChild.cpp b/dom/devicestorage/DeviceStorageRequestChild.cpp index 69f1ac03bd01..e24b569dde24 100644 --- a/dom/devicestorage/DeviceStorageRequestChild.cpp +++ b/dom/devicestorage/DeviceStorageRequestChild.cpp @@ -33,7 +33,8 @@ DeviceStorageRequestChild::~DeviceStorageRequestChild() { } bool -DeviceStorageRequestChild::Recv__delete__(const DeviceStorageResponseValue& aValue) +DeviceStorageRequestChild:: + Recv__delete__(const DeviceStorageResponseValue& aValue) { if (mCallback) { mCallback->RequestComplete(); @@ -105,14 +106,14 @@ DeviceStorageRequestChild::Recv__delete__(const DeviceStorageResponseValue& aVal case DeviceStorageResponseValue::TEnumerationResponse: { EnumerationResponse r = aValue; - nsDOMDeviceStorageCursor* cursor = static_cast(mRequest.get()); + nsDOMDeviceStorageCursor* cursor + = static_cast(mRequest.get()); uint32_t count = r.paths().Length(); for (uint32_t i = 0; i < count; i++) { - nsRefPtr dsf = new DeviceStorageFile(r.type(), - r.paths()[i].storageName(), - r.rootdir(), - r.paths()[i].name()); + nsRefPtr dsf + = new DeviceStorageFile(r.type(), r.paths()[i].storageName(), + r.rootdir(), r.paths()[i].name()); cursor->mFiles.AppendElement(dsf); } @@ -131,7 +132,8 @@ DeviceStorageRequestChild::Recv__delete__(const DeviceStorageResponseValue& aVal } void -DeviceStorageRequestChild::SetCallback(DeviceStorageRequestChildCallback *aCallback) +DeviceStorageRequestChild:: + SetCallback(DeviceStorageRequestChildCallback *aCallback) { mCallback = aCallback; } diff --git a/dom/devicestorage/DeviceStorageRequestParent.cpp b/dom/devicestorage/DeviceStorageRequestParent.cpp index 53e665460536..9f2ee590dea9 100644 --- a/dom/devicestorage/DeviceStorageRequestParent.cpp +++ b/dom/devicestorage/DeviceStorageRequestParent.cpp @@ -18,14 +18,16 @@ namespace mozilla { namespace dom { namespace devicestorage { -DeviceStorageRequestParent::DeviceStorageRequestParent(const DeviceStorageParams& aParams) +DeviceStorageRequestParent::DeviceStorageRequestParent( + const DeviceStorageParams& aParams) : mParams(aParams) , mMutex("DeviceStorageRequestParent::mMutex") , mActorDestoryed(false) { MOZ_COUNT_CTOR(DeviceStorageRequestParent); - DebugOnly usedSpaceCache = DeviceStorageUsedSpaceCache::CreateOrGet(); + DebugOnly usedSpaceCache + = DeviceStorageUsedSpaceCache::CreateOrGet(); NS_ASSERTION(usedSpaceCache, "DeviceStorageUsedSpaceCache is null"); } @@ -48,7 +50,8 @@ DeviceStorageRequestParent::Dispatch() nsRefPtr r = new WriteFileEvent(this, dsf, stream); - nsCOMPtr target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); + nsCOMPtr target + = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); NS_ASSERTION(target, "Must have stream transport service"); target->Dispatch(r, NS_DISPATCH_NORMAL); break; @@ -58,10 +61,12 @@ DeviceStorageRequestParent::Dispatch() { DeviceStorageGetParams p = mParams; nsRefPtr dsf = - new DeviceStorageFile(p.type(), p.storageName(), p.rootDir(), p.relpath()); + new DeviceStorageFile(p.type(), p.storageName(), + p.rootDir(), p.relpath()); nsRefPtr r = new ReadFileEvent(this, dsf); - nsCOMPtr target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); + nsCOMPtr target + = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); NS_ASSERTION(target, "Must have stream transport service"); target->Dispatch(r, NS_DISPATCH_NORMAL); break; @@ -75,7 +80,8 @@ DeviceStorageRequestParent::Dispatch() new DeviceStorageFile(p.type(), p.storageName(), p.relpath()); nsRefPtr r = new DeleteFileEvent(this, dsf); - nsCOMPtr target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); + nsCOMPtr target + = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); NS_ASSERTION(target, "Must have stream transport service"); target->Dispatch(r, NS_DISPATCH_NORMAL); break; @@ -89,7 +95,8 @@ DeviceStorageRequestParent::Dispatch() new DeviceStorageFile(p.type(), p.storageName()); nsRefPtr r = new FreeSpaceFileEvent(this, dsf); - nsCOMPtr target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); + nsCOMPtr target + = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); NS_ASSERTION(target, "Must have stream transport service"); target->Dispatch(r, NS_DISPATCH_NORMAL); break; @@ -97,7 +104,8 @@ DeviceStorageRequestParent::Dispatch() case DeviceStorageParams::TDeviceStorageUsedSpaceParams: { - DeviceStorageUsedSpaceCache* usedSpaceCache = DeviceStorageUsedSpaceCache::CreateOrGet(); + DeviceStorageUsedSpaceCache* usedSpaceCache + = DeviceStorageUsedSpaceCache::CreateOrGet(); NS_ASSERTION(usedSpaceCache, "DeviceStorageUsedSpaceCache is null"); DeviceStorageUsedSpaceParams p = mParams; @@ -116,7 +124,8 @@ DeviceStorageRequestParent::Dispatch() nsRefPtr dsf = new DeviceStorageFile(p.type(), p.storageName()); - nsRefPtr r = new PostAvailableResultEvent(this, dsf); + nsRefPtr r + = new PostAvailableResultEvent(this, dsf); NS_DispatchToMainThread(r); break; } @@ -125,10 +134,13 @@ DeviceStorageRequestParent::Dispatch() { DeviceStorageEnumerationParams p = mParams; nsRefPtr dsf - = new DeviceStorageFile(p.type(), p.storageName(), p.rootdir(), NS_LITERAL_STRING("")); - nsRefPtr r = new EnumerateFileEvent(this, dsf, p.since()); + = new DeviceStorageFile(p.type(), p.storageName(), + p.rootdir(), NS_LITERAL_STRING("")); + nsRefPtr r + = new EnumerateFileEvent(this, dsf, p.since()); - nsCOMPtr target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); + nsCOMPtr target + = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); NS_ASSERTION(target, "Must have stream transport service"); target->Dispatch(r, NS_DISPATCH_NORMAL); break; @@ -142,7 +154,8 @@ DeviceStorageRequestParent::Dispatch() } bool -DeviceStorageRequestParent::EnsureRequiredPermissions(mozilla::dom::ContentParent* aParent) +DeviceStorageRequestParent::EnsureRequiredPermissions( + mozilla::dom::ContentParent* aParent) { if (mozilla::Preferences::GetBool("device.storage.testing", false)) { return true; @@ -224,7 +237,8 @@ DeviceStorageRequestParent::EnsureRequiredPermissions(mozilla::dom::ContentParen } nsAutoCString permissionName; - nsresult rv = DeviceStorageTypeChecker::GetPermissionForType(type, permissionName); + nsresult rv = DeviceStorageTypeChecker::GetPermissionForType(type, + permissionName); if (NS_FAILED(rv)) { return false; } @@ -264,14 +278,16 @@ DeviceStorageRequestParent::ActorDestroy(ActorDestroyReason) } } -DeviceStorageRequestParent::PostFreeSpaceResultEvent::PostFreeSpaceResultEvent(DeviceStorageRequestParent* aParent, - uint64_t aFreeSpace) +DeviceStorageRequestParent::PostFreeSpaceResultEvent::PostFreeSpaceResultEvent( + DeviceStorageRequestParent* aParent, + uint64_t aFreeSpace) : CancelableRunnable(aParent) , mFreeSpace(aFreeSpace) { } -DeviceStorageRequestParent::PostFreeSpaceResultEvent::~PostFreeSpaceResultEvent() {} +DeviceStorageRequestParent::PostFreeSpaceResultEvent:: + ~PostFreeSpaceResultEvent() {} nsresult DeviceStorageRequestParent::PostFreeSpaceResultEvent::CancelableRun() { @@ -282,16 +298,18 @@ DeviceStorageRequestParent::PostFreeSpaceResultEvent::CancelableRun() { return NS_OK; } -DeviceStorageRequestParent::PostUsedSpaceResultEvent::PostUsedSpaceResultEvent(DeviceStorageRequestParent* aParent, - const nsAString& aType, - uint64_t aUsedSpace) +DeviceStorageRequestParent::PostUsedSpaceResultEvent:: + PostUsedSpaceResultEvent(DeviceStorageRequestParent* aParent, + const nsAString& aType, + uint64_t aUsedSpace) : CancelableRunnable(aParent) , mType(aType) , mUsedSpace(aUsedSpace) { } -DeviceStorageRequestParent::PostUsedSpaceResultEvent::~PostUsedSpaceResultEvent() {} +DeviceStorageRequestParent::PostUsedSpaceResultEvent:: + ~PostUsedSpaceResultEvent() {} nsresult DeviceStorageRequestParent::PostUsedSpaceResultEvent::CancelableRun() { @@ -302,8 +320,8 @@ DeviceStorageRequestParent::PostUsedSpaceResultEvent::CancelableRun() { return NS_OK; } -DeviceStorageRequestParent::PostErrorEvent::PostErrorEvent(DeviceStorageRequestParent* aParent, - const char* aError) +DeviceStorageRequestParent::PostErrorEvent:: + PostErrorEvent(DeviceStorageRequestParent* aParent, const char* aError) : CancelableRunnable(aParent) { CopyASCIItoUTF16(aError, mError); @@ -320,7 +338,8 @@ DeviceStorageRequestParent::PostErrorEvent::CancelableRun() { return NS_OK; } -DeviceStorageRequestParent::PostSuccessEvent::PostSuccessEvent(DeviceStorageRequestParent* aParent) +DeviceStorageRequestParent::PostSuccessEvent:: + PostSuccessEvent(DeviceStorageRequestParent* aParent) : CancelableRunnable(aParent) { } @@ -336,11 +355,12 @@ DeviceStorageRequestParent::PostSuccessEvent::CancelableRun() { return NS_OK; } -DeviceStorageRequestParent::PostBlobSuccessEvent::PostBlobSuccessEvent(DeviceStorageRequestParent* aParent, - DeviceStorageFile* aFile, - uint32_t aLength, - nsACString& aMimeType, - uint64_t aLastModifiedDate) +DeviceStorageRequestParent::PostBlobSuccessEvent:: + PostBlobSuccessEvent(DeviceStorageRequestParent* aParent, + DeviceStorageFile* aFile, + uint32_t aLength, + nsACString& aMimeType, + uint64_t aLastModifiedDate) : CancelableRunnable(aParent) , mLength(aLength) , mLastModificationDate(aLastModifiedDate) @@ -360,7 +380,9 @@ DeviceStorageRequestParent::PostBlobSuccessEvent::CancelableRun() { nsString fullPath; mFile->GetFullPath(fullPath); - nsCOMPtr blob = new nsDOMFileFile(fullPath, mime, mLength, mFile->mFile, mLastModificationDate); + nsCOMPtr blob = new nsDOMFileFile(fullPath, mime, mLength, + mFile->mFile, + mLastModificationDate); ContentParent* cp = static_cast(mParent->Manager()); BlobParent* actor = cp->GetOrCreateActorForBlob(blob); @@ -377,10 +399,11 @@ DeviceStorageRequestParent::PostBlobSuccessEvent::CancelableRun() { return NS_OK; } -DeviceStorageRequestParent::PostEnumerationSuccessEvent::PostEnumerationSuccessEvent(DeviceStorageRequestParent* aParent, - const nsAString& aStorageType, - const nsAString& aRelPath, - InfallibleTArray& aPaths) +DeviceStorageRequestParent::PostEnumerationSuccessEvent:: + PostEnumerationSuccessEvent(DeviceStorageRequestParent* aParent, + const nsAString& aStorageType, + const nsAString& aRelPath, + InfallibleTArray& aPaths) : CancelableRunnable(aParent) , mStorageType(aStorageType) , mRelPath(aRelPath) @@ -388,7 +411,8 @@ DeviceStorageRequestParent::PostEnumerationSuccessEvent::PostEnumerationSuccessE { } -DeviceStorageRequestParent::PostEnumerationSuccessEvent::~PostEnumerationSuccessEvent() {} +DeviceStorageRequestParent::PostEnumerationSuccessEvent:: + ~PostEnumerationSuccessEvent() {} nsresult DeviceStorageRequestParent::PostEnumerationSuccessEvent::CancelableRun() { @@ -399,9 +423,10 @@ DeviceStorageRequestParent::PostEnumerationSuccessEvent::CancelableRun() { return NS_OK; } -DeviceStorageRequestParent::WriteFileEvent::WriteFileEvent(DeviceStorageRequestParent* aParent, - DeviceStorageFile* aFile, - nsIInputStream* aInputStream) +DeviceStorageRequestParent::WriteFileEvent:: + WriteFileEvent(DeviceStorageRequestParent* aParent, + DeviceStorageFile* aFile, + nsIInputStream* aInputStream) : CancelableRunnable(aParent) , mFile(aFile) , mInputStream(aInputStream) @@ -428,7 +453,8 @@ DeviceStorageRequestParent::WriteFileEvent::CancelableRun() bool check = false; mFile->mFile->Exists(&check); if (check) { - nsCOMPtr event = new PostErrorEvent(mParent, POST_ERROR_EVENT_FILE_EXISTS); + nsCOMPtr event + = new PostErrorEvent(mParent, POST_ERROR_EVENT_FILE_EXISTS); NS_DispatchToMainThread(event); return NS_OK; } @@ -447,8 +473,8 @@ DeviceStorageRequestParent::WriteFileEvent::CancelableRun() } -DeviceStorageRequestParent::DeleteFileEvent::DeleteFileEvent(DeviceStorageRequestParent* aParent, - DeviceStorageFile* aFile) +DeviceStorageRequestParent::DeleteFileEvent:: + DeleteFileEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile) : CancelableRunnable(aParent) , mFile(aFile) { @@ -480,8 +506,9 @@ DeviceStorageRequestParent::DeleteFileEvent::CancelableRun() return NS_OK; } -DeviceStorageRequestParent::FreeSpaceFileEvent::FreeSpaceFileEvent(DeviceStorageRequestParent* aParent, - DeviceStorageFile* aFile) +DeviceStorageRequestParent::FreeSpaceFileEvent:: + FreeSpaceFileEvent(DeviceStorageRequestParent* aParent, + DeviceStorageFile* aFile) : CancelableRunnable(aParent) , mFile(aFile) { @@ -507,8 +534,9 @@ DeviceStorageRequestParent::FreeSpaceFileEvent::CancelableRun() return NS_OK; } -DeviceStorageRequestParent::UsedSpaceFileEvent::UsedSpaceFileEvent(DeviceStorageRequestParent* aParent, - DeviceStorageFile* aFile) +DeviceStorageRequestParent::UsedSpaceFileEvent:: + UsedSpaceFileEvent(DeviceStorageRequestParent* aParent, + DeviceStorageFile* aFile) : CancelableRunnable(aParent) , mFile(aFile) { @@ -528,7 +556,8 @@ DeviceStorageRequestParent::UsedSpaceFileEvent::CancelableRun() &musicUsage, &totalUsage); nsCOMPtr r; if (mFile->mStorageType.EqualsLiteral(DEVICESTORAGE_PICTURES)) { - r = new PostUsedSpaceResultEvent(mParent, mFile->mStorageType, picturesUsage); + r = new PostUsedSpaceResultEvent(mParent, mFile->mStorageType, + picturesUsage); } else if (mFile->mStorageType.EqualsLiteral(DEVICESTORAGE_VIDEOS)) { r = new PostUsedSpaceResultEvent(mParent, mFile->mStorageType, videosUsage); @@ -542,12 +571,13 @@ DeviceStorageRequestParent::UsedSpaceFileEvent::CancelableRun() return NS_OK; } -DeviceStorageRequestParent::ReadFileEvent::ReadFileEvent(DeviceStorageRequestParent* aParent, - DeviceStorageFile* aFile) +DeviceStorageRequestParent::ReadFileEvent:: + ReadFileEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile) : CancelableRunnable(aParent) , mFile(aFile) { - nsCOMPtr mimeService = do_GetService(NS_MIMESERVICE_CONTRACTID); + nsCOMPtr mimeService + = do_GetService(NS_MIMESERVICE_CONTRACTID); if (mimeService) { nsresult rv = mimeService->GetTypeFromFile(mFile->mFile, mMimeType); if (NS_FAILED(rv)) { @@ -591,14 +621,16 @@ DeviceStorageRequestParent::ReadFileEvent::CancelableRun() return NS_OK; } - r = new PostBlobSuccessEvent(mParent, mFile, static_cast(fileSize), mMimeType, modDate); + r = new PostBlobSuccessEvent(mParent, mFile, static_cast(fileSize), + mMimeType, modDate); NS_DispatchToMainThread(r); return NS_OK; } -DeviceStorageRequestParent::EnumerateFileEvent::EnumerateFileEvent(DeviceStorageRequestParent* aParent, - DeviceStorageFile* aFile, - uint64_t aSince) +DeviceStorageRequestParent::EnumerateFileEvent:: + EnumerateFileEvent(DeviceStorageRequestParent* aParent, + DeviceStorageFile* aFile, + uint64_t aSince) : CancelableRunnable(aParent) , mFile(aFile) , mSince(aSince) @@ -636,14 +668,16 @@ DeviceStorageRequestParent::EnumerateFileEvent::CancelableRun() values.AppendElement(dsvf); } - r = new PostEnumerationSuccessEvent(mParent, mFile->mStorageType, mFile->mRootDir, values); + r = new PostEnumerationSuccessEvent(mParent, mFile->mStorageType, + mFile->mRootDir, values); NS_DispatchToMainThread(r); return NS_OK; } -DeviceStorageRequestParent::PostPathResultEvent::PostPathResultEvent(DeviceStorageRequestParent* aParent, - const nsAString& aPath) +DeviceStorageRequestParent::PostPathResultEvent:: + PostPathResultEvent(DeviceStorageRequestParent* aParent, + const nsAString& aPath) : CancelableRunnable(aParent) , mPath(aPath) { @@ -663,14 +697,16 @@ DeviceStorageRequestParent::PostPathResultEvent::CancelableRun() return NS_OK; } -DeviceStorageRequestParent::PostAvailableResultEvent::PostAvailableResultEvent(DeviceStorageRequestParent* aParent, - DeviceStorageFile* aFile) +DeviceStorageRequestParent::PostAvailableResultEvent:: + PostAvailableResultEvent(DeviceStorageRequestParent* aParent, + DeviceStorageFile* aFile) : CancelableRunnable(aParent) , mFile(aFile) { } -DeviceStorageRequestParent::PostAvailableResultEvent::~PostAvailableResultEvent() +DeviceStorageRequestParent::PostAvailableResultEvent:: + ~PostAvailableResultEvent() { } diff --git a/dom/devicestorage/nsDeviceStorage.cpp b/dom/devicestorage/nsDeviceStorage.cpp index cd5556b031b9..e0b91186e31c 100644 --- a/dom/devicestorage/nsDeviceStorage.cpp +++ b/dom/devicestorage/nsDeviceStorage.cpp @@ -59,7 +59,8 @@ #include "nsIVolumeService.h" #endif -#define DEVICESTORAGE_PROPERTIES "chrome://global/content/devicestorage.properties" +#define DEVICESTORAGE_PROPERTIES \ + "chrome://global/content/devicestorage.properties" #define DEFAULT_THREAD_TIMEOUT_MS 30000 using namespace mozilla; @@ -68,14 +69,16 @@ using namespace mozilla::dom::devicestorage; #include "nsDirectoryServiceDefs.h" -StaticAutoPtr DeviceStorageUsedSpaceCache::sDeviceStorageUsedSpaceCache; +StaticAutoPtr + DeviceStorageUsedSpaceCache::sDeviceStorageUsedSpaceCache; DeviceStorageUsedSpaceCache::DeviceStorageUsedSpaceCache() { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); - mIOThread = new LazyIdleThread(DEFAULT_THREAD_TIMEOUT_MS, - NS_LITERAL_CSTRING("DeviceStorageUsedSpaceCache I/O")); + mIOThread = new LazyIdleThread( + DEFAULT_THREAD_TIMEOUT_MS, + NS_LITERAL_CSTRING("DeviceStorageUsedSpaceCache I/O")); } @@ -117,7 +120,8 @@ GetFreeBytes(const nsAString& aStorageName) // This function makes the assumption that the various types // are all stored on the same filesystem. So we use pictures. - DeviceStorageFile dsf(NS_LITERAL_STRING(DEVICESTORAGE_PICTURES), aStorageName); + DeviceStorageFile dsf(NS_LITERAL_STRING(DEVICESTORAGE_PICTURES), + aStorageName); int64_t freeBytes = 0; dsf.GetDiskFreeSpace(&freeBytes); return freeBytes; @@ -185,7 +189,8 @@ public: static StaticRefPtr sDirs; -StaticAutoPtr DeviceStorageTypeChecker::sDeviceStorageTypeChecker; +StaticAutoPtr + DeviceStorageTypeChecker::sDeviceStorageTypeChecker; DeviceStorageTypeChecker::DeviceStorageTypeChecker() { @@ -202,15 +207,18 @@ DeviceStorageTypeChecker::CreateOrGet() return sDeviceStorageTypeChecker; } - NS_ASSERTION(NS_IsMainThread(), "This can only be created on the main thread!"); + NS_ASSERTION(NS_IsMainThread(), + "This can only be created on the main thread!"); - nsCOMPtr stringService = mozilla::services::GetStringBundleService(); + nsCOMPtr stringService + = mozilla::services::GetStringBundleService(); if (!stringService) { return nullptr; } nsCOMPtr filterBundle; - if (NS_FAILED(stringService->CreateBundle(DEVICESTORAGE_PROPERTIES, getter_AddRefs(filterBundle)))) { + if (NS_FAILED(stringService->CreateBundle(DEVICESTORAGE_PROPERTIES, + getter_AddRefs(filterBundle)))) { return nullptr; } @@ -225,9 +233,15 @@ DeviceStorageTypeChecker::CreateOrGet() void DeviceStorageTypeChecker::InitFromBundle(nsIStringBundle* aBundle) { - aBundle->GetStringFromName(NS_ConvertASCIItoUTF16(DEVICESTORAGE_PICTURES).get(), getter_Copies(mPicturesExtensions)); - aBundle->GetStringFromName(NS_ConvertASCIItoUTF16(DEVICESTORAGE_MUSIC).get(), getter_Copies(mMusicExtensions)); - aBundle->GetStringFromName(NS_ConvertASCIItoUTF16(DEVICESTORAGE_VIDEOS).get(), getter_Copies(mVideosExtensions)); + aBundle->GetStringFromName( + NS_ConvertASCIItoUTF16(DEVICESTORAGE_PICTURES).get(), + getter_Copies(mPicturesExtensions)); + aBundle->GetStringFromName( + NS_ConvertASCIItoUTF16(DEVICESTORAGE_MUSIC).get(), + getter_Copies(mMusicExtensions)); + aBundle->GetStringFromName( + NS_ConvertASCIItoUTF16(DEVICESTORAGE_VIDEOS).get(), + getter_Copies(mVideosExtensions)); } @@ -313,7 +327,8 @@ DeviceStorageTypeChecker::GetTypeFromFile(nsIFile* aFile, nsAString& aType) } void -DeviceStorageTypeChecker::GetTypeFromFileName(const nsAString& aFileName, nsAString& aType) +DeviceStorageTypeChecker::GetTypeFromFileName(const nsAString& aFileName, + nsAString& aType) { aType.AssignLiteral(DEVICESTORAGE_SDCARD); @@ -340,7 +355,8 @@ DeviceStorageTypeChecker::GetTypeFromFileName(const nsAString& aFileName, nsAStr } nsresult -DeviceStorageTypeChecker::GetPermissionForType(const nsAString& aType, nsACString& aPermissionResult) +DeviceStorageTypeChecker::GetPermissionForType(const nsAString& aType, + nsACString& aPermissionResult) { if (!aType.EqualsLiteral(DEVICESTORAGE_PICTURES) && !aType.EqualsLiteral(DEVICESTORAGE_VIDEOS) && @@ -357,7 +373,8 @@ DeviceStorageTypeChecker::GetPermissionForType(const nsAString& aType, nsACStrin } nsresult -DeviceStorageTypeChecker::GetAccessForRequest(const DeviceStorageRequestType aRequestType, nsACString& aAccessResult) +DeviceStorageTypeChecker::GetAccessForRequest( + const DeviceStorageRequestType aRequestType, nsACString& aAccessResult) { switch(aRequestType) { case DEVICE_STORAGE_REQUEST_READ: @@ -426,10 +443,11 @@ FileUpdateDispatcher::Observe(nsISupports *aSubject, NS_WARNING("Device storage file looks invalid!"); return NS_OK; } - ContentChild::GetSingleton()->SendFilePathUpdateNotify(file->mStorageType, - file->mStorageName, - file->mPath, - NS_ConvertUTF16toUTF8(aData)); + ContentChild::GetSingleton() + ->SendFilePathUpdateNotify(file->mStorageType, + file->mStorageName, + file->mPath, + NS_ConvertUTF16toUTF8(aData)); } else { nsCOMPtr obs = mozilla::services::GetObserverService(); obs->NotifyObservers(aSubject, "file-watcher-update", aData); @@ -457,7 +475,8 @@ public: obs->NotifyObservers(mFile, "file-watcher-notify", data.get()); - DeviceStorageUsedSpaceCache* usedSpaceCache = DeviceStorageUsedSpaceCache::CreateOrGet(); + DeviceStorageUsedSpaceCache* usedSpaceCache + = DeviceStorageUsedSpaceCache::CreateOrGet(); NS_ASSERTION(usedSpaceCache, "DeviceStorageUsedSpaceCache is null"); usedSpaceCache->Invalidate(mFile->mStorageName); return NS_OK; @@ -530,7 +549,8 @@ DeviceStorageFile::Dump(const char* label) ptStr = "child"; } - printf_stderr("DSF (%s) %s: mStorageType '%s' mStorageName '%s' mRootDir '%s' mPath '%s' mFile->GetPath '%s'\n", + printf_stderr("DSF (%s) %s: mStorageType '%s' mStorageName '%s' " + "mRootDir '%s' mPath '%s' mFile->GetPath '%s'\n", ptStr, label, NS_LossyConvertUTF16toASCII(mStorageType).get(), NS_LossyConvertUTF16toASCII(mStorageName).get(), @@ -546,7 +566,8 @@ DeviceStorageFile::Init() mStorageName, getter_AddRefs(mFile)); - DebugOnly typeChecker = DeviceStorageTypeChecker::CreateOrGet(); + DebugOnly typeChecker + = DeviceStorageTypeChecker::CreateOrGet(); NS_ASSERTION(typeChecker, "DeviceStorageTypeChecker is null"); } @@ -560,42 +581,65 @@ InitDirs() sDirs = new GlobalDirs; ClearOnShutdown(&sDirs); - nsCOMPtr dirService = do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID); + nsCOMPtr dirService + = do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID); NS_ASSERTION(dirService, "Must have directory service"); #if !defined(MOZ_WIDGET_GONK) #if defined (MOZ_WIDGET_COCOA) - dirService->Get(NS_OSX_PICTURE_DOCUMENTS_DIR, NS_GET_IID(nsIFile), getter_AddRefs(sDirs->pictures)); - dirService->Get(NS_OSX_MOVIE_DOCUMENTS_DIR, NS_GET_IID(nsIFile), getter_AddRefs(sDirs->videos)); - dirService->Get(NS_OSX_MUSIC_DOCUMENTS_DIR, NS_GET_IID(nsIFile), getter_AddRefs(sDirs->music)); + dirService->Get(NS_OSX_PICTURE_DOCUMENTS_DIR, + NS_GET_IID(nsIFile), + getter_AddRefs(sDirs->pictures)); + dirService->Get(NS_OSX_MOVIE_DOCUMENTS_DIR, + NS_GET_IID(nsIFile), + getter_AddRefs(sDirs->videos)); + dirService->Get(NS_OSX_MUSIC_DOCUMENTS_DIR, + NS_GET_IID(nsIFile), + getter_AddRefs(sDirs->music)); #elif defined (XP_UNIX) - dirService->Get(NS_UNIX_XDG_PICTURES_DIR, NS_GET_IID(nsIFile), getter_AddRefs(sDirs->pictures)); - dirService->Get(NS_UNIX_XDG_VIDEOS_DIR, NS_GET_IID(nsIFile), getter_AddRefs(sDirs->videos)); - dirService->Get(NS_UNIX_XDG_MUSIC_DIR, NS_GET_IID(nsIFile), getter_AddRefs(sDirs->music)); + dirService->Get(NS_UNIX_XDG_PICTURES_DIR, + NS_GET_IID(nsIFile), + getter_AddRefs(sDirs->pictures)); + dirService->Get(NS_UNIX_XDG_VIDEOS_DIR, + NS_GET_IID(nsIFile), + getter_AddRefs(sDirs->videos)); + dirService->Get(NS_UNIX_XDG_MUSIC_DIR, + NS_GET_IID(nsIFile), + getter_AddRefs(sDirs->music)); #elif defined (XP_WIN) - dirService->Get(NS_WIN_PICTURES_DIR, NS_GET_IID(nsIFile), getter_AddRefs(sDirs->pictures)); - dirService->Get(NS_WIN_VIDEOS_DIR, NS_GET_IID(nsIFile), getter_AddRefs(sDirs->videos)); - dirService->Get(NS_WIN_MUSIC_DIR, NS_GET_IID(nsIFile), getter_AddRefs(sDirs->music)); + dirService->Get(NS_WIN_PICTURES_DIR, + NS_GET_IID(nsIFile), + getter_AddRefs(sDirs->pictures)); + dirService->Get(NS_WIN_VIDEOS_DIR, + NS_GET_IID(nsIFile), + getter_AddRefs(sDirs->videos)); + dirService->Get(NS_WIN_MUSIC_DIR, + NS_GET_IID(nsIFile), + getter_AddRefs(sDirs->music)); #endif - dirService->Get(NS_APP_USER_PROFILE_50_DIR, NS_GET_IID(nsIFile), getter_AddRefs(sDirs->apps)); + dirService->Get(NS_APP_USER_PROFILE_50_DIR, NS_GET_IID(nsIFile), + getter_AddRefs(sDirs->apps)); if (sDirs->apps) { sDirs->apps->AppendRelativeNativePath(NS_LITERAL_CSTRING("webapps")); } // 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(sDirs->sdcard)); + dirService->Get(NS_APP_USER_PROFILE_50_DIR, NS_GET_IID(nsIFile), + getter_AddRefs(sDirs->sdcard)); if (sDirs->sdcard) { sDirs->sdcard->AppendRelativeNativePath(NS_LITERAL_CSTRING("fake-sdcard")); } #endif // !MOZ_WIDGET_GONK if (mozilla::Preferences::GetBool("device.storage.testing", false)) { - dirService->Get(NS_OS_TEMP_DIR, NS_GET_IID(nsIFile), getter_AddRefs(sDirs->temp)); + dirService->Get(NS_OS_TEMP_DIR, NS_GET_IID(nsIFile), + getter_AddRefs(sDirs->temp)); if (sDirs->temp) { - sDirs->temp->AppendRelativeNativePath(NS_LITERAL_CSTRING("device-storage-testing")); + sDirs->temp->AppendRelativeNativePath( + NS_LITERAL_CSTRING("device-storage-testing")); sDirs->temp->Create(nsIFile::DIRECTORY_TYPE, 0777); sDirs->temp->Normalize(); } @@ -703,7 +747,8 @@ DeviceStorageFile::CreateUnique(nsAString& aFileName, uint32_t aFileType, uint32_t aFileAttributes) { - DeviceStorageTypeChecker* typeChecker = DeviceStorageTypeChecker::CreateOrGet(); + DeviceStorageTypeChecker* typeChecker + = DeviceStorageTypeChecker::CreateOrGet(); NS_ASSERTION(typeChecker, "DeviceStorageTypeChecker is null"); nsString storageType; @@ -726,7 +771,8 @@ DeviceStorageFile::CreateUnique(nsAString& aFileName, nsresult rv = dsf->mFile->CreateUnique(aFileType, aFileAttributes); NS_ENSURE_SUCCESS(rv, nullptr); - // CreateUnique may cause the filename to change. So we need to update mPath to reflect that. + // CreateUnique may cause the filename to change. So we need to update mPath + // to reflect that. nsString leafName; dsf->mFile->GetLeafName(leafName); @@ -860,9 +906,10 @@ DeviceStorageFile::Write(nsIInputStream* aInputStream) while (bufSize) { uint32_t wrote; - rv = bufferedOutputStream->WriteFrom(aInputStream, - static_cast(std::min(bufSize, UINT32_MAX)), - &wrote); + rv = bufferedOutputStream->WriteFrom( + aInputStream, + static_cast(std::min(bufSize, UINT32_MAX)), + &wrote); if (NS_FAILED(rv)) { break; } @@ -993,9 +1040,10 @@ DeviceStorageFile::CollectFiles(nsTArray > &aFiles, } void -DeviceStorageFile::collectFilesInternal(nsTArray > &aFiles, - PRTime aSince, - nsAString& aRootPath) +DeviceStorageFile::collectFilesInternal( + nsTArray > &aFiles, + PRTime aSince, + nsAString& aRootPath) { if (!mFile || !IsAvailable()) { return; @@ -1068,7 +1116,7 @@ DeviceStorageFile::AccumDiskUsage(uint64_t* aPicturesSoFar, DeviceStorageUsedSpaceCache* usedSpaceCache = DeviceStorageUsedSpaceCache::CreateOrGet(); NS_ASSERTION(usedSpaceCache, "DeviceStorageUsedSpaceCache is null"); - nsresult rv = usedSpaceCache->AccumUsedSizes(mStorageName, + nsresult rv = usedSpaceCache->AccumUsedSizes(mStorageName, aPicturesSoFar, aVideosSoFar, aMusicSoFar, aTotalSoFar); if (NS_SUCCEEDED(rv)) { @@ -1109,7 +1157,8 @@ DeviceStorageFile::AccumDirectoryUsage(nsIFile* aFile, } nsCOMPtr files = do_QueryInterface(e); - NS_ASSERTION(files, "GetDirectoryEntries must return a nsIDirectoryEnumerator"); + NS_ASSERTION(files, + "GetDirectoryEntries must return a nsIDirectoryEnumerator"); nsCOMPtr f; while (NS_SUCCEEDED(files->GetNextFile(getter_AddRefs(f))) && f) { @@ -1135,7 +1184,8 @@ DeviceStorageFile::AccumDirectoryUsage(nsIFile* aFile, // for now, lets just totally ignore symlinks. NS_WARNING("DirectoryDiskUsage ignores symlinks"); } else if (isDir) { - AccumDirectoryUsage(f, aPicturesSoFar, aVideosSoFar, aMusicSoFar, aTotalSoFar); + AccumDirectoryUsage(f, aPicturesSoFar, aVideosSoFar, + aMusicSoFar, aTotalSoFar); } else if (isFile) { int64_t size; @@ -1143,7 +1193,8 @@ DeviceStorageFile::AccumDirectoryUsage(nsIFile* aFile, if (NS_FAILED(rv)) { continue; } - DeviceStorageTypeChecker* typeChecker = DeviceStorageTypeChecker::CreateOrGet(); + DeviceStorageTypeChecker* typeChecker + = DeviceStorageTypeChecker::CreateOrGet(); NS_ASSERTION(typeChecker, "DeviceStorageTypeChecker is null"); nsString type; typeChecker->GetTypeFromFile(f, type); @@ -1165,7 +1216,8 @@ DeviceStorageFile::AccumDirectoryUsage(nsIFile* aFile, void DeviceStorageFile::GetDiskFreeSpace(int64_t* aSoFar) { - DeviceStorageTypeChecker* typeChecker = DeviceStorageTypeChecker::CreateOrGet(); + DeviceStorageTypeChecker* typeChecker + = DeviceStorageTypeChecker::CreateOrGet(); if (!typeChecker) { return; } @@ -1191,7 +1243,8 @@ DeviceStorageFile::IsAvailable() void DeviceStorageFile::GetStatus(nsAString& aStatus) { - DeviceStorageTypeChecker* typeChecker = DeviceStorageTypeChecker::CreateOrGet(); + DeviceStorageTypeChecker* typeChecker + = DeviceStorageTypeChecker::CreateOrGet(); if (!typeChecker) { return; } @@ -1213,7 +1266,8 @@ DeviceStorageFile::GetStatus(nsAString& aStatus) NS_ENSURE_SUCCESS_VOID(rv); if (volState == nsIVolume::STATE_MOUNTED) { aStatus.AssignLiteral("available"); - } else if (volState == nsIVolume::STATE_SHARED || volState == nsIVolume::STATE_SHAREDMNT) { + } else if (volState == nsIVolume::STATE_SHARED || + volState == nsIVolume::STATE_SHAREDMNT) { aStatus.AssignLiteral("shared"); } #endif @@ -1256,7 +1310,9 @@ nsDOMDeviceStorage::SetRootDirectoryForType(const nsAString& aStorageType, } JS::Value -InterfaceToJsval(nsPIDOMWindow* aWindow, nsISupports* aObject, const nsIID* aIID) +InterfaceToJsval(nsPIDOMWindow* aWindow, + nsISupports* aObject, + const nsIID* aIID) { AutoJSContext cx; nsCOMPtr sgo = do_QueryInterface(aWindow); @@ -1297,14 +1353,15 @@ nsIFileToJsval(nsPIDOMWindow* aWindow, DeviceStorageFile* aFile) return JSVAL_NULL; } - nsString fullPath; + nsString fullPath; aFile->GetFullPath(fullPath); // This check is useful to know if somewhere the DeviceStorageFile // has not been properly set. Mimetype is not checked because it can be // empty. NS_ASSERTION(aFile->mLength != UINT64_MAX, "Size not set"); - NS_ASSERTION(aFile->mLastModifiedDate != UINT64_MAX, "LastModifiedDate not set"); + NS_ASSERTION(aFile->mLastModifiedDate != UINT64_MAX, + "LastModifiedDate not set"); nsCOMPtr blob = new nsDOMFileFile(fullPath, aFile->mMimeType, aFile->mLength, aFile->mFile, @@ -1346,7 +1403,8 @@ class DeviceStorageCursorRequest MOZ_FINAL { public: NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(DeviceStorageCursorRequest, nsIContentPermissionRequest) + NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(DeviceStorageCursorRequest, + nsIContentPermissionRequest) NS_FORWARD_NSICONTENTPERMISSIONREQUEST(mCursor->); @@ -1432,11 +1490,13 @@ ContinueCursorEvent::GetNextFile() { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); - nsDOMDeviceStorageCursor* cursor = static_cast(mRequest.get()); + nsDOMDeviceStorageCursor* cursor + = static_cast(mRequest.get()); nsString cursorStorageType; cursor->GetStorageType(cursorStorageType); - DeviceStorageTypeChecker* typeChecker = DeviceStorageTypeChecker::CreateOrGet(); + DeviceStorageTypeChecker* typeChecker + = DeviceStorageTypeChecker::CreateOrGet(); if (!typeChecker) { return nullptr; } @@ -1473,17 +1533,20 @@ ContinueCursorEvent::Continue() return; } - nsDOMDeviceStorageCursor* cursor = static_cast(mRequest.get()); + nsDOMDeviceStorageCursor* cursor + = static_cast(mRequest.get()); nsString cursorStorageType; cursor->GetStorageType(cursorStorageType); - DeviceStorageRequestChild* child = new DeviceStorageRequestChild(mRequest, file); + DeviceStorageRequestChild* child + = new DeviceStorageRequestChild(mRequest, file); child->SetCallback(cursor); DeviceStorageGetParams params(cursorStorageType, file->mStorageName, file->mRootDir, file->mPath); - ContentChild::GetSingleton()->SendPDeviceStorageRequestConstructor(child, params); + ContentChild::GetSingleton()->SendPDeviceStorageRequestConstructor(child, + params); mRequest = nullptr; } @@ -1492,7 +1555,8 @@ ContinueCursorEvent::Run() { nsRefPtr file = GetNextFile(); - nsDOMDeviceStorageCursor* cursor = static_cast(mRequest.get()); + nsDOMDeviceStorageCursor* cursor + = static_cast(mRequest.get()); AutoJSContext cx; JS::Rooted val(cx, nsIFileToJsval(cursor->GetOwner(), file)); @@ -1526,16 +1590,19 @@ public: mFile->mFile->IsDirectory(&check); if (!check) { nsCOMPtr event = - new PostErrorEvent(mRequest.forget(), POST_ERROR_EVENT_FILE_NOT_ENUMERABLE); + new PostErrorEvent(mRequest.forget(), + POST_ERROR_EVENT_FILE_NOT_ENUMERABLE); NS_DispatchToMainThread(event); return NS_OK; } } - nsDOMDeviceStorageCursor* cursor = static_cast(mRequest.get()); + nsDOMDeviceStorageCursor* cursor + = static_cast(mRequest.get()); mFile->CollectFiles(cursor->mFiles, cursor->mSince); - nsCOMPtr event = new ContinueCursorEvent(mRequest.forget()); + nsCOMPtr event + = new ContinueCursorEvent(mRequest.forget()); event->Continue(); return NS_OK; @@ -1579,7 +1646,8 @@ nsDOMDeviceStorageCursor::GetStorageType(nsAString & aType) NS_IMETHODIMP nsDOMDeviceStorageCursor::GetType(nsACString & aType) { - return DeviceStorageTypeChecker::GetPermissionForType(mFile->mStorageType, aType); + return DeviceStorageTypeChecker::GetPermissionForType(mFile->mStorageType, + aType); } NS_IMETHODIMP @@ -1613,7 +1681,8 @@ nsDOMDeviceStorageCursor::GetElement(nsIDOMElement * *aRequestingElement) NS_IMETHODIMP nsDOMDeviceStorageCursor::Cancel() { - nsCOMPtr event = new PostErrorEvent(this, POST_ERROR_EVENT_PERMISSION_DENIED); + nsCOMPtr event + = new PostErrorEvent(this, POST_ERROR_EVENT_PERMISSION_DENIED); NS_DispatchToMainThread(event); return NS_OK; } @@ -1622,22 +1691,26 @@ NS_IMETHODIMP nsDOMDeviceStorageCursor::Allow() { if (!mFile->IsSafePath()) { - nsCOMPtr r = new PostErrorEvent(this, POST_ERROR_EVENT_PERMISSION_DENIED); + nsCOMPtr r + = new PostErrorEvent(this, POST_ERROR_EVENT_PERMISSION_DENIED); NS_DispatchToMainThread(r); return NS_OK; } if (XRE_GetProcessType() != GeckoProcessType_Default) { - PDeviceStorageRequestChild* child = new DeviceStorageRequestChild(this, mFile); + PDeviceStorageRequestChild* child + = new DeviceStorageRequestChild(this, mFile); DeviceStorageEnumerationParams params(mFile->mStorageType, mFile->mStorageName, mFile->mRootDir, mSince); - ContentChild::GetSingleton()->SendPDeviceStorageRequestConstructor(child, params); + ContentChild::GetSingleton()->SendPDeviceStorageRequestConstructor(child, + params); return NS_OK; } - nsCOMPtr target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); + nsCOMPtr target + = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); NS_ASSERTION(target, "Must have stream transport service"); nsCOMPtr event = new InitCursorEvent(this, mFile); @@ -1714,7 +1787,8 @@ public: } AutoJSContext cx; - JS::Rooted result(cx, StringToJsval(mRequest->GetOwner(), state)); + JS::Rooted result(cx, + StringToJsval(mRequest->GetOwner(), state)); mRequest->FireSuccess(result); mRequest = nullptr; return NS_OK; @@ -1728,17 +1802,20 @@ private: class PostResultEvent : public nsRunnable { public: - PostResultEvent(already_AddRefed aRequest, DeviceStorageFile* aFile) + PostResultEvent(already_AddRefed aRequest, + DeviceStorageFile* aFile) : mFile(aFile) , mRequest(aRequest) {} - PostResultEvent(already_AddRefed aRequest, const nsAString & aPath) + PostResultEvent(already_AddRefed aRequest, + const nsAString & aPath) : mPath(aPath) , mRequest(aRequest) {} - PostResultEvent(already_AddRefed aRequest, const uint64_t aValue) + PostResultEvent(already_AddRefed aRequest, + const uint64_t aValue) : mValue(aValue) , mRequest(aRequest) {} @@ -1797,7 +1874,8 @@ public: bool check = false; mFile->mFile->Exists(&check); if (check) { - nsCOMPtr event = new PostErrorEvent(mRequest.forget(), POST_ERROR_EVENT_FILE_EXISTS); + nsCOMPtr event = + new PostErrorEvent(mRequest.forget(), POST_ERROR_EVENT_FILE_EXISTS); NS_DispatchToMainThread(event); return NS_OK; } @@ -1807,14 +1885,16 @@ public: if (NS_FAILED(rv)) { mFile->mFile->Remove(false); - nsCOMPtr event = new PostErrorEvent(mRequest.forget(), POST_ERROR_EVENT_UNKNOWN); + nsCOMPtr event = + new PostErrorEvent(mRequest.forget(), POST_ERROR_EVENT_UNKNOWN); NS_DispatchToMainThread(event); return NS_OK; } nsString fullPath; mFile->GetFullPath(fullPath); - nsCOMPtr event = new PostResultEvent(mRequest.forget(), fullPath); + nsCOMPtr event = + new PostResultEvent(mRequest.forget(), fullPath); NS_DispatchToMainThread(event); return NS_OK; } @@ -1847,7 +1927,8 @@ public: bool check = false; mFile->mFile->Exists(&check); if (!check) { - r = new PostErrorEvent(mRequest.forget(), POST_ERROR_EVENT_FILE_DOES_NOT_EXIST); + r = new PostErrorEvent(mRequest.forget(), + POST_ERROR_EVENT_FILE_DOES_NOT_EXIST); } } @@ -1890,7 +1971,8 @@ public: bool check = false; mFile->mFile->Exists(&check); if (check) { - r = new PostErrorEvent(mRequest.forget(), POST_ERROR_EVENT_FILE_DOES_NOT_EXIST); + r = new PostErrorEvent(mRequest.forget(), + POST_ERROR_EVENT_FILE_DOES_NOT_EXIST); } else { nsString fullPath; @@ -1966,7 +2048,8 @@ public: } nsCOMPtr r; - r = new PostResultEvent(mRequest.forget(), static_cast(freeSpace)); + r = new PostResultEvent(mRequest.forget(), + static_cast(freeSpace)); NS_DispatchToMainThread(r); return NS_OK; } @@ -2011,7 +2094,8 @@ public: , mBlob(aBlob) {} NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(DeviceStorageRequest, nsIContentPermissionRequest) + NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(DeviceStorageRequest, + nsIContentPermissionRequest) NS_IMETHOD Run() { @@ -2029,27 +2113,32 @@ public: return NS_OK; } - // Retain a reference so the object isn't deleted without IPDL's knowledge. - // Corresponding release occurs in DeallocPContentPermissionRequest. + // Retain a reference so the object isn't deleted without IPDL's + // knowledge. Corresponding release occurs in + // DeallocPContentPermissionRequest. AddRef(); nsCString type; - nsresult rv = DeviceStorageTypeChecker::GetPermissionForType(mFile->mStorageType, type); + nsresult rv = DeviceStorageTypeChecker::GetPermissionForType( + mFile->mStorageType, type); if (NS_FAILED(rv)) { return rv; } nsCString access; - rv = DeviceStorageTypeChecker::GetAccessForRequest(DeviceStorageRequestType(mRequestType), access); + rv = DeviceStorageTypeChecker::GetAccessForRequest( + DeviceStorageRequestType(mRequestType), access); if (NS_FAILED(rv)) { return rv; } - child->SendPContentPermissionRequestConstructor(this, type, access, IPC::Principal(mPrincipal)); + child->SendPContentPermissionRequestConstructor( + this, type, access, IPC::Principal(mPrincipal)); Sendprompt(); return NS_OK; } - nsCOMPtr prompt = do_CreateInstance(NS_CONTENT_PERMISSION_PROMPT_CONTRACTID); + nsCOMPtr prompt + = do_CreateInstance(NS_CONTENT_PERMISSION_PROMPT_CONTRACTID); if (prompt) { prompt->Prompt(this); } @@ -2059,7 +2148,9 @@ public: NS_IMETHOD GetType(nsACString & aType) { nsCString type; - nsresult rv = DeviceStorageTypeChecker::GetPermissionForType(mFile->mStorageType, aType); + nsresult rv + = DeviceStorageTypeChecker::GetPermissionForType(mFile->mStorageType, + aType); if (NS_FAILED(rv)) { return rv; } @@ -2068,7 +2159,8 @@ public: NS_IMETHOD GetAccess(nsACString & aAccess) { - nsresult rv = DeviceStorageTypeChecker::GetAccessForRequest(DeviceStorageRequestType(mRequestType), aAccess); + nsresult rv = DeviceStorageTypeChecker::GetAccessForRequest( + DeviceStorageRequestType(mRequestType), aAccess); if (NS_FAILED(rv)) { return rv; } @@ -2095,7 +2187,9 @@ public: NS_IMETHOD Cancel() { - nsCOMPtr event = new PostErrorEvent(mRequest.forget(), POST_ERROR_EVENT_PERMISSION_DENIED); + nsCOMPtr event + = new PostErrorEvent(mRequest.forget(), + POST_ERROR_EVENT_PERMISSION_DENIED); NS_DispatchToMainThread(event); return NS_OK; } @@ -2115,21 +2209,24 @@ public: return NS_ERROR_FAILURE; } - DeviceStorageTypeChecker* typeChecker = DeviceStorageTypeChecker::CreateOrGet(); + DeviceStorageTypeChecker* typeChecker + = DeviceStorageTypeChecker::CreateOrGet(); if (!typeChecker) { return NS_OK; } if (!typeChecker->Check(mFile->mStorageType, mFile->mFile) || !typeChecker->Check(mFile->mStorageType, mBlob)) { - r = new PostErrorEvent(mRequest.forget(), POST_ERROR_EVENT_ILLEGAL_TYPE); + r = new PostErrorEvent(mRequest.forget(), + POST_ERROR_EVENT_ILLEGAL_TYPE); NS_DispatchToMainThread(r); return NS_OK; } if (XRE_GetProcessType() != GeckoProcessType_Default) { - BlobChild* actor = ContentChild::GetSingleton()->GetOrCreateActorForBlob(mBlob); + BlobChild* actor + = ContentChild::GetSingleton()->GetOrCreateActorForBlob(mBlob); if (!actor) { return NS_ERROR_FAILURE; } @@ -2140,8 +2237,10 @@ public: params.storageName() = mFile->mStorageName; params.relpath() = mFile->mPath; - PDeviceStorageRequestChild* child = new DeviceStorageRequestChild(mRequest, mFile); - ContentChild::GetSingleton()->SendPDeviceStorageRequestConstructor(child, params); + PDeviceStorageRequestChild* child + = new DeviceStorageRequestChild(mRequest, mFile); + ContentChild::GetSingleton() + ->SendPDeviceStorageRequestConstructor(child, params); return NS_OK; } r = new WriteFileEvent(mBlob, mFile, mRequest.forget()); @@ -2155,24 +2254,28 @@ public: return NS_ERROR_FAILURE; } - DeviceStorageTypeChecker* typeChecker = DeviceStorageTypeChecker::CreateOrGet(); + DeviceStorageTypeChecker* typeChecker + = DeviceStorageTypeChecker::CreateOrGet(); if (!typeChecker) { return NS_OK; } if (!typeChecker->Check(mFile->mStorageType, mFile->mFile)) { - r = new PostErrorEvent(mRequest.forget(), POST_ERROR_EVENT_ILLEGAL_TYPE); + r = new PostErrorEvent(mRequest.forget(), + POST_ERROR_EVENT_ILLEGAL_TYPE); NS_DispatchToMainThread(r); return NS_OK; } if (XRE_GetProcessType() != GeckoProcessType_Default) { - PDeviceStorageRequestChild* child = new DeviceStorageRequestChild(mRequest, mFile); + PDeviceStorageRequestChild* child + = new DeviceStorageRequestChild(mRequest, mFile); DeviceStorageGetParams params(mFile->mStorageType, mFile->mStorageName, mFile->mRootDir, mFile->mPath); - ContentChild::GetSingleton()->SendPDeviceStorageRequestConstructor(child, params); + ContentChild::GetSingleton() + ->SendPDeviceStorageRequestConstructor(child, params); return NS_OK; } @@ -2186,23 +2289,27 @@ public: return NS_ERROR_FAILURE; } - DeviceStorageTypeChecker* typeChecker = DeviceStorageTypeChecker::CreateOrGet(); + DeviceStorageTypeChecker* typeChecker + = DeviceStorageTypeChecker::CreateOrGet(); if (!typeChecker) { return NS_OK; } if (!typeChecker->Check(mFile->mStorageType, mFile->mFile)) { - r = new PostErrorEvent(mRequest.forget(), POST_ERROR_EVENT_ILLEGAL_TYPE); + r = new PostErrorEvent(mRequest.forget(), + POST_ERROR_EVENT_ILLEGAL_TYPE); NS_DispatchToMainThread(r); return NS_OK; } if (XRE_GetProcessType() != GeckoProcessType_Default) { - PDeviceStorageRequestChild* child = new DeviceStorageRequestChild(mRequest, mFile); + PDeviceStorageRequestChild* child + = new DeviceStorageRequestChild(mRequest, mFile); DeviceStorageDeleteParams params(mFile->mStorageType, mFile->mStorageName, mFile->mPath); - ContentChild::GetSingleton()->SendPDeviceStorageRequestConstructor(child, params); + ContentChild::GetSingleton() + ->SendPDeviceStorageRequestConstructor(child, params); return NS_OK; } r = new DeleteFileEvent(mFile, mRequest.forget()); @@ -2212,10 +2319,12 @@ public: case DEVICE_STORAGE_REQUEST_FREE_SPACE: { if (XRE_GetProcessType() != GeckoProcessType_Default) { - PDeviceStorageRequestChild* child = new DeviceStorageRequestChild(mRequest, mFile); + PDeviceStorageRequestChild* child + = new DeviceStorageRequestChild(mRequest, mFile); DeviceStorageFreeSpaceParams params(mFile->mStorageType, mFile->mStorageName); - ContentChild::GetSingleton()->SendPDeviceStorageRequestConstructor(child, params); + ContentChild::GetSingleton() + ->SendPDeviceStorageRequestConstructor(child, params); return NS_OK; } r = new FreeSpaceFileEvent(mFile, mRequest.forget()); @@ -2225,15 +2334,18 @@ public: case DEVICE_STORAGE_REQUEST_USED_SPACE: { if (XRE_GetProcessType() != GeckoProcessType_Default) { - PDeviceStorageRequestChild* child = new DeviceStorageRequestChild(mRequest, mFile); + PDeviceStorageRequestChild* child + = new DeviceStorageRequestChild(mRequest, mFile); DeviceStorageUsedSpaceParams params(mFile->mStorageType, mFile->mStorageName); - ContentChild::GetSingleton()->SendPDeviceStorageRequestConstructor(child, params); + ContentChild::GetSingleton() + ->SendPDeviceStorageRequestConstructor(child, params); return NS_OK; } // this needs to be dispatched to only one (1) // thread or we will do more work than required. - DeviceStorageUsedSpaceCache* usedSpaceCache = DeviceStorageUsedSpaceCache::CreateOrGet(); + DeviceStorageUsedSpaceCache* usedSpaceCache + = DeviceStorageUsedSpaceCache::CreateOrGet(); NS_ASSERTION(usedSpaceCache, "DeviceStorageUsedSpaceCache is null"); r = new UsedSpaceFileEvent(mFile, mRequest.forget()); usedSpaceCache->Dispatch(r); @@ -2243,10 +2355,12 @@ public: case DEVICE_STORAGE_REQUEST_AVAILABLE: { if (XRE_GetProcessType() != GeckoProcessType_Default) { - PDeviceStorageRequestChild* child = new DeviceStorageRequestChild(mRequest, mFile); + PDeviceStorageRequestChild* child + = new DeviceStorageRequestChild(mRequest, mFile); DeviceStorageAvailableParams params(mFile->mStorageType, mFile->mStorageName); - ContentChild::GetSingleton()->SendPDeviceStorageRequestConstructor(child, params); + ContentChild::GetSingleton() + ->SendPDeviceStorageRequestConstructor(child, params); return NS_OK; } r = new PostAvailableResultEvent(mFile, mRequest); @@ -2262,7 +2376,8 @@ public: } if (r) { - nsCOMPtr target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); + nsCOMPtr target + = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); NS_ASSERTION(target, "Must have stream transport service"); target->Dispatch(r, NS_DISPATCH_NORMAL); } @@ -2335,9 +2450,11 @@ nsDOMDeviceStorage::WrapObject(JSContext* aCx, JS::Handle aScope) } nsresult -nsDOMDeviceStorage::Init(nsPIDOMWindow* aWindow, const nsAString &aType, const nsAString &aVolName) +nsDOMDeviceStorage::Init(nsPIDOMWindow* aWindow, const nsAString &aType, + const nsAString &aVolName) { - DebugOnly observer = FileUpdateDispatcher::GetSingleton(); + DebugOnly observer + = FileUpdateDispatcher::GetSingleton(); NS_ASSERTION(observer, "FileUpdateDispatcher is null"); NS_ASSERTION(aWindow, "Must have a content dom"); @@ -2362,13 +2479,15 @@ nsDOMDeviceStorage::Init(nsPIDOMWindow* aWindow, const nsAString &aType, const n // the 'apps' type is special. We only want this exposed // if the caller has the "webapps-manage" permission. if (aType.EqualsLiteral("apps")) { - nsCOMPtr permissionManager = do_GetService(NS_PERMISSIONMANAGER_CONTRACTID); + nsCOMPtr permissionManager + = do_GetService(NS_PERMISSIONMANAGER_CONTRACTID); NS_ENSURE_TRUE(permissionManager, NS_ERROR_FAILURE); uint32_t permission; - nsresult rv = permissionManager->TestPermissionFromPrincipal(mPrincipal, - "webapps-manage", - &permission); + nsresult rv + = permissionManager->TestPermissionFromPrincipal(mPrincipal, + "webapps-manage", + &permission); if (NS_FAILED(rv) || permission != nsIPermissionManager::ALLOW_ACTION) { return NS_ERROR_NOT_AVAILABLE; @@ -2396,11 +2515,13 @@ nsDOMDeviceStorage::Shutdown() obs->RemoveObserver(this, "disk-space-watcher"); } -StaticRefPtr nsDOMDeviceStorage::sVolumeNameCache; +StaticRefPtr + nsDOMDeviceStorage::sVolumeNameCache; // static void -nsDOMDeviceStorage::GetOrderedVolumeNames(nsDOMDeviceStorage::VolumeNameArray &aVolumeNames) +nsDOMDeviceStorage::GetOrderedVolumeNames( + nsDOMDeviceStorage::VolumeNameArray &aVolumeNames) { if (sVolumeNameCache && sVolumeNameCache->mVolumeNames.Length() > 0) { aVolumeNames.AppendElements(sVolumeNameCache->mVolumeNames); @@ -2452,9 +2573,10 @@ nsDOMDeviceStorage::CreateDeviceStorageFor(nsPIDOMWindow* aWin, // static void -nsDOMDeviceStorage::CreateDeviceStoragesFor(nsPIDOMWindow* aWin, - const nsAString &aType, - nsTArray > &aStores) +nsDOMDeviceStorage::CreateDeviceStoragesFor( + nsPIDOMWindow* aWin, + const nsAString &aType, + nsTArray > &aStores) { nsresult rv; @@ -2512,7 +2634,8 @@ nsDOMDeviceStorage::ParseFullPath(const nsAString& aFullPath, } already_AddRefed -nsDOMDeviceStorage::GetStorage(const nsAString& aFullPath, nsAString& aOutStoragePath) +nsDOMDeviceStorage::GetStorage(const nsAString& aFullPath, + nsAString& aOutStoragePath) { nsString storageName; if (!ParseFullPath(aFullPath, storageName, aOutStoragePath)) { @@ -2556,7 +2679,7 @@ nsDOMDeviceStorage::GetStorageByName(const nsAString& aStorageName) // static void nsDOMDeviceStorage::GetDefaultStorageName(const nsAString& aStorageType, - nsAString& aStorageName) + nsAString& aStorageName) { // See if the preferred volume is available. nsRefPtr ds; @@ -2612,7 +2735,8 @@ nsDOMDeviceStorage::Add(nsIDOMBlob* aBlob, ErrorResult& aRv) aBlob->GetType(mimeType); nsCString extension; - mimeSvc->GetPrimaryExtension(NS_LossyConvertUTF16toASCII(mimeType), EmptyCString(), extension); + mimeSvc->GetPrimaryExtension(NS_LossyConvertUTF16toASCII(mimeType), + EmptyCString(), extension); // if extension is null here, we will ignore it for now. // AddNamed() will check the file path and fail. This // will post an onerror to the requestee. @@ -2655,7 +2779,8 @@ nsDOMDeviceStorage::AddNamed(nsIDOMBlob* aBlob, const nsAString& aPath, return nullptr; } - DeviceStorageTypeChecker* typeChecker = DeviceStorageTypeChecker::CreateOrGet(); + DeviceStorageTypeChecker* typeChecker + = DeviceStorageTypeChecker::CreateOrGet(); if (!typeChecker) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; @@ -2756,7 +2881,8 @@ nsDOMDeviceStorage::GetInternal(nsPIDOMWindow *aWin, if (!dsf->IsSafePath()) { r = new PostErrorEvent(aRequest, POST_ERROR_EVENT_PERMISSION_DENIED); } else { - r = new DeviceStorageRequest(aEditable ? DEVICE_STORAGE_REQUEST_WRITE : DEVICE_STORAGE_REQUEST_READ, + r = new DeviceStorageRequest(aEditable ? DEVICE_STORAGE_REQUEST_WRITE + : DEVICE_STORAGE_REQUEST_READ, aWin, mPrincipal, dsf, aRequest); } NS_DispatchToMainThread(r); @@ -2838,11 +2964,9 @@ nsDOMDeviceStorage::FreeSpace(ErrorResult& aRv) nsRefPtr dsf = new DeviceStorageFile(mStorageType, mStorageName); - nsCOMPtr r = new DeviceStorageRequest(DEVICE_STORAGE_REQUEST_FREE_SPACE, - win, - mPrincipal, - dsf, - request); + nsCOMPtr r + = new DeviceStorageRequest(DEVICE_STORAGE_REQUEST_FREE_SPACE, + win, mPrincipal, dsf, request); NS_DispatchToMainThread(r); return request.forget(); } @@ -2865,18 +2989,17 @@ nsDOMDeviceStorage::UsedSpace(ErrorResult& aRv) return nullptr; } - DebugOnly usedSpaceCache = DeviceStorageUsedSpaceCache::CreateOrGet(); + DebugOnly usedSpaceCache + = DeviceStorageUsedSpaceCache::CreateOrGet(); NS_ASSERTION(usedSpaceCache, "DeviceStorageUsedSpaceCache is null"); nsRefPtr request = new DOMRequest(win); nsRefPtr dsf = new DeviceStorageFile(mStorageType, mStorageName); - nsCOMPtr r = new DeviceStorageRequest(DEVICE_STORAGE_REQUEST_USED_SPACE, - win, - mPrincipal, - dsf, - request); + nsCOMPtr r + = new DeviceStorageRequest(DEVICE_STORAGE_REQUEST_USED_SPACE, + win, mPrincipal, dsf, request); NS_DispatchToMainThread(r); return request.forget(); } @@ -2903,17 +3026,16 @@ nsDOMDeviceStorage::Available(ErrorResult& aRv) nsRefPtr dsf = new DeviceStorageFile(mStorageType, mStorageName); - nsCOMPtr r = new DeviceStorageRequest(DEVICE_STORAGE_REQUEST_AVAILABLE, - win, - mPrincipal, - dsf, - request); + nsCOMPtr r + = new DeviceStorageRequest(DEVICE_STORAGE_REQUEST_AVAILABLE, + win, mPrincipal, dsf, request); NS_DispatchToMainThread(r); return request.forget(); } NS_IMETHODIMP -nsDOMDeviceStorage::GetRootDirectoryForFile(const nsAString& aName, nsIFile** aRootDirectory) +nsDOMDeviceStorage::GetRootDirectoryForFile(const nsAString& aName, + nsIFile** aRootDirectory) { nsRefPtr ds; @@ -2990,9 +3112,10 @@ nsDOMDeviceStorage::EnumerateInternal(const nsAString& aPath, EmptyString()); dsf->SetEditable(aEditable); - nsRefPtr cursor = new nsDOMDeviceStorageCursor(win, mPrincipal, - dsf, since); - nsRefPtr r = new DeviceStorageCursorRequest(cursor); + nsRefPtr cursor + = new nsDOMDeviceStorageCursor(win, mPrincipal, dsf, since); + nsRefPtr r + = new DeviceStorageCursorRequest(cursor); if (mozilla::Preferences::GetBool("device.storage.prompt.testing", false)) { r->Allow(); @@ -3016,14 +3139,17 @@ nsDOMDeviceStorage::EnumerateInternal(const nsAString& aPath, if (aRv.Failed()) { return nullptr; } - child->SendPContentPermissionRequestConstructor(r, type, NS_LITERAL_CSTRING("read"), IPC::Principal(mPrincipal)); + child->SendPContentPermissionRequestConstructor(r, type, + NS_LITERAL_CSTRING("read"), + IPC::Principal(mPrincipal)); r->Sendprompt(); return cursor.forget(); } - nsCOMPtr prompt = do_CreateInstance(NS_CONTENT_PERMISSION_PROMPT_CONTRACTID); + nsCOMPtr prompt + = do_CreateInstance(NS_CONTENT_PERMISSION_PROMPT_CONTRACTID); if (prompt) { prompt->Prompt(r); } @@ -3036,7 +3162,8 @@ void nsDOMDeviceStorage::DispatchMountChangeEvent(nsAString& aVolumeStatus) { nsCOMPtr event; - NS_NewDOMDeviceStorageChangeEvent(getter_AddRefs(event), this, nullptr, nullptr); + NS_NewDOMDeviceStorageChangeEvent(getter_AddRefs(event), this, + nullptr, nullptr); nsCOMPtr ce = do_QueryInterface(event); nsresult rv = ce->InitDeviceStorageChangeEvent(NS_LITERAL_STRING("change"), @@ -3053,7 +3180,9 @@ nsDOMDeviceStorage::DispatchMountChangeEvent(nsAString& aVolumeStatus) #endif NS_IMETHODIMP -nsDOMDeviceStorage::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData) +nsDOMDeviceStorage::Observe(nsISupports *aSubject, + const char *aTopic, + const PRUnichar *aData) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -3080,7 +3209,8 @@ nsDOMDeviceStorage::Observe(nsISupports *aSubject, const char *aTopic, const PRU #ifdef MOZ_WIDGET_GONK else if (!strcmp(aTopic, NS_VOLUME_STATE_CHANGED)) { - // We invalidate the used space cache for the volume that actually changed state. + // We invalidate the used space cache for the volume that actually changed + // state. nsCOMPtr vol = do_QueryInterface(aSubject); if (!vol) { return NS_OK; @@ -3088,7 +3218,8 @@ nsDOMDeviceStorage::Observe(nsISupports *aSubject, const char *aTopic, const PRU nsString volName; vol->GetName(volName); - DeviceStorageUsedSpaceCache* usedSpaceCache = DeviceStorageUsedSpaceCache::CreateOrGet(); + DeviceStorageUsedSpaceCache* usedSpaceCache + = DeviceStorageUsedSpaceCache::CreateOrGet(); NS_ASSERTION(usedSpaceCache, "DeviceStorageUsedSpaceCache is null"); usedSpaceCache->Invalidate(volName); @@ -3156,10 +3287,12 @@ nsDOMDeviceStorage::AddEventListener(const nsAString & aType, nsRefPtr request = new DOMRequest(win); nsRefPtr dsf = new DeviceStorageFile(mStorageType, mStorageName); - nsCOMPtr r = new DeviceStorageRequest(DEVICE_STORAGE_REQUEST_WATCH, - win, mPrincipal, dsf, request, this); + nsCOMPtr r + = new DeviceStorageRequest(DEVICE_STORAGE_REQUEST_WATCH, + win, mPrincipal, dsf, request, this); NS_DispatchToMainThread(r); - return nsDOMEventTargetHelper::AddEventListener(aType, aListener, aUseCapture, aWantsUntrusted, aArgc); + return nsDOMEventTargetHelper::AddEventListener(aType, aListener, aUseCapture, + aWantsUntrusted, aArgc); } void @@ -3178,10 +3311,12 @@ nsDOMDeviceStorage::AddEventListener(const nsAString & aType, nsRefPtr request = new DOMRequest(win); nsRefPtr dsf = new DeviceStorageFile(mStorageType, mStorageName); - nsCOMPtr r = new DeviceStorageRequest(DEVICE_STORAGE_REQUEST_WATCH, - win, mPrincipal, dsf, request, this); + nsCOMPtr r + = new DeviceStorageRequest(DEVICE_STORAGE_REQUEST_WATCH, + win, mPrincipal, dsf, request, this); NS_DispatchToMainThread(r); - nsDOMEventTargetHelper::AddEventListener(aType, aListener, aUseCapture, aWantsUntrusted, aRv); + nsDOMEventTargetHelper::AddEventListener(aType, aListener, aUseCapture, + aWantsUntrusted, aRv); } NS_IMETHODIMP @@ -3197,7 +3332,8 @@ nsDOMDeviceStorage::AddSystemEventListener(const nsAString & aType, mIsWatchingFile = true; } - return nsDOMDeviceStorage::AddEventListener(aType,aListener,aUseCapture,aWantsUntrusted, aArgc); + return nsDOMDeviceStorage::AddEventListener(aType, aListener, aUseCapture, + aWantsUntrusted, aArgc); } NS_IMETHODIMP From ebee3cf115efc5a77902869b926b36af3056dbc4 Mon Sep 17 00:00:00 2001 From: Gaia Pushbot Date: Fri, 2 Aug 2013 16:40:25 -0700 Subject: [PATCH 04/10] Bumping gaia.json for 4 gaia-central revision(s) ======== https://hg.mozilla.org/integration/gaia-central/rev/25f044f2ab15 Author: Dave Hylands Desc: Merge pull request #11326 from dhylands/dhylands-893284-ds-test Bug 893284 - Fix ds-test to work with composite support removed. r=djf ======== https://hg.mozilla.org/integration/gaia-central/rev/0c3903493eb9 Author: Dave Hylands Desc: Bug 893284 - Fix ds-test to work with composite support removed. ======== https://hg.mozilla.org/integration/gaia-central/rev/c508b25f290c Author: Dave Hylands Desc: Merge pull request #11325 from dhylands/dhylands-893282-mediadb Bug 893282 - Fix mediadb to scan all device storage areas. r=djf ======== https://hg.mozilla.org/integration/gaia-central/rev/1e490c3e8206 Author: Dave Hylands Desc: Bug 893282 - Fix mediadb to scan all device storage areas. --- b2g/config/gaia.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/b2g/config/gaia.json b/b2g/config/gaia.json index f6560bfaef28..bcbbf2cdb5f0 100644 --- a/b2g/config/gaia.json +++ b/b2g/config/gaia.json @@ -1,4 +1,4 @@ { - "revision": "8561359fa10c204ab1d3660382d5a40604dafa00", + "revision": "25f044f2ab1542ab4e015f67f0f256252cf28e67", "repo_path": "/integration/gaia-central" } From 77bd411859a1e97088b389e23758bc8c99723210 Mon Sep 17 00:00:00 2001 From: Dave Hylands Date: Fri, 2 Aug 2013 16:50:02 -0700 Subject: [PATCH 05/10] Bug 898074 - Defer close to ensure that it doesn't happen before onPacket processing. r=dcamp --- toolkit/devtools/server/transport.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/toolkit/devtools/server/transport.js b/toolkit/devtools/server/transport.js index 72d62a57d7df..0ec350348085 100644 --- a/toolkit/devtools/server/transport.js +++ b/toolkit/devtools/server/transport.js @@ -125,11 +125,14 @@ DebuggerTransport.prototype = { onStopRequest: makeInfallible(function DT_onStopRequest(aRequest, aContext, aStatus) { - this.close(); - if (this.hooks) { - this.hooks.onClosed(aStatus); - this.hooks = null; - } + let self = this; + Services.tm.currentThread.dispatch(makeInfallible(function() { + self.close(); + if (self.hooks) { + self.hooks.onClosed(aStatus); + self.hooks = null; + } + }, "DebuggerTransport instance's this.close"), 0); }, "DebuggerTransport.prototype.onStopRequest"), onDataAvailable: From 93c54d4a20ffe8e8c81a16ca87d6c127440b7e34 Mon Sep 17 00:00:00 2001 From: Gaia Pushbot Date: Sun, 4 Aug 2013 08:45:24 -0700 Subject: [PATCH 06/10] Bumping gaia.json for 2 gaia-central revision(s) ======== https://hg.mozilla.org/integration/gaia-central/rev/3e7b6feeeade Author: David Flanagan Desc: Merge pull request #11328 from jimporter/music-fix-mediadb Bug 901309 - Fix issues with device storage in mediadb.js ======== https://hg.mozilla.org/integration/gaia-central/rev/c21987e9671c Author: Jim Porter Desc: Bug 901309 - Fix issues with device storage in mediadb.js --- b2g/config/gaia.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/b2g/config/gaia.json b/b2g/config/gaia.json index bcbbf2cdb5f0..7023a45bd082 100644 --- a/b2g/config/gaia.json +++ b/b2g/config/gaia.json @@ -1,4 +1,4 @@ { - "revision": "25f044f2ab1542ab4e015f67f0f256252cf28e67", + "revision": "3e7b6feeeadedc472368ecad65016a6df75570f5", "repo_path": "/integration/gaia-central" } From 2e2cee17613e3041d82bb53361d1a60679a708b6 Mon Sep 17 00:00:00 2001 From: Yoshi Huang Date: Thu, 1 Aug 2013 14:57:25 +0800 Subject: [PATCH 07/10] Bug 883741 - Part 1: WebCrypto: Move Crypto to WebIDL. r=bz --- dom/base/Crypto.cpp | 127 ++--- dom/base/Crypto.h | 68 ++- dom/base/nsDOMClassInfo.cpp | 10 - dom/base/nsDOMClassInfoClasses.h | 1 - dom/base/nsGlobalWindow.cpp | 7 +- dom/bindings/Bindings.conf | 5 + dom/interfaces/base/nsIDOMCrypto.idl | 8 +- dom/interfaces/base/nsIDOMCryptoLegacy.idl | 18 +- .../crypto/test_getRandomValues.html | 2 +- dom/webidl/Crypto.webidl | 63 +++ dom/webidl/WebIDL.mk | 1 + js/xpconnect/src/dom_quickstubs.qsconf | 1 - security/manager/ssl/src/nsCrypto.cpp | 456 ++++++++---------- security/manager/ssl/src/nsCrypto.h | 44 +- 14 files changed, 434 insertions(+), 377 deletions(-) create mode 100644 dom/webidl/Crypto.webidl diff --git a/dom/base/Crypto.cpp b/dom/base/Crypto.cpp index e77e14a62238..4227de8a6909 100644 --- a/dom/base/Crypto.cpp +++ b/dom/base/Crypto.cpp @@ -2,16 +2,15 @@ * 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 "Crypto.h" -#include "nsIDOMClassInfo.h" #include "DOMError.h" #include "nsString.h" -#include "jsapi.h" #include "jsfriendapi.h" #include "nsIServiceManager.h" #include "nsCOMPtr.h" #include "nsIRandomGenerator.h" #include "mozilla/dom/ContentChild.h" +#include "mozilla/dom/CryptoBinding.h" using mozilla::dom::ContentChild; @@ -20,18 +19,21 @@ using namespace js::ArrayBufferView; namespace mozilla { namespace dom { -NS_INTERFACE_MAP_BEGIN(Crypto) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Crypto) + NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_ENTRY(nsIDOMCrypto) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Crypto) NS_INTERFACE_MAP_END -NS_IMPL_ADDREF(Crypto) -NS_IMPL_RELEASE(Crypto) +NS_IMPL_CYCLE_COLLECTING_ADDREF(Crypto) +NS_IMPL_CYCLE_COLLECTING_RELEASE(Crypto) + +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(Crypto, mWindow) Crypto::Crypto() { MOZ_COUNT_CTOR(Crypto); + SetIsDOMBinding(); } Crypto::~Crypto() @@ -39,23 +41,25 @@ Crypto::~Crypto() MOZ_COUNT_DTOR(Crypto); } -NS_IMETHODIMP -Crypto::GetRandomValues(const JS::Value& aData, JSContext *cx, - JS::Value* _retval) +void +Crypto::Init(nsIDOMWindow* aWindow) +{ + mWindow = do_QueryInterface(aWindow); + MOZ_ASSERT(mWindow); +} + +/* virtual */ JSObject* +Crypto::WrapObject(JSContext* aCx, JS::Handle aScope) +{ + return CryptoBinding::Wrap(aCx, aScope, this); +} + +JSObject * +Crypto::GetRandomValues(JSContext* aCx, ArrayBufferView& aArray, ErrorResult& aRv) { NS_ABORT_IF_FALSE(NS_IsMainThread(), "Called on the wrong thread"); - // Make sure this is a JavaScript object - if (!aData.isObject()) { - return NS_ERROR_DOM_NOT_OBJECT_ERR; - } - - JS::Rooted view(cx, &aData.toObject()); - - // Make sure this object is an ArrayBufferView - if (!JS_IsTypedArrayObject(view)) { - return NS_ERROR_DOM_TYPE_MISMATCH_ERR; - } + JS::Rooted view(aCx, aArray.Obj()); // Throw if the wrong type of ArrayBufferView is passed in // (Part of the Web Crypto API spec) @@ -69,29 +73,28 @@ Crypto::GetRandomValues(const JS::Value& aData, JSContext *cx, case TYPE_UINT32: break; default: - return NS_ERROR_DOM_TYPE_MISMATCH_ERR; + aRv.Throw(NS_ERROR_DOM_TYPE_MISMATCH_ERR); + return nullptr; } - uint32_t dataLen = JS_GetTypedArrayByteLength(view); - + uint32_t dataLen = aArray.Length(); if (dataLen == 0) { NS_WARNING("ArrayBufferView length is 0, cannot continue"); - return NS_OK; + return view; } else if (dataLen > 65536) { - return NS_ERROR_DOM_QUOTA_EXCEEDED_ERR; + aRv.Throw(NS_ERROR_DOM_QUOTA_EXCEEDED_ERR); + return nullptr; } - void *dataptr = JS_GetArrayBufferViewData(view); - NS_ENSURE_TRUE(dataptr, NS_ERROR_FAILURE); - unsigned char* data = - static_cast(dataptr); + uint8_t* data = aArray.Data(); if (XRE_GetProcessType() != GeckoProcessType_Default) { InfallibleTArray randomValues; // Tell the parent process to generate random values via PContent ContentChild* cc = ContentChild::GetSingleton(); if (!cc->SendGetRandomValues(dataLen, &randomValues)) { - return NS_ERROR_FAILURE; + aRv.Throw(NS_ERROR_FAILURE); + return nullptr; } NS_ASSERTION(dataLen == randomValues.Length(), "Invalid length returned from parent process!"); @@ -100,28 +103,21 @@ Crypto::GetRandomValues(const JS::Value& aData, JSContext *cx, uint8_t *buf = GetRandomValues(dataLen); if (!buf) { - return NS_ERROR_FAILURE; + aRv.Throw(NS_ERROR_FAILURE); + return nullptr; } memcpy(data, buf, dataLen); NS_Free(buf); } - *_retval = OBJECT_TO_JSVAL(view); - - return NS_OK; + return view; } #ifndef MOZ_DISABLE_CRYPTOLEGACY // Stub out the legacy nsIDOMCrypto methods. The actual // implementations are in security/manager/ssl/src/nsCrypto.{cpp,h} -NS_IMETHODIMP -Crypto::GetVersion(nsAString & aVersion) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - NS_IMETHODIMP Crypto::GetEnableSmartCardEvents(bool *aEnableSmartCardEvents) { @@ -133,61 +129,14 @@ Crypto::SetEnableSmartCardEvents(bool aEnableSmartCardEvents) { return NS_ERROR_NOT_IMPLEMENTED; } - -NS_IMETHODIMP -Crypto::GenerateCRMFRequest(nsIDOMCRMFObject * *_retval) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -Crypto::ImportUserCertificates(const nsAString & nickname, - const nsAString & cmmfResponse, - bool doForcedBackup, nsAString & _retval) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -Crypto::PopChallengeResponse(const nsAString & challenge, - nsAString & _retval) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -Crypto::Random(int32_t numBytes, nsAString & _retval) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -Crypto::SignText(const nsAString & stringToSign, const nsAString & caOption, - nsAString & _retval) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -Crypto::Logout() -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -Crypto::DisableRightClick() -{ - return NS_ERROR_NOT_IMPLEMENTED; -} #endif -uint8_t* +/* static */ uint8_t* Crypto::GetRandomValues(uint32_t aLength) { nsCOMPtr randomGenerator; nsresult rv; - randomGenerator = - do_GetService("@mozilla.org/security/random-generator;1"); + randomGenerator = do_GetService("@mozilla.org/security/random-generator;1"); NS_ENSURE_TRUE(randomGenerator, nullptr); uint8_t* buf; diff --git a/dom/base/Crypto.h b/dom/base/Crypto.h index c22dc8ad06f9..4e5da69b288c 100644 --- a/dom/base/Crypto.h +++ b/dom/base/Crypto.h @@ -8,25 +8,89 @@ #include "nsIDOMCrypto.h" #else #include "nsIDOMCryptoLegacy.h" +#include "nsIDOMCRMFObject.h" #endif +#include "nsPIDOMWindow.h" +#include "nsWrapperCache.h" +#include "mozilla/dom/BindingDeclarations.h" +#include "mozilla/dom/TypedArray.h" #define NS_DOMCRYPTO_CID \ {0x929d9320, 0x251e, 0x11d4, { 0x8a, 0x7c, 0x00, 0x60, 0x08, 0xc8, 0x44, 0xc3} } namespace mozilla { namespace dom { -class Crypto : public nsIDOMCrypto +class Crypto : public nsIDOMCrypto, + public nsWrapperCache { public: Crypto(); virtual ~Crypto(); - NS_DECL_ISUPPORTS NS_DECL_NSIDOMCRYPTO + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Crypto) + + JSObject * + GetRandomValues(JSContext* aCx, ArrayBufferView& aArray, ErrorResult& aRv); + +#ifndef MOZ_DISABLE_CRYPTOLEGACY + virtual bool EnableSmartCardEvents() = 0; + virtual void SetEnableSmartCardEvents(bool aEnable, ErrorResult& aRv) = 0; + + virtual void GetVersion(nsString& aVersion) = 0; + + virtual already_AddRefed + GenerateCRMFRequest(JSContext* aContext, + const nsCString& aReqDN, + const nsCString& aRegToken, + const nsCString& aAuthenticator, + const nsCString& aEaCert, + const nsCString& aJsCallback, + const Sequence& aArgs, + ErrorResult& aRv) = 0; + + virtual void ImportUserCertificates(const nsAString& aNickname, + const nsAString& aCmmfResponse, + bool aDoForcedBackup, + nsAString& aReturn, + ErrorResult& aRv) = 0; + + virtual void PopChallengeResponse(const nsAString& aChallenge, + nsAString& aReturn, + ErrorResult& aRv) = 0; + + virtual void Random(int32_t aNumBytes, nsAString& aReturn, ErrorResult& aRv) = 0; + + virtual void SignText(JSContext* aContext, + const nsAString& aStringToSign, + const nsAString& aCaOption, + const Sequence& aArgs, + nsAString& aReturn) = 0; + + virtual void Logout(ErrorResult& aRv) = 0; + + virtual void DisableRightClick(ErrorResult& aRv) = 0; +#endif + + // WebIDL + + nsPIDOMWindow* + GetParentObject() const + { + return mWindow; + } + + virtual JSObject* + WrapObject(JSContext* aCx, JS::Handle aScope) MOZ_OVERRIDE; + static uint8_t* GetRandomValues(uint32_t aLength); + +private: + nsCOMPtr mWindow; }; } // namespace dom diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 5b1b613124cb..60e5bbc1297f 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -160,9 +160,6 @@ #include "nsIDOMXULCommandDispatcher.h" #ifndef MOZ_DISABLE_CRYPTOLEGACY #include "nsIDOMCRMFObject.h" -#include "nsIDOMCryptoLegacy.h" -#else -#include "nsIDOMCrypto.h" #endif #include "nsIControllers.h" #include "nsISelection.h" @@ -319,7 +316,6 @@ const uint32_t kDOMClassInfo_##_dom_class##_interfaces = \ #ifndef MOZ_DISABLE_CRYPTOLEGACY DOMCI_DATA_NO_CLASS(CRMFObject) #endif -DOMCI_DATA_NO_CLASS(Crypto) DOMCI_DATA_NO_CLASS(ContentFrameMessageManager) DOMCI_DATA_NO_CLASS(ChromeMessageBroadcaster) @@ -502,8 +498,6 @@ static nsDOMClassInfoData sClassInfoData[] = { NS_DEFINE_CLASSINFO_DATA(CRMFObject, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) #endif - NS_DEFINE_CLASSINFO_DATA(Crypto, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS) // DOM Chrome Window class. NS_DEFINE_CLASSINFO_DATA(ChromeWindow, nsWindowSH, @@ -1340,10 +1334,6 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_END #endif - DOM_CLASSINFO_MAP_BEGIN(Crypto, nsIDOMCrypto) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCrypto) - DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(ChromeWindow, nsIDOMWindow) DOM_CLASSINFO_WINDOW_MAP_ENTRIES(true) DOM_CLASSINFO_MAP_ENTRY(nsIDOMChromeWindow) diff --git a/dom/base/nsDOMClassInfoClasses.h b/dom/base/nsDOMClassInfoClasses.h index 6d388c879bde..d914f714c23f 100644 --- a/dom/base/nsDOMClassInfoClasses.h +++ b/dom/base/nsDOMClassInfoClasses.h @@ -45,7 +45,6 @@ DOMCI_CLASS(TreeContentView) #ifndef MOZ_DISABLE_CRYPTOLEGACY DOMCI_CLASS(CRMFObject) #endif -DOMCI_CLASS(Crypto) // DOM Chrome Window class, almost identical to Window DOMCI_CLASS(ChromeWindow) diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index d2d114840ddb..25756bd5c2be 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -1679,6 +1679,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGlobalWindow) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPersonalbar) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStatusbar) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mScrollbars) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCrypto) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindow) @@ -1733,6 +1734,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindow) NS_IMPL_CYCLE_COLLECTION_UNLINK(mPersonalbar) NS_IMPL_CYCLE_COLLECTION_UNLINK(mStatusbar) NS_IMPL_CYCLE_COLLECTION_UNLINK(mScrollbars) + NS_IMPL_CYCLE_COLLECTION_UNLINK(mCrypto) NS_IMPL_CYCLE_COLLECTION_UNLINK_END struct TraceData @@ -3878,10 +3880,13 @@ nsGlobalWindow::GetCrypto(nsIDOMCrypto** aCrypto) if (!mCrypto) { #ifndef MOZ_DISABLE_CRYPTOLEGACY - mCrypto = do_CreateInstance(NS_CRYPTO_CONTRACTID); + nsresult rv; + mCrypto = do_CreateInstance(NS_CRYPTO_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); #else mCrypto = new Crypto(); #endif + mCrypto->Init(this); } NS_IF_ADDREF(*aCrypto = mCrypto); return NS_OK; diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index dbd22ef00deb..f199dffdde8e 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -204,6 +204,11 @@ DOMInterfaces = { 'headerFile': 'nsGeoPosition.h' }, +'Crypto' : { + 'implicitJSContext': [ 'generateCRMFRequest', 'signText' ], + 'headerFile': 'Crypto.h' +}, + 'CSS': { 'concrete': False, }, diff --git a/dom/interfaces/base/nsIDOMCrypto.idl b/dom/interfaces/base/nsIDOMCrypto.idl index 3a19ae76ed11..d387ca25ea56 100644 --- a/dom/interfaces/base/nsIDOMCrypto.idl +++ b/dom/interfaces/base/nsIDOMCrypto.idl @@ -4,9 +4,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "nsISupports.idl" - -[scriptable, uuid(a0a3bc68-eab3-4e66-b5cb-b1d86765119c)] + +interface nsIDOMWindow; + +[uuid(729cfcad-11b4-4338-b97e-5c023ae295fa)] interface nsIDOMCrypto : nsISupports { - [implicit_jscontext] jsval getRandomValues(in jsval aData); + [notxpcom] void init(in nsIDOMWindow window); }; diff --git a/dom/interfaces/base/nsIDOMCryptoLegacy.idl b/dom/interfaces/base/nsIDOMCryptoLegacy.idl index 2024ac2c0fa9..071c676eefdd 100644 --- a/dom/interfaces/base/nsIDOMCryptoLegacy.idl +++ b/dom/interfaces/base/nsIDOMCryptoLegacy.idl @@ -6,23 +6,11 @@ #include "domstubs.idl" interface nsIDOMCRMFObject; +interface nsIDOMWindow; -[scriptable, uuid(e1df1d4d-41ef-4225-934a-107c5d612686)] +[uuid(c25ecf08-3f46-4420-bee4-8505792fd63a)] interface nsIDOMCrypto : nsISupports { - readonly attribute DOMString version; + [notxpcom] void init(in nsIDOMWindow window); attribute boolean enableSmartCardEvents; - - nsIDOMCRMFObject generateCRMFRequest(/* ... */); - DOMString importUserCertificates(in DOMString nickname, - in DOMString cmmfResponse, - in boolean doForcedBackup); - DOMString popChallengeResponse(in DOMString challenge); - DOMString random(in long numBytes); - DOMString signText(in DOMString stringToSign, - in DOMString caOption /* ... */); - void logout(); - void disableRightClick(); - - [implicit_jscontext] jsval getRandomValues(in jsval aData); }; diff --git a/dom/tests/mochitest/crypto/test_getRandomValues.html b/dom/tests/mochitest/crypto/test_getRandomValues.html index 4e2c286a9bc1..bbaddc5a2eb7 100644 --- a/dom/tests/mochitest/crypto/test_getRandomValues.html +++ b/dom/tests/mochitest/crypto/test_getRandomValues.html @@ -125,7 +125,7 @@ function onWindowLoad() window.crypto.getRandomValues(null); } catch (ex) { - var test = ex.toString().search(/1003/); + var test = ex.toString().search(/1003|TypeError/); ok((test > -1), "Expected TYPE_ERR, got " + ex + "."); } diff --git a/dom/webidl/Crypto.webidl b/dom/webidl/Crypto.webidl new file mode 100644 index 000000000000..04e9c463b4cc --- /dev/null +++ b/dom/webidl/Crypto.webidl @@ -0,0 +1,63 @@ +/* -*- Mode: IDL; 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/. + * + * The origin of this IDL file is + * http://www.w3.org/TR/WebCryptoAPI/ + */ + +[NoInterfaceObject] +interface RandomSource { + [Throws] + ArrayBufferView getRandomValues(ArrayBufferView array); +}; + +Crypto implements RandomSource; + +interface Crypto { +}; + +#ifndef MOZ_DISABLE_CRYPTOLEGACY +interface CRMFObject; + +[NoInterfaceObject] +interface CryptoLegacy { + readonly attribute DOMString version; + + [SetterThrows] + attribute boolean enableSmartCardEvents; + + [Throws] + CRMFObject generateCRMFRequest(ByteString? reqDN, + ByteString? regToken, + ByteString? authenticator, + ByteString? eaCert, + ByteString? jsCallback, + any... args); + + [Throws] + DOMString importUserCertificates(DOMString nickname, + DOMString cmmfResponse, + boolean doForcedBackup); + + [Throws] + DOMString popChallengeResponse(DOMString challenge); + + [Throws] + DOMString random(long numBytes); + + DOMString signText(DOMString stringToSign, + DOMString caOption, + ByteString... args); + + [Throws] + void logout(); + + [Throws] + void disableRightClick(); +}; + +Crypto implements CryptoLegacy; +#endif // !MOZ_DISABLE_CRYPTOLEGACY + diff --git a/dom/webidl/WebIDL.mk b/dom/webidl/WebIDL.mk index f8c41e2bee62..a784254f8656 100644 --- a/dom/webidl/WebIDL.mk +++ b/dom/webidl/WebIDL.mk @@ -9,6 +9,7 @@ generated_webidl_files = \ $(NULL) preprocessed_webidl_files = \ + Crypto.webidl \ Navigator.webidl \ $(NULL) diff --git a/js/xpconnect/src/dom_quickstubs.qsconf b/js/xpconnect/src/dom_quickstubs.qsconf index 4f08ca12e33b..23ded1a20792 100644 --- a/js/xpconnect/src/dom_quickstubs.qsconf +++ b/js/xpconnect/src/dom_quickstubs.qsconf @@ -19,7 +19,6 @@ members = [ # # Note that many implementations of interfaces in this directory # use GetCurrentNativeCallContext, notably: - # - nsIDOMCrypto.{generateCRMFRequest,signText} # - nsIDOMLocation.reload # - nsIDOMNSHistory.go # - nsIDOMJSPluginArray.refresh diff --git a/security/manager/ssl/src/nsCrypto.cpp b/security/manager/ssl/src/nsCrypto.cpp index ee27db291576..7af694c0f0f1 100644 --- a/security/manager/ssl/src/nsCrypto.cpp +++ b/security/manager/ssl/src/nsCrypto.cpp @@ -74,9 +74,11 @@ #include "nsNSSCertHelper.h" #include +#include "nsWrapperCacheInlines.h" #endif using namespace mozilla; +using namespace mozilla::dom; /* * These are the most common error strings that are returned @@ -256,30 +258,50 @@ nsCrypto::~nsCrypto() { } -NS_IMETHODIMP -nsCrypto::SetEnableSmartCardEvents(bool aEnable) +void +nsCrypto::Init(nsIDOMWindow* aWindow) +{ + mozilla::dom::Crypto::Init(aWindow); +} + +void +nsCrypto::SetEnableSmartCardEvents(bool aEnable, ErrorResult& aRv) { nsresult rv = NS_OK; // this has the side effect of starting the nssComponent (and initializing - // NSS) even if it isn't already going. Starting the nssComponent is a + // NSS) even if it isn't already going. Starting the nssComponent is a // prerequisite for getting smartCard events. if (aEnable) { nsCOMPtr nssComponent(do_GetService(kNSSComponentCID, &rv)); } if (NS_FAILED(rv)) { - return rv; + aRv.Throw(rv); + return; } mEnableSmartCardEvents = aEnable; - return NS_OK; +} + +NS_IMETHODIMP +nsCrypto::SetEnableSmartCardEvents(bool aEnable) +{ + ErrorResult rv; + SetEnableSmartCardEvents(aEnable, rv); + return rv.ErrorCode(); +} + +bool +nsCrypto::EnableSmartCardEvents() +{ + return mEnableSmartCardEvents; } NS_IMETHODIMP nsCrypto::GetEnableSmartCardEvents(bool *aEnable) { - *aEnable = mEnableSmartCardEvents; + *aEnable = EnableSmartCardEvents(); return NS_OK; } @@ -294,11 +316,10 @@ ns_can_escrow(nsKeyGenType keyGenType) //Retrieve crypto.version so that callers know what //version of PSM this is. -NS_IMETHODIMP -nsCrypto::GetVersion(nsAString& aVersion) +void +nsCrypto::GetVersion(nsString& aVersion) { - aVersion.Assign(NS_LITERAL_STRING(PSM_VERSION_STRING).get()); - return NS_OK; + aVersion.Assign(NS_LITERAL_STRING(PSM_VERSION_STRING)); } /* @@ -1831,132 +1852,85 @@ GetISupportsFromContext(JSContext *cx) //The top level method which is a member of nsIDOMCrypto //for generate a base64 encoded CRMF request. -NS_IMETHODIMP -nsCrypto::GenerateCRMFRequest(nsIDOMCRMFObject** aReturn) +already_AddRefed +nsCrypto::GenerateCRMFRequest(JSContext* aContext, + const nsCString& aReqDN, + const nsCString& aRegToken, + const nsCString& aAuthenticator, + const nsCString& aEaCert, + const nsCString& aJsCallback, + const Sequence& aArgs, + ErrorResult& aRv) { nsNSSShutDownPreventionLock locker; - *aReturn = nullptr; + nsCOMPtr crmf; nsresult nrv; - nsCOMPtr xpc(do_GetService(nsIXPConnect::GetCID(), &nrv)); - NS_ENSURE_SUCCESS(nrv, nrv); - nsAXPCNativeCallContext *ncc = nullptr; - - nrv = xpc->GetCurrentNativeCallContext(&ncc); - NS_ENSURE_SUCCESS(nrv, nrv); - - if (!ncc) - return NS_ERROR_NOT_AVAILABLE; - - uint32_t argc; - - ncc->GetArgc(&argc); - - JS::Value *argv = nullptr; - - nrv = ncc->GetArgvPtr(&argv); - NS_ENSURE_SUCCESS(nrv, nrv); - - JSContext *cx; - - nrv = ncc->GetJSContext(&cx); - NS_ENSURE_SUCCESS(nrv, nrv); - - nsCOMPtr holder; + uint32_t argc = aArgs.Length(); /* * Get all of the parameters. */ - if (argc < 5 || ((argc-5) % 3) != 0) { - JS_ReportError(cx, "%s%s", JS_ERROR, - "incorrect number of parameters"); - return NS_ERROR_FAILURE; + if (argc % 3 != 0) { + aRv.ThrowNotEnoughArgsError(); + return nullptr; } - - if (JSVAL_IS_NULL(argv[0])) { - JS_ReportError(cx, "%s%s", JS_ERROR, "no DN specified"); - return NS_ERROR_FAILURE; - } - - JSString *jsString = JS_ValueToString(cx,argv[0]); - NS_ENSURE_TRUE(jsString, NS_ERROR_OUT_OF_MEMORY); - argv[0] = STRING_TO_JSVAL(jsString); - JSAutoByteString reqDN(cx,jsString); - NS_ENSURE_TRUE(!!reqDN, NS_ERROR_OUT_OF_MEMORY); - JSAutoByteString regToken; - if (!JSVAL_IS_NULL(argv[1])) { - jsString = JS_ValueToString(cx, argv[1]); - NS_ENSURE_TRUE(jsString, NS_ERROR_OUT_OF_MEMORY); - argv[1] = STRING_TO_JSVAL(jsString); - regToken.encodeLatin1(cx, jsString); - NS_ENSURE_TRUE(!!regToken, NS_ERROR_OUT_OF_MEMORY); + if (aReqDN.IsVoid()) { + NS_WARNING("no DN specified"); + aRv.Throw(NS_ERROR_FAILURE); + return nullptr; } - JSAutoByteString authenticator; - if (!JSVAL_IS_NULL(argv[2])) { - jsString = JS_ValueToString(cx, argv[2]); - NS_ENSURE_TRUE(jsString, NS_ERROR_OUT_OF_MEMORY); - argv[2] = STRING_TO_JSVAL(jsString); - authenticator.encodeLatin1(cx, jsString); - NS_ENSURE_TRUE(!!authenticator, NS_ERROR_OUT_OF_MEMORY); - } - JSAutoByteString eaCert; - if (!JSVAL_IS_NULL(argv[3])) { - jsString = JS_ValueToString(cx, argv[3]); - NS_ENSURE_TRUE(jsString, NS_ERROR_OUT_OF_MEMORY); - argv[3] = STRING_TO_JSVAL(jsString); - eaCert.encodeLatin1(cx, jsString); - NS_ENSURE_TRUE(!!eaCert, NS_ERROR_OUT_OF_MEMORY); - } - if (JSVAL_IS_NULL(argv[4])) { - JS_ReportError(cx, "%s%s", JS_ERROR, "no completion " - "function specified"); - return NS_ERROR_FAILURE; - } - jsString = JS_ValueToString(cx, argv[4]); - NS_ENSURE_TRUE(jsString, NS_ERROR_OUT_OF_MEMORY); - argv[4] = STRING_TO_JSVAL(jsString); - JSAutoByteString jsCallback(cx, jsString); - NS_ENSURE_TRUE(!!jsCallback, NS_ERROR_OUT_OF_MEMORY); - nrv = xpc->WrapNative(cx, JS::CurrentGlobalOrNull(cx), - static_cast(this), - NS_GET_IID(nsIDOMCrypto), getter_AddRefs(holder)); - NS_ENSURE_SUCCESS(nrv, nrv); + if (aJsCallback.IsVoid()) { + NS_WARNING("no completion function specified"); + aRv.Throw(NS_ERROR_FAILURE); + return nullptr; + } - JS::RootedObject script_obj(cx, holder->GetJSObject()); - NS_ENSURE_STATE(script_obj); + JS::RootedObject script_obj(aContext, GetWrapper()); + if (MOZ_UNLIKELY(!script_obj)) { + aRv.Throw(NS_ERROR_UNEXPECTED); + return nullptr; + } - //Put up some UI warning that someone is trying to + //Put up some UI warning that someone is trying to //escrow the private key. //Don't addref this copy. That way ths reference goes away //at the same the nsIX09Cert ref goes away. nsNSSCertificate *escrowCert = nullptr; nsCOMPtr nssCert; bool willEscrow = false; - if (!!eaCert) { + if (!aEaCert.IsVoid()) { SECItem certDer = {siBuffer, nullptr, 0}; - SECStatus srv = ATOB_ConvertAsciiToItem(&certDer, eaCert.ptr()); + SECStatus srv = ATOB_ConvertAsciiToItem(&certDer, aEaCert.get()); if (srv != SECSuccess) { - return NS_ERROR_FAILURE; + aRv.Throw(NS_ERROR_FAILURE); + return nullptr; } ScopedCERTCertificate cert(CERT_NewTempCertificate(CERT_GetDefaultCertDB(), &certDer, nullptr, false, true)); - if (!cert) - return NS_ERROR_FAILURE; + if (!cert) { + aRv.Throw(NS_ERROR_FAILURE); + return nullptr; + } escrowCert = nsNSSCertificate::Create(cert); nssCert = escrowCert; - if (!nssCert) - return NS_ERROR_OUT_OF_MEMORY; + if (!nssCert) { + aRv.Throw(NS_ERROR_OUT_OF_MEMORY); + return nullptr; + } nsCOMPtr dialogs; nsresult rv = getNSSDialogs(getter_AddRefs(dialogs), NS_GET_IID(nsIDOMCryptoDialogs), NS_DOMCRYPTODIALOGS_CONTRACTID); - if (NS_FAILED(rv)) - return rv; + if (NS_FAILED(rv)) { + aRv.Throw(rv); + return nullptr; + } bool okay=false; { @@ -1968,53 +1942,57 @@ nsCrypto::GenerateCRMFRequest(nsIDOMCRMFObject** aReturn) dialogs->ConfirmKeyEscrow(nssCert, &okay); } } - if (!okay) - return NS_OK; + if (!okay) { + aRv.Throw(NS_ERROR_FAILURE); + return nullptr; + } willEscrow = true; } nsCOMPtr uiCxt = new PipUIContext; - int32_t numRequests = (argc - 5)/3; + int32_t numRequests = argc / 3; nsKeyPairInfo *keyids = new nsKeyPairInfo[numRequests]; memset(keyids, 0, sizeof(nsKeyPairInfo)*numRequests); int keyInfoIndex; uint32_t i; PK11SlotInfo *slot = nullptr; // Go through all of the arguments and generate the appropriate key pairs. - for (i=5,keyInfoIndex=0; i(&aArgs[i]), + &keyids[keyInfoIndex], + uiCxt, &slot, willEscrow); + if (NS_FAILED(nrv)) { if (slot) PK11_FreeSlot(slot); nsFreeKeyPairInfo(keyids,numRequests); - return nrv; + aRv.Throw(nrv); + return nullptr; } } // By this time we'd better have a slot for the key gen. NS_ASSERTION(slot, "There was no slot selected for key generation"); - if (slot) + if (slot) PK11_FreeSlot(slot); char *encodedRequest = nsCreateReqFromKeyPairs(keyids,numRequests, - reqDN.ptr(),regToken.ptr(), - authenticator.ptr(), + const_cast(aReqDN.get()), + const_cast(aRegToken.get()), + const_cast(aAuthenticator.get()), escrowCert); #ifdef DEBUG_javi printf ("Created the folloing CRMF request:\n%s\n", encodedRequest); #endif if (!encodedRequest) { nsFreeKeyPairInfo(keyids, numRequests); - return NS_ERROR_FAILURE; - } + aRv.Throw(NS_ERROR_FAILURE); + return nullptr; + } nsCRMFObject *newObject = new nsCRMFObject(); newObject->SetCRMFRequest(encodedRequest); - *aReturn = newObject; - //Give a reference to the returnee. - NS_ADDREF(*aReturn); + crmf = newObject; nsFreeKeyPairInfo(keyids, numRequests); - // // Post an event on the UI queue so that the JS gets called after // we return control to the JS layer. Why do we have to this? // Because when this API was implemented for PSM 1.x w/ Communicator, @@ -2025,32 +2003,43 @@ nsCrypto::GenerateCRMFRequest(nsIDOMCRMFObject** aReturn) // when the request has been generated. // - nsCOMPtr secMan = do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID); - NS_ENSURE_TRUE(secMan, NS_ERROR_UNEXPECTED); - + if (MOZ_UNLIKELY(!secMan)) { + aRv.Throw(NS_ERROR_UNEXPECTED); + return nullptr; + } + nsCOMPtr principals; nsresult rv = secMan->GetSubjectPrincipal(getter_AddRefs(principals)); - NS_ENSURE_SUCCESS(rv, rv); - NS_ENSURE_TRUE(principals, NS_ERROR_UNEXPECTED); - + if (NS_FAILED(nrv)) { + aRv.Throw(nrv); + return nullptr; + } + if (MOZ_UNLIKELY(!principals)) { + aRv.Throw(NS_ERROR_UNEXPECTED); + return nullptr; + } + nsCryptoRunArgs *args = new nsCryptoRunArgs(); - args->m_cx = cx; - args->m_kungFuDeathGrip = GetISupportsFromContext(cx); + args->m_cx = aContext; + args->m_kungFuDeathGrip = GetISupportsFromContext(aContext); args->m_scope = JS_GetParent(script_obj); - - args->m_jsCallback.Adopt(!!jsCallback ? nsCRT::strdup(jsCallback.ptr()) : 0); + if (!aJsCallback.IsVoid()) { + args->m_jsCallback = aJsCallback; + } args->m_principals = principals; - + nsCryptoRunnable *cryptoRunnable = new nsCryptoRunnable(args); rv = NS_DispatchToMainThread(cryptoRunnable); - if (NS_FAILED(rv)) + if (NS_FAILED(rv)) { + aRv.Throw(rv); delete cryptoRunnable; + } - return rv; + return crmf.forget(); } @@ -2227,14 +2216,14 @@ nsCertListCount(CERTCertList *certList) return numCerts; } - //Import user certificates that arrive as a CMMF base64 encoded //string. -NS_IMETHODIMP -nsCrypto::ImportUserCertificates(const nsAString& aNickname, - const nsAString& aCmmfResponse, - bool aDoForcedBackup, - nsAString& aReturn) +void +nsCrypto::ImportUserCertificates(const nsAString& aNickname, + const nsAString& aCmmfResponse, + bool aDoForcedBackup, + nsAString& aReturn, + ErrorResult& aRv) { nsNSSShutDownPreventionLock locker; char *nickname=nullptr, *cmmfResponse=nullptr; @@ -2425,20 +2414,24 @@ nsCrypto::ImportUserCertificates(const nsAString& aNickname, if (certRepContent) { CMMF_DestroyCertRepContent(certRepContent); } - return rv; + + if (NS_FAILED(rv)) { + aRv.Throw(rv); + } } -NS_IMETHODIMP -nsCrypto::PopChallengeResponse(const nsAString& aChallenge, - nsAString& aReturn) +void +nsCrypto::PopChallengeResponse(const nsAString& aChallenge, + nsAString& aReturn, + ErrorResult& aRv) { - return NS_ERROR_NOT_IMPLEMENTED; + aRv.Throw(NS_ERROR_NOT_IMPLEMENTED); } -NS_IMETHODIMP -nsCrypto::Random(int32_t aNumBytes, nsAString& aReturn) +void +nsCrypto::Random(int32_t aNumBytes, nsAString& aReturn, ErrorResult& aRv) { - return NS_ERROR_NOT_IMPLEMENTED; + aRv.Throw(NS_ERROR_NOT_IMPLEMENTED); } static void @@ -2472,46 +2465,27 @@ void signTextOutputCallback(void *arg, const char *buf, unsigned long len) ((nsCString*)arg)->Append(buf, len); } -NS_IMETHODIMP -nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption, - nsAString& aResult) +void +nsCrypto::SignText(JSContext* aContext, + const nsAString& aStringToSign, + const nsAString& aCaOption, + const Sequence& aArgs, + nsAString& aReturn) { // XXX This code should return error codes, but we're keeping this // backwards compatible with NS4.x and so we can't throw exceptions. NS_NAMED_LITERAL_STRING(internalError, "error:internalError"); - aResult.Truncate(); + aReturn.Truncate(); - nsAXPCNativeCallContext* ncc = nullptr; - nsCOMPtr xpc(do_GetService(nsIXPConnect::GetCID())); - if (xpc) { - xpc->GetCurrentNativeCallContext(&ncc); - } - - if (!ncc) { - aResult.Append(internalError); - - return NS_OK; - } - - uint32_t argc; - ncc->GetArgc(&argc); - - JSContext *cx; - ncc->GetJSContext(&cx); - if (!cx) { - aResult.Append(internalError); - - return NS_OK; - } + uint32_t argc = aArgs.Length(); if (!aCaOption.EqualsLiteral("auto") && !aCaOption.EqualsLiteral("ask")) { - JS_ReportError(cx, "%s%s", JS_ERROR, "caOption argument must be ask or auto"); + NS_WARNING("caOption argument must be ask or auto"); + aReturn.Append(internalError); - aResult.Append(internalError); - - return NS_OK; + return; } // It was decided to always behave as if "ask" were specified. @@ -2519,9 +2493,9 @@ nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption, nsCOMPtr uiContext = new PipUIContext; if (!uiContext) { - aResult.Append(internalError); + aReturn.Append(internalError); - return NS_OK; + return; } bool bestOnly = true; @@ -2530,74 +2504,55 @@ nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption, CERT_FindUserCertsByUsage(CERT_GetDefaultCertDB(), certUsageEmailSigner, bestOnly, validOnly, uiContext); - uint32_t numCAs = argc - 2; + uint32_t numCAs = argc; if (numCAs > 0) { - JS::Value *argv = nullptr; - ncc->GetArgvPtr(&argv); - - nsAutoArrayPtr caNameBytes(new JSAutoByteString[numCAs]); - if (!caNameBytes) { - aResult.Append(internalError); - return NS_OK; - } - - JSAutoRequest ar(cx); - - uint32_t i; - for (i = 2; i < argc; ++i) { - JSString *caName = JS_ValueToString(cx, argv[i]); - NS_ENSURE_TRUE(caName, NS_ERROR_OUT_OF_MEMORY); - argv[i] = STRING_TO_JSVAL(caName); - caNameBytes[i - 2].encodeLatin1(cx, caName); - NS_ENSURE_TRUE(!!caNameBytes[i - 2], NS_ERROR_OUT_OF_MEMORY); - } - nsAutoArrayPtr caNames(new char*[numCAs]); if (!caNames) { - aResult.Append(internalError); - return NS_OK; + aReturn.Append(internalError); + return; } + uint32_t i; for (i = 0; i < numCAs; ++i) - caNames[i] = caNameBytes[i].ptr(); + caNames[i] = const_cast(aArgs[i].get()); if (certList && CERT_FilterCertListByCANames(certList, numCAs, caNames, certUsageEmailSigner) != SECSuccess) { - aResult.Append(internalError); + aReturn.Append(internalError); - return NS_OK; + return; } } if (!certList || CERT_LIST_EMPTY(certList)) { - aResult.AppendLiteral("error:noMatchingCert"); + aReturn.AppendLiteral("error:noMatchingCert"); - return NS_OK; + return; } nsCOMPtr fsd = do_CreateInstance(NS_FORMSIGNINGDIALOG_CONTRACTID); if (!fsd) { - aResult.Append(internalError); + aReturn.Append(internalError); - return NS_OK; + return; } nsCOMPtr document; - GetDocumentFromContext(cx, getter_AddRefs(document)); + GetDocumentFromContext(aContext, getter_AddRefs(document)); if (!document) { - aResult.Append(internalError); + aReturn.Append(internalError); - return NS_OK; + return; } // Get the hostname from the URL of the document. nsIURI* uri = document->GetDocumentURI(); if (!uri) { - aResult.Append(internalError); + aReturn.Append(internalError); - return NS_OK; + return; } nsresult rv; @@ -2605,9 +2560,9 @@ nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption, nsCString host; rv = uri->GetHost(host); if (NS_FAILED(rv)) { - aResult.Append(internalError); + aReturn.Append(internalError); - return NS_OK; + return; } int32_t numberOfCerts = 0; @@ -2620,9 +2575,9 @@ nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption, ScopedCERTCertNicknames nicknames(getNSSCertNicknamesFromCertList(certList)); if (!nicknames) { - aResult.Append(internalError); + aReturn.Append(internalError); - return NS_OK; + return; } NS_ASSERTION(nicknames->numnicknames == numberOfCerts, @@ -2630,9 +2585,9 @@ nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption, nsAutoArrayPtr certNicknameList(new PRUnichar*[nicknames->numnicknames * 2]); if (!certNicknameList) { - aResult.Append(internalError); + aReturn.Append(internalError); - return NS_OK; + return; } PRUnichar** certDetailsList = certNicknameList.get() + nicknames->numnicknames; @@ -2661,9 +2616,9 @@ nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption, } if (certsToUse == 0) { - aResult.Append(internalError); + aReturn.Append(internalError); - return NS_OK; + return; } NS_ConvertUTF8toUTF16 utf16Host(host); @@ -2714,22 +2669,22 @@ nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption, } if (NS_FAILED(rv)) { // something went wrong inside the tryAgain loop - aResult.Append(internalError); + aReturn.Append(internalError); - return NS_OK; + return; } if (canceled) { - aResult.AppendLiteral("error:userCancel"); + aReturn.AppendLiteral("error:userCancel"); - return NS_OK; + return; } SECKEYPrivateKey* privKey = PK11_FindKeyByAnyCert(signingCert, uiContext); if (!privKey) { - aResult.Append(internalError); + aReturn.Append(internalError); - return NS_OK; + return; } nsAutoCString charset(document->GetDocumentCharacterSet()); @@ -2755,9 +2710,9 @@ nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption, rv = encoder->Convert(PromiseFlatString(aStringToSign).get(), getter_Copies(buffer)); if (NS_FAILED(rv)) { - aResult.Append(internalError); + aReturn.Append(internalError); - return NS_OK; + return; } } else { @@ -2767,9 +2722,9 @@ nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption, HASHContext *hc = HASH_Create(HASH_AlgSHA1); if (!hc) { - aResult.Append(internalError); + aReturn.Append(internalError); - return NS_OK; + return; } unsigned char hash[SHA1_LENGTH]; @@ -2804,9 +2759,9 @@ nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption, } if (srv != SECSuccess) { - aResult.Append(internalError); + aReturn.Append(internalError); - return NS_OK; + return; } SECItem binary_item; @@ -2816,25 +2771,26 @@ nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption, char *result = NSSBase64_EncodeItem(nullptr, nullptr, 0, &binary_item); if (result) { - AppendASCIItoUTF16(result, aResult); + AppendASCIItoUTF16(result, aReturn); } else { - aResult.Append(internalError); + aReturn.Append(internalError); } PORT_Free(result); - return NS_OK; + return; } -//Logout out of all installed PKCS11 tokens. -NS_IMETHODIMP -nsCrypto::Logout() +void +nsCrypto::Logout(ErrorResult& aRv) { nsresult rv; nsCOMPtr nssComponent(do_GetService(kNSSComponentCID, &rv)); - if (NS_FAILED(rv)) - return rv; + if (NS_FAILED(rv)) { + aRv.Throw(rv); + return; + } { nsNSSShutDownPreventionLock locker; @@ -2842,20 +2798,16 @@ nsCrypto::Logout() SSL_ClearSessionCache(); } - return nssComponent->LogoutAuthenticatedPK11(); + rv = nssComponent->LogoutAuthenticatedPK11(); + if (NS_FAILED(rv)) { + aRv.Throw(rv); + } } -NS_IMETHODIMP -nsCrypto::DisableRightClick() +void +nsCrypto::DisableRightClick(ErrorResult& aRv) { - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsCrypto::GetRandomValues(const JS::Value& aData, JSContext *cx, - JS::Value* _retval) -{ - return mozilla::dom::Crypto::GetRandomValues(aData, cx, _retval); + aRv.Throw(NS_ERROR_NOT_IMPLEMENTED); } nsCRMFObject::nsCRMFObject() diff --git a/security/manager/ssl/src/nsCrypto.h b/security/manager/ssl/src/nsCrypto.h index f4cab7192bc2..cd2720be1674 100644 --- a/security/manager/ssl/src/nsCrypto.h +++ b/security/manager/ssl/src/nsCrypto.h @@ -6,6 +6,8 @@ #ifndef _nsCrypto_h_ #define _nsCrypto_h_ +#include "mozilla/dom/BindingDeclarations.h" +#include "mozilla/ErrorResult.h" #ifndef MOZ_DISABLE_CRYPTOLEGACY #include "Crypto.h" #include "nsCOMPtr.h" @@ -23,7 +25,6 @@ class nsIPSMComponent; class nsIDOMScriptObjectFactory; - class nsCRMFObject : public nsIDOMCRMFObject { public: @@ -41,7 +42,6 @@ private: nsString mBase64Request; }; - class nsCrypto: public mozilla::dom::Crypto { public: @@ -54,6 +54,46 @@ public: // implements the legacy methods. NS_DECL_NSIDOMCRYPTO + virtual bool EnableSmartCardEvents() MOZ_OVERRIDE; + virtual void SetEnableSmartCardEvents(bool aEnable, + mozilla::ErrorResult& aRv) MOZ_OVERRIDE; + + virtual void GetVersion(nsString& aVersion) MOZ_OVERRIDE; + + virtual already_AddRefed + GenerateCRMFRequest(JSContext* aContext, + const nsCString& aReqDN, + const nsCString& aRegToken, + const nsCString& aAuthenticator, + const nsCString& aEaCert, + const nsCString& aJsCallback, + const mozilla::dom::Sequence& aArgs, + mozilla::ErrorResult& aRv) MOZ_OVERRIDE; + + virtual void ImportUserCertificates(const nsAString& aNickname, + const nsAString& aCmmfResponse, + bool aDoForcedBackup, + nsAString& aReturn, + mozilla::ErrorResult& aRv) MOZ_OVERRIDE; + + virtual void PopChallengeResponse(const nsAString& aChallenge, + nsAString& aReturn, + mozilla::ErrorResult& aRv) MOZ_OVERRIDE; + + virtual void Random(int32_t aNumBytes, + nsAString& aReturn, + mozilla::ErrorResult& aRv) MOZ_OVERRIDE; + + virtual void SignText(JSContext* aContext, + const nsAString& aStringToSign, + const nsAString& aCaOption, + const mozilla::dom::Sequence& aArgs, + nsAString& aReturn) MOZ_OVERRIDE; + + virtual void Logout(mozilla::ErrorResult& aRv) MOZ_OVERRIDE; + + virtual void DisableRightClick(mozilla::ErrorResult& aRv) MOZ_OVERRIDE; + private: static already_AddRefed GetScriptPrincipal(JSContext *cx); From 40c1e002ad765f79b8624e96ccbce894885e4c0e Mon Sep 17 00:00:00 2001 From: Yoshi Huang Date: Thu, 1 Aug 2013 15:14:44 +0800 Subject: [PATCH 08/10] Bug 883741 - Part 2: testing for null in crypto legacy. r=bz --- dom/tests/mochitest/crypto/test_legacy.html | 28 +++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/dom/tests/mochitest/crypto/test_legacy.html b/dom/tests/mochitest/crypto/test_legacy.html index 09b7453d6f20..42894e736988 100644 --- a/dom/tests/mochitest/crypto/test_legacy.html +++ b/dom/tests/mochitest/crypto/test_legacy.html @@ -24,5 +24,33 @@ ok("signText" in window.crypto, "signText in window.crypto"); ok("disableRightClick" in window.crypto, "disableRightClick in window.crypto"); +function jsCallback () { +} + +try { + window.crypto.generateCRMFRequest(null, null, null, null, jsCallback.toString()); + ok(false, "window.crypto.generateCRMFRequest failed, should throw error"); +} catch (e) { + ok(e.toString().search(/Failure/) > -1, + "Expected error: ReqDN cannot be null"); +} + +try { + window.crypto.generateCRMFRequest(document.documentElement, null, null, null, + null); + ok(false, "window.crypto.generateCRMFRequest failed, should throw error"); +} catch (e) { + ok(e.toString().search(/Failure/) > -1, + "Expected error: jsCallback cannot be null"); +} + +try { + window.crypto.generateCRMFRequest(document.documentElement, null, null, null, + jsCallback.toString(), 1024); + ok(false, "window.crypto.generateCRMFRequest failed, should throw error"); +} catch (e) { + ok(e.toString().search(/TypeError/) > -1, + "Expected error: Not enough arguments"); +} From 97c214b56ce96a0886e69ba9042a2af69b395646 Mon Sep 17 00:00:00 2001 From: Gaia Pushbot Date: Sun, 4 Aug 2013 22:55:22 -0700 Subject: [PATCH 09/10] Bumping gaia.json for 2 gaia-central revision(s) ======== https://hg.mozilla.org/integration/gaia-central/rev/5e7a8bbe525c Author: Ian Liu Desc: Merge pull request #11334 from ian-liu/bluetooth/Bug898092_Fail_to_open_Bluetooth_store_files_changed_to_/Download/Bluetooth_from_/Downloads/Bluetooth Bug 898092 - Fail to open Bluetooth received files - path to store files changed to /Download/Bluetooth from /Downloads/Bluetooth, r=@alivedise ======== https://hg.mozilla.org/integration/gaia-central/rev/94dcf9d72f32 Author: ian-liu Desc: Bug 898092 - Fail to open Bluetooth received files - path to store files changed to /Download/Bluetooth from /Downloads/Bluetooth --- b2g/config/gaia.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/b2g/config/gaia.json b/b2g/config/gaia.json index 7023a45bd082..9063eb720327 100644 --- a/b2g/config/gaia.json +++ b/b2g/config/gaia.json @@ -1,4 +1,4 @@ { - "revision": "3e7b6feeeadedc472368ecad65016a6df75570f5", + "revision": "5e7a8bbe525c0a43852770665ce9498fdb93ea81", "repo_path": "/integration/gaia-central" } From 4aea830dd1019357b250e8bfda3e559f5974f2d4 Mon Sep 17 00:00:00 2001 From: "Szu-Yu Chen [:aknow]" Date: Mon, 5 Aug 2013 14:00:28 +0800 Subject: [PATCH 10/10] Bug 900900 - Fix test_ril_worker_clir.js. r=hsinyi --- dom/system/gonk/tests/test_ril_worker_clir.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- dom/system/gonk/tests/test_ril_worker_clir.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dom/system/gonk/tests/test_ril_worker_clir.js b/dom/system/gonk/tests/test_ril_worker_clir.js index 987c79583e8a..e8ff910a5fe8 100644 --- a/dom/system/gonk/tests/test_ril_worker_clir.js +++ b/dom/system/gonk/tests/test_ril_worker_clir.js @@ -41,6 +41,7 @@ add_test(function test_setCLIR_success() { worker.RIL.setCLIR = function fakeSetCLIR(options) { worker.RIL[REQUEST_SET_CLIR](0, { + rilMessageType: "setCLIR", rilRequestError: ERROR_SUCCESS }); }; @@ -63,6 +64,7 @@ add_test(function test_setCLIR_generic_failure() { worker.RIL.setCLIR = function fakeSetCLIR(options) { worker.RIL[REQUEST_SET_CLIR](0, { + rilMessageType: "setCLIR", rilRequestError: ERROR_GENERIC_FAILURE }); }; @@ -90,11 +92,12 @@ add_test(function test_getCLIR_n0_m1() { worker.RIL.getCLIR = function fakeGetCLIR(options) { worker.Buf.int32Array = [ 1, // Presentation indicator is used according to the subscription - // of the CLIR service. + // of the CLIR service. 0, // CLIR provisioned in permanent mode. 2 // Length. ]; worker.RIL[REQUEST_GET_CLIR](1, { + rilMessageType: "setCLIR", rilRequestError: ERROR_SUCCESS }); }; @@ -121,11 +124,12 @@ add_test(function test_getCLIR_error_generic_failure_invalid_length() { worker.RIL.getCLIR = function fakeGetCLIR(options) { worker.Buf.int32Array = [ 1, // Presentation indicator is used according to the subscription - // of the CLIR service. + // of the CLIR service. 0, // CLIR provisioned in permanent mode. 0 // Length (invalid one). ]; worker.RIL[REQUEST_GET_CLIR](1, { + rilMessageType: "setCLIR", rilRequestError: ERROR_SUCCESS }); };