dom/indexedDB/IDBFactory.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef mozilla_dom_indexeddb_idbfactory_h__
michael@0 8 #define mozilla_dom_indexeddb_idbfactory_h__
michael@0 9
michael@0 10 #include "mozilla/dom/BindingDeclarations.h" // for Optional
michael@0 11 #include "mozilla/dom/StorageTypeBinding.h"
michael@0 12 #include "mozilla/dom/quota/PersistenceType.h"
michael@0 13 #include "mozilla/dom/quota/StoragePrivilege.h"
michael@0 14 #include "nsCOMPtr.h"
michael@0 15 #include "nsCycleCollectionParticipant.h"
michael@0 16 #include "nsWrapperCache.h"
michael@0 17
michael@0 18 class mozIStorageConnection;
michael@0 19 class nsIFile;
michael@0 20 class nsIFileURL;
michael@0 21 class nsIPrincipal;
michael@0 22 class nsPIDOMWindow;
michael@0 23 template<typename> class nsRefPtr;
michael@0 24
michael@0 25 namespace mozilla {
michael@0 26 class ErrorResult;
michael@0 27
michael@0 28 namespace dom {
michael@0 29 class ContentParent;
michael@0 30 class IDBOpenDBOptions;
michael@0 31
michael@0 32 namespace indexedDB {
michael@0 33
michael@0 34 struct DatabaseInfo;
michael@0 35 class IDBDatabase;
michael@0 36 class IDBOpenDBRequest;
michael@0 37 class IndexedDBChild;
michael@0 38 class IndexedDBParent;
michael@0 39
michael@0 40 struct ObjectStoreInfo;
michael@0 41
michael@0 42 class IDBFactory MOZ_FINAL : public nsISupports,
michael@0 43 public nsWrapperCache
michael@0 44 {
michael@0 45 typedef mozilla::dom::ContentParent ContentParent;
michael@0 46 typedef mozilla::dom::quota::PersistenceType PersistenceType;
michael@0 47 typedef nsTArray<nsRefPtr<ObjectStoreInfo> > ObjectStoreInfoArray;
michael@0 48 typedef mozilla::dom::quota::StoragePrivilege StoragePrivilege;
michael@0 49
michael@0 50 public:
michael@0 51 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
michael@0 52 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBFactory)
michael@0 53
michael@0 54 // Called when using IndexedDB from a window in a different process.
michael@0 55 static nsresult Create(nsPIDOMWindow* aWindow,
michael@0 56 const nsACString& aGroup,
michael@0 57 const nsACString& aASCIIOrigin,
michael@0 58 ContentParent* aContentParent,
michael@0 59 IDBFactory** aFactory);
michael@0 60
michael@0 61 // Called when using IndexedDB from a window in the current process.
michael@0 62 static nsresult Create(nsPIDOMWindow* aWindow,
michael@0 63 ContentParent* aContentParent,
michael@0 64 IDBFactory** aFactory)
michael@0 65 {
michael@0 66 return Create(aWindow, EmptyCString(), EmptyCString(), aContentParent,
michael@0 67 aFactory);
michael@0 68 }
michael@0 69
michael@0 70 // Called when using IndexedDB from a JS component or a JSM in the current
michael@0 71 // process.
michael@0 72 static nsresult Create(JSContext* aCx,
michael@0 73 JS::Handle<JSObject*> aOwningObject,
michael@0 74 ContentParent* aContentParent,
michael@0 75 IDBFactory** aFactory);
michael@0 76
michael@0 77 // Called when using IndexedDB from a JS component or a JSM in a different
michael@0 78 // process.
michael@0 79 static nsresult Create(ContentParent* aContentParent,
michael@0 80 IDBFactory** aFactory);
michael@0 81
michael@0 82 static already_AddRefed<nsIFileURL>
michael@0 83 GetDatabaseFileURL(nsIFile* aDatabaseFile,
michael@0 84 PersistenceType aPersistenceType,
michael@0 85 const nsACString& aGroup,
michael@0 86 const nsACString& aOrigin);
michael@0 87
michael@0 88 static already_AddRefed<mozIStorageConnection>
michael@0 89 GetConnection(const nsAString& aDatabaseFilePath,
michael@0 90 PersistenceType aPersistenceType,
michael@0 91 const nsACString& aGroup,
michael@0 92 const nsACString& aOrigin);
michael@0 93
michael@0 94 static nsresult
michael@0 95 SetDefaultPragmas(mozIStorageConnection* aConnection);
michael@0 96
michael@0 97 static nsresult
michael@0 98 LoadDatabaseInformation(mozIStorageConnection* aConnection,
michael@0 99 const nsACString& aDatabaseId,
michael@0 100 uint64_t* aVersion,
michael@0 101 ObjectStoreInfoArray& aObjectStores);
michael@0 102
michael@0 103 static nsresult
michael@0 104 SetDatabaseMetadata(DatabaseInfo* aDatabaseInfo,
michael@0 105 uint64_t aVersion,
michael@0 106 ObjectStoreInfoArray& aObjectStores);
michael@0 107
michael@0 108 nsresult
michael@0 109 OpenInternal(const nsAString& aName,
michael@0 110 int64_t aVersion,
michael@0 111 PersistenceType aPersistenceType,
michael@0 112 const nsACString& aGroup,
michael@0 113 const nsACString& aASCIIOrigin,
michael@0 114 StoragePrivilege aStoragePrivilege,
michael@0 115 bool aDeleting,
michael@0 116 IDBOpenDBRequest** _retval);
michael@0 117
michael@0 118 nsresult
michael@0 119 OpenInternal(const nsAString& aName,
michael@0 120 int64_t aVersion,
michael@0 121 PersistenceType aPersistenceType,
michael@0 122 bool aDeleting,
michael@0 123 IDBOpenDBRequest** _retval)
michael@0 124 {
michael@0 125 return OpenInternal(aName, aVersion, aPersistenceType, mGroup, mASCIIOrigin,
michael@0 126 mPrivilege, aDeleting, _retval);
michael@0 127 }
michael@0 128
michael@0 129 void
michael@0 130 SetActor(IndexedDBChild* aActorChild)
michael@0 131 {
michael@0 132 NS_ASSERTION(!aActorChild || !mActorChild, "Shouldn't have more than one!");
michael@0 133 mActorChild = aActorChild;
michael@0 134 }
michael@0 135
michael@0 136 void
michael@0 137 SetActor(IndexedDBParent* aActorParent)
michael@0 138 {
michael@0 139 NS_ASSERTION(!aActorParent || !mActorParent, "Shouldn't have more than one!");
michael@0 140 mActorParent = aActorParent;
michael@0 141 }
michael@0 142
michael@0 143 const nsCString&
michael@0 144 GetASCIIOrigin() const
michael@0 145 {
michael@0 146 return mASCIIOrigin;
michael@0 147 }
michael@0 148
michael@0 149 bool
michael@0 150 FromIPC()
michael@0 151 {
michael@0 152 return !!mContentParent;
michael@0 153 }
michael@0 154
michael@0 155 // nsWrapperCache
michael@0 156 virtual JSObject*
michael@0 157 WrapObject(JSContext* aCx) MOZ_OVERRIDE;
michael@0 158
michael@0 159 // WebIDL
michael@0 160 nsPIDOMWindow*
michael@0 161 GetParentObject() const
michael@0 162 {
michael@0 163 return mWindow;
michael@0 164 }
michael@0 165
michael@0 166 already_AddRefed<IDBOpenDBRequest>
michael@0 167 Open(const nsAString& aName, uint64_t aVersion, ErrorResult& aRv)
michael@0 168 {
michael@0 169 return Open(nullptr, aName, Optional<uint64_t>(aVersion),
michael@0 170 Optional<mozilla::dom::StorageType>(), false, aRv);
michael@0 171 }
michael@0 172
michael@0 173 already_AddRefed<IDBOpenDBRequest>
michael@0 174 Open(const nsAString& aName, const IDBOpenDBOptions& aOptions,
michael@0 175 ErrorResult& aRv);
michael@0 176
michael@0 177 already_AddRefed<IDBOpenDBRequest>
michael@0 178 DeleteDatabase(const nsAString& aName, const IDBOpenDBOptions& aOptions,
michael@0 179 ErrorResult& aRv);
michael@0 180
michael@0 181 int16_t
michael@0 182 Cmp(JSContext* aCx, JS::Handle<JS::Value> aFirst,
michael@0 183 JS::Handle<JS::Value> aSecond, ErrorResult& aRv);
michael@0 184
michael@0 185 already_AddRefed<IDBOpenDBRequest>
michael@0 186 OpenForPrincipal(nsIPrincipal* aPrincipal, const nsAString& aName,
michael@0 187 uint64_t aVersion, ErrorResult& aRv);
michael@0 188
michael@0 189 already_AddRefed<IDBOpenDBRequest>
michael@0 190 OpenForPrincipal(nsIPrincipal* aPrincipal, const nsAString& aName,
michael@0 191 const IDBOpenDBOptions& aOptions, ErrorResult& aRv);
michael@0 192
michael@0 193 already_AddRefed<IDBOpenDBRequest>
michael@0 194 DeleteForPrincipal(nsIPrincipal* aPrincipal, const nsAString& aName,
michael@0 195 const IDBOpenDBOptions& aOptions, ErrorResult& aRv);
michael@0 196
michael@0 197 private:
michael@0 198 IDBFactory();
michael@0 199 ~IDBFactory();
michael@0 200
michael@0 201 already_AddRefed<IDBOpenDBRequest>
michael@0 202 Open(nsIPrincipal* aPrincipal, const nsAString& aName,
michael@0 203 const Optional<uint64_t>& aVersion,
michael@0 204 const Optional<mozilla::dom::StorageType>& aStorageType, bool aDelete,
michael@0 205 ErrorResult& aRv);
michael@0 206
michael@0 207 nsCString mGroup;
michael@0 208 nsCString mASCIIOrigin;
michael@0 209 StoragePrivilege mPrivilege;
michael@0 210 PersistenceType mDefaultPersistenceType;
michael@0 211
michael@0 212 // If this factory lives on a window then mWindow must be non-null. Otherwise
michael@0 213 // mOwningObject must be non-null.
michael@0 214 nsCOMPtr<nsPIDOMWindow> mWindow;
michael@0 215 JS::Heap<JSObject*> mOwningObject;
michael@0 216
michael@0 217 IndexedDBChild* mActorChild;
michael@0 218 IndexedDBParent* mActorParent;
michael@0 219
michael@0 220 mozilla::dom::ContentParent* mContentParent;
michael@0 221
michael@0 222 bool mRootedOwningObject;
michael@0 223 };
michael@0 224
michael@0 225 } // namespace indexedDB
michael@0 226 } // namespace dom
michael@0 227 } // namespace mozilla
michael@0 228
michael@0 229 #endif // mozilla_dom_indexeddb_idbfactory_h__

mercurial