dom/indexedDB/IDBFactory.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/indexedDB/IDBFactory.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,229 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set ts=2 et sw=2 tw=80: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef mozilla_dom_indexeddb_idbfactory_h__
    1.11 +#define mozilla_dom_indexeddb_idbfactory_h__
    1.12 +
    1.13 +#include "mozilla/dom/BindingDeclarations.h" // for Optional
    1.14 +#include "mozilla/dom/StorageTypeBinding.h"
    1.15 +#include "mozilla/dom/quota/PersistenceType.h"
    1.16 +#include "mozilla/dom/quota/StoragePrivilege.h"
    1.17 +#include "nsCOMPtr.h"
    1.18 +#include "nsCycleCollectionParticipant.h"
    1.19 +#include "nsWrapperCache.h"
    1.20 +
    1.21 +class mozIStorageConnection;
    1.22 +class nsIFile;
    1.23 +class nsIFileURL;
    1.24 +class nsIPrincipal;
    1.25 +class nsPIDOMWindow;
    1.26 +template<typename> class nsRefPtr;
    1.27 +
    1.28 +namespace mozilla {
    1.29 +class ErrorResult;
    1.30 +
    1.31 +namespace dom {
    1.32 +class ContentParent;
    1.33 +class IDBOpenDBOptions;
    1.34 +
    1.35 +namespace indexedDB {
    1.36 +
    1.37 +struct DatabaseInfo;
    1.38 +class IDBDatabase;
    1.39 +class IDBOpenDBRequest;
    1.40 +class IndexedDBChild;
    1.41 +class IndexedDBParent;
    1.42 +
    1.43 +struct ObjectStoreInfo;
    1.44 +
    1.45 +class IDBFactory MOZ_FINAL : public nsISupports,
    1.46 +                             public nsWrapperCache
    1.47 +{
    1.48 +  typedef mozilla::dom::ContentParent ContentParent;
    1.49 +  typedef mozilla::dom::quota::PersistenceType PersistenceType;
    1.50 +  typedef nsTArray<nsRefPtr<ObjectStoreInfo> > ObjectStoreInfoArray;
    1.51 +  typedef mozilla::dom::quota::StoragePrivilege StoragePrivilege;
    1.52 +
    1.53 +public:
    1.54 +  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
    1.55 +  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBFactory)
    1.56 +
    1.57 +  // Called when using IndexedDB from a window in a different process.
    1.58 +  static nsresult Create(nsPIDOMWindow* aWindow,
    1.59 +                         const nsACString& aGroup,
    1.60 +                         const nsACString& aASCIIOrigin,
    1.61 +                         ContentParent* aContentParent,
    1.62 +                         IDBFactory** aFactory);
    1.63 +
    1.64 +  // Called when using IndexedDB from a window in the current process.
    1.65 +  static nsresult Create(nsPIDOMWindow* aWindow,
    1.66 +                         ContentParent* aContentParent,
    1.67 +                         IDBFactory** aFactory)
    1.68 +  {
    1.69 +    return Create(aWindow, EmptyCString(), EmptyCString(), aContentParent,
    1.70 +                  aFactory);
    1.71 +  }
    1.72 +
    1.73 +  // Called when using IndexedDB from a JS component or a JSM in the current
    1.74 +  // process.
    1.75 +  static nsresult Create(JSContext* aCx,
    1.76 +                         JS::Handle<JSObject*> aOwningObject,
    1.77 +                         ContentParent* aContentParent,
    1.78 +                         IDBFactory** aFactory);
    1.79 +
    1.80 +  // Called when using IndexedDB from a JS component or a JSM in a different
    1.81 +  // process.
    1.82 +  static nsresult Create(ContentParent* aContentParent,
    1.83 +                         IDBFactory** aFactory);
    1.84 +
    1.85 +  static already_AddRefed<nsIFileURL>
    1.86 +  GetDatabaseFileURL(nsIFile* aDatabaseFile,
    1.87 +                     PersistenceType aPersistenceType,
    1.88 +                     const nsACString& aGroup,
    1.89 +                     const nsACString& aOrigin);
    1.90 +
    1.91 +  static already_AddRefed<mozIStorageConnection>
    1.92 +  GetConnection(const nsAString& aDatabaseFilePath,
    1.93 +                PersistenceType aPersistenceType,
    1.94 +                const nsACString& aGroup,
    1.95 +                const nsACString& aOrigin);
    1.96 +
    1.97 +  static nsresult
    1.98 +  SetDefaultPragmas(mozIStorageConnection* aConnection);
    1.99 +
   1.100 +  static nsresult
   1.101 +  LoadDatabaseInformation(mozIStorageConnection* aConnection,
   1.102 +                          const nsACString& aDatabaseId,
   1.103 +                          uint64_t* aVersion,
   1.104 +                          ObjectStoreInfoArray& aObjectStores);
   1.105 +
   1.106 +  static nsresult
   1.107 +  SetDatabaseMetadata(DatabaseInfo* aDatabaseInfo,
   1.108 +                      uint64_t aVersion,
   1.109 +                      ObjectStoreInfoArray& aObjectStores);
   1.110 +
   1.111 +  nsresult
   1.112 +  OpenInternal(const nsAString& aName,
   1.113 +               int64_t aVersion,
   1.114 +               PersistenceType aPersistenceType,
   1.115 +               const nsACString& aGroup,
   1.116 +               const nsACString& aASCIIOrigin,
   1.117 +               StoragePrivilege aStoragePrivilege,
   1.118 +               bool aDeleting,
   1.119 +               IDBOpenDBRequest** _retval);
   1.120 +
   1.121 +  nsresult
   1.122 +  OpenInternal(const nsAString& aName,
   1.123 +               int64_t aVersion,
   1.124 +               PersistenceType aPersistenceType,
   1.125 +               bool aDeleting,
   1.126 +               IDBOpenDBRequest** _retval)
   1.127 +  {
   1.128 +    return OpenInternal(aName, aVersion, aPersistenceType, mGroup, mASCIIOrigin,
   1.129 +                        mPrivilege, aDeleting, _retval);
   1.130 +  }
   1.131 +
   1.132 +  void
   1.133 +  SetActor(IndexedDBChild* aActorChild)
   1.134 +  {
   1.135 +    NS_ASSERTION(!aActorChild || !mActorChild, "Shouldn't have more than one!");
   1.136 +    mActorChild = aActorChild;
   1.137 +  }
   1.138 +
   1.139 +  void
   1.140 +  SetActor(IndexedDBParent* aActorParent)
   1.141 +  {
   1.142 +    NS_ASSERTION(!aActorParent || !mActorParent, "Shouldn't have more than one!");
   1.143 +    mActorParent = aActorParent;
   1.144 +  }
   1.145 +
   1.146 +  const nsCString&
   1.147 +  GetASCIIOrigin() const
   1.148 +  {
   1.149 +    return mASCIIOrigin;
   1.150 +  }
   1.151 +
   1.152 +  bool
   1.153 +  FromIPC()
   1.154 +  {
   1.155 +    return !!mContentParent;
   1.156 +  }
   1.157 +
   1.158 +  // nsWrapperCache
   1.159 +  virtual JSObject*
   1.160 +  WrapObject(JSContext* aCx) MOZ_OVERRIDE;
   1.161 +
   1.162 +  // WebIDL
   1.163 +  nsPIDOMWindow*
   1.164 +  GetParentObject() const
   1.165 +  {
   1.166 +    return mWindow;
   1.167 +  }
   1.168 +
   1.169 +  already_AddRefed<IDBOpenDBRequest>
   1.170 +  Open(const nsAString& aName, uint64_t aVersion, ErrorResult& aRv)
   1.171 +  {
   1.172 +    return Open(nullptr, aName, Optional<uint64_t>(aVersion),
   1.173 +                Optional<mozilla::dom::StorageType>(), false, aRv);
   1.174 +  }
   1.175 +
   1.176 +  already_AddRefed<IDBOpenDBRequest>
   1.177 +  Open(const nsAString& aName, const IDBOpenDBOptions& aOptions,
   1.178 +       ErrorResult& aRv);
   1.179 +
   1.180 +  already_AddRefed<IDBOpenDBRequest>
   1.181 +  DeleteDatabase(const nsAString& aName, const IDBOpenDBOptions& aOptions,
   1.182 +                 ErrorResult& aRv);
   1.183 +
   1.184 +  int16_t
   1.185 +  Cmp(JSContext* aCx, JS::Handle<JS::Value> aFirst,
   1.186 +      JS::Handle<JS::Value> aSecond, ErrorResult& aRv);
   1.187 +
   1.188 +  already_AddRefed<IDBOpenDBRequest>
   1.189 +  OpenForPrincipal(nsIPrincipal* aPrincipal, const nsAString& aName,
   1.190 +                   uint64_t aVersion, ErrorResult& aRv);
   1.191 +
   1.192 +  already_AddRefed<IDBOpenDBRequest>
   1.193 +  OpenForPrincipal(nsIPrincipal* aPrincipal, const nsAString& aName,
   1.194 +                   const IDBOpenDBOptions& aOptions, ErrorResult& aRv);
   1.195 +
   1.196 +  already_AddRefed<IDBOpenDBRequest>
   1.197 +  DeleteForPrincipal(nsIPrincipal* aPrincipal, const nsAString& aName,
   1.198 +                     const IDBOpenDBOptions& aOptions, ErrorResult& aRv);
   1.199 +
   1.200 +private:
   1.201 +  IDBFactory();
   1.202 +  ~IDBFactory();
   1.203 +
   1.204 +  already_AddRefed<IDBOpenDBRequest>
   1.205 +  Open(nsIPrincipal* aPrincipal, const nsAString& aName,
   1.206 +       const Optional<uint64_t>& aVersion,
   1.207 +       const Optional<mozilla::dom::StorageType>& aStorageType, bool aDelete,
   1.208 +       ErrorResult& aRv);
   1.209 +
   1.210 +  nsCString mGroup;
   1.211 +  nsCString mASCIIOrigin;
   1.212 +  StoragePrivilege mPrivilege;
   1.213 +  PersistenceType mDefaultPersistenceType;
   1.214 +
   1.215 +  // If this factory lives on a window then mWindow must be non-null. Otherwise
   1.216 +  // mOwningObject must be non-null.
   1.217 +  nsCOMPtr<nsPIDOMWindow> mWindow;
   1.218 +  JS::Heap<JSObject*> mOwningObject;
   1.219 +
   1.220 +  IndexedDBChild* mActorChild;
   1.221 +  IndexedDBParent* mActorParent;
   1.222 +
   1.223 +  mozilla::dom::ContentParent* mContentParent;
   1.224 +
   1.225 +  bool mRootedOwningObject;
   1.226 +};
   1.227 +
   1.228 +} // namespace indexedDB
   1.229 +} // namespace dom
   1.230 +} // namespace mozilla
   1.231 +
   1.232 +#endif // mozilla_dom_indexeddb_idbfactory_h__

mercurial