Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ |
michael@0 | 2 | /* vim: set ts=2 et sw=2 tw=80: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 5 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #include "mozilla/dom/FileSystemUtils.h" |
michael@0 | 8 | |
michael@0 | 9 | #include "nsXULAppAPI.h" |
michael@0 | 10 | |
michael@0 | 11 | namespace mozilla { |
michael@0 | 12 | namespace dom { |
michael@0 | 13 | |
michael@0 | 14 | // static |
michael@0 | 15 | void |
michael@0 | 16 | FileSystemUtils::LocalPathToNormalizedPath(const nsAString& aLocal, |
michael@0 | 17 | nsAString& aNorm) |
michael@0 | 18 | { |
michael@0 | 19 | nsString result; |
michael@0 | 20 | result = aLocal; |
michael@0 | 21 | #if defined(XP_WIN) |
michael@0 | 22 | char16_t* cur = result.BeginWriting(); |
michael@0 | 23 | char16_t* end = result.EndWriting(); |
michael@0 | 24 | for (; cur < end; ++cur) { |
michael@0 | 25 | if (char16_t('\\') == *cur) |
michael@0 | 26 | *cur = char16_t('/'); |
michael@0 | 27 | } |
michael@0 | 28 | #endif |
michael@0 | 29 | aNorm = result; |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | // static |
michael@0 | 33 | void |
michael@0 | 34 | FileSystemUtils::NormalizedPathToLocalPath(const nsAString& aNorm, |
michael@0 | 35 | nsAString& aLocal) |
michael@0 | 36 | { |
michael@0 | 37 | nsString result; |
michael@0 | 38 | result = aNorm; |
michael@0 | 39 | #if defined(XP_WIN) |
michael@0 | 40 | char16_t* cur = result.BeginWriting(); |
michael@0 | 41 | char16_t* end = result.EndWriting(); |
michael@0 | 42 | for (; cur < end; ++cur) { |
michael@0 | 43 | if (char16_t('/') == *cur) |
michael@0 | 44 | *cur = char16_t('\\'); |
michael@0 | 45 | } |
michael@0 | 46 | #endif |
michael@0 | 47 | aLocal = result; |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | // static |
michael@0 | 51 | bool |
michael@0 | 52 | FileSystemUtils::IsDescendantPath(const nsAString& aPath, |
michael@0 | 53 | const nsAString& aDescendantPath) |
michael@0 | 54 | { |
michael@0 | 55 | // The descendant path should begin with its ancestor path. |
michael@0 | 56 | nsAutoString prefix; |
michael@0 | 57 | prefix = aPath + NS_LITERAL_STRING(FILESYSTEM_DOM_PATH_SEPARATOR); |
michael@0 | 58 | |
michael@0 | 59 | // Check the sub-directory path to see if it has the parent path as prefix. |
michael@0 | 60 | if (aDescendantPath.Length() < prefix.Length() || |
michael@0 | 61 | !StringBeginsWith(aDescendantPath, prefix)) { |
michael@0 | 62 | return false; |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | return true; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | // static |
michael@0 | 69 | bool |
michael@0 | 70 | FileSystemUtils::IsParentProcess() |
michael@0 | 71 | { |
michael@0 | 72 | return XRE_GetProcessType() == GeckoProcessType_Default; |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | } // namespace dom |
michael@0 | 76 | } // namespace mozilla |