LCOV - code coverage report
Current view: top level - dom/indexedDB - IDBFactory.h (source / functions) Hit Total Coverage
Test: output.info Lines: 6 22 27.3 %
Date: 2017-07-14 16:53:18 Functions: 6 14 42.9 %
Legend: Lines: hit not hit

          Line data    Source code
       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
       5             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : #ifndef mozilla_dom_idbfactory_h__
       8             : #define mozilla_dom_idbfactory_h__
       9             : 
      10             : #include "mozilla/Attributes.h"
      11             : #include "mozilla/dom/BindingDeclarations.h"
      12             : #include "mozilla/dom/StorageTypeBinding.h"
      13             : #include "nsAutoPtr.h"
      14             : #include "nsCOMPtr.h"
      15             : #include "nsCycleCollectionParticipant.h"
      16             : #include "nsISupports.h"
      17             : #include "nsString.h"
      18             : #include "nsTArray.h"
      19             : #include "nsWrapperCache.h"
      20             : 
      21             : class nsIEventTarget;
      22             : class nsIPrincipal;
      23             : class nsPIDOMWindowInner;
      24             : 
      25             : namespace mozilla {
      26             : 
      27             : class ErrorResult;
      28             : 
      29             : namespace ipc {
      30             : 
      31             : class PBackgroundChild;
      32             : class PrincipalInfo;
      33             : 
      34             : } // namespace ipc
      35             : 
      36             : namespace dom {
      37             : 
      38             : struct IDBOpenDBOptions;
      39             : class IDBOpenDBRequest;
      40             : template <typename> class Optional;
      41             : class TabChild;
      42             : enum class CallerType : uint32_t;
      43             : 
      44             : namespace indexedDB {
      45             : class BackgroundFactoryChild;
      46             : class FactoryRequestParams;
      47             : class LoggingInfo;
      48             : }
      49             : 
      50             : class IDBFactory final
      51             :   : public nsISupports
      52             :   , public nsWrapperCache
      53             : {
      54             :   typedef mozilla::dom::StorageType StorageType;
      55             :   typedef mozilla::ipc::PBackgroundChild PBackgroundChild;
      56             :   typedef mozilla::ipc::PrincipalInfo PrincipalInfo;
      57             : 
      58             :   class BackgroundCreateCallback;
      59             :   struct PendingRequestInfo;
      60             : 
      61             :   nsAutoPtr<PrincipalInfo> mPrincipalInfo;
      62             : 
      63             :   // If this factory lives on a window then mWindow must be non-null. Otherwise
      64             :   // mOwningObject must be non-null.
      65             :   nsCOMPtr<nsPIDOMWindowInner> mWindow;
      66             :   JS::Heap<JSObject*> mOwningObject;
      67             : 
      68             :   // This will only be set if the factory belongs to a window in a child
      69             :   // process.
      70             :   RefPtr<TabChild> mTabChild;
      71             : 
      72             :   nsTArray<nsAutoPtr<PendingRequestInfo>> mPendingRequests;
      73             : 
      74             :   indexedDB::BackgroundFactoryChild* mBackgroundActor;
      75             : 
      76             :   // A DocGroup-specific EventTarget if created by CreateForWindow().
      77             :   // Otherwise, it must either be set to SystemGroup on main thread or
      78             :   // NS_GetCurrentThread() off main thread.
      79             :   nsCOMPtr<nsIEventTarget> mEventTarget;
      80             : 
      81             :   uint64_t mInnerWindowID;
      82             : 
      83             :   bool mBackgroundActorFailed;
      84             :   bool mPrivateBrowsingMode;
      85             : 
      86             : public:
      87             :   static nsresult
      88             :   CreateForWindow(nsPIDOMWindowInner* aWindow,
      89             :                   IDBFactory** aFactory);
      90             : 
      91             :   static nsresult
      92             :   CreateForMainThreadJS(JSContext* aCx,
      93             :                         JS::Handle<JSObject*> aOwningObject,
      94             :                         IDBFactory** aFactory);
      95             : 
      96             :   static nsresult
      97             :   CreateForWorker(JSContext* aCx,
      98             :                   JS::Handle<JSObject*> aOwningObject,
      99             :                   const PrincipalInfo& aPrincipalInfo,
     100             :                   uint64_t aInnerWindowID,
     101             :                   IDBFactory** aFactory);
     102             : 
     103             :   static bool
     104             :   AllowedForWindow(nsPIDOMWindowInner* aWindow);
     105             : 
     106             :   static bool
     107             :   AllowedForPrincipal(nsIPrincipal* aPrincipal,
     108             :                       bool* aIsSystemPrincipal = nullptr);
     109             : 
     110             :   void
     111          14 :   AssertIsOnOwningThread() const
     112             :   {
     113          14 :     NS_ASSERT_OWNINGTHREAD(IDBFactory);
     114          14 :   }
     115             : 
     116             :   nsIEventTarget*
     117           0 :   EventTarget() const
     118             :   {
     119           0 :     AssertIsOnOwningThread();
     120           0 :     MOZ_RELEASE_ASSERT(mEventTarget);
     121           0 :     return mEventTarget;
     122             :   }
     123             : 
     124             :   void
     125           0 :   ClearBackgroundActor()
     126             :   {
     127           0 :     AssertIsOnOwningThread();
     128             : 
     129           0 :     mBackgroundActor = nullptr;
     130           0 :   }
     131             : 
     132             :   // Increase/Decrease the number of active transactions for the decision
     133             :   // making of preemption and throttling.
     134             :   // Note: If the state of its actor is not committed or aborted, it could block
     135             :   // IDB operations in other window.
     136             :   void
     137             :   UpdateActiveTransactionCount(int32_t aDelta);
     138             : 
     139             :   // Increase/Decrease the number of active databases and IDBOpenRequests for
     140             :   // the decision making of preemption and throttling.
     141             :   // Note: A non-closed database or a pending IDBOpenRequest could block
     142             :   // IDB operations in other window.
     143             :   void
     144             :   UpdateActiveDatabaseCount(int32_t aDelta);
     145             : 
     146             :   void
     147             :   IncrementParentLoggingRequestSerialNumber();
     148             : 
     149             :   nsPIDOMWindowInner*
     150          14 :   GetParentObject() const
     151             :   {
     152          14 :     return mWindow;
     153             :   }
     154             : 
     155             :   TabChild*
     156           0 :   GetTabChild() const
     157             :   {
     158           0 :     return mTabChild;
     159             :   }
     160             : 
     161             :   PrincipalInfo*
     162           0 :   GetPrincipalInfo() const
     163             :   {
     164           0 :     AssertIsOnOwningThread();
     165             : 
     166           0 :     return mPrincipalInfo;
     167             :   }
     168             : 
     169             :   uint64_t
     170           0 :   InnerWindowID() const
     171             :   {
     172           0 :     AssertIsOnOwningThread();
     173             : 
     174           0 :     return mInnerWindowID;
     175             :   }
     176             : 
     177             :   bool
     178             :   IsChrome() const;
     179             : 
     180             :   already_AddRefed<IDBOpenDBRequest>
     181             :   Open(JSContext* aCx,
     182             :        const nsAString& aName,
     183             :        uint64_t aVersion,
     184             :        CallerType aCallerType,
     185             :        ErrorResult& aRv);
     186             : 
     187             :   already_AddRefed<IDBOpenDBRequest>
     188             :   Open(JSContext* aCx,
     189             :        const nsAString& aName,
     190             :        const IDBOpenDBOptions& aOptions,
     191             :        CallerType aCallerType,
     192             :        ErrorResult& aRv);
     193             : 
     194             :   already_AddRefed<IDBOpenDBRequest>
     195             :   DeleteDatabase(JSContext* aCx,
     196             :                  const nsAString& aName,
     197             :                  const IDBOpenDBOptions& aOptions,
     198             :                  CallerType aCallerType,
     199             :                  ErrorResult& aRv);
     200             : 
     201             :   int16_t
     202             :   Cmp(JSContext* aCx,
     203             :       JS::Handle<JS::Value> aFirst,
     204             :       JS::Handle<JS::Value> aSecond,
     205             :       ErrorResult& aRv);
     206             : 
     207             :   already_AddRefed<IDBOpenDBRequest>
     208             :   OpenForPrincipal(JSContext* aCx,
     209             :                    nsIPrincipal* aPrincipal,
     210             :                    const nsAString& aName,
     211             :                    uint64_t aVersion,
     212             :                    SystemCallerGuarantee,
     213             :                    ErrorResult& aRv);
     214             : 
     215             :   already_AddRefed<IDBOpenDBRequest>
     216             :   OpenForPrincipal(JSContext* aCx,
     217             :                    nsIPrincipal* aPrincipal,
     218             :                    const nsAString& aName,
     219             :                    const IDBOpenDBOptions& aOptions,
     220             :                    SystemCallerGuarantee,
     221             :                    ErrorResult& aRv);
     222             : 
     223             :   already_AddRefed<IDBOpenDBRequest>
     224             :   DeleteForPrincipal(JSContext* aCx,
     225             :                      nsIPrincipal* aPrincipal,
     226             :                      const nsAString& aName,
     227             :                      const IDBOpenDBOptions& aOptions,
     228             :                      SystemCallerGuarantee,
     229             :                      ErrorResult& aRv);
     230             : 
     231             :   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     232         366 :   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBFactory)
     233             : 
     234             :   // nsWrapperCache
     235             :   virtual JSObject*
     236             :   WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
     237             : 
     238             : private:
     239             :   IDBFactory();
     240             :   ~IDBFactory();
     241             : 
     242             :   static nsresult
     243             :   CreateForMainThreadJSInternal(JSContext* aCx,
     244             :                                 JS::Handle<JSObject*> aOwningObject,
     245             :                                 nsAutoPtr<PrincipalInfo>& aPrincipalInfo,
     246             :                                 IDBFactory** aFactory);
     247             : 
     248             :   static nsresult
     249             :   CreateForJSInternal(JSContext* aCx,
     250             :                       JS::Handle<JSObject*> aOwningObject,
     251             :                       nsAutoPtr<PrincipalInfo>& aPrincipalInfo,
     252             :                       uint64_t aInnerWindowID,
     253             :                       IDBFactory** aFactory);
     254             : 
     255             :   static nsresult
     256             :   AllowedForWindowInternal(nsPIDOMWindowInner* aWindow,
     257             :                            nsIPrincipal** aPrincipal);
     258             : 
     259             :   already_AddRefed<IDBOpenDBRequest>
     260             :   OpenInternal(JSContext* aCx,
     261             :                nsIPrincipal* aPrincipal,
     262             :                const nsAString& aName,
     263             :                const Optional<uint64_t>& aVersion,
     264             :                const Optional<StorageType>& aStorageType,
     265             :                bool aDeleting,
     266             :                CallerType aCallerType,
     267             :                ErrorResult& aRv);
     268             : 
     269             :   nsresult
     270             :   BackgroundActorCreated(PBackgroundChild* aBackgroundActor,
     271             :                          const indexedDB::LoggingInfo& aLoggingInfo);
     272             : 
     273             :   void
     274             :   BackgroundActorFailed();
     275             : 
     276             :   nsresult
     277             :   InitiateRequest(IDBOpenDBRequest* aRequest,
     278             :                   const indexedDB::FactoryRequestParams& aParams);
     279             : };
     280             : 
     281             : } // namespace dom
     282             : } // namespace mozilla
     283             : 
     284             : #endif // mozilla_dom_idbfactory_h__

Generated by: LCOV version 1.13