tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

FileSystemDirectoryEntry.cpp (3235B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "FileSystemDirectoryEntry.h"
      8 
      9 #include "CallbackRunnables.h"
     10 #include "FileSystemDirectoryReader.h"
     11 #include "mozilla/dom/Directory.h"
     12 #include "mozilla/dom/FileSystemDirectoryEntryBinding.h"
     13 #include "mozilla/dom/FileSystemUtils.h"
     14 
     15 namespace mozilla::dom {
     16 
     17 NS_IMPL_CYCLE_COLLECTION_INHERITED(FileSystemDirectoryEntry, FileSystemEntry,
     18                                   mDirectory)
     19 
     20 NS_IMPL_ADDREF_INHERITED(FileSystemDirectoryEntry, FileSystemEntry)
     21 NS_IMPL_RELEASE_INHERITED(FileSystemDirectoryEntry, FileSystemEntry)
     22 
     23 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FileSystemDirectoryEntry)
     24 NS_INTERFACE_MAP_END_INHERITING(FileSystemEntry)
     25 
     26 FileSystemDirectoryEntry::FileSystemDirectoryEntry(
     27    nsIGlobalObject* aGlobal, Directory* aDirectory,
     28    FileSystemDirectoryEntry* aParentEntry, FileSystem* aFileSystem)
     29    : FileSystemEntry(aGlobal, aParentEntry, aFileSystem),
     30      mDirectory(aDirectory) {
     31  MOZ_ASSERT(aGlobal);
     32 }
     33 
     34 FileSystemDirectoryEntry::~FileSystemDirectoryEntry() = default;
     35 
     36 JSObject* FileSystemDirectoryEntry::WrapObject(
     37    JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
     38  return FileSystemDirectoryEntry_Binding::Wrap(aCx, this, aGivenProto);
     39 }
     40 
     41 void FileSystemDirectoryEntry::GetName(nsAString& aName,
     42                                       ErrorResult& aRv) const {
     43  MOZ_ASSERT(mDirectory);
     44  mDirectory->GetName(aName, aRv);
     45 }
     46 
     47 void FileSystemDirectoryEntry::GetFullPath(nsAString& aPath,
     48                                           ErrorResult& aRv) const {
     49  MOZ_ASSERT(mDirectory);
     50  mDirectory->GetPath(aPath, aRv);
     51 }
     52 
     53 already_AddRefed<FileSystemDirectoryReader>
     54 FileSystemDirectoryEntry::CreateReader() {
     55  MOZ_ASSERT(mDirectory);
     56 
     57  RefPtr<FileSystemDirectoryReader> reader =
     58      new FileSystemDirectoryReader(this, Filesystem(), mDirectory);
     59  return reader.forget();
     60 }
     61 
     62 void FileSystemDirectoryEntry::GetInternal(
     63    const nsAString& aPath, const FileSystemFlags& aFlag,
     64    const Optional<OwningNonNull<FileSystemEntryCallback>>& aSuccessCallback,
     65    const Optional<OwningNonNull<ErrorCallback>>& aErrorCallback,
     66    GetInternalType aType) {
     67  MOZ_ASSERT(mDirectory);
     68 
     69  if (!aSuccessCallback.WasPassed() && !aErrorCallback.WasPassed()) {
     70    return;
     71  }
     72 
     73  if (aFlag.mCreate) {
     74    ErrorCallbackHelper::Call(GetParentObject(), aErrorCallback,
     75                              NS_ERROR_DOM_SECURITY_ERR);
     76    return;
     77  }
     78 
     79  nsTArray<nsString> parts;
     80  if (!FileSystemUtils::IsValidRelativeDOMPath(aPath, parts)) {
     81    ErrorCallbackHelper::Call(GetParentObject(), aErrorCallback,
     82                              NS_ERROR_DOM_NOT_FOUND_ERR);
     83    return;
     84  }
     85 
     86  RefPtr<GetEntryHelper> helper = new GetEntryHelper(
     87      this, mDirectory, parts, Filesystem(),
     88      aSuccessCallback.WasPassed() ? &aSuccessCallback.Value() : nullptr,
     89      aErrorCallback.WasPassed() ? &aErrorCallback.Value() : nullptr, aType);
     90  helper->Run();
     91 }
     92 
     93 }  // namespace mozilla::dom