From 2bce851d6d6d80b9ff6de12384635b2ce0b0e3dc Mon Sep 17 00:00:00 2001 From: "dcone%netscape.com" Date: Tue, 12 Mar 2002 14:57:25 +0000 Subject: [PATCH] Adding the debug object. This is not part of the build. git-svn-id: svn://10.0.0.236/trunk@116395 18797224-902f-48f8-a5cc-f745e15eee43 --- .../tools/sdk/samples/simple/makefile.win | 46 +++++--- .../sdk/samples/simple/nsScriptablePeer.cpp | 43 +++++++- .../sdk/samples/simple/nsScriptablePeer.h | 6 +- .../tools/sdk/samples/simple/plugin.cpp | 102 ++++++++++++++++-- .../plugin/tools/sdk/samples/simple/plugin.h | 17 ++- .../tools/sdk/samples/simple/resource.h | 2 +- .../plugin/tools/sdk/samples/simple/test.html | 25 +++-- 7 files changed, 203 insertions(+), 38 deletions(-) diff --git a/mozilla/modules/plugin/tools/sdk/samples/simple/makefile.win b/mozilla/modules/plugin/tools/sdk/samples/simple/makefile.win index ad0024b2897..56cc5f68dfd 100644 --- a/mozilla/modules/plugin/tools/sdk/samples/simple/makefile.win +++ b/mozilla/modules/plugin/tools/sdk/samples/simple/makefile.win @@ -19,22 +19,39 @@ # # Contributor(s): -DEPTH=..\..\..\..\..\.. +DEPTH=..\..\.. +MODULE = npdebug +REQUIRES= xpcom \ + dom \ + necko\ + string \ + widget \ + locale \ + view \ + pref \ + gfx2 \ + imglib2 \ + unicharutil \ + java \ + debug \ + $(NULL) + include <$(DEPTH)\config\config.mak> -MODULE = npsimple + + XPIDLSRCS = \ - .\nsISimplePlugin.idl \ + .\nsIDebugPlugin.idl \ $(NULL) MAKE_OBJ_TYPE = DLL -DLLNAME = npsimple -RESFILE = npsimple.res -DEFFILE = npsimple.def +DLLNAME = npdebug +RESFILE = npdebug.res +DEFFILE = npdebug.def DLL=.\$(OBJDIR)\$(DLLNAME).dll -CFLAGS = $(CFLAGS) -I..\include -I..\..\include +CFLAGS = $(CFLAGS) -I.\include OBJS = \ .\$(OBJDIR)\plugin.obj \ @@ -42,7 +59,8 @@ OBJS = \ $(NULL) LLIBS = \ - ..\common\$(OBJDIR)\plugingate.lib \ + .\common\$(OBJDIR)\plugingate.lib \ + $(DIST)\lib\xpcom.lib \ $(NULL) WIN_LIBS = version.lib @@ -51,13 +69,15 @@ include <$(DEPTH)\config\rules.mak> # don't forget to remove files exported by default libs:: $(DLL) - $(RM) $(XPDIST)\idl\nsISimplePlugin.idl - $(RM) $(XPDIST)\include\nsISimplePlugin.h - $(RM) $(DIST)\bin\components\$(DLLNAME).xpt + $(RM) $(XPDIST)\idl\nsIDebugPlugin.idl + $(RM) $(XPDIST)\include\nsIDebugPlugin.h +# $(RM) $(DIST)\bin\components\$(DLLNAME).xpt + $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\plugins + clobber:: $(RM) *.sbr - $(RM) $(XPDIST)\idl\nsISimplePlugin.idl - $(RM) $(XPDIST)\include\nsISimplePlugin.h + $(RM) $(XPDIST)\idl\nsIDebugPlugin.idl + $(RM) $(XPDIST)\include\nsIDebugPlugin.h $(RM) $(DIST)\bin\components\$(DLLNAME).xpt $(RM) $(DIST)\bin\plugins\$(DLLNAME).dll diff --git a/mozilla/modules/plugin/tools/sdk/samples/simple/nsScriptablePeer.cpp b/mozilla/modules/plugin/tools/sdk/samples/simple/nsScriptablePeer.cpp index 86f6c95f3f3..34e80b729ab 100644 --- a/mozilla/modules/plugin/tools/sdk/samples/simple/nsScriptablePeer.cpp +++ b/mozilla/modules/plugin/tools/sdk/samples/simple/nsScriptablePeer.cpp @@ -47,7 +47,7 @@ // #include "plugin.h" -static NS_DEFINE_IID(kISimplePluginIID, NS_ISIMPLEPLUGIN_IID); +static NS_DEFINE_IID(kIDebugPluginIID, NS_IDEBUGPLUGIN_IID); static NS_DEFINE_IID(kIClassInfoIID, NS_ICLASSINFO_IID); static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); @@ -86,8 +86,8 @@ NS_IMETHODIMP nsScriptablePeer::QueryInterface(const nsIID& aIID, void** aInstan if(!aInstancePtr) return NS_ERROR_NULL_POINTER; - if(aIID.Equals(kISimplePluginIID)) { - *aInstancePtr = static_cast(this); + if(aIID.Equals(kIDebugPluginIID)) { + *aInstancePtr = static_cast(this); AddRef(); return NS_OK; } @@ -99,7 +99,7 @@ NS_IMETHODIMP nsScriptablePeer::QueryInterface(const nsIID& aIID, void** aInstan } if(aIID.Equals(kISupportsIID)) { - *aInstancePtr = static_cast(static_cast(this)); + *aInstancePtr = static_cast(static_cast(this)); AddRef(); return NS_OK; } @@ -116,3 +116,38 @@ NS_IMETHODIMP nsScriptablePeer::GetVersion(char * *aVersion) mPlugin->getVersion(aVersion); return NS_OK; } + + +NS_IMETHODIMP nsScriptablePeer::DumpLayout(nsISupports *aWindow, const PRUnichar *aFilePath, const PRUnichar *aFileName) +{ + + if (mPlugin) + mPlugin->DumpLayout(aWindow,aFilePath,aFileName); + + + return NS_OK; +} + + +// +// the following method will be callable from JavaScript +// +NS_IMETHODIMP nsScriptablePeer::StartDirectorySearch(const char *aFilePath) +{ + + if (mPlugin) + mPlugin->StartDirectorySearch(aFilePath); + + return NS_OK; +} + + +NS_IMETHODIMP nsScriptablePeer::GetNextFileInDirectory(char **aFilePath) +{ + + if (mPlugin) + mPlugin->GetNextFileInDirectory(aFilePath); + + + return NS_OK; +} diff --git a/mozilla/modules/plugin/tools/sdk/samples/simple/nsScriptablePeer.h b/mozilla/modules/plugin/tools/sdk/samples/simple/nsScriptablePeer.h index fc6c2542e44..fac4a713ea4 100644 --- a/mozilla/modules/plugin/tools/sdk/samples/simple/nsScriptablePeer.h +++ b/mozilla/modules/plugin/tools/sdk/samples/simple/nsScriptablePeer.h @@ -45,7 +45,7 @@ #ifndef __nsScriptablePeer_h__ #define __nsScriptablePeer_h__ -#include "nsISimplePlugin.h" +#include "nsIDebugPlugin.h" #include "nsIClassInfo.h" class nsPluginInstance; @@ -78,7 +78,7 @@ class nsClassInfoMixin : public nsIClassInfo {return NS_ERROR_NOT_IMPLEMENTED;} }; -class nsScriptablePeer : public nsISimplePlugin, +class nsScriptablePeer : public nsIDebugPlugin, public nsClassInfoMixin { public: @@ -96,7 +96,7 @@ protected: public: // native methods callable from JavaScript - NS_DECL_NSISIMPLEPLUGIN + NS_DECL_NSIDEBUGPLUGIN protected: nsPluginInstance* mPlugin; diff --git a/mozilla/modules/plugin/tools/sdk/samples/simple/plugin.cpp b/mozilla/modules/plugin/tools/sdk/samples/simple/plugin.cpp index d6b7e8f0246..4fbc9ef2146 100644 --- a/mozilla/modules/plugin/tools/sdk/samples/simple/plugin.cpp +++ b/mozilla/modules/plugin/tools/sdk/samples/simple/plugin.cpp @@ -38,6 +38,13 @@ #include "plugin.h" #include "nsIServiceManager.h" #include "nsIMemory.h" +#include "nsIDebugObject.h" +#include "nsXPIDLString.h" +#include "nsIFile.h" +#include "nsILocalFile.h" +#include "nsISimpleEnumerator.h" +#include "nsMemory.h" +#include "nsNetUtil.h" // service manager which will give the access to all public browser services // we will use memory service as an illustration @@ -47,9 +54,9 @@ nsIServiceManager * gServiceManager = NULL; // Unix needs this #ifdef XP_UNIX -#define MIME_TYPES_HANDLED "application/simple-plugin" -#define PLUGIN_NAME "Simple Plugin Example for Mozilla" -#define PLUGIN_DESCRIPTION "Simple Plugin Example for Mozilla" +#define MIME_TYPES_HANDLED "application/debug-plugin" +#define PLUGIN_NAME "Debug Plugin" +#define PLUGIN_DESCRIPTION "Debug Plugin" char* NPP_GetMIMEDescription(void) { @@ -165,6 +172,89 @@ void nsPluginInstance::getVersion(char* *aVersion) NS_IF_RELEASE(nsMemoryService); } +//----------------------------------------------------- + +void +nsPluginInstance::DumpLayout(nsISupports *aWindow, const PRUnichar *aFilePath, const PRUnichar *aFileName) +{ + + nsIDebugObject *theDebugObject=NULL; + + if (gServiceManager) { + // get service using its contract id and use it to allocate the memory + gServiceManager->GetServiceByContractID("@mozilla.org/debug/debugobject;1", NS_GET_IID(nsIDebugObject), (void **)&theDebugObject); + if(theDebugObject){ + theDebugObject->DumpContent(aWindow,aFilePath,aFileName); + } + } +} + +//----------------------------------------------------- + +void +nsPluginInstance::StartDirectorySearch(const char *aFilePath) +{ +nsXPIDLCString dirPath; +nsresult rv; + + nsCOMPtr theDir = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID); + rv = NS_InitFileFromURLSpec(theDir, aFilePath); + + if (NS_FAILED(rv)){ + mIter = 0; + return; + } + + rv = theDir->GetDirectoryEntries(getter_AddRefs(mIter)); + if (NS_FAILED(rv)){ + mIter = 0; + return; + } +} + +//----------------------------------------------------- + +void +nsPluginInstance::GetNextFileInDirectory(char **aDirName) +{ +PRBool hasMore; +nsresult rv; +nsCOMPtr supports; +char* URLName; + + *aDirName = 0; + if ( 0 ==mIter ){ + return; + } + + while ( NS_SUCCEEDED(mIter->HasMoreElements(&hasMore)) ){ + rv = mIter->GetNext(getter_AddRefs(supports)); + if (NS_FAILED(rv)) + break; + nsCOMPtr dirEntry(do_QueryInterface(supports, &rv)); + if (NS_FAILED(rv)) + break; + nsXPIDLCString filePath; + char* afilepath; + rv = dirEntry->GetPath(&afilepath); + if (NS_FAILED(rv)) + continue; + + if( strstr(afilepath,".html") != 0 ) { + *aDirName = afilepath; + NS_GetURLSpecFromFile(dirEntry,&URLName); + *aDirName = URLName; + break; + } else { + nsMemory::Free(afilepath); + } + } +} + + +//----------------------------------------------------- + + // ============================== // ! Scriptability related code ! // ============================== @@ -181,7 +271,7 @@ NPError nsPluginInstance::GetValue(NPPVariable aVariable, void *aValue) switch (aVariable) { case NPPVpluginScriptableInstance: { // addref happens in getter, so we don't addref here - nsISimplePlugin * scriptablePeer = getScriptablePeer(); + nsIDebugPlugin * scriptablePeer = getScriptablePeer(); if (scriptablePeer) { *(nsISupports **)aValue = scriptablePeer; } else @@ -190,7 +280,7 @@ NPError nsPluginInstance::GetValue(NPPVariable aVariable, void *aValue) break; case NPPVpluginScriptableIID: { - static nsIID scriptableIID = NS_ISIMPLEPLUGIN_IID; + static nsIID scriptableIID = NS_IDEBUGPLUGIN_IID; nsIID* ptr = (nsIID *)NPN_MemAlloc(sizeof(nsIID)); if (ptr) { *ptr = scriptableIID; @@ -222,7 +312,7 @@ NPError nsPluginInstance::GetValue(NPPVariable aVariable, void *aValue) // ============================== // // this method will return the scriptable object (and create it if necessary) -nsISimplePlugin* nsPluginInstance::getScriptablePeer() +nsIDebugPlugin* nsPluginInstance::getScriptablePeer() { if (!mScriptablePeer) { mScriptablePeer = new nsScriptablePeer(this); diff --git a/mozilla/modules/plugin/tools/sdk/samples/simple/plugin.h b/mozilla/modules/plugin/tools/sdk/samples/simple/plugin.h index de539577772..592f43a07bc 100644 --- a/mozilla/modules/plugin/tools/sdk/samples/simple/plugin.h +++ b/mozilla/modules/plugin/tools/sdk/samples/simple/plugin.h @@ -40,6 +40,9 @@ #include "pluginbase.h" #include "nsScriptablePeer.h" +#include "nsIFile.h" +#include "nsILocalFile.h" +#include "nsISimpleEnumerator.h" class nsPluginInstance : public nsPluginInstanceBase { @@ -58,13 +61,17 @@ public: // locals void getVersion(char* *aVersion); - - nsISimplePlugin* getScriptablePeer(); + void DumpLayout(nsISupports *aWindow,const PRUnichar *aFilePath, const PRUnichar *aFileName); + void StartDirectorySearch(const char *aFilePath); + void GetNextFileInDirectory(char **aFilePath); + nsIDebugPlugin* getScriptablePeer(); private: - NPP mInstance; - NPBool mInitialized; - nsISimplePlugin * mScriptablePeer; + NPP mInstance; + NPBool mInitialized; + nsIDebugPlugin * mScriptablePeer; + nsCOMPtr mIter; + public: char mString[128]; diff --git a/mozilla/modules/plugin/tools/sdk/samples/simple/resource.h b/mozilla/modules/plugin/tools/sdk/samples/simple/resource.h index 55e59cd1f9c..864d18674f5 100644 --- a/mozilla/modules/plugin/tools/sdk/samples/simple/resource.h +++ b/mozilla/modules/plugin/tools/sdk/samples/simple/resource.h @@ -1,6 +1,6 @@ //{{NO_DEPENDENCIES}} // Microsoft Developer Studio generated include file. -// Used by simple.rc +// Used by npDebug.rc // #define IDD_MAIN 101 #define IDC_BUTTON_GO 1002 diff --git a/mozilla/modules/plugin/tools/sdk/samples/simple/test.html b/mozilla/modules/plugin/tools/sdk/samples/simple/test.html index a6f2c07577b..195c1908325 100644 --- a/mozilla/modules/plugin/tools/sdk/samples/simple/test.html +++ b/mozilla/modules/plugin/tools/sdk/samples/simple/test.html @@ -1,11 +1,11 @@ -Simple Plug-in Test +Debug Plug-in Test
-

XPConnect Scriptable Sample Plug-in

+

XPConnect Scriptable Debug Plug-in

This page contains a testcase which demonstrates the work of scriptable @@ -19,20 +19,33 @@ in the alert box.
-
+

- +