Bug 1936326 - Move IOUtils and PathUtils into XPCOM r=xpcom-reviewers,shtrom,zeid,nika

Differential Revision: https://phabricator.services.mozilla.com/D232251
This commit is contained in:
Beth Rennie
2025-04-03 15:28:31 +00:00
parent 37fd93165d
commit d471649fe2
33 changed files with 239 additions and 234 deletions

View File

@@ -413,6 +413,11 @@ DOMInterfaces = {
'headerFile': 'IDBEvents.h',
},
'IOUtils': {
'nativeType': 'mozilla::IOUtils',
'headerFile': 'mozilla/IOUtils.h',
},
'InspectorFontFace': {
'wrapperCache': False,
},
@@ -589,6 +594,11 @@ DOMInterfaces = {
'headerFile': 'CanvasPath.h'
},
'PathUtils': {
'nativeType': 'mozilla::PathUtils',
'headerFile': 'mozilla/PathUtils.h',
},
'Performance' : {
'implicitJSContext': [
'mark'
@@ -858,7 +868,8 @@ DOMInterfaces = {
},
'SyncReadFile': {
'headerFile': 'mozilla/dom/IOUtils.h',
'nativeType': 'mozilla::SyncReadFile',
'headerFile': 'mozilla/IOUtils.h',
},
'Text': {

View File

@@ -14,12 +14,6 @@ with Files("*ocationProvider*"):
with Files("windows/*LocationProvider*"):
BUG_COMPONENT = ("Core", "DOM: Geolocation")
with Files("IOUtils*"):
BUG_COMPONENT = ("Toolkit", "IOUtils and PathUtils")
with Files("PathUtils*"):
BUG_COMPONENT = ("Toolkit", "IOUtils and PathUtils")
with Files("mac/*LocationProvider*"):
BUG_COMPONENT = ("Core", "DOM: Geolocation")
@@ -32,21 +26,9 @@ with Files("linux/*LocationProvider*"):
with Files("android/*LocationProvider*"):
BUG_COMPONENT = ("Core", "DOM: Geolocation")
with Files("tests/chrome.toml"):
BUG_COMPONENT = ("Toolkit", "IOUtils and PathUtils")
with Files("tests/*constants*"):
BUG_COMPONENT = ("Toolkit", "IOUtils and PathUtils")
with Files("tests/ioutils/**"):
BUG_COMPONENT = ("Toolkit", "IOUtils and PathUtils")
with Files("tests/mochitest.toml"):
BUG_COMPONENT = ("Core", "DOM: Device Interfaces")
with Files("test/*pathutils*"):
BUG_COMPONENT = ("Toolkit", "IOUtils and PathUtils")
with Files("tests/*1197901*"):
BUG_COMPONENT = ("Core", "DOM: Device Interfaces")
@@ -78,17 +60,10 @@ EXPORTS += [
"nsOSPermissionRequestBase.h",
]
EXPORTS.mozilla.dom += [
"IOUtils.h",
"PathUtils.h",
]
UNIFIED_SOURCES += [
"IOUtils.cpp",
"nsDeviceSensors.cpp",
"nsHapticFeedback.cpp",
"nsOSPermissionRequestBase.cpp",
"PathUtils.cpp",
]
EXTRA_JS_MODULES += [
@@ -110,5 +85,4 @@ LOCAL_INCLUDES += [
"/xpcom/base",
]
MOCHITEST_CHROME_MANIFESTS += ["tests/chrome.toml", "tests/ioutils/chrome.toml"]
MOCHITEST_MANIFESTS += ["tests/mochitest.toml"]

View File

@@ -1,6 +0,0 @@
[DEFAULT]
["test_pathutils.html"]
["test_pathutils_worker.xhtml"]
support-files = ["pathutils_worker.js"]

View File

@@ -8,7 +8,7 @@
# documentation and how to modify this file.
repo: mozilla-central
created_at: '2021-10-14T12:50:40.073465'
updated_at: '2025-04-01T14:21:39.951774+00:00'
updated_at: '2025-04-02T20:26:15.852994+00:00'
export:
path: ./docs/mots/index.rst
format: rst
@@ -3245,6 +3245,8 @@ modules:
- name: 'Core: XPCOM'
description: The cross-platform object model and core data structures.
includes:
- dom/chrome-webidl/IOUtils.webidl
- dom/chrome-webidl/PathUtils.webidl
- startupcache/**/*
- xpcom/**/*
- xpcom/base/**/*
@@ -3253,6 +3255,8 @@ modules:
- xpcom/docs/**/*
- xpcom/ds/**/*
- xpcom/glue/**/*
- xpcom/io/**/*
- xpcom/ioutils/**/*
- xpcom/reflect/**/*
- xpcom/rust/**/*
- xpcom/system/**/*
@@ -3271,6 +3275,7 @@ modules:
url: :ref:`XPCOM`
components:
- Core::XPCOM
- Toolkit::IOUtils and PathUtils
review_group: xpcom-reviewers
owners:
- *nika
@@ -4541,5 +4546,5 @@ modules:
- Ryan Tilder
group: dev-platform
hashes:
config: 1f1a65ce9444d293f1f1b8fc74b954bea0aa5a27
export: 26b31fcb1ebef52108b7df136973ebf35a4ddc5b
config: 93b411d8790c372028509fc186c01b8a34ec8cd5
export: 3823627c4a11aab9dc12d92537080eeddffceb34

View File

@@ -49,7 +49,6 @@
#include "mozilla/Unused.h"
#include "mozilla/Telemetry.h"
#include "mozilla/dom/IOUtils.h"
#include "mozilla/dom/workerinternals/RuntimeService.h"
// Normally, the number of milliseconds that AsyncShutdown waits until

View File

@@ -9,7 +9,6 @@
#include <cstdint>
#include "ErrorList.h"
#include "TypedArray.h"
#include "js/ArrayBuffer.h"
#include "js/ColumnNumber.h" // JS::ColumnNumberOneOrigin
#include "js/JSON.h"
@@ -96,10 +95,13 @@
} \
} while (0)
using namespace mozilla::dom;
static constexpr auto SHUTDOWN_ERROR =
"IOUtils: Shutting down and refusing additional I/O tasks"_ns;
namespace mozilla::dom {
namespace mozilla {
// static helper functions
@@ -158,7 +160,7 @@ static nsCString FormatErrorMessage(nsresult aError,
[[nodiscard]] inline bool ToJSValue(
JSContext* aCx, const IOUtils::InternalFileInfo& aInternalFileInfo,
JS::MutableHandle<JS::Value> aValue) {
FileInfo info;
dom::FileInfo info;
info.mPath.Construct(aInternalFileInfo.mPath);
info.mType.Construct(aInternalFileInfo.mType);
info.mSize.Construct(aInternalFileInfo.mSize);
@@ -331,8 +333,8 @@ void IOUtils::DispatchAndResolve(IOUtils::EventQueue* aQueue, Promise* aPromise,
if (!NS_IsMainThread()) {
// We need to manually keep the worker alive until the promise returned by
// Dispatch() resolves or rejects.
workerRef = StrongWorkerRef::CreateForcibly(GetCurrentThreadWorkerPrivate(),
__func__);
workerRef = StrongWorkerRef::CreateForcibly(
GetCurrentThreadWorkerPrivate(), __func__);
}
if (RefPtr<IOPromise<OkT>> p = aQueue->Dispatch<OkT, Fn>(std::move(aFunc))) {
@@ -1884,16 +1886,16 @@ Result<IOUtils::InternalFileInfo, IOUtils::IOError> IOUtils::StatSync(
}
// Now we can populate the info object by querying the file.
info.mType = FileType::Regular;
info.mType = dom::FileType::Regular;
if (!isRegular) {
bool isDir = false;
IOUTILS_TRY_WITH_CONTEXT(aFile->IsDirectory(&isDir), "Could not stat `%s'",
aFile->HumanReadablePath().get());
info.mType = isDir ? FileType::Directory : FileType::Other;
info.mType = isDir ? dom::FileType::Directory : dom::FileType::Other;
}
int64_t size = -1;
if (info.mType == FileType::Regular) {
if (info.mType == dom::FileType::Regular) {
IOUTILS_TRY_WITH_CONTEXT(aFile->GetFileSize(&size), "Could not stat `%s'",
aFile->HumanReadablePath().get());
}
@@ -2099,6 +2101,8 @@ Result<nsString, IOUtils::IOError> IOUtils::CreateUniqueSync(
/* static */
Result<nsCString, IOUtils::IOError> IOUtils::ComputeHexDigestSync(
nsIFile* aFile, const HashAlgorithm aAlgorithm) {
using HashAlgorithm = HashAlgorithm;
static constexpr size_t BUFFER_SIZE = 8192;
SECOidTag alg;
@@ -3093,7 +3097,7 @@ uint32_t IOUtils::LaunchProcess(GlobalObject& aGlobal,
}
#endif // XP_UNIX
} // namespace mozilla::dom
} // namespace mozilla
#undef REJECT_IF_INIT_PATH_FAILED
#undef IOUTILS_TRY_WITH_CONTEXT

View File

@@ -51,8 +51,6 @@ class PR_CloseDelete {
void operator()(PRFileDesc* aPtr) const { PR_Close(aPtr); }
};
namespace dom {
/**
* Implementation for the Web IDL interface at dom/chrome-webidl/IOUtils.webidl.
* Methods of this class must only be called from the parent process.
@@ -72,71 +70,67 @@ class IOUtils final {
using PhaseArray = EnumeratedArray<IOUtils::ShutdownPhase, T,
size_t(IOUtils::ShutdownPhase::Count)>;
static already_AddRefed<Promise> Read(GlobalObject& aGlobal,
const nsAString& aPath,
const ReadOptions& aOptions,
ErrorResult& aError);
static already_AddRefed<dom::Promise> Read(dom::GlobalObject& aGlobal,
static already_AddRefed<Promise> ReadUTF8(GlobalObject& aGlobal,
const nsAString& aPath,
const ReadUTF8Options& aOptions,
ErrorResult& aError);
static already_AddRefed<Promise> ReadJSON(GlobalObject& aGlobal,
const nsAString& aPath,
const ReadUTF8Options& aOptions,
ErrorResult& aError);
static already_AddRefed<Promise> Write(GlobalObject& aGlobal,
const nsAString& aPath,
const Uint8Array& aData,
const WriteOptions& aOptions,
ErrorResult& aError);
static already_AddRefed<Promise> WriteUTF8(GlobalObject& aGlobal,
const nsAString& aPath,
const nsACString& aString,
const WriteOptions& aOptions,
const dom::ReadOptions& aOptions,
ErrorResult& aError);
static already_AddRefed<Promise> WriteJSON(GlobalObject& aGlobal,
const nsAString& aPath,
JS::Handle<JS::Value> aValue,
const WriteOptions& aOptions,
static already_AddRefed<dom::Promise> ReadUTF8(
dom::GlobalObject& aGlobal, const nsAString& aPath,
const dom::ReadUTF8Options& aOptions, ErrorResult& aError);
static already_AddRefed<dom::Promise> ReadJSON(
dom::GlobalObject& aGlobal, const nsAString& aPath,
const dom::ReadUTF8Options& aOptions, ErrorResult& aError);
static already_AddRefed<dom::Promise> Write(dom::GlobalObject& aGlobal,
const nsAString& aPath,
const dom::Uint8Array& aData,
const dom::WriteOptions& aOptions,
ErrorResult& aError);
static already_AddRefed<dom::Promise> WriteUTF8(
dom::GlobalObject& aGlobal, const nsAString& aPath,
const nsACString& aString, const dom::WriteOptions& aOptions,
ErrorResult& aError);
static already_AddRefed<dom::Promise> WriteJSON(
dom::GlobalObject& aGlobal, const nsAString& aPath,
JS::Handle<JS::Value> aValue, const dom::WriteOptions& aOptions,
ErrorResult& aError);
static already_AddRefed<dom::Promise> Move(dom::GlobalObject& aGlobal,
const nsAString& aSourcePath,
const nsAString& aDestPath,
const dom::MoveOptions& aOptions,
ErrorResult& aError);
static already_AddRefed<Promise> Move(GlobalObject& aGlobal,
const nsAString& aSourcePath,
const nsAString& aDestPath,
const MoveOptions& aOptions,
ErrorResult& aError);
static already_AddRefed<dom::Promise> Remove(
dom::GlobalObject& aGlobal, const nsAString& aPath,
const dom::RemoveOptions& aOptions, ErrorResult& aError);
static already_AddRefed<Promise> Remove(GlobalObject& aGlobal,
const nsAString& aPath,
const RemoveOptions& aOptions,
ErrorResult& aError);
static already_AddRefed<dom::Promise> MakeDirectory(
dom::GlobalObject& aGlobal, const nsAString& aPath,
const dom::MakeDirectoryOptions& aOptions, ErrorResult& aError);
static already_AddRefed<Promise> MakeDirectory(
GlobalObject& aGlobal, const nsAString& aPath,
const MakeDirectoryOptions& aOptions, ErrorResult& aError);
static already_AddRefed<dom::Promise> Stat(dom::GlobalObject& aGlobal,
const nsAString& aPath,
ErrorResult& aError);
static already_AddRefed<Promise> Stat(GlobalObject& aGlobal,
const nsAString& aPath,
ErrorResult& aError);
static already_AddRefed<dom::Promise> Copy(dom::GlobalObject& aGlobal,
const nsAString& aSourcePath,
const nsAString& aDestPath,
const dom::CopyOptions& aOptions,
ErrorResult& aError);
static already_AddRefed<Promise> Copy(GlobalObject& aGlobal,
const nsAString& aSourcePath,
const nsAString& aDestPath,
const CopyOptions& aOptions,
ErrorResult& aError);
static already_AddRefed<dom::Promise> SetAccessTime(
dom::GlobalObject& aGlobal, const nsAString& aPath,
const dom::Optional<int64_t>& aAccess, ErrorResult& aError);
static already_AddRefed<Promise> SetAccessTime(
GlobalObject& aGlobal, const nsAString& aPath,
const Optional<int64_t>& aAccess, ErrorResult& aError);
static already_AddRefed<Promise> SetModificationTime(
GlobalObject& aGlobal, const nsAString& aPath,
const Optional<int64_t>& aModification, ErrorResult& aError);
static already_AddRefed<dom::Promise> SetModificationTime(
dom::GlobalObject& aGlobal, const nsAString& aPath,
const dom::Optional<int64_t>& aModification, ErrorResult& aError);
private:
using SetTimeFn = decltype(&nsIFile::SetLastAccessedTime);
@@ -144,109 +138,101 @@ class IOUtils final {
static_assert(
std::is_same_v<SetTimeFn, decltype(&nsIFile::SetLastModifiedTime)>);
static already_AddRefed<Promise> SetTime(GlobalObject& aGlobal,
const nsAString& aPath,
const Optional<int64_t>& aNewTime,
SetTimeFn aSetTimeFn,
const char* const aTimeKind,
ErrorResult& aError);
static already_AddRefed<dom::Promise> SetTime(
dom::GlobalObject& aGlobal, const nsAString& aPath,
const dom::Optional<int64_t>& aNewTime, SetTimeFn aSetTimeFn,
const char* const aTimeKind, ErrorResult& aError);
public:
static already_AddRefed<Promise> HasChildren(
GlobalObject& aGlobal, const nsAString& aPath,
const HasChildrenOptions& aOptions, ErrorResult& aError);
static already_AddRefed<dom::Promise> HasChildren(
dom::GlobalObject& aGlobal, const nsAString& aPath,
const dom::HasChildrenOptions& aOptions, ErrorResult& aError);
static already_AddRefed<Promise> GetChildren(
GlobalObject& aGlobal, const nsAString& aPath,
const GetChildrenOptions& aOptions, ErrorResult& aError);
static already_AddRefed<dom::Promise> GetChildren(
dom::GlobalObject& aGlobal, const nsAString& aPath,
const dom::GetChildrenOptions& aOptions, ErrorResult& aError);
static already_AddRefed<Promise> SetPermissions(GlobalObject& aGlobal,
const nsAString& aPath,
uint32_t aPermissions,
const bool aHonorUmask,
ErrorResult& aError);
static already_AddRefed<dom::Promise> SetPermissions(
dom::GlobalObject& aGlobal, const nsAString& aPath, uint32_t aPermissions,
const bool aHonorUmask, ErrorResult& aError);
static already_AddRefed<Promise> Exists(GlobalObject& aGlobal,
const nsAString& aPath,
ErrorResult& aError);
static already_AddRefed<dom::Promise> Exists(dom::GlobalObject& aGlobal,
const nsAString& aPath,
ErrorResult& aError);
static already_AddRefed<Promise> CreateUniqueFile(GlobalObject& aGlobal,
const nsAString& aParent,
const nsAString& aPrefix,
const uint32_t aPermissions,
ErrorResult& aError);
static already_AddRefed<Promise> CreateUniqueDirectory(
GlobalObject& aGlobal, const nsAString& aParent, const nsAString& aPrefix,
const uint32_t aPermissions, ErrorResult& aError);
static already_AddRefed<dom::Promise> CreateUniqueFile(
dom::GlobalObject& aGlobal, const nsAString& aParent,
const nsAString& aPrefix, const uint32_t aPermissions,
ErrorResult& aError);
static already_AddRefed<dom::Promise> CreateUniqueDirectory(
dom::GlobalObject& aGlobal, const nsAString& aParent,
const nsAString& aPrefix, const uint32_t aPermissions,
ErrorResult& aError);
private:
/**
* A helper method for CreateUniqueFile and CreateUniqueDirectory.
*/
static already_AddRefed<Promise> CreateUnique(GlobalObject& aGlobal,
const nsAString& aParent,
const nsAString& aPrefix,
const uint32_t aFileType,
const uint32_t aPermissions,
ErrorResult& aError);
static already_AddRefed<dom::Promise> CreateUnique(
dom::GlobalObject& aGlobal, const nsAString& aParent,
const nsAString& aPrefix, const uint32_t aFileType,
const uint32_t aPermissions, ErrorResult& aError);
public:
static already_AddRefed<Promise> ComputeHexDigest(
GlobalObject& aGlobal, const nsAString& aPath,
const HashAlgorithm aAlgorithm, ErrorResult& aError);
static already_AddRefed<dom::Promise> ComputeHexDigest(
dom::GlobalObject& aGlobal, const nsAString& aPath,
const dom::HashAlgorithm aAlgorithm, ErrorResult& aError);
#if defined(XP_WIN)
static already_AddRefed<Promise> GetWindowsAttributes(GlobalObject& aGlobal,
const nsAString& aPath,
ErrorResult& aError);
static already_AddRefed<dom::Promise> GetWindowsAttributes(
dom::GlobalObject& aGlobal, const nsAString& aPath, ErrorResult& aError);
static already_AddRefed<Promise> SetWindowsAttributes(
GlobalObject& aGlobal, const nsAString& aPath,
static already_AddRefed<dom::Promise> SetWindowsAttributes(
dom::GlobalObject& aGlobal, const nsAString& aPath,
const mozilla::dom::WindowsFileAttributes& aAttrs, ErrorResult& aError);
#elif defined(XP_MACOSX)
static already_AddRefed<Promise> HasMacXAttr(GlobalObject& aGlobal,
const nsAString& aPath,
const nsACString& aAttr,
ErrorResult& aError);
static already_AddRefed<Promise> GetMacXAttr(GlobalObject& aGlobal,
const nsAString& aPath,
const nsACString& aAttr,
ErrorResult& aError);
static already_AddRefed<Promise> SetMacXAttr(GlobalObject& aGlobal,
const nsAString& aPath,
const nsACString& aAttr,
const Uint8Array& aValue,
ErrorResult& aError);
static already_AddRefed<Promise> DelMacXAttr(GlobalObject& aGlobal,
const nsAString& aPath,
const nsACString& aAttr,
ErrorResult& aError);
static already_AddRefed<dom::Promise> HasMacXAttr(dom::GlobalObject& aGlobal,
const nsAString& aPath,
const nsACString& aAttr,
ErrorResult& aError);
static already_AddRefed<dom::Promise> GetMacXAttr(dom::GlobalObject& aGlobal,
const nsAString& aPath,
const nsACString& aAttr,
ErrorResult& aError);
static already_AddRefed<dom::Promise> SetMacXAttr(
dom::GlobalObject& aGlobal, const nsAString& aPath,
const nsACString& aAttr, const dom::Uint8Array& aValue,
ErrorResult& aError);
static already_AddRefed<dom::Promise> DelMacXAttr(dom::GlobalObject& aGlobal,
const nsAString& aPath,
const nsACString& aAttr,
ErrorResult& aError);
#endif
#ifdef XP_UNIX
using UnixString = OwningUTF8StringOrUint8Array;
static uint32_t LaunchProcess(GlobalObject& aGlobal,
const Sequence<UnixString>& aArgv,
const LaunchOptions& aOptions,
using UnixString = dom::OwningUTF8StringOrUint8Array;
static uint32_t LaunchProcess(dom::GlobalObject& aGlobal,
const dom::Sequence<UnixString>& aArgv,
const dom::LaunchOptions& aOptions,
ErrorResult& aRv);
#endif
static already_AddRefed<Promise> GetFile(
GlobalObject& aGlobal, const Sequence<nsString>& aComponents,
static already_AddRefed<dom::Promise> GetFile(
dom::GlobalObject& aGlobal, const dom::Sequence<nsString>& aComponents,
ErrorResult& aError);
static already_AddRefed<Promise> GetDirectory(
GlobalObject& aGlobal, const Sequence<nsString>& aComponents,
static already_AddRefed<dom::Promise> GetDirectory(
dom::GlobalObject& aGlobal, const dom::Sequence<nsString>& aComponents,
ErrorResult& aError);
static void GetProfileBeforeChange(GlobalObject& aGlobal,
static void GetProfileBeforeChange(dom::GlobalObject& aGlobal,
JS::MutableHandle<JS::Value>,
ErrorResult& aRv);
static void GetSendTelemetry(GlobalObject& aGlobal,
static void GetSendTelemetry(dom::GlobalObject& aGlobal,
JS::MutableHandle<JS::Value>, ErrorResult& aRv);
static RefPtr<SyncReadFile> OpenFileForSyncReading(GlobalObject& aGlobal,
static RefPtr<SyncReadFile> OpenFileForSyncReading(dom::GlobalObject& aGlobal,
const nsAString& aPath,
ErrorResult& aRv);
@@ -255,7 +241,7 @@ class IOUtils final {
/**
* The kind of buffer to allocate.
*
* This controls what kind of JS object (a JSString or a Uint8Array) is
* This controls what kind of JS object (a JSString or a dom::Uint8Array) is
* returned by |ToJSValue()|.
*/
enum class BufferKind {
@@ -277,9 +263,8 @@ class IOUtils final {
class State;
template <typename Fn>
static already_AddRefed<Promise> WithPromiseAndState(GlobalObject& aGlobal,
ErrorResult& aError,
Fn aFn);
static already_AddRefed<dom::Promise> WithPromiseAndState(
dom::GlobalObject& aGlobal, ErrorResult& aError, Fn aFn);
/**
* Dispatch a task on the event queue and resolve or reject the associated
@@ -293,16 +278,16 @@ class IOUtils final {
* @param aFunc The task to run.
*/
template <typename OkT, typename Fn>
static void DispatchAndResolve(EventQueue* aQueue, Promise* aPromise,
static void DispatchAndResolve(EventQueue* aQueue, dom::Promise* aPromise,
Fn aFunc);
/**
* Creates a new JS Promise.
* Creates a new JS dom::Promise.
*
* @return The new promise, or |nullptr| on failure.
*/
static already_AddRefed<Promise> CreateJSPromise(GlobalObject& aGlobal,
ErrorResult& aError);
static already_AddRefed<dom::Promise> CreateJSPromise(
dom::GlobalObject& aGlobal, ErrorResult& aError);
// Allow conversion of |InternalFileInfo| with |ToJSValue|.
friend bool ToJSValue(JSContext* aCx,
@@ -539,7 +524,7 @@ class IOUtils final {
* @return The hash of the file, as a hex digest.
*/
static Result<nsCString, IOError> ComputeHexDigestSync(
nsIFile* aFile, const HashAlgorithm aAlgorithm);
nsIFile* aFile, const dom::HashAlgorithm aAlgorithm);
#if defined(XP_WIN)
/**
@@ -573,7 +558,7 @@ class IOUtils final {
const nsCString& aAttr);
#endif
static void GetShutdownClient(GlobalObject& aGlobal,
static void GetShutdownClient(dom::GlobalObject& aGlobal,
JS::MutableHandle<JS::Value> aClient,
ErrorResult& aRv, const ShutdownPhase aPhase);
@@ -727,7 +712,7 @@ class IOUtils::IOError {
*/
struct IOUtils::InternalFileInfo {
nsString mPath;
FileType mType = FileType::Other;
dom::FileType mType = dom::FileType::Other;
uint64_t mSize = 0;
Maybe<PRTime> mCreationTime; // In ms since epoch.
PRTime mLastAccessed = 0; // In ms since epoch.
@@ -746,12 +731,12 @@ struct IOUtils::InternalFileInfo {
struct IOUtils::InternalWriteOpts {
RefPtr<nsIFile> mBackupFile;
RefPtr<nsIFile> mTmpFile;
WriteMode mMode;
dom::WriteMode mMode;
bool mFlush = false;
bool mCompress = false;
static Result<InternalWriteOpts, IOUtils::IOError> FromBinding(
const WriteOptions& aOptions);
const dom::WriteOptions& aOptions);
};
/**
@@ -938,7 +923,7 @@ class SyncReadFile : public nsISupports, public nsWrapperCache {
JS::Handle<JSObject*> aGivenProto) override;
int64_t Size() const { return mSize; }
void ReadBytesInto(const Uint8Array&, const int64_t, ErrorResult& aRv);
void ReadBytesInto(const dom::Uint8Array&, const int64_t, ErrorResult& aRv);
void Close();
private:
@@ -949,7 +934,6 @@ class SyncReadFile : public nsISupports, public nsWrapperCache {
int64_t mSize = 0;
};
} // namespace dom
} // namespace mozilla
#endif

View File

@@ -31,7 +31,9 @@
#include "nsURLHelper.h"
#include "xpcpublic.h"
namespace mozilla::dom {
using namespace mozilla::dom;
namespace mozilla {
static constexpr auto ERROR_EMPTY_PATH =
"PathUtils does not support empty paths"_ns;
@@ -632,4 +634,4 @@ nsresult PathUtils::DirectoryCache::PopulateDirectoriesImpl(
return NS_OK;
}
} // namespace mozilla::dom
} // namespace mozilla

View File

@@ -23,8 +23,6 @@
namespace mozilla {
class ErrorResult;
namespace dom {
class PathUtils final {
public:
/**
@@ -41,14 +39,15 @@ class PathUtils final {
*/
static nsresult InitFileWithPath(nsIFile* aFile, const nsAString& aPath);
static void Filename(const GlobalObject&, const nsAString& aPath,
static void Filename(const dom::GlobalObject&, const nsAString& aPath,
nsString& aResult, ErrorResult& aErr);
static void Parent(const GlobalObject&, const nsAString& aPath,
static void Parent(const dom::GlobalObject&, const nsAString& aPath,
const int32_t aDepth, nsString& aResult,
ErrorResult& aErr);
static void Join(const GlobalObject&, const Sequence<nsString>& aComponents,
static void Join(const dom::GlobalObject&,
const dom::Sequence<nsString>& aComponents,
nsString& aResult, ErrorResult& aErr);
/**
@@ -65,45 +64,47 @@ class PathUtils final {
static already_AddRefed<nsIFile> Join(const Span<const nsString>& aComponents,
ErrorResult& aErr);
static void JoinRelative(const GlobalObject&, const nsAString& aBasePath,
static void JoinRelative(const dom::GlobalObject&, const nsAString& aBasePath,
const nsAString& aRelativePath, nsString& aResult,
ErrorResult& aErr);
static void ToExtendedWindowsPath(const GlobalObject&, const nsAString& aPath,
nsString& aResult, ErrorResult& aErr);
static void Normalize(const GlobalObject&, const nsAString& aPath,
nsString& aResult, ErrorResult& aErr);
static void Split(const GlobalObject&, const nsAString& aPath,
nsTArray<nsString>& aResult, ErrorResult& aErr);
static void SplitRelative(const GlobalObject& aGlobal, const nsAString& aPath,
const SplitRelativeOptions& aOptions,
nsTArray<nsString>& aResult, ErrorResult& aErr);
static void ToFileURI(const GlobalObject&, const nsAString& aPath,
nsCString& aResult, ErrorResult& aErr);
static bool IsAbsolute(const GlobalObject&, const nsAString& aPath);
static void GetProfileDirSync(const GlobalObject&, nsString& aResult,
ErrorResult& aErr);
static void GetLocalProfileDirSync(const GlobalObject&, nsString& aResult,
ErrorResult& aErr);
static void GetTempDirSync(const GlobalObject&, nsString& aResult,
ErrorResult& aErr);
static void GetXulLibraryPathSync(const GlobalObject&, nsString& aResult,
static void ToExtendedWindowsPath(const dom::GlobalObject&,
const nsAString& aPath, nsString& aResult,
ErrorResult& aErr);
static already_AddRefed<Promise> GetProfileDirAsync(
const GlobalObject& aGlobal, ErrorResult& aErr);
static already_AddRefed<Promise> GetLocalProfileDirAsync(
const GlobalObject& aGlobal, ErrorResult& aErr);
static already_AddRefed<Promise> GetTempDirAsync(const GlobalObject& aGlobal,
ErrorResult& aErr);
static already_AddRefed<Promise> GetXulLibraryPathAsync(
const GlobalObject& aGlobal, ErrorResult& aErr);
static void Normalize(const dom::GlobalObject&, const nsAString& aPath,
nsString& aResult, ErrorResult& aErr);
static void Split(const dom::GlobalObject&, const nsAString& aPath,
nsTArray<nsString>& aResult, ErrorResult& aErr);
static void SplitRelative(const dom::GlobalObject& aGlobal,
const nsAString& aPath,
const dom::SplitRelativeOptions& aOptions,
nsTArray<nsString>& aResult, ErrorResult& aErr);
static void ToFileURI(const dom::GlobalObject&, const nsAString& aPath,
nsCString& aResult, ErrorResult& aErr);
static bool IsAbsolute(const dom::GlobalObject&, const nsAString& aPath);
static void GetProfileDirSync(const dom::GlobalObject&, nsString& aResult,
ErrorResult& aErr);
static void GetLocalProfileDirSync(const dom::GlobalObject&,
nsString& aResult, ErrorResult& aErr);
static void GetTempDirSync(const dom::GlobalObject&, nsString& aResult,
ErrorResult& aErr);
static void GetXulLibraryPathSync(const dom::GlobalObject&, nsString& aResult,
ErrorResult& aErr);
static already_AddRefed<dom::Promise> GetProfileDirAsync(
const dom::GlobalObject& aGlobal, ErrorResult& aErr);
static already_AddRefed<dom::Promise> GetLocalProfileDirAsync(
const dom::GlobalObject& aGlobal, ErrorResult& aErr);
static already_AddRefed<dom::Promise> GetTempDirAsync(
const dom::GlobalObject& aGlobal, ErrorResult& aErr);
static already_AddRefed<dom::Promise> GetXulLibraryPathAsync(
const dom::GlobalObject& aGlobal, ErrorResult& aErr);
private:
class DirectoryCache;
@@ -175,9 +176,9 @@ class PathUtils::DirectoryCache final {
*
* @return A promise that resolves to the path of the requested directory.
*/
already_AddRefed<Promise> GetDirectoryAsync(const GlobalObject& aGlobalObject,
ErrorResult& aErr,
const Directory aRequestedDir);
already_AddRefed<dom::Promise> GetDirectoryAsync(
const dom::GlobalObject& aGlobalObject, ErrorResult& aErr,
const Directory aRequestedDir);
private:
using PopulateDirectoriesPromise = MozPromise<Ok, nsresult, false>;
@@ -238,7 +239,8 @@ class PathUtils::DirectoryCache final {
* @param aPromise The JS promise to resolve.
* @param aRequestedDir The requested directory cache entry.
*/
void ResolveWithDirectory(Promise* aPromise, const Directory aRequestedDir);
void ResolveWithDirectory(dom::Promise* aPromise,
const Directory aRequestedDir);
template <typename T>
using DirectoryArray =
@@ -255,7 +257,6 @@ class PathUtils::DirectoryCache final {
};
};
} // namespace dom
} // namespace mozilla
#endif

24
xpcom/ioutils/moz.build Normal file
View File

@@ -0,0 +1,24 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.
with Files("**/*"):
BUG_COMPONENT = ("Toolkit", "IOUtils and PathUtils")
EXPORTS.mozilla += [
"IOUtils.h",
"PathUtils.h",
]
UNIFIED_SOURCES += [
"IOUtils.cpp",
"PathUtils.cpp",
]
MOCHITEST_CHROME_MANIFESTS += ["tests/chrome.toml"]
FINAL_LIBRARY = "xul"
include("/ipc/chromium/chromium-config.mozbuild")

View File

@@ -37,3 +37,8 @@ run-if = ["os == 'mac'"]
run-if = ["os == 'win'"]
["test_ioutils_worker.xhtml"]
["test_pathutils.html"]
["test_pathutils_worker.xhtml"]
support-files = ["pathutils_worker.js"]

View File

@@ -1,5 +1,7 @@
// Utility functions.
/* eslint-env mozilla/simpletest */
Uint8Array.prototype.equals = function equals(other) {
if (this.byteLength !== other.byteLength) {
return false;

View File

@@ -1,4 +1,3 @@
<!-- Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ -->
<!DOCTYPE HTML>

View File

@@ -27,6 +27,7 @@ DIRS += [
"system",
"../chrome",
"build",
"ioutils",
]
if CONFIG["OS_ARCH"] == "WINNT" and CONFIG["MOZ_DEBUG"]: