nsCOMPtr <nsIChannel> channel = do_QueryInterface(aRequest);
nsCOMPtr <nsIChannel> channel = do_QueryInterface(aRequest, &rv); if (NS_FAILED(rv)) { NS_ERROR("Error querying request to nsIChannel"); return rv; }
GtkMozEmbedPrivate::OnChromeStateChange(nsIWebProgress *aWebProgress,					nsIRequest *aRequest,					PRInt32 aStateFlags,					PRUint32 aStatus){  // XXX add shortcut here for content + chrome already loaded  if ((aStateFlags & GTK_MOZ_EMBED_FLAG_IS_DOCUMENT) &&       (aStateFlags & GTK_MOZ_EMBED_FLAG_STOP))  {    nsXPIDLCString uriString;    nsCString      chromeString;    // get the original URI for this    nsCOMPtr <nsIChannel> channel = do_QueryInterface(aRequest);    nsCOMPtr <nsIURI>     origURI;    channel->GetOriginalURI(getter_AddRefs(origURI));    origURI->GetSpec(getter_Copies(uriString));    chromeString.AssignWithConversion(mChromeLocation);    // check to see if this was our chrome that was finished loading.    if (chromeString.Equals(uriString))    {      if (!mChromeLoaded)	mChromeLoaded = PR_TRUE;    }    // if the chrome has been loaded but the content hasn't been    // loaded yet, try to load it.    if (mChromeLoaded && !mContentLoaded)    {            // get the browser as an item      nsCOMPtr<nsIDocShellTreeItem> browserAsItem;      browserAsItem = do_QueryInterface(mWebBrowser);      if (!browserAsItem)      {	NS_ASSERTION(0, "failed to get browser as item");	return NS_OK;      }      // get the owner for that item      nsCOMPtr<nsIDocShellTreeOwner> treeOwner;      browserAsItem->GetTreeOwner(getter_AddRefs(treeOwner));      if (!treeOwner)      {	NS_ASSERTION(0, "failed to get tree owner");	return NS_OK;      }      // get the primary content shell as an item      nsCOMPtr<nsIDocShellTreeItem> contentItem;      treeOwner->GetPrimaryContentShell(getter_AddRefs(contentItem));      if (!contentItem)      {	// apparently our primary content area hasn't been loaded.	// tis ok	printf("Warning: Failed to find primary content shell!  I will try again later.\n");	return NS_OK;      }      // if we made it this far, our primary content shell has been      // loaded.  Mark our flag.      mContentLoaded = PR_TRUE;      // attach our chrome object as the tree owner for the content      // docShell.  this is so that we get JS and link over      // notifications.      contentItem->SetTreeOwner(treeOwner);      // get the docshell for that item      nsCOMPtr <nsIDocShell> docShell;      docShell = do_QueryInterface(contentItem);      if (!docShell)      {	NS_ASSERTION(0, "failed to get docshell");	return NS_OK;      }      // get the nsIWebProgress object for that docshell      nsCOMPtr <nsIWebProgress> webProgress;      webProgress = do_GetInterface(docShell);      if (!webProgress)      {	NS_ASSERTION(0, "Failed to get webProgress object from content area docShell");	return NS_OK;      }      // attach the mContentProgress object to that docshell      webProgress->AddProgressListener(mContentProgress);      // get the navigation for the content area      mContentNav = do_QueryInterface(docShell);      if (!mContentNav)      {	NS_ASSERTION(0, "Failed to get mContentNav object from content area docShell");	return NS_OK;      }      // attach our session history object to the content area      mContentNav->SetSessionHistory(mSessionHistory);      // now that the content is loaded, attach our key listener to      // the chrome document      AddEventListener();      // check to see whether or not we should load a new uri.      if (mCurrentURI.Length() > 0)      {	nsString tmpString;	tmpString.AssignWithConversion(mCurrentURI);	mContentNav->LoadURI(tmpString.GetUnicode(), nsIWebNavigation::LOAD_FLAGS_NONE);      }    }  }  return NS_OK;}