diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 086accbe59f6..342502498f91 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -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': { diff --git a/dom/system/moz.build b/dom/system/moz.build index fa7367fd65d6..73e77871371e 100644 --- a/dom/system/moz.build +++ b/dom/system/moz.build @@ -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"] diff --git a/dom/system/tests/chrome.toml b/dom/system/tests/chrome.toml deleted file mode 100644 index 87f782b4659f..000000000000 --- a/dom/system/tests/chrome.toml +++ /dev/null @@ -1,6 +0,0 @@ -[DEFAULT] - -["test_pathutils.html"] - -["test_pathutils_worker.xhtml"] -support-files = ["pathutils_worker.js"] diff --git a/mots.yaml b/mots.yaml index 5b5478649306..42a5b1fe86f9 100644 --- a/mots.yaml +++ b/mots.yaml @@ -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 diff --git a/toolkit/components/terminator/nsTerminator.cpp b/toolkit/components/terminator/nsTerminator.cpp index 00557ad9e2de..e613f0b27b69 100644 --- a/toolkit/components/terminator/nsTerminator.cpp +++ b/toolkit/components/terminator/nsTerminator.cpp @@ -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 diff --git a/dom/system/IOUtils.cpp b/xpcom/ioutils/IOUtils.cpp similarity index 99% rename from dom/system/IOUtils.cpp rename to xpcom/ioutils/IOUtils.cpp index 6688ccbe2a4c..103c8ef77698 100644 --- a/dom/system/IOUtils.cpp +++ b/xpcom/ioutils/IOUtils.cpp @@ -9,7 +9,6 @@ #include #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 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> p = aQueue->Dispatch(std::move(aFunc))) { @@ -1884,16 +1886,16 @@ Result 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 IOUtils::CreateUniqueSync( /* static */ Result 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 diff --git a/dom/system/IOUtils.h b/xpcom/ioutils/IOUtils.h similarity index 76% rename from dom/system/IOUtils.h rename to xpcom/ioutils/IOUtils.h index 19800e392955..8d44d74761ba 100644 --- a/dom/system/IOUtils.h +++ b/xpcom/ioutils/IOUtils.h @@ -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; - static already_AddRefed Read(GlobalObject& aGlobal, - const nsAString& aPath, - const ReadOptions& aOptions, - ErrorResult& aError); + static already_AddRefed Read(dom::GlobalObject& aGlobal, - static already_AddRefed ReadUTF8(GlobalObject& aGlobal, - const nsAString& aPath, - const ReadUTF8Options& aOptions, - ErrorResult& aError); - - static already_AddRefed ReadJSON(GlobalObject& aGlobal, - const nsAString& aPath, - const ReadUTF8Options& aOptions, - ErrorResult& aError); - - static already_AddRefed Write(GlobalObject& aGlobal, - const nsAString& aPath, - const Uint8Array& aData, - const WriteOptions& aOptions, - ErrorResult& aError); - - static already_AddRefed WriteUTF8(GlobalObject& aGlobal, const nsAString& aPath, - const nsACString& aString, - const WriteOptions& aOptions, + const dom::ReadOptions& aOptions, ErrorResult& aError); - static already_AddRefed WriteJSON(GlobalObject& aGlobal, - const nsAString& aPath, - JS::Handle aValue, - const WriteOptions& aOptions, + static already_AddRefed ReadUTF8( + dom::GlobalObject& aGlobal, const nsAString& aPath, + const dom::ReadUTF8Options& aOptions, ErrorResult& aError); + + static already_AddRefed ReadJSON( + dom::GlobalObject& aGlobal, const nsAString& aPath, + const dom::ReadUTF8Options& aOptions, ErrorResult& aError); + + static already_AddRefed Write(dom::GlobalObject& aGlobal, + const nsAString& aPath, + const dom::Uint8Array& aData, + const dom::WriteOptions& aOptions, + ErrorResult& aError); + + static already_AddRefed WriteUTF8( + dom::GlobalObject& aGlobal, const nsAString& aPath, + const nsACString& aString, const dom::WriteOptions& aOptions, + ErrorResult& aError); + + static already_AddRefed WriteJSON( + dom::GlobalObject& aGlobal, const nsAString& aPath, + JS::Handle aValue, const dom::WriteOptions& aOptions, + ErrorResult& aError); + + static already_AddRefed Move(dom::GlobalObject& aGlobal, + const nsAString& aSourcePath, + const nsAString& aDestPath, + const dom::MoveOptions& aOptions, ErrorResult& aError); - static already_AddRefed Move(GlobalObject& aGlobal, - const nsAString& aSourcePath, - const nsAString& aDestPath, - const MoveOptions& aOptions, - ErrorResult& aError); + static already_AddRefed Remove( + dom::GlobalObject& aGlobal, const nsAString& aPath, + const dom::RemoveOptions& aOptions, ErrorResult& aError); - static already_AddRefed Remove(GlobalObject& aGlobal, - const nsAString& aPath, - const RemoveOptions& aOptions, - ErrorResult& aError); + static already_AddRefed MakeDirectory( + dom::GlobalObject& aGlobal, const nsAString& aPath, + const dom::MakeDirectoryOptions& aOptions, ErrorResult& aError); - static already_AddRefed MakeDirectory( - GlobalObject& aGlobal, const nsAString& aPath, - const MakeDirectoryOptions& aOptions, ErrorResult& aError); + static already_AddRefed Stat(dom::GlobalObject& aGlobal, + const nsAString& aPath, + ErrorResult& aError); - static already_AddRefed Stat(GlobalObject& aGlobal, - const nsAString& aPath, - ErrorResult& aError); + static already_AddRefed Copy(dom::GlobalObject& aGlobal, + const nsAString& aSourcePath, + const nsAString& aDestPath, + const dom::CopyOptions& aOptions, + ErrorResult& aError); - static already_AddRefed Copy(GlobalObject& aGlobal, - const nsAString& aSourcePath, - const nsAString& aDestPath, - const CopyOptions& aOptions, - ErrorResult& aError); + static already_AddRefed SetAccessTime( + dom::GlobalObject& aGlobal, const nsAString& aPath, + const dom::Optional& aAccess, ErrorResult& aError); - static already_AddRefed SetAccessTime( - GlobalObject& aGlobal, const nsAString& aPath, - const Optional& aAccess, ErrorResult& aError); - - static already_AddRefed SetModificationTime( - GlobalObject& aGlobal, const nsAString& aPath, - const Optional& aModification, ErrorResult& aError); + static already_AddRefed SetModificationTime( + dom::GlobalObject& aGlobal, const nsAString& aPath, + const dom::Optional& aModification, ErrorResult& aError); private: using SetTimeFn = decltype(&nsIFile::SetLastAccessedTime); @@ -144,109 +138,101 @@ class IOUtils final { static_assert( std::is_same_v); - static already_AddRefed SetTime(GlobalObject& aGlobal, - const nsAString& aPath, - const Optional& aNewTime, - SetTimeFn aSetTimeFn, - const char* const aTimeKind, - ErrorResult& aError); + static already_AddRefed SetTime( + dom::GlobalObject& aGlobal, const nsAString& aPath, + const dom::Optional& aNewTime, SetTimeFn aSetTimeFn, + const char* const aTimeKind, ErrorResult& aError); public: - static already_AddRefed HasChildren( - GlobalObject& aGlobal, const nsAString& aPath, - const HasChildrenOptions& aOptions, ErrorResult& aError); + static already_AddRefed HasChildren( + dom::GlobalObject& aGlobal, const nsAString& aPath, + const dom::HasChildrenOptions& aOptions, ErrorResult& aError); - static already_AddRefed GetChildren( - GlobalObject& aGlobal, const nsAString& aPath, - const GetChildrenOptions& aOptions, ErrorResult& aError); + static already_AddRefed GetChildren( + dom::GlobalObject& aGlobal, const nsAString& aPath, + const dom::GetChildrenOptions& aOptions, ErrorResult& aError); - static already_AddRefed SetPermissions(GlobalObject& aGlobal, - const nsAString& aPath, - uint32_t aPermissions, - const bool aHonorUmask, - ErrorResult& aError); + static already_AddRefed SetPermissions( + dom::GlobalObject& aGlobal, const nsAString& aPath, uint32_t aPermissions, + const bool aHonorUmask, ErrorResult& aError); - static already_AddRefed Exists(GlobalObject& aGlobal, - const nsAString& aPath, - ErrorResult& aError); + static already_AddRefed Exists(dom::GlobalObject& aGlobal, + const nsAString& aPath, + ErrorResult& aError); - static already_AddRefed CreateUniqueFile(GlobalObject& aGlobal, - const nsAString& aParent, - const nsAString& aPrefix, - const uint32_t aPermissions, - ErrorResult& aError); - static already_AddRefed CreateUniqueDirectory( - GlobalObject& aGlobal, const nsAString& aParent, const nsAString& aPrefix, - const uint32_t aPermissions, ErrorResult& aError); + static already_AddRefed CreateUniqueFile( + dom::GlobalObject& aGlobal, const nsAString& aParent, + const nsAString& aPrefix, const uint32_t aPermissions, + ErrorResult& aError); + static already_AddRefed 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 CreateUnique(GlobalObject& aGlobal, - const nsAString& aParent, - const nsAString& aPrefix, - const uint32_t aFileType, - const uint32_t aPermissions, - ErrorResult& aError); + static already_AddRefed CreateUnique( + dom::GlobalObject& aGlobal, const nsAString& aParent, + const nsAString& aPrefix, const uint32_t aFileType, + const uint32_t aPermissions, ErrorResult& aError); public: - static already_AddRefed ComputeHexDigest( - GlobalObject& aGlobal, const nsAString& aPath, - const HashAlgorithm aAlgorithm, ErrorResult& aError); + static already_AddRefed ComputeHexDigest( + dom::GlobalObject& aGlobal, const nsAString& aPath, + const dom::HashAlgorithm aAlgorithm, ErrorResult& aError); #if defined(XP_WIN) - static already_AddRefed GetWindowsAttributes(GlobalObject& aGlobal, - const nsAString& aPath, - ErrorResult& aError); + static already_AddRefed GetWindowsAttributes( + dom::GlobalObject& aGlobal, const nsAString& aPath, ErrorResult& aError); - static already_AddRefed SetWindowsAttributes( - GlobalObject& aGlobal, const nsAString& aPath, + static already_AddRefed SetWindowsAttributes( + dom::GlobalObject& aGlobal, const nsAString& aPath, const mozilla::dom::WindowsFileAttributes& aAttrs, ErrorResult& aError); #elif defined(XP_MACOSX) - static already_AddRefed HasMacXAttr(GlobalObject& aGlobal, - const nsAString& aPath, - const nsACString& aAttr, - ErrorResult& aError); - static already_AddRefed GetMacXAttr(GlobalObject& aGlobal, - const nsAString& aPath, - const nsACString& aAttr, - ErrorResult& aError); - static already_AddRefed SetMacXAttr(GlobalObject& aGlobal, - const nsAString& aPath, - const nsACString& aAttr, - const Uint8Array& aValue, - ErrorResult& aError); - static already_AddRefed DelMacXAttr(GlobalObject& aGlobal, - const nsAString& aPath, - const nsACString& aAttr, - ErrorResult& aError); + static already_AddRefed HasMacXAttr(dom::GlobalObject& aGlobal, + const nsAString& aPath, + const nsACString& aAttr, + ErrorResult& aError); + static already_AddRefed GetMacXAttr(dom::GlobalObject& aGlobal, + const nsAString& aPath, + const nsACString& aAttr, + ErrorResult& aError); + static already_AddRefed SetMacXAttr( + dom::GlobalObject& aGlobal, const nsAString& aPath, + const nsACString& aAttr, const dom::Uint8Array& aValue, + ErrorResult& aError); + static already_AddRefed 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& aArgv, - const LaunchOptions& aOptions, + using UnixString = dom::OwningUTF8StringOrUint8Array; + static uint32_t LaunchProcess(dom::GlobalObject& aGlobal, + const dom::Sequence& aArgv, + const dom::LaunchOptions& aOptions, ErrorResult& aRv); #endif - static already_AddRefed GetFile( - GlobalObject& aGlobal, const Sequence& aComponents, + static already_AddRefed GetFile( + dom::GlobalObject& aGlobal, const dom::Sequence& aComponents, ErrorResult& aError); - static already_AddRefed GetDirectory( - GlobalObject& aGlobal, const Sequence& aComponents, + static already_AddRefed GetDirectory( + dom::GlobalObject& aGlobal, const dom::Sequence& aComponents, ErrorResult& aError); - static void GetProfileBeforeChange(GlobalObject& aGlobal, + static void GetProfileBeforeChange(dom::GlobalObject& aGlobal, JS::MutableHandle, ErrorResult& aRv); - static void GetSendTelemetry(GlobalObject& aGlobal, + static void GetSendTelemetry(dom::GlobalObject& aGlobal, JS::MutableHandle, ErrorResult& aRv); - static RefPtr OpenFileForSyncReading(GlobalObject& aGlobal, + static RefPtr 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 - static already_AddRefed WithPromiseAndState(GlobalObject& aGlobal, - ErrorResult& aError, - Fn aFn); + static already_AddRefed 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 - 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 CreateJSPromise(GlobalObject& aGlobal, - ErrorResult& aError); + static already_AddRefed 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 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 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 mCreationTime; // In ms since epoch. PRTime mLastAccessed = 0; // In ms since epoch. @@ -746,12 +731,12 @@ struct IOUtils::InternalFileInfo { struct IOUtils::InternalWriteOpts { RefPtr mBackupFile; RefPtr mTmpFile; - WriteMode mMode; + dom::WriteMode mMode; bool mFlush = false; bool mCompress = false; static Result FromBinding( - const WriteOptions& aOptions); + const dom::WriteOptions& aOptions); }; /** @@ -938,7 +923,7 @@ class SyncReadFile : public nsISupports, public nsWrapperCache { JS::Handle 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 diff --git a/dom/system/PathUtils.cpp b/xpcom/ioutils/PathUtils.cpp similarity index 99% rename from dom/system/PathUtils.cpp rename to xpcom/ioutils/PathUtils.cpp index 1d4fee8df163..258024845187 100644 --- a/dom/system/PathUtils.cpp +++ b/xpcom/ioutils/PathUtils.cpp @@ -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 diff --git a/dom/system/PathUtils.h b/xpcom/ioutils/PathUtils.h similarity index 77% rename from dom/system/PathUtils.h rename to xpcom/ioutils/PathUtils.h index 1870d92f2352..67f72d173e5e 100644 --- a/dom/system/PathUtils.h +++ b/xpcom/ioutils/PathUtils.h @@ -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& aComponents, + static void Join(const dom::GlobalObject&, + const dom::Sequence& aComponents, nsString& aResult, ErrorResult& aErr); /** @@ -65,45 +64,47 @@ class PathUtils final { static already_AddRefed Join(const Span& 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& aResult, ErrorResult& aErr); - - static void SplitRelative(const GlobalObject& aGlobal, const nsAString& aPath, - const SplitRelativeOptions& aOptions, - nsTArray& 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 GetProfileDirAsync( - const GlobalObject& aGlobal, ErrorResult& aErr); - static already_AddRefed GetLocalProfileDirAsync( - const GlobalObject& aGlobal, ErrorResult& aErr); - static already_AddRefed GetTempDirAsync(const GlobalObject& aGlobal, - ErrorResult& aErr); - static already_AddRefed 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& aResult, ErrorResult& aErr); + + static void SplitRelative(const dom::GlobalObject& aGlobal, + const nsAString& aPath, + const dom::SplitRelativeOptions& aOptions, + nsTArray& 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 GetProfileDirAsync( + const dom::GlobalObject& aGlobal, ErrorResult& aErr); + static already_AddRefed GetLocalProfileDirAsync( + const dom::GlobalObject& aGlobal, ErrorResult& aErr); + static already_AddRefed GetTempDirAsync( + const dom::GlobalObject& aGlobal, ErrorResult& aErr); + static already_AddRefed 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 GetDirectoryAsync(const GlobalObject& aGlobalObject, - ErrorResult& aErr, - const Directory aRequestedDir); + already_AddRefed GetDirectoryAsync( + const dom::GlobalObject& aGlobalObject, ErrorResult& aErr, + const Directory aRequestedDir); private: using PopulateDirectoriesPromise = MozPromise; @@ -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 using DirectoryArray = @@ -255,7 +257,6 @@ class PathUtils::DirectoryCache final { }; }; -} // namespace dom } // namespace mozilla #endif diff --git a/xpcom/ioutils/moz.build b/xpcom/ioutils/moz.build new file mode 100644 index 000000000000..25a638808c59 --- /dev/null +++ b/xpcom/ioutils/moz.build @@ -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") diff --git a/dom/system/tests/ioutils/chrome.toml b/xpcom/ioutils/tests/chrome.toml similarity index 87% rename from dom/system/tests/ioutils/chrome.toml rename to xpcom/ioutils/tests/chrome.toml index cb0582e006ea..e55cd495d37c 100644 --- a/dom/system/tests/ioutils/chrome.toml +++ b/xpcom/ioutils/tests/chrome.toml @@ -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"] diff --git a/dom/system/tests/ioutils/file_ioutils_test_fixtures.js b/xpcom/ioutils/tests/file_ioutils_test_fixtures.js similarity index 98% rename from dom/system/tests/ioutils/file_ioutils_test_fixtures.js rename to xpcom/ioutils/tests/file_ioutils_test_fixtures.js index 5d2e5011c954..80236cdd1572 100644 --- a/dom/system/tests/ioutils/file_ioutils_test_fixtures.js +++ b/xpcom/ioutils/tests/file_ioutils_test_fixtures.js @@ -1,5 +1,7 @@ // Utility functions. +/* eslint-env mozilla/simpletest */ + Uint8Array.prototype.equals = function equals(other) { if (this.byteLength !== other.byteLength) { return false; diff --git a/dom/system/tests/ioutils/file_ioutils_worker.js b/xpcom/ioutils/tests/file_ioutils_worker.js similarity index 100% rename from dom/system/tests/ioutils/file_ioutils_worker.js rename to xpcom/ioutils/tests/file_ioutils_worker.js diff --git a/dom/system/tests/pathutils_worker.js b/xpcom/ioutils/tests/pathutils_worker.js similarity index 100% rename from dom/system/tests/pathutils_worker.js rename to xpcom/ioutils/tests/pathutils_worker.js diff --git a/dom/system/tests/ioutils/test_ioutils.html b/xpcom/ioutils/tests/test_ioutils.html similarity index 100% rename from dom/system/tests/ioutils/test_ioutils.html rename to xpcom/ioutils/tests/test_ioutils.html diff --git a/dom/system/tests/ioutils/test_ioutils_compute_hex_digest.html b/xpcom/ioutils/tests/test_ioutils_compute_hex_digest.html similarity index 99% rename from dom/system/tests/ioutils/test_ioutils_compute_hex_digest.html rename to xpcom/ioutils/tests/test_ioutils_compute_hex_digest.html index 7a98f83a1fef..977dbd23fba2 100644 --- a/dom/system/tests/ioutils/test_ioutils_compute_hex_digest.html +++ b/xpcom/ioutils/tests/test_ioutils_compute_hex_digest.html @@ -1,4 +1,3 @@ - diff --git a/dom/system/tests/ioutils/test_ioutils_copy_move.html b/xpcom/ioutils/tests/test_ioutils_copy_move.html similarity index 100% rename from dom/system/tests/ioutils/test_ioutils_copy_move.html rename to xpcom/ioutils/tests/test_ioutils_copy_move.html diff --git a/dom/system/tests/ioutils/test_ioutils_create_unique.html b/xpcom/ioutils/tests/test_ioutils_create_unique.html similarity index 100% rename from dom/system/tests/ioutils/test_ioutils_create_unique.html rename to xpcom/ioutils/tests/test_ioutils_create_unique.html diff --git a/dom/system/tests/ioutils/test_ioutils_dir_iteration.html b/xpcom/ioutils/tests/test_ioutils_dir_iteration.html similarity index 100% rename from dom/system/tests/ioutils/test_ioutils_dir_iteration.html rename to xpcom/ioutils/tests/test_ioutils_dir_iteration.html diff --git a/dom/system/tests/ioutils/test_ioutils_getfile.html b/xpcom/ioutils/tests/test_ioutils_getfile.html similarity index 100% rename from dom/system/tests/ioutils/test_ioutils_getfile.html rename to xpcom/ioutils/tests/test_ioutils_getfile.html diff --git a/dom/system/tests/ioutils/test_ioutils_mac_xattr.html b/xpcom/ioutils/tests/test_ioutils_mac_xattr.html similarity index 100% rename from dom/system/tests/ioutils/test_ioutils_mac_xattr.html rename to xpcom/ioutils/tests/test_ioutils_mac_xattr.html diff --git a/dom/system/tests/ioutils/test_ioutils_mkdir.html b/xpcom/ioutils/tests/test_ioutils_mkdir.html similarity index 100% rename from dom/system/tests/ioutils/test_ioutils_mkdir.html rename to xpcom/ioutils/tests/test_ioutils_mkdir.html diff --git a/dom/system/tests/ioutils/test_ioutils_read_write.html b/xpcom/ioutils/tests/test_ioutils_read_write.html similarity index 100% rename from dom/system/tests/ioutils/test_ioutils_read_write.html rename to xpcom/ioutils/tests/test_ioutils_read_write.html diff --git a/dom/system/tests/ioutils/test_ioutils_read_write_json.html b/xpcom/ioutils/tests/test_ioutils_read_write_json.html similarity index 100% rename from dom/system/tests/ioutils/test_ioutils_read_write_json.html rename to xpcom/ioutils/tests/test_ioutils_read_write_json.html diff --git a/dom/system/tests/ioutils/test_ioutils_read_write_utf8.html b/xpcom/ioutils/tests/test_ioutils_read_write_utf8.html similarity index 100% rename from dom/system/tests/ioutils/test_ioutils_read_write_utf8.html rename to xpcom/ioutils/tests/test_ioutils_read_write_utf8.html diff --git a/dom/system/tests/ioutils/test_ioutils_remove.html b/xpcom/ioutils/tests/test_ioutils_remove.html similarity index 100% rename from dom/system/tests/ioutils/test_ioutils_remove.html rename to xpcom/ioutils/tests/test_ioutils_remove.html diff --git a/dom/system/tests/ioutils/test_ioutils_set_permissions.html b/xpcom/ioutils/tests/test_ioutils_set_permissions.html similarity index 100% rename from dom/system/tests/ioutils/test_ioutils_set_permissions.html rename to xpcom/ioutils/tests/test_ioutils_set_permissions.html diff --git a/dom/system/tests/ioutils/test_ioutils_stat_set_modification_time.html b/xpcom/ioutils/tests/test_ioutils_stat_set_modification_time.html similarity index 100% rename from dom/system/tests/ioutils/test_ioutils_stat_set_modification_time.html rename to xpcom/ioutils/tests/test_ioutils_stat_set_modification_time.html diff --git a/dom/system/tests/ioutils/test_ioutils_windows_file_attributes.html b/xpcom/ioutils/tests/test_ioutils_windows_file_attributes.html similarity index 100% rename from dom/system/tests/ioutils/test_ioutils_windows_file_attributes.html rename to xpcom/ioutils/tests/test_ioutils_windows_file_attributes.html diff --git a/dom/system/tests/ioutils/test_ioutils_worker.xhtml b/xpcom/ioutils/tests/test_ioutils_worker.xhtml similarity index 100% rename from dom/system/tests/ioutils/test_ioutils_worker.xhtml rename to xpcom/ioutils/tests/test_ioutils_worker.xhtml diff --git a/dom/system/tests/test_pathutils.html b/xpcom/ioutils/tests/test_pathutils.html similarity index 100% rename from dom/system/tests/test_pathutils.html rename to xpcom/ioutils/tests/test_pathutils.html diff --git a/dom/system/tests/test_pathutils_worker.xhtml b/xpcom/ioutils/tests/test_pathutils_worker.xhtml similarity index 100% rename from dom/system/tests/test_pathutils_worker.xhtml rename to xpcom/ioutils/tests/test_pathutils_worker.xhtml diff --git a/xpcom/moz.build b/xpcom/moz.build index 54c04ad8464e..63df48e9f15a 100644 --- a/xpcom/moz.build +++ b/xpcom/moz.build @@ -27,6 +27,7 @@ DIRS += [ "system", "../chrome", "build", + "ioutils", ] if CONFIG["OS_ARCH"] == "WINNT" and CONFIG["MOZ_DEBUG"]: