Bug 1475065 part 5. Remove nsIDOMOfflineResourceList::MozAdd. r=mystor
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 11 Jul 2018 17:47:56 -0700
changeset 1564016 b61749fcc326b713f7a9097fec41d1352a0155c6
parent 1564015 3a96e85140ad1a05aec4da0904bf0d138d0846c3
child 1564017 feeac4038d93c48d0a4708fb83ba6a63cc4df86e
push id283952
push userbzbarsky@mozilla.com
push dateThu, 12 Jul 2018 06:01:37 +0000
treeherdertry@3f386196ace6 [default view] [failures only]
reviewersmystor
bugs1475065
milestone63.0a1
Bug 1475065 part 5. Remove nsIDOMOfflineResourceList::MozAdd. r=mystor
dom/interfaces/offline/nsIDOMOfflineResourceList.idl
dom/offline/nsDOMOfflineResourceList.cpp
dom/offline/nsDOMOfflineResourceList.h
--- a/dom/interfaces/offline/nsIDOMOfflineResourceList.idl
+++ b/dom/interfaces/offline/nsIDOMOfflineResourceList.idl
@@ -9,25 +9,16 @@
 interface nsIDOMOfflineResourceList : nsISupports
 {
   /**
    * Get the list of dynamically-managed entries.
    */
   readonly attribute nsISupports mozItems;
 
   /**
-   * Add an item to the list of dynamically-managed entries.  The resource
-   * will be fetched into the application cache.
-   *
-   * @param uri
-   *        The resource to add.
-   */
-  void mozAdd(in DOMString uri);
-
-  /**
    * Remove an item from the list of dynamically-managed entries.  If this
    * was the last reference to a URI in the application cache, the cache
    * entry will be removed.
    *
    * @param uri
    *        The resource to remove.
    */
   void mozRemove(in DOMString uri);
--- a/dom/offline/nsDOMOfflineResourceList.cpp
+++ b/dom/offline/nsDOMOfflineResourceList.cpp
@@ -328,84 +328,119 @@ nsDOMOfflineResourceList::IndexedGetter(
     aFound = false;
     return;
   }
 
   aFound = true;
   CopyUTF8toUTF16(mCachedKeys[aIndex], aURI);
 }
 
-NS_IMETHODIMP
-nsDOMOfflineResourceList::MozAdd(const nsAString& aURI)
+void
+nsDOMOfflineResourceList::MozAdd(const nsAString& aURI, ErrorResult& aRv)
 {
-  if (IS_CHILD_PROCESS())
-    return NS_ERROR_NOT_IMPLEMENTED;
+  if (IS_CHILD_PROCESS()) {
+    aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
+    return;
+  }
 
   nsresult rv = Init();
-  NS_ENSURE_SUCCESS(rv, rv);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    aRv.Throw(rv);
+    return;
+  }
 
   if (!nsContentUtils::OfflineAppAllowed(mDocumentURI)) {
-    return NS_ERROR_DOM_SECURITY_ERR;
+    aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
+    return;
   }
 
   nsCOMPtr<nsIApplicationCache> appCache = GetDocumentAppCache();
   if (!appCache) {
-    return NS_ERROR_DOM_INVALID_STATE_ERR;
+    aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
+    return;
   }
 
-  if (aURI.Length() > MAX_URI_LENGTH) return NS_ERROR_DOM_BAD_URI;
+  if (aURI.Length() > MAX_URI_LENGTH) {
+    aRv.Throw(NS_ERROR_DOM_BAD_URI);
+    return;
+  }
 
   // this will fail if the URI is not absolute
   nsCOMPtr<nsIURI> requestedURI;
   rv = NS_NewURI(getter_AddRefs(requestedURI), aURI);
-  NS_ENSURE_SUCCESS(rv, rv);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    aRv.Throw(rv);
+    return;
+  }
 
   nsAutoCString scheme;
   rv = requestedURI->GetScheme(scheme);
-  NS_ENSURE_SUCCESS(rv, rv);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    aRv.Throw(rv);
+    return;
+  }
 
   bool match;
   rv = mManifestURI->SchemeIs(scheme.get(), &match);
-  NS_ENSURE_SUCCESS(rv, rv);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    aRv.Throw(rv);
+    return;
+  }
 
   if (!match) {
-    return NS_ERROR_DOM_SECURITY_ERR;
+    aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
+    return;
   }
 
-  ErrorResult res;
-  uint32_t length = GetMozLength(res);
-  if (NS_WARN_IF(res.Failed())) {
-    return res.StealNSResult();
+  uint32_t length = GetMozLength(aRv);
+  if (NS_WARN_IF(aRv.Failed())) {
+    return;
   }
   uint32_t maxEntries =
     Preferences::GetUint(kMaxEntriesPref, DEFAULT_MAX_ENTRIES);
 
-  if (length > maxEntries) return NS_ERROR_NOT_AVAILABLE;
+  if (length > maxEntries) {
+    aRv.Throw(NS_ERROR_NOT_AVAILABLE);
+    return;
+  }
 
   ClearCachedKeys();
 
   nsCOMPtr<nsIOfflineCacheUpdate> update =
     do_CreateInstance(NS_OFFLINECACHEUPDATE_CONTRACTID, &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    aRv.Throw(rv);
+    return;
+  }
 
   nsAutoCString clientID;
   rv = appCache->GetClientID(clientID);
-  NS_ENSURE_SUCCESS(rv, rv);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    aRv.Throw(rv);
+    return;
+  }
 
   rv = update->InitPartial(mManifestURI, clientID,
                            mDocumentURI, mLoadingPrincipal);
-  NS_ENSURE_SUCCESS(rv, rv);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    aRv.Throw(rv);
+    return;
+  }
 
   rv = update->AddDynamicURI(requestedURI);
-  NS_ENSURE_SUCCESS(rv, rv);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    aRv.Throw(rv);
+    return;
+  }
 
   rv = update->Schedule();
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  return NS_OK;
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    aRv.Throw(rv);
+    return;
+  }
 }
 
 NS_IMETHODIMP
 nsDOMOfflineResourceList::MozRemove(const nsAString& aURI)
 {
   if (IS_CHILD_PROCESS())
     return NS_ERROR_NOT_IMPLEMENTED;
 
--- a/dom/offline/nsDOMOfflineResourceList.h
+++ b/dom/offline/nsDOMOfflineResourceList.h
@@ -99,20 +99,17 @@ public:
   void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aURI,
                      ErrorResult& aRv);
   uint32_t Length()
   {
     mozilla::IgnoredErrorResult rv;
     uint32_t length = GetMozLength(rv);
     return rv.Failed() ? 0 : length;
   }
-  void MozAdd(const nsAString& aURI, ErrorResult& aRv)
-  {
-    aRv = MozAdd(aURI);
-  }
+  void MozAdd(const nsAString& aURI, ErrorResult& aRv);
   void MozRemove(const nsAString& aURI, ErrorResult& aRv)
   {
     aRv = MozRemove(aURI);
   }
 
 protected:
   virtual ~nsDOMOfflineResourceList();