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 nsAppStartup::CreateChromeWindow2(nsIWebBrowserChrome *aParent, PRUint32 aChromeFlags, PRUint32 aContextFlags, nsIURI *aURI, PRBool *aCancel, nsIWebBrowserChrome **_retval) { NS_ENSURE_ARG_POINTER(aCancel); NS_ENSURE_ARG_POINTER(_retval); *aCancel = PR_FALSE; *_retval = 0; // Non-modal windows cannot be opened if we are attempting to quit if (mAttemptingQuit && (aChromeFlags & nsIWebBrowserChrome::CHROME_MODAL) == 0) return NS_ERROR_ILLEGAL_DURING_SHUTDOWN; nsCOMPtr<nsIXULWindow> newWindow; if (aParent) { nsCOMPtr<nsIXULWindow> xulParent(do_GetInterface(aParent)); NS_ASSERTION(xulParent, "window created using non-XUL parent. that's unexpected, but may work."); if (xulParent) xulParent->CreateNewWindow(aChromeFlags, mAppShell, getter_AddRefs(newWindow)); // And if it fails, don't try again without a parent. It could fail // intentionally (bug 115969). } else { // try using basic methods: /* You really shouldn't be making dependent windows without a parent. But unparented modal (and therefore dependent) windows happen in our codebase, so we allow it after some bellyaching: */ if (aChromeFlags & nsIWebBrowserChrome::CHROME_DEPENDENT) NS_WARNING("dependent window created without a parent"); nsCOMPtr<nsIAppShellService> appShell(do_GetService(NS_APPSHELLSERVICE_CONTRACTID)); if (!appShell) return NS_ERROR_FAILURE; appShell->CreateTopLevelWindow(0, 0, aChromeFlags, nsIAppShellService::SIZE_TO_CONTENT, nsIAppShellService::SIZE_TO_CONTENT, mAppShell, getter_AddRefs(newWindow)); } // if anybody gave us anything to work with, use it if (newWindow) { newWindow->SetContextFlags(aContextFlags); nsCOMPtr<nsIInterfaceRequestor> thing(do_QueryInterface(newWindow)); if (thing) CallGetInterface(thing.get(), _retval); } return *_retval ? NS_OK : NS_ERROR_FAILURE; }
NS_IMETHODIMP MiroWindowCreator::CreateChromeWindow2( nsIWebBrowserChrome *parent, PRUint32 chromeFlags, PRUint32 contextFlags, nsIURI *uri, PRBool *cancel, nsIWebBrowserChrome **_retval) { nsCAutoString specString; if((chromeFlags & nsIWebBrowserChrome::CHROME_OPENAS_CHROME) == 0) { *cancel = PR_TRUE; *_retval = nsnull; if(uri) { uri->GetSpec(specString); if(mWindowCallback) { mWindowCallback((char*)specString.get(), mWindowCallbackData); } } else { log_warning("Trying to open window with no URI"); } } else { nsCOMPtr <nsIAppShellService> appShellService(do_GetService(NS_APPSHELLSERVICE_CONTRACTID)); if (!appShellService) { return NS_ERROR_FAILURE; } nsCOMPtr <nsIXULWindow> newWindow; nsCOMPtr <nsIAppShell> appShell(do_GetService(kAppShellCID)); appShellService->CreateTopLevelWindow(0, 0, chromeFlags, nsIAppShellService::SIZE_TO_CONTENT, nsIAppShellService::SIZE_TO_CONTENT, appShell, getter_AddRefs(newWindow)); if (newWindow) { newWindow->SetContextFlags(contextFlags); nsCOMPtr<nsIInterfaceRequestor> thing(do_QueryInterface(newWindow)); if (thing) { CallGetInterface(thing.get(), _retval); NS_IF_ADDREF(*_retval); } } } return NS_OK; }