Bug 1431774 part 4. de-COM the image loading content observer APIs. r=mystor
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 19 Jan 2018 14:19:39 -0500
changeset 454405 a414dcbea9c97a79de62c35ccc3988cefd765c6d
parent 454404 36ecbfa0db66a5d15ecafeab8f9e24703c83dc28
child 454406 2f9b914468dc619e619d8135646e25c61311d075
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmystor
bugs1431774
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1431774 part 4. de-COM the image loading content observer APIs. r=mystor MozReview-Commit-ID: KwWBFXNzWVx
dom/base/nsIImageLoadingContent.idl
dom/base/nsImageLoadingContent.cpp
dom/base/nsImageLoadingContent.h
dom/webidl/HTMLImageElement.webidl
--- a/dom/base/nsIImageLoadingContent.idl
+++ b/dom/base/nsIImageLoadingContent.idl
@@ -76,39 +76,25 @@ interface nsIImageLoadingContent : imgIN
   /**
    * Used to register an image decoder observer.  Typically, this will
    * be a proxy for a frame that wants to paint the image.
    * Notifications from ongoing image loads will be passed to all
    * registered observers.  Notifications for all request types,
    * current and pending, will be passed through.
    *
    * @param aObserver the observer to register
-   *
-   * @throws NS_ERROR_OUT_OF_MEMORY
    */
-  [notxpcom] nsresult addNativeObserver(in imgINotificationObserver aObserver);
+  [notxpcom, nostdcall] void addNativeObserver(in imgINotificationObserver aObserver);
 
   /**
    * Used to unregister an image decoder observer.
    *
    * @param aObserver the observer to unregister
    */
-  [notxpcom] nsresult removeNativeObserver(in imgINotificationObserver aObserver);
-
-  /**
-   * Same as addNativeObserver but intended for scripted observers or observers
-   * from another or without a document.
-   */
-  [noscript] void addObserver(in imgINotificationObserver aObserver);
-
-  /**
-   * Same as removeNativeObserver but intended for scripted observers or
-   * observers from another or without a document.
-   */
-  [noscript] void removeObserver(in imgINotificationObserver aObserver);
+  [notxpcom, nostdcall] void removeNativeObserver(in imgINotificationObserver aObserver);
 
   /**
    * Accessor to get the image requests
    *
    * @param aRequestType a value saying which request is wanted
    *
    * @return the imgIRequest object (may be null, even when no error
    * is thrown)
--- a/dom/base/nsImageLoadingContent.cpp
+++ b/dom/base/nsImageLoadingContent.cpp
@@ -375,54 +375,56 @@ ReplayImageStatus(imgIRequest* aRequest,
   if (status & imgIRequest::STATUS_DECODE_COMPLETE) {
     aObserver->Notify(aRequest, imgINotificationObserver::DECODE_COMPLETE, nullptr);
   }
   if (status & imgIRequest::STATUS_LOAD_COMPLETE) {
     aObserver->Notify(aRequest, imgINotificationObserver::LOAD_COMPLETE, nullptr);
   }
 }
 
-NS_IMETHODIMP
+void
 nsImageLoadingContent::AddNativeObserver(imgINotificationObserver* aObserver)
 {
-  NS_ENSURE_ARG_POINTER(aObserver);
+  if (NS_WARN_IF(!aObserver)) {
+    return;
+  }
 
   if (!mObserverList.mObserver) {
     // Don't touch the linking of the list!
     mObserverList.mObserver = aObserver;
 
     ReplayImageStatus(mCurrentRequest, aObserver);
     ReplayImageStatus(mPendingRequest, aObserver);
 
-    return NS_OK;
+    return;
   }
 
   // otherwise we have to create a new entry
 
   ImageObserver* observer = &mObserverList;
   while (observer->mNext) {
     observer = observer->mNext;
   }
 
   observer->mNext = new ImageObserver(aObserver);
   ReplayImageStatus(mCurrentRequest, aObserver);
   ReplayImageStatus(mPendingRequest, aObserver);
-
-  return NS_OK;
 }
 
-NS_IMETHODIMP
+void
 nsImageLoadingContent::RemoveNativeObserver(imgINotificationObserver* aObserver)
 {
-  NS_ENSURE_ARG_POINTER(aObserver);
+  if (NS_WARN_IF(!aObserver)) {
+    return;
+  }
 
   if (mObserverList.mObserver == aObserver) {
     mObserverList.mObserver = nullptr;
     // Don't touch the linking of the list!
-    return NS_OK;
+    return;
   }
 
   // otherwise have to find it and splice it out
   ImageObserver* observer = &mObserverList;
   while (observer->mNext && observer->mNext->mObserver != aObserver) {
     observer = observer->mNext;
   }
 
@@ -435,79 +437,80 @@ nsImageLoadingContent::RemoveNativeObser
     oldObserver->mNext = nullptr;  // so we don't destroy them all
     delete oldObserver;
   }
 #ifdef DEBUG
   else {
     NS_WARNING("Asked to remove nonexistent observer");
   }
 #endif
-  return NS_OK;
 }
 
-NS_IMETHODIMP
+void
 nsImageLoadingContent::AddObserver(imgINotificationObserver* aObserver)
 {
-  NS_ENSURE_ARG_POINTER(aObserver);
+  if (NS_WARN_IF(!aObserver)) {
+    return;
+  }
 
   nsresult rv = NS_OK;
   RefPtr<imgRequestProxy> currentReq;
   if (mCurrentRequest) {
     // Scripted observers may not belong to the same document as us, so when we
     // create the imgRequestProxy, we shouldn't use any. This allows the request
     // to dispatch notifications from the correct scheduler group.
     rv = mCurrentRequest->Clone(aObserver, nullptr, getter_AddRefs(currentReq));
     if (NS_FAILED(rv)) {
-      return rv;
+      return;
     }
   }
 
   RefPtr<imgRequestProxy> pendingReq;
   if (mPendingRequest) {
     // See above for why we don't use the loading document.
     rv = mPendingRequest->Clone(aObserver, nullptr, getter_AddRefs(pendingReq));
     if (NS_FAILED(rv)) {
       mCurrentRequest->CancelAndForgetObserver(NS_BINDING_ABORTED);
-      return rv;
+      return;
     }
   }
 
   mScriptedObservers.AppendElement(
     new ScriptedImageObserver(aObserver, Move(currentReq), Move(pendingReq)));
-  return rv;
 }
 
-NS_IMETHODIMP
+void
 nsImageLoadingContent::RemoveObserver(imgINotificationObserver* aObserver)
 {
-  NS_ENSURE_ARG_POINTER(aObserver);
+  if (NS_WARN_IF(!aObserver)) {
+    return;
+  }
 
   if (NS_WARN_IF(mScriptedObservers.IsEmpty())) {
-    return NS_OK;
+    return;
   }
 
   RefPtr<ScriptedImageObserver> observer;
   auto i = mScriptedObservers.Length();
   do {
     --i;
     if (mScriptedObservers[i]->mObserver == aObserver) {
       observer = Move(mScriptedObservers[i]);
       mScriptedObservers.RemoveElementAt(i);
       break;
     }
   } while(i > 0);
 
   if (NS_WARN_IF(!observer)) {
-    return NS_OK;
+    return;
   }
 
   // If the cancel causes a mutation, it will be harmless, because we have
   // already removed the observer from the list.
   observer->CancelRequests();
-  return NS_OK;
 }
 
 void
 nsImageLoadingContent::ClearScriptedRequests(int32_t aRequestType, nsresult aReason)
 {
   if (MOZ_LIKELY(mScriptedObservers.IsEmpty())) {
     return;
   }
--- a/dom/base/nsImageLoadingContent.h
+++ b/dom/base/nsImageLoadingContent.h
@@ -51,25 +51,27 @@ class nsImageLoadingContent : public nsI
 public:
   nsImageLoadingContent();
   virtual ~nsImageLoadingContent();
 
   NS_DECL_IMGINOTIFICATIONOBSERVER
   NS_DECL_NSIIMAGELOADINGCONTENT
 
   // Web IDL binding methods.
-  // Note that the XPCOM SetLoadingEnabled, AddObserver, RemoveObserver,
-  // ForceImageState methods are OK for Web IDL bindings to use as well,
-  // since none of them throw when called via the Web IDL bindings.
+  // Note that the XPCOM SetLoadingEnabled, ForceImageState methods are OK for
+  // Web IDL bindings to use as well, since none of them throw when called via
+  // the Web IDL bindings.
 
   bool LoadingEnabled() const { return mLoadingEnabled; }
   int16_t ImageBlockingStatus() const
   {
     return mImageBlockingStatus;
   }
+  void AddObserver(imgINotificationObserver* aObserver);
+  void RemoveObserver(imgINotificationObserver* aObserver);
   already_AddRefed<imgIRequest>
     GetRequest(int32_t aRequestType, mozilla::ErrorResult& aError);
   int32_t
     GetRequestType(imgIRequest* aRequest, mozilla::ErrorResult& aError);
   already_AddRefed<nsIURI> GetCurrentURI(mozilla::ErrorResult& aError);
   already_AddRefed<nsIURI> GetCurrentRequestFinalURI();
   void ForceReload(const mozilla::dom::Optional<bool>& aNotify,
                    mozilla::ErrorResult& aError);
--- a/dom/webidl/HTMLImageElement.webidl
+++ b/dom/webidl/HTMLImageElement.webidl
@@ -87,18 +87,26 @@ interface MozImageLoadingContent {
   const long CURRENT_REQUEST = 0;
   [ChromeOnly]
   const long PENDING_REQUEST = 1;
 
   [ChromeOnly]
   attribute boolean loadingEnabled;
   [ChromeOnly]
   readonly attribute short imageBlockingStatus;
+  /**
+   * Same as addNativeObserver but intended for scripted observers or observers
+   * from another or without a document.
+   */
   [ChromeOnly]
   void addObserver(imgINotificationObserver aObserver);
+  /**
+   * Same as removeNativeObserver but intended for scripted observers or
+   * observers from another or without a document.
+   */
   [ChromeOnly]
   void removeObserver(imgINotificationObserver aObserver);
   [ChromeOnly,Throws]
   imgIRequest? getRequest(long aRequestType);
   [ChromeOnly,Throws]
   long getRequestType(imgIRequest aRequest);
   [ChromeOnly,Throws]
   readonly attribute URI? currentURI;