1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/filesystem/FileSystemUtils.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,76 @@ 1.4 +/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#include "mozilla/dom/FileSystemUtils.h" 1.11 + 1.12 +#include "nsXULAppAPI.h" 1.13 + 1.14 +namespace mozilla { 1.15 +namespace dom { 1.16 + 1.17 +// static 1.18 +void 1.19 +FileSystemUtils::LocalPathToNormalizedPath(const nsAString& aLocal, 1.20 + nsAString& aNorm) 1.21 +{ 1.22 + nsString result; 1.23 + result = aLocal; 1.24 +#if defined(XP_WIN) 1.25 + char16_t* cur = result.BeginWriting(); 1.26 + char16_t* end = result.EndWriting(); 1.27 + for (; cur < end; ++cur) { 1.28 + if (char16_t('\\') == *cur) 1.29 + *cur = char16_t('/'); 1.30 + } 1.31 +#endif 1.32 + aNorm = result; 1.33 +} 1.34 + 1.35 +// static 1.36 +void 1.37 +FileSystemUtils::NormalizedPathToLocalPath(const nsAString& aNorm, 1.38 + nsAString& aLocal) 1.39 +{ 1.40 + nsString result; 1.41 + result = aNorm; 1.42 +#if defined(XP_WIN) 1.43 + char16_t* cur = result.BeginWriting(); 1.44 + char16_t* end = result.EndWriting(); 1.45 + for (; cur < end; ++cur) { 1.46 + if (char16_t('/') == *cur) 1.47 + *cur = char16_t('\\'); 1.48 + } 1.49 +#endif 1.50 + aLocal = result; 1.51 +} 1.52 + 1.53 +// static 1.54 +bool 1.55 +FileSystemUtils::IsDescendantPath(const nsAString& aPath, 1.56 + const nsAString& aDescendantPath) 1.57 +{ 1.58 + // The descendant path should begin with its ancestor path. 1.59 + nsAutoString prefix; 1.60 + prefix = aPath + NS_LITERAL_STRING(FILESYSTEM_DOM_PATH_SEPARATOR); 1.61 + 1.62 + // Check the sub-directory path to see if it has the parent path as prefix. 1.63 + if (aDescendantPath.Length() < prefix.Length() || 1.64 + !StringBeginsWith(aDescendantPath, prefix)) { 1.65 + return false; 1.66 + } 1.67 + 1.68 + return true; 1.69 +} 1.70 + 1.71 +// static 1.72 +bool 1.73 +FileSystemUtils::IsParentProcess() 1.74 +{ 1.75 + return XRE_GetProcessType() == GeckoProcessType_Default; 1.76 +} 1.77 + 1.78 +} // namespace dom 1.79 +} // namespace mozilla