nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObject; theDoc->GetScriptGlobalObject(getter_AddRefs(scriptGlobalObject));  nsCOMPtr<nsIDOMWindowInternal> domWindow = do_QueryInterface(scriptGlobalObject);
nsCOMPtr<nsIDOMWindowInternal> domWindow = do_QueryInterface(theDoc->GetScriptGlobalObject());
NS_IMETHODIMP nsDocViewerSelectionListener::NotifySelectionChanged(nsIDOMDocument *, nsISelection *, short){  NS_ASSERTION(mDocViewer, "Should have doc viewer!");  // get the selection state  nsCOMPtr<nsISelection> selection;  nsresult rv = mDocViewer->GetDocumentSelection(getter_AddRefs(selection));  if (NS_FAILED(rv)) return rv;  PRBool selectionCollapsed;  selection->GetIsCollapsed(&selectionCollapsed);  // we only call UpdateCommands when the selection changes from collapsed  // to non-collapsed or vice versa. We might need another update string  // for simple selection changes, but that would be expenseive.  if (!mGotSelectionState || mSelectionWasCollapsed != selectionCollapsed)  {    nsCOMPtr<nsIDocument> theDoc;    mDocViewer->GetDocument(getter_AddRefs(theDoc));    if (!theDoc) return NS_ERROR_FAILURE;    nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObject;    theDoc->GetScriptGlobalObject(getter_AddRefs(scriptGlobalObject));    nsCOMPtr<nsIDOMWindowInternal> domWindow = do_QueryInterface(scriptGlobalObject);    if (!domWindow) return NS_ERROR_FAILURE;    domWindow->UpdateCommands(NS_LITERAL_STRING("select"));    mGotSelectionState = PR_TRUE;    mSelectionWasCollapsed = selectionCollapsed;  }  return NS_OK;}