NS_IMETHODIMP nsMsgWindow::GetRootDocShell(nsIDocShell * *aDocShell) { if (mRootDocShellWeak) CallQueryReferent(mRootDocShellWeak.get(), aDocShell); else *aDocShell = nsnull; return NS_OK; }
NS_IMETHODIMP nsMsgWindow::GetDomWindow(nsIDOMWindow **aWindow) { NS_ENSURE_ARG_POINTER(aWindow); if (mDomWindow) CallQueryReferent(mDomWindow.get(), aWindow); else *aWindow = nsnull; return NS_OK; }
already_AddRefed<nsIPresShell> nsAccessNode::GetPresShell() { nsIPresShell* presShell = nsnull; if (mWeakShell) CallQueryReferent(mWeakShell.get(), &presShell); return presShell; }
/* Get a handle to the Session history listener */ NS_IMETHODIMP nsSHistory::GetListener(nsISHistoryListener ** aListener) { NS_ENSURE_ARG_POINTER(aListener); if (mListener) CallQueryReferent(mListener.get(), aListener); // Don't addref aListener. It is a weak pointer. return NS_OK; }
int main() { /* * NOTE: This does NOT demonstrate how these functions are * intended to be used. They are intended for filling in out * parameters that need to be |AddRef|ed. I'm just too lazy * to write lots of little getter functions for a test program * when I don't need to. */ NS_NOTREACHED("This test is not intended to run, only to compile!"); /* Test CallQueryInterface */ nsISupports *mySupportsPtr = reinterpret_cast<nsISupports*>(0x1000); nsITestService *myITestService = nsnull; CallQueryInterface(mySupportsPtr, &myITestService); nsTestService *myTestService = reinterpret_cast<nsTestService*>(mySupportsPtr); nsISupportsWeakReference *mySupportsWeakRef; CallQueryInterface(myTestService, &mySupportsWeakRef); nsCOMPtr<nsISupports> mySupportsCOMPtr = mySupportsPtr; CallQueryInterface(mySupportsCOMPtr, &myITestService); nsRefPtr<nsTestService> myTestServiceRefPtr = myTestService; CallQueryInterface(myTestServiceRefPtr, &mySupportsWeakRef); /* Test CallQueryReferent */ nsIWeakReference *myWeakRef = static_cast<nsIWeakReference*>(mySupportsPtr); CallQueryReferent(myWeakRef, &myITestService); /* Test CallCreateInstance */ CallCreateInstance(kTestServiceCID, mySupportsPtr, &myITestService); CallCreateInstance(kTestServiceCID, &myITestService); CallCreateInstance(NS_TEST_SERVICE_CONTRACTID, mySupportsPtr, &myITestService); CallCreateInstance(NS_TEST_SERVICE_CONTRACTID, &myITestService); /* Test CallGetService */ CallGetService(kTestServiceCID, &myITestService); CallGetService(NS_TEST_SERVICE_CONTRACTID, &myITestService); /* Test CallGetInterface */ nsIInterfaceRequestor *myInterfaceRequestor = static_cast<nsIInterfaceRequestor*>(mySupportsPtr); CallGetInterface(myInterfaceRequestor, &myITestService); return 0; }
NS_IMETHODIMP nsMsgProgress::GetMsgWindow(nsIMsgWindow **aMsgWindow) { NS_ENSURE_ARG_POINTER(aMsgWindow); if (m_msgWindow) CallQueryReferent(m_msgWindow.get(), aMsgWindow); else *aMsgWindow = nsnull; return NS_OK; }
already_AddRefed<nsIPresShell> nsBoxObject::GetPresShell() { if (!mPresShell) { return nsnull; } nsIPresShell* shell = nsnull; CallQueryReferent(mPresShell.get(), &shell); return shell; }
NS_IMETHODIMP nsDOMPopupBlockedEvent::GetRequestingWindow(nsIDOMWindow **aRequestingWindow) { *aRequestingWindow = nsnull; if (mEvent->eventStructType == NS_POPUPBLOCKED_EVENT) { nsPopupBlockedEvent* event = static_cast<nsPopupBlockedEvent*>(mEvent); if (event->mRequestingWindow) { CallQueryReferent(event->mRequestingWindow.get(), aRequestingWindow); } } return NS_OK; // Don't throw an exception }
already_AddRefed<nsIPresShell> nsTypeAheadFind::GetPresShell() { if (!mPresShell) return nsnull; nsIPresShell *shell = nsnull; CallQueryReferent(mPresShell.get(), &shell); if (shell) { nsPresContext *pc = shell->GetPresContext(); if (!pc || !nsCOMPtr<nsISupports>(pc->GetContainer())) { NS_RELEASE(shell); } } return shell; }
nsresult nsIOService::GetCachedProtocolHandler(const char *scheme, nsIProtocolHandler **result, uint32_t start, uint32_t end) { uint32_t len = end - start - 1; for (unsigned int i=0; i<NS_N(gScheme); i++) { if (!mWeakHandler[i]) continue; // handle unterminated strings // start is inclusive, end is exclusive, len = end - start - 1 if (end ? (!nsCRT::strncasecmp(scheme + start, gScheme[i], len) && gScheme[i][len] == '\0') : (!nsCRT::strcasecmp(scheme, gScheme[i]))) { return CallQueryReferent(mWeakHandler[i].get(), result); } } return NS_ERROR_FAILURE; }