michael@0: /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "mozilla/dom/FileSystemUtils.h" michael@0: michael@0: #include "nsXULAppAPI.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: // static michael@0: void michael@0: FileSystemUtils::LocalPathToNormalizedPath(const nsAString& aLocal, michael@0: nsAString& aNorm) michael@0: { michael@0: nsString result; michael@0: result = aLocal; michael@0: #if defined(XP_WIN) michael@0: char16_t* cur = result.BeginWriting(); michael@0: char16_t* end = result.EndWriting(); michael@0: for (; cur < end; ++cur) { michael@0: if (char16_t('\\') == *cur) michael@0: *cur = char16_t('/'); michael@0: } michael@0: #endif michael@0: aNorm = result; michael@0: } michael@0: michael@0: // static michael@0: void michael@0: FileSystemUtils::NormalizedPathToLocalPath(const nsAString& aNorm, michael@0: nsAString& aLocal) michael@0: { michael@0: nsString result; michael@0: result = aNorm; michael@0: #if defined(XP_WIN) michael@0: char16_t* cur = result.BeginWriting(); michael@0: char16_t* end = result.EndWriting(); michael@0: for (; cur < end; ++cur) { michael@0: if (char16_t('/') == *cur) michael@0: *cur = char16_t('\\'); michael@0: } michael@0: #endif michael@0: aLocal = result; michael@0: } michael@0: michael@0: // static michael@0: bool michael@0: FileSystemUtils::IsDescendantPath(const nsAString& aPath, michael@0: const nsAString& aDescendantPath) michael@0: { michael@0: // The descendant path should begin with its ancestor path. michael@0: nsAutoString prefix; michael@0: prefix = aPath + NS_LITERAL_STRING(FILESYSTEM_DOM_PATH_SEPARATOR); michael@0: michael@0: // Check the sub-directory path to see if it has the parent path as prefix. michael@0: if (aDescendantPath.Length() < prefix.Length() || michael@0: !StringBeginsWith(aDescendantPath, prefix)) { michael@0: return false; michael@0: } michael@0: michael@0: return true; michael@0: } michael@0: michael@0: // static michael@0: bool michael@0: FileSystemUtils::IsParentProcess() michael@0: { michael@0: return XRE_GetProcessType() == GeckoProcessType_Default; michael@0: } michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla