Bug 1029403 - Trigger a storage-state-change event when there is volume state change. r=dhylands

This commit is contained in:
Alphan Chen 2014-07-02 17:35:54 +08:00
parent 77e10bb1ca
commit 44e42eb96d
2 changed files with 32 additions and 7 deletions

View File

@ -349,7 +349,8 @@ private:
#ifdef MOZ_WIDGET_GONK
nsString mLastStatus;
void DispatchMountChangeEvent(nsAString& aVolumeStatus);
void DispatchStatusChangeEvent(nsAString& aStatus);
void DispatchStorageStatusChangeEvent(nsAString& aVolumeStatus);
#endif
// nsIDOMDeviceStorage.type

View File

@ -4194,14 +4194,32 @@ nsDOMDeviceStorage::EnumerateInternal(const nsAString& aPath,
#ifdef MOZ_WIDGET_GONK
void
nsDOMDeviceStorage::DispatchMountChangeEvent(nsAString& aVolumeStatus)
nsDOMDeviceStorage::DispatchStatusChangeEvent(nsAString& aStatus)
{
if (aVolumeStatus == mLastStatus) {
if (aStatus == mLastStatus) {
// We've already sent this status, don't bother sending it again.
return;
}
mLastStatus = aVolumeStatus;
mLastStatus = aStatus;
DeviceStorageChangeEventInit init;
init.mBubbles = true;
init.mCancelable = false;
init.mPath = mStorageName;
init.mReason = aStatus;
nsRefPtr<DeviceStorageChangeEvent> event =
DeviceStorageChangeEvent::Constructor(this, NS_LITERAL_STRING("change"),
init);
event->SetTrusted(true);
bool ignore;
DispatchEvent(event, &ignore);
}
void
nsDOMDeviceStorage::DispatchStorageStatusChangeEvent(nsAString& aVolumeStatus)
{
DeviceStorageChangeEventInit init;
init.mBubbles = true;
init.mCancelable = false;
@ -4209,7 +4227,7 @@ nsDOMDeviceStorage::DispatchMountChangeEvent(nsAString& aVolumeStatus)
init.mReason = aVolumeStatus;
nsRefPtr<DeviceStorageChangeEvent> event =
DeviceStorageChangeEvent::Constructor(this, NS_LITERAL_STRING("change"),
DeviceStorageChangeEvent::Constructor(this, NS_LITERAL_STRING("storage-state-change"),
init);
event->SetTrusted(true);
@ -4268,9 +4286,15 @@ nsDOMDeviceStorage::Observe(nsISupports *aSubject,
}
DeviceStorageFile dsf(mStorageType, mStorageName);
nsString status;
nsString status, storageStatus;
// Get Status (one of "available, unavailable, shared")
dsf.GetStatus(status);
DispatchMountChangeEvent(status);
DispatchStatusChangeEvent(status);
// Get real volume status (defined in dom/system/gonk/nsIVolume.idl)
dsf.GetStorageStatus(storageStatus);
DispatchStorageStatusChangeEvent(storageStatus);
return NS_OK;
}
#endif