Bug 1600283 - Remove uses of plain pointers. r=#dom-workers-and-storage draft
authorSimon Giesecke <sgiesecke@mozilla.com>
Wed, 04 Dec 2019 16:50:22 +0000
changeset 2516007 be843f9a84a87522a0c5c320cc5a84439f9ab1f9
parent 2516006 60ce6217362c27b7e08855e6e5abea958d0e2bdc
child 2516008 ad7ac3cb82e3829ea6f874927a52654fed87a255
push id460090
push userreviewbot
push dateWed, 04 Dec 2019 16:51:29 +0000
treeherdertry@35d310cdd9cf [default view] [failures only]
bugs1600283
milestone73.0a1
Bug 1600283 - Remove uses of plain pointers. r=#dom-workers-and-storage Differential Revision: https://phabricator.services.mozilla.com/D55512 Differential Diff: PHID-DIFF-qeriaf6uozfhh5g2rb7h
dom/indexedDB/IDBFactory.cpp
dom/indexedDB/IDBFactory.h
--- a/dom/indexedDB/IDBFactory.cpp
+++ b/dom/indexedDB/IDBFactory.cpp
@@ -135,17 +135,17 @@ IDBFactory::~IDBFactory() {
 // static
 nsresult IDBFactory::CreateForWindow(nsPIDOMWindowInner* aWindow,
                                      IDBFactory** aFactory) {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aWindow);
   MOZ_ASSERT(aFactory);
 
   nsCOMPtr<nsIPrincipal> principal;
-  nsresult rv = AllowedForWindowInternal(aWindow, getter_AddRefs(principal));
+  nsresult rv = AllowedForWindowInternal(aWindow, &principal);
 
   if (rv == NS_ERROR_DOM_NOT_SUPPORTED_ERR) {
     NS_WARNING("IndexedDB is not permitted in a third-party window.");
     *aFactory = nullptr;
     return NS_OK;
   }
 
   if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -234,72 +234,69 @@ nsresult IDBFactory::CreateForMainThread
 nsresult IDBFactory::CreateForWorker(nsIGlobalObject* aGlobal,
                                      const PrincipalInfo& aPrincipalInfo,
                                      uint64_t aInnerWindowID,
                                      IDBFactory** aFactory) {
   MOZ_ASSERT(!NS_IsMainThread());
   MOZ_ASSERT(aGlobal);
   MOZ_ASSERT(aPrincipalInfo.type() != PrincipalInfo::T__None);
 
-  nsAutoPtr<PrincipalInfo> principalInfo(new PrincipalInfo(aPrincipalInfo));
-
-  nsresult rv =
-      CreateInternal(aGlobal, principalInfo, aInnerWindowID, aFactory);
+  nsresult rv = CreateInternal(
+      aGlobal, nsAutoPtr<PrincipalInfo>(new PrincipalInfo(aPrincipalInfo)),
+      aInnerWindowID, aFactory);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  MOZ_ASSERT(!principalInfo);
-
   return NS_OK;
 }
 
 // static
 nsresult IDBFactory::CreateForMainThreadJSInternal(
-    nsIGlobalObject* aGlobal, nsAutoPtr<PrincipalInfo>& aPrincipalInfo,
+    nsIGlobalObject* aGlobal, nsAutoPtr<PrincipalInfo> aPrincipalInfo,
     IDBFactory** aFactory) {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aGlobal);
   MOZ_ASSERT(aPrincipalInfo);
 
   IndexedDatabaseManager* mgr = IndexedDatabaseManager::GetOrCreate();
   if (NS_WARN_IF(!mgr)) {
     IDB_REPORT_INTERNAL_ERR();
     return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
   }
 
-  nsresult rv =
-      CreateInternal(aGlobal, aPrincipalInfo, /* aInnerWindowID */ 0, aFactory);
+  nsresult rv = CreateInternal(aGlobal, std::move(aPrincipalInfo),
+                               /* aInnerWindowID */ 0, aFactory);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   return NS_OK;
 }
 
 // static
 nsresult IDBFactory::CreateInternal(nsIGlobalObject* aGlobal,
-                                    nsAutoPtr<PrincipalInfo>& aPrincipalInfo,
+                                    nsAutoPtr<PrincipalInfo> aPrincipalInfo,
                                     uint64_t aInnerWindowID,
                                     IDBFactory** aFactory) {
   MOZ_ASSERT(aGlobal);
   MOZ_ASSERT(aPrincipalInfo);
   MOZ_ASSERT(aPrincipalInfo->type() != PrincipalInfo::T__None);
   MOZ_ASSERT(aFactory);
 
   if (aPrincipalInfo->type() != PrincipalInfo::TContentPrincipalInfo &&
       aPrincipalInfo->type() != PrincipalInfo::TSystemPrincipalInfo) {
     NS_WARNING("IndexedDB not allowed for this principal!");
     aPrincipalInfo = nullptr;
     *aFactory = nullptr;
     return NS_OK;
   }
 
   RefPtr<IDBFactory> factory = new IDBFactory();
-  factory->mPrincipalInfo = aPrincipalInfo.forget();
+  factory->mPrincipalInfo = std::move(aPrincipalInfo);
   factory->mGlobal = aGlobal;
   factory->mEventTarget = GetCurrentThreadEventTarget();
   factory->mInnerWindowID = aInnerWindowID;
 
   factory.forget(aFactory);
   return NS_OK;
 }
 
@@ -307,18 +304,18 @@ nsresult IDBFactory::CreateInternal(nsIG
 bool IDBFactory::AllowedForWindow(nsPIDOMWindowInner* aWindow) {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aWindow);
 
   return !NS_WARN_IF(NS_FAILED(AllowedForWindowInternal(aWindow, nullptr)));
 }
 
 // static
-nsresult IDBFactory::AllowedForWindowInternal(nsPIDOMWindowInner* aWindow,
-                                              nsIPrincipal** aPrincipal) {
+nsresult IDBFactory::AllowedForWindowInternal(
+    nsPIDOMWindowInner* aWindow, nsCOMPtr<nsIPrincipal>* aPrincipal) {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aWindow);
 
   if (NS_WARN_IF(!IndexedDatabaseManager::GetOrCreate())) {
     return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
   }
 
   StorageAccess access = StorageAllowedForWindow(aWindow);
@@ -340,17 +337,17 @@ nsresult IDBFactory::AllowedForWindowInt
   MOZ_ASSERT(sop);
 
   nsCOMPtr<nsIPrincipal> principal = sop->GetEffectiveStoragePrincipal();
   if (NS_WARN_IF(!principal)) {
     return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
   }
 
   if (nsContentUtils::IsSystemPrincipal(principal)) {
-    principal.forget(aPrincipal);
+    *aPrincipal = std::move(principal);
     return NS_OK;
   }
 
   // About URIs shouldn't be able to access IndexedDB unless they have the
   // nsIAboutModule::ENABLE_INDEXED_DB flag set on them.
 
   if (principal->SchemeIs("about")) {
     uint32_t flags;
@@ -359,17 +356,17 @@ nsresult IDBFactory::AllowedForWindowInt
         return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
       }
     } else {
       return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
     }
   }
 
   if (aPrincipal) {
-    principal.forget(aPrincipal);
+    *aPrincipal = std::move(principal);
   }
   return NS_OK;
 }
 
 // static
 bool IDBFactory::AllowedForPrincipal(nsIPrincipal* aPrincipal,
                                      bool* aIsSystemPrincipal) {
   MOZ_ASSERT(NS_IsMainThread());
--- a/dom/indexedDB/IDBFactory.h
+++ b/dom/indexedDB/IDBFactory.h
@@ -183,26 +183,26 @@ class IDBFactory final : public nsISuppo
   virtual JSObject* WrapObject(JSContext* aCx,
                                JS::Handle<JSObject*> aGivenProto) override;
 
  private:
   IDBFactory();
   ~IDBFactory();
 
   static nsresult CreateForMainThreadJSInternal(
-      nsIGlobalObject* aGlobal, nsAutoPtr<PrincipalInfo>& aPrincipalInfo,
+      nsIGlobalObject* aGlobal, nsAutoPtr<PrincipalInfo> aPrincipalInfo,
       IDBFactory** aFactory);
 
   static nsresult CreateInternal(nsIGlobalObject* aGlobal,
-                                 nsAutoPtr<PrincipalInfo>& aPrincipalInfo,
+                                 nsAutoPtr<PrincipalInfo> aPrincipalInfo,
                                  uint64_t aInnerWindowID,
                                  IDBFactory** aFactory);
 
   static nsresult AllowedForWindowInternal(nsPIDOMWindowInner* aWindow,
-                                           nsIPrincipal** aPrincipal);
+                                           nsCOMPtr<nsIPrincipal>* aPrincipal);
 
   MOZ_MUST_USE RefPtr<IDBOpenDBRequest> OpenInternal(
       JSContext* aCx, nsIPrincipal* aPrincipal, const nsAString& aName,
       const Optional<uint64_t>& aVersion,
       const Optional<StorageType>& aStorageType, bool aDeleting,
       CallerType aCallerType, ErrorResult& aRv);
 
   nsresult InitiateRequest(IDBOpenDBRequest* aRequest,