if (NS_FAILED(rv)) {   mContent->SetProperty(nsCSSPseudoClasses::mozBroken, NS_INT32_TO_PTR(1));   rv = aPresContext->PresShell()->CantRenderReplacedElement(this); } else {    NotifyContentObjectWrapper(); }
nsIPresShell* presShell; aPresContext.GetShell(&presShell); presShell->CantRenderReplacedElement(&aPresContext, this); NS_RELEASE(presShell);
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;  }  // if mInstance is null, we need to determine what kind of object we are and instantiate ourselves  if (!mInstanceOwner) {    // XXX - do we need to create this for widgets as well?    mInstanceOwner = new nsPluginInstanceOwner();    if (!mInstanceOwner)      return NS_ERROR_OUT_OF_MEMORY;    NS_ADDREF(mInstanceOwner);    mInstanceOwner->Init(aPresContext, this);    // get the nsIPluginHost service    nsCOMPtr<nsIPluginHost> pluginHost(do_GetService(kCPluginManagerCID));    nsCOMPtr<nsISupports> container;    nsCOMPtr<nsIURI> fullURL;    nsAutoString classid;    nsCOMPtr<nsIURI> baseURI = mContent->GetBaseURI();    nsAutoString codeBase;    if ((NS_CONTENT_ATTR_HAS_VALUE ==         mContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::codebase, codeBase)) &&        !codeBase.IsEmpty()) {      nsCOMPtr<nsIURI> codeBaseURL;      rv = MakeAbsoluteURL(getter_AddRefs(codeBaseURL), codeBase, baseURI);      if (NS_SUCCEEDED(rv)) {        baseURI = codeBaseURL;      }    }    // if we have a clsid, we're either an internal widget, an ActiveX control, or an applet    if (mContent->Tag() == nsHTMLAtoms::object &&        NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::classid, classid)) {      PRBool bJavaObject;      bJavaObject = StringBeginsWith(classid, NS_LITERAL_STRING("java:"));      // if we find "java:" in the class id, we have a java applet      if (bJavaObject) {        if (!baseURI) {          rv = NS_ERROR_FAILURE;        }        else {          fullURL = baseURI;          if (pluginHost) {            mInstanceOwner->SetPluginHost(pluginHost);            rv = InstantiatePlugin(aPresContext, aMetrics, aReflowState,                                   pluginHost, "application/x-java-vm",                                   fullURL);          }        }      }      else { // otherwise, we're either an ActiveX control or an internal widget        // These are some builtin types that we know about for now.        // (Eventually this will move somewhere else.)        if (classid.EqualsLiteral("browser")) {          rv = InstantiateWidget(aPresContext, aMetrics,                                 aReflowState, kCAppShellCID);        }        else {          // if we haven't matched to an internal type, check to see if          // we have an ActiveX handler          // if not, create the default plugin          if (!baseURI) {            rv = NS_ERROR_FAILURE;          }          else {            fullURL = baseURI;            if (pluginHost) {              mInstanceOwner->SetPluginHost(pluginHost);              if (NS_SUCCEEDED(pluginHost->IsPluginEnabledForType("application/x-oleobject"))) {                rv = InstantiatePlugin(aPresContext, aMetrics, aReflowState,                                       pluginHost, "application/x-oleobject",                                       fullURL);              } else if (NS_SUCCEEDED(pluginHost->IsPluginEnabledForType("application/oleobject"))) {                rv = InstantiatePlugin(aPresContext, aMetrics, aReflowState,                                       pluginHost, "application/oleobject",                                       fullURL);              } else {                rv = NS_ERROR_FAILURE;              }            }          }        }      }      // finish up      if (NS_SUCCEEDED(rv)) {        aStatus = NS_FRAME_COMPLETE;        return NS_OK;      }    }    else { // no clsid - the object is either an applet or a plugin      nsAutoString    src;      if (!baseURI) {        rv = NS_ERROR_FAILURE;      }      else {        if (pluginHost) {          mInstanceOwner->SetPluginHost(pluginHost);          nsIAtom *tag = mContent->Tag();          if (tag == nsHTMLAtoms::applet) {            if (NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::code, src)) {              // Create an absolute URL              rv = MakeAbsoluteURL(getter_AddRefs(fullURL), src, baseURI);            }            else              fullURL = baseURI;            rv = InstantiatePlugin(aPresContext, aMetrics, aReflowState,                                  pluginHost, "application/x-java-vm", fullURL);          } else { // traditional plugin            nsXPIDLCString mimeTypeStr;            nsAutoString type;            mContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::type, type);            if (type.Length()) {              mimeTypeStr.Adopt(ToNewCString(type));            }            // Stream in the object source if there is one...            // If this is an OBJECT tag, we should look for a DATA attribute.            // If not, it's an EMBED tag, and so we should look for a SRC attribute.            if (tag == nsHTMLAtoms::object)              rv = mContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::data, src);            else              rv = mContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::src, src);                        if (NS_CONTENT_ATTR_HAS_VALUE == rv) {              // Create an absolute URL              rv = MakeAbsoluteURL(getter_AddRefs(fullURL), src, baseURI);              if (NS_FAILED(rv)) {                // Failed to create URI, maybe because we didn't                // reconize the protocol handler ==> treat like                // no 'src'/'data' was specified in the embed/object tag                fullURL = baseURI;              }            }            else {              // we didn't find a src or data param, so just set the url              // to the base              fullURL = baseURI;            }            // now try to instantiate a plugin instance based on a mime type            const char* mimeType = mimeTypeStr.get();            if (mimeType || !src.IsEmpty()) {              if (!mimeType) {                // we don't have a mime type, try to figure it out                // from extension                PRInt32 offset = src.RFindChar(PRUnichar('.'));                if (offset != kNotFound)                  pluginHost->IsPluginEnabledForExtension(NS_ConvertUTF16toUTF8(Substring(src, offset + 1, src.Length())).get(), mimeType);              }              // if we fail to get a mime type from extension we can              // still try to instantiate plugin as it can be possible              // to determine it later              rv = InstantiatePlugin(aPresContext, aMetrics, aReflowState,                                     pluginHost, mimeType, fullURL);            }            else // if we have neither we should not bother              rv = NS_ERROR_FAILURE;          }        }      }    }  }  else { // if (!mInstanceOwner)    rv = ReinstantiatePlugin(aPresContext, aMetrics, aReflowState);  }  // finish up  if (NS_FAILED(rv)) {    // XXXbz A bit of a hack with the property name, but that's ok.    // biesi's moving this stuff into content anyway.  ;)    mContent->SetProperty(nsCSSPseudoClasses::mozBroken,                          NS_INT32_TO_PTR(1));    // check for alternative content with CantRenderReplacedElement()    rv = aPresContext->PresShell()->CantRenderReplacedElement(this);  } else {    // XXXbz can't quite unset the property here, since that would    // actually clobber it on nodes that are supposed to have it!  Not    // sure why...    NotifyContentObjectWrapper();  }  aStatus = NS_FRAME_COMPLETE;  NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aMetrics);  return rv;}