michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_indexeddb_idbfactory_h__ michael@0: #define mozilla_dom_indexeddb_idbfactory_h__ michael@0: michael@0: #include "mozilla/dom/BindingDeclarations.h" // for Optional michael@0: #include "mozilla/dom/StorageTypeBinding.h" michael@0: #include "mozilla/dom/quota/PersistenceType.h" michael@0: #include "mozilla/dom/quota/StoragePrivilege.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsCycleCollectionParticipant.h" michael@0: #include "nsWrapperCache.h" michael@0: michael@0: class mozIStorageConnection; michael@0: class nsIFile; michael@0: class nsIFileURL; michael@0: class nsIPrincipal; michael@0: class nsPIDOMWindow; michael@0: template class nsRefPtr; michael@0: michael@0: namespace mozilla { michael@0: class ErrorResult; michael@0: michael@0: namespace dom { michael@0: class ContentParent; michael@0: class IDBOpenDBOptions; michael@0: michael@0: namespace indexedDB { michael@0: michael@0: struct DatabaseInfo; michael@0: class IDBDatabase; michael@0: class IDBOpenDBRequest; michael@0: class IndexedDBChild; michael@0: class IndexedDBParent; michael@0: michael@0: struct ObjectStoreInfo; michael@0: michael@0: class IDBFactory MOZ_FINAL : public nsISupports, michael@0: public nsWrapperCache michael@0: { michael@0: typedef mozilla::dom::ContentParent ContentParent; michael@0: typedef mozilla::dom::quota::PersistenceType PersistenceType; michael@0: typedef nsTArray > ObjectStoreInfoArray; michael@0: typedef mozilla::dom::quota::StoragePrivilege StoragePrivilege; michael@0: michael@0: public: michael@0: NS_DECL_CYCLE_COLLECTING_ISUPPORTS michael@0: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBFactory) michael@0: michael@0: // Called when using IndexedDB from a window in a different process. michael@0: static nsresult Create(nsPIDOMWindow* aWindow, michael@0: const nsACString& aGroup, michael@0: const nsACString& aASCIIOrigin, michael@0: ContentParent* aContentParent, michael@0: IDBFactory** aFactory); michael@0: michael@0: // Called when using IndexedDB from a window in the current process. michael@0: static nsresult Create(nsPIDOMWindow* aWindow, michael@0: ContentParent* aContentParent, michael@0: IDBFactory** aFactory) michael@0: { michael@0: return Create(aWindow, EmptyCString(), EmptyCString(), aContentParent, michael@0: aFactory); michael@0: } michael@0: michael@0: // Called when using IndexedDB from a JS component or a JSM in the current michael@0: // process. michael@0: static nsresult Create(JSContext* aCx, michael@0: JS::Handle aOwningObject, michael@0: ContentParent* aContentParent, michael@0: IDBFactory** aFactory); michael@0: michael@0: // Called when using IndexedDB from a JS component or a JSM in a different michael@0: // process. michael@0: static nsresult Create(ContentParent* aContentParent, michael@0: IDBFactory** aFactory); michael@0: michael@0: static already_AddRefed michael@0: GetDatabaseFileURL(nsIFile* aDatabaseFile, michael@0: PersistenceType aPersistenceType, michael@0: const nsACString& aGroup, michael@0: const nsACString& aOrigin); michael@0: michael@0: static already_AddRefed michael@0: GetConnection(const nsAString& aDatabaseFilePath, michael@0: PersistenceType aPersistenceType, michael@0: const nsACString& aGroup, michael@0: const nsACString& aOrigin); michael@0: michael@0: static nsresult michael@0: SetDefaultPragmas(mozIStorageConnection* aConnection); michael@0: michael@0: static nsresult michael@0: LoadDatabaseInformation(mozIStorageConnection* aConnection, michael@0: const nsACString& aDatabaseId, michael@0: uint64_t* aVersion, michael@0: ObjectStoreInfoArray& aObjectStores); michael@0: michael@0: static nsresult michael@0: SetDatabaseMetadata(DatabaseInfo* aDatabaseInfo, michael@0: uint64_t aVersion, michael@0: ObjectStoreInfoArray& aObjectStores); michael@0: michael@0: nsresult michael@0: OpenInternal(const nsAString& aName, michael@0: int64_t aVersion, michael@0: PersistenceType aPersistenceType, michael@0: const nsACString& aGroup, michael@0: const nsACString& aASCIIOrigin, michael@0: StoragePrivilege aStoragePrivilege, michael@0: bool aDeleting, michael@0: IDBOpenDBRequest** _retval); michael@0: michael@0: nsresult michael@0: OpenInternal(const nsAString& aName, michael@0: int64_t aVersion, michael@0: PersistenceType aPersistenceType, michael@0: bool aDeleting, michael@0: IDBOpenDBRequest** _retval) michael@0: { michael@0: return OpenInternal(aName, aVersion, aPersistenceType, mGroup, mASCIIOrigin, michael@0: mPrivilege, aDeleting, _retval); michael@0: } michael@0: michael@0: void michael@0: SetActor(IndexedDBChild* aActorChild) michael@0: { michael@0: NS_ASSERTION(!aActorChild || !mActorChild, "Shouldn't have more than one!"); michael@0: mActorChild = aActorChild; michael@0: } michael@0: michael@0: void michael@0: SetActor(IndexedDBParent* aActorParent) michael@0: { michael@0: NS_ASSERTION(!aActorParent || !mActorParent, "Shouldn't have more than one!"); michael@0: mActorParent = aActorParent; michael@0: } michael@0: michael@0: const nsCString& michael@0: GetASCIIOrigin() const michael@0: { michael@0: return mASCIIOrigin; michael@0: } michael@0: michael@0: bool michael@0: FromIPC() michael@0: { michael@0: return !!mContentParent; michael@0: } michael@0: michael@0: // nsWrapperCache michael@0: virtual JSObject* michael@0: WrapObject(JSContext* aCx) MOZ_OVERRIDE; michael@0: michael@0: // WebIDL michael@0: nsPIDOMWindow* michael@0: GetParentObject() const michael@0: { michael@0: return mWindow; michael@0: } michael@0: michael@0: already_AddRefed michael@0: Open(const nsAString& aName, uint64_t aVersion, ErrorResult& aRv) michael@0: { michael@0: return Open(nullptr, aName, Optional(aVersion), michael@0: Optional(), false, aRv); michael@0: } michael@0: michael@0: already_AddRefed michael@0: Open(const nsAString& aName, const IDBOpenDBOptions& aOptions, michael@0: ErrorResult& aRv); michael@0: michael@0: already_AddRefed michael@0: DeleteDatabase(const nsAString& aName, const IDBOpenDBOptions& aOptions, michael@0: ErrorResult& aRv); michael@0: michael@0: int16_t michael@0: Cmp(JSContext* aCx, JS::Handle aFirst, michael@0: JS::Handle aSecond, ErrorResult& aRv); michael@0: michael@0: already_AddRefed michael@0: OpenForPrincipal(nsIPrincipal* aPrincipal, const nsAString& aName, michael@0: uint64_t aVersion, ErrorResult& aRv); michael@0: michael@0: already_AddRefed michael@0: OpenForPrincipal(nsIPrincipal* aPrincipal, const nsAString& aName, michael@0: const IDBOpenDBOptions& aOptions, ErrorResult& aRv); michael@0: michael@0: already_AddRefed michael@0: DeleteForPrincipal(nsIPrincipal* aPrincipal, const nsAString& aName, michael@0: const IDBOpenDBOptions& aOptions, ErrorResult& aRv); michael@0: michael@0: private: michael@0: IDBFactory(); michael@0: ~IDBFactory(); michael@0: michael@0: already_AddRefed michael@0: Open(nsIPrincipal* aPrincipal, const nsAString& aName, michael@0: const Optional& aVersion, michael@0: const Optional& aStorageType, bool aDelete, michael@0: ErrorResult& aRv); michael@0: michael@0: nsCString mGroup; michael@0: nsCString mASCIIOrigin; michael@0: StoragePrivilege mPrivilege; michael@0: PersistenceType mDefaultPersistenceType; michael@0: michael@0: // If this factory lives on a window then mWindow must be non-null. Otherwise michael@0: // mOwningObject must be non-null. michael@0: nsCOMPtr mWindow; michael@0: JS::Heap mOwningObject; michael@0: michael@0: IndexedDBChild* mActorChild; michael@0: IndexedDBParent* mActorParent; michael@0: michael@0: mozilla::dom::ContentParent* mContentParent; michael@0: michael@0: bool mRootedOwningObject; michael@0: }; michael@0: michael@0: } // namespace indexedDB michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla_dom_indexeddb_idbfactory_h__