NS_WITH_SERVICE(nsIJVMManager, jvm, nsIJVMManager::GetCID(), &rv);
nsCOMPtr<nsIJVMManager> jvm(do_GetService(nsIJVMManager::GetCID(), &rv));
nsHTMLAppletElement::GetScriptObject(nsIScriptContext* aContext,                                     void** aScriptObject){  nsresult rv = NS_OK;  NS_WITH_SERVICE(nsIJVMManager, jvm, nsIJVMManager::GetCID(), &rv);  if (NS_SUCCEEDED(rv)) {    if (!mReflectedApplet) {      // 0. Make sure the presentation is up-to-date      if (mDocument) {        mDocument->FlushPendingNotifications();      }      // 1. get the script object corresponding to the <APPLET> element itself.      JSObject* elementObject = nsnull;      rv = nsGenericHTMLContainerElement::GetScriptObject(aContext,                                                          (void**)&elementObject);      if (NS_OK != rv)        return rv;      // 2. get the plugin instance corresponding to this element.      nsCOMPtr<nsIPresShell> shell;      if (mDocument)        shell = dont_AddRef(mDocument->GetShellAt(0));      nsIFrame* frame = nsnull;      if (shell) {        shell->GetPrimaryFrameFor(this, &frame);      }      if (frame) {        nsCOMPtr<nsIAtom> frameType;        frame->GetFrameType(getter_AddRefs(frameType));        if(nsLayoutAtoms::objectFrame != frameType.get()) {          *aScriptObject = elementObject;          return rv;        }      }      // 3. get the Java object corresponding to this applet, and      // reflect it into JavaScript using the LiveConnect manager.      JSContext* context = (JSContext*)aContext->GetNativeContext();      JSObject* wrappedAppletObject = nsnull;      nsCOMPtr<nsIPluginInstance> pluginInstance;      rv = NS_GetObjectFramePluginInstance(frame,                                           *getter_AddRefs(pluginInstance));      if ((rv == NS_OK) && (nsnull != pluginInstance)) {        nsCOMPtr<nsIJVMPluginInstance> javaPluginInstance;        javaPluginInstance = do_QueryInterface(pluginInstance);        if (javaPluginInstance) {          jobject appletObject = nsnull;          rv = javaPluginInstance->GetJavaObject(&appletObject);          if (NS_OK == rv) {            nsCOMPtr<nsILiveConnectManager> manager;            manager = do_GetService(nsIJVMManager::GetCID());            if (manager) {              rv = manager->WrapJavaObject(context, appletObject,                                           &wrappedAppletObject);            }          }        }      }      // 4. set the __proto__ field of the applet object to be the      // element script object.      if (nsnull != wrappedAppletObject) {        JS_SetPrototype(context, wrappedAppletObject, elementObject);        SetScriptObject(wrappedAppletObject);        mReflectedApplet = PR_TRUE;      }      *aScriptObject = wrappedAppletObject;    }    else {      rv = nsGenericHTMLContainerElement::GetScriptObject(aContext,                                                          aScriptObject);    }  }  else {    rv = nsGenericHTMLContainerElement::GetScriptObject(aContext,                                                        aScriptObject);  }  return rv;}