tor-browser

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

Directory.h (3757B)


      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 #ifndef mozilla_dom_Directory_h
      8 #define mozilla_dom_Directory_h
      9 
     10 #include "mozilla/dom/BindingDeclarations.h"
     11 #include "mozilla/dom/File.h"
     12 #include "nsCycleCollectionParticipant.h"
     13 #include "nsWrapperCache.h"
     14 
     15 namespace mozilla {
     16 class ErrorResult;
     17 
     18 namespace dom {
     19 
     20 class FileSystemBase;
     21 class Promise;
     22 class StringOrFileOrDirectory;
     23 
     24 class Directory final : public nsISupports, public nsWrapperCache {
     25 public:
     26  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     27  NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(Directory)
     28 
     29  static already_AddRefed<Directory> Constructor(const GlobalObject& aGlobal,
     30                                                 const nsAString& aRealPath,
     31                                                 ErrorResult& aRv);
     32 
     33  static already_AddRefed<Directory> Create(nsIGlobalObject* aGlobal,
     34                                            nsIFile* aDirectory,
     35                                            FileSystemBase* aFileSystem = 0);
     36 
     37  // ========= Begin WebIDL bindings. ===========
     38 
     39  nsIGlobalObject* GetParentObject() const;
     40 
     41  virtual JSObject* WrapObject(JSContext* aCx,
     42                               JS::Handle<JSObject*> aGivenProto) override;
     43 
     44  void GetName(nsAString& aRetval, ErrorResult& aRv);
     45 
     46  // From
     47  // https://microsoftedge.github.io/directory-upload/proposal.html#directory-interface
     48  // :
     49 
     50  void GetPath(nsAString& aRetval, ErrorResult& aRv);
     51 
     52  nsresult GetFullRealPath(nsAString& aPath);
     53 
     54  already_AddRefed<Promise> GetFilesAndDirectories(ErrorResult& aRv);
     55 
     56  already_AddRefed<Promise> GetFiles(bool aRecursiveFlag, ErrorResult& aRv);
     57 
     58  // =========== End WebIDL bindings.============
     59 
     60  /**
     61   * Sets a semi-colon separated list of filters to filter-in or filter-out
     62   * certain types of files when the contents of this directory are requested
     63   * via a GetFilesAndDirectories() call.
     64   *
     65   * Currently supported keywords:
     66   *
     67   *   * filter-out-sensitive
     68   *       This keyword filters out files or directories that we don't wish to
     69   *       make available to Web content because we are concerned that there is
     70   *       a risk that users may unwittingly give Web content access to them
     71   *       and suffer undesirable consequences.  The details of what is
     72   *       filtered out can be found in GetDirectoryListingTask::Work.
     73   *
     74   * In future, we will likely support filtering based on filename extensions
     75   * (for example, aFilters could be "*.jpg; *.jpeg; *.gif"), but that isn't
     76   * supported yet.  Once supported, files that don't match a specified
     77   * extension (if any are specified) would be filtered out.  This
     78   * functionality would allow us to apply the 'accept' attribute from
     79   * <input type=file directory accept="..."> to the results of a directory
     80   * picker operation.
     81   */
     82  void SetContentFilters(const nsAString& aFilters);
     83 
     84  FileSystemBase* GetFileSystem(ErrorResult& aRv);
     85 
     86  nsIFile* GetInternalNsIFile() const { return mFile; }
     87 
     88 private:
     89  Directory(nsIGlobalObject* aGlobal, nsIFile* aFile,
     90            FileSystemBase* aFileSystem = nullptr);
     91  ~Directory();
     92 
     93  /*
     94   * Convert relative DOM path to the absolute real path.
     95   */
     96  nsresult DOMPathToRealPath(const nsAString& aPath, nsIFile** aFile) const;
     97 
     98  nsCOMPtr<nsIGlobalObject> mGlobal;
     99  RefPtr<FileSystemBase> mFileSystem;
    100  nsCOMPtr<nsIFile> mFile;
    101 
    102  nsString mFilters;
    103  nsString mPath;
    104 };
    105 
    106 }  // namespace dom
    107 }  // namespace mozilla
    108 
    109 #endif  // mozilla_dom_Directory_h