nsCOMPtr<nsIPresContext> context; GetPresContext(this, getter_AddRefs(context));  if (context) { nsIFrame* frame; rv = context->PresShell()->GetPrimaryFrameFor(this, &frame); NS_ENSURE_SUCCESS(rv, rv);
nsIFrame* frame = GetPrimaryFrameFor(this, mDocument, PR_FALSE);
nsHTMLBodyElement::GetBgColor(nsAString& aBgColor){  aBgColor.Truncate();  nsAutoString attr;  nscolor bgcolor;  nsresult rv = GetAttr(kNameSpaceID_None, nsHTMLAtoms::bgcolor, attr);  // If we don't have an attribute, find the actual color used for  // (generally from the user agent style sheet) for compatibility  if (rv == NS_CONTENT_ATTR_NOT_THERE) {    // XXX This should just use nsGenericHTMLElement::GetPrimaryFrame()    if (mDocument) {      // Make sure the presentation is up-to-date      mDocument->FlushPendingNotifications();    }    nsCOMPtr<nsIPresContext> context;    GetPresContext(this, getter_AddRefs(context));    if (context) {      nsIFrame* frame;      rv = context->PresShell()->GetPrimaryFrameFor(this, &frame);      NS_ENSURE_SUCCESS(rv, rv);      if (frame) {        bgcolor = frame->GetStyleBackground()->mBackgroundColor;        NS_RGBToHex(bgcolor, aBgColor);      }    }  }  else if (NS_ColorNameToRGB(attr, &bgcolor)) {    // If we have a color name which we can convert to an nscolor,    // then we should use the hex value instead of the color name.    NS_RGBToHex(bgcolor, aBgColor);  }  else {    // Otherwise, just assign whatever the attribute value is.    aBgColor.Assign(attr);  }  return NS_OK;}