Bug 1507540 part 7. Use notxpcom more in dom/. r=mccr8
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 19 Nov 2018 20:20:17 -0500
changeset 503593 d583bf98a4b2086c0e016de10bebc871c35a3361
parent 503592 6b60870ec6f8473b578be250179840c5316f0444
child 503594 60639eb34a6dfb0e52d2c2536706c1c979332f24
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1507540
milestone65.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 1507540 part 7. Use notxpcom more in dom/. r=mccr8
accessible/base/nsAccessibilityService.cpp
dom/base/nsContentUtils.cpp
dom/base/nsIImageLoadingContent.idl
dom/base/nsIObjectLoadingContent.idl
dom/base/nsImageLoadingContent.cpp
dom/base/nsImageLoadingContent.h
dom/base/nsObjectLoadingContent.cpp
dom/base/nsObjectLoadingContent.h
dom/html/HTMLImageElement.cpp
dom/html/HTMLImageElement.h
dom/html/HTMLObjectElement.cpp
dom/html/PluginDocument.cpp
dom/plugins/base/nsIPluginInstanceOwner.idl
dom/plugins/base/nsPluginHost.cpp
dom/plugins/base/nsPluginInstanceOwner.cpp
layout/generic/nsIObjectFrame.h
layout/generic/nsPluginFrame.cpp
layout/generic/nsPluginFrame.h
--- a/accessible/base/nsAccessibilityService.cpp
+++ b/accessible/base/nsAccessibilityService.cpp
@@ -422,19 +422,18 @@ nsAccessibilityService::CreatePluginAcce
                                                Accessible* aContext)
 {
   // nsPluginFrame means a plugin, so we need to use the accessibility support
   // of the plugin.
   if (aFrame->GetRect().IsEmpty())
     return nullptr;
 
 #if defined(XP_WIN) || defined(MOZ_ACCESSIBILITY_ATK)
-  RefPtr<nsNPAPIPluginInstance> pluginInstance;
-  if (NS_SUCCEEDED(aFrame->GetPluginInstance(getter_AddRefs(pluginInstance))) &&
-      pluginInstance) {
+  RefPtr<nsNPAPIPluginInstance> pluginInstance = aFrame->GetPluginInstance();
+  if (pluginInstance) {
 #ifdef XP_WIN
     if (!sPendingPlugins->Contains(aContent) &&
         (Preferences::GetBool("accessibility.delay_plugins") ||
          Compatibility::IsJAWS() || Compatibility::IsWE())) {
       RefPtr<PluginTimerCallBack> cb = new PluginTimerCallBack(aContent);
       nsCOMPtr<nsITimer> timer;
       NS_NewTimerWithCallback(getter_AddRefs(timer),
                               cb, Preferences::GetUint("accessibility.delay_plugin_time"),
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -7146,18 +7146,17 @@ nsContentUtils::HasPluginWithUncontrolle
     return false;
   }
 
   nsCOMPtr<nsIObjectLoadingContent> olc = do_QueryInterface(aContent);
   if (!olc) {
     return false;
   }
 
-  RefPtr<nsNPAPIPluginInstance> plugin;
-  olc->GetPluginInstance(getter_AddRefs(plugin));
+  RefPtr<nsNPAPIPluginInstance> plugin = olc->GetPluginInstance();
   if (!plugin) {
     return false;
   }
 
   bool isWindowless = false;
   nsresult res = plugin->IsWindowless(&isWindowless);
   if (NS_FAILED(res)) {
     return false;
--- a/dom/base/nsIImageLoadingContent.idl
+++ b/dom/base/nsIImageLoadingContent.idl
@@ -66,17 +66,17 @@ interface nsIImageLoadingContent : imgIN
   [notxpcom, nostdcall] void setLoadingEnabled(in boolean aEnabled);
 
   /**
    * Returns the image blocking status (@see nsIContentPolicy).  This
    * will always be an nsIContentPolicy REJECT_* status for cases when
    * the image was blocked.  This status always refers to the
    * CURRENT_REQUEST load.
    */
-  [noscript, infallible] readonly attribute short imageBlockingStatus;
+  [notxpcom, nostdcall] readonly attribute short imageBlockingStatus;
 
   /**
    * 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.
    *
@@ -162,23 +162,16 @@ interface nsIImageLoadingContent : imgIN
   /**
    * Enables/disables image state forcing. When |aForce| is true, we force
    * nsImageLoadingContent::ImageState() to return |aState|. Call again with |aForce|
    * as false to revert ImageState() to its original behaviour.
    */
   [notxpcom, nostdcall] void forceImageState(in boolean aForce, in unsigned long long aState);
 
   /**
-   * The intrinsic size and width of this content. May differ from actual image
-   * size due to things like responsive image density.
-   */
-  [noscript] readonly attribute unsigned long    naturalWidth;
-  [noscript] readonly attribute unsigned long    naturalHeight;
-
-  /**
    * Called by layout to announce when the frame associated with this content
    * has changed its visibility state.
    *
    * @param aNewVisibility    The new visibility state.
    * @param aNonvisibleAction A requested action if the frame has become
    *                          nonvisible. If Nothing(), no action is
    *                          requested. If DISCARD_IMAGES is specified, the
    *                          frame is requested to ask any images it's
--- a/dom/base/nsIObjectLoadingContent.idl
+++ b/dom/base/nsIObjectLoadingContent.idl
@@ -89,28 +89,21 @@ interface nsIObjectLoadingContent : nsIS
   /**
    * Gets the content type that corresponds to the give MIME type.  See the
    * constants above for the list of possible values.  If nothing else fits,
    * TYPE_NULL will be returned.
    */
   unsigned long getContentTypeForMIMEType(in AUTF8String aMimeType);
 
   /**
-   * Returns the base URI of the object as seen by plugins. This differs from
-   * the normal codebase in that it takes <param> tags and plugin-specific
-   * quirks into account.
-   */
-  [noscript] readonly attribute nsIURI baseURI;
-
-  /**
    * Returns the plugin instance if it has already been instantiated. This
    * will never instantiate the plugin and so is safe to call even when
    * content script must not execute.
    */
-  [noscript] readonly attribute nsNPAPIPluginInstancePtr pluginInstance;
+  [notxpcom,nostdcall] readonly attribute nsNPAPIPluginInstancePtr pluginInstance;
 
   /**
    * Tells the content about an associated object frame.
    * This can be called multiple times for different frames.
    *
    * This is noscript because this is an internal method that will go away, and
    * because nsIObjectFrame is unscriptable.
    */
--- a/dom/base/nsImageLoadingContent.cpp
+++ b/dom/base/nsImageLoadingContent.cpp
@@ -384,22 +384,20 @@ nsImageLoadingContent::MaybeForceSyncDec
 
   if (imageFrame) {
     imageFrame->SetForceSyncDecoding(forceSync);
   } else {
     svgImageFrame->SetForceSyncDecoding(forceSync);
   }
 }
 
-NS_IMETHODIMP
-nsImageLoadingContent::GetImageBlockingStatus(int16_t* aStatus)
+int16_t
+nsImageLoadingContent::GetImageBlockingStatus()
 {
-  MOZ_ASSERT(aStatus, "Null out param");
-  *aStatus = ImageBlockingStatus();
-  return NS_OK;
+  return ImageBlockingStatus();
 }
 
 static void
 ReplayImageStatus(imgIRequest* aRequest, imgINotificationObserver* aObserver)
 {
   if (!aRequest) {
     return;
   }
@@ -1100,54 +1098,46 @@ nsImageLoadingContent::LoadImage(nsIURI*
 void
 nsImageLoadingContent::ForceImageState(bool aForce,
                                        EventStates::InternalType aState)
 {
   mIsImageStateForced = aForce;
   mForcedImageState = EventStates(aState);
 }
 
-NS_IMETHODIMP
-nsImageLoadingContent::GetNaturalWidth(uint32_t* aNaturalWidth)
+uint32_t
+nsImageLoadingContent::NaturalWidth()
 {
-  NS_ENSURE_ARG_POINTER(aNaturalWidth);
-
   nsCOMPtr<imgIContainer> image;
   if (mCurrentRequest) {
     mCurrentRequest->GetImage(getter_AddRefs(image));
   }
 
   int32_t width;
   if (image && NS_SUCCEEDED(image->GetWidth(&width))) {
-    *aNaturalWidth = width;
-  } else {
-    *aNaturalWidth = 0;
+    return width;
   }
 
-  return NS_OK;
+  return 0;
 }
 
-NS_IMETHODIMP
-nsImageLoadingContent::GetNaturalHeight(uint32_t* aNaturalHeight)
+uint32_t
+nsImageLoadingContent::NaturalHeight()
 {
-  NS_ENSURE_ARG_POINTER(aNaturalHeight);
-
   nsCOMPtr<imgIContainer> image;
   if (mCurrentRequest) {
     mCurrentRequest->GetImage(getter_AddRefs(image));
   }
 
   int32_t height;
   if (image && NS_SUCCEEDED(image->GetHeight(&height))) {
-    *aNaturalHeight = height;
-  } else {
-    *aNaturalHeight = 0;
+    return height;
   }
 
-  return NS_OK;
+  return 0;
 }
 
 EventStates
 nsImageLoadingContent::ImageState() const
 {
   if (mIsImageStateForced) {
     return mForcedImageState;
   }
--- a/dom/base/nsImageLoadingContent.h
+++ b/dom/base/nsImageLoadingContent.h
@@ -229,16 +229,20 @@ protected:
   static nsContentPolicyType PolicyTypeForLoad(ImageLoadType aImageLoadType);
 
   void AsyncEventRunning(mozilla::AsyncEventDispatcher* aEvent);
 
   // Get ourselves as an nsIContent*.  Not const because some of the callers
   // want a non-const nsIContent.
   virtual nsIContent* AsContent() = 0;
 
+  // Hooks for subclasses to call to get the intrinsic width and height.
+  uint32_t NaturalWidth();
+  uint32_t NaturalHeight();
+
   enum class ImageDecodingType : uint8_t {
     Auto,
     Async,
     Sync,
   };
 
   static const nsAttrValue::EnumTable kDecodingTable[];
   static const nsAttrValue::EnumTable* kDecodingTableDefault;
--- a/dom/base/nsObjectLoadingContent.cpp
+++ b/dom/base/nsObjectLoadingContent.cpp
@@ -534,20 +534,18 @@ nsObjectLoadingContent::MakePluginListen
   }
   RefPtr<nsPluginHost> pluginHost = nsPluginHost::GetInst();
   if (!pluginHost) {
     MOZ_ASSERT_UNREACHABLE("No pluginHost");
     return false;
   }
   NS_ASSERTION(!mFinalListener, "overwriting a final listener");
   nsresult rv;
-  RefPtr<nsNPAPIPluginInstance> inst;
+  RefPtr<nsNPAPIPluginInstance> inst = mInstanceOwner->GetInstance();
   nsCOMPtr<nsIStreamListener> finalListener;
-  rv = mInstanceOwner->GetInstance(getter_AddRefs(inst));
-  NS_ENSURE_SUCCESS(rv, false);
   rv = pluginHost->NewPluginStreamListener(mURI, inst,
                                            getter_AddRefs(finalListener));
   NS_ENSURE_SUCCESS(rv, false);
   mFinalListener = finalListener;
   return true;
 }
 
 // Helper to spawn the frameloader.
@@ -750,35 +748,30 @@ nsObjectLoadingContent::InstantiatePlugi
 
   if (!mInstantiating || NS_FAILED(rv)) {
     LOG(("OBJLC [%p]: Plugin instantiation failed or re-entered, "
          "killing old instance", this));
     // XXX(johns): This needs to be de-duplicated with DoStopPlugin, but we
     //             don't want to touch the protochain or delayed stop.
     //             (Bug 767635)
     if (newOwner) {
-      RefPtr<nsNPAPIPluginInstance> inst;
-      newOwner->GetInstance(getter_AddRefs(inst));
+      RefPtr<nsNPAPIPluginInstance> inst = newOwner->GetInstance();
       newOwner->SetFrame(nullptr);
       if (inst) {
         pluginHost->StopPluginInstance(inst);
       }
       newOwner->Destroy();
     }
     return NS_OK;
   }
 
   mInstanceOwner = newOwner;
 
   if (mInstanceOwner) {
-    RefPtr<nsNPAPIPluginInstance> inst;
-    rv = mInstanceOwner->GetInstance(getter_AddRefs(inst));
-    if (NS_WARN_IF(NS_FAILED(rv))) {
-      return rv;
-    }
+    RefPtr<nsNPAPIPluginInstance> inst = mInstanceOwner->GetInstance();
 
     rv = inst->GetRunID(&mRunID);
     mHasRunID = NS_SUCCEEDED(rv);
   }
 
   // Ensure the frame did not change during instantiation re-entry (common).
   // HasNewFrame would not have mInstanceOwner yet, so the new frame would be
   // dangling. (Bug 854082)
@@ -789,18 +782,17 @@ nsObjectLoadingContent::InstantiatePlugi
     // Bug 870216 - Adobe Reader renders with incorrect dimensions until it gets
     // a second SetWindow call. This is otherwise redundant.
     mInstanceOwner->CallSetWindow();
   }
 
   // Set up scripting interfaces.
   NotifyContentObjectWrapper();
 
-  RefPtr<nsNPAPIPluginInstance> pluginInstance;
-  GetPluginInstance(getter_AddRefs(pluginInstance));
+  RefPtr<nsNPAPIPluginInstance> pluginInstance = GetPluginInstance();
   if (pluginInstance) {
     nsCOMPtr<nsIPluginTag> pluginTag;
     pluginHost->GetPluginTagForInstance(pluginInstance,
                                         getter_AddRefs(pluginTag));
 
 
     uint32_t blockState = nsIBlocklistService::STATE_NOT_BLOCKED;
     pluginTag->GetBlocklistState(&blockState);
@@ -1184,43 +1176,34 @@ nsObjectLoadingContent::HasNewFrame(nsIO
   // Otherwise, we're just changing frames
   // Set up relationship between instance owner and frame.
   nsPluginFrame *objFrame = static_cast<nsPluginFrame*>(aFrame);
   mInstanceOwner->SetFrame(objFrame);
 
   return NS_OK;
 }
 
-NS_IMETHODIMP
-nsObjectLoadingContent::GetPluginInstance(nsNPAPIPluginInstance** aInstance)
+nsNPAPIPluginInstance*
+nsObjectLoadingContent::GetPluginInstance()
 {
-  *aInstance = nullptr;
-
   if (!mInstanceOwner) {
-    return NS_OK;
+    return nullptr;
   }
 
-  return mInstanceOwner->GetInstance(aInstance);
+  return mInstanceOwner->GetInstance();
 }
 
 NS_IMETHODIMP
 nsObjectLoadingContent::GetContentTypeForMIMEType(const nsACString& aMIMEType,
                                                   uint32_t* aType)
 {
   *aType = GetTypeOfContent(PromiseFlatCString(aMIMEType), false);
   return NS_OK;
 }
 
-NS_IMETHODIMP
-nsObjectLoadingContent::GetBaseURI(nsIURI **aResult)
-{
-  NS_IF_ADDREF(*aResult = mBaseURI);
-  return NS_OK;
-}
-
 // nsIInterfaceRequestor
 // We use a shim class to implement this so that JS consumers still
 // see an interface requestor even though WebIDL bindings don't expose
 // that stuff.
 class ObjectInterfaceRequestorShim final : public nsIInterfaceRequestor,
                                            public nsIChannelEventSink,
                                            public nsIStreamListener
 {
@@ -2823,19 +2806,18 @@ nsObjectLoadingContent::PluginCrashed(ns
                              submittedCrashReport);
   nsresult rv = NS_DispatchToCurrentThread(ev);
   if (NS_FAILED(rv)) {
     NS_WARNING("failed to dispatch nsPluginCrashedEvent");
   }
   return NS_OK;
 }
 
-nsresult
-nsObjectLoadingContent::ScriptRequestPluginInstance(JSContext* aCx,
-                                                    nsNPAPIPluginInstance **aResult)
+nsNPAPIPluginInstance*
+nsObjectLoadingContent::ScriptRequestPluginInstance(JSContext* aCx)
 {
   // The below methods pull the cx off the stack, so make sure they match.
   //
   // NB: Sometimes there's a null cx on the stack, in which case |cx| is the
   // safe JS context. But in that case, IsCallerChrome() will return true,
   // so the ensuing expression is short-circuited.
   // XXXbz the NB comment above doesn't really make sense.  At the moment, all
   // the callers to this except maybe SetupProtoChain have a useful JSContext*
@@ -2845,18 +2827,16 @@ nsObjectLoadingContent::ScriptRequestPlu
                 aCx == nsContentUtils::GetCurrentJSContext());
   bool callerIsContentJS = (nsContentUtils::GetCurrentJSContext() &&
                             !nsContentUtils::IsCallerChrome() &&
                             !nsContentUtils::IsCallerContentXBL());
 
   nsCOMPtr<nsIContent> thisContent =
     do_QueryInterface(static_cast<nsIImageLoadingContent*>(this));
 
-  *aResult = nullptr;
-
   // The first time content script attempts to access placeholder content, fire
   // an event.  Fallback types >= eFallbackClickToPlay are plugin-replacement
   // types, see header.
   if (callerIsContentJS && !mScriptRequested &&
       InActiveDocument(thisContent) && mType == eType_Null &&
       mFallbackType >= eFallbackClickToPlay) {
     nsCOMPtr<nsIRunnable> ev =
       new nsSimplePluginEvent(thisContent,
@@ -2870,21 +2850,21 @@ nsObjectLoadingContent::ScriptRequestPlu
              nsContentUtils::IsSafeToRunScript() &&
              InActiveDocument(thisContent)) {
     // If we're configured as a plugin in an active document and it's safe to
     // run scripts right now, try spawning synchronously
     SyncStartPluginInstance();
   }
 
   if (mInstanceOwner) {
-    return mInstanceOwner->GetInstance(aResult);
+    return mInstanceOwner->GetInstance();
   }
 
   // Note that returning a null plugin is expected (and happens often)
-  return NS_OK;
+  return nullptr;
 }
 
 NS_IMETHODIMP
 nsObjectLoadingContent::SyncStartPluginInstance()
 {
   NS_ASSERTION(nsContentUtils::IsSafeToRunScript(),
                "Must be able to run script in order to instantiate a plugin instance!");
 
@@ -3022,18 +3002,17 @@ nsObjectLoadingContent::DoStopPlugin(nsP
 
   RefPtr<nsPluginInstanceOwner> kungFuDeathGrip(aInstanceOwner);
   if (mType == eType_FakePlugin) {
     if (mFrameLoader) {
       mFrameLoader->Destroy();
       mFrameLoader = nullptr;
     }
   } else {
-    RefPtr<nsNPAPIPluginInstance> inst;
-    aInstanceOwner->GetInstance(getter_AddRefs(inst));
+    RefPtr<nsNPAPIPluginInstance> inst = aInstanceOwner->GetInstance();
     if (inst) {
 #if defined(XP_MACOSX)
       aInstanceOwner->HidePluginWindow();
 #endif
 
       RefPtr<nsPluginHost> pluginHost = nsPluginHost::GetInst();
       NS_ASSERTION(pluginHost, "No plugin host?");
       pluginHost->StopPluginInstance(inst);
@@ -3572,31 +3551,27 @@ nsObjectLoadingContent::SetupProtoChain(
   // We get called on random realms here for some reason
   // (perhaps because WrapObject can happen on a random realm?)
   // so make sure to enter the realm of aObject.
   MOZ_ASSERT(aCx == nsContentUtils::GetCurrentJSContext());
 
   MOZ_ASSERT(IsDOMObject(aObject));
   JSAutoRealm ar(aCx, aObject);
 
-  RefPtr<nsNPAPIPluginInstance> pi;
-  nsresult rv = ScriptRequestPluginInstance(aCx, getter_AddRefs(pi));
-  if (NS_FAILED(rv)) {
-    return;
-  }
+  RefPtr<nsNPAPIPluginInstance> pi = ScriptRequestPluginInstance(aCx);
 
   if (!pi) {
     // No plugin around for this object.
     return;
   }
 
   JS::Rooted<JSObject*> pi_obj(aCx); // XPConnect-wrapped peer object, when we get it.
   JS::Rooted<JSObject*> pi_proto(aCx); // 'pi.__proto__'
 
-  rv = GetPluginJSObject(aCx, pi, &pi_obj, &pi_proto);
+  nsresult rv = GetPluginJSObject(aCx, pi, &pi_obj, &pi_proto);
   if (NS_FAILED(rv)) {
     return;
   }
 
   if (!pi_obj) {
     // Didn't get a plugin instance JSObject, nothing we can do then.
     return;
   }
@@ -3741,22 +3716,17 @@ nsObjectLoadingContent::TeardownProtoCha
 
 bool
 nsObjectLoadingContent::DoResolve(JSContext* aCx, JS::Handle<JSObject*> aObject,
                                   JS::Handle<jsid> aId,
                                   JS::MutableHandle<JS::PropertyDescriptor> aDesc)
 {
   // We don't resolve anything; we just try to make sure we're instantiated.
   // This purposefully does not fire for chrome/xray resolves, see bug 967694
-
-  RefPtr<nsNPAPIPluginInstance> pi;
-  nsresult rv = ScriptRequestPluginInstance(aCx, getter_AddRefs(pi));
-  if (NS_FAILED(rv)) {
-    return mozilla::dom::Throw(aCx, rv);
-  }
+  Unused << ScriptRequestPluginInstance(aCx);
   return true;
 }
 
 /* static */
 bool
 nsObjectLoadingContent::MayResolve(jsid aId)
 {
   // We can resolve anything, really.
@@ -3767,18 +3737,17 @@ void
 nsObjectLoadingContent::GetOwnPropertyNames(JSContext* aCx,
                                             JS::AutoIdVector& /* unused */,
                                             bool /* unused */,
                                             ErrorResult& aRv)
 {
   // Just like DoResolve, just make sure we're instantiated.  That will do
   // the work our Enumerate hook needs to do.  This purposefully does not fire
   // for xray resolves, see bug 967694
-  RefPtr<nsNPAPIPluginInstance> pi;
-  aRv = ScriptRequestPluginInstance(aCx, getter_AddRefs(pi));
+  Unused << ScriptRequestPluginInstance(aCx);
 }
 
 void
 nsObjectLoadingContent::MaybeFireErrorEvent()
 {
   nsCOMPtr<nsIContent> thisContent =
     do_QueryInterface(static_cast<nsIImageLoadingContent*>(this));
   // Queue a task to fire an error event if we're an <object> element.  The
--- a/dom/base/nsObjectLoadingContent.h
+++ b/dom/base/nsObjectLoadingContent.h
@@ -614,18 +614,17 @@ class nsObjectLoadingContent : public ns
 
     private:
       // We store an nsIObjectLoadingContent because we can
       // unambiguously refcount that.
       RefPtr<nsIObjectLoadingContent> mContent;
     };
 
     // Utility getter for getting our nsNPAPIPluginInstance in a safe way.
-    nsresult ScriptRequestPluginInstance(JSContext* aCx,
-                                         nsNPAPIPluginInstance** aResult);
+    nsNPAPIPluginInstance* ScriptRequestPluginInstance(JSContext* aCx);
 
     // Utility method for getting our plugin JSObject
     static nsresult GetPluginJSObject(JSContext *cx,
                                       nsNPAPIPluginInstance *plugin_inst,
                                       JS::MutableHandle<JSObject*> plugin_obj,
                                       JS::MutableHandle<JSObject*> plugin_proto);
 
     // Utility for firing an error event, if we're an <object>.
--- a/dom/html/HTMLImageElement.cpp
+++ b/dom/html/HTMLImageElement.cpp
@@ -753,60 +753,34 @@ HTMLImageElement::Image(const GlobalObje
         return nullptr;
       }
     }
   }
 
   return img.forget();
 }
 
-NS_IMETHODIMP
-HTMLImageElement::GetNaturalHeight(uint32_t* aNaturalHeight)
-{
-  *aNaturalHeight = NaturalHeight();
-  return NS_OK;
-}
-
 uint32_t
 HTMLImageElement::NaturalHeight()
 {
-  uint32_t height;
-  nsresult rv = nsImageLoadingContent::GetNaturalHeight(&height);
-
-  if (NS_FAILED(rv)) {
-    MOZ_ASSERT(false, "GetNaturalHeight should not fail");
-    return 0;
-  }
+  uint32_t height = nsImageLoadingContent::NaturalHeight();
 
   if (mResponsiveSelector) {
     double density = mResponsiveSelector->GetSelectedImageDensity();
     MOZ_ASSERT(density >= 0.0);
     height = NSToIntRound(double(height) / density);
   }
 
   return height;
 }
 
-NS_IMETHODIMP
-HTMLImageElement::GetNaturalWidth(uint32_t* aNaturalWidth)
-{
-  *aNaturalWidth = NaturalWidth();
-  return NS_OK;
-}
-
 uint32_t
 HTMLImageElement::NaturalWidth()
 {
-  uint32_t width;
-  nsresult rv = nsImageLoadingContent::GetNaturalWidth(&width);
-
-  if (NS_FAILED(rv)) {
-    MOZ_ASSERT(false, "GetNaturalWidth should not fail");
-    return 0;
-  }
+  uint32_t width = nsImageLoadingContent::NaturalWidth();
 
   if (mResponsiveSelector) {
     double density = mResponsiveSelector->GetSelectedImageDensity();
     MOZ_ASSERT(density >= 0.0);
     width = NSToIntRound(double(width) / density);
   }
 
   return width;
--- a/dom/html/HTMLImageElement.h
+++ b/dom/html/HTMLImageElement.h
@@ -82,21 +82,16 @@ public:
   virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
 
   virtual void NodeInfoChanged(nsIDocument* aOldDoc) override;
 
   nsresult CopyInnerTo(HTMLImageElement* aDest);
 
   void MaybeLoadImage(bool aAlwaysForceLoad);
 
-  // Overrides for nsImageLoadingContent's GetNaturalHeight/Width, since we
-  // handle responsive scaling in the element's version of these methods.
-  NS_IMETHOD GetNaturalHeight(uint32_t* aNaturalHeight) override;
-  NS_IMETHOD GetNaturalWidth(uint32_t* aNaturalWidth) override;
-
   bool IsMap()
   {
     return GetBoolAttr(nsGkAtoms::ismap);
   }
   void SetIsMap(bool aIsMap, ErrorResult& aError)
   {
     SetHTMLBoolAttr(nsGkAtoms::ismap, aIsMap, aError);
   }
--- a/dom/html/HTMLObjectElement.cpp
+++ b/dom/html/HTMLObjectElement.cpp
@@ -407,20 +407,20 @@ HTMLObjectElement::SubmitNamesValues(HTM
 
   nsIObjectFrame *objFrame = do_QueryFrame(frame);
   if (!objFrame) {
     // No frame, nothing to submit.
 
     return NS_OK;
   }
 
-  RefPtr<nsNPAPIPluginInstance> pi;
-  objFrame->GetPluginInstance(getter_AddRefs(pi));
-  if (!pi)
+  RefPtr<nsNPAPIPluginInstance> pi = objFrame->GetPluginInstance();
+  if (!pi) {
     return NS_OK;
+  }
 
   nsAutoString value;
   nsresult rv = pi->GetFormValue(value);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return aFormSubmission->AddNameValuePair(name, value);
 }
 
--- a/dom/html/PluginDocument.cpp
+++ b/dom/html/PluginDocument.cpp
@@ -266,18 +266,17 @@ PluginDocument::CreateSyntheticPluginDoc
 NS_IMETHODIMP
 PluginDocument::Print()
 {
   NS_ENSURE_TRUE(mPluginContent, NS_ERROR_FAILURE);
 
   nsIObjectFrame* objectFrame =
     do_QueryFrame(mPluginContent->GetPrimaryFrame());
   if (objectFrame) {
-    RefPtr<nsNPAPIPluginInstance> pi;
-    objectFrame->GetPluginInstance(getter_AddRefs(pi));
+    RefPtr<nsNPAPIPluginInstance> pi = objectFrame->GetPluginInstance();
     if (pi) {
       NPPrint npprint;
       npprint.mode = NP_FULL;
       npprint.print.fullPrint.pluginPrinted = false;
       npprint.print.fullPrint.printOne = false;
       npprint.print.fullPrint.platformPrint = nullptr;
 
       pi->Print(&npprint);
--- a/dom/plugins/base/nsIPluginInstanceOwner.idl
+++ b/dom/plugins/base/nsIPluginInstanceOwner.idl
@@ -31,17 +31,17 @@ interface nsIPluginInstanceOwner : nsISu
   /**
    * Let the owner know what its instance is
    */
   void setInstance(in nsNPAPIPluginInstancePtr aInstance);
 
   /**
    * Get the instance associated with this owner.
    */
-  nsNPAPIPluginInstancePtr getInstance();
+  [notxpcom, nostdcall] nsNPAPIPluginInstancePtr getInstance();
 
   /**
    * Get a handle to the window structure of the owner.
    * This pointer cannot be made persistent by the caller.
    */
   void getWindow(in NPWindowStarRef aWindow);
 
   /**
--- a/dom/plugins/base/nsPluginHost.cpp
+++ b/dom/plugins/base/nsPluginHost.cpp
@@ -824,22 +824,17 @@ nsPluginHost::InstantiatePluginInstance(
   }
 
   rv = SetUpPluginInstance(aMimeType, aURL, instanceOwner);
   if (NS_FAILED(rv)) {
     instanceOwner->Destroy();
     return NS_ERROR_FAILURE;
   }
 
-  RefPtr<nsNPAPIPluginInstance> instance;
-  rv = instanceOwner->GetInstance(getter_AddRefs(instance));
-  if (NS_FAILED(rv)) {
-    instanceOwner->Destroy();
-    return rv;
-  }
+  RefPtr<nsNPAPIPluginInstance> instance = instanceOwner->GetInstance();
 
   if (instance) {
     CreateWidget(instanceOwner);
   }
 
   // At this point we consider instantiation to be successful. Do not return an error.
   instanceOwner.forget(aOwner);
 
--- a/dom/plugins/base/nsPluginInstanceOwner.cpp
+++ b/dom/plugins/base/nsPluginInstanceOwner.cpp
@@ -389,23 +389,20 @@ void nsPluginInstanceOwner::GetAttribute
   loadingContent->GetPluginAttributes(attributes);
 }
 
 NS_IMETHODIMP nsPluginInstanceOwner::GetDOMElement(Element** result)
 {
   return CallQueryReferent(mContent.get(), result);
 }
 
-nsresult nsPluginInstanceOwner::GetInstance(nsNPAPIPluginInstance **aInstance)
+nsNPAPIPluginInstance*
+nsPluginInstanceOwner::GetInstance()
 {
-  NS_ENSURE_ARG_POINTER(aInstance);
-
-  *aInstance = mInstance;
-  NS_IF_ADDREF(*aInstance);
-  return NS_OK;
+  return mInstance;
 }
 
 NS_IMETHODIMP nsPluginInstanceOwner::GetURL(const char *aURL,
                                             const char *aTarget,
                                             nsIInputStream *aPostStream,
                                             void *aHeadersData,
                                             uint32_t aHeadersDataLen,
                                             bool aDoCheckLoadURIChecks)
--- a/layout/generic/nsIObjectFrame.h
+++ b/layout/generic/nsIObjectFrame.h
@@ -17,17 +17,17 @@
 class nsNPAPIPluginInstance;
 class nsIWidget;
 
 class nsIObjectFrame : public nsQueryFrame
 {
 public:
   NS_DECL_QUERYFRAME_TARGET(nsIObjectFrame)
 
-  NS_IMETHOD GetPluginInstance(nsNPAPIPluginInstance** aPluginInstance) = 0;
+  virtual nsNPAPIPluginInstance* GetPluginInstance() = 0;
 
   /**
    * Get the native widget for the plugin, if any.
    */
   virtual nsIWidget* GetWidget() = 0;
 
   /**
    * Update plugin active state. Frame should update if it is on an active tab
--- a/layout/generic/nsPluginFrame.cpp
+++ b/layout/generic/nsPluginFrame.cpp
@@ -592,18 +592,17 @@ nsPluginFrame::FixupWindow(const nsSize&
 nsresult
 nsPluginFrame::CallSetWindow(bool aCheckIsHidden)
 {
   NPWindow *win = nullptr;
 
   nsresult rv = NS_ERROR_FAILURE;
   RefPtr<nsNPAPIPluginInstance> pi;
   if (!mInstanceOwner ||
-      NS_FAILED(rv = mInstanceOwner->GetInstance(getter_AddRefs(pi))) ||
-      !pi ||
+      !(pi = mInstanceOwner->GetInstance()) ||
       NS_FAILED(rv = mInstanceOwner->GetWindow(win)) ||
       !win)
     return rv;
 
   nsPluginNativeWindow *window = (nsPluginNativeWindow *)win;
 
   if (aCheckIsHidden && IsHidden())
     return NS_ERROR_FAILURE;
@@ -1119,21 +1118,20 @@ nsPluginFrame::IsTransparentMode() const
   mInstanceOwner->GetWindow(window);
   if (!window) {
     return false;
   }
 
   if (window->type != NPWindowTypeDrawable)
     return false;
 
-  nsresult rv;
-  RefPtr<nsNPAPIPluginInstance> pi;
-  rv = mInstanceOwner->GetInstance(getter_AddRefs(pi));
-  if (NS_FAILED(rv) || !pi)
+  RefPtr<nsNPAPIPluginInstance> pi = mInstanceOwner->GetInstance();
+  if (!pi) {
     return false;
+  }
 
   bool transparent = false;
   pi->IsTransparent(&transparent);
   return transparent;
 #endif
 }
 
 void
@@ -1225,19 +1223,20 @@ nsPluginFrame::PrintPlugin(gfxContext& a
   // we may need to go through the children to get it
   nsIObjectFrame* objectFrame = do_QueryFrame(frame);
   if (!objectFrame)
     objectFrame = GetNextObjectFrame(presContext,frame);
   if (!objectFrame)
     return;
 
   // finally we can get our plugin instance
-  RefPtr<nsNPAPIPluginInstance> pi;
-  if (NS_FAILED(objectFrame->GetPluginInstance(getter_AddRefs(pi))) || !pi)
+  RefPtr<nsNPAPIPluginInstance> pi = objectFrame->GetPluginInstance();
+  if (!pi) {
     return;
+  }
 
   // now we need to setup the correct location for printing
   NPWindow window;
   window.window = nullptr;
 
   // prepare embedded mode printing struct
   NPPrint npprint;
   npprint.mode = NP_EMBED;
@@ -1692,37 +1691,34 @@ nsPluginFrame::WantsToHandleWheelEventAs
   // On Windows, only when the plugin is windowless, we need to send wheel
   // events as default action.
   return window->type == NPWindowTypeDrawable;
 #else
   return false;
 #endif
 }
 
-nsresult
-nsPluginFrame::GetPluginInstance(nsNPAPIPluginInstance** aPluginInstance)
+nsNPAPIPluginInstance*
+nsPluginFrame::GetPluginInstance()
 {
-  *aPluginInstance = nullptr;
-
   if (!mInstanceOwner) {
-    return NS_OK;
+    return nullptr;
   }
 
-  return mInstanceOwner->GetInstance(aPluginInstance);
+  return mInstanceOwner->GetInstance();
 }
 
 nsresult
 nsPluginFrame::GetCursor(const nsPoint& aPoint, nsIFrame::Cursor& aCursor)
 {
   if (!mInstanceOwner) {
     return NS_ERROR_FAILURE;
   }
 
-  RefPtr<nsNPAPIPluginInstance> inst;
-  mInstanceOwner->GetInstance(getter_AddRefs(inst));
+  RefPtr<nsNPAPIPluginInstance> inst = mInstanceOwner->GetInstance();
   if (!inst) {
     return NS_ERROR_FAILURE;
   }
 
   bool useDOMCursor = static_cast<nsNPAPIPluginInstance*>(inst.get())->UsesDOMForCursor();
   if (!useDOMCursor) {
     return NS_ERROR_FAILURE;
   }
@@ -1740,20 +1736,19 @@ nsPluginFrame::SetIsDocumentActive(bool 
 
 // static
 nsIObjectFrame *
 nsPluginFrame::GetNextObjectFrame(nsPresContext* aPresContext, nsIFrame* aRoot)
 {
   for (nsIFrame* child : aRoot->PrincipalChildList()) {
     nsIObjectFrame* outFrame = do_QueryFrame(child);
     if (outFrame) {
-      RefPtr<nsNPAPIPluginInstance> pi;
-      outFrame->GetPluginInstance(getter_AddRefs(pi));  // make sure we have a REAL plugin
-      if (pi)
+      if (outFrame->GetPluginInstance()) { // make sure we have a REAL plugin
         return outFrame;
+      }
     }
 
     outFrame = GetNextObjectFrame(aPresContext, child);
     if (outFrame)
       return outFrame;
   }
 
   return nullptr;
--- a/layout/generic/nsPluginFrame.h
+++ b/layout/generic/nsPluginFrame.h
@@ -100,17 +100,17 @@ public:
 #ifdef DEBUG_FRAME_DUMP
   virtual nsresult GetFrameName(nsAString& aResult) const override;
 #endif
 
   virtual void DestroyFrom(nsIFrame* aDestructRoot, PostDestroyData& aPostDestroyData) override;
 
   virtual void DidSetComputedStyle(ComputedStyle* aOldComputedStyle) override;
 
-  NS_IMETHOD GetPluginInstance(nsNPAPIPluginInstance** aPluginInstance) override;
+  nsNPAPIPluginInstance* GetPluginInstance() override;
 
   virtual void SetIsDocumentActive(bool aIsActive) override;
 
   virtual nsresult GetCursor(const nsPoint& aPoint,
                              nsIFrame::Cursor& aCursor) override;
 
   // APIs used by nsRootPresContext to set up the widget position/size/clip
   // region.