if (mCXMenuListener) { mCXMenuListener->Destroy(mOwner); NS_RELEASE(mCXMenuListener); }
nsPluginInstanceOwner::Destroy(){  nsCOMPtr<nsIContent> content;  mOwner->GetContent(getter_AddRefs(content));  // 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");  mOwner = nsnull; // break relationship between frame and plugin instance owner  return NS_OK;}