diff --git a/modules/plugin/base/src/nsPluginInstancePeer.cpp b/modules/plugin/base/src/nsPluginInstancePeer.cpp index cb392cb514d..a2412934461 100644 --- a/modules/plugin/base/src/nsPluginInstancePeer.cpp +++ b/modules/plugin/base/src/nsPluginInstancePeer.cpp @@ -35,7 +35,6 @@ #include "nsIServiceManager.h" #include "nsIDocument.h" -#include "nsIScriptContextOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIScriptObjectOwner.h" @@ -781,31 +780,23 @@ NS_IMETHODIMP nsPluginInstancePeerImpl::GetJSWindow(JSObject* *outJSWindow) *outJSWindow = NULL; nsresult rv = NS_ERROR_FAILURE; NS_WITH_SERVICE ( nsIJVMManager, jvm, nsIJVMManager::GetCID(), &rv); - if ( NS_SUCCEEDED ( rv ) && jvm != nsnull ) - { - nsIDocument* document = nsnull; - if (mOwner->GetDocument(&document) == NS_OK) { - nsIScriptContextOwner* contextOwner = document->GetScriptContextOwner(); - if (nsnull != contextOwner) { - nsIScriptGlobalObject *global = nsnull; - contextOwner->GetScriptGlobalObject(&global); - nsIScriptContext* context = nsnull; - contextOwner->GetScriptContext(&context); - if (nsnull != global && nsnull != context) { - static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); - nsIScriptObjectOwner* window = nsnull; - if (global->QueryInterface(kIScriptObjectOwnerIID, (void **)&window) == NS_OK) { - rv = window->GetScriptObject(context, (void**)outJSWindow); - NS_RELEASE(window); - } - } - NS_IF_RELEASE(global); - NS_IF_RELEASE(context); - NS_RELEASE(contextOwner); - } - NS_RELEASE(document); - } - } + if ( NS_SUCCEEDED ( rv ) && jvm != nsnull ) { + nsCOMPtr document; + if (mOwner->GetDocument(getter_AddRefs(document)) == NS_OK) { + nsCOMPtr global; + document->GetScriptGlobalObject(getter_AddRefs(global)); + if(global) { + nsCOMPtr context; + global->GetContext(getter_AddRefs(context)); + if (nsnull != context) { + nsCOMPtr window(do_QueryInterface(global)); + if (window) { + rv = window->GetScriptObject(context, (void**)outJSWindow); + } + } + } + } + } return rv; } @@ -821,21 +812,19 @@ NS_IMETHODIMP nsPluginInstancePeerImpl::GetJSContext(JSContext* *outContext) nsresult rv = NS_ERROR_FAILURE; NS_WITH_SERVICE(nsIJVMManager, jvm, nsIJVMManager::GetCID(), &rv); if (NS_SUCCEEDED(rv) && jvm != nsnull ) { - nsIDocument* document = nsnull; - if (mOwner->GetDocument(&document) == NS_OK) { - nsIScriptContextOwner* contextOwner = document->GetScriptContextOwner(); - if (nsnull != contextOwner) { - nsIScriptContext* context = nsnull; - if (contextOwner->GetScriptContext(&context) == NS_OK) { + nsCOMPtr document; + if (mOwner->GetDocument(getter_AddRefs(document)) == NS_OK) { + nsCOMPtr global; + document->GetScriptGlobalObject(getter_AddRefs(global)); + if (global) { + nsCOMPtr context; + if (global->GetContext(getter_AddRefs(context)) == NS_OK) { *outContext = (JSContext*) context->GetNativeContext(); - NS_RELEASE(context); rv = NS_OK; } - NS_RELEASE(contextOwner); - } - NS_RELEASE(document); - } - } + } + } + } return rv; } diff --git a/modules/plugin/nglsrc/nsPluginInstancePeer.cpp b/modules/plugin/nglsrc/nsPluginInstancePeer.cpp index cb392cb514d..a2412934461 100644 --- a/modules/plugin/nglsrc/nsPluginInstancePeer.cpp +++ b/modules/plugin/nglsrc/nsPluginInstancePeer.cpp @@ -35,7 +35,6 @@ #include "nsIServiceManager.h" #include "nsIDocument.h" -#include "nsIScriptContextOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIScriptObjectOwner.h" @@ -781,31 +780,23 @@ NS_IMETHODIMP nsPluginInstancePeerImpl::GetJSWindow(JSObject* *outJSWindow) *outJSWindow = NULL; nsresult rv = NS_ERROR_FAILURE; NS_WITH_SERVICE ( nsIJVMManager, jvm, nsIJVMManager::GetCID(), &rv); - if ( NS_SUCCEEDED ( rv ) && jvm != nsnull ) - { - nsIDocument* document = nsnull; - if (mOwner->GetDocument(&document) == NS_OK) { - nsIScriptContextOwner* contextOwner = document->GetScriptContextOwner(); - if (nsnull != contextOwner) { - nsIScriptGlobalObject *global = nsnull; - contextOwner->GetScriptGlobalObject(&global); - nsIScriptContext* context = nsnull; - contextOwner->GetScriptContext(&context); - if (nsnull != global && nsnull != context) { - static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); - nsIScriptObjectOwner* window = nsnull; - if (global->QueryInterface(kIScriptObjectOwnerIID, (void **)&window) == NS_OK) { - rv = window->GetScriptObject(context, (void**)outJSWindow); - NS_RELEASE(window); - } - } - NS_IF_RELEASE(global); - NS_IF_RELEASE(context); - NS_RELEASE(contextOwner); - } - NS_RELEASE(document); - } - } + if ( NS_SUCCEEDED ( rv ) && jvm != nsnull ) { + nsCOMPtr document; + if (mOwner->GetDocument(getter_AddRefs(document)) == NS_OK) { + nsCOMPtr global; + document->GetScriptGlobalObject(getter_AddRefs(global)); + if(global) { + nsCOMPtr context; + global->GetContext(getter_AddRefs(context)); + if (nsnull != context) { + nsCOMPtr window(do_QueryInterface(global)); + if (window) { + rv = window->GetScriptObject(context, (void**)outJSWindow); + } + } + } + } + } return rv; } @@ -821,21 +812,19 @@ NS_IMETHODIMP nsPluginInstancePeerImpl::GetJSContext(JSContext* *outContext) nsresult rv = NS_ERROR_FAILURE; NS_WITH_SERVICE(nsIJVMManager, jvm, nsIJVMManager::GetCID(), &rv); if (NS_SUCCEEDED(rv) && jvm != nsnull ) { - nsIDocument* document = nsnull; - if (mOwner->GetDocument(&document) == NS_OK) { - nsIScriptContextOwner* contextOwner = document->GetScriptContextOwner(); - if (nsnull != contextOwner) { - nsIScriptContext* context = nsnull; - if (contextOwner->GetScriptContext(&context) == NS_OK) { + nsCOMPtr document; + if (mOwner->GetDocument(getter_AddRefs(document)) == NS_OK) { + nsCOMPtr global; + document->GetScriptGlobalObject(getter_AddRefs(global)); + if (global) { + nsCOMPtr context; + if (global->GetContext(getter_AddRefs(context)) == NS_OK) { *outContext = (JSContext*) context->GetNativeContext(); - NS_RELEASE(context); rv = NS_OK; } - NS_RELEASE(contextOwner); - } - NS_RELEASE(document); - } - } + } + } + } return rv; }