From f7510c86368ce4a6bb5c563f0d715d280e47fc05 Mon Sep 17 00:00:00 2001 From: "beard%netscape.com" Date: Wed, 24 Mar 1999 05:40:02 +0000 Subject: [PATCH] added GetJSWindow --- .../plugin/base/src/nsPluginInstancePeer.cpp | 34 +++++++++++++++++++ .../plugin/base/src/nsPluginInstancePeer.h | 3 ++ .../plugin/nglsrc/nsPluginInstancePeer.cpp | 34 +++++++++++++++++++ modules/plugin/nglsrc/nsPluginInstancePeer.h | 3 ++ 4 files changed, 74 insertions(+) diff --git a/modules/plugin/base/src/nsPluginInstancePeer.cpp b/modules/plugin/base/src/nsPluginInstancePeer.cpp index 2e79df18ab8a..bd50e558baf8 100644 --- a/modules/plugin/base/src/nsPluginInstancePeer.cpp +++ b/modules/plugin/base/src/nsPluginInstancePeer.cpp @@ -27,6 +27,11 @@ #include "nsFileSpec.h" #include "nsCOMPtr.h" +#include "nsIDocument.h" +#include "nsIScriptContextOwner.h" +#include "nsIScriptGlobalObject.h" +#include "nsIScriptObjectOwner.h" + #ifdef XP_PC #include "windows.h" #include "winbase.h" @@ -751,6 +756,35 @@ printf("instance peer setwindowsize called\n"); return NS_OK; } +NS_IMETHODIMP nsPluginInstancePeerImpl::GetJSWindow(JSObject* *outJSWindow) +{ + *outJSWindow = NULL; + nsresult rv = NS_ERROR_FAILURE; + 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); + } + return rv; +} + nsresult nsPluginInstancePeerImpl :: Initialize(nsIPluginInstanceOwner *aOwner, const nsMIMEType aMIMEType) { diff --git a/modules/plugin/base/src/nsPluginInstancePeer.h b/modules/plugin/base/src/nsPluginInstancePeer.h index 6d0e6599878c..2547a2b7872c 100644 --- a/modules/plugin/base/src/nsPluginInstancePeer.h +++ b/modules/plugin/base/src/nsPluginInstancePeer.h @@ -58,6 +58,9 @@ public: NS_IMETHOD SetWindowSize(PRUint32 width, PRUint32 height); + NS_IMETHOD + GetJSWindow(JSObject* *outJSWindow); + // nsIWindowlessPluginInstancePeer // (Corresponds to NPN_InvalidateRect.) diff --git a/modules/plugin/nglsrc/nsPluginInstancePeer.cpp b/modules/plugin/nglsrc/nsPluginInstancePeer.cpp index 2e79df18ab8a..bd50e558baf8 100644 --- a/modules/plugin/nglsrc/nsPluginInstancePeer.cpp +++ b/modules/plugin/nglsrc/nsPluginInstancePeer.cpp @@ -27,6 +27,11 @@ #include "nsFileSpec.h" #include "nsCOMPtr.h" +#include "nsIDocument.h" +#include "nsIScriptContextOwner.h" +#include "nsIScriptGlobalObject.h" +#include "nsIScriptObjectOwner.h" + #ifdef XP_PC #include "windows.h" #include "winbase.h" @@ -751,6 +756,35 @@ printf("instance peer setwindowsize called\n"); return NS_OK; } +NS_IMETHODIMP nsPluginInstancePeerImpl::GetJSWindow(JSObject* *outJSWindow) +{ + *outJSWindow = NULL; + nsresult rv = NS_ERROR_FAILURE; + 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); + } + return rv; +} + nsresult nsPluginInstancePeerImpl :: Initialize(nsIPluginInstanceOwner *aOwner, const nsMIMEType aMIMEType) { diff --git a/modules/plugin/nglsrc/nsPluginInstancePeer.h b/modules/plugin/nglsrc/nsPluginInstancePeer.h index 6d0e6599878c..2547a2b7872c 100644 --- a/modules/plugin/nglsrc/nsPluginInstancePeer.h +++ b/modules/plugin/nglsrc/nsPluginInstancePeer.h @@ -58,6 +58,9 @@ public: NS_IMETHOD SetWindowSize(PRUint32 width, PRUint32 height); + NS_IMETHOD + GetJSWindow(JSObject* *outJSWindow); + // nsIWindowlessPluginInstancePeer // (Corresponds to NPN_InvalidateRect.)