From 9d6661c4ef18c5afcb8b13113814c6f20ea49a8e Mon Sep 17 00:00:00 2001 From: "beard%netscape.com" Date: Wed, 24 Mar 1999 05:40:02 +0000 Subject: [PATCH] added GetJSWindow git-svn-id: svn://10.0.0.236/trunk@24970 18797224-902f-48f8-a5cc-f745e15eee43 --- .../plugin/base/src/nsPluginInstancePeer.cpp | 34 +++++++++++++++++++ .../plugin/base/src/nsPluginInstancePeer.h | 3 ++ .../plugin/nglsrc/nsPluginInstancePeer.cpp | 34 +++++++++++++++++++ .../plugin/nglsrc/nsPluginInstancePeer.h | 3 ++ 4 files changed, 74 insertions(+) diff --git a/mozilla/modules/plugin/base/src/nsPluginInstancePeer.cpp b/mozilla/modules/plugin/base/src/nsPluginInstancePeer.cpp index 2e79df18ab8..bd50e558baf 100644 --- a/mozilla/modules/plugin/base/src/nsPluginInstancePeer.cpp +++ b/mozilla/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/mozilla/modules/plugin/base/src/nsPluginInstancePeer.h b/mozilla/modules/plugin/base/src/nsPluginInstancePeer.h index 6d0e6599878..2547a2b7872 100644 --- a/mozilla/modules/plugin/base/src/nsPluginInstancePeer.h +++ b/mozilla/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/mozilla/modules/plugin/nglsrc/nsPluginInstancePeer.cpp b/mozilla/modules/plugin/nglsrc/nsPluginInstancePeer.cpp index 2e79df18ab8..bd50e558baf 100644 --- a/mozilla/modules/plugin/nglsrc/nsPluginInstancePeer.cpp +++ b/mozilla/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/mozilla/modules/plugin/nglsrc/nsPluginInstancePeer.h b/mozilla/modules/plugin/nglsrc/nsPluginInstancePeer.h index 6d0e6599878..2547a2b7872 100644 --- a/mozilla/modules/plugin/nglsrc/nsPluginInstancePeer.h +++ b/mozilla/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.)