From 8e03e4e94b3262235d877672405fce3079df219f Mon Sep 17 00:00:00 2001 From: "peterlubczynski%netscape.com" Date: Sat, 5 Oct 2002 02:57:21 +0000 Subject: [PATCH] Fixing bug 169513, Add the means to obtain the DOM from a plugin r=adamlock sr=beard git-svn-id: svn://10.0.0.236/trunk@131221 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/modules/plugin/base/public/npapi.h | 7 +- .../modules/plugin/base/src/ns4xPlugin.cpp | 74 +++++++++++++++++++ 2 files changed, 79 insertions(+), 2 deletions(-) diff --git a/mozilla/modules/plugin/base/public/npapi.h b/mozilla/modules/plugin/base/public/npapi.h index 05179551407..4c97aa4ae5b 100644 --- a/mozilla/modules/plugin/base/public/npapi.h +++ b/mozilla/modules/plugin/base/public/npapi.h @@ -38,7 +38,7 @@ /* - * npapi.h $Revision: 3.23 $ + * npapi.h $Revision: 3.24 $ * Netscape client plug-in API spec */ @@ -353,7 +353,10 @@ typedef enum { NPNVisOfflineBool, /* 10 and over are available on Mozilla builds starting with 0.9.4 */ - NPNVserviceManager = 10 + NPNVserviceManager = 10, + NPNVDOMElement = 11, /* available in Mozilla 1.2 */ + NPNVDOMDocument = 12, + NPNVDOMWindow = 13 } NPNVariable; /* diff --git a/mozilla/modules/plugin/base/src/ns4xPlugin.cpp b/mozilla/modules/plugin/base/src/ns4xPlugin.cpp index 170b77dd06b..3a2dc4d904d 100644 --- a/mozilla/modules/plugin/base/src/ns4xPlugin.cpp +++ b/mozilla/modules/plugin/base/src/ns4xPlugin.cpp @@ -53,6 +53,13 @@ #include "nsIPluginInstancePeer2.h" #include "nsIJSContextStack.h" +#include "nsPIPluginInstancePeer.h" +#include "nsIDOMElement.h" +#include "nsIDOMDocument.h" +#include "nsIDOMWindow.h" +#include "nsIDocument.h" +#include "nsIScriptGlobalObject.h" + #ifdef XP_MAC #include #endif @@ -1211,6 +1218,73 @@ _getvalue(NPP npp, NPNVariable variable, void *result) return NPERR_GENERIC_ERROR; } + case NPNVDOMElement: { + ns4xPluginInstance *inst = (ns4xPluginInstance *) npp->ndata; + NS_ENSURE_TRUE(inst, NPERR_GENERIC_ERROR); + + nsCOMPtr pip; + inst->GetPeer(getter_AddRefs(pip)); + nsCOMPtr pti2 (do_QueryInterface(pip)); + if (pti2) { + nsCOMPtr e; + pti2->GetDOMElement(getter_AddRefs(e)); + if (e) { + NS_ADDREF(*(nsIDOMElement**)result = e.get()); + return NPERR_NO_ERROR; + } + } + return NPERR_GENERIC_ERROR; + } + + case NPNVDOMDocument: { + ns4xPluginInstance *inst = (ns4xPluginInstance *) npp->ndata; + NS_ENSURE_TRUE(inst, NPERR_GENERIC_ERROR); + + nsCOMPtr pip; + inst->GetPeer(getter_AddRefs(pip)); + nsCOMPtr pp (do_QueryInterface(pip)); + if (pp) { + nsCOMPtr owner; + pp->GetOwner(getter_AddRefs(owner)); + if (owner) { + nsCOMPtr doc; + owner->GetDocument(getter_AddRefs(doc)); + nsCOMPtr domDoc (do_QueryInterface(doc)); + if (domDoc) { + NS_ADDREF(*(nsIDOMDocument**)result = domDoc.get()); + return NPERR_NO_ERROR; + } + } + } + return NPERR_GENERIC_ERROR; + } + + case NPNVDOMWindow: { + ns4xPluginInstance *inst = (ns4xPluginInstance *) npp->ndata; + NS_ENSURE_TRUE(inst, NPERR_GENERIC_ERROR); + + nsCOMPtr pip; + inst->GetPeer(getter_AddRefs(pip)); + nsCOMPtr pp (do_QueryInterface(pip)); + if (pp) { + nsCOMPtr owner; + pp->GetOwner(getter_AddRefs(owner)); + if (owner) { + nsCOMPtr doc; + owner->GetDocument(getter_AddRefs(doc)); + if (doc) { + nsCOMPtr globalScript; + doc->GetScriptGlobalObject(getter_AddRefs(globalScript)); + nsCOMPtr domWindow (do_QueryInterface(globalScript)); + if (domWindow) { + NS_ADDREF(*(nsIDOMWindow**)result = domWindow.get()); + return NPERR_NO_ERROR; + } + } + } + } + return NPERR_GENERIC_ERROR; + } default : return NPERR_GENERIC_ERROR; } }