if (mShell) {   nsIDocument *doc = mShell->GetDocument(); if (doc) { doc->RemoveCharSetObserver(this); } }
mShell = aShell; if (nsnull != mShell) { nsCOMPtr<nsIDocument> doc; if (NS_SUCCEEDED(mShell->GetDocument(getter_AddRefs(doc)))) { NS_ASSERTION(doc, "expect document here"); if (doc) { doc->GetBaseURL(*getter_AddRefs(mBaseURL));
nsPresContext::SetShell(nsIPresShell* aShell){  if (mShell) {    // Remove ourselves as the charset observer from the shell's doc, because    // this shell may be going away for good.    nsIDocument *doc = mShell->GetDocument();    if (doc) {      doc->RemoveCharSetObserver(this);    }  }      mShell = aShell;  if (mShell) {    nsIDocument *doc = mShell->GetDocument();    NS_ASSERTION(doc, "expect document here");    if (doc) {      nsIURI *baseURI = doc->GetBaseURI();      if (mMedium != nsLayoutAtoms::print && baseURI) {        PRBool isChrome = PR_FALSE;        PRBool isRes = PR_FALSE;        baseURI->SchemeIs("chrome", &isChrome);        baseURI->SchemeIs("resource", &isRes);        if (!isChrome && !isRes)          mImageAnimationMode = mImageAnimationModePref;        else          mImageAnimationMode = imgIContainer::kNormalAnimMode;      }      if (mLangService) {        doc->AddCharSetObserver(this);        UpdateCharSet(doc->GetDocumentCharacterSet());      }    }  }}