nsCOMPtr<nsIDocument> doc(do_CreateInstance(kHTMLDocumentCID)); if (doc) { mDocument = doc; NS_ADDREF(mDocument);    nsCOMPtr<nsIURI> uri; GetURI(getter_AddRefs(uri)); if (uri) mDocument->SetDocumentURL(uri);    nsCOMPtr<nsIScriptGlobalObject> global (do_GetInterface(mContainer)); if (global) { mDocument->SetScriptGlobalObject(global); nsCOMPtr<nsIDOMDocument> domdoc(do_QueryInterface(mDocument)); if (domdoc) global->SetNewDocument(domdoc, PR_TRUE, PR_TRUE); }  }
PluginViewerImpl::StartLoad(nsIRequest* request, nsIStreamListener*& aResult){  nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);  if (!channel || !mWindow)     return NS_ERROR_FAILURE;    NS_IF_RELEASE(mChannel);  mChannel = channel;  NS_ADDREF(mChannel);#ifdef DEBUG  nsCAutoString contentType;  channel->GetContentType(contentType);  printf("PluginViewerImpl::StartLoad: content-type=%s\n", contentType.get());#endif  aResult = nsnull;  // Only instantiate the plugin if our container can host it  nsCOMPtr<nsIPluginHost> host;  host = do_GetService(kCPluginManagerCID);  nsresult rv = NS_ERROR_FAILURE;  if(host)   {    // create a document so that we can pass something back to plugin    // instance if it wants one    nsCOMPtr<nsIDocument> doc(do_CreateInstance(kHTMLDocumentCID));    if (doc) {          mDocument = doc;      NS_ADDREF(mDocument);  // released in ~nsPluginViewer            // set the document's URL       // so it can be fetched later for resolving relative URLs      nsCOMPtr<nsIURI> uri;      GetURI(getter_AddRefs(uri));      if (uri)        mDocument->SetDocumentURL(uri);             // we're going to need the docshell later to reload this full-page plugin in the event of a plugins refresh      // so stuff it in the document we created      nsCOMPtr<nsIScriptGlobalObject> global (do_GetInterface(mContainer));      if (global) {        mDocument->SetScriptGlobalObject(global);        nsCOMPtr<nsIDOMDocument> domdoc(do_QueryInterface(mDocument));        if (domdoc)          global->SetNewDocument(domdoc, PR_TRUE, PR_TRUE);      }    }    nsRect r;    mWindow->GetClientBounds(r);    rv = CreatePlugin(request, host, nsRect(0, 0, r.width, r.height), aResult);#ifdef XP_MAC    // On Mac, we need to initiate the intial invalidate for full-page plugins to ensure    // the entire window gets cleared. Otherwise, Acrobat won't initially repaint on top     // of our previous presentation and we may have garbage leftover    mWindow->Invalidate(PR_FALSE);#endif  }  return rv;}