scriptGlobal = doc->GetScriptGlobalObject();
window = doc->GetWindow();
NS_CP_GetDocShellFromContext(nsISupports *aContext){    if (!aContext) {        return nsnull;    }    nsCOMPtr<nsIScriptGlobalObject> scriptGlobal = do_QueryInterface(aContext);    if (!scriptGlobal) {        // our context might be a document (which also QIs to nsIDOMNode), so        // try that first        nsCOMPtr<nsIDocument> doc = do_QueryInterface(aContext);        if (!doc) {            // we were not a document after all, get our ownerDocument,            // hopefully            nsCOMPtr<nsIContent> content = do_QueryInterface(aContext);            if (content) {                doc = content->GetOwnerDoc();            }        }        if (doc) {            scriptGlobal = doc->GetScriptGlobalObject();        }    }    if (!scriptGlobal) {        return nsnull;    }    return scriptGlobal->GetDocShell();}