Bug 637253: Remove nsIPluginInstance interface. r=bsmedberg
authorJosh Aas <joshmoz@gmail.com>
Tue, 17 May 2011 21:48:34 -0400
changeset 69892 5ffdf4967deca4a6de8ca3f6ead80e7ea3df4a65
parent 69891 a34c75072a5bf3d9de5599040b04fefc476c2e45
child 69893 676006c214ad329a115a7e5fc7c1a9315b0ae901
push id76
push userbzbarsky@mozilla.com
push dateTue, 05 Jul 2011 17:00:57 +0000
treeherdermozilla-beta@d3a2732c35f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs637253
milestone6.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 637253: Remove nsIPluginInstance interface. r=bsmedberg
accessible/src/base/nsAccessibilityService.cpp
caps/src/nsScriptSecurityManager.cpp
content/base/public/nsIObjectLoadingContent.idl
content/base/src/nsObjectLoadingContent.cpp
content/html/content/src/nsHTMLObjectElement.cpp
content/html/document/src/nsPluginDocument.cpp
dom/base/nsDOMClassInfo.cpp
dom/base/nsDOMClassInfo.h
dom/base/nsGlobalWindow.cpp
dom/plugins/base/Makefile.in
dom/plugins/base/nsIPluginHost.idl
dom/plugins/base/nsIPluginInstance.idl
dom/plugins/base/nsIPluginInstanceOwner.idl
dom/plugins/base/nsJSNPRuntime.cpp
dom/plugins/base/nsNPAPIPlugin.cpp
dom/plugins/base/nsNPAPIPlugin.h
dom/plugins/base/nsNPAPIPluginInstance.cpp
dom/plugins/base/nsNPAPIPluginInstance.h
dom/plugins/base/nsPluginHost.cpp
dom/plugins/base/nsPluginHost.h
dom/plugins/base/nsPluginNativeWindow.h
dom/plugins/base/nsPluginNativeWindowGtk2.cpp
dom/plugins/base/nsPluginNativeWindowQt.cpp
dom/plugins/base/nsPluginNativeWindowWin.cpp
dom/plugins/base/nsPluginSafety.h
dom/plugins/base/nsPluginStreamListenerPeer.cpp
layout/base/nsPresShell.cpp
layout/generic/nsIObjectFrame.h
layout/generic/nsObjectFrame.cpp
layout/generic/nsObjectFrame.h
widget/src/cocoa/nsChildView.mm
--- a/accessible/src/base/nsAccessibilityService.cpp
+++ b/accessible/src/base/nsAccessibilityService.cpp
@@ -63,17 +63,17 @@
 #include "nsIDOMHTMLObjectElement.h"
 #include "nsIDOMHTMLOptGroupElement.h"
 #include "nsIDOMHTMLOptionElement.h"
 #include "nsIDOMXULElement.h"
 #include "nsIHTMLDocument.h"
 #include "nsImageFrame.h"
 #include "nsILink.h"
 #include "nsIObserverService.h"
-#include "nsIPluginInstance.h"
+#include "nsNPAPIPluginInstance.h"
 #include "nsISupportsUtils.h"
 #include "nsObjectFrame.h"
 #include "nsOuterDocAccessible.h"
 #include "nsRootAccessibleWrap.h"
 #include "nsTextFragment.h"
 #include "mozilla/Services.h"
 #include "nsEventStates.h"
 
@@ -341,18 +341,18 @@ nsAccessibilityService::CreateHTMLObject
     nsCOMPtr<nsIDOMDocument> domDoc;
     obj->GetContentDocument(getter_AddRefs(domDoc));
     if (domDoc)
       return CreateOuterDocAccessible(aContent, aPresShell);
   }
 
 #if defined(XP_WIN) || defined(MOZ_ACCESSIBILITY_ATK)
   // 2) for plugins
-  nsCOMPtr<nsIPluginInstance> pluginInstance;
-  if (NS_SUCCEEDED(aFrame->GetPluginInstance(*getter_AddRefs(pluginInstance))) &&
+  nsRefPtr<nsNPAPIPluginInstance> pluginInstance;
+  if (NS_SUCCEEDED(aFrame->GetPluginInstance(getter_AddRefs(pluginInstance))) &&
       pluginInstance) {
 #ifdef XP_WIN
     // Note: pluginPort will be null if windowless.
     HWND pluginPort = nsnull;
     aFrame->GetPluginPort(&pluginPort);
 
     nsAccessible* accessible = new nsHTMLWin32ObjectOwnerAccessible(aContent,
                                                                     weakShell,
--- a/caps/src/nsScriptSecurityManager.cpp
+++ b/caps/src/nsScriptSecurityManager.cpp
@@ -67,17 +67,16 @@
 #include "nsTextFormatter.h"
 #include "nsIStringBundle.h"
 #include "nsNetUtil.h"
 #include "nsIProperties.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsIFile.h"
 #include "nsIFileURL.h"
 #include "nsIZipReader.h"
-#include "nsIPluginInstance.h"
 #include "nsIXPConnect.h"
 #include "nsIScriptGlobalObject.h"
 #include "nsPIDOMWindow.h"
 #include "nsIDocShell.h"
 #include "nsIDocShellTreeItem.h"
 #include "nsIPrompt.h"
 #include "nsIWindowWatcher.h"
 #include "nsIConsoleService.h"
@@ -3284,37 +3283,16 @@ nsScriptSecurityManager::CheckXPCPermiss
         {
             PRBool canAccess = PR_FALSE;
             if (NS_SUCCEEDED(IsCapabilityEnabled(aObjectSecurityLevel, &canAccess)) &&
                 canAccess)
                 return NS_OK;
         }
     }
 
-    //-- If user allows scripting of plugins by untrusted scripts,
-    //   and the target object is a plugin, allow the access.
-    if(aObj)
-    {
-        nsresult rv;
-        nsCOMPtr<nsIPluginInstance> plugin(do_QueryInterface(aObj, &rv));
-        if (NS_SUCCEEDED(rv))
-        {
-            static PRBool prefSet = PR_FALSE;
-            static PRBool allowPluginAccess = PR_FALSE;
-            if (!prefSet)
-            {
-                rv = mPrefBranch->GetBoolPref("security.xpconnect.plugin.unrestricted",
-                                                       &allowPluginAccess);
-                prefSet = PR_TRUE;
-            }
-            if (allowPluginAccess)
-                return NS_OK;
-        }
-    }
-
     //-- Access tests failed
     return NS_ERROR_DOM_XPCONNECT_ACCESS_DENIED;
 }
 
 /////////////////////////////////////////////
 // Method implementing nsIChannelEventSink //
 /////////////////////////////////////////////
 NS_IMETHODIMP
--- a/content/base/public/nsIObjectLoadingContent.idl
+++ b/content/base/public/nsIObjectLoadingContent.idl
@@ -34,21 +34,25 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsISupports.idl"
 
 interface nsIFrame;
 interface nsIObjectFrame;
-interface nsIPluginInstance;
 interface nsIPluginTag;
 interface nsIDOMElement;
 interface nsIDOMClientRect;
 
+%{C++
+#include "nsNPAPIPluginInstance.h"
+%}
+[ptr] native nsNPAPIPluginInstancePtr(nsNPAPIPluginInstance);
+
 /**
  * This interface represents a content node that loads objects.
  */
 [scriptable, uuid(9558649a-7255-4b00-afb4-1171e9cdcead)]
 interface nsIObjectLoadingContent : nsISupports
 {
   const unsigned long TYPE_LOADING  = 0;
   const unsigned long TYPE_IMAGE    = 1;
@@ -75,17 +79,17 @@ interface nsIObjectLoadingContent : nsIS
    */
   unsigned long getContentTypeForMIMEType(in AUTF8String aMimeType);
 
   /**
    * 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 nsIPluginInstance pluginInstance;
+  [noscript] readonly attribute nsNPAPIPluginInstancePtr pluginInstance;
 
   /**
    * Makes sure that a frame for this object exists, and that the plugin is
    * instantiated. This method does nothing if the type is not #TYPE_PLUGIN.
    * There is no guarantee that there will be a frame after this method is
    * called; for example, the node may have a display:none style. If plugin
    * instantiation is possible, it will be done synchronously by this method,
    * and the plugin instance will be returned. A success return value does not
@@ -93,17 +97,17 @@ interface nsIObjectLoadingContent : nsIS
    *
    * This is a noscript method because it is internal and will go away once
    * plugin loading moves to content.
    *
    * @note If there is an error instantiating the plugin, this method will
    * trigger fallback to replacement content, and the type will change (and
    * this method will return a failure code)
    */
-  [noscript] nsIPluginInstance ensureInstantiation();
+  [noscript] nsNPAPIPluginInstancePtr ensureInstantiation();
 
   /**
    * 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/content/base/src/nsObjectLoadingContent.cpp
+++ b/content/base/src/nsObjectLoadingContent.cpp
@@ -51,18 +51,17 @@
 #include "nsIDocument.h"
 #include "nsIDOMDataContainerEvent.h"
 #include "nsIDOMDocumentEvent.h"
 #include "nsIDOMEventTarget.h"
 #include "nsIExternalProtocolHandler.h"
 #include "nsEventStates.h"
 #include "nsIObjectFrame.h"
 #include "nsIPluginDocument.h"
-#include "nsIPluginHost.h"
-#include "nsIPluginInstance.h"
+#include "nsPluginHost.h"
 #include "nsIPresShell.h"
 #include "nsIPrivateDOMEvent.h"
 #include "nsIScriptGlobalObject.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsIStreamConverterService.h"
 #include "nsIURILoader.h"
 #include "nsIURL.h"
 #include "nsIWebNavigation.h"
@@ -839,17 +838,17 @@ NS_IMETHODIMP
 nsObjectLoadingContent::GetDisplayedType(PRUint32* aType)
 {
   *aType = mType;
   return NS_OK;
 }
 
 
 NS_IMETHODIMP
-nsObjectLoadingContent::EnsureInstantiation(nsIPluginInstance** aInstance)
+nsObjectLoadingContent::EnsureInstantiation(nsNPAPIPluginInstance** aInstance)
 {
   // Must set our out parameter to null as we have various early returns with
   // an NS_OK result.
   *aInstance = nsnull;
 
   if (mType != eType_Plugin) {
     return NS_OK;
   }
@@ -907,21 +906,21 @@ nsObjectLoadingContent::EnsureInstantiat
     }
 
     nsiframe = do_QueryFrame(frame);
   }
 
   nsWeakFrame weakFrame(nsiframe);
 
   // We may have a plugin instance already; if so, do nothing
-  nsresult rv = frame->GetPluginInstance(*aInstance);
+  nsresult rv = frame->GetPluginInstance(aInstance);
   if (!*aInstance && weakFrame.IsAlive()) {
     rv = Instantiate(frame, mContentType, mURI);
     if (NS_SUCCEEDED(rv) && weakFrame.IsAlive()) {
-      rv = frame->GetPluginInstance(*aInstance);
+      rv = frame->GetPluginInstance(aInstance);
     } else {
       Fallback(PR_TRUE);
     }
   }
   return rv;
 }
 
 NS_IMETHODIMP
@@ -937,18 +936,18 @@ nsObjectLoadingContent::HasNewFrame(nsIO
   if (!doc || doc->IsStaticDocument() || doc->IsBeingUsedAsImage()) {
     return NS_OK;
   }
 
   // "revoke" any existing instantiate event as it likely has out of
   // date data (frame pointer etc).
   mPendingInstantiateEvent = nsnull;
 
-  nsCOMPtr<nsIPluginInstance> instance;
-  aFrame->GetPluginInstance(*getter_AddRefs(instance));
+  nsRefPtr<nsNPAPIPluginInstance> instance;
+  aFrame->GetPluginInstance(getter_AddRefs(instance));
 
   if (instance) {
     // The frame already has a plugin instance, that means the plugin
     // has already been instantiated.
 
     return NS_OK;
   }
 
@@ -985,26 +984,26 @@ nsObjectLoadingContent::HasNewFrame(nsIO
       // when the event runs.
       mPendingInstantiateEvent = event;
     }
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsObjectLoadingContent::GetPluginInstance(nsIPluginInstance** aInstance)
+nsObjectLoadingContent::GetPluginInstance(nsNPAPIPluginInstance** aInstance)
 {
   *aInstance = nsnull;
 
   nsIObjectFrame* objFrame = GetExistingFrame(eDontFlush);
   if (!objFrame) {
     return NS_OK;
   }
 
-  return objFrame->GetPluginInstance(*aInstance);
+  return objFrame->GetPluginInstance(aInstance);
 }
 
 NS_IMETHODIMP
 nsObjectLoadingContent::GetContentTypeForMIMEType(const nsACString& aMIMEType,
                                                   PRUint32* aType)
 {
   *aType = GetTypeOfContent(PromiseFlatCString(aMIMEType));
   return NS_OK;
@@ -1829,18 +1828,18 @@ nsObjectLoadingContent::TryInstantiate(c
                                        nsIURI* aURI)
 {
   nsIObjectFrame* frame = GetExistingFrame(eFlushContent);
   if (!frame) {
     LOG(("OBJLC [%p]: No frame yet\n", this));
     return NS_OK; // Not a failure to have no frame
   }
 
-  nsCOMPtr<nsIPluginInstance> instance;
-  frame->GetPluginInstance(*getter_AddRefs(instance));
+  nsRefPtr<nsNPAPIPluginInstance> instance;
+  frame->GetPluginInstance(getter_AddRefs(instance));
 
   if (!instance) {
     // The frame has no plugin instance yet. If the frame hasn't been
     // reflowed yet, do nothing as once the reflow happens we'll end up
     // instantiating the plugin with the correct size n' all (which
     // isn't known until we've done the first reflow). But if the
     // frame does have a plugin instance already, be sure to
     // re-instantiate the plugin as its source or whatnot might have
@@ -1894,24 +1893,25 @@ nsObjectLoadingContent::Instantiate(nsIO
   // We'll always have a type or a URI by the time we get here
   NS_ASSERTION(aURI || !typeToUse.IsEmpty(), "Need a URI or a type");
   LOG(("OBJLC [%p]: Calling [%p]->Instantiate(<%s>, %p)\n", this, aFrame,
        typeToUse.get(), aURI));
   nsresult rv = aFrame->Instantiate(typeToUse.get(), aURI);
 
   mInstantiating = oldInstantiatingValue;
 
-  nsCOMPtr<nsIPluginInstance> pluginInstance;
+  nsRefPtr<nsNPAPIPluginInstance> pluginInstance;
   if (weakFrame.IsAlive()) {
-    aFrame->GetPluginInstance(*getter_AddRefs(pluginInstance));
+    aFrame->GetPluginInstance(getter_AddRefs(pluginInstance));
   }
   if (pluginInstance) {
     nsCOMPtr<nsIPluginTag> pluginTag;
     nsCOMPtr<nsIPluginHost> host(do_GetService(MOZ_PLUGIN_HOST_CONTRACTID));
-    host->GetPluginTagForInstance(pluginInstance, getter_AddRefs(pluginTag));
+    static_cast<nsPluginHost*>(host.get())->
+      GetPluginTagForInstance(pluginInstance, getter_AddRefs(pluginTag));
 
     nsCOMPtr<nsIBlocklistService> blocklist =
       do_GetService("@mozilla.org/extensions/blocklist;1");
     if (blocklist) {
       PRUint32 blockState = nsIBlocklistService::STATE_NOT_BLOCKED;
       blocklist->GetPluginBlocklistState(pluginTag, EmptyString(),
                                          EmptyString(), &blockState);
       if (blockState == nsIBlocklistService::STATE_OUTDATED)
--- a/content/html/content/src/nsHTMLObjectElement.cpp
+++ b/content/html/content/src/nsHTMLObjectElement.cpp
@@ -31,30 +31,31 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "nsAutoPtr.h"
 #include "nsGenericHTMLElement.h"
 #include "nsObjectLoadingContent.h"
 #include "nsGkAtoms.h"
 #include "nsDOMError.h"
 #include "nsIDocument.h"
 #include "nsIDOMDocument.h"
 #ifdef MOZ_SVG
 #include "nsIDOMSVGDocument.h"
 #include "nsIDOMGetSVGDocument.h"
 #endif
 #include "nsIDOMHTMLObjectElement.h"
 #include "nsFormSubmission.h"
 #include "nsIObjectFrame.h"
-#include "nsIPluginInstance.h"
+#include "nsNPAPIPluginInstance.h"
 #include "nsIConstraintValidation.h"
 
 using namespace mozilla::dom;
 
 class nsHTMLObjectElement : public nsGenericHTMLFormElement
                           , public nsObjectLoadingContent
                           , public nsIDOMHTMLObjectElement
                           , public nsIConstraintValidation
@@ -391,18 +392,18 @@ nsHTMLObjectElement::SubmitNamesValues(n
 
   nsIObjectFrame *objFrame = do_QueryFrame(frame);
   if (!objFrame) {
     // No frame, nothing to submit.
 
     return NS_OK;
   }
 
-  nsCOMPtr<nsIPluginInstance> pi;
-  objFrame->GetPluginInstance(*getter_AddRefs(pi));
+  nsRefPtr<nsNPAPIPluginInstance> pi;
+  objFrame->GetPluginInstance(getter_AddRefs(pi));
   if (!pi)
     return NS_OK;
 
   nsAutoString value;
   nsresult rv = pi->GetFormValue(value);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return aFormSubmission->AddNameValuePair(name, value);
--- a/content/html/document/src/nsPluginDocument.cpp
+++ b/content/html/document/src/nsPluginDocument.cpp
@@ -35,17 +35,17 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsMediaDocument.h"
 #include "nsIPluginDocument.h"
 #include "nsGkAtoms.h"
 #include "nsIPresShell.h"
 #include "nsIObjectFrame.h"
-#include "nsIPluginInstance.h"
+#include "nsNPAPIPluginInstance.h"
 #include "nsIDocShellTreeItem.h"
 #include "nsNodeInfoManager.h"
 #include "nsContentCreatorFunctions.h"
 #include "nsContentPolicyUtils.h"
 #include "nsIPropertyBag2.h"
 #include "mozilla/dom/Element.h"
 
 using namespace mozilla::dom;
@@ -347,19 +347,18 @@ nsPluginDocument::SetStreamListener(nsIS
 NS_IMETHODIMP
 nsPluginDocument::Print()
 {
   NS_ENSURE_TRUE(mPluginContent, NS_ERROR_FAILURE);
 
   nsIObjectFrame* objectFrame =
     do_QueryFrame(mPluginContent->GetPrimaryFrame());
   if (objectFrame) {
-    nsCOMPtr<nsIPluginInstance> pi;
-    objectFrame->GetPluginInstance(*getter_AddRefs(pi));
-
+    nsCOMPtr<nsNPAPIPluginInstance> pi;
+    objectFrame->GetPluginInstance(getter_AddRefs(pi));
     if (pi) {
       NPPrint npprint;
       npprint.mode = NP_FULL;
       npprint.print.fullPrint.pluginPrinted = PR_FALSE;
       npprint.print.fullPrint.printOne = PR_FALSE;
       npprint.print.fullPrint.platformPrint = nsnull;
 
       pi->Print(&npprint);
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -145,17 +145,17 @@
 
 // Constraint Validation API helper includes
 #include "nsIDOMValidityState.h"
 
 // HTMLSelectElement helper includes
 #include "nsIDOMHTMLSelectElement.h"
 
 // HTMLEmbed/ObjectElement helper includes
-#include "nsIPluginInstance.h"
+#include "nsNPAPIPluginInstance.h"
 #include "nsIObjectFrame.h"
 #include "nsIObjectLoadingContent.h"
 #include "nsIPluginHost.h"
 
 // Oh, did I mention that I hate Microsoft for doing this to me?
 #ifdef XP_WIN
 #undef GetClassName
 #endif
@@ -9693,17 +9693,17 @@ nsHTMLSelectElementSH::SetProperty(nsIXP
 
 
 // HTMLObject/EmbedElement helper
 
 // static
 nsresult
 nsHTMLPluginObjElementSH::GetPluginInstanceIfSafe(nsIXPConnectWrappedNative *wrapper,
                                                   JSObject *obj,
-                                                  nsIPluginInstance **_result)
+                                                  nsNPAPIPluginInstance **_result)
 {
   *_result = nsnull;
 
   nsCOMPtr<nsIContent> content(do_QueryWrappedNative(wrapper, obj));
   NS_ENSURE_TRUE(content, NS_ERROR_UNEXPECTED);
 
   nsCOMPtr<nsIObjectLoadingContent> objlc(do_QueryInterface(content));
   NS_ASSERTION(objlc, "Object nodes must implement nsIObjectLoadingContent");
@@ -9796,17 +9796,17 @@ nsHTMLPluginObjElementSH::SetupProtoChai
 
   JSAutoRequest ar(cx);
 
   JSAutoEnterCompartment ac;
   if (!ac.enter(cx, obj)) {
     return NS_ERROR_UNEXPECTED;
   }
 
-  nsCOMPtr<nsIPluginInstance> pi;
+  nsRefPtr<nsNPAPIPluginInstance> pi;
   nsresult rv = GetPluginInstanceIfSafe(wrapper, obj, getter_AddRefs(pi));
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (!pi) {
     // No plugin around for this object.
 
     return NS_OK;
   }
@@ -10013,17 +10013,17 @@ nsHTMLPluginObjElementSH::SetProperty(ns
   return nsElementSH::SetProperty(wrapper, cx, obj, id, vp, _retval);
 }
 
 NS_IMETHODIMP
 nsHTMLPluginObjElementSH::Call(nsIXPConnectWrappedNative *wrapper,
                                JSContext *cx, JSObject *obj, PRUint32 argc,
                                jsval *argv, jsval *vp, PRBool *_retval)
 {
-  nsCOMPtr<nsIPluginInstance> pi;
+  nsRefPtr<nsNPAPIPluginInstance> pi;
   nsresult rv = GetPluginInstanceIfSafe(wrapper, obj, getter_AddRefs(pi));
   NS_ENSURE_SUCCESS(rv, rv);
 
   // If obj is a native wrapper, or if there's no plugin around for
   // this object, throw.
   if (ObjectIsNativeWrapper(cx, obj) || !pi) {
     return NS_ERROR_NOT_AVAILABLE;
   }
@@ -10045,17 +10045,17 @@ nsHTMLPluginObjElementSH::Call(nsIXPConn
   *_retval = ::JS::Call(cx, argv[-1], pi_obj, argc, argv, vp);
 
   return NS_OK;
 }
 
 
 nsresult
 nsHTMLPluginObjElementSH::GetPluginJSObject(JSContext *cx, JSObject *obj,
-                                            nsIPluginInstance *plugin_inst,
+                                            nsNPAPIPluginInstance *plugin_inst,
                                             JSObject **plugin_obj,
                                             JSObject **plugin_proto)
 {
   *plugin_obj = nsnull;
   *plugin_proto = nsnull;
 
   JSAutoRequest ar(cx);
 
@@ -10081,17 +10081,17 @@ NS_IMETHODIMP
 nsHTMLPluginObjElementSH::NewResolve(nsIXPConnectWrappedNative *wrapper,
                                      JSContext *cx, JSObject *obj, jsid id,
                                      PRUint32 flags, JSObject **objp,
                                      PRBool *_retval)
 {
   // Make sure the plugin instance is loaded and instantiated, if
   // possible.
 
-  nsCOMPtr<nsIPluginInstance> pi;
+  nsRefPtr<nsNPAPIPluginInstance> pi;
   nsresult rv = GetPluginInstanceIfSafe(wrapper, obj, getter_AddRefs(pi));
   NS_ENSURE_SUCCESS(rv, rv);
 
   return nsElementSH::NewResolve(wrapper, cx, obj, id, flags, objp,
                                  _retval);
 }
  
 // HTMLOptionsCollection helper
--- a/dom/base/nsDOMClassInfo.h
+++ b/dom/base/nsDOMClassInfo.h
@@ -67,17 +67,17 @@ class nsIDOMSVGPathSeg;
 class nsIDOMSVGPathSegList;
 class nsIDOMSVGPoint;
 class nsIDOMSVGPointList;
 class nsIDOMSVGTransform;
 class nsIDOMSVGTransformList;
 class nsIDOMWindow;
 class nsIForm;
 class nsIHTMLDocument;
-class nsIPluginInstance;
+class nsNPAPIPluginInstance;
 class nsSVGTransformList;
 
 struct nsDOMClassInfoData;
 
 typedef nsIClassInfo* (*nsDOMClassInfoConstructorFnc)
   (nsDOMClassInfoData* aData);
 
 typedef nsresult (*nsDOMConstructorFunc)(nsISupports** aNewObject);
@@ -1088,20 +1088,20 @@ protected:
   }
 
   virtual ~nsHTMLPluginObjElementSH()
   {
   }
 
   static nsresult GetPluginInstanceIfSafe(nsIXPConnectWrappedNative *aWrapper,
                                           JSObject *obj,
-                                          nsIPluginInstance **aResult);
+                                          nsNPAPIPluginInstance **aResult);
 
   static nsresult GetPluginJSObject(JSContext *cx, JSObject *obj,
-                                    nsIPluginInstance *plugin_inst,
+                                    nsNPAPIPluginInstance *plugin_inst,
                                     JSObject **plugin_obj,
                                     JSObject **plugin_proto);
 
 public:
   NS_IMETHOD NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
                         JSObject *obj, jsid id, PRUint32 flags,
                         JSObject **objp, PRBool *_retval);
   NS_IMETHOD PreCreate(nsISupports *nativeObj, JSContext *cx,
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -454,17 +454,17 @@ public:
   NPError ShowNativeContextMenu(NPMenu* menu, void* event);
   NPBool ConvertPoint(double sourceX, double sourceY, NPCoordinateSpace sourceSpace,
                       double *destX, double *destY, NPCoordinateSpace destSpace);
   void SendIdleEvent();
 
   NS_DECL_CYCLE_COLLECTION_CLASS(nsDummyJavaPluginOwner)
 
 private:
-  nsCOMPtr<nsIPluginInstance> mInstance;
+  nsRefPtr<nsNPAPIPluginInstance> mInstance;
   nsCOMPtr<nsIDocument> mDocument;
 };
 
 NS_IMPL_CYCLE_COLLECTION_2(nsDummyJavaPluginOwner, mDocument, mInstance)
 
 // QueryInterface implementation for nsDummyJavaPluginOwner
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDummyJavaPluginOwner)
   NS_INTERFACE_MAP_ENTRY(nsISupports)
@@ -484,33 +484,34 @@ nsDummyJavaPluginOwner::Destroy()
     mInstance->InvalidateOwner();
     mInstance = nsnull;
   }
 
   mDocument = nsnull;
 }
 
 NS_IMETHODIMP
-nsDummyJavaPluginOwner::SetInstance(nsIPluginInstance *aInstance)
+nsDummyJavaPluginOwner::SetInstance(nsNPAPIPluginInstance *aInstance)
 {
   // If we're going to null out mInstance after use, be sure to call
   // mInstance->InvalidateOwner() here, since it now won't be called
   // from nsDummyJavaPluginOwner::Destroy().
   if (mInstance && !aInstance)
     mInstance->InvalidateOwner();
 
   mInstance = aInstance;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsDummyJavaPluginOwner::GetInstance(nsIPluginInstance *&aInstance)
-{
-  NS_IF_ADDREF(aInstance = mInstance);
+nsDummyJavaPluginOwner::GetInstance(nsNPAPIPluginInstance **aInstance)
+{
+  NS_IF_ADDREF(mInstance);
+  *aInstance = mInstance;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDummyJavaPluginOwner::GetWindow(NPWindow *&aWindow)
 {
   aWindow = nsnull;
@@ -6565,18 +6566,18 @@ nsGlobalWindow::InitJavaProperties()
   // It's possible for us (or the Java plugin, rather) to process
   // events during the above call, which can lead to this window being
   // torn down or what not, so re-check that the dummy plugin is still
   // around.
   if (!mDummyJavaPluginOwner) {
     return;
   }
 
-  nsCOMPtr<nsIPluginInstance> dummyPlugin;
-  mDummyJavaPluginOwner->GetInstance(*getter_AddRefs(dummyPlugin));
+  nsRefPtr<nsNPAPIPluginInstance> dummyPlugin;
+  mDummyJavaPluginOwner->GetInstance(getter_AddRefs(dummyPlugin));
 
   if (dummyPlugin) {
     // A dummy plugin was instantiated. This means we have a Java
     // plugin that supports NPRuntime. For such a plugin, the plugin
     // instantiation code defines the Java properties for us, so we're
     // done here.
 
     return;
--- a/dom/plugins/base/Makefile.in
+++ b/dom/plugins/base/Makefile.in
@@ -52,17 +52,16 @@ LIBXUL_LIBRARY = 1
 
 EXPORTS_NAMESPACES = mozilla
 
 XPIDLSRCS = \
   nsIHTTPHeaderListener.idl \
   nsIPluginDocument.idl \
   nsIPluginHost.idl \
   nsIPluginInputStream.idl \
-  nsIPluginInstance.idl \
   nsIPluginInstanceOwner.idl \
   nsIPluginStreamInfo.idl \
   nsIPluginStreamListener.idl \
   nsIPluginTag.idl \
   nsIPluginTagInfo.idl \
   nspluginroot.idl \
   $(NULL)
 
@@ -70,16 +69,21 @@ EXPORTS = \
   npapi.h \
   npfunctions.h \
   nptypes.h \
   npruntime.h \
   nsPluginLogging.h \
   nsPluginError.h \
   nsPluginNativeWindow.h \
   nsPluginsCID.h \
+  nsNPAPIPluginInstance.h \
+  nsPluginsDir.h \
+  nsPluginTags.h \
+  nsPluginDirServiceProvider.h \
+  nsPluginHost.h \
   $(NULL)
 
 EXPORTS_mozilla = \
   PluginPRLibrary.h \
   $(NULL)
 
 CPPSRCS		= \
 		nsNPAPIPlugin.cpp \
--- a/dom/plugins/base/nsIPluginHost.idl
+++ b/dom/plugins/base/nsIPluginHost.idl
@@ -58,17 +58,17 @@
 interface nsIURI;
 interface nsIDOMPlugin;
 interface nsIChannel;
 interface nsIPluginStreamListener;
 
 [ptr] native PRLibraryPtr(PRLibrary);
 [ptr] native nsPluginNativeWindowPtr(nsPluginNativeWindow);
 
-[scriptable, uuid(FB2E7827-1E7D-4DCC-93A8-94098A4B588D)]
+[scriptable, uuid(17523504-EC17-4B6A-B803-2B465D26DB44)]
 interface nsIPluginHost : nsISupports
 {
   [noscript] void init();
 
   [noscript] void destroy();
 
   [noscript] void loadPlugins();
 
@@ -100,20 +100,16 @@ interface nsIPluginHost : nsISupports
   [noscript] void isPluginEnabledForExtension(in string aExtension, in constCharStarRef aMimeType);
 
   [noscript] readonly attribute unsigned long pluginCount;
   
   [noscript] void getPlugins(in unsigned long aPluginCount, out /*array*/ nsIDOMPlugin aPluginArray);
 
   void getPluginTags([optional] out unsigned long aPluginCount,
     [retval, array, size_is(aPluginCount)] out nsIPluginTag aResults);
-
-  [noscript] void stopPluginInstance(in nsIPluginInstance aInstance);
-
-  [noscript] void handleBadPlugin(in PRLibraryPtr aLibrary, in nsIPluginInstance instance);
   
   /**
    * Fetches a URL.
    *
    * (Corresponds to NPN_GetURL and NPN_GetURLNotify.)
    *
    * @param pluginInst - the plugin making the request. If NULL, the URL
    *  is fetched in the background.
@@ -246,32 +242,16 @@ interface nsIPluginHost : nsISupports
   /**
    * Instantiate a "dummy" java plugin if a java plugin that supports
    * NPRuntime is installed. This plugin is used for exposing
    * window.java and window.Packages. If the java plugin supports
    * NPRuntime and instantiation was successful, aOwners instance will
    * be non-null, if not, it will be null.
    */
   [noscript] void instantiateDummyJavaPlugin(in nsIPluginInstanceOwner aOwner);
-
-  /**
-   * Get the plugin name for the plugin instance.
-   * @param aInstance the plugin instance object
-   * @param aPluginName returns a pointer to a shared readonly string value,
-   *        it's only valid for the lifetime of the plugin instance - you must
-   *        copy the string value if you need it longer than that.
-   */
-  [noscript] void getPluginName(in nsIPluginInstance aInstance, [shared] out string aPluginName);
-
-  /**
-   * Get the plugin tag associated with a given plugin instance.
-   * @param aInstance the plugin instance object
-   * @return plugin tag object
-   */
-  [noscript] nsIPluginTag getPluginTagForInstance(in nsIPluginInstance aInstance);
   
   [noscript, notxpcom] void addIdleTimeTarget(in nsIPluginInstanceOwner objectFrame, in boolean isVisible);
   [noscript, notxpcom] void removeIdleTimeTarget(in nsIPluginInstanceOwner objectFrame);
 
   /*
    * Flags for use with clearSiteData.
    *
    * FLAG_CLEAR_ALL: clear all data associated with a site.
deleted file mode 100644
--- a/dom/plugins/base/nsIPluginInstance.idl
+++ /dev/null
@@ -1,286 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include "nsISupports.idl"
-#include "nsIPluginStreamListener.idl"
-
-interface nsIPluginInstanceOwner;
-interface nsIOutputStream;
-
-%{C++
-#include "npapi.h"
-#include "nsStringGlue.h"
-#include "gfxASurface.h"
-#include "ImageLayers.h"
-struct JSContext;
-struct JSObject;
-class gfxASurface;
-class gfxContext;
-struct nsIntRect;
-struct nsIntSize;
-
-namespace mozilla {
-namespace layers {
-class Image;
-class ImageContainer;
-}
-}
-
-#define NPRUNTIME_JSCLASS_NAME "NPObject JS wrapper class"
-%}
-
-[ptr] native JSContextPtr(JSContext);
-[ptr] native JSObjectPtr(JSObject);
-[ptr] native gfxASurfacePtr(gfxASurface);
-[ptr] native gfxContextPtr(gfxContext);
-[ptr] native ImagePtr(mozilla::layers::Image);
-[ptr] native ImageContainerPtr(mozilla::layers::ImageContainer);
-[ptr] native nsIntRectPtr(nsIntRect);
-[ptr] native nsIntSizePtr(nsIntSize);
-
-[uuid(84994340-E120-4051-824F-D4EE8AEF1A3E)]
-interface nsIPluginInstance : nsISupports
-{
-    /**
-     * Initializes a newly created plugin instance.
-     * 
-     * @param aOwner - the plugin instance owner
-     * @param aMime - the mime type for the instance
-     * @result      - NS_OK if this operation was successful
-     */
-    void initialize(in nsIPluginInstanceOwner aOwner, in string aMIMEType);
-
-    /**
-     * Called to instruct the plugin instance to start. This will be
-     * called after the plugin is first created and initialized, and
-     * may be called after the plugin is stopped (via the Stop method)
-     * if the plugin instance is returned to in the browser window's
-     * history.
-     *
-     * @result - NS_OK if this operation was successful
-     */
-    void start();
-
-    /**
-     * Called to instruct the plugin instance to stop, thereby
-     * suspending its state.  This method will be called whenever the
-     * browser window goes on to display another page and the page
-     * containing the plugin goes into the window's history list.
-     *
-     * @result - NS_OK if this operation was successful
-     */
-    void stop();
-
-    /**
-     * Called when the window containing the plugin instance changes.
-     *
-     * (Corresponds to NPP_SetWindow.)
-     *
-     * @param aWindow - the plugin window structure
-     * @result        - NS_OK if this operation was successful
-     */
-    void setWindow(in NPWindowPtr aWindow);
-
-    /**
-     * Called to tell the plugin that the initial src/data stream is
-     * ready.  Expects the plugin to return a nsIPluginStreamListener.
-     *
-     * (Corresponds to NPP_NewStream.)
-     *
-     * @param aListener - listener the browser will use to give the plugin the data
-     * @result          - NS_OK if this operation was successful
-     */
-    void newStreamToPlugin(out nsIPluginStreamListener aListener);
-
-    /**
-     * This operation is called by the plugin instance when it wishes to send
-     * a stream of data to the browser. It constructs a new output stream to which
-     * the plugin may send the data. When complete, the Close and Release methods
-     * should be called on the output stream.
-     *
-     * (Corresponds to NPN_NewStream.)
-     *
-     * @param aType   - MIME type of the stream to create
-     * @param aTarget - the target window name to receive the data
-     * @param aResult - the resulting output stream
-     * @result        - NS_OK if this operation was successful
-     */
-    void newStreamFromPlugin(in string aType, in string aTarget, out nsIOutputStream aResult);
-
-    /**
-     * Called to instruct the plugin instance to print itself to a printer.
-     *
-     * (Corresponds to NPP_Print.)
-     *
-     * @param aPlatformPrint - platform-specific printing information
-     * @result               - NS_OK if this operation was successful
-     */
-    void print(in NPPrintPtr aPlatformPrint);
-
-    /**
-     * Handles an event.
-     *
-     * Note that for Unix and Mac the nsPluginEvent structure is different
-     * from the old NPEvent structure -- it's no longer the native event
-     * record, but is instead a struct. This was done for future extensibility,
-     * and so that the Mac could receive the window argument too. For Windows
-     * and OS2, it's always been a struct, so there's no change for them.
-     *
-     * (Corresponds to NPP_HandleEvent.)
-     *
-     * @param aEvent   - the event to be handled
-     * @param aHandled - if non-NULL, set to the NPAPI NPP_HandleEvent
-     *                   return value
-     * @result - NS_OK if this operation was successful
-     */
-    void handleEvent(in voidPtr aEvent, out PRInt16 aHandled);
-
-    /** 
-     * Corresponds to NPN_InvalidateRect
-     */
-    void invalidateRect(in NPRectPtr aRect);
-
-    /** 
-     * Corresponds to NPN_InvalidateRegion
-     */
-    void invalidateRegion(in NPRegion aRegion);
-
-    /** 
-     * Corresponds to NPN_ForceRedraw
-     */
-    void forceRedraw();
-    
-    /**
-     * Returns the MIME type of the plugin instance. 
-     *
-     * (Corresponds to NPP_New's MIMEType argument.)
-     *
-     * @param aMIMEType - resulting MIME type
-     * @result          - NS_OK if this operation was successful
-     */
-    void getMIMEType([const, shared] out string aValue);
-
-    /**
-     * Get the JavaScript context to this plugin instance.
-     *
-     * @param aJSContext - the resulting JavaScript context
-     * @result           - NS_OK if this operation was successful
-     */
-    readonly attribute JSContextPtr JSContext;
-
-    attribute nsIPluginInstanceOwner owner;
-    
-    /**
-     * This operation causes status information to be displayed on the window
-     * associated with the plugin instance. 
-     *
-     * (Corresponds to NPN_Status.)
-     *
-     * @param aMessage - the status message to display
-     * @result         - NS_OK if this operation was successful
-     */
-    void showStatus(in string aMessage);
-
-    /**
-     * Drop our reference to our owner.
-     */
-    void invalidateOwner();
-
-    JSObjectPtr GetJSObject(in JSContextPtr cx);
-
-    readonly attribute AString formValue;
-
-    void pushPopupsEnabledState(in boolean aEnabled);
-    void popPopupsEnabledState();
-
-    readonly attribute PRUint16 pluginAPIVersion;
-
-    void defineJavaProperties();
-
-    PRBool shouldCache();
-
-    PRBool isWindowless();
-
-    PRBool isTransparent();
-
-    void getValueFromPlugin(in NPPVariable variable, in voidPtr aValue);
-
-    PRInt32 getDrawingModel();
-
-    /**
-     * async version of SetWindow call
-     *
-     * @param aWindow  - the plugin window structure
-     */
-    void asyncSetWindow(in NPWindowPtr aWindow);
-
-    /**
-     * Call this each time after the plugin has been painted to the screen
-     */
-    void notifyPainted();
-
-    /**
-     * @return true if plugin module supports async rendering
-     */
-    PRBool useAsyncPainting();
-
-    PRBool isRemoteDrawingCoreAnimation();
-
-    /**
-     * Returns a new Image object which draws an asynchronously-rendered
-     * plugin. The Image is created using aContainer.
-     * Fails if the plugin is using async rendering but no image has yet
-     * been received, or if the plugin is not using async rendering.
-     */
-    void getImage(in ImageContainerPtr aContainer, out ImagePtr aImage);
-
-    /**
-     * Returns the size of the Image object that would be created if we called
-     * getImage.
-     * Fails if the plugin is using async rendering but no image has yet
-     * been received, or if the plugin is not using async rendering.
-     */
-    void getImageSize(in nsIntSizePtr aSize);
-
-    /**
-     * This is the second leg in the trip to PluginInstanceParent.  It
-     * approximately follows the ReadbackSink API.
-     */
-    void setBackgroundUnknown();
-    void beginUpdateBackground(in nsIntRectPtr rect, out gfxContextPtr ctx);
-    void endUpdateBackground(in gfxContextPtr ctx, in nsIntRectPtr rect);
-};
--- a/dom/plugins/base/nsIPluginInstanceOwner.idl
+++ b/dom/plugins/base/nsIPluginInstanceOwner.idl
@@ -34,45 +34,38 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsISupports.idl"
 #include "nspluginroot.idl"
 #include "nsIInputStream.idl"
 
-interface nsIPluginInstance;
 interface nsIDocument;
 
 %{C++
 #include "npapi.h"
+#include "nsNPAPIPluginInstance.h"
 class nsPluginEvent;
 %}
 
-[ref] native nsIPluginInstanceRef(nsIPluginInstance*);
+[ptr] native nsNPAPIPluginInstancePtr(nsNPAPIPluginInstance);
 
-[uuid(B48DC23E-C20B-4292-974E-E8FF97B9F1CC)]
+[uuid(17E89C1F-AE62-448E-83D5-C33FA6E07A19)]
 interface nsIPluginInstanceOwner : nsISupports
 {
   /**
    * Let the owner know what its instance is
    */
-  void setInstance(in nsIPluginInstance aInstance);
+  void setInstance(in nsNPAPIPluginInstancePtr aInstance);
 
   /**
    * Get the instance associated with this owner.
    */
-  void getInstance(in nsIPluginInstanceRef aInstance);
-
-%{C++
-  // make getter_AddRefs work
-  inline nsresult GetInstance(nsIPluginInstance** aInstance) {
-    return GetInstance(*aInstance);
-  }
-%}
+  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/nsJSNPRuntime.cpp
+++ b/dom/plugins/base/nsJSNPRuntime.cpp
@@ -50,16 +50,18 @@
 #include "nsIDocument.h"
 #include "nsIJSRuntimeService.h"
 #include "nsIJSContextStack.h"
 #include "nsIXPConnect.h"
 #include "nsIDOMElement.h"
 #include "prmem.h"
 #include "nsIContent.h"
 
+#define NPRUNTIME_JSCLASS_NAME "NPObject JS wrapper class"
+
 using namespace mozilla::plugins::parent;
 
 #include "mozilla/plugins/PluginScriptableObjectParent.h"
 using mozilla::plugins::PluginScriptableObjectParent;
 using mozilla::plugins::ParentNPObject;
 
 // Hash of JSObject wrappers that wraps JSObjects as NPObjects. There
 // will be one wrapper per JSObject per plugin instance, i.e. if two
--- a/dom/plugins/base/nsNPAPIPlugin.cpp
+++ b/dom/plugins/base/nsNPAPIPlugin.cpp
@@ -530,29 +530,29 @@ nsNPAPIPlugin::GetLibrary()
 
 NPPluginFuncs*
 nsNPAPIPlugin::PluginFuncs()
 {
   return &mPluginFuncs;
 }
 
 nsresult
-nsNPAPIPlugin::CreatePluginInstance(nsIPluginInstance **aResult)
+nsNPAPIPlugin::CreatePluginInstance(nsNPAPIPluginInstance **aResult)
 {
   if (!aResult)
     return NS_ERROR_NULL_POINTER;
 
   *aResult = NULL;
 
   nsRefPtr<nsNPAPIPluginInstance> inst = new nsNPAPIPluginInstance(this);
   if (!inst)
     return NS_ERROR_OUT_OF_MEMORY;
 
   NS_ADDREF(inst);
-  *aResult = static_cast<nsIPluginInstance*>(inst);
+  *aResult = inst;
   return NS_OK;
 }
 
 nsresult
 nsNPAPIPlugin::Shutdown()
 {
   NPP_PLUGIN_LOG(PLUGIN_LOG_BASIC,
                  ("NPP Shutdown to be called: this=%p\n", this));
@@ -1043,17 +1043,17 @@ NPError NP_CALLBACK
     return NPERR_INVALID_PARAM;
   }
   NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL,
   ("NPN_NewStream: npp=%p, type=%s, target=%s\n", (void*)npp,
    (const char *)type, target));
 
   NPError err = NPERR_INVALID_INSTANCE_ERROR;
   if (npp && npp->ndata) {
-    nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
+    nsNPAPIPluginInstance *inst = (nsNPAPIPluginInstance*)npp->ndata;
 
     PluginDestructionGuard guard(inst);
 
     nsCOMPtr<nsIOutputStream> stream;
     if (NS_SUCCEEDED(inst->NewStreamFromPlugin((const char*) type, target,
                                                getter_AddRefs(stream)))) {
       nsNPAPIStreamWrapper* wrapper = new nsNPAPIStreamWrapper(stream);
       if (wrapper) {
@@ -1163,17 +1163,17 @@ void NP_CALLBACK
   NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL, ("NPN_Status: npp=%p, message=%s\n",
                                      (void*)npp, message));
 
   if (!npp || !npp->ndata) {
     NS_WARNING("_status: npp or npp->ndata == 0");
     return;
   }
 
-  nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
+  nsNPAPIPluginInstance *inst = (nsNPAPIPluginInstance*)npp->ndata;
 
   PluginDestructionGuard guard(inst);
 
   inst->ShowStatus(message);
 }
 
 void NP_CALLBACK
 _memfree (void *ptr)
@@ -1228,17 +1228,17 @@ void NP_CALLBACK
                   "right=%d\n", (void *)npp, invalidRect->top,
                   invalidRect->left, invalidRect->bottom, invalidRect->right));
 
   if (!npp || !npp->ndata) {
     NS_WARNING("_invalidaterect: npp or npp->ndata == 0");
     return;
   }
 
-  nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
+  nsNPAPIPluginInstance *inst = (nsNPAPIPluginInstance*)npp->ndata;
 
   PluginDestructionGuard guard(inst);
 
   inst->InvalidateRect((NPRect *)invalidRect);
 }
 
 void NP_CALLBACK
 _invalidateregion(NPP npp, NPRegion invalidRegion)
@@ -1251,17 +1251,17 @@ void NP_CALLBACK
                  ("NPN_InvalidateRegion: npp=%p, region=%p\n", (void*)npp,
                   (void*)invalidRegion));
 
   if (!npp || !npp->ndata) {
     NS_WARNING("_invalidateregion: npp or npp->ndata == 0");
     return;
   }
 
-  nsIPluginInstance *inst = (nsIPluginInstance *)npp->ndata;
+  nsNPAPIPluginInstance *inst = (nsNPAPIPluginInstance*)npp->ndata;
 
   PluginDestructionGuard guard(inst);
 
   inst->InvalidateRegion((NPRegion)invalidRegion);
 }
 
 void NP_CALLBACK
 _forceredraw(NPP npp)
@@ -1272,17 +1272,17 @@ void NP_CALLBACK
   }
   NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL, ("NPN_ForceDraw: npp=%p\n", (void*)npp));
 
   if (!npp || !npp->ndata) {
     NS_WARNING("_forceredraw: npp or npp->ndata == 0");
     return;
   }
 
-  nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
+  nsNPAPIPluginInstance *inst = (nsNPAPIPluginInstance*)npp->ndata;
 
   PluginDestructionGuard guard(inst);
 
   inst->ForceRedraw();
 }
 
 NPObject* NP_CALLBACK
 _getwindowobject(NPP npp)
--- a/dom/plugins/base/nsNPAPIPlugin.h
+++ b/dom/plugins/base/nsNPAPIPlugin.h
@@ -98,17 +98,17 @@ public:
   // crashes and is no longer usable. pluginDumpID/browserDumpID are
   // the IDs of respective minidumps that were written, or empty if no
   // minidump was written.
   void PluginCrashed(const nsAString& pluginDumpID,
                      const nsAString& browserDumpID);
   
   static PRBool RunPluginOOP(const nsPluginTag *aPluginTag);
 
-  nsresult CreatePluginInstance(nsIPluginInstance **aResult);
+  nsresult CreatePluginInstance(nsNPAPIPluginInstance **aResult);
   nsresult Shutdown();
 
 protected:
   NPPluginFuncs mPluginFuncs;
   PluginLibrary* mLibrary;
 };
 
 namespace mozilla {
--- a/dom/plugins/base/nsNPAPIPluginInstance.cpp
+++ b/dom/plugins/base/nsNPAPIPluginInstance.cpp
@@ -59,17 +59,17 @@
 #include "nsPluginStreamListenerPeer.h"
 
 using namespace mozilla;
 using namespace mozilla::plugins::parent;
 
 static NS_DEFINE_IID(kIOutputStreamIID, NS_IOUTPUTSTREAM_IID);
 static NS_DEFINE_IID(kIPluginStreamListenerIID, NS_IPLUGINSTREAMLISTENER_IID);
 
-NS_IMPL_ISUPPORTS1(nsNPAPIPluginInstance, nsIPluginInstance)
+NS_IMPL_ISUPPORTS0(nsNPAPIPluginInstance)
 
 nsNPAPIPluginInstance::nsNPAPIPluginInstance(nsNPAPIPlugin* plugin)
   :
 #ifdef XP_MACOSX
 #ifdef NP_NO_QUICKDRAW
     mDrawingModel(NPDrawingModelCoreGraphics),
 #else
     mDrawingModel(NPDrawingModelQuickDraw),
@@ -129,43 +129,43 @@ nsNPAPIPluginInstance::Destroy()
 }
 
 TimeStamp
 nsNPAPIPluginInstance::LastStopTime()
 {
   return mStopTime;
 }
 
-NS_IMETHODIMP nsNPAPIPluginInstance::Initialize(nsIPluginInstanceOwner* aOwner, const char* aMIMEType)
+nsresult nsNPAPIPluginInstance::Initialize(nsIPluginInstanceOwner* aOwner, const char* aMIMEType)
 {
   PLUGIN_LOG(PLUGIN_LOG_NORMAL, ("nsNPAPIPluginInstance::Initialize this=%p\n",this));
 
   mOwner = aOwner;
 
   if (aMIMEType) {
     mMIMEType = (char*)PR_Malloc(PL_strlen(aMIMEType) + 1);
 
     if (mMIMEType)
       PL_strcpy(mMIMEType, aMIMEType);
   }
 
   return InitializePlugin();
 }
 
-NS_IMETHODIMP nsNPAPIPluginInstance::Start()
+nsresult nsNPAPIPluginInstance::Start()
 {
   PLUGIN_LOG(PLUGIN_LOG_NORMAL, ("nsNPAPIPluginInstance::Start this=%p\n",this));
 
   if (RUNNING == mRunning)
     return NS_OK;
 
   return InitializePlugin();
 }
 
-NS_IMETHODIMP nsNPAPIPluginInstance::Stop()
+nsresult nsNPAPIPluginInstance::Stop()
 {
   PLUGIN_LOG(PLUGIN_LOG_NORMAL, ("nsNPAPIPluginInstance::Stop this=%p\n",this));
 
   // Make sure the plugin didn't leave popups enabled.
   if (mPopupStates.Length() > 0) {
     nsCOMPtr<nsPIDOMWindow> window = GetDOMWindow();
 
     if (window) {
@@ -426,17 +426,17 @@ nsNPAPIPluginInstance::InitializePlugin(
     mRunning = DESTROYED;
     nsJSNPRuntime::OnPluginDestroy(&mNPP);
     return NS_ERROR_FAILURE;
   }
   
   return NS_OK;
 }
 
-NS_IMETHODIMP nsNPAPIPluginInstance::SetWindow(NPWindow* window)
+nsresult nsNPAPIPluginInstance::SetWindow(NPWindow* window)
 {
   // NPAPI plugins don't want a SetWindow(NULL).
   if (!window || RUNNING != mRunning)
     return NS_OK;
 
 #if defined(MOZ_WIDGET_GTK2)
   // bug 108347, flash plugin on linux doesn't like window->width <=
   // 0, but Java needs wants this call.
@@ -472,24 +472,24 @@ NS_IMETHODIMP nsNPAPIPluginInstance::Set
     NPP_PLUGIN_LOG(PLUGIN_LOG_NORMAL,
     ("NPP SetWindow called: this=%p, [x=%d,y=%d,w=%d,h=%d], clip[t=%d,b=%d,l=%d,r=%d], return=%d\n",
     this, window->x, window->y, window->width, window->height,
     window->clipRect.top, window->clipRect.bottom, window->clipRect.left, window->clipRect.right, error));
   }
   return NS_OK;
 }
 
-NS_IMETHODIMP
+nsresult
 nsNPAPIPluginInstance::NewStreamToPlugin(nsIPluginStreamListener** listener)
 {
   // This method can be removed at the next opportunity.
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
-NS_IMETHODIMP
+nsresult
 nsNPAPIPluginInstance::NewStreamFromPlugin(const char* type, const char* target,
                                            nsIOutputStream* *result)
 {
   nsPluginStreamToFile* stream = new nsPluginStreamToFile(target, mOwner);
   if (!stream)
     return NS_ERROR_OUT_OF_MEMORY;
 
   return stream->QueryInterface(kIOutputStreamIID, (void**)result);
@@ -502,17 +502,17 @@ nsNPAPIPluginInstance::NewStreamListener
   nsNPAPIPluginStreamListener* stream = new nsNPAPIPluginStreamListener(this, notifyData, aURL);
   NS_ENSURE_TRUE(stream, NS_ERROR_OUT_OF_MEMORY);
 
   mStreamListeners.AppendElement(stream);
 
   return stream->QueryInterface(kIPluginStreamListenerIID, (void**)listener);
 }
 
-NS_IMETHODIMP nsNPAPIPluginInstance::Print(NPPrint* platformPrint)
+nsresult nsNPAPIPluginInstance::Print(NPPrint* platformPrint)
 {
   NS_ENSURE_TRUE(platformPrint, NS_ERROR_NULL_POINTER);
 
   PluginDestructionGuard guard(this);
 
   if (!mPlugin || !mPlugin->GetLibrary())
     return NS_ERROR_FAILURE;
 
@@ -552,17 +552,17 @@ NS_IMETHODIMP nsNPAPIPluginInstance::Pri
   platformPrint->print.embedPrint.window.clipRect.top,
   platformPrint->print.embedPrint.window.clipRect.bottom,
   platformPrint->print.embedPrint.window.clipRect.left,
   platformPrint->print.embedPrint.window.clipRect.right));
 
   return NS_OK;
 }
 
-NS_IMETHODIMP nsNPAPIPluginInstance::HandleEvent(void* event, PRInt16* result)
+nsresult nsNPAPIPluginInstance::HandleEvent(void* event, PRInt16* result)
 {
   if (RUNNING != mRunning)
     return NS_OK;
 
   if (!event)
     return NS_ERROR_FAILURE;
 
   PluginDestructionGuard guard(this);
@@ -588,17 +588,17 @@ NS_IMETHODIMP nsNPAPIPluginInstance::Han
     if (result)
       *result = tmpResult;
     mCurrentPluginEvent = nsnull;
   }
 
   return NS_OK;
 }
 
-NS_IMETHODIMP nsNPAPIPluginInstance::GetValueFromPlugin(NPPVariable variable, void* value)
+nsresult nsNPAPIPluginInstance::GetValueFromPlugin(NPPVariable variable, void* value)
 {
 #if (MOZ_PLATFORM_MAEMO == 5)
   // The maemo flash plugin does not remember this.  It sets the
   // value, but doesn't support the get value.
   if (variable == NPPVpluginWindowlessLocalBool) {
     *(NPBool*)value = mWindowlessLocal;
     return NS_OK;
   }
@@ -721,58 +721,58 @@ void nsNPAPIPluginInstance::SetEventMode
     return;
   }
 
   owner->SetEventModel(aModel);
 }
 
 #endif
 
-NS_IMETHODIMP nsNPAPIPluginInstance::GetDrawingModel(PRInt32* aModel)
+nsresult nsNPAPIPluginInstance::GetDrawingModel(PRInt32* aModel)
 {
 #ifdef XP_MACOSX
   *aModel = (PRInt32)mDrawingModel;
   return NS_OK;
 #else
   return NS_ERROR_FAILURE;
 #endif
 }
 
-NS_IMETHODIMP nsNPAPIPluginInstance::IsRemoteDrawingCoreAnimation(PRBool* aDrawing)
+nsresult nsNPAPIPluginInstance::IsRemoteDrawingCoreAnimation(PRBool* aDrawing)
 {
 #ifdef XP_MACOSX
   if (!mPlugin)
       return NS_ERROR_FAILURE;
 
   PluginLibrary* library = mPlugin->GetLibrary();
   if (!library)
       return NS_ERROR_FAILURE;
   
   return library->IsRemoteDrawingCoreAnimation(&mNPP, aDrawing);
 #else
   return NS_ERROR_FAILURE;
 #endif
 }
 
-NS_IMETHODIMP
+nsresult
 nsNPAPIPluginInstance::GetJSObject(JSContext *cx, JSObject** outObject)
 {
   NPObject *npobj = nsnull;
   nsresult rv = GetValueFromPlugin(NPPVpluginScriptableNPObject, &npobj);
   if (NS_FAILED(rv) || !npobj)
     return NS_ERROR_FAILURE;
 
   *outObject = nsNPObjWrapper::GetNewOrUsed(&mNPP, cx, npobj);
 
   _releaseobject(npobj);
 
   return NS_OK;
 }
 
-NS_IMETHODIMP
+nsresult
 nsNPAPIPluginInstance::DefineJavaProperties()
 {
   NPObject *plugin_obj = nsnull;
 
   // The dummy Java plugin's scriptable object is what we want to
   // expose as window.Packages. And Window.Packages.java will be
   // exposed as window.java.
 
@@ -826,24 +826,24 @@ nsNPAPIPluginInstance::DefineJavaPropert
 
 nsresult
 nsNPAPIPluginInstance::SetCached(PRBool aCache)
 {
   mCached = aCache;
   return NS_OK;
 }
 
-NS_IMETHODIMP
+nsresult
 nsNPAPIPluginInstance::ShouldCache(PRBool* shouldCache)
 {
   *shouldCache = mCached;
   return NS_OK;
 }
 
-NS_IMETHODIMP
+nsresult
 nsNPAPIPluginInstance::IsWindowless(PRBool* isWindowless)
 {
   *isWindowless = mWindowless;
   return NS_OK;
 }
 
 class NS_STACK_CLASS AutoPluginLibraryCall
 {
@@ -859,125 +859,125 @@ public:
   PluginLibrary* operator->() { return mLibrary; }
 
 private:
   nsNPAPIPluginInstance* mThis;
   PluginDestructionGuard mGuard;
   PluginLibrary* mLibrary;
 };
 
-NS_IMETHODIMP
+nsresult
 nsNPAPIPluginInstance::AsyncSetWindow(NPWindow* window)
 {
   if (RUNNING != mRunning)
     return NS_OK;
 
   AutoPluginLibraryCall library(this);
   if (!library)
     return NS_ERROR_FAILURE;
 
   return library->AsyncSetWindow(&mNPP, window);
 }
 
-NS_IMETHODIMP
+nsresult
 nsNPAPIPluginInstance::GetImage(ImageContainer* aContainer, Image** aImage)
 {
   *aImage = nsnull;
 
   if (RUNNING != mRunning)
     return NS_OK;
 
   AutoPluginLibraryCall library(this);
   return !library ? NS_ERROR_FAILURE : library->GetImage(&mNPP, aContainer, aImage);
 }
 
-NS_IMETHODIMP
+nsresult
 nsNPAPIPluginInstance::GetImageSize(nsIntSize* aSize)
 {
   *aSize = nsIntSize(0, 0);
 
   if (RUNNING != mRunning)
     return NS_OK;
 
   AutoPluginLibraryCall library(this);
   return !library ? NS_ERROR_FAILURE : library->GetImageSize(&mNPP, aSize);
 }
 
-NS_IMETHODIMP
+nsresult
 nsNPAPIPluginInstance::NotifyPainted(void)
 {
   NS_NOTREACHED("Dead code, shouldn't be called.");
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
-NS_IMETHODIMP
+nsresult
 nsNPAPIPluginInstance::UseAsyncPainting(PRBool* aIsAsync)
 {
   if (!mUsePluginLayersPref) {
     *aIsAsync = mUsePluginLayersPref;
     return NS_OK;
   }
 
   AutoPluginLibraryCall library(this);
   if (!library)
     return NS_ERROR_FAILURE;
 
   *aIsAsync = library->UseAsyncPainting();
   return NS_OK;
 }
 
-NS_IMETHODIMP
+nsresult
 nsNPAPIPluginInstance::SetBackgroundUnknown()
 {
   if (RUNNING != mRunning)
     return NS_OK;
 
   AutoPluginLibraryCall library(this);
   if (!library)
     return NS_ERROR_FAILURE;
 
   return library->SetBackgroundUnknown(&mNPP);
 }
 
-NS_IMETHODIMP
+nsresult
 nsNPAPIPluginInstance::BeginUpdateBackground(nsIntRect* aRect,
                                              gfxContext** aContext)
 {
   if (RUNNING != mRunning)
     return NS_OK;
 
   AutoPluginLibraryCall library(this);
   if (!library)
     return NS_ERROR_FAILURE;
 
   return library->BeginUpdateBackground(&mNPP, *aRect, aContext);
 }
 
-NS_IMETHODIMP
+nsresult
 nsNPAPIPluginInstance::EndUpdateBackground(gfxContext* aContext,
                                            nsIntRect* aRect)
 {
   if (RUNNING != mRunning)
     return NS_OK;
 
   AutoPluginLibraryCall library(this);
   if (!library)
     return NS_ERROR_FAILURE;
 
   return library->EndUpdateBackground(&mNPP, aContext, *aRect);
 }
 
-NS_IMETHODIMP
+nsresult
 nsNPAPIPluginInstance::IsTransparent(PRBool* isTransparent)
 {
   *isTransparent = mTransparent;
   return NS_OK;
 }
 
-NS_IMETHODIMP
+nsresult
 nsNPAPIPluginInstance::GetFormValue(nsAString& aValue)
 {
   aValue.Truncate();
 
   char *value = nsnull;
   nsresult rv = GetValueFromPlugin(NPPVformValue, &value);
   if (NS_FAILED(rv) || !value)
     return NS_ERROR_FAILURE;
@@ -986,17 +986,17 @@ nsNPAPIPluginInstance::GetFormValue(nsAS
 
   // NPPVformValue allocates with NPN_MemAlloc(), which uses
   // nsMemory.
   nsMemory::Free(value);
 
   return NS_OK;
 }
 
-NS_IMETHODIMP
+nsresult
 nsNPAPIPluginInstance::PushPopupsEnabledState(PRBool aEnabled)
 {
   nsCOMPtr<nsPIDOMWindow> window = GetDOMWindow();
   if (!window)
     return NS_ERROR_FAILURE;
 
   PopupControlState oldState =
     window->PushPopupControlState(aEnabled ? openAllowed : openAbused,
@@ -1006,17 +1006,17 @@ nsNPAPIPluginInstance::PushPopupsEnabled
     // Appending to our state stack failed, pop what we just pushed.
     window->PopPopupControlState(oldState);
     return NS_ERROR_FAILURE;
   }
 
   return NS_OK;
 }
 
-NS_IMETHODIMP
+nsresult
 nsNPAPIPluginInstance::PopPopupsEnabledState()
 {
   PRInt32 last = mPopupStates.Length() - 1;
 
   if (last < 0) {
     // Nothing to pop.
     return NS_OK;
   }
@@ -1029,17 +1029,17 @@ nsNPAPIPluginInstance::PopPopupsEnabledS
 
   window->PopPopupControlState(oldState);
 
   mPopupStates.RemoveElementAt(last);
   
   return NS_OK;
 }
 
-NS_IMETHODIMP
+nsresult
 nsNPAPIPluginInstance::GetPluginAPIVersion(PRUint16* version)
 {
   NS_ENSURE_ARG_POINTER(version);
 
   if (!mPlugin)
     return NS_ERROR_FAILURE;
 
   if (!mPlugin->GetLibrary())
@@ -1203,70 +1203,70 @@ nsNPAPIPluginInstance::GetDOMElement(nsI
 
   nsCOMPtr<nsIPluginTagInfo> tinfo(do_QueryInterface(mOwner));
   if (tinfo)
     return tinfo->GetDOMElement(result);
 
   return NS_ERROR_FAILURE;
 }
 
-NS_IMETHODIMP
+nsresult
 nsNPAPIPluginInstance::InvalidateRect(NPRect *invalidRect)
 {
   if (RUNNING != mRunning)
     return NS_OK;
 
   nsCOMPtr<nsIPluginInstanceOwner> owner;
   GetOwner(getter_AddRefs(owner));
   if (!owner)
     return NS_ERROR_FAILURE;
 
   return owner->InvalidateRect(invalidRect);
 }
 
-NS_IMETHODIMP
+nsresult
 nsNPAPIPluginInstance::InvalidateRegion(NPRegion invalidRegion)
 {
   if (RUNNING != mRunning)
     return NS_OK;
 
   nsCOMPtr<nsIPluginInstanceOwner> owner;
   GetOwner(getter_AddRefs(owner));
   if (!owner)
     return NS_ERROR_FAILURE;
 
   return owner->InvalidateRegion(invalidRegion);
 }
 
-NS_IMETHODIMP
+nsresult
 nsNPAPIPluginInstance::ForceRedraw()
 {
   if (RUNNING != mRunning)
     return NS_OK;
 
   nsCOMPtr<nsIPluginInstanceOwner> owner;
   GetOwner(getter_AddRefs(owner));
   if (!owner)
     return NS_ERROR_FAILURE;
 
   return owner->ForceRedraw();
 }
 
-NS_IMETHODIMP
+nsresult
 nsNPAPIPluginInstance::GetMIMEType(const char* *result)
 {
   if (!mMIMEType)
     *result = "";
   else
     *result = mMIMEType;
 
   return NS_OK;
 }
 
-NS_IMETHODIMP
+nsresult
 nsNPAPIPluginInstance::GetJSContext(JSContext* *outContext)
 {
   nsCOMPtr<nsIPluginInstanceOwner> owner;
   GetOwner(getter_AddRefs(owner));
   if (!owner)
     return NS_ERROR_FAILURE;
 
   *outContext = NULL;
@@ -1284,42 +1284,42 @@ nsNPAPIPluginInstance::GetJSContext(JSCo
         *outContext = (JSContext*) context->GetNativeContext();
       }
     }
   }
 
   return rv;
 }
 
-NS_IMETHODIMP
+nsresult
 nsNPAPIPluginInstance::GetOwner(nsIPluginInstanceOwner **aOwner)
 {
   NS_ENSURE_ARG_POINTER(aOwner);
   *aOwner = mOwner;
   NS_IF_ADDREF(mOwner);
   return (mOwner ? NS_OK : NS_ERROR_FAILURE);
 }
 
-NS_IMETHODIMP
+nsresult
 nsNPAPIPluginInstance::SetOwner(nsIPluginInstanceOwner *aOwner)
 {
   mOwner = aOwner;
   return NS_OK;
 }
 
-NS_IMETHODIMP
+nsresult
 nsNPAPIPluginInstance::ShowStatus(const char* message)
 {
   if (mOwner)
     return mOwner->ShowStatus(message);
 
   return NS_ERROR_FAILURE;
 }
 
-NS_IMETHODIMP
+nsresult
 nsNPAPIPluginInstance::InvalidateOwner()
 {
   mOwner = nsnull;
 
   return NS_OK;
 }
 
 nsresult
--- a/dom/plugins/base/nsNPAPIPluginInstance.h
+++ b/dom/plugins/base/nsNPAPIPluginInstance.h
@@ -37,49 +37,89 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsNPAPIPluginInstance_h_
 #define nsNPAPIPluginInstance_h_
 
 #include "nsCOMPtr.h"
 #include "nsTArray.h"
-#include "nsIPluginInstance.h"
 #include "nsPIDOMWindow.h"
 #include "nsITimer.h"
 #include "nsIPluginTagInfo.h"
 #include "nsIURI.h"
 #include "nsIChannel.h"
 #include "nsInterfaceHashtable.h"
 #include "nsHashKeys.h"
 
 #include "mozilla/TimeStamp.h"
 #include "mozilla/PluginLibrary.h"
 
+struct JSObject;
+
 class nsPluginStreamListenerPeer; // browser-initiated stream class
 class nsNPAPIPluginStreamListener; // plugin-initiated stream class
 class nsIPluginInstanceOwner;
+class nsIPluginStreamListener;
+class nsIOutputStream;
 
 class nsNPAPITimer
 {
 public:
   NPP npp;
   uint32_t id;
   nsCOMPtr<nsITimer> timer;
   void (*callback)(NPP npp, uint32_t timerID);
 };
 
-class nsNPAPIPluginInstance : public nsIPluginInstance
+class nsNPAPIPluginInstance : public nsISupports
 {
 private:
   typedef mozilla::PluginLibrary PluginLibrary;
 
 public:
   NS_DECL_ISUPPORTS
-  NS_DECL_NSIPLUGININSTANCE
+
+  nsresult Initialize(nsIPluginInstanceOwner* aOwner, const char* aMIMEType);
+  nsresult Start();
+  nsresult Stop();
+  nsresult SetWindow(NPWindow* window);
+  nsresult NewStreamToPlugin(nsIPluginStreamListener** listener);
+  nsresult NewStreamFromPlugin(const char* type, const char* target, nsIOutputStream* *result);
+  nsresult Print(NPPrint* platformPrint);
+  nsresult HandleEvent(void* event, PRInt16* result);
+  nsresult GetValueFromPlugin(NPPVariable variable, void* value);
+  nsresult GetDrawingModel(PRInt32* aModel);
+  nsresult IsRemoteDrawingCoreAnimation(PRBool* aDrawing);
+  nsresult GetJSObject(JSContext *cx, JSObject** outObject);
+  nsresult DefineJavaProperties();
+  nsresult ShouldCache(PRBool* shouldCache);
+  nsresult IsWindowless(PRBool* isWindowless);
+  nsresult AsyncSetWindow(NPWindow* window);
+  nsresult GetImage(ImageContainer* aContainer, Image** aImage);
+  nsresult GetImageSize(nsIntSize* aSize);
+  nsresult NotifyPainted(void);
+  nsresult UseAsyncPainting(PRBool* aIsAsync);
+  nsresult SetBackgroundUnknown();
+  nsresult BeginUpdateBackground(nsIntRect* aRect, gfxContext** aContext);
+  nsresult EndUpdateBackground(gfxContext* aContext, nsIntRect* aRect);
+  nsresult IsTransparent(PRBool* isTransparent);
+  nsresult GetFormValue(nsAString& aValue);
+  nsresult PushPopupsEnabledState(PRBool aEnabled);
+  nsresult PopPopupsEnabledState();
+  nsresult GetPluginAPIVersion(PRUint16* version);
+  nsresult InvalidateRect(NPRect *invalidRect);
+  nsresult InvalidateRegion(NPRegion invalidRegion);
+  nsresult ForceRedraw();
+  nsresult GetMIMEType(const char* *result);
+  nsresult GetJSContext(JSContext* *outContext);
+  nsresult GetOwner(nsIPluginInstanceOwner **aOwner);
+  nsresult SetOwner(nsIPluginInstanceOwner *aOwner);
+  nsresult ShowStatus(const char* message);
+  nsresult InvalidateOwner();
 
   nsNPAPIPlugin* GetPlugin();
 
   nsresult GetNPP(NPP * aNPP);
 
   void SetURI(nsIURI* uri);
   nsIURI* GetURI();
 
--- a/dom/plugins/base/nsPluginHost.cpp
+++ b/dom/plugins/base/nsPluginHost.cpp
@@ -1059,45 +1059,43 @@ nsPluginHost::InstantiateEmbeddedPlugin(
       if (handler)
         bCanHandleInternally = PR_TRUE;
   }
 
   if (FindStoppedPluginForURL(aURL, aOwner) == NS_OK) {
     PLUGIN_LOG(PLUGIN_LOG_NOISY,
     ("nsPluginHost::InstantiateEmbeddedPlugin FoundStopped mime=%s\n", aMimeType));
 
-    nsCOMPtr<nsIPluginInstance> instanceCOMPtr;
-    aOwner->GetInstance(getter_AddRefs(instanceCOMPtr));
-    nsNPAPIPluginInstance *instance = static_cast<nsNPAPIPluginInstance*>(instanceCOMPtr.get());
-    if (!isJava && bCanHandleInternally)
-      rv = NewEmbeddedPluginStream(aURL, aOwner, instance);
+    if (!isJava && bCanHandleInternally) {
+      nsNPAPIPluginInstance* instance;
+      aOwner->GetInstance(&instance);
+      NewEmbeddedPluginStream(aURL, aOwner, instance);
+      NS_IF_RELEASE(instance);
+    }
 
     return NS_OK;
   }
 
   // if we don't have a MIME type at this point, we still have one more chance by
   // opening the stream and seeing if the server hands one back
   if (!aMimeType)
     return bCanHandleInternally ? NewEmbeddedPluginStream(aURL, aOwner, nsnull) : NS_ERROR_FAILURE;
 
   rv = SetUpPluginInstance(aMimeType, aURL, aOwner);
 
   if (NS_FAILED(rv))
     return NS_ERROR_FAILURE;
 
-  nsCOMPtr<nsIPluginInstance> instanceCOMPtr;
-  rv = aOwner->GetInstance(getter_AddRefs(instanceCOMPtr));
+  nsRefPtr<nsNPAPIPluginInstance> instance;
+  rv = aOwner->GetInstance(getter_AddRefs(instance));
   // if we have a failure error, it means we found a plugin for the mimetype,
   // but we had a problem with the entry point
   if (rv == NS_ERROR_FAILURE)
     return rv;
 
-  // if we are here then we have loaded a plugin for this mimetype
-  nsNPAPIPluginInstance *instance = static_cast<nsNPAPIPluginInstance*>(instanceCOMPtr.get());
-
   if (instance) {
     instance->Start();
     aOwner->CreateWidget();
 
     // If we've got a native window, the let the plugin know about it.
     aOwner->SetWindow();
 
     // create an initial stream with data
@@ -1108,17 +1106,17 @@ nsPluginHost::InstantiateEmbeddedPlugin(
 
     if (pti) {
       const char *value;
       havedata = NS_SUCCEEDED(pti->GetAttribute("SRC", &value));
       // no need to check for "data" as it would have been converted to "src"
     }
 
     if (havedata && !isJava && bCanHandleInternally)
-      rv = NewEmbeddedPluginStream(aURL, aOwner, instance);
+      rv = NewEmbeddedPluginStream(aURL, aOwner, instance.get());
   }
 
 #ifdef PLUGIN_LOGGING
   nsCAutoString urlSpec2;
   if (aURL != nsnull) aURL->GetAsciiSpec(urlSpec2);
 
   PR_LOG(nsPluginLogging::gPluginLog, PLUGIN_LOG_NORMAL,
         ("nsPluginHost::InstantiateEmbeddedPlugin Finished mime=%s, rv=%d, owner=%p, url=%s\n",
@@ -1145,41 +1143,40 @@ nsresult nsPluginHost::InstantiateFullPa
 
   if (FindStoppedPluginForURL(aURI, aOwner) == NS_OK) {
     PLUGIN_LOG(PLUGIN_LOG_NOISY,
     ("nsPluginHost::InstantiateFullPagePlugin FoundStopped mime=%s\n",aMimeType));
 
 
     nsPluginTag* pluginTag = FindPluginForType(aMimeType, PR_TRUE);
     if (!pluginTag || !pluginTag->mIsJavaPlugin) {
-      nsCOMPtr<nsIPluginInstance> instanceCOMPtr;
-      aOwner->GetInstance(getter_AddRefs(instanceCOMPtr));
-      NewFullPagePluginStream(aURI, static_cast<nsNPAPIPluginInstance*>(instanceCOMPtr.get()), aStreamListener);
+      nsRefPtr<nsNPAPIPluginInstance> instance;
+      aOwner->GetInstance(getter_AddRefs(instance));
+      NewFullPagePluginStream(aURI, instance.get(), aStreamListener);
     }
     return NS_OK;
   }
 
   nsresult rv = SetUpPluginInstance(aMimeType, aURI, aOwner);
 
   if (NS_OK == rv) {
-    nsCOMPtr<nsIPluginInstance> instanceCOMPtr;
-    aOwner->GetInstance(getter_AddRefs(instanceCOMPtr));
-    nsNPAPIPluginInstance *instance = static_cast<nsNPAPIPluginInstance*>(instanceCOMPtr.get());
+    nsRefPtr<nsNPAPIPluginInstance> instance;
+    aOwner->GetInstance(getter_AddRefs(instance));
 
     NPWindow* win = nsnull;
     aOwner->GetWindow(win);
 
     if (win && instance) {
       instance->Start();
       aOwner->CreateWidget();
 
       // If we've got a native window, the let the plugin know about it.
       aOwner->SetWindow();
 
-      rv = NewFullPagePluginStream(aURI, instance, aStreamListener);
+      rv = NewFullPagePluginStream(aURI, instance.get(), aStreamListener);
 
       // If we've got a native window, the let the plugin know about it.
       aOwner->SetWindow();
     }
   }
 
   PLUGIN_LOG(PLUGIN_LOG_NORMAL,
   ("nsPluginHost::InstantiateFullPagePlugin End mime=%s, rv=%d, owner=%p, url=%s\n",
@@ -1320,17 +1317,18 @@ nsPluginHost::TrySetUpPluginInstance(con
     mimetype = aMimeType;
   }
 
   NS_ASSERTION(pluginTag, "Must have plugin tag here!");
 
   nsRefPtr<nsNPAPIPlugin> plugin;
   GetPlugin(mimetype, getter_AddRefs(plugin));
 
-  nsCOMPtr<nsIPluginInstance> instance;
+  nsRefPtr<nsNPAPIPluginInstance> instance;
+
   if (plugin) {
 #if defined(XP_WIN)
     static BOOL firstJavaPlugin = FALSE;
     BOOL restoreOrigDir = FALSE;
     WCHAR origDir[_MAX_PATH];
     if (pluginTag->mIsJavaPlugin && !firstJavaPlugin) {
       DWORD dw = GetCurrentDirectoryW(_MAX_PATH, origDir);
       NS_ASSERTION(dw <= _MAX_PATH, "Failed to obtain the current directory, which may lead to incorrect class loading");
@@ -1356,28 +1354,28 @@ nsPluginHost::TrySetUpPluginInstance(con
     }
 #endif
   }
 
   if (NS_FAILED(rv))
     return rv;
 
   // it is adreffed here
-  aOwner->SetInstance(instance);
+  aOwner->SetInstance(instance.get());
 
   // this should not addref the instance or owner
   // except in some cases not Java, see bug 140931
   // our COM pointer will free the peer
   rv = instance->Initialize(aOwner, mimetype);
   if (NS_FAILED(rv)) {
     aOwner->SetInstance(nsnull);
     return rv;
   }
 
-  mInstances.AppendElement(static_cast<nsNPAPIPluginInstance*>(instance.get()));
+  mInstances.AppendElement(instance.get());
 
 #ifdef PLUGIN_LOGGING
   nsCAutoString urlSpec2;
   if (aURL)
     aURL->GetSpec(urlSpec2);
 
   PR_LOG(nsPluginLogging::gPluginLog, PLUGIN_LOG_BASIC,
         ("nsPluginHost::TrySetupPluginInstance Finished mime=%s, rv=%d, owner=%p, url=%s\n",
@@ -3288,27 +3286,27 @@ nsPluginHost::AddHeadersToChannel(const 
     if (NS_FAILED(rv)) {
       rv = NS_ERROR_NULL_POINTER;
       return rv;
     }
   }
   return rv;
 }
 
-NS_IMETHODIMP
-nsPluginHost::StopPluginInstance(nsIPluginInstance* aInstance)
+nsresult
+nsPluginHost::StopPluginInstance(nsNPAPIPluginInstance* aInstance)
 {
   if (PluginDestructionGuard::DelayDestroy(aInstance)) {
     return NS_OK;
   }
 
   PLUGIN_LOG(PLUGIN_LOG_NORMAL,
   ("nsPluginHost::StopPluginInstance called instance=%p\n",aInstance));
 
-  nsNPAPIPluginInstance* instance = static_cast<nsNPAPIPluginInstance*>(aInstance);
+  nsNPAPIPluginInstance* instance = aInstance;
   if (instance->HasStartedDestroying())
     return NS_OK;
 
   aInstance->Stop();
 
   // if the plugin does not want to be 'cached' just remove it
   PRBool doCache = PR_TRUE;
   aInstance->ShouldCache(&doCache);
@@ -3439,18 +3437,18 @@ NS_IMETHODIMP nsPluginHost::Observe(nsIS
     // inform all active plugins of changed private mode state
     for (PRUint32 i = 0; i < mInstances.Length(); i++) {
       mInstances[i]->PrivateModeStateChanged();
     }
   }
   return NS_OK;
 }
 
-NS_IMETHODIMP
-nsPluginHost::HandleBadPlugin(PRLibrary* aLibrary, nsIPluginInstance *aInstance)
+nsresult
+nsPluginHost::HandleBadPlugin(PRLibrary* aLibrary, nsNPAPIPluginInstance *aInstance)
 {
   // the |aLibrary| parameter is not needed anymore, after we added |aInstance| which
   // can also be used to look up the plugin name, but we cannot get rid of it because
   // the |nsIPluginHost| interface is deprecated which in fact means 'frozen'
 
   NS_ERROR("Plugin performed illegal operation");
   NS_ENSURE_ARG_POINTER(aInstance);
 
@@ -3496,19 +3494,17 @@ nsPluginHost::HandleBadPlugin(PRLibrary*
                                formatStrings, 1, getter_Copies(message))))
     return rv;
 
   rv = bundle->GetStringFromName(NS_LITERAL_STRING("BadPluginCheckboxMessage").get(),
                                  getter_Copies(checkboxMessage));
   if (NS_FAILED(rv))
     return rv;
 
-  nsNPAPIPluginInstance *instance = static_cast<nsNPAPIPluginInstance*>(aInstance);
-
-  nsNPAPIPlugin *plugin = instance->GetPlugin();
+  nsNPAPIPlugin *plugin = aInstance->GetPlugin();
   if (!plugin)
     return NS_ERROR_FAILURE;
 
   nsPluginTag *pluginTag = TagForPlugin(plugin);
 
   // add plugin name to the message
   nsCString pluginname;
   if (pluginTag) {
@@ -3816,52 +3812,51 @@ nsPluginHost::InstantiateDummyJavaPlugin
     // instantiating a dummy plugin then.
 
     return NS_OK;
   }
 
   nsresult rv = SetUpPluginInstance("application/x-java-vm", nsnull, aOwner);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsIPluginInstance> instance;
-  aOwner->GetInstance(*getter_AddRefs(instance));
+  nsRefPtr<nsNPAPIPluginInstance> instance;
+  aOwner->GetInstance(getter_AddRefs(instance));
   if (!instance)
     return NS_OK;
 
   instance->DefineJavaProperties();
 
   return NS_OK;
 }
 
-NS_IMETHODIMP
-nsPluginHost::GetPluginName(nsIPluginInstance *aPluginInstance,
+nsresult
+nsPluginHost::GetPluginName(nsNPAPIPluginInstance *aPluginInstance,
                             const char** aPluginName)
 {
   nsNPAPIPluginInstance *instance = static_cast<nsNPAPIPluginInstance*>(aPluginInstance);
   if (!instance)
     return NS_ERROR_FAILURE;
 
   nsNPAPIPlugin* plugin = instance->GetPlugin();
   if (!plugin)
     return NS_ERROR_FAILURE;
 
   *aPluginName = TagForPlugin(plugin)->mName.get();
 
   return NS_OK;
 }
 
-NS_IMETHODIMP
-nsPluginHost::GetPluginTagForInstance(nsIPluginInstance *aPluginInstance,
+nsresult
+nsPluginHost::GetPluginTagForInstance(nsNPAPIPluginInstance *aPluginInstance,
                                       nsIPluginTag **aPluginTag)
 {
   NS_ENSURE_ARG_POINTER(aPluginInstance);
   NS_ENSURE_ARG_POINTER(aPluginTag);
 
-  nsNPAPIPluginInstance *instance = static_cast<nsNPAPIPluginInstance*>(aPluginInstance);
-  nsNPAPIPlugin *plugin = instance->GetPlugin();
+  nsNPAPIPlugin *plugin = aPluginInstance->GetPlugin();
   if (!plugin)
     return NS_ERROR_FAILURE;
 
   *aPluginTag = TagForPlugin(plugin);
 
   NS_ADDREF(*aPluginTag);
   return NS_OK;
 }
@@ -4155,31 +4150,31 @@ nsPluginHost::DestroyRunningInstances(ns
 }
 
 // Runnable that does an async destroy of a plugin.
 
 class nsPluginDestroyRunnable : public nsRunnable,
                                 public PRCList
 {
 public:
-  nsPluginDestroyRunnable(nsIPluginInstance *aInstance)
+  nsPluginDestroyRunnable(nsNPAPIPluginInstance *aInstance)
     : mInstance(aInstance)
   {
     PR_INIT_CLIST(this);
     PR_APPEND_LINK(this, &sRunnableListHead);
   }
 
   virtual ~nsPluginDestroyRunnable()
   {
     PR_REMOVE_LINK(this);
   }
 
   NS_IMETHOD Run()
   {
-    nsCOMPtr<nsIPluginInstance> instance;
+    nsRefPtr<nsNPAPIPluginInstance> instance;
 
     // Null out mInstance to make sure this code in another runnable
     // will do the right thing even if someone was holding on to this
     // runnable longer than we expect.
     instance.swap(mInstance);
 
     if (PluginDestructionGuard::DelayDestroy(instance)) {
       // It's still not safe to destroy the plugin, it's now up to the
@@ -4208,17 +4203,17 @@ public:
 
     PLUGIN_LOG(PLUGIN_LOG_NORMAL,
                ("Done with delayed destroy of instance %p\n", instance.get()));
 
     return NS_OK;
   }
 
 protected:
-  nsCOMPtr<nsIPluginInstance> mInstance;
+  nsRefPtr<nsNPAPIPluginInstance> mInstance;
 
   static PRCList sRunnableListHead;
 };
 
 PRCList nsPluginDestroyRunnable::sRunnableListHead =
   PR_INIT_STATIC_CLIST(&nsPluginDestroyRunnable::sRunnableListHead);
 
 PRCList PluginDestructionGuard::sListHead =
@@ -4238,17 +4233,17 @@ PluginDestructionGuard::~PluginDestructi
       new nsPluginDestroyRunnable(mInstance);
 
     NS_DispatchToMainThread(evt);
   }
 }
 
 // static
 PRBool
-PluginDestructionGuard::DelayDestroy(nsIPluginInstance *aInstance)
+PluginDestructionGuard::DelayDestroy(nsNPAPIPluginInstance *aInstance)
 {
   NS_ASSERTION(NS_IsMainThread(), "Should be on the main thread");
   NS_ASSERTION(aInstance, "Uh, I need an instance!");
 
   // Find the first guard on the stack and make it do a delayed
   // destroy upon destruction.
 
   PluginDestructionGuard *g =
--- a/dom/plugins/base/nsPluginHost.h
+++ b/dom/plugins/base/nsPluginHost.h
@@ -101,16 +101,21 @@ public:
 
   NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
 
   NS_DECL_ISUPPORTS
   NS_DECL_NSIPLUGINHOST
   NS_DECL_NSIOBSERVER
   NS_DECL_NSITIMERCALLBACK
 
+  nsresult GetPluginName(nsNPAPIPluginInstance *aPluginInstance, const char** aPluginName);
+  nsresult StopPluginInstance(nsNPAPIPluginInstance* aInstance);
+  nsresult HandleBadPlugin(PRLibrary* aLibrary, nsNPAPIPluginInstance *aInstance);
+  nsresult GetPluginTagForInstance(nsNPAPIPluginInstance *aPluginInstance, nsIPluginTag **aPluginTag);
+
   nsresult
   NewPluginURLStream(const nsString& aURL, 
                      nsNPAPIPluginInstance *aInstance, 
                      nsIPluginStreamListener *aListener,
                      nsIInputStream *aPostStream = nsnull,
                      const char *aHeadersData = nsnull, 
                      PRUint32 aHeadersDataLen = 0);
 
@@ -296,42 +301,42 @@ private:
   nsCOMPtr<nsITimer> mHiddenPluginTimer;
   nsTObserverArray<nsIPluginInstanceOwner*> mHiddenTimerTargets;
 #endif
 };
 
 class NS_STACK_CLASS PluginDestructionGuard : protected PRCList
 {
 public:
-  PluginDestructionGuard(nsIPluginInstance *aInstance)
+  PluginDestructionGuard(nsNPAPIPluginInstance *aInstance)
     : mInstance(aInstance)
   {
     Init();
   }
 
   PluginDestructionGuard(NPP npp)
     : mInstance(npp ? static_cast<nsNPAPIPluginInstance*>(npp->ndata) : nsnull)
   {
     Init();
   }
 
   ~PluginDestructionGuard();
 
-  static PRBool DelayDestroy(nsIPluginInstance *aInstance);
+  static PRBool DelayDestroy(nsNPAPIPluginInstance *aInstance);
 
 protected:
   void Init()
   {
     NS_ASSERTION(NS_IsMainThread(), "Should be on the main thread");
 
     mDelayedDestroy = PR_FALSE;
 
     PR_INIT_CLIST(this);
     PR_INSERT_BEFORE(this, &sListHead);
   }
 
-  nsCOMPtr<nsIPluginInstance> mInstance;
+  nsRefPtr<nsNPAPIPluginInstance> mInstance;
   PRBool mDelayedDestroy;
 
   static PRCList sListHead;
 };
 
 #endif // nsPluginHost_h_
--- a/dom/plugins/base/nsPluginNativeWindow.h
+++ b/dom/plugins/base/nsPluginNativeWindow.h
@@ -37,18 +37,19 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef _nsPluginNativeWindow_h_
 #define _nsPluginNativeWindow_h_
 
 #include "nscore.h"
+#include "nsAutoPtr.h"
 #include "nsCOMPtr.h"
-#include "nsIPluginInstance.h"
+#include "nsNPAPIPluginInstance.h"
 #include "npapi.h"
 #include "nsIWidget.h"
 #include "nsTraceRefcnt.h"
 
 /**
  * base class for native plugin window implementations
  */
 class nsPluginNativeWindow : public NPWindow
@@ -68,37 +69,37 @@ public:
    * The base class |nsPluginWindow| is defined as a struct in nsplugindefs.h,
    * thus it does not have a destructor of its own.
    * One should never attempt to delete |nsPluginNativeWindow| object instance
    * (or derivatives) using a pointer of |nsPluginWindow *| type. Should such
    * necessity occur it must be properly casted first.
    */
 
 public:
-  nsresult GetPluginInstance(nsCOMPtr<nsIPluginInstance> &aPluginInstance) { 
+  nsresult GetPluginInstance(nsRefPtr<nsNPAPIPluginInstance> &aPluginInstance) { 
     aPluginInstance = mPluginInstance;
     return NS_OK;
   }
-  nsresult SetPluginInstance(nsIPluginInstance *aPluginInstance) { 
+  nsresult SetPluginInstance(nsNPAPIPluginInstance *aPluginInstance) { 
     if (mPluginInstance != aPluginInstance)
       mPluginInstance = aPluginInstance;
     return NS_OK;
   }
 
   nsresult GetPluginWidget(nsIWidget **aWidget) {
     NS_IF_ADDREF(*aWidget = mWidget);
     return NS_OK;
   }
   nsresult SetPluginWidget(nsIWidget *aWidget) { 
     mWidget = aWidget;
     return NS_OK;
   }
 
 public:
-  virtual nsresult CallSetWindow(nsCOMPtr<nsIPluginInstance> &aPluginInstance) {
+  virtual nsresult CallSetWindow(nsRefPtr<nsNPAPIPluginInstance> &aPluginInstance) {
     // null aPluginInstance means that we want to call SetWindow(null)
     if (aPluginInstance)
       aPluginInstance->SetWindow(this);
     else if (mPluginInstance)
       mPluginInstance->SetWindow(nsnull);
 
     SetPluginInstance(aPluginInstance);
     return NS_OK;
@@ -109,16 +110,16 @@ public:
 #ifdef MOZ_COMPOSITED_PLUGINS
   /* XXX: we use this to leak the socket widget out from nsPlugNativeWindowGtk2
      so that Renderer::NativeDraw() in nsObjectFrame.cpp can draw the widget.
      I don't currently know a better way to do this... */
   void *mPlugWindow;
 #endif
 
 protected:
-  nsCOMPtr<nsIPluginInstance> mPluginInstance;
-  nsCOMPtr<nsIWidget>         mWidget;
+  nsRefPtr<nsNPAPIPluginInstance> mPluginInstance;
+  nsCOMPtr<nsIWidget> mWidget;
 };
 
 nsresult PLUG_NewPluginNativeWindow(nsPluginNativeWindow ** aPluginNativeWindow);
 nsresult PLUG_DeletePluginNativeWindow(nsPluginNativeWindow * aPluginNativeWindow);
 
 #endif //_nsPluginNativeWindow_h_
--- a/dom/plugins/base/nsPluginNativeWindowGtk2.cpp
+++ b/dom/plugins/base/nsPluginNativeWindowGtk2.cpp
@@ -62,17 +62,17 @@ extern "C" {
 
 #include "gtk2xtbin.h"
 
 class nsPluginNativeWindowGtk2 : public nsPluginNativeWindow {
 public: 
   nsPluginNativeWindowGtk2();
   virtual ~nsPluginNativeWindowGtk2();
 
-  virtual nsresult CallSetWindow(nsCOMPtr<nsIPluginInstance> &aPluginInstance);
+  virtual nsresult CallSetWindow(nsRefPtr<nsNPAPIPluginInstance> &aPluginInstance);
 private:
   NPSetWindowCallbackStruct mWsInfo;
   /**
    * Either a GtkSocket or a special GtkXtBin widget (derived from GtkSocket)
    * that encapsulates the Xt toolkit within a Gtk Application.
    */
   GtkWidget* mSocketWidget;
   nsresult  CreateXEmbedWindow();
@@ -174,17 +174,17 @@ nsPluginNativeWindowGtk2::plugin_composi
 
   if (native_window->mPluginInstance)
     native_window->mPluginInstance->InvalidateRect(&rect);
 
   return GDK_FILTER_REMOVE;
 }
 #endif
 
-nsresult nsPluginNativeWindowGtk2::CallSetWindow(nsCOMPtr<nsIPluginInstance> &aPluginInstance)
+nsresult nsPluginNativeWindowGtk2::CallSetWindow(nsRefPtr<nsNPAPIPluginInstance> &aPluginInstance)
 {
   if (aPluginInstance) {
     if (type == NPWindowTypeWindow) {
       if (!mSocketWidget) {
         nsresult rv;
 
         PRBool needXEmbed = PR_FALSE;
         rv = aPluginInstance->GetValueFromPlugin(NPPVpluginNeedsXEmbed, &needXEmbed);
--- a/dom/plugins/base/nsPluginNativeWindowQt.cpp
+++ b/dom/plugins/base/nsPluginNativeWindowQt.cpp
@@ -51,17 +51,17 @@
  * Qt implementation of plugin window
  */
 class nsPluginNativeWindowQt : public nsPluginNativeWindow
 {
 public:
   nsPluginNativeWindowQt();
   virtual ~nsPluginNativeWindowQt();
 
-  virtual nsresult CallSetWindow(nsCOMPtr<nsIPluginInstance> &aPluginInstance);
+  virtual nsresult CallSetWindow(nsRefPtr<nsNPAPIPluginInstance> &aPluginInstance);
 private:
 
   NPSetWindowCallbackStruct mWsInfo;
 };
 
 nsPluginNativeWindowQt::nsPluginNativeWindowQt() : nsPluginNativeWindow()
 {
   //Initialize member variables
@@ -100,17 +100,17 @@ nsresult PLUG_NewPluginNativeWindow(nsPl
 nsresult PLUG_DeletePluginNativeWindow(nsPluginNativeWindow * aPluginNativeWindow)
 {
   NS_ENSURE_ARG_POINTER(aPluginNativeWindow);
   nsPluginNativeWindowQt *p = (nsPluginNativeWindowQt *)aPluginNativeWindow;
   delete p;
   return NS_OK;
 }
 
-nsresult nsPluginNativeWindowQt::CallSetWindow(nsCOMPtr<nsIPluginInstance> &aPluginInstance)
+nsresult nsPluginNativeWindowQt::CallSetWindow(nsRefPtr<nsNPAPIPluginInstance> &aPluginInstance)
 {
   if (aPluginInstance) {
     if (type == NPWindowTypeWindow) {
       return NS_ERROR_FAILURE;
     } // NPWindowTypeWindow
     aPluginInstance->SetWindow(this);
   }
   else if (mPluginInstance)
--- a/dom/plugins/base/nsPluginNativeWindowWin.cpp
+++ b/dom/plugins/base/nsPluginNativeWindowWin.cpp
@@ -138,17 +138,17 @@ typedef enum {
   nsPluginType_Other
 } nsPluginType;
 
 class nsPluginNativeWindowWin : public nsPluginNativeWindow {
 public: 
   nsPluginNativeWindowWin();
   virtual ~nsPluginNativeWindowWin();
 
-  virtual nsresult CallSetWindow(nsCOMPtr<nsIPluginInstance> &aPluginInstance);
+  virtual nsresult CallSetWindow(nsRefPtr<nsNPAPIPluginInstance> &aPluginInstance);
 
 private:
   nsresult SubclassAndAssociateWindow();
   nsresult UndoSubclassAndAssociateWindow();
 
 public:
   // locals
   WNDPROC GetPrevWindowProc();
@@ -170,17 +170,17 @@ private:
 public:
   nsPluginType mPluginType;
 };
 
 static PRBool sInMessageDispatch = PR_FALSE;
 static PRBool sInPreviousMessageDispatch = PR_FALSE;
 static UINT sLastMsg = 0;
 
-static PRBool ProcessFlashMessageDelayed(nsPluginNativeWindowWin * aWin, nsIPluginInstance * aInst,
+static PRBool ProcessFlashMessageDelayed(nsPluginNativeWindowWin * aWin, nsNPAPIPluginInstance * aInst,
                                          HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 {
   NS_ENSURE_TRUE(aWin, NS_ERROR_NULL_POINTER);
   NS_ENSURE_TRUE(aInst, NS_ERROR_NULL_POINTER);
 
   if (msg == sWM_FLASHBOUNCEMSG) {
     // See PluginWindowEvent::Run() below.
     NS_ASSERTION((sWM_FLASHBOUNCEMSG != 0), "RegisterWindowMessage failed in flash plugin WM_USER message handling!");
@@ -199,24 +199,24 @@ static PRBool ProcessFlashMessageDelayed
     return PR_TRUE;  
   }
   return PR_FALSE;
 }
 
 class nsDelayedPopupsEnabledEvent : public nsRunnable
 {
 public:
-  nsDelayedPopupsEnabledEvent(nsIPluginInstance *inst)
+  nsDelayedPopupsEnabledEvent(nsNPAPIPluginInstance *inst)
     : mInst(inst)
   {}
 
   NS_DECL_NSIRUNNABLE
 
 private:
-  nsCOMPtr<nsIPluginInstance> mInst;
+  nsRefPtr<nsNPAPIPluginInstance> mInst;
 };
 
 NS_IMETHODIMP nsDelayedPopupsEnabledEvent::Run()
 {
   mInst->PushPopupsEnabledState(PR_FALSE);
   return NS_OK;	
 }
 
@@ -227,17 +227,17 @@ static LRESULT CALLBACK PluginWndProcInt
 {
   nsPluginNativeWindowWin * win = (nsPluginNativeWindowWin *)::GetProp(hWnd, NS_PLUGIN_WINDOW_PROPERTY_ASSOCIATION);
   if (!win)
     return TRUE;
 
   // The DispatchEvent(NS_PLUGIN_ACTIVATE) below can trigger a reentrant focus
   // event which might destroy us.  Hold a strong ref on the plugin instance
   // to prevent that, bug 374229.
-  nsCOMPtr<nsIPluginInstance> inst;
+  nsRefPtr<nsNPAPIPluginInstance> inst;
   win->GetPluginInstance(inst);
 
   // Real may go into a state where it recursivly dispatches the same event
   // when subclassed. If this is Real, lets examine the event and drop it
   // on the floor if we get into this recursive situation. See bug 192914.
   if (win->mPluginType == nsPluginType_Real) {
     if (sInMessageDispatch && msg == sLastMsg)
       return PR_TRUE;
@@ -559,17 +559,17 @@ NS_IMETHODIMP PluginWindowEvent::Run()
   nsPluginNativeWindowWin *win = mPluginWindowRef.get();
   if (!win)
     return NS_OK;
 
   HWND hWnd = GetWnd();
   if (!hWnd)
     return NS_OK;
 
-  nsCOMPtr<nsIPluginInstance> inst;
+  nsRefPtr<nsNPAPIPluginInstance> inst;
   win->GetPluginInstance(inst);
 
   if (GetMsg() == WM_USER_FLASH) {
     // XXX Unwind issues related to runnable event callback depth for this
     // event and destruction of the plugin. (Bug 493601)
     ::PostMessage(hWnd, sWM_FLASHBOUNCEMSG, GetWParam(), GetLParam());
   }
   else {
@@ -616,17 +616,17 @@ nsPluginNativeWindowWin::GetPluginWindow
   {
     event = mCachedPluginWindowEvent;
   }
 
   event->Init(mWeakRef, aWnd, aMsg, aWParam, aLParam);
   return event;
 }
 
-nsresult nsPluginNativeWindowWin::CallSetWindow(nsCOMPtr<nsIPluginInstance> &aPluginInstance)
+nsresult nsPluginNativeWindowWin::CallSetWindow(nsRefPtr<nsNPAPIPluginInstance> &aPluginInstance)
 {
   // Note, 'window' can be null
 
   // check the incoming instance, null indicates that window is going away and we are
   // not interested in subclassing business any more, undo and don't subclass
   if (!aPluginInstance) {
     UndoSubclassAndAssociateWindow();
     nsPluginNativeWindow::CallSetWindow(aPluginInstance);
--- a/dom/plugins/base/nsPluginSafety.h
+++ b/dom/plugins/base/nsPluginSafety.h
@@ -34,17 +34,17 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsPluginSafety_h_
 #define nsPluginSafety_h_
 
 #include "npapi.h"
-#include "nsIPluginHost.h"
+#include "nsPluginHost.h"
 #include "nsIPrefBranch.h"
 #include "nsIPrefService.h"
 #include <prinrval.h>
 
 #if defined(XP_WIN)
 #define CALL_SAFETY_ON
 #endif
 
@@ -73,17 +73,17 @@ PR_BEGIN_MACRO                          
     {                                              \
       ret = fun;                                   \
     }                                              \
     MOZ_SEH_EXCEPT(PR_TRUE)                        \
     {                                              \
       nsresult res;                                \
       nsCOMPtr<nsIPluginHost> host(do_GetService(MOZ_PLUGIN_HOST_CONTRACTID, &res));\
       if(NS_SUCCEEDED(res) && (host != nsnull))    \
-        host->HandleBadPlugin(nsnull, pluginInst); \
+        static_cast<nsPluginHost*>(host.get())->HandleBadPlugin(nsnull, pluginInst); \
       ret = (NPError)NS_ERROR_FAILURE;             \
     }                                              \
   }                                                \
   NS_NotifyPluginCall(startTime);		   \
 PR_END_MACRO
 
 #define NS_TRY_SAFE_CALL_VOID(fun, pluginInst) \
 PR_BEGIN_MACRO                              \
@@ -96,17 +96,17 @@ PR_BEGIN_MACRO                          
     {                                       \
       fun;                                  \
     }                                       \
     MOZ_SEH_EXCEPT(PR_TRUE)                 \
     {                                       \
       nsresult res;                         \
       nsCOMPtr<nsIPluginHost> host(do_GetService(MOZ_PLUGIN_HOST_CONTRACTID, &res));\
       if(NS_SUCCEEDED(res) && (host != nsnull))\
-        host->HandleBadPlugin(nsnull, pluginInst);\
+        static_cast<nsPluginHost*>(host.get())->HandleBadPlugin(nsnull, pluginInst);\
     }                                       \
   }                                         \
   NS_NotifyPluginCall(startTime);		   \
 PR_END_MACRO
 
 #else // vanilla calls
 
 #define NS_TRY_SAFE_CALL_RETURN(ret, fun, pluginInst) \
--- a/dom/plugins/base/nsPluginStreamListenerPeer.cpp
+++ b/dom/plugins/base/nsPluginStreamListenerPeer.cpp
@@ -638,19 +638,19 @@ nsPluginStreamListenerPeer::OnStartReque
   // if we don't have an nsNPAPIPluginInstance (mPluginInstance), it means
   // we weren't able to load a plugin previously because we
   // didn't have the mimetype.  Now that we do (aContentType),
   // we'll try again with SetUpPluginInstance()
   // which is called by InstantiateEmbeddedPlugin()
   // NOTE: we don't want to try again if we didn't get the MIME type this time
   
   if (!mPluginInstance && mOwner && !aContentType.IsEmpty()) {
-    nsCOMPtr<nsIPluginInstance> pluginInstCOMPtr;
-    mOwner->GetInstance(getter_AddRefs(pluginInstCOMPtr));
-    mPluginInstance = static_cast<nsNPAPIPluginInstance*>(pluginInstCOMPtr.get());
+    nsRefPtr<nsNPAPIPluginInstance> pluginInstRefPtr;
+    mOwner->GetInstance(getter_AddRefs(pluginInstRefPtr));
+    mPluginInstance = pluginInstRefPtr.get();
 
     mOwner->GetWindow(window);
     if (!mPluginInstance && window) {
       nsRefPtr<nsPluginHost> pluginHost = dont_AddRef(nsPluginHost::GetInst());
       
       // determine if we need to try embedded again. FullPage takes a different code path
       PRInt32 mode;
       mOwner->GetMode(&mode);
@@ -661,18 +661,18 @@ nsPluginStreamListenerPeer::OnStartReque
         rv = pluginHost->InstantiateEmbeddedPlugin(aContentType.get(), aURL,
                                                    mOwner, PR_FALSE);
       }
       else {
         rv = pluginHost->SetUpPluginInstance(aContentType.get(), aURL, mOwner);
       }
       
       if (NS_OK == rv) {
-        mOwner->GetInstance(getter_AddRefs(pluginInstCOMPtr));
-        mPluginInstance = static_cast<nsNPAPIPluginInstance*>(pluginInstCOMPtr.get());
+        mOwner->GetInstance(getter_AddRefs(pluginInstRefPtr));
+        mPluginInstance = pluginInstRefPtr.get();
         if (mPluginInstance) {
           mPluginInstance->Start();
           mOwner->CreateWidget();
           // If we've got a native window, the let the plugin know about it.
           mOwner->SetWindow();
         }
       }
     }
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -143,17 +143,17 @@
 #ifdef MOZ_REFLOW_PERF
 #include "nsFontMetrics.h"
 #endif
 
 #include "nsIReflowCallback.h"
 
 #include "nsPIDOMWindow.h"
 #include "nsFocusManager.h"
-#include "nsIPluginInstance.h"
+#include "nsNPAPIPluginInstance.h"
 #include "nsIObjectFrame.h"
 #include "nsIObjectLoadingContent.h"
 #include "nsNetUtil.h"
 #include "nsEventDispatcher.h"
 #include "nsThreadUtils.h"
 #include "nsStyleSheetService.h"
 #include "gfxImageSurface.h"
 #include "gfxContext.h"
@@ -7755,17 +7755,17 @@ PresShell::FireOrClearDelayedEvents(PRBo
   }
 }
 
 static void
 ThawElement(nsIContent *aContent, void *aShell)
 {
   nsCOMPtr<nsIObjectLoadingContent> objlc(do_QueryInterface(aContent));
   if (objlc) {
-    nsCOMPtr<nsIPluginInstance> inst;
+    nsRefPtr<nsNPAPIPluginInstance> inst;
     objlc->EnsureInstantiation(getter_AddRefs(inst));
   }
 }
 
 static PRBool
 ThawSubDocument(nsIDocument *aDocument, void *aData)
 {
   nsIPresShell *shell = aDocument->GetShell();
--- a/layout/generic/nsIObjectFrame.h
+++ b/layout/generic/nsIObjectFrame.h
@@ -40,24 +40,24 @@
  * a plugin
  */
 
 #ifndef nsIObjectFrame_h___
 #define nsIObjectFrame_h___
 
 #include "nsIFrame.h"
 
-class nsIPluginInstance;
+class nsNPAPIPluginInstance;
 
 class nsIObjectFrame : public nsQueryFrame
 {
 public:
   NS_DECL_QUERYFRAME_TARGET(nsIObjectFrame)
 
-  NS_IMETHOD GetPluginInstance(nsIPluginInstance*& aPluginInstance) = 0;
+  NS_IMETHOD GetPluginInstance(nsNPAPIPluginInstance** aPluginInstance) = 0;
 
   /**
    * Instantiate a plugin for a channel, returning a stream listener for the
    * data.
    *
    * @note Calling this method can delete the frame, so don't assume
    *       the frame is alive after this call returns.
    */
--- a/layout/generic/nsObjectFrame.cpp
+++ b/layout/generic/nsObjectFrame.cpp
@@ -82,17 +82,16 @@ enum { XKeyPress = KeyPress };
 #include "prmem.h"
 #include "nsGkAtoms.h"
 #include "nsIAppShell.h"
 #include "nsIDocument.h"
 #include "nsINodeInfo.h"
 #include "nsIURL.h"
 #include "nsNetUtil.h"
 #include "nsIPluginInstanceOwner.h"
-#include "nsIPluginInstance.h"
 #include "nsNPAPIPluginInstance.h"
 #include "nsIPluginTagInfo.h"
 #include "plstr.h"
 #include "nsILinkHandler.h"
 #include "nsIScrollPositionListener.h"
 #include "nsITimer.h"
 #include "nsIDocShellTreeItem.h"
 #include "nsIDocShellTreeOwner.h"
@@ -278,18 +277,16 @@ class nsPluginInstanceOwner : public nsI
                               public nsIDOMFocusListener,
                               public nsIScrollPositionListener
 {
 public:
   nsPluginInstanceOwner();
   virtual ~nsPluginInstanceOwner();
 
   NS_DECL_ISUPPORTS
-
-  //nsIPluginInstanceOwner interface
   NS_DECL_NSIPLUGININSTANCEOWNER
 
   NS_IMETHOD GetURL(const char *aURL, const char *aTarget,
                     nsIInputStream *aPostStream, 
                     void *aHeadersData, PRUint32 aHeadersDataLen);
 
   NS_IMETHOD ShowStatus(const PRUnichar *aStatusMsg);
 
@@ -430,16 +427,17 @@ public:
   }
 
 #ifdef MOZ_X11
   void GetPluginDescription(nsACString& aDescription)
   {
     aDescription.Truncate();
     if (mInstance && mPluginHost) {
       nsCOMPtr<nsIPluginTag> pluginTag;
+      
       mPluginHost->GetPluginTagForInstance(mInstance,
                                            getter_AddRefs(pluginTag));
       if (pluginTag) {
         pluginTag->GetDescription(aDescription);
       }
     }
   }
 #endif
@@ -504,23 +502,23 @@ private:
     nsIntSize size;
     return NS_SUCCEEDED(mInstance->GetImageSize(&size)) &&
            size == nsIntSize(mPluginWindow->width, mPluginWindow->height);
   }
 
   void FixUpURLS(const nsString &name, nsAString &value);
 
   nsPluginNativeWindow       *mPluginWindow;
-  nsCOMPtr<nsIPluginInstance> mInstance;
+  nsRefPtr<nsNPAPIPluginInstance> mInstance;
   nsObjectFrame              *mObjectFrame; // owns nsPluginInstanceOwner
   nsCOMPtr<nsIContent>        mContent;
   nsCString                   mDocumentBase;
   char                       *mTagText;
   nsCOMPtr<nsIWidget>         mWidget;
-  nsCOMPtr<nsIPluginHost>     mPluginHost;
+  nsRefPtr<nsPluginHost>      mPluginHost;
 
 #ifdef XP_MACOSX
   NP_CGContext                              mCGPluginPortCopy;
 #ifndef NP_NO_QUICKDRAW
   NP_Port                                   mQDPluginPortCopy;
 #endif
   PRInt32                                   mInCGPaintLevel;
   nsIOSurface                              *mIOSurface;
@@ -1178,19 +1176,19 @@ nsObjectFrame::FixupWindow(const nsSize&
 }
 
 nsresult
 nsObjectFrame::CallSetWindow(PRBool aCheckIsHidden)
 {
   NPWindow *win = nsnull;
  
   nsresult rv = NS_ERROR_FAILURE;
-  nsCOMPtr<nsIPluginInstance> pi; 
+  nsRefPtr<nsNPAPIPluginInstance> pi;
   if (!mInstanceOwner ||
-      NS_FAILED(rv = mInstanceOwner->GetInstance(*getter_AddRefs(pi))) ||
+      NS_FAILED(rv = mInstanceOwner->GetInstance(getter_AddRefs(pi))) ||
       !pi ||
       NS_FAILED(rv = mInstanceOwner->GetWindow(win)) || 
       !win)
     return rv;
 
   nsPluginNativeWindow *window = (nsPluginNativeWindow *)win;
 #ifdef XP_MACOSX
   mInstanceOwner->FixUpPluginWindow(ePluginPaintDisable);
@@ -1570,18 +1568,18 @@ nsObjectFrame::IsTransparentMode() const
     return PR_FALSE;
 
   NPWindow *window;
   mInstanceOwner->GetWindow(window);
   if (window->type != NPWindowTypeDrawable)
     return PR_FALSE;
 
   nsresult rv;
-  nsCOMPtr<nsIPluginInstance> pi;
-  rv = mInstanceOwner->GetInstance(*getter_AddRefs(pi));
+  nsRefPtr<nsNPAPIPluginInstance> pi;
+  rv = mInstanceOwner->GetInstance(getter_AddRefs(pi));
   if (NS_FAILED(rv) || !pi)
     return PR_FALSE;
 
   PRBool transparent = PR_FALSE;
   pi->IsTransparent(&transparent);
   return transparent;
 #endif
 }
@@ -1688,18 +1686,18 @@ nsObjectFrame::PrintPlugin(nsRenderingCo
   // 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
-  nsCOMPtr<nsIPluginInstance> pi;
-  if (NS_FAILED(objectFrame->GetPluginInstance(*getter_AddRefs(pi))) || !pi)
+  nsRefPtr<nsNPAPIPluginInstance> pi;
+  if (NS_FAILED(objectFrame->GetPluginInstance(getter_AddRefs(pi))) || !pi)
     return;
 
   // now we need to setup the correct location for printing
   NPWindow window;
   window.window = nsnull;
 
   // prepare embedded mode printing struct
   NPPrint npprint;
@@ -2228,18 +2226,18 @@ nsObjectFrame::PaintPlugin(nsDisplayList
       gfxQuartzNativeDrawing nativeDrawing(ctx, nativeClipRect - offset);
 
       CGContextRef cgContext = nativeDrawing.BeginNativeDrawing();
       if (!cgContext) {
         NS_WARNING("null CGContextRef during PaintPlugin");
         return;
       }
 
-      nsCOMPtr<nsIPluginInstance> inst;
-      GetPluginInstance(*getter_AddRefs(inst));
+      nsRefPtr<nsNPAPIPluginInstance> inst;
+      GetPluginInstance(getter_AddRefs(inst));
       if (!inst) {
         NS_WARNING("null plugin instance during PaintPlugin");
         nativeDrawing.EndNativeDrawing();
         return;
       }
       NPWindow* window;
       mInstanceOwner->GetWindow(window);
       if (!window) {
@@ -2315,18 +2313,18 @@ nsObjectFrame::PaintPlugin(nsDisplayList
       gfxRect dirtyGfxRect =
         PresContext()->AppUnitsToGfxUnits(aDirtyRect);
       gfxContext* ctx = aRenderingContext.ThebesContext();
 
       mInstanceOwner->Paint(ctx, frameGfxRect, dirtyGfxRect);
     }
   }
 #elif defined(XP_WIN)
-  nsCOMPtr<nsIPluginInstance> inst;
-  GetPluginInstance(*getter_AddRefs(inst));
+  nsRefPtr<nsNPAPIPluginInstance> inst;
+  GetPluginInstance(getter_AddRefs(inst));
   if (inst) {
     gfxRect frameGfxRect =
       PresContext()->AppUnitsToGfxUnits(aPluginRect);
     gfxRect dirtyGfxRect =
       PresContext()->AppUnitsToGfxUnits(aDirtyRect);
     gfxContext *ctx = aRenderingContext.ThebesContext();
     gfxMatrix currentMatrix = ctx->CurrentMatrix();
 
@@ -2419,18 +2417,18 @@ nsObjectFrame::PaintPlugin(nsDisplayList
         nativeDraw.EndNativeDrawing();
       } while (nativeDraw.ShouldRenderAgain());
       nativeDraw.PaintToContext();
     }
 
     ctx->SetMatrix(currentMatrix);
   }
 #elif defined(XP_OS2)
-  nsCOMPtr<nsIPluginInstance> inst;
-  GetPluginInstance(*getter_AddRefs(inst));
+  nsRefPtr<nsNPAPIPluginInstance> inst;
+  GetPluginInstance(getter_AddRefs(inst));
   if (inst) {
     // Look if it's windowless
     NPWindow *window;
     mInstanceOwner->GetWindow(window);
 
     if (window->type == NPWindowTypeDrawable) {
       // FIXME - Bug 385435: Doesn't aDirtyRect need translating too?
       nsRenderingContext::AutoPushTranslation
@@ -2583,19 +2581,19 @@ nsObjectFrame::HandlePress(nsPresContext
                            nsEventStatus* anEventStatus)
 {
   nsIPresShell::SetCapturingContent(GetContent(), CAPTURE_IGNOREALLOWED);
   return nsObjectFrameSuper::HandlePress(aPresContext, anEvent, anEventStatus);
 }
 #endif
 
 nsresult
-nsObjectFrame::GetPluginInstance(nsIPluginInstance*& aPluginInstance)
-{
-  aPluginInstance = nsnull;
+nsObjectFrame::GetPluginInstance(nsNPAPIPluginInstance** aPluginInstance)
+{
+  *aPluginInstance = nsnull;
 
   if (!mInstanceOwner)
     return NS_OK;
   
   return mInstanceOwner->GetInstance(aPluginInstance);
 }
 
 nsresult
@@ -2741,18 +2739,18 @@ nsObjectFrame::Instantiate(const char* a
   mPreventInstantiation = PR_FALSE;
 
   return rv;
 }
 
 void
 nsObjectFrame::TryNotifyContentObjectWrapper()
 {
-  nsCOMPtr<nsIPluginInstance> inst;
-  mInstanceOwner->GetInstance(*getter_AddRefs(inst));
+  nsRefPtr<nsNPAPIPluginInstance> inst;
+  mInstanceOwner->GetInstance(getter_AddRefs(inst));
   if (inst) {
     // The plugin may have set up new interfaces; we need to mess with our JS
     // wrapper.  Note that we DO NOT want to call this if there is no plugin
     // instance!  That would just reenter Instantiate(), trying to create
     // said plugin instance.
     NotifyContentObjectWrapper();
   }
 }
@@ -2778,17 +2776,17 @@ private:
   nsCOMPtr<nsITimer> mTimer;
   nsRefPtr<nsPluginInstanceOwner> mInstanceOwner;
 };
 
 NS_IMPL_ISUPPORTS_INHERITED1(nsStopPluginRunnable, nsRunnable, nsITimerCallback)
 
 #if defined(XP_MACOSX) || defined (XP_WIN)
 static const char*
-GetMIMEType(nsIPluginInstance *aPluginInstance)
+GetMIMEType(nsNPAPIPluginInstance *aPluginInstance)
 {
   if (aPluginInstance) {
     const char* mime = nsnull;
     if (NS_SUCCEEDED(aPluginInstance->GetMIMEType(&mime)) && mime)
       return mime;
   }
   return "";
 }
@@ -2818,39 +2816,39 @@ DoDelayedStop(nsPluginInstanceOwner *aIn
     return PR_TRUE;
   }
   return PR_FALSE;
 }
 
 static void
 DoStopPlugin(nsPluginInstanceOwner *aInstanceOwner, PRBool aDelayedStop)
 {
-  nsCOMPtr<nsIPluginInstance> inst;
-  aInstanceOwner->GetInstance(*getter_AddRefs(inst));
+  nsRefPtr<nsNPAPIPluginInstance> inst;
+  aInstanceOwner->GetInstance(getter_AddRefs(inst));
   if (inst) {
     NPWindow *win;
     aInstanceOwner->GetWindow(win);
     nsPluginNativeWindow *window = (nsPluginNativeWindow *)win;
-    nsCOMPtr<nsIPluginInstance> nullinst;
+    nsRefPtr<nsNPAPIPluginInstance> nullinst;
 
     if (window) 
       window->CallSetWindow(nullinst);
     else 
       inst->SetWindow(nsnull);
     
     if (DoDelayedStop(aInstanceOwner, aDelayedStop))
       return;
 
 #if defined(XP_MACOSX)
     aInstanceOwner->HidePluginWindow();
 #endif
 
     nsCOMPtr<nsIPluginHost> pluginHost = do_GetService(MOZ_PLUGIN_HOST_CONTRACTID);
     NS_ASSERTION(pluginHost, "Without a pluginHost, how can we have an instance to destroy?");
-    pluginHost->StopPluginInstance(inst);
+    static_cast<nsPluginHost*>(pluginHost.get())->StopPluginInstance(inst);
 
     // the frame is going away along with its widget so tell the
     // window to forget its widget too
     if (window)
       window->SetPluginWidget(nsnull);
   }
 
   aInstanceOwner->Destroy();
@@ -2895,19 +2893,19 @@ nsStopPluginRunnable::Run()
   return NS_OK;
 }
 
 void
 nsObjectFrame::StopPlugin()
 {
   PRBool delayedStop = PR_FALSE;
 #ifdef XP_WIN
-  nsCOMPtr<nsIPluginInstance> inst;
+  nsRefPtr<nsNPAPIPluginInstance> inst;
   if (mInstanceOwner)
-    mInstanceOwner->GetInstance(*getter_AddRefs(inst));
+    mInstanceOwner->GetInstance(getter_AddRefs(inst));
   if (inst) {
     // Delayed stop for Real plugin only; see bug 420886, 426852.
     const char* pluginType = ::GetMIMEType(inst);
     delayedStop = strcmp(pluginType, "audio/x-pn-realaudio-plugin") == 0;
   }
 #endif
   StopPluginInternal(delayedStop);
 }
@@ -2990,18 +2988,18 @@ nsObjectFrame::StopPluginInternal(PRBool
 
 NS_IMETHODIMP
 nsObjectFrame::GetCursor(const nsPoint& aPoint, nsIFrame::Cursor& aCursor)
 {
   if (!mInstanceOwner) {
     return NS_ERROR_FAILURE;
   }
 
-  nsCOMPtr<nsIPluginInstance> inst;
-  mInstanceOwner->GetInstance(*getter_AddRefs(inst));
+  nsRefPtr<nsNPAPIPluginInstance> inst;
+  mInstanceOwner->GetInstance(getter_AddRefs(inst));
   if (!inst) {
     return NS_ERROR_FAILURE;
   }
 
   PRBool useDOMCursor = static_cast<nsNPAPIPluginInstance*>(inst.get())->UsesDOMForCursor();
   if (!useDOMCursor) {
     return NS_ERROR_FAILURE;
   }
@@ -3050,18 +3048,18 @@ nsObjectFrame::NotifyContentObjectWrappe
 nsIObjectFrame *
 nsObjectFrame::GetNextObjectFrame(nsPresContext* aPresContext, nsIFrame* aRoot)
 {
   nsIFrame* child = aRoot->GetFirstChild(nsnull);
 
   while (child) {
     nsIObjectFrame* outFrame = do_QueryFrame(child);
     if (outFrame) {
-      nsCOMPtr<nsIPluginInstance> pi;
-      outFrame->GetPluginInstance(*getter_AddRefs(pi));  // make sure we have a REAL plugin
+      nsRefPtr<nsNPAPIPluginInstance> pi;
+      outFrame->GetPluginInstance(getter_AddRefs(pi));  // make sure we have a REAL plugin
       if (pi)
         return outFrame;
     }
 
     outFrame = GetNextObjectFrame(aPresContext, child);
     if (outFrame)
       return outFrame;
     child = child->GetNextSibling();
@@ -3306,18 +3304,18 @@ NS_INTERFACE_MAP_BEGIN(nsPluginInstanceO
   NS_INTERFACE_MAP_ENTRY(nsIDOMMouseListener)
   NS_INTERFACE_MAP_ENTRY(nsIDOMMouseMotionListener)
   NS_INTERFACE_MAP_ENTRY(nsIDOMKeyListener)
   NS_INTERFACE_MAP_ENTRY(nsIDOMFocusListener)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIDOMEventListener, nsIDOMMouseListener)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIPluginInstanceOwner)
 NS_INTERFACE_MAP_END
 
-NS_IMETHODIMP
-nsPluginInstanceOwner::SetInstance(nsIPluginInstance *aInstance)
+nsresult
+nsPluginInstanceOwner::SetInstance(nsNPAPIPluginInstance *aInstance)
 {
   NS_ASSERTION(!mInstance || !aInstance, "mInstance should only be set or unset!");
 
   // If we're going to null out mInstance after use, be sure to call
   // mInstance->InvalidateOwner() here, since it now won't be called
   // from our destructor.  This fixes bug 613376.
   if (mInstance && !aInstance)
     mInstance->InvalidateOwner();
@@ -3383,20 +3381,22 @@ NS_IMETHODIMP nsPluginInstanceOwner::Get
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP nsPluginInstanceOwner::GetDOMElement(nsIDOMElement* *result)
 {
   return CallQueryInterface(mContent, result);
 }
 
-NS_IMETHODIMP nsPluginInstanceOwner::GetInstance(nsIPluginInstance *&aInstance)
-{
-  NS_IF_ADDREF(aInstance = mInstance);
-
+nsresult nsPluginInstanceOwner::GetInstance(nsNPAPIPluginInstance **aInstance)
+{
+  NS_ENSURE_ARG_POINTER(aInstance);
+
+  NS_IF_ADDREF(mInstance);
+  *aInstance = mInstance;
   return NS_OK;
 }
 
 NS_IMETHODIMP nsPluginInstanceOwner::GetURL(const char *aURL,
                                             const char *aTarget,
                                             nsIInputStream *aPostStream,
                                             void *aHeadersData,
                                             PRUint32 aHeadersDataLen)
@@ -6348,17 +6348,17 @@ nsPluginInstanceOwner::Renderer::DrawWit
   Screen *screen = cairo_xlib_surface_get_screen(xsurface->CairoSurface());
   Colormap colormap;
   Visual* visual;
   if (!xsurface->GetColormapAndVisual(&colormap, &visual)) {
     NS_ERROR("Failed to get visual and colormap");
     return NS_ERROR_UNEXPECTED;
   }
 
-  nsIPluginInstance *instance = mInstanceOwner->mInstance;
+  nsNPAPIPluginInstance *instance = mInstanceOwner->mInstance;
   if (!instance)
     return NS_ERROR_FAILURE;
 
   // See if the plugin must be notified of new window parameters.
   PRBool doupdatewindow = PR_FALSE;
 
   if (mWindow->x != offset.x || mWindow->y != offset.y) {
     mWindow->x = offset.x;
@@ -6736,17 +6736,17 @@ NS_IMETHODIMP nsPluginInstanceOwner::Cre
     }
   }
 
   return rv;
 }
 
 void nsPluginInstanceOwner::SetPluginHost(nsIPluginHost* aHost)
 {
-  mPluginHost = aHost;
+  mPluginHost = static_cast<nsPluginHost*>(aHost);
 }
 
 #ifdef MOZ_USE_IMAGE_EXPOSE
 PRBool nsPluginInstanceOwner::UpdateVisibility(PRBool aVisible)
 {
   // NOTE: Death grip must be held by caller.
   if (!mInstance)
     return PR_TRUE;
--- a/layout/generic/nsObjectFrame.h
+++ b/layout/generic/nsObjectFrame.h
@@ -120,17 +120,17 @@ public:
 #ifdef DEBUG
   NS_IMETHOD GetFrameName(nsAString& aResult) const;
 #endif
 
   virtual void DestroyFrom(nsIFrame* aDestructRoot);
 
   virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext);
 
-  NS_IMETHOD GetPluginInstance(nsIPluginInstance*& aPluginInstance);
+  NS_METHOD GetPluginInstance(nsNPAPIPluginInstance** aPluginInstance);
   virtual nsresult Instantiate(nsIChannel* aChannel, nsIStreamListener** aStreamListener);
   virtual nsresult Instantiate(const char* aMimeType, nsIURI* aURI);
   virtual void TryNotifyContentObjectWrapper();
   virtual void StopPlugin();
 
   /*
    * Stop a plugin instance. If aDelayedStop is true, the plugin will
    * be stopped at a later point when it's safe to do so (i.e. not
--- a/widget/src/cocoa/nsChildView.mm
+++ b/widget/src/cocoa/nsChildView.mm
@@ -64,17 +64,17 @@
 #include "nsIViewManager.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsIServiceManager.h"
 #include "nsILocalFile.h"
 #include "nsILocalFileMac.h"
 #include "nsGfxCIID.h"
 #include "nsIMenuRollup.h"
 #include "nsIDOMSimpleGestureEvent.h"
-#include "nsIPluginInstance.h"
+#include "nsNPAPIPluginInstance.h"
 #include "nsThemeConstants.h"
 
 #include "nsDragService.h"
 #include "nsClipboard.h"
 #include "nsCursorManager.h"
 #include "nsWindowMap.h"
 #include "nsCocoaUtils.h"
 #include "nsMenuUtilsX.h"
@@ -712,18 +712,18 @@ void nsChildView::HidePlugin()
   NS_ASSERTION(mWindowType == eWindowType_plugin,
                "HidePlugin called on non-plugin view");
 
 #ifndef NP_NO_QUICKDRAW
   if (mPluginInstanceOwner && mView &&
       [(ChildView*)mView pluginDrawingModel] == NPDrawingModelQuickDraw) {
     NPWindow* window;
     mPluginInstanceOwner->GetWindow(window);
-    nsCOMPtr<nsIPluginInstance> instance;
-    mPluginInstanceOwner->GetInstance(*getter_AddRefs(instance));
+    nsRefPtr<nsNPAPIPluginInstance> instance;
+    mPluginInstanceOwner->GetInstance(getter_AddRefs(instance));
     if (window && instance) {
        window->clipRect.top = 0;
        window->clipRect.left = 0;
        window->clipRect.bottom = 0;
        window->clipRect.right = 0;
        instance->SetWindow(window);
     }
   }
@@ -1177,18 +1177,18 @@ void nsChildView::PaintQD()
   void *window = ::GetWindowFromPort(static_cast<NP_Port*>(pluginPort)->port);
 
   NS_SUCCEEDED(StartDrawPlugin());
   EventRecord updateEvent;
   InitializeEventRecord(&updateEvent, nsnull);
   updateEvent.what = updateEvt;
   updateEvent.message = UInt32(window);
 
-  nsCOMPtr<nsIPluginInstance> instance;
-  mPluginInstanceOwner->GetInstance(*getter_AddRefs(instance));
+  nsRefPtr<nsNPAPIPluginInstance> instance;
+  mPluginInstanceOwner->GetInstance(getter_AddRefs(instance));
 
   instance->HandleEvent(&updateEvent, nsnull);
   EndDrawPlugin();
 #endif
 }
 
 NS_IMETHODIMP nsChildView::StartDrawPlugin()
 {