if (IsBroken()) {     if (!child) { CreateDefaultFrames(aPresContext, aMetrics, aReflowState);  child = mFrames.FirstChild(); }  if (child) { GetDesiredSize(aPresContext, aReflowState, aMetrics);    nsHTMLReflowState state(aPresContext, aReflowState, child, nsSize(aReflowState.availableWidth, aReflowState.availableHeight));  float t2p = aPresContext->TwipsToPixels(); PRInt32 width = NSTwipsToIntPixels(aMetrics.width - state.mComputedBorderPadding.LeftRight(), t2p); PRInt32 height = NSTwipsToIntPixels(aMetrics.height - state.mComputedBorderPadding.TopBottom(), t2p);   SizeAnchor(child->GetContent(), width, height);        nsReflowType reflowType(eReflowType_StyleChanged); aPresContext->PresShell()->CancelReflowCommand(child, &reflowType); }
if(child != nsnull) return HandleImage(aPresContext, aMetrics, aReflowState, aStatus, child);   if(!mInstanceOwner) {  mInstanceOwner = new nsPluginInstanceOwner(); if(!mInstanceOwner) return NS_ERROR_OUT_OF_MEMORY;  NS_ADDREF(mInstanceOwner); mInstanceOwner->Init(&aPresContext, this);  nsISupports               *container = nsnull; nsIPluginHost             *pluginHost = nsnull; nsIContentViewerContainer *cv = nsnull; nsIURI* baseURL = nsnull; nsIURI* fullURL = nsnull;  nsAutoString classid; PRInt32 nameSpaceID;   mContent->GetNameSpaceID(nameSpaceID); if (NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute(nameSpaceID, nsHTMLAtoms::classid, classid)) { nsCID widgetCID;  PRBool bJavaObject = PR_FALSE; PRBool bJavaPluginClsid = PR_FALSE;  if (classid.Find("java:") != -1) { classid.Cut(0, 5); bJavaObject = PR_TRUE; }  if (classid.Find("clsid:") != -1) { classid.Cut(0, 6); bJavaPluginClsid = (classid == JAVA_CLASS_ID); }   if(bJavaObject || bJavaPluginClsid) { mimeType = (char *)PR_Malloc(PL_strlen("application/x-java-vm") + 1); PL_strcpy(mimeType, "application/x-java-vm");  if((rv = GetBaseURL(baseURL)) != NS_OK) return rv;  #ifndef NECKO nsILoadGroup* group = nsnull; if (nsnull != baseURL) baseURL->GetLoadGroup(&group); #endif  nsAutoString codeBase; if(NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::codebase, codeBase) && !bJavaPluginClsid) { nsIURI* codeBaseURL = nsnull; #ifdef NECKO rv = NS_NewURI(&codeBaseURL, codeBase, baseURL); #else rv = NS_NewURL(&codeBaseURL, codeBase, baseURL, nsnull, group); #endif if(rv == NS_OK) { NS_IF_RELEASE(baseURL); baseURL = codeBaseURL; } }  #ifndef NECKO const char* urlxxx; (void)baseURL->GetSpec(&urlxxx); #endif   if(bJavaPluginClsid) { #ifdef NECKO rv = NS_NewURI(&fullURL, classid, baseURL); #else rv = NS_NewURL(&fullURL, classid, baseURL, nsnull, group); #endif } else { fullURL = baseURL; NS_IF_ADDREF(fullURL); } #ifndef NECKO NS_IF_RELEASE(group); #endif   if((rv = aPresContext.GetContainer(&container)) != NS_OK) return rv; if((rv = container->QueryInterface(kIContentViewerContainerIID, (void **)&cv)) != NS_OK) { NS_RELEASE(container); return rv; } if((rv = cv->QueryCapability(kIPluginHostIID, (void **)&pluginHost)) != NS_OK) { NS_RELEASE(container); NS_RELEASE(cv); return rv; }  mInstanceOwner->SetPluginHost(pluginHost); rv = InstantiatePlugin(aPresContext, aMetrics, aReflowState, pluginHost, mimeType, fullURL); } else {   if (classid == "browser") { widgetCID = kCAppShellCID; rv = InstantiateWidget(aPresContext, aMetrics, aReflowState, widgetCID); } else {   if((rv = GetBaseURL(baseURL)) != NS_OK) return rv;  #ifndef NECKO nsILoadGroup* group = nsnull; if(nsnull != baseURL) baseURL->GetLoadGroup(&group); #endif   nsAutoString codeBase; if (NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::codebase, codeBase)) { nsIURI* codeBaseURL = nsnull; #ifdef NECKO rv = NS_NewURI(&fullURL, codeBase, baseURL); #else rv = NS_NewURL(&fullURL, codeBase, baseURL, nsnull, group); #endif if(rv == NS_OK) { NS_IF_RELEASE(baseURL); baseURL = codeBaseURL; } } else { fullURL = baseURL; NS_IF_ADDREF(fullURL); }  #ifndef NECKO NS_IF_RELEASE(group); #endif   if((rv = aPresContext.GetContainer(&container)) != NS_OK) return rv; if((rv = container->QueryInterface(kIContentViewerContainerIID, (void **)&cv)) != NS_OK) { NS_RELEASE(container); return rv; } if((rv = cv->QueryCapability(kIPluginHostIID, (void **)&pluginHost)) != NS_OK) { NS_RELEASE(container); NS_RELEASE(cv); return rv; }  mInstanceOwner->SetPluginHost(pluginHost); if(pluginHost->IsPluginEnabledForType("application/x-oleobject") == NS_OK) rv = InstantiatePlugin(aPresContext, aMetrics, aReflowState, pluginHost, "application/x-oleobject", fullURL); else if(pluginHost->IsPluginEnabledForType("application/oleobject") == NS_OK) rv = InstantiatePlugin(aPresContext, aMetrics, aReflowState, pluginHost, "application/oleobject", fullURL); else rv = NS_ERROR_FAILURE; } }  NS_IF_RELEASE(baseURL); NS_IF_RELEASE(fullURL); NS_IF_RELEASE(pluginHost); NS_IF_RELEASE(cv); NS_IF_RELEASE(container);   if(rv == NS_OK) { aStatus = NS_FRAME_COMPLETE; return NS_OK; }   nsIPresShell* presShell; aPresContext.GetShell(&presShell); presShell->CantRenderReplacedElement(&aPresContext, this); NS_RELEASE(presShell); aStatus = NS_FRAME_COMPLETE; return NS_OK; }    nsIAtom* atom = nsnull; nsAutoString    src;  if((rv = GetBaseURL(baseURL)) != NS_OK) return rv;   if((rv = aPresContext.GetContainer(&container)) != NS_OK) return rv; if((rv = container->QueryInterface(kIContentViewerContainerIID, (void **)&cv)) != NS_OK) { NS_RELEASE(container); return rv; } if((rv = cv->QueryCapability(kIPluginHostIID, (void **)&pluginHost)) != NS_OK) { NS_RELEASE(container); NS_RELEASE(cv); return rv; }  mInstanceOwner->SetPluginHost(pluginHost);  mContent->GetTag(atom);  if (atom == nsHTMLAtoms::applet && atom) { mimeType = (char *)PR_Malloc(PL_strlen("application/x-java-vm") + 1); PL_strcpy(mimeType, "application/x-java-vm");  if (NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::code, src)) { #ifndef NECKO nsILoadGroup* group = nsnull; if (nsnull != baseURL) baseURL->GetLoadGroup(&group); #endif  nsAutoString codeBase; if (NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::codebase, codeBase)) { nsIURI* codeBaseURL = nsnull; #ifdef NECKO rv = NS_NewURI(&codeBaseURL, codeBase, baseURL); #else rv = NS_NewURL(&codeBaseURL, codeBase, baseURL, nsnull, group); #endif if(rv == NS_OK) { NS_IF_RELEASE(baseURL); baseURL = codeBaseURL; } }   #ifdef NECKO rv = NS_NewURI(&fullURL, src, baseURL); #else rv = NS_NewURL(&fullURL, src, baseURL, nsnull, group); NS_IF_RELEASE(group); #endif }  rv = InstantiatePlugin(aPresContext, aMetrics, aReflowState, pluginHost, mimeType, fullURL); } else { nsAutoString type; mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::type, type);  buflen = type.Length(); if (buflen > 0) { mimeType = (char *)PR_Malloc(buflen + 1); if (nsnull != mimeType) type.ToCString(mimeType, buflen + 1); }   if (NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::src, src)) { #ifdef NECKO  rv = NS_NewURI(&fullURL, src, baseURL); #else nsILoadGroup* group = nsnull; if (nsnull != baseURL) baseURL->GetLoadGroup(&group);   rv = NS_NewURL(&fullURL, src, baseURL, nsnull, group); NS_IF_RELEASE(group); #endif } else if(NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::data, src)) { #ifdef NECKO  rv = NS_NewURI(&fullURL, src, baseURL); #else nsILoadGroup* group = nsnull; if (nsnull != baseURL) baseURL->GetLoadGroup(&group);   rv = NS_NewURL(&fullURL, src, baseURL, nsnull, group); NS_IF_RELEASE(group); #endif } else { fullURL = baseURL; NS_IF_ADDREF(fullURL); }    if(!mimeType && src.GetUnicode()) { char* extension; char* cString = src.ToNewCString(); extension = PL_strrchr(cString, '.'); if(extension) ++extension;  pluginHost->IsPluginEnabledForExtension((const char *)extension, (const char *&)mimeType);  delete [] cString; }  rv = InstantiatePlugin(aPresContext, aMetrics, aReflowState, pluginHost, mimeType, fullURL); }  NS_IF_RELEASE(atom); NS_IF_RELEASE(baseURL); NS_IF_RELEASE(fullURL); NS_IF_RELEASE(pluginHost); NS_IF_RELEASE(cv); NS_IF_RELEASE(container);
nsObjectFrame::Reflow(nsPresContext*           aPresContext,                      nsHTMLReflowMetrics&     aMetrics,                      const nsHTMLReflowState& aReflowState,                      nsReflowStatus&          aStatus){  DO_GLOBAL_REFLOW_COUNT("nsObjectFrame", aReflowState.reason);  DISPLAY_REFLOW(aPresContext, this, aReflowState, aMetrics, aStatus);  nsresult rv = NS_OK;  // If we have a child, we toss the reflow over to it.  nsIFrame * child = mFrames.FirstChild();  if (IsBroken()) {    // This is a broken plugin, if we don't already have a child    // frame, create the child frames manually. If any of this frame    // construction code ever changes to use the frame constructor, or    // any other change, this probably needs some changes too.    if (!child) {      CreateDefaultFrames(aPresContext, aMetrics, aReflowState);      child = mFrames.FirstChild();    }    if (child) {      GetDesiredSize(aPresContext, aReflowState, aMetrics);      // Build a reflow state so we can see what the child's border and      // padding are going to be      nsHTMLReflowState state(aPresContext, aReflowState, child,                              nsSize(aReflowState.availableWidth,                                     aReflowState.availableHeight));      float t2p = aPresContext->TwipsToPixels();      PRInt32 width = NSTwipsToIntPixels(aMetrics.width - state.mComputedBorderPadding.LeftRight(), t2p);      PRInt32 height = NSTwipsToIntPixels(aMetrics.height - state.mComputedBorderPadding.TopBottom(), t2p);      // Set the child's content width and height      SizeAnchor(child->GetContent(), width, height);      // SizeAnchor() is seriously evil as it ends up setting an      // attribute (through the style changes that it does) while      // we're in reflow. This is also seriously evil, as it pulls      // that reflow command out of the reflow queue, as leaving it      // there can get us into infinite loops while reflowing object      // frames for missing plugins.      nsReflowType reflowType(eReflowType_StyleChanged);      aPresContext->PresShell()->CancelReflowCommand(child, &reflowType);    }  }  if (child) {    // Reflow the child; our size just depends on that of the child,    // pure and simple    return HandleChild(aPresContext, aMetrics, aReflowState, aStatus, child);  }  // Get our desired size  GetDesiredSize(aPresContext, aReflowState, aMetrics);  // delay plugin instantiation until all children have  // arrived. Otherwise there may be PARAMs or other stuff that the  // plugin needs to see that haven't arrived yet.  if (!GetContent()->IsDoneAddingChildren()) {    aStatus = NS_FRAME_COMPLETE;    return rv;  }  // if we are printing or print previewing, bail for now  if (aPresContext->Medium() == nsLayoutAtoms::print) {    aStatus = NS_FRAME_COMPLETE;    return rv;  }  FixupWindow(nsSize(aMetrics.width, aMetrics.height));  aStatus = NS_FRAME_COMPLETE;  NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aMetrics);  return rv;}