dom/file/FileHandle.h

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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 #ifndef mozilla_dom_file_filehandle_h__
michael@0 8 #define mozilla_dom_file_filehandle_h__
michael@0 9
michael@0 10 #include "FileCommon.h"
michael@0 11
michael@0 12 #include "nsIFile.h"
michael@0 13 #include "nsIFileStorage.h"
michael@0 14
michael@0 15 #include "mozilla/Attributes.h"
michael@0 16 #include "mozilla/DOMEventTargetHelper.h"
michael@0 17 #include "mozilla/dom/FileModeBinding.h"
michael@0 18
michael@0 19 class nsIDOMFile;
michael@0 20 class nsIFileStorage;
michael@0 21 class nsPIDOMWindow;
michael@0 22
michael@0 23 namespace mozilla {
michael@0 24 namespace dom {
michael@0 25 class DOMRequest;
michael@0 26 namespace indexedDB {
michael@0 27 class FileInfo;
michael@0 28 } // namespace indexedDB
michael@0 29 } // namespace dom
michael@0 30 } // namespace mozilla
michael@0 31
michael@0 32 BEGIN_FILE_NAMESPACE
michael@0 33
michael@0 34 class FileService;
michael@0 35 class LockedFile;
michael@0 36 class FinishHelper;
michael@0 37 class FileHelper;
michael@0 38
michael@0 39 /**
michael@0 40 * This class provides a default FileHandle implementation, but it can be also
michael@0 41 * subclassed. The subclass can override implementation of GetFileId,
michael@0 42 * GetFileInfo, CreateStream and CreateFileObject.
michael@0 43 * (for example IDBFileHandle provides IndexedDB specific implementation).
michael@0 44 */
michael@0 45 class FileHandle : public DOMEventTargetHelper
michael@0 46 {
michael@0 47 friend class FileService;
michael@0 48 friend class LockedFile;
michael@0 49 friend class FinishHelper;
michael@0 50 friend class FileHelper;
michael@0 51
michael@0 52 public:
michael@0 53 NS_DECL_ISUPPORTS_INHERITED
michael@0 54 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FileHandle, DOMEventTargetHelper)
michael@0 55
michael@0 56 static already_AddRefed<FileHandle>
michael@0 57 Create(nsPIDOMWindow* aWindow,
michael@0 58 nsIFileStorage* aFileStorage,
michael@0 59 nsIFile* aFile);
michael@0 60
michael@0 61 const nsAString&
michael@0 62 Name() const
michael@0 63 {
michael@0 64 return mName;
michael@0 65 }
michael@0 66
michael@0 67 const nsAString&
michael@0 68 Type() const
michael@0 69 {
michael@0 70 return mType;
michael@0 71 }
michael@0 72
michael@0 73 virtual int64_t
michael@0 74 GetFileId()
michael@0 75 {
michael@0 76 return -1;
michael@0 77 }
michael@0 78
michael@0 79 virtual mozilla::dom::indexedDB::FileInfo*
michael@0 80 GetFileInfo()
michael@0 81 {
michael@0 82 return nullptr;
michael@0 83 }
michael@0 84
michael@0 85 virtual already_AddRefed<nsISupports>
michael@0 86 CreateStream(nsIFile* aFile, bool aReadOnly);
michael@0 87
michael@0 88 virtual already_AddRefed<nsIDOMFile>
michael@0 89 CreateFileObject(LockedFile* aLockedFile, uint32_t aFileSize);
michael@0 90
michael@0 91 // nsWrapperCache
michael@0 92 virtual JSObject*
michael@0 93 WrapObject(JSContext* aCx) MOZ_OVERRIDE;
michael@0 94
michael@0 95 // WebIDL
michael@0 96 nsPIDOMWindow*
michael@0 97 GetParentObject() const
michael@0 98 {
michael@0 99 return GetOwner();
michael@0 100 }
michael@0 101
michael@0 102 void
michael@0 103 GetName(nsString& aName) const
michael@0 104 {
michael@0 105 aName = mName;
michael@0 106 }
michael@0 107
michael@0 108 void
michael@0 109 GetType(nsString& aType) const
michael@0 110 {
michael@0 111 aType = mType;
michael@0 112 }
michael@0 113
michael@0 114 already_AddRefed<LockedFile>
michael@0 115 Open(FileMode aMode, ErrorResult& aError);
michael@0 116
michael@0 117 already_AddRefed<DOMRequest>
michael@0 118 GetFile(ErrorResult& aError);
michael@0 119
michael@0 120 IMPL_EVENT_HANDLER(abort)
michael@0 121 IMPL_EVENT_HANDLER(error)
michael@0 122
michael@0 123 protected:
michael@0 124 FileHandle(nsPIDOMWindow* aWindow)
michael@0 125 : DOMEventTargetHelper(aWindow)
michael@0 126 {
michael@0 127 }
michael@0 128
michael@0 129 FileHandle(DOMEventTargetHelper* aOwner)
michael@0 130 : DOMEventTargetHelper(aOwner)
michael@0 131 {
michael@0 132 }
michael@0 133
michael@0 134 ~FileHandle()
michael@0 135 {
michael@0 136 }
michael@0 137
michael@0 138 nsCOMPtr<nsIFileStorage> mFileStorage;
michael@0 139
michael@0 140 nsString mName;
michael@0 141 nsString mType;
michael@0 142
michael@0 143 nsCOMPtr<nsIFile> mFile;
michael@0 144 nsString mFileName;
michael@0 145 };
michael@0 146
michael@0 147 END_FILE_NAMESPACE
michael@0 148
michael@0 149 #endif // mozilla_dom_file_filehandle_h__

mercurial