2014-03-05 07:26:39 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 22:32:37 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-03-05 07:26:39 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "mozilla/dom/Directory.h"
|
|
|
|
|
2014-03-05 07:25:40 +04:00
|
|
|
#include "CreateDirectoryTask.h"
|
2014-03-05 12:40:48 +04:00
|
|
|
#include "CreateFileTask.h"
|
2014-03-05 07:24:19 +04:00
|
|
|
#include "FileSystemPermissionRequest.h"
|
2015-06-23 02:31:34 +03:00
|
|
|
#include "GetDirectoryListingTask.h"
|
2014-03-05 07:25:40 +04:00
|
|
|
#include "GetFileOrDirectoryTask.h"
|
2014-03-12 10:30:21 +04:00
|
|
|
#include "RemoveTask.h"
|
2014-03-05 07:25:40 +04:00
|
|
|
|
|
|
|
#include "nsCharSeparatedTokenizer.h"
|
2014-03-05 07:26:39 +04:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "mozilla/dom/DirectoryBinding.h"
|
2014-03-05 07:25:40 +04:00
|
|
|
#include "mozilla/dom/FileSystemBase.h"
|
|
|
|
#include "mozilla/dom/FileSystemUtils.h"
|
2014-03-05 07:26:39 +04:00
|
|
|
|
|
|
|
// Resolve the name collision of Microsoft's API name with macros defined in
|
|
|
|
// Windows header files. Undefine the macro of CreateDirectory to avoid
|
|
|
|
// Directory#CreateDirectory being replaced by Directory#CreateDirectoryW.
|
|
|
|
#ifdef CreateDirectory
|
|
|
|
#undef CreateDirectory
|
|
|
|
#endif
|
2014-03-05 12:40:48 +04:00
|
|
|
// Undefine the macro of CreateFile to avoid Directory#CreateFile being replaced
|
|
|
|
// by Directory#CreateFileW.
|
|
|
|
#ifdef CreateFile
|
|
|
|
#undef CreateFile
|
|
|
|
#endif
|
2014-03-05 07:26:39 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(Directory)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(Directory)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(Directory)
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Directory)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2014-03-05 07:25:40 +04:00
|
|
|
// static
|
|
|
|
already_AddRefed<Promise>
|
2014-07-19 05:31:11 +04:00
|
|
|
Directory::GetRoot(FileSystemBase* aFileSystem, ErrorResult& aRv)
|
2014-03-05 07:25:40 +04:00
|
|
|
{
|
|
|
|
nsRefPtr<GetFileOrDirectoryTask> task = new GetFileOrDirectoryTask(
|
2014-07-19 05:31:11 +04:00
|
|
|
aFileSystem, EmptyString(), true, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-03-05 07:24:19 +04:00
|
|
|
FileSystemPermissionRequest::RequestForTask(task);
|
2014-03-05 07:25:40 +04:00
|
|
|
return task->GetPromise();
|
|
|
|
}
|
|
|
|
|
|
|
|
Directory::Directory(FileSystemBase* aFileSystem,
|
|
|
|
const nsAString& aPath)
|
|
|
|
: mFileSystem(aFileSystem)
|
|
|
|
, mPath(aPath)
|
2014-03-05 07:26:39 +04:00
|
|
|
{
|
2014-03-05 07:25:40 +04:00
|
|
|
MOZ_ASSERT(aFileSystem, "aFileSystem should not be null.");
|
|
|
|
// Remove the trailing "/".
|
|
|
|
mPath.Trim(FILESYSTEM_DOM_PATH_SEPARATOR, false, true);
|
2014-03-05 07:26:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Directory::~Directory()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPIDOMWindow*
|
|
|
|
Directory::GetParentObject() const
|
|
|
|
{
|
2014-03-05 07:25:40 +04:00
|
|
|
return mFileSystem->GetWindow();
|
2014-03-05 07:26:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
Directory::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2014-03-05 07:26:39 +04:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
return DirectoryBinding::Wrap(aCx, this, aGivenProto);
|
2014-03-05 07:26:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-06-04 15:19:25 +03:00
|
|
|
Directory::GetName(nsAString& aRetval) const
|
2014-03-05 07:26:39 +04:00
|
|
|
{
|
|
|
|
aRetval.Truncate();
|
2014-03-05 07:25:40 +04:00
|
|
|
|
|
|
|
if (mPath.IsEmpty()) {
|
2015-07-10 20:54:53 +03:00
|
|
|
mFileSystem->GetRootName(aRetval);
|
2014-03-05 07:25:40 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aRetval = Substring(mPath,
|
|
|
|
mPath.RFindChar(FileSystemUtils::kSeparatorChar) + 1);
|
2014-03-05 07:26:39 +04:00
|
|
|
}
|
|
|
|
|
2014-03-05 12:40:48 +04:00
|
|
|
already_AddRefed<Promise>
|
2014-07-19 05:31:11 +04:00
|
|
|
Directory::CreateFile(const nsAString& aPath, const CreateFileOptions& aOptions,
|
|
|
|
ErrorResult& aRv)
|
2014-03-05 12:40:48 +04:00
|
|
|
{
|
|
|
|
nsresult error = NS_OK;
|
2015-06-23 02:31:38 +03:00
|
|
|
nsAutoString realPath;
|
2015-05-12 15:09:51 +03:00
|
|
|
nsRefPtr<Blob> blobData;
|
2014-03-05 12:40:48 +04:00
|
|
|
InfallibleTArray<uint8_t> arrayData;
|
|
|
|
bool replace = (aOptions.mIfExists == CreateIfExistsMode::Replace);
|
|
|
|
|
|
|
|
// Get the file content.
|
|
|
|
if (aOptions.mData.WasPassed()) {
|
|
|
|
auto& data = aOptions.mData.Value();
|
|
|
|
if (data.IsString()) {
|
|
|
|
NS_ConvertUTF16toUTF8 str(data.GetAsString());
|
|
|
|
arrayData.AppendElements(reinterpret_cast<const uint8_t *>(str.get()),
|
|
|
|
str.Length());
|
|
|
|
} else if (data.IsArrayBuffer()) {
|
2014-06-24 00:03:57 +04:00
|
|
|
const ArrayBuffer& buffer = data.GetAsArrayBuffer();
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-28 01:32:41 +04:00
|
|
|
buffer.ComputeLengthAndData();
|
2014-03-05 12:40:48 +04:00
|
|
|
arrayData.AppendElements(buffer.Data(), buffer.Length());
|
|
|
|
} else if (data.IsArrayBufferView()){
|
2014-06-24 00:03:57 +04:00
|
|
|
const ArrayBufferView& view = data.GetAsArrayBufferView();
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-28 01:32:41 +04:00
|
|
|
view.ComputeLengthAndData();
|
2014-03-05 12:40:48 +04:00
|
|
|
arrayData.AppendElements(view.Data(), view.Length());
|
|
|
|
} else {
|
|
|
|
blobData = data.GetAsBlob();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!DOMPathToRealPath(aPath, realPath)) {
|
|
|
|
error = NS_ERROR_DOM_FILESYSTEM_INVALID_PATH_ERR;
|
|
|
|
}
|
|
|
|
|
2014-10-08 20:15:22 +04:00
|
|
|
nsRefPtr<CreateFileTask> task =
|
|
|
|
new CreateFileTask(mFileSystem, realPath, blobData, arrayData, replace, aRv);
|
2014-07-19 05:31:11 +04:00
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-03-05 12:40:48 +04:00
|
|
|
task->SetError(error);
|
|
|
|
FileSystemPermissionRequest::RequestForTask(task);
|
|
|
|
return task->GetPromise();
|
|
|
|
}
|
|
|
|
|
2014-03-05 07:26:39 +04:00
|
|
|
already_AddRefed<Promise>
|
2014-07-19 05:31:11 +04:00
|
|
|
Directory::CreateDirectory(const nsAString& aPath, ErrorResult& aRv)
|
2014-03-05 07:26:39 +04:00
|
|
|
{
|
2014-03-05 07:25:40 +04:00
|
|
|
nsresult error = NS_OK;
|
2015-06-23 02:31:38 +03:00
|
|
|
nsAutoString realPath;
|
2014-03-05 07:25:40 +04:00
|
|
|
if (!DOMPathToRealPath(aPath, realPath)) {
|
|
|
|
error = NS_ERROR_DOM_FILESYSTEM_INVALID_PATH_ERR;
|
|
|
|
}
|
|
|
|
nsRefPtr<CreateDirectoryTask> task = new CreateDirectoryTask(
|
2014-07-19 05:31:11 +04:00
|
|
|
mFileSystem, realPath, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-03-05 07:25:40 +04:00
|
|
|
task->SetError(error);
|
2014-03-05 07:24:19 +04:00
|
|
|
FileSystemPermissionRequest::RequestForTask(task);
|
2014-03-05 07:25:40 +04:00
|
|
|
return task->GetPromise();
|
2014-03-05 07:26:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
2014-07-19 05:31:11 +04:00
|
|
|
Directory::Get(const nsAString& aPath, ErrorResult& aRv)
|
2014-03-05 07:26:39 +04:00
|
|
|
{
|
2014-03-05 07:25:40 +04:00
|
|
|
nsresult error = NS_OK;
|
2015-06-23 02:31:38 +03:00
|
|
|
nsAutoString realPath;
|
2014-03-05 07:25:40 +04:00
|
|
|
if (!DOMPathToRealPath(aPath, realPath)) {
|
|
|
|
error = NS_ERROR_DOM_FILESYSTEM_INVALID_PATH_ERR;
|
|
|
|
}
|
|
|
|
nsRefPtr<GetFileOrDirectoryTask> task = new GetFileOrDirectoryTask(
|
2014-07-19 05:31:11 +04:00
|
|
|
mFileSystem, realPath, false, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-03-05 07:25:40 +04:00
|
|
|
task->SetError(error);
|
2014-03-05 07:24:19 +04:00
|
|
|
FileSystemPermissionRequest::RequestForTask(task);
|
2014-03-05 07:25:40 +04:00
|
|
|
return task->GetPromise();
|
|
|
|
}
|
|
|
|
|
2014-03-12 10:30:21 +04:00
|
|
|
already_AddRefed<Promise>
|
2014-07-19 05:31:11 +04:00
|
|
|
Directory::Remove(const StringOrFileOrDirectory& aPath, ErrorResult& aRv)
|
2014-03-12 10:30:21 +04:00
|
|
|
{
|
2014-07-19 05:31:11 +04:00
|
|
|
return RemoveInternal(aPath, false, aRv);
|
2014-03-12 10:30:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
2014-07-19 05:31:11 +04:00
|
|
|
Directory::RemoveDeep(const StringOrFileOrDirectory& aPath, ErrorResult& aRv)
|
2014-03-12 10:30:21 +04:00
|
|
|
{
|
2014-07-19 05:31:11 +04:00
|
|
|
return RemoveInternal(aPath, true, aRv);
|
2014-03-12 10:30:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
2014-07-19 05:31:11 +04:00
|
|
|
Directory::RemoveInternal(const StringOrFileOrDirectory& aPath, bool aRecursive,
|
|
|
|
ErrorResult& aRv)
|
2014-03-12 10:30:21 +04:00
|
|
|
{
|
|
|
|
nsresult error = NS_OK;
|
2015-06-23 02:31:38 +03:00
|
|
|
nsAutoString realPath;
|
2015-05-12 15:11:03 +03:00
|
|
|
nsRefPtr<BlobImpl> blob;
|
2014-03-12 10:30:21 +04:00
|
|
|
|
|
|
|
// Check and get the target path.
|
|
|
|
|
|
|
|
if (aPath.IsFile()) {
|
2015-05-12 15:11:03 +03:00
|
|
|
blob = aPath.GetAsFile().Impl();
|
2015-04-20 22:48:15 +03:00
|
|
|
} else if (aPath.IsString()) {
|
2014-03-12 10:30:21 +04:00
|
|
|
if (!DOMPathToRealPath(aPath.GetAsString(), realPath)) {
|
|
|
|
error = NS_ERROR_DOM_FILESYSTEM_INVALID_PATH_ERR;
|
|
|
|
}
|
2015-04-20 22:48:15 +03:00
|
|
|
} else if (!mFileSystem->IsSafeDirectory(&aPath.GetAsDirectory())) {
|
2014-03-12 10:30:21 +04:00
|
|
|
error = NS_ERROR_DOM_SECURITY_ERR;
|
2015-04-20 22:48:15 +03:00
|
|
|
} else {
|
|
|
|
realPath = aPath.GetAsDirectory().mPath;
|
|
|
|
// The target must be a descendant of this directory.
|
|
|
|
if (!FileSystemUtils::IsDescendantPath(mPath, realPath)) {
|
|
|
|
error = NS_ERROR_DOM_FILESYSTEM_NO_MODIFICATION_ALLOWED_ERR;
|
|
|
|
}
|
2014-03-12 10:30:21 +04:00
|
|
|
}
|
|
|
|
|
2015-05-12 15:11:03 +03:00
|
|
|
nsRefPtr<RemoveTask> task = new RemoveTask(mFileSystem, mPath, blob, realPath,
|
2014-07-19 05:31:11 +04:00
|
|
|
aRecursive, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-03-12 10:30:21 +04:00
|
|
|
task->SetError(error);
|
|
|
|
FileSystemPermissionRequest::RequestForTask(task);
|
|
|
|
return task->GetPromise();
|
|
|
|
}
|
|
|
|
|
2015-06-23 02:31:34 +03:00
|
|
|
void
|
|
|
|
Directory::GetPath(nsAString& aRetval) const
|
|
|
|
{
|
|
|
|
if (mPath.IsEmpty()) {
|
|
|
|
// The Directory ctor removes any trailing '/'; this is the root directory.
|
|
|
|
aRetval.AssignLiteral(FILESYSTEM_DOM_PATH_SEPARATOR);
|
|
|
|
} else {
|
|
|
|
aRetval = Substring(mPath, 0,
|
|
|
|
mPath.RFindChar(FileSystemUtils::kSeparatorChar) + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
|
|
|
Directory::GetFilesAndDirectories()
|
|
|
|
{
|
|
|
|
nsresult error = NS_OK;
|
|
|
|
nsString realPath;
|
|
|
|
ErrorResult rv;
|
|
|
|
nsRefPtr<GetDirectoryListingTask> task =
|
|
|
|
new GetDirectoryListingTask(mFileSystem, mPath, rv);
|
|
|
|
if (NS_WARN_IF(rv.Failed())) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
task->SetError(error);
|
|
|
|
FileSystemPermissionRequest::RequestForTask(task);
|
|
|
|
return task->GetPromise();
|
|
|
|
}
|
|
|
|
|
2014-03-12 10:30:21 +04:00
|
|
|
FileSystemBase*
|
|
|
|
Directory::GetFileSystem() const
|
|
|
|
{
|
|
|
|
return mFileSystem.get();
|
|
|
|
}
|
|
|
|
|
2014-03-05 07:25:40 +04:00
|
|
|
bool
|
|
|
|
Directory::DOMPathToRealPath(const nsAString& aPath, nsAString& aRealPath) const
|
|
|
|
{
|
|
|
|
aRealPath.Truncate();
|
|
|
|
|
|
|
|
nsString relativePath;
|
|
|
|
relativePath = aPath;
|
|
|
|
|
|
|
|
// Trim white spaces.
|
|
|
|
static const char kWhitespace[] = "\b\t\r\n ";
|
|
|
|
relativePath.Trim(kWhitespace);
|
|
|
|
|
|
|
|
if (!IsValidRelativePath(relativePath)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aRealPath = mPath + NS_LITERAL_STRING(FILESYSTEM_DOM_PATH_SEPARATOR) +
|
|
|
|
relativePath;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
bool
|
|
|
|
Directory::IsValidRelativePath(const nsString& aPath)
|
|
|
|
{
|
|
|
|
// We don't allow empty relative path to access the root.
|
|
|
|
if (aPath.IsEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Leading and trailing "/" are not allowed.
|
|
|
|
if (aPath.First() == FileSystemUtils::kSeparatorChar ||
|
|
|
|
aPath.Last() == FileSystemUtils::kSeparatorChar) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_NAMED_LITERAL_STRING(kCurrentDir, ".");
|
|
|
|
NS_NAMED_LITERAL_STRING(kParentDir, "..");
|
|
|
|
|
|
|
|
// Split path and check each path component.
|
|
|
|
nsCharSeparatedTokenizer tokenizer(aPath, FileSystemUtils::kSeparatorChar);
|
|
|
|
while (tokenizer.hasMoreTokens()) {
|
|
|
|
nsDependentSubstring pathComponent = tokenizer.nextToken();
|
|
|
|
// The path containing empty components, such as "foo//bar", is invalid.
|
|
|
|
// We don't allow paths, such as "../foo", "foo/./bar" and "foo/../bar",
|
|
|
|
// to walk up the directory.
|
|
|
|
if (pathComponent.IsEmpty() ||
|
|
|
|
pathComponent.Equals(kCurrentDir) ||
|
|
|
|
pathComponent.Equals(kParentDir)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2014-03-05 07:26:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|