nsCOMPtr<nsIChannel> aChannel = do_QueryInterface(aRequest); if (!aChannel) return NS_ERROR_FAILURE;
} }   if (!parentWindow || !jsContext) { nsCOMPtr<nsIAppShellService> windowService (do_GetService(kAppShellServiceCID)); NS_ENSURE_SUCCESS(windowService->GetHiddenWindowAndJSContext(getter_AddRefs(parentWindow), &jsContext), NS_ERROR_FAILURE); }
NS_IMETHODIMP nsBrowserContentHandler::HandleContent(const char * aContentType,                                                     nsIInterfaceRequestor * aWindowContext,                                                     nsIRequest * aRequest){  NS_PRECONDITION(aContentType, "Must have a content type");  // Verify that we can handle this content, to avoid infinite window opening  // loops  nsresult rv;  nsCOMPtr<nsIWebNavigationInfo> webNavInfo =    do_GetService(NS_WEBNAVIGATION_INFO_CONTRACTID, &rv);  NS_ENSURE_SUCCESS(rv, rv);  PRUint32 typeSupported;  rv = webNavInfo->IsTypeSupported(nsDependentCString(aContentType), nsnull,                                   &typeSupported);  NS_ENSURE_SUCCESS(rv, rv);  if (!typeSupported)      return NS_ERROR_WONT_HANDLE_CONTENT;  // create a new browser window to handle the content  NS_ENSURE_ARG(aRequest);  nsCOMPtr<nsIDOMWindow> parentWindow;  if (aWindowContext)    parentWindow = do_GetInterface(aWindowContext);  nsCOMPtr<nsIChannel> aChannel = do_QueryInterface(aRequest);  if (!aChannel) return NS_ERROR_FAILURE;  nsCOMPtr<nsIURI> uri;  aChannel->GetURI(getter_AddRefs(uri));  NS_ENSURE_TRUE(uri, NS_ERROR_FAILURE);  nsCAutoString spec;  uri->GetSpec(spec);  nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID));  if (wwatch) {    nsCOMPtr<nsIDOMWindow> newWindow;    wwatch->OpenWindow(parentWindow, spec.get(), "", 0, 0,              getter_AddRefs(newWindow));  }  // now abort the current channel load...  aRequest->Cancel(NS_BINDING_ABORTED);  return NS_OK;}