if (content) { nsCOMPtr<nsIDOMEventReceiver> receiver(do_QueryInterface(content)); if (receiver) { nsCOMPtr<nsIDOMDragListener> dragListener; QueryInterface(NS_GET_IID(nsIDOMDragListener), getter_AddRefs(dragListener)); if (dragListener) { receiver->RemoveEventListener(NS_LITERAL_STRING("dragdrop"), dragListener, PR_TRUE); receiver->RemoveEventListener(NS_LITERAL_STRING("dragover"), dragListener, PR_TRUE); receiver->RemoveEventListener(NS_LITERAL_STRING("dragexit"), dragListener, PR_TRUE); receiver->RemoveEventListener(NS_LITERAL_STRING("dragenter"), dragListener, PR_TRUE); receiver->RemoveEventListener(NS_LITERAL_STRING("draggesture"), dragListener, PR_TRUE); } else NS_ASSERTION(PR_FALSE, "Unable to remove event listener for plugin"); } else NS_ASSERTION(PR_FALSE, "plugin was not an event listener"); } else NS_ASSERTION(PR_FALSE, "plugin had no content");   nsIFrame* parentWithView; mOwner->GetParentWithView(mContext, &parentWithView);  nsIView* curView = nsnull; if (parentWithView) parentWithView->GetView(mContext, &curView); while (curView) { nsIScrollableView* scrollingView; if (NS_SUCCEEDED(CallQueryInterface(curView, &scrollingView))) scrollingView->RemoveScrollPositionListener((nsIScrollPositionListener *)this);  curView->GetParent(curView); }  mOwner = nsnull;
nsPluginInstanceOwner::Destroy(){  nsCOMPtr<nsIContent> content;  mOwner->GetContent(getter_AddRefs(content));  // stop the timer explicitly to reduce reference count.  CancelTimer();  // unregister context menu listener  if (mCXMenuListener) {    mCXMenuListener->Destroy(mOwner);        NS_RELEASE(mCXMenuListener);  }  // Unregister focus event listener  if (content) {    nsCOMPtr<nsIDOMEventReceiver> receiver(do_QueryInterface(content));    if (receiver) {      nsCOMPtr<nsIDOMFocusListener> focusListener;      QueryInterface(NS_GET_IID(nsIDOMFocusListener), getter_AddRefs(focusListener));      if (focusListener) {         receiver->RemoveEventListenerByIID(focusListener, NS_GET_IID(nsIDOMFocusListener));      }      else NS_ASSERTION(PR_FALSE, "Unable to remove event listener for plugin");    }    else NS_ASSERTION(PR_FALSE, "plugin was not an event listener");  }  else NS_ASSERTION(PR_FALSE, "plugin had no content");    // Unregister mouse event listener  if (content) {    nsCOMPtr<nsIDOMEventReceiver> receiver(do_QueryInterface(content));    if (receiver) {      nsCOMPtr<nsIDOMMouseListener> mouseListener;      QueryInterface(NS_GET_IID(nsIDOMMouseListener), getter_AddRefs(mouseListener));      if (mouseListener) {         receiver->RemoveEventListenerByIID(mouseListener, NS_GET_IID(nsIDOMMouseListener));      }      else NS_ASSERTION(PR_FALSE, "Unable to remove event listener for plugin");      // now for the mouse motion listener      nsCOMPtr<nsIDOMMouseMotionListener> mouseMotionListener;      QueryInterface(NS_GET_IID(nsIDOMMouseMotionListener), getter_AddRefs(mouseMotionListener));      if (mouseMotionListener) {         receiver->RemoveEventListenerByIID(mouseMotionListener, NS_GET_IID(nsIDOMMouseMotionListener));      }      else NS_ASSERTION(PR_FALSE, "Unable to remove event listener for plugin");    }    else NS_ASSERTION(PR_FALSE, "plugin was not an event listener");  }  else NS_ASSERTION(PR_FALSE, "plugin had no content");    // Unregister key event listener;  if (content) {    nsCOMPtr<nsIDOMEventReceiver> receiver(do_QueryInterface(content));    if (receiver) {      nsCOMPtr<nsIDOMKeyListener> keyListener;      QueryInterface(NS_GET_IID(nsIDOMKeyListener), getter_AddRefs(keyListener));      if (keyListener) {         receiver->RemoveEventListener(NS_LITERAL_STRING("keypress"), keyListener, PR_TRUE);        receiver->RemoveEventListener(NS_LITERAL_STRING("keydown"), keyListener, PR_TRUE);        receiver->RemoveEventListener(NS_LITERAL_STRING("keyup"), keyListener, PR_TRUE);      }      else NS_ASSERTION(PR_FALSE, "Unable to remove event listener for plugin");    }    else NS_ASSERTION(PR_FALSE, "plugin was not an event listener");  }  else NS_ASSERTION(PR_FALSE, "plugin had no content");  // Unregister drag event listener;  if (content) {    nsCOMPtr<nsIDOMEventReceiver> receiver(do_QueryInterface(content));    if (receiver) {      nsCOMPtr<nsIDOMDragListener> dragListener;      QueryInterface(NS_GET_IID(nsIDOMDragListener), getter_AddRefs(dragListener));      if (dragListener) {         receiver->RemoveEventListener(NS_LITERAL_STRING("dragdrop"), dragListener, PR_TRUE);        receiver->RemoveEventListener(NS_LITERAL_STRING("dragover"), dragListener, PR_TRUE);        receiver->RemoveEventListener(NS_LITERAL_STRING("dragexit"), dragListener, PR_TRUE);        receiver->RemoveEventListener(NS_LITERAL_STRING("dragenter"), dragListener, PR_TRUE);        receiver->RemoveEventListener(NS_LITERAL_STRING("draggesture"), dragListener, PR_TRUE);      }      else NS_ASSERTION(PR_FALSE, "Unable to remove event listener for plugin");    }    else NS_ASSERTION(PR_FALSE, "plugin was not an event listener");  }  else NS_ASSERTION(PR_FALSE, "plugin had no content");  // Unregister scroll position listener  nsIFrame* parentWithView;  mOwner->GetParentWithView(mContext, &parentWithView);    nsIView* curView = nsnull;  if (parentWithView)    parentWithView->GetView(mContext, &curView);  while (curView)  {    nsIScrollableView* scrollingView;    if (NS_SUCCEEDED(CallQueryInterface(curView, &scrollingView)))      scrollingView->RemoveScrollPositionListener((nsIScrollPositionListener *)this);        curView->GetParent(curView);  }  mOwner = nsnull; // break relationship between frame and plugin instance owner  return NS_OK;}