зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1173320 - patch 2/8 - Proper naming for the FileSystem path serialization, r=smaug
This commit is contained in:
Родитель
232e5767b0
Коммит
f43b2ad7ea
|
@ -31,12 +31,6 @@ DeviceStorageFileSystem::DeviceStorageFileSystem(
|
|||
mStorageType = aStorageType;
|
||||
mStorageName = aStorageName;
|
||||
|
||||
// Generate the string representation of the file system.
|
||||
mString.AppendLiteral("devicestorage-");
|
||||
mString.Append(mStorageType);
|
||||
mString.Append('-');
|
||||
mString.Append(mStorageName);
|
||||
|
||||
mRequiresPermissionChecks =
|
||||
!mozilla::Preferences::GetBool("device.storage.prompt.testing", false);
|
||||
|
||||
|
@ -140,8 +134,24 @@ DeviceStorageFileSystem::IsSafeDirectory(Directory* aDir) const
|
|||
return false;
|
||||
}
|
||||
|
||||
nsAutoString fsSerialization;
|
||||
fs->SerializeDOMPath(fsSerialization);
|
||||
|
||||
nsAutoString thisSerialization;
|
||||
SerializeDOMPath(thisSerialization);
|
||||
|
||||
// Check if the given directory is from this storage.
|
||||
return fs->ToString() == mString;
|
||||
return fsSerialization == thisSerialization;
|
||||
}
|
||||
|
||||
void
|
||||
DeviceStorageFileSystem::SerializeDOMPath(nsAString& aString) const
|
||||
{
|
||||
// Generate the string representation of the file system.
|
||||
aString.AssignLiteral("devicestorage-");
|
||||
aString.Append(mStorageType);
|
||||
aString.Append('-');
|
||||
aString.Append(mStorageName);
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
|
|
|
@ -41,6 +41,10 @@ public:
|
|||
|
||||
virtual bool
|
||||
IsSafeDirectory(Directory* aDir) const override;
|
||||
|
||||
virtual void
|
||||
SerializeDOMPath(nsAString& aSerializedString) const override;
|
||||
|
||||
private:
|
||||
virtual
|
||||
~DeviceStorageFileSystem();
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace dom {
|
|||
|
||||
// static
|
||||
already_AddRefed<FileSystemBase>
|
||||
FileSystemBase::FromString(const nsAString& aString)
|
||||
FileSystemBase::DeserializeDOMPath(const nsAString& aString)
|
||||
{
|
||||
if (StringBeginsWith(aString, NS_LITERAL_STRING("devicestorage-"))) {
|
||||
// The string representation of devicestorage file system is of the format:
|
||||
|
@ -38,6 +38,7 @@ FileSystemBase::FromString(const nsAString& aString)
|
|||
new DeviceStorageFileSystem(storageType, storageName);
|
||||
return f.forget();
|
||||
}
|
||||
|
||||
return RefPtr<OSFileSystem>(new OSFileSystem(aString)).forget();
|
||||
}
|
||||
|
||||
|
|
|
@ -25,19 +25,16 @@ public:
|
|||
|
||||
// Create file system object from its string representation.
|
||||
static already_AddRefed<FileSystemBase>
|
||||
FromString(const nsAString& aString);
|
||||
DeserializeDOMPath(const nsAString& aString);
|
||||
|
||||
FileSystemBase();
|
||||
|
||||
virtual void
|
||||
Shutdown();
|
||||
|
||||
// Get the string representation of the file system.
|
||||
const nsString&
|
||||
ToString() const
|
||||
{
|
||||
return mString;
|
||||
}
|
||||
// SerializeDOMPath the FileSystem to string.
|
||||
virtual void
|
||||
SerializeDOMPath(nsAString& aOutput) const = 0;
|
||||
|
||||
virtual nsPIDOMWindowInner*
|
||||
GetWindow() const;
|
||||
|
@ -110,9 +107,6 @@ protected:
|
|||
// The same, but with path separators normalized to "/".
|
||||
nsString mNormalizedLocalRootPath;
|
||||
|
||||
// The string representation of the file system.
|
||||
nsString mString;
|
||||
|
||||
bool mShutdown;
|
||||
|
||||
// The permission name required to access the file system.
|
||||
|
|
|
@ -28,7 +28,7 @@ FileSystemRequestParent::~FileSystemRequestParent()
|
|||
#define FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(name) \
|
||||
case FileSystemParams::TFileSystem##name##Params: { \
|
||||
const FileSystem##name##Params& p = aParams; \
|
||||
mFileSystem = FileSystemBase::FromString(p.filesystem()); \
|
||||
mFileSystem = FileSystemBase::DeserializeDOMPath(p.filesystem()); \
|
||||
task = name##Task::Create(mFileSystem, p, this, rv); \
|
||||
if (NS_WARN_IF(rv.Failed())) { \
|
||||
return false; \
|
||||
|
|
|
@ -106,8 +106,11 @@ FileSystemTaskBase::Start()
|
|||
return;
|
||||
}
|
||||
|
||||
nsAutoString serialization;
|
||||
mFileSystem->SerializeDOMPath(serialization);
|
||||
|
||||
ErrorResult rv;
|
||||
FileSystemParams params = GetRequestParams(mFileSystem->ToString(), rv);
|
||||
FileSystemParams params = GetRequestParams(serialization, rv);
|
||||
if (NS_WARN_IF(rv.Failed())) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ GetDirectoryListingTask::Create(FileSystemBase* aFileSystem,
|
|||
}
|
||||
|
||||
task->mType = aParam.isRoot()
|
||||
? Directory::eDOMRootDirectory : Directory::eNotRootDirectory;
|
||||
? Directory::eDOMRootDirectory : Directory::eNotDOMRootDirectory;
|
||||
return task.forget();
|
||||
}
|
||||
|
||||
|
@ -215,7 +215,7 @@ GetDirectoryListingTask::Work()
|
|||
}
|
||||
|
||||
if (!exists) {
|
||||
if (mType == Directory::eNotRootDirectory) {
|
||||
if (mType == Directory::eNotDOMRootDirectory) {
|
||||
return NS_ERROR_DOM_FILE_NOT_FOUND_ERR;
|
||||
}
|
||||
|
||||
|
@ -390,7 +390,7 @@ GetDirectoryListingTask::HandlerCallback()
|
|||
|
||||
RefPtr<Directory> directory = Directory::Create(mFileSystem->GetWindow(),
|
||||
directoryPath,
|
||||
Directory::eNotRootDirectory,
|
||||
Directory::eNotDOMRootDirectory,
|
||||
mFileSystem);
|
||||
MOZ_ASSERT(directory);
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ GetFileOrDirectoryTask::Create(FileSystemBase* aFileSystem,
|
|||
}
|
||||
|
||||
task->mType = aParam.isRoot()
|
||||
? Directory::eDOMRootDirectory : Directory::eNotRootDirectory;
|
||||
? Directory::eDOMRootDirectory : Directory::eNotDOMRootDirectory;
|
||||
return task.forget();
|
||||
}
|
||||
|
||||
|
@ -200,7 +200,7 @@ GetFileOrDirectoryTask::Work()
|
|||
}
|
||||
|
||||
if (!exists) {
|
||||
if (mType == Directory::eNotRootDirectory) {
|
||||
if (mType == Directory::eNotDOMRootDirectory) {
|
||||
return NS_ERROR_DOM_FILE_NOT_FOUND_ERR;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,8 +27,6 @@ OSFileSystem::OSFileSystem(const nsAString& aRootDir)
|
|||
// access different parts of devices storage like Pictures, or Videos, etc.
|
||||
mRequiresPermissionChecks = false;
|
||||
|
||||
mString = mLocalRootPath;
|
||||
|
||||
#ifdef DEBUG
|
||||
mPermission.AssignLiteral("never-used");
|
||||
#endif
|
||||
|
@ -89,5 +87,11 @@ OSFileSystem::Traverse(nsCycleCollectionTraversalCallback &cb)
|
|||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow);
|
||||
}
|
||||
|
||||
void
|
||||
OSFileSystem::SerializeDOMPath(nsAString& aOutput) const
|
||||
{
|
||||
aOutput = mLocalRootPath;
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -34,6 +34,9 @@ public:
|
|||
virtual bool
|
||||
IsSafeDirectory(Directory* aDir) const override;
|
||||
|
||||
virtual void
|
||||
SerializeDOMPath(nsAString& aOutput) const override;
|
||||
|
||||
// CC methods
|
||||
virtual void Unlink() override;
|
||||
virtual void Traverse(nsCycleCollectionTraversalCallback &cb) override;
|
||||
|
|
Загрузка…
Ссылка в новой задаче